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;
92 GtkWidget *treeview_spell_checker;
94 GtkWidget *checkbutton_location_publish;
95 GtkWidget *checkbutton_location_reduce_accuracy;
96 GtkWidget *checkbutton_location_resource_network;
97 GtkWidget *checkbutton_location_resource_cell;
98 GtkWidget *checkbutton_location_resource_gps;
100 GtkWidget *vbox_chat_theme;
101 GtkWidget *combobox_chat_theme;
102 GtkWidget *combobox_chat_theme_variant;
103 GtkWidget *hbox_chat_theme_variant;
104 GtkWidget *sw_chat_theme_preview;
105 EmpathyChatView *chat_theme_preview;
106 EmpathyThemeManager *theme_manager;
108 GSettings *gsettings;
109 GSettings *gsettings_chat;
110 GSettings *gsettings_call;
111 GSettings *gsettings_loc;
112 GSettings *gsettings_notify;
113 GSettings *gsettings_sound;
114 GSettings *gsettings_ui;
115 GSettings *gsettings_logger;
118 static void preferences_setup_widgets (EmpathyPreferences *preferences);
119 static void preferences_languages_setup (EmpathyPreferences *preferences);
120 static void preferences_languages_add (EmpathyPreferences *preferences);
121 static void preferences_languages_save (EmpathyPreferences *preferences);
122 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
126 static void preferences_languages_load (EmpathyPreferences *preferences);
127 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
131 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
133 EmpathyPreferences *preferences);
143 COL_THEME_VISIBLE_NAME,
146 COL_THEME_ADIUM_PATH,
147 COL_THEME_ADIUM_INFO,
169 /* TODO: add phone related sounds also? */
170 static SoundEventEntry sound_entries [] = {
171 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
172 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
173 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
174 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
175 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
176 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
177 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
181 preferences_setup_widgets (EmpathyPreferences *preferences)
183 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
185 g_settings_bind (priv->gsettings_notify,
186 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
187 priv->checkbutton_notifications_enabled,
189 G_SETTINGS_BIND_DEFAULT);
190 g_settings_bind (priv->gsettings_notify,
191 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
192 priv->checkbutton_notifications_disabled_away,
194 G_SETTINGS_BIND_DEFAULT);
195 g_settings_bind (priv->gsettings_notify,
196 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
197 priv->checkbutton_notifications_focus,
199 G_SETTINGS_BIND_DEFAULT);
200 g_settings_bind (priv->gsettings_notify,
201 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
202 priv->checkbutton_notifications_contact_signin,
204 G_SETTINGS_BIND_DEFAULT);
205 g_settings_bind (priv->gsettings_notify,
206 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
207 priv->checkbutton_notifications_contact_signout,
209 G_SETTINGS_BIND_DEFAULT);
211 g_settings_bind (priv->gsettings_notify,
212 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
213 priv->checkbutton_notifications_disabled_away,
215 G_SETTINGS_BIND_GET);
216 g_settings_bind (priv->gsettings_notify,
217 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
218 priv->checkbutton_notifications_focus,
220 G_SETTINGS_BIND_GET);
221 g_settings_bind (priv->gsettings_notify,
222 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
223 priv->checkbutton_notifications_contact_signin,
225 G_SETTINGS_BIND_GET);
226 g_settings_bind (priv->gsettings_notify,
227 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
228 priv->checkbutton_notifications_contact_signout,
230 G_SETTINGS_BIND_GET);
232 g_settings_bind (priv->gsettings_sound,
233 EMPATHY_PREFS_SOUNDS_ENABLED,
234 priv->checkbutton_sounds_enabled,
236 G_SETTINGS_BIND_DEFAULT);
237 g_settings_bind (priv->gsettings_sound,
238 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
239 priv->checkbutton_sounds_disabled_away,
241 G_SETTINGS_BIND_DEFAULT);
243 g_settings_bind (priv->gsettings_sound,
244 EMPATHY_PREFS_SOUNDS_ENABLED,
245 priv->checkbutton_sounds_disabled_away,
247 G_SETTINGS_BIND_GET);
248 g_settings_bind (priv->gsettings_sound,
249 EMPATHY_PREFS_SOUNDS_ENABLED,
250 priv->treeview_sounds,
252 G_SETTINGS_BIND_GET);
254 g_settings_bind (priv->gsettings_ui,
255 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
256 priv->checkbutton_separate_chat_windows,
258 G_SETTINGS_BIND_DEFAULT);
260 g_settings_bind (priv->gsettings_ui,
261 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
262 priv->checkbutton_events_notif_area,
264 G_SETTINGS_BIND_DEFAULT);
266 g_settings_bind (priv->gsettings_chat,
267 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
268 priv->checkbutton_show_smileys,
270 G_SETTINGS_BIND_DEFAULT);
271 g_settings_bind (priv->gsettings_chat,
272 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
273 priv->checkbutton_show_contacts_in_rooms,
275 G_SETTINGS_BIND_DEFAULT);
277 g_settings_bind (priv->gsettings_call,
278 EMPATHY_PREFS_CALL_SOUND_VOLUME,
279 priv->adj_call_volume,
281 G_SETTINGS_BIND_DEFAULT);
283 g_settings_bind (priv->gsettings,
284 EMPATHY_PREFS_AUTOCONNECT,
285 priv->checkbutton_autoconnect,
287 G_SETTINGS_BIND_DEFAULT);
289 g_settings_bind (priv->gsettings_loc,
290 EMPATHY_PREFS_LOCATION_PUBLISH,
291 priv->checkbutton_location_publish,
293 G_SETTINGS_BIND_DEFAULT);
295 g_settings_bind (priv->gsettings_loc,
296 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
297 priv->checkbutton_location_resource_network,
299 G_SETTINGS_BIND_DEFAULT);
300 g_settings_bind (priv->gsettings_loc,
301 EMPATHY_PREFS_LOCATION_PUBLISH,
302 priv->checkbutton_location_resource_network,
304 G_SETTINGS_BIND_GET);
306 g_settings_bind (priv->gsettings_loc,
307 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
308 priv->checkbutton_location_resource_cell,
310 G_SETTINGS_BIND_DEFAULT);
311 g_settings_bind (priv->gsettings_loc,
312 EMPATHY_PREFS_LOCATION_PUBLISH,
313 priv->checkbutton_location_resource_cell,
315 G_SETTINGS_BIND_GET);
317 g_settings_bind (priv->gsettings_loc,
318 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
319 priv->checkbutton_location_resource_gps,
321 G_SETTINGS_BIND_DEFAULT);
322 g_settings_bind (priv->gsettings_loc,
323 EMPATHY_PREFS_LOCATION_PUBLISH,
324 priv->checkbutton_location_resource_gps,
326 G_SETTINGS_BIND_GET);
328 g_settings_bind (priv->gsettings_loc,
329 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
330 priv->checkbutton_location_reduce_accuracy,
332 G_SETTINGS_BIND_DEFAULT);
333 g_settings_bind (priv->gsettings_loc,
334 EMPATHY_PREFS_LOCATION_PUBLISH,
335 priv->checkbutton_location_reduce_accuracy,
337 G_SETTINGS_BIND_GET);
339 g_settings_bind (priv->gsettings_logger,
340 EMPATHY_PREFS_LOGGER_ENABLED,
341 priv->checkbutton_logging,
343 G_SETTINGS_BIND_DEFAULT);
347 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
349 EmpathyPreferences *preferences)
351 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
359 view = GTK_TREE_VIEW (priv->treeview_sounds);
360 model = gtk_tree_view_get_model (view);
362 path = gtk_tree_path_new_from_string (path_string);
364 gtk_tree_model_get_iter (model, &iter, path);
365 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
366 COL_SOUND_ENABLED, &instore, -1);
370 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
371 COL_SOUND_ENABLED, instore, -1);
373 g_settings_set_boolean (priv->gsettings_sound, key, instore);
376 gtk_tree_path_free (path);
380 preferences_sound_load (EmpathyPreferences *preferences)
382 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
389 view = GTK_TREE_VIEW (priv->treeview_sounds);
390 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
392 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
393 set = g_settings_get_boolean (priv->gsettings_sound,
394 sound_entries[i].key);
396 gtk_list_store_insert_with_values (store, &iter, i,
397 COL_SOUND_NAME, gettext (sound_entries[i].name),
398 COL_SOUND_KEY, sound_entries[i].key,
399 COL_SOUND_ENABLED, set, -1);
404 preferences_sound_setup (EmpathyPreferences *preferences)
406 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
409 GtkCellRenderer *renderer;
410 GtkTreeViewColumn *column;
412 view = GTK_TREE_VIEW (priv->treeview_sounds);
414 store = gtk_list_store_new (COL_SOUND_COUNT,
415 G_TYPE_BOOLEAN, /* enabled */
416 G_TYPE_STRING, /* name */
417 G_TYPE_STRING); /* key */
419 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
421 renderer = gtk_cell_renderer_toggle_new ();
422 g_signal_connect (renderer, "toggled",
423 G_CALLBACK (preferences_sound_cell_toggled_cb),
426 column = gtk_tree_view_column_new ();
427 gtk_tree_view_column_pack_start (column, renderer, FALSE);
428 gtk_tree_view_column_add_attribute (column, renderer,
429 "active", COL_SOUND_ENABLED);
431 renderer = gtk_cell_renderer_text_new ();
432 gtk_tree_view_column_pack_start (column, renderer, FALSE);
433 gtk_tree_view_column_add_attribute (column, renderer,
434 "text", COL_SOUND_NAME);
436 gtk_tree_view_append_column (view, column);
438 gtk_tree_view_column_set_resizable (column, FALSE);
439 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
441 g_object_unref (store);
445 preferences_languages_setup (EmpathyPreferences *preferences)
447 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
450 GtkTreeSelection *selection;
451 GtkTreeViewColumn *column;
452 GtkCellRenderer *renderer;
455 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
457 store = gtk_list_store_new (COL_LANG_COUNT,
458 G_TYPE_BOOLEAN, /* enabled */
459 G_TYPE_STRING, /* code */
460 G_TYPE_STRING); /* name */
462 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
464 selection = gtk_tree_view_get_selection (view);
465 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
467 renderer = gtk_cell_renderer_toggle_new ();
468 g_signal_connect (renderer, "toggled",
469 G_CALLBACK (preferences_languages_cell_toggled_cb),
472 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
473 "active", COL_LANG_ENABLED,
476 gtk_tree_view_append_column (view, column);
478 renderer = gtk_cell_renderer_text_new ();
479 col_offset = gtk_tree_view_insert_column_with_attributes (view,
482 "text", COL_LANG_NAME,
485 g_object_set_data (G_OBJECT (renderer),
486 "column", GINT_TO_POINTER (COL_LANG_NAME));
488 column = gtk_tree_view_get_column (view, col_offset - 1);
489 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
490 gtk_tree_view_column_set_resizable (column, FALSE);
491 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
493 g_object_unref (store);
497 preferences_languages_add (EmpathyPreferences *preferences)
499 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
504 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
505 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
507 codes = empathy_spell_get_language_codes ();
510 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
513 for (l = codes; l; l = l->next) {
519 name = empathy_spell_get_language_name (code);
524 gtk_list_store_append (store, &iter);
525 gtk_list_store_set (store, &iter,
531 empathy_spell_free_language_codes (codes);
535 preferences_languages_save (EmpathyPreferences *preferences)
537 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
541 gchar *languages = NULL;
543 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
544 model = gtk_tree_view_get_model (view);
546 gtk_tree_model_foreach (model,
547 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
550 /* if user selects no languages, we don't want spell check */
551 g_settings_set_boolean (priv->gsettings_chat,
552 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
555 g_settings_set_string (priv->gsettings_chat,
556 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
557 languages != NULL ? languages : "");
563 preferences_languages_save_foreach (GtkTreeModel *model,
575 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
580 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
586 *languages = g_strdup (code);
588 gchar *str = *languages;
589 *languages = g_strdup_printf ("%s,%s", str, code);
599 preferences_languages_load (EmpathyPreferences *preferences)
601 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
604 GList *enabled_codes;
606 enabled_codes = empathy_spell_get_enabled_language_codes ();
608 g_settings_set_boolean (priv->gsettings_chat,
609 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
610 enabled_codes != NULL);
612 if (enabled_codes == NULL)
615 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
616 model = gtk_tree_view_get_model (view);
618 gtk_tree_model_foreach (model,
619 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
622 g_list_free (enabled_codes);
626 preferences_languages_load_foreach (GtkTreeModel *model,
632 gboolean found = FALSE;
638 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
643 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
648 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
653 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
655 EmpathyPreferences *preferences)
657 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
665 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
666 model = gtk_tree_view_get_model (view);
667 store = GTK_LIST_STORE (model);
669 path = gtk_tree_path_new_from_string (path_string);
671 gtk_tree_model_get_iter (model, &iter, path);
672 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
676 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
677 gtk_tree_path_free (path);
679 preferences_languages_save (preferences);
683 preferences_preview_theme_append_message (EmpathyChatView *view,
684 EmpathyContact *sender,
685 EmpathyContact *receiver,
688 EmpathyMessage *message;
690 message = g_object_new (EMPATHY_TYPE_MESSAGE,
692 "receiver", receiver,
696 empathy_chat_view_append_message (view, message);
697 g_object_unref (message);
701 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
702 EmpathyPreferences *preferences)
704 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
707 EmpathyContact *juliet;
708 EmpathyContact *romeo;
710 DEBUG ("Theme changed, update preview widget");
712 if (priv->chat_theme_preview != NULL) {
713 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
715 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
716 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
717 GTK_WIDGET (priv->chat_theme_preview));
718 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
720 /* FIXME: It is ugly to add a fake conversation like that.
721 * Would be cool if we could request a TplLogManager for a fake
723 dbus = tp_dbus_daemon_dup (NULL);
724 account = tp_account_new (dbus,
725 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
726 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
729 /* translators: Contact name for the chat theme preview */
730 "alias", _("Juliet"),
733 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
736 /* translators: Contact name for the chat theme preview */
741 preferences_preview_theme_append_message (priv->chat_theme_preview,
742 /* translators: Quote from Romeo & Julier, for chat theme preview */
743 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
744 preferences_preview_theme_append_message (priv->chat_theme_preview,
745 /* translators: Quote from Romeo & Julier, for chat theme preview */
746 juliet, romeo, _("Deny thy father and refuse thy name;"));
747 preferences_preview_theme_append_message (priv->chat_theme_preview,
748 /* translators: Quote from Romeo & Julier, for chat theme preview */
749 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
750 preferences_preview_theme_append_message (priv->chat_theme_preview,
751 /* translators: Quote from Romeo & Julier, for chat theme preview */
752 juliet, romeo, _("And I'll no longer be a Capulet."));
753 preferences_preview_theme_append_message (priv->chat_theme_preview,
754 /* translators: Quote from Romeo & Julier, for chat theme preview */
755 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
757 /* translators: Quote from Romeo & Julier, for chat theme preview */
758 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
760 g_object_unref (juliet);
761 g_object_unref (romeo);
762 g_object_unref (account);
763 g_object_unref (dbus);
767 preferences_theme_variant_changed_cb (GtkComboBox *combo,
768 EmpathyPreferences *preferences)
770 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
773 if (gtk_combo_box_get_active_iter (combo, &iter)) {
777 model = gtk_combo_box_get_model (combo);
778 gtk_tree_model_get (model, &iter,
779 COL_VARIANT_NAME, &name,
782 g_settings_set_string (priv->gsettings_chat,
783 EMPATHY_PREFS_CHAT_THEME_VARIANT,
791 preferences_theme_variant_notify_cb (GSettings *gsettings,
795 EmpathyPreferences *preferences = user_data;
796 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
801 GtkTreeIter default_iter;
802 gboolean found_default = FALSE;
803 gboolean found = FALSE;
806 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
807 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
808 model = gtk_combo_box_get_model (combo);
810 for (ok = gtk_tree_model_get_iter_first (model, &iter);
812 ok = gtk_tree_model_iter_next (model, &iter)) {
816 gtk_tree_model_get (model, &iter,
817 COL_VARIANT_NAME, &name,
818 COL_VARIANT_DEFAULT, &is_default,
821 if (!tp_strdiff (name, conf_name)) {
823 gtk_combo_box_set_active_iter (combo, &iter);
826 found_default = TRUE;
833 /* Fallback to the first one. */
836 gtk_combo_box_set_active_iter (combo, &default_iter);
837 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
838 gtk_combo_box_set_active_iter (combo, &iter);
846 preferences_theme_variants_fill (EmpathyPreferences *preferences,
849 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
854 const gchar *default_variant;
856 #endif /* HAVE_WEBKIT */
858 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
859 store = GTK_LIST_STORE (model);
860 gtk_list_store_clear (store);
863 variants = empathy_adium_info_get_available_variants (info);
864 default_variant = empathy_adium_info_get_default_variant (info);
865 for (i = 0; i < variants->len; i++) {
866 gchar *name = g_ptr_array_index (variants, i);
868 gtk_list_store_insert_with_values (store, NULL, -1,
869 COL_VARIANT_NAME, name,
870 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
873 #endif /* HAVE_WEBKIT */
875 /* Select the variant from the GSetting key */
876 preferences_theme_variant_notify_cb (priv->gsettings_chat,
877 EMPATHY_PREFS_CHAT_THEME_VARIANT,
882 preferences_theme_variants_setup (EmpathyPreferences *preferences)
884 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
886 GtkCellLayout *cell_layout;
887 GtkCellRenderer *renderer;
890 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
891 cell_layout = GTK_CELL_LAYOUT (combo);
893 /* Create the model */
894 store = gtk_list_store_new (COL_VARIANT_COUNT,
895 G_TYPE_STRING, /* name */
896 G_TYPE_BOOLEAN); /* is default */
897 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
898 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
900 /* Add cell renderer */
901 renderer = gtk_cell_renderer_text_new ();
902 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
903 gtk_cell_layout_set_attributes (cell_layout, renderer,
904 "text", COL_VARIANT_NAME, NULL);
906 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
907 g_object_unref (store);
909 g_signal_connect (combo, "changed",
910 G_CALLBACK (preferences_theme_variant_changed_cb),
913 /* Track changes of the GSetting key */
914 g_signal_connect (priv->gsettings_chat,
915 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
916 G_CALLBACK (preferences_theme_variant_notify_cb),
921 preferences_theme_changed_cb (GtkComboBox *combo,
922 EmpathyPreferences *preferences)
924 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
927 if (gtk_combo_box_get_active_iter (combo, &iter)) {
934 model = gtk_combo_box_get_model (combo);
935 gtk_tree_model_get (model, &iter,
936 COL_THEME_IS_ADIUM, &is_adium,
937 COL_THEME_NAME, &name,
938 COL_THEME_ADIUM_PATH, &path,
939 COL_THEME_ADIUM_INFO, &info,
942 g_settings_set_string (priv->gsettings_chat,
943 EMPATHY_PREFS_CHAT_THEME,
946 g_settings_set_string (priv->gsettings_chat,
947 EMPATHY_PREFS_CHAT_ADIUM_PATH,
949 preferences_theme_variants_fill (preferences, info);
950 gtk_widget_show (priv->hbox_chat_theme_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 preferences_call_format_volume_cb (GtkScale *scale,
1106 return g_strdup_printf ("%g%%", value);
1110 empathy_preferences_response (GtkDialog *widget,
1113 gtk_widget_destroy (GTK_WIDGET (widget));
1117 empathy_preferences_finalize (GObject *self)
1119 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1121 g_object_unref (priv->theme_manager);
1123 g_object_unref (priv->gsettings);
1124 g_object_unref (priv->gsettings_chat);
1125 g_object_unref (priv->gsettings_call);
1126 g_object_unref (priv->gsettings_loc);
1127 g_object_unref (priv->gsettings_notify);
1128 g_object_unref (priv->gsettings_sound);
1129 g_object_unref (priv->gsettings_ui);
1130 g_object_unref (priv->gsettings_logger);
1132 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1136 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1138 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1139 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1141 dialog_class->response = empathy_preferences_response;
1143 object_class->finalize = empathy_preferences_finalize;
1145 g_type_class_add_private (object_class,
1146 sizeof (EmpathyPreferencesPriv));
1150 empathy_preferences_init (EmpathyPreferences *preferences)
1152 EmpathyPreferencesPriv *priv;
1157 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1158 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1160 gtk_dialog_add_button (GTK_DIALOG (preferences),
1161 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1163 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1164 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1165 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1166 gtk_window_set_position (GTK_WINDOW (preferences),
1167 GTK_WIN_POS_CENTER_ON_PARENT);
1168 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1170 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1171 gui = empathy_builder_get_file (filename,
1172 "notebook", &priv->notebook,
1173 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1174 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1175 "vbox_chat_theme", &priv->vbox_chat_theme,
1176 "combobox_chat_theme", &priv->combobox_chat_theme,
1177 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1178 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1179 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1180 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1181 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1182 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1183 "checkbutton_logging", &priv->checkbutton_logging,
1184 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1185 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1186 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1187 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1188 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1189 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1190 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1191 "treeview_sounds", &priv->treeview_sounds,
1192 "treeview_spell_checker", &priv->treeview_spell_checker,
1193 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1194 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1195 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1196 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1197 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1198 "call_volume_scale", &priv->scale_call_volume,
1199 "call_volume_adjustment", &priv->adj_call_volume,
1203 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1204 gtk_widget_show (priv->notebook);
1206 g_object_unref (gui);
1208 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1209 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1210 priv->gsettings_call = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1211 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1212 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1213 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1214 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1215 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1217 /* Create chat theme preview, and track changes */
1218 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1219 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1220 G_CALLBACK (preferences_preview_theme_changed_cb),
1222 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1224 g_signal_connect (priv->scale_call_volume, "format-value",
1225 G_CALLBACK (preferences_call_format_volume_cb),
1228 preferences_themes_setup (preferences);
1230 preferences_setup_widgets (preferences);
1232 preferences_languages_setup (preferences);
1233 preferences_languages_add (preferences);
1234 preferences_languages_load (preferences);
1236 preferences_sound_setup (preferences);
1237 preferences_sound_load (preferences);
1239 if (empathy_spell_supported ()) {
1240 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_SPELL);
1241 gtk_widget_show (page);
1244 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), EMPATHY_PREFERENCES_TAB_LOCATION);
1246 gtk_widget_show (page);
1248 gtk_widget_hide (page);
1252 static EmpathyPreferencesTab
1253 empathy_preferences_tab_from_string (const gchar *str)
1257 for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
1259 if (!tp_strdiff (str, empathy_preferences_tabs[i]))
1263 g_warn_if_reached ();
1268 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
1270 g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
1272 return empathy_preferences_tabs[tab];
1276 empathy_preferences_new (GtkWindow *parent)
1280 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1282 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1284 if (parent != NULL) {
1285 gtk_window_set_transient_for (GTK_WINDOW (self),
1293 empathy_preferences_show_tab (EmpathyPreferences *self,
1296 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1298 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1299 empathy_preferences_tab_from_string (page));