Re: [evolution-patches] (Gal) Fix to handle double click on attachment bar



Made them as a memeber variables. Also changed the relative code to use
camel_url* to construct urls.

-Srini.
On Thu, 2005-08-18 at 12:19 +0800, Not Zed wrote:
> Whats with all the g_object_set_data stuff?  That's pretty messy, when
> all you need is a pointer.
> 
> ON the object.
> 
> Thats the whole point of having the object there, not merely as a shitty
> associative array.
> 
> 
> On Wed, 2005-08-17 at 20:03 +0530, Srinivasa Ragavan wrote:
> > +                               if (!uri) {
> > +                                       path = temp_save_part
> > (attachment->body);
> > +                                       url =
> > g_strdup_printf("file://%s", path);
> > +                                       g_object_set_data_full
> > ((GObject *) attachment, "e-open-url", url, g_free);
> > +                                       uri =
> > g_strdup_printf("file://%s\r\n", path);
> > +                                       g_object_set_data_full
> > ((GObject *) attachment, "e-drag-uri", uri, g_free);
> > +                               } else { 
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/widgets/misc/ChangeLog,v
retrieving revision 1.371
diff -u -p -r1.371 ChangeLog
--- ChangeLog	16 Aug 2005 05:26:17 -0000	1.371
+++ ChangeLog	18 Aug 2005 06:36:51 -0000
@@ -1,3 +1,16 @@
+2005-08-17  Srinivasa Ragavan <sragavan novell com>
+
+	* e-attachment-bar.c 
+	eab_drag_data_get: Use camel_url to construct url
+	(eab_icon_clicked_cb) (e_attachment_bar_new): 
+	Fixed part of bug #312224. It handles double click on a attachment
+	icon and calls gnome_url_show.
+
+	* e-attachment.[ch] (finalise) (init): Add a new member to preserve
+	the stored location
+	(e_attachment_new)(e_attachment_build_remote_file): Camel_url to 
+	construct urls
+	
 2005-08-16  Srinivasa Ragavan <sragavan novell com>
 
 	* e-attachment.c (download_to_local_path) (e_attachment_edit): Fixed
Index: e-attachment-bar.c
===================================================================
RCS file: /cvs/gnome/evolution/widgets/misc/e-attachment-bar.c,v
retrieving revision 1.7
diff -u -p -r1.7 e-attachment-bar.c
--- e-attachment-bar.c	16 Aug 2005 03:47:55 -0000	1.7
+++ e-attachment-bar.c	18 Aug 2005 06:36:51 -0000
@@ -34,6 +34,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
 #include <libgnome/gnome-i18n.h>
+#include <libgnome/libgnome.h>
 
 #include "e-attachment.h"
 #include "e-attachment-bar.h"
@@ -704,14 +705,13 @@ eab_drag_data_get(EAttachmentBar *bar, G
 	for (; tmp; tmp = tmp->next) {
 		int num = GPOINTER_TO_INT(tmp->data);
 		EAttachment *attachment = g_list_nth_data(bar->priv->attachments, num);	
-		char *uri;
+		CamelURL *curl;
 
 		if (!attachment->is_available_local)
 			continue;
 
-		uri = g_object_get_data((GObject *)attachment, "e-drag-uri");
-		if (uri) {
-			uris[i] = uri;
+		if (attachment->store_uri) {
+			uris[i] = attachment->store_uri;
 			i++;
 			continue;
 		}
@@ -720,10 +720,13 @@ eab_drag_data_get(EAttachmentBar *bar, G
 		if (path == NULL) 
 			continue;
 		
-		uri = g_strdup_printf("file://%s\r\n", path);
+		curl = camel_url_new("file:", NULL);
+		camel_url_set_path (curl, path);
+		attachment->store_uri = camel_url_to_string (curl, FALSE);
+		camel_url_free(curl);		
 		g_free(path);
-		g_object_set_data_full((GObject *)attachment, "e-drag-uri", uri, g_free);
-		uris[i] = uri;
+		
+		uris[i] = attachment->store_uri;
 		i++;
 	}
 	uris[i]=0;
@@ -810,6 +813,53 @@ eab_button_press_event(EAttachmentBar *b
 	return FALSE;
 }
 
+static gboolean
+eab_icon_clicked_cb (EAttachmentBar *bar, GdkEvent *event, gpointer *dummy)
+{
+	GSList *p = NULL;
+	GError *error = NULL;
+	gboolean ret = FALSE;
+
+	if (E_IS_ATTACHMENT_BAR (bar) && event->type == GDK_2BUTTON_PRESS) {
+		p = e_attachment_bar_get_selected (bar);
+		if (p && g_slist_length(p) == 1) {
+			EAttachment *attachment;
+			char *path = NULL;
+
+			attachment = (EAttachment *)p->data;
+
+			/* Check if the file is stored already */
+			if (!attachment->store_uri) {
+				CamelURL *curl;
+				
+				path = temp_save_part (attachment->body);				
+				curl  = camel_url_new ("file:", NULL);
+				camel_url_set_path ( curl, path);
+				attachment->store_uri = camel_url_to_string (curl, FALSE);
+				camel_url_free (curl);
+			}
+
+			/* launch the url now */
+			gnome_url_show (attachment->store_uri, &error);
+			if (error) {
+				g_message ("DEBUG: Launch failed: %s\n", error->message);
+				g_error_free (error);
+				error = NULL;
+			}
+
+			g_free (path);
+			ret = TRUE;
+		}
+
+		if (p) {
+			g_slist_foreach (p, (GFunc)g_object_unref, NULL);
+			g_slist_free (p);
+		}
+	}
+
+	return ret;
+}
+
 /* Initialization.  */
 
 static void
@@ -910,6 +960,7 @@ e_attachment_bar_new (GtkAdjustment *adj
 	g_signal_connect (new, "button_release_event", G_CALLBACK(eab_button_release_event), NULL);
 	g_signal_connect (new, "button_press_event", G_CALLBACK(eab_button_press_event), NULL);
 	g_signal_connect (new, "drag-data-get", G_CALLBACK(eab_drag_data_get), NULL);
+	g_signal_connect (icon_list, "event", G_CALLBACK (eab_icon_clicked_cb), NULL);
 	
 	return GTK_WIDGET (new);
 }
Index: e-attachment.c
===================================================================
RCS file: /cvs/gnome/evolution/widgets/misc/e-attachment.c,v
retrieving revision 1.5
diff -u -p -r1.5 e-attachment.c
--- e-attachment.c	16 Aug 2005 05:26:17 -0000	1.5
+++ e-attachment.c	18 Aug 2005 06:36:51 -0000
@@ -78,6 +78,7 @@ finalise(GObject *object)
 	}
 
 	g_free (attachment->file_name);
+	g_free (attachment->store_uri);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -143,6 +144,7 @@ init (EAttachment *attachment)
 	attachment->disposition = FALSE;
 	attachment->sign = CAMEL_CIPHER_VALIDITY_SIGN_NONE;
 	attachment->encrypt = CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE;
+	attachment->store_uri = NULL;
 }
 
 GType
@@ -210,7 +212,7 @@ e_attachment_new (const char *file_name,
 	struct stat statbuf;
 	char *mime_type;
 	char *filename;
-	char *uri;
+	CamelURL *curl;
 	
 	g_return_val_if_fail (file_name != NULL, NULL);
 	
@@ -283,8 +285,11 @@ e_attachment_new (const char *file_name,
 	new->handle = NULL;
 	new->is_available_local = TRUE;
 	new->file_name = filename;
-	uri = g_strdup_printf("file://%s\r\n", file_name);
-	g_object_set_data_full((GObject *)new, "e-drag-uri", uri, g_free);
+	
+	curl = camel_url_new ("file:", NULL);
+	camel_url_set_path (curl, file_name);
+	new->store_uri = camel_url_to_string (curl, FALSE);
+	camel_url_free (curl);
 	
 	return new;
 }
@@ -411,7 +416,7 @@ e_attachment_build_remote_file (const ch
 	struct stat statbuf;
 	char *mime_type;
 	char *filename;
-	char *uri;
+	CamelURL *curl;
 	
 	g_return_if_fail (file_name != NULL);
 	
@@ -486,9 +491,12 @@ e_attachment_build_remote_file (const ch
 	attachment->guessed_type = TRUE;
 	g_free (attachment->file_name);
 	attachment->file_name = g_strdup (filename);
-	uri = g_strdup_printf("file://%s\r\n", file_name);
-	g_object_set_data_full((GObject *)attachment, "e-drag-uri", uri, g_free);
 	
+	curl = camel_url_new ("file:", NULL);
+	camel_url_set_path (curl, file_name);
+	attachment->store_uri = camel_url_to_string (curl, FALSE);
+	camel_url_free (curl);
+
 }
 
 
Index: e-attachment.h
===================================================================
RCS file: /cvs/gnome/evolution/widgets/misc/e-attachment.h,v
retrieving revision 1.2
diff -u -p -r1.2 e-attachment.h
--- e-attachment.h	20 Jul 2005 11:17:42 -0000	1.2
+++ e-attachment.h	18 Aug 2005 06:36:51 -0000
@@ -65,6 +65,7 @@ struct _EAttachment {
 	char *description;
 	gboolean disposition;
 	int index;
+	char *store_uri;
 
 	/* Status of signed/encrypted attachments */
 	camel_cipher_validity_sign_t sign;


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