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-gtk-enum-types.h>
43 #include <libempathy-gtk/empathy-theme-adium.h>
45 #include "empathy-preferences.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
48 #include <libempathy/empathy-debug.h>
50 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
52 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
54 static const gchar * empathy_preferences_tabs[] =
65 struct _EmpathyPreferencesPriv {
68 GtkWidget *checkbutton_show_smileys;
69 GtkWidget *checkbutton_show_contacts_in_rooms;
70 GtkWidget *checkbutton_separate_chat_windows;
71 GtkWidget *checkbutton_events_notif_area;
72 GtkWidget *checkbutton_autoconnect;
73 GtkWidget *checkbutton_logging;
75 GtkWidget *checkbutton_sounds_enabled;
76 GtkWidget *checkbutton_sounds_disabled_away;
77 GtkWidget *treeview_sounds;
79 GtkWidget *checkbutton_notifications_enabled;
80 GtkWidget *checkbutton_notifications_disabled_away;
81 GtkWidget *checkbutton_notifications_focus;
82 GtkWidget *checkbutton_notifications_contact_signin;
83 GtkWidget *checkbutton_notifications_contact_signout;
85 GtkWidget *echo_cancellation;
87 GtkWidget *treeview_spell_checker;
89 GtkWidget *checkbutton_location_publish;
90 GtkWidget *checkbutton_location_reduce_accuracy;
91 GtkWidget *checkbutton_location_resource_network;
92 GtkWidget *checkbutton_location_resource_cell;
93 GtkWidget *checkbutton_location_resource_gps;
95 GtkWidget *vbox_chat_theme;
96 GtkWidget *combobox_chat_theme;
97 GtkWidget *combobox_chat_theme_variant;
98 GtkWidget *hbox_chat_theme_variant;
99 GtkWidget *sw_chat_theme_preview;
100 EmpathyChatView *chat_theme_preview;
101 EmpathyThemeManager *theme_manager;
103 GSettings *gsettings;
104 GSettings *gsettings_chat;
105 GSettings *gsettings_call;
106 GSettings *gsettings_loc;
107 GSettings *gsettings_notify;
108 GSettings *gsettings_sound;
109 GSettings *gsettings_ui;
110 GSettings *gsettings_logger;
113 static void preferences_setup_widgets (EmpathyPreferences *preferences);
114 static void preferences_languages_setup (EmpathyPreferences *preferences);
115 static void preferences_languages_add (EmpathyPreferences *preferences);
116 static void preferences_languages_save (EmpathyPreferences *preferences);
117 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
121 static void preferences_languages_load (EmpathyPreferences *preferences);
122 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
126 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
128 EmpathyPreferences *preferences);
138 COL_THEME_VISIBLE_NAME,
141 COL_THEME_ADIUM_PATH,
142 COL_THEME_ADIUM_INFO,
164 /* TODO: add phone related sounds also? */
165 static SoundEventEntry sound_entries [] = {
166 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
167 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
168 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
169 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
170 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
171 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
172 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
176 preferences_setup_widgets (EmpathyPreferences *preferences)
178 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
180 g_settings_bind (priv->gsettings_notify,
181 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
182 priv->checkbutton_notifications_enabled,
184 G_SETTINGS_BIND_DEFAULT);
185 g_settings_bind (priv->gsettings_notify,
186 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
187 priv->checkbutton_notifications_disabled_away,
189 G_SETTINGS_BIND_DEFAULT);
190 g_settings_bind (priv->gsettings_notify,
191 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
192 priv->checkbutton_notifications_focus,
194 G_SETTINGS_BIND_DEFAULT);
195 g_settings_bind (priv->gsettings_notify,
196 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
197 priv->checkbutton_notifications_contact_signin,
199 G_SETTINGS_BIND_DEFAULT);
200 g_settings_bind (priv->gsettings_notify,
201 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
202 priv->checkbutton_notifications_contact_signout,
204 G_SETTINGS_BIND_DEFAULT);
206 g_settings_bind (priv->gsettings_notify,
207 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
208 priv->checkbutton_notifications_disabled_away,
210 G_SETTINGS_BIND_GET);
211 g_settings_bind (priv->gsettings_notify,
212 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
213 priv->checkbutton_notifications_focus,
215 G_SETTINGS_BIND_GET);
216 g_settings_bind (priv->gsettings_notify,
217 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
218 priv->checkbutton_notifications_contact_signin,
220 G_SETTINGS_BIND_GET);
221 g_settings_bind (priv->gsettings_notify,
222 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
223 priv->checkbutton_notifications_contact_signout,
225 G_SETTINGS_BIND_GET);
227 g_settings_bind (priv->gsettings_sound,
228 EMPATHY_PREFS_SOUNDS_ENABLED,
229 priv->checkbutton_sounds_enabled,
231 G_SETTINGS_BIND_DEFAULT);
232 g_settings_bind (priv->gsettings_sound,
233 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
234 priv->checkbutton_sounds_disabled_away,
236 G_SETTINGS_BIND_DEFAULT);
238 g_settings_bind (priv->gsettings_sound,
239 EMPATHY_PREFS_SOUNDS_ENABLED,
240 priv->checkbutton_sounds_disabled_away,
242 G_SETTINGS_BIND_GET);
243 g_settings_bind (priv->gsettings_sound,
244 EMPATHY_PREFS_SOUNDS_ENABLED,
245 priv->treeview_sounds,
247 G_SETTINGS_BIND_GET);
249 g_settings_bind (priv->gsettings_ui,
250 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
251 priv->checkbutton_separate_chat_windows,
253 G_SETTINGS_BIND_DEFAULT);
255 g_settings_bind (priv->gsettings_ui,
256 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
257 priv->checkbutton_events_notif_area,
259 G_SETTINGS_BIND_DEFAULT);
261 g_settings_bind (priv->gsettings_chat,
262 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
263 priv->checkbutton_show_smileys,
265 G_SETTINGS_BIND_DEFAULT);
266 g_settings_bind (priv->gsettings_chat,
267 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
268 priv->checkbutton_show_contacts_in_rooms,
270 G_SETTINGS_BIND_DEFAULT);
272 g_settings_bind (priv->gsettings_call,
273 EMPATHY_PREFS_CALL_ECHO_CANCELLATION,
274 priv->echo_cancellation,
276 G_SETTINGS_BIND_DEFAULT);
278 g_settings_bind (priv->gsettings,
279 EMPATHY_PREFS_AUTOCONNECT,
280 priv->checkbutton_autoconnect,
282 G_SETTINGS_BIND_DEFAULT);
284 g_settings_bind (priv->gsettings_loc,
285 EMPATHY_PREFS_LOCATION_PUBLISH,
286 priv->checkbutton_location_publish,
288 G_SETTINGS_BIND_DEFAULT);
290 g_settings_bind (priv->gsettings_loc,
291 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
292 priv->checkbutton_location_resource_network,
294 G_SETTINGS_BIND_DEFAULT);
295 g_settings_bind (priv->gsettings_loc,
296 EMPATHY_PREFS_LOCATION_PUBLISH,
297 priv->checkbutton_location_resource_network,
299 G_SETTINGS_BIND_GET);
301 g_settings_bind (priv->gsettings_loc,
302 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
303 priv->checkbutton_location_resource_cell,
305 G_SETTINGS_BIND_DEFAULT);
306 g_settings_bind (priv->gsettings_loc,
307 EMPATHY_PREFS_LOCATION_PUBLISH,
308 priv->checkbutton_location_resource_cell,
310 G_SETTINGS_BIND_GET);
312 g_settings_bind (priv->gsettings_loc,
313 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
314 priv->checkbutton_location_resource_gps,
316 G_SETTINGS_BIND_DEFAULT);
317 g_settings_bind (priv->gsettings_loc,
318 EMPATHY_PREFS_LOCATION_PUBLISH,
319 priv->checkbutton_location_resource_gps,
321 G_SETTINGS_BIND_GET);
323 g_settings_bind (priv->gsettings_loc,
324 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
325 priv->checkbutton_location_reduce_accuracy,
327 G_SETTINGS_BIND_DEFAULT);
328 g_settings_bind (priv->gsettings_loc,
329 EMPATHY_PREFS_LOCATION_PUBLISH,
330 priv->checkbutton_location_reduce_accuracy,
332 G_SETTINGS_BIND_GET);
334 g_settings_bind (priv->gsettings_logger,
335 EMPATHY_PREFS_LOGGER_ENABLED,
336 priv->checkbutton_logging,
338 G_SETTINGS_BIND_DEFAULT);
342 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
344 EmpathyPreferences *preferences)
346 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
354 view = GTK_TREE_VIEW (priv->treeview_sounds);
355 model = gtk_tree_view_get_model (view);
357 path = gtk_tree_path_new_from_string (path_string);
359 gtk_tree_model_get_iter (model, &iter, path);
360 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
361 COL_SOUND_ENABLED, &instore, -1);
365 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
366 COL_SOUND_ENABLED, instore, -1);
368 g_settings_set_boolean (priv->gsettings_sound, key, instore);
371 gtk_tree_path_free (path);
375 preferences_sound_load (EmpathyPreferences *preferences)
377 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
384 view = GTK_TREE_VIEW (priv->treeview_sounds);
385 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
387 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
388 set = g_settings_get_boolean (priv->gsettings_sound,
389 sound_entries[i].key);
391 gtk_list_store_insert_with_values (store, &iter, i,
392 COL_SOUND_NAME, gettext (sound_entries[i].name),
393 COL_SOUND_KEY, sound_entries[i].key,
394 COL_SOUND_ENABLED, set, -1);
399 preferences_sound_setup (EmpathyPreferences *preferences)
401 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
404 GtkCellRenderer *renderer;
405 GtkTreeViewColumn *column;
407 view = GTK_TREE_VIEW (priv->treeview_sounds);
409 store = gtk_list_store_new (COL_SOUND_COUNT,
410 G_TYPE_BOOLEAN, /* enabled */
411 G_TYPE_STRING, /* name */
412 G_TYPE_STRING); /* key */
414 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
416 renderer = gtk_cell_renderer_toggle_new ();
417 g_signal_connect (renderer, "toggled",
418 G_CALLBACK (preferences_sound_cell_toggled_cb),
421 column = gtk_tree_view_column_new ();
422 gtk_tree_view_column_pack_start (column, renderer, FALSE);
423 gtk_tree_view_column_add_attribute (column, renderer,
424 "active", COL_SOUND_ENABLED);
426 renderer = gtk_cell_renderer_text_new ();
427 gtk_tree_view_column_pack_start (column, renderer, FALSE);
428 gtk_tree_view_column_add_attribute (column, renderer,
429 "text", COL_SOUND_NAME);
431 gtk_tree_view_append_column (view, column);
433 gtk_tree_view_column_set_resizable (column, FALSE);
434 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
436 g_object_unref (store);
440 preferences_languages_setup (EmpathyPreferences *preferences)
442 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
445 GtkTreeSelection *selection;
446 GtkTreeViewColumn *column;
447 GtkCellRenderer *renderer;
450 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
452 store = gtk_list_store_new (COL_LANG_COUNT,
453 G_TYPE_BOOLEAN, /* enabled */
454 G_TYPE_STRING, /* code */
455 G_TYPE_STRING); /* name */
457 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
459 selection = gtk_tree_view_get_selection (view);
460 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
462 renderer = gtk_cell_renderer_toggle_new ();
463 g_signal_connect (renderer, "toggled",
464 G_CALLBACK (preferences_languages_cell_toggled_cb),
467 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
468 "active", COL_LANG_ENABLED,
471 gtk_tree_view_append_column (view, column);
473 renderer = gtk_cell_renderer_text_new ();
474 col_offset = gtk_tree_view_insert_column_with_attributes (view,
477 "text", COL_LANG_NAME,
480 g_object_set_data (G_OBJECT (renderer),
481 "column", GINT_TO_POINTER (COL_LANG_NAME));
483 column = gtk_tree_view_get_column (view, col_offset - 1);
484 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
485 gtk_tree_view_column_set_resizable (column, FALSE);
486 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
488 g_object_unref (store);
492 preferences_languages_add (EmpathyPreferences *preferences)
494 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
499 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
500 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
502 codes = empathy_spell_get_language_codes ();
505 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
508 for (l = codes; l; l = l->next) {
514 name = empathy_spell_get_language_name (code);
519 gtk_list_store_append (store, &iter);
520 gtk_list_store_set (store, &iter,
526 empathy_spell_free_language_codes (codes);
530 preferences_languages_save (EmpathyPreferences *preferences)
532 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
536 gchar *languages = NULL;
538 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
539 model = gtk_tree_view_get_model (view);
541 gtk_tree_model_foreach (model,
542 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
545 /* if user selects no languages, we don't want spell check */
546 g_settings_set_boolean (priv->gsettings_chat,
547 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
550 g_settings_set_string (priv->gsettings_chat,
551 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
552 languages != NULL ? languages : "");
558 preferences_languages_save_foreach (GtkTreeModel *model,
570 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
575 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
581 *languages = g_strdup (code);
583 gchar *str = *languages;
584 *languages = g_strdup_printf ("%s,%s", str, code);
594 preferences_languages_load (EmpathyPreferences *preferences)
596 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
599 GList *enabled_codes;
601 enabled_codes = empathy_spell_get_enabled_language_codes ();
603 g_settings_set_boolean (priv->gsettings_chat,
604 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
605 enabled_codes != NULL);
607 if (enabled_codes == NULL)
610 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
611 model = gtk_tree_view_get_model (view);
613 gtk_tree_model_foreach (model,
614 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
617 g_list_free (enabled_codes);
621 preferences_languages_load_foreach (GtkTreeModel *model,
627 gboolean found = FALSE;
633 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
638 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
643 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
648 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
650 EmpathyPreferences *preferences)
652 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
660 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
661 model = gtk_tree_view_get_model (view);
662 store = GTK_LIST_STORE (model);
664 path = gtk_tree_path_new_from_string (path_string);
666 gtk_tree_model_get_iter (model, &iter, path);
667 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
671 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
672 gtk_tree_path_free (path);
674 preferences_languages_save (preferences);
678 preferences_preview_theme_append_message (EmpathyChatView *view,
679 EmpathyContact *sender,
680 EmpathyContact *receiver,
683 EmpathyMessage *message;
685 message = g_object_new (EMPATHY_TYPE_MESSAGE,
687 "receiver", receiver,
691 empathy_chat_view_append_message (view, message);
692 g_object_unref (message);
696 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
697 EmpathyPreferences *preferences)
699 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
702 EmpathyContact *juliet;
703 EmpathyContact *romeo;
705 DEBUG ("Theme changed, update preview widget");
707 if (priv->chat_theme_preview != NULL) {
708 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
710 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
711 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
712 GTK_WIDGET (priv->chat_theme_preview));
713 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
715 /* FIXME: It is ugly to add a fake conversation like that.
716 * Would be cool if we could request a TplLogManager for a fake
718 dbus = tp_dbus_daemon_dup (NULL);
719 account = tp_account_new (dbus,
720 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
721 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
724 /* translators: Contact name for the chat theme preview */
725 "alias", _("Juliet"),
728 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
731 /* translators: Contact name for the chat theme preview */
736 preferences_preview_theme_append_message (priv->chat_theme_preview,
737 /* translators: Quote from Romeo & Julier, for chat theme preview */
738 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
739 preferences_preview_theme_append_message (priv->chat_theme_preview,
740 /* translators: Quote from Romeo & Julier, for chat theme preview */
741 juliet, romeo, _("Deny thy father and refuse thy name;"));
742 preferences_preview_theme_append_message (priv->chat_theme_preview,
743 /* translators: Quote from Romeo & Julier, for chat theme preview */
744 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
745 preferences_preview_theme_append_message (priv->chat_theme_preview,
746 /* translators: Quote from Romeo & Julier, for chat theme preview */
747 juliet, romeo, _("And I'll no longer be a Capulet."));
748 preferences_preview_theme_append_message (priv->chat_theme_preview,
749 /* translators: Quote from Romeo & Julier, for chat theme preview */
750 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
752 /* translators: Quote from Romeo & Julier, for chat theme preview */
753 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
755 g_object_unref (juliet);
756 g_object_unref (romeo);
757 g_object_unref (account);
758 g_object_unref (dbus);
762 preferences_theme_variant_changed_cb (GtkComboBox *combo,
763 EmpathyPreferences *preferences)
765 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
768 if (gtk_combo_box_get_active_iter (combo, &iter)) {
772 model = gtk_combo_box_get_model (combo);
773 gtk_tree_model_get (model, &iter,
774 COL_VARIANT_NAME, &name,
777 g_settings_set_string (priv->gsettings_chat,
778 EMPATHY_PREFS_CHAT_THEME_VARIANT,
786 preferences_theme_variant_notify_cb (GSettings *gsettings,
790 EmpathyPreferences *preferences = user_data;
791 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
796 GtkTreeIter default_iter;
797 gboolean found_default = FALSE;
798 gboolean found = FALSE;
801 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
802 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
803 model = gtk_combo_box_get_model (combo);
805 for (ok = gtk_tree_model_get_iter_first (model, &iter);
807 ok = gtk_tree_model_iter_next (model, &iter)) {
811 gtk_tree_model_get (model, &iter,
812 COL_VARIANT_NAME, &name,
813 COL_VARIANT_DEFAULT, &is_default,
816 if (!tp_strdiff (name, conf_name)) {
818 gtk_combo_box_set_active_iter (combo, &iter);
821 found_default = TRUE;
828 /* Fallback to the first one. */
831 gtk_combo_box_set_active_iter (combo, &default_iter);
832 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
833 gtk_combo_box_set_active_iter (combo, &iter);
840 /* return TRUE if we added at least one variant */
842 preferences_theme_variants_fill (EmpathyPreferences *preferences,
845 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
849 const gchar *default_variant;
851 gboolean result = FALSE;
853 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
854 store = GTK_LIST_STORE (model);
855 gtk_list_store_clear (store);
857 variants = empathy_adium_info_get_available_variants (info);
858 default_variant = empathy_adium_info_get_default_variant (info);
859 for (i = 0; i < variants->len; i++) {
860 gchar *name = g_ptr_array_index (variants, i);
862 gtk_list_store_insert_with_values (store, NULL, -1,
863 COL_VARIANT_NAME, name,
864 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
870 /* Select the variant from the GSetting key */
871 preferences_theme_variant_notify_cb (priv->gsettings_chat,
872 EMPATHY_PREFS_CHAT_THEME_VARIANT,
879 preferences_theme_variants_setup (EmpathyPreferences *preferences)
881 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
883 GtkCellLayout *cell_layout;
884 GtkCellRenderer *renderer;
887 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
888 cell_layout = GTK_CELL_LAYOUT (combo);
890 /* Create the model */
891 store = gtk_list_store_new (COL_VARIANT_COUNT,
892 G_TYPE_STRING, /* name */
893 G_TYPE_BOOLEAN); /* is default */
894 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
895 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
897 /* Add cell renderer */
898 renderer = gtk_cell_renderer_text_new ();
899 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
900 gtk_cell_layout_set_attributes (cell_layout, renderer,
901 "text", COL_VARIANT_NAME, NULL);
903 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
904 g_object_unref (store);
906 g_signal_connect (combo, "changed",
907 G_CALLBACK (preferences_theme_variant_changed_cb),
910 /* Track changes of the GSetting key */
911 g_signal_connect (priv->gsettings_chat,
912 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
913 G_CALLBACK (preferences_theme_variant_notify_cb),
918 preferences_theme_changed_cb (GtkComboBox *combo,
919 EmpathyPreferences *preferences)
921 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
924 if (gtk_combo_box_get_active_iter (combo, &iter)) {
931 model = gtk_combo_box_get_model (combo);
932 gtk_tree_model_get (model, &iter,
933 COL_THEME_IS_ADIUM, &is_adium,
934 COL_THEME_NAME, &name,
935 COL_THEME_ADIUM_PATH, &path,
936 COL_THEME_ADIUM_INFO, &info,
939 g_settings_set_string (priv->gsettings_chat,
940 EMPATHY_PREFS_CHAT_THEME,
945 g_settings_set_string (priv->gsettings_chat,
946 EMPATHY_PREFS_CHAT_ADIUM_PATH,
949 variant = preferences_theme_variants_fill (preferences, info);
950 gtk_widget_set_visible (priv->hbox_chat_theme_variant, variant);
952 gtk_widget_hide (priv->hbox_chat_theme_variant);
956 tp_clear_pointer (&info, g_hash_table_unref);
961 preferences_theme_notify_cb (GSettings *gsettings,
965 EmpathyPreferences *preferences = user_data;
966 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
972 gboolean found = FALSE;
975 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
976 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
978 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
979 model = gtk_combo_box_get_model (combo);
980 for (ok = gtk_tree_model_get_iter_first (model, &iter);
982 ok = gtk_tree_model_iter_next (model, &iter)) {
987 gtk_tree_model_get (model, &iter,
988 COL_THEME_IS_ADIUM, &is_adium,
989 COL_THEME_NAME, &name,
990 COL_THEME_ADIUM_PATH, &path,
993 if (!tp_strdiff (name, conf_name) &&
994 (!is_adium || !tp_strdiff (path, conf_path))) {
996 gtk_combo_box_set_active_iter (combo, &iter);
1003 /* Fallback to the first one. */
1005 if (gtk_tree_model_get_iter_first (model, &iter)) {
1006 gtk_combo_box_set_active_iter (combo, &iter);
1015 preferences_themes_setup (EmpathyPreferences *preferences)
1017 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
1019 GtkCellLayout *cell_layout;
1020 GtkCellRenderer *renderer;
1021 GtkListStore *store;
1022 const gchar **themes;
1023 GList *adium_themes;
1026 preferences_theme_variants_setup (preferences);
1028 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1029 cell_layout = GTK_CELL_LAYOUT (combo);
1031 /* Create the model */
1032 store = gtk_list_store_new (COL_THEME_COUNT,
1033 G_TYPE_STRING, /* Display name */
1034 G_TYPE_STRING, /* Theme name */
1035 G_TYPE_BOOLEAN, /* Is an Adium theme */
1036 G_TYPE_STRING, /* Adium theme path */
1037 G_TYPE_HASH_TABLE); /* Adium theme info */
1038 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1039 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1041 /* Fill the model */
1042 themes = empathy_theme_manager_get_themes ();
1043 for (i = 0; themes[i]; i += 2) {
1044 gtk_list_store_insert_with_values (store, NULL, -1,
1045 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1046 COL_THEME_NAME, themes[i],
1047 COL_THEME_IS_ADIUM, FALSE,
1051 adium_themes = empathy_theme_manager_get_adium_themes ();
1052 while (adium_themes != NULL) {
1057 info = adium_themes->data;
1058 name = tp_asv_get_string (info, "CFBundleName");
1059 path = tp_asv_get_string (info, "path");
1061 if (name != NULL && path != NULL) {
1062 gtk_list_store_insert_with_values (store, NULL, -1,
1063 COL_THEME_VISIBLE_NAME, name,
1064 COL_THEME_NAME, "adium",
1065 COL_THEME_IS_ADIUM, TRUE,
1066 COL_THEME_ADIUM_PATH, path,
1067 COL_THEME_ADIUM_INFO, info,
1070 g_hash_table_unref (info);
1071 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1074 /* Add cell renderer */
1075 renderer = gtk_cell_renderer_text_new ();
1076 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1077 gtk_cell_layout_set_attributes (cell_layout, renderer,
1078 "text", COL_THEME_VISIBLE_NAME, NULL);
1080 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1081 g_object_unref (store);
1083 g_signal_connect (combo, "changed",
1084 G_CALLBACK (preferences_theme_changed_cb),
1087 /* Select the theme from the GSetting key and track changes */
1088 preferences_theme_notify_cb (priv->gsettings_chat,
1089 EMPATHY_PREFS_CHAT_THEME,
1091 g_signal_connect (priv->gsettings_chat,
1092 "changed::" EMPATHY_PREFS_CHAT_THEME,
1093 G_CALLBACK (preferences_theme_notify_cb),
1096 g_signal_connect (priv->gsettings_chat,
1097 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1098 G_CALLBACK (preferences_theme_notify_cb),
1103 empathy_preferences_response (GtkDialog *widget,
1106 gtk_widget_destroy (GTK_WIDGET (widget));
1110 empathy_preferences_finalize (GObject *self)
1112 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1114 g_object_unref (priv->theme_manager);
1116 g_object_unref (priv->gsettings);
1117 g_object_unref (priv->gsettings_chat);
1118 g_object_unref (priv->gsettings_call);
1119 g_object_unref (priv->gsettings_loc);
1120 g_object_unref (priv->gsettings_notify);
1121 g_object_unref (priv->gsettings_sound);
1122 g_object_unref (priv->gsettings_ui);
1123 g_object_unref (priv->gsettings_logger);
1125 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1129 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1131 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1132 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1134 dialog_class->response = empathy_preferences_response;
1136 object_class->finalize = empathy_preferences_finalize;
1138 g_type_class_add_private (object_class,
1139 sizeof (EmpathyPreferencesPriv));
1143 empathy_preferences_init (EmpathyPreferences *preferences)
1145 EmpathyPreferencesPriv *priv;
1150 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1151 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1153 gtk_dialog_add_button (GTK_DIALOG (preferences),
1154 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1156 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1157 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1158 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1159 gtk_window_set_position (GTK_WINDOW (preferences),
1160 GTK_WIN_POS_CENTER_ON_PARENT);
1161 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1163 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1164 gui = empathy_builder_get_file (filename,
1165 "notebook", &priv->notebook,
1166 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1167 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1168 "vbox_chat_theme", &priv->vbox_chat_theme,
1169 "combobox_chat_theme", &priv->combobox_chat_theme,
1170 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1171 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1172 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1173 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1174 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1175 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1176 "checkbutton_logging", &priv->checkbutton_logging,
1177 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1178 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1179 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1180 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1181 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1182 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1183 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1184 "treeview_sounds", &priv->treeview_sounds,
1185 "treeview_spell_checker", &priv->treeview_spell_checker,
1186 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1187 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1188 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1189 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1190 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1191 "call_echo_cancellation", &priv->echo_cancellation,
1195 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1196 gtk_widget_show (priv->notebook);
1198 g_object_unref (gui);
1200 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1201 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1202 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1203 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1204 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1205 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1206 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1207 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1209 /* Create chat theme preview, and track changes */
1210 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1211 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1212 G_CALLBACK (preferences_preview_theme_changed_cb),
1214 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1216 preferences_themes_setup (preferences);
1218 preferences_setup_widgets (preferences);
1220 preferences_languages_setup (preferences);
1221 preferences_languages_add (preferences);
1222 preferences_languages_load (preferences);
1224 preferences_sound_setup (preferences);
1225 preferences_sound_load (preferences);
1227 if (empathy_spell_supported ()) {
1228 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1229 gtk_widget_show (page);
1232 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1234 gtk_widget_show (page);
1236 gtk_widget_hide (page);
1240 static EmpathyPreferencesTab
1241 empathy_preferences_tab_from_string (const gchar *str)
1245 for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1247 if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1251 g_warn_if_reached ();
1256 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1258 g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1260 return empathy_preferences_tabs[tab];
1264 empathy_preferences_new (GtkWindow *parent,
1265 gboolean shell_running)
1268 EmpathyPreferencesPriv *priv;
1269 GtkWidget *notif_page;
1271 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1273 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1275 if (parent != NULL) {
1276 gtk_window_set_transient_for (GTK_WINDOW (self),
1280 /* when running in Gnome Shell we must hide these options since they
1281 * are meaningless in that context:
1282 * - 'Display incoming events in the notification area' (General->Behavior)
1283 * - 'Notifications' tab
1285 priv = GET_PRIV (self);
1286 if (shell_running) {
1287 gtk_widget_hide (priv->checkbutton_events_notif_area);
1288 notif_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook),
1289 EMPATHY_PREFERENCES_TAB_NOTIFICATIONS);
1290 gtk_widget_hide (notif_page);
1297 empathy_preferences_show_tab (EmpathyPreferences *self,
1300 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1302 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1303 empathy_preferences_tab_from_string (page));