[gimp/nielsdg/xdg-pick-button-version-check: 85/85] pickbutton: Add version check for XDG portal




commit e5caf21bcb3354cdd3837104892a1ac9eac9964b
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Apr 10 15:31:27 2022 +0200

    pickbutton: Add version check for XDG portal
    
    `PickColor()` API only got added in version 2, so check for that before
    trying to use it.

 libgimpwidgets/gimppickbutton-xdg.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)
---
diff --git a/libgimpwidgets/gimppickbutton-xdg.c b/libgimpwidgets/gimppickbutton-xdg.c
index 3b3dcee33a..05a225593b 100644
--- a/libgimpwidgets/gimppickbutton-xdg.c
+++ b/libgimpwidgets/gimppickbutton-xdg.c
@@ -36,7 +36,9 @@
 gboolean
 _gimp_pick_button_xdg_available (void)
 {
-  GDBusProxy *proxy = NULL;
+  gboolean    ret     = TRUE;
+  GDBusProxy *proxy   = NULL;
+  GVariant   *version = NULL;
 
   proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                          G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
@@ -46,24 +48,30 @@ _gimp_pick_button_xdg_available (void)
                                          "org.freedesktop.portal.Screenshot",
                                          NULL, NULL);
 
-  if (proxy)
+  if (proxy == NULL)
     {
-      GError *error = NULL;
-
-      g_dbus_proxy_call_sync (proxy, "org.freedesktop.DBus.Peer.Ping",
-                              NULL,
-                              G_DBUS_CALL_FLAGS_NONE,
-                              -1, NULL, &error);
-      if (! error)
-        return TRUE;
+      ret = FALSE;
+      goto out;
+    }
 
-      g_clear_error (&error);
+  /* Finally, PickColor is only available starting V2 of the portal */
+  version = g_dbus_proxy_get_cached_property (proxy, "version");
+  if (version == NULL)
+    {
+      ret = FALSE;
+      goto out;
+    }
 
-      g_object_unref (proxy);
-      proxy = NULL;
+  if (g_variant_get_uint32 (version) < 2)
+    {
+      ret = FALSE;
+      goto out;
     }
 
-  return FALSE;
+out:
+  g_clear_pointer (&version, g_variant_unref);
+  g_clear_object (&proxy);
+  return ret;
 }
 
 static void


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