Small patches



Hi all,

Two (small!) patches attached:
  dnd    - Enabled DnD for bookmarks in the menus
  import - No longer create "->" topics when importing

Should we consider converting all "->" style topics to sets of topics
when reading old epiphany bookmark files?

Regards,
Peter.

Index: ephy-bookmark-action.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/bookmarks/ephy-bookmark-action.c,v
retrieving revision 1.68
diff -u -r1.68 ephy-bookmark-action.c
--- ephy-bookmark-action.c	16 Oct 2005 20:29:26 -0000	1.68
+++ ephy-bookmark-action.c	18 Oct 2005 00:32:12 -0000
@@ -31,6 +31,7 @@
 #include "ephy-shell.h"
 #include "ephy-gui.h"
 #include "ephy-debug.h"
+#include "ephy-dnd.h"
 
 #include <glib/gi18n.h>
 #include <gtk/gtkwidget.h>
@@ -46,9 +47,12 @@
 #include <gtk/gtktoolitem.h>
 #include <gtk/gtkmain.h>
 #include <libgnomevfs/gnome-vfs-uri.h>
-
 #include <string.h>
 
+static const GtkTargetEntry drag_types[] = {
+  {EPHY_DND_URL_TYPE, 0, 0},
+};
+
 /* FIXME tweak this, or make it configurable? (bug 148093) */
 #define ENTRY_WIDTH_CHARS	12
 #define TOOLITEM_WIDTH_CHARS	20
@@ -468,6 +472,35 @@
 	return FALSE;
 }
 
+static void
+drag_begin_cb (GtkWidget          *widget,
+	       GdkDragContext     *context,
+	       GtkAction          *action)
+{
+	widget = gtk_widget_get_ancestor (widget, GTK_TYPE_MENU);
+	while (widget != NULL)
+	{
+		gtk_menu_shell_deactivate (GTK_MENU_SHELL (widget));
+		widget = gtk_menu_get_attach_widget (GTK_MENU (widget));
+		if (widget) widget = gtk_widget_get_ancestor (widget, GTK_TYPE_MENU);
+	}
+}
+
+static void
+drag_data_get_cb (GtkWidget          *widget,
+		  GdkDragContext     *context,
+		  GtkSelectionData   *selection_data,
+		  guint               info,
+		  guint32             time,
+		  GtkAction          *action)
+{
+	EphyNode *node = ephy_bookmark_action_get_bookmark (EPHY_BOOKMARK_ACTION (action));
+	const char *location = ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_LOCATION);
+
+	g_return_if_fail (location != NULL);
+
+	gtk_selection_data_set (selection_data, selection_data->target, 8, (unsigned char *)location, strlen (location));
+}
 
 static void
 connect_proxy (GtkAction *action, GtkWidget *proxy)
@@ -515,6 +548,13 @@
 		gtk_label_set_max_width_chars (label, LABEL_WIDTH_CHARS);
 
 		g_signal_connect (proxy, "activate", G_CALLBACK (activate_cb), action);
+
+		g_signal_connect (proxy, "drag_begin",
+				  G_CALLBACK (drag_begin_cb), action);
+		g_signal_connect (proxy, "drag_data_get",
+				  G_CALLBACK (drag_data_get_cb), action);
+		gtk_drag_source_set (proxy, GDK_BUTTON1_MASK, drag_types,
+				     G_N_ELEMENTS (drag_types), GDK_ACTION_COPY);
 	}
 }
 
Index: ephy-bookmarks-import.c
===================================================================
RCS file: /cvs/gnome/epiphany/src/bookmarks/ephy-bookmarks-import.c,v
retrieving revision 1.43
diff -u -r1.43 ephy-bookmarks-import.c
--- ephy-bookmarks-import.c	28 May 2005 21:04:49 -0000	1.43
+++ ephy-bookmarks-import.c	18 Oct 2005 00:34:59 -0000
@@ -261,7 +261,7 @@
 }
 
 static int
