diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-09 18:06:15 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-09 18:06:15 +0800 |
commit | 00c9111bef2e541e74eae9f23cbc1d82ad822ea6 (patch) | |
tree | 6ba64677dd580b31eeb9016fcc86e5fd5a6f33f5 /src | |
parent | e8499acc40dc33d78df27d1b8ac14c296098fc9e (diff) | |
download | gsoc2013-empathy-00c9111bef2e541e74eae9f23cbc1d82ad822ea6.tar gsoc2013-empathy-00c9111bef2e541e74eae9f23cbc1d82ad822ea6.tar.gz gsoc2013-empathy-00c9111bef2e541e74eae9f23cbc1d82ad822ea6.tar.bz2 gsoc2013-empathy-00c9111bef2e541e74eae9f23cbc1d82ad822ea6.tar.lz gsoc2013-empathy-00c9111bef2e541e74eae9f23cbc1d82ad822ea6.tar.xz gsoc2013-empathy-00c9111bef2e541e74eae9f23cbc1d82ad822ea6.tar.zst gsoc2013-empathy-00c9111bef2e541e74eae9f23cbc1d82ad822ea6.zip |
Port EmpathyEventManager to the new singleton policy.
svn path=/trunk/; revision=2117
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-event-manager.c | 36 | ||||
-rw-r--r-- | src/empathy-event-manager.h | 2 | ||||
-rw-r--r-- | src/empathy-main-window.c | 2 |
3 files changed, 27 insertions, 13 deletions
diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c index f192b9731..efcea9ec8 100644 --- a/src/empathy-event-manager.c +++ b/src/empathy-event-manager.c @@ -71,6 +71,8 @@ static guint signals[LAST_SIGNAL]; G_DEFINE_TYPE (EmpathyEventManager, empathy_event_manager, G_TYPE_OBJECT); +static EmpathyEventManager * manager_singleton = NULL; + static void event_remove (EventPriv *event); static void @@ -387,6 +389,26 @@ event_manager_pendings_changed_cb (EmpathyContactList *list, g_string_free (str, TRUE); } +static GObject * +event_manager_constructor (GType type, + guint n_props, + GObjectConstructParam *props) +{ + GObject *retval; + + if (manager_singleton) { + retval = g_object_ref (manager_singleton); + } else { + retval = G_OBJECT_CLASS (empathy_event_manager_parent_class)->constructor + (type, n_props, props); + g_object_add_weak_pointer (retval, (gpointer *) &retval); + + manager_singleton = EMPATHY_EVENT_MANAGER (retval); + } + + return retval; +} + static void event_manager_finalize (GObject *object) { @@ -404,6 +426,7 @@ empathy_event_manager_class_init (EmpathyEventManagerClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = event_manager_finalize; + object_class->constructor = event_manager_constructor; signals[EVENT_ADDED] = g_signal_new ("event-added", @@ -453,18 +476,9 @@ empathy_event_manager_init (EmpathyEventManager *manager) } EmpathyEventManager * -empathy_event_manager_new (void) +empathy_event_manager_dup_singleton (void) { - static EmpathyEventManager *manager = NULL; - - if (!manager) { - manager = g_object_new (EMPATHY_TYPE_EVENT_MANAGER, NULL); - g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager); - } else { - g_object_ref (manager); - } - - return manager; + return g_object_new (EMPATHY_TYPE_EVENT_MANAGER, NULL); } GSList * diff --git a/src/empathy-event-manager.h b/src/empathy-event-manager.h index 89cb74d63..cd299207f 100644 --- a/src/empathy-event-manager.h +++ b/src/empathy-event-manager.h @@ -55,7 +55,7 @@ typedef struct { } EmpathyEvent; GType empathy_event_manager_get_type (void) G_GNUC_CONST; -EmpathyEventManager *empathy_event_manager_new (void); +EmpathyEventManager *empathy_event_manager_dup_singleton (void); EmpathyEvent * empathy_event_manager_get_top_event (EmpathyEventManager *manager); GSList * empathy_event_manager_get_events (EmpathyEventManager *manager); void empathy_event_activate (EmpathyEvent *event); diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 07c236f96..3d5524923 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -639,7 +639,7 @@ empathy_main_window_show (void) } /* Enable event handling */ - window->event_manager = empathy_event_manager_new (); + window->event_manager = empathy_event_manager_dup_singleton (); g_signal_connect (window->event_manager, "event-added", G_CALLBACK (main_window_event_added_cb), window); |