[evolution] Bug 793240 - Let open attachments in default application easily
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 793240 - Let open attachments in default application easily
- Date: Tue, 13 Feb 2018 17:35:00 +0000 (UTC)
commit c2b43b3f3024bb6106a17159065404b4716b57f1
Author: Milan Crha <mcrha redhat com>
Date: Tue Feb 13 18:35:50 2018 +0100
Bug 793240 - Let open attachments in default application easily
src/e-util/e-attachment.c | 24 +++++++++++-
src/e-util/e-attachment.h | 1 +
src/em-format/e-mail-formatter-attachment.c | 7 ++-
src/mail/e-mail-display.c | 56 ++++++++++++++++++++++++++-
4 files changed, 82 insertions(+), 6 deletions(-)
---
diff --git a/src/e-util/e-attachment.c b/src/e-util/e-attachment.c
index 511c7d2..156e95c 100644
--- a/src/e-util/e-attachment.c
+++ b/src/e-util/e-attachment.c
@@ -1684,6 +1684,28 @@ e_attachment_is_rfc822 (EAttachment *attachment)
return is_rfc822;
}
+GAppInfo *
+e_attachment_ref_default_app (EAttachment *attachment)
+{
+ GFileInfo *file_info;
+ GAppInfo *default_app = NULL;
+ const gchar *content_type;
+
+ g_return_val_if_fail (E_IS_ATTACHMENT (attachment), NULL);
+
+ file_info = e_attachment_ref_file_info (attachment);
+ if (file_info == NULL)
+ return NULL;
+
+ content_type = g_file_info_get_content_type (file_info);
+ if (content_type && !g_content_type_equals (content_type, "application/octet-stream"))
+ default_app = g_app_info_get_default_for_type (content_type, FALSE);
+
+ g_object_unref (file_info);
+
+ return default_app;
+}
+
GList *
e_attachment_list_apps (EAttachment *attachment)
{
@@ -1721,7 +1743,7 @@ e_attachment_list_apps (EAttachment *attachment)
g_free (allocated);
exit:
- default_app = g_app_info_get_default_for_type (content_type, FALSE);
+ default_app = e_attachment_ref_default_app (attachment);
if (default_app) {
GList *link;
diff --git a/src/e-util/e-attachment.h b/src/e-util/e-attachment.h
index 5fa662e..2a060a7 100644
--- a/src/e-util/e-attachment.h
+++ b/src/e-util/e-attachment.h
@@ -128,6 +128,7 @@ gchar * e_attachment_dup_description (EAttachment *attachment);
gchar * e_attachment_dup_thumbnail_path (EAttachment *attachment);
gboolean e_attachment_is_rfc822 (EAttachment *attachment);
GList * e_attachment_list_apps (EAttachment *attachment);
+GAppInfo * e_attachment_ref_default_app (EAttachment *attachment);
void e_attachment_update_store_columns
(EAttachment *attachment);
diff --git a/src/em-format/e-mail-formatter-attachment.c b/src/em-format/e-mail-formatter-attachment.c
index ad12eeb..8e88efe 100644
--- a/src/em-format/e-mail-formatter-attachment.c
+++ b/src/em-format/e-mail-formatter-attachment.c
@@ -260,7 +260,7 @@ emfe_attachment_format (EMailFormatterExtension *extension,
"<table width=\"100%%\" border=\"0\" style=\"border-spacing: 0px\">"
"<tr valign=\"middle\">"
"<td align=\"left\" width=\"1px\" style=\"white-space:pre;\">"
- "<button type=\"button\" class=\"attachment-expander\" id=\"%s\" value=\"%p\" data=\"%s\"
style=\"vertical-align:middle; margin:0px;\" %s>"
+ "<button type=\"button\" class=\"attachment-expander\" id=\"%s\" value=\"%p\" data=\"%s\"
style=\"vertical-align:middle; margin:0px;\">"
"<img id=\"attachment-expander-img-%p\" src=\"gtk-stock://%s?size=%d\" width=\"%dpx\"
height=\"%dpx\" style=\"vertical-align:middle;\">"
"<img src=\"%s\" width=\"%dpx\" height=\"%dpx\" style=\"vertical-align:middle;\">"
"</button>"
@@ -268,8 +268,9 @@ emfe_attachment_format (EMailFormatterExtension *extension,
"<img src=\"gtk-stock://x-evolution-arrow-down?size=%d\" width=\"%dpx\" height=\"%dpx\"
style=\"vertical-align:middle;\">"
"</button>"
"</td><td align=\"left\">%s</td></tr>",
- part_id, attachment_ptr, html, e_mail_part_attachment_get_expandable (empa) ? "" : "disabled",
- attachment_ptr, e_mail_part_should_show_inline (part) ? "go-down" : "go-next",
GTK_ICON_SIZE_BUTTON, icon_width, icon_height,
+ part_id, attachment_ptr, html, attachment_ptr,
+ e_mail_part_should_show_inline (part) ? "go-down" : e_mail_part_attachment_get_expandable
(empa) ? "go-next" : "go-top",
+ GTK_ICON_SIZE_BUTTON, icon_width, icon_height,
icon_uri, icon_width, icon_height,
part_id, attachment_ptr, GTK_ICON_SIZE_BUTTON, icon_width, icon_height,
html);
diff --git a/src/mail/e-mail-display.c b/src/mail/e-mail-display.c
index 126f8f9..b7d00a1 100644
--- a/src/mail/e-mail-display.c
+++ b/src/mail/e-mail-display.c
@@ -875,6 +875,21 @@ mail_display_ref_attachment_from_element (EMailDisplay *display,
}
static void
+call_attachment_save_handle_error (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GtkWindow *window = user_data;
+
+ g_return_if_fail (E_IS_ATTACHMENT (source_object));
+ g_return_if_fail (!window || GTK_IS_WINDOW (window));
+
+ e_attachment_save_handle_error (E_ATTACHMENT (source_object), result, window);
+
+ g_clear_object (&window);
+}
+
+static void
mail_display_attachment_expander_clicked_cb (EWebView *web_view,
const gchar *element_class,
const gchar *element_value,
@@ -893,8 +908,45 @@ mail_display_attachment_expander_clicked_cb (EWebView *web_view,
attachment = mail_display_ref_attachment_from_element (display, element_value);
if (attachment) {
- /* Flip the current 'visible' state */
- mail_display_change_one_attachment_visibility (display, attachment, FALSE, TRUE);
+ if (e_attachment_get_can_show (attachment)) {
+ /* Flip the current 'visible' state */
+ mail_display_change_one_attachment_visibility (display, attachment, FALSE, TRUE);
+ } else {
+ GAppInfo *default_app;
+ gpointer parent;
+
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
+ parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
+
+ /* Either open in the default application... */
+ default_app = e_attachment_ref_default_app (attachment);
+ if (default_app) {
+ e_attachment_open_async (
+ attachment, default_app, (GAsyncReadyCallback)
+ e_attachment_open_handle_error, parent);
+
+ g_object_unref (default_app);
+ } else {
+ /* ...or save it */
+ GList *attachments;
+ EAttachmentStore *store;
+ GFile *destination;
+
+ store = e_mail_display_get_attachment_store (display);
+ attachments = g_list_prepend (NULL, attachment);
+
+ destination = e_attachment_store_run_save_dialog (store, attachments, parent);
+ if (destination) {
+ e_attachment_save_async (
+ attachment, destination, (GAsyncReadyCallback)
+ call_attachment_save_handle_error, parent ? g_object_ref
(parent) : NULL);
+
+ g_object_unref (destination);
+ }
+
+ g_list_free (attachments);
+ }
+ }
}
g_clear_object (&attachment);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]