]> git.0d.be Git - empathy.git/blob - tp-account-widgets/tpaw-utils.c
8570658c34e661c6eff94eb18e64df7c2bb324e6
[empathy.git] / tp-account-widgets / tpaw-utils.c
1 /*
2  * Copyright (C) 2009-2013 Collabora Ltd.
3  *
4  * Authors: Marco Barisione <marco.barisione@collabora.co.uk>
5  *          Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #include "config.h"
23 #include "tpaw-utils.h"
24
25 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
26 #include "empathy-debug.h"
27
28 /* Change the RequestedPresence of a newly created account to ensure that it
29  * is actually connected. */
30 void
31 tpaw_connect_new_account (TpAccount *account,
32     TpAccountManager *account_manager)
33 {
34   TpConnectionPresenceType presence;
35   gchar *status, *message;
36
37   /* only force presence if presence was offline, unknown or unset */
38   presence = tp_account_get_requested_presence (account, NULL, NULL);
39   switch (presence)
40     {
41       case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
42       case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
43       case TP_CONNECTION_PRESENCE_TYPE_UNSET:
44         presence = tp_account_manager_get_most_available_presence (
45             account_manager, &status, &message);
46
47         if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
48           /* Global presence is offline; we force it so user doesn't have to
49            * manually change the presence to connect his new account. */
50           presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
51
52         tp_account_request_presence_async (account, presence,
53             status, NULL, NULL, NULL);
54
55         g_free (status);
56         g_free (message);
57         break;
58
59        case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
60        case TP_CONNECTION_PRESENCE_TYPE_AWAY:
61        case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
62        case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
63        case TP_CONNECTION_PRESENCE_TYPE_BUSY:
64        case TP_CONNECTION_PRESENCE_TYPE_ERROR:
65        default:
66         /* do nothing if the presence is not offline */
67         break;
68     }
69 }