empathy r2185 - in trunk: libempathy libempathy-gtk src tests



Author: xclaesse
Date: Fri Jan  9 16:15:17 2009
New Revision: 2185
URL: http://svn.gnome.org/viewvc/empathy?rev=2185&view=rev

Log:
Convert EmpathyChatroomManager to the new singleton convention

Signed-off-by: Sjoerd Simons <sjoerd simons collabora co uk>

Modified:
   trunk/libempathy-gtk/empathy-contact-menu.c
   trunk/libempathy/empathy-chatroom-manager.c
   trunk/libempathy/empathy-chatroom-manager.h
   trunk/libempathy/empathy-dispatcher.c
   trunk/src/empathy-chat-window.c
   trunk/src/empathy-chatrooms-window.c
   trunk/src/empathy-main-window.c
   trunk/tests/check-empathy-chatroom-manager.c

Modified: trunk/libempathy-gtk/empathy-contact-menu.c
==============================================================================
--- trunk/libempathy-gtk/empathy-contact-menu.c	(original)
+++ trunk/libempathy-gtk/empathy-contact-menu.c	Fri Jan  9 16:15:17 2009
@@ -352,7 +352,7 @@
 					      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));
 

Modified: trunk/libempathy/empathy-chatroom-manager.c
==============================================================================
--- trunk/libempathy/empathy-chatroom-manager.c	(original)
+++ trunk/libempathy/empathy-chatroom-manager.c	Fri Jan  9 16:15:17 2009
@@ -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 @@
   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 @@
   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 @@
 }
 
 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

Modified: trunk/libempathy/empathy-chatroom-manager.h
==============================================================================
--- trunk/libempathy/empathy-chatroom-manager.h	(original)
+++ trunk/libempathy/empathy-chatroom-manager.h	Fri Jan  9 16:15:17 2009
@@ -54,7 +54,7 @@
 };
 
 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,

Modified: trunk/libempathy/empathy-dispatcher.c
==============================================================================
--- trunk/libempathy/empathy-dispatcher.c	(original)
+++ trunk/libempathy/empathy-dispatcher.c	Fri Jan  9 16:15:17 2009
@@ -898,7 +898,7 @@
   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);
 }
 

Modified: trunk/src/empathy-chat-window.c
==============================================================================
--- trunk/src/empathy-chat-window.c	(original)
+++ trunk/src/empathy-chat-window.c	Fri Jan  9 16:15:17 2009
@@ -1252,7 +1252,7 @@
 
 	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"); 

Modified: trunk/src/empathy-chatrooms-window.c
==============================================================================
--- trunk/src/empathy-chatrooms-window.c	(original)
+++ trunk/src/empathy-chatrooms-window.c	Fri Jan  9 16:15:17 2009
@@ -144,7 +144,7 @@
 	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),

Modified: trunk/src/empathy-main-window.c
==============================================================================
--- trunk/src/empathy-main-window.c	(original)
+++ trunk/src/empathy-main-window.c	Fri Jan  9 16:15:17 2009
@@ -743,7 +743,7 @@
 {
 	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));
 

Modified: trunk/tests/check-empathy-chatroom-manager.c
==============================================================================
--- trunk/tests/check-empathy-chatroom-manager.c	(original)
+++ trunk/tests/check-empathy-chatroom-manager.c	Fri Jan  9 16:15:17 2009
@@ -102,7 +102,7 @@
   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 @@
   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 @@
   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 @@
 
   /* 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 @@
 
   /* 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 @@
   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 @@
 
   /* 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 @@
 
   /* 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 @@
   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 @@
 
   /* 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 @@
 
   /* 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 @@
   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 @@
 
   /* 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 @@
 
   /* 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 @@
 
   /* 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 @@
 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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]