]> spindle.queued.net Git - midori/commitdiff
Fix edit/ delete/ new operations on bookmarks
authorAlexander Butenko <a.butenka@gmail.com>
Sun, 13 Jun 2010 20:33:23 +0000 (16:33 -0400)
committerChristian Dywan <christian@twotoasts.de>
Wed, 16 Jun 2010 21:27:59 +0000 (23:27 +0200)
midori/midori-browser.c
panels/midori-bookmarks.c
panels/midori-bookmarks.h

index 49ed5348c2ec928c19e3af3f733943e15e28d610..67f6ee53a1e3da88d1147eac1879d3029c9895b9 100644 (file)
@@ -175,6 +175,17 @@ midori_browser_get_property (GObject*    object,
                              GValue*     value,
                              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
 midori_browser_new_history_item (MidoriBrowser* browser,
                                  KatzeItem**    item);
@@ -891,6 +902,11 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
     {
         gchar* selected;
         KatzeArray* folder;
+        #if HAVE_SQLITE
+        sqlite3* db;
+
+        db = g_object_get_data (G_OBJECT (browser->bookmarks), "db");
+        #endif
 
         katze_item_set_name (bookmark,
             gtk_entry_get_text (GTK_ENTRY (entry_title)));
@@ -914,26 +930,15 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
 
         folder = browser->bookmarks;
         selected = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_folder));
-        if (strcmp (selected, _("Toplevel folder")))
-        {
-            guint i = 0;
-            KatzeItem* item;
-            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;
-                    }
-        }
+
+        #if HAVE_SQLITE
+        midori_bookmarks_remove_item_from_db (db, bookmark);
+        if (!strcmp (selected, _("Toplevel folder")))
+            midori_bookmarks_insert_item_db (db, bookmark, "");
+        else
+            midori_bookmarks_insert_item_db (db, bookmark, selected);
+        #endif
         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);
 }
index 2a53ad75e221b34fbe3e50178ec4dcc06ad169f5..b98b4ed99bfb4f21d62e221ece783fe0c1cce9df 100644 (file)
@@ -131,7 +131,7 @@ midori_bookmarks_import_array_db (KatzeArray* array,
         if (KATZE_IS_ARRAY (list->data))
             midori_bookmarks_import_array_db (list->data, db);
         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
 midori_bookmarks_insert_item_db (sqlite3*   db,
-                                 KatzeItem* item)
+                                 KatzeItem* item,
+                                 gchar*     folder)
 {
     gchar* sqlcmd;
     char* errmsg = NULL;
@@ -215,7 +216,9 @@ midori_bookmarks_insert_item_db (sqlite3*   db,
     else
         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)));
     else
         parent = g_strdup ("");
@@ -238,22 +241,17 @@ midori_bookmarks_insert_item_db (sqlite3*   db,
     sqlite3_free (sqlcmd);
 }
 
-static void
-midori_bookmarks_remove_item_from_db (MidoriBookmarks* bookmarks,
-                                      KatzeItem*       item)
+void
+midori_bookmarks_remove_item_from_db (sqlite3*   db,
+                                      KatzeItem* item)
 {
     gchar* sqlcmd;
-    sqlite3* db;
     char* errmsg = NULL;
 
-    db = g_object_get_data (G_OBJECT (bookmarks->array), "db");
-
     if (katze_item_get_uri (item))
         sqlcmd = sqlite3_mprintf (
-            "DELETE FROM bookmarks WHERE uri = '%q' AND"
-            " title = '%q'",
-            katze_item_get_uri (item),
-            katze_item_get_name (item));
+            "DELETE FROM bookmarks WHERE uri = '%q'",
+            katze_item_get_uri (item));
     else
        sqlcmd = sqlite3_mprintf (
             "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);
     }
 
-    g_debug ("%s", sqlcmd);
     sqlite3_free (sqlcmd);
 }
 #endif
@@ -292,13 +289,12 @@ midori_bookmarks_edit_clicked_cb (GtkWidget*       toolitem,
 
         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)
         {
             MidoriBrowser* browser = midori_browser_get_for_widget (toolitem);
             midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
         }
-
         g_object_unref (item);
     }
 }
@@ -309,6 +305,11 @@ midori_bookmarks_delete_clicked_cb (GtkWidget*       toolitem,
 {
     GtkTreeModel* model;
     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),
                                            &model, &iter))
@@ -318,7 +319,7 @@ midori_bookmarks_delete_clicked_cb (GtkWidget*       toolitem,
         gtk_tree_model_get (model, &iter, 0, &item, -1);
 
         #if HAVE_SQLITE
-        midori_bookmarks_remove_item_from_db (bookmarks, item);
+        midori_bookmarks_remove_item_from_db (db, item);
         #endif
         gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
 
@@ -705,10 +706,14 @@ midori_bookmarks_delete_activate_cb (GtkWidget*       menuitem,
                                      MidoriBookmarks* bookmarks)
 {
     KatzeItem* item;
+    #if HAVE_SQLITE
+    sqlite3* db;
+    #endif
 
     item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
     #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
     /* FIXME: Refresh menu */
 }
index 8beff86ca0f0f9ea04993770f54f41e2c6d55630..f5e33a7dbede490b2986ac4e60990cbbb422ff3e 100644 (file)
@@ -48,7 +48,13 @@ midori_bookmarks_new                    (void);
 #if HAVE_SQLITE
 void
 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
 midori_bookmarks_import_array_db (KatzeArray* array,
                                   sqlite3*    db);