]> spindle.queued.net Git - midori/commitdiff
Move bookmarks code out of midori/main.c
authorVincent Cappe <vcappe@gmail.com>
Sat, 14 Apr 2012 00:36:58 +0000 (02:36 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sat, 12 May 2012 02:03:14 +0000 (04:03 +0200)
midori/main.c
midori/midori-bookmarks.c [new file with mode: 0644]
midori/midori-bookmarks.h [new file with mode: 0644]
midori/midori.h
tests/properties.c

index 2ec55990aba39734d4045cb15e3870099f859f94..588bac33f86d0afd41e6da0a7c864034442bdf30 100644 (file)
@@ -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 (file)
index 0000000..97ea7a6
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ Copyright (C) 2010 Christian Dywan <christian@twotoasts.de>
+ Copyright (C) 2010 Alexander Butenko <a.butenka@gmail.com>
+
+ 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 <glib/gi18n.h>
+
+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 (file)
index 0000000..a5f38ce
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ Copyright (C) 2010 Christian Dywan <christian@twotoasts.de>
+ Copyright (C) 2010 Alexander Butenko <a.butenka@gmail.com>
+
+ 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 <sqlite3.h>
+#include <katze/katze.h>
+
+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);
index 02af3671ce1097a14a55058d0eb0282c9c9cc05f..a272938f9fb1dc75e3ae26a7089ad8786967513e 100644 (file)
@@ -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"
index 3f4f04037e7f42c4c1cda8a800895d3f8f91fa9f..e6d299474be398f73a869c124db6d18f825d6bc8 100644 (file)
@@ -10,7 +10,6 @@
 */
 
 #include "midori.h"
-#include "midori-bookmarks.h"
 
 typedef struct
 {