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 *treeview_spell_checker;
80 GtkWidget *checkbutton_location_publish;
81 GtkWidget *checkbutton_location_reduce_accuracy;
82 GtkWidget *checkbutton_location_resource_network;
83 GtkWidget *checkbutton_location_resource_cell;
84 GtkWidget *checkbutton_location_resource_gps;
86 GtkWidget *vbox_chat_theme;
87 GtkWidget *combobox_chat_theme;
88 GtkWidget *combobox_chat_theme_variant;
89 GtkWidget *hbox_chat_theme_variant;
90 GtkWidget *sw_chat_theme_preview;
91 EmpathyChatView *chat_theme_preview;
92 EmpathyThemeManager *theme_manager;
95 GSettings *gsettings_chat;
96 GSettings *gsettings_loc;
97 GSettings *gsettings_notify;
98 GSettings *gsettings_sound;
99 GSettings *gsettings_ui;
100 GSettings *gsettings_logger;
103 static void preferences_setup_widgets (EmpathyPreferences *preferences);
104 static void preferences_languages_setup (EmpathyPreferences *preferences);
105 static void preferences_languages_add (EmpathyPreferences *preferences);
106 static void preferences_languages_save (EmpathyPreferences *preferences);
107 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
111 static void preferences_languages_load (EmpathyPreferences *preferences);
112 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
116 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
118 EmpathyPreferences *preferences);
128 COL_THEME_VISIBLE_NAME,
131 COL_THEME_ADIUM_PATH,
132 COL_THEME_ADIUM_INFO,
154 /* TODO: add phone related sounds also? */
155 static SoundEventEntry sound_entries [] = {
156 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
157 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
158 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
159 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
160 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
161 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
162 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
166 preferences_setup_widgets (EmpathyPreferences *preferences)
168 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
170 g_settings_bind (priv->gsettings_notify,
171 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
172 priv->checkbutton_notifications_enabled,
174 G_SETTINGS_BIND_DEFAULT);
175 g_settings_bind (priv->gsettings_notify,
176 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
177 priv->checkbutton_notifications_disabled_away,
179 G_SETTINGS_BIND_DEFAULT);
180 g_settings_bind (priv->gsettings_notify,
181 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
182 priv->checkbutton_notifications_focus,
184 G_SETTINGS_BIND_DEFAULT);
185 g_settings_bind (priv->gsettings_notify,
186 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
187 priv->checkbutton_notifications_contact_signin,
189 G_SETTINGS_BIND_DEFAULT);
190 g_settings_bind (priv->gsettings_notify,
191 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
192 priv->checkbutton_notifications_contact_signout,
194 G_SETTINGS_BIND_DEFAULT);
196 g_settings_bind (priv->gsettings_notify,
197 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
198 priv->checkbutton_notifications_disabled_away,
200 G_SETTINGS_BIND_GET);
201 g_settings_bind (priv->gsettings_notify,
202 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
203 priv->checkbutton_notifications_focus,
205 G_SETTINGS_BIND_GET);
206 g_settings_bind (priv->gsettings_notify,
207 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
208 priv->checkbutton_notifications_contact_signin,
210 G_SETTINGS_BIND_GET);
211 g_settings_bind (priv->gsettings_notify,
212 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
213 priv->checkbutton_notifications_contact_signout,
215 G_SETTINGS_BIND_GET);
217 g_settings_bind (priv->gsettings_sound,
218 EMPATHY_PREFS_SOUNDS_ENABLED,
219 priv->checkbutton_sounds_enabled,
221 G_SETTINGS_BIND_DEFAULT);
222 g_settings_bind (priv->gsettings_sound,
223 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
224 priv->checkbutton_sounds_disabled_away,
226 G_SETTINGS_BIND_DEFAULT);
228 g_settings_bind (priv->gsettings_sound,
229 EMPATHY_PREFS_SOUNDS_ENABLED,
230 priv->checkbutton_sounds_disabled_away,
232 G_SETTINGS_BIND_GET);
233 g_settings_bind (priv->gsettings_sound,
234 EMPATHY_PREFS_SOUNDS_ENABLED,
235 priv->treeview_sounds,
237 G_SETTINGS_BIND_GET);
239 g_settings_bind (priv->gsettings_ui,
240 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
241 priv->checkbutton_separate_chat_windows,
243 G_SETTINGS_BIND_DEFAULT);
245 g_settings_bind (priv->gsettings_ui,
246 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
247 priv->checkbutton_events_notif_area,
249 G_SETTINGS_BIND_DEFAULT);
251 g_settings_bind (priv->gsettings_chat,
252 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
253 priv->checkbutton_show_smileys,
255 G_SETTINGS_BIND_DEFAULT);
256 g_settings_bind (priv->gsettings_chat,
257 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
258 priv->checkbutton_show_contacts_in_rooms,
260 G_SETTINGS_BIND_DEFAULT);
262 g_settings_bind (priv->gsettings,
263 EMPATHY_PREFS_AUTOCONNECT,
264 priv->checkbutton_autoconnect,
266 G_SETTINGS_BIND_DEFAULT);
268 g_settings_bind (priv->gsettings_loc,
269 EMPATHY_PREFS_LOCATION_PUBLISH,
270 priv->checkbutton_location_publish,
272 G_SETTINGS_BIND_DEFAULT);
274 g_settings_bind (priv->gsettings_loc,
275 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
276 priv->checkbutton_location_resource_network,
278 G_SETTINGS_BIND_DEFAULT);
279 g_settings_bind (priv->gsettings_loc,
280 EMPATHY_PREFS_LOCATION_PUBLISH,
281 priv->checkbutton_location_resource_network,
283 G_SETTINGS_BIND_GET);
285 g_settings_bind (priv->gsettings_loc,
286 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
287 priv->checkbutton_location_resource_cell,
289 G_SETTINGS_BIND_DEFAULT);
290 g_settings_bind (priv->gsettings_loc,
291 EMPATHY_PREFS_LOCATION_PUBLISH,
292 priv->checkbutton_location_resource_cell,
294 G_SETTINGS_BIND_GET);
296 g_settings_bind (priv->gsettings_loc,
297 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
298 priv->checkbutton_location_resource_gps,
300 G_SETTINGS_BIND_DEFAULT);
301 g_settings_bind (priv->gsettings_loc,
302 EMPATHY_PREFS_LOCATION_PUBLISH,
303 priv->checkbutton_location_resource_gps,
305 G_SETTINGS_BIND_GET);
307 g_settings_bind (priv->gsettings_loc,
308 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
309 priv->checkbutton_location_reduce_accuracy,
311 G_SETTINGS_BIND_DEFAULT);
312 g_settings_bind (priv->gsettings_loc,
313 EMPATHY_PREFS_LOCATION_PUBLISH,
314 priv->checkbutton_location_reduce_accuracy,
316 G_SETTINGS_BIND_GET);
318 g_settings_bind (priv->gsettings_logger,
319 EMPATHY_PREFS_LOGGER_ENABLED,
320 priv->checkbutton_logging,
322 G_SETTINGS_BIND_DEFAULT);
326 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
328 EmpathyPreferences *preferences)
330 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
338 view = GTK_TREE_VIEW (priv->treeview_sounds);
339 model = gtk_tree_view_get_model (view);
341 path = gtk_tree_path_new_from_string (path_string);
343 gtk_tree_model_get_iter (model, &iter, path);
344 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
345 COL_SOUND_ENABLED, &instore, -1);
349 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
350 COL_SOUND_ENABLED, instore, -1);
352 g_settings_set_boolean (priv->gsettings_sound, key, instore);
355 gtk_tree_path_free (path);
359 preferences_sound_load (EmpathyPreferences *preferences)
361 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
368 view = GTK_TREE_VIEW (priv->treeview_sounds);
369 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
371 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
372 set = g_settings_get_boolean (priv->gsettings_sound,
373 sound_entries[i].key);
375 gtk_list_store_insert_with_values (store, &iter, i,
376 COL_SOUND_NAME, gettext (sound_entries[i].name),
377 COL_SOUND_KEY, sound_entries[i].key,
378 COL_SOUND_ENABLED, set, -1);
383 preferences_sound_setup (EmpathyPreferences *preferences)
385 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
388 GtkCellRenderer *renderer;
389 GtkTreeViewColumn *column;
391 view = GTK_TREE_VIEW (priv->treeview_sounds);
393 store = gtk_list_store_new (COL_SOUND_COUNT,
394 G_TYPE_BOOLEAN, /* enabled */
395 G_TYPE_STRING, /* name */
396 G_TYPE_STRING); /* key */
398 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
400 renderer = gtk_cell_renderer_toggle_new ();
401 g_signal_connect (renderer, "toggled",
402 G_CALLBACK (preferences_sound_cell_toggled_cb),
405 column = gtk_tree_view_column_new ();
406 gtk_tree_view_column_pack_start (column, renderer, FALSE);
407 gtk_tree_view_column_add_attribute (column, renderer,
408 "active", COL_SOUND_ENABLED);
410 renderer = gtk_cell_renderer_text_new ();
411 gtk_tree_view_column_pack_start (column, renderer, FALSE);
412 gtk_tree_view_column_add_attribute (column, renderer,
413 "text", COL_SOUND_NAME);
415 gtk_tree_view_append_column (view, column);
417 gtk_tree_view_column_set_resizable (column, FALSE);
418 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
420 g_object_unref (store);
424 preferences_languages_setup (EmpathyPreferences *preferences)
426 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
429 GtkTreeSelection *selection;
430 GtkTreeViewColumn *column;
431 GtkCellRenderer *renderer;
434 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
436 store = gtk_list_store_new (COL_LANG_COUNT,
437 G_TYPE_BOOLEAN, /* enabled */
438 G_TYPE_STRING, /* code */
439 G_TYPE_STRING); /* name */
441 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
443 selection = gtk_tree_view_get_selection (view);
444 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
446 renderer = gtk_cell_renderer_toggle_new ();
447 g_signal_connect (renderer, "toggled",
448 G_CALLBACK (preferences_languages_cell_toggled_cb),
451 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
452 "active", COL_LANG_ENABLED,
455 gtk_tree_view_append_column (view, column);
457 renderer = gtk_cell_renderer_text_new ();
458 col_offset = gtk_tree_view_insert_column_with_attributes (view,
461 "text", COL_LANG_NAME,
464 g_object_set_data (G_OBJECT (renderer),
465 "column", GINT_TO_POINTER (COL_LANG_NAME));
467 column = gtk_tree_view_get_column (view, col_offset - 1);
468 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
469 gtk_tree_view_column_set_resizable (column, FALSE);
470 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
472 g_object_unref (store);
476 preferences_languages_add (EmpathyPreferences *preferences)
478 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
483 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
484 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
486 codes = empathy_spell_get_language_codes ();
489 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
492 for (l = codes; l; l = l->next) {
498 name = empathy_spell_get_language_name (code);
503 gtk_list_store_append (store, &iter);
504 gtk_list_store_set (store, &iter,
510 empathy_spell_free_language_codes (codes);
514 preferences_languages_save (EmpathyPreferences *preferences)
516 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
520 gchar *languages = NULL;
522 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
523 model = gtk_tree_view_get_model (view);
525 gtk_tree_model_foreach (model,
526 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
529 /* if user selects no languages, we don't want spell check */
530 g_settings_set_boolean (priv->gsettings_chat,
531 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
534 g_settings_set_string (priv->gsettings_chat,
535 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
536 languages != NULL ? languages : "");
542 preferences_languages_save_foreach (GtkTreeModel *model,
554 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
559 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
565 *languages = g_strdup (code);
567 gchar *str = *languages;
568 *languages = g_strdup_printf ("%s,%s", str, code);
578 preferences_languages_load (EmpathyPreferences *preferences)
580 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
583 GList *enabled_codes;
585 enabled_codes = empathy_spell_get_enabled_language_codes ();
587 g_settings_set_boolean (priv->gsettings_chat,
588 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
589 enabled_codes != NULL);
591 if (enabled_codes == NULL)
594 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
595 model = gtk_tree_view_get_model (view);
597 gtk_tree_model_foreach (model,
598 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
601 g_list_free (enabled_codes);
605 preferences_languages_load_foreach (GtkTreeModel *model,
611 gboolean found = FALSE;
617 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
622 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
627 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
632 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
634 EmpathyPreferences *preferences)
636 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
644 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
645 model = gtk_tree_view_get_model (view);
646 store = GTK_LIST_STORE (model);
648 path = gtk_tree_path_new_from_string (path_string);
650 gtk_tree_model_get_iter (model, &iter, path);
651 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
655 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
656 gtk_tree_path_free (path);
658 preferences_languages_save (preferences);
662 preferences_preview_theme_append_message (EmpathyChatView *view,
663 EmpathyContact *sender,
664 EmpathyContact *receiver,
667 EmpathyMessage *message;
669 message = g_object_new (EMPATHY_TYPE_MESSAGE,
671 "receiver", receiver,
675 empathy_chat_view_append_message (view, message);
676 g_object_unref (message);
680 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
681 EmpathyPreferences *preferences)
683 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
686 EmpathyContact *juliet;
687 EmpathyContact *romeo;
689 DEBUG ("Theme changed, update preview widget");
691 if (priv->chat_theme_preview != NULL) {
692 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
694 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
695 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
696 GTK_WIDGET (priv->chat_theme_preview));
697 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
699 /* FIXME: It is ugly to add a fake conversation like that.
700 * Would be cool if we could request a TplLogManager for a fake
702 dbus = tp_dbus_daemon_dup (NULL);
703 account = tp_account_new (dbus,
704 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
705 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
708 /* translators: Contact name for the chat theme preview */
709 "alias", _("Juliet"),
712 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
715 /* translators: Contact name for the chat theme preview */
720 preferences_preview_theme_append_message (priv->chat_theme_preview,
721 /* translators: Quote from Romeo & Julier, for chat theme preview */
722 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
723 preferences_preview_theme_append_message (priv->chat_theme_preview,
724 /* translators: Quote from Romeo & Julier, for chat theme preview */
725 juliet, romeo, _("Deny thy father and refuse thy name;"));
726 preferences_preview_theme_append_message (priv->chat_theme_preview,
727 /* translators: Quote from Romeo & Julier, for chat theme preview */
728 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
729 preferences_preview_theme_append_message (priv->chat_theme_preview,
730 /* translators: Quote from Romeo & Julier, for chat theme preview */
731 juliet, romeo, _("And I'll no longer be a Capulet."));
732 preferences_preview_theme_append_message (priv->chat_theme_preview,
733 /* translators: Quote from Romeo & Julier, for chat theme preview */
734 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
736 /* translators: Quote from Romeo & Julier, for chat theme preview */
737 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
739 g_object_unref (juliet);
740 g_object_unref (romeo);
741 g_object_unref (account);
742 g_object_unref (dbus);
746 preferences_theme_variant_changed_cb (GtkComboBox *combo,
747 EmpathyPreferences *preferences)
749 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
752 if (gtk_combo_box_get_active_iter (combo, &iter)) {
756 model = gtk_combo_box_get_model (combo);
757 gtk_tree_model_get (model, &iter,
758 COL_VARIANT_NAME, &name,
761 g_settings_set_string (priv->gsettings_chat,
762 EMPATHY_PREFS_CHAT_THEME_VARIANT,
770 preferences_theme_variant_notify_cb (GSettings *gsettings,
774 EmpathyPreferences *preferences = user_data;
775 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
780 GtkTreeIter default_iter;
781 gboolean found_default = FALSE;
782 gboolean found = FALSE;
785 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
786 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
787 model = gtk_combo_box_get_model (combo);
789 for (ok = gtk_tree_model_get_iter_first (model, &iter);
791 ok = gtk_tree_model_iter_next (model, &iter)) {
795 gtk_tree_model_get (model, &iter,
796 COL_VARIANT_NAME, &name,
797 COL_VARIANT_DEFAULT, &is_default,
800 if (!tp_strdiff (name, conf_name)) {
802 gtk_combo_box_set_active_iter (combo, &iter);
805 found_default = TRUE;
812 /* Fallback to the first one. */
815 gtk_combo_box_set_active_iter (combo, &default_iter);
816 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
817 gtk_combo_box_set_active_iter (combo, &iter);
825 preferences_theme_variants_fill (EmpathyPreferences *preferences,
828 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
832 const gchar *default_variant;
835 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
836 store = GTK_LIST_STORE (model);
837 gtk_list_store_clear (store);
839 variants = empathy_adium_info_get_available_variants (info);
840 default_variant = empathy_adium_info_get_default_variant (info);
841 for (i = 0; i < variants->len; i++) {
842 gchar *name = g_ptr_array_index (variants, i);
844 gtk_list_store_insert_with_values (store, NULL, -1,
845 COL_VARIANT_NAME, name,
846 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
850 /* Select the variant from the GSetting key */
851 preferences_theme_variant_notify_cb (priv->gsettings_chat,
852 EMPATHY_PREFS_CHAT_THEME_VARIANT,
857 preferences_theme_variants_setup (EmpathyPreferences *preferences)
859 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
861 GtkCellLayout *cell_layout;
862 GtkCellRenderer *renderer;
865 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
866 cell_layout = GTK_CELL_LAYOUT (combo);
868 /* Create the model */
869 store = gtk_list_store_new (COL_VARIANT_COUNT,
870 G_TYPE_STRING, /* name */
871 G_TYPE_BOOLEAN); /* is default */
872 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
873 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
875 /* Add cell renderer */
876 renderer = gtk_cell_renderer_text_new ();
877 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
878 gtk_cell_layout_set_attributes (cell_layout, renderer,
879 "text", COL_VARIANT_NAME, NULL);
881 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
882 g_object_unref (store);
884 g_signal_connect (combo, "changed",
885 G_CALLBACK (preferences_theme_variant_changed_cb),
888 /* Track changes of the GSetting key */
889 g_signal_connect (priv->gsettings_chat,
890 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
891 G_CALLBACK (preferences_theme_variant_notify_cb),
896 preferences_theme_changed_cb (GtkComboBox *combo,
897 EmpathyPreferences *preferences)
899 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
902 if (gtk_combo_box_get_active_iter (combo, &iter)) {
909 model = gtk_combo_box_get_model (combo);
910 gtk_tree_model_get (model, &iter,
911 COL_THEME_IS_ADIUM, &is_adium,
912 COL_THEME_NAME, &name,
913 COL_THEME_ADIUM_PATH, &path,
914 COL_THEME_ADIUM_INFO, &info,
917 g_settings_set_string (priv->gsettings_chat,
918 EMPATHY_PREFS_CHAT_THEME,
921 g_settings_set_string (priv->gsettings_chat,
922 EMPATHY_PREFS_CHAT_ADIUM_PATH,
924 preferences_theme_variants_fill (preferences, info);
925 gtk_widget_show (priv->hbox_chat_theme_variant);
927 gtk_widget_hide (priv->hbox_chat_theme_variant);
931 tp_clear_pointer (&info, g_hash_table_unref);
936 preferences_theme_notify_cb (GSettings *gsettings,
940 EmpathyPreferences *preferences = user_data;
941 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
947 gboolean found = FALSE;
950 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
951 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
953 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
954 model = gtk_combo_box_get_model (combo);
955 for (ok = gtk_tree_model_get_iter_first (model, &iter);
957 ok = gtk_tree_model_iter_next (model, &iter)) {
962 gtk_tree_model_get (model, &iter,
963 COL_THEME_IS_ADIUM, &is_adium,
964 COL_THEME_NAME, &name,
965 COL_THEME_ADIUM_PATH, &path,
968 if (!tp_strdiff (name, conf_name) &&
969 (!is_adium || !tp_strdiff (path, conf_path))) {
971 gtk_combo_box_set_active_iter (combo, &iter);
978 /* Fallback to the first one. */
980 if (gtk_tree_model_get_iter_first (model, &iter)) {
981 gtk_combo_box_set_active_iter (combo, &iter);
990 preferences_themes_setup (EmpathyPreferences *preferences)
992 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
994 GtkCellLayout *cell_layout;
995 GtkCellRenderer *renderer;
997 const gchar **themes;
1001 preferences_theme_variants_setup (preferences);
1003 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1004 cell_layout = GTK_CELL_LAYOUT (combo);
1006 /* Create the model */
1007 store = gtk_list_store_new (COL_THEME_COUNT,
1008 G_TYPE_STRING, /* Display name */
1009 G_TYPE_STRING, /* Theme name */
1010 G_TYPE_BOOLEAN, /* Is an Adium theme */
1011 G_TYPE_STRING, /* Adium theme path */
1012 G_TYPE_HASH_TABLE); /* Adium theme info */
1013 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1014 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1016 /* Fill the model */
1017 themes = empathy_theme_manager_get_themes ();
1018 for (i = 0; themes[i]; i += 2) {
1019 gtk_list_store_insert_with_values (store, NULL, -1,
1020 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1021 COL_THEME_NAME, themes[i],
1022 COL_THEME_IS_ADIUM, FALSE,
1026 adium_themes = empathy_theme_manager_get_adium_themes ();
1027 while (adium_themes != NULL) {
1032 info = adium_themes->data;
1033 name = tp_asv_get_string (info, "CFBundleName");
1034 path = tp_asv_get_string (info, "path");
1036 if (name != NULL && path != NULL) {
1037 gtk_list_store_insert_with_values (store, NULL, -1,
1038 COL_THEME_VISIBLE_NAME, name,
1039 COL_THEME_NAME, "adium",
1040 COL_THEME_IS_ADIUM, TRUE,
1041 COL_THEME_ADIUM_PATH, path,
1042 COL_THEME_ADIUM_INFO, info,
1045 g_hash_table_unref (info);
1046 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1049 /* Add cell renderer */
1050 renderer = gtk_cell_renderer_text_new ();
1051 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1052 gtk_cell_layout_set_attributes (cell_layout, renderer,
1053 "text", COL_THEME_VISIBLE_NAME, NULL);
1055 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1056 g_object_unref (store);
1058 g_signal_connect (combo, "changed",
1059 G_CALLBACK (preferences_theme_changed_cb),
1062 /* Select the theme from the GSetting key and track changes */
1063 preferences_theme_notify_cb (priv->gsettings_chat,
1064 EMPATHY_PREFS_CHAT_THEME,
1066 g_signal_connect (priv->gsettings_chat,
1067 "changed::" EMPATHY_PREFS_CHAT_THEME,
1068 G_CALLBACK (preferences_theme_notify_cb),
1071 g_signal_connect (priv->gsettings_chat,
1072 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1073 G_CALLBACK (preferences_theme_notify_cb),
1078 empathy_preferences_response (GtkDialog *widget,
1081 gtk_widget_destroy (GTK_WIDGET (widget));
1085 empathy_preferences_finalize (GObject *self)
1087 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1089 g_object_unref (priv->theme_manager);
1091 g_object_unref (priv->gsettings);
1092 g_object_unref (priv->gsettings_chat);
1093 g_object_unref (priv->gsettings_loc);
1094 g_object_unref (priv->gsettings_notify);
1095 g_object_unref (priv->gsettings_sound);
1096 g_object_unref (priv->gsettings_ui);
1097 g_object_unref (priv->gsettings_logger);
1099 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1103 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1105 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1106 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1108 dialog_class->response = empathy_preferences_response;
1110 object_class->finalize = empathy_preferences_finalize;
1112 g_type_class_add_private (object_class,
1113 sizeof (EmpathyPreferencesPriv));
1117 empathy_preferences_init (EmpathyPreferences *preferences)
1119 EmpathyPreferencesPriv *priv;
1124 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1125 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1127 gtk_dialog_add_button (GTK_DIALOG (preferences),
1128 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1130 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1131 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1132 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1133 gtk_window_set_position (GTK_WINDOW (preferences),
1134 GTK_WIN_POS_CENTER_ON_PARENT);
1135 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1137 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1138 gui = empathy_builder_get_file (filename,
1139 "notebook", &priv->notebook,
1140 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1141 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1142 "vbox_chat_theme", &priv->vbox_chat_theme,
1143 "combobox_chat_theme", &priv->combobox_chat_theme,
1144 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1145 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1146 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1147 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1148 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1149 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1150 "checkbutton_logging", &priv->checkbutton_logging,
1151 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1152 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1153 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1154 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1155 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1156 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1157 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1158 "treeview_sounds", &priv->treeview_sounds,
1159 "treeview_spell_checker", &priv->treeview_spell_checker,
1160 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1161 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1162 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1163 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1164 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1168 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1169 gtk_widget_show (priv->notebook);
1171 g_object_unref (gui);
1173 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1174 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1175 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1176 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1177 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1178 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1179 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1181 /* Create chat theme preview, and track changes */
1182 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1183 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1184 G_CALLBACK (preferences_preview_theme_changed_cb),
1186 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1188 preferences_themes_setup (preferences);
1190 preferences_setup_widgets (preferences);
1192 preferences_languages_setup (preferences);
1193 preferences_languages_add (preferences);
1194 preferences_languages_load (preferences);
1196 preferences_sound_setup (preferences);
1197 preferences_sound_load (preferences);
1199 if (empathy_spell_supported ()) {
1200 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 2);
1201 gtk_widget_show (page);
1204 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 3);
1206 gtk_widget_show (page);
1208 gtk_widget_hide (page);
1213 empathy_preferences_new (GtkWindow *parent)
1217 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1219 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1221 if (parent != NULL) {
1222 gtk_window_set_transient_for (GTK_WINDOW (self),