summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-04-24 23:52:48 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-04-24 23:52:48 +0200
commite4bd032ee3f525a8f774402c6128ba0646c30bcd (patch)
treea1e3d5b76d7884380fbd69054c6f22bff20a9a9e
parentd394a7e8ae4c6d450ffe6d774fe65310b03d00c9 (diff)
Store timestamp when adding wallpapers.
-rw-r--r--db.c43
-rw-r--r--db.h2
2 files changed, 32 insertions, 13 deletions
diff --git a/db.c b/db.c
index fe8c6a2..6b0bd22 100644
--- a/db.c
+++ b/db.c
@@ -22,6 +22,7 @@ static int db_create_tables() {
"create table wallpaper ("
" id integer not null,"
" dirid integer not null,"
+ " date integer not null,"
" filepath text not null,"
" size integer not null,"
" width integer not null,"
@@ -30,6 +31,7 @@ static int db_create_tables() {
");"
"create table tag ("
" id integer not null,"
+ " parent integer null,"
" name varchar(100) not null,"
" primary key (id)"
");"
@@ -221,7 +223,7 @@ sqlite_uint64 db_add_wallpaper(const char *filepath, sqlite_uint64 dirid, int si
sqlite3_stmt *stmt;
int rc;
- rc = sqlite3_prepare_v2(db, "INSERT INTO wallpaper (dirid, filepath, size, width, height) VALUES (?, ?, ?, ?, ?)", -1, &stmt, NULL);
+ rc = sqlite3_prepare_v2(db, "INSERT INTO wallpaper (dirid, date, filepath, size, width, height) VALUES (?, datetime('now'), ?, ?, ?, ?)", -1, &stmt, NULL);
if(rc != SQLITE_OK) {
return 0;
@@ -318,7 +320,7 @@ int db_get_wallpaper_data(sqlite_uint64 id, struct wallpaper_t *wall) {
sqlite3_stmt *stmt;
int rc;
- rc = sqlite3_prepare_v2(db, "SELECT id, filepath, size, width, height FROM wallpaper WHERE id = ? LIMIT 1", -1, &stmt, NULL);
+ rc = sqlite3_prepare_v2(db, "SELECT id, filepath, date, size, width, height FROM wallpaper WHERE id = ? LIMIT 1", -1, &stmt, NULL);
if(rc != SQLITE_OK) {
return 0;
}
@@ -333,9 +335,14 @@ int db_get_wallpaper_data(sqlite_uint64 id, struct wallpaper_t *wall) {
if(rc == SQLITE_ROW) {
wall->filepath = g_strdup((const gchar*)sqlite3_column_text(stmt, 1));
wall->id = sqlite3_column_int64(stmt, 0);
- wall->size = sqlite3_column_int(stmt, 2);
- wall->width = sqlite3_column_int(stmt, 3);
- wall->height = sqlite3_column_int(stmt, 4);
+ if(sizeof(time_t) == 8) {
+ wall->date = sqlite3_column_int64(stmt, 2);
+ } else {
+ wall->date = sqlite3_column_int(stmt, 2);
+ }
+ wall->size = sqlite3_column_int(stmt, 3);
+ wall->width = sqlite3_column_int(stmt, 4);
+ wall->height = sqlite3_column_int(stmt, 5);
}
sqlite3_finalize(stmt);
@@ -385,7 +392,7 @@ int db_get_wallpapers(sqlite_uint64 dirid, GArray **array) {
sqlite3_stmt *stmt;
int rc;
- rc = sqlite3_prepare_v2(db, "SELECT id, filepath, size, width, height FROM wallpaper WHERE dirid = ? ORDER BY filepath", -1, &stmt, NULL);
+ rc = sqlite3_prepare_v2(db, "SELECT id, filepath, date, size, width, height FROM wallpaper WHERE dirid = ? ORDER BY filepath", -1, &stmt, NULL);
if(rc != SQLITE_OK) {
return 0;
@@ -401,9 +408,14 @@ int db_get_wallpapers(sqlite_uint64 dirid, GArray **array) {
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);
- temp.size = sqlite3_column_int(stmt, 2);
- temp.width = sqlite3_column_int(stmt, 3);
- temp.height = sqlite3_column_int(stmt, 4);
+ 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);
}
@@ -449,7 +461,7 @@ int db_get_walls_by_tags(GArray *tags, GArray **array) {
struct wallpaper_t temp, *temp2;
join = gen_joinstring(tags->len);
- query = g_strdup_printf("SELECT w.id, w.filepath, w.size, w.width, w.height "
+ query = g_strdup_printf("SELECT w.id, w.filepath, w.date, w.size, w.width, w.height "
"FROM wallpaper w JOIN walltags t ON (t.wallid = w.id) WHERE t.tagid IN (%s)",
join);
g_free(join);
@@ -478,9 +490,14 @@ int db_get_walls_by_tags(GArray *tags, GArray **array) {
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);
- temp.size = sqlite3_column_int(stmt, 2);
- temp.width = sqlite3_column_int(stmt, 3);
- temp.height = sqlite3_column_int(stmt, 4);
+ 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);
}
diff --git a/db.h b/db.h
index 5992c76..771b5e3 100644
--- a/db.h
+++ b/db.h
@@ -3,6 +3,7 @@
#include <glib.h>
#include <sqlite3.h>
+#include <time.h>
struct directory_t {
gchar *name;
@@ -12,6 +13,7 @@ struct directory_t {
struct wallpaper_t {
gchar *filepath;
sqlite_uint64 id;
+ time_t date;
int size;
int width;
int height;