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 #include <libempathy-gtk/empathy-theme-manager.h>
34 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
35 #include <libempathy/empathy-debug.h>
38 * This number has to be increased each time a new task is added or modified.
40 * If the number stored in gsettings is lower than it, all the tasks will
43 #define SANITY_CLEANING_NUMBER 3
46 account_update_parameters_cb (GObject *source,
51 TpAccount *account = TP_ACCOUNT (source);
53 if (!tp_account_update_parameters_finish (account, result, NULL, &error))
55 DEBUG ("Failed to update parameters of account '%s': %s",
56 tp_account_get_path_suffix (account), error->message);
62 tp_account_reconnect_async (account, NULL, NULL);
65 /* Make sure XMPP accounts don't have a negative priority (bgo #671452) */
67 fix_xmpp_account_priority (TpAccountManager *am)
71 accounts = tp_account_manager_get_valid_accounts (am);
72 for (l = accounts; l != NULL; l = g_list_next (l))
74 TpAccount *account = l->data;
78 if (tp_strdiff (tp_account_get_protocol (account), "jabber"))
81 params = (GHashTable *) tp_account_get_parameters (account);
85 priority = tp_asv_get_int32 (params, "priority", NULL);
89 DEBUG ("Resetting XMPP priority of account '%s' to 0",
90 tp_account_get_path_suffix (account));
93 "priority", G_TYPE_INT, 0,
96 tp_account_update_parameters_async (account, params, NULL,
97 account_update_parameters_cb, NULL);
99 g_hash_table_unref (params);
102 g_list_free (accounts);
106 set_facebook_account_fallback_server (TpAccountManager *am)
110 accounts = tp_account_manager_get_valid_accounts (am);
111 for (l = accounts; l != NULL; l = g_list_next (l))
113 TpAccount *account = l->data;
115 gchar *fallback_servers[] = {
116 "chat.facebook.com:443",
119 if (tp_strdiff (tp_account_get_service (account), "facebook"))
122 params = (GHashTable *) tp_account_get_parameters (account);
126 if (tp_asv_get_strv (params, "fallback-servers") != NULL)
129 DEBUG ("Setting chat.facebook.com:443 as a fallback on account '%s'",
130 tp_account_get_path_suffix (account));
132 params = tp_asv_new (
133 "fallback-servers", G_TYPE_STRV, fallback_servers,
136 tp_account_update_parameters_async (account, params, NULL,
137 account_update_parameters_cb, NULL);
139 g_hash_table_unref (params);
142 g_list_free (accounts);
146 upgrade_chat_theme_settings (void)
148 GSettings *gsettings_chat;
149 gchar *theme, *new_theme = NULL;
150 const char *variant = "";
152 gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
154 theme = g_settings_get_string (gsettings_chat,
155 EMPATHY_PREFS_CHAT_THEME);
157 if (!tp_strdiff (theme, "adium")) {
160 path = g_settings_get_string (gsettings_chat,
161 EMPATHY_PREFS_CHAT_ADIUM_PATH);
163 new_theme = empathy_theme_manager_dup_theme_name_from_path (path);
164 if (new_theme == NULL)
166 /* Use the Classic theme as fallback */
167 new_theme = g_strdup ("Classic");
171 } else if (!tp_strdiff (theme, "gnome")) {
172 new_theme = g_strdup ("PlanetGNOME");
173 } else if (!tp_strdiff (theme, "simple")) {
174 new_theme = g_strdup ("Boxes");
176 } else if (!tp_strdiff (theme, "clean")) {
177 new_theme = g_strdup ("Boxes");
179 } else if (!tp_strdiff (theme, "blue")) {
180 new_theme = g_strdup ("Boxes");
183 /* Assume that's an Adium theme name. The theme manager will fallback to
184 * 'Classic' if it can't find it. */
188 DEBUG ("Migrating to '%s' variant '%s'", new_theme, variant);
190 g_settings_set_string (gsettings_chat,
191 EMPATHY_PREFS_CHAT_THEME, new_theme);
192 g_settings_set_string (gsettings_chat,
193 EMPATHY_PREFS_CHAT_THEME_VARIANT, variant);
198 g_object_unref (gsettings_chat);
202 run_sanity_cleaning_tasks (TpAccountManager *am)
204 DEBUG ("Starting sanity cleaning tasks");
206 fix_xmpp_account_priority (am);
207 set_facebook_account_fallback_server (am);
208 upgrade_chat_theme_settings ();
212 am_prepare_cb (GObject *source,
213 GAsyncResult *result,
216 GError *error = NULL;
217 TpAccountManager *am = TP_ACCOUNT_MANAGER (source);
219 if (!tp_proxy_prepare_finish (am, result, &error))
221 DEBUG ("Failed to prepare account manager: %s", error->message);
222 g_error_free (error);
226 run_sanity_cleaning_tasks (am);
229 void empathy_sanity_checking_run_if_needed (void)
233 TpAccountManager *am;
235 settings = g_settings_new (EMPATHY_PREFS_SCHEMA);
236 number = g_settings_get_uint (settings, EMPATHY_PREFS_SANITY_CLEANING_NUMBER);
238 if (number == SANITY_CLEANING_NUMBER)
241 am = tp_account_manager_dup ();
243 tp_proxy_prepare_async (am, NULL, am_prepare_cb, NULL);
245 g_settings_set_uint (settings, EMPATHY_PREFS_SANITY_CLEANING_NUMBER,
246 SANITY_CLEANING_NUMBER);
250 g_object_unref (settings);