[evolution/gnome-3-30] I#169 - [Flatpak] Cannot open attachment directly from the attachments bar



commit ea604c187e0fd7e9881965e3a90913fadea765f3
Author: Milan Crha <mcrha redhat com>
Date:   Wed Nov 14 23:43:55 2018 +0100

    I#169 - [Flatpak] Cannot open attachment directly from the attachments bar
    
    Closes https://gitlab.gnome.org/GNOME/evolution/issues/169

 src/e-util/e-attachment-view.c | 45 +++++++++++++++++++++++++++++-------------
 src/e-util/e-misc-utils.c      | 27 +++++++++++++++++++++++++
 src/e-util/e-misc-utils.h      |  1 +
 src/mail/e-mail-display.c      |  2 +-
 4 files changed, 60 insertions(+), 15 deletions(-)
---
diff --git a/src/e-util/e-attachment-view.c b/src/e-util/e-attachment-view.c
index 0384451ff1..ff268dd543 100644
--- a/src/e-util/e-attachment-view.c
+++ b/src/e-util/e-attachment-view.c
@@ -164,7 +164,6 @@ action_open_with_app_info_cb (GtkAction *action,
        path = list->data;
 
        app_info = g_object_get_data (G_OBJECT (action), "app-info");
-       g_return_if_fail (G_IS_APP_INFO (app_info));
 
        e_attachment_view_open_path (view, path, app_info);
 
@@ -727,7 +726,7 @@ attachment_view_update_actions (EAttachmentView *view)
        gtk_action_set_visible (action, busy);
 
        action = e_attachment_view_get_action (view, "open-with");
-       gtk_action_set_visible (action, !busy && n_selected == 1);
+       gtk_action_set_visible (action, !busy && n_selected == 1 && !e_util_is_running_flatpak ());
 
        action = e_attachment_view_get_action (view, "properties");
        gtk_action_set_visible (action, !busy && n_selected == 1);
@@ -751,6 +750,9 @@ attachment_view_update_actions (EAttachmentView *view)
 
        list = e_attachment_list_apps (attachment);
 
+       if (!list && e_util_is_running_flatpak ())
+               list = g_list_prepend (list, NULL);
+
        for (iter = list; iter != NULL; iter = iter->next) {
                GAppInfo *app_info = iter->data;
                GtkAction *action;
@@ -761,9 +763,15 @@ attachment_view_update_actions (EAttachmentView *view)
                gchar *action_label;
                gchar *action_name;
 
-               app_id = g_app_info_get_id (app_info);
-               app_icon = g_app_info_get_icon (app_info);
-               app_name = g_app_info_get_name (app_info);
+               if (app_info) {
+                       app_id = g_app_info_get_id (app_info);
+                       app_icon = g_app_info_get_icon (app_info);
+                       app_name = g_app_info_get_name (app_info);
+               } else {
+                       app_id = "org.gnome.evolution.flatpak.default-app";
+                       app_icon = NULL;
+                       app_name = NULL;
+               }
 
                if (app_id == NULL)
                        continue;
@@ -774,21 +782,25 @@ attachment_view_update_actions (EAttachmentView *view)
 
                action_name = g_strdup_printf ("open-with-%s", app_id);
 
-               action_label = g_strdup_printf (
-                       _("Open With ā€œ%sā€"), app_name);
-
-               action_tooltip = g_strdup_printf (
-                       _("Open this attachment in %s"), app_name);
+               if (app_info) {
+                       action_label = g_strdup_printf (_("Open With ā€œ%sā€"), app_name);
+                       action_tooltip = g_strdup_printf (_("Open this attachment in %s"), app_name);
+               } else {
+                       action_label = g_strdup (_("Open With Other Application..."));
+                       action_tooltip = NULL;
+               }
 
                action = gtk_action_new (
                        action_name, action_label, action_tooltip, NULL);
 
                gtk_action_set_gicon (action, app_icon);
 
-               g_object_set_data_full (
-                       G_OBJECT (action),
-                       "app-info", g_object_ref (app_info),
-                       (GDestroyNotify) g_object_unref);
+               if (app_info) {
+                       g_object_set_data_full (
+                               G_OBJECT (action),
+                               "app-info", g_object_ref (app_info),
+                               (GDestroyNotify) g_object_unref);
+               }
 
                g_object_set_data_full (
                        G_OBJECT (action),
@@ -809,6 +821,11 @@ attachment_view_update_actions (EAttachmentView *view)
                g_free (action_name);
                g_free (action_label);
                g_free (action_tooltip);
+
+               if (!app_info) {
+                       list = g_list_remove (list, app_info);
+                       break;
+               }
        }
 
        g_list_free_full (list, g_object_unref);
diff --git a/src/e-util/e-misc-utils.c b/src/e-util/e-misc-utils.c
index fffd9207bf..c6a3db3372 100644
--- a/src/e-util/e-misc-utils.c
+++ b/src/e-util/e-misc-utils.c
@@ -3450,6 +3450,33 @@ e_util_is_running_gnome (void)
 #endif
 }
 
+/**
+ * e_util_is_running_flatpak:
+ *
+ * Returns: Whether running in Flatpak.
+ *
+ * Since: 3.30.3
+ **/
+gboolean
+e_util_is_running_flatpak (void)
+{
+#ifdef G_OS_UNIX
+       static gint is_flatpak = -1;
+
+       if (is_flatpak == -1) {
+               if (g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS) ||
+                   g_getenv ("EVOLUTION_FLATPAK") != NULL) /* Only for debugging purposes */
+                       is_flatpak = 1;
+               else
+                       is_flatpak = 0;
+       }
+
+       return is_flatpak == 1;
+#else
+       return FALSE;
+#endif
+}
+
 /**
  * e_util_set_entry_issue_hint:
  * @entry: a #GtkEntry
diff --git a/src/e-util/e-misc-utils.h b/src/e-util/e-misc-utils.h
index e170e1993c..abb7d209d9 100644
--- a/src/e-util/e-misc-utils.h
+++ b/src/e-util/e-misc-utils.h
@@ -290,6 +290,7 @@ void                e_util_run_simple_async_result_in_thread
                                                 GSimpleAsyncThreadFunc func,
                                                 GCancellable *cancellable);
 gboolean       e_util_is_running_gnome         (void);
+gboolean       e_util_is_running_flatpak       (void);
 void           e_util_set_entry_issue_hint     (GtkWidget *entry,
                                                 const gchar *hint);
 
diff --git a/src/mail/e-mail-display.c b/src/mail/e-mail-display.c
index bf1623a734..458e9731d0 100644
--- a/src/mail/e-mail-display.c
+++ b/src/mail/e-mail-display.c
@@ -932,7 +932,7 @@ mail_display_attachment_expander_clicked_cb (EWebView *web_view,
 
                        /* Either open in the default application... */
                        default_app = e_attachment_ref_default_app (attachment);
-                       if (default_app) {
+                       if (default_app || e_util_is_running_flatpak ()) {
                                e_attachment_open_async (
                                        attachment, default_app, (GAsyncReadyCallback)
                                        e_attachment_open_handle_error, parent);


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