[Xfce4-commits] <midori:master> Move bookmarks code out of midori/main.c
Christian Dywan
noreply at xfce.org
Sat May 12 04:06:01 CEST 2012
Updating branch refs/heads/master
to 45ac40d6145e15606d51e50c58585784095fc9d9 (commit)
from 66abde2db90e8f33a13479f106586ccd1dd3b6f3 (commit)
commit 45ac40d6145e15606d51e50c58585784095fc9d9
Author: Vincent Cappe <vcappe at gmail.com>
Date: Sat Apr 14 02:36:58 2012 +0200
Move bookmarks code out of midori/main.c
midori/main.c | 88 +-------------------------------------
midori/midori-bookmarks.c | 104 +++++++++++++++++++++++++++++++++++++++++++++
midori/midori-bookmarks.h | 33 ++++++++++++++
midori/midori.h | 1 +
tests/properties.c | 1 -
5 files changed, 139 insertions(+), 88 deletions(-)
diff --git a/midori/main.c b/midori/main.c
index 2ec5599..588bac3 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"
@@ -529,93 +530,6 @@ midori_history_terminate (KatzeArray* array,
}
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,
MidoriApp* app)
diff --git a/midori/midori-bookmarks.c b/midori/midori-bookmarks.c
new file mode 100644
index 0000000..97ea7a6
--- /dev/null
+++ b/midori/midori-bookmarks.c
@@ -0,0 +1,104 @@
+/*
+ Copyright (C) 2010 Christian Dywan <christian at twotoasts.de>
+ Copyright (C) 2010 Alexander Butenko <a.butenka at 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
index 0000000..a5f38ce
--- /dev/null
+++ b/midori/midori-bookmarks.h
@@ -0,0 +1,33 @@
+/*
+ Copyright (C) 2010 Christian Dywan <christian at twotoasts.de>
+ Copyright (C) 2010 Alexander Butenko <a.butenka at 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);
diff --git a/midori/midori.h b/midori/midori.h
index 02af367..a272938 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 3f4f040..e6d2994 100644
--- a/tests/properties.c
+++ b/tests/properties.c
@@ -10,7 +10,6 @@
*/
#include "midori.h"
-#include "midori-bookmarks.h"
typedef struct
{
More information about the Xfce4-commits
mailing list