From 3c4896f94fb507afc00ac83bb54656293a0a8904 Mon Sep 17 00:00:00 2001 From: Alexander Butenko Date: Thu, 1 Jul 2010 15:21:01 -0400 Subject: [PATCH] Start using new sqlite helper functions --- midori/midori-browser.c | 63 +++++++++++---------------------------- panels/midori-bookmarks.c | 39 ++---------------------- 2 files changed, 20 insertions(+), 82 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index a50e413a..5bbba4e9 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -2728,39 +2728,27 @@ _action_history_populate_popup (GtkAction* action, GtkMenu* menu, MidoriBrowser* browser) { - #if HAVE_SQLITE sqlite3* db; - sqlite3_stmt* statement; - gint result; const gchar* sqlcmd; + KatzeArray* array; + KatzeItem* item; + gint i = 0; db = g_object_get_data (G_OBJECT (browser->history), "db"); sqlcmd = "SELECT uri, title, date FROM history " "GROUP BY uri ORDER BY date ASC LIMIT 10"; - result = sqlite3_prepare_v2 (db, sqlcmd, -1, &statement, NULL); - if (result != SQLITE_OK) - { - g_print (_("Failed to execute database statement: %s\n"), - sqlite3_errmsg (db)); - return; - } + array = katze_array_from_sqlite (db, sqlcmd); - while ((result = sqlite3_step (statement)) == SQLITE_ROW) + while ((item = katze_array_get_nth_item (KATZE_ARRAY (array), i))) { - const unsigned char* uri; - const unsigned char* title; - KatzeItem* item; GtkWidget* menuitem; GdkPixbuf* icon; GtkWidget* image; + const gchar* uri; + const gchar* title; - uri = sqlite3_column_text (statement, 0); - title = sqlite3_column_text (statement, 1); - - item = katze_item_new (); - katze_item_set_uri (item, (gchar*)uri); - katze_item_set_name (item, (gchar*)title); - + uri = katze_item_get_uri (item); + title = katze_item_get_name (item); menuitem = katze_image_menu_item_new_ellipsized ((gchar*)title); icon = katze_load_cached_icon ((gchar*)uri, GTK_WIDGET (browser)); image = gtk_image_new_from_pixbuf (icon); @@ -2783,9 +2771,8 @@ _action_history_populate_popup (GtkAction* action, G_CALLBACK (midori_browser_menu_item_select_cb), browser); g_signal_connect (menuitem, "deselect", G_CALLBACK (midori_browser_menu_item_deselect_cb), browser); + i++; } - sqlite3_finalize (statement); - #endif } static void @@ -6515,9 +6502,10 @@ midori_bookmarkbar_populate (MidoriBrowser* browser) { GtkWidget* homepage; sqlite3* db; - gint result; const gchar* sqlcmd; - sqlite3_stmt* statement; + KatzeArray* array; + KatzeItem* item; + gint i; homepage = gtk_action_create_tool_item (_action_by_name (browser, "Homepage")); gtk_tool_item_set_is_important (GTK_TOOL_ITEM (homepage), TRUE); @@ -6532,34 +6520,19 @@ midori_bookmarkbar_populate (MidoriBrowser* browser) sqlcmd = "SELECT uri, title, app FROM bookmarks WHERE " " toolbar = 1 ORDER BY type ASC"; - result = sqlite3_prepare_v2 (db, sqlcmd, -1, &statement, NULL); - if (result != SQLITE_OK) + + array = katze_array_from_sqlite (db, sqlcmd); + if (!array) { _action_set_sensitive (browser, "BookmarkAdd", FALSE); _action_set_sensitive (browser, "BookmarkFolderAdd", FALSE); return; } - while ((result = sqlite3_step (statement)) == SQLITE_ROW) + while ((item = katze_array_get_nth_item (KATZE_ARRAY (array), i))) { - gint app; - KatzeItem* item; - const unsigned char* uri; - const unsigned char* title; - - uri = sqlite3_column_text (statement, 0); - title = sqlite3_column_text (statement, 1); - app = sqlite3_column_int64 (statement, 2); - - item = katze_item_new (); - katze_item_set_name (item, (gchar*)title); - katze_item_set_meta_integer (item, "toolbar", 1); - if (uri) - { - katze_item_set_uri (item, (gchar*)uri); - katze_item_set_meta_integer (item, "app", app); - } midori_bookmarkbar_insert_item (browser->bookmarkbar, item); + i++; } _action_set_sensitive (browser, "BookmarkAdd", TRUE); _action_set_sensitive (browser, "BookmarkFolderAdd", TRUE); diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c index e1cc618d..791f786e 100644 --- a/panels/midori-bookmarks.c +++ b/panels/midori-bookmarks.c @@ -11,6 +11,7 @@ #include "midori-bookmarks.h" +#include "midori-array.h" #include "midori-app.h" #include "midori-browser.h" #include "midori-stock.h" @@ -143,7 +144,6 @@ midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks, sqlite3_stmt* statement; gint result; const gchar* sqlcmd; - KatzeArray* array; db = g_object_get_data (G_OBJECT (bookmarks->array), "db"); @@ -155,42 +155,7 @@ midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks, if (result != SQLITE_OK) return NULL; - array = katze_array_new (KATZE_TYPE_ITEM); - - while ((result = sqlite3_step (statement)) == SQLITE_ROW) - { - gint type; - gint app; - gint toolbar; - KatzeItem* item; - const unsigned char* uri; - const unsigned char* title; - - uri = sqlite3_column_text (statement, 0); - title = sqlite3_column_text (statement, 1); - type = sqlite3_column_int64 (statement, 2); - app = sqlite3_column_int64 (statement, 3); - toolbar = sqlite3_column_int64 (statement, 4); - - item = katze_item_new (); - katze_item_set_name (item, (gchar*)title); - katze_item_set_meta_integer (item, "toolbar", toolbar); - - /* type 0 -- folder, 1 -- entry */ - if (type == 1) - { - katze_item_set_uri (item, (gchar*)uri); - katze_item_set_meta_integer (item, "app", app); - } - katze_array_add_item (array, item); - } - - if (result != SQLITE_DONE) - g_print (_("Failed to execute database statement: %s\n"), - sqlite3_errmsg (db)); - - sqlite3_finalize (statement); - return array; + return katze_array_from_statement (statement); } static void