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-gtk-enum-types.h>
43 #include <libempathy-gtk/empathy-theme-adium.h>
45 #include "empathy-preferences.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
48 #include <libempathy/empathy-debug.h>
50 G_DEFINE_TYPE (EmpathyPreferences
, empathy_preferences
, GTK_TYPE_DIALOG
);
52 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
54 static const gchar
* empathy_preferences_tabs
[] =
65 struct _EmpathyPreferencesPriv
{
68 GtkWidget
*checkbutton_show_smileys
;
69 GtkWidget
*checkbutton_show_contacts_in_rooms
;
70 GtkWidget
*radiobutton_chats_new_windows
;
71 GtkWidget
*checkbutton_events_notif_area
;
72 GtkWidget
*checkbutton_autoconnect
;
73 GtkWidget
*checkbutton_logging
;
75 GtkWidget
*checkbutton_sounds_enabled
;
76 GtkWidget
*checkbutton_sounds_disabled_away
;
77 GtkWidget
*treeview_sounds
;
79 GtkWidget
*checkbutton_notifications_enabled
;
80 GtkWidget
*checkbutton_notifications_disabled_away
;
81 GtkWidget
*checkbutton_notifications_focus
;
82 GtkWidget
*checkbutton_notifications_contact_signin
;
83 GtkWidget
*checkbutton_notifications_contact_signout
;
85 GtkWidget
*echo_cancellation
;
87 GtkWidget
*treeview_spell_checker
;
89 GtkWidget
*checkbutton_location_publish
;
90 GtkWidget
*checkbutton_location_reduce_accuracy
;
91 GtkWidget
*checkbutton_location_resource_network
;
92 GtkWidget
*checkbutton_location_resource_cell
;
93 GtkWidget
*checkbutton_location_resource_gps
;
95 GtkWidget
*vbox_chat_theme
;
96 GtkWidget
*combobox_chat_theme
;
97 GtkWidget
*combobox_chat_theme_variant
;
98 GtkWidget
*hbox_chat_theme_variant
;
99 GtkWidget
*sw_chat_theme_preview
;
100 EmpathyChatView
*chat_theme_preview
;
101 EmpathyThemeManager
*theme_manager
;
103 GSettings
*gsettings
;
104 GSettings
*gsettings_chat
;
105 GSettings
*gsettings_call
;
106 GSettings
*gsettings_loc
;
107 GSettings
*gsettings_notify
;
108 GSettings
*gsettings_sound
;
109 GSettings
*gsettings_ui
;
110 GSettings
*gsettings_logger
;
113 static void preferences_setup_widgets (EmpathyPreferences
*preferences
);
114 static void preferences_languages_setup (EmpathyPreferences
*preferences
);
115 static void preferences_languages_add (EmpathyPreferences
*preferences
);
116 static void preferences_languages_save (EmpathyPreferences
*preferences
);
117 static gboolean
preferences_languages_save_foreach (GtkTreeModel
*model
,
121 static void preferences_languages_load (EmpathyPreferences
*preferences
);
122 static gboolean
preferences_languages_load_foreach (GtkTreeModel
*model
,
126 static void preferences_languages_cell_toggled_cb (GtkCellRendererToggle
*cell
,
128 EmpathyPreferences
*preferences
);
138 COL_THEME_VISIBLE_NAME
,
141 COL_THEME_ADIUM_PATH
,
142 COL_THEME_ADIUM_INFO
,
164 /* TODO: add phone related sounds also? */
165 static SoundEventEntry sound_entries
[] = {
166 { N_("Message received"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE
},
167 { N_("Message sent"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE
},
168 { N_("New conversation"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION
},
169 { N_("Contact comes online"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN
},
170 { N_("Contact goes offline"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT
},
171 { N_("Account connected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN
},
172 { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT
}
176 preferences_setup_widgets (EmpathyPreferences
*preferences
)
178 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
180 g_settings_bind (priv
->gsettings_notify
,
181 EMPATHY_PREFS_NOTIFICATIONS_ENABLED
,
182 priv
->checkbutton_notifications_enabled
,
184 G_SETTINGS_BIND_DEFAULT
);
185 g_settings_bind (priv
->gsettings_notify
,
186 EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY
,
187 priv
->checkbutton_notifications_disabled_away
,
189 G_SETTINGS_BIND_DEFAULT
);
190 g_settings_bind (priv
->gsettings_notify
,
191 EMPATHY_PREFS_NOTIFICATIONS_FOCUS
,
192 priv
->checkbutton_notifications_focus
,
194 G_SETTINGS_BIND_DEFAULT
);
195 g_settings_bind (priv
->gsettings_notify
,
196 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN
,
197 priv
->checkbutton_notifications_contact_signin
,
199 G_SETTINGS_BIND_DEFAULT
);
200 g_settings_bind (priv
->gsettings_notify
,
201 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT
,
202 priv
->checkbutton_notifications_contact_signout
,
204 G_SETTINGS_BIND_DEFAULT
);
206 g_settings_bind (priv
->gsettings_notify
,
207 EMPATHY_PREFS_NOTIFICATIONS_ENABLED
,
208 priv
->checkbutton_notifications_disabled_away
,
210 G_SETTINGS_BIND_GET
);
211 g_settings_bind (priv
->gsettings_notify
,
212 EMPATHY_PREFS_NOTIFICATIONS_ENABLED
,
213 priv
->checkbutton_notifications_focus
,
215 G_SETTINGS_BIND_GET
);
216 g_settings_bind (priv
->gsettings_notify
,
217 EMPATHY_PREFS_NOTIFICATIONS_ENABLED
,
218 priv
->checkbutton_notifications_contact_signin
,
220 G_SETTINGS_BIND_GET
);
221 g_settings_bind (priv
->gsettings_notify
,
222 EMPATHY_PREFS_NOTIFICATIONS_ENABLED
,
223 priv
->checkbutton_notifications_contact_signout
,
225 G_SETTINGS_BIND_GET
);
227 g_settings_bind (priv
->gsettings_sound
,
228 EMPATHY_PREFS_SOUNDS_ENABLED
,
229 priv
->checkbutton_sounds_enabled
,
231 G_SETTINGS_BIND_DEFAULT
);
232 g_settings_bind (priv
->gsettings_sound
,
233 EMPATHY_PREFS_SOUNDS_DISABLED_AWAY
,
234 priv
->checkbutton_sounds_disabled_away
,
236 G_SETTINGS_BIND_DEFAULT
);
238 g_settings_bind (priv
->gsettings_sound
,
239 EMPATHY_PREFS_SOUNDS_ENABLED
,
240 priv
->checkbutton_sounds_disabled_away
,
242 G_SETTINGS_BIND_GET
);
243 g_settings_bind (priv
->gsettings_sound
,
244 EMPATHY_PREFS_SOUNDS_ENABLED
,
245 priv
->treeview_sounds
,
247 G_SETTINGS_BIND_GET
);
249 g_settings_bind (priv
->gsettings_ui
,
250 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS
,
251 priv
->radiobutton_chats_new_windows
,
253 G_SETTINGS_BIND_DEFAULT
);
255 g_settings_bind (priv
->gsettings_ui
,
256 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA
,
257 priv
->checkbutton_events_notif_area
,
259 G_SETTINGS_BIND_DEFAULT
);
261 g_settings_bind (priv
->gsettings_chat
,
262 EMPATHY_PREFS_CHAT_SHOW_SMILEYS
,
263 priv
->checkbutton_show_smileys
,
265 G_SETTINGS_BIND_DEFAULT
);
266 g_settings_bind (priv
->gsettings_chat
,
267 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS
,
268 priv
->checkbutton_show_contacts_in_rooms
,
270 G_SETTINGS_BIND_DEFAULT
);
272 g_settings_bind (priv
->gsettings_call
,
273 EMPATHY_PREFS_CALL_ECHO_CANCELLATION
,
274 priv
->echo_cancellation
,
276 G_SETTINGS_BIND_DEFAULT
);
278 g_settings_bind (priv
->gsettings
,
279 EMPATHY_PREFS_AUTOCONNECT
,
280 priv
->checkbutton_autoconnect
,
282 G_SETTINGS_BIND_DEFAULT
);
284 g_settings_bind (priv
->gsettings_loc
,
285 EMPATHY_PREFS_LOCATION_PUBLISH
,
286 priv
->checkbutton_location_publish
,
288 G_SETTINGS_BIND_DEFAULT
);
290 g_settings_bind (priv
->gsettings_loc
,
291 EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK
,
292 priv
->checkbutton_location_resource_network
,
294 G_SETTINGS_BIND_DEFAULT
);
295 g_settings_bind (priv
->gsettings_loc
,
296 EMPATHY_PREFS_LOCATION_PUBLISH
,
297 priv
->checkbutton_location_resource_network
,
299 G_SETTINGS_BIND_GET
);
301 g_settings_bind (priv
->gsettings_loc
,
302 EMPATHY_PREFS_LOCATION_RESOURCE_CELL
,
303 priv
->checkbutton_location_resource_cell
,
305 G_SETTINGS_BIND_DEFAULT
);
306 g_settings_bind (priv
->gsettings_loc
,
307 EMPATHY_PREFS_LOCATION_PUBLISH
,
308 priv
->checkbutton_location_resource_cell
,
310 G_SETTINGS_BIND_GET
);
312 g_settings_bind (priv
->gsettings_loc
,
313 EMPATHY_PREFS_LOCATION_RESOURCE_GPS
,
314 priv
->checkbutton_location_resource_gps
,
316 G_SETTINGS_BIND_DEFAULT
);
317 g_settings_bind (priv
->gsettings_loc
,
318 EMPATHY_PREFS_LOCATION_PUBLISH
,
319 priv
->checkbutton_location_resource_gps
,
321 G_SETTINGS_BIND_GET
);
323 g_settings_bind (priv
->gsettings_loc
,
324 EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY
,
325 priv
->checkbutton_location_reduce_accuracy
,
327 G_SETTINGS_BIND_DEFAULT
);
328 g_settings_bind (priv
->gsettings_loc
,
329 EMPATHY_PREFS_LOCATION_PUBLISH
,
330 priv
->checkbutton_location_reduce_accuracy
,
332 G_SETTINGS_BIND_GET
);
334 g_settings_bind (priv
->gsettings_logger
,
335 EMPATHY_PREFS_LOGGER_ENABLED
,
336 priv
->checkbutton_logging
,
338 G_SETTINGS_BIND_DEFAULT
);
342 preferences_sound_cell_toggled_cb (GtkCellRendererToggle
*toggle
,
344 EmpathyPreferences
*preferences
)
346 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
354 view
= GTK_TREE_VIEW (priv
->treeview_sounds
);
355 model
= gtk_tree_view_get_model (view
);
357 path
= gtk_tree_path_new_from_string (path_string
);
359 gtk_tree_model_get_iter (model
, &iter
, path
);
360 gtk_tree_model_get (model
, &iter
, COL_SOUND_KEY
, &key
,
361 COL_SOUND_ENABLED
, &instore
, -1);
365 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
366 COL_SOUND_ENABLED
, instore
, -1);
368 g_settings_set_boolean (priv
->gsettings_sound
, key
, instore
);
371 gtk_tree_path_free (path
);
375 preferences_sound_load (EmpathyPreferences
*preferences
)
377 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
384 view
= GTK_TREE_VIEW (priv
->treeview_sounds
);
385 store
= GTK_LIST_STORE (gtk_tree_view_get_model (view
));
387 for (i
= 0; i
< G_N_ELEMENTS (sound_entries
); i
++) {
388 set
= g_settings_get_boolean (priv
->gsettings_sound
,
389 sound_entries
[i
].key
);
391 gtk_list_store_insert_with_values (store
, &iter
, i
,
392 COL_SOUND_NAME
, gettext (sound_entries
[i
].name
),
393 COL_SOUND_KEY
, sound_entries
[i
].key
,
394 COL_SOUND_ENABLED
, set
, -1);
399 preferences_sound_setup (EmpathyPreferences
*preferences
)
401 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
404 GtkCellRenderer
*renderer
;
405 GtkTreeViewColumn
*column
;
407 view
= GTK_TREE_VIEW (priv
->treeview_sounds
);
409 store
= gtk_list_store_new (COL_SOUND_COUNT
,
410 G_TYPE_BOOLEAN
, /* enabled */
411 G_TYPE_STRING
, /* name */
412 G_TYPE_STRING
); /* key */
414 gtk_tree_view_set_model (view
, GTK_TREE_MODEL (store
));
416 renderer
= gtk_cell_renderer_toggle_new ();
417 g_signal_connect (renderer
, "toggled",
418 G_CALLBACK (preferences_sound_cell_toggled_cb
),
421 column
= gtk_tree_view_column_new ();
422 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
423 gtk_tree_view_column_add_attribute (column
, renderer
,
424 "active", COL_SOUND_ENABLED
);
426 renderer
= gtk_cell_renderer_text_new ();
427 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
428 gtk_tree_view_column_add_attribute (column
, renderer
,
429 "text", COL_SOUND_NAME
);
431 gtk_tree_view_append_column (view
, column
);
433 gtk_tree_view_column_set_resizable (column
, FALSE
);
434 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
436 g_object_unref (store
);
440 preferences_languages_setup (EmpathyPreferences
*preferences
)
442 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
445 GtkTreeSelection
*selection
;
446 GtkTreeViewColumn
*column
;
447 GtkCellRenderer
*renderer
;
450 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
452 store
= gtk_list_store_new (COL_LANG_COUNT
,
453 G_TYPE_BOOLEAN
, /* enabled */
454 G_TYPE_STRING
, /* code */
455 G_TYPE_STRING
); /* name */
457 gtk_tree_view_set_model (view
, GTK_TREE_MODEL (store
));
459 selection
= gtk_tree_view_get_selection (view
);
460 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_SINGLE
);
462 renderer
= gtk_cell_renderer_toggle_new ();
463 g_signal_connect (renderer
, "toggled",
464 G_CALLBACK (preferences_languages_cell_toggled_cb
),
467 column
= gtk_tree_view_column_new_with_attributes (NULL
, renderer
,
468 "active", COL_LANG_ENABLED
,
471 gtk_tree_view_append_column (view
, column
);
473 renderer
= gtk_cell_renderer_text_new ();
474 col_offset
= gtk_tree_view_insert_column_with_attributes (view
,
477 "text", COL_LANG_NAME
,
480 g_object_set_data (G_OBJECT (renderer
),
481 "column", GINT_TO_POINTER (COL_LANG_NAME
));
483 column
= gtk_tree_view_get_column (view
, col_offset
- 1);
484 gtk_tree_view_column_set_sort_column_id (column
, COL_LANG_NAME
);
485 gtk_tree_view_column_set_resizable (column
, FALSE
);
486 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column
), TRUE
);
488 g_object_unref (store
);
492 preferences_languages_add (EmpathyPreferences
*preferences
)
494 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
499 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
500 store
= GTK_LIST_STORE (gtk_tree_view_get_model (view
));
502 codes
= empathy_spell_get_language_codes ();
505 gtk_widget_set_sensitive (priv
->treeview_spell_checker
, FALSE
);
508 for (l
= codes
; l
; l
= l
->next
) {
514 name
= empathy_spell_get_language_name (code
);
519 gtk_list_store_append (store
, &iter
);
520 gtk_list_store_set (store
, &iter
,
526 empathy_spell_free_language_codes (codes
);
530 preferences_languages_save (EmpathyPreferences
*preferences
)
532 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
536 gchar
*languages
= NULL
;
538 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
539 model
= gtk_tree_view_get_model (view
);
541 gtk_tree_model_foreach (model
,
542 (GtkTreeModelForeachFunc
) preferences_languages_save_foreach
,
545 /* if user selects no languages, we don't want spell check */
546 g_settings_set_boolean (priv
->gsettings_chat
,
547 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED
,
550 g_settings_set_string (priv
->gsettings_chat
,
551 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES
,
552 languages
!= NULL
? languages
: "");
558 preferences_languages_save_foreach (GtkTreeModel
*model
,
570 gtk_tree_model_get (model
, iter
, COL_LANG_ENABLED
, &enabled
, -1);
575 gtk_tree_model_get (model
, iter
, COL_LANG_CODE
, &code
, -1);
581 *languages
= g_strdup (code
);
583 gchar
*str
= *languages
;
584 *languages
= g_strdup_printf ("%s,%s", str
, code
);
594 preferences_languages_load (EmpathyPreferences
*preferences
)
596 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
599 GList
*enabled_codes
;
601 enabled_codes
= empathy_spell_get_enabled_language_codes ();
603 g_settings_set_boolean (priv
->gsettings_chat
,
604 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED
,
605 enabled_codes
!= NULL
);
607 if (enabled_codes
== NULL
)
610 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
611 model
= gtk_tree_view_get_model (view
);
613 gtk_tree_model_foreach (model
,
614 (GtkTreeModelForeachFunc
) preferences_languages_load_foreach
,
617 g_list_free (enabled_codes
);
621 preferences_languages_load_foreach (GtkTreeModel
*model
,
627 gboolean found
= FALSE
;
633 gtk_tree_model_get (model
, iter
, COL_LANG_CODE
, &code
, -1);
638 if (g_list_find_custom (languages
, code
, (GCompareFunc
) strcmp
)) {
643 gtk_list_store_set (GTK_LIST_STORE (model
), iter
, COL_LANG_ENABLED
, found
, -1);
648 preferences_languages_cell_toggled_cb (GtkCellRendererToggle
*cell
,
650 EmpathyPreferences
*preferences
)
652 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
660 view
= GTK_TREE_VIEW (priv
->treeview_spell_checker
);
661 model
= gtk_tree_view_get_model (view
);
662 store
= GTK_LIST_STORE (model
);
664 path
= gtk_tree_path_new_from_string (path_string
);
666 gtk_tree_model_get_iter (model
, &iter
, path
);
667 gtk_tree_model_get (model
, &iter
, COL_LANG_ENABLED
, &enabled
, -1);
671 gtk_list_store_set (store
, &iter
, COL_LANG_ENABLED
, enabled
, -1);
672 gtk_tree_path_free (path
);
674 preferences_languages_save (preferences
);
678 preferences_preview_theme_append_message (EmpathyChatView
*view
,
679 EmpathyContact
*sender
,
680 EmpathyContact
*receiver
,
682 gboolean should_highlight
)
684 EmpathyMessage
*message
;
686 message
= g_object_new (EMPATHY_TYPE_MESSAGE
,
688 "receiver", receiver
,
692 empathy_chat_view_append_message (view
, message
, should_highlight
);
693 g_object_unref (message
);
697 preferences_preview_theme_changed_cb (EmpathyThemeManager
*manager
,
698 EmpathyPreferences
*preferences
)
700 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
703 EmpathyContact
*juliet
;
704 EmpathyContact
*romeo
;
706 DEBUG ("Theme changed, update preview widget");
708 if (priv
->chat_theme_preview
!= NULL
) {
709 gtk_widget_destroy (GTK_WIDGET (priv
->chat_theme_preview
));
711 priv
->chat_theme_preview
= empathy_theme_manager_create_view (manager
);
712 gtk_container_add (GTK_CONTAINER (priv
->sw_chat_theme_preview
),
713 GTK_WIDGET (priv
->chat_theme_preview
));
714 gtk_widget_show (GTK_WIDGET (priv
->chat_theme_preview
));
716 /* FIXME: It is ugly to add a fake conversation like that.
717 * Would be cool if we could request a TplLogManager for a fake
719 dbus
= tp_dbus_daemon_dup (NULL
);
720 account
= tp_account_new (dbus
,
721 TP_ACCOUNT_OBJECT_PATH_BASE
"cm/jabber/account", NULL
);
722 juliet
= g_object_new (EMPATHY_TYPE_CONTACT
,
725 /* translators: Contact name for the chat theme preview */
726 "alias", _("Juliet"),
729 romeo
= g_object_new (EMPATHY_TYPE_CONTACT
,
732 /* translators: Contact name for the chat theme preview */
737 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
738 /* translators: Quote from Romeo & Julier, for chat theme preview */
739 juliet
, romeo
, _("O Romeo, Romeo, wherefore art thou Romeo?"),
740 TRUE
/* this message mentions Romeo */);
741 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
742 /* translators: Quote from Romeo & Julier, for chat theme preview */
743 juliet
, romeo
, _("Deny thy father and refuse thy name;"), FALSE
);
744 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
745 /* translators: Quote from Romeo & Julier, for chat theme preview */
746 juliet
, romeo
, _("Or if thou wilt not, be but sworn my love"), FALSE
);
747 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
748 /* translators: Quote from Romeo & Julier, for chat theme preview */
749 juliet
, romeo
, _("And I'll no longer be a Capulet."), FALSE
);
750 preferences_preview_theme_append_message (priv
->chat_theme_preview
,
751 /* translators: Quote from Romeo & Julier, for chat theme preview */
752 romeo
, juliet
, _("Shall I hear more, or shall I speak at this?"), FALSE
);
754 /* translators: Quote from Romeo & Julier, for chat theme preview */
755 empathy_chat_view_append_event (priv
->chat_theme_preview
, _("Juliet has disconnected"));
757 g_object_unref (juliet
);
758 g_object_unref (romeo
);
759 g_object_unref (account
);
760 g_object_unref (dbus
);
764 preferences_theme_variant_changed_cb (GtkComboBox
*combo
,
765 EmpathyPreferences
*preferences
)
767 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
770 if (gtk_combo_box_get_active_iter (combo
, &iter
)) {
774 model
= gtk_combo_box_get_model (combo
);
775 gtk_tree_model_get (model
, &iter
,
776 COL_VARIANT_NAME
, &name
,
779 g_settings_set_string (priv
->gsettings_chat
,
780 EMPATHY_PREFS_CHAT_THEME_VARIANT
,
788 preferences_theme_variant_notify_cb (GSettings
*gsettings
,
792 EmpathyPreferences
*preferences
= user_data
;
793 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
798 GtkTreeIter default_iter
;
799 gboolean found_default
= FALSE
;
800 gboolean found
= FALSE
;
803 conf_name
= g_settings_get_string (gsettings
, EMPATHY_PREFS_CHAT_THEME_VARIANT
);
804 combo
= GTK_COMBO_BOX (priv
->combobox_chat_theme_variant
);
805 model
= gtk_combo_box_get_model (combo
);
807 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
809 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
813 gtk_tree_model_get (model
, &iter
,
814 COL_VARIANT_NAME
, &name
,
815 COL_VARIANT_DEFAULT
, &is_default
,
818 if (!tp_strdiff (name
, conf_name
)) {
820 gtk_combo_box_set_active_iter (combo
, &iter
);
823 found_default
= TRUE
;
830 /* Fallback to the first one. */
833 gtk_combo_box_set_active_iter (combo
, &default_iter
);
834 } else if (gtk_tree_model_get_iter_first (model
, &iter
)) {
835 gtk_combo_box_set_active_iter (combo
, &iter
);
842 /* return TRUE if we added at least one variant */
844 preferences_theme_variants_fill (EmpathyPreferences
*preferences
,
847 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
851 const gchar
*default_variant
;
853 gboolean result
= FALSE
;
855 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (priv
->combobox_chat_theme_variant
));
856 store
= GTK_LIST_STORE (model
);
857 gtk_list_store_clear (store
);
859 variants
= empathy_adium_info_get_available_variants (info
);
860 default_variant
= empathy_adium_info_get_default_variant (info
);
861 for (i
= 0; i
< variants
->len
; i
++) {
862 gchar
*name
= g_ptr_array_index (variants
, i
);
864 gtk_list_store_insert_with_values (store
, NULL
, -1,
865 COL_VARIANT_NAME
, name
,
866 COL_VARIANT_DEFAULT
, !tp_strdiff (name
, default_variant
),
872 /* Select the variant from the GSetting key */
873 preferences_theme_variant_notify_cb (priv
->gsettings_chat
,
874 EMPATHY_PREFS_CHAT_THEME_VARIANT
,
881 preferences_theme_variants_setup (EmpathyPreferences
*preferences
)
883 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
885 GtkCellLayout
*cell_layout
;
886 GtkCellRenderer
*renderer
;
889 combo
= GTK_COMBO_BOX (priv
->combobox_chat_theme_variant
);
890 cell_layout
= GTK_CELL_LAYOUT (combo
);
892 /* Create the model */
893 store
= gtk_list_store_new (COL_VARIANT_COUNT
,
894 G_TYPE_STRING
, /* name */
895 G_TYPE_BOOLEAN
); /* is default */
896 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
897 COL_VARIANT_NAME
, GTK_SORT_ASCENDING
);
899 /* Add cell renderer */
900 renderer
= gtk_cell_renderer_text_new ();
901 gtk_cell_layout_pack_start (cell_layout
, renderer
, TRUE
);
902 gtk_cell_layout_set_attributes (cell_layout
, renderer
,
903 "text", COL_VARIANT_NAME
, NULL
);
905 gtk_combo_box_set_model (combo
, GTK_TREE_MODEL (store
));
906 g_object_unref (store
);
908 g_signal_connect (combo
, "changed",
909 G_CALLBACK (preferences_theme_variant_changed_cb
),
912 /* Track changes of the GSetting key */
913 g_signal_connect (priv
->gsettings_chat
,
914 "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT
,
915 G_CALLBACK (preferences_theme_variant_notify_cb
),
920 preferences_theme_changed_cb (GtkComboBox
*combo
,
921 EmpathyPreferences
*preferences
)
923 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
926 if (gtk_combo_box_get_active_iter (combo
, &iter
)) {
933 model
= gtk_combo_box_get_model (combo
);
934 gtk_tree_model_get (model
, &iter
,
935 COL_THEME_IS_ADIUM
, &is_adium
,
936 COL_THEME_NAME
, &name
,
937 COL_THEME_ADIUM_PATH
, &path
,
938 COL_THEME_ADIUM_INFO
, &info
,
941 g_settings_set_string (priv
->gsettings_chat
,
942 EMPATHY_PREFS_CHAT_THEME
,
947 g_settings_set_string (priv
->gsettings_chat
,
948 EMPATHY_PREFS_CHAT_ADIUM_PATH
,
951 variant
= preferences_theme_variants_fill (preferences
, info
);
952 gtk_widget_set_visible (priv
->hbox_chat_theme_variant
, variant
);
954 gtk_widget_hide (priv
->hbox_chat_theme_variant
);
958 tp_clear_pointer (&info
, g_hash_table_unref
);
963 preferences_theme_notify_cb (GSettings
*gsettings
,
967 EmpathyPreferences
*preferences
= user_data
;
968 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
974 gboolean found
= FALSE
;
977 conf_name
= g_settings_get_string (gsettings
, EMPATHY_PREFS_CHAT_THEME
);
978 conf_path
= g_settings_get_string (gsettings
, EMPATHY_PREFS_CHAT_ADIUM_PATH
);
980 combo
= GTK_COMBO_BOX (priv
->combobox_chat_theme
);
981 model
= gtk_combo_box_get_model (combo
);
982 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
984 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
989 gtk_tree_model_get (model
, &iter
,
990 COL_THEME_IS_ADIUM
, &is_adium
,
991 COL_THEME_NAME
, &name
,
992 COL_THEME_ADIUM_PATH
, &path
,
995 if (!tp_strdiff (name
, conf_name
) &&
996 (!is_adium
|| !tp_strdiff (path
, conf_path
))) {
998 gtk_combo_box_set_active_iter (combo
, &iter
);
1005 /* Fallback to the first one. */
1007 if (gtk_tree_model_get_iter_first (model
, &iter
)) {
1008 gtk_combo_box_set_active_iter (combo
, &iter
);
1017 preferences_themes_setup (EmpathyPreferences
*preferences
)
1019 EmpathyPreferencesPriv
*priv
= GET_PRIV (preferences
);
1021 GtkCellLayout
*cell_layout
;
1022 GtkCellRenderer
*renderer
;
1023 GtkListStore
*store
;
1024 const gchar
**themes
;
1025 GList
*adium_themes
;
1028 preferences_theme_variants_setup (preferences
);
1030 combo
= GTK_COMBO_BOX (priv
->combobox_chat_theme
);
1031 cell_layout
= GTK_CELL_LAYOUT (combo
);
1033 /* Create the model */
1034 store
= gtk_list_store_new (COL_THEME_COUNT
,
1035 G_TYPE_STRING
, /* Display name */
1036 G_TYPE_STRING
, /* Theme name */
1037 G_TYPE_BOOLEAN
, /* Is an Adium theme */
1038 G_TYPE_STRING
, /* Adium theme path */
1039 G_TYPE_HASH_TABLE
); /* Adium theme info */
1040 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
1041 COL_THEME_VISIBLE_NAME
, GTK_SORT_ASCENDING
);
1043 /* Fill the model */
1044 themes
= empathy_theme_manager_get_themes ();
1045 for (i
= 0; themes
[i
]; i
+= 2) {
1046 gtk_list_store_insert_with_values (store
, NULL
, -1,
1047 COL_THEME_VISIBLE_NAME
, _(themes
[i
+ 1]),
1048 COL_THEME_NAME
, themes
[i
],
1049 COL_THEME_IS_ADIUM
, FALSE
,
1053 adium_themes
= empathy_theme_manager_get_adium_themes ();
1054 while (adium_themes
!= NULL
) {
1059 info
= adium_themes
->data
;
1060 name
= tp_asv_get_string (info
, "CFBundleName");
1061 path
= tp_asv_get_string (info
, "path");
1063 if (name
!= NULL
&& path
!= NULL
) {
1064 gtk_list_store_insert_with_values (store
, NULL
, -1,
1065 COL_THEME_VISIBLE_NAME
, name
,
1066 COL_THEME_NAME
, "adium",
1067 COL_THEME_IS_ADIUM
, TRUE
,
1068 COL_THEME_ADIUM_PATH
, path
,
1069 COL_THEME_ADIUM_INFO
, info
,
1072 g_hash_table_unref (info
);
1073 adium_themes
= g_list_delete_link (adium_themes
, adium_themes
);
1076 /* Add cell renderer */
1077 renderer
= gtk_cell_renderer_text_new ();
1078 gtk_cell_layout_pack_start (cell_layout
, renderer
, TRUE
);
1079 gtk_cell_layout_set_attributes (cell_layout
, renderer
,
1080 "text", COL_THEME_VISIBLE_NAME
, NULL
);
1082 gtk_combo_box_set_model (combo
, GTK_TREE_MODEL (store
));
1083 g_object_unref (store
);
1085 g_signal_connect (combo
, "changed",
1086 G_CALLBACK (preferences_theme_changed_cb
),
1089 /* Select the theme from the GSetting key and track changes */
1090 preferences_theme_notify_cb (priv
->gsettings_chat
,
1091 EMPATHY_PREFS_CHAT_THEME
,
1093 g_signal_connect (priv
->gsettings_chat
,
1094 "changed::" EMPATHY_PREFS_CHAT_THEME
,
1095 G_CALLBACK (preferences_theme_notify_cb
),
1098 g_signal_connect (priv
->gsettings_chat
,
1099 "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH
,
1100 G_CALLBACK (preferences_theme_notify_cb
),
1105 empathy_preferences_response (GtkDialog
*widget
,
1108 gtk_widget_destroy (GTK_WIDGET (widget
));
1112 empathy_preferences_finalize (GObject
*self
)
1114 EmpathyPreferencesPriv
*priv
= GET_PRIV (self
);
1116 g_object_unref (priv
->theme_manager
);
1118 g_object_unref (priv
->gsettings
);
1119 g_object_unref (priv
->gsettings_chat
);
1120 g_object_unref (priv
->gsettings_call
);
1121 g_object_unref (priv
->gsettings_loc
);
1122 g_object_unref (priv
->gsettings_notify
);
1123 g_object_unref (priv
->gsettings_sound
);
1124 g_object_unref (priv
->gsettings_ui
);
1125 g_object_unref (priv
->gsettings_logger
);
1127 G_OBJECT_CLASS (empathy_preferences_parent_class
)->finalize (self
);
1131 empathy_preferences_class_init (EmpathyPreferencesClass
*klass
)
1133 GtkDialogClass
*dialog_class
= GTK_DIALOG_CLASS (klass
);
1134 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1136 dialog_class
->response
= empathy_preferences_response
;
1138 object_class
->finalize
= empathy_preferences_finalize
;
1140 g_type_class_add_private (object_class
,
1141 sizeof (EmpathyPreferencesPriv
));
1145 empathy_preferences_init (EmpathyPreferences
*preferences
)
1147 EmpathyPreferencesPriv
*priv
;
1152 priv
= preferences
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (preferences
,
1153 EMPATHY_TYPE_PREFERENCES
, EmpathyPreferencesPriv
);
1155 gtk_dialog_add_button (GTK_DIALOG (preferences
),
1156 GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
);
1158 gtk_container_set_border_width (GTK_CONTAINER (preferences
), 5);
1159 gtk_window_set_title (GTK_WINDOW (preferences
), _("Preferences"));
1160 gtk_window_set_role (GTK_WINDOW (preferences
), "preferences");
1161 gtk_window_set_position (GTK_WINDOW (preferences
),
1162 GTK_WIN_POS_CENTER_ON_PARENT
);
1163 gtk_window_set_icon_name (GTK_WINDOW (preferences
), "gtk-preferences");
1165 filename
= empathy_file_lookup ("empathy-preferences.ui", "src");
1166 gui
= empathy_builder_get_file (filename
,
1167 "notebook", &priv
->notebook
,
1168 "checkbutton_show_smileys", &priv
->checkbutton_show_smileys
,
1169 "checkbutton_show_contacts_in_rooms", &priv
->checkbutton_show_contacts_in_rooms
,
1170 "vbox_chat_theme", &priv
->vbox_chat_theme
,
1171 "combobox_chat_theme", &priv
->combobox_chat_theme
,
1172 "combobox_chat_theme_variant", &priv
->combobox_chat_theme_variant
,
1173 "hbox_chat_theme_variant", &priv
->hbox_chat_theme_variant
,
1174 "sw_chat_theme_preview", &priv
->sw_chat_theme_preview
,
1175 "radiobutton_chats_new_windows", &priv
->radiobutton_chats_new_windows
,
1176 "checkbutton_events_notif_area", &priv
->checkbutton_events_notif_area
,
1177 "checkbutton_autoconnect", &priv
->checkbutton_autoconnect
,
1178 "checkbutton_logging", &priv
->checkbutton_logging
,
1179 "checkbutton_notifications_enabled", &priv
->checkbutton_notifications_enabled
,
1180 "checkbutton_notifications_disabled_away", &priv
->checkbutton_notifications_disabled_away
,
1181 "checkbutton_notifications_focus", &priv
->checkbutton_notifications_focus
,
1182 "checkbutton_notifications_contact_signin", &priv
->checkbutton_notifications_contact_signin
,
1183 "checkbutton_notifications_contact_signout", &priv
->checkbutton_notifications_contact_signout
,
1184 "checkbutton_sounds_enabled", &priv
->checkbutton_sounds_enabled
,
1185 "checkbutton_sounds_disabled_away", &priv
->checkbutton_sounds_disabled_away
,
1186 "treeview_sounds", &priv
->treeview_sounds
,
1187 "treeview_spell_checker", &priv
->treeview_spell_checker
,
1188 "checkbutton_location_publish", &priv
->checkbutton_location_publish
,
1189 "checkbutton_location_reduce_accuracy", &priv
->checkbutton_location_reduce_accuracy
,
1190 "checkbutton_location_resource_network", &priv
->checkbutton_location_resource_network
,
1191 "checkbutton_location_resource_cell", &priv
->checkbutton_location_resource_cell
,
1192 "checkbutton_location_resource_gps", &priv
->checkbutton_location_resource_gps
,
1193 "call_echo_cancellation", &priv
->echo_cancellation
,
1197 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (preferences
))), priv
->notebook
);
1198 gtk_widget_show (priv
->notebook
);
1200 g_object_unref (gui
);
1202 priv
->gsettings
= g_settings_new (EMPATHY_PREFS_SCHEMA
);
1203 priv
->gsettings_chat
= g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA
);
1204 priv
->gsettings_call
= g_settings_new (EMPATHY_PREFS_CALL_SCHEMA
);
1205 priv
->gsettings_loc
= g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA
);
1206 priv
->gsettings_notify
= g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA
);
1207 priv
->gsettings_sound
= g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA
);
1208 priv
->gsettings_ui
= g_settings_new (EMPATHY_PREFS_UI_SCHEMA
);
1209 priv
->gsettings_logger
= g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA
);
1211 /* Create chat theme preview, and track changes */
1212 priv
->theme_manager
= empathy_theme_manager_dup_singleton ();
1213 tp_g_signal_connect_object (priv
->theme_manager
, "theme-changed",
1214 G_CALLBACK (preferences_preview_theme_changed_cb
),
1216 preferences_preview_theme_changed_cb (priv
->theme_manager
, preferences
);
1218 preferences_themes_setup (preferences
);
1220 preferences_setup_widgets (preferences
);
1222 preferences_languages_setup (preferences
);
1223 preferences_languages_add (preferences
);
1224 preferences_languages_load (preferences
);
1226 preferences_sound_setup (preferences
);
1227 preferences_sound_load (preferences
);
1229 if (empathy_spell_supported ()) {
1230 page
= gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv
->notebook
), EMPATHY_PREFERENCES_TAB_SPELL
);
1231 gtk_widget_show (page
);
1234 page
= gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv
->notebook
), EMPATHY_PREFERENCES_TAB_LOCATION
);
1236 gtk_widget_show (page
);
1238 gtk_widget_hide (page
);
1242 static EmpathyPreferencesTab
1243 empathy_preferences_tab_from_string (const gchar
*str
)
1247 for (i
= 0; i
< G_N_ELEMENTS (empathy_preferences_tabs
); i
++)
1249 if (!tp_strdiff (str
, empathy_preferences_tabs
[i
]))
1253 g_warn_if_reached ();
1258 empathy_preferences_tab_to_string (EmpathyPreferencesTab tab
)
1260 g_return_val_if_fail (tab
< G_N_ELEMENTS (empathy_preferences_tabs
), NULL
);
1262 return empathy_preferences_tabs
[tab
];
1266 empathy_preferences_new (GtkWindow
*parent
,
1267 gboolean shell_running
)
1270 EmpathyPreferencesPriv
*priv
;
1271 GtkWidget
*notif_page
;
1273 g_return_val_if_fail (parent
== NULL
|| GTK_IS_WINDOW (parent
), NULL
);
1275 self
= g_object_new (EMPATHY_TYPE_PREFERENCES
, NULL
);
1277 if (parent
!= NULL
) {
1278 gtk_window_set_transient_for (GTK_WINDOW (self
),
1282 /* when running in Gnome Shell we must hide these options since they
1283 * are meaningless in that context:
1284 * - 'Display incoming events in the notification area' (General->Behavior)
1285 * - 'Notifications' tab
1287 priv
= GET_PRIV (self
);
1288 if (shell_running
) {
1289 gtk_widget_hide (priv
->checkbutton_events_notif_area
);
1290 notif_page
= gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv
->notebook
),
1291 EMPATHY_PREFERENCES_TAB_NOTIFICATIONS
);
1292 gtk_widget_hide (notif_page
);
1299 empathy_preferences_show_tab (EmpathyPreferences
*self
,
1302 EmpathyPreferencesPriv
*priv
= GET_PRIV (self
);
1304 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv
->notebook
),
1305 empathy_preferences_tab_from_string (page
));