Fix edit/ delete/ new operations on bookmarks

This commit is contained in:
Alexander Butenko 2010-06-13 16:33:23 -04:00 committed by Christian Dywan
parent 6f415c4e6e
commit 5af37f6c92
3 changed files with 54 additions and 38 deletions

View file

@ -175,6 +175,17 @@ midori_browser_get_property (GObject* object,
GValue* value, GValue* value,
GParamSpec* pspec); GParamSpec* pspec);
#if HAVE_SQLITE
void
midori_bookmarks_insert_item_db (sqlite3* db,
KatzeItem* item,
gchar* folder);
void
midori_bookmarks_remove_item_from_db (sqlite3* db,
KatzeItem* item);
#endif
static void static void
midori_browser_new_history_item (MidoriBrowser* browser, midori_browser_new_history_item (MidoriBrowser* browser,
KatzeItem** item); KatzeItem** item);
@ -891,6 +902,11 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
{ {
gchar* selected; gchar* selected;
KatzeArray* folder; KatzeArray* folder;
#if HAVE_SQLITE
sqlite3* db;
db = g_object_get_data (G_OBJECT (browser->bookmarks), "db");
#endif
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)));
@ -914,26 +930,15 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
folder = browser->bookmarks; folder = browser->bookmarks;
selected = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_folder)); selected = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_folder));
if (strcmp (selected, _("Toplevel folder")))
{ #if HAVE_SQLITE
guint i = 0; midori_bookmarks_remove_item_from_db (db, bookmark);
KatzeItem* item; if (!strcmp (selected, _("Toplevel folder")))
while ((item = katze_array_get_nth_item (browser->bookmarks, i++))) midori_bookmarks_insert_item_db (db, bookmark, "");
if (KATZE_IS_ARRAY (item)) else
if (!g_strcmp0 (katze_item_get_name (item), selected)) midori_bookmarks_insert_item_db (db, bookmark, selected);
{ #endif
folder = KATZE_ARRAY (item);
break;
}
}
g_free (selected); g_free (selected);
if (folder != katze_item_get_parent (bookmark) && folder != browser->bookmarks)
{
katze_array_remove_item (katze_item_get_parent (bookmark), bookmark);
new_bookmark = TRUE;
}
if (new_bookmark)
katze_array_add_item (folder, bookmark);
} }
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }

View file

