[Epiphany] galeon bookmark import



Hi,

I just installed ephy a day or so ago, and I am really liking it so
far.  That said, one of the only things missing for me was the ability
to import galeon bookmarks.  So, here's a patch :)

Excellent work guys thus far, keep it up!

Thanks,
James
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/epiphany/ChangeLog,v
retrieving revision 1.69
diff -u -r1.69 ChangeLog
--- ChangeLog	4 Feb 2003 20:17:11 -0000	1.69
+++ ChangeLog	5 Feb 2003 01:37:20 -0000
@@ -1,3 +1,17 @@
+2003-02-04  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 bookmarks.
+
 2003-02-04  Xan Lopez  <xan@masilla.org>
 
 	* src/bookmarks/ephy-bookmarks-editor.c:
Index: data/starthere/section.xsl
===================================================================
RCS file: /cvs/gnome/epiphany/data/starthere/section.xsl,v
retrieving revision 1.3
diff -u -r1.3 section.xsl
--- data/starthere/section.xsl	8 Jan 2003 19:12:29 -0000	1.3
+++ data/starthere/section.xsl	5 Feb 2003 01:37:20 -0000
@@ -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">
Index: embed/mozilla/StartHereProtocolHandler.cpp
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/StartHereProtocolHandler.cpp,v
retrieving revision 1.6
diff -u -r1.6 StartHereProtocolHandler.cpp
--- embed/mozilla/StartHereProtocolHandler.cpp	4 Feb 2003 17:11:27 -0000	1.6
+++ embed/mozilla/StartHereProtocolHandler.cpp	5 Feb 2003 01:37:20 -0000
@@ -124,10 +124,16 @@
 	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-xbel-bookmarks"))
+	{
+		g_signal_emit_by_name (embed_shell, "command", "import-xbel-bookmarks",
+				       path.get() + strlen ("import-xbel-bookmarks?"));
 		return NS_ERROR_FAILURE;
 	}
 	else if (g_str_has_prefix (path.get(), "configure-network"))
Index: lib/ephy-start-here.c
===================================================================
RCS file: /cvs/gnome/epiphany/lib/ephy-start-here.c,v
retrieving revision 1.4
diff -u -r1.4 ephy-start-here.c
--- lib/ephy-start-here.c	4 Feb 2003 17:11:27 -0000	1.4
+++ lib/ephy-start-here.c	5 Feb 2003 01:37:21 -0000
@@ -220,6 +220,25 @@
 	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 void
 attach_content (EphyStartHere *sh, xmlNodePtr node, xmlChar *id)
 {
@@ -232,12 +251,24 @@
 		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-xbel-bookmarks");
+			xmlSetProp (child, "param", bmk_file);
+			xmlAddChild (node, child);
+		}
+		g_free (bmk_file);
+
 	}
 }
 
Index: src/ephy-shell.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/ephy-shell.c,v
retrieving revision 1.11
diff -u -r1.11 ephy-shell.c
--- src/ephy-shell.c	21 Jan 2003 12:37:02 -0000	1.11
+++ src/ephy-shell.c	5 Feb 2003 01:37:21 -0000
@@ -133,7 +133,7 @@
 
 	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);
 
@@ -143,6 +143,29 @@
                          GTK_MESSAGE_ERROR,
                          GTK_BUTTONS_OK,
                          _("Bookmarks imported successfully."));
+		gtk_dialog_run (GTK_DIALOG (dialog));
+		gtk_widget_destroy (dialog);
+	}
+	else if (strcmp (command, "import-xbel-bookmarks") == 0)
+	{
+		if (ephy_bookmarks_import_xbel (bookmarks, param))
+		{
+			dialog = gtk_message_dialog_new
+				(NULL,
+				 GTK_DIALOG_MODAL,
+				 GTK_MESSAGE_INFO,
+				 GTK_BUTTONS_OK,
+				 _("Bookmarks imported successfully."));
+		}
+		else
+		{
+			dialog = gtk_message_dialog_new
+				(NULL,
+				 GTK_DIALOG_MODAL,
+				 GTK_MESSAGE_ERROR,
+				 GTK_BUTTONS_OK,
+				 _("Importing bookmarks failed."));
+		}
 		gtk_dialog_run (GTK_DIALOG (dialog));
 		gtk_widget_destroy (dialog);
 	}
Index: src/bookmarks/ephy-bookmarks-import.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/bookmarks/ephy-bookmarks-import.c,v
retrieving revision 1.1
diff -u -r1.1 ephy-bookmarks-import.c
--- src/bookmarks/ephy-bookmarks-import.c	2 Jan 2003 20:24:53 -0000	1.1
+++ src/bookmarks/ephy-bookmarks-import.c	5 Feb 2003 01:37:21 -0000
@@ -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,131 @@
 	}
 }
 
+
+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)
+{
+	xmlNodePtr child = node;
+	xmlChar *keyword = NULL;
+
+	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);
+
+			if (keyword)
+			{
+				g_free (keyword);
+				keyword = NULL;
+			}
+		}
+		
+		child = child->next;
+	}
+}
+
+
+static void
+xbel_parse_bookmarks (EphyBookmarks *bookmarks,
+		      xmlNodePtr node)
+{
+	xmlNodePtr child = node;
+
+	while (child != NULL)
+	{
+		if (xmlStrEqual (child->name, "xbel"))
+		{
+			xbel_parse_bookmarks (bookmarks, child->children);
+		}
+
+		if (xmlStrEqual (child->name, "folder"))
+		{
+			xbel_parse_folder (bookmarks, child->children);
+		}
+
+		child = child->next;
+	}
+}
+
 gboolean
 ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
 			       const char *filename)
@@ -88,6 +219,27 @@
 
 	g_free (keyword);
         xmlFreeDoc (doc);
+
+	return TRUE;
+}
+
+gboolean
+ephy_bookmarks_import_xbel (EphyBookmarks *bookmarks,
+			    const char *filename)
+{
+	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);
+
+	xmlFreeDoc (doc);
 
 	return TRUE;
 }
Index: src/bookmarks/ephy-bookmarks-import.h
===================================================================
RCS file: /cvs/gnome/epiphany/src/bookmarks/ephy-bookmarks-import.h,v
retrieving revision 1.1
diff -u -r1.1 ephy-bookmarks-import.h
--- src/bookmarks/ephy-bookmarks-import.h	2 Jan 2003 20:24:53 -0000	1.1
+++ src/bookmarks/ephy-bookmarks-import.h	5 Feb 2003 01:37:21 -0000
@@ -26,6 +26,9 @@
 gboolean ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
 					const char *filename);
 
+gboolean ephy_bookmarks_import_xbel    (EphyBookmarks *bookmarks,
+					const char *filename);
+
 G_END_DECLS
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]