[empathy: 6/59] Add empathy_idle_account_is_just_connected function.
- From: Jonny Lamb <jonnylamb src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [empathy: 6/59] Add empathy_idle_account_is_just_connected function.
- Date: Mon, 2 Nov 2009 13:38:13 +0000 (UTC)
commit e8894e6a663fe524a4d6282befa4a224c16180d5
Author: Jonny Lamb <jonnylamb gnome org>
Date: Sat Oct 24 15:26:31 2009 +0100
Add empathy_idle_account_is_just_connected function.
Signed-off-by: Jonny Lamb <jonnylamb gnome org>
libempathy/empathy-idle.c | 68 +++++++++++++++++++++++++++++++++++++++++++++
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 481ae5e..7f68b79 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 8d565d0..1a8c313 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]