Add "Read" filter to main window
* src/data.c (data_get_unread_manga): New function. Gets any manga that have unread volumes. (data_get_volumes_for_manga): Default `volumes' to `NULL' to make sure we don't get garbage by mistake. * src/eom-main-window.c: Add new enum. The filter states that the main screen has. (eom_main_window_load): Get a list of unread manga if the window's state indecates we're looking for them. (add_menu): Add read filter button, shows only unread manga.
This commit is contained in:
parent
7727a458fb
commit
18d4d38e8d
3 changed files with 50 additions and 6 deletions
20
src/data.c
20
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue