[anjal] Add 'Save to Downloads' option.



commit 7154cabee850ddfacd23a46e4a42ef48ec0f5885
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Fri Jul 17 17:53:20 2009 +0530

    Add 'Save to Downloads' option.

 src/em-format-mail-display.c |   50 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 3 deletions(-)
---
diff --git a/src/em-format-mail-display.c b/src/em-format-mail-display.c
index bd689b2..75bd30d 100644
--- a/src/em-format-mail-display.c
+++ b/src/em-format-mail-display.c
@@ -67,7 +67,7 @@
 #include "certificate-viewer.h"
 #include "e-cert-db.h"
 #endif
-
+#include <gio/gio.h>
 #include "mail/mail-config.h"
 #include "misc/e-attachment-button.h"
 #include "misc/e-attachment-view.h"
@@ -1496,6 +1496,38 @@ efhd_attachment_image(EMFormatMail *efh, GtkWidget *eb, EMFormatMailPObject *pob
 	return eb;
 }
 
+static void
+emfd_save_attachment (GtkButton *button, EAttachment *attachment)
+{
+	char *path;
+	GFileInfo *file_info;
+	const gchar *name = NULL;
+	GFile *dest;
+	int i = 1;
+
+	file_info = e_attachment_get_file_info (attachment);
+	if (file_info != NULL)
+		name = g_file_info_get_display_name (file_info);
+	if (name == NULL)
+		/* Translators: Default attachment filename. */
+		name = _("attachment.dat");
+	
+	path = g_build_filename (g_get_home_dir(), "Downloads", name, NULL);
+	while (g_file_test(path, G_FILE_TEST_EXISTS)) {
+		char *tname = g_strdup_printf("%s_%d", name, i++);
+		g_free(path);
+		path = g_build_filename (g_get_home_dir(), "Downloads", tname, NULL);
+		g_free(tname);
+	}
+	
+	dest = g_file_new_for_path (path);
+	e_attachment_save_async (
+		attachment, dest, (GAsyncReadyCallback)
+		e_attachment_save_handle_error, gtk_widget_get_toplevel(button));
+	g_object_unref (dest);
+	g_free(path);
+}
+
 /* attachment button callback */
 static GtkWidget *
 efhd_attachment_button(EMFormatMail *efh, GtkWidget *eb, EMFormatMailPObject *pobject)
@@ -1505,10 +1537,10 @@ efhd_attachment_button(EMFormatMail *efh, GtkWidget *eb, EMFormatMailPObject *po
 	EAttachmentView *view;
 	EAttachmentStore *store;
 	EAttachment *attachment;
-	GtkWidget *widget, *mainbox, *topbox;
+	GtkWidget *widget, *mainbox, *topbox, *tmp;
 	gpointer parent = NULL;
 	char *txt;
-
+	
 	/* FIXME: handle default shown case */
 	d(printf("adding attachment button/content\n"));
 
@@ -1568,6 +1600,18 @@ efhd_attachment_button(EMFormatMail *efh, GtkWidget *eb, EMFormatMailPObject *po
 	widget  = gtk_label_new (txt);
 	gtk_widget_show (widget);
 	gtk_box_pack_start ((GtkBox *)mainbox, widget, FALSE, FALSE, 6);
+
+	tmp = gtk_hbox_new (FALSE, 0);
+	widget = gtk_image_new_from_stock ("gtk-save", GTK_ICON_SIZE_BUTTON);
+	gtk_box_pack_start ((GtkBox *)tmp, widget, FALSE, FALSE, 2);
+	widget = gtk_label_new (_("Save to Downloads"));
+	gtk_box_pack_start ((GtkBox *)tmp, widget, FALSE, FALSE, 2);
+	widget = gtk_button_new ();
+	g_signal_connect (widget, "clicked", G_CALLBACK (emfd_save_attachment), attachment); 
+	gtk_container_add (widget, tmp);
+	gtk_widget_show_all (widget);
+	gtk_box_pack_start ((GtkBox *)mainbox, widget, FALSE, FALSE, 6);
+
 	gtk_box_pack_start ((GtkBox *)eb, mainbox, FALSE, FALSE, 0);
 	gtk_widget_show_all(mainbox);
 	if (info->child_box)



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