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