@ -131,7 +131,7 @@ midori_bookmarks_import_array_db (KatzeArray* array,
if (KATZE_IS_ARRAY (list->data)) if (KATZE_IS_ARRAY (list->data))
midori_bookmarks_import_array_db (list->data, db); midori_bookmarks_import_array_db (list->data, db);
item = (KatzeItem*) list->data; item = (KatzeItem*) list->data;
midori_bookmarks_insert_item_db (db, item); midori_bookmarks_insert_item_db (db, item, NULL);
} }
} }
@ -203,7 +203,8 @@ midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks,
void void
midori_bookmarks_insert_item_db (sqlite3* db, midori_bookmarks_insert_item_db (sqlite3* db,
KatzeItem* item) KatzeItem* item,
gchar* folder)
{ {
gchar* sqlcmd; gchar* sqlcmd;
char* errmsg = NULL; char* errmsg = NULL;
@ -215,7 +216,9 @@ midori_bookmarks_insert_item_db (sqlite3* db,
else else
type = 0; type = 0;
if (katze_item_get_name (katze_item_get_parent (item))) if (folder)
parent = g_strdup (folder);
else if (katze_item_get_name (katze_item_get_parent (item)))
parent = g_strdup (katze_item_get_name (katze_item_get_parent (item))); parent = g_strdup (katze_item_get_name (katze_item_get_parent (item)));
else else
parent = g_strdup (""); parent = g_strdup ("");
@ -238,22 +241,17 @@ midori_bookmarks_insert_item_db (sqlite3* db,
sqlite3_free (sqlcmd); sqlite3_free (sqlcmd);
} }
static void void
midori_bookmarks_remove_item_from_db (MidoriBookmarks* bookmarks, midori_bookmarks_remove_item_from_db (sqlite3* db,
KatzeItem* item) KatzeItem* item)
{ {
gchar* sqlcmd; gchar* sqlcmd;
sqlite3* db;
char* errmsg = NULL; char* errmsg = NULL;
db = g_object_get_data (G_OBJECT (bookmarks->array), "db");
if (katze_item_get_uri (item)) if (katze_item_get_uri (item))
sqlcmd = sqlite3_mprintf ( sqlcmd = sqlite3_mprintf (
"DELETE FROM bookmarks WHERE uri = '%q' AND" "DELETE FROM bookmarks WHERE uri = '%q'",
" title = '%q'", katze_item_get_uri (item));
katze_item_get_uri (item),
katze_item_get_name (item));
else else
sqlcmd = sqlite3_mprintf ( sqlcmd = sqlite3_mprintf (
"DELETE FROM bookmarks WHERE folder = '%q'", katze_item_get_name (item)); "DELETE FROM bookmarks WHERE folder = '%q'", katze_item_get_name (item));
@ -264,7 +262,6 @@ midori_bookmarks_remove_item_from_db (MidoriBookmarks* bookmarks,
sqlite3_free (errmsg); sqlite3_free (errmsg);
} }
g_debug ("%s", sqlcmd);
sqlite3_free (sqlcmd); sqlite3_free (sqlcmd);
} }
#endif #endif
@ -292,13 +289,12 @@ midori_bookmarks_edit_clicked_cb (GtkWidget* toolitem,
gtk_tree_model_get (model, &iter, 0, &item, -1); gtk_tree_model_get (model, &iter, 0, &item, -1);
is_separator = !KATZE_IS_ARRAY (item) && !katze_item_get_uri (item); is_separator = item && !katze_item_get_uri (item);
if (!is_separator) if (!is_separator)
{ {
MidoriBrowser* browser = midori_browser_get_for_widget (toolitem); MidoriBrowser* browser = midori_browser_get_for_widget (toolitem);
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE); midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
} }
g_object_unref (item); g_object_unref (item);
} }
} }
@ -309,6 +305,11 @@ midori_bookmarks_delete_clicked_cb (GtkWidget* toolitem,
{ {
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
#if HAVE_SQLITE
sqlite3* db;
db = g_object_get_data (G_OBJECT (bookmarks->array), "db");
#endif
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))
@ -318,7 +319,7 @@ 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);
#if HAVE_SQLITE #if HAVE_SQLITE
midori_bookmarks_remove_item_from_db (bookmarks, item); midori_bookmarks_remove_item_from_db (db, item);
#endif #endif
gtk_tree_store_remove (GTK_TREE_STORE (model), &iter); gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
@ -705,10 +706,14 @@ midori_bookmarks_delete_activate_cb (GtkWidget* menuitem,
MidoriBookmarks* bookmarks) MidoriBookmarks* bookmarks)
{ {
KatzeItem* item; KatzeItem* item;
#if HAVE_SQLITE
sqlite3* db;
#endif
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
#if HAVE_SQLITE #if HAVE_SQLITE
midori_bookmarks_remove_item_from_db (bookmarks, item); db = g_object_get_data (G_OBJECT (bookmarks->array), "db");
midori_bookmarks_remove_item_from_db (db, item);
#endif #endif
/* FIXME: Refresh menu */ /* FIXME: Refresh menu */
} }

View file

@ -48,7 +48,13 @@ midori_bookmarks_new (void);
#if HAVE_SQLITE #if HAVE_SQLITE
void void
midori_bookmarks_insert_item_db (sqlite3* db, midori_bookmarks_insert_item_db (sqlite3* db,
KatzeItem* item); KatzeItem* item,
gchar* folder);
void
midori_bookmarks_remove_item_from_db (sqlite3* db,
KatzeItem* item);
void void
midori_bookmarks_import_array_db (KatzeArray* array, midori_bookmarks_import_array_db (KatzeArray* array,
sqlite3* db); sqlite3* db);