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);
849 /* return TRUE if we added at least one variant */
851 preferences_theme_variants_fill (EmpathyPreferences *preferences,
854 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
858 const gchar *default_variant;
860 gboolean result = FALSE;
862 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
863 store = GTK_LIST_STORE (model);
864 gtk_list_store_clear (store);
866 variants = empathy_adium_info_get_available_variants (info);
867 default_variant = empathy_adium_info_get_default_variant (info);
868 for (i = 0; i < variants->len; i++) {
869 gchar *name = g_ptr_array_index (variants, i);
871 gtk_list_store_insert_with_values (store, NULL, -1,
872 COL_VARIANT_NAME, name,
873 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
879 /* Select the variant from the GSetting key */
880 preferences_theme_variant_notify_cb (priv->gsettings_chat,
881 EMPATHY_PREFS_CHAT_THEME_VARIANT,
888 preferences_theme_variants_setup (EmpathyPreferences *preferences)
890 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
892 GtkCellLayout *cell_layout;
893 GtkCellRenderer *renderer;
896 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
897 cell_layout = GTK_CELL_LAYOUT (combo);
899 /* Create the model */
900 store = gtk_list_store_new (COL_VARIANT_COUNT,
901 G_TYPE_STRING, /* name */
902 G_TYPE_BOOLEAN); /* is default */
903 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
904 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
906 /* Add cell renderer */
907 renderer = gtk_cell_renderer_text_new ();
908 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
909 gtk_cell_layout_set_attributes (cell_layout, renderer,
910 "text", COL_VARIANT_NAME, NULL);
912 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
913 g_object_unref (store);
915 g_signal_connect (combo, "changed",
916 G_CALLBACK (preferences_theme_variant_changed_cb),
919 /* Track changes of the GSetting key */
920 g_signal_connect (priv->gsettings_chat,
921 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
922 G_CALLBACK (preferences_theme_variant_notify_cb),
927 preferences_theme_changed_cb (GtkComboBox *combo,
928 EmpathyPreferences *preferences)
930 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
933 if (gtk_combo_box_get_active_iter (combo, &iter)) {
940 model = gtk_combo_box_get_model (combo);
941 gtk_tree_model_get (model, &iter,
942 COL_THEME_IS_ADIUM, &is_adium,
943 COL_THEME_NAME, &name,
944 COL_THEME_ADIUM_PATH, &path,
945 COL_THEME_ADIUM_INFO, &info,
948 g_settings_set_string (priv->gsettings_chat,
949 EMPATHY_PREFS_CHAT_THEME,
954 g_settings_set_string (priv->gsettings_chat,
955 EMPATHY_PREFS_CHAT_ADIUM_PATH,
958 variant = preferences_theme_variants_fill (preferences, info);
959 gtk_widget_set_visible (priv->hbox_chat_theme_variant, variant);
961 gtk_widget_hide (priv->hbox_chat_theme_variant);
965 tp_clear_pointer (&info, g_hash_table_unref);
970 preferences_theme_notify_cb (GSettings *gsettings,
974 EmpathyPreferences *preferences = user_data;
975 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
981 gboolean found = FALSE;
984 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
985 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
987 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
988 model = gtk_combo_box_get_model (combo);
989 for (ok = gtk_tree_model_get_iter_first (model, &iter);
991 ok = gtk_tree_model_iter_next (model, &iter)) {
996 gtk_tree_model_get (model, &iter,
997 COL_THEME_IS_ADIUM, &is_adium,
998 COL_THEME_NAME, &name,
999 COL_THEME_ADIUM_PATH, &path,
1002 if (!tp_strdiff (name, conf_name) &&
1003 (!is_adium || !tp_strdiff (path, conf_path))) {
1005 gtk_combo_box_set_active_iter (combo, &iter);
1012 /* Fallback to the first one. */
1014 if (gtk_tree_model_get_iter_first (model, &iter)) {
1015 gtk_combo_box_set_active_iter (combo, &iter);
1024 preferences_themes_setup (EmpathyPreferences *preferences)
1026 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
1028 GtkCellLayout *cell_layout;
1029 GtkCellRenderer *renderer;
1030 GtkListStore *store;
1031 const gchar **themes;
1032 GList *adium_themes;
1035 preferences_theme_variants_setup (preferences);
1037 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1038 cell_layout = GTK_CELL_LAYOUT (combo);
1040 /* Create the model */
1041 store = gtk_list_store_new (COL_THEME_COUNT,
1042 G_TYPE_STRING, /* Display name */
1043 G_TYPE_STRING, /* Theme name */
1044 G_TYPE_BOOLEAN, /* Is an Adium theme */
1045 G_TYPE_STRING, /* Adium theme path */
1046 G_TYPE_HASH_TABLE); /* Adium theme info */
1047 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1048 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1050 /* Fill the model */
1051 themes = empathy_theme_manager_get_themes ();
1052 for (i = 0; themes[i]; i += 2) {
1053 gtk_list_store_insert_with_values (store, NULL, -1,
1054 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1055 COL_THEME_NAME, themes[i],
1056 COL_THEME_IS_ADIUM, FALSE,
1060 adium_themes = empathy_theme_manager_get_adium_themes ();
1061 while (adium_themes != NULL) {
1066 info = adium_themes->data;
1067 name = tp_asv_get_string (info, "CFBundleName");
1068 path = tp_asv_get_string (info, "path");
1070 if (name != NULL && path != NULL) {
1071 gtk_list_store_insert_with_values (store, NULL, -1,
1072 COL_THEME_VISIBLE_NAME, name,
1073 COL_THEME_NAME, "adium",
1074 COL_THEME_IS_ADIUM, TRUE,
1075 COL_THEME_ADIUM_PATH, path,
1076 COL_THEME_ADIUM_INFO, info,
1079 g_hash_table_unref (info);
1080 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1083 /* Add cell renderer */
1084 renderer = gtk_cell_renderer_text_new ();
1085 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1086 gtk_cell_layout_set_attributes (cell_layout, renderer,
1087 "text", COL_THEME_VISIBLE_NAME, NULL);
1089 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1090 g_object_unref (store);
1092 g_signal_connect (combo, "changed",
1093 G_CALLBACK (preferences_theme_changed_cb),
1096 /* Select the theme from the GSetting key and track changes */
1097 preferences_theme_notify_cb (priv->gsettings_chat,
1098 EMPATHY_PREFS_CHAT_THEME,
1100 g_signal_connect (priv->gsettings_chat,
1101 "changed::" EMPATHY_PREFS_CHAT_THEME,
1102 G_CALLBACK (preferences_theme_notify_cb),
1105 g_signal_connect (priv->gsettings_chat,
1106 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1107 G_CALLBACK (preferences_theme_notify_cb),
1112 preferences_call_format_volume_cb (GtkScale *scale,
1115 return g_strdup_printf ("%g%%", value);
1119 empathy_preferences_response (GtkDialog *widget,
1122 gtk_widget_destroy (GTK_WIDGET (widget));
1126 empathy_preferences_finalize (GObject *self)
1128 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1130 g_object_unref (priv->theme_manager);
1132 g_object_unref (priv->gsettings);
1133 g_object_unref (priv->gsettings_chat);
1134 g_object_unref (priv->gsettings_call);
1135 g_object_unref (priv->gsettings_loc);
1136 g_object_unref (priv->gsettings_notify);
1137 g_object_unref (priv->gsettings_sound);
1138 g_object_unref (priv->gsettings_ui);
1139 g_object_unref (priv->gsettings_logger);
1141 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1145 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1147 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1148 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1150 dialog_class->response = empathy_preferences_response;
1152 object_class->finalize = empathy_preferences_finalize;
1154 g_type_class_add_private (object_class,
1155 sizeof (EmpathyPreferencesPriv));
1159 empathy_preferences_init (EmpathyPreferences *preferences)
1161 EmpathyPreferencesPriv *priv;
1165 GtkWidget *call_volume_scale_box;
1166 GtkWidget *call_volume_bar_box;
1168 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1169 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1171 gtk_dialog_add_button (GTK_DIALOG (preferences),
1172 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1174 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1175 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1176 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1177 gtk_window_set_position (GTK_WINDOW (preferences),
1178 GTK_WIN_POS_CENTER_ON_PARENT);
1179 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1181 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1182 gui = empathy_builder_get_file (filename,
1183 "notebook", &priv->notebook,
1184 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1185 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1186 "vbox_chat_theme", &priv->vbox_chat_theme,
1187 "combobox_chat_theme", &priv->combobox_chat_theme,
1188 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1189 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1190 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1191 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1192 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1193 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1194 "checkbutton_logging", &priv->checkbutton_logging,
1195 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1196 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1197 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1198 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1199 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1200 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1201 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1202 "treeview_sounds", &priv->treeview_sounds,
1203 "treeview_spell_checker", &priv->treeview_spell_checker,
1204 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1205 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1206 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1207 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1208 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1209 "call_volume_scale_box", &call_volume_scale_box,
1210 "call_volume_bar_box", &call_volume_bar_box,
1211 "call_volume_scale", &priv->scale_call_volume,
1212 "call_volume_adjustment", &priv->adj_call_volume,
1213 "call_echo_cancellation", &priv->echo_cancellation,
1217 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1218 gtk_widget_show (priv->notebook);
1220 g_object_unref (gui);
1222 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1223 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1224 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1225 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1226 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1227 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1228 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1229 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1231 /* Create chat theme preview, and track changes */
1232 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1233 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1234 G_CALLBACK (preferences_preview_theme_changed_cb),
1236 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1238 g_signal_connect (priv->scale_call_volume, "format-value",
1239 G_CALLBACK (preferences_call_format_volume_cb),
1243 gtk_widget_hide (call_volume_scale_box);
1244 gtk_widget_hide (call_volume_bar_box);
1247 preferences_themes_setup (preferences);
1249 preferences_setup_widgets (preferences);
1251 preferences_languages_setup (preferences);
1252 preferences_languages_add (preferences);
1253 preferences_languages_load (preferences);
1255 preferences_sound_setup (preferences);
1256 preferences_sound_load (preferences);
1258 if (empathy_spell_supported ()) {
1259 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1260 gtk_widget_show (page);
1263 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1265 gtk_widget_show (page);
1267 gtk_widget_hide (page);
1271 static EmpathyPreferencesTab
1272 empathy_preferences_tab_from_string (const gchar *str)
1276 for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1278 if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1282 g_warn_if_reached ();
1287 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1289 g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1291 return empathy_preferences_tabs[tab];
1295 empathy_preferences_new (GtkWindow *parent,
1296 gboolean shell_running)
1299 EmpathyPreferencesPriv *priv;
1300 GtkWidget *notif_page;
1302 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1304 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1306 if (parent != NULL) {
1307 gtk_window_set_transient_for (GTK_WINDOW (self),
1311 /* when running in Gnome Shell we must hide these options since they
1312 * are meaningless in that context:
1313 * - 'Display incoming events in the notification area' (General->Behavior)
1314 * - 'Notifications' tab
1316 priv = GET_PRIV (self);
1317 if (shell_running) {
1318 gtk_widget_hide (priv->checkbutton_events_notif_area);
1319 notif_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook),
1320 EMPATHY_PREFERENCES_TAB_NOTIFICATIONS);
1321 gtk_widget_hide (notif_page);
1328 empathy_preferences_show_tab (EmpathyPreferences *self,
1331 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1333 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1334 empathy_preferences_tab_from_string (page));