1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2003-2007 Imendio AB
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.
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.
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
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>
32 #include <glib/gi18n.h>
33 #include <telepathy-glib/dbus.h>
34 #include <telepathy-glib/util.h>
36 #include <libempathy/empathy-gsettings.h>
37 #include <libempathy/empathy-utils.h>
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>
46 #include <libempathy-gtk/empathy-theme-adium.h>
49 #include "empathy-preferences.h"
51 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
52 #include <libempathy/empathy-debug.h>
54 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
56 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
58 struct _EmpathyPreferencesPriv {
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;
68 GtkWidget *checkbutton_sounds_enabled;
69 GtkWidget *checkbutton_sounds_disabled_away;
70 GtkWidget *treeview_sounds;
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;
78 GtkWidget *treeview_spell_checker;
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;
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;
95 GSettings *gsettings_chat;
96 GSettings *gsettings_loc;
97 GSettings *gsettings_notify;
98 GSettings *gsettings_sound;
99 GSettings *gsettings_ui;
100 GSettings *gsettings_logger;
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,
111 static void preferences_languages_load (EmpathyPreferences *preferences);
112 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
116 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
118 EmpathyPreferences *preferences);
128 COL_THEME_VISIBLE_NAME,
131 COL_THEME_ADIUM_PATH,
132 COL_THEME_ADIUM_INFO,
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 }
166 preferences_setup_widgets (EmpathyPreferences *preferences)
168 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
170 g_settings_bind (priv->gsettings_notify,
171 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
172 priv->checkbutton_notifications_enabled,
174 G_SETTINGS_BIND_DEFAULT);
175 g_settings_bind (priv->gsettings_notify,
176 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
177 priv->checkbutton_notifications_disabled_away,
179 G_SETTINGS_BIND_DEFAULT);
180 g_settings_bind (priv->gsettings_notify,
181 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
182 priv->checkbutton_notifications_focus,
184 G_SETTINGS_BIND_DEFAULT);
185 g_settings_bind (priv->gsettings_notify,
186 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
187 priv->checkbutton_notifications_contact_signin,
189 G_SETTINGS_BIND_DEFAULT);
190 g_settings_bind (priv->gsettings_notify,
191 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
192 priv->checkbutton_notifications_contact_signout,
194 G_SETTINGS_BIND_DEFAULT);
196 g_settings_bind (priv->gsettings_notify,
197 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
198 priv->checkbutton_notifications_disabled_away,
200 G_SETTINGS_BIND_GET);
201 g_settings_bind (priv->gsettings_notify,
202 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
203 priv->checkbutton_notifications_focus,
205 G_SETTINGS_BIND_GET);
206 g_settings_bind (priv->gsettings_notify,
207 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
208 priv->checkbutton_notifications_contact_signin,
210 G_SETTINGS_BIND_GET);
211 g_settings_bind (priv->gsettings_notify,
212 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
213 priv->checkbutton_notifications_contact_signout,
215 G_SETTINGS_BIND_GET);
217 g_settings_bind (priv->gsettings_sound,
218 EMPATHY_PREFS_SOUNDS_ENABLED,
219 priv->checkbutton_sounds_enabled,
221 G_SETTINGS_BIND_DEFAULT);
222 g_settings_bind (priv->gsettings_sound,
223 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
224 priv->checkbutton_sounds_disabled_away,
226 G_SETTINGS_BIND_DEFAULT);
228 g_settings_bind (priv->gsettings_sound,
229 EMPATHY_PREFS_SOUNDS_ENABLED,
230 priv->checkbutton_sounds_disabled_away,
232 G_SETTINGS_BIND_GET);
233 g_settings_bind (priv->gsettings_sound,
234 EMPATHY_PREFS_SOUNDS_ENABLED,
235 priv->treeview_sounds,
237 G_SETTINGS_BIND_GET);
239 g_settings_bind (priv->gsettings_ui,
240 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
241 priv->checkbutton_separate_chat_windows,
243 G_SETTINGS_BIND_DEFAULT);
245 g_settings_bind (priv->gsettings_ui,
246 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
247 priv->checkbutton_events_notif_area,
249 G_SETTINGS_BIND_DEFAULT);
251 g_settings_bind (priv->gsettings_chat,
252 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
253 priv->checkbutton_show_smileys,
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,
260 G_SETTINGS_BIND_DEFAULT);
262 g_settings_bind (priv->gsettings,
263 EMPATHY_PREFS_AUTOCONNECT,
264 priv->checkbutton_autoconnect,
266 G_SETTINGS_BIND_DEFAULT);
268 g_settings_bind (priv->gsettings_loc,
269 EMPATHY_PREFS_LOCATION_PUBLISH,
270 priv->checkbutton_location_publish,
272 G_SETTINGS_BIND_DEFAULT);
274 g_settings_bind (priv->gsettings_loc,
275 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
276 priv->checkbutton_location_resource_network,
278 G_SETTINGS_BIND_DEFAULT);
279 g_settings_bind (priv->gsettings_loc,
280 EMPATHY_PREFS_LOCATION_PUBLISH,
281 priv->checkbutton_location_resource_network,
283 G_SETTINGS_BIND_GET);
285 g_settings_bind (priv->gsettings_loc,
286 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
287 priv->checkbutton_location_resource_cell,
289 G_SETTINGS_BIND_DEFAULT);
290 g_settings_bind (priv->gsettings_loc,
291 EMPATHY_PREFS_LOCATION_PUBLISH,
292 priv->checkbutton_location_resource_cell,
294 G_SETTINGS_BIND_GET);
296 g_settings_bind (priv->gsettings_loc,
297 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
298 priv->checkbutton_location_resource_gps,
300 G_SETTINGS_BIND_DEFAULT);
301 g_settings_bind (priv->gsettings_loc,
302 EMPATHY_PREFS_LOCATION_PUBLISH,
303 priv->checkbutton_location_resource_gps,
305 G_SETTINGS_BIND_GET);
307 g_settings_bind (priv->gsettings_loc,
308 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
309 priv->checkbutton_location_reduce_accuracy,
311 G_SETTINGS_BIND_DEFAULT);
312 g_settings_bind (priv->gsettings_loc,
313 EMPATHY_PREFS_LOCATION_PUBLISH,
314 priv->checkbutton_location_reduce_accuracy,
316 G_SETTINGS_BIND_GET);
318 g_settings_bind (priv->gsettings_logger,
319 EMPATHY_PREFS_LOGGER_ENABLED,
320 priv->checkbutton_logging,
322 G_SETTINGS_BIND_DEFAULT);
326 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
328 EmpathyPreferences *preferences)
330 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
338 view = GTK_TREE_VIEW (priv->treeview_sounds);
339 model = gtk_tree_view_get_model (view);
341 path = gtk_tree_path_new_from_string (path_string);
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);
349 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
350 COL_SOUND_ENABLED, instore, -1);
352 g_settings_set_boolean (priv->gsettings_sound, key, instore);
355 gtk_tree_path_free (path);
359 preferences_sound_load (EmpathyPreferences *preferences)
361 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
368 view = GTK_TREE_VIEW (priv->treeview_sounds);
369 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
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);
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);
383 preferences_sound_setup (EmpathyPreferences *preferences)
385 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
388 GtkCellRenderer *renderer;
389 GtkTreeViewColumn *column;
391 view = GTK_TREE_VIEW (priv->treeview_sounds);
393 store = gtk_list_store_new (COL_SOUND_COUNT,
394 G_TYPE_BOOLEAN, /* enabled */
395 G_TYPE_STRING, /* name */
396 G_TYPE_STRING); /* key */
398 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
400 renderer = gtk_cell_renderer_toggle_new ();
401 g_signal_connect (renderer, "toggled",
402 G_CALLBACK (preferences_sound_cell_toggled_cb),
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);
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);
415 gtk_tree_view_append_column (view, column);
417 gtk_tree_view_column_set_resizable (column, FALSE);
418 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
420 g_object_unref (store);
424 preferences_languages_setup (EmpathyPreferences *preferences)
426 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
429 GtkTreeSelection *selection;
430 GtkTreeViewColumn *column;
431 GtkCellRenderer *renderer;
434 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
436 store = gtk_list_store_new (COL_LANG_COUNT,
437 G_TYPE_BOOLEAN, /* enabled */
438 G_TYPE_STRING, /* code */
439 G_TYPE_STRING); /* name */
441 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
443 selection = gtk_tree_view_get_selection (view);
444 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
446 renderer = gtk_cell_renderer_toggle_new ();
447 g_signal_connect (renderer, "toggled",
448 G_CALLBACK (preferences_languages_cell_toggled_cb),
451 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
452 "active", COL_LANG_ENABLED,
455 gtk_tree_view_append_column (view, column);
457 renderer = gtk_cell_renderer_text_new ();
458 col_offset = gtk_tree_view_insert_column_with_attributes (view,
461 "text", COL_LANG_NAME,
464 g_object_set_data (G_OBJECT (renderer),
465 "column", GINT_TO_POINTER (COL_LANG_NAME));
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);
472 g_object_unref (store);
476 preferences_languages_add (EmpathyPreferences *preferences)
478 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
483 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
484 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
486 codes = empathy_spell_get_language_codes ();
489 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
492 for (l = codes; l; l = l->next) {
498 name = empathy_spell_get_language_name (code);
503 gtk_list_store_append (store, &iter);
504 gtk_list_store_set (store, &iter,
510 empathy_spell_free_language_codes (codes);
514 preferences_languages_save (EmpathyPreferences *preferences)
516 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
520 gchar *languages = NULL;
522 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
523 model = gtk_tree_view_get_model (view);
525 gtk_tree_model_foreach (model,
526 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
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,
534 g_settings_set_string (priv->gsettings_chat,
535 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
536 languages != NULL ? languages : "");
542 preferences_languages_save_foreach (GtkTreeModel *model,
554 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
559 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
565 *languages = g_strdup (code);
567 gchar *str = *languages;
568 *languages = g_strdup_printf ("%s,%s", str, code);
578 preferences_languages_load (EmpathyPreferences *preferences)
580 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
583 GList *enabled_codes;
585 enabled_codes = empathy_spell_get_enabled_language_codes ();
587 g_settings_set_boolean (priv->gsettings_chat,
588 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
589 enabled_codes != NULL);
591 if (enabled_codes == NULL)
594 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
595 model = gtk_tree_view_get_model (view);
597 gtk_tree_model_foreach (model,
598 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
601 g_list_free (enabled_codes);
605 preferences_languages_load_foreach (GtkTreeModel *model,
611 gboolean found = FALSE;
617 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
622 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
627 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
632 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
634 EmpathyPreferences *preferences)
636 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
644 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
645 model = gtk_tree_view_get_model (view);
646 store = GTK_LIST_STORE (model);
648 path = gtk_tree_path_new_from_string (path_string);
650 gtk_tree_model_get_iter (model, &iter, path);
651 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
655 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
656 gtk_tree_path_free (path);
658 preferences_languages_save (preferences);
662 preferences_preview_theme_append_message (EmpathyChatView *view,
663 EmpathyContact *sender,
664 EmpathyContact *receiver,
667 EmpathyMessage *message;
669 message = g_object_new (EMPATHY_TYPE_MESSAGE,
671 "receiver", receiver,
675 empathy_chat_view_append_message (view, message);
676 g_object_unref (message);
680 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
681 EmpathyPreferences *preferences)
683 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
686 EmpathyContact *juliet;
687 EmpathyContact *romeo;
689 DEBUG ("Theme changed, update preview widget");
691 if (priv->chat_theme_preview != NULL) {
692 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
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));
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
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,
708 /* translators: Contact name for the chat theme preview */
709 "alias", _("Juliet"),
712 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
715 /* translators: Contact name for the chat theme preview */
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?"));
736 /* translators: Quote from Romeo & Julier, for chat theme preview */
737 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
739 g_object_unref (juliet);
740 g_object_unref (romeo);
741 g_object_unref (account);
742 g_object_unref (dbus);
746 preferences_theme_variant_changed_cb (GtkComboBox *combo,
747 EmpathyPreferences *preferences)
749 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
752 if (gtk_combo_box_get_active_iter (combo, &iter)) {
756 model = gtk_combo_box_get_model (combo);
757 gtk_tree_model_get (model, &iter,
758 COL_VARIANT_NAME, &name,
761 g_settings_set_string (priv->gsettings_chat,
762 EMPATHY_PREFS_CHAT_THEME_VARIANT,
770 preferences_theme_variant_notify_cb (GSettings *gsettings,
774 EmpathyPreferences *preferences = user_data;
775 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
780 GtkTreeIter default_iter;
781 gboolean found_default = FALSE;
782 gboolean found = FALSE;
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);
789 for (ok = gtk_tree_model_get_iter_first (model, &iter);
791 ok = gtk_tree_model_iter_next (model, &iter)) {
795 gtk_tree_model_get (model, &iter,
796 COL_VARIANT_NAME, &name,
797 COL_VARIANT_DEFAULT, &is_default,
800 if (!tp_strdiff (name, conf_name)) {
802 gtk_combo_box_set_active_iter (combo, &iter);
805 found_default = TRUE;
812 /* Fallback to the first one. */
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);
825 preferences_theme_variants_fill (EmpathyPreferences *preferences,
828 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
833 const gchar *default_variant;
835 #endif /* HAVE_WEBKIT */
837 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
838 store = GTK_LIST_STORE (model);
839 gtk_list_store_clear (store);
842 variants = empathy_adium_info_get_available_variants (info);
843 default_variant = empathy_adium_info_get_default_variant (info);
844 for (i = 0; i < variants->len; i++) {
845 gchar *name = g_ptr_array_index (variants, i);
847 gtk_list_store_insert_with_values (store, NULL, -1,
848 COL_VARIANT_NAME, name,
849 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
852 #endif /* HAVE_WEBKIT */
854 /* Select the variant from the GSetting key */
855 preferences_theme_variant_notify_cb (priv->gsettings_chat,
856 EMPATHY_PREFS_CHAT_THEME_VARIANT,
861 preferences_theme_variants_setup (EmpathyPreferences *preferences)
863 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
865 GtkCellLayout *cell_layout;
866 GtkCellRenderer *renderer;
869 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
870 cell_layout = GTK_CELL_LAYOUT (combo);
872 /* Create the model */
873 store = gtk_list_store_new (COL_VARIANT_COUNT,
874 G_TYPE_STRING, /* name */
875 G_TYPE_BOOLEAN); /* is default */
876 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
877 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
879 /* Add cell renderer */
880 renderer = gtk_cell_renderer_text_new ();
881 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
882 gtk_cell_layout_set_attributes (cell_layout, renderer,
883 "text", COL_VARIANT_NAME, NULL);
885 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
886 g_object_unref (store);
888 g_signal_connect (combo, "changed",
889 G_CALLBACK (preferences_theme_variant_changed_cb),
892 /* Track changes of the GSetting key */
893 g_signal_connect (priv->gsettings_chat,
894 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
895 G_CALLBACK (preferences_theme_variant_notify_cb),
900 preferences_theme_changed_cb (GtkComboBox *combo,
901 EmpathyPreferences *preferences)
903 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
906 if (gtk_combo_box_get_active_iter (combo, &iter)) {
913 model = gtk_combo_box_get_model (combo);
914 gtk_tree_model_get (model, &iter,
915 COL_THEME_IS_ADIUM, &is_adium,
916 COL_THEME_NAME, &name,
917 COL_THEME_ADIUM_PATH, &path,
918 COL_THEME_ADIUM_INFO, &info,
921 g_settings_set_string (priv->gsettings_chat,
922 EMPATHY_PREFS_CHAT_THEME,
925 g_settings_set_string (priv->gsettings_chat,
926 EMPATHY_PREFS_CHAT_ADIUM_PATH,
928 preferences_theme_variants_fill (preferences, info);
929 gtk_widget_show (priv->hbox_chat_theme_variant);
931 gtk_widget_hide (priv->hbox_chat_theme_variant);
935 tp_clear_pointer (&info, g_hash_table_unref);
940 preferences_theme_notify_cb (GSettings *gsettings,
944 EmpathyPreferences *preferences = user_data;
945 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
951 gboolean found = FALSE;
954 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
955 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
957 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
958 model = gtk_combo_box_get_model (combo);
959 for (ok = gtk_tree_model_get_iter_first (model, &iter);
961 ok = gtk_tree_model_iter_next (model, &iter)) {
966 gtk_tree_model_get (model, &iter,
967 COL_THEME_IS_ADIUM, &is_adium,
968 COL_THEME_NAME, &name,
969 COL_THEME_ADIUM_PATH, &path,
972 if (!tp_strdiff (name, conf_name) &&
973 (!is_adium || !tp_strdiff (path, conf_path))) {
975 gtk_combo_box_set_active_iter (combo, &iter);
982 /* Fallback to the first one. */
984 if (gtk_tree_model_get_iter_first (model, &iter)) {
985 gtk_combo_box_set_active_iter (combo, &iter);
994 preferences_themes_setup (EmpathyPreferences *preferences)
996 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
998 GtkCellLayout *cell_layout;
999 GtkCellRenderer *renderer;
1000 GtkListStore *store;
1001 const gchar **themes;
1002 GList *adium_themes;
1005 preferences_theme_variants_setup (preferences);
1007 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1008 cell_layout = GTK_CELL_LAYOUT (combo);
1010 /* Create the model */
1011 store = gtk_list_store_new (COL_THEME_COUNT,
1012 G_TYPE_STRING, /* Display name */
1013 G_TYPE_STRING, /* Theme name */
1014 G_TYPE_BOOLEAN, /* Is an Adium theme */
1015 G_TYPE_STRING, /* Adium theme path */
1016 G_TYPE_HASH_TABLE); /* Adium theme info */
1017 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1018 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1020 /* Fill the model */
1021 themes = empathy_theme_manager_get_themes ();
1022 for (i = 0; themes[i]; i += 2) {
1023 gtk_list_store_insert_with_values (store, NULL, -1,
1024 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1025 COL_THEME_NAME, themes[i],
1026 COL_THEME_IS_ADIUM, FALSE,
1030 adium_themes = empathy_theme_manager_get_adium_themes ();
1031 while (adium_themes != NULL) {
1036 info = adium_themes->data;
1037 name = tp_asv_get_string (info, "CFBundleName");
1038 path = tp_asv_get_string (info, "path");
1040 if (name != NULL && path != NULL) {
1041 gtk_list_store_insert_with_values (store, NULL, -1,
1042 COL_THEME_VISIBLE_NAME, name,
1043 COL_THEME_NAME, "adium",
1044 COL_THEME_IS_ADIUM, TRUE,
1045 COL_THEME_ADIUM_PATH, path,
1046 COL_THEME_ADIUM_INFO, info,
1049 g_hash_table_unref (info);
1050 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1053 /* Add cell renderer */
1054 renderer = gtk_cell_renderer_text_new ();
1055 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1056 gtk_cell_layout_set_attributes (cell_layout, renderer,
1057 "text", COL_THEME_VISIBLE_NAME, NULL);
1059 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1060 g_object_unref (store);
1062 g_signal_connect (combo, "changed",
1063 G_CALLBACK (preferences_theme_changed_cb),
1066 /* Select the theme from the GSetting key and track changes */
1067 preferences_theme_notify_cb (priv->gsettings_chat,
1068 EMPATHY_PREFS_CHAT_THEME,
1070 g_signal_connect (priv->gsettings_chat,
1071 "changed::" EMPATHY_PREFS_CHAT_THEME,
1072 G_CALLBACK (preferences_theme_notify_cb),
1075 g_signal_connect (priv->gsettings_chat,
1076 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1077 G_CALLBACK (preferences_theme_notify_cb),
1082 empathy_preferences_response (GtkDialog *widget,
1085 gtk_widget_destroy (GTK_WIDGET (widget));
1089 empathy_preferences_finalize (GObject *self)
1091 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1093 g_object_unref (priv->theme_manager);
1095 g_object_unref (priv->gsettings);
1096 g_object_unref (priv->gsettings_chat);
1097 g_object_unref (priv->gsettings_loc);
1098 g_object_unref (priv->gsettings_notify);
1099 g_object_unref (priv->gsettings_sound);
1100 g_object_unref (priv->gsettings_ui);
1101 g_object_unref (priv->gsettings_logger);
1103 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1107 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1109 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1110 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1112 dialog_class->response = empathy_preferences_response;
1114 object_class->finalize = empathy_preferences_finalize;
1116 g_type_class_add_private (object_class,
1117 sizeof (EmpathyPreferencesPriv));
1121 empathy_preferences_init (EmpathyPreferences *preferences)
1123 EmpathyPreferencesPriv *priv;
1128 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1129 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1131 gtk_dialog_add_button (GTK_DIALOG (preferences),
1132 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1134 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1135 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1136 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1137 gtk_window_set_position (GTK_WINDOW (preferences),
1138 GTK_WIN_POS_CENTER_ON_PARENT);
1139 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1141 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1142 gui = empathy_builder_get_file (filename,
1143 "notebook", &priv->notebook,
1144 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1145 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1146 "vbox_chat_theme", &priv->vbox_chat_theme,
1147 "combobox_chat_theme", &priv->combobox_chat_theme,
1148 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1149 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1150 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1151 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1152 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1153 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1154 "checkbutton_logging", &priv->checkbutton_logging,
1155 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1156 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1157 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1158 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1159 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1160 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1161 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1162 "treeview_sounds", &priv->treeview_sounds,
1163 "treeview_spell_checker", &priv->treeview_spell_checker,
1164 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1165 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1166 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1167 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1168 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1172 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1173 gtk_widget_show (priv->notebook);
1175 g_object_unref (gui);
1177 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1178 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1179 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1180 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1181 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1182 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1183 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1185 /* Create chat theme preview, and track changes */
1186 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1187 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1188 G_CALLBACK (preferences_preview_theme_changed_cb),
1190 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1192 preferences_themes_setup (preferences);
1194 preferences_setup_widgets (preferences);
1196 preferences_languages_setup (preferences);
1197 preferences_languages_add (preferences);
1198 preferences_languages_load (preferences);
1200 preferences_sound_setup (preferences);
1201 preferences_sound_load (preferences);
1203 if (empathy_spell_supported ()) {
1204 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 2);
1205 gtk_widget_show (page);
1208 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 3);
1210 gtk_widget_show (page);
1212 gtk_widget_hide (page);
1217 empathy_preferences_new (GtkWindow *parent)
1221 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1223 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1225 if (parent != NULL) {
1226 gtk_window_set_transient_for (GTK_WINDOW (self),