-xbel_parse_folder (EphyBookmarks *eb, xmlTextReaderPtr reader, char *parent_folder)
+xbel_parse_folder (EphyBookmarks *eb, xmlTextReaderPtr reader, GList *folders)
 {
 	EphyXBELImporterState state = STATE_FOLDER;
 	char *folder = NULL;
@@ -285,22 +285,9 @@
 		{
 			if (state == STATE_TITLE && folder == NULL)
 			{
-				char *title;
-
-				title = (char *) xmlTextReaderValue (reader);
-
-				if (!parent_folder)
-				{
-					folder = g_strdup (title);
-				}
-				else
-				{
-					folder = g_strconcat (parent_folder,
-							      BOOKMARKS_HIERARCHY_SEP,
-							      title, NULL);
-				}
-
-				g_free (title);
+				folder = (char *) xmlTextReaderValue (reader);
+				
+				folders = g_list_prepend (folders, folder);
 			}
 			else
 			{
@@ -310,19 +297,27 @@
 		else if (xmlStrEqual (tag, (xmlChar *) "bookmark") && type == 1 && state == STATE_FOLDER)
 		{
 			EphyNode *node = NULL, *keyword;
+			GList *l;
 
 			ret = xbel_parse_bookmark (eb, reader, &node);
 
-			keyword = ephy_bookmarks_find_keyword (eb, folder ? folder : "", FALSE);
-			
-			if (keyword == NULL && folder != NULL && folder[0] != '\0')
+			for (l = folders; l != NULL; l=l->next)
 			{
-				keyword = ephy_bookmarks_add_keyword (eb, folder);
-			}
+				char *title;
+				
+				title = l->data ? (char *) l->data : "";
+				
+				keyword = ephy_bookmarks_find_keyword (eb, title, FALSE);
+			
+				if (keyword == NULL && title[0] != '\0')
+				{
+					keyword = ephy_bookmarks_add_keyword (eb, title);
+				}
 
-			if (node != NULL && keyword != NULL)
-			{
-				ephy_bookmarks_set_keyword (eb, keyword, node);
+				if (node != NULL && keyword != NULL)
+				{
+					ephy_bookmarks_set_keyword (eb, keyword, node);
+				}
 			}
 
 			if (ret != 1) break;
@@ -332,7 +327,7 @@
 		{
 			if (type == XML_READER_TYPE_ELEMENT)
 			{
-				ret = xbel_parse_folder (eb, reader, folder ? folder : "");
+				ret = xbel_parse_folder (eb, reader, folders);
 				
 				if (ret != 1) break;
 			}
@@ -384,8 +379,12 @@
 		/* next one, please */
 		ret = xmlTextReaderRead (reader);
 	}
-
-	g_free (folder);
+	
+	if (folder)
+	{
+		folders = g_list_remove (folders, folder);
+		g_free (folder);
+	}
 
 	return ret;
 }
@@ -660,25 +659,6 @@
 	return temp;
 }
 
-static char *
-folders_list_to_topic_name (GList *folders)
-{
-	GString *topic;
-	GList *l;
-
-	g_return_val_if_fail (folders != NULL, NULL);
-
-	topic = g_string_new (folders->data);
-
-	for (l = folders->next; l != NULL; l = l->next)
-	{
-		g_string_append (topic, BOOKMARKS_HIERARCHY_SEP);
-		g_string_append (topic, l->data);
-	}
-
-	return g_string_free (topic, FALSE);
-}
-
 gboolean
 ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
 			       const char *filename)
@@ -733,18 +713,18 @@
 			if (folders != NULL)
 			{
 				EphyNode *keyword;
+				GList *l;
 
-				topic = folders_list_to_topic_name (folders);
-				g_return_val_if_fail (topic != NULL, FALSE);
-
-				keyword = ephy_bookmarks_find_keyword (bookmarks, topic, FALSE);
-				if (keyword == NULL)
+				for (l = folders; l != NULL; l = l->next)
 				{
-					keyword = ephy_bookmarks_add_keyword (bookmarks, topic);
-				}
-				g_free (topic);
+					keyword = ephy_bookmarks_find_keyword (bookmarks, l->data, FALSE);
+					if (keyword == NULL)
+					{
+						keyword = ephy_bookmarks_add_keyword (bookmarks, l->data);
+					}
 
-				ephy_bookmarks_set_keyword (bookmarks, keyword, node);
+					ephy_bookmarks_set_keyword (bookmarks, keyword, node);
+				}
 			}
 
 			g_free (parsedname);


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