[glib] GApplication: add accessor for DBus information



commit eb5381b8622eda26b6bd86dbac39bd9ed86bf730
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Apr 30 12:20:54 2012 -0400

    GApplication: add accessor for DBus information
    
    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 |    3 ++
 gio/gapplication.c                  |   65 ++++++++++++++++++++++++++++++++++-
 gio/gapplication.h                  |    5 +++
 gio/gapplicationimpl-dbus.c         |   11 ++++++
 gio/gapplicationimpl.h              |    6 +++
 gio/gio.symbols                     |    2 +
 6 files changed, 91 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index a9a9309..584a3f5 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -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
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 947885b..e675852 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -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:
diff --git a/gio/gapplication.h b/gio/gapplication.h
index c6c63a5..c0cad11 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -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);
diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c
index 7612748..b258f02 100644
--- a/gio/gapplicationimpl-dbus.c
+++ b/gio/gapplicationimpl-dbus.c
@@ -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 */
 
diff --git a/gio/gapplicationimpl.h b/gio/gapplicationimpl.h
index ef25f2b..acf3c53 100644
--- a/gio/gapplicationimpl.h
+++ b/gio/gapplicationimpl.h
@@ -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);
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 42fb1cb..f4dff35 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -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



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