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>
46 #include <libempathy-gtk/empathy-theme-adium.h>
49 #include "empathy-preferences.h"
51 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
52 #include <libempathy/empathy-debug.h>
54 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
56 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
58 static const gchar * empathy_preferences_tabs[] =
69 struct _EmpathyPreferencesPriv {
72 GtkWidget *checkbutton_show_smileys;
73 GtkWidget *checkbutton_show_contacts_in_rooms;
74 GtkWidget *checkbutton_separate_chat_windows;
75 GtkWidget *checkbutton_events_notif_area;
76 GtkWidget *checkbutton_autoconnect;
77 GtkWidget *checkbutton_logging;
79 GtkWidget *checkbutton_sounds_enabled;
80 GtkWidget *checkbutton_sounds_disabled_away;
81 GtkWidget *treeview_sounds;
83 GtkWidget *checkbutton_notifications_enabled;
84 GtkWidget *checkbutton_notifications_disabled_away;
85 GtkWidget *checkbutton_notifications_focus;
86 GtkWidget *checkbutton_notifications_contact_signin;
87 GtkWidget *checkbutton_notifications_contact_signout;
89 GtkWidget *scale_call_volume;
90 GtkWidget *adj_call_volume;
91 GtkWidget *echo_cancellation;
93 GtkWidget *treeview_spell_checker;
95 GtkWidget *checkbutton_location_publish;
96 GtkWidget *checkbutton_location_reduce_accuracy;
97 GtkWidget *checkbutton_location_resource_network;
98 GtkWidget *checkbutton_location_resource_cell;
99 GtkWidget *checkbutton_location_resource_gps;
101 GtkWidget *vbox_chat_theme;
102 GtkWidget *combobox_chat_theme;
103 GtkWidget *combobox_chat_theme_variant;
104 GtkWidget *hbox_chat_theme_variant;
105 GtkWidget *sw_chat_theme_preview;
106 EmpathyChatView *chat_theme_preview;
107 EmpathyThemeManager *theme_manager;
109 GSettings *gsettings;
110 GSettings *gsettings_chat;
111 GSettings *gsettings_call;
112 GSettings *gsettings_loc;
113 GSettings *gsettings_notify;
114 GSettings *gsettings_sound;
115 GSettings *gsettings_ui;
116 GSettings *gsettings_logger;
119 static void preferences_setup_widgets (EmpathyPreferences *preferences);
120 static void preferences_languages_setup (EmpathyPreferences *preferences);
121 static void preferences_languages_add (EmpathyPreferences *preferences);
122 static void preferences_languages_save (EmpathyPreferences *preferences);
123 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
127 static void preferences_languages_load (EmpathyPreferences *preferences);
128 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
132 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
134 EmpathyPreferences *preferences);
144 COL_THEME_VISIBLE_NAME,
147 COL_THEME_ADIUM_PATH,
148 COL_THEME_ADIUM_INFO,
170 /* TODO: add phone related sounds also? */
171 static SoundEventEntry sound_entries [] = {
172 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
173 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
174 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
175 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
176 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
177 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
178 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
182 preferences_setup_widgets (EmpathyPreferences *preferences)
184 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
186 g_settings_bind (priv->gsettings_notify,
187 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
188 priv->checkbutton_notifications_enabled,
190 G_SETTINGS_BIND_DEFAULT);
191 g_settings_bind (priv->gsettings_notify,
192 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
193 priv->checkbutton_notifications_disabled_away,
195 G_SETTINGS_BIND_DEFAULT);
196 g_settings_bind (priv->gsettings_notify,
197 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
198 priv->checkbutton_notifications_focus,
200 G_SETTINGS_BIND_DEFAULT);
201 g_settings_bind (priv->gsettings_notify,
202 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
203 priv->checkbutton_notifications_contact_signin,
205 G_SETTINGS_BIND_DEFAULT);
206 g_settings_bind (priv->gsettings_notify,
207 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
208 priv->checkbutton_notifications_contact_signout,
210 G_SETTINGS_BIND_DEFAULT);
212 g_settings_bind (priv->gsettings_notify,
213 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
214 priv->checkbutton_notifications_disabled_away,
216 G_SETTINGS_BIND_GET);
217 g_settings_bind (priv->gsettings_notify,
218 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
219 priv->checkbutton_notifications_focus,
221 G_SETTINGS_BIND_GET);
222 g_settings_bind (priv->gsettings_notify,
223 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
224 priv->checkbutton_notifications_contact_signin,
226 G_SETTINGS_BIND_GET);
227 g_settings_bind (priv->gsettings_notify,
228 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
229 priv->checkbutton_notifications_contact_signout,
231 G_SETTINGS_BIND_GET);
233 g_settings_bind (priv->gsettings_sound,
234 EMPATHY_PREFS_SOUNDS_ENABLED,
235 priv->checkbutton_sounds_enabled,
237 G_SETTINGS_BIND_DEFAULT);
238 g_settings_bind (priv->gsettings_sound,
239 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
240 priv->checkbutton_sounds_disabled_away,
242 G_SETTINGS_BIND_DEFAULT);
244 g_settings_bind (priv->gsettings_sound,
245 EMPATHY_PREFS_SOUNDS_ENABLED,
246 priv->checkbutton_sounds_disabled_away,
248 G_SETTINGS_BIND_GET);
249 g_settings_bind (priv->gsettings_sound,
250 EMPATHY_PREFS_SOUNDS_ENABLED,
251 priv->treeview_sounds,
253 G_SETTINGS_BIND_GET);
255 g_settings_bind (priv->gsettings_ui,
256 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
257 priv->checkbutton_separate_chat_windows,
259 G_SETTINGS_BIND_DEFAULT);
261 g_settings_bind (priv->gsettings_ui,
262 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
263 priv->checkbutton_events_notif_area,
265 G_SETTINGS_BIND_DEFAULT);
267 g_settings_bind (priv->gsettings_chat,
268 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
269 priv->checkbutton_show_smileys,
271 G_SETTINGS_BIND_DEFAULT);
272 g_settings_bind (priv->gsettings_chat,
273 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
274 priv->checkbutton_show_contacts_in_rooms,
276 G_SETTINGS_BIND_DEFAULT);
278 g_settings_bind (priv->gsettings_call,
279 EMPATHY_PREFS_CALL_SOUND_VOLUME,
280 priv->adj_call_volume,
282 G_SETTINGS_BIND_DEFAULT);
284 g_settings_bind (priv->gsettings_call,
285 EMPATHY_PREFS_CALL_ECHO_CANCELLATION,
286 priv->echo_cancellation,
288 G_SETTINGS_BIND_DEFAULT);
290 g_settings_bind (priv->gsettings,
291 EMPATHY_PREFS_AUTOCONNECT,
292 priv->checkbutton_autoconnect,
294 G_SETTINGS_BIND_DEFAULT);
296 g_settings_bind (priv->gsettings_loc,
297 EMPATHY_PREFS_LOCATION_PUBLISH,
298 priv->checkbutton_location_publish,
300 G_SETTINGS_BIND_DEFAULT);
302 g_settings_bind (priv->gsettings_loc,
303 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
304 priv->checkbutton_location_resource_network,
306 G_SETTINGS_BIND_DEFAULT);
307 g_settings_bind (priv->gsettings_loc,
308 EMPATHY_PREFS_LOCATION_PUBLISH,
309 priv->checkbutton_location_resource_network,
311 G_SETTINGS_BIND_GET);
313 g_settings_bind (priv->gsettings_loc,
314 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
315 priv->checkbutton_location_resource_cell,
317 G_SETTINGS_BIND_DEFAULT);
318 g_settings_bind (priv->gsettings_loc,
319 EMPATHY_PREFS_LOCATION_PUBLISH,
320 priv->checkbutton_location_resource_cell,
322 G_SETTINGS_BIND_GET);
324 g_settings_bind (priv->gsettings_loc,
325 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
326 priv->checkbutton_location_resource_gps,
328 G_SETTINGS_BIND_DEFAULT);
329 g_settings_bind (priv->gsettings_loc,
330 EMPATHY_PREFS_LOCATION_PUBLISH,
331 priv->checkbutton_location_resource_gps,
333 G_SETTINGS_BIND_GET);
335 g_settings_bind (priv->gsettings_loc,
336 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
337 priv->checkbutton_location_reduce_accuracy,
339 G_SETTINGS_BIND_DEFAULT);
340 g_settings_bind (priv->gsettings_loc,
341 EMPATHY_PREFS_LOCATION_PUBLISH,
342 priv->checkbutton_location_reduce_accuracy,
344 G_SETTINGS_BIND_GET);
346 g_settings_bind (priv->gsettings_logger,
347 EMPATHY_PREFS_LOGGER_ENABLED,
348 priv->checkbutton_logging,
350 G_SETTINGS_BIND_DEFAULT);
354 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
356 EmpathyPreferences *preferences)
358 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
366 view = GTK_TREE_VIEW (priv->treeview_sounds);
367 model = gtk_tree_view_get_model (view);
369 path = gtk_tree_path_new_from_string (path_string);
371 gtk_tree_model_get_iter (model, &iter, path);
372 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
373 COL_SOUND_ENABLED, &instore, -1);
377 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
378 COL_SOUND_ENABLED, instore, -1);
380 g_settings_set_boolean (priv->gsettings_sound, key, instore);
383 gtk_tree_path_free (path);
387 preferences_sound_load (EmpathyPreferences *preferences)
389 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
396 view = GTK_TREE_VIEW (priv->treeview_sounds);
397 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
399 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
400 set = g_settings_get_boolean (priv->gsettings_sound,
401 sound_entries[i].key);
403 gtk_list_store_insert_with_values (store, &iter, i,
404 COL_SOUND_NAME, gettext (sound_entries[i].name),
405 COL_SOUND_KEY, sound_entries[i].key,
406 COL_SOUND_ENABLED, set, -1);
411 preferences_sound_setup (EmpathyPreferences *preferences)
413 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
416 GtkCellRenderer *renderer;
417 GtkTreeViewColumn *column;
419 view = GTK_TREE_VIEW (priv->treeview_sounds);
421 store = gtk_list_store_new (COL_SOUND_COUNT,
422 G_TYPE_BOOLEAN, /* enabled */
423 G_TYPE_STRING, /* name */
424 G_TYPE_STRING); /* key */
426 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
428 renderer = gtk_cell_renderer_toggle_new ();
429 g_signal_connect (renderer, "toggled",
430 G_CALLBACK (preferences_sound_cell_toggled_cb),
433 column = gtk_tree_view_column_new ();
434 gtk_tree_view_column_pack_start (column, renderer, FALSE);
435 gtk_tree_view_column_add_attribute (column, renderer,
436 "active", COL_SOUND_ENABLED);
438 renderer = gtk_cell_renderer_text_new ();
439 gtk_tree_view_column_pack_start (column, renderer, FALSE);
440 gtk_tree_view_column_add_attribute (column, renderer,
441 "text", COL_SOUND_NAME);
443 gtk_tree_view_append_column (view, column);
445 gtk_tree_view_column_set_resizable (column, FALSE);
446 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
448 g_object_unref (store);
452 preferences_languages_setup (EmpathyPreferences *preferences)
454 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
457 GtkTreeSelection *selection;
458 GtkTreeViewColumn *column;
459 GtkCellRenderer *renderer;
462 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
464 store = gtk_list_store_new (COL_LANG_COUNT,
465 G_TYPE_BOOLEAN, /* enabled */
466 G_TYPE_STRING, /* code */
467 G_TYPE_STRING); /* name */
469 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
471 selection = gtk_tree_view_get_selection (view);
472 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
474 renderer = gtk_cell_renderer_toggle_new ();
475 g_signal_connect (renderer, "toggled",
476 G_CALLBACK (preferences_languages_cell_toggled_cb),
479 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
480 "active", COL_LANG_ENABLED,
483 gtk_tree_view_append_column (view, column);
485 renderer = gtk_cell_renderer_text_new ();
486 col_offset = gtk_tree_view_insert_column_with_attributes (view,
489 "text", COL_LANG_NAME,
492 g_object_set_data (G_OBJECT (renderer),
493 "column", GINT_TO_POINTER (COL_LANG_NAME));
495 column = gtk_tree_view_get_column (view, col_offset - 1);
496 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
497 gtk_tree_view_column_set_resizable (column, FALSE);
498 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
500 g_object_unref (store);
504 preferences_languages_add (EmpathyPreferences *preferences)
506 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
511 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
512 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
514 codes = empathy_spell_get_language_codes ();
517 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
520 for (l = codes; l; l = l->next) {
526 name = empathy_spell_get_language_name (code);
531 gtk_list_store_append (store, &iter);
532 gtk_list_store_set (store, &iter,
538 empathy_spell_free_language_codes (codes);
542 preferences_languages_save (EmpathyPreferences *preferences)
544 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
548 gchar *languages = NULL;
550 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
551 model = gtk_tree_view_get_model (view);
553 gtk_tree_model_foreach (model,
554 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
557 /* if user selects no languages, we don't want spell check */
558 g_settings_set_boolean (priv->gsettings_chat,
559 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
562 g_settings_set_string (priv->gsettings_chat,
563 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
564 languages != NULL ? languages : "");
570 preferences_languages_save_foreach (GtkTreeModel *model,
582 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
587 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
593 *languages = g_strdup (code);
595 gchar *str = *languages;
596 *languages = g_strdup_printf ("%s,%s", str, code);
606 preferences_languages_load (EmpathyPreferences *preferences)
608 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
611 GList *enabled_codes;
613 enabled_codes = empathy_spell_get_enabled_language_codes ();
615 g_settings_set_boolean (priv->gsettings_chat,
616 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
617 enabled_codes != NULL);
619 if (enabled_codes == NULL)
622 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
623 model = gtk_tree_view_get_model (view);
625 gtk_tree_model_foreach (model,
626 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
629 g_list_free (enabled_codes);
633 preferences_languages_load_foreach (GtkTreeModel *model,
639 gboolean found = FALSE;
645 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
650 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
655 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
660 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
662 EmpathyPreferences *preferences)
664 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
672 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
673 model = gtk_tree_view_get_model (view);
674 store = GTK_LIST_STORE (model);
676 path = gtk_tree_path_new_from_string (path_string);
678 gtk_tree_model_get_iter (model, &iter, path);
679 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
683 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
684 gtk_tree_path_free (path);
686 preferences_languages_save (preferences);
690 preferences_preview_theme_append_message (EmpathyChatView *view,
691 EmpathyContact *sender,
692 EmpathyContact *receiver,
695 EmpathyMessage *message;
697 message = g_object_new (EMPATHY_TYPE_MESSAGE,
699 "receiver", receiver,
703 empathy_chat_view_append_message (view, message);
704 g_object_unref (message);
708 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
709 EmpathyPreferences *preferences)
711 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
714 EmpathyContact *juliet;
715 EmpathyContact *romeo;
717 DEBUG ("Theme changed, update preview widget");
719 if (priv->chat_theme_preview != NULL) {
720 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
722 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
723 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
724 GTK_WIDGET (priv->chat_theme_preview));
725 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
727 /* FIXME: It is ugly to add a fake conversation like that.
728 * Would be cool if we could request a TplLogManager for a fake
730 dbus = tp_dbus_daemon_dup (NULL);
731 account = tp_account_new (dbus,
732 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
733 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
736 /* translators: Contact name for the chat theme preview */
737 "alias", _("Juliet"),
740 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
743 /* translators: Contact name for the chat theme preview */
748 preferences_preview_theme_append_message (priv->chat_theme_preview,
749 /* translators: Quote from Romeo & Julier, for chat theme preview */
750 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
751 preferences_preview_theme_append_message (priv->chat_theme_preview,
752 /* translators: Quote from Romeo & Julier, for chat theme preview */
753 juliet, romeo, _("Deny thy father and refuse thy name;"));
754 preferences_preview_theme_append_message (priv->chat_theme_preview,
755 /* translators: Quote from Romeo & Julier, for chat theme preview */
756 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
757 preferences_preview_theme_append_message (priv->chat_theme_preview,
758 /* translators: Quote from Romeo & Julier, for chat theme preview */
759 juliet, romeo, _("And I'll no longer be a Capulet."));
760 preferences_preview_theme_append_message (priv->chat_theme_preview,
761 /* translators: Quote from Romeo & Julier, for chat theme preview */
762 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
764 /* translators: Quote from Romeo & Julier, for chat theme preview */
765 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
767 g_object_unref (juliet);
768 g_object_unref (romeo);
769 g_object_unref (account);
770 g_object_unref (dbus);
774 preferences_theme_variant_changed_cb (GtkComboBox *combo,
775 EmpathyPreferences *preferences)
777 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
780 if (gtk_combo_box_get_active_iter (combo, &iter)) {
784 model = gtk_combo_box_get_model (combo);
785 gtk_tree_model_get (model, &iter,
786 COL_VARIANT_NAME, &name,
789 g_settings_set_string (priv->gsettings_chat,
790 EMPATHY_PREFS_CHAT_THEME_VARIANT,
798 preferences_theme_variant_notify_cb (GSettings *gsettings,
802 EmpathyPreferences *preferences = user_data;
803 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
808 GtkTreeIter default_iter;
809 gboolean found_default = FALSE;
810 gboolean found = FALSE;
813 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
814 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
815 model = gtk_combo_box_get_model (combo);
817 for (ok = gtk_tree_model_get_iter_first (model, &iter);
819 ok = gtk_tree_model_iter_next (model, &iter)) {
823 gtk_tree_model_get (model, &iter,
824 COL_VARIANT_NAME, &name,
825 COL_VARIANT_DEFAULT, &is_default,
828 if (!tp_strdiff (name, conf_name)) {
830 gtk_combo_box_set_active_iter (combo, &iter);
833 found_default = TRUE;
840 /* Fallback to the first one. */
843 gtk_combo_box_set_active_iter (combo, &default_iter);
844 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
845 gtk_combo_box_set_active_iter (combo, &iter);
853 preferences_theme_variants_fill (EmpathyPreferences *preferences,
856 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
861 const gchar *default_variant;
863 #endif /* HAVE_WEBKIT */
865 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
866 store = GTK_LIST_STORE (model);
867 gtk_list_store_clear (store);
870 variants = empathy_adium_info_get_available_variants (info);
871 default_variant = empathy_adium_info_get_default_variant (info);
872 for (i = 0; i < variants->len; i++) {
873 gchar *name = g_ptr_array_index (variants, i);
875 gtk_list_store_insert_with_values (store, NULL, -1,
876 COL_VARIANT_NAME, name,
877 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
880 #endif /* HAVE_WEBKIT */
882 /* Select the variant from the GSetting key */
883 preferences_theme_variant_notify_cb (priv->gsettings_chat,
884 EMPATHY_PREFS_CHAT_THEME_VARIANT,
889 preferences_theme_variants_setup (EmpathyPreferences *preferences)
891 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
893 GtkCellLayout *cell_layout;
894 GtkCellRenderer *renderer;
897 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
898 cell_layout = GTK_CELL_LAYOUT (combo);
900 /* Create the model */
901 store = gtk_list_store_new (COL_VARIANT_COUNT,
902 G_TYPE_STRING, /* name */
903 G_TYPE_BOOLEAN); /* is default */
904 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
905 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
907 /* Add cell renderer */
908 renderer = gtk_cell_renderer_text_new ();
909 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
910 gtk_cell_layout_set_attributes (cell_layout, renderer,
911 "text", COL_VARIANT_NAME, NULL);
913 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
914 g_object_unref (store);
916 g_signal_connect (combo, "changed",
917 G_CALLBACK (preferences_theme_variant_changed_cb),
920 /* Track changes of the GSetting key */
921 g_signal_connect (priv->gsettings_chat,
922 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
923 G_CALLBACK (preferences_theme_variant_notify_cb),
928 preferences_theme_changed_cb (GtkComboBox *combo,
929 EmpathyPreferences *preferences)
931 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
934 if (gtk_combo_box_get_active_iter (combo, &iter)) {
941 model = gtk_combo_box_get_model (combo);
942 gtk_tree_model_get (model, &iter,
943 COL_THEME_IS_ADIUM, &is_adium,
944 COL_THEME_NAME, &name,
945 COL_THEME_ADIUM_PATH, &path,
946 COL_THEME_ADIUM_INFO, &info,
949 g_settings_set_string (priv->gsettings_chat,
950 EMPATHY_PREFS_CHAT_THEME,
953 g_settings_set_string (priv->gsettings_chat,
954 EMPATHY_PREFS_CHAT_ADIUM_PATH,
956 preferences_theme_variants_fill (preferences, info);
957 gtk_widget_show (priv->hbox_chat_theme_variant);
959 gtk_widget_hide (priv->hbox_chat_theme_variant);
963 tp_clear_pointer (&info, g_hash_table_unref);
968 preferences_theme_notify_cb (GSettings *gsettings,
972 EmpathyPreferences *preferences = user_data;
973 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
979 gboolean found = FALSE;
982 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
983 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
985 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
986 model = gtk_combo_box_get_model (combo);
987 for (ok = gtk_tree_model_get_iter_first (model, &iter);
989 ok = gtk_tree_model_iter_next (model, &iter)) {
994 gtk_tree_model_get (model, &iter,
995 COL_THEME_IS_ADIUM, &is_adium,
996 COL_THEME_NAME, &name,
997 COL_THEME_ADIUM_PATH, &path,
1000 if (!tp_strdiff (name, conf_name) &&
1001 (!is_adium || !tp_strdiff (path, conf_path))) {
1003 gtk_combo_box_set_active_iter (combo, &iter);
1010 /* Fallback to the first one. */
1012 if (gtk_tree_model_get_iter_first (model, &iter)) {
1013 gtk_combo_box_set_active_iter (combo, &iter);
1022 preferences_themes_setup (EmpathyPreferences *preferences)
1024 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
1026 GtkCellLayout *cell_layout;
1027 GtkCellRenderer *renderer;
1028 GtkListStore *store;
1029 const gchar **themes;
1030 GList *adium_themes;
1033 preferences_theme_variants_setup (preferences);
1035 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1036 cell_layout = GTK_CELL_LAYOUT (combo);
1038 /* Create the model */
1039 store = gtk_list_store_new (COL_THEME_COUNT,
1040 G_TYPE_STRING, /* Display name */
1041 G_TYPE_STRING, /* Theme name */
1042 G_TYPE_BOOLEAN, /* Is an Adium theme */
1043 G_TYPE_STRING, /* Adium theme path */
1044 G_TYPE_HASH_TABLE); /* Adium theme info */
1045 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1046 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1048 /* Fill the model */
1049 themes = empathy_theme_manager_get_themes ();
1050 for (i = 0; themes[i]; i += 2) {
1051 gtk_list_store_insert_with_values (store, NULL, -1,
1052 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1053 COL_THEME_NAME, themes[i],
1054 COL_THEME_IS_ADIUM, FALSE,
1058 adium_themes = empathy_theme_manager_get_adium_themes ();
1059 while (adium_themes != NULL) {
1064 info = adium_themes->data;
1065 name = tp_asv_get_string (info, "CFBundleName");
1066 path = tp_asv_get_string (info, "path");
1068 if (name != NULL && path != NULL) {
1069 gtk_list_store_insert_with_values (store, NULL, -1,
1070 COL_THEME_VISIBLE_NAME, name,
1071 COL_THEME_NAME, "adium",
1072 COL_THEME_IS_ADIUM, TRUE,
1073 COL_THEME_ADIUM_PATH, path,
1074 COL_THEME_ADIUM_INFO, info,
1077 g_hash_table_unref (info);
1078 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1081 /* Add cell renderer */
1082 renderer = gtk_cell_renderer_text_new ();
1083 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1084 gtk_cell_layout_set_attributes (cell_layout, renderer,
1085 "text", COL_THEME_VISIBLE_NAME, NULL);
1087 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1088 g_object_unref (store);
1090 g_signal_connect (combo, "changed",
1091 G_CALLBACK (preferences_theme_changed_cb),
1094 /* Select the theme from the GSetting key and track changes */
1095 preferences_theme_notify_cb (priv->gsettings_chat,
1096 EMPATHY_PREFS_CHAT_THEME,
1098 g_signal_connect (priv->gsettings_chat,
1099 "changed::" EMPATHY_PREFS_CHAT_THEME,
1100 G_CALLBACK (preferences_theme_notify_cb),
1103 g_signal_connect (priv->gsettings_chat,
1104 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1105 G_CALLBACK (preferences_theme_notify_cb),
1110 preferences_call_format_volume_cb (GtkScale *scale,
1113 return g_strdup_printf ("%g%%", value);
1117 empathy_preferences_response (GtkDialog *widget,
1120 gtk_widget_destroy (GTK_WIDGET (widget));
1124 empathy_preferences_finalize (GObject *self)
1126 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1128 g_object_unref (priv->theme_manager);
1130 g_object_unref (priv->gsettings);
1131 g_object_unref (priv->gsettings_chat);
1132 g_object_unref (priv->gsettings_call);
1133 g_object_unref (priv->gsettings_loc);
1134 g_object_unref (priv->gsettings_notify);
1135 g_object_unref (priv->gsettings_sound);
1136 g_object_unref (priv->gsettings_ui);
1137 g_object_unref (priv->gsettings_logger);
1139 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1143 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1145 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1146 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1148 dialog_class->response = empathy_preferences_response;
1150 object_class->finalize = empathy_preferences_finalize;
1152 g_type_class_add_private (object_class,
1153 sizeof (EmpathyPreferencesPriv));
1157 empathy_preferences_init (EmpathyPreferences *preferences)
1159 EmpathyPreferencesPriv *priv;
1164 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1165 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1167 gtk_dialog_add_button (GTK_DIALOG (preferences),
1168 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1170 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1171 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1172 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1173 gtk_window_set_position (GTK_WINDOW (preferences),
1174 GTK_WIN_POS_CENTER_ON_PARENT);
1175 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1177 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1178 gui = empathy_builder_get_file (filename,
1179 "notebook", &priv->notebook,
1180 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1181 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1182 "vbox_chat_theme", &priv->vbox_chat_theme,
1183 "combobox_chat_theme", &priv->combobox_chat_theme,
1184 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1185 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1186 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1187 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1188 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1189 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1190 "checkbutton_logging", &priv->checkbutton_logging,
1191 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1192 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1193 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1194 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1195 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1196 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1197 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1198 "treeview_sounds", &priv->treeview_sounds,
1199 "treeview_spell_checker", &priv->treeview_spell_checker,
1200 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1201 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1202 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1203 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1204 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1205 "call_volume_scale", &priv->scale_call_volume,
1206 "call_volume_adjustment", &priv->adj_call_volume,
1207 "call_echo_cancellation", &priv->echo_cancellation,
1211 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1212 gtk_widget_show (priv->notebook);
1214 g_object_unref (gui);
1216 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1217 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1218 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1219 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1220 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1221 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1222 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1223 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1225 /* Create chat theme preview, and track changes */
1226 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1227 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1228 G_CALLBACK (preferences_preview_theme_changed_cb),
1230 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1232 g_signal_connect (priv->scale_call_volume, "format-value",
1233 G_CALLBACK (preferences_call_format_volume_cb),
1236 preferences_themes_setup (preferences);
1238 preferences_setup_widgets (preferences);
1240 preferences_languages_setup (preferences);
1241 preferences_languages_add (preferences);
1242 preferences_languages_load (preferences);
1244 preferences_sound_setup (preferences);
1245 preferences_sound_load (preferences);
1247 if (empathy_spell_supported ()) {
1248 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1249 gtk_widget_show (page);
1252 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1254 gtk_widget_show (page);
1256 gtk_widget_hide (page);
1260 static EmpathyPreferencesTab
1261 empathy_preferences_tab_from_string (const gchar *str)
1265 for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1267 if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1271 g_warn_if_reached ();
1276 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1278 g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1280 return empathy_preferences_tabs[tab];
1284 empathy_preferences_new (GtkWindow *parent)
1288 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1290 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1292 if (parent != NULL) {
1293 gtk_window_set_transient_for (GTK_WINDOW (self),
1301 empathy_preferences_show_tab (EmpathyPreferences *self,
1304 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1306 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1307 empathy_preferences_tab_from_string (page));