1/* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright 2016 Red Hat, Inc.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "config.h"
20
21#include "gportalsupport.h"
22
23static gboolean use_portal;
24static gboolean network_available;
25static gboolean dconf_access;
26
27static void
28read_flatpak_info (void)
29{
30 static gsize flatpak_info_read = 0;
31 const gchar *path = "/.flatpak-info";
32
33 if (!g_once_init_enter (&flatpak_info_read))
34 return;
35
36 if (g_file_test (filename: path, test: G_FILE_TEST_EXISTS))
37 {
38 GKeyFile *keyfile;
39
40 use_portal = TRUE;
41 network_available = FALSE;
42 dconf_access = FALSE;
43
44 keyfile = g_key_file_new ();
45 if (g_key_file_load_from_file (key_file: keyfile, file: path, flags: G_KEY_FILE_NONE, NULL))
46 {
47 char **shared = NULL;
48 char *dconf_policy = NULL;
49
50 shared = g_key_file_get_string_list (key_file: keyfile, group_name: "Context", key: "shared", NULL, NULL);
51 if (shared)
52 {
53 network_available = g_strv_contains (strv: (const char * const *)shared, str: "network");
54 g_strfreev (str_array: shared);
55 }
56
57 dconf_policy = g_key_file_get_string (key_file: keyfile, group_name: "Session Bus Policy", key: "ca.desrt.dconf", NULL);
58 if (dconf_policy)
59 {
60 if (strcmp (s1: dconf_policy, s2: "talk") == 0)
61 dconf_access = TRUE;
62 g_free (mem: dconf_policy);
63 }
64 }
65
66 g_key_file_unref (key_file: keyfile);
67 }
68 else
69 {
70 const char *var;
71
72 var = g_getenv (variable: "GTK_USE_PORTAL");
73 if (var && var[0] == '1')
74 use_portal = TRUE;
75 network_available = TRUE;
76 dconf_access = TRUE;
77 }
78
79 g_once_init_leave (&flatpak_info_read, 1);
80}
81
82gboolean
83glib_should_use_portal (void)
84{
85 read_flatpak_info ();
86 return use_portal;
87}
88
89gboolean
90glib_network_available_in_sandbox (void)
91{
92 read_flatpak_info ();
93 return network_available;
94}
95
96gboolean
97glib_has_dconf_access_in_sandbox (void)
98{
99 read_flatpak_info ();
100 return dconf_access;
101}
102

source code of gtk/subprojects/glib/gio/gportalsupport.c