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 struct _EmpathyPreferencesPriv {
61 GtkWidget *checkbutton_show_smileys;
62 GtkWidget *checkbutton_show_contacts_in_rooms;
63 GtkWidget *checkbutton_separate_chat_windows;
64 GtkWidget *checkbutton_events_notif_area;
65 GtkWidget *checkbutton_autoconnect;
66 GtkWidget *checkbutton_logging;
68 GtkWidget *checkbutton_sounds_enabled;
69 GtkWidget *checkbutton_sounds_disabled_away;
70 GtkWidget *treeview_sounds;
72 GtkWidget *checkbutton_notifications_enabled;
73 GtkWidget *checkbutton_notifications_disabled_away;
74 GtkWidget *checkbutton_notifications_focus;
75 GtkWidget *checkbutton_notifications_contact_signin;
76 GtkWidget *checkbutton_notifications_contact_signout;
78 GtkWidget *scale_call_volume;
79 GtkWidget *adj_call_volume;
81 GtkWidget *treeview_spell_checker;
83 GtkWidget *checkbutton_location_publish;
84 GtkWidget *checkbutton_location_reduce_accuracy;
85 GtkWidget *checkbutton_location_resource_network;
86 GtkWidget *checkbutton_location_resource_cell;
87 GtkWidget *checkbutton_location_resource_gps;
89 GtkWidget *vbox_chat_theme;
90 GtkWidget *combobox_chat_theme;
91 GtkWidget *combobox_chat_theme_variant;
92 GtkWidget *hbox_chat_theme_variant;
93 GtkWidget *sw_chat_theme_preview;
94 EmpathyChatView *chat_theme_preview;
95 EmpathyThemeManager *theme_manager;
98 GSettings *gsettings_chat;
99 GSettings *gsettings_call;
100 GSettings *gsettings_loc;
101 GSettings *gsettings_notify;
102 GSettings *gsettings_sound;
103 GSettings *gsettings_ui;
104 GSettings *gsettings_logger;
107 static void preferences_setup_widgets (EmpathyPreferences *preferences);
108 static void preferences_languages_setup (EmpathyPreferences *preferences);
109 static void preferences_languages_add (EmpathyPreferences *preferences);
110 static void preferences_languages_save (EmpathyPreferences *preferences);
111 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
115 static void preferences_languages_load (EmpathyPreferences *preferences);
116 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
120 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
122 EmpathyPreferences *preferences);
132 COL_THEME_VISIBLE_NAME,
135 COL_THEME_ADIUM_PATH,
136 COL_THEME_ADIUM_INFO,
158 /* TODO: add phone related sounds also? */
159 static SoundEventEntry sound_entries [] = {
160 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
161 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
162 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
163 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
164 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
165 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
166 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
170 preferences_setup_widgets (EmpathyPreferences *preferences)
172 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
174 g_settings_bind (priv->gsettings_notify,
175 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
176 priv->checkbutton_notifications_enabled,
178 G_SETTINGS_BIND_DEFAULT);
179 g_settings_bind (priv->gsettings_notify,
180 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
181 priv->checkbutton_notifications_disabled_away,
183 G_SETTINGS_BIND_DEFAULT);
184 g_settings_bind (priv->gsettings_notify,
185 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
186 priv->checkbutton_notifications_focus,
188 G_SETTINGS_BIND_DEFAULT);
189 g_settings_bind (priv->gsettings_notify,
190 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
191 priv->checkbutton_notifications_contact_signin,
193 G_SETTINGS_BIND_DEFAULT);
194 g_settings_bind (priv->gsettings_notify,
195 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
196 priv->checkbutton_notifications_contact_signout,
198 G_SETTINGS_BIND_DEFAULT);
200 g_settings_bind (priv->gsettings_notify,
201 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
202 priv->checkbutton_notifications_disabled_away,
204 G_SETTINGS_BIND_GET);
205 g_settings_bind (priv->gsettings_notify,
206 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
207 priv->checkbutton_notifications_focus,
209 G_SETTINGS_BIND_GET);
210 g_settings_bind (priv->gsettings_notify,
211 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
212 priv->checkbutton_notifications_contact_signin,
214 G_SETTINGS_BIND_GET);
215 g_settings_bind (priv->gsettings_notify,
216 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
217 priv->checkbutton_notifications_contact_signout,
219 G_SETTINGS_BIND_GET);
221 g_settings_bind (priv->gsettings_sound,
222 EMPATHY_PREFS_SOUNDS_ENABLED,
223 priv->checkbutton_sounds_enabled,
225 G_SETTINGS_BIND_DEFAULT);
226 g_settings_bind (priv->gsettings_sound,
227 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
228 priv->checkbutton_sounds_disabled_away,
230 G_SETTINGS_BIND_DEFAULT);
232 g_settings_bind (priv->gsettings_sound,
233 EMPATHY_PREFS_SOUNDS_ENABLED,
234 priv->checkbutton_sounds_disabled_away,
236 G_SETTINGS_BIND_GET);
237 g_settings_bind (priv->gsettings_sound,
238 EMPATHY_PREFS_SOUNDS_ENABLED,
239 priv->treeview_sounds,
241 G_SETTINGS_BIND_GET);
243 g_settings_bind (priv->gsettings_ui,
244 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
245 priv->checkbutton_separate_chat_windows,
247 G_SETTINGS_BIND_DEFAULT);
249 g_settings_bind (priv->gsettings_ui,
250 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
251 priv->checkbutton_events_notif_area,
253 G_SETTINGS_BIND_DEFAULT);
255 g_settings_bind (priv->gsettings_chat,
256 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
257 priv->checkbutton_show_smileys,
259 G_SETTINGS_BIND_DEFAULT);
260 g_settings_bind (priv->gsettings_chat,
261 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
262 priv->checkbutton_show_contacts_in_rooms,
264 G_SETTINGS_BIND_DEFAULT);
266 g_settings_bind (priv->gsettings_call,
267 EMPATHY_PREFS_CALL_SOUND_VOLUME,
268 priv->adj_call_volume,
270 G_SETTINGS_BIND_DEFAULT);
272 g_settings_bind (priv->gsettings,
273 EMPATHY_PREFS_AUTOCONNECT,
274 priv->checkbutton_autoconnect,
276 G_SETTINGS_BIND_DEFAULT);
278 g_settings_bind (priv->gsettings_loc,
279 EMPATHY_PREFS_LOCATION_PUBLISH,
280 priv->checkbutton_location_publish,
282 G_SETTINGS_BIND_DEFAULT);
284 g_settings_bind (priv->gsettings_loc,
285 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
286 priv->checkbutton_location_resource_network,
288 G_SETTINGS_BIND_DEFAULT);
289 g_settings_bind (priv->gsettings_loc,
290 EMPATHY_PREFS_LOCATION_PUBLISH,
291 priv->checkbutton_location_resource_network,
293 G_SETTINGS_BIND_GET);
295 g_settings_bind (priv->gsettings_loc,
296 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
297 priv->checkbutton_location_resource_cell,
299 G_SETTINGS_BIND_DEFAULT);
300 g_settings_bind (priv->gsettings_loc,
301 EMPATHY_PREFS_LOCATION_PUBLISH,
302 priv->checkbutton_location_resource_cell,
304 G_SETTINGS_BIND_GET);
306 g_settings_bind (priv->gsettings_loc,
307 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
308 priv->checkbutton_location_resource_gps,
310 G_SETTINGS_BIND_DEFAULT);
311 g_settings_bind (priv->gsettings_loc,
312 EMPATHY_PREFS_LOCATION_PUBLISH,
313 priv->checkbutton_location_resource_gps,
315 G_SETTINGS_BIND_GET);
317 g_settings_bind (priv->gsettings_loc,
318 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
319 priv->checkbutton_location_reduce_accuracy,
321 G_SETTINGS_BIND_DEFAULT);
322 g_settings_bind (priv->gsettings_loc,
323 EMPATHY_PREFS_LOCATION_PUBLISH,
324 priv->checkbutton_location_reduce_accuracy,
326 G_SETTINGS_BIND_GET);
328 g_settings_bind (priv->gsettings_logger,
329 EMPATHY_PREFS_LOGGER_ENABLED,
330 priv->checkbutton_logging,
332 G_SETTINGS_BIND_DEFAULT);
336 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
338 EmpathyPreferences *preferences)
340 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
348 view = GTK_TREE_VIEW (priv->treeview_sounds);
349 model = gtk_tree_view_get_model (view);
351 path = gtk_tree_path_new_from_string (path_string);
353 gtk_tree_model_get_iter (model, &iter, path);
354 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
355 COL_SOUND_ENABLED, &instore, -1);
359 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
360 COL_SOUND_ENABLED, instore, -1);
362 g_settings_set_boolean (priv->gsettings_sound, key, instore);
365 gtk_tree_path_free (path);
369 preferences_sound_load (EmpathyPreferences *preferences)
371 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
378 view = GTK_TREE_VIEW (priv->treeview_sounds);
379 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
381 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
382 set = g_settings_get_boolean (priv->gsettings_sound,
383 sound_entries[i].key);
385 gtk_list_store_insert_with_values (store, &iter, i,
386 COL_SOUND_NAME, gettext (sound_entries[i].name),
387 COL_SOUND_KEY, sound_entries[i].key,
388 COL_SOUND_ENABLED, set, -1);
393 preferences_sound_setup (EmpathyPreferences *preferences)
395 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
398 GtkCellRenderer *renderer;
399 GtkTreeViewColumn *column;
401 view = GTK_TREE_VIEW (priv->treeview_sounds);
403 store = gtk_list_store_new (COL_SOUND_COUNT,
404 G_TYPE_BOOLEAN, /* enabled */
405 G_TYPE_STRING, /* name */
406 G_TYPE_STRING); /* key */
408 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
410 renderer = gtk_cell_renderer_toggle_new ();
411 g_signal_connect (renderer, "toggled",
412 G_CALLBACK (preferences_sound_cell_toggled_cb),
415 column = gtk_tree_view_column_new ();
416 gtk_tree_view_column_pack_start (column, renderer, FALSE);
417 gtk_tree_view_column_add_attribute (column, renderer,
418 "active", COL_SOUND_ENABLED);
420 renderer = gtk_cell_renderer_text_new ();
421 gtk_tree_view_column_pack_start (column, renderer, FALSE);
422 gtk_tree_view_column_add_attribute (column, renderer,
423 "text", COL_SOUND_NAME);
425 gtk_tree_view_append_column (view, column);
427 gtk_tree_view_column_set_resizable (column, FALSE);
428 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
430 g_object_unref (store);
434 preferences_languages_setup (EmpathyPreferences *preferences)
436 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
439 GtkTreeSelection *selection;
440 GtkTreeViewColumn *column;
441 GtkCellRenderer *renderer;
444 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
446 store = gtk_list_store_new (COL_LANG_COUNT,
447 G_TYPE_BOOLEAN, /* enabled */
448 G_TYPE_STRING, /* code */
449 G_TYPE_STRING); /* name */
451 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
453 selection = gtk_tree_view_get_selection (view);
454 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
456 renderer = gtk_cell_renderer_toggle_new ();
457 g_signal_connect (renderer, "toggled",
458 G_CALLBACK (preferences_languages_cell_toggled_cb),
461 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
462 "active", COL_LANG_ENABLED,
465 gtk_tree_view_append_column (view, column);
467 renderer = gtk_cell_renderer_text_new ();
468 col_offset = gtk_tree_view_insert_column_with_attributes (view,
471 "text", COL_LANG_NAME,
474 g_object_set_data (G_OBJECT (renderer),
475 "column", GINT_TO_POINTER (COL_LANG_NAME));
477 column = gtk_tree_view_get_column (view, col_offset - 1);
478 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
479 gtk_tree_view_column_set_resizable (column, FALSE);
480 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
482 g_object_unref (store);
486 preferences_languages_add (EmpathyPreferences *preferences)
488 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
493 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
494 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
496 codes = empathy_spell_get_language_codes ();
499 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
502 for (l = codes; l; l = l->next) {
508 name = empathy_spell_get_language_name (code);
513 gtk_list_store_append (store, &iter);
514 gtk_list_store_set (store, &iter,
520 empathy_spell_free_language_codes (codes);
524 preferences_languages_save (EmpathyPreferences *preferences)
526 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
530 gchar *languages = NULL;
532 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
533 model = gtk_tree_view_get_model (view);
535 gtk_tree_model_foreach (model,
536 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
539 /* if user selects no languages, we don't want spell check */
540 g_settings_set_boolean (priv->gsettings_chat,
541 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
544 g_settings_set_string (priv->gsettings_chat,
545 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
546 languages != NULL ? languages : "");
552 preferences_languages_save_foreach (GtkTreeModel *model,
564 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
569 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
575 *languages = g_strdup (code);
577 gchar *str = *languages;
578 *languages = g_strdup_printf ("%s,%s", str, code);
588 preferences_languages_load (EmpathyPreferences *preferences)
590 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
593 GList *enabled_codes;
595 enabled_codes = empathy_spell_get_enabled_language_codes ();
597 g_settings_set_boolean (priv->gsettings_chat,
598 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
599 enabled_codes != NULL);
601 if (enabled_codes == NULL)
604 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
605 model = gtk_tree_view_get_model (view);
607 gtk_tree_model_foreach (model,
608 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
611 g_list_free (enabled_codes);
615 preferences_languages_load_foreach (GtkTreeModel *model,
621 gboolean found = FALSE;
627 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
632 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
637 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
642 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
644 EmpathyPreferences *preferences)
646 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
654 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
655 model = gtk_tree_view_get_model (view);
656 store = GTK_LIST_STORE (model);
658 path = gtk_tree_path_new_from_string (path_string);
660 gtk_tree_model_get_iter (model, &iter, path);
661 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
665 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
666 gtk_tree_path_free (path);
668 preferences_languages_save (preferences);
672 preferences_preview_theme_append_message (EmpathyChatView *view,
673 EmpathyContact *sender,
674 EmpathyContact *receiver,
677 EmpathyMessage *message;
679 message = g_object_new (EMPATHY_TYPE_MESSAGE,
681 "receiver", receiver,
685 empathy_chat_view_append_message (view, message);
686 g_object_unref (message);
690 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
691 EmpathyPreferences *preferences)
693 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
696 EmpathyContact *juliet;
697 EmpathyContact *romeo;
699 DEBUG ("Theme changed, update preview widget");
701 if (priv->chat_theme_preview != NULL) {
702 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
704 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
705 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
706 GTK_WIDGET (priv->chat_theme_preview));
707 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
709 /* FIXME: It is ugly to add a fake conversation like that.
710 * Would be cool if we could request a TplLogManager for a fake
712 dbus = tp_dbus_daemon_dup (NULL);
713 account = tp_account_new (dbus,
714 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
715 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
718 /* translators: Contact name for the chat theme preview */
719 "alias", _("Juliet"),
722 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
725 /* translators: Contact name for the chat theme preview */
730 preferences_preview_theme_append_message (priv->chat_theme_preview,
731 /* translators: Quote from Romeo & Julier, for chat theme preview */
732 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
733 preferences_preview_theme_append_message (priv->chat_theme_preview,
734 /* translators: Quote from Romeo & Julier, for chat theme preview */
735 juliet, romeo, _("Deny thy father and refuse thy name;"));
736 preferences_preview_theme_append_message (priv->chat_theme_preview,
737 /* translators: Quote from Romeo & Julier, for chat theme preview */
738 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
739 preferences_preview_theme_append_message (priv->chat_theme_preview,
740 /* translators: Quote from Romeo & Julier, for chat theme preview */
741 juliet, romeo, _("And I'll no longer be a Capulet."));
742 preferences_preview_theme_append_message (priv->chat_theme_preview,
743 /* translators: Quote from Romeo & Julier, for chat theme preview */
744 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
746 /* translators: Quote from Romeo & Julier, for chat theme preview */
747 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
749 g_object_unref (juliet);
750 g_object_unref (romeo);
751 g_object_unref (account);
752 g_object_unref (dbus);
756 preferences_theme_variant_changed_cb (GtkComboBox *combo,
757 EmpathyPreferences *preferences)
759 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
762 if (gtk_combo_box_get_active_iter (combo, &iter)) {
766 model = gtk_combo_box_get_model (combo);
767 gtk_tree_model_get (model, &iter,
768 COL_VARIANT_NAME, &name,
771 g_settings_set_string (priv->gsettings_chat,
772 EMPATHY_PREFS_CHAT_THEME_VARIANT,
780 preferences_theme_variant_notify_cb (GSettings *gsettings,
784 EmpathyPreferences *preferences = user_data;
785 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
790 GtkTreeIter default_iter;
791 gboolean found_default = FALSE;
792 gboolean found = FALSE;
795 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
796 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
797 model = gtk_combo_box_get_model (combo);
799 for (ok = gtk_tree_model_get_iter_first (model, &iter);
801 ok = gtk_tree_model_iter_next (model, &iter)) {
805 gtk_tree_model_get (model, &iter,
806 COL_VARIANT_NAME, &name,
807 COL_VARIANT_DEFAULT, &is_default,
810 if (!tp_strdiff (name, conf_name)) {
812 gtk_combo_box_set_active_iter (combo, &iter);
815 found_default = TRUE;
822 /* Fallback to the first one. */
825 gtk_combo_box_set_active_iter (combo, &default_iter);
826 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
827 gtk_combo_box_set_active_iter (combo, &iter);
835 preferences_theme_variants_fill (EmpathyPreferences *preferences,
838 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
843 const gchar *default_variant;
845 #endif /* HAVE_WEBKIT */
847 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
848 store = GTK_LIST_STORE (model);
849 gtk_list_store_clear (store);
852 variants = empathy_adium_info_get_available_variants (info);
853 default_variant = empathy_adium_info_get_default_variant (info);
854 for (i = 0; i < variants->len; i++) {
855 gchar *name = g_ptr_array_index (variants, i);
857 gtk_list_store_insert_with_values (store, NULL, -1,
858 COL_VARIANT_NAME, name,
859 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
862 #endif /* HAVE_WEBKIT */
864 /* Select the variant from the GSetting key */
865 preferences_theme_variant_notify_cb (priv->gsettings_chat,
866 EMPATHY_PREFS_CHAT_THEME_VARIANT,
871 preferences_theme_variants_setup (EmpathyPreferences *preferences)
873 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
875 GtkCellLayout *cell_layout;
876 GtkCellRenderer *renderer;
879 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
880 cell_layout = GTK_CELL_LAYOUT (combo);
882 /* Create the model */
883 store = gtk_list_store_new (COL_VARIANT_COUNT,
884 G_TYPE_STRING, /* name */
885 G_TYPE_BOOLEAN); /* is default */
886 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
887 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
889 /* Add cell renderer */
890 renderer = gtk_cell_renderer_text_new ();
891 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
892 gtk_cell_layout_set_attributes (cell_layout, renderer,
893 "text", COL_VARIANT_NAME, NULL);
895 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
896 g_object_unref (store);
898 g_signal_connect (combo, "changed",
899 G_CALLBACK (preferences_theme_variant_changed_cb),
902 /* Track changes of the GSetting key */
903 g_signal_connect (priv->gsettings_chat,
904 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
905 G_CALLBACK (preferences_theme_variant_notify_cb),
910 preferences_theme_changed_cb (GtkComboBox *combo,
911 EmpathyPreferences *preferences)
913 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
916 if (gtk_combo_box_get_active_iter (combo, &iter)) {
923 model = gtk_combo_box_get_model (combo);
924 gtk_tree_model_get (model, &iter,
925 COL_THEME_IS_ADIUM, &is_adium,
926 COL_THEME_NAME, &name,
927 COL_THEME_ADIUM_PATH, &path,
928 COL_THEME_ADIUM_INFO, &info,
931 g_settings_set_string (priv->gsettings_chat,
932 EMPATHY_PREFS_CHAT_THEME,
935 g_settings_set_string (priv->gsettings_chat,
936 EMPATHY_PREFS_CHAT_ADIUM_PATH,
938 preferences_theme_variants_fill (preferences, info);
939 gtk_widget_show (priv->hbox_chat_theme_variant);
941 gtk_widget_hide (priv->hbox_chat_theme_variant);
945 tp_clear_pointer (&info, g_hash_table_unref);
950 preferences_theme_notify_cb (GSettings *gsettings,
954 EmpathyPreferences *preferences = user_data;
955 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
961 gboolean found = FALSE;
964 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
965 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
967 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
968 model = gtk_combo_box_get_model (combo);
969 for (ok = gtk_tree_model_get_iter_first (model, &iter);
971 ok = gtk_tree_model_iter_next (model, &iter)) {
976 gtk_tree_model_get (model, &iter,
977 COL_THEME_IS_ADIUM, &is_adium,
978 COL_THEME_NAME, &name,
979 COL_THEME_ADIUM_PATH, &path,
982 if (!tp_strdiff (name, conf_name) &&
983 (!is_adium || !tp_strdiff (path, conf_path))) {
985 gtk_combo_box_set_active_iter (combo, &iter);
992 /* Fallback to the first one. */
994 if (gtk_tree_model_get_iter_first (model, &iter)) {
995 gtk_combo_box_set_active_iter (combo, &iter);
1004 preferences_themes_setup (EmpathyPreferences *preferences)
1006 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
1008 GtkCellLayout *cell_layout;
1009 GtkCellRenderer *renderer;
1010 GtkListStore *store;
1011 const gchar **themes;
1012 GList *adium_themes;
1015 preferences_theme_variants_setup (preferences);
1017 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1018 cell_layout = GTK_CELL_LAYOUT (combo);
1020 /* Create the model */
1021 store = gtk_list_store_new (COL_THEME_COUNT,
1022 G_TYPE_STRING, /* Display name */
1023 G_TYPE_STRING, /* Theme name */
1024 G_TYPE_BOOLEAN, /* Is an Adium theme */
1025 G_TYPE_STRING, /* Adium theme path */
1026 G_TYPE_HASH_TABLE); /* Adium theme info */
1027 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1028 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1030 /* Fill the model */
1031 themes = empathy_theme_manager_get_themes ();
1032 for (i = 0; themes[i]; i += 2) {
1033 gtk_list_store_insert_with_values (store, NULL, -1,
1034 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1035 COL_THEME_NAME, themes[i],
1036 COL_THEME_IS_ADIUM, FALSE,
1040 adium_themes = empathy_theme_manager_get_adium_themes ();
1041 while (adium_themes != NULL) {
1046 info = adium_themes->data;
1047 name = tp_asv_get_string (info, "CFBundleName");
1048 path = tp_asv_get_string (info, "path");
1050 if (name != NULL && path != NULL) {
1051 gtk_list_store_insert_with_values (store, NULL, -1,
1052 COL_THEME_VISIBLE_NAME, name,
1053 COL_THEME_NAME, "adium",
1054 COL_THEME_IS_ADIUM, TRUE,
1055 COL_THEME_ADIUM_PATH, path,
1056 COL_THEME_ADIUM_INFO, info,
1059 g_hash_table_unref (info);
1060 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1063 /* Add cell renderer */
1064 renderer = gtk_cell_renderer_text_new ();
1065 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1066 gtk_cell_layout_set_attributes (cell_layout, renderer,
1067 "text", COL_THEME_VISIBLE_NAME, NULL);
1069 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1070 g_object_unref (store);
1072 g_signal_connect (combo, "changed",
1073 G_CALLBACK (preferences_theme_changed_cb),
1076 /* Select the theme from the GSetting key and track changes */
1077 preferences_theme_notify_cb (priv->gsettings_chat,
1078 EMPATHY_PREFS_CHAT_THEME,
1080 g_signal_connect (priv->gsettings_chat,
1081 "changed::" EMPATHY_PREFS_CHAT_THEME,
1082 G_CALLBACK (preferences_theme_notify_cb),
1085 g_signal_connect (priv->gsettings_chat,
1086 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1087 G_CALLBACK (preferences_theme_notify_cb),
1092 preferences_call_format_volume_cb (GtkScale *scale,
1095 return g_strdup_printf ("%g%%", value);
1099 empathy_preferences_response (GtkDialog *widget,
1102 gtk_widget_destroy (GTK_WIDGET (widget));
1106 empathy_preferences_finalize (GObject *self)
1108 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1110 g_object_unref (priv->theme_manager);
1112 g_object_unref (priv->gsettings);
1113 g_object_unref (priv->gsettings_chat);
1114 g_object_unref (priv->gsettings_call);
1115 g_object_unref (priv->gsettings_loc);
1116 g_object_unref (priv->gsettings_notify);
1117 g_object_unref (priv->gsettings_sound);
1118 g_object_unref (priv->gsettings_ui);
1119 g_object_unref (priv->gsettings_logger);
1121 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1125 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1127 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1128 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1130 dialog_class->response = empathy_preferences_response;
1132 object_class->finalize = empathy_preferences_finalize;
1134 g_type_class_add_private (object_class,
1135 sizeof (EmpathyPreferencesPriv));
1139 empathy_preferences_init (EmpathyPreferences *preferences)
1141 EmpathyPreferencesPriv *priv;
1146 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1147 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1149 gtk_dialog_add_button (GTK_DIALOG (preferences),
1150 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1152 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1153 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1154 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1155 gtk_window_set_position (GTK_WINDOW (preferences),
1156 GTK_WIN_POS_CENTER_ON_PARENT);
1157 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1159 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1160 gui = empathy_builder_get_file (filename,
1161 "notebook", &priv->notebook,
1162 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1163 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1164 "vbox_chat_theme", &priv->vbox_chat_theme,
1165 "combobox_chat_theme", &priv->combobox_chat_theme,
1166 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1167 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1168 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1169 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1170 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1171 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1172 "checkbutton_logging", &priv->checkbutton_logging,
1173 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1174 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1175 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1176 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1177 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1178 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1179 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1180 "treeview_sounds", &priv->treeview_sounds,
1181 "treeview_spell_checker", &priv->treeview_spell_checker,
1182 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1183 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1184 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1185 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1186 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1187 "call_volume_scale", &priv->scale_call_volume,
1188 "call_volume_adjustment", &priv->adj_call_volume,
1192 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1193 gtk_widget_show (priv->notebook);
1195 g_object_unref (gui);
1197 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1198 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1199 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1200 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1201 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1202 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1203 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1204 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1206 /* Create chat theme preview, and track changes */
1207 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1208 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1209 G_CALLBACK (preferences_preview_theme_changed_cb),
1211 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1213 g_signal_connect (priv->scale_call_volume, "format-value",
1214 G_CALLBACK (preferences_call_format_volume_cb),
1217 preferences_themes_setup (preferences);
1219 preferences_setup_widgets (preferences);
1221 preferences_languages_setup (preferences);
1222 preferences_languages_add (preferences);
1223 preferences_languages_load (preferences);
1225 preferences_sound_setup (preferences);
1226 preferences_sound_load (preferences);
1228 if (empathy_spell_supported ()) {
1229 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 2);
1230 gtk_widget_show (page);
1233 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 3);
1235 gtk_widget_show (page);
1237 gtk_widget_hide (page);
1242 empathy_preferences_new (GtkWindow *parent)
1246 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1248 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1250 if (parent != NULL) {
1251 gtk_window_set_transient_for (GTK_WINDOW (self),