aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>2009-01-10 00:15:17 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2009-01-10 00:15:17 +0800
commit1991fd5404adbc78e244cd38c7aa297c4933aef1 (patch)
treebac99eb80423cf7de6e4561b4a3542e4f4097a9c /libempathy
parente805d6ba0430bcc5f7bbc400e5152cf36b8d92ff (diff)
downloadgsoc2013-empathy-1991fd5404adbc78e244cd38c7aa297c4933aef1.tar
gsoc2013-empathy-1991fd5404adbc78e244cd38c7aa297c4933aef1.tar.gz
gsoc2013-empathy-1991fd5404adbc78e244cd38c7aa297c4933aef1.tar.bz2
gsoc2013-empathy-1991fd5404adbc78e244cd38c7aa297c4933aef1.tar.lz
gsoc2013-empathy-1991fd5404adbc78e244cd38c7aa297c4933aef1.tar.xz
gsoc2013-empathy-1991fd5404adbc78e244cd38c7aa297c4933aef1.tar.zst
gsoc2013-empathy-1991fd5404adbc78e244cd38c7aa297c4933aef1.zip
Convert EmpathyChatroomManager to the new singleton convention
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk> svn path=/trunk/; revision=2185
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-chatroom-manager.c25
-rw-r--r--libempathy/empathy-chatroom-manager.h2
-rw-r--r--libempathy/empathy-dispatcher.c2
3 files changed, 13 insertions, 16 deletions
diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c
index 585319604..282d7ed71 100644
--- a/libempathy/empathy-chatroom-manager.c
+++ b/libempathy/empathy-chatroom-manager.c
@@ -42,6 +42,8 @@
#define CHATROOMS_DTD_FILENAME "empathy-chatroom-manager.dtd"
#define SAVE_TIMER 4
+static EmpathyChatroomManager *chatroom_manager_singleton = NULL;
+
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChatroomManager)
typedef struct {
GList *chatrooms;
@@ -126,6 +128,9 @@ empathy_chatroom_manager_constructor (GType type,
EmpathyChatroomManager *self;
EmpathyChatroomManagerPriv *priv;
+ if (chatroom_manager_singleton != NULL)
+ return g_object_ref (chatroom_manager_singleton);
+
/* Parent constructor chain */
obj = G_OBJECT_CLASS (empathy_chatroom_manager_parent_class)->
constructor (type, n_props, props);
@@ -133,6 +138,9 @@ empathy_chatroom_manager_constructor (GType type,
self = EMPATHY_CHATROOM_MANAGER (obj);
priv = GET_PRIV (self);
+ chatroom_manager_singleton = self;
+ g_object_add_weak_pointer (obj, (gpointer *) &chatroom_manager_singleton);
+
if (priv->file == NULL)
{
/* Set the default file path */
@@ -247,21 +255,10 @@ chatroom_manager_finalize (GObject *object)
}
EmpathyChatroomManager *
-empathy_chatroom_manager_new (const gchar *file)
+empathy_chatroom_manager_dup_singleton (const gchar *file)
{
- static EmpathyChatroomManager *manager = NULL;
-
- if (!manager) {
- manager = g_object_new (EMPATHY_TYPE_CHATROOM_MANAGER,
- "file", file,
- NULL);
-
- g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager);
- } else {
- g_object_ref (manager);
- }
-
- return manager;
+ return EMPATHY_CHATROOM_MANAGER (g_object_new (EMPATHY_TYPE_CHATROOM_MANAGER,
+ "file", file, NULL));
}
static gboolean
diff --git a/libempathy/empathy-chatroom-manager.h b/libempathy/empathy-chatroom-manager.h
index b8e739ad4..4077a3ccd 100644
--- a/libempathy/empathy-chatroom-manager.h
+++ b/libempathy/empathy-chatroom-manager.h
@@ -54,7 +54,7 @@ struct _EmpathyChatroomManagerClass {
};
GType empathy_chatroom_manager_get_type (void) G_GNUC_CONST;
-EmpathyChatroomManager *empathy_chatroom_manager_new (const gchar *file);
+EmpathyChatroomManager *empathy_chatroom_manager_dup_singleton (const gchar *file);
gboolean empathy_chatroom_manager_add (EmpathyChatroomManager *manager,
EmpathyChatroom *chatroom);
void empathy_chatroom_manager_remove (EmpathyChatroomManager *manager,
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c
index e065326e1..f004db0cb 100644
--- a/libempathy/empathy-dispatcher.c
+++ b/libempathy/empathy-dispatcher.c
@@ -898,7 +898,7 @@ empathy_dispatcher_init (EmpathyDispatcher *dispatcher)
g_list_free (accounts);
/* FIXME thisshould probably be created by another object.. */
- priv->chatroom_mgr = empathy_chatroom_manager_new (NULL);
+ priv->chatroom_mgr = empathy_chatroom_manager_dup_singleton (NULL);
empathy_chatroom_manager_observe (priv->chatroom_mgr, dispatcher);
}