[recipes] Move the portal check around
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Move the portal check around
- Date: Wed, 18 Jan 2017 17:48:20 +0000 (UTC)
commit 645f5729d0ec6e16d5d2acf1841b837e3ff156fe
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jan 18 07:36:22 2017 -0500
Move the portal check around
We will use this in more places, so make it available
as a utility.
src/gr-app.c | 25 ++++++++++++++++++++++++-
src/gr-app.h | 1 +
src/gr-image-viewer.c | 18 +-----------------
src/gr-utils.c | 6 ++++++
src/gr-utils.h | 1 +
5 files changed, 33 insertions(+), 18 deletions(-)
---
diff --git a/src/gr-app.c b/src/gr-app.c
index 0671504..1e74bc8 100644
--- a/src/gr-app.c
+++ b/src/gr-app.c
@@ -38,6 +38,7 @@ struct _GrApp
GrRecipeStore *store;
GrShellSearchProvider *search_provider;
+ GDBusProxy *portal;
};
G_DEFINE_TYPE (GrApp, gr_app, GTK_TYPE_APPLICATION)
@@ -50,7 +51,7 @@ gr_app_finalize (GObject *object)
g_clear_object (&self->store);
g_clear_object (&self->search_provider);
-
+ g_clear_object (&self->portal);
G_OBJECT_CLASS (gr_app_parent_class)->finalize (object);
}
@@ -928,7 +929,20 @@ gr_app_dbus_unregister (GApplication *application,
static void
gr_app_init (GrApp *self)
{
+ g_autoptr(GDBusConnection) bus = NULL;
+
self->store = gr_recipe_store_new ();
+
+ bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ self->portal = g_dbus_proxy_new_sync (bus,
+ 0,
+ NULL,
+ "org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.FileChooser",
+ NULL,
+ NULL);
+
}
static void
@@ -960,3 +974,12 @@ gr_app_get_recipe_store (GrApp *app)
{
return app->store;
}
+
+gboolean
+gr_app_portals_available (GrApp *app)
+{
+ g_autofree char *owner = NULL;
+
+ owner = g_dbus_proxy_get_name_owner (app->portal);
+ return owner != NULL;
+}
diff --git a/src/gr-app.h b/src/gr-app.h
index 6db6956..30e8b7a 100644
--- a/src/gr-app.h
+++ b/src/gr-app.h
@@ -29,5 +29,6 @@ G_DECLARE_FINAL_TYPE (GrApp, gr_app, GR, APP, GtkApplication)
GrApp *gr_app_new (void);
GrRecipeStore *gr_app_get_recipe_store (GrApp *app);
+gboolean gr_app_portals_available (GrApp *app);
G_END_DECLS
diff --git a/src/gr-image-viewer.c b/src/gr-image-viewer.c
index 5b9adbd..51dea5a 100644
--- a/src/gr-image-viewer.c
+++ b/src/gr-image-viewer.c
@@ -47,7 +47,6 @@ struct _GrImageViewer
guint hide_timeout;
GtkGesture *gesture;
- GDBusProxy *portal;
};
@@ -83,7 +82,6 @@ gr_image_viewer_finalize (GObject *object)
g_clear_pointer (&viewer->images, g_array_unref);
remove_hide_timeout (viewer);
g_clear_object (&viewer->gesture);
- g_clear_object (&viewer->portal);
G_OBJECT_CLASS (gr_image_viewer_parent_class)->finalize (object);
}
@@ -322,8 +320,6 @@ key_press_event (GtkWidget *widget,
static void
gr_image_viewer_init (GrImageViewer *self)
{
- g_autoptr(GDBusConnection) bus = NULL;
-
gtk_widget_init_template (GTK_WIDGET (self));
gtk_widget_add_events (GTK_WIDGET (self->event_box), GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
GDK_POINTER_MOTION_MASK);
gtk_widget_add_events (GTK_WIDGET (self->event_box), GDK_BUTTON_PRESS_MASK);
@@ -337,16 +333,6 @@ gr_image_viewer_init (GrImageViewer *self)
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (self->gesture), GTK_PHASE_BUBBLE);
g_signal_connect_swapped (self->gesture, "pressed", G_CALLBACK (button_press), self);
self->images = gr_rotated_image_array_new ();
-
- bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
- self->portal = g_dbus_proxy_new_sync (bus,
- 0,
- NULL,
- "org.freedesktop.portal.Desktop",
- "/org/freedesktop/portal/desktop",
- "org.freedesktop.portal.FileChooser",
- NULL,
- NULL);
}
static void
@@ -489,12 +475,10 @@ open_filechooser (GrImageViewer *viewer)
GtkWidget *window;
GtkFileChooserNative *chooser;
g_autoptr(GtkFileFilter) filter = NULL;
- g_autofree char *owner = NULL;
window = gtk_widget_get_ancestor (GTK_WIDGET (viewer), GTK_TYPE_APPLICATION_WINDOW);
- owner = g_dbus_proxy_get_name_owner (viewer->portal);
- if (in_flatpak_sandbox () && owner == NULL) {
+ if (in_flatpak_sandbox () && !portals_available ()) {
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
diff --git a/src/gr-utils.c b/src/gr-utils.c
index f9a2560..119b1e4 100644
--- a/src/gr-utils.c
+++ b/src/gr-utils.c
@@ -25,6 +25,7 @@
#include <stdarg.h>
#include "gr-utils.h"
+#include "gr-app.h"
/* load image rotated by angle to fit in width x height while preserving
* aspect ratio, filling seams with transparency
@@ -432,3 +433,8 @@ in_flatpak_sandbox (void)
return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS);
}
+gboolean
+portals_available (void)
+{
+ return gr_app_portals_available (GR_APP (g_application_get_default ()));
+}
diff --git a/src/gr-utils.h b/src/gr-utils.h
index d43e8db..174d191 100644
--- a/src/gr-utils.h
+++ b/src/gr-utils.h
@@ -58,3 +58,4 @@ void stop_recording (void);
void record_step (const char *blurb);
gboolean in_flatpak_sandbox (void);
+gboolean portals_available (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]