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