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>
44 #include <libempathy-gtk/empathy-theme-adium.h>
46 #include "empathy-preferences.h"
48 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
49 #include <libempathy/empathy-debug.h>
51 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
53 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
55 struct _EmpathyPreferencesPriv {
58 GtkWidget *checkbutton_show_smileys;
59 GtkWidget *checkbutton_show_contacts_in_rooms;
60 GtkWidget *checkbutton_separate_chat_windows;
61 GtkWidget *checkbutton_events_notif_area;
62 GtkWidget *checkbutton_autoconnect;
63 GtkWidget *checkbutton_logging;
65 GtkWidget *checkbutton_sounds_enabled;
66 GtkWidget *checkbutton_sounds_disabled_away;
67 GtkWidget *treeview_sounds;
69 GtkWidget *checkbutton_notifications_enabled;
70 GtkWidget *checkbutton_notifications_disabled_away;
71 GtkWidget *checkbutton_notifications_focus;
72 GtkWidget *checkbutton_notifications_contact_signin;
73 GtkWidget *checkbutton_notifications_contact_signout;
75 GtkWidget *treeview_spell_checker;
77 GtkWidget *checkbutton_location_publish;
78 GtkWidget *checkbutton_location_reduce_accuracy;
79 GtkWidget *checkbutton_location_resource_network;
80 GtkWidget *checkbutton_location_resource_cell;
81 GtkWidget *checkbutton_location_resource_gps;
83 GtkWidget *vbox_chat_theme;
84 GtkWidget *combobox_chat_theme;
85 GtkWidget *combobox_chat_theme_variant;
86 GtkWidget *hbox_chat_theme_variant;
87 GtkWidget *sw_chat_theme_preview;
88 EmpathyChatView *chat_theme_preview;
89 EmpathyThemeManager *theme_manager;
92 GSettings *gsettings_chat;
93 GSettings *gsettings_loc;
94 GSettings *gsettings_notify;
95 GSettings *gsettings_sound;
96 GSettings *gsettings_ui;
97 GSettings *gsettings_logger;
100 static void preferences_setup_widgets (EmpathyPreferences *preferences);
101 static void preferences_languages_setup (EmpathyPreferences *preferences);
102 static void preferences_languages_add (EmpathyPreferences *preferences);
103 static void preferences_languages_save (EmpathyPreferences *preferences);
104 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
108 static void preferences_languages_load (EmpathyPreferences *preferences);
109 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
113 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
115 EmpathyPreferences *preferences);
125 COL_THEME_VISIBLE_NAME,
128 COL_THEME_ADIUM_PATH,
129 COL_THEME_ADIUM_INFO,
151 /* TODO: add phone related sounds also? */
152 static SoundEventEntry sound_entries [] = {
153 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
154 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
155 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
156 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
157 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
158 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
159 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
163 preferences_setup_widgets (EmpathyPreferences *preferences)
165 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
167 g_settings_bind (priv->gsettings_notify,
168 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
169 priv->checkbutton_notifications_enabled,
171 G_SETTINGS_BIND_DEFAULT);
172 g_settings_bind (priv->gsettings_notify,
173 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
174 priv->checkbutton_notifications_disabled_away,
176 G_SETTINGS_BIND_DEFAULT);
177 g_settings_bind (priv->gsettings_notify,
178 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
179 priv->checkbutton_notifications_focus,
181 G_SETTINGS_BIND_DEFAULT);
182 g_settings_bind (priv->gsettings_notify,
183 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
184 priv->checkbutton_notifications_contact_signin,
186 G_SETTINGS_BIND_DEFAULT);
187 g_settings_bind (priv->gsettings_notify,
188 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
189 priv->checkbutton_notifications_contact_signout,
191 G_SETTINGS_BIND_DEFAULT);
193 g_settings_bind (priv->gsettings_notify,
194 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
195 priv->checkbutton_notifications_disabled_away,
197 G_SETTINGS_BIND_GET);
198 g_settings_bind (priv->gsettings_notify,
199 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
200 priv->checkbutton_notifications_focus,
202 G_SETTINGS_BIND_GET);
203 g_settings_bind (priv->gsettings_notify,
204 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
205 priv->checkbutton_notifications_contact_signin,
207 G_SETTINGS_BIND_GET);
208 g_settings_bind (priv->gsettings_notify,
209 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
210 priv->checkbutton_notifications_contact_signout,
212 G_SETTINGS_BIND_GET);
214 g_settings_bind (priv->gsettings_sound,
215 EMPATHY_PREFS_SOUNDS_ENABLED,
216 priv->checkbutton_sounds_enabled,
218 G_SETTINGS_BIND_DEFAULT);
219 g_settings_bind (priv->gsettings_sound,
220 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
221 priv->checkbutton_sounds_disabled_away,
223 G_SETTINGS_BIND_DEFAULT);
225 g_settings_bind (priv->gsettings_sound,
226 EMPATHY_PREFS_SOUNDS_ENABLED,
227 priv->checkbutton_sounds_disabled_away,
229 G_SETTINGS_BIND_GET);
230 g_settings_bind (priv->gsettings_sound,
231 EMPATHY_PREFS_SOUNDS_ENABLED,
232 priv->treeview_sounds,
234 G_SETTINGS_BIND_GET);
236 g_settings_bind (priv->gsettings_ui,
237 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
238 priv->checkbutton_separate_chat_windows,
240 G_SETTINGS_BIND_DEFAULT);
242 g_settings_bind (priv->gsettings_ui,
243 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
244 priv->checkbutton_events_notif_area,
246 G_SETTINGS_BIND_DEFAULT);
248 g_settings_bind (priv->gsettings_chat,
249 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
250 priv->checkbutton_show_smileys,
252 G_SETTINGS_BIND_DEFAULT);
253 g_settings_bind (priv->gsettings_chat,
254 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
255 priv->checkbutton_show_contacts_in_rooms,
257 G_SETTINGS_BIND_DEFAULT);
259 g_settings_bind (priv->gsettings,
260 EMPATHY_PREFS_AUTOCONNECT,
261 priv->checkbutton_autoconnect,
263 G_SETTINGS_BIND_DEFAULT);
265 g_settings_bind (priv->gsettings_loc,
266 EMPATHY_PREFS_LOCATION_PUBLISH,
267 priv->checkbutton_location_publish,
269 G_SETTINGS_BIND_DEFAULT);
271 g_settings_bind (priv->gsettings_loc,
272 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
273 priv->checkbutton_location_resource_network,
275 G_SETTINGS_BIND_DEFAULT);
276 g_settings_bind (priv->gsettings_loc,
277 EMPATHY_PREFS_LOCATION_PUBLISH,
278 priv->checkbutton_location_resource_network,
280 G_SETTINGS_BIND_GET);
282 g_settings_bind (priv->gsettings_loc,
283 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
284 priv->checkbutton_location_resource_cell,
286 G_SETTINGS_BIND_DEFAULT);
287 g_settings_bind (priv->gsettings_loc,
288 EMPATHY_PREFS_LOCATION_PUBLISH,
289 priv->checkbutton_location_resource_cell,
291 G_SETTINGS_BIND_GET);
293 g_settings_bind (priv->gsettings_loc,
294 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
295 priv->checkbutton_location_resource_gps,
297 G_SETTINGS_BIND_DEFAULT);
298 g_settings_bind (priv->gsettings_loc,
299 EMPATHY_PREFS_LOCATION_PUBLISH,
300 priv->checkbutton_location_resource_gps,
302 G_SETTINGS_BIND_GET);
304 g_settings_bind (priv->gsettings_loc,
305 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
306 priv->checkbutton_location_reduce_accuracy,
308 G_SETTINGS_BIND_DEFAULT);
309 g_settings_bind (priv->gsettings_loc,
310 EMPATHY_PREFS_LOCATION_PUBLISH,
311 priv->checkbutton_location_reduce_accuracy,
313 G_SETTINGS_BIND_GET);
315 g_settings_bind (priv->gsettings_logger,
316 EMPATHY_PREFS_LOGGER_ENABLED,
317 priv->checkbutton_logging,
319 G_SETTINGS_BIND_DEFAULT);
323 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
325 EmpathyPreferences *preferences)
327 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
335 view = GTK_TREE_VIEW (priv->treeview_sounds);
336 model = gtk_tree_view_get_model (view);
338 path = gtk_tree_path_new_from_string (path_string);
340 gtk_tree_model_get_iter (model, &iter, path);
341 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
342 COL_SOUND_ENABLED, &instore, -1);
346 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
347 COL_SOUND_ENABLED, instore, -1);
349 g_settings_set_boolean (priv->gsettings_sound, key, instore);
352 gtk_tree_path_free (path);
356 preferences_sound_load (EmpathyPreferences *preferences)
358 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
365 view = GTK_TREE_VIEW (priv->treeview_sounds);
366 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
368 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
369 set = g_settings_get_boolean (priv->gsettings_sound,
370 sound_entries[i].key);
372 gtk_list_store_insert_with_values (store, &iter, i,
373 COL_SOUND_NAME, gettext (sound_entries[i].name),
374 COL_SOUND_KEY, sound_entries[i].key,
375 COL_SOUND_ENABLED, set, -1);
380 preferences_sound_setup (EmpathyPreferences *preferences)
382 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
385 GtkCellRenderer *renderer;
386 GtkTreeViewColumn *column;
388 view = GTK_TREE_VIEW (priv->treeview_sounds);
390 store = gtk_list_store_new (COL_SOUND_COUNT,
391 G_TYPE_BOOLEAN, /* enabled */
392 G_TYPE_STRING, /* name */
393 G_TYPE_STRING); /* key */
395 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
397 renderer = gtk_cell_renderer_toggle_new ();
398 g_signal_connect (renderer, "toggled",
399 G_CALLBACK (preferences_sound_cell_toggled_cb),
402 column = gtk_tree_view_column_new ();
403 gtk_tree_view_column_pack_start (column, renderer, FALSE);
404 gtk_tree_view_column_add_attribute (column, renderer,
405 "active", COL_SOUND_ENABLED);
407 renderer = gtk_cell_renderer_text_new ();
408 gtk_tree_view_column_pack_start (column, renderer, FALSE);
409 gtk_tree_view_column_add_attribute (column, renderer,
410 "text", COL_SOUND_NAME);
412 gtk_tree_view_append_column (view, column);
414 gtk_tree_view_column_set_resizable (column, FALSE);
415 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
417 g_object_unref (store);
421 preferences_languages_setup (EmpathyPreferences *preferences)
423 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
426 GtkTreeSelection *selection;
427 GtkTreeViewColumn *column;
428 GtkCellRenderer *renderer;
431 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
433 store = gtk_list_store_new (COL_LANG_COUNT,
434 G_TYPE_BOOLEAN, /* enabled */
435 G_TYPE_STRING, /* code */
436 G_TYPE_STRING); /* name */
438 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
440 selection = gtk_tree_view_get_selection (view);
441 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
443 renderer = gtk_cell_renderer_toggle_new ();
444 g_signal_connect (renderer, "toggled",
445 G_CALLBACK (preferences_languages_cell_toggled_cb),
448 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
449 "active", COL_LANG_ENABLED,
452 gtk_tree_view_append_column (view, column);
454 renderer = gtk_cell_renderer_text_new ();
455 col_offset = gtk_tree_view_insert_column_with_attributes (view,
458 "text", COL_LANG_NAME,
461 g_object_set_data (G_OBJECT (renderer),
462 "column", GINT_TO_POINTER (COL_LANG_NAME));
464 column = gtk_tree_view_get_column (view, col_offset - 1);
465 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
466 gtk_tree_view_column_set_resizable (column, FALSE);
467 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
469 g_object_unref (store);
473 preferences_languages_add (EmpathyPreferences *preferences)
475 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
480 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
481 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
483 codes = empathy_spell_get_language_codes ();
486 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
489 for (l = codes; l; l = l->next) {
495 name = empathy_spell_get_language_name (code);
500 gtk_list_store_append (store, &iter);
501 gtk_list_store_set (store, &iter,
507 empathy_spell_free_language_codes (codes);
511 preferences_languages_save (EmpathyPreferences *preferences)
513 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
517 gchar *languages = NULL;
519 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
520 model = gtk_tree_view_get_model (view);
522 gtk_tree_model_foreach (model,
523 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
526 /* if user selects no languages, we don't want spell check */
527 g_settings_set_boolean (priv->gsettings_chat,
528 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
531 g_settings_set_string (priv->gsettings_chat,
532 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
533 languages != NULL ? languages : "");
539 preferences_languages_save_foreach (GtkTreeModel *model,
551 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
556 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
562 *languages = g_strdup (code);
564 gchar *str = *languages;
565 *languages = g_strdup_printf ("%s,%s", str, code);
575 preferences_languages_load (EmpathyPreferences *preferences)
577 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
580 GList *enabled_codes;
582 enabled_codes = empathy_spell_get_enabled_language_codes ();
584 g_settings_set_boolean (priv->gsettings_chat,
585 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
586 enabled_codes != NULL);
588 if (enabled_codes == NULL)
591 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
592 model = gtk_tree_view_get_model (view);
594 gtk_tree_model_foreach (model,
595 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
598 g_list_free (enabled_codes);
602 preferences_languages_load_foreach (GtkTreeModel *model,
608 gboolean found = FALSE;
614 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
619 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
624 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
629 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
631 EmpathyPreferences *preferences)
633 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
641 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
642 model = gtk_tree_view_get_model (view);
643 store = GTK_LIST_STORE (model);
645 path = gtk_tree_path_new_from_string (path_string);
647 gtk_tree_model_get_iter (model, &iter, path);
648 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
652 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
653 gtk_tree_path_free (path);
655 preferences_languages_save (preferences);
659 preferences_preview_theme_append_message (EmpathyChatView *view,
660 EmpathyContact *sender,
661 EmpathyContact *receiver,
664 EmpathyMessage *message;
666 message = g_object_new (EMPATHY_TYPE_MESSAGE,
668 "receiver", receiver,
672 empathy_chat_view_append_message (view, message);
673 g_object_unref (message);
677 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
678 EmpathyPreferences *preferences)
680 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
683 EmpathyContact *juliet;
684 EmpathyContact *romeo;
686 DEBUG ("Theme changed, update preview widget");
688 if (priv->chat_theme_preview != NULL) {
689 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
691 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
692 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
693 GTK_WIDGET (priv->chat_theme_preview));
694 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
696 /* FIXME: It is ugly to add a fake conversation like that.
697 * Would be cool if we could request a TplLogManager for a fake
699 dbus = tp_dbus_daemon_dup (NULL);
700 account = tp_account_new (dbus,
701 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
702 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
705 /* translators: Contact name for the chat theme preview */
706 "alias", _("Juliet"),
709 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
712 /* translators: Contact name for the chat theme preview */
717 preferences_preview_theme_append_message (priv->chat_theme_preview,
718 /* translators: Quote from Romeo & Julier, for chat theme preview */
719 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
720 preferences_preview_theme_append_message (priv->chat_theme_preview,
721 /* translators: Quote from Romeo & Julier, for chat theme preview */
722 juliet, romeo, _("Deny thy father and refuse thy name;"));
723 preferences_preview_theme_append_message (priv->chat_theme_preview,
724 /* translators: Quote from Romeo & Julier, for chat theme preview */
725 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
726 preferences_preview_theme_append_message (priv->chat_theme_preview,
727 /* translators: Quote from Romeo & Julier, for chat theme preview */
728 juliet, romeo, _("And I'll no longer be a Capulet."));
729 preferences_preview_theme_append_message (priv->chat_theme_preview,
730 /* translators: Quote from Romeo & Julier, for chat theme preview */
731 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
733 /* translators: Quote from Romeo & Julier, for chat theme preview */
734 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
736 g_object_unref (juliet);
737 g_object_unref (romeo);
738 g_object_unref (account);
739 g_object_unref (dbus);
743 preferences_theme_variant_changed_cb (GtkComboBox *combo,
744 EmpathyPreferences *preferences)
746 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
749 if (gtk_combo_box_get_active_iter (combo, &iter)) {
753 model = gtk_combo_box_get_model (combo);
754 gtk_tree_model_get (model, &iter,
755 COL_VARIANT_NAME, &name,
758 g_settings_set_string (priv->gsettings_chat,
759 EMPATHY_PREFS_CHAT_THEME_VARIANT,
767 preferences_theme_variant_notify_cb (GSettings *gsettings,
771 EmpathyPreferences *preferences = user_data;
772 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
777 GtkTreeIter default_iter;
778 gboolean found_default = FALSE;
779 gboolean found = FALSE;
782 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME_VARIANT);
783 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
784 model = gtk_combo_box_get_model (combo);
786 for (ok = gtk_tree_model_get_iter_first (model, &iter);
788 ok = gtk_tree_model_iter_next (model, &iter)) {
792 gtk_tree_model_get (model, &iter,
793 COL_VARIANT_NAME, &name,
794 COL_VARIANT_DEFAULT, &is_default,
797 if (!tp_strdiff (name, conf_name)) {
799 gtk_combo_box_set_active_iter (combo, &iter);
802 found_default = TRUE;
809 /* Fallback to the first one. */
812 gtk_combo_box_set_active_iter (combo, &default_iter);
813 } else if (gtk_tree_model_get_iter_first (model, &iter)) {
814 gtk_combo_box_set_active_iter (combo, &iter);
822 preferences_theme_variants_fill (EmpathyPreferences *preferences,
825 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
829 const gchar *default_variant;
832 model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combobox_chat_theme_variant));
833 store = GTK_LIST_STORE (model);
834 gtk_list_store_clear (store);
836 variants = empathy_adium_info_get_available_variants (info);
837 default_variant = empathy_adium_info_get_default_variant (info);
838 for (i = 0; i < variants->len; i++) {
839 gchar *name = g_ptr_array_index (variants, i);
841 gtk_list_store_insert_with_values (store, NULL, -1,
842 COL_VARIANT_NAME, name,
843 COL_VARIANT_DEFAULT, !tp_strdiff (name, default_variant),
847 /* Select the variant from the GSetting key */
848 preferences_theme_variant_notify_cb (priv->gsettings_chat,
849 EMPATHY_PREFS_CHAT_THEME_VARIANT,
854 preferences_theme_variants_setup (EmpathyPreferences *preferences)
856 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
858 GtkCellLayout *cell_layout;
859 GtkCellRenderer *renderer;
862 combo = GTK_COMBO_BOX (priv->combobox_chat_theme_variant);
863 cell_layout = GTK_CELL_LAYOUT (combo);
865 /* Create the model */
866 store = gtk_list_store_new (COL_VARIANT_COUNT,
867 G_TYPE_STRING, /* name */
868 G_TYPE_BOOLEAN); /* is default */
869 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
870 COL_VARIANT_NAME, GTK_SORT_ASCENDING);
872 /* Add cell renderer */
873 renderer = gtk_cell_renderer_text_new ();
874 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
875 gtk_cell_layout_set_attributes (cell_layout, renderer,
876 "text", COL_VARIANT_NAME, NULL);
878 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
879 g_object_unref (store);
881 g_signal_connect (combo, "changed",
882 G_CALLBACK (preferences_theme_variant_changed_cb),
885 /* Track changes of the GSetting key */
886 g_signal_connect (priv->gsettings_chat,
887 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
888 G_CALLBACK (preferences_theme_variant_notify_cb),
893 preferences_theme_changed_cb (GtkComboBox *combo,
894 EmpathyPreferences *preferences)
896 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
899 if (gtk_combo_box_get_active_iter (combo, &iter)) {
906 model = gtk_combo_box_get_model (combo);
907 gtk_tree_model_get (model, &iter,
908 COL_THEME_IS_ADIUM, &is_adium,
909 COL_THEME_NAME, &name,
910 COL_THEME_ADIUM_PATH, &path,
911 COL_THEME_ADIUM_INFO, &info,
914 g_settings_set_string (priv->gsettings_chat,
915 EMPATHY_PREFS_CHAT_THEME,
918 g_settings_set_string (priv->gsettings_chat,
919 EMPATHY_PREFS_CHAT_ADIUM_PATH,
921 preferences_theme_variants_fill (preferences, info);
922 gtk_widget_show (priv->hbox_chat_theme_variant);
924 gtk_widget_hide (priv->hbox_chat_theme_variant);
928 tp_clear_pointer (&info, g_hash_table_unref);
933 preferences_theme_notify_cb (GSettings *gsettings,
937 EmpathyPreferences *preferences = user_data;
938 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
944 gboolean found = FALSE;
947 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
948 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
950 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
951 model = gtk_combo_box_get_model (combo);
952 for (ok = gtk_tree_model_get_iter_first (model, &iter);
954 ok = gtk_tree_model_iter_next (model, &iter)) {
959 gtk_tree_model_get (model, &iter,
960 COL_THEME_IS_ADIUM, &is_adium,
961 COL_THEME_NAME, &name,
962 COL_THEME_ADIUM_PATH, &path,
965 if (!tp_strdiff (name, conf_name) &&
966 (!is_adium || !tp_strdiff (path, conf_path))) {
968 gtk_combo_box_set_active_iter (combo, &iter);
975 /* Fallback to the first one. */
977 if (gtk_tree_model_get_iter_first (model, &iter)) {
978 gtk_combo_box_set_active_iter (combo, &iter);
987 preferences_themes_setup (EmpathyPreferences *preferences)
989 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
991 GtkCellLayout *cell_layout;
992 GtkCellRenderer *renderer;
994 const gchar **themes;
998 preferences_theme_variants_setup (preferences);
1000 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
1001 cell_layout = GTK_CELL_LAYOUT (combo);
1003 /* Create the model */
1004 store = gtk_list_store_new (COL_THEME_COUNT,
1005 G_TYPE_STRING, /* Display name */
1006 G_TYPE_STRING, /* Theme name */
1007 G_TYPE_BOOLEAN, /* Is an Adium theme */
1008 G_TYPE_STRING, /* Adium theme path */
1009 G_TYPE_HASH_TABLE); /* Adium theme info */
1010 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1011 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
1013 /* Fill the model */
1014 themes = empathy_theme_manager_get_themes ();
1015 for (i = 0; themes[i]; i += 2) {
1016 gtk_list_store_insert_with_values (store, NULL, -1,
1017 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
1018 COL_THEME_NAME, themes[i],
1019 COL_THEME_IS_ADIUM, FALSE,
1023 adium_themes = empathy_theme_manager_get_adium_themes ();
1024 while (adium_themes != NULL) {
1029 info = adium_themes->data;
1030 name = tp_asv_get_string (info, "CFBundleName");
1031 path = tp_asv_get_string (info, "path");
1033 if (name != NULL && path != NULL) {
1034 gtk_list_store_insert_with_values (store, NULL, -1,
1035 COL_THEME_VISIBLE_NAME, name,
1036 COL_THEME_NAME, "adium",
1037 COL_THEME_IS_ADIUM, TRUE,
1038 COL_THEME_ADIUM_PATH, path,
1039 COL_THEME_ADIUM_INFO, info,
1042 g_hash_table_unref (info);
1043 adium_themes = g_list_delete_link (adium_themes, adium_themes);
1046 /* Add cell renderer */
1047 renderer = gtk_cell_renderer_text_new ();
1048 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
1049 gtk_cell_layout_set_attributes (cell_layout, renderer,
1050 "text", COL_THEME_VISIBLE_NAME, NULL);
1052 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
1053 g_object_unref (store);
1055 g_signal_connect (combo, "changed",
1056 G_CALLBACK (preferences_theme_changed_cb),
1059 /* Select the theme from the GSetting key and track changes */
1060 preferences_theme_notify_cb (priv->gsettings_chat,
1061 EMPATHY_PREFS_CHAT_THEME,
1063 g_signal_connect (priv->gsettings_chat,
1064 "changed::" EMPATHY_PREFS_CHAT_THEME,
1065 G_CALLBACK (preferences_theme_notify_cb),
1068 g_signal_connect (priv->gsettings_chat,
1069 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
1070 G_CALLBACK (preferences_theme_notify_cb),
1075 empathy_preferences_response (GtkDialog *widget,
1078 gtk_widget_destroy (GTK_WIDGET (widget));
1082 empathy_preferences_finalize (GObject *self)
1084 EmpathyPreferencesPriv *priv = GET_PRIV (self);
1086 g_object_unref (priv->theme_manager);
1088 g_object_unref (priv->gsettings);
1089 g_object_unref (priv->gsettings_chat);
1090 g_object_unref (priv->gsettings_loc);
1091 g_object_unref (priv->gsettings_notify);
1092 g_object_unref (priv->gsettings_sound);
1093 g_object_unref (priv->gsettings_ui);
1094 g_object_unref (priv->gsettings_logger);
1096 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
1100 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
1102 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
1103 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1105 dialog_class->response = empathy_preferences_response;
1107 object_class->finalize = empathy_preferences_finalize;
1109 g_type_class_add_private (object_class,
1110 sizeof (EmpathyPreferencesPriv));
1114 empathy_preferences_init (EmpathyPreferences *preferences)
1116 EmpathyPreferencesPriv *priv;
1121 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
1122 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
1124 gtk_dialog_add_button (GTK_DIALOG (preferences),
1125 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
1127 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
1128 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
1129 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
1130 gtk_window_set_position (GTK_WINDOW (preferences),
1131 GTK_WIN_POS_CENTER_ON_PARENT);
1132 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
1134 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
1135 gui = empathy_builder_get_file (filename,
1136 "notebook", &priv->notebook,
1137 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
1138 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
1139 "vbox_chat_theme", &priv->vbox_chat_theme,
1140 "combobox_chat_theme", &priv->combobox_chat_theme,
1141 "combobox_chat_theme_variant", &priv->combobox_chat_theme_variant,
1142 "hbox_chat_theme_variant", &priv->hbox_chat_theme_variant,
1143 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
1144 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
1145 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
1146 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
1147 "checkbutton_logging", &priv->checkbutton_logging,
1148 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
1149 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
1150 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
1151 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
1152 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
1153 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
1154 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
1155 "treeview_sounds", &priv->treeview_sounds,
1156 "treeview_spell_checker", &priv->treeview_spell_checker,
1157 "checkbutton_location_publish", &priv->checkbutton_location_publish,
1158 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
1159 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
1160 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
1161 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
1165 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
1166 gtk_widget_show (priv->notebook);
1168 g_object_unref (gui);
1170 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1171 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1172 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1173 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1174 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1175 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1176 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1178 /* Create chat theme preview, and track changes */
1179 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1180 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1181 G_CALLBACK (preferences_preview_theme_changed_cb),
1183 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1185 preferences_themes_setup (preferences);
1187 preferences_setup_widgets (preferences);
1189 preferences_languages_setup (preferences);
1190 preferences_languages_add (preferences);
1191 preferences_languages_load (preferences);
1193 preferences_sound_setup (preferences);
1194 preferences_sound_load (preferences);
1196 if (empathy_spell_supported ()) {
1197 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 2);
1198 gtk_widget_show (page);
1201 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 3);
1203 gtk_widget_show (page);
1205 gtk_widget_hide (page);
1210 empathy_preferences_new (GtkWindow *parent)
1214 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1216 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1218 if (parent != NULL) {
1219 gtk_window_set_transient_for (GTK_WINDOW (self),