aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2007-04-18 19:09:52 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2007-04-18 19:09:52 +0800
commitbb05f6e6d0541bf29c8dde4e264cc7c23ba52fbb (patch)
treeb283928d6429c0cdf29869008cdad860ba3d8e87
parent86d3ffedacdaa16e49d98875f4804c3423466462 (diff)
downloadgsoc2013-evolution-bb05f6e6d0541bf29c8dde4e264cc7c23ba52fbb.tar.gz
gsoc2013-evolution-bb05f6e6d0541bf29c8dde4e264cc7c23ba52fbb.tar.zst
gsoc2013-evolution-bb05f6e6d0541bf29c8dde4e264cc7c23ba52fbb.zip
** Fixes bug #423766
2007-04-18 Matthew Barnes <mbarnes@redhat.com> ** Fixes bug #423766 * mail/em-format-html-display.c (attachments_save_all_clicked): Call em_utils_save_part() if there's only one attachment to save. * mail/em-utils.c (em_utils_save_part): Refactor to use gtk_dialog_run() instead of a "response" callback. * mail/em-utils.c (em_utils_save_parts): Refactor to use gtk_dialog_run() instead of a "response" callback. Use gtk_file_chooser_get_uri() to fetch the selected folder. svn path=/trunk/; revision=33429
-rw-r--r--mail/ChangeLog14
-rw-r--r--mail/em-format-html-display.c21
-rw-r--r--mail/em-utils.c156
3 files changed, 105 insertions, 86 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index f50ae11b98..75b68a8981 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,17 @@
+2007-04-18 Matthew Barnes <mbarnes@redhat.com>
+
+ ** Fixes bug #423766
+
+ * em-format-html-display.c (attachments_save_all_clicked):
+ Call em_utils_save_part() if there's only one attachment to save.
+
+ * em-utils.c (em_utils_save_part):
+ Refactor to use gtk_dialog_run() instead of a "response" callback.
+
+ * em-utils.c (em_utils_save_parts):
+ Refactor to use gtk_dialog_run() instead of a "response" callback.
+ Use gtk_file_chooser_get_uri() to fetch the selected folder.
+
2007-04-11 Srinivasa Ragavan <sragavan@novell.com>
* em-folder-view.c: (emfv_spin), (emfv_message_selected_timeout): Add
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index e35db056c4..d4c7a01d11 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -2098,12 +2098,26 @@ attachment_bar_arrow_clicked(GtkWidget *w, EMFormatHTMLDisplay *efhd)
}
static void
-attachments_save_all_clicked(GtkWidget *w, EMFormatHTMLDisplay *efhd)
+attachments_save_all_clicked (GtkWidget *widget, EMFormatHTMLDisplay *efhd)
{
GSList *attachment_parts;
+ guint n_attachment_parts;
- attachment_parts = e_attachment_bar_get_parts(E_ATTACHMENT_BAR(efhd->priv->attachment_bar));
- em_utils_save_parts(w, _("Select folder to save all attachments..."), attachment_parts);
+ attachment_parts = e_attachment_bar_get_parts (
+ E_ATTACHMENT_BAR (efhd->priv->attachment_bar));
+ n_attachment_parts = g_slist_length (attachment_parts);
+ g_return_if_fail (n_attachment_parts > 0);
+
+ if (n_attachment_parts == 1)
+ em_utils_save_part (
+ widget, _("Save attachment as"),
+ attachment_parts->data);
+ else
+ em_utils_save_parts (
+ widget, _("Select folder to save all attachments"),
+ attachment_parts);
+
+ g_slist_free (attachment_parts);
}
static void
@@ -2143,6 +2157,7 @@ efhd_bar_save_selected(EPopup *ep, EPopupItem *item, void *data)
parts = g_slist_reverse(parts);
em_utils_save_parts(efhd->priv->attachment_bar, _("Select folder to save selected attachments..."), parts);
+ g_slist_free (parts);
g_slist_foreach(attachment_parts, (GFunc)g_object_unref, NULL);
g_slist_free (attachment_parts);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 4b0ff0bd8a..98be4854df 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -354,28 +354,23 @@ em_filename_make_safe (gchar *string)
/* Saving messages... */
-static void
-emu_save_part_response(GtkWidget *filesel, int response, CamelMimePart *part)
+static const gchar *
+emu_save_get_filename_for_part (CamelMimePart *part)
{
- char *uri;
-
- if (response == GTK_RESPONSE_OK) {
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (filesel));
+ const gchar *filename;
- if (!e_file_can_save((GtkWindow *)filesel, uri)) {
- g_free(uri);
- return;
- }
-
- e_file_update_save_path(gtk_file_chooser_get_current_folder_uri(
- GTK_FILE_CHOOSER(filesel)), TRUE);
- /* FIXME: popup error if it fails? */
- mail_save_part(part, uri, NULL, NULL, FALSE);
- g_free(uri);
+ filename = camel_mime_part_get_filename (part);
+ if (filename == NULL) {
+ if (CAMEL_IS_MIME_MESSAGE (part)) {
+ filename = camel_mime_message_get_subject (
+ CAMEL_MIME_MESSAGE (part));
+ if (filename == NULL)
+ filename = _("message");
+ } else
+ filename = _("attachment");
}
- gtk_widget_destroy((GtkWidget *)filesel);
- camel_object_unref(part);
+ return filename;
}
/**
@@ -387,83 +382,78 @@ emu_save_part_response(GtkWidget *filesel, int response, CamelMimePart *part)
* Saves a mime part to disk (prompting the user for filename).
**/
void
-em_utils_save_part(GtkWidget *parent, const char *prompt, CamelMimePart *part)
+em_utils_save_part (GtkWidget *parent, const char *prompt, CamelMimePart *part)
{
- const char *name;
- GtkWidget *filesel;
+ GtkWidget *file_chooser;
+ const gchar *filename;
+ gchar *uri = NULL;
- name = camel_mime_part_get_filename(part);
- if (name == NULL) {
- if (CAMEL_IS_MIME_MESSAGE(part)) {
- name = camel_mime_message_get_subject((CamelMimeMessage *)part);
- if (name == NULL)
- name = _("message");
- } else {
- name = _("attachment");
- }
+ filename = emu_save_get_filename_for_part (part);
+
+ file_chooser = e_file_get_save_filesel (
+ parent, prompt, filename, GTK_FILE_CHOOSER_ACTION_SAVE);
+
+ if (gtk_dialog_run (GTK_DIALOG (file_chooser)) != GTK_RESPONSE_OK)
+ goto exit;
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_chooser));
+
+ /* XXX Would be nice to mention _why_ we can't save. */
+ if (!e_file_can_save (GTK_WINDOW (file_chooser), uri)) {
+ g_warning ("Unable to save %s", uri);
+ goto exit;
}
- filesel = e_file_get_save_filesel(parent, prompt, name, GTK_FILE_CHOOSER_ACTION_SAVE);
- camel_object_ref(part);
- g_signal_connect (filesel, "response", G_CALLBACK (emu_save_part_response), part);
- gtk_widget_show (filesel);
+ e_file_update_save_path (
+ gtk_file_chooser_get_current_folder_uri (
+ GTK_FILE_CHOOSER (file_chooser)), TRUE);
+
+ mail_save_part (part, uri, NULL, NULL, FALSE);
+
+exit:
+ gtk_widget_destroy (file_chooser);
+ g_free (uri);
}
-static void
-emu_save_parts_response (GtkWidget *filesel, int response, GSList *parts)
+void
+em_utils_save_parts (GtkWidget *parent, const gchar *prompt, GSList *parts)
{
- GSList *selected;
- char *uri = NULL;
- if (response == GTK_RESPONSE_OK) {
- uri = gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER (filesel));
- e_file_update_save_path(uri, FALSE);
-
- for ( selected = parts; selected != NULL; selected = selected->next) {
- const char *file_name;
- char *safe_name = NULL;
- char *file_path;
- CamelMimePart *part = selected->data;
-
- file_name = camel_mime_part_get_filename(part);
- if (file_name == NULL) {
- if (CAMEL_IS_MIME_MESSAGE(part)) {
- file_name = camel_mime_message_get_subject((CamelMimeMessage *)part);
- if (file_name == NULL)
- file_name = _("message");
- } else {
- file_name = _("attachment");
- }
- } else {
- safe_name = g_strdup(file_name);
- em_filename_make_safe(safe_name);
- file_name = safe_name;
- }
-
- file_path = g_build_filename (uri, file_name, NULL);
- if (!e_file_check_local(file_path) || !g_file_test(file_path, (G_FILE_TEST_EXISTS)) || e_error_run(NULL, E_ERROR_ASK_FILE_EXISTS_OVERWRITE, file_name, NULL) == GTK_RESPONSE_OK)
- mail_save_part(part, file_path, NULL, NULL, FALSE);
- else
- g_warning ("Could not save %s. File already exists", file_path);
+ GtkWidget *file_chooser;
+ gchar *path_uri;
+ GSList *iter;
+
+ file_chooser = e_file_get_save_filesel (
+ parent, prompt, NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+ if (gtk_dialog_run (GTK_DIALOG (file_chooser)) != GTK_RESPONSE_OK)
+ goto exit;
+
+ path_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_chooser));
+
+ e_file_update_save_path (path_uri, FALSE);
- g_free (file_path);
- g_free (safe_name);
- }
+ for (iter = parts; iter != NULL; iter = iter->next) {
+ CamelMimePart *part = iter->data;
+ const gchar *filename;
+ gchar *uri;
+
+ filename = emu_save_get_filename_for_part (part);
+
+ uri = g_build_path ("/", path_uri, filename, NULL);
+
+ /* XXX Would be nice to mention _why_ we can't save. */
+ if (e_file_can_save (GTK_WINDOW (file_chooser), uri))
+ mail_save_part (part, uri, NULL, NULL, FALSE);
+ else
+ g_warning ("Unable to save %s", uri);
g_free (uri);
- }
-
- g_slist_free (parts);
- gtk_widget_destroy((GtkWidget *)filesel);
-}
+ }
-void
-em_utils_save_parts (GtkWidget *parent, const char *prompt, GSList * parts)
-{
- GtkWidget *filesel;
+ g_free (path_uri);
- filesel = e_file_get_save_filesel (parent, prompt, NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
- g_signal_connect (filesel, "response", G_CALLBACK (emu_save_parts_response), parts);
- gtk_widget_show (filesel);
+exit:
+ gtk_widget_destroy (file_chooser);
}