diff --git a/src/data.c b/src/data.c index 94e4735..da425ef 100644 --- a/src/data.c +++ b/src/data.c @@ -126,11 +126,29 @@ data_get_manga_by_id(gint manga_id) return manga; } +GList * +data_get_unread_manga(void) +{ + const char *sql = + " SELECT m.id, " + " m.name, " + " m.current_qty, " + " m.total_qty " + " FROM manga m " + " JOIN volume ON (m.id = manga_id) " + " WHERE read = 0 " + " GROUP BY m.id " + " ORDER BY name " + " COLLATE NOCASE "; + + return get_manga_for_query(sql); +} + void data_get_volumes_for_manga(Manga *manga) { gint count; - Volume *volumes; + Volume *volumes = NULL; sqlite3 *db; sqlite3_stmt *stmt; gchar *data_file; diff --git a/src/data.h b/src/data.h index 9dbf5e6..eb2cd39 100644 --- a/src/data.h +++ b/src/data.h @@ -25,6 +25,7 @@ gboolean data_add_volume_to_manga(gint, gint); GList *data_get_incomplete_manga(void); GList *data_get_manga(void); Manga *data_get_manga_by_id(gint); +GList *data_get_unread_manga(void); void data_get_volumes_for_manga(Manga*); gboolean data_mark_volume_read(gint, gint, gint); gboolean data_remove_volume_from_manga(gint, gint); diff --git a/src/eom-main-window.c b/src/eom-main-window.c index 6e95670..ea3a1df 100644 --- a/src/eom-main-window.c +++ b/src/eom-main-window.c @@ -21,6 +21,12 @@ enum { NUM_COLS }; +enum { + STATE_NORMAL = 0, + STATE_COLLECT, + STATE_READ +}; + struct filter_args { EomMainWindow *window; gint state; @@ -56,10 +62,17 @@ eom_main_window_load(EomMainWindow *self) gtk_list_store_clear(self->store); - if (self->state) + switch (self->state) { + case STATE_COLLECT: list = data_get_incomplete_manga(); - else + break; + case STATE_READ: + list = data_get_unread_manga(); + break; + default: list = data_get_manga(); + break; + } while (list) { Manga *manga = list->data; @@ -91,14 +104,17 @@ add_menu(EomMainWindow *window) { HildonAppMenu *appmenu; GtkWidget *new_button; - GtkWidget *all_filter, *collect_filter; + GtkWidget *all_filter, *collect_filter, *read_filter; struct filter_args *args0 = malloc(sizeof(struct filter_args)); struct filter_args *args1 = malloc(sizeof(struct filter_args)); + struct filter_args *args2 = malloc(sizeof(struct filter_args)); args0->window = window; - args0->state = 0; + args0->state = STATE_NORMAL; args1->window = window; - args1->state = 1; + args1->state = STATE_COLLECT; + args2->window = window; + args2->state = STATE_READ; appmenu = HILDON_APP_MENU(hildon_app_menu_new()); new_button = hildon_gtk_button_new(HILDON_SIZE_AUTO); @@ -123,6 +139,15 @@ add_menu(EomMainWindow *window) hildon_app_menu_add_filter(appmenu, GTK_BUTTON(collect_filter)); gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(collect_filter), FALSE); + read_filter = + hildon_gtk_radio_button_new_from_widget(HILDON_SIZE_AUTO, + GTK_RADIO_BUTTON(all_filter)); + gtk_button_set_label(GTK_BUTTON(read_filter), "Read"); + g_signal_connect_after(read_filter, "clicked", + G_CALLBACK(on_filter), args2); + hildon_app_menu_add_filter(appmenu, GTK_BUTTON(read_filter)); + gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(read_filter), FALSE); + gtk_widget_show_all(GTK_WIDGET(appmenu)); hildon_stackable_window_set_main_menu(HILDON_STACKABLE_WINDOW(window),