Revamp bookmark import with sqlite

This commit is contained in:
Alexander Butenko 2010-07-01 23:55:41 -04:00 committed by Christian Dywan
parent e1fbfb6bde
commit 8c6a8abe5f
4 changed files with 36 additions and 37 deletions

View file

@ -469,7 +469,7 @@ midori_bookmarks_import (const gchar* filename,
g_error_free (error); g_error_free (error);
return; return;
} }
midori_bookmarks_import_array_db (bookmarks, db); midori_bookmarks_import_array_db (db, bookmarks, "");
} }
#endif #endif

View file

@ -171,6 +171,11 @@ midori_browser_get_property (GObject* object,
GParamSpec* pspec); GParamSpec* pspec);
#if HAVE_SQLITE #if HAVE_SQLITE
void
midori_bookmarks_import_array_db (sqlite3* db,
KatzeArray* array,
gchar* folder);
void void
midori_bookmarks_insert_item_db (sqlite3* db, midori_bookmarks_insert_item_db (sqlite3* db,
KatzeItem* item, KatzeItem* item,
@ -4122,6 +4127,9 @@ _action_bookmarks_import_activate (GtkAction* action,
gint icon_width = 16; gint icon_width = 16;
guint i; guint i;
KatzeItem* item; KatzeItem* item;
sqlite3* db;
const gchar* sqlcmd;
KatzeArray* bookmarkdirs;
if (!browser->bookmarks || !gtk_widget_get_visible (GTK_WIDGET (browser))) if (!browser->bookmarks || !gtk_widget_get_visible (GTK_WIDGET (browser)))
return; return;
@ -4183,21 +4191,20 @@ _action_bookmarks_import_activate (GtkAction* action,
combobox_folder = GTK_COMBO_BOX (combo); combobox_folder = GTK_COMBO_BOX (combo);
gtk_combo_box_append_text (combobox_folder, _("Toplevel folder")); gtk_combo_box_append_text (combobox_folder, _("Toplevel folder"));
gtk_combo_box_set_active (combobox_folder, 0); gtk_combo_box_set_active (combobox_folder, 0);
db = g_object_get_data (G_OBJECT (browser->bookmarks), "db");
sqlcmd = "SELECT title from bookmarks where uri=''";
bookmarkdirs = katze_array_from_sqlite (db, sqlcmd);
i = 0; i = 0;
while ((item = katze_array_get_nth_item (browser->bookmarks, i++))) while ((item = katze_array_get_nth_item (bookmarkdirs, i++)))
{
if (KATZE_IS_ARRAY (item))
{ {
const gchar* name = katze_item_get_name (item); const gchar* name = katze_item_get_name (item);
if (name)
gtk_combo_box_append_text (combobox_folder, name); gtk_combo_box_append_text (combobox_folder, name);
} }
}
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (content_area), hbox); gtk_container_add (GTK_CONTAINER (content_area), hbox);
gtk_widget_show_all (hbox); gtk_widget_show_all (hbox);
/* FIXME: Importing into a subfolder doesn't work */ gtk_widget_set_sensitive (combo, TRUE);
gtk_widget_set_sensitive (combo, FALSE);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
@ -4205,26 +4212,14 @@ _action_bookmarks_import_activate (GtkAction* action,
GtkTreeIter iter; GtkTreeIter iter;
gchar* path; gchar* path;
gchar* selected; gchar* selected;
KatzeArray* folder;
GError* error; GError* error;
gtk_combo_box_get_active_iter (combobox, &iter); gtk_combo_box_get_active_iter (combobox, &iter);
gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 2, &path, -1); gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 2, &path, -1);
selected = gtk_combo_box_get_active_text (combobox_folder); selected = gtk_combo_box_get_active_text (combobox_folder);
folder = browser->bookmarks; if (g_str_equal (selected, _("Toplevel folder")))
if (g_strcmp0 (selected, _("Toplevel folder"))) selected = g_strdup ("");
{
i = 0;
while ((item = katze_array_get_nth_item (browser->bookmarks, i++)))
if (KATZE_IS_ARRAY (item))
if (!g_strcmp0 (katze_item_get_name (item), selected))
{
folder = KATZE_ARRAY (item);
break;
}
}
g_free (selected);
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
if (!path) if (!path)
@ -4239,13 +4234,15 @@ _action_bookmarks_import_activate (GtkAction* action,
} }
error = NULL; error = NULL;
if (path && !midori_array_from_file (folder, path, NULL, &error)) if (path && !midori_array_from_file (browser->bookmarks, path, NULL, &error))
{ {
sokoke_message_dialog (GTK_MESSAGE_ERROR, sokoke_message_dialog (GTK_MESSAGE_ERROR,
_("Failed to import bookmarks"), error ? error->message : ""); _("Failed to import bookmarks"), error ? error->message : "");
if (error) if (error)
g_error_free (error); g_error_free (error);
} }
midori_bookmarks_import_array_db (db, browser->bookmarks, selected);
g_free (selected);
g_free (path); g_free (path);
} }
else else

View file

@ -118,8 +118,9 @@ midori_bookmarks_get_stock_id (MidoriViewable* viewable)
#if HAVE_SQLITE #if HAVE_SQLITE
void void
midori_bookmarks_import_array_db (KatzeArray* array, midori_bookmarks_import_array_db (sqlite3* db,
sqlite3* db) KatzeArray* array,
const gchar* folder)
{ {
GList* list = NULL; GList* list = NULL;
GList* bookmarks; GList* bookmarks;
@ -130,9 +131,9 @@ midori_bookmarks_import_array_db (KatzeArray* array,
KatzeItem* item; KatzeItem* item;
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 (db, list->data, folder);
item = (KatzeItem*) list->data; item = (KatzeItem*) list->data;
midori_bookmarks_insert_item_db (db, item, NULL); midori_bookmarks_insert_item_db (db, item, folder);
} }
} }
@ -173,7 +174,7 @@ midori_bookmarks_read_from_db_to_model (MidoriBookmarks* bookmarks,
void void
midori_bookmarks_insert_item_db (sqlite3* db, midori_bookmarks_insert_item_db (sqlite3* db,
KatzeItem* item, KatzeItem* item,
gchar* folder) const gchar* folder)
{ {
gchar* sqlcmd; gchar* sqlcmd;
char* errmsg = NULL; char* errmsg = NULL;

View file

@ -49,15 +49,16 @@ midori_bookmarks_new (void);
void void
midori_bookmarks_insert_item_db (sqlite3* db, midori_bookmarks_insert_item_db (sqlite3* db,
KatzeItem* item, KatzeItem* item,
gchar* folder); const gchar* folder);
void void
midori_bookmarks_remove_item_from_db (sqlite3* db, midori_bookmarks_remove_item_from_db (sqlite3* db,
KatzeItem* item); KatzeItem* item);
void void
midori_bookmarks_import_array_db (KatzeArray* array, midori_bookmarks_import_array_db (sqlite3* db,
sqlite3* db); KatzeArray* array,
const gchar* folder);
#endif #endif
G_END_DECLS G_END_DECLS