diff options
author | Jonny Lamb <jonnylamb@gnome.org> | 2009-10-24 22:26:31 +0800 |
---|---|---|
committer | Jonny Lamb <jonnylamb@gnome.org> | 2009-10-24 22:26:31 +0800 |
commit | e8894e6a663fe524a4d6282befa4a224c16180d5 (patch) | |
tree | b1a54c87a77c07ba95cd8b0f46381322b90e16f2 | |
parent | d133b3b80a6a7fd4911905a077be21dabe0ef4bb (diff) | |
download | gsoc2013-empathy-e8894e6a663fe524a4d6282befa4a224c16180d5.tar gsoc2013-empathy-e8894e6a663fe524a4d6282befa4a224c16180d5.tar.gz gsoc2013-empathy-e8894e6a663fe524a4d6282befa4a224c16180d5.tar.bz2 gsoc2013-empathy-e8894e6a663fe524a4d6282befa4a224c16180d5.tar.lz gsoc2013-empathy-e8894e6a663fe524a4d6282befa4a224c16180d5.tar.xz gsoc2013-empathy-e8894e6a663fe524a4d6282befa4a224c16180d5.tar.zst gsoc2013-empathy-e8894e6a663fe524a4d6282befa4a224c16180d5.zip |
Add empathy_idle_account_is_just_connected function.
Signed-off-by: Jonny Lamb <jonnylamb@gnome.org>
-rw-r--r-- | libempathy/empathy-idle.c | 68 | ||||
-rw-r--r-- | libempathy/empathy-idle.h | 2 |
2 files changed, 70 insertions, 0 deletions
diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 481ae5ea6..7f68b7947 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -59,6 +59,7 @@ typedef struct { guint ext_away_timeout; TpAccountManager *manager; + GHashTable *connect_times; TpConnectionPresenceType requested_presence_type; gchar *requested_status_message; @@ -307,6 +308,9 @@ idle_finalize (GObject *object) g_object_unref (priv->connectivity); + g_hash_table_destroy (priv->connect_times); + priv->connect_times = NULL; + idle_ext_away_stop (EMPATHY_IDLE (object)); } @@ -438,6 +442,30 @@ empathy_idle_class_init (EmpathyIdleClass *klass) } static void +account_status_changed_cb (TpAccount *account, + guint old_status, + guint new_status, + guint reason, + gchar *dbus_error_name, + GHashTable *details, + gpointer user_data) +{ + EmpathyIdle *idle = EMPATHY_IDLE (user_data); + EmpathyIdlePriv *priv = GET_PRIV (idle); + GTimeVal val; + + if (new_status != TP_CONNECTION_STATUS_CONNECTED) { + return; + } + + g_get_current_time (&val); + + g_hash_table_insert (priv->connect_times, + g_strdup (tp_proxy_get_object_path (account)), + GINT_TO_POINTER (val.tv_sec)); +} + +static void account_manager_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) @@ -447,6 +475,7 @@ account_manager_ready_cb (GObject *source_object, EmpathyIdlePriv *priv = GET_PRIV (idle); TpConnectionPresenceType state; gchar *status, *status_message; + GList *accounts, *l; if (!tp_account_manager_prepare_finish (account_manager, result, NULL)) { return; @@ -458,6 +487,14 @@ account_manager_ready_cb (GObject *source_object, idle_presence_changed_cb (account_manager, state, status, status_message, idle); + accounts = tp_account_manager_get_valid_accounts (priv->manager); + for (l = accounts; l != NULL; l = l->next) { + empathy_signal_connect_weak (l->data, "status-changed", + G_CALLBACK (account_status_changed_cb), + G_OBJECT (idle)); + } + g_list_free (accounts); + g_free (status); g_free (status_message); } @@ -496,6 +533,9 @@ empathy_idle_init (EmpathyIdle *idle) priv->connectivity = empathy_connectivity_dup_singleton (); priv->state_change_signal_id = g_signal_connect (priv->connectivity, "state-change", G_CALLBACK (idle_state_change_cb), idle); + + priv->connect_times = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, NULL); } EmpathyIdle * @@ -674,3 +714,31 @@ empathy_idle_get_requested_presence (EmpathyIdle *idle, return priv->requested_presence_type; } + +gboolean +empathy_idle_account_is_just_connected (EmpathyIdle *idle, + TpAccount *account) +{ + EmpathyIdlePriv *priv = GET_PRIV (idle); + GTimeVal val; + gpointer ptr; + glong t; + + if (tp_account_get_connection_status (account, NULL) + != TP_CONNECTION_STATUS_CONNECTED) { + return FALSE; + } + + ptr = g_hash_table_lookup (priv->connect_times, + tp_proxy_get_object_path (account)); + + if (ptr == NULL) { + return FALSE; + } + + t = GPOINTER_TO_INT (ptr); + + g_get_current_time (&val); + + return (val.tv_sec - t) < 10; +} diff --git a/libempathy/empathy-idle.h b/libempathy/empathy-idle.h index 8d565d036..1a8c313bc 100644 --- a/libempathy/empathy-idle.h +++ b/libempathy/empathy-idle.h @@ -69,6 +69,8 @@ TpConnectionPresenceType empathy_idle_get_requested_presence (EmpathyIdle *idle, gchar **status, gchar **status_message); +gboolean empathy_idle_account_is_just_connected (EmpathyIdle *idle, + TpAccount *account); G_END_DECLS |