#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;
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);
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 */
}
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
return TRUE;
}
-START_TEST (test_empathy_chatroom_manager_new)
+START_TEST (test_empathy_chatroom_manager_dup_singleton)
{
EmpathyChatroomManager *mgr;
gchar *file;
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);
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);
/* 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);
/* 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);
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");
/* 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);
/* 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);
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");
/* 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);
/* 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);
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);
/* 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);
/* 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);
/* 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);
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);