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 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'db.c') 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; -- cgit v1.2.3