]> git.0d.be Git - empathy.git/blob - src/empathy-preferences.c
Add Echo cancellation preference
[empathy.git] / src / empathy-preferences.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2003-2007 Imendio AB
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA  02110-1301  USA
19  *
20  * Authors: Mikael Hallendal <micke@imendio.com>
21  *          Richard Hult <richard@imendio.com>
22  *          Martyn Russell <martyn@imendio.com>
23  *          Danielle Madeley <danielle.madeley@collabora.co.uk>
24  */
25
26 #include <config.h>
27
28 #include <string.h>
29 #include <stdio.h>
30
31 #include <gtk/gtk.h>
32 #include <glib/gi18n.h>
33 #include <telepathy-glib/dbus.h>
34 #include <telepathy-glib/util.h>
35
36 #include <libempathy/empathy-gsettings.h>
37 #include <libempathy/empathy-utils.h>
38
39 #include <libempathy-gtk/empathy-ui-utils.h>
40 #include <libempathy-gtk/empathy-theme-manager.h>
41 #include <libempathy-gtk/empathy-spell.h>
42 #include <libempathy-gtk/empathy-contact-list-store.h>
43 #include <libempathy-gtk/empathy-gtk-enum-types.h>
44
45 #ifdef HAVE_WEBKIT
46 #include <libempathy-gtk/empathy-theme-adium.h>
47 #endif
48
49 #include "empathy-preferences.h"
50
51 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
52 #include <libempathy/empathy-debug.h>
53
54 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
55
56 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
57
58 static const gchar * empathy_preferences_tabs[] =
59 {
60   "general",
61   "notifications",
62   "sounds",
63   "calls",
64   "location",
65   "spell",
66   "themes",
67 };
68
69 struct _EmpathyPreferencesPriv {
70         GtkWidget *notebook;
71
72         GtkWidget *checkbutton_show_smileys;
73         GtkWidget *checkbutton_show_contacts_in_rooms;
74         GtkWidget *checkbutton_separate_chat_windows;
75         GtkWidget *checkbutton_events_notif_area;
76         GtkWidget *checkbutton_autoconnect;
77         GtkWidget *checkbutton_logging;
78
79         GtkWidget *checkbutton_sounds_enabled;
80         GtkWidget *checkbutton_sounds_disabled_away;
81         GtkWidget *treeview_sounds;
82
83         GtkWidget *checkbutton_notifications_enabled;
84         GtkWidget *checkbutton_notifications_disabled_away;
85         GtkWidget *checkbutton_notifications_focus;
86         GtkWidget *checkbutton_notifications_contact_signin;
87         GtkWidget *checkbutton_notifications_contact_signout;
88
89         GtkWidget *scale_call_volume;
90         GtkWidget *adj_call_volume;
91         GtkWidget *echo_cancellation;
92
93         GtkWidget *treeview_spell_checker;
94
95         GtkWidget *checkbutton_location_publish;
96         GtkWidget *checkbutton_location_reduce_accuracy;
97         GtkWidget *checkbutton_location_resource_network;
98         GtkWidget *checkbutton_location_resource_cell;
99         GtkWidget *checkbutton_location_resource_gps;
100
101         GtkWidget *vbox_chat_theme;
102         GtkWidget *combobox_chat_theme;
103         GtkWidget *combobox_chat_theme_variant;
104         GtkWidget *hbox_chat_theme_variant;
105         GtkWidget *sw_chat_theme_preview;
106         EmpathyChatView *chat_theme_preview;
107         EmpathyThemeManager *theme_manager;
108
109         GSettings *gsettings;
110         GSettings *gsettings_chat;
111         GSettings *gsettings_call;
112         GSettings *gsettings_loc;
113         GSettings *gsettings_notify;
114         GSettings *gsettings_sound;
115         GSettings *gsettings_ui;
116         GSettings *gsettings_logger;
117 };
118
119 static void     preferences_setup_widgets                (EmpathyPreferences      *preferences);
120 static void     preferences_languages_setup              (EmpathyPreferences      *preferences);
121 static void     preferences_languages_add                (EmpathyPreferences      *preferences);
122 static void     preferences_languages_save               (EmpathyPreferences      *preferences);
123 static gboolean preferences_languages_save_foreach       (GtkTreeModel           *model,
124                                                           GtkTreePath            *path,
125                                                           GtkTreeIter            *iter,
126                                                           gchar                 **languages);
127 static void     preferences_languages_load               (EmpathyPreferences      *preferences);
128 static gboolean preferences_languages_load_foreach       (GtkTreeModel           *model,
129                                                           GtkTreePath            *path,
130                                                           GtkTreeIter            *iter,
131                                                           GList                  *languages);
132 static void     preferences_languages_cell_toggled_cb    (GtkCellRendererToggle  *cell,
133                                                           gchar                  *path_string,
134                                                           EmpathyPreferences      *preferences);
135
136 enum {
137         COL_LANG_ENABLED,
138         COL_LANG_CODE,
139         COL_LANG_NAME,
140         COL_LANG_COUNT
141 };
142
143 enum {
144         COL_THEME_VISIBLE_NAME,
145         COL_THEME_NAME,
146         COL_THEME_IS_ADIUM,
147         COL_THEME_ADIUM_PATH,
148         COL_THEME_ADIUM_INFO,
149         COL_THEME_COUNT
150 };
151
152 enum {
153         COL_VARIANT_NAME,
154         COL_VARIANT_DEFAULT,
155         COL_VARIANT_COUNT
156 };
157
158 enum {
159         COL_SOUND_ENABLED,
160         COL_SOUND_NAME,
161         COL_SOUND_KEY,
162         COL_SOUND_COUNT
163 };
164
165 typedef struct {
166         const char *name;
167         const char *key;
168 } SoundEventEntry;
169
170 /* TODO: add phone related sounds also? */
171 static SoundEventEntry sound_entries [] = {
172         { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
173         { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
174         { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
175         { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
176         { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
177         { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
178         { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
179 };
180
181 static void
182 preferences_setup_widgets (EmpathyPreferences *preferences)
183 {
184         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
185
186         g_settings_bind (priv->gsettings_notify,
187                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
188                          priv->checkbutton_notifications_enabled,
189                          "active",
190                          G_SETTINGS_BIND_DEFAULT);
191         g_settings_bind (priv->gsettings_notify,
192                          EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
193                          priv->checkbutton_notifications_disabled_away,
194                          "active",
195                          G_SETTINGS_BIND_DEFAULT);
196         g_settings_bind (priv->gsettings_notify,
197                          EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
198                          priv->checkbutton_notifications_focus,
199                          "active",
200                          G_SETTINGS_BIND_DEFAULT);
201         g_settings_bind (priv->gsettings_notify,
202                          EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
203                          priv->checkbutton_notifications_contact_signin,
204                          "active",
205                          G_SETTINGS_BIND_DEFAULT);
206         g_settings_bind (priv->gsettings_notify,
207                          EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
208                          priv->checkbutton_notifications_contact_signout,
209                          "active",
210                          G_SETTINGS_BIND_DEFAULT);
211
212         g_settings_bind (priv->gsettings_notify,
213                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
214                          priv->checkbutton_notifications_disabled_away,
215                          "sensitive",
216                          G_SETTINGS_BIND_GET);
217         g_settings_bind (priv->gsettings_notify,
218                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
219                          priv->checkbutton_notifications_focus,
220                          "sensitive",
221                          G_SETTINGS_BIND_GET);
222         g_settings_bind (priv->gsettings_notify,
223                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
224                          priv->checkbutton_notifications_contact_signin,
225                          "sensitive",
226                          G_SETTINGS_BIND_GET);
227         g_settings_bind (priv->gsettings_notify,
228                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
229                          priv->checkbutton_notifications_contact_signout,
230                          "sensitive",
231                          G_SETTINGS_BIND_GET);
232
233         g_settings_bind (priv->gsettings_sound,
234                          EMPATHY_PREFS_SOUNDS_ENABLED,
235                          priv->checkbutton_sounds_enabled,
236                          "active",
237                          G_SETTINGS_BIND_DEFAULT);
238         g_settings_bind (priv->gsettings_sound,
239                          EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
240                          priv->checkbutton_sounds_disabled_away,
241                          "active",
242                          G_SETTINGS_BIND_DEFAULT);
243
244         g_settings_bind (priv->gsettings_sound,
245                          EMPATHY_PREFS_SOUNDS_ENABLED,
246                          priv->checkbutton_sounds_disabled_away,
247                          "sensitive",
248                          G_SETTINGS_BIND_GET);
249         g_settings_bind (priv->gsettings_sound,
250                         EMPATHY_PREFS_SOUNDS_ENABLED,
251                         priv->treeview_sounds,
252                         "sensitive",
253                         G_SETTINGS_BIND_GET);
254
255         g_settings_bind (priv->gsettings_ui,
256                          EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
257                          priv->checkbutton_separate_chat_windows,
258                          "active",
259                          G_SETTINGS_BIND_DEFAULT);
260
261         g_settings_bind (priv->gsettings_ui,
262                          EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
263                          priv->checkbutton_events_notif_area,
264                          "active",
265                          G_SETTINGS_BIND_DEFAULT);
266
267         g_settings_bind (priv->gsettings_chat,
268                          EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
269                          priv->checkbutton_show_smileys,
270                          "active",
271                          G_SETTINGS_BIND_DEFAULT);
272         g_settings_bind (priv->gsettings_chat,
273                          EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
274                          priv->checkbutton_show_contacts_in_rooms,
275                          "active",
276                          G_SETTINGS_BIND_DEFAULT);
277
278         g_settings_bind (priv->gsettings_call,
279                          EMPATHY_PREFS_CALL_SOUND_VOLUME,
280                          priv->adj_call_volume,
281                          "value",
282                          G_SETTINGS_BIND_DEFAULT);
283
284         g_settings_bind (priv->gsettings_call,
285                          EMPATHY_PREFS_CALL_ECHO_CANCELLATION,
286                          priv->echo_cancellation,
287                          "active",
288                          G_SETTINGS_BIND_DEFAULT);
289
290         g_settings_bind (priv->gsettings,
291                          EMPATHY_PREFS_AUTOCONNECT,
292                          priv->checkbutton_autoconnect,
293                          "active",
294                          G_SETTINGS_BIND_DEFAULT);
295
296         g_settings_bind (priv->gsettings_loc,
297                          EMPATHY_PREFS_LOCATION_PUBLISH,
298                          priv->checkbutton_location_publish,
299                          "active",
300                          G_SETTINGS_BIND_DEFAULT);
301
302         g_settings_bind (priv->gsettings_loc,
303                          EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
304                          priv->checkbutton_location_resource_network,
305                          "active",
306                          G_SETTINGS_BIND_DEFAULT);
307         g_settings_bind (priv->gsettings_loc,
308                          EMPATHY_PREFS_LOCATION_PUBLISH,
309                          priv->checkbutton_location_resource_network,
310                          "sensitive",
311                          G_SETTINGS_BIND_GET);
312
313         g_settings_bind (priv->gsettings_loc,
314                          EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
315                          priv->checkbutton_location_resource_cell,
316                          "active",
317                          G_SETTINGS_BIND_DEFAULT);
318         g_settings_bind (priv->gsettings_loc,
319                          EMPATHY_PREFS_LOCATION_PUBLISH,
320                          priv->checkbutton_location_resource_cell,
321                          "sensitive",
322                          G_SETTINGS_BIND_GET);
323
324         g_settings_bind (priv->gsettings_loc,
325                          EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
326                          priv->checkbutton_location_resource_gps,
327                          "active",
328                          G_SETTINGS_BIND_DEFAULT);
329         g_settings_bind (priv->gsettings_loc,
330                          EMPATHY_PREFS_LOCATION_PUBLISH,
331                          priv->checkbutton_location_resource_gps,
332                          "sensitive",
333                          G_SETTINGS_BIND_GET);
334
335         g_settings_bind (priv->gsettings_loc,
336                          EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
337                          priv->checkbutton_location_reduce_accuracy,
338                          "active",
339                          G_SETTINGS_BIND_DEFAULT);
340         g_settings_bind (priv->gsettings_loc,
341                          EMPATHY_PREFS_LOCATION_PUBLISH,
342                          priv->checkbutton_location_reduce_accuracy,
343                          "sensitive",
344                          G_SETTINGS_BIND_GET);
345
346         g_settings_bind (priv->gsettings_logger,
347                          EMPATHY_PREFS_LOGGER_ENABLED,
348                          priv->checkbutton_logging,
349                          "active",
350                          G_SETTINGS_BIND_DEFAULT);
351 }
352
353 static void
354 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
355                                    char *path_string,
356                                    EmpathyPreferences *preferences)
357 {
358         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
359         GtkTreePath *path;
360         gboolean instore;
361         GtkTreeIter iter;
362         GtkTreeView *view;
363         GtkTreeModel *model;
364         char *key;
365
366         view = GTK_TREE_VIEW (priv->treeview_sounds);
367         model = gtk_tree_view_get_model (view);
368
369         path = gtk_tree_path_new_from_string (path_string);
370
371         gtk_tree_model_get_iter (model, &iter, path);
372         gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
373                             COL_SOUND_ENABLED, &instore, -1);
374
375         instore ^= 1;
376
377         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
378                             COL_SOUND_ENABLED, instore, -1);
379
380         g_settings_set_boolean (priv->gsettings_sound, key, instore);
381
382         g_free (key);
383         gtk_tree_path_free (path);
384 }
385
386 static void
387 preferences_sound_load (EmpathyPreferences *preferences)
388 {
389         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
390         guint i;
391         GtkTreeView *view;
392         GtkListStore *store;
393         GtkTreeIter iter;
394         gboolean set;
395
396         view = GTK_TREE_VIEW (priv->treeview_sounds);
397         store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
398
399         for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
400                 set = g_settings_get_boolean (priv->gsettings_sound,
401                                               sound_entries[i].key);
402
403                 gtk_list_store_insert_with_values (store, &iter, i,
404                                                    COL_SOUND_NAME, gettext (sound_entries[i].name),
405                                                    COL_SOUND_KEY, sound_entries[i].key,
406                                                    COL_SOUND_ENABLED, set, -1);
407         }
408 }
409
410 static void
411 preferences_sound_setup (EmpathyPreferences *preferences)
412 {
413         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
414         GtkTreeView *view;
415         GtkListStore *store;
416         GtkCellRenderer *renderer;
417         GtkTreeViewColumn *column;
418
419         view = GTK_TREE_VIEW (priv->treeview_sounds);
420
421         store = gtk_list_store_new (COL_SOUND_COUNT,
422                                     G_TYPE_BOOLEAN, /* enabled */
423                                     G_TYPE_STRING,  /* name */
424                                     G_TYPE_STRING); /* key */
425
426         gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
427
428         renderer = gtk_cell_renderer_toggle_new ();
429         g_signal_connect (renderer, "toggled",
430                           G_CALLBACK (preferences_sound_cell_toggled_cb),
431                           preferences);
432
433         column = gtk_tree_view_column_new ();
434         gtk_tree_view_column_pack_start (column, renderer, FALSE);
435         gtk_tree_view_column_add_attribute (column, renderer,
436                                             "active", COL_SOUND_ENABLED);
437
438         renderer = gtk_cell_renderer_text_new ();
439         gtk_tree_view_column_pack_start (column, renderer, FALSE);
440         gtk_tree_view_column_add_attribute (column, renderer,
441                                             "text", COL_SOUND_NAME);
442
443         gtk_tree_view_append_column (view, column);
444
445         gtk_tree_view_column_set_resizable (column, FALSE);
446         gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
447
448         g_object_unref (store);
449 }
450
451 static void
452 preferences_languages_setup (EmpathyPreferences *preferences)
453 {
454         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
455         GtkTreeView       *view;
456         GtkListStore      *store;
457         GtkTreeSelection  *selection;
458         GtkTreeViewColumn *column;
459         GtkCellRenderer   *renderer;
460         guint              col_offset;
461
462         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
463
464         store = gtk_list_store_new (COL_LANG_COUNT,
465                                     G_TYPE_BOOLEAN,  /* enabled */
466                                     G_TYPE_STRING,   /* code */
467                                     G_TYPE_STRING);  /* name */
468
469         gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
470
471         selection = gtk_tree_view_get_selection (view);
472         gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
473
474         renderer = gtk_cell_renderer_toggle_new ();
475         g_signal_connect (renderer, "toggled",
476                           G_CALLBACK (preferences_languages_cell_toggled_cb),
477                           preferences);
478
479         column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
480                                                            "active", COL_LANG_ENABLED,
481                                                            NULL);
482
483         gtk_tree_view_append_column (view, column);
484
485         renderer = gtk_cell_renderer_text_new ();
486         col_offset = gtk_tree_view_insert_column_with_attributes (view,
487                                                                   -1, _("Language"),
488                                                                   renderer,
489                                                                   "text", COL_LANG_NAME,
490                                                                   NULL);
491
492         g_object_set_data (G_OBJECT (renderer),
493                            "column", GINT_TO_POINTER (COL_LANG_NAME));
494
495         column = gtk_tree_view_get_column (view, col_offset - 1);
496         gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
497         gtk_tree_view_column_set_resizable (column, FALSE);
498         gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
499
500         g_object_unref (store);
501 }
502
503 static void
504 preferences_languages_add (EmpathyPreferences *preferences)
505 {
506         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
507         GtkTreeView  *view;
508         GtkListStore *store;
509         GList        *codes, *l;
510
511         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
512         store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
513
514         codes = empathy_spell_get_language_codes ();
515
516         if (!codes) {
517                 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
518         }
519
520         for (l = codes; l; l = l->next) {
521                 GtkTreeIter  iter;
522                 const gchar *code;
523                 const gchar *name;
524
525                 code = l->data;
526                 name = empathy_spell_get_language_name (code);
527                 if (!name) {
528                         continue;
529                 }
530
531                 gtk_list_store_append (store, &iter);
532                 gtk_list_store_set (store, &iter,
533                                     COL_LANG_CODE, code,
534                                     COL_LANG_NAME, name,
535                                     -1);
536         }
537
538         empathy_spell_free_language_codes (codes);
539 }
540
541 static void
542 preferences_languages_save (EmpathyPreferences *preferences)
543 {
544         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
545         GtkTreeView       *view;
546         GtkTreeModel      *model;
547
548         gchar             *languages = NULL;
549
550         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
551         model = gtk_tree_view_get_model (view);
552
553         gtk_tree_model_foreach (model,
554                                 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
555                                 &languages);
556
557         /* if user selects no languages, we don't want spell check */
558         g_settings_set_boolean (priv->gsettings_chat,
559                                 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
560                                 languages != NULL);
561
562         g_settings_set_string (priv->gsettings_chat,
563                                EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
564                                languages != NULL ? languages : "");
565
566         g_free (languages);
567 }
568
569 static gboolean
570 preferences_languages_save_foreach (GtkTreeModel  *model,
571                                     GtkTreePath   *path,
572                                     GtkTreeIter   *iter,
573                                     gchar        **languages)
574 {
575         gboolean  enabled;
576         gchar    *code;
577
578         if (!languages) {
579                 return TRUE;
580         }
581
582         gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
583         if (!enabled) {
584                 return FALSE;
585         }
586
587         gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
588         if (!code) {
589                 return FALSE;
590         }
591
592         if (!(*languages)) {
593                 *languages = g_strdup (code);
594         } else {
595                 gchar *str = *languages;
596                 *languages = g_strdup_printf ("%s,%s", str, code);
597                 g_free (str);
598         }
599
600         g_free (code);
601
602         return FALSE;
603 }
604
605 static void
606 preferences_languages_load (EmpathyPreferences *preferences)
607 {
608         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
609         GtkTreeView   *view;
610         GtkTreeModel  *model;
611         GList         *enabled_codes;
612
613         enabled_codes = empathy_spell_get_enabled_language_codes ();
614
615         g_settings_set_boolean (priv->gsettings_chat,
616                                 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
617                                 enabled_codes != NULL);
618
619         if (enabled_codes == NULL)
620                 return;
621
622         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
623         model = gtk_tree_view_get_model (view);
624
625         gtk_tree_model_foreach (model,
626                                 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
627                                 enabled_codes);
628
629         g_list_free (enabled_codes);
630 }
631
632 static gboolean
633 preferences_languages_load_foreach (GtkTreeModel  *model,
634                                     GtkTreePath   *path,
635                                     GtkTreeIter   *iter,
636                                     GList         *languages)
637 {
638         gchar    *code;
639         gboolean  found = FALSE;
640
641         if (!languages) {
642                 return TRUE;
643         }
644
645         gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
646         if (!code) {
647                 return FALSE;
648         }
649
650         if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
651                 found = TRUE;
652         }
653
654         g_free (code);
655         gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
656         return FALSE;
657 }
658
659 static void
660 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
661                                        gchar                 *path_string,
662                                        EmpathyPreferences     *preferences)
663 {
664         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
665         GtkTreeView  *view;
666         GtkTreeModel *model;
667         GtkListStore *store;
668         GtkTreePath  *path;
669         GtkTreeIter   iter;
670         gboolean      enabled;
671
672         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
673         model = gtk_tree_view_get_model (view);
674         store = GTK_LIST_STORE (model);
675
676         path = gtk_tree_path_new_from_string (path_string);
677
678         gtk_tree_model_get_iter (model, &iter, path);
679         gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
680
681         enabled ^= 1;
682
683         gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
684         gtk_tree_path_free (path);
685
686         preferences_languages_save (preferences);
687 }
688
689 static void
690 preferences_preview_theme_append_message (EmpathyChatView *view,
691                                           EmpathyContact *sender,
692                                           EmpathyContact *receiver,
693                                           const gchar *text)
694 {
695         EmpathyMessage *message;
696
697         message = g_object_new (EMPATHY_TYPE_MESSAGE,
698                 "sender", sender,
699                 "receiver", receiver,
700                 "body", text,
701                 NULL);
702
703         empathy_chat_view_append_message (view, message);
704         g_object_unref (message);
705 }
706
707 static void
708 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
709                                       EmpathyPreferences  *preferences)
710 {
711         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
712         TpDBusDaemon *dbus;
713         TpAccount *account;
714         EmpathyContact *juliet;
715         EmpathyContact *romeo;
716
717         DEBUG ("Theme changed, update preview widget");
718
719         if (priv->chat_theme_preview != NULL) {
720                 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
721         }
722         priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
723         gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
724                            GTK_WIDGET (priv->chat_theme_preview));
725         gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
726
727         /* FIXME: It is ugly to add a fake conversation like that.
728          * Would be cool if we could request a TplLogManager for a fake
729          * conversation */
730         dbus = tp_dbus_daemon_dup (NULL);
731         account = tp_account_new (dbus,
732                 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
733         juliet = g_object_new (EMPATHY_TYPE_CONTACT,
734                 "account", account,
735                 "id", "juliet",
736                 /* translators: Contact name for the chat theme preview */
737                 "alias", _("Juliet"),
738                 "is-user", FALSE,
739                 NULL);
740         romeo = g_object_new (EMPATHY_TYPE_CONTACT,
741                 "account", account,
742                 "id", "romeo",
743                 /* translators: Contact name for the chat theme preview */
744                 "alias", _("Romeo"),
745                 "is-user", TRUE,
746                 NULL);
747
748         preferences_preview_theme_append_message (priv->chat_theme_preview,
749                 /* translators: Quote from Romeo & Julier, for chat theme preview */
750                 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
751         preferences_preview_theme_append_message (priv->chat_theme_preview,
752                 /* translators: Quote from Romeo & Julier, for chat theme preview */
753                 juliet, romeo, _("Deny thy father and refuse thy name;"));
754         preferences_preview_theme_append_message (priv->chat_theme_preview,
755                 /* translators: Quote from Romeo & Julier, for chat theme preview */
756                 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
757         preferences_preview_theme_append_message (priv->chat_theme_preview,
758                 /* translators: Quote from Romeo & Julier, for chat theme preview */
759                 juliet, romeo, _("And I'll no longer be a Capulet."));
760         preferences_preview_theme_append_message (priv->chat_theme_preview,
761                 /* translators: Quote from Romeo & Julier, for chat theme preview */
762                 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
763
764         /* translators: Quote from Romeo & Julier, for chat theme preview */
765         empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
766
767         g_object_unref (juliet);
768         g_object_unref (romeo);
769         g_object_unref (account);
770         g_object_unref (dbus);
771 }
772
773 static void
774 preferences_theme_variant_changed_cb (GtkComboBox        *combo,
775                                       EmpathyPreferences *preferences)
776 {
777         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
778         GtkTreeIter   iter;
779
780         if (gtk_combo_box_get_active_iter (combo, &iter)) {
781                 GtkTreeModel *model;
782                 gchar        *name;
783
784                 model = gtk_combo_box_get_model (combo);
785                 gtk_tree_model_get (model, &iter,
786                                     COL_VARIANT_NAME, &name,
787                                     -1);
788
789                 g_settings_set_string (priv->gsettings_chat,
790                                        EMPATHY_PREFS_CHAT_THEME_VARIANT,
791                                        name);
792
793                 g_free (name);
794         }
795 }
796
797 static void
798 preferences_theme_variant_notify_cb (GSettings   *gsettings,
799                                      const gchar *key,
800                                      gpointer     user_data)
801 {
802         EmpathyPreferences *preferences = user_data;
803         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
804         GtkComboBox        *combo;
805         gchar              *conf_name;
806         GtkTreeModel       *model;
807         GtkTreeIter         iter;
808         GtkTreeIter         default_iter;
809         gboolean            found_default = FALSE;
810         gboolean            found = FALSE;
811         gboolean            ok;
812
813         conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
814         combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
815         model = gtk_combo_box_get_model (combo);
816
817         for (ok = gtk_tree_model_get_iter_first (model, &iter);
818              ok && !found;
819              ok = gtk_tree_model_iter_next (model, &iter)) {
820                 gchar *name;
821                 gboolean is_default;
822
823                 gtk_tree_model_get (model, &iter,
824                                     COL_VARIANT_NAME, &name,
825                                     COL_VARIANT_DEFAULT, &is_default,
826                                     -1);
827
828                 if (!tp_strdiff (name, conf_name)) {
829                         found = TRUE;
830                         gtk_combo_box_set_active_iter (combo, &iter);
831                 }
832                 if (is_default) {
833                         found_default = TRUE;
834                         default_iter = iter;
835                 }
836
837                 g_free (name);
838         }
839
840         /* Fallback to the first one. */
841         if (!found) {
842                 if (found_default) {
843                         gtk_combo_box_set_active_iter (combo, &default_iter);
844                 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
845                         gtk_combo_box_set_active_iter (combo, &iter);
846                 }
847         }
848
849         g_free (conf_name);
850 }
851
852 static void
853 preferences_theme_variants_fill (EmpathyPreferences *preferences,
854                                  GHashTable         *info)
855 {
856         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
857         GtkTreeModel *model;
858         GtkListStore *store;
859 #ifdef HAVE_WEBKIT
860         GPtrArray    *variants;
861         const gchar  *default_variant;
862         guint         i;
863 #endif /* HAVE_WEBKIT */
864
865         model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
866         store = GTK_LIST_STORE (model);
867         gtk_list_store_clear (store);
868
869 #ifdef HAVE_WEBKIT
870         variants = empathy_adium_info_get_available_variants (info);
871         default_variant = empathy_adium_info_get_default_variant (info);
872         for (i = 0; i < variants->len; i++) {
873                 gchar *name = g_ptr_array_index (variants, i);
874
875                 gtk_list_store_insert_with_values (store, NULL, -1,
876                         COL_VARIANT_NAME, name,
877                         COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
878                         -1);
879         }
880 #endif /* HAVE_WEBKIT */
881
882         /* Select the variant from the GSetting key */
883         preferences_theme_variant_notify_cb (priv->gsettings_chat,
884                                              EMPATHY_PREFS_CHAT_THEME_VARIANT,
885                                              preferences);
886 }
887
888 static void
889 preferences_theme_variants_setup (EmpathyPreferences *preferences)
890 {
891         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
892         GtkComboBox   *combo;
893         GtkCellLayout *cell_layout;
894         GtkCellRenderer *renderer;
895         GtkListStore  *store;
896
897         combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
898         cell_layout = GTK_CELL_LAYOUT (combo);
899
900         /* Create the model */
901         store = gtk_list_store_new (COL_VARIANT_COUNT,
902                                     G_TYPE_STRING,      /* name */
903                                     G_TYPE_BOOLEAN);    /* is default */
904         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
905                 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
906
907         /* Add cell renderer */
908         renderer = gtk_cell_renderer_text_new ();
909         gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
910         gtk_cell_layout_set_attributes (cell_layout, renderer,
911                 "text", COL_VARIANT_NAME, NULL);
912
913         gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
914         g_object_unref (store);
915
916         g_signal_connect (combo, "changed",
917                           G_CALLBACK (preferences_theme_variant_changed_cb),
918                           preferences);
919
920         /* Track changes of the GSetting key */
921         g_signal_connect (priv->gsettings_chat,
922                           "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
923                           G_CALLBACK (preferences_theme_variant_notify_cb),
924                           preferences);
925 }
926
927 static void
928 preferences_theme_changed_cb (GtkComboBox        *combo,
929                               EmpathyPreferences *preferences)
930 {
931         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
932         GtkTreeIter   iter;
933
934         if (gtk_combo_box_get_active_iter (combo, &iter)) {
935                 GtkTreeModel *model;
936                 gboolean      is_adium;
937                 gchar        *name;
938                 gchar        *path;
939                 GHashTable   *info;
940
941                 model = gtk_combo_box_get_model (combo);
942                 gtk_tree_model_get (model, &iter,
943                                     COL_THEME_IS_ADIUM, &is_adium,
944                                     COL_THEME_NAME, &name,
945                                     COL_THEME_ADIUM_PATH, &path,
946                                     COL_THEME_ADIUM_INFO, &info,
947                                     -1);
948
949                 g_settings_set_string (priv->gsettings_chat,
950                                        EMPATHY_PREFS_CHAT_THEME,
951                                        name);
952                 if (is_adium) {
953                         g_settings_set_string (priv->gsettings_chat,
954                                                EMPATHY_PREFS_CHAT_ADIUM_PATH,
955                                                path);
956                         preferences_theme_variants_fill (preferences, info);
957                         gtk_widget_show (priv->hbox_chat_theme_variant);
958                 } else {
959                         gtk_widget_hide (priv->hbox_chat_theme_variant);
960                 }
961                 g_free (name);
962                 g_free (path);
963                 tp_clear_pointer (&info, g_hash_table_unref);
964         }
965 }
966
967 static void
968 preferences_theme_notify_cb (GSettings   *gsettings,
969                              const gchar *key,
970                              gpointer     user_data)
971 {
972         EmpathyPreferences *preferences = user_data;
973         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
974         GtkComboBox        *combo;
975         gchar              *conf_name;
976         gchar              *conf_path;
977         GtkTreeModel       *model;
978         GtkTreeIter         iter;
979         gboolean            found = FALSE;
980         gboolean            ok;
981
982         conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
983         conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
984
985         combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
986         model = gtk_combo_box_get_model (combo);
987         for (ok = gtk_tree_model_get_iter_first (model, &iter);
988              ok && !found;
989              ok = gtk_tree_model_iter_next (model, &iter)) {
990                 gboolean is_adium;
991                 gchar *name;
992                 gchar *path;
993
994                 gtk_tree_model_get (model, &iter,
995                                     COL_THEME_IS_ADIUM, &is_adium,
996                                     COL_THEME_NAME, &name,
997                                     COL_THEME_ADIUM_PATH, &path,
998                                     -1);
999
1000                 if (!tp_strdiff (name, conf_name) &&
1001                     (!is_adium || !tp_strdiff (path, conf_path))) {
1002                         found = TRUE;
1003                         gtk_combo_box_set_active_iter (combo, &iter);
1004                 }
1005
1006                 g_free (name);
1007                 g_free (path);
1008         }
1009
1010         /* Fallback to the first one. */
1011         if (!found) {
1012                 if (gtk_tree_model_get_iter_first (model, &iter)) {
1013                         gtk_combo_box_set_active_iter (combo, &iter);
1014                 }
1015         }
1016
1017         g_free (conf_name);
1018         g_free (conf_path);
1019 }
1020
1021 static void
1022 preferences_themes_setup (EmpathyPreferences *preferences)
1023 {
1024         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
1025         GtkComboBox   *combo;
1026         GtkCellLayout *cell_layout;
1027         GtkCellRenderer *renderer;
1028         GtkListStore  *store;
1029         const gchar  **themes;
1030         GList         *adium_themes;
1031         gint           i;
1032
1033         preferences_theme_variants_setup (preferences);
1034
1035         combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1036         cell_layout = GTK_CELL_LAYOUT (combo);
1037
1038         /* Create the model */
1039         store = gtk_list_store_new (COL_THEME_COUNT,
1040                                     G_TYPE_STRING,      /* Display name */
1041                                     G_TYPE_STRING,      /* Theme name */
1042                                     G_TYPE_BOOLEAN,     /* Is an Adium theme */
1043                                     G_TYPE_STRING,      /* Adium theme path */
1044                                     G_TYPE_HASH_TABLE); /* Adium theme info */
1045         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1046                 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1047
1048         /* Fill the model */
1049         themes = empathy_theme_manager_get_themes ();
1050         for (i = 0; themes[i]; i += 2) {
1051                 gtk_list_store_insert_with_values (store, NULL, -1,
1052                         COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1053                         COL_THEME_NAME, themes[i],
1054                         COL_THEME_IS_ADIUM, FALSE,
1055                         -1);
1056         }
1057
1058         adium_themes = empathy_theme_manager_get_adium_themes ();
1059         while (adium_themes != NULL) {
1060                 GHashTable *info;
1061                 const gchar *name;
1062                 const gchar *path;
1063
1064                 info = adium_themes->data;
1065                 name = tp_asv_get_string (info, "CFBundleName");
1066                 path = tp_asv_get_string (info, "path");
1067
1068                 if (name != NULL && path != NULL) {
1069                         gtk_list_store_insert_with_values (store, NULL, -1,
1070                                 COL_THEME_VISIBLE_NAME, name,
1071                                 COL_THEME_NAME, "adium",
1072                                 COL_THEME_IS_ADIUM, TRUE,
1073                                 COL_THEME_ADIUM_PATH, path,
1074                                 COL_THEME_ADIUM_INFO, info,
1075                                 -1);
1076                 }
1077                 g_hash_table_unref (info);
1078                 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1079         }
1080
1081         /* Add cell renderer */
1082         renderer = gtk_cell_renderer_text_new ();
1083         gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1084         gtk_cell_layout_set_attributes (cell_layout, renderer,
1085                 "text", COL_THEME_VISIBLE_NAME, NULL);
1086
1087         gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1088         g_object_unref (store);
1089
1090         g_signal_connect (combo, "changed",
1091                           G_CALLBACK (preferences_theme_changed_cb),
1092                           preferences);
1093
1094         /* Select the theme from the GSetting key and track changes */
1095         preferences_theme_notify_cb (priv->gsettings_chat,
1096                                      EMPATHY_PREFS_CHAT_THEME,
1097                                      preferences);
1098         g_signal_connect (priv->gsettings_chat,
1099                           "changed::" EMPATHY_PREFS_CHAT_THEME,
1100                           G_CALLBACK (preferences_theme_notify_cb),
1101                           preferences);
1102
1103         g_signal_connect (priv->gsettings_chat,
1104                           "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1105                           G_CALLBACK (preferences_theme_notify_cb),
1106                           preferences);
1107 }
1108
1109 static gchar*
1110 preferences_call_format_volume_cb (GtkScale *scale,
1111                                    gdouble value)
1112 {
1113         return g_strdup_printf ("%g%%", value);
1114 }
1115
1116 static void
1117 empathy_preferences_response (GtkDialog *widget,
1118                               gint response)
1119 {
1120         gtk_widget_destroy (GTK_WIDGET (widget));
1121 }
1122
1123 static void
1124 empathy_preferences_finalize (GObject *self)
1125 {
1126         EmpathyPreferencesPriv *priv = GET_PRIV (self);
1127
1128         g_object_unref (priv->theme_manager);
1129
1130         g_object_unref (priv->gsettings);
1131         g_object_unref (priv->gsettings_chat);
1132         g_object_unref (priv->gsettings_call);
1133         g_object_unref (priv->gsettings_loc);
1134         g_object_unref (priv->gsettings_notify);
1135         g_object_unref (priv->gsettings_sound);
1136         g_object_unref (priv->gsettings_ui);
1137         g_object_unref (priv->gsettings_logger);
1138
1139         G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1140 }
1141
1142 static void
1143 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1144 {
1145         GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1146         GObjectClass *object_class = G_OBJECT_CLASS (klass);
1147
1148         dialog_class->response = empathy_preferences_response;
1149
1150         object_class->finalize = empathy_preferences_finalize;
1151
1152         g_type_class_add_private (object_class,
1153                                   sizeof (EmpathyPreferencesPriv));
1154 }
1155
1156 static void
1157 empathy_preferences_init (EmpathyPreferences *preferences)
1158 {
1159         EmpathyPreferencesPriv    *priv;
1160         GtkBuilder                *gui;
1161         gchar                     *filename;
1162         GtkWidget                 *page;
1163
1164         priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1165                         EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1166
1167         gtk_dialog_add_button (GTK_DIALOG (preferences),
1168                                GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1169
1170         gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1171         gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1172         gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1173         gtk_window_set_position (GTK_WINDOW (preferences),
1174                                  GTK_WIN_POS_CENTER_ON_PARENT);
1175         gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1176
1177         filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1178         gui = empathy_builder_get_file (filename,
1179                 "notebook", &priv->notebook,
1180                 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1181                 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1182                 "vbox_chat_theme", &priv->vbox_chat_theme,
1183                 "combobox_chat_theme", &priv->combobox_chat_theme,
1184                 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1185                 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1186                 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1187                 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1188                 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1189                 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1190                 "checkbutton_logging", &priv->checkbutton_logging,
1191                 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1192                 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1193                 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1194                 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1195                 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1196                 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1197                 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1198                 "treeview_sounds", &priv->treeview_sounds,
1199                 "treeview_spell_checker", &priv->treeview_spell_checker,
1200                 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1201                 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1202                 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1203                 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1204                 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1205                 "call_volume_scale", &priv->scale_call_volume,
1206                 "call_volume_adjustment", &priv->adj_call_volume,
1207                 "call_echo_cancellation", &priv->echo_cancellation,
1208                 NULL);
1209         g_free (filename);
1210
1211         gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1212         gtk_widget_show (priv->notebook);
1213
1214         g_object_unref (gui);
1215
1216         priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1217         priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1218         priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1219         priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1220         priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1221         priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1222         priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1223         priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1224
1225         /* Create chat theme preview, and track changes */
1226         priv->theme_manager = empathy_theme_manager_dup_singleton ();
1227         tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1228                           G_CALLBACK (preferences_preview_theme_changed_cb),
1229                           preferences, 0);
1230         preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1231
1232         g_signal_connect (priv->scale_call_volume, "format-value",
1233                           G_CALLBACK (preferences_call_format_volume_cb),
1234                           preferences);
1235
1236         preferences_themes_setup (preferences);
1237
1238         preferences_setup_widgets (preferences);
1239
1240         preferences_languages_setup (preferences);
1241         preferences_languages_add (preferences);
1242         preferences_languages_load (preferences);
1243
1244         preferences_sound_setup (preferences);
1245         preferences_sound_load (preferences);
1246
1247         if (empathy_spell_supported ()) {
1248                 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1249                 gtk_widget_show (page);
1250         }
1251
1252         page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1253 #ifdef HAVE_GEOCLUE
1254         gtk_widget_show (page);
1255 #else
1256         gtk_widget_hide (page);
1257 #endif
1258 }
1259
1260 static EmpathyPreferencesTab
1261 empathy_preferences_tab_from_string (const gchar *str)
1262 {
1263   guint i;
1264
1265   for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1266     {
1267       if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1268         return i;
1269     }
1270
1271   g_warn_if_reached ();
1272   return -1;
1273 }
1274
1275 const gchar *
1276 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1277 {
1278   g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1279
1280   return empathy_preferences_tabs[tab];
1281 }
1282
1283 GtkWidget *
1284 empathy_preferences_new (GtkWindow *parent)
1285 {
1286         GtkWidget *self;
1287
1288         g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1289
1290         self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1291
1292         if (parent != NULL) {
1293                 gtk_window_set_transient_for (GTK_WINDOW (self),
1294                                               parent);
1295         }
1296
1297         return self;
1298 }
1299
1300 void
1301 empathy_preferences_show_tab (EmpathyPreferences *self,
1302                               const gchar *page)
1303 {
1304         EmpathyPreferencesPriv *priv = GET_PRIV (self);
1305
1306         gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1307                                        empathy_preferences_tab_from_string (page));
1308 }