]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-idle.c
Add empathy_tp_chat_get_connection() to direct access the channel's connection.
[empathy.git] / libempathy / empathy-idle.c
index 2751f7cfafc0d5729392febc8ced689bd589a68c..eeb183892e64ddab5ec42931ff1431997d01a051 100644 (file)
@@ -53,6 +53,7 @@ typedef struct {
 
        McPresence      away_saved_state;
        McPresence      nm_saved_state;
+       gchar          *nm_saved_status;
 
        gboolean        is_idle;
        gboolean        nm_connected;
@@ -95,7 +96,7 @@ idle_presence_changed_cb (MissionControl *mc,
        g_free (priv->status);
        priv->state = state;
        priv->status = NULL;
-       if (!G_STR_EMPTY (status)) {
+       if (!EMP_STR_EMPTY (status)) {
                priv->status = g_strdup (status);
        }
 
@@ -242,15 +243,23 @@ idle_nm_state_change_cb (DBusGProxy  *proxy,
 
        if (old_nm_connected && !new_nm_connected) {
                /* We are no more connected */
-               DEBUG ("Disconnected: Save state %d", priv->state);
+               DEBUG ("Disconnected: Save state %d (%s)",
+                               priv->state, priv->status);
                priv->nm_saved_state = priv->state;
+               g_free (priv->nm_saved_status);
+               priv->nm_saved_status = g_strdup (priv->status);
                empathy_idle_set_state (idle, MC_PRESENCE_OFFLINE);
        }
        else if (!old_nm_connected && new_nm_connected) {
                /* We are now connected */
-               DEBUG ("Reconnected: Restore state %d", priv->nm_saved_state);
-               empathy_idle_set_state (idle, priv->nm_saved_state);
+               DEBUG ("Reconnected: Restore state %d (%s)",
+                               priv->nm_saved_state, priv->nm_saved_status);
+               empathy_idle_set_presence (idle,
+                               priv->nm_saved_state,
+                               priv->nm_saved_status);
                priv->nm_saved_state = MC_PRESENCE_UNSET;
+               g_free (priv->nm_saved_status);
+               priv->nm_saved_status = NULL;
        }
 
        priv->nm_connected = new_nm_connected;
@@ -285,9 +294,9 @@ idle_constructor (GType type,
        } 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);
+               g_object_add_weak_pointer (retval, (gpointer) &idle_singleton);
        }
 
        return retval;
@@ -424,7 +433,7 @@ empathy_idle_init (EmpathyIdle *idle)
 
        idle->priv = priv;
        priv->is_idle = FALSE;
-       priv->mc = empathy_mission_control_new ();
+       priv->mc = empathy_mission_control_dup_singleton ();
        priv->state = mission_control_get_presence_actual (priv->mc, &error);
        if (error) {
                DEBUG ("Error getting actual presence: %s", error->message);
@@ -433,7 +442,7 @@ empathy_idle_init (EmpathyIdle *idle)
                g_clear_error (&error);
        }
        priv->status = mission_control_get_presence_message_actual (priv->mc, &error);
-       if (error || G_STR_EMPTY (priv->status)) {
+       if (error || EMP_STR_EMPTY (priv->status)) {
                g_free (priv->status);
                priv->status = NULL;
 
@@ -590,7 +599,7 @@ empathy_idle_set_presence (EmpathyIdle *idle,
                if (tp_strdiff (priv->status, status)) {
                        g_free (priv->status);
                        priv->status = NULL;
-                       if (!G_STR_EMPTY (status)) {
+                       if (!EMP_STR_EMPTY (status)) {
                                priv->status = g_strdup (status);
                        }
                        g_object_notify (G_OBJECT (idle), "status");