Use KatzeArray* to remove and monitor deleted bookmarks
The panel and the bookmarkbar need to monitor the removal of bookmarks, and there can be multiple windows, so the database should only be used to remove in one central place.
This commit is contained in:
parent
71549af089
commit
a7452bd0b5
4 changed files with 66 additions and 46 deletions
|
@ -428,6 +428,37 @@ midori_history_terminate (sqlite3* db,
|
||||||
sqlite3_close (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*
|
static sqlite3*
|
||||||
midori_bookmarks_initialize (KatzeArray* array,
|
midori_bookmarks_initialize (KatzeArray* array,
|
||||||
const gchar* filename,
|
const gchar* filename,
|
||||||
|
@ -450,6 +481,8 @@ midori_bookmarks_initialize (KatzeArray* array,
|
||||||
"desc text, app integer, toolbar integer);",
|
"desc text, app integer, toolbar integer);",
|
||||||
NULL, NULL, errmsg) != SQLITE_OK)
|
NULL, NULL, errmsg) != SQLITE_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
g_signal_connect (array, "remove-item",
|
||||||
|
G_CALLBACK (midori_bookmarks_remove_item_cb), db);
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,10 +183,6 @@ midori_bookmarks_insert_item_db (sqlite3* db,
|
||||||
KatzeItem* item,
|
KatzeItem* item,
|
||||||
gchar* folder);
|
gchar* folder);
|
||||||
|
|
||||||
void
|
|
||||||
midori_bookmarks_remove_item_from_db (sqlite3* db,
|
|
||||||
KatzeItem* item);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_bookmarkbar_populate (MidoriBrowser* browser);
|
midori_bookmarkbar_populate (MidoriBrowser* browser);
|
||||||
|
|
||||||
|
@ -927,7 +923,7 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
|
||||||
GtkTreeModel* model;
|
GtkTreeModel* model;
|
||||||
|
|
||||||
if (!new_bookmark)
|
if (!new_bookmark)
|
||||||
midori_bookmarks_remove_item_from_db (db, bookmark);
|
katze_array_remove_item (browser->bookmarks, bookmark);
|
||||||
|
|
||||||
katze_item_set_name (bookmark,
|
katze_item_set_name (bookmark,
|
||||||
gtk_entry_get_text (GTK_ENTRY (entry_title)));
|
gtk_entry_get_text (GTK_ENTRY (entry_title)));
|
||||||
|
@ -3862,14 +3858,10 @@ static void
|
||||||
midori_browser_bookmark_delete_activate_cb (GtkWidget* menuitem,
|
midori_browser_bookmark_delete_activate_cb (GtkWidget* menuitem,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
sqlite3* db;
|
|
||||||
KatzeItem* item;
|
KatzeItem* item;
|
||||||
|
|
||||||
db = g_object_get_data (G_OBJECT (browser->bookmarks), "db");
|
|
||||||
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
|
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
|
||||||
|
katze_array_remove_item (browser->bookmarks, item);
|
||||||
midori_bookmarks_remove_item_from_db (db, item);
|
|
||||||
g_object_unref (item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -6367,6 +6359,15 @@ midori_bookmarkbar_insert_item (GtkWidget* toolbar,
|
||||||
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
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
|
static void
|
||||||
midori_bookmarkbar_populate (MidoriBrowser* browser)
|
midori_bookmarkbar_populate (MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
|
@ -6456,6 +6457,9 @@ midori_browser_set_bookmarks (MidoriBrowser* browser,
|
||||||
{
|
{
|
||||||
MidoriWebSettings* settings;
|
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);
|
settings = midori_browser_get_settings (browser);
|
||||||
g_signal_handlers_disconnect_by_func (settings,
|
g_signal_handlers_disconnect_by_func (settings,
|
||||||
midori_browser_show_bookmarkbar_notify_value_cb, browser);
|
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_signal_connect (settings, "notify::show-bookmarkbar",
|
||||||
G_CALLBACK (midori_browser_show_bookmarkbar_notify_value_cb), browser);
|
G_CALLBACK (midori_browser_show_bookmarkbar_notify_value_cb), browser);
|
||||||
g_object_notify (G_OBJECT (settings), "show-bookmarkbar");
|
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
|
static void
|
||||||
|
|
|
@ -281,34 +281,15 @@ midori_bookmarks_insert_item_db (sqlite3* db,
|
||||||
sqlite3_free (sqlcmd);
|
sqlite3_free (sqlcmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
midori_bookmarks_remove_item_from_db (sqlite3* db,
|
midori_bookmarks_remove_item_cb (KatzeArray* array,
|
||||||
KatzeItem* item)
|
KatzeItem* item,
|
||||||
|
MidoriBookmarks* bookmarks)
|
||||||
{
|
{
|
||||||
gchar* sqlcmd;
|
GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
|
||||||
char* errmsg = NULL;
|
gtk_tree_store_clear (GTK_TREE_STORE (model));
|
||||||
|
midori_bookmarks_read_from_db_to_model (bookmarks,
|
||||||
if (KATZE_ITEM_IS_BOOKMARK (item))
|
GTK_TREE_STORE (model), NULL, NULL, bookmarks->filter);
|
||||||
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 void
|
static void
|
||||||
|
@ -342,7 +323,7 @@ midori_bookmarks_row_changed_cb (GtkTreeModel* model,
|
||||||
else
|
else
|
||||||
parent_name = g_strdup ("");
|
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);
|
midori_bookmarks_insert_item_db (db, item, parent_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,9 +368,7 @@ midori_bookmarks_delete_clicked_cb (GtkWidget* toolitem,
|
||||||
{
|
{
|
||||||
GtkTreeModel* model;
|
GtkTreeModel* model;
|
||||||
GtkTreeIter iter;
|
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),
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (bookmarks->treeview),
|
||||||
&model, &iter))
|
&model, &iter))
|
||||||
{
|
{
|
||||||
|
@ -397,9 +376,13 @@ midori_bookmarks_delete_clicked_cb (GtkWidget* toolitem,
|
||||||
|
|
||||||
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
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);
|
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_unref (item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,6 +475,8 @@ midori_bookmarks_set_app (MidoriBookmarks* bookmarks,
|
||||||
g_object_ref (app);
|
g_object_ref (app);
|
||||||
bookmarks->array = katze_object_get_object (app, "bookmarks");
|
bookmarks->array = katze_object_get_object (app, "bookmarks");
|
||||||
g_object_set_data (G_OBJECT (bookmarks->array), "treeview", bookmarks->treeview);
|
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);
|
midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), NULL, "", NULL);
|
||||||
g_signal_connect_after (model, "row-changed",
|
g_signal_connect_after (model, "row-changed",
|
||||||
|
|
|
@ -47,10 +47,6 @@ midori_bookmarks_insert_item_db (sqlite3* db,
|
||||||
KatzeItem* item,
|
KatzeItem* item,
|
||||||
const gchar* folder);
|
const gchar* folder);
|
||||||
|
|
||||||
void
|
|
||||||
midori_bookmarks_remove_item_from_db (sqlite3* db,
|
|
||||||
KatzeItem* item);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
midori_bookmarks_import_array_db (sqlite3* db,
|
midori_bookmarks_import_array_db (sqlite3* db,
|
||||||
KatzeArray* array,
|
KatzeArray* array,
|
||||||
|
|
Loading…
Reference in a new issue