Commit c2a1dec0 authored by Xavier Claessens's avatar Xavier Claessens

Port EmpathyIdle to the new singleton policy.

svn path=/trunk/; revision=2114
parent 4100a5f5
...@@ -203,7 +203,7 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser) ...@@ -203,7 +203,7 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
G_CALLBACK (presence_chooser_scroll_event_cb), G_CALLBACK (presence_chooser_scroll_event_cb),
NULL); NULL);
priv->idle = empathy_idle_new (); priv->idle = empathy_idle_dup_singleton ();
presence_chooser_presence_changed_cb (chooser); presence_chooser_presence_changed_cb (chooser);
g_signal_connect_swapped (priv->idle, "notify", g_signal_connect_swapped (priv->idle, "notify",
G_CALLBACK (presence_chooser_presence_changed_cb), G_CALLBACK (presence_chooser_presence_changed_cb),
...@@ -747,7 +747,7 @@ presence_chooser_set_state (McPresence state, ...@@ -747,7 +747,7 @@ presence_chooser_set_state (McPresence state,
{ {
EmpathyIdle *idle; EmpathyIdle *idle;
idle = empathy_idle_new (); idle = empathy_idle_dup_singleton ();
empathy_idle_set_presence (idle, state, status); empathy_idle_set_presence (idle, state, status);
g_object_unref (idle); g_object_unref (idle);
} }
......
...@@ -76,7 +76,9 @@ enum { ...@@ -76,7 +76,9 @@ enum {
PROP_USE_NM 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 static void
idle_presence_changed_cb (MissionControl *mc, idle_presence_changed_cb (MissionControl *mc,
...@@ -271,6 +273,26 @@ idle_finalize (GObject *object) ...@@ -271,6 +273,26 @@ idle_finalize (GObject *object)
idle_ext_away_stop (EMPATHY_IDLE (object)); 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 static void
idle_get_property (GObject *object, idle_get_property (GObject *object,
guint param_id, guint param_id,
...@@ -345,6 +367,7 @@ empathy_idle_class_init (EmpathyIdleClass *klass) ...@@ -345,6 +367,7 @@ empathy_idle_class_init (EmpathyIdleClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = idle_finalize; object_class->finalize = idle_finalize;
object_class->constructor = idle_constructor;
object_class->get_property = idle_get_property; object_class->get_property = idle_get_property;
object_class->set_property = idle_set_property; object_class->set_property = idle_set_property;
...@@ -465,18 +488,9 @@ empathy_idle_init (EmpathyIdle *idle) ...@@ -465,18 +488,9 @@ empathy_idle_init (EmpathyIdle *idle)
} }
EmpathyIdle * EmpathyIdle *
empathy_idle_new (void) empathy_idle_dup_singleton (void)
{ {
static EmpathyIdle *idle = NULL; return g_object_new (EMPATHY_TYPE_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;
} }
McPresence McPresence
......
...@@ -48,7 +48,7 @@ struct _EmpathyIdleClass { ...@@ -48,7 +48,7 @@ struct _EmpathyIdleClass {
}; };
GType empathy_idle_get_type (void) G_GNUC_CONST; 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); McPresence empathy_idle_get_state (EmpathyIdle *idle);
void empathy_idle_set_state (EmpathyIdle *idle, void empathy_idle_set_state (EmpathyIdle *idle,
McPresence state); McPresence state);
......
...@@ -396,8 +396,8 @@ empathy_status_icon_init (EmpathyStatusIcon *icon) ...@@ -396,8 +396,8 @@ empathy_status_icon_init (EmpathyStatusIcon *icon)
icon->priv = priv; icon->priv = priv;
priv->icon = gtk_status_icon_new (); priv->icon = gtk_status_icon_new ();
priv->account_manager = empathy_account_manager_dup_singleton (); priv->account_manager = empathy_account_manager_dup_singleton ();
priv->idle = empathy_idle_new (); priv->idle = empathy_idle_dup_singleton ();
priv->event_manager = empathy_event_manager_new (); priv->event_manager = empathy_event_manager_dup_singleton ();
g_signal_connect (priv->account_manager, g_signal_connect (priv->account_manager,
"account-connection-changed", "account-connection-changed",
......
...@@ -473,7 +473,7 @@ main (int argc, char *argv[]) ...@@ -473,7 +473,7 @@ main (int argc, char *argv[])
} }
/* Setting up Idle */ /* Setting up Idle */
idle = empathy_idle_new (); idle = empathy_idle_dup_singleton ();
empathy_idle_set_auto_away (idle, TRUE); empathy_idle_set_auto_away (idle, TRUE);
use_nm_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_NM, idle); use_nm_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_NM, idle);
empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_NM, empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_NM,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment