diff options
author | James Willcox <jwillcox@gnome.org> | 2003-02-06 09:55:50 +0800 |
---|---|---|
committer | James Willcox <jwillcox@src.gnome.org> | 2003-02-06 09:55:50 +0800 |
commit | 5a4dc61b3d5599842daef9004cb4a61c28c4dffa (patch) | |
tree | e7d10dec4ea563a2b63f6516b858acd5c358bedd /src | |
parent | 2f1334d2b432eec9ed13d64ac350beeeea43b49f (diff) | |
download | gsoc2013-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')
-rw-r--r-- | src/bookmarks/ephy-bookmarks-import.c | 168 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-import.h | 4 | ||||
-rw-r--r-- | src/ephy-shell.c | 50 |
3 files changed, 221 insertions, 1 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; +} 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", |