aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Willcox <jwillcox@gnome.org>2003-02-06 09:55:50 +0800
committerJames Willcox <jwillcox@src.gnome.org>2003-02-06 09:55:50 +0800
commit5a4dc61b3d5599842daef9004cb4a61c28c4dffa (patch)
treee7d10dec4ea563a2b63f6516b858acd5c358bedd
parent2f1334d2b432eec9ed13d64ac350beeeea43b49f (diff)
downloadgsoc2013-epiphany-5a4dc61b3d5599842daef9004cb4a61c28c4dffa.tar
gsoc2013-epiphany-5a4dc61b3d5599842daef9004cb4a61c28c4dffa.tar.gz
gsoc2013-epiphany-5a4dc61b3d5599842daef9004cb4a61c28c4dffa.tar.bz2
gsoc2013-epiphany-5a4dc61b3d5599842daef9004cb4a61c28c4dffa.tar.lz
gsoc2013-epiphany-5a4dc61b3d5599842daef9004cb4a61c28c4dffa.tar.xz
gsoc2013-epiphany-5a4dc61b3d5599842daef9004cb4a61c28c4dffa.tar.zst
gsoc2013-epiphany-5a4dc61b3d5599842daef9004cb4a61c28c4dffa.zip
Added the ability to import galeon and konqueror bookmarks.
2003-02-05 James Willcox <jwillcox@gnome.org> * data/starthere/section.xsl: * embed/mozilla/StartHereProtocolHandler.cpp: * lib/ephy-start-here.c: (galeon_bookmarks), (attach_content): * src/bookmarks/ephy-bookmarks-import.c: (xbel_parse_single_bookmark), (xbel_parse_folder), (xbel_parse_bookmarks), (ephy_bookmarks_import_mozilla), (ephy_bookmarks_import_xbel): * src/bookmarks/ephy-bookmarks-import.h: * src/ephy-shell.c: (ephy_shell_command_cb): Added the ability to import galeon and konqueror bookmarks.
-rw-r--r--ChangeLog14
-rw-r--r--data/starthere/section.xsl2
-rw-r--r--embed/mozilla/StartHereProtocolHandler.cpp18
-rw-r--r--lib/ephy-start-here.c66
-rw-r--r--src/bookmarks/ephy-bookmarks-import.c168
-rw-r--r--src/bookmarks/ephy-bookmarks-import.h4
-rw-r--r--src/ephy-shell.c50
7 files changed, 316 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 9005a5c63..1320daec1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2003-02-05 James Willcox <jwillcox@gnome.org>
+
+ * data/starthere/section.xsl:
+ * embed/mozilla/StartHereProtocolHandler.cpp:
+ * lib/ephy-start-here.c: (galeon_bookmarks), (attach_content):
+ * src/bookmarks/ephy-bookmarks-import.c:
+ (xbel_parse_single_bookmark), (xbel_parse_folder),
+ (xbel_parse_bookmarks), (ephy_bookmarks_import_mozilla),
+ (ephy_bookmarks_import_xbel):
+ * src/bookmarks/ephy-bookmarks-import.h:
+ * src/ephy-shell.c: (ephy_shell_command_cb):
+
+ Added the ability to import galeon and konqueror bookmarks.
+
2003-02-05 Marco Pesenti Gritti <marco@it.gnome.org>
* embed/mozilla/PromptService.cpp:
diff --git a/data/starthere/section.xsl b/data/starthere/section.xsl
index fb19cded3..d9d9091e2 100644
--- a/data/starthere/section.xsl
+++ b/data/starthere/section.xsl
@@ -57,7 +57,7 @@
<xsl:template match="action">
<a href="start-here:{@id}?{@param}">
<xsl:apply-templates/>
-</a>
+</a><br/>
</xsl:template>
<xsl:template match="smartbookmark">
diff --git a/embed/mozilla/StartHereProtocolHandler.cpp b/embed/mozilla/StartHereProtocolHandler.cpp
index 52235ab00..d2f9d33d7 100644
--- a/embed/mozilla/StartHereProtocolHandler.cpp
+++ b/embed/mozilla/StartHereProtocolHandler.cpp
@@ -124,12 +124,26 @@ NS_IMETHODIMP GStartHereProtocolHandler::NewChannel(nsIURI *aURI,
rv = aURI->GetPath(path);
if (NS_FAILED(rv)) return rv;
- if (g_str_has_prefix (path.get(), "import-bookmarks"))
+ if (g_str_has_prefix (path.get(), "import-mozilla-bookmarks"))
{
- g_signal_emit_by_name (embed_shell, "command", "import-bookmarks",
+ g_signal_emit_by_name (embed_shell, "command", "import-mozilla-bookmarks",
path.get() + strlen ("import-bookmarks?"));
return NS_ERROR_FAILURE;
}
+ else if (g_str_has_prefix (path.get(), "import-galeon-bookmarks"))
+ {
+ g_signal_emit_by_name (embed_shell, "command",
+ "import-galeon-bookmarks",
+ path.get() + strlen ("import-galeon-bookmarks?"));
+ return NS_ERROR_FAILURE;
+ }
+ else if (g_str_has_prefix (path.get(), "import-konqueror-bookmarks"))
+ {
+ g_signal_emit_by_name (embed_shell, "command",
+ "import-konqueror-bookmarks",
+ path.get() + strlen ("import-konqueror-bookmarks?"));
+ return NS_ERROR_FAILURE;
+ }
else if (g_str_has_prefix (path.get(), "configure-network"))
{
g_signal_emit_by_name (embed_shell, "command", "configure-network",
diff --git a/lib/ephy-start-here.c b/lib/ephy-start-here.c
index 40b23c452..06d08de38 100644
--- a/lib/ephy-start-here.c
+++ b/lib/ephy-start-here.c
@@ -220,6 +220,45 @@ mozilla_bookmarks (void)
return result;
}
+static char *
+galeon_bookmarks (void)
+{
+ GSList *l;
+ char *dir;
+ char *result;
+
+ dir = g_build_filename (g_get_home_dir (), ".galeon", NULL);
+ l = ephy_file_find (dir, "bookmarks.xbel", 4);
+ g_free (dir);
+
+ result = l ? g_strdup (l->data) : NULL;
+
+ g_slist_foreach (l, (GFunc) g_free, NULL);
+ g_slist_free (l);
+
+ return result;
+}
+
+static char *
+konqueror_bookmarks (void)
+{
+ GSList *l;
+ char *dir;
+ char *result;
+
+ dir = g_build_filename (g_get_home_dir (), ".kde", "share",
+ "apps", "konqueror", NULL);
+ l = ephy_file_find (dir, "bookmarks.xml", 4);
+ g_free (dir);
+
+ result = l ? g_strdup (l->data) : NULL;
+
+ g_slist_foreach (l, (GFunc) g_free, NULL);
+ g_slist_free (l);
+
+ return result;
+}
+
static void
attach_content (EphyStartHere *sh, xmlNodePtr node, xmlChar *id)
{
@@ -232,12 +271,35 @@ attach_content (EphyStartHere *sh, xmlNodePtr node, xmlChar *id)
if (bmk_file)
{
child = xmlNewDocNode (sh->priv->doc, NULL, "action",
- _("Import mozilla bookmarks"));
- xmlSetProp (child, "id", "import-bookmarks");
+ _("Import Mozilla bookmarks"));
+ xmlSetProp (child, "id", "import-mozilla-bookmarks");
+ xmlSetProp (child, "param", bmk_file);
+ xmlAddChild (node, child);
+ }
+ g_free (bmk_file);
+
+ bmk_file = galeon_bookmarks ();
+ if (bmk_file)
+ {
+ child = xmlNewDocNode (sh->priv->doc, NULL, "action",
+ _("Import Galeon bookmarks"));
+ xmlSetProp (child, "id", "import-galeon-bookmarks");
+ xmlSetProp (child, "param", bmk_file);
+ xmlAddChild (node, child);
+ }
+ g_free (bmk_file);
+
+ bmk_file = konqueror_bookmarks ();
+ if (bmk_file)
+ {
+ child = xmlNewDocNode (sh->priv->doc, NULL, "action",
+ _("Import Konqueror bookmarks"));
+ xmlSetProp (child, "id", "import-konqueror-bookmarks");
xmlSetProp (child, "param", bmk_file);
xmlAddChild (node, child);
}
g_free (bmk_file);
+
}
}
diff --git a/src/bookmarks/ephy-bookmarks-import.c b/src/bookmarks/ephy-bookmarks-import.c
index 19eaecc0b..9182bed60 100644
--- a/src/bookmarks/ephy-bookmarks-import.c
+++ b/src/bookmarks/ephy-bookmarks-import.c
@@ -23,6 +23,12 @@
#include "ephy-bookmarks-import.h"
#include "ephy-string.h"
+typedef struct _XbelInfo
+{
+ char *title;
+ char *smarturl;
+} XbelInfo;
+
static char *
build_keyword (const char *folder)
{
@@ -69,6 +75,146 @@ mozilla_parse_bookmarks (EphyBookmarks *bookmarks,
}
}
+
+static void
+xbel_parse_single_bookmark (EphyBookmarks *bookmarks,
+ xmlNodePtr node, XbelInfo *xbel)
+{
+ xmlNodePtr child = node;
+
+ while (child != NULL)
+ {
+ if (xmlStrEqual (child->name, "title"))
+ {
+ xbel->title = xmlNodeGetContent (child);
+ }
+ else if (xmlStrEqual (child->name, "info"))
+ {
+ xbel_parse_single_bookmark (bookmarks,
+ child->children,
+ xbel);
+ }
+ else if (xmlStrEqual (child->name, "metadata"))
+ {
+ xbel_parse_single_bookmark (bookmarks,
+ child->children,
+ xbel);
+ }
+ else if (xmlStrEqual (child->name, "smarturl"))
+ {
+ xbel->smarturl = xmlNodeGetContent (child);
+ }
+
+ child = child->next;
+ }
+}
+
+static void
+xbel_parse_folder (EphyBookmarks *bookmarks,
+ xmlNodePtr node,
+ const char *default_keyword)
+{
+ xmlNodePtr child = node;
+ xmlChar *keyword = g_strdup (default_keyword);
+
+ while (child != NULL)
+ {
+ if (xmlStrEqual (child->name, "title"))
+ {
+ xmlChar *tmp;
+
+ tmp = xmlNodeGetContent (child);
+
+ g_free (keyword);
+ keyword = build_keyword (tmp);
+ xmlFree (tmp);
+ }
+ else if (xmlStrEqual (child->name, "bookmark"))
+ {
+ XbelInfo *xbel;
+ xmlChar *url;
+
+ xbel = g_new0 (XbelInfo, 1);
+ xbel->title = NULL;
+ xbel->smarturl = NULL;
+
+ url = xmlGetProp (child, "href");
+
+ xbel_parse_single_bookmark (bookmarks,
+ child->children,
+ xbel);
+
+
+ ephy_bookmarks_add (bookmarks,
+ xbel->title,
+ url,
+ xbel->smarturl,
+ keyword);
+
+ if (url)
+ xmlFree (url);
+
+
+ if (xbel && xbel->title)
+ xmlFree (xbel->title);
+
+ if (xbel && xbel->smarturl)
+ xmlFree (xbel->smarturl);
+
+ g_free (xbel);
+ }
+ else if (xmlStrEqual (child->name, "folder"))
+ {
+ xbel_parse_folder (bookmarks,
+ child->children,
+ keyword);
+
+ if (keyword)
+ {
+ g_free (keyword);
+ keyword = NULL;
+ }
+ }
+
+ child = child->next;
+ }
+
+ g_free (keyword);
+}
+
+
+static void
+xbel_parse_bookmarks (EphyBookmarks *bookmarks,
+ xmlNodePtr node,
+ const char *default_keyword)
+{
+ xmlNodePtr child = node;
+
+ while (child != NULL)
+ {
+ if (xmlStrEqual (child->name, "xbel"))
+ {
+ xbel_parse_bookmarks (bookmarks,
+ child->children,
+ default_keyword);
+ }
+ else if (xmlStrEqual (child->name, "folder"))
+ {
+ xbel_parse_folder (bookmarks,
+ child->children,
+ default_keyword);
+ }
+ else if (xmlStrEqual (child->name, "bookmark"))
+ {
+ xbel_parse_folder (bookmarks,
+ child,
+ default_keyword);
+ }
+
+ child = child->next;
+ }
+}
+
gboolean
ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
const char *filename)
@@ -91,3 +237,25 @@ ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
return TRUE;
}
+
+gboolean
+ephy_bookmarks_import_xbel (EphyBookmarks *bookmarks,
+ const char *filename,
+ const char *default_keyword)
+{
+ xmlDocPtr doc;
+ xmlNodePtr child;
+
+ if (g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE)
+ return FALSE;
+
+ doc = xmlParseFile (filename);
+ g_assert (doc != NULL);
+
+ child = doc->children;
+ xbel_parse_bookmarks (bookmarks, child, default_keyword);
+
+ xmlFreeDoc (doc);
+
+ return TRUE;
+}
diff --git a/src/bookmarks/ephy-bookmarks-import.h b/src/bookmarks/ephy-bookmarks-import.h
index 3280af4c1..79f83c897 100644
--- a/src/bookmarks/ephy-bookmarks-import.h
+++ b/src/bookmarks/ephy-bookmarks-import.h
@@ -26,6 +26,10 @@ G_BEGIN_DECLS
gboolean ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
const char *filename);
+gboolean ephy_bookmarks_import_xbel (EphyBookmarks *bookmarks,
+ const char *filename,
+ const char *default_keyword);
+
G_END_DECLS
#endif
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 964744a4a..9f903c500 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -133,7 +133,7 @@ ephy_shell_command_cb (EphyEmbedShell *shell,
bookmarks = ephy_shell_get_bookmarks (EPHY_SHELL (shell));
- if (strcmp (command, "import-bookmarks") == 0)
+ if (strcmp (command, "import-mozilla-bookmarks") == 0)
{
ephy_bookmarks_import_mozilla (bookmarks, param);
@@ -146,6 +146,54 @@ ephy_shell_command_cb (EphyEmbedShell *shell,
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
+ else if (strcmp (command, "import-galeon-bookmarks") == 0)
+ {
+ if (ephy_bookmarks_import_xbel (bookmarks, param,
+ _("Galeon")))
+ {
+ dialog = gtk_message_dialog_new
+ (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Galeon bookmarks imported successfully."));
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new
+ (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Importing Galeon bookmarks failed."));
+ }
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+ else if (strcmp (command, "import-konqueror-bookmarks") == 0)
+ {
+ if (ephy_bookmarks_import_xbel (bookmarks, param,
+ _("Konqueror")))
+ {
+ dialog = gtk_message_dialog_new
+ (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Konqueror bookmarks imported successfully."));
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new
+ (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Importing Konqueror bookmarks failed."));
+ }
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
else if (strcmp (command, "configure-network") == 0)
{
ephy_file_launch_application ("gnome-network-preferences",