empathy r2114 - in trunk: libempathy libempathy-gtk src



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

Log:
Port EmpathyIdle to the new singleton policy.

Modified:
   trunk/libempathy-gtk/empathy-presence-chooser.c
   trunk/libempathy/empathy-idle.c
   trunk/libempathy/empathy-idle.h
   trunk/src/empathy-status-icon.c
   trunk/src/empathy.c

Modified: trunk/libempathy-gtk/empathy-presence-chooser.c
==============================================================================
--- trunk/libempathy-gtk/empathy-presence-chooser.c	(original)
+++ trunk/libempathy-gtk/empathy-presence-chooser.c	Fri Jan  9 10:06:00 2009
@@ -203,7 +203,7 @@
 			  G_CALLBACK (presence_chooser_scroll_event_cb),
 			  NULL);
 
-	priv->idle = empathy_idle_new ();
+	priv->idle = empathy_idle_dup_singleton ();
 	presence_chooser_presence_changed_cb (chooser);
 	g_signal_connect_swapped (priv->idle, "notify",
 				  G_CALLBACK (presence_chooser_presence_changed_cb),
@@ -747,7 +747,7 @@
 {
 	EmpathyIdle *idle;
 
-	idle = empathy_idle_new ();
+	idle = empathy_idle_dup_singleton ();
 	empathy_idle_set_presence (idle, state, status);
 	g_object_unref (idle);
 }

Modified: trunk/libempathy/empathy-idle.c
==============================================================================
--- trunk/libempathy/empathy-idle.c	(original)
+++ trunk/libempathy/empathy-idle.c	Fri Jan  9 10:06:00 2009
@@ -76,7 +76,9 @@
 	PROP_USE_NM
 };
 
-G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT)
+G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT);
+
+static EmpathyIdle * idle_singleton = NULL;
 
 static void
 idle_presence_changed_cb (MissionControl *mc,
@@ -271,6 +273,26 @@
 	idle_ext_away_stop (EMPATHY_IDLE (object));
 }
 
+static GObject *
+idle_constructor (GType type,
+		  guint n_props,
+		  GObjectConstructParam *props)
+{
+	GObject *retval;
+
+	if (idle_singleton) {
+		retval = g_object_ref (idle_singleton);
+	} else {
+		retval = G_OBJECT_CLASS (empathy_idle_parent_class)->constructor
+			(type, n_props, props);
+		g_object_add_weak_pointer (retval, (gpointer *) &retval);
+
+		idle_singleton = EMPATHY_IDLE (retval);
+	}
+
+	return retval;
+}
+
 static void
 idle_get_property (GObject    *object,
 		   guint       param_id,
@@ -345,6 +367,7 @@
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
 	object_class->finalize = idle_finalize;
+	object_class->constructor = idle_constructor;
 	object_class->get_property = idle_get_property;
 	object_class->set_property = idle_set_property;
 
@@ -465,18 +488,9 @@
 }
 
 EmpathyIdle *
-empathy_idle_new (void)
+empathy_idle_dup_singleton (void)
 {
-	static EmpathyIdle *idle = NULL;
-
-	if (!idle) {
-		idle = g_object_new (EMPATHY_TYPE_IDLE, NULL);
-		g_object_add_weak_pointer (G_OBJECT (idle), (gpointer) &idle);
-	} else {
-		g_object_ref (idle);
-	}
-
-	return idle;
+	return g_object_new (EMPATHY_TYPE_IDLE, NULL);
 }
 
 McPresence

Modified: trunk/libempathy/empathy-idle.h
==============================================================================
--- trunk/libempathy/empathy-idle.h	(original)
+++ trunk/libempathy/empathy-idle.h	Fri Jan  9 10:06:00 2009
@@ -48,7 +48,7 @@
 };
 
 GType        empathy_idle_get_type            (void) G_GNUC_CONST;
-EmpathyIdle *empathy_idle_new                 (void);
+EmpathyIdle *empathy_idle_dup_singleton       (void);
 McPresence   empathy_idle_get_state           (EmpathyIdle *idle);
 void         empathy_idle_set_state           (EmpathyIdle *idle,
 					       McPresence   state);

Modified: trunk/src/empathy-status-icon.c
==============================================================================
--- trunk/src/empathy-status-icon.c	(original)
+++ trunk/src/empathy-status-icon.c	Fri Jan  9 10:06:00 2009
@@ -396,8 +396,8 @@
 	icon->priv = priv;
 	priv->icon = gtk_status_icon_new ();
 	priv->account_manager = empathy_account_manager_dup_singleton ();
-	priv->idle = empathy_idle_new ();
-	priv->event_manager = empathy_event_manager_new ();
+	priv->idle = empathy_idle_dup_singleton ();
+	priv->event_manager = empathy_event_manager_dup_singleton ();
 
 	g_signal_connect (priv->account_manager,
 			  "account-connection-changed",

Modified: trunk/src/empathy.c
==============================================================================
--- trunk/src/empathy.c	(original)
+++ trunk/src/empathy.c	Fri Jan  9 10:06:00 2009
@@ -473,7 +473,7 @@
 	}
 
 	/* Setting up Idle */
-	idle = empathy_idle_new ();
+	idle = empathy_idle_dup_singleton ();
 	empathy_idle_set_auto_away (idle, TRUE);
 	use_nm_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_NM, idle);
 	empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_NM,



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