From a35488f4b8f5c88b5f81f134596929a28dd74b42 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 5 Nov 2010 01:04:22 +0100 Subject: List untagged wallpapers from the new 'Other' page. --- db.c | 41 +++++++++++++++++++++++++++++++++++++++++ db.h | 1 + walls.ui | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ window_main.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) diff --git a/db.c b/db.c index 2e3c5bf..c6e6e93 100644 --- a/db.c +++ b/db.c @@ -521,6 +521,47 @@ int db_get_walls_by_tags(GArray *tags, GArray **array) { return 1; } +int db_get_walls_untagged(GArray **array) { + sqlite3_stmt *stmt; + int rc; + struct wallpaper_t temp, *temp2; + + rc = sqlite3_prepare_v2(db, "SELECT w.id, w.filepath, w.date, w.size, w.width, w.height " + "FROM wallpaper w WHERE NOT (SELECT COUNT(*) FROM walltags t WHERE t.wallid = w.id)", + -1, &stmt, NULL); + if(rc != SQLITE_OK) { + return 0; + } + + *array = g_array_new(FALSE, FALSE, sizeof(struct wallpaper_t)); + while((rc = sqlite3_step(stmt)) == SQLITE_ROW) { + temp.filepath = g_strdup((const gchar*)sqlite3_column_text(stmt, 1)); + temp.id = sqlite3_column_int64(stmt, 0); + if(sizeof(time_t) == 8) { + temp.date = sqlite3_column_int64(stmt, 2); + } else { + temp.date = sqlite3_column_int(stmt, 2); + } + temp.size = sqlite3_column_int(stmt, 3); + temp.width = sqlite3_column_int(stmt, 4); + temp.height = sqlite3_column_int(stmt, 5); + g_array_append_val(*array, temp); + } + + sqlite3_finalize(stmt); + + if(rc != SQLITE_DONE) { + for(int i = 0; i < (*array)->len; i++) { + temp2 = &g_array_index(*array, struct wallpaper_t, i); + g_free(temp2->filepath); + } + g_array_free(*array, TRUE); + return 0; + } + + return 1; +} + sqlite_uint64 db_add_tag(const char *name, sqlite_uint64 parent) { sqlite3_stmt *stmt; int rc; diff --git a/db.h b/db.h index 97a830c..433cfa7 100644 --- a/db.h +++ b/db.h @@ -43,6 +43,7 @@ int db_get_wallpaper_data(sqlite_uint64, struct wallpaper_t*); int db_get_wall_tags(sqlite_uint64, GArray**); int db_get_wallpapers(sqlite_uint64, GArray**); int db_get_walls_by_tags(GArray*, GArray**); +int db_get_walls_untagged(GArray**); sqlite_uint64 db_add_tag(const char*, sqlite_uint64); int db_get_tags_all(GArray**); int db_get_top_level_tags(GArray**); diff --git a/walls.ui b/walls.ui index f4aa3c9..083b59f 100644 --- a/walls.ui +++ b/walls.ui @@ -241,6 +241,54 @@ False + + + True + vertical + + + None + True + True + False + True + + + + False + 0 + + + + + Untagged + True + True + False + True + other_none_radiobtn + + + + False + 1 + + + + + 2 + + + + + True + Other + + + 2 + False + + False diff --git a/window_main.c b/window_main.c index 8d756d7..680506b 100644 --- a/window_main.c +++ b/window_main.c @@ -921,6 +921,50 @@ gboolean on_thumbview_button_press_event(GtkWidget *widget, GdkEventButton *even return FALSE; } +void on_other_none_radiobtn_toggled(GtkToggleButton *togglebutton, gpointer user_data) { + GtkListStore *liststore; + GtkTreeModel *old_model; + + if(gtk_toggle_button_get_active(togglebutton) == FALSE) { + return; + } + + old_model = gtk_icon_view_get_model(thumbview); + + liststore = gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_STRING); + gtk_icon_view_set_model(thumbview, GTK_TREE_MODEL(liststore)); + + if(old_model) + gtk_list_store_clear(GTK_LIST_STORE(old_model)); +} + +void on_other_untagged_radiobtn_toggled(GtkToggleButton *togglebutton, gpointer user_data) { + GtkListStore *liststore; + GtkTreeModel *old_model; + GArray *wallarray; + + if(gtk_toggle_button_get_active(togglebutton) == FALSE) { + return; + } + + if(!db_get_walls_untagged(&wallarray)) { + g_warning("Could not fetch untagged walls\n"); + return; + } + + liststore = gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_STRING); + fill_wall_list(liststore, wallarray); + + old_model = gtk_icon_view_get_model(thumbview); + + gtk_icon_view_set_model(thumbview, GTK_TREE_MODEL(liststore)); + + start_thumb_thread(liststore); + + if(old_model) + gtk_list_store_clear(GTK_LIST_STORE(old_model)); +} + gboolean on_left_pages_switch_page(GtkNotebook *notebook, GtkNotebookTab page, guint page_num, gpointer user_data) { switch(page_num) { case 0: -- cgit v1.2.3