aboutsummaryrefslogtreecommitdiffstats
path: root/src/c-main-window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c-main-window.c')
-rw-r--r--src/c-main-window.c87
1 files changed, 83 insertions, 4 deletions
diff --git a/src/c-main-window.c b/src/c-main-window.c
index 79c47c6..2afc87b 100644
--- a/src/c-main-window.c
+++ b/src/c-main-window.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <stdlib.h>
#include "c-new-item-dialog.h"
+#include "data.h"
#include "interface.h"
G_DEFINE_TYPE(CMainWindow, c_main_window, HILDON_TYPE_STACKABLE_WINDOW)
@@ -17,12 +18,31 @@ enum {
static void c_main_window_add_menu(CMainWindow *window);
static void c_main_window_on_new(GtkWidget *widget, GtkWindow *window);
+static void c_main_window_on_selection_changed(GtkTreeSelection *selection,
+ gpointer user_data);
GtkWidget *c_main_window_new(void)
{
return g_object_new(C_TYPE_MAIN_WINDOW, NULL);
}
+void c_main_window_load(CMainWindow *self)
+{
+ GList *list;
+
+ gtk_list_store_clear(self->store);
+
+ list = data_get_series();
+
+ while (list) {
+ struct collection *col = list->data;
+ c_main_window_add_line(self, col->name, col->current_qty, col->total_qty);
+ list = g_list_next(list);
+ }
+
+ g_list_free_1(list);
+}
+
void c_main_window_add_line(CMainWindow *window,
const gchar *name,
gint current_qty,
@@ -36,6 +56,22 @@ void c_main_window_add_line(CMainWindow *window,
-1);
}
+void c_main_window_set_no_select(CMainWindow *self)
+{
+ if (GTK_IS_WIDGET(self->add_button))
+ gtk_widget_set_sensitive(GTK_WIDGET(self->add_button), FALSE);
+ if (GTK_IS_WIDGET(self->remove_button))
+ gtk_widget_set_sensitive(GTK_WIDGET(self->remove_button), FALSE);
+}
+
+void c_main_window_set_has_select(CMainWindow *self)
+{
+ if (GTK_IS_WIDGET(self->add_button))
+ gtk_widget_set_sensitive(GTK_WIDGET(self->add_button), TRUE);
+ if (GTK_IS_WIDGET(self->remove_button))
+ gtk_widget_set_sensitive(GTK_WIDGET(self->remove_button), TRUE);
+}
+
static void c_main_window_class_init(CMainWindowClass *class)
{}
@@ -43,7 +79,10 @@ static void c_main_window_init(CMainWindow *window)
{
GtkCellRenderer *renderer;
GtkWidget *view;
+ GtkWidget *vbox;
+ GtkWidget *hbuttonbox;
GtkTreeViewColumn *current_column;
+ GtkTreeSelection *selection;
int index;
index = -1;
@@ -58,7 +97,15 @@ static void c_main_window_init(CMainWindow *window)
G_TYPE_INT,
G_TYPE_INT);
+ vbox = gtk_vbox_new(FALSE, 0);
+
view = gtk_tree_view_new();
+ gtk_box_pack_start(GTK_BOX(vbox), view, TRUE, TRUE, 0);
+
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+ g_signal_connect(selection, "changed",
+ G_CALLBACK(c_main_window_on_selection_changed),
+ (gpointer)window);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
@@ -71,7 +118,10 @@ static void c_main_window_init(CMainWindow *window)
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_object_set(GTK_OBJECT(renderer),
+ "xalign", 1.0,
+ "width", 100,
+ NULL);
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
++index,
"",
@@ -80,7 +130,10 @@ static void c_main_window_init(CMainWindow *window)
NULL);
renderer = gtk_cell_renderer_text_new();
- gtk_object_set(GTK_OBJECT(renderer), "xalign", 1.0, NULL);
+ gtk_object_set(GTK_OBJECT(renderer),
+ "xalign", 1.0,
+ "width", 100,
+ NULL);
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
++index,
"",
@@ -92,7 +145,19 @@ static void c_main_window_init(CMainWindow *window)
GTK_TREE_MODEL(window->store));
g_object_unref(window->store);
- gtk_container_add(GTK_CONTAINER(window), view);
+ hbuttonbox = gtk_hbutton_box_new();
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox), GTK_BUTTONBOX_END);
+ gtk_box_pack_start(GTK_BOX(vbox), hbuttonbox, FALSE, TRUE, 0);
+
+ window->add_button = gtk_button_new_from_stock(GTK_STOCK_ADD);
+ gtk_box_pack_start(GTK_BOX(hbuttonbox), window->add_button, FALSE, FALSE, 0);
+
+ window->remove_button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
+ gtk_box_pack_start(GTK_BOX(hbuttonbox), window->remove_button, FALSE, FALSE, 0);
+
+ gtk_container_add(GTK_CONTAINER(window), vbox);
+
+ c_main_window_set_no_select(window);
}
static void c_main_window_add_menu(CMainWindow *window)
@@ -141,6 +206,20 @@ static void c_main_window_on_new(GtkWidget *widget, GtkWindow *window)
}
if (name != NULL) {
- c_main_window_add_line(C_MAIN_WINDOW(window), name, 0, total_qty);
+ if (data_add_series(name, total_qty))
+ c_main_window_load(C_MAIN_WINDOW(window));
}
}
+
+static void c_main_window_on_selection_changed(GtkTreeSelection *selection,
+ gpointer user_data)
+{
+ gint count;
+ CMainWindow *self = (CMainWindow *)user_data;
+
+ count = gtk_tree_selection_count_selected_rows(selection);
+ if (count == 0)
+ c_main_window_set_no_select(self);
+ else
+ c_main_window_set_has_select(self);
+}