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 *echo_cancellation;
88 GtkWidget *treeview_spell_checker;
90 GtkWidget *checkbutton_location_publish;
91 GtkWidget *checkbutton_location_reduce_accuracy;
92 GtkWidget *checkbutton_location_resource_network;
93 GtkWidget *checkbutton_location_resource_cell;
94 GtkWidget *checkbutton_location_resource_gps;
96 GtkWidget *vbox_chat_theme;
97 GtkWidget *combobox_chat_theme;
98 GtkWidget *combobox_chat_theme_variant;
99 GtkWidget *hbox_chat_theme_variant;
100 GtkWidget *sw_chat_theme_preview;
101 EmpathyChatView *chat_theme_preview;
102 EmpathyThemeManager *theme_manager;
104 GSettings *gsettings;
105 GSettings *gsettings_chat;
106 GSettings *gsettings_call;
107 GSettings *gsettings_loc;
108 GSettings *gsettings_notify;
109 GSettings *gsettings_sound;
110 GSettings *gsettings_ui;
111 GSettings *gsettings_logger;
114 static void preferences_setup_widgets (EmpathyPreferences *preferences);
115 static void preferences_languages_setup (EmpathyPreferences *preferences);
116 static void preferences_languages_add (EmpathyPreferences *preferences);
117 static void preferences_languages_save (EmpathyPreferences *preferences);
118 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
122 static void preferences_languages_load (EmpathyPreferences *preferences);
123 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
127 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
129 EmpathyPreferences *preferences);
139 COL_THEME_VISIBLE_NAME,
142 COL_THEME_ADIUM_PATH,
143 COL_THEME_ADIUM_INFO,
165 /* TODO: add phone related sounds also? */
166 static SoundEventEntry sound_entries [] = {
167 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
168 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
169 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
170 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
171 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
172 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
173 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
177 preferences_setup_widgets (EmpathyPreferences *preferences)
179 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
181 g_settings_bind (priv->gsettings_notify,
182 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
183 priv->checkbutton_notifications_enabled,
185 G_SETTINGS_BIND_DEFAULT);
186 g_settings_bind (priv->gsettings_notify,
187 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
188 priv->checkbutton_notifications_disabled_away,
190 G_SETTINGS_BIND_DEFAULT);
191 g_settings_bind (priv->gsettings_notify,
192 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
193 priv->checkbutton_notifications_focus,
195 G_SETTINGS_BIND_DEFAULT);
196 g_settings_bind (priv->gsettings_notify,
197 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
198 priv->checkbutton_notifications_contact_signin,
200 G_SETTINGS_BIND_DEFAULT);
201 g_settings_bind (priv->gsettings_notify,
202 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
203 priv->checkbutton_notifications_contact_signout,
205 G_SETTINGS_BIND_DEFAULT);
207 g_settings_bind (priv->gsettings_notify,
208 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
209 priv->checkbutton_notifications_disabled_away,
211 G_SETTINGS_BIND_GET);
212 g_settings_bind (priv->gsettings_notify,
213 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
214 priv->checkbutton_notifications_focus,
216 G_SETTINGS_BIND_GET);
217 g_settings_bind (priv->gsettings_notify,
218 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
219 priv->checkbutton_notifications_contact_signin,
221 G_SETTINGS_BIND_GET);
222 g_settings_bind (priv->gsettings_notify,
223 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
224 priv->checkbutton_notifications_contact_signout,
226 G_SETTINGS_BIND_GET);
228 g_settings_bind (priv->gsettings_sound,
229 EMPATHY_PREFS_SOUNDS_ENABLED,
230 priv->checkbutton_sounds_enabled,
232 G_SETTINGS_BIND_DEFAULT);
233 g_settings_bind (priv->gsettings_sound,
234 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
235 priv->checkbutton_sounds_disabled_away,
237 G_SETTINGS_BIND_DEFAULT);
239 g_settings_bind (priv->gsettings_sound,
240 EMPATHY_PREFS_SOUNDS_ENABLED,
241 priv->checkbutton_sounds_disabled_away,
243 G_SETTINGS_BIND_GET);
244 g_settings_bind (priv->gsettings_sound,
245 EMPATHY_PREFS_SOUNDS_ENABLED,
246 priv->treeview_sounds,
248 G_SETTINGS_BIND_GET);
250 g_settings_bind (priv->gsettings_ui,
251 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
252 priv->checkbutton_separate_chat_windows,
254 G_SETTINGS_BIND_DEFAULT);
256 g_settings_bind (priv->gsettings_ui,
257 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
258 priv->checkbutton_events_notif_area,
260 G_SETTINGS_BIND_DEFAULT);
262 g_settings_bind (priv->gsettings_chat,
263 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
264 priv->checkbutton_show_smileys,
266 G_SETTINGS_BIND_DEFAULT);
267 g_settings_bind (priv->gsettings_chat,
268 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
269 priv->checkbutton_show_contacts_in_rooms,
271 G_SETTINGS_BIND_DEFAULT);
273 g_settings_bind (priv->gsettings_call,
274 EMPATHY_PREFS_CALL_ECHO_CANCELLATION,
275 priv->echo_cancellation,
277 G_SETTINGS_BIND_DEFAULT);
279 g_settings_bind (priv->gsettings,
280 EMPATHY_PREFS_AUTOCONNECT,
281 priv->checkbutton_autoconnect,
283 G_SETTINGS_BIND_DEFAULT);
285 g_settings_bind (priv->gsettings_loc,
286 EMPATHY_PREFS_LOCATION_PUBLISH,
287 priv->checkbutton_location_publish,
289 G_SETTINGS_BIND_DEFAULT);
291 g_settings_bind (priv->gsettings_loc,
292 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
293 priv->checkbutton_location_resource_network,
295 G_SETTINGS_BIND_DEFAULT);
296 g_settings_bind (priv->gsettings_loc,
297 EMPATHY_PREFS_LOCATION_PUBLISH,
298 priv->checkbutton_location_resource_network,
300 G_SETTINGS_BIND_GET);
302 g_settings_bind (priv->gsettings_loc,
303 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
304 priv->checkbutton_location_resource_cell,
306 G_SETTINGS_BIND_DEFAULT);
307 g_settings_bind (priv->gsettings_loc,
308 EMPATHY_PREFS_LOCATION_PUBLISH,
309 priv->checkbutton_location_resource_cell,
311 G_SETTINGS_BIND_GET);
313 g_settings_bind (priv->gsettings_loc,
314 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
315 priv->checkbutton_location_resource_gps,
317 G_SETTINGS_BIND_DEFAULT);
318 g_settings_bind (priv->gsettings_loc,
319 EMPATHY_PREFS_LOCATION_PUBLISH,
320 priv->checkbutton_location_resource_gps,
322 G_SETTINGS_BIND_GET);
324 g_settings_bind (priv->gsettings_loc,
325 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
326 priv->checkbutton_location_reduce_accuracy,
328 G_SETTINGS_BIND_DEFAULT);
329 g_settings_bind (priv->gsettings_loc,
330 EMPATHY_PREFS_LOCATION_PUBLISH,
331 priv->checkbutton_location_reduce_accuracy,
333 G_SETTINGS_BIND_GET);
335 g_settings_bind (priv->gsettings_logger,
336 EMPATHY_PREFS_LOGGER_ENABLED,
337 priv->checkbutton_logging,
339 G_SETTINGS_BIND_DEFAULT);
343 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
345 EmpathyPreferences *preferences)
347 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
355 view = GTK_TREE_VIEW (priv->treeview_sounds);
356 model = gtk_tree_view_get_model (view);
358 path = gtk_tree_path_new_from_string (path_string);
360 gtk_tree_model_get_iter (model, &iter, path);
361 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
362 COL_SOUND_ENABLED, &instore, -1);
366 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
367 COL_SOUND_ENABLED, instore, -1);
369 g_settings_set_boolean (priv->gsettings_sound, key, instore);
372 gtk_tree_path_free (path);
376 preferences_sound_load (EmpathyPreferences *preferences)
378 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
385 view = GTK_TREE_VIEW (priv->treeview_sounds);
386 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
388 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
389 set = g_settings_get_boolean (priv->gsettings_sound,
390 sound_entries[i].key);
392 gtk_list_store_insert_with_values (store, &iter, i,
393 COL_SOUND_NAME, gettext (sound_entries[i].name),
394 COL_SOUND_KEY, sound_entries[i].key,
395 COL_SOUND_ENABLED, set, -1);
400 preferences_sound_setup (EmpathyPreferences *preferences)
402 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
405 GtkCellRenderer *renderer;
406 GtkTreeViewColumn *column;
408 view = GTK_TREE_VIEW (priv->treeview_sounds);
410 store = gtk_list_store_new (COL_SOUND_COUNT,
411 G_TYPE_BOOLEAN, /* enabled */
412 G_TYPE_STRING, /* name */
413 G_TYPE_STRING); /* key */
415 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
417 renderer = gtk_cell_renderer_toggle_new ();
418 g_signal_connect (renderer, "toggled",
419 G_CALLBACK (preferences_sound_cell_toggled_cb),
422 column = gtk_tree_view_column_new ();
423 gtk_tree_view_column_pack_start (column, renderer, FALSE);
424 gtk_tree_view_column_add_attribute (column, renderer,
425 "active", COL_SOUND_ENABLED);
427 renderer = gtk_cell_renderer_text_new ();
428 gtk_tree_view_column_pack_start (column, renderer, FALSE);
429 gtk_tree_view_column_add_attribute (column, renderer,
430 "text", COL_SOUND_NAME);
432 gtk_tree_view_append_column (view, column);
434 gtk_tree_view_column_set_resizable (column, FALSE);
435 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
437 g_object_unref (store);
441 preferences_languages_setup (EmpathyPreferences *preferences)
443 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
446 GtkTreeSelection *selection;
447 GtkTreeViewColumn *column;
448 GtkCellRenderer *renderer;
451 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
453 store = gtk_list_store_new (COL_LANG_COUNT,
454 G_TYPE_BOOLEAN, /* enabled */
455 G_TYPE_STRING, /* code */
456 G_TYPE_STRING); /* name */
458 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
460 selection = gtk_tree_view_get_selection (view);
461 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
463 renderer = gtk_cell_renderer_toggle_new ();
464 g_signal_connect (renderer, "toggled",
465 G_CALLBACK (preferences_languages_cell_toggled_cb),
468 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
469 "active", COL_LANG_ENABLED,
472 gtk_tree_view_append_column (view, column);
474 renderer = gtk_cell_renderer_text_new ();
475 col_offset = gtk_tree_view_insert_column_with_attributes (view,
478 "text", COL_LANG_NAME,
481 g_object_set_data (G_OBJECT (renderer),
482 "column", GINT_TO_POINTER (COL_LANG_NAME));
484 column = gtk_tree_view_get_column (view, col_offset - 1);
485 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
486 gtk_tree_view_column_set_resizable (column, FALSE);
487 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
489 g_object_unref (store);
493 preferences_languages_add (EmpathyPreferences *preferences)
495 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
500 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
501 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
503 codes = empathy_spell_get_language_codes ();
506 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
509 for (l = codes; l; l = l->next) {
515 name = empathy_spell_get_language_name (code);
520 gtk_list_store_append (store, &iter);
521 gtk_list_store_set (store, &iter,
527 empathy_spell_free_language_codes (codes);
531 preferences_languages_save (EmpathyPreferences *preferences)
533 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
537 gchar *languages = NULL;
539 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
540 model = gtk_tree_view_get_model (view);
542 gtk_tree_model_foreach (model,
543 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
546 /* if user selects no languages, we don't want spell check */
547 g_settings_set_boolean (priv->gsettings_chat,
548 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
551 g_settings_set_string (priv->gsettings_chat,
552 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
553 languages != NULL ? languages : "");
559 preferences_languages_save_foreach (GtkTreeModel *model,
571 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
576 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
582 *languages = g_strdup (code);
584 gchar *str = *languages;
585 *languages = g_strdup_printf ("%s,%s", str, code);
595 preferences_languages_load (EmpathyPreferences *preferences)
597 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
600 GList *enabled_codes;
602 enabled_codes = empathy_spell_get_enabled_language_codes ();
604 g_settings_set_boolean (priv->gsettings_chat,
605 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
606 enabled_codes != NULL);
608 if (enabled_codes == NULL)
611 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
612 model = gtk_tree_view_get_model (view);
614 gtk_tree_model_foreach (model,
615 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
618 g_list_free (enabled_codes);
622 preferences_languages_load_foreach (GtkTreeModel *model,
628 gboolean found = FALSE;
634 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
639 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
644 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
649 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
651 EmpathyPreferences *preferences)
653 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
661 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
662 model = gtk_tree_view_get_model (view);
663 store = GTK_LIST_STORE (model);
665 path = gtk_tree_path_new_from_string (path_string);
667 gtk_tree_model_get_iter (model, &iter, path);
668 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
672 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
673 gtk_tree_path_free (path);
675 preferences_languages_save (preferences);
679 preferences_preview_theme_append_message (EmpathyChatView *view,
680 EmpathyContact *sender,
681 EmpathyContact *receiver,
684 EmpathyMessage *message;
686 message = g_object_new (EMPATHY_TYPE_MESSAGE,
688 "receiver", receiver,
692 empathy_chat_view_append_message (view, message);
693 g_object_unref (message);
697 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
698 EmpathyPreferences *preferences)
700 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
703 EmpathyContact *juliet;
704 EmpathyContact *romeo;
706 DEBUG ("Theme changed, update preview widget");
708 if (priv->chat_theme_preview != NULL) {
709 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
711 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
712 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
713 GTK_WIDGET (priv->chat_theme_preview));
714 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
716 /* FIXME: It is ugly to add a fake conversation like that.
717 * Would be cool if we could request a TplLogManager for a fake
719 dbus = tp_dbus_daemon_dup (NULL);
720 account = tp_account_new (dbus,
721 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
722 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
725 /* translators: Contact name for the chat theme preview */
726 "alias", _("Juliet"),
729 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
732 /* translators: Contact name for the chat theme preview */
737 preferences_preview_theme_append_message (priv->chat_theme_preview,
738 /* translators: Quote from Romeo & Julier, for chat theme preview */
739 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
740 preferences_preview_theme_append_message (priv->chat_theme_preview,
741 /* translators: Quote from Romeo & Julier, for chat theme preview */
742 juliet, romeo, _("Deny thy father and refuse thy name;"));
743 preferences_preview_theme_append_message (priv->chat_theme_preview,
744 /* translators: Quote from Romeo & Julier, for chat theme preview */
745 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
746 preferences_preview_theme_append_message (priv->chat_theme_preview,
747 /* translators: Quote from Romeo & Julier, for chat theme preview */
748 juliet, romeo, _("And I'll no longer be a Capulet."));
749 preferences_preview_theme_append_message (priv->chat_theme_preview,
750 /* translators: Quote from Romeo & Julier, for chat theme preview */
751 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
753 /* translators: Quote from Romeo & Julier, for chat theme preview */
754 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
756 g_object_unref (juliet);
757 g_object_unref (romeo);
758 g_object_unref (account);
759 g_object_unref (dbus);
763 preferences_theme_variant_changed_cb (GtkComboBox *combo,
764 EmpathyPreferences *preferences)
766 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
769 if (gtk_combo_box_get_active_iter (combo, &iter)) {
773 model = gtk_combo_box_get_model (combo);
774 gtk_tree_model_get (model, &iter,
775 COL_VARIANT_NAME, &name,
778 g_settings_set_string (priv->gsettings_chat,
779 EMPATHY_PREFS_CHAT_THEME_VARIANT,
787 preferences_theme_variant_notify_cb (GSettings *gsettings,
791 EmpathyPreferences *preferences = user_data;
792 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
797 GtkTreeIter default_iter;
798 gboolean found_default = FALSE;
799 gboolean found = FALSE;
802 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
803 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
804 model = gtk_combo_box_get_model (combo);
806 for (ok = gtk_tree_model_get_iter_first (model, &iter);
808 ok = gtk_tree_model_iter_next (model, &iter)) {
812 gtk_tree_model_get (model, &iter,
813 COL_VARIANT_NAME, &name,
814 COL_VARIANT_DEFAULT, &is_default,
817 if (!tp_strdiff (name, conf_name)) {
819 gtk_combo_box_set_active_iter (combo, &iter);
822 found_default = TRUE;
829 /* Fallback to the first one. */
832 gtk_combo_box_set_active_iter (combo, &default_iter);
833 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
834 gtk_combo_box_set_active_iter (combo, &iter);
841 /* return TRUE if we added at least one variant */
843 preferences_theme_variants_fill (EmpathyPreferences *preferences,
846 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
850 const gchar *default_variant;
852 gboolean result = FALSE;
854 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
855 store = GTK_LIST_STORE (model);
856 gtk_list_store_clear (store);
858 variants = empathy_adium_info_get_available_variants (info);
859 default_variant = empathy_adium_info_get_default_variant (info);
860 for (i = 0; i < variants->len; i++) {
861 gchar *name = g_ptr_array_index (variants, i);
863 gtk_list_store_insert_with_values (store, NULL, -1,
864 COL_VARIANT_NAME, name,
865 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
871 /* Select the variant from the GSetting key */
872 preferences_theme_variant_notify_cb (priv->gsettings_chat,
873 EMPATHY_PREFS_CHAT_THEME_VARIANT,
880 preferences_theme_variants_setup (EmpathyPreferences *preferences)
882 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
884 GtkCellLayout *cell_layout;
885 GtkCellRenderer *renderer;
888 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
889 cell_layout = GTK_CELL_LAYOUT (combo);
891 /* Create the model */
892 store = gtk_list_store_new (COL_VARIANT_COUNT,
893 G_TYPE_STRING, /* name */
894 G_TYPE_BOOLEAN); /* is default */
895 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
896 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
898 /* Add cell renderer */
899 renderer = gtk_cell_renderer_text_new ();
900 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
901 gtk_cell_layout_set_attributes (cell_layout, renderer,
902 "text", COL_VARIANT_NAME, NULL);
904 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
905 g_object_unref (store);
907 g_signal_connect (combo, "changed",
908 G_CALLBACK (preferences_theme_variant_changed_cb),
911 /* Track changes of the GSetting key */
912 g_signal_connect (priv->gsettings_chat,
913 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
914 G_CALLBACK (preferences_theme_variant_notify_cb),
919 preferences_theme_changed_cb (GtkComboBox *combo,
920 EmpathyPreferences *preferences)
922 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
925 if (gtk_combo_box_get_active_iter (combo, &iter)) {
932 model = gtk_combo_box_get_model (combo);
933 gtk_tree_model_get (model, &iter,
934 COL_THEME_IS_ADIUM, &is_adium,
935 COL_THEME_NAME, &name,
936 COL_THEME_ADIUM_PATH, &path,
937 COL_THEME_ADIUM_INFO, &info,
940 g_settings_set_string (priv->gsettings_chat,
941 EMPATHY_PREFS_CHAT_THEME,
946 g_settings_set_string (priv->gsettings_chat,
947 EMPATHY_PREFS_CHAT_ADIUM_PATH,
950 variant = preferences_theme_variants_fill (preferences, info);
951 gtk_widget_set_visible (priv->hbox_chat_theme_variant, variant);
953 gtk_widget_hide (priv->hbox_chat_theme_variant);
957 tp_clear_pointer (&info, g_hash_table_unref);
962 preferences_theme_notify_cb (GSettings *gsettings,
966 EmpathyPreferences *preferences = user_data;
967 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
973 gboolean found = FALSE;
976 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
977 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
979 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
980 model = gtk_combo_box_get_model (combo);
981 for (ok = gtk_tree_model_get_iter_first (model, &iter);
983 ok = gtk_tree_model_iter_next (model, &iter)) {
988 gtk_tree_model_get (model, &iter,
989 COL_THEME_IS_ADIUM, &is_adium,
990 COL_THEME_NAME, &name,
991 COL_THEME_ADIUM_PATH, &path,
994 if (!tp_strdiff (name, conf_name) &&
995 (!is_adium || !tp_strdiff (path, conf_path))) {
997 gtk_combo_box_set_active_iter (combo, &iter);
1004 /* Fallback to the first one. */
1006 if (gtk_tree_model_get_iter_first (model, &iter)) {
1007 gtk_combo_box_set_active_iter (combo, &iter);
1016 preferences_themes_setup (EmpathyPreferences *preferences)
1018 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
1020 GtkCellLayout *cell_layout;
1021 GtkCellRenderer *renderer;
1022 GtkListStore *store;
1023 const gchar **themes;
1024 GList *adium_themes;
1027 preferences_theme_variants_setup (preferences);
1029 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1030 cell_layout = GTK_CELL_LAYOUT (combo);
1032 /* Create the model */
1033 store = gtk_list_store_new (COL_THEME_COUNT,
1034 G_TYPE_STRING, /* Display name */
1035 G_TYPE_STRING, /* Theme name */
1036 G_TYPE_BOOLEAN, /* Is an Adium theme */
1037 G_TYPE_STRING, /* Adium theme path */
1038 G_TYPE_HASH_TABLE); /* Adium theme info */
1039 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1040 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1042 /* Fill the model */
1043 themes = empathy_theme_manager_get_themes ();
1044 for (i = 0; themes[i]; i += 2) {
1045 gtk_list_store_insert_with_values (store, NULL, -1,
1046 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1047 COL_THEME_NAME, themes[i],
1048 COL_THEME_IS_ADIUM, FALSE,
1052 adium_themes = empathy_theme_manager_get_adium_themes ();
1053 while (adium_themes != NULL) {
1058 info = adium_themes->data;
1059 name = tp_asv_get_string (info, "CFBundleName");
1060 path = tp_asv_get_string (info, "path");
1062 if (name != NULL && path != NULL) {
1063 gtk_list_store_insert_with_values (store, NULL, -1,
1064 COL_THEME_VISIBLE_NAME, name,
1065 COL_THEME_NAME, "adium",
1066 COL_THEME_IS_ADIUM, TRUE,
1067 COL_THEME_ADIUM_PATH, path,
1068 COL_THEME_ADIUM_INFO, info,
1071 g_hash_table_unref (info);
1072 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1075 /* Add cell renderer */
1076 renderer = gtk_cell_renderer_text_new ();
1077 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1078 gtk_cell_layout_set_attributes (cell_layout, renderer,
1079 "text", COL_THEME_VISIBLE_NAME, NULL);
1081 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1082 g_object_unref (store);
1084 g_signal_connect (combo, "changed",
1085 G_CALLBACK (preferences_theme_changed_cb),
1088 /* Select the theme from the GSetting key and track changes */
1089 preferences_theme_notify_cb (priv->gsettings_chat,
1090 EMPATHY_PREFS_CHAT_THEME,
1092 g_signal_connect (priv->gsettings_chat,
1093 "changed::" EMPATHY_PREFS_CHAT_THEME,
1094 G_CALLBACK (preferences_theme_notify_cb),
1097 g_signal_connect (priv->gsettings_chat,
1098 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1099 G_CALLBACK (preferences_theme_notify_cb),
1104 empathy_preferences_response (GtkDialog *widget,
1107 gtk_widget_destroy (GTK_WIDGET (widget));
1111 empathy_preferences_finalize (GObject *self)
1113 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1115 g_object_unref (priv->theme_manager);
1117 g_object_unref (priv->gsettings);
1118 g_object_unref (priv->gsettings_chat);
1119 g_object_unref (priv->gsettings_call);
1120 g_object_unref (priv->gsettings_loc);
1121 g_object_unref (priv->gsettings_notify);
1122 g_object_unref (priv->gsettings_sound);
1123 g_object_unref (priv->gsettings_ui);
1124 g_object_unref (priv->gsettings_logger);
1126 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1130 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1132 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1133 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1135 dialog_class->response = empathy_preferences_response;
1137 object_class->finalize = empathy_preferences_finalize;
1139 g_type_class_add_private (object_class,
1140 sizeof (EmpathyPreferencesPriv));
1144 empathy_preferences_init (EmpathyPreferences *preferences)
1146 EmpathyPreferencesPriv *priv;
1151 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1152 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1154 gtk_dialog_add_button (GTK_DIALOG (preferences),
1155 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1157 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1158 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1159 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1160 gtk_window_set_position (GTK_WINDOW (preferences),
1161 GTK_WIN_POS_CENTER_ON_PARENT);
1162 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1164 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1165 gui = empathy_builder_get_file (filename,
1166 "notebook", &priv->notebook,
1167 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1168 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1169 "vbox_chat_theme", &priv->vbox_chat_theme,
1170 "combobox_chat_theme", &priv->combobox_chat_theme,
1171 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1172 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1173 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1174 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1175 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1176 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1177 "checkbutton_logging", &priv->checkbutton_logging,
1178 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1179 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1180 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1181 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1182 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1183 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1184 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1185 "treeview_sounds", &priv->treeview_sounds,
1186 "treeview_spell_checker", &priv->treeview_spell_checker,
1187 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1188 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1189 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1190 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1191 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1192 "call_echo_cancellation", &priv->echo_cancellation,
1196 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1197 gtk_widget_show (priv->notebook);
1199 g_object_unref (gui);
1201 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1202 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1203 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1204 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1205 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1206 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1207 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1208 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1210 /* Create chat theme preview, and track changes */
1211 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1212 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1213 G_CALLBACK (preferences_preview_theme_changed_cb),
1215 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1217 preferences_themes_setup (preferences);
1219 preferences_setup_widgets (preferences);
1221 preferences_languages_setup (preferences);
1222 preferences_languages_add (preferences);
1223 preferences_languages_load (preferences);
1225 preferences_sound_setup (preferences);
1226 preferences_sound_load (preferences);
1228 if (empathy_spell_supported ()) {
1229 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1230 gtk_widget_show (page);
1233 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1235 gtk_widget_show (page);
1237 gtk_widget_hide (page);
1241 static EmpathyPreferencesTab
1242 empathy_preferences_tab_from_string (const gchar *str)
1246 for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1248 if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1252 g_warn_if_reached ();
1257 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1259 g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1261 return empathy_preferences_tabs[tab];
1265 empathy_preferences_new (GtkWindow *parent,
1266 gboolean shell_running)
1269 EmpathyPreferencesPriv *priv;
1270 GtkWidget *notif_page;
1272 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1274 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1276 if (parent != NULL) {
1277 gtk_window_set_transient_for (GTK_WINDOW (self),
1281 /* when running in Gnome Shell we must hide these options since they
1282 * are meaningless in that context:
1283 * - 'Display incoming events in the notification area' (General->Behavior)
1284 * - 'Notifications' tab
1286 priv = GET_PRIV (self);
1287 if (shell_running) {
1288 gtk_widget_hide (priv->checkbutton_events_notif_area);
1289 notif_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook),
1290 EMPATHY_PREFERENCES_TAB_NOTIFICATIONS);
1291 gtk_widget_hide (notif_page);
1298 empathy_preferences_show_tab (EmpathyPreferences *self,
1301 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1303 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1304 empathy_preferences_tab_from_string (page));