Loading

Paste #phmpnturz

  1. XDP_PUBLIC
  2. void       xdp_portal_pick_color             (XdpPortal           *portal,
  3.                                               XdpParent           *parent,
  4.                                               GCancellable        *cancellable,
  5.                                               GAsyncReadyCallback  callback,
  6.                                               gpointer             data);
  7.  
  8. XDP_PUBLIC
  9. GVariant * xdp_portal_pick_color_finish      (XdpPortal           *portal,
  10.                                               GAsyncResult        *result,
  11.                                               GError             **error);
  12.  
  13.  
  14. static void
  15. pick_color_cb (GObject      *source_object,
  16.                GAsyncResult *result,
  17.                gpointer      user_data)
  18. {
  19.   MyObject *my_object;
  20.   GVariant *variant; /* this is the result of the async function call */
  21.   GError *error = NULL;
  22.  
  23.   variant = xdp_portal_pick_color_finish (XDP_POTRAL (source_object), result, &error);
  24.   if (!variant)
  25.     {
  26.       if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
  27.         g_warning ("Failed to pick color: %s", error->message);
  28.       g_error_free (error);
  29.       return;
  30.     }
  31.  
  32.   /* Not cancelled, so it's safe to use my_object */
  33.   my_object = MY_OBJECT (user_data);
  34.  
  35.   /* do stuff with the variant ... */
  36. }
  37.  
  38. static void
  39. my_object_do_something (MyObject *my_object)
  40. {
  41.   // portal and parent are declared somewhere
  42.   // cancellable is cancelled and freed in my_object_dispose
  43.  
  44.   xdp_potral_pick_color (portal, parent,
  45.                          my_object->cancellable,
  46.                          pick_color_cb, my_object);
  47. }