Initial commit
This commit is contained in:
commit
767ca99d33
9 changed files with 380 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
collections
|
16
src/Makefile
Normal file
16
src/Makefile
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
CFLAGS=`pkg-config hildon-1 --cflags --libs`
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(CC) -Wall -Wextra -pedantic \
|
||||||
|
collections.c \
|
||||||
|
interface.c \
|
||||||
|
c-main-window.c \
|
||||||
|
c-new-item-dialog.c \
|
||||||
|
$(CFLAGS) \
|
||||||
|
-o collections
|
||||||
|
|
||||||
|
.PHONY: check-syntax
|
||||||
|
check-syntax:
|
||||||
|
/scratchbox/login $(CC) -pedantic -Wall -Wextra -fsyntax-only \
|
||||||
|
`readlink -f $(CHK_SOURCES)` \
|
||||||
|
`/scratchbox/login pkg-config hildon-1 --cflags --libs`
|
146
src/c-main-window.c
Normal file
146
src/c-main-window.c
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
#include "c-main-window.h"
|
||||||
|
#include <hildon/hildon.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "c-new-item-dialog.h"
|
||||||
|
#include "interface.h"
|
||||||
|
|
||||||
|
G_DEFINE_TYPE(CMainWindow, c_main_window, HILDON_TYPE_STACKABLE_WINDOW)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
COL_NAME = 0,
|
||||||
|
COL_CURRENT,
|
||||||
|
COL_TOTAL,
|
||||||
|
NUM_COLS
|
||||||
|
};
|
||||||
|
|
||||||
|
static void c_main_window_add_menu(CMainWindow *window);
|
||||||
|
static void c_main_window_on_new(GtkWidget *widget, GtkWindow *window);
|
||||||
|
|
||||||
|
GtkWidget *c_main_window_new(void)
|
||||||
|
{
|
||||||
|
return g_object_new(C_TYPE_MAIN_WINDOW, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void c_main_window_add_line(CMainWindow *window,
|
||||||
|
const gchar *name,
|
||||||
|
gint current_qty,
|
||||||
|
gint total_qty)
|
||||||
|
{
|
||||||
|
gtk_list_store_append(window->store, &window->iter);
|
||||||
|
gtk_list_store_set(window ->store, &window->iter,
|
||||||
|
COL_NAME, name,
|
||||||
|
COL_CURRENT, current_qty,
|
||||||
|
COL_TOTAL, total_qty,
|
||||||
|
-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_main_window_class_init(CMainWindowClass *class)
|
||||||
|
{}
|
||||||
|
|
||||||
|
static void c_main_window_init(CMainWindow *window)
|
||||||
|
{
|
||||||
|
GtkCellRenderer *renderer;
|
||||||
|
GtkWidget *view;
|
||||||
|
GtkTreeViewColumn *current_column;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
index = -1;
|
||||||
|
|
||||||
|
c_main_window_add_menu(window);
|
||||||
|
|
||||||
|
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||||
|
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
|
||||||
|
|
||||||
|
window->store = gtk_list_store_new(NUM_COLS,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_INT,
|
||||||
|
G_TYPE_INT);
|
||||||
|
|
||||||
|
view = gtk_tree_view_new();
|
||||||
|
|
||||||
|
renderer = gtk_cell_renderer_text_new();
|
||||||
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
|
||||||
|
++index,
|
||||||
|
"Naam",
|
||||||
|
renderer,
|
||||||
|
"text", COL_NAME,
|
||||||
|
NULL);
|
||||||
|
current_column = gtk_tree_view_get_column(GTK_TREE_VIEW(view), index);
|
||||||
|
gtk_tree_view_column_set_expand(current_column, TRUE);
|
||||||
|
|
||||||
|
renderer = gtk_cell_renderer_text_new();
|
||||||
|
gtk_object_set(GTK_OBJECT(renderer), "xalign", 1.0, NULL);
|
||||||
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
|
||||||
|
++index,
|
||||||
|
"",
|
||||||
|
renderer,
|
||||||
|
"text", COL_CURRENT,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
renderer = gtk_cell_renderer_text_new();
|
||||||
|
gtk_object_set(GTK_OBJECT(renderer), "xalign", 1.0, NULL);
|
||||||
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
|
||||||
|
++index,
|
||||||
|
"",
|
||||||
|
renderer,
|
||||||
|
"text", COL_TOTAL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gtk_tree_view_set_model(GTK_TREE_VIEW(view),
|
||||||
|
GTK_TREE_MODEL(window->store));
|
||||||
|
g_object_unref(window->store);
|
||||||
|
|
||||||
|
gtk_container_add(GTK_CONTAINER(window), view);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_main_window_add_menu(CMainWindow *window)
|
||||||
|
{
|
||||||
|
GtkWidget *appmenu;
|
||||||
|
GtkWidget *new_button;
|
||||||
|
|
||||||
|
appmenu = hildon_app_menu_new();
|
||||||
|
|
||||||
|
new_button = hildon_gtk_button_new(HILDON_SIZE_AUTO);
|
||||||
|
gtk_button_set_label(GTK_BUTTON(new_button), "New Item");
|
||||||
|
g_signal_connect_after(new_button,
|
||||||
|
"clicked",
|
||||||
|
G_CALLBACK(c_main_window_on_new),
|
||||||
|
GTK_WINDOW(window));
|
||||||
|
|
||||||
|
hildon_app_menu_append(HILDON_APP_MENU(appmenu), GTK_BUTTON(new_button));
|
||||||
|
gtk_widget_show_all(appmenu);
|
||||||
|
|
||||||
|
hildon_stackable_window_set_main_menu(HILDON_STACKABLE_WINDOW(window),
|
||||||
|
HILDON_APP_MENU(appmenu));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_main_window_on_new(GtkWidget *widget, GtkWindow *window)
|
||||||
|
{
|
||||||
|
GtkWidget *dialog;
|
||||||
|
gint result;
|
||||||
|
gchar *name = NULL;
|
||||||
|
gint total_qty;
|
||||||
|
|
||||||
|
dialog = interface_show_new_item_dialog(window);
|
||||||
|
|
||||||
|
result = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||||
|
|
||||||
|
if (result == GTK_RESPONSE_OK) {
|
||||||
|
const gchar *tmp;
|
||||||
|
tmp = c_new_item_dialog_get_name(C_NEW_ITEM_DIALOG(dialog));
|
||||||
|
name = (gchar *)malloc(strlen(tmp) + 1);
|
||||||
|
|
||||||
|
strcpy(name, tmp);
|
||||||
|
strcat(name, "\0");
|
||||||
|
|
||||||
|
total_qty = c_new_item_dialog_get_total_qty(C_NEW_ITEM_DIALOG(dialog));
|
||||||
|
|
||||||
|
gtk_widget_destroy(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name != NULL) {
|
||||||
|
c_main_window_add_line(C_MAIN_WINDOW(window), name, 0, total_qty);
|
||||||
|
}
|
||||||
|
}
|
61
src/c-main-window.h
Normal file
61
src/c-main-window.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#ifndef __C_MAIN_WINDOW_H__
|
||||||
|
#define __C_MAIN_WINDOW_H__
|
||||||
|
|
||||||
|
#include <hildon/hildon-stackable-window.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define C_TYPE_MAIN_WINDOW \
|
||||||
|
(c_main_window_get_type())
|
||||||
|
|
||||||
|
#define C_MAIN_WINDOW(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||||
|
C_TYPE_MAIN_WINDOW, \
|
||||||
|
CMainWindow))
|
||||||
|
|
||||||
|
#define C_MAIN_WINDOW_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
||||||
|
C_TYPE_MAIN_WINDOW, \
|
||||||
|
CMainWindowClass))
|
||||||
|
|
||||||
|
#define C_IS_MAIN_WINDOW(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||||
|
C_TYPE_MAIN_WINDOW))
|
||||||
|
|
||||||
|
#define C_IS_MAIN_WINDOW_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
|
||||||
|
C_TYPE_MAIN_WINDOW))
|
||||||
|
|
||||||
|
#define C_MAIN_WINDOW_GET_CLASS(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||||
|
C_TYPE_MAIN_WINDOW, \
|
||||||
|
CMainWindowClass))
|
||||||
|
|
||||||
|
typedef struct _CMainWindow CMainWindow;
|
||||||
|
typedef struct _CMainWindowClass CMainWindowClass;
|
||||||
|
|
||||||
|
struct _CMainWindowClass
|
||||||
|
{
|
||||||
|
HildonStackableWindowClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _CMainWindow
|
||||||
|
{
|
||||||
|
HildonStackableWindow parent;
|
||||||
|
|
||||||
|
GtkTreeIter iter;
|
||||||
|
GtkListStore *store;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType c_main_window_get_type(void);
|
||||||
|
|
||||||
|
GtkWidget *c_main_window_new(void);
|
||||||
|
|
||||||
|
void c_main_window_add_line(CMainWindow *window,
|
||||||
|
const gchar *name,
|
||||||
|
gint current_qty,
|
||||||
|
gint total_qty);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __C_MAIN_WINDOW_H__ */
|
49
src/c-new-item-dialog.c
Normal file
49
src/c-new-item-dialog.c
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#include "c-new-item-dialog.h"
|
||||||
|
#include <hildon/hildon-entry.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
G_DEFINE_TYPE(CNewItemDialog, c_new_item_dialog, GTK_TYPE_DIALOG)
|
||||||
|
|
||||||
|
GtkWidget *c_new_item_dialog_new(void)
|
||||||
|
{
|
||||||
|
return g_object_new(C_TYPE_NEW_ITEM_DIALOG, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar *c_new_item_dialog_get_name(CNewItemDialog *dialog)
|
||||||
|
{
|
||||||
|
return hildon_entry_get_text(HILDON_ENTRY(dialog->name_entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
gint c_new_item_dialog_get_total_qty(CNewItemDialog *dialog)
|
||||||
|
{
|
||||||
|
return atoi(hildon_entry_get_text(HILDON_ENTRY(dialog->qty_entry)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_new_item_dialog_class_init(CNewItemDialogClass *class)
|
||||||
|
{}
|
||||||
|
|
||||||
|
static void c_new_item_dialog_init(CNewItemDialog *dialog)
|
||||||
|
{
|
||||||
|
GtkWidget *content_area;
|
||||||
|
GtkWidget *hbox;
|
||||||
|
|
||||||
|
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||||
|
|
||||||
|
hbox = gtk_vbox_new(FALSE, 0);
|
||||||
|
gtk_container_add(GTK_CONTAINER(content_area), hbox);
|
||||||
|
|
||||||
|
dialog->name_entry = hildon_entry_new(HILDON_SIZE_AUTO);
|
||||||
|
hildon_entry_set_placeholder(HILDON_ENTRY(dialog->name_entry), "Name...");
|
||||||
|
gtk_box_pack_start(GTK_BOX(hbox), dialog->name_entry, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
dialog->qty_entry = hildon_entry_new(HILDON_SIZE_AUTO);
|
||||||
|
hildon_entry_set_text(HILDON_ENTRY(dialog->qty_entry), "0");
|
||||||
|
gtk_box_pack_start(GTK_BOX(hbox), dialog->qty_entry, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
gtk_window_set_title(GTK_WINDOW(dialog), "New item");
|
||||||
|
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
|
||||||
|
GTK_STOCK_OK,
|
||||||
|
GTK_RESPONSE_OK,
|
||||||
|
NULL);
|
||||||
|
}
|
60
src/c-new-item-dialog.h
Normal file
60
src/c-new-item-dialog.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#ifndef __C_NEW_ITEM_DIALOG_H__
|
||||||
|
#define __C_NEW_ITEM_DIALOG_H__
|
||||||
|
|
||||||
|
#include <gtk/gtkdialog.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define C_TYPE_NEW_ITEM_DIALOG \
|
||||||
|
(c_new_item_dialog_get_type())
|
||||||
|
|
||||||
|
#define C_NEW_ITEM_DIALOG(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||||
|
C_TYPE_NEW_ITEM_DIALOG, \
|
||||||
|
CNewItemDialog))
|
||||||
|
|
||||||
|
#define C_NEW_ITEM_DIALOG_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
||||||
|
C_TYPE_NEW_ITEM_DIALOG, \
|
||||||
|
CNewItemDialogClass))
|
||||||
|
|
||||||
|
#define C_IS_NEW_ITEM_DIALOG(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||||
|
C_TYPE_NEW_ITEM_DIALOG))
|
||||||
|
|
||||||
|
#define C_IS_NEW_ITEM_DIALOG_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
|
||||||
|
C_TYPE_NEW_ITEM_DIALOG))
|
||||||
|
|
||||||
|
#define C_NEW_ITEM_DIALOG_GET_CLASS(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||||
|
C_TYPE_NEW_ITEM_DIALOG, \
|
||||||
|
CNewItemDialogClass))
|
||||||
|
|
||||||
|
typedef struct _CNewItemDialog CNewItemDialog;
|
||||||
|
typedef struct _CNewItemDialogClass CNewItemDialogClass;
|
||||||
|
|
||||||
|
struct _CNewItemDialogClass
|
||||||
|
{
|
||||||
|
GtkDialogClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _CNewItemDialog
|
||||||
|
{
|
||||||
|
GtkDialog parent;
|
||||||
|
|
||||||
|
GtkWidget *name_entry;
|
||||||
|
GtkWidget *qty_entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType c_new_item_dialog_get_type(void);
|
||||||
|
|
||||||
|
GtkWidget *c_new_item_dialog_new(void);
|
||||||
|
|
||||||
|
const gchar *c_new_item_dialog_get_name(CNewItemDialog *dialog);
|
||||||
|
|
||||||
|
gint c_new_item_dialog_get_total_qty(CNewItemDialog *dialog);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __C_NEW_ITEM_DIALOG_H__ */
|
15
src/collections.c
Normal file
15
src/collections.c
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include <hildon/hildon.h>
|
||||||
|
#include "interface.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
hildon_gtk_init(&argc, &argv);
|
||||||
|
|
||||||
|
g_set_application_name("Collections");
|
||||||
|
|
||||||
|
interface_show_main_window();
|
||||||
|
|
||||||
|
gtk_main();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
28
src/interface.c
Normal file
28
src/interface.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include <hildon/hildon.h>
|
||||||
|
#include "interface.h"
|
||||||
|
#include "c-main-window.h"
|
||||||
|
#include "c-new-item-dialog.h"
|
||||||
|
|
||||||
|
void interface_show_main_window(void)
|
||||||
|
{
|
||||||
|
GtkWidget *window;
|
||||||
|
|
||||||
|
window = c_main_window_new();
|
||||||
|
gtk_widget_show_all(window);
|
||||||
|
|
||||||
|
c_main_window_add_line(C_MAIN_WINDOW(window), "Biomega", 2, 0);
|
||||||
|
c_main_window_add_line(C_MAIN_WINDOW(window), "Blame!", 7, 10);
|
||||||
|
c_main_window_add_line(C_MAIN_WINDOW(window), "Hellsing", 2, 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkWidget *interface_show_new_item_dialog(GtkWindow *window)
|
||||||
|
{
|
||||||
|
GtkWidget *dialog;
|
||||||
|
|
||||||
|
dialog = c_new_item_dialog_new();
|
||||||
|
gtk_widget_show_all(dialog);
|
||||||
|
|
||||||
|
gtk_window_set_transient_for(GTK_WINDOW(dialog), window);
|
||||||
|
|
||||||
|
return dialog;
|
||||||
|
}
|
4
src/interface.h
Normal file
4
src/interface.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#include <gtk/gtkwindow.h>
|
||||||
|
|
||||||
|
void interface_show_main_window(void);
|
||||||
|
GtkWidget *interface_show_new_item_dialog(GtkWindow *window);
|
Loading…
Reference in a new issue