aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--libempathy-gtk/empathy-contact-menu.c2
-rw-r--r--libempathy/empathy-chatroom-manager.c25
-rw-r--r--libempathy/empathy-chatroom-manager.h2
-rw-r--r--libempathy/empathy-dispatcher.c2
-rw-r--r--src/empathy-chat-window.c2
-rw-r--r--src/empathy-chatrooms-window.c2
-rw-r--r--src/empathy-main-window.c2
-rw-r--r--tests/check-empathy-chatroom-manager.c32
8 files changed, 33 insertions, 36 deletions
diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c
index cf8580d23..91138e293 100644
--- a/libempathy-gtk/empathy-contact-menu.c
+++ b/libempathy-gtk/empathy-contact-menu.c
@@ -352,7 +352,7 @@ empathy_contact_invite_menu_item_new (EmpathyContact *contact)
GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
- mgr = empathy_chatroom_manager_new (NULL);
+ mgr = empathy_chatroom_manager_dup_singleton (NULL);
rooms = empathy_chatroom_manager_get_chatrooms (mgr,
empathy_contact_get_account (contact));
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);
}
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index c9e67d3c5..f032bbdab 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -1252,7 +1252,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
g_object_unref (glade);
- priv->chatroom_manager = empathy_chatroom_manager_new (NULL);
+ priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
priv->notebook = gtk_notebook_new ();
gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow");
diff --git a/src/empathy-chatrooms-window.c b/src/empathy-chatrooms-window.c
index a29c5278e..841abf7d5 100644
--- a/src/empathy-chatrooms-window.c
+++ b/src/empathy-chatrooms-window.c
@@ -144,7 +144,7 @@ empathy_chatrooms_window_show (GtkWindow *parent)
g_object_add_weak_pointer (G_OBJECT (window->window), (gpointer) &window);
/* Get the session and chat room manager */
- window->manager = empathy_chatroom_manager_new (NULL);
+ window->manager = empathy_chatroom_manager_dup_singleton (NULL);
g_signal_connect (window->manager, "chatroom-added",
G_CALLBACK (chatrooms_window_chatroom_added_cb),
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c
index a20345e6d..002820c39 100644
--- a/src/empathy-main-window.c
+++ b/src/empathy-main-window.c
@@ -743,7 +743,7 @@ main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
{
GList *chatrooms, *l;
- window->chatroom_manager = empathy_chatroom_manager_new (NULL);
+ window->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
diff --git a/tests/check-empathy-chatroom-manager.c b/tests/check-empathy-chatroom-manager.c
index 827404ed0..ef5c77618 100644
--- a/tests/check-empathy-chatroom-manager.c
+++ b/tests/check-empathy-chatroom-manager.c
@@ -102,7 +102,7 @@ change_account_name_in_file (McAccount *account,
return TRUE;
}
-START_TEST (test_empathy_chatroom_manager_new)
+START_TEST (test_empathy_chatroom_manager_dup_singleton)
{
EmpathyChatroomManager *mgr;
gchar *file;
@@ -121,7 +121,7 @@ START_TEST (test_empathy_chatroom_manager_new)
if (!change_account_name_in_file (account, file))
return;
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
check_chatrooms_list (mgr, account, chatrooms, 2);
g_free (file);
@@ -152,7 +152,7 @@ START_TEST (test_empathy_chatroom_manager_add)
if (!change_account_name_in_file (account, file))
return;
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
/* add a favorite chatroom */
chatroom = empathy_chatroom_new_full (account, "room3", "name3", FALSE);
@@ -164,7 +164,7 @@ START_TEST (test_empathy_chatroom_manager_add)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
/* chatroom has been added to the XML file as it's a favorite */
check_chatrooms_list (mgr, account, chatrooms, 3);
@@ -179,7 +179,7 @@ START_TEST (test_empathy_chatroom_manager_add)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
/* chatrooms has not been added to the XML file */
check_chatrooms_list (mgr, account, chatrooms, 3);
@@ -209,7 +209,7 @@ START_TEST (test_empathy_chatroom_manager_remove)
if (!change_account_name_in_file (account, file))
return;
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
/* remove room1 */
chatroom = empathy_chatroom_manager_find (mgr, account, "room1");
@@ -220,7 +220,7 @@ START_TEST (test_empathy_chatroom_manager_remove)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
check_chatrooms_list (mgr, account, chatrooms, 1);
@@ -234,7 +234,7 @@ START_TEST (test_empathy_chatroom_manager_remove)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
check_chatrooms_list (mgr, account, chatrooms, 0);
@@ -264,7 +264,7 @@ START_TEST (test_empathy_chatroom_manager_change_favorite)
if (!change_account_name_in_file (account, file))
return;
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
/* room2 is not favorite anymore */
chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
@@ -275,7 +275,7 @@ START_TEST (test_empathy_chatroom_manager_change_favorite)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
/* room2 is not present in the XML file anymore as it's not a favorite */
check_chatrooms_list (mgr, account, chatrooms, 1);
@@ -294,7 +294,7 @@ START_TEST (test_empathy_chatroom_manager_change_favorite)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
/* room2 is back in the XML file now */
check_chatrooms_list (mgr, account, chatrooms, 2);
@@ -326,7 +326,7 @@ START_TEST (test_empathy_chatroom_manager_change_chatroom)
if (!change_account_name_in_file (account, file))
return;
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
check_chatrooms_list (mgr, account, chatrooms, 2);
@@ -337,7 +337,7 @@ START_TEST (test_empathy_chatroom_manager_change_chatroom)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
chatrooms[1].name = "new_name";
check_chatrooms_list (mgr, account, chatrooms, 2);
@@ -349,7 +349,7 @@ START_TEST (test_empathy_chatroom_manager_change_chatroom)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
chatrooms[1].auto_connect = TRUE;
check_chatrooms_list (mgr, account, chatrooms, 2);
@@ -361,7 +361,7 @@ START_TEST (test_empathy_chatroom_manager_change_chatroom)
/* reload chatrooms file */
g_object_unref (mgr);
- mgr = empathy_chatroom_manager_new (file);
+ mgr = empathy_chatroom_manager_dup_singleton (file);
chatrooms[1].room = "new_room";
check_chatrooms_list (mgr, account, chatrooms, 2);
@@ -376,7 +376,7 @@ TCase *
make_empathy_chatroom_manager_tcase (void)
{
TCase *tc = tcase_create ("empathy-chatroom-manager");
- tcase_add_test (tc, test_empathy_chatroom_manager_new);
+ tcase_add_test (tc, test_empathy_chatroom_manager_dup_singleton);
tcase_add_test (tc, test_empathy_chatroom_manager_add);
tcase_add_test (tc, test_empathy_chatroom_manager_remove);
tcase_add_test (tc, test_empathy_chatroom_manager_change_favorite);