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>
27 #include "empathy-preferences.h"
29 #include <glib/gi18n.h>
30 #include <tp-account-widgets/tpaw-builder.h>
31 #include <telepathy-glib/telepathy-glib-dbus.h>
33 #include "empathy-client-factory.h"
34 #include "empathy-gsettings.h"
35 #include "empathy-spell.h"
36 #include "empathy-theme-manager.h"
37 #include "empathy-ui-utils.h"
38 #include "empathy-utils.h"
40 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
41 #include "empathy-debug.h"
43 G_DEFINE_TYPE (EmpathyPreferences
, empathy_preferences
, GTK_TYPE_DIALOG
);
45 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
47 static const gchar
* empathy_preferences_tabs
[] =
58 struct _EmpathyPreferencesPriv
{
61 GtkWidget
*label_general_behavior
;
62 GtkWidget
*checkbutton_events_notif_area
;
63 GtkWidget
*checkbutton_autoconnect
;
65 GtkWidget
*treeview_sounds
;
66 GtkWidget
*treeview_spell_checker
;
68 GtkWidget
*vbox_chat_theme
;
69 GtkWidget
*combobox_chat_theme
;
70 GtkWidget
*combobox_chat_theme_variant
;
71 GtkWidget
*hbox_chat_theme_variant
;
72 GtkWidget
*sw_chat_theme_preview
;
73 EmpathyThemeAdium
*chat_theme_preview
;
74 EmpathyThemeManager
*theme_manager
;
77 GSettings
*gsettings_chat
;
78 GSettings
*gsettings_call
;
79 GSettings
*gsettings_loc
;
80 GSettings
*gsettings_notify
;
81 GSettings
*gsettings_sound
;
82 GSettings
*gsettings_ui
;
83 GSettings
*gsettings_logger
;
86 static void preferences_setup_widgets (EmpathyPreferences
*preferences
,
88 static void preferences_languages_setup (EmpathyPreferences
*preferences
);
89 static void preferences_languages_add (EmpathyPreferences
*preferences
);
90 static void preferences_languages_save (EmpathyPreferences
*preferences
);
91 static gboolean
preferences_languages_save_foreach (GtkTreeModel
*model
,
95 static void preferences_languages_load (EmpathyPreferences
*preferences
);
96 static gboolean
preferences_languages_load_foreach (GtkTreeModel
*model
,
100 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle
*cell
,
102 EmpathyPreferences
*preferences
);
112 COL_THEME_VISIBLE_NAME
,
113 COL_THEME_ADIUM_NAME
,
114 COL_THEME_ADIUM_INFO
,
136 /* TODO: add phone related sounds also? */
137 static SoundEventEntry sound_entries
[] = {
138 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE
},
139 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE
},
140 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION
},
141 { N_("Contact comes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN
},
142 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT
},
143 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN
},
144 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT
}
148 preferences_setup_widgets (EmpathyPreferences
*preferences
,
151 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
152 #define BIND_ACTIVE(schema, key, widget) \
153 g_settings_bind (priv->gsettings_##schema, EMPATHY_PREFS_##key, \
154 gtk_builder_get_object (gui, widget), "active", \
155 G_SETTINGS_BIND_DEFAULT);
157 BIND_ACTIVE (notify
, NOTIFICATIONS_ENABLED
,
158 "checkbutton_notifications_enabled");
159 BIND_ACTIVE (notify
, NOTIFICATIONS_DISABLED_AWAY
,
160 "checkbutton_notifications_disabled_away");
161 BIND_ACTIVE (notify
, NOTIFICATIONS_FOCUS
,
162 "checkbutton_notifications_focus");
163 BIND_ACTIVE (notify
, NOTIFICATIONS_CONTACT_SIGNIN
,
164 "checkbutton_notifications_contact_signin");
165 BIND_ACTIVE (notify
, NOTIFICATIONS_CONTACT_SIGNOUT
,
166 "checkbutton_notifications_contact_signout");
168 BIND_ACTIVE (sound
, SOUNDS_ENABLED
,
169 "checkbutton_sounds_enabled");
170 BIND_ACTIVE (sound
, SOUNDS_DISABLED_AWAY
,
171 "checkbutton_sounds_disabled_away");
173 BIND_ACTIVE (ui
, UI_SHOW_OFFLINE
,
174 "checkbutton_show_offline");
175 BIND_ACTIVE (ui
, UI_SHOW_GROUPS
,
176 "checkbutton_show_groups");
177 BIND_ACTIVE (ui
, UI_SEPARATE_CHAT_WINDOWS
,
178 "radiobutton_chats_new_windows");
179 BIND_ACTIVE (ui
, UI_EVENTS_NOTIFY_AREA
,
180 "checkbutton_events_notif_area");
181 BIND_ACTIVE (ui
, UI_SHOW_BALANCES
,
182 "checkbutton_show_balances");
184 BIND_ACTIVE (chat
, CHAT_SHOW_SMILEYS
,
185 "checkbutton_show_smileys");
186 BIND_ACTIVE (chat
, CHAT_SHOW_CONTACTS_IN_ROOMS
,
187 "checkbutton_show_contacts_in_rooms");
189 BIND_ACTIVE (call
, CALL_ECHO_CANCELLATION
,
190 "call_echo_cancellation");
192 BIND_ACTIVE (loc
, LOCATION_PUBLISH
,
193 "checkbutton_location_publish");
194 BIND_ACTIVE (loc
, LOCATION_REDUCE_ACCURACY
,
195 "checkbutton_location_reduce_accuracy");
197 BIND_ACTIVE (logger
, LOGGER_ENABLED
,
198 "checkbutton_logging");
202 #define BIND_SENSITIVE(schema, key, widget) \
203 g_settings_bind (priv->gsettings_##schema, EMPATHY_PREFS_##key, \
204 gtk_builder_get_object (gui, widget), "sensitive", \
205 G_SETTINGS_BIND_GET);
206 /* N.B. BIND_SENSITIVE() is in addition to the sensitivity setting of
208 BIND_SENSITIVE (notify
, NOTIFICATIONS_ENABLED
,
209 "checkbutton_notifications_disabled_away");
210 BIND_SENSITIVE (notify
, NOTIFICATIONS_ENABLED
,
211 "checkbutton_notifications_focus");
212 BIND_SENSITIVE (notify
, NOTIFICATIONS_ENABLED
,
213 "checkbutton_notifications_contact_signin");
214 BIND_SENSITIVE (notify
, NOTIFICATIONS_ENABLED
,
215 "checkbutton_notifications_contact_signout");
217 BIND_SENSITIVE (sound
, SOUNDS_ENABLED
,
218 "checkbutton_sounds_disabled_away");
219 BIND_SENSITIVE (sound
, SOUNDS_ENABLED
,
222 BIND_SENSITIVE (loc
, LOCATION_PUBLISH
,
223 "checkbutton_location_reduce_accuracy");
225 #undef BIND_SENSITIVE
227 g_settings_bind (priv
->gsettings
,
228 EMPATHY_PREFS_AUTOCONNECT
,
229 gtk_builder_get_object (gui
,
230 "checkbutton_autoconnect"),
232 G_SETTINGS_BIND_DEFAULT
);
236 preferences_sound_cell_toggled_cb (GtkCellRendererToggle
*toggle
,
238 EmpathyPreferences
*preferences
)
240 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
248 view
= GTK_TREE_VIEW (priv
->treeview_sounds
);
249 model
= gtk_tree_view_get_model (view
);
251 path
= gtk_tree_path_new_from_string (path_string
);
253 gtk_tree_model_get_iter (model
, &iter
, path
);
254 gtk_tree_model_get (model
, &iter
, COL_SOUND_KEY
, &key
,
255 COL_SOUND_ENABLED
, &instore
, -1);
259 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
260 COL_SOUND_ENABLED
, instore
, -1);
262 g_settings_set_boolean (priv
->gsettings_sound
, key
, instore
);
265 gtk_tree_path_free (path
);
269 preferences_sound_load (EmpathyPreferences
*preferences
)
271 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
278 view
= GTK_TREE_VIEW (priv
->treeview_sounds
);
279 store
= GTK_LIST_STORE (gtk_tree_view_get_model (view
));
281 for (i
= 0; i
< G_N_ELEMENTS (sound_entries
); i
++) {
282 set
= g_settings_get_boolean (priv
->gsettings_sound
,
283 sound_entries
[i
].key
);
285 gtk_list_store_insert_with_values (store
, &iter
, i
,
286 COL_SOUND_NAME
, gettext (sound_entries
[i
].name
),
287 COL_SOUND_KEY
, sound_entries
[i
].key
,
288 COL_SOUND_ENABLED
, set
, -1);
293 preferences_sound_setup (EmpathyPreferences
*preferences
)
295 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
298 GtkCellRenderer
*renderer
;
299 GtkTreeViewColumn
*column
;
301 view
= GTK_TREE_VIEW (priv
->treeview_sounds
);
303 store
= gtk_list_store_new (COL_SOUND_COUNT
,
304 G_TYPE_BOOLEAN
, /* enabled */
305 G_TYPE_STRING
, /* name */
306 G_TYPE_STRING
); /* key */
308 gtk_tree_view_set_model (view
, GTK_TREE_MODEL (store
));
310 renderer
= gtk_cell_renderer_toggle_new ();
311 g_signal_connect (renderer
, "toggled",
312 G_CALLBACK (preferences_sound_cell_toggled_cb
),
315 column
= gtk_tree_view_column_new ();
316 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
317 gtk_tree_view_column_add_attribute (column
, renderer
,
318 "active", COL_SOUND_ENABLED
);
320 renderer
= gtk_cell_renderer_text_new ();
321 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
322 gtk_tree_view_column_add_attribute (column
, renderer
,
323 "text", COL_SOUND_NAME
);
325 gtk_tree_view_append_column (view
, column
);
327 gtk_tree_view_column_set_resizable (column
, FALSE
);
328 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
330 g_object_unref (store
);
334 preferences_languages_setup (EmpathyPreferences
*preferences
)
336 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
339 GtkTreeSelection
*selection
;
340 GtkTreeViewColumn
*column
;
341 GtkCellRenderer
*renderer
;
344 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
346 store
= gtk_list_store_new (COL_LANG_COUNT
,
347 G_TYPE_BOOLEAN
, /* enabled */
348 G_TYPE_STRING
, /* code */
349 G_TYPE_STRING
); /* name */
351 gtk_tree_view_set_model (view
, GTK_TREE_MODEL (store
));
353 selection
= gtk_tree_view_get_selection (view
);
354 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_SINGLE
);
356 renderer
= gtk_cell_renderer_toggle_new ();
357 g_signal_connect (renderer
, "toggled",
358 G_CALLBACK (preferences_languages_cell_toggled_cb
),
361 column
= gtk_tree_view_column_new_with_attributes (NULL
, renderer
,
362 "active", COL_LANG_ENABLED
,
365 gtk_tree_view_append_column (view
, column
);
367 renderer
= gtk_cell_renderer_text_new ();
368 col_offset
= gtk_tree_view_insert_column_with_attributes (view
,
371 "text", COL_LANG_NAME
,
374 g_object_set_data (G_OBJECT (renderer
),
375 "column", GINT_TO_POINTER (COL_LANG_NAME
));
377 column
= gtk_tree_view_get_column (view
, col_offset
- 1);
378 gtk_tree_view_column_set_sort_column_id (column
, COL_LANG_NAME
);
379 gtk_tree_view_column_set_resizable (column
, FALSE
);
380 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
382 g_object_unref (store
);
386 preferences_languages_add (EmpathyPreferences
*preferences
)
388 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
393 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
394 store
= GTK_LIST_STORE (gtk_tree_view_get_model (view
));
396 codes
= empathy_spell_get_language_codes ();
399 gtk_widget_set_sensitive (priv
->treeview_spell_checker
, FALSE
);
402 for (l
= codes
; l
; l
= l
->next
) {
407 name
= empathy_spell_get_language_name (code
);
412 gtk_list_store_insert_with_values (store
, NULL
, -1,
418 empathy_spell_free_language_codes (codes
);
422 preferences_languages_save (EmpathyPreferences
*preferences
)
424 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
428 gchar
*languages
= NULL
;
430 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
431 model
= gtk_tree_view_get_model (view
);
433 gtk_tree_model_foreach (model
,
434 (GtkTreeModelForeachFunc
) preferences_languages_save_foreach
,
437 /* if user selects no languages, we don't want spell check */
438 g_settings_set_boolean (priv
->gsettings_chat
,
439 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED
,
442 g_settings_set_string (priv
->gsettings_chat
,
443 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES
,
444 languages
!= NULL
? languages
: "");
450 preferences_languages_save_foreach (GtkTreeModel
*model
,
462 gtk_tree_model_get (model
, iter
, COL_LANG_ENABLED
, &enabled
, -1);
467 gtk_tree_model_get (model
, iter
, COL_LANG_CODE
, &code
, -1);
473 *languages
= g_strdup (code
);
475 gchar
*str
= *languages
;
476 *languages
= g_strdup_printf ("%s,%s", str
, code
);
486 preferences_languages_load (EmpathyPreferences
*preferences
)
488 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
491 GList
*enabled_codes
;
493 enabled_codes
= empathy_spell_get_enabled_language_codes ();
495 g_settings_set_boolean (priv
->gsettings_chat
,
496 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED
,
497 enabled_codes
!= NULL
);
499 if (enabled_codes
== NULL
)
502 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
503 model
= gtk_tree_view_get_model (view
);
505 gtk_tree_model_foreach (model
,
506 (GtkTreeModelForeachFunc
) preferences_languages_load_foreach
,
509 g_list_free (enabled_codes
);
513 preferences_languages_load_foreach (GtkTreeModel
*model
,
519 gboolean found
= FALSE
;
525 gtk_tree_model_get (model
, iter
, COL_LANG_CODE
, &code
, -1);
530 if (g_list_find_custom (languages
, code
, (GCompareFunc
) strcmp
)) {
535 gtk_list_store_set (GTK_LIST_STORE (model
), iter
, COL_LANG_ENABLED
, found
, -1);
540 preferences_languages_cell_toggled_cb (GtkCellRendererToggle
*cell
,
542 EmpathyPreferences
*preferences
)
544 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
552 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
553 model
= gtk_tree_view_get_model (view
);
554 store
= GTK_LIST_STORE (model
);
556 path
= gtk_tree_path_new_from_string (path_string
);
558 gtk_tree_model_get_iter (model
, &iter
, path
);
559 gtk_tree_model_get (model
, &iter
, COL_LANG_ENABLED
, &enabled
, -1);
563 gtk_list_store_set (store
, &iter
, COL_LANG_ENABLED
, enabled
, -1);
564 gtk_tree_path_free (path
);
566 preferences_languages_save (preferences
);
570 preferences_preview_theme_append_message (EmpathyThemeAdium
*view
,
571 EmpathyContact
*sender
,
572 EmpathyContact
*receiver
,
574 gboolean should_highlight
)
576 EmpathyMessage
*message
;
578 message
= g_object_new (EMPATHY_TYPE_MESSAGE
,
580 "receiver", receiver
,
584 empathy_theme_adium_append_message (view
, message
, should_highlight
);
585 g_object_unref (message
);
589 preferences_preview_theme_changed_cb (EmpathyThemeManager
*manager
,
590 EmpathyPreferences
*preferences
)
592 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
593 EmpathyClientFactory
*factory
;
595 EmpathyContact
*juliet
;
596 EmpathyContact
*romeo
;
598 DEBUG ("Theme changed, update preview widget");
600 if (priv
->chat_theme_preview
!= NULL
) {
601 gtk_widget_destroy (GTK_WIDGET (priv
->chat_theme_preview
));
603 priv
->chat_theme_preview
= empathy_theme_manager_create_view (manager
);
604 if (GTK_IS_SCROLLABLE (priv
->chat_theme_preview
))
606 gtk_container_add (GTK_CONTAINER (priv
->sw_chat_theme_preview
),
607 GTK_WIDGET (priv
->chat_theme_preview
));
611 gtk_widget_hide (priv
->sw_chat_theme_preview
);
612 gtk_box_pack_start (GTK_BOX (priv
->vbox_chat_theme
),
613 GTK_WIDGET (priv
->chat_theme_preview
),
616 gtk_widget_show (GTK_WIDGET (priv
->chat_theme_preview
));
618 /* FIXME: It is ugly to add a fake conversation like that.
619 * Would be cool if we could request a TplLogManager for a fake
621 factory
= empathy_client_factory_dup ();
623 account
= tp_simple_client_factory_ensure_account (
624 TP_SIMPLE_CLIENT_FACTORY (factory
),
625 TP_ACCOUNT_OBJECT_PATH_BASE
"cm/jabber/account", NULL
, NULL
);
626 juliet
= g_object_new (EMPATHY_TYPE_CONTACT
,
629 /* translators: Contact name for the chat theme preview */
630 "alias", _("Juliet"),
633 romeo
= g_object_new (EMPATHY_TYPE_CONTACT
,
636 /* translators: Contact name for the chat theme preview */
641 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
642 /* translators: Quote from Romeo & Julier, for chat theme preview */
643 juliet
, romeo
, _("O Romeo, Romeo, wherefore art thou Romeo?"),
644 TRUE
/* this message mentions Romeo */);
645 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
646 /* translators: Quote from Romeo & Julier, for chat theme preview */
647 juliet
, romeo
, _("Deny thy father and refuse thy name;"), FALSE
);
648 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
649 /* translators: Quote from Romeo & Julier, for chat theme preview */
650 juliet
, romeo
, _("Or if thou wilt not, be but sworn my love"), FALSE
);
651 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
652 /* translators: Quote from Romeo & Julier, for chat theme preview */
653 juliet
, romeo
, _("And I’ll no longer be a Capulet."), FALSE
);
654 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
655 /* translators: Quote from Romeo & Julier, for chat theme preview */
656 romeo
, juliet
, _("Shall I hear more, or shall I speak at this?"), FALSE
);
658 /* translators: Quote from Romeo & Julier, for chat theme preview */
659 empathy_theme_adium_append_event (priv
->chat_theme_preview
, _("Juliet has disconnected"));
661 g_object_unref (juliet
);
662 g_object_unref (romeo
);
663 g_object_unref (account
);
664 g_object_unref (factory
);
668 preferences_theme_variant_changed_cb (GtkComboBox
*combo
,
669 EmpathyPreferences
*preferences
)
671 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
674 if (gtk_combo_box_get_active_iter (combo
, &iter
)) {
678 model
= gtk_combo_box_get_model (combo
);
679 gtk_tree_model_get (model
, &iter
,
680 COL_VARIANT_NAME
, &name
,
683 g_settings_set_string (priv
->gsettings_chat
,
684 EMPATHY_PREFS_CHAT_THEME_VARIANT
,
692 preferences_theme_variant_notify_cb (GSettings
*gsettings
,
696 EmpathyPreferences
*preferences
= user_data
;
697 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
702 GtkTreeIter default_iter
;
703 gboolean found_default
= FALSE
;
704 gboolean found
= FALSE
;
707 conf_name
= g_settings_get_string (gsettings
, EMPATHY_PREFS_CHAT_THEME_VARIANT
);
708 combo
= GTK_COMBO_BOX (priv
->combobox_chat_theme_variant
);
709 model
= gtk_combo_box_get_model (combo
);
711 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
713 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
717 gtk_tree_model_get (model
, &iter
,
718 COL_VARIANT_NAME
, &name
,
719 COL_VARIANT_DEFAULT
, &is_default
,
722 if (!tp_strdiff (name
, conf_name
)) {
724 gtk_combo_box_set_active_iter (combo
, &iter
);
727 found_default
= TRUE
;
734 /* Fallback to the first one. */
737 gtk_combo_box_set_active_iter (combo
, &default_iter
);
738 } else if (gtk_tree_model_get_iter_first (model
, &iter
)) {
739 gtk_combo_box_set_active_iter (combo
, &iter
);
746 /* return TRUE if we added at least one variant */
748 preferences_theme_variants_fill (EmpathyPreferences
*preferences
,
751 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
755 const gchar
*default_variant
;
757 gboolean result
= FALSE
;
759 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (priv
->combobox_chat_theme_variant
));
760 store
= GTK_LIST_STORE (model
);
761 gtk_list_store_clear (store
);
763 variants
= empathy_adium_info_get_available_variants (info
);
764 default_variant
= empathy_adium_info_get_default_variant (info
);
765 for (i
= 0; i
< variants
->len
; i
++) {
766 gchar
*name
= g_ptr_array_index (variants
, i
);
768 gtk_list_store_insert_with_values (store
, NULL
, -1,
769 COL_VARIANT_NAME
, name
,
770 COL_VARIANT_DEFAULT
, !tp_strdiff (name
, default_variant
),
776 /* Select the variant from the GSetting key */
777 preferences_theme_variant_notify_cb (priv
->gsettings_chat
,
778 EMPATHY_PREFS_CHAT_THEME_VARIANT
,
785 preferences_theme_variants_setup (EmpathyPreferences
*preferences
)
787 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
789 GtkCellLayout
*cell_layout
;
790 GtkCellRenderer
*renderer
;
793 combo
= GTK_COMBO_BOX (priv
->combobox_chat_theme_variant
);
794 cell_layout
= GTK_CELL_LAYOUT (combo
);
796 /* Create the model */
797 store
= gtk_list_store_new (COL_VARIANT_COUNT
,
798 G_TYPE_STRING
, /* name */
799 G_TYPE_BOOLEAN
); /* is default */
800 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
801 COL_VARIANT_NAME
, GTK_SORT_ASCENDING
);
803 /* Add cell renderer */
804 renderer
= gtk_cell_renderer_text_new ();
805 gtk_cell_layout_pack_start (cell_layout
, renderer
, TRUE
);
806 gtk_cell_layout_set_attributes (cell_layout
, renderer
,
807 "text", COL_VARIANT_NAME
, NULL
);
809 gtk_combo_box_set_model (combo
, GTK_TREE_MODEL (store
));
810 g_object_unref (store
);
812 g_signal_connect (combo
, "changed",
813 G_CALLBACK (preferences_theme_variant_changed_cb
),
816 /* Track changes of the GSetting key */
817 g_signal_connect (priv
->gsettings_chat
,
818 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT
,
819 G_CALLBACK (preferences_theme_variant_notify_cb
),
824 preferences_theme_changed_cb (GtkComboBox
*combo
,
825 EmpathyPreferences
*preferences
)
827 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
830 if (gtk_combo_box_get_active_iter (combo
, &iter
)) {
836 model
= gtk_combo_box_get_model (combo
);
837 gtk_tree_model_get (model
, &iter
,
838 COL_THEME_ADIUM_NAME
, &name
,
839 COL_THEME_ADIUM_INFO
, &info
,
842 g_settings_set_string (priv
->gsettings_chat
,
843 EMPATHY_PREFS_CHAT_THEME
,
846 variant
= preferences_theme_variants_fill (preferences
, info
);
847 gtk_widget_set_visible (priv
->hbox_chat_theme_variant
, variant
);
850 tp_clear_pointer (&info
, g_hash_table_unref
);
855 preferences_theme_notify_cb (GSettings
*gsettings
,
859 EmpathyPreferences
*preferences
= user_data
;
860 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
865 gboolean found
= FALSE
;
868 theme
= g_settings_get_string (gsettings
, key
);
870 combo
= GTK_COMBO_BOX (priv
->combobox_chat_theme
);
871 model
= gtk_combo_box_get_model (combo
);
872 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
874 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
877 gtk_tree_model_get (model
, &iter
,
878 COL_THEME_ADIUM_NAME
, &name
,
881 if (!tp_strdiff (name
, theme
)) {
883 gtk_combo_box_set_active_iter (combo
, &iter
);
889 /* Fallback to the first one. */
891 if (gtk_tree_model_get_iter_first (model
, &iter
)) {
892 gtk_combo_box_set_active_iter (combo
, &iter
);
900 preferences_themes_setup (EmpathyPreferences
*preferences
)
902 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
904 GtkCellLayout
*cell_layout
;
905 GtkCellRenderer
*renderer
;
909 preferences_theme_variants_setup (preferences
);
911 combo
= GTK_COMBO_BOX (priv
->combobox_chat_theme
);
912 cell_layout
= GTK_CELL_LAYOUT (combo
);
914 /* Create the model */
915 store
= gtk_list_store_new (COL_THEME_COUNT
,
916 G_TYPE_STRING
, /* Display name */
917 G_TYPE_STRING
, /* Adium theme path */
918 G_TYPE_HASH_TABLE
); /* Adium theme info */
919 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
920 COL_THEME_VISIBLE_NAME
, GTK_SORT_ASCENDING
);
923 adium_themes
= empathy_theme_manager_get_adium_themes ();
924 while (adium_themes
!= NULL
) {
926 const gchar
*visible_name
;
929 info
= adium_themes
->data
;
930 visible_name
= tp_asv_get_string (info
, "CFBundleName");
931 name
= empathy_theme_manager_dup_theme_name_from_path (
932 tp_asv_get_string (info
, "path"));
934 if (visible_name
!= NULL
&& name
!= NULL
) {
935 gtk_list_store_insert_with_values (store
, NULL
, -1,
936 COL_THEME_VISIBLE_NAME
, visible_name
,
937 COL_THEME_ADIUM_NAME
, name
,
938 COL_THEME_ADIUM_INFO
, info
,
941 g_hash_table_unref (info
);
943 adium_themes
= g_list_delete_link (adium_themes
, adium_themes
);
946 /* Add cell renderer */
947 renderer
= gtk_cell_renderer_text_new ();
948 gtk_cell_layout_pack_start (cell_layout
, renderer
, TRUE
);
949 gtk_cell_layout_set_attributes (cell_layout
, renderer
,
950 "text", COL_THEME_VISIBLE_NAME
, NULL
);
952 gtk_combo_box_set_model (combo
, GTK_TREE_MODEL (store
));
953 g_object_unref (store
);
955 g_signal_connect (combo
, "changed",
956 G_CALLBACK (preferences_theme_changed_cb
),
959 /* Select the theme from the GSetting key and track changes */
960 preferences_theme_notify_cb (priv
->gsettings_chat
,
961 EMPATHY_PREFS_CHAT_THEME
,
964 g_signal_connect (priv
->gsettings_chat
,
965 "changed::" EMPATHY_PREFS_CHAT_THEME
,
966 G_CALLBACK (preferences_theme_notify_cb
),
971 empathy_preferences_response (GtkDialog
*widget
,
974 gtk_widget_destroy (GTK_WIDGET (widget
));
978 empathy_preferences_finalize (GObject
*self
)
980 EmpathyPreferencesPriv
*priv
= GET_PRIV (self
);
982 g_object_unref (priv
->theme_manager
);
984 g_object_unref (priv
->gsettings
);
985 g_object_unref (priv
->gsettings_chat
);
986 g_object_unref (priv
->gsettings_call
);
987 g_object_unref (priv
->gsettings_loc
);
988 g_object_unref (priv
->gsettings_notify
);
989 g_object_unref (priv
->gsettings_sound
);
990 g_object_unref (priv
->gsettings_ui
);
991 g_object_unref (priv
->gsettings_logger
);
993 G_OBJECT_CLASS (empathy_preferences_parent_class
)->finalize (self
);
997 empathy_preferences_class_init (EmpathyPreferencesClass
*klass
)
999 GtkDialogClass
*dialog_class
= GTK_DIALOG_CLASS (klass
);
1000 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1002 dialog_class
->response
= empathy_preferences_response
;
1004 object_class
->finalize
= empathy_preferences_finalize
;
1006 g_type_class_add_private (object_class
,
1007 sizeof (EmpathyPreferencesPriv
));
1011 empathy_preferences_init (EmpathyPreferences
*preferences
)
1013 EmpathyPreferencesPriv
*priv
;
1018 priv
= preferences
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (preferences
,
1019 EMPATHY_TYPE_PREFERENCES
, EmpathyPreferencesPriv
);
1021 gtk_dialog_add_button (GTK_DIALOG (preferences
),
1022 GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
);
1024 gtk_container_set_border_width (GTK_CONTAINER (preferences
), 5);
1025 gtk_window_set_title (GTK_WINDOW (preferences
), _("Preferences"));
1026 gtk_window_set_role (GTK_WINDOW (preferences
), "preferences");
1027 gtk_window_set_position (GTK_WINDOW (preferences
),
1028 GTK_WIN_POS_CENTER_ON_PARENT
);
1029 gtk_window_set_icon_name (GTK_WINDOW (preferences
), "preferences-desktop");
1031 filename
= empathy_file_lookup ("empathy-preferences.ui", "src");
1032 gui
= tpaw_builder_get_file (filename
,
1033 "notebook", &priv
->notebook
,
1034 "vbox_chat_theme", &priv
->vbox_chat_theme
,
1035 "combobox_chat_theme", &priv
->combobox_chat_theme
,
1036 "combobox_chat_theme_variant", &priv
->combobox_chat_theme_variant
,
1037 "hbox_chat_theme_variant", &priv
->hbox_chat_theme_variant
,
1038 "sw_chat_theme_preview", &priv
->sw_chat_theme_preview
,
1039 "treeview_sounds", &priv
->treeview_sounds
,
1040 "treeview_spell_checker", &priv
->treeview_spell_checker
,
1041 "label_general_behavior", &priv
->label_general_behavior
,
1042 "checkbutton_events_notif_area", &priv
->checkbutton_events_notif_area
,
1043 "checkbutton_autoconnect", &priv
->checkbutton_autoconnect
,
1047 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences
))), priv
->notebook
);
1048 gtk_widget_show (priv
->notebook
);
1050 priv
->gsettings
= g_settings_new (EMPATHY_PREFS_SCHEMA
);
1051 priv
->gsettings_chat
= g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA
);
1052 priv
->gsettings_call
= g_settings_new (EMPATHY_PREFS_CALL_SCHEMA
);
1053 priv
->gsettings_loc
= g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA
);
1054 priv
->gsettings_notify
= g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA
);
1055 priv
->gsettings_sound
= g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA
);
1056 priv
->gsettings_ui
= g_settings_new (EMPATHY_PREFS_UI_SCHEMA
);
1057 priv
->gsettings_logger
= g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA
);
1059 /* Create chat theme preview, and track changes */
1060 priv
->theme_manager
= empathy_theme_manager_dup_singleton ();
1061 tp_g_signal_connect_object (priv
->theme_manager
, "theme-changed",
1062 G_CALLBACK (preferences_preview_theme_changed_cb
),
1064 preferences_preview_theme_changed_cb (priv
->theme_manager
, preferences
);
1066 preferences_themes_setup (preferences
);
1068 preferences_setup_widgets (preferences
, gui
);
1070 preferences_languages_setup (preferences
);
1071 preferences_languages_add (preferences
);
1072 preferences_languages_load (preferences
);
1074 preferences_sound_setup (preferences
);
1075 preferences_sound_load (preferences
);
1077 g_object_unref (gui
);
1079 if (empathy_spell_supported ()) {
1080 page
= gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv
->notebook
), EMPATHY_PREFERENCES_TAB_SPELL
);
1081 gtk_widget_show (page
);
1084 page
= gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv
->notebook
), EMPATHY_PREFERENCES_TAB_LOCATION
);
1086 gtk_widget_show (page
);
1088 gtk_widget_hide (page
);
1092 static EmpathyPreferencesTab
1093 empathy_preferences_tab_from_string (const gchar
*str
)
1097 for (i
= 0; i
< G_N_ELEMENTS (empathy_preferences_tabs
); i
++)
1099 if (!tp_strdiff (str
, empathy_preferences_tabs
[i
]))
1103 g_warn_if_reached ();
1108 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab
)
1110 g_return_val_if_fail (tab
< G_N_ELEMENTS (empathy_preferences_tabs
), NULL
);
1112 return empathy_preferences_tabs
[tab
];
1116 empathy_preferences_new (GtkWindow
*parent
,
1117 gboolean shell_running
)
1120 EmpathyPreferencesPriv
*priv
;
1121 GtkWidget
*notif_page
;
1123 g_return_val_if_fail (parent
== NULL
|| GTK_IS_WINDOW (parent
), NULL
);
1125 self
= g_object_new (EMPATHY_TYPE_PREFERENCES
, NULL
);
1127 if (parent
!= NULL
) {
1128 gtk_window_set_transient_for (GTK_WINDOW (self
),
1132 /* when running in Gnome Shell we must hide these options since they
1133 * are meaningless in that context:
1134 * - General->Behavior label
1135 * - 'Display incoming events in the notification area' (General->Behavior)
1136 * - 'Automatically connect at startup' (General->Behavior)
1137 * - 'Notifications' tab
1139 priv
= GET_PRIV (self
);
1140 if (shell_running
) {
1142 gtk_widget_hide (priv
->label_general_behavior
);
1143 gtk_widget_hide (priv
->checkbutton_events_notif_area
);
1144 gtk_widget_hide (priv
->checkbutton_autoconnect
);
1146 /* Notifications tab */
1147 notif_page
= gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv
->notebook
),
1148 EMPATHY_PREFERENCES_TAB_NOTIFICATIONS
);
1149 gtk_widget_hide (notif_page
);
1156 empathy_preferences_show_tab (EmpathyPreferences
*self
,
1159 EmpathyPreferencesPriv
*priv
= GET_PRIV (self
);
1161 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv
->notebook
),
1162 empathy_preferences_tab_from_string (page
));