]> git.0d.be Git - empathy.git/blob - libempathy/empathy-idle.c
all: log error messages if preparing the account manager fails
[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
29 #include <telepathy-glib/account-manager.h>
30 #include <telepathy-glib/dbus.h>
31 #include <telepathy-glib/util.h>
32
33 #include "empathy-idle.h"
34 #include "empathy-utils.h"
35 #include "empathy-connectivity.h"
36
37 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
38 #include "empathy-debug.h"
39
40 /* Number of seconds before entering extended autoaway. */
41 #define EXT_AWAY_TIME (30*60)
42
43 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIdle)
44 typedef struct {
45         DBusGProxy     *gs_proxy;
46         EmpathyConnectivity *connectivity;
47         gulong state_change_signal_id;
48
49         TpConnectionPresenceType      state;
50         gchar          *status;
51         TpConnectionPresenceType      flash_state;
52         gboolean        auto_away;
53
54         TpConnectionPresenceType      away_saved_state;
55         TpConnectionPresenceType      saved_state;
56         gchar          *saved_status;
57
58         gboolean        is_idle;
59         guint           ext_away_timeout;
60
61         TpAccountManager *manager;
62         GHashTable *connect_times;
63
64         TpConnectionPresenceType requested_presence_type;
65         gchar *requested_status_message;
66
67 } EmpathyIdlePriv;
68
69 typedef enum {
70         SESSION_STATUS_AVAILABLE,
71         SESSION_STATUS_INVISIBLE,
72         SESSION_STATUS_BUSY,
73         SESSION_STATUS_IDLE,
74         SESSION_STATUS_UNKNOWN
75 } SessionStatus;
76
77 enum {
78         PROP_0,
79         PROP_STATE,
80         PROP_STATUS,
81         PROP_FLASH_STATE,
82         PROP_AUTO_AWAY
83 };
84
85 G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT);
86
87 static EmpathyIdle * idle_singleton = NULL;
88
89 static const gchar *presence_type_to_status[NUM_TP_CONNECTION_PRESENCE_TYPES] = {
90         NULL,
91         "offline",
92         "available",
93         "away",
94         "xa",
95         "hidden",
96         "busy",
97         NULL,
98         NULL,
99 };
100
101 static void
102 idle_presence_changed_cb (TpAccountManager *manager,
103                           TpConnectionPresenceType state,
104                           gchar          *status,
105                           gchar          *status_message,
106                           EmpathyIdle    *idle)
107 {
108         EmpathyIdlePriv *priv;
109
110         priv = GET_PRIV (idle);
111
112         if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET)
113                 /* Assume our presence is offline if MC reports UNSET */
114                 state = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
115
116         DEBUG ("Presence changed to '%s' (%d) \"%s\"", status, state,
117                 status_message);
118
119         g_free (priv->status);
120         priv->state = state;
121         if (EMP_STR_EMPTY (status_message))
122                 priv->status = NULL;
123         else
124                 priv->status = g_strdup (status_message);
125
126         g_object_notify (G_OBJECT (idle), "state");
127         g_object_notify (G_OBJECT (idle), "status");
128 }
129
130 static gboolean
131 idle_ext_away_cb (EmpathyIdle *idle)
132 {
133         EmpathyIdlePriv *priv;
134
135         priv = GET_PRIV (idle);
136
137         DEBUG ("Going to extended autoaway");
138         empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY);
139         priv->ext_away_timeout = 0;
140
141         return FALSE;
142 }
143
144 static void
145 idle_ext_away_stop (EmpathyIdle *idle)
146 {
147         EmpathyIdlePriv *priv;
148
149         priv = GET_PRIV (idle);
150
151         if (priv->ext_away_timeout) {
152                 g_source_remove (priv->ext_away_timeout);
153                 priv->ext_away_timeout = 0;
154         }
155 }
156
157 static void
158 idle_ext_away_start (EmpathyIdle *idle)
159 {
160         EmpathyIdlePriv *priv;
161
162         priv = GET_PRIV (idle);
163
164         if (priv->ext_away_timeout != 0) {
165                 return;
166         }
167         priv->ext_away_timeout = g_timeout_add_seconds (EXT_AWAY_TIME,
168                                                         (GSourceFunc) idle_ext_away_cb,
169                                                         idle);
170 }
171
172 static void
173 idle_session_status_changed_cb (DBusGProxy    *gs_proxy,
174                                 SessionStatus  status,
175                                 EmpathyIdle   *idle)
176 {
177         EmpathyIdlePriv *priv;
178         gboolean is_idle;
179
180         priv = GET_PRIV (idle);
181
182         is_idle = (status == SESSION_STATUS_IDLE);
183
184         DEBUG ("Session idle state changed, %s -> %s",
185                 priv->is_idle ? "yes" : "no",
186                 is_idle ? "yes" : "no");
187
188         if (!priv->auto_away ||
189             (priv->saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
190              (priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
191               priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN))) {
192                 /* We don't want to go auto away OR we explicitely asked to be
193                  * offline, nothing to do here */
194                 priv->is_idle = is_idle;
195                 return;
196         }
197
198         if (is_idle && !priv->is_idle) {
199                 TpConnectionPresenceType new_state;
200                 /* We are now idle */
201
202                 idle_ext_away_start (idle);
203
204                 if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
205                         /* We are disconnected, when coming back from away
206                          * we want to restore the presence before the
207                          * disconnection. */
208                         priv->away_saved_state = priv->saved_state;
209                 } else {
210                         priv->away_saved_state = priv->state;
211                 }
212
213                 new_state = TP_CONNECTION_PRESENCE_TYPE_AWAY;
214                 if (priv->state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
215                         new_state = TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY;
216                 }
217
218                 DEBUG ("Going to autoaway. Saved state=%d, new state=%d",
219                         priv->away_saved_state, new_state);
220                 empathy_idle_set_state (idle, new_state);
221         } else if (!is_idle && priv->is_idle) {
222                 const gchar *new_status;
223                 /* We are no more idle, restore state */
224
225                 idle_ext_away_stop (idle);
226
227                 if (priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_AWAY ||
228                     priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
229                         priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
230                         new_status = NULL;
231                 } else {
232                         new_status = priv->status;
233                 }
234
235                 /* Only try and set the presence if the away saved state is not
236                  * unset. This is an odd case because it means that the session
237                  * didn't notify us of the state change to idle, and as a
238                  * result, we couldn't save the current state at that time.
239                  */
240                 if (priv->away_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
241                         DEBUG ("Restoring state to %d, reset status to %s",
242                                 priv->away_saved_state, new_status);
243
244                         empathy_idle_set_presence (idle,
245                                                    priv->away_saved_state,
246                                                    new_status);
247                 } else {
248                         DEBUG ("Away saved state is unset. This means that we "
249                                "weren't told when the session went idle. "
250                                "As a result, I'm not trying to set presence");
251                 }
252
253                 priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
254         }
255
256         priv->is_idle = is_idle;
257 }
258
259 static void
260 idle_state_change_cb (EmpathyConnectivity *connectivity,
261                       gboolean new_online,
262                       EmpathyIdle *idle)
263 {
264         EmpathyIdlePriv *priv;
265
266         priv = GET_PRIV (idle);
267
268         if (!new_online) {
269                 /* We are no longer connected */
270                 DEBUG ("Disconnected: Save state %d (%s)",
271                                 priv->state, priv->status);
272                 priv->saved_state = priv->state;
273                 g_free (priv->saved_status);
274                 priv->saved_status = g_strdup (priv->status);
275                 empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
276         }
277         else if (new_online
278                         && priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
279                 /* We are now connected */
280                 DEBUG ("Reconnected: Restore state %d (%s)",
281                                 priv->saved_state, priv->saved_status);
282                 empathy_idle_set_presence (idle,
283                                 priv->saved_state,
284                                 priv->saved_status);
285                 priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
286                 g_free (priv->saved_status);
287                 priv->saved_status = NULL;
288         }
289 }
290
291 static void
292 idle_finalize (GObject *object)
293 {
294         EmpathyIdlePriv *priv;
295
296         priv = GET_PRIV (object);
297
298         g_free (priv->status);
299         g_free (priv->requested_status_message);
300
301         if (priv->gs_proxy) {
302                 g_object_unref (priv->gs_proxy);
303         }
304
305         g_signal_handler_disconnect (priv->connectivity,
306                                      priv->state_change_signal_id);
307         priv->state_change_signal_id = 0;
308
309         g_object_unref (priv->connectivity);
310
311         g_hash_table_destroy (priv->connect_times);
312         priv->connect_times = NULL;
313
314         idle_ext_away_stop (EMPATHY_IDLE (object));
315 }
316
317 static GObject *
318 idle_constructor (GType type,
319                   guint n_props,
320                   GObjectConstructParam *props)
321 {
322         GObject *retval;
323
324         if (idle_singleton) {
325                 retval = g_object_ref (idle_singleton);
326         } else {
327                 retval = G_OBJECT_CLASS (empathy_idle_parent_class)->constructor
328                         (type, n_props, props);
329
330                 idle_singleton = EMPATHY_IDLE (retval);
331                 g_object_add_weak_pointer (retval, (gpointer) &idle_singleton);
332         }
333
334         return retval;
335 }
336
337 static void
338 idle_get_property (GObject    *object,
339                    guint       param_id,
340                    GValue     *value,
341                    GParamSpec *pspec)
342 {
343         EmpathyIdlePriv *priv;
344         EmpathyIdle     *idle;
345
346         priv = GET_PRIV (object);
347         idle = EMPATHY_IDLE (object);
348
349         switch (param_id) {
350         case PROP_STATE:
351                 g_value_set_enum (value, empathy_idle_get_state (idle));
352                 break;
353         case PROP_STATUS:
354                 g_value_set_string (value, empathy_idle_get_status (idle));
355                 break;
356         case PROP_FLASH_STATE:
357                 g_value_set_enum (value, empathy_idle_get_flash_state (idle));
358                 break;
359         case PROP_AUTO_AWAY:
360                 g_value_set_boolean (value, empathy_idle_get_auto_away (idle));
361                 break;
362         default:
363                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
364                 break;
365         };
366 }
367
368 static void
369 idle_set_property (GObject      *object,
370                    guint         param_id,
371                    const GValue *value,
372                    GParamSpec   *pspec)
373 {
374         EmpathyIdlePriv *priv;
375         EmpathyIdle     *idle;
376
377         priv = GET_PRIV (object);
378         idle = EMPATHY_IDLE (object);
379
380         switch (param_id) {
381         case PROP_STATE:
382                 empathy_idle_set_state (idle, g_value_get_enum (value));
383                 break;
384         case PROP_STATUS:
385                 empathy_idle_set_status (idle, g_value_get_string (value));
386                 break;
387         case PROP_FLASH_STATE:
388                 empathy_idle_set_flash_state (idle, g_value_get_enum (value));
389                 break;
390         case PROP_AUTO_AWAY:
391                 empathy_idle_set_auto_away (idle, g_value_get_boolean (value));
392                 break;
393         default:
394                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
395                 break;
396         };
397 }
398
399 static void
400 empathy_idle_class_init (EmpathyIdleClass *klass)
401 {
402         GObjectClass *object_class = G_OBJECT_CLASS (klass);
403
404         object_class->finalize = idle_finalize;
405         object_class->constructor = idle_constructor;
406         object_class->get_property = idle_get_property;
407         object_class->set_property = idle_set_property;
408
409         g_object_class_install_property (object_class,
410                                          PROP_STATE,
411                                          g_param_spec_uint ("state",
412                                                             "state",
413                                                             "state",
414                                                             0, NUM_TP_CONNECTION_PRESENCE_TYPES,
415                                                             TP_CONNECTION_PRESENCE_TYPE_UNSET,
416                                                             G_PARAM_READWRITE));
417         g_object_class_install_property (object_class,
418                                          PROP_STATUS,
419                                          g_param_spec_string ("status",
420                                                               "status",
421                                                               "status",
422                                                               NULL,
423                                                               G_PARAM_READWRITE));
424         g_object_class_install_property (object_class,
425                                          PROP_FLASH_STATE,
426                                          g_param_spec_uint ("flash-state",
427                                                             "flash-state",
428                                                             "flash-state",
429                                                             0, NUM_TP_CONNECTION_PRESENCE_TYPES,
430                                                             TP_CONNECTION_PRESENCE_TYPE_UNSET,
431                                                             G_PARAM_READWRITE));
432
433          g_object_class_install_property (object_class,
434                                           PROP_AUTO_AWAY,
435                                           g_param_spec_boolean ("auto-away",
436                                                                 "Automatic set presence to away",
437                                                                 "Should it set presence to away if inactive",
438                                                                 FALSE,
439                                                                 G_PARAM_READWRITE));
440
441         g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
442 }
443
444 static void
445 account_status_changed_cb (TpAccount  *account,
446                            guint       old_status,
447                            guint       new_status,
448                            guint       reason,
449                            gchar      *dbus_error_name,
450                            GHashTable *details,
451                            gpointer    user_data)
452 {
453         EmpathyIdle *idle = EMPATHY_IDLE (user_data);
454         EmpathyIdlePriv *priv = GET_PRIV (idle);
455         GTimeVal val;
456
457         if (new_status == TP_CONNECTION_STATUS_CONNECTED) {
458                 g_get_current_time (&val);
459                 g_hash_table_insert (priv->connect_times, account,
460                                      GINT_TO_POINTER (val.tv_sec));
461         } else if (new_status == TP_CONNECTION_STATUS_DISCONNECTED) {
462                 g_hash_table_remove (priv->connect_times, account);
463         }
464 }
465
466 static void
467 account_manager_ready_cb (GObject *source_object,
468                           GAsyncResult *result,
469                           gpointer user_data)
470 {
471         EmpathyIdle *idle = EMPATHY_IDLE (user_data);
472         TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
473         EmpathyIdlePriv *priv = GET_PRIV (idle);
474         TpConnectionPresenceType state;
475         gchar *status, *status_message;
476         GList *accounts, *l;
477         GError *error = NULL;
478
479         if (!tp_account_manager_prepare_finish (account_manager, result, &error)) {
480                 DEBUG ("Failed to prepare account manager: %s", error->message);
481                 g_error_free (error);
482                 return;
483         }
484
485         state = tp_account_manager_get_most_available_presence (priv->manager,
486                 &status, &status_message);
487
488         idle_presence_changed_cb (account_manager, state, status,
489                 status_message, idle);
490
491         accounts = tp_account_manager_get_valid_accounts (priv->manager);
492         for (l = accounts; l != NULL; l = l->next) {
493                 empathy_signal_connect_weak (l->data, "status-changed",
494                                              G_CALLBACK (account_status_changed_cb),
495                                              G_OBJECT (idle));
496         }
497         g_list_free (accounts);
498
499         g_free (status);
500         g_free (status_message);
501 }
502
503 static void
504 empathy_idle_init (EmpathyIdle *idle)
505 {
506         EmpathyIdlePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (idle,
507                 EMPATHY_TYPE_IDLE, EmpathyIdlePriv);
508
509         idle->priv = priv;
510         priv->is_idle = FALSE;
511
512         priv->manager = tp_account_manager_dup ();
513
514         tp_account_manager_prepare_async (priv->manager, NULL,
515             account_manager_ready_cb, idle);
516
517         g_signal_connect (priv->manager, "most-available-presence-changed",
518                 G_CALLBACK (idle_presence_changed_cb), idle);
519
520         priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
521                                                     "org.gnome.SessionManager",
522                                                     "/org/gnome/SessionManager/Presence",
523                                                     "org.gnome.SessionManager.Presence");
524         if (priv->gs_proxy) {
525                 dbus_g_proxy_add_signal (priv->gs_proxy, "StatusChanged",
526                                          G_TYPE_UINT, G_TYPE_INVALID);
527                 dbus_g_proxy_connect_signal (priv->gs_proxy, "StatusChanged",
528                                              G_CALLBACK (idle_session_status_changed_cb),
529                                              idle, NULL);
530         } else {
531                 DEBUG ("Failed to get gs proxy");
532         }
533
534         priv->connectivity = empathy_connectivity_dup_singleton ();
535         priv->state_change_signal_id = g_signal_connect (priv->connectivity,
536             "state-change", G_CALLBACK (idle_state_change_cb), idle);
537
538         priv->connect_times = g_hash_table_new (g_direct_hash, g_direct_equal);
539 }
540
541 EmpathyIdle *
542 empathy_idle_dup_singleton (void)
543 {
544         return g_object_new (EMPATHY_TYPE_IDLE, NULL);
545 }
546
547 TpConnectionPresenceType
548 empathy_idle_get_state (EmpathyIdle *idle)
549 {
550         EmpathyIdlePriv *priv;
551
552         priv = GET_PRIV (idle);
553
554         return priv->state;
555 }
556
557 void
558 empathy_idle_set_state (EmpathyIdle *idle,
559                         TpConnectionPresenceType   state)
560 {
561         EmpathyIdlePriv *priv;
562
563         priv = GET_PRIV (idle);
564
565         empathy_idle_set_presence (idle, state, priv->status);
566 }
567
568 const gchar *
569 empathy_idle_get_status (EmpathyIdle *idle)
570 {
571         EmpathyIdlePriv *priv;
572
573         priv = GET_PRIV (idle);
574
575         if (!priv->status) {
576                 return empathy_presence_get_default_message (priv->state);
577         }
578
579         return priv->status;
580 }
581
582 void
583 empathy_idle_set_status (EmpathyIdle *idle,
584                          const gchar *status)
585 {
586         EmpathyIdlePriv *priv;
587
588         priv = GET_PRIV (idle);
589
590         empathy_idle_set_presence (idle, priv->state, status);
591 }
592
593 TpConnectionPresenceType
594 empathy_idle_get_flash_state (EmpathyIdle *idle)
595 {
596         EmpathyIdlePriv *priv;
597
598         priv = GET_PRIV (idle);
599
600         return priv->flash_state;
601 }
602
603 void
604 empathy_idle_set_flash_state (EmpathyIdle *idle,
605                               TpConnectionPresenceType   state)
606 {
607         EmpathyIdlePriv *priv;
608
609         priv = GET_PRIV (idle);
610
611         priv->flash_state = state;
612
613         if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET) {
614         }
615
616         g_object_notify (G_OBJECT (idle), "flash-state");
617 }
618
619 static void
620 empathy_idle_do_set_presence (EmpathyIdle *idle,
621                            TpConnectionPresenceType status_type,
622                            const gchar *status_message)
623 {
624         EmpathyIdlePriv *priv = GET_PRIV (idle);
625         const gchar *status;
626
627         g_assert (status_type > 0 && status_type < NUM_TP_CONNECTION_PRESENCE_TYPES);
628
629         status = presence_type_to_status[status_type];
630
631         g_return_if_fail (status != NULL);
632
633         /* FIXME: Should be sure that the account manager is prepared, but
634          * sometimes this isn't possible, like when exiting. In other words,
635          * we need a callback to empathy_idle_set_presence to be sure the
636          * presence is set on all accounts successfully. */
637         tp_account_manager_set_all_requested_presences (priv->manager,
638                 status_type, status, status_message);
639 }
640
641 void
642 empathy_idle_set_presence (EmpathyIdle *idle,
643                            TpConnectionPresenceType   state,
644                            const gchar *status)
645 {
646         EmpathyIdlePriv *priv;
647         const gchar     *default_status;
648
649         priv = GET_PRIV (idle);
650
651         DEBUG ("Changing presence to %s (%d)", status, state);
652
653         g_free (priv->requested_status_message);
654         priv->requested_presence_type = state;
655         priv->requested_status_message = g_strdup (status);
656
657         /* Do not set translated default messages */
658         default_status = empathy_presence_get_default_message (state);
659         if (!tp_strdiff (status, default_status)) {
660                 status = NULL;
661         }
662
663         if (state != TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
664                         !empathy_connectivity_is_online (priv->connectivity)) {
665                 DEBUG ("Empathy is not online");
666
667                 priv->saved_state = state;
668                 if (tp_strdiff (priv->status, status)) {
669                         g_free (priv->saved_status);
670                         priv->saved_status = NULL;
671                         if (!EMP_STR_EMPTY (status)) {
672                                 priv->saved_status = g_strdup (status);
673                         }
674                 }
675                 return;
676         }
677
678         empathy_idle_do_set_presence (idle, state, status);
679 }
680
681 gboolean
682 empathy_idle_get_auto_away (EmpathyIdle *idle)
683 {
684         EmpathyIdlePriv *priv = GET_PRIV (idle);
685
686         return priv->auto_away;
687 }
688
689 void
690 empathy_idle_set_auto_away (EmpathyIdle *idle,
691                             gboolean     auto_away)
692 {
693         EmpathyIdlePriv *priv = GET_PRIV (idle);
694
695         priv->auto_away = auto_away;
696
697         g_object_notify (G_OBJECT (idle), "auto-away");
698 }
699
700 TpConnectionPresenceType
701 empathy_idle_get_requested_presence (EmpathyIdle *idle,
702     gchar **status,
703     gchar **status_message)
704 {
705         EmpathyIdlePriv *priv = GET_PRIV (idle);
706
707         if (status != NULL) {
708                 *status = g_strdup (presence_type_to_status[priv->requested_presence_type]);
709         }
710
711         if (status_message != NULL) {
712                 *status_message = g_strdup (priv->requested_status_message);
713         }
714
715         return priv->requested_presence_type;
716 }
717
718 gboolean
719 empathy_idle_account_is_just_connected (EmpathyIdle *idle,
720                                         TpAccount *account)
721 {
722         EmpathyIdlePriv *priv = GET_PRIV (idle);
723         GTimeVal val;
724         gpointer ptr;
725         glong t;
726
727         if (tp_account_get_connection_status (account, NULL)
728             != TP_CONNECTION_STATUS_CONNECTED) {
729                 return FALSE;
730         }
731
732         ptr = g_hash_table_lookup (priv->connect_times, account);
733
734         if (ptr == NULL) {
735                 return FALSE;
736         }
737
738         t = GPOINTER_TO_INT (ptr);
739
740         g_get_current_time (&val);
741
742         return (val.tv_sec - t) < 10;
743 }