]> git.0d.be Git - empathy.git/blob - tp-account-widgets/tpaw-utils.c
tpaw-utils: copy empathy_make_color_whiter()
[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  *          Sjoerd Simons <sjoerd.simons@collabora.co.uk>
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "config.h"
24 #include "tpaw-utils.h"
25
26 #include <glib/gi18n-lib.h>
27
28 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
29 #include "empathy-debug.h"
30
31 /* Change the RequestedPresence of a newly created account to ensure that it
32  * is actually connected. */
33 void
34 tpaw_connect_new_account (TpAccount *account,
35     TpAccountManager *account_manager)
36 {
37   TpConnectionPresenceType presence;
38   gchar *status, *message;
39
40   /* only force presence if presence was offline, unknown or unset */
41   presence = tp_account_get_requested_presence (account, NULL, NULL);
42   switch (presence)
43     {
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);
49
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;
54
55         tp_account_request_presence_async (account, presence,
56             status, NULL, NULL, NULL);
57
58         g_free (status);
59         g_free (message);
60         break;
61
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:
68        default:
69         /* do nothing if the presence is not offline */
70         break;
71     }
72 }
73
74 gchar *
75 tpaw_protocol_icon_name (const gchar *protocol)
76 {
77   if (!tp_strdiff (protocol, "yahoojp"))
78     /* Yahoo Japan uses the same icon as Yahoo */
79     protocol = "yahoo";
80   else if (!tp_strdiff (protocol, "simple"))
81     /* SIMPLE uses the same icon as SIP */
82     protocol = "sip";
83   else if (!tp_strdiff (protocol, "sms"))
84     return g_strdup ("phone");
85
86   return g_strdup_printf ("im-%s", protocol);
87 }
88
89 const char *
90 tpaw_protocol_name_to_display_name (const gchar *proto_name)
91 {
92   int i;
93   static struct {
94     const gchar *proto;
95     const gchar *display;
96     gboolean translated;
97   } names[] = {
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 },
115     { NULL, NULL }
116   };
117
118   for (i = 0; names[i].proto != NULL; i++)
119     {
120       if (!tp_strdiff (proto_name, names[i].proto))
121         {
122           if (names[i].translated)
123             return gettext (names[i].display);
124           else
125             return names[i].display;
126         }
127     }
128
129   return proto_name;
130 }
131
132 const char *
133 tpaw_service_name_to_display_name (const gchar *service_name)
134 {
135   int i;
136   static struct {
137     const gchar *service;
138     const gchar *display;
139     gboolean translated;
140   } names[] = {
141     { "google-talk", N_("Google Talk"), FALSE },
142     { "facebook", N_("Facebook Chat"), TRUE },
143     { NULL, NULL }
144   };
145
146   for (i = 0; names[i].service != NULL; i++)
147     {
148       if (!tp_strdiff (service_name, names[i].service))
149         {
150           if (names[i].translated)
151             return gettext (names[i].display);
152           else
153             return names[i].display;
154         }
155     }
156
157   return service_name;
158 }
159
160 void
161 tpaw_make_color_whiter (GdkRGBA *color)
162 {
163   const GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 };
164
165   color->red = (color->red + white.red) / 2;
166   color->green = (color->green + white.green) / 2;
167   color->blue = (color->blue + white.blue) / 2;
168 }