diff --git a/midori/main.c b/midori/main.c index 5b480b2a..14b97272 100644 --- a/midori/main.c +++ b/midori/main.c @@ -428,6 +428,37 @@ midori_history_terminate (sqlite3* db, sqlite3_close (db); } +static void +midori_bookmarks_remove_item_cb (KatzeArray* array, + KatzeItem* item, + sqlite3* db) +{ + gchar* sqlcmd; + char* errmsg = NULL; + + if (KATZE_ITEM_IS_BOOKMARK (item)) + sqlcmd = sqlite3_mprintf ( + "DELETE FROM bookmarks WHERE uri = '%q' " + " AND folder = '%q'", + katze_item_get_uri (item), + katze_item_get_meta_string (item, "folder")); + + else + sqlcmd = sqlite3_mprintf ( + "DELETE FROM bookmarks WHERE title = '%q'" + " AND folder = '%q'", + katze_item_get_name (item), + katze_item_get_meta_string (item, "folder")); + + if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK) + { + g_printerr (_("Failed to remove history item: %s\n"), errmsg); + sqlite3_free (errmsg); + } + + sqlite3_free (sqlcmd); +} + static sqlite3* midori_bookmarks_initialize (KatzeArray* array, const gchar* filename, @@ -450,6 +481,8 @@ midori_bookmarks_initialize (KatzeArray* array, "desc text, app integer, toolbar integer);", NULL, NULL, errmsg) != SQLITE_OK) return NULL; + g_signal_connect (array, "remove-item", + G_CALLBACK (midori_bookmarks_remove_item_cb), db); return db; } diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 0e3e7633..df831223 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -183,10 +183,6 @@ midori_bookmarks_insert_item_db (sqlite3* db, KatzeItem* item, gchar* folder); -void -midori_bookmarks_remove_item_from_db (sqlite3* db, - KatzeItem* item); - static void midori_bookmarkbar_populate (MidoriBrowser* browser); @@ -927,7 +923,7 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser, GtkTreeModel* model; if (!new_bookmark) - midori_bookmarks_remove_item_from_db (db, bookmark); + katze_array_remove_item (browser->bookmarks, bookmark); katze_item_set_name (bookmark, gtk_entry_get_text (GTK_ENTRY (entry_title))); @@ -3862,14 +3858,10 @@ static void midori_browser_bookmark_delete_activate_cb (GtkWidget* menuitem, MidoriBrowser* browser) { - sqlite3* db; KatzeItem* item; - db = g_object_get_data (G_OBJECT (browser->bookmarks), "db"); item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); - - midori_bookmarks_remove_item_from_db (db, item); - g_object_unref (item); + katze_array_remove_item (browser->bookmarks, item); } static void @@ -6367,6 +6359,15 @@ midori_bookmarkbar_insert_item (GtkWidget* toolbar, gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); } +static void +midori_bookmarkbar_remove_item_cb (KatzeArray* bookmarks, + KatzeItem* item, + MidoriBrowser* browser) +{ + if (gtk_widget_get_visible (browser->bookmarkbar)) + midori_bookmarkbar_populate (browser); +} + static void midori_bookmarkbar_populate (MidoriBrowser* browser) { @@ -6456,6 +6457,9 @@ midori_browser_set_bookmarks (MidoriBrowser* browser, { MidoriWebSettings* settings; + if (browser->bookmarks != NULL) + g_signal_handlers_disconnect_by_func (browser->bookmarks, + midori_bookmarkbar_remove_item_cb, browser); settings = midori_browser_get_settings (browser); g_signal_handlers_disconnect_by_func (settings, midori_browser_show_bookmarkbar_notify_value_cb, browser); @@ -6468,6 +6472,8 @@ midori_browser_set_bookmarks (MidoriBrowser* browser, g_signal_connect (settings, "notify::show-bookmarkbar", G_CALLBACK (midori_browser_show_bookmarkbar_notify_value_cb), browser); g_object_notify (G_OBJECT (settings), "show-bookmarkbar"); + g_signal_connect_after (bookmarks, "remove-item", + G_CALLBACK (midori_bookmarkbar_remove_item_cb), browser); } static void diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c index b572a98c..339c9d4e 100644 --- a/panels/midori-bookmarks.c +++ b/panels/midori-bookmarks.c @@ -281,34 +281,15 @@ midori_bookmarks_insert_item_db (sqlite3* db, sqlite3_free (sqlcmd); } -void -midori_bookmarks_remove_item_from_db (sqlite3* db, - KatzeItem* item) +static void +midori_bookmarks_remove_item_cb (KatzeArray* array, + KatzeItem* item, + MidoriBookmarks* bookmarks) { - gchar* sqlcmd; - char* errmsg = NULL; - - if (KATZE_ITEM_IS_BOOKMARK (item)) - sqlcmd = sqlite3_mprintf ( - "DELETE FROM bookmarks WHERE uri = '%q' " - " AND folder = '%q'", - katze_item_get_uri (item), - katze_item_get_meta_string (item, "folder")); - - else - sqlcmd = sqlite3_mprintf ( - "DELETE FROM bookmarks WHERE title = '%q'" - " AND folder = '%q'", - katze_item_get_name (item), - katze_item_get_meta_string (item, "folder")); - - if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK) - { - g_printerr (_("Failed to remove history item: %s\n"), errmsg); - sqlite3_free (errmsg); - } - - sqlite3_free (sqlcmd); + GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); + gtk_tree_store_clear (GTK_TREE_STORE (model)); + midori_bookmarks_read_from_db_to_model (bookmarks, + GTK_TREE_STORE (model), NULL, NULL, bookmarks->filter); } static void @@ -342,7 +323,7 @@ midori_bookmarks_row_changed_cb (GtkTreeModel* model, else parent_name = g_strdup (""); - midori_bookmarks_remove_item_from_db (db, item); + katze_array_remove_item (bookmarks->array, item); midori_bookmarks_insert_item_db (db, item, parent_name); } @@ -387,9 +368,7 @@ midori_bookmarks_delete_clicked_cb (GtkWidget* toolitem, { GtkTreeModel* model; GtkTreeIter iter; - sqlite3* db; - db = g_object_get_data (G_OBJECT (bookmarks->array), "db"); if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (bookmarks->treeview), &model, &iter)) { @@ -397,9 +376,13 @@ midori_bookmarks_delete_clicked_cb (GtkWidget* toolitem, gtk_tree_model_get (model, &iter, 0, &item, -1); - midori_bookmarks_remove_item_from_db (db, item); + /* Manually remove the iter and block clearing the treeview */ gtk_tree_store_remove (GTK_TREE_STORE (model), &iter); - + g_signal_handlers_block_by_func (bookmarks->array, + midori_bookmarks_remove_item_cb, bookmarks); + katze_array_remove_item (bookmarks->array, item); + g_signal_handlers_unblock_by_func (bookmarks->array, + midori_bookmarks_remove_item_cb, bookmarks); g_object_unref (item); } } @@ -492,6 +475,8 @@ midori_bookmarks_set_app (MidoriBookmarks* bookmarks, g_object_ref (app); bookmarks->array = katze_object_get_object (app, "bookmarks"); g_object_set_data (G_OBJECT (bookmarks->array), "treeview", bookmarks->treeview); + g_signal_connect (bookmarks->array, "remove-item", + G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks); midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), NULL, "", NULL); g_signal_connect_after (model, "row-changed", diff --git a/panels/midori-bookmarks.h b/panels/midori-bookmarks.h index 2c53712f..3dc260be 100644 --- a/panels/midori-bookmarks.h +++ b/panels/midori-bookmarks.h @@ -47,10 +47,6 @@ midori_bookmarks_insert_item_db (sqlite3* db, KatzeItem* item, const gchar* folder); -void -midori_bookmarks_remove_item_from_db (sqlite3* db, - KatzeItem* item); - void midori_bookmarks_import_array_db (sqlite3* db, KatzeArray* array,