Blame gio/gportalsupport.c

Packit 84794d
/* GIO - GLib Input, Output and Streaming Library
Packit 84794d
 *
Packit 84794d
 * Copyright 2016 Red Hat, Inc.
Packit 84794d
 *
Packit 84794d
 * This library is free software; you can redistribute it and/or
Packit 84794d
 * modify it under the terms of the GNU Lesser General Public
Packit 84794d
 * License as published by the Free Software Foundation; either
Packit 84794d
 * version 2.1 of the License, or (at your option) any later version.
Packit 84794d
 *
Packit 84794d
 * This library is distributed in the hope that it will be useful,
Packit 84794d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 84794d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 84794d
 * Lesser General Public License for more details.
Packit 84794d
 *
Packit 84794d
 * You should have received a copy of the GNU Lesser General
Packit 84794d
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit 84794d
 */
Packit 84794d
Packit 84794d
#include "config.h"
Packit 84794d
Packit 84794d
#include "gportalsupport.h"
Packit 84794d
Packit 84794d
static gboolean flatpak_info_read;
Packit 84794d
static gboolean use_portal;
Packit 84794d
static gboolean network_available;
Packit 84794d
Packit 84794d
static void
Packit 84794d
read_flatpak_info (void)
Packit 84794d
{
Packit 84794d
  const gchar *path = "/.flatpak-info";
Packit 84794d
Packit 84794d
  if (flatpak_info_read)
Packit 84794d
    return;
Packit 84794d
Packit 84794d
  flatpak_info_read = TRUE;
Packit 84794d
Packit 84794d
  if (g_file_test (path, G_FILE_TEST_EXISTS))
Packit 84794d
    {
Packit 84794d
      GKeyFile *keyfile;
Packit 84794d
Packit 84794d
      use_portal = TRUE;
Packit 84794d
      network_available = FALSE;
Packit 84794d
Packit 84794d
      keyfile = g_key_file_new ();
Packit 84794d
      if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL))
Packit 84794d
        {
Packit 84794d
          char **shared = NULL;
Packit 84794d
Packit 84794d
          shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
Packit 84794d
          if (shared)
Packit 84794d
            {
Packit 84794d
              network_available = g_strv_contains ((const char * const *)shared, "network");
Packit 84794d
              g_strfreev (shared);
Packit 84794d
            }
Packit 84794d
        }
Packit 84794d
Packit 84794d
      g_key_file_unref (keyfile);
Packit 84794d
    }
Packit 84794d
  else
Packit 84794d
    {
Packit 84794d
      const char *var;
Packit 84794d
Packit 84794d
      var = g_getenv ("GTK_USE_PORTAL");
Packit 84794d
      if (var && var[0] == '1')
Packit 84794d
        use_portal = TRUE;
Packit 84794d
      network_available = TRUE;
Packit 84794d
    }
Packit 84794d
}
Packit 84794d
Packit 84794d
gboolean
Packit 84794d
glib_should_use_portal (void)
Packit 84794d
{
Packit 84794d
  read_flatpak_info ();
Packit 84794d
  return use_portal;
Packit 84794d
}
Packit 84794d
Packit 84794d
gboolean
Packit 84794d
glib_network_available_in_sandbox (void)
Packit 84794d
{
Packit 84794d
  read_flatpak_info ();
Packit 84794d
  return network_available;
Packit 84794d
}
Packit 84794d