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 2
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 run_sanity_cleaning_tasks (TpAccountManager *am)
146 DEBUG ("Starting sanity cleaning tasks");
148 fix_xmpp_account_priority (am);
149 set_facebook_account_fallback_server (am);
153 am_prepare_cb (GObject *source,
154 GAsyncResult *result,
157 GError *error = NULL;
158 TpAccountManager *am = TP_ACCOUNT_MANAGER (source);
160 if (!tp_proxy_prepare_finish (am, result, &error))
162 DEBUG ("Failed to prepare account manager: %s", error->message);
163 g_error_free (error);
167 run_sanity_cleaning_tasks (am);
170 void empathy_sanity_checking_run_if_needed (void)
174 TpAccountManager *am;
176 settings = g_settings_new (EMPATHY_PREFS_SCHEMA);
177 number = g_settings_get_uint (settings, EMPATHY_PREFS_SANITY_CLEANING_NUMBER);
179 if (number == SANITY_CLEANING_NUMBER)
182 am = tp_account_manager_dup ();
184 tp_proxy_prepare_async (am, NULL, am_prepare_cb, NULL);
186 g_settings_set_uint (settings, EMPATHY_PREFS_SANITY_CLEANING_NUMBER,
187 SANITY_CLEANING_NUMBER);
191 g_object_unref (settings);