4 #include "stuffkeeperglue.h"
7 #include "stuffkeeper-data-item.h"
11 #include <glib/gstdio.h>
14 #include "stuffkeeper-data-backend.h"
17 #define KEYFILE_GENERAL "general"
18 #define SAVE_TIMEOUT 30000
22 class Stuffkeeper:Data:Tag from G:Object
24 private GList *items = {NULL} destroywith g_list_free;
25 private sqlite3 *sqlHandle = {NULL};
26 private StuffkeeperDataBackend *skdb = {NULL};
27 private gint id = {0};
33 signal last NONE (NONE)
46 open_from_id(StuffkeeperDataBackend *skdb, gint id)
50 obj->_priv->skdb = STUFFKEEPER_DATA_BACKEND(skdb);
51 obj->_priv->sqlHandle = stuffkeeper_data_backend_get_handle(obj->_priv->skdb);;
56 new(StuffkeeperDataBackend *skdb)
62 obj->_priv->skdb = STUFFKEEPER_DATA_BACKEND(skdb);
63 obj->_priv->sqlHandle = stuffkeeper_data_backend_get_handle(obj->_priv->skdb);;
65 query = sqlite3_mprintf
66 ("INSERT INTO 'Tags' ('mtime','name')"
68 (int)time(NULL), "New Tag");
70 result = sqlite3_exec(obj->_priv->sqlHandle, query, NULL, NULL, &error);
71 if (result != SQLITE_OK) {
72 printf("failed: %s\n", error);
75 obj->_priv->id = sqlite3_last_insert_rowid(obj->_priv->sqlHandle);
82 new_with_id(StuffkeeperDataBackend *skdb, gint id)
89 obj->_priv->skdb = STUFFKEEPER_DATA_BACKEND(skdb);
90 obj->_priv->sqlHandle = stuffkeeper_data_backend_get_handle(obj->_priv->skdb);;
92 query = sqlite3_mprintf
93 ("INSERT INTO 'Tags' ('id','mtime','name')"
94 "values (%i,%i,'%q');",
95 id,(int)time(NULL), "New Tag");
97 result = sqlite3_exec(obj->_priv->sqlHandle, query, NULL, NULL, &error);
98 if (result != SQLITE_OK) {
99 printf("failed: %s\n", error);
115 return self->_priv->id;
126 char *query = sqlite3_mprintf("SELECT name FROM Tags WHERE id=%i", self->_priv->id);
130 r = sqlite3_prepare_v2(self->_priv->sqlHandle, query, -1, &stmt, &tail);
133 if((r = sqlite3_step(stmt)) == SQLITE_ROW)
135 retv = g_strdup((gchar *)sqlite3_column_text(stmt, 0));
138 sqlite3_finalize(stmt);
141 retv = g_strdup("Failed to get row");
150 set_title(self, const gchar *title)
154 char *query = sqlite3_mprintf("UPDATE Tags SET mtime=%i,name=%Q WHERE id=%i",(int)time(NULL), title, self->_priv->id);
155 result = sqlite3_exec(self->_priv->sqlHandle, query, NULL, NULL, &error);
156 if (result != SQLITE_OK) {
157 printf("failed: %s\n", error);
160 self_tag_changed(self);
165 * Functions to manage
171 delete_yourself(self)
175 char *query = sqlite3_mprintf("DELETE FROM Tags WHERE id=%i",self->_priv->id);
176 result = sqlite3_exec(self->_priv->sqlHandle, query, NULL, NULL, &error);
177 if (result != SQLITE_OK) {
178 printf("failed: %s\n", error);
188 return g_list_length(self->_priv->items);
192 add_item(self, StuffkeeperDataItem *item)
194 self->_priv->items = g_list_append(self->_priv->items, STUFFKEEPER_DATA_ITEM(item));
195 self_tag_changed(self);
199 remove_item(self, StuffkeeperDataItem *item)
201 self->_priv->items = g_list_remove(self->_priv->items, STUFFKEEPER_DATA_ITEM(item));
202 self_tag_changed(self);
206 finalize(G:Object *obj)
208 g_debug("destroying tag\n");
216 return g_list_copy(self->_priv->items);