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 *adj_call_volume;
80 GtkWidget *treeview_spell_checker;
82 GtkWidget *checkbutton_location_publish;
83 GtkWidget *checkbutton_location_reduce_accuracy;
84 GtkWidget *checkbutton_location_resource_network;
85 GtkWidget *checkbutton_location_resource_cell;
86 GtkWidget *checkbutton_location_resource_gps;
88 GtkWidget *vbox_chat_theme;
89 GtkWidget *combobox_chat_theme;
90 GtkWidget *combobox_chat_theme_variant;
91 GtkWidget *hbox_chat_theme_variant;
92 GtkWidget *sw_chat_theme_preview;
93 EmpathyChatView *chat_theme_preview;
94 EmpathyThemeManager *theme_manager;
97 GSettings *gsettings_chat;
98 GSettings *gsettings_call;
99 GSettings *gsettings_loc;
100 GSettings *gsettings_notify;
101 GSettings *gsettings_sound;
102 GSettings *gsettings_ui;
103 GSettings *gsettings_logger;
106 static void preferences_setup_widgets (EmpathyPreferences *preferences);
107 static void preferences_languages_setup (EmpathyPreferences *preferences);
108 static void preferences_languages_add (EmpathyPreferences *preferences);
109 static void preferences_languages_save (EmpathyPreferences *preferences);
110 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
114 static void preferences_languages_load (EmpathyPreferences *preferences);
115 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
119 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
121 EmpathyPreferences *preferences);
131 COL_THEME_VISIBLE_NAME,
134 COL_THEME_ADIUM_PATH,
135 COL_THEME_ADIUM_INFO,
157 /* TODO: add phone related sounds also? */
158 static SoundEventEntry sound_entries [] = {
159 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
160 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
161 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
162 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
163 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
164 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
165 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
169 preferences_setup_widgets (EmpathyPreferences *preferences)
171 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
173 g_settings_bind (priv->gsettings_notify,
174 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
175 priv->checkbutton_notifications_enabled,
177 G_SETTINGS_BIND_DEFAULT);
178 g_settings_bind (priv->gsettings_notify,
179 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
180 priv->checkbutton_notifications_disabled_away,
182 G_SETTINGS_BIND_DEFAULT);
183 g_settings_bind (priv->gsettings_notify,
184 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
185 priv->checkbutton_notifications_focus,
187 G_SETTINGS_BIND_DEFAULT);
188 g_settings_bind (priv->gsettings_notify,
189 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
190 priv->checkbutton_notifications_contact_signin,
192 G_SETTINGS_BIND_DEFAULT);
193 g_settings_bind (priv->gsettings_notify,
194 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
195 priv->checkbutton_notifications_contact_signout,
197 G_SETTINGS_BIND_DEFAULT);
199 g_settings_bind (priv->gsettings_notify,
200 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
201 priv->checkbutton_notifications_disabled_away,
203 G_SETTINGS_BIND_GET);
204 g_settings_bind (priv->gsettings_notify,
205 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
206 priv->checkbutton_notifications_focus,
208 G_SETTINGS_BIND_GET);
209 g_settings_bind (priv->gsettings_notify,
210 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
211 priv->checkbutton_notifications_contact_signin,
213 G_SETTINGS_BIND_GET);
214 g_settings_bind (priv->gsettings_notify,
215 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
216 priv->checkbutton_notifications_contact_signout,
218 G_SETTINGS_BIND_GET);
220 g_settings_bind (priv->gsettings_sound,
221 EMPATHY_PREFS_SOUNDS_ENABLED,
222 priv->checkbutton_sounds_enabled,
224 G_SETTINGS_BIND_DEFAULT);
225 g_settings_bind (priv->gsettings_sound,
226 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
227 priv->checkbutton_sounds_disabled_away,
229 G_SETTINGS_BIND_DEFAULT);
231 g_settings_bind (priv->gsettings_sound,
232 EMPATHY_PREFS_SOUNDS_ENABLED,
233 priv->checkbutton_sounds_disabled_away,
235 G_SETTINGS_BIND_GET);
236 g_settings_bind (priv->gsettings_sound,
237 EMPATHY_PREFS_SOUNDS_ENABLED,
238 priv->treeview_sounds,
240 G_SETTINGS_BIND_GET);
242 g_settings_bind (priv->gsettings_ui,
243 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
244 priv->checkbutton_separate_chat_windows,
246 G_SETTINGS_BIND_DEFAULT);
248 g_settings_bind (priv->gsettings_ui,
249 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
250 priv->checkbutton_events_notif_area,
252 G_SETTINGS_BIND_DEFAULT);
254 g_settings_bind (priv->gsettings_chat,
255 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
256 priv->checkbutton_show_smileys,
258 G_SETTINGS_BIND_DEFAULT);
259 g_settings_bind (priv->gsettings_chat,
260 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
261 priv->checkbutton_show_contacts_in_rooms,
263 G_SETTINGS_BIND_DEFAULT);
265 g_settings_bind (priv->gsettings_call,
266 EMPATHY_PREFS_CALL_SOUND_VOLUME,
267 priv->adj_call_volume,
269 G_SETTINGS_BIND_DEFAULT);
271 g_settings_bind (priv->gsettings,
272 EMPATHY_PREFS_AUTOCONNECT,
273 priv->checkbutton_autoconnect,
275 G_SETTINGS_BIND_DEFAULT);
277 g_settings_bind (priv->gsettings_loc,
278 EMPATHY_PREFS_LOCATION_PUBLISH,
279 priv->checkbutton_location_publish,
281 G_SETTINGS_BIND_DEFAULT);
283 g_settings_bind (priv->gsettings_loc,
284 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
285 priv->checkbutton_location_resource_network,
287 G_SETTINGS_BIND_DEFAULT);
288 g_settings_bind (priv->gsettings_loc,
289 EMPATHY_PREFS_LOCATION_PUBLISH,
290 priv->checkbutton_location_resource_network,
292 G_SETTINGS_BIND_GET);
294 g_settings_bind (priv->gsettings_loc,
295 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
296 priv->checkbutton_location_resource_cell,
298 G_SETTINGS_BIND_DEFAULT);
299 g_settings_bind (priv->gsettings_loc,
300 EMPATHY_PREFS_LOCATION_PUBLISH,
301 priv->checkbutton_location_resource_cell,
303 G_SETTINGS_BIND_GET);
305 g_settings_bind (priv->gsettings_loc,
306 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
307 priv->checkbutton_location_resource_gps,
309 G_SETTINGS_BIND_DEFAULT);
310 g_settings_bind (priv->gsettings_loc,
311 EMPATHY_PREFS_LOCATION_PUBLISH,
312 priv->checkbutton_location_resource_gps,
314 G_SETTINGS_BIND_GET);
316 g_settings_bind (priv->gsettings_loc,
317 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
318 priv->checkbutton_location_reduce_accuracy,
320 G_SETTINGS_BIND_DEFAULT);
321 g_settings_bind (priv->gsettings_loc,
322 EMPATHY_PREFS_LOCATION_PUBLISH,
323 priv->checkbutton_location_reduce_accuracy,
325 G_SETTINGS_BIND_GET);
327 g_settings_bind (priv->gsettings_logger,
328 EMPATHY_PREFS_LOGGER_ENABLED,
329 priv->checkbutton_logging,
331 G_SETTINGS_BIND_DEFAULT);
335 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
337 EmpathyPreferences *preferences)
339 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
347 view = GTK_TREE_VIEW (priv->treeview_sounds);
348 model = gtk_tree_view_get_model (view);
350 path = gtk_tree_path_new_from_string (path_string);
352 gtk_tree_model_get_iter (model, &iter, path);
353 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
354 COL_SOUND_ENABLED, &instore, -1);
358 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
359 COL_SOUND_ENABLED, instore, -1);
361 g_settings_set_boolean (priv->gsettings_sound, key, instore);
364 gtk_tree_path_free (path);
368 preferences_sound_load (EmpathyPreferences *preferences)
370 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
377 view = GTK_TREE_VIEW (priv->treeview_sounds);
378 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
380 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
381 set = g_settings_get_boolean (priv->gsettings_sound,
382 sound_entries[i].key);
384 gtk_list_store_insert_with_values (store, &iter, i,
385 COL_SOUND_NAME, gettext (sound_entries[i].name),
386 COL_SOUND_KEY, sound_entries[i].key,
387 COL_SOUND_ENABLED, set, -1);
392 preferences_sound_setup (EmpathyPreferences *preferences)
394 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
397 GtkCellRenderer *renderer;
398 GtkTreeViewColumn *column;
400 view = GTK_TREE_VIEW (priv->treeview_sounds);
402 store = gtk_list_store_new (COL_SOUND_COUNT,
403 G_TYPE_BOOLEAN, /* enabled */
404 G_TYPE_STRING, /* name */
405 G_TYPE_STRING); /* key */
407 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
409 renderer = gtk_cell_renderer_toggle_new ();
410 g_signal_connect (renderer, "toggled",
411 G_CALLBACK (preferences_sound_cell_toggled_cb),
414 column = gtk_tree_view_column_new ();
415 gtk_tree_view_column_pack_start (column, renderer, FALSE);
416 gtk_tree_view_column_add_attribute (column, renderer,
417 "active", COL_SOUND_ENABLED);
419 renderer = gtk_cell_renderer_text_new ();
420 gtk_tree_view_column_pack_start (column, renderer, FALSE);
421 gtk_tree_view_column_add_attribute (column, renderer,
422 "text", COL_SOUND_NAME);
424 gtk_tree_view_append_column (view, column);
426 gtk_tree_view_column_set_resizable (column, FALSE);
427 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
429 g_object_unref (store);
433 preferences_languages_setup (EmpathyPreferences *preferences)
435 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
438 GtkTreeSelection *selection;
439 GtkTreeViewColumn *column;
440 GtkCellRenderer *renderer;
443 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
445 store = gtk_list_store_new (COL_LANG_COUNT,
446 G_TYPE_BOOLEAN, /* enabled */
447 G_TYPE_STRING, /* code */
448 G_TYPE_STRING); /* name */
450 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
452 selection = gtk_tree_view_get_selection (view);
453 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
455 renderer = gtk_cell_renderer_toggle_new ();
456 g_signal_connect (renderer, "toggled",
457 G_CALLBACK (preferences_languages_cell_toggled_cb),
460 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
461 "active", COL_LANG_ENABLED,
464 gtk_tree_view_append_column (view, column);
466 renderer = gtk_cell_renderer_text_new ();
467 col_offset = gtk_tree_view_insert_column_with_attributes (view,
470 "text", COL_LANG_NAME,
473 g_object_set_data (G_OBJECT (renderer),
474 "column", GINT_TO_POINTER (COL_LANG_NAME));
476 column = gtk_tree_view_get_column (view, col_offset - 1);
477 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
478 gtk_tree_view_column_set_resizable (column, FALSE);
479 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
481 g_object_unref (store);
485 preferences_languages_add (EmpathyPreferences *preferences)
487 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
492 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
493 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
495 codes = empathy_spell_get_language_codes ();
498 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
501 for (l = codes; l; l = l->next) {
507 name = empathy_spell_get_language_name (code);
512 gtk_list_store_append (store, &iter);
513 gtk_list_store_set (store, &iter,
519 empathy_spell_free_language_codes (codes);
523 preferences_languages_save (EmpathyPreferences *preferences)
525 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
529 gchar *languages = NULL;
531 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
532 model = gtk_tree_view_get_model (view);
534 gtk_tree_model_foreach (model,
535 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
538 /* if user selects no languages, we don't want spell check */
539 g_settings_set_boolean (priv->gsettings_chat,
540 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
543 g_settings_set_string (priv->gsettings_chat,
544 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
545 languages != NULL ? languages : "");
551 preferences_languages_save_foreach (GtkTreeModel *model,
563 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
568 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
574 *languages = g_strdup (code);
576 gchar *str = *languages;
577 *languages = g_strdup_printf ("%s,%s", str, code);
587 preferences_languages_load (EmpathyPreferences *preferences)
589 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
592 GList *enabled_codes;
594 enabled_codes = empathy_spell_get_enabled_language_codes ();
596 g_settings_set_boolean (priv->gsettings_chat,
597 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
598 enabled_codes != NULL);
600 if (enabled_codes == NULL)
603 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
604 model = gtk_tree_view_get_model (view);
606 gtk_tree_model_foreach (model,
607 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
610 g_list_free (enabled_codes);
614 preferences_languages_load_foreach (GtkTreeModel *model,
620 gboolean found = FALSE;
626 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
631 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
636 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
641 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
643 EmpathyPreferences *preferences)
645 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
653 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
654 model = gtk_tree_view_get_model (view);
655 store = GTK_LIST_STORE (model);
657 path = gtk_tree_path_new_from_string (path_string);
659 gtk_tree_model_get_iter (model, &iter, path);
660 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
664 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
665 gtk_tree_path_free (path);
667 preferences_languages_save (preferences);
671 preferences_preview_theme_append_message (EmpathyChatView *view,
672 EmpathyContact *sender,
673 EmpathyContact *receiver,
676 EmpathyMessage *message;
678 message = g_object_new (EMPATHY_TYPE_MESSAGE,
680 "receiver", receiver,
684 empathy_chat_view_append_message (view, message);
685 g_object_unref (message);
689 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
690 EmpathyPreferences *preferences)
692 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
695 EmpathyContact *juliet;
696 EmpathyContact *romeo;
698 DEBUG ("Theme changed, update preview widget");
700 if (priv->chat_theme_preview != NULL) {
701 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
703 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
704 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
705 GTK_WIDGET (priv->chat_theme_preview));
706 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
708 /* FIXME: It is ugly to add a fake conversation like that.
709 * Would be cool if we could request a TplLogManager for a fake
711 dbus = tp_dbus_daemon_dup (NULL);
712 account = tp_account_new (dbus,
713 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
714 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
717 /* translators: Contact name for the chat theme preview */
718 "alias", _("Juliet"),
721 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
724 /* translators: Contact name for the chat theme preview */
729 preferences_preview_theme_append_message (priv->chat_theme_preview,
730 /* translators: Quote from Romeo & Julier, for chat theme preview */
731 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
732 preferences_preview_theme_append_message (priv->chat_theme_preview,
733 /* translators: Quote from Romeo & Julier, for chat theme preview */
734 juliet, romeo, _("Deny thy father and refuse thy name;"));
735 preferences_preview_theme_append_message (priv->chat_theme_preview,
736 /* translators: Quote from Romeo & Julier, for chat theme preview */
737 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
738 preferences_preview_theme_append_message (priv->chat_theme_preview,
739 /* translators: Quote from Romeo & Julier, for chat theme preview */
740 juliet, romeo, _("And I'll no longer be a Capulet."));
741 preferences_preview_theme_append_message (priv->chat_theme_preview,
742 /* translators: Quote from Romeo & Julier, for chat theme preview */
743 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
745 /* translators: Quote from Romeo & Julier, for chat theme preview */
746 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
748 g_object_unref (juliet);
749 g_object_unref (romeo);
750 g_object_unref (account);
751 g_object_unref (dbus);
755 preferences_theme_variant_changed_cb (GtkComboBox *combo,
756 EmpathyPreferences *preferences)
758 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
761 if (gtk_combo_box_get_active_iter (combo, &iter)) {
765 model = gtk_combo_box_get_model (combo);
766 gtk_tree_model_get (model, &iter,
767 COL_VARIANT_NAME, &name,
770 g_settings_set_string (priv->gsettings_chat,
771 EMPATHY_PREFS_CHAT_THEME_VARIANT,
779 preferences_theme_variant_notify_cb (GSettings *gsettings,
783 EmpathyPreferences *preferences = user_data;
784 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
789 GtkTreeIter default_iter;
790 gboolean found_default = FALSE;
791 gboolean found = FALSE;
794 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
795 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
796 model = gtk_combo_box_get_model (combo);
798 for (ok = gtk_tree_model_get_iter_first (model, &iter);
800 ok = gtk_tree_model_iter_next (model, &iter)) {
804 gtk_tree_model_get (model, &iter,
805 COL_VARIANT_NAME, &name,
806 COL_VARIANT_DEFAULT, &is_default,
809 if (!tp_strdiff (name, conf_name)) {
811 gtk_combo_box_set_active_iter (combo, &iter);
814 found_default = TRUE;
821 /* Fallback to the first one. */
824 gtk_combo_box_set_active_iter (combo, &default_iter);
825 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
826 gtk_combo_box_set_active_iter (combo, &iter);
834 preferences_theme_variants_fill (EmpathyPreferences *preferences,
837 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
842 const gchar *default_variant;
844 #endif /* HAVE_WEBKIT */
846 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
847 store = GTK_LIST_STORE (model);
848 gtk_list_store_clear (store);
851 variants = empathy_adium_info_get_available_variants (info);
852 default_variant = empathy_adium_info_get_default_variant (info);
853 for (i = 0; i < variants->len; i++) {
854 gchar *name = g_ptr_array_index (variants, i);
856 gtk_list_store_insert_with_values (store, NULL, -1,
857 COL_VARIANT_NAME, name,
858 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
861 #endif /* HAVE_WEBKIT */
863 /* Select the variant from the GSetting key */
864 preferences_theme_variant_notify_cb (priv->gsettings_chat,
865 EMPATHY_PREFS_CHAT_THEME_VARIANT,
870 preferences_theme_variants_setup (EmpathyPreferences *preferences)
872 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
874 GtkCellLayout *cell_layout;
875 GtkCellRenderer *renderer;
878 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
879 cell_layout = GTK_CELL_LAYOUT (combo);
881 /* Create the model */
882 store = gtk_list_store_new (COL_VARIANT_COUNT,
883 G_TYPE_STRING, /* name */
884 G_TYPE_BOOLEAN); /* is default */
885 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
886 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
888 /* Add cell renderer */
889 renderer = gtk_cell_renderer_text_new ();
890 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
891 gtk_cell_layout_set_attributes (cell_layout, renderer,
892 "text", COL_VARIANT_NAME, NULL);
894 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
895 g_object_unref (store);
897 g_signal_connect (combo, "changed",
898 G_CALLBACK (preferences_theme_variant_changed_cb),
901 /* Track changes of the GSetting key */
902 g_signal_connect (priv->gsettings_chat,
903 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
904 G_CALLBACK (preferences_theme_variant_notify_cb),
909 preferences_theme_changed_cb (GtkComboBox *combo,
910 EmpathyPreferences *preferences)
912 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
915 if (gtk_combo_box_get_active_iter (combo, &iter)) {
922 model = gtk_combo_box_get_model (combo);
923 gtk_tree_model_get (model, &iter,
924 COL_THEME_IS_ADIUM, &is_adium,
925 COL_THEME_NAME, &name,
926 COL_THEME_ADIUM_PATH, &path,
927 COL_THEME_ADIUM_INFO, &info,
930 g_settings_set_string (priv->gsettings_chat,
931 EMPATHY_PREFS_CHAT_THEME,
934 g_settings_set_string (priv->gsettings_chat,
935 EMPATHY_PREFS_CHAT_ADIUM_PATH,
937 preferences_theme_variants_fill (preferences, info);
938 gtk_widget_show (priv->hbox_chat_theme_variant);
940 gtk_widget_hide (priv->hbox_chat_theme_variant);
944 tp_clear_pointer (&info, g_hash_table_unref);
949 preferences_theme_notify_cb (GSettings *gsettings,
953 EmpathyPreferences *preferences = user_data;
954 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
960 gboolean found = FALSE;
963 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
964 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
966 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
967 model = gtk_combo_box_get_model (combo);
968 for (ok = gtk_tree_model_get_iter_first (model, &iter);
970 ok = gtk_tree_model_iter_next (model, &iter)) {
975 gtk_tree_model_get (model, &iter,
976 COL_THEME_IS_ADIUM, &is_adium,
977 COL_THEME_NAME, &name,
978 COL_THEME_ADIUM_PATH, &path,
981 if (!tp_strdiff (name, conf_name) &&
982 (!is_adium || !tp_strdiff (path, conf_path))) {
984 gtk_combo_box_set_active_iter (combo, &iter);
991 /* Fallback to the first one. */
993 if (gtk_tree_model_get_iter_first (model, &iter)) {
994 gtk_combo_box_set_active_iter (combo, &iter);
1003 preferences_themes_setup (EmpathyPreferences *preferences)
1005 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
1007 GtkCellLayout *cell_layout;
1008 GtkCellRenderer *renderer;
1009 GtkListStore *store;
1010 const gchar **themes;
1011 GList *adium_themes;
1014 preferences_theme_variants_setup (preferences);
1016 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1017 cell_layout = GTK_CELL_LAYOUT (combo);
1019 /* Create the model */
1020 store = gtk_list_store_new (COL_THEME_COUNT,
1021 G_TYPE_STRING, /* Display name */
1022 G_TYPE_STRING, /* Theme name */
1023 G_TYPE_BOOLEAN, /* Is an Adium theme */
1024 G_TYPE_STRING, /* Adium theme path */
1025 G_TYPE_HASH_TABLE); /* Adium theme info */
1026 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1027 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1029 /* Fill the model */
1030 themes = empathy_theme_manager_get_themes ();
1031 for (i = 0; themes[i]; i += 2) {
1032 gtk_list_store_insert_with_values (store, NULL, -1,
1033 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1034 COL_THEME_NAME, themes[i],
1035 COL_THEME_IS_ADIUM, FALSE,
1039 adium_themes = empathy_theme_manager_get_adium_themes ();
1040 while (adium_themes != NULL) {
1045 info = adium_themes->data;
1046 name = tp_asv_get_string (info, "CFBundleName");
1047 path = tp_asv_get_string (info, "path");
1049 if (name != NULL && path != NULL) {
1050 gtk_list_store_insert_with_values (store, NULL, -1,
1051 COL_THEME_VISIBLE_NAME, name,
1052 COL_THEME_NAME, "adium",
1053 COL_THEME_IS_ADIUM, TRUE,
1054 COL_THEME_ADIUM_PATH, path,
1055 COL_THEME_ADIUM_INFO, info,
1058 g_hash_table_unref (info);
1059 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1062 /* Add cell renderer */
1063 renderer = gtk_cell_renderer_text_new ();
1064 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1065 gtk_cell_layout_set_attributes (cell_layout, renderer,
1066 "text", COL_THEME_VISIBLE_NAME, NULL);
1068 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1069 g_object_unref (store);
1071 g_signal_connect (combo, "changed",
1072 G_CALLBACK (preferences_theme_changed_cb),
1075 /* Select the theme from the GSetting key and track changes */
1076 preferences_theme_notify_cb (priv->gsettings_chat,
1077 EMPATHY_PREFS_CHAT_THEME,
1079 g_signal_connect (priv->gsettings_chat,
1080 "changed::" EMPATHY_PREFS_CHAT_THEME,
1081 G_CALLBACK (preferences_theme_notify_cb),
1084 g_signal_connect (priv->gsettings_chat,
1085 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1086 G_CALLBACK (preferences_theme_notify_cb),
1091 empathy_preferences_response (GtkDialog *widget,
1094 gtk_widget_destroy (GTK_WIDGET (widget));
1098 empathy_preferences_finalize (GObject *self)
1100 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1102 g_object_unref (priv->theme_manager);
1104 g_object_unref (priv->gsettings);
1105 g_object_unref (priv->gsettings_chat);
1106 g_object_unref (priv->gsettings_call);
1107 g_object_unref (priv->gsettings_loc);
1108 g_object_unref (priv->gsettings_notify);
1109 g_object_unref (priv->gsettings_sound);
1110 g_object_unref (priv->gsettings_ui);
1111 g_object_unref (priv->gsettings_logger);
1113 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1117 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1119 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1120 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1122 dialog_class->response = empathy_preferences_response;
1124 object_class->finalize = empathy_preferences_finalize;
1126 g_type_class_add_private (object_class,
1127 sizeof (EmpathyPreferencesPriv));
1131 empathy_preferences_init (EmpathyPreferences *preferences)
1133 EmpathyPreferencesPriv *priv;
1138 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1139 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1141 gtk_dialog_add_button (GTK_DIALOG (preferences),
1142 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1144 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1145 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1146 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1147 gtk_window_set_position (GTK_WINDOW (preferences),
1148 GTK_WIN_POS_CENTER_ON_PARENT);
1149 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1151 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1152 gui = empathy_builder_get_file (filename,
1153 "notebook", &priv->notebook,
1154 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1155 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1156 "vbox_chat_theme", &priv->vbox_chat_theme,
1157 "combobox_chat_theme", &priv->combobox_chat_theme,
1158 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1159 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1160 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1161 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1162 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1163 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1164 "checkbutton_logging", &priv->checkbutton_logging,
1165 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1166 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1167 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1168 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1169 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1170 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1171 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1172 "treeview_sounds", &priv->treeview_sounds,
1173 "treeview_spell_checker", &priv->treeview_spell_checker,
1174 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1175 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1176 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1177 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1178 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1179 "call_volume_adjustment", &priv->adj_call_volume,
1183 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1184 gtk_widget_show (priv->notebook);
1186 g_object_unref (gui);
1188 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1189 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1190 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1191 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1192 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1193 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1194 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1195 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1197 /* Create chat theme preview, and track changes */
1198 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1199 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1200 G_CALLBACK (preferences_preview_theme_changed_cb),
1202 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1204 preferences_themes_setup (preferences);
1206 preferences_setup_widgets (preferences);
1208 preferences_languages_setup (preferences);
1209 preferences_languages_add (preferences);
1210 preferences_languages_load (preferences);
1212 preferences_sound_setup (preferences);
1213 preferences_sound_load (preferences);
1215 if (empathy_spell_supported ()) {
1216 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 2);
1217 gtk_widget_show (page);
1220 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 3);
1222 gtk_widget_show (page);
1224 gtk_widget_hide (page);
1229 empathy_preferences_new (GtkWindow *parent)
1233 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1235 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1237 if (parent != NULL) {
1238 gtk_window_set_transient_for (GTK_WINDOW (self),