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