]> git.0d.be Git - empathy.git/blob - libempathy/empathy-idle.c
contact-manager, dispatcher: renamed _new_connection_cb to _status_changed_cb
[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
478         if (!tp_account_manager_prepare_finish (account_manager, result, NULL)) {
479                 return;
480         }
481
482         state = tp_account_manager_get_most_available_presence (priv->manager,
483                 &status, &status_message);
484
485         idle_presence_changed_cb (account_manager, state, status,
486                 status_message, idle);
487
488         accounts = tp_account_manager_get_valid_accounts (priv->manager);
489         for (l = accounts; l != NULL; l = l->next) {
490                 empathy_signal_connect_weak (l->data, "status-changed",
491                                              G_CALLBACK (account_status_changed_cb),
492                                              G_OBJECT (idle));
493         }
494         g_list_free (accounts);
495
496         g_free (status);
497         g_free (status_message);
498 }
499
500 static void
501 empathy_idle_init (EmpathyIdle *idle)
502 {
503         EmpathyIdlePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (idle,
504                 EMPATHY_TYPE_IDLE, EmpathyIdlePriv);
505
506         idle->priv = priv;
507         priv->is_idle = FALSE;
508
509         priv->manager = tp_account_manager_dup ();
510
511         tp_account_manager_prepare_async (priv->manager, NULL,
512             account_manager_ready_cb, idle);
513
514         g_signal_connect (priv->manager, "most-available-presence-changed",
515                 G_CALLBACK (idle_presence_changed_cb), idle);
516
517         priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
518                                                     "org.gnome.SessionManager",
519                                                     "/org/gnome/SessionManager/Presence",
520                                                     "org.gnome.SessionManager.Presence");
521         if (priv->gs_proxy) {
522                 dbus_g_proxy_add_signal (priv->gs_proxy, "StatusChanged",
523                                          G_TYPE_UINT, G_TYPE_INVALID);
524                 dbus_g_proxy_connect_signal (priv->gs_proxy, "StatusChanged",
525                                              G_CALLBACK (idle_session_status_changed_cb),
526                                              idle, NULL);
527         } else {
528                 DEBUG ("Failed to get gs proxy");
529         }
530
531         priv->connectivity = empathy_connectivity_dup_singleton ();
532         priv->state_change_signal_id = g_signal_connect (priv->connectivity,
533             "state-change", G_CALLBACK (idle_state_change_cb), idle);
534
535         priv->connect_times = g_hash_table_new (g_direct_hash, g_direct_equal);
536 }
537
538 EmpathyIdle *
539 empathy_idle_dup_singleton (void)
540 {
541         return g_object_new (EMPATHY_TYPE_IDLE, NULL);
542 }
543
544 TpConnectionPresenceType
545 empathy_idle_get_state (EmpathyIdle *idle)
546 {
547         EmpathyIdlePriv *priv;
548
549         priv = GET_PRIV (idle);
550
551         return priv->state;
552 }
553
554 void
555 empathy_idle_set_state (EmpathyIdle *idle,
556                         TpConnectionPresenceType   state)
557 {
558         EmpathyIdlePriv *priv;
559
560         priv = GET_PRIV (idle);
561
562         empathy_idle_set_presence (idle, state, priv->status);
563 }
564
565 const gchar *
566 empathy_idle_get_status (EmpathyIdle *idle)
567 {
568         EmpathyIdlePriv *priv;
569
570         priv = GET_PRIV (idle);
571
572         if (!priv->status) {
573                 return empathy_presence_get_default_message (priv->state);
574         }
575
576         return priv->status;
577 }
578
579 void
580 empathy_idle_set_status (EmpathyIdle *idle,
581                          const gchar *status)
582 {
583         EmpathyIdlePriv *priv;
584
585         priv = GET_PRIV (idle);
586
587         empathy_idle_set_presence (idle, priv->state, status);
588 }
589
590 TpConnectionPresenceType
591 empathy_idle_get_flash_state (EmpathyIdle *idle)
592 {
593         EmpathyIdlePriv *priv;
594
595         priv = GET_PRIV (idle);
596
597         return priv->flash_state;
598 }
599
600 void
601 empathy_idle_set_flash_state (EmpathyIdle *idle,
602                               TpConnectionPresenceType   state)
603 {
604         EmpathyIdlePriv *priv;
605
606         priv = GET_PRIV (idle);
607
608         priv->flash_state = state;
609
610         if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET) {
611         }
612
613         g_object_notify (G_OBJECT (idle), "flash-state");
614 }
615
616 static void
617 empathy_idle_do_set_presence (EmpathyIdle *idle,
618                            TpConnectionPresenceType status_type,
619                            const gchar *status_message)
620 {
621         EmpathyIdlePriv *priv = GET_PRIV (idle);
622         const gchar *status;
623
624         g_assert (status_type > 0 && status_type < NUM_TP_CONNECTION_PRESENCE_TYPES);
625
626         status = presence_type_to_status[status_type];
627
628         g_return_if_fail (status != NULL);
629
630         /* FIXME: Should be sure that the account manager is prepared, but
631          * sometimes this isn't possible, like when exiting. In other words,
632          * we need a callback to empathy_idle_set_presence to be sure the
633          * presence is set on all accounts successfully. */
634         tp_account_manager_set_all_requested_presences (priv->manager,
635                 status_type, status, status_message);
636 }
637
638 void
639 empathy_idle_set_presence (EmpathyIdle *idle,
640                            TpConnectionPresenceType   state,
641                            const gchar *status)
642 {
643         EmpathyIdlePriv *priv;
644         const gchar     *default_status;
645
646         priv = GET_PRIV (idle);
647
648         DEBUG ("Changing presence to %s (%d)", status, state);
649
650         g_free (priv->requested_status_message);
651         priv->requested_presence_type = state;
652         priv->requested_status_message = g_strdup (status);
653
654         /* Do not set translated default messages */
655         default_status = empathy_presence_get_default_message (state);
656         if (!tp_strdiff (status, default_status)) {
657                 status = NULL;
658         }
659
660         if (state != TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
661                         !empathy_connectivity_is_online (priv->connectivity)) {
662                 DEBUG ("Empathy is not online");
663
664                 priv->saved_state = state;
665                 if (tp_strdiff (priv->status, status)) {
666                         g_free (priv->saved_status);
667                         priv->saved_status = NULL;
668                         if (!EMP_STR_EMPTY (status)) {
669                                 priv->saved_status = g_strdup (status);
670                         }
671                 }
672                 return;
673         }
674
675         empathy_idle_do_set_presence (idle, state, status);
676 }
677
678 gboolean
679 empathy_idle_get_auto_away (EmpathyIdle *idle)
680 {
681         EmpathyIdlePriv *priv = GET_PRIV (idle);
682
683         return priv->auto_away;
684 }
685
686 void
687 empathy_idle_set_auto_away (EmpathyIdle *idle,
688                             gboolean     auto_away)
689 {
690         EmpathyIdlePriv *priv = GET_PRIV (idle);
691
692         priv->auto_away = auto_away;
693
694         g_object_notify (G_OBJECT (idle), "auto-away");
695 }
696
697 TpConnectionPresenceType
698 empathy_idle_get_requested_presence (EmpathyIdle *idle,
699     gchar **status,
700     gchar **status_message)
701 {
702         EmpathyIdlePriv *priv = GET_PRIV (idle);
703
704         if (status != NULL) {
705                 *status = g_strdup (presence_type_to_status[priv->requested_presence_type]);
706         }
707
708         if (status_message != NULL) {
709                 *status_message = g_strdup (priv->requested_status_message);
710         }
711
712         return priv->requested_presence_type;
713 }
714
715 gboolean
716 empathy_idle_account_is_just_connected (EmpathyIdle *idle,
717                                         TpAccount *account)
718 {
719         EmpathyIdlePriv *priv = GET_PRIV (idle);
720         GTimeVal val;
721         gpointer ptr;
722         glong t;
723
724         if (tp_account_get_connection_status (account, NULL)
725             != TP_CONNECTION_STATUS_CONNECTED) {
726                 return FALSE;
727         }
728
729         ptr = g_hash_table_lookup (priv->connect_times, account);
730
731         if (ptr == NULL) {
732                 return FALSE;
733         }
734
735         t = GPOINTER_TO_INT (ptr);
736
737         g_get_current_time (&val);
738
739         return (val.tv_sec - t) < 10;
740 }