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>
44 #include <libempathy-gtk/empathy-theme-adium.h>
46 #include "empathy-preferences.h"
48 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
49 #include <libempathy/empathy-debug.h>
51 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
53 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
55 static const gchar * empathy_preferences_tabs[] =
66 struct _EmpathyPreferencesPriv {
69 GtkWidget *checkbutton_show_smileys;
70 GtkWidget *checkbutton_show_contacts_in_rooms;
71 GtkWidget *checkbutton_separate_chat_windows;
72 GtkWidget *checkbutton_events_notif_area;
73 GtkWidget *checkbutton_autoconnect;
74 GtkWidget *checkbutton_logging;
76 GtkWidget *checkbutton_sounds_enabled;
77 GtkWidget *checkbutton_sounds_disabled_away;
78 GtkWidget *treeview_sounds;
80 GtkWidget *checkbutton_notifications_enabled;
81 GtkWidget *checkbutton_notifications_disabled_away;
82 GtkWidget *checkbutton_notifications_focus;
83 GtkWidget *checkbutton_notifications_contact_signin;
84 GtkWidget *checkbutton_notifications_contact_signout;
86 GtkWidget *scale_call_volume;
87 GtkWidget *adj_call_volume;
88 GtkWidget *echo_cancellation;
90 GtkWidget *treeview_spell_checker;
92 GtkWidget *checkbutton_location_publish;
93 GtkWidget *checkbutton_location_reduce_accuracy;
94 GtkWidget *checkbutton_location_resource_network;
95 GtkWidget *checkbutton_location_resource_cell;
96 GtkWidget *checkbutton_location_resource_gps;
98 GtkWidget *vbox_chat_theme;
99 GtkWidget *combobox_chat_theme;
100 GtkWidget *combobox_chat_theme_variant;
101 GtkWidget *hbox_chat_theme_variant;
102 GtkWidget *sw_chat_theme_preview;
103 EmpathyChatView *chat_theme_preview;
104 EmpathyThemeManager *theme_manager;
106 GSettings *gsettings;
107 GSettings *gsettings_chat;
108 GSettings *gsettings_call;
109 GSettings *gsettings_loc;
110 GSettings *gsettings_notify;
111 GSettings *gsettings_sound;
112 GSettings *gsettings_ui;
113 GSettings *gsettings_logger;
116 static void preferences_setup_widgets (EmpathyPreferences *preferences);
117 static void preferences_languages_setup (EmpathyPreferences *preferences);
118 static void preferences_languages_add (EmpathyPreferences *preferences);
119 static void preferences_languages_save (EmpathyPreferences *preferences);
120 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
124 static void preferences_languages_load (EmpathyPreferences *preferences);
125 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
129 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
131 EmpathyPreferences *preferences);
141 COL_THEME_VISIBLE_NAME,
144 COL_THEME_ADIUM_PATH,
145 COL_THEME_ADIUM_INFO,
167 /* TODO: add phone related sounds also? */
168 static SoundEventEntry sound_entries [] = {
169 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
170 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
171 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
172 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
173 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
174 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
175 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
179 preferences_setup_widgets (EmpathyPreferences *preferences)
181 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
183 g_settings_bind (priv->gsettings_notify,
184 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
185 priv->checkbutton_notifications_enabled,
187 G_SETTINGS_BIND_DEFAULT);
188 g_settings_bind (priv->gsettings_notify,
189 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
190 priv->checkbutton_notifications_disabled_away,
192 G_SETTINGS_BIND_DEFAULT);
193 g_settings_bind (priv->gsettings_notify,
194 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
195 priv->checkbutton_notifications_focus,
197 G_SETTINGS_BIND_DEFAULT);
198 g_settings_bind (priv->gsettings_notify,
199 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
200 priv->checkbutton_notifications_contact_signin,
202 G_SETTINGS_BIND_DEFAULT);
203 g_settings_bind (priv->gsettings_notify,
204 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
205 priv->checkbutton_notifications_contact_signout,
207 G_SETTINGS_BIND_DEFAULT);
209 g_settings_bind (priv->gsettings_notify,
210 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
211 priv->checkbutton_notifications_disabled_away,
213 G_SETTINGS_BIND_GET);
214 g_settings_bind (priv->gsettings_notify,
215 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
216 priv->checkbutton_notifications_focus,
218 G_SETTINGS_BIND_GET);
219 g_settings_bind (priv->gsettings_notify,
220 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
221 priv->checkbutton_notifications_contact_signin,
223 G_SETTINGS_BIND_GET);
224 g_settings_bind (priv->gsettings_notify,
225 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
226 priv->checkbutton_notifications_contact_signout,
228 G_SETTINGS_BIND_GET);
230 g_settings_bind (priv->gsettings_sound,
231 EMPATHY_PREFS_SOUNDS_ENABLED,
232 priv->checkbutton_sounds_enabled,
234 G_SETTINGS_BIND_DEFAULT);
235 g_settings_bind (priv->gsettings_sound,
236 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
237 priv->checkbutton_sounds_disabled_away,
239 G_SETTINGS_BIND_DEFAULT);
241 g_settings_bind (priv->gsettings_sound,
242 EMPATHY_PREFS_SOUNDS_ENABLED,
243 priv->checkbutton_sounds_disabled_away,
245 G_SETTINGS_BIND_GET);
246 g_settings_bind (priv->gsettings_sound,
247 EMPATHY_PREFS_SOUNDS_ENABLED,
248 priv->treeview_sounds,
250 G_SETTINGS_BIND_GET);
252 g_settings_bind (priv->gsettings_ui,
253 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
254 priv->checkbutton_separate_chat_windows,
256 G_SETTINGS_BIND_DEFAULT);
258 g_settings_bind (priv->gsettings_ui,
259 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
260 priv->checkbutton_events_notif_area,
262 G_SETTINGS_BIND_DEFAULT);
264 g_settings_bind (priv->gsettings_chat,
265 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
266 priv->checkbutton_show_smileys,
268 G_SETTINGS_BIND_DEFAULT);
269 g_settings_bind (priv->gsettings_chat,
270 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
271 priv->checkbutton_show_contacts_in_rooms,
273 G_SETTINGS_BIND_DEFAULT);
275 g_settings_bind (priv->gsettings_call,
276 EMPATHY_PREFS_CALL_SOUND_VOLUME,
277 priv->adj_call_volume,
279 G_SETTINGS_BIND_DEFAULT);
281 g_settings_bind (priv->gsettings_call,
282 EMPATHY_PREFS_CALL_ECHO_CANCELLATION,
283 priv->echo_cancellation,
285 G_SETTINGS_BIND_DEFAULT);
287 g_settings_bind (priv->gsettings,
288 EMPATHY_PREFS_AUTOCONNECT,
289 priv->checkbutton_autoconnect,
291 G_SETTINGS_BIND_DEFAULT);
293 g_settings_bind (priv->gsettings_loc,
294 EMPATHY_PREFS_LOCATION_PUBLISH,
295 priv->checkbutton_location_publish,
297 G_SETTINGS_BIND_DEFAULT);
299 g_settings_bind (priv->gsettings_loc,
300 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
301 priv->checkbutton_location_resource_network,
303 G_SETTINGS_BIND_DEFAULT);
304 g_settings_bind (priv->gsettings_loc,
305 EMPATHY_PREFS_LOCATION_PUBLISH,
306 priv->checkbutton_location_resource_network,
308 G_SETTINGS_BIND_GET);
310 g_settings_bind (priv->gsettings_loc,
311 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
312 priv->checkbutton_location_resource_cell,
314 G_SETTINGS_BIND_DEFAULT);
315 g_settings_bind (priv->gsettings_loc,
316 EMPATHY_PREFS_LOCATION_PUBLISH,
317 priv->checkbutton_location_resource_cell,
319 G_SETTINGS_BIND_GET);
321 g_settings_bind (priv->gsettings_loc,
322 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
323 priv->checkbutton_location_resource_gps,
325 G_SETTINGS_BIND_DEFAULT);
326 g_settings_bind (priv->gsettings_loc,
327 EMPATHY_PREFS_LOCATION_PUBLISH,
328 priv->checkbutton_location_resource_gps,
330 G_SETTINGS_BIND_GET);
332 g_settings_bind (priv->gsettings_loc,
333 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
334 priv->checkbutton_location_reduce_accuracy,
336 G_SETTINGS_BIND_DEFAULT);
337 g_settings_bind (priv->gsettings_loc,
338 EMPATHY_PREFS_LOCATION_PUBLISH,
339 priv->checkbutton_location_reduce_accuracy,
341 G_SETTINGS_BIND_GET);
343 g_settings_bind (priv->gsettings_logger,
344 EMPATHY_PREFS_LOGGER_ENABLED,
345 priv->checkbutton_logging,
347 G_SETTINGS_BIND_DEFAULT);
351 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
353 EmpathyPreferences *preferences)
355 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
363 view = GTK_TREE_VIEW (priv->treeview_sounds);
364 model = gtk_tree_view_get_model (view);
366 path = gtk_tree_path_new_from_string (path_string);
368 gtk_tree_model_get_iter (model, &iter, path);
369 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
370 COL_SOUND_ENABLED, &instore, -1);
374 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
375 COL_SOUND_ENABLED, instore, -1);
377 g_settings_set_boolean (priv->gsettings_sound, key, instore);
380 gtk_tree_path_free (path);
384 preferences_sound_load (EmpathyPreferences *preferences)
386 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
393 view = GTK_TREE_VIEW (priv->treeview_sounds);
394 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
396 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
397 set = g_settings_get_boolean (priv->gsettings_sound,
398 sound_entries[i].key);
400 gtk_list_store_insert_with_values (store, &iter, i,
401 COL_SOUND_NAME, gettext (sound_entries[i].name),
402 COL_SOUND_KEY, sound_entries[i].key,
403 COL_SOUND_ENABLED, set, -1);
408 preferences_sound_setup (EmpathyPreferences *preferences)
410 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
413 GtkCellRenderer *renderer;
414 GtkTreeViewColumn *column;
416 view = GTK_TREE_VIEW (priv->treeview_sounds);
418 store = gtk_list_store_new (COL_SOUND_COUNT,
419 G_TYPE_BOOLEAN, /* enabled */
420 G_TYPE_STRING, /* name */
421 G_TYPE_STRING); /* key */
423 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
425 renderer = gtk_cell_renderer_toggle_new ();
426 g_signal_connect (renderer, "toggled",
427 G_CALLBACK (preferences_sound_cell_toggled_cb),
430 column = gtk_tree_view_column_new ();
431 gtk_tree_view_column_pack_start (column, renderer, FALSE);
432 gtk_tree_view_column_add_attribute (column, renderer,
433 "active", COL_SOUND_ENABLED);
435 renderer = gtk_cell_renderer_text_new ();
436 gtk_tree_view_column_pack_start (column, renderer, FALSE);
437 gtk_tree_view_column_add_attribute (column, renderer,
438 "text", COL_SOUND_NAME);
440 gtk_tree_view_append_column (view, column);
442 gtk_tree_view_column_set_resizable (column, FALSE);
443 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
445 g_object_unref (store);
449 preferences_languages_setup (EmpathyPreferences *preferences)
451 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
454 GtkTreeSelection *selection;
455 GtkTreeViewColumn *column;
456 GtkCellRenderer *renderer;
459 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
461 store = gtk_list_store_new (COL_LANG_COUNT,
462 G_TYPE_BOOLEAN, /* enabled */
463 G_TYPE_STRING, /* code */
464 G_TYPE_STRING); /* name */
466 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
468 selection = gtk_tree_view_get_selection (view);
469 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
471 renderer = gtk_cell_renderer_toggle_new ();
472 g_signal_connect (renderer, "toggled",
473 G_CALLBACK (preferences_languages_cell_toggled_cb),
476 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
477 "active", COL_LANG_ENABLED,
480 gtk_tree_view_append_column (view, column);
482 renderer = gtk_cell_renderer_text_new ();
483 col_offset = gtk_tree_view_insert_column_with_attributes (view,
486 "text", COL_LANG_NAME,
489 g_object_set_data (G_OBJECT (renderer),
490 "column", GINT_TO_POINTER (COL_LANG_NAME));
492 column = gtk_tree_view_get_column (view, col_offset - 1);
493 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
494 gtk_tree_view_column_set_resizable (column, FALSE);
495 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
497 g_object_unref (store);
501 preferences_languages_add (EmpathyPreferences *preferences)
503 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
508 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
509 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
511 codes = empathy_spell_get_language_codes ();
514 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
517 for (l = codes; l; l = l->next) {
523 name = empathy_spell_get_language_name (code);
528 gtk_list_store_append (store, &iter);
529 gtk_list_store_set (store, &iter,
535 empathy_spell_free_language_codes (codes);
539 preferences_languages_save (EmpathyPreferences *preferences)
541 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
545 gchar *languages = NULL;
547 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
548 model = gtk_tree_view_get_model (view);
550 gtk_tree_model_foreach (model,
551 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
554 /* if user selects no languages, we don't want spell check */
555 g_settings_set_boolean (priv->gsettings_chat,
556 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
559 g_settings_set_string (priv->gsettings_chat,
560 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
561 languages != NULL ? languages : "");
567 preferences_languages_save_foreach (GtkTreeModel *model,
579 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
584 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
590 *languages = g_strdup (code);
592 gchar *str = *languages;
593 *languages = g_strdup_printf ("%s,%s", str, code);
603 preferences_languages_load (EmpathyPreferences *preferences)
605 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
608 GList *enabled_codes;
610 enabled_codes = empathy_spell_get_enabled_language_codes ();
612 g_settings_set_boolean (priv->gsettings_chat,
613 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
614 enabled_codes != NULL);
616 if (enabled_codes == NULL)
619 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
620 model = gtk_tree_view_get_model (view);
622 gtk_tree_model_foreach (model,
623 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
626 g_list_free (enabled_codes);
630 preferences_languages_load_foreach (GtkTreeModel *model,
636 gboolean found = FALSE;
642 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
647 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
652 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
657 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
659 EmpathyPreferences *preferences)
661 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
669 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
670 model = gtk_tree_view_get_model (view);
671 store = GTK_LIST_STORE (model);
673 path = gtk_tree_path_new_from_string (path_string);
675 gtk_tree_model_get_iter (model, &iter, path);
676 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
680 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
681 gtk_tree_path_free (path);
683 preferences_languages_save (preferences);
687 preferences_preview_theme_append_message (EmpathyChatView *view,
688 EmpathyContact *sender,
689 EmpathyContact *receiver,
692 EmpathyMessage *message;
694 message = g_object_new (EMPATHY_TYPE_MESSAGE,
696 "receiver", receiver,
700 empathy_chat_view_append_message (view, message);
701 g_object_unref (message);
705 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
706 EmpathyPreferences *preferences)
708 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
711 EmpathyContact *juliet;
712 EmpathyContact *romeo;
714 DEBUG ("Theme changed, update preview widget");
716 if (priv->chat_theme_preview != NULL) {
717 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
719 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
720 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
721 GTK_WIDGET (priv->chat_theme_preview));
722 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
724 /* FIXME: It is ugly to add a fake conversation like that.
725 * Would be cool if we could request a TplLogManager for a fake
727 dbus = tp_dbus_daemon_dup (NULL);
728 account = tp_account_new (dbus,
729 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
730 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
733 /* translators: Contact name for the chat theme preview */
734 "alias", _("Juliet"),
737 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
740 /* translators: Contact name for the chat theme preview */
745 preferences_preview_theme_append_message (priv->chat_theme_preview,
746 /* translators: Quote from Romeo & Julier, for chat theme preview */
747 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
748 preferences_preview_theme_append_message (priv->chat_theme_preview,
749 /* translators: Quote from Romeo & Julier, for chat theme preview */
750 juliet, romeo, _("Deny thy father and refuse thy name;"));
751 preferences_preview_theme_append_message (priv->chat_theme_preview,
752 /* translators: Quote from Romeo & Julier, for chat theme preview */
753 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
754 preferences_preview_theme_append_message (priv->chat_theme_preview,
755 /* translators: Quote from Romeo & Julier, for chat theme preview */
756 juliet, romeo, _("And I'll no longer be a Capulet."));
757 preferences_preview_theme_append_message (priv->chat_theme_preview,
758 /* translators: Quote from Romeo & Julier, for chat theme preview */
759 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
761 /* translators: Quote from Romeo & Julier, for chat theme preview */
762 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
764 g_object_unref (juliet);
765 g_object_unref (romeo);
766 g_object_unref (account);
767 g_object_unref (dbus);
771 preferences_theme_variant_changed_cb (GtkComboBox *combo,
772 EmpathyPreferences *preferences)
774 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
777 if (gtk_combo_box_get_active_iter (combo, &iter)) {
781 model = gtk_combo_box_get_model (combo);
782 gtk_tree_model_get (model, &iter,
783 COL_VARIANT_NAME, &name,
786 g_settings_set_string (priv->gsettings_chat,
787 EMPATHY_PREFS_CHAT_THEME_VARIANT,
795 preferences_theme_variant_notify_cb (GSettings *gsettings,
799 EmpathyPreferences *preferences = user_data;
800 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
805 GtkTreeIter default_iter;
806 gboolean found_default = FALSE;
807 gboolean found = FALSE;
810 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
811 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
812 model = gtk_combo_box_get_model (combo);
814 for (ok = gtk_tree_model_get_iter_first (model, &iter);
816 ok = gtk_tree_model_iter_next (model, &iter)) {
820 gtk_tree_model_get (model, &iter,
821 COL_VARIANT_NAME, &name,
822 COL_VARIANT_DEFAULT, &is_default,
825 if (!tp_strdiff (name, conf_name)) {
827 gtk_combo_box_set_active_iter (combo, &iter);
830 found_default = TRUE;
837 /* Fallback to the first one. */
840 gtk_combo_box_set_active_iter (combo, &default_iter);
841 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
842 gtk_combo_box_set_active_iter (combo, &iter);
850 preferences_theme_variants_fill (EmpathyPreferences *preferences,
853 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
857 const gchar *default_variant;
860 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
861 store = GTK_LIST_STORE (model);
862 gtk_list_store_clear (store);
864 variants = empathy_adium_info_get_available_variants (info);
865 default_variant = empathy_adium_info_get_default_variant (info);
866 for (i = 0; i < variants->len; i++) {
867 gchar *name = g_ptr_array_index (variants, i);
869 gtk_list_store_insert_with_values (store, NULL, -1,
870 COL_VARIANT_NAME, name,
871 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
875 /* Select the variant from the GSetting key */
876 preferences_theme_variant_notify_cb (priv->gsettings_chat,
877 EMPATHY_PREFS_CHAT_THEME_VARIANT,
882 preferences_theme_variants_setup (EmpathyPreferences *preferences)
884 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
886 GtkCellLayout *cell_layout;
887 GtkCellRenderer *renderer;
890 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
891 cell_layout = GTK_CELL_LAYOUT (combo);
893 /* Create the model */
894 store = gtk_list_store_new (COL_VARIANT_COUNT,
895 G_TYPE_STRING, /* name */
896 G_TYPE_BOOLEAN); /* is default */
897 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
898 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
900 /* Add cell renderer */
901 renderer = gtk_cell_renderer_text_new ();
902 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
903 gtk_cell_layout_set_attributes (cell_layout, renderer,
904 "text", COL_VARIANT_NAME, NULL);
906 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
907 g_object_unref (store);
909 g_signal_connect (combo, "changed",
910 G_CALLBACK (preferences_theme_variant_changed_cb),
913 /* Track changes of the GSetting key */
914 g_signal_connect (priv->gsettings_chat,
915 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
916 G_CALLBACK (preferences_theme_variant_notify_cb),
921 preferences_theme_changed_cb (GtkComboBox *combo,
922 EmpathyPreferences *preferences)
924 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
927 if (gtk_combo_box_get_active_iter (combo, &iter)) {
934 model = gtk_combo_box_get_model (combo);
935 gtk_tree_model_get (model, &iter,
936 COL_THEME_IS_ADIUM, &is_adium,
937 COL_THEME_NAME, &name,
938 COL_THEME_ADIUM_PATH, &path,
939 COL_THEME_ADIUM_INFO, &info,
942 g_settings_set_string (priv->gsettings_chat,
943 EMPATHY_PREFS_CHAT_THEME,
946 g_settings_set_string (priv->gsettings_chat,
947 EMPATHY_PREFS_CHAT_ADIUM_PATH,
949 preferences_theme_variants_fill (preferences, info);
950 gtk_widget_show (priv->hbox_chat_theme_variant);
952 gtk_widget_hide (priv->hbox_chat_theme_variant);
956 tp_clear_pointer (&info, g_hash_table_unref);
961 preferences_theme_notify_cb (GSettings *gsettings,
965 EmpathyPreferences *preferences = user_data;
966 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
972 gboolean found = FALSE;
975 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
976 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
978 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
979 model = gtk_combo_box_get_model (combo);
980 for (ok = gtk_tree_model_get_iter_first (model, &iter);
982 ok = gtk_tree_model_iter_next (model, &iter)) {
987 gtk_tree_model_get (model, &iter,
988 COL_THEME_IS_ADIUM, &is_adium,
989 COL_THEME_NAME, &name,
990 COL_THEME_ADIUM_PATH, &path,
993 if (!tp_strdiff (name, conf_name) &&
994 (!is_adium || !tp_strdiff (path, conf_path))) {
996 gtk_combo_box_set_active_iter (combo, &iter);
1003 /* Fallback to the first one. */
1005 if (gtk_tree_model_get_iter_first (model, &iter)) {
1006 gtk_combo_box_set_active_iter (combo, &iter);
1015 preferences_themes_setup (EmpathyPreferences *preferences)
1017 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
1019 GtkCellLayout *cell_layout;
1020 GtkCellRenderer *renderer;
1021 GtkListStore *store;
1022 const gchar **themes;
1023 GList *adium_themes;
1026 preferences_theme_variants_setup (preferences);
1028 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1029 cell_layout = GTK_CELL_LAYOUT (combo);
1031 /* Create the model */
1032 store = gtk_list_store_new (COL_THEME_COUNT,
1033 G_TYPE_STRING, /* Display name */
1034 G_TYPE_STRING, /* Theme name */
1035 G_TYPE_BOOLEAN, /* Is an Adium theme */
1036 G_TYPE_STRING, /* Adium theme path */
1037 G_TYPE_HASH_TABLE); /* Adium theme info */
1038 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1039 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1041 /* Fill the model */
1042 themes = empathy_theme_manager_get_themes ();
1043 for (i = 0; themes[i]; i += 2) {
1044 gtk_list_store_insert_with_values (store, NULL, -1,
1045 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1046 COL_THEME_NAME, themes[i],
1047 COL_THEME_IS_ADIUM, FALSE,
1051 adium_themes = empathy_theme_manager_get_adium_themes ();
1052 while (adium_themes != NULL) {
1057 info = adium_themes->data;
1058 name = tp_asv_get_string (info, "CFBundleName");
1059 path = tp_asv_get_string (info, "path");
1061 if (name != NULL && path != NULL) {
1062 gtk_list_store_insert_with_values (store, NULL, -1,
1063 COL_THEME_VISIBLE_NAME, name,
1064 COL_THEME_NAME, "adium",
1065 COL_THEME_IS_ADIUM, TRUE,
1066 COL_THEME_ADIUM_PATH, path,
1067 COL_THEME_ADIUM_INFO, info,
1070 g_hash_table_unref (info);
1071 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1074 /* Add cell renderer */
1075 renderer = gtk_cell_renderer_text_new ();
1076 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1077 gtk_cell_layout_set_attributes (cell_layout, renderer,
1078 "text", COL_THEME_VISIBLE_NAME, NULL);
1080 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1081 g_object_unref (store);
1083 g_signal_connect (combo, "changed",
1084 G_CALLBACK (preferences_theme_changed_cb),
1087 /* Select the theme from the GSetting key and track changes */
1088 preferences_theme_notify_cb (priv->gsettings_chat,
1089 EMPATHY_PREFS_CHAT_THEME,
1091 g_signal_connect (priv->gsettings_chat,
1092 "changed::" EMPATHY_PREFS_CHAT_THEME,
1093 G_CALLBACK (preferences_theme_notify_cb),
1096 g_signal_connect (priv->gsettings_chat,
1097 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1098 G_CALLBACK (preferences_theme_notify_cb),
1103 preferences_call_format_volume_cb (GtkScale *scale,
1106 return g_strdup_printf ("%g%%", value);
1110 empathy_preferences_response (GtkDialog *widget,
1113 gtk_widget_destroy (GTK_WIDGET (widget));
1117 empathy_preferences_finalize (GObject *self)
1119 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1121 g_object_unref (priv->theme_manager);
1123 g_object_unref (priv->gsettings);
1124 g_object_unref (priv->gsettings_chat);
1125 g_object_unref (priv->gsettings_call);
1126 g_object_unref (priv->gsettings_loc);
1127 g_object_unref (priv->gsettings_notify);
1128 g_object_unref (priv->gsettings_sound);
1129 g_object_unref (priv->gsettings_ui);
1130 g_object_unref (priv->gsettings_logger);
1132 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1136 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1138 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1139 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1141 dialog_class->response = empathy_preferences_response;
1143 object_class->finalize = empathy_preferences_finalize;
1145 g_type_class_add_private (object_class,
1146 sizeof (EmpathyPreferencesPriv));
1150 empathy_preferences_init (EmpathyPreferences *preferences)
1152 EmpathyPreferencesPriv *priv;
1156 GtkWidget *call_volume_scale_box;
1157 GtkWidget *call_volume_bar_box;
1159 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1160 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1162 gtk_dialog_add_button (GTK_DIALOG (preferences),
1163 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1165 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1166 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1167 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1168 gtk_window_set_position (GTK_WINDOW (preferences),
1169 GTK_WIN_POS_CENTER_ON_PARENT);
1170 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1172 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1173 gui = empathy_builder_get_file (filename,
1174 "notebook", &priv->notebook,
1175 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1176 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1177 "vbox_chat_theme", &priv->vbox_chat_theme,
1178 "combobox_chat_theme", &priv->combobox_chat_theme,
1179 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1180 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1181 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1182 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1183 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1184 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1185 "checkbutton_logging", &priv->checkbutton_logging,
1186 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1187 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1188 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1189 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1190 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1191 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1192 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1193 "treeview_sounds", &priv->treeview_sounds,
1194 "treeview_spell_checker", &priv->treeview_spell_checker,
1195 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1196 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1197 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1198 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1199 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1200 "call_volume_scale_box", &call_volume_scale_box,
1201 "call_volume_bar_box", &call_volume_bar_box,
1202 "call_volume_scale", &priv->scale_call_volume,
1203 "call_volume_adjustment", &priv->adj_call_volume,
1204 "call_echo_cancellation", &priv->echo_cancellation,
1208 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1209 gtk_widget_show (priv->notebook);
1211 g_object_unref (gui);
1213 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1214 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1215 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1216 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1217 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1218 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1219 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1220 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1222 /* Create chat theme preview, and track changes */
1223 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1224 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1225 G_CALLBACK (preferences_preview_theme_changed_cb),
1227 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1229 g_signal_connect (priv->scale_call_volume, "format-value",
1230 G_CALLBACK (preferences_call_format_volume_cb),
1234 gtk_widget_hide (call_volume_scale_box);
1235 gtk_widget_hide (call_volume_bar_box);
1238 preferences_themes_setup (preferences);
1240 preferences_setup_widgets (preferences);
1242 preferences_languages_setup (preferences);
1243 preferences_languages_add (preferences);
1244 preferences_languages_load (preferences);
1246 preferences_sound_setup (preferences);
1247 preferences_sound_load (preferences);
1249 if (empathy_spell_supported ()) {
1250 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1251 gtk_widget_show (page);
1254 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1256 gtk_widget_show (page);
1258 gtk_widget_hide (page);
1262 static EmpathyPreferencesTab
1263 empathy_preferences_tab_from_string (const gchar *str)
1267 for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1269 if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1273 g_warn_if_reached ();
1278 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1280 g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1282 return empathy_preferences_tabs[tab];
1286 empathy_preferences_new (GtkWindow *parent,
1287 gboolean shell_running)
1290 EmpathyPreferencesPriv *priv;
1291 GtkWidget *notif_page;
1293 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1295 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1297 if (parent != NULL) {
1298 gtk_window_set_transient_for (GTK_WINDOW (self),
1302 /* when running in Gnome Shell we must hide these options since they
1303 * are meaningless in that context:
1304 * - 'Display incoming events in the notification area' (General->Behavior)
1305 * - 'Notifications' tab
1307 priv = GET_PRIV (self);
1308 if (shell_running) {
1309 gtk_widget_hide (priv->checkbutton_events_notif_area);
1310 notif_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook),
1311 EMPATHY_PREFERENCES_TAB_NOTIFICATIONS);
1312 gtk_widget_hide (notif_page);
1319 empathy_preferences_show_tab (EmpathyPreferences *self,
1322 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1324 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1325 empathy_preferences_tab_from_string (page));