mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 03:02:10 +01:00
Move some portal support to its own files
This is better than copying these utility functions around to multiple places.
This commit is contained in:
parent
e8df162402
commit
de5b18dfc3
@ -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) \
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "glibintl.h"
|
||||
#include <gioerror.h>
|
||||
#include <gfile.h>
|
||||
#include "gportalsupport.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -669,26 +670,6 @@ g_app_info_should_show (GAppInfo *appinfo)
|
||||
return (* iface->should_show) (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,
|
||||
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
69
gio/gportalsupport.c
Normal file
69
gio/gportalsupport.c
Normal file
@ -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;
|
||||
}
|
||||
|
30
gio/gportalsupport.h
Normal file
30
gio/gportalsupport.h
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user