summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-01-02 19:14:29 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-01-02 19:14:29 +0100
commitf4e78b03800068498ab72b24f54d9d2c2ab71201 (patch)
tree8a61733ad595404f7a26fc84b53ff1f65c7359c1
parentdd29fc5cc27b5540500fa341726b594221aee76d (diff)
Implemented removal of tags.
-rw-r--r--db.c48
-rw-r--r--db.h1
-rw-r--r--window_tag.c34
3 files changed, 83 insertions, 0 deletions
diff --git a/db.c b/db.c
index 86a10f8..d47793a 100644
--- a/db.c
+++ b/db.c
@@ -428,6 +428,54 @@ sqlite_uint64 db_add_tag(const char *name) {
}
}
+static void db_remove_tag_walltags(sqlite_uint64 tagid) {
+ sqlite3_stmt *stmt;
+ int rc;
+
+ rc = sqlite3_prepare_v2(db, "DELETE FROM walltags WHERE tagid = ?", -1, &stmt, NULL);
+
+ if(rc != SQLITE_OK) {
+ return;
+ }
+
+ rc = sqlite3_bind_int64(stmt, 1, tagid);
+ if(rc != SQLITE_OK) {
+ sqlite3_finalize(stmt);
+ return;
+ }
+
+ sqlite3_step(stmt);
+
+ sqlite3_finalize(stmt);
+}
+
+static void db_remove_tag_tag(sqlite_uint64 tagid) {
+ sqlite3_stmt *stmt;
+ int rc;
+
+ rc = sqlite3_prepare_v2(db, "DELETE FROM tag WHERE id = ?", -1, &stmt, NULL);
+
+ if(rc != SQLITE_OK) {
+ return;
+ }
+
+ rc = sqlite3_bind_int64(stmt, 1, tagid);
+ if(rc != SQLITE_OK) {
+ sqlite3_finalize(stmt);
+ return;
+ }
+
+ sqlite3_step(stmt);
+
+ sqlite3_finalize(stmt);
+}
+
+void db_remove_tag(sqlite_uint64 tagid) {
+ db_remove_tag_walltags(tagid);
+
+ db_remove_tag_tag(tagid);
+}
+
int db_get_tags_all(GArray **array) {
struct tag_t temp, *temp2;
sqlite3_stmt *stmt;
diff --git a/db.h b/db.h
index 16f4cac..9cc1aec 100644
--- a/db.h
+++ b/db.h
@@ -36,6 +36,7 @@ int db_get_wallpapers(sqlite_uint64, GArray**);
sqlite_uint64 db_add_tag(const char*);
int db_get_tags_all(GArray**);
int db_add_wall_tag(sqlite_uint64, sqlite_uint64);
+void db_remove_tag(sqlite_uint64);
int db_remove_wall_tag(sqlite_uint64, sqlite_uint64);
#endif
diff --git a/window_tag.c b/window_tag.c
index 2209572..ad3dfba 100644
--- a/window_tag.c
+++ b/window_tag.c
@@ -150,6 +150,40 @@ void on_tags_addbtn_clicked(GtkButton *button, gpointer user_data) {
}
void on_tags_rembtn_clicked(GtkButton *button, gpointer user_data) {
+ GtkWidget *dialog;
+ struct tagdialog_data_t *data;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gchar *tagname;
+ guint64 tagid;
+ GValue value = {0};
+
+ data = user_data;
+
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->tagview));
+ if(!gtk_tree_selection_get_selected(selection, &model, &iter))
+ return;
+
+ gtk_tree_model_get_value(model, &iter, 3, &value);
+ tagid = g_value_get_uint64(&value);
+ g_value_unset(&value);
+
+ gtk_tree_model_get_value(model, &iter, 2, &value);
+ tagname = g_value_dup_string(&value);
+ g_value_unset(&value);
+
+ dialog = gtk_message_dialog_new(GTK_WINDOW(data->dialog), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are you sure you want to delete the tag \"%s\"?", tagname);
+
+ g_free(tagname);
+
+ if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_YES) {
+ db_remove_tag(tagid);
+ tagview_create_model(GTK_TREE_VIEW(data->tagview), user_data);
+ }
+
+ gtk_widget_destroy(dialog);
}
void on_tags_selallbtn_clicked(GtkButton *button, gpointer user_data) {