]> git.0d.be Git - empathy.git/blob - src/empathy-preferences.c
Merge branch 'log-window-webview'
[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 #include <libempathy-gtk/empathy-theme-adium.h>
45
46 #include "empathy-preferences.h"
47
48 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
49 #include <libempathy/empathy-debug.h>
50
51 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
52
53 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
54
55 static const gchar * empathy_preferences_tabs[] =
56 {
57   "general",
58   "notifications",
59   "sounds",
60   "calls",
61   "location",
62   "spell",
63   "themes",
64 };
65
66 struct _EmpathyPreferencesPriv {
67         GtkWidget *notebook;
68
69         GtkWidget *checkbutton_show_smileys;
70         GtkWidget *checkbutton_show_contacts_in_rooms;
71         GtkWidget *checkbutton_separate_chat_windows;
72         GtkWidget *checkbutton_events_notif_area;
73         GtkWidget *checkbutton_autoconnect;
74         GtkWidget *checkbutton_logging;
75
76         GtkWidget *checkbutton_sounds_enabled;
77         GtkWidget *checkbutton_sounds_disabled_away;
78         GtkWidget *treeview_sounds;
79
80         GtkWidget *checkbutton_notifications_enabled;
81         GtkWidget *checkbutton_notifications_disabled_away;
82         GtkWidget *checkbutton_notifications_focus;
83         GtkWidget *checkbutton_notifications_contact_signin;
84         GtkWidget *checkbutton_notifications_contact_signout;
85
86         GtkWidget *scale_call_volume;
87         GtkWidget *adj_call_volume;
88         GtkWidget *echo_cancellation;
89
90         GtkWidget *treeview_spell_checker;
91
92         GtkWidget *checkbutton_location_publish;
93         GtkWidget *checkbutton_location_reduce_accuracy;
94         GtkWidget *checkbutton_location_resource_network;
95         GtkWidget *checkbutton_location_resource_cell;
96         GtkWidget *checkbutton_location_resource_gps;
97
98         GtkWidget *vbox_chat_theme;
99         GtkWidget *combobox_chat_theme;
100         GtkWidget *combobox_chat_theme_variant;
101         GtkWidget *hbox_chat_theme_variant;
102         GtkWidget *sw_chat_theme_preview;
103         EmpathyChatView *chat_theme_preview;
104         EmpathyThemeManager *theme_manager;
105
106         GSettings *gsettings;
107         GSettings *gsettings_chat;
108         GSettings *gsettings_call;
109         GSettings *gsettings_loc;
110         GSettings *gsettings_notify;
111         GSettings *gsettings_sound;
112         GSettings *gsettings_ui;
113         GSettings *gsettings_logger;
114 };
115
116 static void     preferences_setup_widgets                (EmpathyPreferences      *preferences);
117 static void     preferences_languages_setup              (EmpathyPreferences      *preferences);
118 static void     preferences_languages_add                (EmpathyPreferences      *preferences);
119 static void     preferences_languages_save               (EmpathyPreferences      *preferences);
120 static gboolean preferences_languages_save_foreach       (GtkTreeModel           *model,
121                                                           GtkTreePath            *path,
122                                                           GtkTreeIter            *iter,
123                                                           gchar                 **languages);
124 static void     preferences_languages_load               (EmpathyPreferences      *preferences);
125 static gboolean preferences_languages_load_foreach       (GtkTreeModel           *model,
126                                                           GtkTreePath            *path,
127                                                           GtkTreeIter            *iter,
128                                                           GList                  *languages);
129 static void     preferences_languages_cell_toggled_cb    (GtkCellRendererToggle  *cell,
130                                                           gchar                  *path_string,
131                                                           EmpathyPreferences      *preferences);
132
133 enum {
134         COL_LANG_ENABLED,
135         COL_LANG_CODE,
136         COL_LANG_NAME,
137         COL_LANG_COUNT
138 };
139
140 enum {
141         COL_THEME_VISIBLE_NAME,
142         COL_THEME_NAME,
143         COL_THEME_IS_ADIUM,
144         COL_THEME_ADIUM_PATH,
145         COL_THEME_ADIUM_INFO,
146         COL_THEME_COUNT
147 };
148
149 enum {
150         COL_VARIANT_NAME,
151         COL_VARIANT_DEFAULT,
152         COL_VARIANT_COUNT
153 };
154
155 enum {
156         COL_SOUND_ENABLED,
157         COL_SOUND_NAME,
158         COL_SOUND_KEY,
159         COL_SOUND_COUNT
160 };
161
162 typedef struct {
163         const char *name;
164         const char *key;
165 } SoundEventEntry;
166
167 /* TODO: add phone related sounds also? */
168 static SoundEventEntry sound_entries [] = {
169         { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
170         { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
171         { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
172         { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
173         { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
174         { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
175         { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
176 };
177
178 static void
179 preferences_setup_widgets (EmpathyPreferences *preferences)
180 {
181         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
182
183         g_settings_bind (priv->gsettings_notify,
184                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
185                          priv->checkbutton_notifications_enabled,
186                          "active",
187                          G_SETTINGS_BIND_DEFAULT);
188         g_settings_bind (priv->gsettings_notify,
189                          EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
190                          priv->checkbutton_notifications_disabled_away,
191                          "active",
192                          G_SETTINGS_BIND_DEFAULT);
193         g_settings_bind (priv->gsettings_notify,
194                          EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
195                          priv->checkbutton_notifications_focus,
196                          "active",
197                          G_SETTINGS_BIND_DEFAULT);
198         g_settings_bind (priv->gsettings_notify,
199                          EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
200                          priv->checkbutton_notifications_contact_signin,
201                          "active",
202                          G_SETTINGS_BIND_DEFAULT);
203         g_settings_bind (priv->gsettings_notify,
204                          EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
205                          priv->checkbutton_notifications_contact_signout,
206                          "active",
207                          G_SETTINGS_BIND_DEFAULT);
208
209         g_settings_bind (priv->gsettings_notify,
210                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
211                          priv->checkbutton_notifications_disabled_away,
212                          "sensitive",
213                          G_SETTINGS_BIND_GET);
214         g_settings_bind (priv->gsettings_notify,
215                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
216                          priv->checkbutton_notifications_focus,
217                          "sensitive",
218                          G_SETTINGS_BIND_GET);
219         g_settings_bind (priv->gsettings_notify,
220                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
221                          priv->checkbutton_notifications_contact_signin,
222                          "sensitive",
223                          G_SETTINGS_BIND_GET);
224         g_settings_bind (priv->gsettings_notify,
225                          EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
226                          priv->checkbutton_notifications_contact_signout,
227                          "sensitive",
228                          G_SETTINGS_BIND_GET);
229
230         g_settings_bind (priv->gsettings_sound,
231                          EMPATHY_PREFS_SOUNDS_ENABLED,
232                          priv->checkbutton_sounds_enabled,
233                          "active",
234                          G_SETTINGS_BIND_DEFAULT);
235         g_settings_bind (priv->gsettings_sound,
236                          EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
237                          priv->checkbutton_sounds_disabled_away,
238                          "active",
239                          G_SETTINGS_BIND_DEFAULT);
240
241         g_settings_bind (priv->gsettings_sound,
242                          EMPATHY_PREFS_SOUNDS_ENABLED,
243                          priv->checkbutton_sounds_disabled_away,
244                          "sensitive",
245                          G_SETTINGS_BIND_GET);
246         g_settings_bind (priv->gsettings_sound,
247                         EMPATHY_PREFS_SOUNDS_ENABLED,
248                         priv->treeview_sounds,
249                         "sensitive",
250                         G_SETTINGS_BIND_GET);
251
252         g_settings_bind (priv->gsettings_ui,
253                          EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
254                          priv->checkbutton_separate_chat_windows,
255                          "active",
256                          G_SETTINGS_BIND_DEFAULT);
257
258         g_settings_bind (priv->gsettings_ui,
259                          EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
260                          priv->checkbutton_events_notif_area,
261                          "active",
262                          G_SETTINGS_BIND_DEFAULT);
263
264         g_settings_bind (priv->gsettings_chat,
265                          EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
266                          priv->checkbutton_show_smileys,
267                          "active",
268                          G_SETTINGS_BIND_DEFAULT);
269         g_settings_bind (priv->gsettings_chat,
270                          EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
271                          priv->checkbutton_show_contacts_in_rooms,
272                          "active",
273                          G_SETTINGS_BIND_DEFAULT);
274
275         g_settings_bind (priv->gsettings_call,
276                          EMPATHY_PREFS_CALL_SOUND_VOLUME,
277                          priv->adj_call_volume,
278                          "value",
279                          G_SETTINGS_BIND_DEFAULT);
280
281         g_settings_bind (priv->gsettings_call,
282                          EMPATHY_PREFS_CALL_ECHO_CANCELLATION,
283                          priv->echo_cancellation,
284                          "active",
285                          G_SETTINGS_BIND_DEFAULT);
286
287         g_settings_bind (priv->gsettings,
288                          EMPATHY_PREFS_AUTOCONNECT,
289                          priv->checkbutton_autoconnect,
290                          "active",
291                          G_SETTINGS_BIND_DEFAULT);
292
293         g_settings_bind (priv->gsettings_loc,
294                          EMPATHY_PREFS_LOCATION_PUBLISH,
295                          priv->checkbutton_location_publish,
296                          "active",
297                          G_SETTINGS_BIND_DEFAULT);
298
299         g_settings_bind (priv->gsettings_loc,
300                          EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
301                          priv->checkbutton_location_resource_network,
302                          "active",
303                          G_SETTINGS_BIND_DEFAULT);
304         g_settings_bind (priv->gsettings_loc,
305                          EMPATHY_PREFS_LOCATION_PUBLISH,
306                          priv->checkbutton_location_resource_network,
307                          "sensitive",
308                          G_SETTINGS_BIND_GET);
309
310         g_settings_bind (priv->gsettings_loc,
311                          EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
312                          priv->checkbutton_location_resource_cell,
313                          "active",
314                          G_SETTINGS_BIND_DEFAULT);
315         g_settings_bind (priv->gsettings_loc,
316                          EMPATHY_PREFS_LOCATION_PUBLISH,
317                          priv->checkbutton_location_resource_cell,
318                          "sensitive",
319                          G_SETTINGS_BIND_GET);
320
321         g_settings_bind (priv->gsettings_loc,
322                          EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
323                          priv->checkbutton_location_resource_gps,
324                          "active",
325                          G_SETTINGS_BIND_DEFAULT);
326         g_settings_bind (priv->gsettings_loc,
327                          EMPATHY_PREFS_LOCATION_PUBLISH,
328                          priv->checkbutton_location_resource_gps,
329                          "sensitive",
330                          G_SETTINGS_BIND_GET);
331
332         g_settings_bind (priv->gsettings_loc,
333                          EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
334                          priv->checkbutton_location_reduce_accuracy,
335                          "active",
336                          G_SETTINGS_BIND_DEFAULT);
337         g_settings_bind (priv->gsettings_loc,
338                          EMPATHY_PREFS_LOCATION_PUBLISH,
339                          priv->checkbutton_location_reduce_accuracy,
340                          "sensitive",
341                          G_SETTINGS_BIND_GET);
342
343         g_settings_bind (priv->gsettings_logger,
344                          EMPATHY_PREFS_LOGGER_ENABLED,
345                          priv->checkbutton_logging,
346                          "active",
347                          G_SETTINGS_BIND_DEFAULT);
348 }
349
350 static void
351 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
352                                    char *path_string,
353                                    EmpathyPreferences *preferences)
354 {
355         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
356         GtkTreePath *path;
357         gboolean instore;
358         GtkTreeIter iter;
359         GtkTreeView *view;
360         GtkTreeModel *model;
361         char *key;
362
363         view = GTK_TREE_VIEW (priv->treeview_sounds);
364         model = gtk_tree_view_get_model (view);
365
366         path = gtk_tree_path_new_from_string (path_string);
367
368         gtk_tree_model_get_iter (model, &iter, path);
369         gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
370                             COL_SOUND_ENABLED, &instore, -1);
371
372         instore ^= 1;
373
374         gtk_list_store_set (GTK_LIST_STORE (model), &iter,
375                             COL_SOUND_ENABLED, instore, -1);
376
377         g_settings_set_boolean (priv->gsettings_sound, key, instore);
378
379         g_free (key);
380         gtk_tree_path_free (path);
381 }
382
383 static void
384 preferences_sound_load (EmpathyPreferences *preferences)
385 {
386         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
387         guint i;
388         GtkTreeView *view;
389         GtkListStore *store;
390         GtkTreeIter iter;
391         gboolean set;
392
393         view = GTK_TREE_VIEW (priv->treeview_sounds);
394         store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
395
396         for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
397                 set = g_settings_get_boolean (priv->gsettings_sound,
398                                               sound_entries[i].key);
399
400                 gtk_list_store_insert_with_values (store, &iter, i,
401                                                    COL_SOUND_NAME, gettext (sound_entries[i].name),
402                                                    COL_SOUND_KEY, sound_entries[i].key,
403                                                    COL_SOUND_ENABLED, set, -1);
404         }
405 }
406
407 static void
408 preferences_sound_setup (EmpathyPreferences *preferences)
409 {
410         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
411         GtkTreeView *view;
412         GtkListStore *store;
413         GtkCellRenderer *renderer;
414         GtkTreeViewColumn *column;
415
416         view = GTK_TREE_VIEW (priv->treeview_sounds);
417
418         store = gtk_list_store_new (COL_SOUND_COUNT,
419                                     G_TYPE_BOOLEAN, /* enabled */
420                                     G_TYPE_STRING,  /* name */
421                                     G_TYPE_STRING); /* key */
422
423         gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
424
425         renderer = gtk_cell_renderer_toggle_new ();
426         g_signal_connect (renderer, "toggled",
427                           G_CALLBACK (preferences_sound_cell_toggled_cb),
428                           preferences);
429
430         column = gtk_tree_view_column_new ();
431         gtk_tree_view_column_pack_start (column, renderer, FALSE);
432         gtk_tree_view_column_add_attribute (column, renderer,
433                                             "active", COL_SOUND_ENABLED);
434
435         renderer = gtk_cell_renderer_text_new ();
436         gtk_tree_view_column_pack_start (column, renderer, FALSE);
437         gtk_tree_view_column_add_attribute (column, renderer,
438                                             "text", COL_SOUND_NAME);
439
440         gtk_tree_view_append_column (view, column);
441
442         gtk_tree_view_column_set_resizable (column, FALSE);
443         gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
444
445         g_object_unref (store);
446 }
447
448 static void
449 preferences_languages_setup (EmpathyPreferences *preferences)
450 {
451         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
452         GtkTreeView       *view;
453         GtkListStore      *store;
454         GtkTreeSelection  *selection;
455         GtkTreeViewColumn *column;
456         GtkCellRenderer   *renderer;
457         guint              col_offset;
458
459         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
460
461         store = gtk_list_store_new (COL_LANG_COUNT,
462                                     G_TYPE_BOOLEAN,  /* enabled */
463                                     G_TYPE_STRING,   /* code */
464                                     G_TYPE_STRING);  /* name */
465
466         gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
467
468         selection = gtk_tree_view_get_selection (view);
469         gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
470
471         renderer = gtk_cell_renderer_toggle_new ();
472         g_signal_connect (renderer, "toggled",
473                           G_CALLBACK (preferences_languages_cell_toggled_cb),
474                           preferences);
475
476         column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
477                                                            "active", COL_LANG_ENABLED,
478                                                            NULL);
479
480         gtk_tree_view_append_column (view, column);
481
482         renderer = gtk_cell_renderer_text_new ();
483         col_offset = gtk_tree_view_insert_column_with_attributes (view,
484                                                                   -1, _("Language"),
485                                                                   renderer,
486                                                                   "text", COL_LANG_NAME,
487                                                                   NULL);
488
489         g_object_set_data (G_OBJECT (renderer),
490                            "column", GINT_TO_POINTER (COL_LANG_NAME));
491
492         column = gtk_tree_view_get_column (view, col_offset - 1);
493         gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
494         gtk_tree_view_column_set_resizable (column, FALSE);
495         gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
496
497         g_object_unref (store);
498 }
499
500 static void
501 preferences_languages_add (EmpathyPreferences *preferences)
502 {
503         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
504         GtkTreeView  *view;
505         GtkListStore *store;
506         GList        *codes, *l;
507
508         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
509         store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
510
511         codes = empathy_spell_get_language_codes ();
512
513         if (!codes) {
514                 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
515         }
516
517         for (l = codes; l; l = l->next) {
518                 GtkTreeIter  iter;
519                 const gchar *code;
520                 const gchar *name;
521
522                 code = l->data;
523                 name = empathy_spell_get_language_name (code);
524                 if (!name) {
525                         continue;
526                 }
527
528                 gtk_list_store_append (store, &iter);
529                 gtk_list_store_set (store, &iter,
530                                     COL_LANG_CODE, code,
531                                     COL_LANG_NAME, name,
532                                     -1);
533         }
534
535         empathy_spell_free_language_codes (codes);
536 }
537
538 static void
539 preferences_languages_save (EmpathyPreferences *preferences)
540 {
541         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
542         GtkTreeView       *view;
543         GtkTreeModel      *model;
544
545         gchar             *languages = NULL;
546
547         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
548         model = gtk_tree_view_get_model (view);
549
550         gtk_tree_model_foreach (model,
551                                 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
552                                 &languages);
553
554         /* if user selects no languages, we don't want spell check */
555         g_settings_set_boolean (priv->gsettings_chat,
556                                 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
557                                 languages != NULL);
558
559         g_settings_set_string (priv->gsettings_chat,
560                                EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
561                                languages != NULL ? languages : "");
562
563         g_free (languages);
564 }
565
566 static gboolean
567 preferences_languages_save_foreach (GtkTreeModel  *model,
568                                     GtkTreePath   *path,
569                                     GtkTreeIter   *iter,
570                                     gchar        **languages)
571 {
572         gboolean  enabled;
573         gchar    *code;
574
575         if (!languages) {
576                 return TRUE;
577         }
578
579         gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
580         if (!enabled) {
581                 return FALSE;
582         }
583
584         gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
585         if (!code) {
586                 return FALSE;
587         }
588
589         if (!(*languages)) {
590                 *languages = g_strdup (code);
591         } else {
592                 gchar *str = *languages;
593                 *languages = g_strdup_printf ("%s,%s", str, code);
594                 g_free (str);
595         }
596
597         g_free (code);
598
599         return FALSE;
600 }
601
602 static void
603 preferences_languages_load (EmpathyPreferences *preferences)
604 {
605         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
606         GtkTreeView   *view;
607         GtkTreeModel  *model;
608         GList         *enabled_codes;
609
610         enabled_codes = empathy_spell_get_enabled_language_codes ();
611
612         g_settings_set_boolean (priv->gsettings_chat,
613                                 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
614                                 enabled_codes != NULL);
615
616         if (enabled_codes == NULL)
617                 return;
618
619         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
620         model = gtk_tree_view_get_model (view);
621
622         gtk_tree_model_foreach (model,
623                                 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
624                                 enabled_codes);
625
626         g_list_free (enabled_codes);
627 }
628
629 static gboolean
630 preferences_languages_load_foreach (GtkTreeModel  *model,
631                                     GtkTreePath   *path,
632                                     GtkTreeIter   *iter,
633                                     GList         *languages)
634 {
635         gchar    *code;
636         gboolean  found = FALSE;
637
638         if (!languages) {
639                 return TRUE;
640         }
641
642         gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
643         if (!code) {
644                 return FALSE;
645         }
646
647         if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
648                 found = TRUE;
649         }
650
651         g_free (code);
652         gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
653         return FALSE;
654 }
655
656 static void
657 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
658                                        gchar                 *path_string,
659                                        EmpathyPreferences     *preferences)
660 {
661         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
662         GtkTreeView  *view;
663         GtkTreeModel *model;
664         GtkListStore *store;
665         GtkTreePath  *path;
666         GtkTreeIter   iter;
667         gboolean      enabled;
668
669         view = GTK_TREE_VIEW (priv->treeview_spell_checker);
670         model = gtk_tree_view_get_model (view);
671         store = GTK_LIST_STORE (model);
672
673         path = gtk_tree_path_new_from_string (path_string);
674
675         gtk_tree_model_get_iter (model, &iter, path);
676         gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
677
678         enabled ^= 1;
679
680         gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
681         gtk_tree_path_free (path);
682
683         preferences_languages_save (preferences);
684 }
685
686 static void
687 preferences_preview_theme_append_message (EmpathyChatView *view,
688                                           EmpathyContact *sender,
689                                           EmpathyContact *receiver,
690                                           const gchar *text)
691 {
692         EmpathyMessage *message;
693
694         message = g_object_new (EMPATHY_TYPE_MESSAGE,
695                 "sender", sender,
696                 "receiver", receiver,
697                 "body", text,
698                 NULL);
699
700         empathy_chat_view_append_message (view, message);
701         g_object_unref (message);
702 }
703
704 static void
705 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
706                                       EmpathyPreferences  *preferences)
707 {
708         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
709         TpDBusDaemon *dbus;
710         TpAccount *account;
711         EmpathyContact *juliet;
712         EmpathyContact *romeo;
713
714         DEBUG ("Theme changed, update preview widget");
715
716         if (priv->chat_theme_preview != NULL) {
717                 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
718         }
719         priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
720         gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
721                            GTK_WIDGET (priv->chat_theme_preview));
722         gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
723
724         /* FIXME: It is ugly to add a fake conversation like that.
725          * Would be cool if we could request a TplLogManager for a fake
726          * conversation */
727         dbus = tp_dbus_daemon_dup (NULL);
728         account = tp_account_new (dbus,
729                 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
730         juliet = g_object_new (EMPATHY_TYPE_CONTACT,
731                 "account", account,
732                 "id", "juliet",
733                 /* translators: Contact name for the chat theme preview */
734                 "alias", _("Juliet"),
735                 "is-user", FALSE,
736                 NULL);
737         romeo = g_object_new (EMPATHY_TYPE_CONTACT,
738                 "account", account,
739                 "id", "romeo",
740                 /* translators: Contact name for the chat theme preview */
741                 "alias", _("Romeo"),
742                 "is-user", TRUE,
743                 NULL);
744
745         preferences_preview_theme_append_message (priv->chat_theme_preview,
746                 /* translators: Quote from Romeo & Julier, for chat theme preview */
747                 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
748         preferences_preview_theme_append_message (priv->chat_theme_preview,
749                 /* translators: Quote from Romeo & Julier, for chat theme preview */
750                 juliet, romeo, _("Deny thy father and refuse thy name;"));
751         preferences_preview_theme_append_message (priv->chat_theme_preview,
752                 /* translators: Quote from Romeo & Julier, for chat theme preview */
753                 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
754         preferences_preview_theme_append_message (priv->chat_theme_preview,
755                 /* translators: Quote from Romeo & Julier, for chat theme preview */
756                 juliet, romeo, _("And I'll no longer be a Capulet."));
757         preferences_preview_theme_append_message (priv->chat_theme_preview,
758                 /* translators: Quote from Romeo & Julier, for chat theme preview */
759                 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
760
761         /* translators: Quote from Romeo & Julier, for chat theme preview */
762         empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
763
764         g_object_unref (juliet);
765         g_object_unref (romeo);
766         g_object_unref (account);
767         g_object_unref (dbus);
768 }
769
770 static void
771 preferences_theme_variant_changed_cb (GtkComboBox        *combo,
772                                       EmpathyPreferences *preferences)
773 {
774         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
775         GtkTreeIter   iter;
776
777         if (gtk_combo_box_get_active_iter (combo, &iter)) {
778                 GtkTreeModel *model;
779                 gchar        *name;
780
781                 model = gtk_combo_box_get_model (combo);
782                 gtk_tree_model_get (model, &iter,
783                                     COL_VARIANT_NAME, &name,
784                                     -1);
785
786                 g_settings_set_string (priv->gsettings_chat,
787                                        EMPATHY_PREFS_CHAT_THEME_VARIANT,
788                                        name);
789
790                 g_free (name);
791         }
792 }
793
794 static void
795 preferences_theme_variant_notify_cb (GSettings   *gsettings,
796                                      const gchar *key,
797                                      gpointer     user_data)
798 {
799         EmpathyPreferences *preferences = user_data;
800         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
801         GtkComboBox        *combo;
802         gchar              *conf_name;
803         GtkTreeModel       *model;
804         GtkTreeIter         iter;
805         GtkTreeIter         default_iter;
806         gboolean            found_default = FALSE;
807         gboolean            found = FALSE;
808         gboolean            ok;
809
810         conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
811         combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
812         model = gtk_combo_box_get_model (combo);
813
814         for (ok = gtk_tree_model_get_iter_first (model, &iter);
815              ok && !found;
816              ok = gtk_tree_model_iter_next (model, &iter)) {
817                 gchar *name;
818                 gboolean is_default;
819
820                 gtk_tree_model_get (model, &iter,
821                                     COL_VARIANT_NAME, &name,
822                                     COL_VARIANT_DEFAULT, &is_default,
823                                     -1);
824
825                 if (!tp_strdiff (name, conf_name)) {
826                         found = TRUE;
827                         gtk_combo_box_set_active_iter (combo, &iter);
828                 }
829                 if (is_default) {
830                         found_default = TRUE;
831                         default_iter = iter;
832                 }
833
834                 g_free (name);
835         }
836
837         /* Fallback to the first one. */
838         if (!found) {
839                 if (found_default) {
840                         gtk_combo_box_set_active_iter (combo, &default_iter);
841                 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
842                         gtk_combo_box_set_active_iter (combo, &iter);
843                 }
844         }
845
846         g_free (conf_name);
847 }
848
849 static void
850 preferences_theme_variants_fill (EmpathyPreferences *preferences,
851                                  GHashTable         *info)
852 {
853         EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
854         GtkTreeModel *model;
855         GtkListStore *store;
856         GPtrArray    *variants;
857         const gchar  *default_variant;
858         guint         i;
859
860         model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
861         store = GTK_LIST_STORE (model);
862         gtk_list_store_clear (store);
863
864         variants = empathy_adium_info_get_available_variants (info);
865         default_variant = empathy_adium_info_get_default_variant (info);
866         for (i = 0; i < variants->len; i++) {
867                 gchar *name = g_ptr_array_index (variants, i);
868
869                 gtk_list_store_insert_with_values (store, NULL, -1,
870                         COL_VARIANT_NAME, name,
871                         COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
872                         -1);
873         }
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         GtkWidget                 *call_volume_scale_box;
1157         GtkWidget                 *call_volume_bar_box;
1158
1159         priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1160                         EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1161
1162         gtk_dialog_add_button (GTK_DIALOG (preferences),
1163                                GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1164
1165         gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1166         gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1167         gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1168         gtk_window_set_position (GTK_WINDOW (preferences),
1169                                  GTK_WIN_POS_CENTER_ON_PARENT);
1170         gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1171
1172         filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1173         gui = empathy_builder_get_file (filename,
1174                 "notebook", &priv->notebook,
1175                 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1176                 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1177                 "vbox_chat_theme", &priv->vbox_chat_theme,
1178                 "combobox_chat_theme", &priv->combobox_chat_theme,
1179                 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1180                 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1181                 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1182                 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1183                 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1184                 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1185                 "checkbutton_logging", &priv->checkbutton_logging,
1186                 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1187                 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1188                 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1189                 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1190                 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1191                 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1192                 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1193                 "treeview_sounds", &priv->treeview_sounds,
1194                 "treeview_spell_checker", &priv->treeview_spell_checker,
1195                 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1196                 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1197                 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1198                 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1199                 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1200                 "call_volume_scale_box", &call_volume_scale_box,
1201                 "call_volume_bar_box", &call_volume_bar_box,
1202                 "call_volume_scale", &priv->scale_call_volume,
1203                 "call_volume_adjustment", &priv->adj_call_volume,
1204                 "call_echo_cancellation", &priv->echo_cancellation,
1205                 NULL);
1206         g_free (filename);
1207
1208         gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1209         gtk_widget_show (priv->notebook);
1210
1211         g_object_unref (gui);
1212
1213         priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1214         priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1215         priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1216         priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1217         priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1218         priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1219         priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1220         priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1221
1222         /* Create chat theme preview, and track changes */
1223         priv->theme_manager = empathy_theme_manager_dup_singleton ();
1224         tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1225                           G_CALLBACK (preferences_preview_theme_changed_cb),
1226                           preferences, 0);
1227         preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1228
1229         g_signal_connect (priv->scale_call_volume, "format-value",
1230                           G_CALLBACK (preferences_call_format_volume_cb),
1231                           preferences);
1232
1233 #ifndef HAVE_CALL
1234         gtk_widget_hide (call_volume_scale_box);
1235         gtk_widget_hide (call_volume_bar_box);
1236 #endif
1237
1238         preferences_themes_setup (preferences);
1239
1240         preferences_setup_widgets (preferences);
1241
1242         preferences_languages_setup (preferences);
1243         preferences_languages_add (preferences);
1244         preferences_languages_load (preferences);
1245
1246         preferences_sound_setup (preferences);
1247         preferences_sound_load (preferences);
1248
1249         if (empathy_spell_supported ()) {
1250                 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1251                 gtk_widget_show (page);
1252         }
1253
1254         page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1255 #ifdef HAVE_GEOCLUE
1256         gtk_widget_show (page);
1257 #else
1258         gtk_widget_hide (page);
1259 #endif
1260 }
1261
1262 static EmpathyPreferencesTab
1263 empathy_preferences_tab_from_string (const gchar *str)
1264 {
1265   guint i;
1266
1267   for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1268     {
1269       if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1270         return i;
1271     }
1272
1273   g_warn_if_reached ();
1274   return -1;
1275 }
1276
1277 const gchar *
1278 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1279 {
1280   g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1281
1282   return empathy_preferences_tabs[tab];
1283 }
1284
1285 GtkWidget *
1286 empathy_preferences_new (GtkWindow *parent)
1287 {
1288         GtkWidget *self;
1289
1290         g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1291
1292         self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1293
1294         if (parent != NULL) {
1295                 gtk_window_set_transient_for (GTK_WINDOW (self),
1296                                               parent);
1297         }
1298
1299         return self;
1300 }
1301
1302 void
1303 empathy_preferences_show_tab (EmpathyPreferences *self,
1304                               const gchar *page)
1305 {
1306         EmpathyPreferencesPriv *priv = GET_PRIV (self);
1307
1308         gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1309                                        empathy_preferences_tab_from_string (page));
1310 }