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