[eog/use-appchooser-and-portals: 3/3] EogWindow: Use Portals for "Open With" when possible
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog/use-appchooser-and-portals: 3/3] EogWindow: Use Portals for "Open With" when possible
- Date: Mon, 22 Jun 2020 12:58:05 +0000 (UTC)
commit 101e91210fce05fbaf8e1caa32ab8157d7082954
Author: Felipe Borges <felipeborges gnome org>
Date: Fri Mar 27 13:20:40 2020 +0100
EogWindow: Use Portals for "Open With" when possible
If we detect that Eog is running inside a Flatpak container, we
can use the OpenURI Portal[0] to open an AppChooser dialog for
the user to pick an appliation.
[0] https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-org.freedesktop.portal.OpenURI
Fixes #98
src/eog-util.c | 42 ++++++++++++++++++++++++++++++++++++++++++
src/eog-util.h | 7 +++++++
src/eog-window.c | 31 +++++++++++++++++++++----------
3 files changed, 70 insertions(+), 10 deletions(-)
---
diff --git a/src/eog-util.c b/src/eog-util.c
index a6828a58..6fd3239e 100644
--- a/src/eog-util.c
+++ b/src/eog-util.c
@@ -43,6 +43,8 @@
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib/gi18n.h>
+#include <libportal/portal.h>
+#include <libportal/portal-gtk3.h>
void
eog_util_show_help (const gchar *section, GtkWindow *parent)
@@ -503,3 +505,43 @@ eog_util_show_file_in_filemanager (GFile *file, GtkWindow *toplevel)
if (!done)
_eog_util_show_file_in_filemanager_fallback (file, toplevel);
}
+
+/* Portal */
+
+gboolean
+eog_util_is_running_inside_flatpak (void)
+{
+ return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS);
+}
+
+static void
+open_with_flatpak_portal_cb (GObject *source, GAsyncResult *result, gpointer user_data)
+{
+ XdpPortal *portal = XDP_PORTAL (source);
+ g_autoptr(GError) error = NULL;
+
+ if (!xdp_portal_open_uri_finish (portal, result, &error))
+ {
+ g_warning ("Failed to open file via portal: %s", error->message);
+ }
+}
+
+void
+eog_util_open_file_with_flatpak_portal (GFile *file, GtkWindow *window)
+{
+ g_autoptr(XdpPortal) portal = NULL;
+ g_autofree gchar *uri = NULL;
+ XdpParent *parent = NULL;
+
+ portal = xdp_portal_new ();
+ parent = xdp_parent_new_gtk (window);
+ uri = g_file_get_uri (file);
+
+ xdp_portal_open_uri (portal,
+ parent,
+ uri,
+ XDP_OPEN_URI_FLAG_ASK,
+ NULL,
+ open_with_flatpak_portal_cb,
+ parent);
+}
diff --git a/src/eog-util.h b/src/eog-util.h
index 9f2ad4c1..a87c97c3 100644
--- a/src/eog-util.h
+++ b/src/eog-util.h
@@ -69,6 +69,13 @@ G_GNUC_INTERNAL
void eog_util_show_file_in_filemanager (GFile *file,
GtkWindow *toplevel);
+G_GNUC_INTERNAL
+gboolean eog_util_is_running_inside_flatpak (void);
+
+G_GNUC_INTERNAL
+void eog_util_open_file_with_flatpak_portal (GFile *file,
+ GtkWindow *window);
+
G_END_DECLS
#endif /* __EOG_UTIL_H__ */
diff --git a/src/eog-window.c b/src/eog-window.c
index e84a2b91..32ef8347 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -1070,23 +1070,15 @@ out:
}
static void
-eog_window_action_open_with (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+eog_window_open_file_chooser_dialog (EogWindow *window)
{
- EogWindow *window;
GtkWidget *dialog;
GFileInfo *file_info;
GFile *file;
const gchar *mime_type = NULL;
- g_return_if_fail (EOG_IS_WINDOW (user_data));
- window = EOG_WINDOW (user_data);
-
file = eog_image_get_file (window->priv->image);
- file_info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- 0, NULL, NULL);
+ file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL);
mime_type = g_content_type_get_mime_type (
g_file_info_get_content_type (file_info));
g_object_unref (file_info);
@@ -1105,6 +1097,25 @@ eog_window_action_open_with (GSimpleAction *action,
g_object_unref (file);
}
+static void
+eog_window_action_open_with (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ EogWindow *window;
+
+ g_return_if_fail (EOG_IS_WINDOW (user_data));
+ window = EOG_WINDOW (user_data);
+
+ if (eog_util_is_running_inside_flatpak ()) {
+ GFile *file = eog_image_get_file (window->priv->image);
+
+ eog_util_open_file_with_flatpak_portal (file, GTK_WINDOW (window));
+ } else {
+ eog_window_open_file_chooser_dialog (window);
+ }
+}
+
static void
eog_window_clear_load_job (EogWindow *window)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]