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 *sw_chat_theme_preview;
89 EmpathyChatView *chat_theme_preview;
90 EmpathyThemeManager *theme_manager;
93 GSettings *gsettings_chat;
94 GSettings *gsettings_loc;
95 GSettings *gsettings_notify;
96 GSettings *gsettings_sound;
97 GSettings *gsettings_ui;
98 GSettings *gsettings_logger;
101 static void preferences_setup_widgets (EmpathyPreferences *preferences);
102 static void preferences_languages_setup (EmpathyPreferences *preferences);
103 static void preferences_languages_add (EmpathyPreferences *preferences);
104 static void preferences_languages_save (EmpathyPreferences *preferences);
105 static gboolean preferences_languages_save_foreach (GtkTreeModel *model,
109 static void preferences_languages_load (EmpathyPreferences *preferences);
110 static gboolean preferences_languages_load_foreach (GtkTreeModel *model,
114 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
116 EmpathyPreferences *preferences);
126 COL_THEME_VISIBLE_NAME,
129 COL_THEME_ADIUM_PATH,
145 /* TODO: add phone related sounds also? */
146 static SoundEventEntry sound_entries [] = {
147 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE },
148 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE },
149 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
150 { N_("Contact goes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
151 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
152 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
153 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
157 preferences_setup_widgets (EmpathyPreferences *preferences)
159 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
161 g_settings_bind (priv->gsettings_notify,
162 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
163 priv->checkbutton_notifications_enabled,
165 G_SETTINGS_BIND_DEFAULT);
166 g_settings_bind (priv->gsettings_notify,
167 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
168 priv->checkbutton_notifications_disabled_away,
170 G_SETTINGS_BIND_DEFAULT);
171 g_settings_bind (priv->gsettings_notify,
172 EMPATHY_PREFS_NOTIFICATIONS_FOCUS,
173 priv->checkbutton_notifications_focus,
175 G_SETTINGS_BIND_DEFAULT);
176 g_settings_bind (priv->gsettings_notify,
177 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN,
178 priv->checkbutton_notifications_contact_signin,
180 G_SETTINGS_BIND_DEFAULT);
181 g_settings_bind (priv->gsettings_notify,
182 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT,
183 priv->checkbutton_notifications_contact_signout,
185 G_SETTINGS_BIND_DEFAULT);
187 g_settings_bind (priv->gsettings_notify,
188 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
189 priv->checkbutton_notifications_disabled_away,
191 G_SETTINGS_BIND_GET);
192 g_settings_bind (priv->gsettings_notify,
193 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
194 priv->checkbutton_notifications_focus,
196 G_SETTINGS_BIND_GET);
197 g_settings_bind (priv->gsettings_notify,
198 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
199 priv->checkbutton_notifications_contact_signin,
201 G_SETTINGS_BIND_GET);
202 g_settings_bind (priv->gsettings_notify,
203 EMPATHY_PREFS_NOTIFICATIONS_ENABLED,
204 priv->checkbutton_notifications_contact_signout,
206 G_SETTINGS_BIND_GET);
208 g_settings_bind (priv->gsettings_sound,
209 EMPATHY_PREFS_SOUNDS_ENABLED,
210 priv->checkbutton_sounds_enabled,
212 G_SETTINGS_BIND_DEFAULT);
213 g_settings_bind (priv->gsettings_sound,
214 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
215 priv->checkbutton_sounds_disabled_away,
217 G_SETTINGS_BIND_DEFAULT);
219 g_settings_bind (priv->gsettings_sound,
220 EMPATHY_PREFS_SOUNDS_ENABLED,
221 priv->checkbutton_sounds_disabled_away,
223 G_SETTINGS_BIND_GET);
224 g_settings_bind (priv->gsettings_sound,
225 EMPATHY_PREFS_SOUNDS_ENABLED,
226 priv->treeview_sounds,
228 G_SETTINGS_BIND_GET);
230 g_settings_bind (priv->gsettings_ui,
231 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
232 priv->checkbutton_separate_chat_windows,
234 G_SETTINGS_BIND_DEFAULT);
236 g_settings_bind (priv->gsettings_ui,
237 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA,
238 priv->checkbutton_events_notif_area,
240 G_SETTINGS_BIND_DEFAULT);
242 g_settings_bind (priv->gsettings_chat,
243 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
244 priv->checkbutton_show_smileys,
246 G_SETTINGS_BIND_DEFAULT);
247 g_settings_bind (priv->gsettings_chat,
248 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
249 priv->checkbutton_show_contacts_in_rooms,
251 G_SETTINGS_BIND_DEFAULT);
253 g_settings_bind (priv->gsettings,
254 EMPATHY_PREFS_AUTOCONNECT,
255 priv->checkbutton_autoconnect,
257 G_SETTINGS_BIND_DEFAULT);
259 g_settings_bind (priv->gsettings_loc,
260 EMPATHY_PREFS_LOCATION_PUBLISH,
261 priv->checkbutton_location_publish,
263 G_SETTINGS_BIND_DEFAULT);
265 g_settings_bind (priv->gsettings_loc,
266 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
267 priv->checkbutton_location_resource_network,
269 G_SETTINGS_BIND_DEFAULT);
270 g_settings_bind (priv->gsettings_loc,
271 EMPATHY_PREFS_LOCATION_PUBLISH,
272 priv->checkbutton_location_resource_network,
274 G_SETTINGS_BIND_GET);
276 g_settings_bind (priv->gsettings_loc,
277 EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
278 priv->checkbutton_location_resource_cell,
280 G_SETTINGS_BIND_DEFAULT);
281 g_settings_bind (priv->gsettings_loc,
282 EMPATHY_PREFS_LOCATION_PUBLISH,
283 priv->checkbutton_location_resource_cell,
285 G_SETTINGS_BIND_GET);
287 g_settings_bind (priv->gsettings_loc,
288 EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
289 priv->checkbutton_location_resource_gps,
291 G_SETTINGS_BIND_DEFAULT);
292 g_settings_bind (priv->gsettings_loc,
293 EMPATHY_PREFS_LOCATION_PUBLISH,
294 priv->checkbutton_location_resource_gps,
296 G_SETTINGS_BIND_GET);
298 g_settings_bind (priv->gsettings_loc,
299 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
300 priv->checkbutton_location_reduce_accuracy,
302 G_SETTINGS_BIND_DEFAULT);
303 g_settings_bind (priv->gsettings_loc,
304 EMPATHY_PREFS_LOCATION_PUBLISH,
305 priv->checkbutton_location_reduce_accuracy,
307 G_SETTINGS_BIND_GET);
309 g_settings_bind (priv->gsettings_logger,
310 EMPATHY_PREFS_LOGGER_ENABLED,
311 priv->checkbutton_logging,
313 G_SETTINGS_BIND_DEFAULT);
317 preferences_sound_cell_toggled_cb (GtkCellRendererToggle *toggle,
319 EmpathyPreferences *preferences)
321 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
329 view = GTK_TREE_VIEW (priv->treeview_sounds);
330 model = gtk_tree_view_get_model (view);
332 path = gtk_tree_path_new_from_string (path_string);
334 gtk_tree_model_get_iter (model, &iter, path);
335 gtk_tree_model_get (model, &iter, COL_SOUND_KEY, &key,
336 COL_SOUND_ENABLED, &instore, -1);
340 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
341 COL_SOUND_ENABLED, instore, -1);
343 g_settings_set_boolean (priv->gsettings_sound, key, instore);
346 gtk_tree_path_free (path);
350 preferences_sound_load (EmpathyPreferences *preferences)
352 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
359 view = GTK_TREE_VIEW (priv->treeview_sounds);
360 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
362 for (i = 0; i < G_N_ELEMENTS (sound_entries); i++) {
363 set = g_settings_get_boolean (priv->gsettings_sound,
364 sound_entries[i].key);
366 gtk_list_store_insert_with_values (store, &iter, i,
367 COL_SOUND_NAME, gettext (sound_entries[i].name),
368 COL_SOUND_KEY, sound_entries[i].key,
369 COL_SOUND_ENABLED, set, -1);
374 preferences_sound_setup (EmpathyPreferences *preferences)
376 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
379 GtkCellRenderer *renderer;
380 GtkTreeViewColumn *column;
382 view = GTK_TREE_VIEW (priv->treeview_sounds);
384 store = gtk_list_store_new (COL_SOUND_COUNT,
385 G_TYPE_BOOLEAN, /* enabled */
386 G_TYPE_STRING, /* name */
387 G_TYPE_STRING); /* key */
389 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
391 renderer = gtk_cell_renderer_toggle_new ();
392 g_signal_connect (renderer, "toggled",
393 G_CALLBACK (preferences_sound_cell_toggled_cb),
396 column = gtk_tree_view_column_new ();
397 gtk_tree_view_column_pack_start (column, renderer, FALSE);
398 gtk_tree_view_column_add_attribute (column, renderer,
399 "active", COL_SOUND_ENABLED);
401 renderer = gtk_cell_renderer_text_new ();
402 gtk_tree_view_column_pack_start (column, renderer, FALSE);
403 gtk_tree_view_column_add_attribute (column, renderer,
404 "text", COL_SOUND_NAME);
406 gtk_tree_view_append_column (view, column);
408 gtk_tree_view_column_set_resizable (column, FALSE);
409 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
411 g_object_unref (store);
415 preferences_languages_setup (EmpathyPreferences *preferences)
417 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
420 GtkTreeSelection *selection;
421 GtkTreeViewColumn *column;
422 GtkCellRenderer *renderer;
425 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
427 store = gtk_list_store_new (COL_LANG_COUNT,
428 G_TYPE_BOOLEAN, /* enabled */
429 G_TYPE_STRING, /* code */
430 G_TYPE_STRING); /* name */
432 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
434 selection = gtk_tree_view_get_selection (view);
435 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
437 renderer = gtk_cell_renderer_toggle_new ();
438 g_signal_connect (renderer, "toggled",
439 G_CALLBACK (preferences_languages_cell_toggled_cb),
442 column = gtk_tree_view_column_new_with_attributes (NULL, renderer,
443 "active", COL_LANG_ENABLED,
446 gtk_tree_view_append_column (view, column);
448 renderer = gtk_cell_renderer_text_new ();
449 col_offset = gtk_tree_view_insert_column_with_attributes (view,
452 "text", COL_LANG_NAME,
455 g_object_set_data (G_OBJECT (renderer),
456 "column", GINT_TO_POINTER (COL_LANG_NAME));
458 column = gtk_tree_view_get_column (view, col_offset - 1);
459 gtk_tree_view_column_set_sort_column_id (column, COL_LANG_NAME);
460 gtk_tree_view_column_set_resizable (column, FALSE);
461 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
463 g_object_unref (store);
467 preferences_languages_add (EmpathyPreferences *preferences)
469 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
474 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
475 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
477 codes = empathy_spell_get_language_codes ();
480 gtk_widget_set_sensitive (priv->treeview_spell_checker, FALSE);
483 for (l = codes; l; l = l->next) {
489 name = empathy_spell_get_language_name (code);
494 gtk_list_store_append (store, &iter);
495 gtk_list_store_set (store, &iter,
501 empathy_spell_free_language_codes (codes);
505 preferences_languages_save (EmpathyPreferences *preferences)
507 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
511 gchar *languages = NULL;
513 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
514 model = gtk_tree_view_get_model (view);
516 gtk_tree_model_foreach (model,
517 (GtkTreeModelForeachFunc) preferences_languages_save_foreach,
520 /* if user selects no languages, we don't want spell check */
521 g_settings_set_boolean (priv->gsettings_chat,
522 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
525 g_settings_set_string (priv->gsettings_chat,
526 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
527 languages != NULL ? languages : "");
533 preferences_languages_save_foreach (GtkTreeModel *model,
545 gtk_tree_model_get (model, iter, COL_LANG_ENABLED, &enabled, -1);
550 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
556 *languages = g_strdup (code);
558 gchar *str = *languages;
559 *languages = g_strdup_printf ("%s,%s", str, code);
569 preferences_languages_load (EmpathyPreferences *preferences)
571 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
574 GList *enabled_codes;
576 enabled_codes = empathy_spell_get_enabled_language_codes ();
578 g_settings_set_boolean (priv->gsettings_chat,
579 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
580 enabled_codes != NULL);
582 if (enabled_codes == NULL)
585 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
586 model = gtk_tree_view_get_model (view);
588 gtk_tree_model_foreach (model,
589 (GtkTreeModelForeachFunc) preferences_languages_load_foreach,
592 g_list_free (enabled_codes);
596 preferences_languages_load_foreach (GtkTreeModel *model,
602 gboolean found = FALSE;
608 gtk_tree_model_get (model, iter, COL_LANG_CODE, &code, -1);
613 if (g_list_find_custom (languages, code, (GCompareFunc) strcmp)) {
618 gtk_list_store_set (GTK_LIST_STORE (model), iter, COL_LANG_ENABLED, found, -1);
623 preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
625 EmpathyPreferences *preferences)
627 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
635 view = GTK_TREE_VIEW (priv->treeview_spell_checker);
636 model = gtk_tree_view_get_model (view);
637 store = GTK_LIST_STORE (model);
639 path = gtk_tree_path_new_from_string (path_string);
641 gtk_tree_model_get_iter (model, &iter, path);
642 gtk_tree_model_get (model, &iter, COL_LANG_ENABLED, &enabled, -1);
646 gtk_list_store_set (store, &iter, COL_LANG_ENABLED, enabled, -1);
647 gtk_tree_path_free (path);
649 preferences_languages_save (preferences);
653 preferences_preview_theme_append_message (EmpathyChatView *view,
654 EmpathyContact *sender,
655 EmpathyContact *receiver,
658 EmpathyMessage *message;
660 message = g_object_new (EMPATHY_TYPE_MESSAGE,
662 "receiver", receiver,
666 empathy_chat_view_append_message (view, message);
667 g_object_unref (message);
671 preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
672 EmpathyPreferences *preferences)
674 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
677 EmpathyContact *juliet;
678 EmpathyContact *romeo;
680 DEBUG ("Theme changed, update preview widget");
682 if (priv->chat_theme_preview != NULL) {
683 gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview));
685 priv->chat_theme_preview = empathy_theme_manager_create_view (manager);
686 gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview),
687 GTK_WIDGET (priv->chat_theme_preview));
688 gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview));
690 /* FIXME: It is ugly to add a fake conversation like that.
691 * Would be cool if we could request a TplLogManager for a fake
693 dbus = tp_dbus_daemon_dup (NULL);
694 account = tp_account_new (dbus,
695 TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL);
696 juliet = g_object_new (EMPATHY_TYPE_CONTACT,
699 /* translators: Contact name for the chat theme preview */
700 "alias", _("Juliet"),
703 romeo = g_object_new (EMPATHY_TYPE_CONTACT,
706 /* translators: Contact name for the chat theme preview */
711 preferences_preview_theme_append_message (priv->chat_theme_preview,
712 /* translators: Quote from Romeo & Julier, for chat theme preview */
713 juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?"));
714 preferences_preview_theme_append_message (priv->chat_theme_preview,
715 /* translators: Quote from Romeo & Julier, for chat theme preview */
716 juliet, romeo, _("Deny thy father and refuse thy name;"));
717 preferences_preview_theme_append_message (priv->chat_theme_preview,
718 /* translators: Quote from Romeo & Julier, for chat theme preview */
719 juliet, romeo, _("Or if thou wilt not, be but sworn my love"));
720 preferences_preview_theme_append_message (priv->chat_theme_preview,
721 /* translators: Quote from Romeo & Julier, for chat theme preview */
722 juliet, romeo, _("And I'll no longer be a Capulet."));
723 preferences_preview_theme_append_message (priv->chat_theme_preview,
724 /* translators: Quote from Romeo & Julier, for chat theme preview */
725 romeo, juliet, _("Shall I hear more, or shall I speak at this?"));
727 /* translators: Quote from Romeo & Julier, for chat theme preview */
728 empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
730 g_object_unref (juliet);
731 g_object_unref (romeo);
732 g_object_unref (account);
733 g_object_unref (dbus);
737 preferences_theme_changed_cb (GtkComboBox *combo,
738 EmpathyPreferences *preferences)
740 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
743 if (gtk_combo_box_get_active_iter (combo, &iter)) {
749 model = gtk_combo_box_get_model (combo);
750 gtk_tree_model_get (model, &iter,
751 COL_THEME_IS_ADIUM, &is_adium,
752 COL_THEME_NAME, &name,
753 COL_THEME_ADIUM_PATH, &path,
756 g_settings_set_string (priv->gsettings_chat,
757 EMPATHY_PREFS_CHAT_THEME,
760 g_settings_set_string (priv->gsettings_chat,
761 EMPATHY_PREFS_CHAT_ADIUM_PATH,
771 preferences_theme_notify_cb (GSettings *gsettings,
775 EmpathyPreferences *preferences = user_data;
776 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
782 gboolean found = FALSE;
785 conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME);
786 conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH);
788 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
789 model = gtk_combo_box_get_model (combo);
790 for (ok = gtk_tree_model_get_iter_first (model, &iter);
792 ok = gtk_tree_model_iter_next (model, &iter)) {
797 gtk_tree_model_get (model, &iter,
798 COL_THEME_IS_ADIUM, &is_adium,
799 COL_THEME_NAME, &name,
800 COL_THEME_ADIUM_PATH, &path,
803 if (!tp_strdiff (name, conf_name) &&
804 (!is_adium || !tp_strdiff (path, conf_path))) {
806 gtk_combo_box_set_active_iter (combo, &iter);
813 /* Fallback to the first one. */
815 if (gtk_tree_model_get_iter_first (model, &iter)) {
816 gtk_combo_box_set_active_iter (combo, &iter);
825 preferences_themes_setup (EmpathyPreferences *preferences)
827 EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
829 GtkCellLayout *cell_layout;
830 GtkCellRenderer *renderer;
832 const gchar **themes;
836 combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
837 cell_layout = GTK_CELL_LAYOUT (combo);
839 /* Create the model */
840 store = gtk_list_store_new (COL_THEME_COUNT,
841 G_TYPE_STRING, /* Display name */
842 G_TYPE_STRING, /* Theme name */
843 G_TYPE_BOOLEAN, /* Is an Adium theme */
844 G_TYPE_STRING); /* Adium theme path */
845 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
846 COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING);
849 themes = empathy_theme_manager_get_themes ();
850 for (i = 0; themes[i]; i += 2) {
851 gtk_list_store_insert_with_values (store, NULL, -1,
852 COL_THEME_VISIBLE_NAME, _(themes[i + 1]),
853 COL_THEME_NAME, themes[i],
854 COL_THEME_IS_ADIUM, FALSE,
858 adium_themes = empathy_theme_manager_get_adium_themes ();
859 while (adium_themes != NULL) {
864 info = adium_themes->data;
865 name = tp_asv_get_string (info, "CFBundleName");
866 path = tp_asv_get_string (info, "path");
868 if (name != NULL && path != NULL) {
869 gtk_list_store_insert_with_values (store, NULL, -1,
870 COL_THEME_VISIBLE_NAME, name,
871 COL_THEME_NAME, "adium",
872 COL_THEME_IS_ADIUM, TRUE,
873 COL_THEME_ADIUM_PATH, path,
876 g_hash_table_unref (info);
877 adium_themes = g_list_delete_link (adium_themes, adium_themes);
880 /* Add cell renderer */
881 renderer = gtk_cell_renderer_text_new ();
882 gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
883 gtk_cell_layout_set_attributes (cell_layout, renderer,
884 "text", COL_THEME_VISIBLE_NAME, NULL);
886 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
887 g_object_unref (store);
889 g_signal_connect (combo, "changed",
890 G_CALLBACK (preferences_theme_changed_cb),
893 /* Select the theme from the GSetting key and track changes */
894 preferences_theme_notify_cb (priv->gsettings_chat,
895 EMPATHY_PREFS_CHAT_THEME,
897 g_signal_connect (priv->gsettings_chat,
898 "changed::" EMPATHY_PREFS_CHAT_THEME,
899 G_CALLBACK (preferences_theme_notify_cb),
902 g_signal_connect (priv->gsettings_chat,
903 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
904 G_CALLBACK (preferences_theme_notify_cb),
909 empathy_preferences_response (GtkDialog *widget,
912 gtk_widget_destroy (GTK_WIDGET (widget));
916 empathy_preferences_finalize (GObject *self)
918 EmpathyPreferencesPriv *priv = GET_PRIV (self);
920 g_object_unref (priv->theme_manager);
922 g_object_unref (priv->gsettings);
923 g_object_unref (priv->gsettings_chat);
924 g_object_unref (priv->gsettings_loc);
925 g_object_unref (priv->gsettings_notify);
926 g_object_unref (priv->gsettings_sound);
927 g_object_unref (priv->gsettings_ui);
928 g_object_unref (priv->gsettings_logger);
930 G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
934 empathy_preferences_class_init (EmpathyPreferencesClass *klass)
936 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
937 GObjectClass *object_class = G_OBJECT_CLASS (klass);
939 dialog_class->response = empathy_preferences_response;
941 object_class->finalize = empathy_preferences_finalize;
943 g_type_class_add_private (object_class,
944 sizeof (EmpathyPreferencesPriv));
948 empathy_preferences_init (EmpathyPreferences *preferences)
950 EmpathyPreferencesPriv *priv;
955 priv = preferences->priv = G_TYPE_INSTANCE_GET_PRIVATE (preferences,
956 EMPATHY_TYPE_PREFERENCES, EmpathyPreferencesPriv);
958 gtk_dialog_add_button (GTK_DIALOG (preferences),
959 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
961 gtk_container_set_border_width (GTK_CONTAINER (preferences), 5);
962 gtk_window_set_title (GTK_WINDOW (preferences), _("Preferences"));
963 gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
964 gtk_window_set_position (GTK_WINDOW (preferences),
965 GTK_WIN_POS_CENTER_ON_PARENT);
966 gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
968 filename = empathy_file_lookup ("empathy-preferences.ui", "src");
969 gui = empathy_builder_get_file (filename,
970 "notebook", &priv->notebook,
971 "checkbutton_show_smileys", &priv->checkbutton_show_smileys,
972 "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms,
973 "vbox_chat_theme", &priv->vbox_chat_theme,
974 "combobox_chat_theme", &priv->combobox_chat_theme,
975 "sw_chat_theme_preview", &priv->sw_chat_theme_preview,
976 "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows,
977 "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area,
978 "checkbutton_autoconnect", &priv->checkbutton_autoconnect,
979 "checkbutton_logging", &priv->checkbutton_logging,
980 "checkbutton_notifications_enabled", &priv->checkbutton_notifications_enabled,
981 "checkbutton_notifications_disabled_away", &priv->checkbutton_notifications_disabled_away,
982 "checkbutton_notifications_focus", &priv->checkbutton_notifications_focus,
983 "checkbutton_notifications_contact_signin", &priv->checkbutton_notifications_contact_signin,
984 "checkbutton_notifications_contact_signout", &priv->checkbutton_notifications_contact_signout,
985 "checkbutton_sounds_enabled", &priv->checkbutton_sounds_enabled,
986 "checkbutton_sounds_disabled_away", &priv->checkbutton_sounds_disabled_away,
987 "treeview_sounds", &priv->treeview_sounds,
988 "treeview_spell_checker", &priv->treeview_spell_checker,
989 "checkbutton_location_publish", &priv->checkbutton_location_publish,
990 "checkbutton_location_reduce_accuracy", &priv->checkbutton_location_reduce_accuracy,
991 "checkbutton_location_resource_network", &priv->checkbutton_location_resource_network,
992 "checkbutton_location_resource_cell", &priv->checkbutton_location_resource_cell,
993 "checkbutton_location_resource_gps", &priv->checkbutton_location_resource_gps,
997 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences))), priv->notebook);
998 gtk_widget_show (priv->notebook);
1000 g_object_unref (gui);
1002 priv->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
1003 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
1004 priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
1005 priv->gsettings_notify = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1006 priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
1007 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1008 priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
1010 /* Create chat theme preview, and track changes */
1011 priv->theme_manager = empathy_theme_manager_dup_singleton ();
1012 tp_g_signal_connect_object (priv->theme_manager, "theme-changed",
1013 G_CALLBACK (preferences_preview_theme_changed_cb),
1015 preferences_preview_theme_changed_cb (priv->theme_manager, preferences);
1017 preferences_themes_setup (preferences);
1019 preferences_setup_widgets (preferences);
1021 preferences_languages_setup (preferences);
1022 preferences_languages_add (preferences);
1023 preferences_languages_load (preferences);
1025 preferences_sound_setup (preferences);
1026 preferences_sound_load (preferences);
1028 if (empathy_spell_supported ()) {
1029 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 2);
1030 gtk_widget_show (page);
1033 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 3);
1035 gtk_widget_show (page);
1037 gtk_widget_hide (page);
1042 empathy_preferences_new (GtkWindow *parent)
1046 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1048 self = g_object_new (EMPATHY_TYPE_PREFERENCES, NULL);
1050 if (parent != NULL) {
1051 gtk_window_set_transient_for (GTK_WINDOW (self),