GApplication: add accessor for DBus information
authorRyan Lortie <desrt@desrt.ca>
Mon, 30 Apr 2012 16:20:54 +0000 (12:20 -0400)
committerRyan Lortie <desrt@desrt.ca>
Mon, 30 Apr 2012 21:43:06 +0000 (17:43 -0400)
Provide public access to the GDBusConnect and object path that
GApplication is using.  Prevents others from having to guess these
things for themselves based on the application ID.

https://bugzilla.gnome.org/show_bug.cgi?id=671249

docs/reference/gio/gio-sections.txt
gio/gapplication.c
gio/gapplication.h
gio/gapplicationimpl-dbus.c
gio/gapplicationimpl.h
gio/gio.symbols

index a9a9309..584a3f5 100644 (file)
@@ -2897,6 +2897,9 @@ g_application_set_inactivity_timeout
 g_application_get_flags
 g_application_set_flags
 <SUBSECTION>
+g_application_get_dbus_connection
+g_application_get_dbus_object_path
+<SUBSECTION>
 g_application_set_action_group
 <SUBSECTION>
 g_application_get_is_registered
index 947885b..e675852 100644 (file)
@@ -1085,7 +1085,7 @@ g_application_set_inactivity_timeout (GApplication *application,
       g_object_notify (G_OBJECT (application), "inactivity-timeout");
     }
 }
-/* Read-only property getters (is registered, is remote) {{{1 */
+/* Read-only property getters (is registered, is remote, dbus stuff) {{{1 */
 /**
  * g_application_get_is_registered:
  * @application: a #GApplication
@@ -1135,6 +1135,69 @@ g_application_get_is_remote (GApplication *application)
   return application->priv->is_remote;
 }
 
+/**
+ * g_application_get_dbus_connection:
+ * @application: a #GApplication
+ *
+ * Gets the #GDBusConnection being used by the application, or %NULL.
+ *
+ * If #GApplication is using its D-Bus backend then this function will
+ * return the #GDBusConnection being used for uniqueness and
+ * communication with the desktop environment and other instances of the
+ * application.
+ *
+ * If #GApplication is not using D-Bus then this function will return
+ * %NULL.  This includes the situation where the D-Bus backend would
+ * normally be in use but we were unable to connect to the bus.
+ *
+ * This function must not be called before the application has been
+ * registered.  See g_application_get_is_registered().
+ *
+ * Returns: (transfer none): a #GDBusConnection, or %NULL
+ *
+ * Since: 2.34
+ **/
+GDBusConnection *
+g_application_get_dbus_connection (GApplication *application)
+{
+  g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
+  g_return_val_if_fail (application->priv->is_registered, FALSE);
+
+  return g_application_impl_get_dbus_connection (application->priv->impl);
+}
+
+/**
+ * g_application_get_dbus_object_path:
+ * @application: a #GApplication
+ *
+ * Gets the D-Bus object path being used by the application, or %NULL.
+ *
+ * If #GApplication is using its D-Bus backend then this function will
+ * return the D-Bus object path that #GApplication is using.  If the
+ * application is the primary instance then there is an object published
+ * at this path.  If the application is not the primary instance then
+ * the result of this function is undefined.
+ *
+ * If #GApplication is not using D-Bus then this function will return
+ * %NULL.  This includes the situation where the D-Bus backend would
+ * normally be in use but we were unable to connect to the bus.
+ *
+ * This function must not be called before the application has been
+ * registered.  See g_application_get_is_registered().
+ *
+ * Returns: the object path, or %NULL
+ *
+ * Since: 2.34
+ **/
+const gchar *
+g_application_get_dbus_object_path (GApplication *application)
+{
+  g_return_val_if_fail (G_IS_APPLICATION (application), FALSE);
+  g_return_val_if_fail (application->priv->is_registered, FALSE);
+
+  return g_application_impl_get_dbus_object_path (application->priv->impl);
+}
+
 /* Register {{{1 */
 /**
  * g_application_register:
index c6c63a5..c0cad11 100644 (file)
@@ -105,6 +105,11 @@ const gchar *           g_application_get_application_id                (GApplic
 void                    g_application_set_application_id                (GApplication             *application,
                                                                          const gchar              *application_id);
 
+GLIB_AVAILABLE_IN_2_34
+GDBusConnection *       g_application_get_dbus_connection               (GApplication             *application);
+GLIB_AVAILABLE_IN_2_34
+const gchar *           g_application_get_dbus_object_path              (GApplication             *application);
+
 guint                   g_application_get_inactivity_timeout            (GApplication             *application);
 void                    g_application_set_inactivity_timeout            (GApplication             *application,
                                                                          guint                     inactivity_timeout);
index 7612748..b258f02 100644 (file)
@@ -597,6 +597,17 @@ g_application_impl_flush (GApplicationImpl *impl)
     g_dbus_connection_flush_sync (impl->session_bus, NULL, NULL);
 }
 
+GDBusConnection *
+g_application_impl_get_dbus_connection (GApplicationImpl *impl)
+{
+  return impl->session_bus;
+}
+
+const gchar *
+g_application_impl_get_dbus_object_path (GApplicationImpl *impl)
+{
+  return impl->object_path;
+}
 
 /* GDBusCommandLine implementation {{{1 */
 
index ef25f2b..acf3c53 100644 (file)
@@ -41,3 +41,9 @@ int                     g_application_impl_command_line                 (GApplic
 
 G_GNUC_INTERNAL
 void                    g_application_impl_flush                        (GApplicationImpl   *impl);
+
+G_GNUC_INTERNAL
+GDBusConnection *       g_application_impl_get_dbus_connection          (GApplicationImpl   *impl);
+
+G_GNUC_INTERNAL
+const gchar *           g_application_impl_get_dbus_object_path         (GApplicationImpl   *impl);
index 42fb1cb..f4dff35 100644 (file)
@@ -14,6 +14,8 @@ g_application_get_type
 g_application_activate
 g_application_flags_get_type
 g_application_get_application_id
+g_application_get_dbus_connection
+g_application_get_dbus_object_path
 g_application_get_default
 g_application_get_flags
 g_application_get_inactivity_timeout