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>
27 #include "empathy-preferences.h"
29 #include <glib/gi18n.h>
30 #include <tp-account-widgets/tpaw-builder.h>
32 #include "empathy-client-factory.h"
33 #include "empathy-gsettings.h"
34 #include "empathy-spell.h"
35 #include "empathy-theme-manager.h"
36 #include "empathy-ui-utils.h"
37 #include "empathy-utils.h"
39 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
40 #include "empathy-debug.h"
42 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
44 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
46 static const gchar * empathy_preferences_tabs[] =
57 struct _EmpathyPreferencesPriv {
60 GtkWidget *label_general_behavior;
61 GtkWidget *checkbutton_events_notif_area;
62 GtkWidget *checkbutton_autoconnect;
64 GtkWidget *treeview_sounds;
65 GtkWidget *treeview_spell_checker;
67 GtkWidget *vbox_chat_theme;
68 GtkWidget *combobox_chat_theme;
69 GtkWidget *combobox_chat_theme_variant;
70 GtkWidget *hbox_chat_theme_variant;
71 GtkWidget *sw_chat_theme_preview;
72 EmpathyThemeAdium *chat_theme_preview;
73 EmpathyThemeManager *theme_manager;
76 GSettings *gsettings_chat;
77 GSettings *gsettings_call;
78 GSettings *gsettings_loc;
79 GSettings *gsettings_notify;
80 GSettings *gsettings_sound;
81 GSettings *gsettings_ui;
82 GSettings *gsettings_logger;
85 static void preferences_setup_widgets (EmpathyPreferences *preferences,
87 static void preferences_languages_setup (EmpathyPreferences *preferences);
88 static void preferences_languages_add (EmpathyPreferences *preferences);
89 static void preferences_languages_save (EmpathyPreferences *preferences);
90 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
94 static void preferences_languages_load (EmpathyPreferences *preferences);
95 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
99 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
101 EmpathyPreferences *preferences);
111 COL_THEME_VISIBLE_NAME,
112 COL_THEME_ADIUM_NAME,
113 COL_THEME_ADIUM_INFO,
135 /* TODO: add phone related sounds also? */
136 static SoundEventEntry sound_entries [] = {
137 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
138 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
139 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
140 { N_("Contact comes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
141 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
142 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
143 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
147 preferences_setup_widgets (EmpathyPreferences *preferences,
150 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
151 #define BIND_ACTIVE(schema, key, widget) \
152 g_settings_bind (priv->gsettings_##schema, EMPATHY_PREFS_##key, \
153 gtk_builder_get_object (gui, widget), "active", \
154 G_SETTINGS_BIND_DEFAULT);
156 BIND_ACTIVE (notify, NOTIFICATIONS_ENABLED,
157 "checkbutton_notifications_enabled");
158 BIND_ACTIVE (notify, NOTIFICATIONS_DISABLED_AWAY,
159 "checkbutton_notifications_disabled_away");
160 BIND_ACTIVE (notify, NOTIFICATIONS_FOCUS,
161 "checkbutton_notifications_focus");
162 BIND_ACTIVE (notify, NOTIFICATIONS_CONTACT_SIGNIN,
163 "checkbutton_notifications_contact_signin");
164 BIND_ACTIVE (notify, NOTIFICATIONS_CONTACT_SIGNOUT,
165 "checkbutton_notifications_contact_signout");
167 BIND_ACTIVE (sound, SOUNDS_ENABLED,
168 "checkbutton_sounds_enabled");
169 BIND_ACTIVE (sound, SOUNDS_DISABLED_AWAY,
170 "checkbutton_sounds_disabled_away");
172 BIND_ACTIVE (ui, UI_SHOW_OFFLINE,
173 "checkbutton_show_offline");
174 BIND_ACTIVE (ui, UI_SHOW_GROUPS,
175 "checkbutton_show_groups");
176 BIND_ACTIVE (ui, UI_SEPARATE_CHAT_WINDOWS,
177 "radiobutton_chats_new_windows");
178 BIND_ACTIVE (ui, UI_EVENTS_NOTIFY_AREA,
179 "checkbutton_events_notif_area");
180 BIND_ACTIVE (ui, UI_SHOW_BALANCES,
181 "checkbutton_show_balances");
183 BIND_ACTIVE (chat, CHAT_SHOW_SMILEYS,
184 "checkbutton_show_smileys");
185 BIND_ACTIVE (chat, CHAT_SHOW_CONTACTS_IN_ROOMS,
186 "checkbutton_show_contacts_in_rooms");
188 BIND_ACTIVE (call, CALL_ECHO_CANCELLATION,
189 "call_echo_cancellation");
191 BIND_ACTIVE (loc, LOCATION_PUBLISH,
192 "checkbutton_location_publish");
193 BIND_ACTIVE (loc, LOCATION_RESOURCE_NETWORK,
194 "checkbutton_location_resource_network");
195 BIND_ACTIVE (loc, LOCATION_RESOURCE_CELL,
196 "checkbutton_location_resource_cell");
197 BIND_ACTIVE (loc, LOCATION_RESOURCE_GPS,
198 "checkbutton_location_resource_gps");
199 BIND_ACTIVE (loc, LOCATION_REDUCE_ACCURACY,
200 "checkbutton_location_reduce_accuracy");
202 BIND_ACTIVE (logger, LOGGER_ENABLED,
203 "checkbutton_logging");
207 #define BIND_SENSITIVE(schema, key, widget) \
208 g_settings_bind (priv->gsettings_##schema, EMPATHY_PREFS_##key, \
209 gtk_builder_get_object (gui, widget), "sensitive", \
210 G_SETTINGS_BIND_GET);
211 /* N.B. BIND_SENSITIVE() is in addition to the sensitivity setting of
213 BIND_SENSITIVE (notify, NOTIFICATIONS_ENABLED,
214 "checkbutton_notifications_disabled_away");
215 BIND_SENSITIVE (notify, NOTIFICATIONS_ENABLED,
216 "checkbutton_notifications_focus");
217 BIND_SENSITIVE (notify, NOTIFICATIONS_ENABLED,
218 "checkbutton_notifications_contact_signin");
219 BIND_SENSITIVE (notify, NOTIFICATIONS_ENABLED,
220 "checkbutton_notifications_contact_signout");
222 BIND_SENSITIVE (sound, SOUNDS_ENABLED,
223 "checkbutton_sounds_disabled_away");
224 BIND_SENSITIVE (sound, SOUNDS_ENABLED,
227 BIND_SENSITIVE (loc, LOCATION_PUBLISH,
228 "checkbutton_location_resource_network");
229 BIND_SENSITIVE (loc, LOCATION_PUBLISH,
230 "checkbutton_location_resource_cell");
231 BIND_SENSITIVE (loc, LOCATION_PUBLISH,
232 "checkbutton_location_resource_gps");
233 BIND_SENSITIVE (loc, LOCATION_PUBLISH,
234 "checkbutton_location_reduce_accuracy");
236 #undef BIND_SENSITIVE
238 g_settings_bind (priv->gsettings,
239 EMPATHY_PREFS_AUTOCONNECT,
240 gtk_builder_get_object (gui,
241 "checkbutton_autoconnect"),
243 G_SETTINGS_BIND_DEFAULT);
247 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
249 EmpathyPreferences *preferences)
251 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
259 view = GTK_TREE_VIEW (priv->treeview_sounds);
260 model = gtk_tree_view_get_model (view);
262 path = gtk_tree_path_new_from_string (path_string);
264 gtk_tree_model_get_iter (model, &iter, path);
265 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
266 COL_SOUND_ENABLED, &instore, -1);
270 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
271 COL_SOUND_ENABLED, instore, -1);
273 g_settings_set_boolean (priv->gsettings_sound, key, instore);
276 gtk_tree_path_free (path);
280 preferences_sound_load (EmpathyPreferences *preferences)
282 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
289 view = GTK_TREE_VIEW (priv->treeview_sounds);
290 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
292 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
293 set = g_settings_get_boolean (priv->gsettings_sound,
294 sound_entries[i].key);
296 gtk_list_store_insert_with_values (store, &iter, i,
297 COL_SOUND_NAME, gettext (sound_entries[i].name),
298 COL_SOUND_KEY, sound_entries[i].key,
299 COL_SOUND_ENABLED, set, -1);
304 preferences_sound_setup (EmpathyPreferences *preferences)
306 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
309 GtkCellRenderer *renderer;
310 GtkTreeViewColumn *column;
312 view = GTK_TREE_VIEW (priv->treeview_sounds);
314 store = gtk_list_store_new (COL_SOUND_COUNT,
315 G_TYPE_BOOLEAN, /* enabled */
316 G_TYPE_STRING, /* name */
317 G_TYPE_STRING); /* key */
319 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
321 renderer = gtk_cell_renderer_toggle_new ();
322 g_signal_connect (renderer, "toggled",
323 G_CALLBACK (preferences_sound_cell_toggled_cb),
326 column = gtk_tree_view_column_new ();
327 gtk_tree_view_column_pack_start (column, renderer, FALSE);
328 gtk_tree_view_column_add_attribute (column, renderer,
329 "active", COL_SOUND_ENABLED);
331 renderer = gtk_cell_renderer_text_new ();
332 gtk_tree_view_column_pack_start (column, renderer, FALSE);
333 gtk_tree_view_column_add_attribute (column, renderer,
334 "text", COL_SOUND_NAME);
336 gtk_tree_view_append_column (view, column);
338 gtk_tree_view_column_set_resizable (column, FALSE);
339 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
341 g_object_unref (store);
345 preferences_languages_setup (EmpathyPreferences *preferences)
347 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
350 GtkTreeSelection *selection;
351 GtkTreeViewColumn *column;
352 GtkCellRenderer *renderer;
355 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
357 store = gtk_list_store_new (COL_LANG_COUNT,
358 G_TYPE_BOOLEAN, /* enabled */
359 G_TYPE_STRING, /* code */
360 G_TYPE_STRING); /* name */
362 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
364 selection = gtk_tree_view_get_selection (view);
365 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
367 renderer = gtk_cell_renderer_toggle_new ();
368 g_signal_connect (renderer, "toggled",
369 G_CALLBACK (preferences_languages_cell_toggled_cb),
372 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
373 "active", COL_LANG_ENABLED,
376 gtk_tree_view_append_column (view, column);
378 renderer = gtk_cell_renderer_text_new ();
379 col_offset = gtk_tree_view_insert_column_with_attributes (view,
382 "text", COL_LANG_NAME,
385 g_object_set_data (G_OBJECT (renderer),
386 "column", GINT_TO_POINTER (COL_LANG_NAME));
388 column = gtk_tree_view_get_column (view, col_offset - 1);
389 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
390 gtk_tree_view_column_set_resizable (column, FALSE);
391 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
393 g_object_unref (store);
397 preferences_languages_add (EmpathyPreferences *preferences)
399 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
404 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
405 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
407 codes = empathy_spell_get_language_codes ();
410 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
413 for (l = codes; l; l = l->next) {
418 name = empathy_spell_get_language_name (code);
423 gtk_list_store_insert_with_values (store, NULL, -1,
429 empathy_spell_free_language_codes (codes);
433 preferences_languages_save (EmpathyPreferences *preferences)
435 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
439 gchar *languages = NULL;
441 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
442 model = gtk_tree_view_get_model (view);
444 gtk_tree_model_foreach (model,
445 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
448 /* if user selects no languages, we don't want spell check */
449 g_settings_set_boolean (priv->gsettings_chat,
450 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
453 g_settings_set_string (priv->gsettings_chat,
454 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
455 languages != NULL ? languages : "");
461 preferences_languages_save_foreach (GtkTreeModel *model,
473 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
478 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
484 *languages = g_strdup (code);
486 gchar *str = *languages;
487 *languages = g_strdup_printf ("%s,%s", str, code);
497 preferences_languages_load (EmpathyPreferences *preferences)
499 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
502 GList *enabled_codes;
504 enabled_codes = empathy_spell_get_enabled_language_codes ();
506 g_settings_set_boolean (priv->gsettings_chat,
507 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
508 enabled_codes != NULL);
510 if (enabled_codes == NULL)
513 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
514 model = gtk_tree_view_get_model (view);
516 gtk_tree_model_foreach (model,
517 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
520 g_list_free (enabled_codes);
524 preferences_languages_load_foreach (GtkTreeModel *model,
530 gboolean found = FALSE;
536 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
541 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
546 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
551 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
553 EmpathyPreferences *preferences)
555 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
563 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
564 model = gtk_tree_view_get_model (view);
565 store = GTK_LIST_STORE (model);
567 path = gtk_tree_path_new_from_string (path_string);
569 gtk_tree_model_get_iter (model, &iter, path);
570 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
574 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
575 gtk_tree_path_free (path);
577 preferences_languages_save (preferences);
581 preferences_preview_theme_append_message (EmpathyThemeAdium *view,
582 EmpathyContact *sender,
583 EmpathyContact *receiver,
585 gboolean should_highlight)
587 EmpathyMessage *message;
589 message = g_object_new (EMPATHY_TYPE_MESSAGE,
591 "receiver", receiver,
595 empathy_theme_adium_append_message (view, message, should_highlight);
596 g_object_unref (message);
600 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
601 EmpathyPreferences *preferences)
603 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
604 EmpathyClientFactory *factory;
606 EmpathyContact *juliet;
607 EmpathyContact *romeo;
609 DEBUG ("Theme changed, update preview widget");
611 if (priv->chat_theme_preview != NULL) {
612 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
614 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
615 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
616 GTK_WIDGET (priv->chat_theme_preview));
617 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
619 /* FIXME: It is ugly to add a fake conversation like that.
620 * Would be cool if we could request a TplLogManager for a fake
622 factory = empathy_client_factory_dup ();
624 account = tp_simple_client_factory_ensure_account (
625 TP_SIMPLE_CLIENT_FACTORY (factory),
626 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL, NULL);
627 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
630 /* translators: Contact name for the chat theme preview */
631 "alias", _("Juliet"),
634 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
637 /* translators: Contact name for the chat theme preview */
642 preferences_preview_theme_append_message (priv->chat_theme_preview,
643 /* translators: Quote from Romeo & Julier, for chat theme preview */
644 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"),
645 TRUE /* this message mentions Romeo */);
646 preferences_preview_theme_append_message (priv->chat_theme_preview,
647 /* translators: Quote from Romeo & Julier, for chat theme preview */
648 juliet, romeo, _("Deny thy father and refuse thy name;"), FALSE);
649 preferences_preview_theme_append_message (priv->chat_theme_preview,
650 /* translators: Quote from Romeo & Julier, for chat theme preview */
651 juliet, romeo, _("Or if thou wilt not, be but sworn my love"), FALSE);
652 preferences_preview_theme_append_message (priv->chat_theme_preview,
653 /* translators: Quote from Romeo & Julier, for chat theme preview */
654 juliet, romeo, _("And I'll no longer be a Capulet."), FALSE);
655 preferences_preview_theme_append_message (priv->chat_theme_preview,
656 /* translators: Quote from Romeo & Julier, for chat theme preview */
657 romeo, juliet, _("Shall I hear more, or shall I speak at this?"), FALSE);
659 /* translators: Quote from Romeo & Julier, for chat theme preview */
660 empathy_theme_adium_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
662 g_object_unref (juliet);
663 g_object_unref (romeo);
664 g_object_unref (account);
665 g_object_unref (factory);
669 preferences_theme_variant_changed_cb (GtkComboBox *combo,
670 EmpathyPreferences *preferences)
672 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
675 if (gtk_combo_box_get_active_iter (combo, &iter)) {
679 model = gtk_combo_box_get_model (combo);
680 gtk_tree_model_get (model, &iter,
681 COL_VARIANT_NAME, &name,
684 g_settings_set_string (priv->gsettings_chat,
685 EMPATHY_PREFS_CHAT_THEME_VARIANT,
693 preferences_theme_variant_notify_cb (GSettings *gsettings,
697 EmpathyPreferences *preferences = user_data;
698 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
703 GtkTreeIter default_iter;
704 gboolean found_default = FALSE;
705 gboolean found = FALSE;
708 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
709 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
710 model = gtk_combo_box_get_model (combo);
712 for (ok = gtk_tree_model_get_iter_first (model, &iter);
714 ok = gtk_tree_model_iter_next (model, &iter)) {
718 gtk_tree_model_get (model, &iter,
719 COL_VARIANT_NAME, &name,
720 COL_VARIANT_DEFAULT, &is_default,
723 if (!tp_strdiff (name, conf_name)) {
725 gtk_combo_box_set_active_iter (combo, &iter);
728 found_default = TRUE;
735 /* Fallback to the first one. */
738 gtk_combo_box_set_active_iter (combo, &default_iter);
739 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
740 gtk_combo_box_set_active_iter (combo, &iter);
747 /* return TRUE if we added at least one variant */
749 preferences_theme_variants_fill (EmpathyPreferences *preferences,
752 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
756 const gchar *default_variant;
758 gboolean result = FALSE;
760 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
761 store = GTK_LIST_STORE (model);
762 gtk_list_store_clear (store);
764 variants = empathy_adium_info_get_available_variants (info);
765 default_variant = empathy_adium_info_get_default_variant (info);
766 for (i = 0; i < variants->len; i++) {
767 gchar *name = g_ptr_array_index (variants, i);
769 gtk_list_store_insert_with_values (store, NULL, -1,
770 COL_VARIANT_NAME, name,
771 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
777 /* Select the variant from the GSetting key */
778 preferences_theme_variant_notify_cb (priv->gsettings_chat,
779 EMPATHY_PREFS_CHAT_THEME_VARIANT,
786 preferences_theme_variants_setup (EmpathyPreferences *preferences)
788 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
790 GtkCellLayout *cell_layout;
791 GtkCellRenderer *renderer;
794 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
795 cell_layout = GTK_CELL_LAYOUT (combo);
797 /* Create the model */
798 store = gtk_list_store_new (COL_VARIANT_COUNT,
799 G_TYPE_STRING, /* name */
800 G_TYPE_BOOLEAN); /* is default */
801 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
802 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
804 /* Add cell renderer */
805 renderer = gtk_cell_renderer_text_new ();
806 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
807 gtk_cell_layout_set_attributes (cell_layout, renderer,
808 "text", COL_VARIANT_NAME, NULL);
810 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
811 g_object_unref (store);
813 g_signal_connect (combo, "changed",
814 G_CALLBACK (preferences_theme_variant_changed_cb),
817 /* Track changes of the GSetting key */
818 g_signal_connect (priv->gsettings_chat,
819 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
820 G_CALLBACK (preferences_theme_variant_notify_cb),
825 preferences_theme_changed_cb (GtkComboBox *combo,
826 EmpathyPreferences *preferences)
828 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
831 if (gtk_combo_box_get_active_iter (combo, &iter)) {
837 model = gtk_combo_box_get_model (combo);
838 gtk_tree_model_get (model, &iter,
839 COL_THEME_ADIUM_NAME, &name,
840 COL_THEME_ADIUM_INFO, &info,
843 g_settings_set_string (priv->gsettings_chat,
844 EMPATHY_PREFS_CHAT_THEME,
847 variant = preferences_theme_variants_fill (preferences, info);
848 gtk_widget_set_visible (priv->hbox_chat_theme_variant, variant);
851 tp_clear_pointer (&info, g_hash_table_unref);
856 preferences_theme_notify_cb (GSettings *gsettings,
860 EmpathyPreferences *preferences = user_data;
861 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
866 gboolean found = FALSE;
869 theme = g_settings_get_string (gsettings, key);
871 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
872 model = gtk_combo_box_get_model (combo);
873 for (ok = gtk_tree_model_get_iter_first (model, &iter);
875 ok = gtk_tree_model_iter_next (model, &iter)) {
878 gtk_tree_model_get (model, &iter,
879 COL_THEME_ADIUM_NAME, &name,
882 if (!tp_strdiff (name, theme)) {
884 gtk_combo_box_set_active_iter (combo, &iter);
890 /* Fallback to the first one. */
892 if (gtk_tree_model_get_iter_first (model, &iter)) {
893 gtk_combo_box_set_active_iter (combo, &iter);
901 preferences_themes_setup (EmpathyPreferences *preferences)
903 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
905 GtkCellLayout *cell_layout;
906 GtkCellRenderer *renderer;
910 preferences_theme_variants_setup (preferences);
912 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
913 cell_layout = GTK_CELL_LAYOUT (combo);
915 /* Create the model */
916 store = gtk_list_store_new (COL_THEME_COUNT,
917 G_TYPE_STRING, /* Display name */
918 G_TYPE_STRING, /* Adium theme path */
919 G_TYPE_HASH_TABLE); /* Adium theme info */
920 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
921 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
924 adium_themes = empathy_theme_manager_get_adium_themes ();
925 while (adium_themes != NULL) {
927 const gchar *visible_name;
930 info = adium_themes->data;
931 visible_name = tp_asv_get_string (info, "CFBundleName");
932 name = empathy_theme_manager_dup_theme_name_from_path (
933 tp_asv_get_string (info, "path"));
935 if (visible_name != NULL && name != NULL) {
936 gtk_list_store_insert_with_values (store, NULL, -1,
937 COL_THEME_VISIBLE_NAME, visible_name,
938 COL_THEME_ADIUM_NAME, name,
939 COL_THEME_ADIUM_INFO, info,
942 g_hash_table_unref (info);
944 adium_themes = g_list_delete_link (adium_themes, adium_themes);
947 /* Add cell renderer */
948 renderer = gtk_cell_renderer_text_new ();
949 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
950 gtk_cell_layout_set_attributes (cell_layout, renderer,
951 "text", COL_THEME_VISIBLE_NAME, NULL);
953 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
954 g_object_unref (store);
956 g_signal_connect (combo, "changed",
957 G_CALLBACK (preferences_theme_changed_cb),
960 /* Select the theme from the GSetting key and track changes */
961 preferences_theme_notify_cb (priv->gsettings_chat,
962 EMPATHY_PREFS_CHAT_THEME,
965 g_signal_connect (priv->gsettings_chat,
966 "changed::" EMPATHY_PREFS_CHAT_THEME,
967 G_CALLBACK (preferences_theme_notify_cb),
972 empathy_preferences_response (GtkDialog *widget,
975 gtk_widget_destroy (GTK_WIDGET (widget));
979 empathy_preferences_finalize (GObject *self)
981 EmpathyPreferencesPriv *priv = GET_PRIV (self);
983 g_object_unref (priv->theme_manager);
985 g_object_unref (priv->gsettings);
986 g_object_unref (priv->gsettings_chat);
987 g_object_unref (priv->gsettings_call);
988 g_object_unref (priv->gsettings_loc);
989 g_object_unref (priv->gsettings_notify);
990 g_object_unref (priv->gsettings_sound);
991 g_object_unref (priv->gsettings_ui);
992 g_object_unref (priv->gsettings_logger);
994 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
998 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1000 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1001 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1003 dialog_class->response = empathy_preferences_response;
1005 object_class->finalize = empathy_preferences_finalize;
1007 g_type_class_add_private (object_class,
1008 sizeof (EmpathyPreferencesPriv));
1012 empathy_preferences_init (EmpathyPreferences *preferences)
1014 EmpathyPreferencesPriv *priv;
1019 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1020 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1022 gtk_dialog_add_button (GTK_DIALOG (preferences),
1023 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1025 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1026 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1027 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1028 gtk_window_set_position (GTK_WINDOW (preferences),
1029 GTK_WIN_POS_CENTER_ON_PARENT);
1030 gtk_window_set_icon_name (GTK_WINDOW (preferences), "preferences-desktop");
1032 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1033 gui = tpaw_builder_get_file (filename,
1034 "notebook", &priv->notebook,
1035 "vbox_chat_theme", &priv->vbox_chat_theme,
1036 "combobox_chat_theme", &priv->combobox_chat_theme,
1037 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1038 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1039 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1040 "treeview_sounds", &priv->treeview_sounds,
1041 "treeview_spell_checker", &priv->treeview_spell_checker,
1042 "label_general_behavior", &priv->label_general_behavior,
1043 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1044 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1048 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1049 gtk_widget_show (priv->notebook);
1051 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1052 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1053 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1054 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1055 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1056 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1057 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1058 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1060 /* Create chat theme preview, and track changes */
1061 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1062 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1063 G_CALLBACK (preferences_preview_theme_changed_cb),
1065 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1067 preferences_themes_setup (preferences);
1069 preferences_setup_widgets (preferences, gui);
1071 preferences_languages_setup (preferences);
1072 preferences_languages_add (preferences);
1073 preferences_languages_load (preferences);
1075 preferences_sound_setup (preferences);
1076 preferences_sound_load (preferences);
1078 g_object_unref (gui);
1080 if (empathy_spell_supported ()) {
1081 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1082 gtk_widget_show (page);
1085 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1087 gtk_widget_show (page);
1089 gtk_widget_hide (page);
1093 static EmpathyPreferencesTab
1094 empathy_preferences_tab_from_string (const gchar *str)
1098 for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1100 if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1104 g_warn_if_reached ();
1109 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1111 g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1113 return empathy_preferences_tabs[tab];
1117 empathy_preferences_new (GtkWindow *parent,
1118 gboolean shell_running)
1121 EmpathyPreferencesPriv *priv;
1122 GtkWidget *notif_page;
1124 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1126 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1128 if (parent != NULL) {
1129 gtk_window_set_transient_for (GTK_WINDOW (self),
1133 /* when running in Gnome Shell we must hide these options since they
1134 * are meaningless in that context:
1135 * - General->Behavior label
1136 * - 'Display incoming events in the notification area' (General->Behavior)
1137 * - 'Automatically connect at startup' (General->Behavior)
1138 * - 'Notifications' tab
1140 priv = GET_PRIV (self);
1141 if (shell_running) {
1143 gtk_widget_hide (priv->label_general_behavior);
1144 gtk_widget_hide (priv->checkbutton_events_notif_area);
1145 gtk_widget_hide (priv->checkbutton_autoconnect);
1147 /* Notifications tab */
1148 notif_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook),
1149 EMPATHY_PREFERENCES_TAB_NOTIFICATIONS);
1150 gtk_widget_hide (notif_page);
1157 empathy_preferences_show_tab (EmpathyPreferences *self,
1160 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1162 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1163 empathy_preferences_tab_from_string (page));