empathy r2115 - in trunk: libempathy libempathy-gtk



Author: xclaesse
Date: Fri Jan  9 10:06:05 2009
New Revision: 2115
URL: http://svn.gnome.org/viewvc/empathy?rev=2115&view=rev

Log:
Port EmpathyLogManager to the new singleton policy.

Modified:
   trunk/libempathy-gtk/empathy-chat.c
   trunk/libempathy-gtk/empathy-contact-menu.c
   trunk/libempathy-gtk/empathy-log-window.c
   trunk/libempathy/empathy-log-manager.c
   trunk/libempathy/empathy-log-manager.h

Modified: trunk/libempathy-gtk/empathy-chat.c
==============================================================================
--- trunk/libempathy-gtk/empathy-chat.c	(original)
+++ trunk/libempathy-gtk/empathy-chat.c	Fri Jan  9 10:06:05 2009
@@ -1526,7 +1526,7 @@
 		EMPATHY_TYPE_CHAT, EmpathyChatPriv);
 
 	chat->priv = priv;
-	priv->log_manager = empathy_log_manager_new ();
+	priv->log_manager = empathy_log_manager_dup_singleton ();
 	priv->contacts_width = -1;
 	priv->sent_messages = NULL;
 	priv->sent_messages_index = -1;

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 10:06:05 2009
@@ -171,7 +171,7 @@
 
 	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
-	manager = empathy_log_manager_new ();
+	manager = empathy_log_manager_dup_singleton ();
 	have_log = empathy_log_manager_exists (manager,
 					       empathy_contact_get_account (contact),
 					       empathy_contact_get_id (contact),

Modified: trunk/libempathy-gtk/empathy-log-window.c
==============================================================================
--- trunk/libempathy-gtk/empathy-log-window.c	(original)
+++ trunk/libempathy-gtk/empathy-log-window.c	Fri Jan  9 10:06:05 2009
@@ -160,7 +160,7 @@
 	}
 
 	window = g_new0 (EmpathyLogWindow, 1);
-	window->log_manager = empathy_log_manager_new ();
+	window->log_manager = empathy_log_manager_dup_singleton ();
 
 	filename = empathy_file_lookup ("empathy-log-window.glade",
 					"libempathy-gtk");

Modified: trunk/libempathy/empathy-log-manager.c
==============================================================================
--- trunk/libempathy/empathy-log-manager.c	(original)
+++ trunk/libempathy/empathy-log-manager.c	Fri Jan  9 10:06:05 2009
@@ -55,7 +55,6 @@
 	gchar *basedir;
 } EmpathyLogManagerPriv;
 
-static void                 log_manager_finalize                   (GObject                *object);
 static const gchar *        log_manager_get_basedir                (EmpathyLogManager      *manager);
 static GList *              log_manager_get_all_files              (EmpathyLogManager      *manager,
 								    const gchar            *dir);
@@ -83,15 +82,7 @@
 
 G_DEFINE_TYPE (EmpathyLogManager, empathy_log_manager, G_TYPE_OBJECT);
 
-static void
-empathy_log_manager_class_init (EmpathyLogManagerClass *klass)
-{
-	GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-	object_class->finalize = log_manager_finalize;
-
-	g_type_class_add_private (object_class, sizeof (EmpathyLogManagerPriv));
-}
+static EmpathyLogManager * manager_singleton = NULL;
 
 static void
 empathy_log_manager_init (EmpathyLogManager *manager)
@@ -112,19 +103,41 @@
 	g_free (priv->basedir);
 }
 
-EmpathyLogManager *
-empathy_log_manager_new (void)
+static GObject *
+log_manager_constructor (GType type,
+			 guint n_props,
+			 GObjectConstructParam *props)
 {
-	static EmpathyLogManager *manager = NULL;
+	GObject *retval;
 
-	if (!manager) {
-		manager = g_object_new (EMPATHY_TYPE_LOG_MANAGER, NULL);
-		g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager);
+	if (manager_singleton) {
+		retval = g_object_ref (manager_singleton);
 	} else {
-		g_object_ref (manager);
+		retval = G_OBJECT_CLASS (empathy_log_manager_parent_class)->constructor
+			(type, n_props, props);
+		g_object_add_weak_pointer (retval, (gpointer *) &retval);
+
+		manager_singleton = EMPATHY_LOG_MANAGER (retval);
 	}
 
-	return manager;
+	return retval;
+}
+
+static void
+empathy_log_manager_class_init (EmpathyLogManagerClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize = log_manager_finalize;
+	object_class->constructor = log_manager_constructor;
+
+	g_type_class_add_private (object_class, sizeof (EmpathyLogManagerPriv));
+}
+
+EmpathyLogManager *
+empathy_log_manager_dup_singleton (void)
+{
+	return g_object_new (EMPATHY_TYPE_LOG_MANAGER, NULL);
 }
 
 void

Modified: trunk/libempathy/empathy-log-manager.h
==============================================================================
--- trunk/libempathy/empathy-log-manager.h	(original)
+++ trunk/libempathy/empathy-log-manager.h	Fri Jan  9 10:06:05 2009
@@ -61,7 +61,7 @@
 };
 
 GType              empathy_log_manager_get_type              (void) G_GNUC_CONST;
-EmpathyLogManager *empathy_log_manager_new                   (void);
+EmpathyLogManager *empathy_log_manager_dup_singleton         (void);
 void               empathy_log_manager_add_message           (EmpathyLogManager *manager,
 							      const gchar       *chat_id,
 							      gboolean           chatroom,



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