2 * empathy-sanity-cleaning.c
3 * Code automatically called when starting a specific version of Empathy for
4 * the first time doing misc cleaning.
6 * Copyright (C) 2012 Collabora Ltd.
7 * @author Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "empathy-sanity-cleaning.h"
28 #include <telepathy-glib/telepathy-glib.h>
30 #include <libempathy/empathy-gsettings.h>
32 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
33 #include <libempathy/empathy-debug.h>
36 * This number has to be increased each time a new task is added or modified.
38 * If the number stored in gsettings is lower than it, all the tasks will
41 #define SANITY_CLEANING_NUMBER 3
44 account_update_parameters_cb (GObject *source,
49 TpAccount *account = TP_ACCOUNT (source);
51 if (!tp_account_update_parameters_finish (account, result, NULL, &error))
53 DEBUG ("Failed to update parameters of account '%s': %s",
54 tp_account_get_path_suffix (account), error->message);
60 tp_account_reconnect_async (account, NULL, NULL);
63 /* Make sure XMPP accounts don't have a negative priority (bgo #671452) */
65 fix_xmpp_account_priority (TpAccountManager *am)
69 accounts = tp_account_manager_get_valid_accounts (am);
70 for (l = accounts; l != NULL; l = g_list_next (l))
72 TpAccount *account = l->data;
76 if (tp_strdiff (tp_account_get_protocol (account), "jabber"))
79 params = (GHashTable *) tp_account_get_parameters (account);
83 priority = tp_asv_get_int32 (params, "priority", NULL);
87 DEBUG ("Resetting XMPP priority of account '%s' to 0",
88 tp_account_get_path_suffix (account));
91 "priority", G_TYPE_INT, 0,
94 tp_account_update_parameters_async (account, params, NULL,
95 account_update_parameters_cb, NULL);
97 g_hash_table_unref (params);
100 g_list_free (accounts);
104 set_facebook_account_fallback_server (TpAccountManager *am)
108 accounts = tp_account_manager_get_valid_accounts (am);
109 for (l = accounts; l != NULL; l = g_list_next (l))
111 TpAccount *account = l->data;
113 gchar *fallback_servers[] = {
114 "chat.facebook.com:443",
117 if (tp_strdiff (tp_account_get_service (account), "facebook"))
120 params = (GHashTable *) tp_account_get_parameters (account);
124 if (tp_asv_get_strv (params, "fallback-servers") != NULL)
127 DEBUG ("Setting chat.facebook.com:443 as a fallback on account '%s'",
128 tp_account_get_path_suffix (account));
130 params = tp_asv_new (
131 "fallback-servers", G_TYPE_STRV, fallback_servers,
134 tp_account_update_parameters_async (account, params, NULL,
135 account_update_parameters_cb, NULL);
137 g_hash_table_unref (params);
140 g_list_free (accounts);
144 upgrade_chat_theme_settings (void)
146 GSettings *gsettings_chat;
147 gchar *theme, *new_theme = NULL;
148 const char *variant = "";
150 gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
152 theme = g_settings_get_string (gsettings_chat,
153 EMPATHY_PREFS_CHAT_THEME);
155 if (!tp_strdiff (theme, "adium")) {
156 gchar *path, *fullname;
158 path = g_settings_get_string (gsettings_chat,
159 EMPATHY_PREFS_CHAT_ADIUM_PATH);
161 fullname = g_path_get_basename (path);
162 if (g_str_has_suffix (fullname, ".AdiumMessageStyle"))
166 tmp = g_strsplit (fullname, ".AdiumMessageStyle", 0);
167 new_theme = g_strdup (tmp[0]);
173 /* Use the Classic theme as fallback */
174 new_theme = g_strdup ("Classic");
179 } else if (!tp_strdiff (theme, "gnome")) {
180 new_theme = g_strdup ("PlanetGNOME");
181 } else if (!tp_strdiff (theme, "simple")) {
182 new_theme = g_strdup ("Boxes");
184 } else if (!tp_strdiff (theme, "clean")) {
185 new_theme = g_strdup ("Boxes");
187 } else if (!tp_strdiff (theme, "blue")) {
188 new_theme = g_strdup ("Boxes");
191 /* Assume that's an Adium theme name. The theme manager will fallback to
192 * 'Classic' if it can't find it. */
196 DEBUG ("Migrating to '%s' variant '%s'", new_theme, variant);
198 g_settings_set_string (gsettings_chat,
199 EMPATHY_PREFS_CHAT_THEME, new_theme);
200 g_settings_set_string (gsettings_chat,
201 EMPATHY_PREFS_CHAT_THEME_VARIANT, variant);
206 g_object_unref (gsettings_chat);
210 run_sanity_cleaning_tasks (TpAccountManager *am)
212 DEBUG ("Starting sanity cleaning tasks");
214 fix_xmpp_account_priority (am);
215 set_facebook_account_fallback_server (am);
216 upgrade_chat_theme_settings ();
220 am_prepare_cb (GObject *source,
221 GAsyncResult *result,
224 GError *error = NULL;
225 TpAccountManager *am = TP_ACCOUNT_MANAGER (source);
227 if (!tp_proxy_prepare_finish (am, result, &error))
229 DEBUG ("Failed to prepare account manager: %s", error->message);
230 g_error_free (error);
234 run_sanity_cleaning_tasks (am);
237 void empathy_sanity_checking_run_if_needed (void)
241 TpAccountManager *am;
243 settings = g_settings_new (EMPATHY_PREFS_SCHEMA);
244 number = g_settings_get_uint (settings, EMPATHY_PREFS_SANITY_CLEANING_NUMBER);
246 if (number == SANITY_CLEANING_NUMBER)
249 am = tp_account_manager_dup ();
251 tp_proxy_prepare_async (am, NULL, am_prepare_cb, NULL);
253 g_settings_set_uint (settings, EMPATHY_PREFS_SANITY_CLEANING_NUMBER,
254 SANITY_CLEANING_NUMBER);
258 g_object_unref (settings);