2 * Copyright (C) 2009-2013 Collabora Ltd.
4 * Authors: Marco Barisione <marco.barisione@collabora.co.uk>
5 * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
6 * Sjoerd Simons <sjoerd.simons@collabora.co.uk>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "tpaw-utils.h"
26 #include <glib/gi18n-lib.h>
28 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
29 #include "empathy-debug.h"
31 /* Change the RequestedPresence of a newly created account to ensure that it
32 * is actually connected. */
34 tpaw_connect_new_account (TpAccount *account,
35 TpAccountManager *account_manager)
37 TpConnectionPresenceType presence;
38 gchar *status, *message;
40 /* only force presence if presence was offline, unknown or unset */
41 presence = tp_account_get_requested_presence (account, NULL, NULL);
44 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
45 case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
46 case TP_CONNECTION_PRESENCE_TYPE_UNSET:
47 presence = tp_account_manager_get_most_available_presence (
48 account_manager, &status, &message);
50 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
51 /* Global presence is offline; we force it so user doesn't have to
52 * manually change the presence to connect his new account. */
53 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
55 tp_account_request_presence_async (account, presence,
56 status, NULL, NULL, NULL);
62 case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
63 case TP_CONNECTION_PRESENCE_TYPE_AWAY:
64 case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
65 case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
66 case TP_CONNECTION_PRESENCE_TYPE_BUSY:
67 case TP_CONNECTION_PRESENCE_TYPE_ERROR:
69 /* do nothing if the presence is not offline */
75 tpaw_protocol_icon_name (const gchar *protocol)
77 if (!tp_strdiff (protocol, "yahoojp"))
78 /* Yahoo Japan uses the same icon as Yahoo */
80 else if (!tp_strdiff (protocol, "simple"))
81 /* SIMPLE uses the same icon as SIP */
83 else if (!tp_strdiff (protocol, "sms"))
84 return g_strdup ("phone");
86 return g_strdup_printf ("im-%s", protocol);
90 tpaw_protocol_name_to_display_name (const gchar *proto_name)
98 { "jabber", "Jabber", FALSE },
99 { "msn", "Windows Live (MSN)", FALSE, },
100 { "local-xmpp", N_("People Nearby"), TRUE },
101 { "irc", "IRC", FALSE },
102 { "icq", "ICQ", FALSE },
103 { "aim", "AIM", FALSE },
104 { "yahoo", "Yahoo!", FALSE },
105 { "yahoojp", N_("Yahoo! Japan"), TRUE },
106 { "groupwise", "GroupWise", FALSE },
107 { "sip", "SIP", FALSE },
108 { "gadugadu", "Gadu-Gadu", FALSE },
109 { "mxit", "Mxit", FALSE },
110 { "myspace", "Myspace", FALSE },
111 { "sametime", "Sametime", FALSE },
112 { "skype-dbus", "Skype (D-BUS)", FALSE },
113 { "skype-x11", "Skype (X11)", FALSE },
114 { "zephyr", "Zephyr", FALSE },
118 for (i = 0; names[i].proto != NULL; i++)
120 if (!tp_strdiff (proto_name, names[i].proto))
122 if (names[i].translated)
123 return gettext (names[i].display);
125 return names[i].display;
133 tpaw_service_name_to_display_name (const gchar *service_name)
137 const gchar *service;
138 const gchar *display;
141 { "google-talk", N_("Google Talk"), FALSE },
142 { "facebook", N_("Facebook Chat"), TRUE },
146 for (i = 0; names[i].service != NULL; i++)
148 if (!tp_strdiff (service_name, names[i].service))
150 if (names[i].translated)
151 return gettext (names[i].display);
153 return names[i].display;
161 tpaw_make_color_whiter (GdkRGBA *color)
163 const GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 };
165 color->red = (color->red + white.red) / 2;
166 color->green = (color->green + white.green) / 2;
167 color->blue = (color->blue + white.blue) / 2;