]> git.0d.be Git - empathy.git/blob - libempathy/empathy-idle.c
Always react when disconnecting from the network
[empathy.git] / libempathy / empathy-idle.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include <config.h>
23
24 #include <string.h>
25
26 #include <glib/gi18n-lib.h>
27 #include <dbus/dbus-glib.h>
28 #ifdef HAVE_NM
29 #include <nm-client.h>
30 #endif
31
32 #include <telepathy-glib/dbus.h>
33 #include <telepathy-glib/util.h>
34 #include <libmissioncontrol/mc-enum-types.h>
35
36 #include "empathy-idle.h"
37 #include "empathy-utils.h"
38
39 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
40 #include "empathy-debug.h"
41
42 /* Number of seconds before entering extended autoaway. */
43 #define EXT_AWAY_TIME (30*60)
44
45 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIdle)
46 typedef struct {
47         MissionControl *mc;
48         DBusGProxy     *gs_proxy;
49 #ifdef HAVE_NM
50         NMClient       *nm_client;
51 #endif
52
53         TpConnectionPresenceType      state;
54         gchar          *status;
55         TpConnectionPresenceType      flash_state;
56         gboolean        auto_away;
57         gboolean        use_nm;
58
59         TpConnectionPresenceType      away_saved_state;
60         TpConnectionPresenceType      nm_saved_state;
61         gchar          *nm_saved_status;
62
63         gboolean        is_idle;
64         gboolean        nm_connected;
65         guint           ext_away_timeout;
66 } EmpathyIdlePriv;
67
68 typedef enum {
69         SESSION_STATUS_AVAILABLE,
70         SESSION_STATUS_INVISIBLE,
71         SESSION_STATUS_BUSY,
72         SESSION_STATUS_IDLE,
73         SESSION_STATUS_UNKNOWN
74 } SessionStatus;
75
76 enum {
77         PROP_0,
78         PROP_STATE,
79         PROP_STATUS,
80         PROP_FLASH_STATE,
81         PROP_AUTO_AWAY,
82         PROP_USE_NM
83 };
84
85 G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT);
86
87 static EmpathyIdle * idle_singleton = NULL;
88
89 static void
90 idle_presence_changed_cb (MissionControl *mc,
91                           TpConnectionPresenceType state,
92                           gchar          *status,
93                           EmpathyIdle    *idle)
94 {
95         EmpathyIdlePriv *priv;
96
97         priv = GET_PRIV (idle);
98
99         if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET)
100                 /* Assume our presence is offline if MC reports UNSET */
101                 state = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
102
103         DEBUG ("Presence changed to '%s' (%d)", status, state);
104
105         g_free (priv->status);
106         priv->state = state;
107         priv->status = NULL;
108         if (!EMP_STR_EMPTY (status)) {
109                 priv->status = g_strdup (status);
110         }
111
112         g_object_notify (G_OBJECT (idle), "state");
113         g_object_notify (G_OBJECT (idle), "status");
114 }
115
116 static gboolean
117 idle_ext_away_cb (EmpathyIdle *idle)
118 {
119         EmpathyIdlePriv *priv;
120
121         priv = GET_PRIV (idle);
122
123         DEBUG ("Going to extended autoaway");
124         empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY);
125         priv->ext_away_timeout = 0;
126
127         return FALSE;
128 }
129
130 static void
131 idle_ext_away_stop (EmpathyIdle *idle)
132 {
133         EmpathyIdlePriv *priv;
134
135         priv = GET_PRIV (idle);
136
137         if (priv->ext_away_timeout) {
138                 g_source_remove (priv->ext_away_timeout);
139                 priv->ext_away_timeout = 0;
140         }
141 }
142
143 static void
144 idle_ext_away_start (EmpathyIdle *idle)
145 {
146         EmpathyIdlePriv *priv;
147
148         priv = GET_PRIV (idle);
149
150         if (priv->ext_away_timeout != 0) {
151                 return;
152         }
153         priv->ext_away_timeout = g_timeout_add_seconds (EXT_AWAY_TIME,
154                                                         (GSourceFunc) idle_ext_away_cb,
155                                                         idle);
156 }
157
158 static void
159 idle_session_status_changed_cb (DBusGProxy    *gs_proxy,
160                                 SessionStatus  status,
161                                 EmpathyIdle   *idle)
162 {
163         EmpathyIdlePriv *priv;
164         gboolean is_idle;
165
166         priv = GET_PRIV (idle);
167
168         is_idle = (status == SESSION_STATUS_IDLE);
169
170         DEBUG ("Session idle state changed, %s -> %s",
171                 priv->is_idle ? "yes" : "no",
172                 is_idle ? "yes" : "no");
173
174         if (!priv->auto_away ||
175             (priv->nm_saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
176              (priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
177               priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN))) {
178                 /* We don't want to go auto away OR we explicitely asked to be
179                  * offline, nothing to do here */
180                 priv->is_idle = is_idle;
181                 return;
182         }
183
184         if (is_idle && !priv->is_idle) {
185                 TpConnectionPresenceType new_state;
186                 /* We are now idle */
187
188                 idle_ext_away_start (idle);
189
190                 if (priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
191                         /* We are disconnected, when coming back from away
192                          * we want to restore the presence before the
193                          * disconnection. */
194                         priv->away_saved_state = priv->nm_saved_state;
195                 } else {
196                         priv->away_saved_state = priv->state;
197                 }
198
199                 new_state = TP_CONNECTION_PRESENCE_TYPE_AWAY;
200                 if (priv->state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
201                         new_state = TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY;
202                 }
203
204                 DEBUG ("Going to autoaway. Saved state=%d, new state=%d",
205                         priv->away_saved_state, new_state);
206                 empathy_idle_set_state (idle, new_state);
207         } else if (!is_idle && priv->is_idle) {
208                 const gchar *new_status;
209                 /* We are no more idle, restore state */
210
211                 idle_ext_away_stop (idle);
212
213                 if (priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_AWAY ||
214                     priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
215                         priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
216                         new_status = NULL;
217                 } else {
218                         new_status = priv->status;
219                 }
220
221                 DEBUG ("Restoring state to %d, reset status to %s",
222                         priv->away_saved_state, new_status);
223
224                 empathy_idle_set_presence (idle,
225                                            priv->away_saved_state,
226                                            new_status);
227
228                 priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
229         }
230
231         priv->is_idle = is_idle;
232 }
233
234 #ifdef HAVE_NM
235 static void
236 idle_nm_state_change_cb (NMClient         *client,
237                          const GParamSpec *pspec,
238                          EmpathyIdle      *idle)
239 {
240         EmpathyIdlePriv *priv;
241         gboolean         old_nm_connected;
242         gboolean         new_nm_connected;
243         NMState          state;
244
245         priv = GET_PRIV (idle);
246
247         if (!priv->use_nm) {
248                 return;
249         }
250
251         state = nm_client_get_state (priv->nm_client);
252         old_nm_connected = priv->nm_connected;
253         new_nm_connected = !(state == NM_STATE_CONNECTING ||
254                              state == NM_STATE_DISCONNECTED);
255         priv->nm_connected = TRUE; /* To be sure _set_state will work */
256
257         DEBUG ("New network state %d", state);
258
259         if (old_nm_connected && !new_nm_connected) {
260                 /* We are no more connected */
261                 DEBUG ("Disconnected: Save state %d (%s)",
262                                 priv->state, priv->status);
263                 priv->nm_saved_state = priv->state;
264                 g_free (priv->nm_saved_status);
265                 priv->nm_saved_status = g_strdup (priv->status);
266                 empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
267         }
268         else if (!old_nm_connected && new_nm_connected
269                         && priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
270                 /* We are now connected */
271                 DEBUG ("Reconnected: Restore state %d (%s)",
272                                 priv->nm_saved_state, priv->nm_saved_status);
273                 empathy_idle_set_presence (idle,
274                                 priv->nm_saved_state,
275                                 priv->nm_saved_status);
276                 priv->nm_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
277                 g_free (priv->nm_saved_status);
278                 priv->nm_saved_status = NULL;
279         }
280
281         priv->nm_connected = new_nm_connected;
282 }
283 #endif
284
285 static void
286 idle_finalize (GObject *object)
287 {
288         EmpathyIdlePriv *priv;
289
290         priv = GET_PRIV (object);
291
292         g_free (priv->status);
293         g_object_unref (priv->mc);
294
295         if (priv->gs_proxy) {
296                 g_object_unref (priv->gs_proxy);
297         }
298
299 #ifdef HAVE_NM
300         if (priv->nm_client) {
301                 g_object_unref (priv->nm_client);
302         }
303 #endif
304
305         idle_ext_away_stop (EMPATHY_IDLE (object));
306 }
307
308 static GObject *
309 idle_constructor (GType type,
310                   guint n_props,
311                   GObjectConstructParam *props)
312 {
313         GObject *retval;
314
315         if (idle_singleton) {
316                 retval = g_object_ref (idle_singleton);
317         } else {
318                 retval = G_OBJECT_CLASS (empathy_idle_parent_class)->constructor
319                         (type, n_props, props);
320
321                 idle_singleton = EMPATHY_IDLE (retval);
322                 g_object_add_weak_pointer (retval, (gpointer) &idle_singleton);
323         }
324
325         return retval;
326 }
327
328 static void
329 idle_get_property (GObject    *object,
330                    guint       param_id,
331                    GValue     *value,
332                    GParamSpec *pspec)
333 {
334         EmpathyIdlePriv *priv;
335         EmpathyIdle     *idle;
336
337         priv = GET_PRIV (object);
338         idle = EMPATHY_IDLE (object);
339
340         switch (param_id) {
341         case PROP_STATE:
342                 g_value_set_enum (value, empathy_idle_get_state (idle));
343                 break;
344         case PROP_STATUS:
345                 g_value_set_string (value, empathy_idle_get_status (idle));
346                 break;
347         case PROP_FLASH_STATE:
348                 g_value_set_enum (value, empathy_idle_get_flash_state (idle));
349                 break;
350         case PROP_AUTO_AWAY:
351                 g_value_set_boolean (value, empathy_idle_get_auto_away (idle));
352                 break;
353         case PROP_USE_NM:
354                 g_value_set_boolean (value, empathy_idle_get_use_nm (idle));
355                 break;
356         default:
357                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
358                 break;
359         };
360 }
361
362 static void
363 idle_set_property (GObject      *object,
364                    guint         param_id,
365                    const GValue *value,
366                    GParamSpec   *pspec)
367 {
368         EmpathyIdlePriv *priv;
369         EmpathyIdle     *idle;
370
371         priv = GET_PRIV (object);
372         idle = EMPATHY_IDLE (object);
373
374         switch (param_id) {
375         case PROP_STATE:
376                 empathy_idle_set_state (idle, g_value_get_enum (value));
377                 break;
378         case PROP_STATUS:
379                 empathy_idle_set_status (idle, g_value_get_string (value));
380                 break;
381         case PROP_FLASH_STATE:
382                 empathy_idle_set_flash_state (idle, g_value_get_enum (value));
383                 break;
384         case PROP_AUTO_AWAY:
385                 empathy_idle_set_auto_away (idle, g_value_get_boolean (value));
386                 break;
387         case PROP_USE_NM:
388                 empathy_idle_set_use_nm (idle, g_value_get_boolean (value));
389                 break;
390         default:
391                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
392                 break;
393         };
394 }
395
396 static void
397 empathy_idle_class_init (EmpathyIdleClass *klass)
398 {
399         GObjectClass *object_class = G_OBJECT_CLASS (klass);
400
401         object_class->finalize = idle_finalize;
402         object_class->constructor = idle_constructor;
403         object_class->get_property = idle_get_property;
404         object_class->set_property = idle_set_property;
405
406         g_object_class_install_property (object_class,
407                                          PROP_STATE,
408                                          g_param_spec_uint ("state",
409                                                             "state",
410                                                             "state",
411                                                             0, NUM_TP_CONNECTION_PRESENCE_TYPES,
412                                                             TP_CONNECTION_PRESENCE_TYPE_UNSET,
413                                                             G_PARAM_READWRITE));
414         g_object_class_install_property (object_class,
415                                          PROP_STATUS,
416                                          g_param_spec_string ("status",
417                                                               "status",
418                                                               "status",
419                                                               NULL,
420                                                               G_PARAM_READWRITE));
421         g_object_class_install_property (object_class,
422                                          PROP_FLASH_STATE,
423                                          g_param_spec_uint ("flash-state",
424                                                             "flash-state",
425                                                             "flash-state",
426                                                             0, NUM_TP_CONNECTION_PRESENCE_TYPES,
427                                                             TP_CONNECTION_PRESENCE_TYPE_UNSET,
428                                                             G_PARAM_READWRITE));
429
430          g_object_class_install_property (object_class,
431                                           PROP_AUTO_AWAY,
432                                           g_param_spec_boolean ("auto-away",
433                                                                 "Automatic set presence to away",
434                                                                 "Should it set presence to away if inactive",
435                                                                 FALSE,
436                                                                 G_PARAM_READWRITE));
437
438          g_object_class_install_property (object_class,
439                                           PROP_USE_NM,
440                                           g_param_spec_boolean ("use-nm",
441                                                                 "Use Network Manager",
442                                                                 "Set presence according to Network Manager",
443                                                                 FALSE,
444                                                                 G_PARAM_READWRITE));
445
446         g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
447 }
448
449 static TpConnectionPresenceType
450 empathy_idle_get_actual_presence (EmpathyIdle *idle, GError **error)
451 {
452         McPresence presence;
453         EmpathyIdlePriv *priv = GET_PRIV (idle);
454
455         presence = mission_control_get_presence_actual (priv->mc, error);
456
457         switch (presence) {
458         case MC_PRESENCE_OFFLINE:
459                 return TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
460         case MC_PRESENCE_AVAILABLE:
461                 return TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
462         case MC_PRESENCE_AWAY:
463                 return TP_CONNECTION_PRESENCE_TYPE_AWAY;
464         case MC_PRESENCE_EXTENDED_AWAY:
465                 return TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY;
466         case MC_PRESENCE_HIDDEN:
467                 return TP_CONNECTION_PRESENCE_TYPE_HIDDEN;
468         case MC_PRESENCE_DO_NOT_DISTURB:
469                 return TP_CONNECTION_PRESENCE_TYPE_BUSY;
470         default:
471                 return TP_CONNECTION_PRESENCE_TYPE_UNSET;
472         }
473 }
474
475 static void
476 empathy_idle_init (EmpathyIdle *idle)
477 {
478         GError          *error = NULL;
479         EmpathyIdlePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (idle,
480                 EMPATHY_TYPE_IDLE, EmpathyIdlePriv);
481
482         idle->priv = priv;
483         priv->is_idle = FALSE;
484         priv->mc = empathy_mission_control_dup_singleton ();
485         priv->state = empathy_idle_get_actual_presence (idle, &error);
486         if (error) {
487                 DEBUG ("Error getting actual presence: %s", error->message);
488
489                 /* Fallback to OFFLINE as that's what mission_control_get_presence_actual
490                 does. This also ensure to always display the status icon (there is no
491                 unset presence icon). */
492                 priv->state = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
493                 g_clear_error (&error);
494         }
495         priv->status = mission_control_get_presence_message_actual (priv->mc, &error);
496         if (error || EMP_STR_EMPTY (priv->status)) {
497                 g_free (priv->status);
498                 priv->status = NULL;
499
500                 if (error) {
501                         DEBUG ("Error getting actual presence message: %s", error->message);
502                         g_clear_error (&error);
503                 }
504         }
505
506         dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
507                                      "PresenceChanged",
508                                      G_CALLBACK (idle_presence_changed_cb),
509                                      idle, NULL);
510
511         priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
512                                                     "org.gnome.SessionManager",
513                                                     "/org/gnome/SessionManager/Presence",
514                                                     "org.gnome.SessionManager.Presence");
515         if (priv->gs_proxy) {
516                 dbus_g_proxy_add_signal (priv->gs_proxy, "StatusChanged",
517                                          G_TYPE_UINT, G_TYPE_INVALID);
518                 dbus_g_proxy_connect_signal (priv->gs_proxy, "StatusChanged",
519                                              G_CALLBACK (idle_session_status_changed_cb),
520                                              idle, NULL);
521         } else {
522                 DEBUG ("Failed to get gs proxy");
523         }
524
525 #ifdef HAVE_NM
526         priv->nm_client = nm_client_new ();
527         if (priv->nm_client) {
528                 g_signal_connect (priv->nm_client, "notify::" NM_CLIENT_STATE,
529                                   G_CALLBACK (idle_nm_state_change_cb),
530                                   idle);
531         } else {
532                 DEBUG ("Failed to get nm proxy");
533         }
534
535         priv->nm_connected = TRUE;
536 #endif
537 }
538
539 EmpathyIdle *
540 empathy_idle_dup_singleton (void)
541 {
542         return g_object_new (EMPATHY_TYPE_IDLE, NULL);
543 }
544
545 TpConnectionPresenceType
546 empathy_idle_get_state (EmpathyIdle *idle)
547 {
548         EmpathyIdlePriv *priv;
549
550         priv = GET_PRIV (idle);
551
552         return priv->state;
553 }
554
555 void
556 empathy_idle_set_state (EmpathyIdle *idle,
557                         TpConnectionPresenceType   state)
558 {
559         EmpathyIdlePriv *priv;
560
561         priv = GET_PRIV (idle);
562
563         empathy_idle_set_presence (idle, state, priv->status);
564 }
565
566 const gchar *
567 empathy_idle_get_status (EmpathyIdle *idle)
568 {
569         EmpathyIdlePriv *priv;
570
571         priv = GET_PRIV (idle);
572
573         if (!priv->status) {
574                 return empathy_presence_get_default_message (priv->state);
575         }
576
577         return priv->status;
578 }
579
580 void
581 empathy_idle_set_status (EmpathyIdle *idle,
582                          const gchar *status)
583 {
584         EmpathyIdlePriv *priv;
585
586         priv = GET_PRIV (idle);
587
588         empathy_idle_set_presence (idle, priv->state, status);
589 }
590
591 TpConnectionPresenceType
592 empathy_idle_get_flash_state (EmpathyIdle *idle)
593 {
594         EmpathyIdlePriv *priv;
595
596         priv = GET_PRIV (idle);
597
598         return priv->flash_state;
599 }
600
601 void
602 empathy_idle_set_flash_state (EmpathyIdle *idle,
603                               TpConnectionPresenceType   state)
604 {
605         EmpathyIdlePriv *priv;
606
607         priv = GET_PRIV (idle);
608
609         priv->flash_state = state;
610
611         if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET) {
612         }
613
614         g_object_notify (G_OBJECT (idle), "flash-state");
615 }
616
617 static void
618 empathy_idle_do_set_presence (EmpathyIdle *idle,
619                            TpConnectionPresenceType   state,
620                            const gchar *status)
621 {
622         McPresence mc_state = MC_PRESENCE_UNSET;
623         EmpathyIdlePriv *priv = GET_PRIV (idle);
624
625         switch (state) {
626                 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
627                         mc_state = MC_PRESENCE_OFFLINE;
628                         break;
629                 case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
630                         mc_state = MC_PRESENCE_AVAILABLE;
631                         break;
632                 case TP_CONNECTION_PRESENCE_TYPE_AWAY:
633                         mc_state = MC_PRESENCE_AWAY;
634                         break;
635                 case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
636                         mc_state = MC_PRESENCE_EXTENDED_AWAY;
637                         break;
638                 case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
639                         mc_state = MC_PRESENCE_HIDDEN;
640                         break;
641                 case TP_CONNECTION_PRESENCE_TYPE_BUSY:
642                         mc_state = MC_PRESENCE_DO_NOT_DISTURB;
643                         break;
644                 default:
645                         g_assert_not_reached ();
646         }
647
648         mission_control_set_presence (priv->mc, mc_state, status, NULL, NULL);
649 }
650
651 void
652 empathy_idle_set_presence (EmpathyIdle *idle,
653                            TpConnectionPresenceType   state,
654                            const gchar *status)
655 {
656         EmpathyIdlePriv *priv;
657         const gchar     *default_status;
658
659         priv = GET_PRIV (idle);
660
661         DEBUG ("Changing presence to %s (%d)", status, state);
662
663         /* Do not set translated default messages */
664         default_status = empathy_presence_get_default_message (state);
665         if (!tp_strdiff (status, default_status)) {
666                 status = NULL;
667         }
668
669         if (!priv->nm_connected) {
670                 DEBUG ("NM not connected");
671
672                 priv->nm_saved_state = state;
673                 if (tp_strdiff (priv->status, status)) {
674                         g_free (priv->status);
675                         priv->status = NULL;
676                         if (!EMP_STR_EMPTY (status)) {
677                                 priv->status = g_strdup (status);
678                         }
679                         g_object_notify (G_OBJECT (idle), "status");
680                 }
681
682                 return;
683         }
684
685         empathy_idle_do_set_presence (idle, state, status);
686 }
687
688 gboolean
689 empathy_idle_get_auto_away (EmpathyIdle *idle)
690 {
691         EmpathyIdlePriv *priv = GET_PRIV (idle);
692
693         return priv->auto_away;
694 }
695
696 void
697 empathy_idle_set_auto_away (EmpathyIdle *idle,
698                             gboolean     auto_away)
699 {
700         EmpathyIdlePriv *priv = GET_PRIV (idle);
701
702         priv->auto_away = auto_away;
703
704         g_object_notify (G_OBJECT (idle), "auto-away");
705 }
706
707 gboolean
708 empathy_idle_get_use_nm (EmpathyIdle *idle)
709 {
710         EmpathyIdlePriv *priv = GET_PRIV (idle);
711
712         return priv->use_nm;
713 }
714
715 void
716 empathy_idle_set_use_nm (EmpathyIdle *idle,
717                          gboolean     use_nm)
718 {
719         EmpathyIdlePriv *priv = GET_PRIV (idle);
720
721 #ifdef HAVE_NM
722         if (!priv->nm_client || use_nm == priv->use_nm) {
723                 return;
724         }
725 #endif
726
727         priv->use_nm = use_nm;
728
729 #ifdef HAVE_NM
730         if (use_nm) {
731                 idle_nm_state_change_cb (priv->nm_client, NULL, idle);
732 #else
733         if (0) {
734 #endif
735         } else {
736                 priv->nm_connected = TRUE;
737                 if (priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
738                         empathy_idle_set_state (idle, priv->nm_saved_state);
739                 }
740                 priv->nm_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
741         }
742
743         g_object_notify (G_OBJECT (idle), "use-nm");
744 }
745