evince r3351 - in trunk: . libview shell



Author: chpe
Date: Sun Jan 18 15:00:58 2009
New Revision: 3351
URL: http://svn.gnome.org/viewvc/evince?rev=3351&view=rev

Log:
Bug 558084 â simplify drag data handling

Modified:
   trunk/ChangeLog
   trunk/libview/ev-view.c
   trunk/shell/ev-sidebar-attachments.c
   trunk/shell/ev-window.c

Modified: trunk/libview/ev-view.c
==============================================================================
--- trunk/libview/ev-view.c	(original)
+++ trunk/libview/ev-view.c	Sun Jan 18 15:00:58 2009
@@ -72,21 +72,6 @@
 	TARGET_DND_IMAGE
 };
 
-enum {
-	TARGET_STRING,
-	TARGET_TEXT,
-	TARGET_COMPOUND_TEXT,
-	TARGET_UTF8_STRING,
-	TARGET_TEXT_BUFFER_CONTENTS
-};
-
-static const GtkTargetEntry clipboard_targets[] = {
-	{ "STRING", 0, TARGET_STRING },
-	{ "TEXT",   0, TARGET_TEXT },
-	{ "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
-	{ "UTF8_STRING", 0, TARGET_UTF8_STRING },
-};
-
 static guint signals[N_SIGNALS];
 
 typedef enum {
@@ -2752,7 +2737,7 @@
 			if (view->image_dnd_info.image) {
 				GdkPixbuf   *pixbuf;
 				const gchar *tmp_uri;
-				gchar      **uris;
+				gchar      **uris[2];
 
 				ev_document_doc_mutex_lock ();
 				pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (view->document),
@@ -2762,13 +2747,9 @@
 				tmp_uri = ev_image_save_tmp (view->image_dnd_info.image, pixbuf);
 				g_object_unref (pixbuf);
 
-				uris = g_new0 (gchar *, 2);
 				uris[0] = (gchar *)tmp_uri;
-				
+                                uris[1] = NULL;
 				gtk_selection_data_set_uris (selection_data, uris);
-
-				/* g_free instead of g_strfreev since tmp_uri is const */ 
-				g_free (uris);
 			}
 	}
 }
@@ -5625,13 +5606,23 @@
                                               GDK_SELECTION_PRIMARY);
 
 	if (ev_view->selection_info.selections || ev_view->link_selected) {
+                GtkTargetList *target_list;
+                GtkTargetEntry *targets;
+                int n_targets;
+
+                target_list = gtk_target_list_new (NULL, 0);
+                gtk_target_list_add_text_targets (target_list, 0);
+                targets = gtk_target_table_new_from_list (target_list, &n_targets);
+                gtk_target_list_unref (target_list);
+                
 		if (!gtk_clipboard_set_with_owner (clipboard,
-						   clipboard_targets,
-						   G_N_ELEMENTS (clipboard_targets),
+						   targets, n_targets,
 						   ev_view_primary_get_cb,
 						   ev_view_primary_clear_cb,
 						   G_OBJECT (ev_view)))
 			ev_view_primary_clear_cb (clipboard, ev_view);
+
+                gtk_target_table_free (targets, n_targets);
 	} else {
 		if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (ev_view))
 			gtk_clipboard_clear (clipboard);

Modified: trunk/shell/ev-sidebar-attachments.c
==============================================================================
--- trunk/shell/ev-sidebar-attachments.c	(original)
+++ trunk/shell/ev-sidebar-attachments.c	Sun Jan 18 15:00:58 2009
@@ -55,10 +55,6 @@
 	N_SIGNALS
 };
 
-static const GtkTargetEntry drag_targets[] = {
-	{ "text/uri-list", 0, 0 }
-};
-
 static guint signals[N_SIGNALS];
 
 struct _EvSidebarAttachmentsPrivate {
@@ -398,15 +394,15 @@
 				      gpointer          user_data)
 {
 	EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (user_data);
-	GString              *uri_list;
-	gchar                *uris = NULL;
 	GList                *selected = NULL, *l;
+        GPtrArray            *uris;
+        char                **uri_list;
 
 	selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (ev_attachbar->priv->icon_view));
 	if (!selected)
 		return;
 
