aboutsummaryrefslogtreecommitdiffstats
path: root/src/bookmarks/ephy-bookmarks-import.c
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 /src/bookmarks/ephy-bookmarks-import.c
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.
Diffstat (limited to 'src/bookmarks/ephy-bookmarks-import.c')
-rw-r--r--src/bookmarks/ephy-bookmarks-import.c168
1 files changed, 168 insertions, 0 deletions
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;
+}