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,
"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;
}
KatzeItem* item,
gchar* folder);
-void
-midori_bookmarks_remove_item_from_db (sqlite3* db,
- KatzeItem* item);
-
static void
midori_bookmarkbar_populate (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)));
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
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)
{
{
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);
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
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
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);
}
{
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))
{
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);
}
}
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",
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,