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