From 535053a3e6bb85807e696ed1692543b80de40eba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Forysiuk?= Date: Tue, 18 Jan 2011 17:49:57 +0100 Subject: [PATCH] Separate bookmark insertion from array callback --- midori/main.c | 40 ++------------------------------ panels/midori-bookmarks.c | 49 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/midori/main.c b/midori/main.c index 32420b0c..31276b01 100644 --- a/midori/main.c +++ b/midori/main.c @@ -494,44 +494,8 @@ 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); + midori_bookmarks_insert_item_db (db, item, + katze_item_get_meta_string (item, "folder")); } static void diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c index 66891406..f059a7cd 100644 --- a/panels/midori-bookmarks.c +++ b/panels/midori-bookmarks.c @@ -162,8 +162,7 @@ midori_bookmarks_import_array_db (sqlite3* db, { if (KATZE_IS_ARRAY (item)) midori_bookmarks_import_array_db (db, KATZE_ARRAY (item), folder); - katze_item_set_meta_string (item, "folder", folder); - katze_array_add_item (array, item); + midori_bookmarks_insert_item_db (db, item, folder); } g_list_free (list); } @@ -232,6 +231,52 @@ 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) +{ + 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)); + 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); + } + + g_free (uri); + g_free (parent); + sqlite3_free (sqlcmd); +} + static void midori_bookmarks_add_item_cb (KatzeArray* array, KatzeItem* item, -- 2.39.5