Add Friulian translation
[glib.git] / gio / gportalsupport.c
blob74cb270c47a7ece1c744b24a58102bbbfd46e474
1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright 2016 Red Hat, Inc.
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 of the License, or (at your option) any later version.
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.
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/>.
19 #include "config.h"
21 #include "gportalsupport.h"
23 static gboolean flatpak_info_read;
24 static gboolean use_portal;
25 static gboolean network_available;
27 static void
28 read_flatpak_info (void)
30 char *path;
32 if (flatpak_info_read)
33 return;
35 flatpak_info_read = TRUE;
37 path = g_build_filename (g_get_user_runtime_dir (), "flatpak-info", NULL);
38 if (g_file_test (path, G_FILE_TEST_EXISTS))
40 GKeyFile *keyfile;
42 use_portal = TRUE;
43 network_available = FALSE;
45 keyfile = g_key_file_new ();
46 if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL))
48 char **shared = NULL;
50 shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
51 if (shared)
53 network_available = g_strv_contains ((const char * const *)shared, "network");
54 g_strfreev (shared);
58 g_key_file_unref (keyfile);
60 else
62 const char *var;
64 var = g_getenv ("GTK_USE_PORTAL");
65 if (var && var[0] == '1')
66 use_portal = TRUE;
67 network_available = TRUE;
70 g_free (path);
73 gboolean
74 glib_should_use_portal (void)
76 read_flatpak_info ();
77 return use_portal;
80 gboolean
81 glib_network_available_in_sandbox (void)
83 read_flatpak_info ();
84 return network_available;