summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2016-06-21 23:15:25 -0400
committerMatthias Clasen <mclasen@redhat.com>2016-07-03 18:01:45 -0400
commitde5b18dfc38fa2105d5ba6057e5bfa8e5a0fadd8 (patch)
treee47ea6e45c74627b340dd19330fe37ec1b62d68d
parente8df162402d1bcae52f3f25a3fbd071a45ace4a9 (diff)
downloadglib-de5b18dfc38fa2105d5ba6057e5bfa8e5a0fadd8.tar.gz
Move some portal support to its own files
This is better than copying these utility functions around to multiple places.
-rw-r--r--gio/Makefile.am2
-rw-r--r--gio/gappinfo.c23
-rw-r--r--gio/gnetworkmonitorportal.c45
-rw-r--r--gio/gportalsupport.c69
-rw-r--r--gio/gportalsupport.h30
5 files changed, 106 insertions, 63 deletions
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 58d51b8ff..dd5039999 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -354,6 +354,8 @@ $(xdp_dbus_built_sources) : $(srcdir)/org.freedesktop.portal.NetworkMonitor.xml
$(NULL)
portal_sources = \
+ gportalsupport.c \
+ gportalsupport.h \
gnetworkmonitorportal.c \
gnetworkmonitorportal.h \
$(xdp_dbus_built_sources) \
diff --git a/gio/gappinfo.c b/gio/gappinfo.c
index 963607b2a..0ea80510f 100644
--- a/gio/gappinfo.c
+++ b/gio/gappinfo.c
@@ -31,6 +31,7 @@
#include "glibintl.h"
#include <gioerror.h>
#include <gfile.h>
+#include "gportalsupport.h"
/**
@@ -670,26 +671,6 @@ g_app_info_should_show (GAppInfo *appinfo)
}
static gboolean
-should_use_portal (void)
-{
- const char *use_portal;
- char *path;
-
- path = g_strdup_printf ("/run/user/%d/flatpak-info", getuid());
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- use_portal = "1";
- else
- {
- use_portal = g_getenv ("GTK_USE_PORTAL");
- if (!use_portal)
- use_portal = "";
- }
- g_free (path);
-
- return g_str_equal (use_portal, "1");
-}
-
-static gboolean
launch_default_with_portal (const char *uri,
GAppLaunchContext *context,
GError **error)
@@ -754,7 +735,7 @@ g_app_info_launch_default_for_uri (const char *uri,
GList l;
gboolean res;
- if (should_use_portal ())
+ if (glib_should_use_portal ())
return launch_default_with_portal (uri, launch_context, error);
/* g_file_query_default_handler() calls
diff --git a/gio/gnetworkmonitorportal.c b/gio/gnetworkmonitorportal.c
index 655f787c5..d56c7fb76 100644
--- a/gio/gnetworkmonitorportal.c
+++ b/gio/gnetworkmonitorportal.c
@@ -23,6 +23,7 @@
#include "giomodule-priv.h"
#include "gnetworkmonitor.h"
#include "xdp-dbus.h"
+#include "gportalsupport.h"
static void g_network_monitor_portal_iface_init (GNetworkMonitorInterface *iface);
@@ -104,46 +105,6 @@ proxy_changed (XdpNetworkMonitor *proxy,
g_signal_emit_by_name (nm, "network-changed", available);
}
-
-static gboolean
-should_use_portal (void)
-{
- const char *use_portal;
- char *path;
-
- path = g_strdup_printf ("/run/user/%d/flatpak-info", getuid());
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- use_portal = "1";
- else
- {
- use_portal = g_getenv ("GTK_USE_PORTAL");
- if (!use_portal)
- use_portal = "";
- }
- g_free (path);
-
- return g_str_equal (use_portal, "1");
-}
-
-static gboolean
-network_available_in_sandbox (void)
-{
- char *path;
- g_autoptr(GKeyFile) keyfile = g_key_file_new ();
-
- path = g_strdup_printf ("/run/user/%d/flatpak-info", getuid());
- if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL))
- {
- g_auto(GStrv) shared = NULL;
-
- shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
-
- return g_strv_contains ((const char * const *)shared, "network");
- }
-
- return TRUE;
-}
-
static gboolean
g_network_monitor_portal_initable_init (GInitable *initable,
GCancellable *cancellable,
@@ -153,7 +114,7 @@ g_network_monitor_portal_initable_init (GInitable *initable,
XdpNetworkMonitor *proxy;
gchar *name_owner = NULL;
- if (!should_use_portal ())
+ if (!glib_should_use_portal ())
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Not using portals");
return FALSE;
@@ -181,7 +142,7 @@ g_network_monitor_portal_initable_init (GInitable *initable,
g_signal_connect (G_OBJECT (proxy), "changed", G_CALLBACK (proxy_changed), nm);
nm->priv->proxy = proxy;
- nm->priv->network_available = network_available_in_sandbox ();
+ nm->priv->network_available = glib_network_available_in_sandbox ();
return TRUE;
}
diff --git a/gio/gportalsupport.c b/gio/gportalsupport.c
new file mode 100644
index 000000000..d7ba523c8
--- /dev/null
+++ b/gio/gportalsupport.c
@@ -0,0 +1,69 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <unistd.h>
+
+#include "gportalsupport.h"
+
+gboolean
+glib_should_use_portal (void)
+{
+ const char *use_portal;
+ char *path;
+
+ path = g_strdup_printf ("/run/user/%d/flatpak-info", getuid());
+ if (g_file_test (path, G_FILE_TEST_EXISTS))
+ use_portal = "1";
+ else
+ {
+ use_portal = g_getenv ("GTK_USE_PORTAL");
+ if (!use_portal)
+ use_portal = "";
+ }
+ g_free (path);
+
+ return g_str_equal (use_portal, "1");
+}
+
+gboolean
+glib_network_available_in_sandbox (void)
+{
+ char *path;
+ GKeyFile *keyfile;
+ gboolean available = TRUE;
+
+ path = g_strdup_printf ("/run/user/%d/flatpak-info", getuid());
+
+ keyfile = g_key_file_new ();
+ if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL))
+ {
+ char **shared = NULL;
+
+ shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
+ available = g_strv_contains ((const char * const *)shared, "network");
+ g_strfreev (shared);
+ }
+
+ g_key_file_free (keyfile);
+ g_free (path);
+
+ return available;
+}
+
diff --git a/gio/gportalsupport.h b/gio/gportalsupport.h
new file mode 100644
index 000000000..a92e07ca7
--- /dev/null
+++ b/gio/gportalsupport.h
@@ -0,0 +1,30 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __G_PORTAL_SUPPORT_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean glib_should_use_portal (void);
+gboolean glib_network_available_in_sandbox (void);
+
+G_END_DECLS
+
+#endif