-	uri_list = g_string_new (NULL);
+        uris = g_ptr_array_new ();
 	
 	for (l = selected; l && l->data; l = g_list_next (l)) {
 		EvAttachment *attachment;
@@ -434,9 +430,7 @@
 			gchar *uri;
 
 			uri = g_file_get_uri (file);
-			g_string_append (uri_list, uri);
-			g_string_append_c (uri_list, '\n');
-			g_free (uri);
+                        g_ptr_array_add (uris, uri);
 		}
 	
 		if (error) {
@@ -449,15 +443,10 @@
 		g_object_unref (attachment);
 	}
 
-	uris = g_string_free (uri_list, FALSE);
-
-	if (uris) {
-		gtk_selection_data_set (data,
-					data->target,
-					8,
-					(guchar *)uris,
-					strlen (uris));
-	}
+        g_ptr_array_add (uris, NULL); /* NULL-terminate */
+        uri_list = (char **) g_ptr_array_free (uris, FALSE);
+        gtk_selection_data_set_uris (data, uri_list);
+        g_strfreev (uri_list);
 
 	g_list_free (selected);
 }
@@ -545,6 +534,12 @@
 static void
 ev_sidebar_attachments_init (EvSidebarAttachments *ev_attachbar)
 {
+#if !GTK_CHECK_VERSION (2, 15, 0)
+        const GtkTargetEntry drag_targets[] = {
+                { "text/uri-list", 0, 0 }
+        };
+#endif
+
 	GtkWidget *swindow;
 	
 	ev_attachbar->priv = EV_SIDEBAR_ATTACHMENTS_GET_PRIVATE (ev_attachbar);
@@ -594,12 +589,21 @@
 								g_object_unref);
 
 	/* Drag and Drop */
+#if GTK_CHECK_VERSION (2, 15, 0)
+	gtk_icon_view_enable_model_drag_source (
+		GTK_ICON_VIEW (ev_attachbar->priv->icon_view),
+		GDK_BUTTON1_MASK,
+		NULL, 0,
+		GDK_ACTION_COPY);
+        gtk_drag_source_add_uri_targets (ev_attachbar->priv->icon_view);
+#else
 	gtk_icon_view_enable_model_drag_source (
 		GTK_ICON_VIEW (ev_attachbar->priv->icon_view),
 		GDK_BUTTON1_MASK,
 		drag_targets,
 		G_N_ELEMENTS (drag_targets),
 		GDK_ACTION_COPY);
+#endif
 
 	g_signal_connect (G_OBJECT (ev_attachbar->priv->icon_view),
 			  "drag-data-get",

Modified: trunk/shell/ev-window.c
==============================================================================
--- trunk/shell/ev-window.c	(original)
+++ trunk/shell/ev-window.c	Sun Jan 18 15:00:58 2009
@@ -242,10 +242,6 @@
 	GTK_PRINT_SETTINGS_OUTPUT_URI
 };
 
-static const GtkTargetEntry ev_window_drop_targets[] = {
-	{ "text/uri-list", 0, 0 }
-};
-
 static void	ev_window_update_actions	 	(EvWindow         *ev_window);
 static void     ev_window_sidebar_visibility_changed_cb (EvSidebar        *ev_sidebar,
 							 GParamSpec       *pspec,
@@ -6265,9 +6261,9 @@
 	/* Drag and Drop */
 	gtk_drag_dest_set (GTK_WIDGET (ev_window),
 			   GTK_DEST_DEFAULT_ALL,
-			   ev_window_drop_targets,
-			   G_N_ELEMENTS (ev_window_drop_targets),
+			   NULL, 0,
 			   GDK_ACTION_COPY);
+	gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window));
 }
 
 /**



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