[Xfce4-commits] <midori:master> Fix edit/ delete/ new operations on bookmarks

Christian Dywan noreply at xfce.org
Thu Jun 17 00:14:07 CEST 2010


Updating branch refs/heads/master
         to 5af37f6c92d5f07ac3968618289c86b918d4bb2e (commit)
       from 6f415c4e6e9154285c760fd06b419ab6ff42c0b9 (commit)

commit 5af37f6c92d5f07ac3968618289c86b918d4bb2e
Author: Alexander Butenko <a.butenka at gmail.com>
Date:   Sun Jun 13 16:33:23 2010 -0400

    Fix edit/ delete/ new operations on bookmarks

 midori/midori-browser.c   |   43 ++++++++++++++++++++++++-------------------
 panels/midori-bookmarks.c |   41 +++++++++++++++++++++++------------------
 panels/midori-bookmarks.h |    8 +++++++-
 3 files changed, 54 insertions(+), 38 deletions(-)

diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 49ed534..67f6ee5 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -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);
 }
diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c
index 2a53ad7..b98b4ed 100644
--- a/panels/midori-bookmarks.c
+++ b/panels/midori-bookmarks.c
@@ -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 */
 }
diff --git a/panels/midori-bookmarks.h b/panels/midori-bookmarks.h
index 8beff86..f5e33a7 100644
--- a/panels/midori-bookmarks.h
+++ b/panels/midori-bookmarks.h
@@ -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);



More information about the Xfce4-commits mailing list