]> spindle.queued.net Git - midori/commitdiff
Revamp bookmark import with sqlite
authorAlexander Butenko <a.butenka@gmail.com>
Fri, 2 Jul 2010 03:55:41 +0000 (23:55 -0400)
committerChristian Dywan <christian@twotoasts.de>
Fri, 2 Jul 2010 21:05:27 +0000 (23:05 +0200)
midori/main.c
midori/midori-browser.c
panels/midori-bookmarks.c
panels/midori-bookmarks.h

index 9c38e3b4a294598f2a9983e5b730d353637b7b10..f0e4d7810a920f7f3ded9d093746e4fe6995eeca 100644 (file)
@@ -469,7 +469,7 @@ midori_bookmarks_import (const gchar* filename,
         g_error_free (error);
         return;
     }
-    midori_bookmarks_import_array_db (bookmarks, db);
+    midori_bookmarks_import_array_db (db, bookmarks, "");
 }
 #endif
 
index 8113567b676a5eafef6cb364002e7b06258e92ba..d043310c707291353c7c90e189fd20c981066622 100644 (file)
@@ -171,6 +171,11 @@ midori_browser_get_property (GObject*    object,
                              GParamSpec* pspec);
 
 #if HAVE_SQLITE
+void
+midori_bookmarks_import_array_db (sqlite3*    db,
+                                  KatzeArray* array,
+                                  gchar*      folder);
+
 void
 midori_bookmarks_insert_item_db (sqlite3*   db,
                                  KatzeItem* item,
@@ -4122,6 +4127,9 @@ _action_bookmarks_import_activate (GtkAction*     action,
     gint icon_width = 16;
     guint i;
     KatzeItem* item;
+    sqlite3* db;
+    const gchar* sqlcmd;
+    KatzeArray* bookmarkdirs;
 
     if (!browser->bookmarks || !gtk_widget_get_visible (GTK_WIDGET (browser)))
         return;
@@ -4183,21 +4191,20 @@ _action_bookmarks_import_activate (GtkAction*     action,
     combobox_folder = GTK_COMBO_BOX (combo);
     gtk_combo_box_append_text (combobox_folder, _("Toplevel folder"));
     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;
-    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);
-            if (name)
-                gtk_combo_box_append_text (combobox_folder, name);
-        }
+        const gchar* name = katze_item_get_name (item);
+        gtk_combo_box_append_text (combobox_folder, name);
     }
     gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
     gtk_container_add (GTK_CONTAINER (content_area), hbox);
     gtk_widget_show_all (hbox);
-    /* FIXME: Importing into a subfolder doesn't work */
-    gtk_widget_set_sensitive (combo, FALSE);
+    gtk_widget_set_sensitive (combo, TRUE);
 
     gtk_dialog_set_default_response (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;
         gchar* path;
         gchar* selected;
-        KatzeArray* folder;
         GError* error;
 
         gtk_combo_box_get_active_iter (combobox, &iter);
         gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 2, &path, -1);
 
         selected = gtk_combo_box_get_active_text (combobox_folder);
-        folder = browser->bookmarks;
-        if (g_strcmp0 (selected, _("Toplevel folder")))
-        {
-            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);
+        if (g_str_equal (selected, _("Toplevel folder")))
+            selected = g_strdup ("");
 
         gtk_widget_destroy (dialog);
         if (!path)
@@ -4239,13 +4234,15 @@ _action_bookmarks_import_activate (GtkAction*     action,
         }
 
         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,
                 _("Failed to import bookmarks"), error ? error->message : "");
             if (error)
                 g_error_free (error);
         }
+        midori_bookmarks_import_array_db (db, browser->bookmarks, selected);
+        g_free (selected);
         g_free (path);
     }
     else
index 3bd2ef4d63ea17d86fe98c78ab32c0c315cda58f..4d8985d4927098e799b39365143c3b52a79a9aeb 100644 (file)
@@ -118,8 +118,9 @@ midori_bookmarks_get_stock_id (MidoriViewable* viewable)
 
 #if HAVE_SQLITE
 void
-midori_bookmarks_import_array_db (KatzeArray* array,
-                                  sqlite3*    db)
+midori_bookmarks_import_array_db (sqlite3*     db,
+                                  KatzeArray*  array,
+                                  const gchar* folder)
 {
     GList* list = NULL;
     GList* bookmarks;
@@ -130,9 +131,9 @@ midori_bookmarks_import_array_db (KatzeArray* array,
         KatzeItem* item;
 
         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;
-        midori_bookmarks_insert_item_db (db, item, NULL);
+        midori_bookmarks_insert_item_db (db, item, folder);
     }
 }
 
@@ -171,9 +172,9 @@ midori_bookmarks_read_from_db_to_model (MidoriBookmarks* bookmarks,
 }
 
 void
-midori_bookmarks_insert_item_db (sqlite3*   db,
-                                 KatzeItem* item,
-                                 gchar*     folder)
+midori_bookmarks_insert_item_db (sqlite3*     db,
+                                 KatzeItem*   item,
+                                 const gchar* folder)
 {
     gchar* sqlcmd;
     char* errmsg = NULL;
index f5e33a7dbede490b2986ac4e60990cbbb422ff3e..0a20a8806e43b44079b1e63e71d67dfb4cf1c01a 100644 (file)
@@ -47,17 +47,18 @@ midori_bookmarks_new                    (void);
 
 #if HAVE_SQLITE
 void
-midori_bookmarks_insert_item_db (sqlite3*   db,
-                                 KatzeItem* item,
-                                 gchar*     folder);
+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 (KatzeArray* array,
-                                  sqlite3*    db);
+midori_bookmarks_import_array_db (sqlite3*       db,
+                                  KatzeArray*    array,
+                                  const gchar*   folder);
 #endif
 
 G_END_DECLS