diff --git a/midori/main.c b/midori/main.c index 2ec55990..588bac33 100644 --- a/midori/main.c +++ b/midori/main.c @@ -13,6 +13,7 @@ #include "midori-app.h" #include "midori-array.h" #include "midori-bookmarks.h" +#include "panels/midori-bookmarks.h" #include "midori-extension.h" #include "midori-extensions.h" #include "midori-history.h" @@ -528,93 +529,6 @@ midori_history_terminate (KatzeArray* array, sqlite3_close (db); } -static void -midori_bookmarks_add_item_cb (KatzeArray* array, - KatzeItem* item, - sqlite3* db) -{ - midori_bookmarks_insert_item_db (db, item, - katze_item_get_meta_string (item, "folder")); -} - -static void -midori_bookmarks_remove_item_cb (KatzeArray* array, - KatzeItem* item, - sqlite3* db) -{ - gchar* sqlcmd; - char* errmsg = NULL; - - if (KATZE_ITEM_IS_BOOKMARK (item)) - sqlcmd = sqlite3_mprintf ( - "DELETE FROM bookmarks WHERE uri = '%q' " - " AND folder = '%q'", - katze_item_get_uri (item), - katze_str_non_null (katze_item_get_meta_string (item, "folder"))); - - else - sqlcmd = sqlite3_mprintf ( - "DELETE FROM bookmarks WHERE title = '%q'" - " AND folder = '%q'", - katze_item_get_name (item), - katze_str_non_null (katze_item_get_meta_string (item, "folder"))); - - if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK) - { - g_printerr (_("Failed to remove history item: %s\n"), errmsg); - sqlite3_free (errmsg); - } - - sqlite3_free (sqlcmd); -} - -static sqlite3* -midori_bookmarks_initialize (KatzeArray* array, - const gchar* filename, - char** errmsg) -{ - sqlite3* db; - - if (sqlite3_open (filename, &db) != SQLITE_OK) - { - if (errmsg) - *errmsg = g_strdup_printf (_("Failed to open database: %s\n"), - sqlite3_errmsg (db)); - sqlite3_close (db); - return NULL; - } - - if (sqlite3_exec (db, - "CREATE TABLE IF NOT EXISTS " - "bookmarks (uri text, title text, folder text, " - "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; -} - -static void -midori_bookmarks_import (const gchar* filename, - sqlite3* db) -{ - KatzeArray* bookmarks; - GError* error = NULL; - - bookmarks = katze_array_new (KATZE_TYPE_ARRAY); - - if (!midori_array_from_file (bookmarks, filename, "xbel", &error)) - { - g_warning (_("The bookmarks couldn't be saved. %s"), error->message); - g_error_free (error); - return; - } - midori_bookmarks_import_array_db (db, bookmarks, ""); -} - static void settings_notify_cb (MidoriWebSettings* settings, GParamSpec* pspec, diff --git a/midori/midori-bookmarks.c b/midori/midori-bookmarks.c new file mode 100644 index 00000000..97ea7a67 --- /dev/null +++ b/midori/midori-bookmarks.c @@ -0,0 +1,104 @@ +/* + Copyright (C) 2010 Christian Dywan + Copyright (C) 2010 Alexander Butenko + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +#include "midori-bookmarks.h" +#include "panels/midori-bookmarks.h" +#include "midori-array.h" + +#include + +void +midori_bookmarks_add_item_cb (KatzeArray* array, + KatzeItem* item, + sqlite3* db) +{ + midori_bookmarks_insert_item_db (db, item, + katze_item_get_meta_string (item, "folder")); +} + +void +midori_bookmarks_remove_item_cb (KatzeArray* array, + KatzeItem* item, + sqlite3* db) +{ + gchar* sqlcmd; + char* errmsg = NULL; + + if (KATZE_ITEM_IS_BOOKMARK (item)) + sqlcmd = sqlite3_mprintf ( + "DELETE FROM bookmarks WHERE uri = '%q' " + " AND folder = '%q'", + katze_item_get_uri (item), + katze_str_non_null (katze_item_get_meta_string (item, "folder"))); + + else + sqlcmd = sqlite3_mprintf ( + "DELETE FROM bookmarks WHERE title = '%q'" + " AND folder = '%q'", + katze_item_get_name (item), + katze_str_non_null (katze_item_get_meta_string (item, "folder"))); + + if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK) + { + g_printerr (_("Failed to remove history item: %s\n"), errmsg); + sqlite3_free (errmsg); + } + + sqlite3_free (sqlcmd); +} + +sqlite3* +midori_bookmarks_initialize (KatzeArray* array, + const gchar* filename, + char** errmsg) +{ + sqlite3* db; + + if (sqlite3_open (filename, &db) != SQLITE_OK) + { + if (errmsg) + *errmsg = g_strdup_printf (_("Failed to open database: %s\n"), + sqlite3_errmsg (db)); + sqlite3_close (db); + return NULL; + } + + if (sqlite3_exec (db, + "CREATE TABLE IF NOT EXISTS " + "bookmarks (uri text, title text, folder text, " + "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; +} + +void +midori_bookmarks_import (const gchar* filename, + sqlite3* db) +{ + KatzeArray* bookmarks; + GError* error = NULL; + + bookmarks = katze_array_new (KATZE_TYPE_ARRAY); + + if (!midori_array_from_file (bookmarks, filename, "xbel", &error)) + { + g_warning (_("The bookmarks couldn't be saved. %s"), error->message); + g_error_free (error); + return; + } + midori_bookmarks_import_array_db (db, bookmarks, ""); +} diff --git a/midori/midori-bookmarks.h b/midori/midori-bookmarks.h new file mode 100644 index 00000000..a5f38ce1 --- /dev/null +++ b/midori/midori-bookmarks.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 2010 Christian Dywan + Copyright (C) 2010 Alexander Butenko + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +#include +#include + +void +midori_bookmarks_add_item_cb (KatzeArray* array, + KatzeItem* item, + sqlite3* db); + +void +midori_bookmarks_remove_item_cb (KatzeArray* array, + KatzeItem* item, + sqlite3* db); + +sqlite3* +midori_bookmarks_initialize (KatzeArray* array, + const gchar* filename, + char** errmsg); + +void +midori_bookmarks_import (const gchar* filename, + sqlite3* db); diff --git a/midori/midori.h b/midori/midori.h index 02af3671..a272938f 100644 --- a/midori/midori.h +++ b/midori/midori.h @@ -14,6 +14,7 @@ #include "midori-app.h" #include "midori-array.h" +#include "midori-bookmarks.h" #include "midori-browser.h" #include "midori-extension.h" #include "midori-locationaction.h" diff --git a/tests/properties.c b/tests/properties.c index 3f4f0403..e6d29947 100644 --- a/tests/properties.c +++ b/tests/properties.c @@ -10,7 +10,6 @@ */ #include "midori.h" -#include "midori-bookmarks.h" typedef struct {