[gtk/wip/hadess/portal-select-folders: 37/38] Add portal version checking helper
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/hadess/portal-select-folders: 37/38] Add portal version checking helper
- Date: Mon, 23 Mar 2020 14:44:07 +0000 (UTC)
commit 93ab478af12648dc6e501e8f47661971d6e0b795
Author: Bastien Nocera <hadess hadess net>
Date: Mon Mar 23 14:56:43 2020 +0100
Add portal version checking helper
Add gtk_get_portal_interface_version() to check the version of a portal.
gtk/gtkprivate.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkprivate.h | 2 ++
2 files changed, 53 insertions(+)
---
diff --git a/gtk/gtkprivate.c b/gtk/gtkprivate.c
index a437047658..134d3bbfe1 100644
--- a/gtk/gtkprivate.c
+++ b/gtk/gtkprivate.c
@@ -292,6 +292,57 @@ gtk_should_use_portal (void)
return use_portal[0] == '1';
}
+/*
+ * gtk_get_portal_interface_version:
+ * @connection: a session #GDBusConnection
+ * @interface_name: the interface name for the portal interface
+ * we're interested in.
+ *
+ * Returns: the version number of the portal, or 0 on error.
+ */
+guint
+gtk_get_portal_interface_version (GDBusConnection *connection,
+ const char *interface_name)
+{
+ g_autoptr(GDBusProxy) proxy = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) ret = NULL;
+ g_autofree char *owner = NULL;
+ guint version = 0;
+
+ proxy = g_dbus_proxy_new_sync (connection,
+ 0,
+ NULL,
+ "org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ interface_name,
+ NULL,
+ &error);
+ if (!proxy)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Could not query portal version on interface '%s': %s",
+ interface_name, error->message);
+ return 0;
+ }
+
+ owner = g_dbus_proxy_get_name_owner (proxy);
+ if (owner == NULL)
+ {
+ g_debug ("%s not provided by any service", interface_name);
+ return FALSE;
+ }
+
+ ret = g_dbus_proxy_get_cached_property (proxy, "version");
+ if (ret)
+ version = g_variant_get_uint32 (ret);
+
+ g_debug ("Got version %u for portal interface '%s'",
+ version, interface_name);
+
+ return version;
+}
+
static char *
get_portal_path (GDBusConnection *connection,
const char *kind,
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
index af7e58b5e9..80a18a1419 100644
--- a/gtk/gtkprivate.h
+++ b/gtk/gtkprivate.h
@@ -100,6 +100,8 @@ char *gtk_get_portal_request_path (GDBusConnection *connection,
char **token);
char *gtk_get_portal_session_path (GDBusConnection *connection,
char **token);
+guint gtk_get_portal_interface_version (GDBusConnection *connection,
+ const char *interface_name);
#ifdef G_OS_WIN32
void _gtk_load_dll_with_libgtk3_manifest (const char *dllname);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]