[glib] GAppLaunchContext: make it possible ot get the effective startup id



commit bace1822d792cd8767156508834237d550888177
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Nov 16 18:24:21 2012 -0500

    GAppLaunchContext: make it possible ot get the effective startup id
    
    gnome-session needs to know the startup id that was given to
    a started app; this was not available via GAppLaunchContext.
    This commit adds a ::launched signal to get this information.
    At the same time, turn the launch_failed vfunc into a signal
    as well.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688497

 gio/gappinfo.c        |   55 +++++++++++++++++++++++++++++++++++++++++++-----
 gio/gappinfo.h        |    4 ++-
 gio/gdesktopappinfo.c |   14 ++++++++++++
 3 files changed, 66 insertions(+), 7 deletions(-)
---
diff --git a/gio/gappinfo.c b/gio/gappinfo.c
index 9c9a32a..9472c0c 100644
--- a/gio/gappinfo.c
+++ b/gio/gappinfo.c
@@ -782,6 +782,14 @@ g_app_info_delete (GAppInfo *appinfo)
 }
 
 
+enum {
+  LAUNCH_FAILED,
+  LAUNCHED,
+  LAST_SIGNAL
+};
+
+guint signals[LAST_SIGNAL] = { 0 };
+
 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
 
 struct _GAppLaunchContextPrivate {
@@ -820,6 +828,46 @@ g_app_launch_context_class_init (GAppLaunchContextClass *klass)
   g_type_class_add_private (klass, sizeof (GAppLaunchContextPrivate));
 
   object_class->finalize = g_app_launch_context_finalize;
+
+  /*
+   * GAppLaunchContext::launch-failed:
+   * @context: the object emitting the signal
+   * @startup_notify_id: the startup notification id for the failed launch
+   *
+   * The ::launch-failed signal is emitted when a #GAppInfo launch
+   * fails. The startup notification id is provided, so that the launcher
+   * can cancel the startup notification.
+   *
+   * Since: 2.36
+   */
+  signals[LAUNCH_FAILED] = g_signal_new ("launch-failed",
+                                         G_OBJECT_CLASS_TYPE (object_class),
+                                         G_SIGNAL_RUN_LAST,
+                                         G_STRUCT_OFFSET (GAppLaunchContextClass, launch_failed),
+                                         NULL, NULL, NULL,
+                                         G_TYPE_NONE, 1, G_TYPE_STRING);
+
+  /*
+   * GAppLaunchContext::launched:
+   * @context: the object emitting the signal
+   * @info: the #GAppInfo that was just launched
+   * @platform_data: additional platform-specific data for this launch
+   *
+   * The ::launched signal is emitted when a #GAppInfo is successfully
+   * launched. The @platform_data is an GVariant dictionary mapping
+   * strings to variants (ie a{sv}), which contains additional,
+   * platform-specific data about this launch. On UNIX, at least the
+   * "pid" and "startup-notification-id" keys will be present.
+   *
+   * Since: 2.36
+   */
+  signals[LAUNCHED] = g_signal_new ("launched",
+                                    G_OBJECT_CLASS_TYPE (object_class),
+                                    G_SIGNAL_RUN_LAST,
+                                    G_STRUCT_OFFSET (GAppLaunchContextClass, launched),
+                                    NULL, NULL, NULL,
+                                    G_TYPE_NONE, 2,
+                                    G_TYPE_APP_INFO, G_TYPE_VARIANT);
 }
 
 static void
@@ -974,13 +1022,8 @@ void
 g_app_launch_context_launch_failed (GAppLaunchContext *context,
 				    const char        *startup_notify_id)
 {
-  GAppLaunchContextClass *class;
-
   g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
   g_return_if_fail (startup_notify_id != NULL);
 
-  class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
-
-  if (class->launch_failed != NULL)
-    class->launch_failed (context, startup_notify_id);
+  g_signal_emit (context, signals[LAUNCH_FAILED], 0, startup_notify_id);
 }
diff --git a/gio/gappinfo.h b/gio/gappinfo.h
index 578f62f..a27e58b 100644
--- a/gio/gappinfo.h
+++ b/gio/gappinfo.h
@@ -226,13 +226,15 @@ struct _GAppLaunchContextClass
                                     GList             *files);
   void   (* launch_failed)         (GAppLaunchContext *context,
                                     const char        *startup_notify_id);
+  void   (* launched)              (GAppLaunchContext *context,
+                                    GAppInfo          *info,
+                                    GVariant          *platform_data);
 
   /* Padding for future expansion */
   void (*_g_reserved1) (void);
   void (*_g_reserved2) (void);
   void (*_g_reserved3) (void);
   void (*_g_reserved4) (void);
-  void (*_g_reserved5) (void);
 };
 
 GType              g_app_launch_context_get_type              (void) G_GNUC_CONST;
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index aab444e..bb1c99c 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -1358,6 +1358,20 @@ _g_desktop_app_info_launch_uris_internal (GAppInfo                   *appinfo,
       if (pid_callback != NULL)
 	pid_callback (info, pid, pid_callback_data);
 
+      if (launch_context != NULL)
+        {
+          GVariantBuilder builder;
+          GVariant *platform_data;
+
+          g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+          g_variant_builder_add (&builder, "{sv}", "pid", g_variant_new_int32 (pid));
+          if (sn_id)
+            g_variant_builder_add (&builder, "{sv}", "startup-notification-id", g_variant_new_string (sn_id));
+          platform_data = g_variant_ref_sink (g_variant_builder_end (&builder));
+          g_signal_emit_by_name (launch_context, "launched", info, platform_data);
+          g_variant_unref (platform_data);
+        }
+
       notify_desktop_launch (session_bus,
 			     info,
 			     pid,



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