[Xfce4-commits] <midori:master> Add bookmarks through array and update the panel

Christian Dywan noreply at xfce.org
Mon Nov 22 03:50:03 CET 2010


Updating branch refs/heads/master
         to 8ad224c9a8f7240cd2d0e003d70c43b783369761 (commit)
       from 93c483c9043193a2ff71018fbe1b23c3e254f268 (commit)

commit 8ad224c9a8f7240cd2d0e003d70c43b783369761
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Nov 21 16:49:20 2010 +0100

    Add bookmarks through array and update the panel

 midori/main.c             |   47 +++++++++++++++++++++++++++++++++
 midori/midori-browser.c   |   25 +++--------------
 panels/midori-bookmarks.c |   64 +++++++++++++-------------------------------
 3 files changed, 70 insertions(+), 66 deletions(-)

diff --git a/midori/main.c b/midori/main.c
index 430e52e..63be105 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -490,6 +490,51 @@ midori_history_terminate (KatzeArray* array,
 }
 
 static void
+midori_bookmarks_add_item_cb (KatzeArray* array,
+                              KatzeItem*  item,
+                              sqlite3*    db)
+{
+    gchar* sqlcmd;
+    char* errmsg = NULL;
+    KatzeItem* old_parent;
+    const gchar* uri;
+    const gchar* folder = katze_item_get_meta_string (item, "folder");
+    const gchar* parent;
+
+    if (KATZE_ITEM_IS_BOOKMARK (item))
+        uri = katze_item_get_uri (item);
+    else
+        uri = "";
+
+    /* Use folder, otherwise fallback to parent folder */
+    old_parent = katze_item_get_parent (item);
+    if (folder && *folder)
+        parent = folder;
+    else if (old_parent && katze_item_get_name (old_parent))
+        parent = katze_item_get_name (old_parent);
+    else
+        parent = "";
+
+    sqlcmd = sqlite3_mprintf (
+            "INSERT into bookmarks (uri, title, desc, folder, toolbar, app) values"
+            " ('%q', '%q', '%q', '%q', %d, %d)",
+            uri,
+            katze_item_get_name (item),
+            katze_item_get_text (item),
+            parent,
+            katze_item_get_meta_boolean (item, "toolbar"),
+            katze_item_get_meta_boolean (item, "app"));
+
+    if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
+    {
+        g_printerr (_("Failed to add bookmark item: %s\n"), errmsg);
+        sqlite3_free (errmsg);
+    }
+
+    sqlite3_free (sqlcmd);
+}
+
+static void
 midori_bookmarks_remove_item_cb (KatzeArray* array,
                                  KatzeItem*  item,
                                  sqlite3*    db)
@@ -542,6 +587,8 @@ midori_bookmarks_initialize (KatzeArray*  array,
                       "desc text, app integer, toolbar integer);",
                       NULL, NULL, errmsg) != SQLITE_OK)
         return NULL;
+    g_signal_connect (array, "add-item",
+                      G_CALLBACK (midori_bookmarks_add_item_cb), db);
     g_signal_connect (array, "remove-item",
                       G_CALLBACK (midori_bookmarks_remove_item_cb), db);
     return db;
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 85c841f..d456032 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -179,11 +179,6 @@ midori_bookmarks_export_array_db (sqlite3*     db,
                                   const gchar* folder);
 
 void
-midori_bookmarks_insert_item_db (sqlite3*   db,
-                                 KatzeItem* item,
-                                 gchar*     folder);
-
-void
 midori_browser_open_bookmark (MidoriBrowser* browser,
                               KatzeItem*     item);
 
@@ -909,8 +904,6 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
     if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
     {
         gchar* selected;
-        GtkTreeView* treeview;
-        GtkTreeModel* model;
 
         if (!new_bookmark)
             katze_array_remove_item (browser->bookmarks, bookmark);
@@ -930,23 +923,13 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
         }
 
         selected = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_folder));
-
         if (!strcmp (selected, _("Toplevel folder")))
-            selected = g_strdup ("");
-
-        midori_bookmarks_insert_item_db (db, bookmark, selected);
-
-        if (new_bookmark)
-        {
-            treeview = g_object_get_data (G_OBJECT (browser->bookmarks), "treeview");
-            model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
-            gtk_tree_store_insert_with_values (GTK_TREE_STORE (model),
-                NULL, NULL, G_MAXINT, 0, bookmark, -1);
-        }
+            katze_assign (selected, g_strdup (""));
+        katze_item_set_meta_string (bookmark, "folder", selected);
+        katze_array_add_item (browser->bookmarks, bookmark);
 
         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_toolbar)))
