[glib/portal2: 1/5] Add portal support



commit 3abab9f0ae2a36d3128423abedc705d731bdaea2
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jul 6 23:34:55 2016 -0400

    Add portal support
    
    These are helper functions that will be used in the
    following commits.

 gio/Makefile.am      |    2 +
 gio/gportalsupport.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gio/gportalsupport.h |   30 +++++++++++++++++++++
 3 files changed, 103 insertions(+), 0 deletions(-)
---
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 3b3c104..9a0d758 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -424,6 +424,8 @@ libgio_2_0_la_SOURCES =             \
        gpollableutils.c        \
        gpollfilemonitor.c      \
        gpollfilemonitor.h      \
+       gportalsupport.c        \
+       gportalsupport.h        \
        gproxy.c                \
        gproxyaddress.c         \
        gproxyaddressenumerator.c \
diff --git a/gio/gportalsupport.c b/gio/gportalsupport.c
new file mode 100644
index 0000000..7a8c539
--- /dev/null
+++ b/gio/gportalsupport.c
@@ -0,0 +1,71 @@
+/* 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 "gportalsupport.h"
+
+gboolean
+glib_should_use_portal (void)
+{
+  const char *use_portal;
+  char *path;
+
+  path = g_build_filename (g_get_user_runtime_dir (), "flatpak-info", NULL);
+  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_build_filename (g_get_user_runtime_dir (), "flatpak-info", NULL);
+  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);
+      if (shared)
+        {
+          available = g_strv_contains ((const char * const *)shared, "network");
+          g_strfreev (shared);
+        }
+      else
+        available = FALSE;
+    }
+
+  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 0000000..a92e07c
--- /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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]