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