-            if (!gtk_widget_get_visible (browser->bookmarkbar)
-             && browser->bookmarks != NULL)
+            if (!gtk_widget_get_visible (browser->bookmarkbar))
                 _action_set_active (browser, "Bookmarkbar", TRUE);
         g_free (selected);
         return_status = TRUE;
diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c
index 4933f46..07a312d 100644
--- a/panels/midori-bookmarks.c
+++ b/panels/midori-bookmarks.c
@@ -161,7 +161,8 @@ midori_bookmarks_import_array_db (sqlite3*     db,
     {
         if (KATZE_IS_ARRAY (item))
             midori_bookmarks_import_array_db (db, KATZE_ARRAY (item), folder);
-        midori_bookmarks_insert_item_db (db, item, folder);
+        katze_item_set_meta_string (item, "folder", folder);
+        katze_array_add_item (array, item);
     }
 }
 
@@ -229,50 +230,22 @@ midori_bookmarks_read_from_db_to_model (MidoriBookmarks* bookmarks,
         g_object_unref (item);
 }
 
-void
-midori_bookmarks_insert_item_db (sqlite3*     db,
-                                 KatzeItem*   item,
-                                 const gchar* folder)
+static void
+midori_bookmarks_add_item_cb (KatzeArray*      array,
+                              KatzeItem*       item,
+                              MidoriBookmarks* bookmarks)
 {
-    gchar* sqlcmd;
-    char* errmsg = NULL;
-    KatzeItem* old_parent;
-    gchar* parent;
-    gchar* uri;
-
-    if (KATZE_ITEM_IS_BOOKMARK (item))
-        uri = g_strdup (katze_item_get_uri (item));
-    else
-        uri = g_strdup ("");
-
-    /* Use folder, otherwise fallback to parent folder */
-    old_parent = katze_item_get_parent (item);
-    if (folder && *folder)
-        parent = g_strdup (folder);
-    else if (old_parent && katze_item_get_name (old_parent))
-        parent = g_strdup (katze_item_get_name (old_parent));
+    GtkTreeModel* model;
+    model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
+    if (!strcmp (katze_item_get_meta_string (item, "folder"), ""))
+        gtk_tree_store_insert_with_values (GTK_TREE_STORE (model),
+                                           NULL, NULL, G_MAXINT, 0, item, -1);
     else
-        parent = g_strdup ("");
-
-    sqlcmd = sqlite3_mprintf (
-            "INSERT into bookmarks (uri, title, desc, folder, toolbar, app) values"
-            " ('%q', '%q', '%q', '%q', %d, %d)",
-            uri,
-            katze_item_get_name (item),
-            katze_item_get_text (item),
-            parent,
-            katze_item_get_meta_boolean (item, "toolbar"),
-            katze_item_get_meta_boolean (item, "app"));
-
-    if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
     {
-        g_printerr (_("Failed to add bookmark item: %s\n"), errmsg);
-        sqlite3_free (errmsg);
+        gtk_tree_store_clear (GTK_TREE_STORE (model));
+        midori_bookmarks_read_from_db_to_model (bookmarks,
+            GTK_TREE_STORE (model), NULL, NULL, bookmarks->filter);
     }
-
-    g_free (uri);
-    g_free (parent);
-    sqlite3_free (sqlcmd);
 }
 
 static void
@@ -318,7 +291,8 @@ midori_bookmarks_row_changed_cb (GtkTreeModel*    model,
         parent_name = g_strdup ("");
 
     katze_array_remove_item (bookmarks->array, item);
-    midori_bookmarks_insert_item_db (db, item, parent_name);
+    katze_item_set_meta_string (item, "folder", parent_name);
+    katze_array_add_item (bookmarks->array, item);
 }
 
 static void
@@ -468,11 +442,11 @@ midori_bookmarks_set_app (MidoriBookmarks* bookmarks,
 
     g_object_ref (app);
     bookmarks->array = katze_object_get_object (app, "bookmarks");
-    g_object_set_data (G_OBJECT (bookmarks->array), "treeview", bookmarks->treeview);
+    midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), NULL, "", NULL);
+    g_signal_connect (bookmarks->array, "add-item",
+                      G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
     g_signal_connect (bookmarks->array, "remove-item",
                       G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks);
-
-    midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), NULL, "", NULL);
     g_signal_connect_after (model, "row-changed",
                             G_CALLBACK (midori_bookmarks_row_changed_cb),
                             bookmarks);



More information about the Xfce4-commits mailing list