diff options
Diffstat (limited to 'tp-account-widgets/tpaw-utils.c')
-rw-r--r-- | tp-account-widgets/tpaw-utils.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/tp-account-widgets/tpaw-utils.c b/tp-account-widgets/tpaw-utils.c index d8bebdac0..8570658c3 100644 --- a/tp-account-widgets/tpaw-utils.c +++ b/tp-account-widgets/tpaw-utils.c @@ -1,7 +1,8 @@ /* - * Copyright (C) 2013 Collabora Ltd. + * Copyright (C) 2009-2013 Collabora Ltd. * * Authors: Marco Barisione <marco.barisione@collabora.co.uk> + * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -23,3 +24,46 @@ #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include "empathy-debug.h" + +/* Change the RequestedPresence of a newly created account to ensure that it + * is actually connected. */ +void +tpaw_connect_new_account (TpAccount *account, + TpAccountManager *account_manager) +{ + TpConnectionPresenceType presence; + gchar *status, *message; + + /* only force presence if presence was offline, unknown or unset */ + presence = tp_account_get_requested_presence (account, NULL, NULL); + switch (presence) + { + case TP_CONNECTION_PRESENCE_TYPE_OFFLINE: + case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN: + case TP_CONNECTION_PRESENCE_TYPE_UNSET: + presence = tp_account_manager_get_most_available_presence ( + account_manager, &status, &message); + + if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE) + /* Global presence is offline; we force it so user doesn't have to + * manually change the presence to connect his new account. */ + presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE; + + tp_account_request_presence_async (account, presence, + status, NULL, NULL, NULL); + + g_free (status); + g_free (message); + break; + + case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE: + case TP_CONNECTION_PRESENCE_TYPE_AWAY: + case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY: + case TP_CONNECTION_PRESENCE_TYPE_HIDDEN: + case TP_CONNECTION_PRESENCE_TYPE_BUSY: + case TP_CONNECTION_PRESENCE_TYPE_ERROR: + default: + /* do nothing if the presence is not offline */ + break; + } +} |