diff options
author | Ted Gould <ted@canonical.com> | 2009-02-11 16:30:59 -0600 |
---|---|---|
committer | Ted Gould <ted@canonical.com> | 2009-02-11 16:30:59 -0600 |
commit | 584e64c3eb0be0b2c8734ebfea7c4d2087d029db (patch) | |
tree | 21cb7e1bf1c7beeead297ba7326fc78627f1e3ea | |
parent | 8c06d7e7c2de9d498636996708a75a0a681e25aa (diff) | |
download | libayatana-indicator-584e64c3eb0be0b2c8734ebfea7c4d2087d029db.tar.gz libayatana-indicator-584e64c3eb0be0b2c8734ebfea7c4d2087d029db.tar.bz2 libayatana-indicator-584e64c3eb0be0b2c8734ebfea7c4d2087d029db.zip |
Adding in a ref-default function so that we can keep one listener
around for fun and profit.
-rw-r--r-- | libindicate/listener.c | 18 | ||||
-rw-r--r-- | libindicate/listener.h | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/libindicate/listener.c b/libindicate/listener.c index efd69fc..5ac03b9 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -243,11 +243,29 @@ indicate_listener_finalize (GObject * obj) IndicateListener * indicate_listener_new (void) { + g_warning("Creating a new listener is general discouraged, please use indicate_listener_ref_default"); + IndicateListener * listener; listener = g_object_new(INDICATE_TYPE_LISTENER, NULL); return listener; } +static IndicateListener * default_indicate_listener = NULL; + +IndicateListener * +indicate_listener_ref_default (void) +{ + if (default_indicate_listener != NULL) { + g_object_ref(default_indicate_listener); + } else { + default_indicate_listener = g_object_new(INDICATE_TYPE_LISTENER, NULL); + g_object_add_weak_pointer(G_OBJECT(default_indicate_listener), + (gpointer *)&default_indicate_listener); + } + + return default_indicate_listener; +} + static void dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, IndicateListener * listener) { diff --git a/libindicate/listener.h b/libindicate/listener.h index 9ecdfc6..3d8c7ef 100644 --- a/libindicate/listener.h +++ b/libindicate/listener.h @@ -83,6 +83,7 @@ typedef void (*indicate_listener_get_server_property_cb) (IndicateListener * lis /* Create a new listener */ IndicateListener * indicate_listener_new (void); +IndicateListener * indicate_listener_ref_default (void); void indicate_listener_get_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, |