From 74c8015453317b0084bdac8a22e6974e2af0865d Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 3 May 2011 16:21:54 +0200 Subject: Preferences: Show chat theme preview Fixes bug #541438 --- src/empathy-preferences.c | 250 +++++--- src/empathy-preferences.ui | 1427 ++++++++++++++++++++++++-------------------- 2 files changed, 965 insertions(+), 712 deletions(-) (limited to 'src') diff --git a/src/empathy-preferences.c b/src/empathy-preferences.c index 813637dca..52bc3de7a 100644 --- a/src/empathy-preferences.c +++ b/src/empathy-preferences.c @@ -48,6 +48,9 @@ #include "empathy-preferences.h" +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include + G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG); #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv) @@ -57,7 +60,6 @@ struct _EmpathyPreferencesPriv { GtkWidget *checkbutton_show_smileys; GtkWidget *checkbutton_show_contacts_in_rooms; - GtkWidget *combobox_chat_theme; GtkWidget *checkbutton_separate_chat_windows; GtkWidget *checkbutton_events_notif_area; GtkWidget *checkbutton_autoconnect; @@ -81,6 +83,12 @@ struct _EmpathyPreferencesPriv { GtkWidget *checkbutton_location_resource_cell; GtkWidget *checkbutton_location_resource_gps; + GtkWidget *vbox_chat_theme; + GtkWidget *combobox_chat_theme; + GtkWidget *sw_chat_theme_preview; + EmpathyChatView *chat_theme_preview; + EmpathyThemeManager *theme_manager; + GSettings *gsettings; GSettings *gsettings_chat; GSettings *gsettings_loc; @@ -115,11 +123,11 @@ enum { }; enum { - COL_COMBO_IS_ADIUM, - COL_COMBO_VISIBLE_NAME, - COL_COMBO_NAME, - COL_COMBO_PATH, - COL_COMBO_COUNT + COL_THEME_VISIBLE_NAME, + COL_THEME_NAME, + COL_THEME_IS_ADIUM, + COL_THEME_ADIUM_PATH, + COL_THEME_COUNT }; enum { @@ -645,6 +653,124 @@ preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell, preferences_languages_save (preferences); } +static void +preferences_preview_theme_append_message (EmpathyChatView *view, + EmpathyContact *sender, + EmpathyContact *receiver, + const gchar *text) +{ + EmpathyMessage *message; + + message = g_object_new (EMPATHY_TYPE_MESSAGE, + "sender", sender, + "receiver", receiver, + "body", text, + NULL); + + empathy_chat_view_append_message (view, message); + g_object_unref (message); +} + +static void +preferences_preview_theme_changed_cb (EmpathyThemeManager *manager, + EmpathyPreferences *preferences) +{ + EmpathyPreferencesPriv *priv = GET_PRIV (preferences); + TpDBusDaemon *dbus; + TpAccount *account; + EmpathyContact *juliet; + EmpathyContact *romeo; + + DEBUG ("Theme changed, update preview widget"); + + if (priv->chat_theme_preview != NULL) { + gtk_widget_destroy (GTK_WIDGET (priv->chat_theme_preview)); + } + priv->chat_theme_preview = empathy_theme_manager_create_view (manager); + gtk_container_add (GTK_CONTAINER (priv->sw_chat_theme_preview), + GTK_WIDGET (priv->chat_theme_preview)); + gtk_widget_show (GTK_WIDGET (priv->chat_theme_preview)); + + /* FIXME: It is ugly to add a fake conversation like that. + * Would be cool if we could request a TplLogManager for a fake + * conversation */ + dbus = tp_dbus_daemon_dup (NULL); + account = tp_account_new (dbus, + TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL); + juliet = g_object_new (EMPATHY_TYPE_CONTACT, + "account", account, + "id", "juliet", + /* translators: Contact name for the chat theme preview */ + "alias", _("Juliet"), + "is-user", FALSE, + NULL); + romeo = g_object_new (EMPATHY_TYPE_CONTACT, + "account", account, + "id", "romeo", + /* translators: Contact name for the chat theme preview */ + "alias", _("Romeo"), + "is-user", TRUE, + NULL); + + preferences_preview_theme_append_message (priv->chat_theme_preview, + /* translators: Quote from Romeo & Julier, for chat theme preview */ + juliet, romeo, _("O Romeo, Romeo, wherefore art thou Romeo?")); + preferences_preview_theme_append_message (priv->chat_theme_preview, + /* translators: Quote from Romeo & Julier, for chat theme preview */ + juliet, romeo, _("Deny thy father and refuse thy name;")); + preferences_preview_theme_append_message (priv->chat_theme_preview, + /* translators: Quote from Romeo & Julier, for chat theme preview */ + juliet, romeo, _("Or if thou wilt not, be but sworn my love")); + preferences_preview_theme_append_message (priv->chat_theme_preview, + /* translators: Quote from Romeo & Julier, for chat theme preview */ + juliet, romeo, _("And I'll no longer be a Capulet.")); + preferences_preview_theme_append_message (priv->chat_theme_preview, + /* translators: Quote from Romeo & Julier, for chat theme preview */ + romeo, juliet, _("Shall I hear more, or shall I speak at this?")); + + /* translators: Quote from Romeo & Julier, for chat theme preview */ + empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected")); + + g_object_unref (juliet); + g_object_unref (romeo); + g_object_unref (account); + g_object_unref (dbus); +} + +static void +preferences_theme_changed_cb (GtkComboBox *combo, + EmpathyPreferences *preferences) +{ + EmpathyPreferencesPriv *priv = GET_PRIV (preferences); + GtkTreeIter iter; + + if (gtk_combo_box_get_active_iter (combo, &iter)) { + GtkTreeModel *model; + gboolean is_adium; + gchar *name; + gchar *path; + + model = gtk_combo_box_get_model (combo); + gtk_tree_model_get (model, &iter, + COL_THEME_IS_ADIUM, &is_adium, + COL_THEME_NAME, &name, + COL_THEME_ADIUM_PATH, &path, + -1); + + g_settings_set_string (priv->gsettings_chat, + EMPATHY_PREFS_CHAT_THEME, + name); + if (is_adium) { + g_settings_set_string (priv->gsettings_chat, + EMPATHY_PREFS_CHAT_ADIUM_PATH, + path); + } + + g_free (name); + g_free (path); + } +} + static void preferences_theme_notify_cb (GSettings *gsettings, const gchar *key, @@ -658,38 +784,34 @@ preferences_theme_notify_cb (GSettings *gsettings, GtkTreeModel *model; GtkTreeIter iter; gboolean found = FALSE; + gboolean ok; conf_name = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_THEME); conf_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ADIUM_PATH); combo = GTK_COMBO_BOX (priv->combobox_chat_theme); model = gtk_combo_box_get_model (combo); - if (gtk_tree_model_get_iter_first (model, &iter)) { + for (ok = gtk_tree_model_get_iter_first (model, &iter); + ok && !found; + ok = gtk_tree_model_iter_next (model, &iter)) { gboolean is_adium; gchar *name; gchar *path; - do { - gtk_tree_model_get (model, &iter, - COL_COMBO_IS_ADIUM, &is_adium, - COL_COMBO_NAME, &name, - COL_COMBO_PATH, &path, - -1); - - if (!tp_strdiff (name, conf_name)) { - if (tp_strdiff (name, "adium") || - !tp_strdiff (path, conf_path)) { - found = TRUE; - gtk_combo_box_set_active_iter (combo, &iter); - g_free (name); - g_free (path); - break; - } - } - - g_free (name); - g_free (path); - } while (gtk_tree_model_iter_next (model, &iter)); + gtk_tree_model_get (model, &iter, + COL_THEME_IS_ADIUM, &is_adium, + COL_THEME_NAME, &name, + COL_THEME_ADIUM_PATH, &path, + -1); + + if (!tp_strdiff (name, conf_name) && + (!is_adium || !tp_strdiff (path, conf_path))) { + found = TRUE; + gtk_combo_box_set_active_iter (combo, &iter); + } + + g_free (name); + g_free (path); } /* Fallback to the first one. */ @@ -703,38 +825,6 @@ preferences_theme_notify_cb (GSettings *gsettings, g_free (conf_path); } -static void -preferences_theme_changed_cb (GtkComboBox *combo, - EmpathyPreferences *preferences) -{ - EmpathyPreferencesPriv *priv = GET_PRIV (preferences); - GtkTreeModel *model; - GtkTreeIter iter; - gboolean is_adium; - gchar *name; - gchar *path; - - if (gtk_combo_box_get_active_iter (combo, &iter)) { - model = gtk_combo_box_get_model (combo); - - gtk_tree_model_get (model, &iter, - COL_COMBO_IS_ADIUM, &is_adium, - COL_COMBO_NAME, &name, - COL_COMBO_PATH, &path, - -1); - - g_settings_set_string (priv->gsettings_chat, - EMPATHY_PREFS_CHAT_THEME, - name); - if (is_adium == TRUE) - g_settings_set_string (priv->gsettings_chat, - EMPATHY_PREFS_CHAT_ADIUM_PATH, - path); - g_free (name); - g_free (path); - } -} - static void preferences_themes_setup (EmpathyPreferences *preferences) { @@ -751,22 +841,21 @@ preferences_themes_setup (EmpathyPreferences *preferences) cell_layout = GTK_CELL_LAYOUT (combo); /* Create the model */ - store = gtk_list_store_new (COL_COMBO_COUNT, - G_TYPE_BOOLEAN, /* Is an Adium theme */ - G_TYPE_STRING, /* Display name */ - G_TYPE_STRING, /* Theme name */ - G_TYPE_STRING); /* Theme path */ + store = gtk_list_store_new (COL_THEME_COUNT, + G_TYPE_STRING, /* Display name */ + G_TYPE_STRING, /* Theme name */ + G_TYPE_BOOLEAN, /* Is an Adium theme */ + G_TYPE_STRING); /* Adium theme path */ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), - COL_COMBO_VISIBLE_NAME, GTK_SORT_ASCENDING); + COL_THEME_VISIBLE_NAME, GTK_SORT_ASCENDING); /* Fill the model */ themes = empathy_theme_manager_get_themes (); for (i = 0; themes[i]; i += 2) { gtk_list_store_insert_with_values (store, NULL, -1, - COL_COMBO_IS_ADIUM, FALSE, - COL_COMBO_VISIBLE_NAME, _(themes[i + 1]), - COL_COMBO_NAME, themes[i], - COL_COMBO_PATH, NULL, + COL_THEME_VISIBLE_NAME, _(themes[i + 1]), + COL_THEME_NAME, themes[i], + COL_THEME_IS_ADIUM, FALSE, -1); } @@ -782,10 +871,10 @@ preferences_themes_setup (EmpathyPreferences *preferences) if (name != NULL && path != NULL) { gtk_list_store_insert_with_values (store, NULL, -1, - COL_COMBO_IS_ADIUM, TRUE, - COL_COMBO_VISIBLE_NAME, name, - COL_COMBO_NAME, "adium", - COL_COMBO_PATH, path, + COL_THEME_VISIBLE_NAME, name, + COL_THEME_NAME, "adium", + COL_THEME_IS_ADIUM, TRUE, + COL_THEME_ADIUM_PATH, path, -1); } g_hash_table_unref (info); @@ -796,7 +885,7 @@ preferences_themes_setup (EmpathyPreferences *preferences) renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, TRUE); gtk_cell_layout_set_attributes (cell_layout, renderer, - "text", COL_COMBO_VISIBLE_NAME, NULL); + "text", COL_THEME_VISIBLE_NAME, NULL); gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store)); g_object_unref (store); @@ -832,6 +921,8 @@ empathy_preferences_finalize (GObject *self) { EmpathyPreferencesPriv *priv = GET_PRIV (self); + g_object_unref (priv->theme_manager); + g_object_unref (priv->gsettings); g_object_unref (priv->gsettings_chat); g_object_unref (priv->gsettings_loc); @@ -883,7 +974,9 @@ empathy_preferences_init (EmpathyPreferences *preferences) "notebook", &priv->notebook, "checkbutton_show_smileys", &priv->checkbutton_show_smileys, "checkbutton_show_contacts_in_rooms", &priv->checkbutton_show_contacts_in_rooms, + "vbox_chat_theme", &priv->vbox_chat_theme, "combobox_chat_theme", &priv->combobox_chat_theme, + "sw_chat_theme_preview", &priv->sw_chat_theme_preview, "checkbutton_separate_chat_windows", &priv->checkbutton_separate_chat_windows, "checkbutton_events_notif_area", &priv->checkbutton_events_notif_area, "checkbutton_autoconnect", &priv->checkbutton_autoconnect, @@ -918,6 +1011,13 @@ empathy_preferences_init (EmpathyPreferences *preferences) priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA); priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA); + /* Create chat theme preview, and track changes */ + priv->theme_manager = empathy_theme_manager_dup_singleton (); + tp_g_signal_connect_object (priv->theme_manager, "theme-changed", + G_CALLBACK (preferences_preview_theme_changed_cb), + preferences, 0); + preferences_preview_theme_changed_cb (priv->theme_manager, preferences); + preferences_themes_setup (preferences); preferences_setup_widgets (preferences); diff --git a/src/empathy-preferences.ui b/src/empathy-preferences.ui index 4acc6f3c7..6bc17b761 100644 --- a/src/empathy-preferences.ui +++ b/src/empathy-preferences.ui @@ -1,308 +1,606 @@ - + - - + + True + True + 5 + + + True + False + 12 + vertical + 18 + + True - True - 5 + False + 0 + none - + True - 12 - 18 - vertical + False + 6 + 12 - + True - 0 - none + False + vertical - + + Show _smileys as images True - 6 - 12 - - - True - vertical - - - Show _smileys as images - True - True - False - True - True - True - - - False - False - 2 - - - - - Show contact _list in rooms - True - True - False - True - True - True - - - False - False - 3 - - - - + True + False + False + True + True + True + + False + False + 2 + - - + + + Show contact _list in rooms True - Appearance - - - + True + False + False + True + True + True + + False + False + 3 + - - False - False - 0 - + + + + + True + False + Appearance + + + + + + + + False + False + 0 + + + + + True + False + 0 + none + + + True + False + 6 + 12 - + True - 0 - none + False + vertical - + + _Open new chats in separate windows True - 6 - 12 - - - vertical - True - - - _Open new chats in separate windows - True - True - False - True - True - - - False - False - 0 - - - - - Display incoming events in the notification area - True - True - False - True - True - - - False - False - 1 - - - - - _Automatically connect on startup - True - True - False - True - True - True - - - 2 - - - - - Log conversations - True - True - False - True - True - True - - - 3 - - - - + True + False + False + True + True + + False + False + 0 + - - + + + Display incoming events in the notification area + True + True + False + False + True + True + + + False + False + 1 + + + + + _Automatically connect on startup + True + True + False + False + True + True + True + + + False + True + 2 + + + + + Log conversations True - Behavior - - - + True + False + False + True + True + True + + False + True + 3 + + + + + + + True + False + Behavior + + + + + + + + False + False + 1 + + + + + + + True + False + General + + + False + + + + + True + False + 12 + vertical + 6 + + + _Enable bubble notifications + True + True + False + False + True + True + + + False + False + 0 + + + + + True + False + 12 + + + True + False + vertical + 6 + + + Disable notifications when _away or busy + True + True + False + False + True + True + + + False + True + 0 + + + + + Enable notifications when the _chat is not focused + True + True + False + False + True + True + False - False + True 1 + + + Enable notifications when a contact comes online + True + True + False + False + True + True + + + False + True + 2 + + + + + Enable notifications when a contact goes offline + True + True + False + False + True + True + + + False + True + 3 + + - - + + + False + True + 1 + + + + + 1 + + + + + True + False + Notifications + + + 1 + False + + + + + True + False + 12 + vertical + 18 + + + True + False + vertical + 6 + + + _Enable sound notifications True - General + True + False + False + True + True - False + False + False + 0 - + True - 12 - 6 - vertical + False + 12 - - _Enable bubble notifications + + Disable sounds when _away or busy True True False + False True True - - False - False - 0 - + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + vertical + 6 + + + True + False + 0 + Play sound for events + + + + + + False + False + 0 + + + + + True + False + 12 + + + True + True + in + + + True + True + False + + + + + + + + + + True + True + 1 + + + + + False + True + 1 + + + + + 2 + + + + + True + False + Sounds + + + 2 + False + + + + + True + False + 12 + vertical + 18 + + + _Publish location to my contacts + True + True + False + False + True + True + + + False + False + 0 + + + + + True + False + 0 + none + + + True + False + 6 + 12 - + True - 12 + False + vertical + 6 - + True + False 6 - vertical - - Disable notifications when _away or busy + True - True - False - True - True + False + 0 + gtk-dialog-info + False + True 0 - - Enable notifications when the _chat is not focused + True - True - False - True - True + False + 0 + Reduced location accuracy means that nothing more precise than your city, state and country will be published. GPS coordinates will be accurate to 1 decimal place. + True + + + + False + True 1 - - - Enable notifications when a contact comes online - True - True - False - True - True - - - 2 - - - - - Enable notifications when a contact goes offline - True - True - False - True - True - - - 3 - - + + False + True + 0 + + + + + _Reduce location accuracy + True + True + False + False + True + True + True + + + False + False + 1 + - - False - 1 - - - 1 - - - + + True - Notifications + False + Privacy + + + - - 1 - False - + + + False + False + 1 + + + + + True + False + 0 + none - + True - 12 - 18 - vertical + False + 6 + 12 - + True - 6 + False vertical - - _Enable sound notifications + + _GPS True True False + False True True @@ -313,500 +611,355 @@ - + + _Cellphone True - 12 - - - Disable sounds when _away or busy - True - True - False - True - True - - + True + False + False + True + True + True + False + False 1 - - - False - 0 - - - - - True - 6 - vertical - + + _Network (IP, Wi-Fi) True - 0 - Play sound for events - - - + True + False + False + True + True + True False False - 0 - - - - - True - 12 - - - True - True - automatic - automatic - in - - - True - True - False - - - - - - - 1 - True + 2 - - 1 - - - 2 - - - + + True - Sounds + False + Location sources: + + + - - 2 - False - + + + False + True + 2 + + + + + 3 + + + + + True + False + Location + + + 3 + False + + + + + True + False + 12 + vertical + 18 + + + True + False + 0 + none - + True - 12 - vertical - 18 - - - _Publish location to my contacts - True - True - False - True - True - - - False - False - 0 - - + False + 6 + 12 - + True - 0 - none + False + vertical + 6 - + True - 6 - 12 + False + in - + True - vertical - 6 - - - True - 6 - horizontal - - - True - 0 - gtk-dialog-info - - - False - 0 - - - - - True - 0 - True - Reduced location accuracy means that nothing more precise than your city, state and country will be published. GPS coordinates will be accurate to 1 decimal place. - - - - - - 1 - - - - - False - 0 - - - - - _Reduce location accuracy - True - True - False - True - True - True - - - False - False - 1 - + True + False + + + + True + True + 0 + - - - True - Privacy - - - - - - - - False - False - 1 - - - - - True - 0 - none - + True - 6 - 12 + False + 6 - + True - vertical - - - _GPS - True - True - False - True - True - - - False - False - 0 - - - - - _Cellphone - True - True - False - True - True - True - - - False - False - 1 - - - - - _Network (IP, Wi-Fi) - True - True - False - True - True - True - - - False - False - 2 - - + False + 0 + gtk-dialog-info + + False + True + 0 + + + + + True + False + 0 + The list of languages reflects only the languages for which you have a dictionary installed. + True + + + + + + False + True + 1 + - - - - True - Location sources: - - - - + + False + True + 1 + - - False - 2 - - - 3 - - - + + True - Location + False + Enable spell checking for languages: + + + - - 3 - False - + + + False + True + 0 + + + + + + + + 4 + + + + + True + False + Spell Checking + + + 4 + False + + + + + True + False + 12 + vertical + 18 + + + True + False + 0 + none - + True - 12 - 18 - vertical + False + 6 + 12 - + True - 0 - none + False + vertical + 6 - + True - 6 - 12 + False + 12 - + True - 6 - vertical - - - True - False - automatic - automatic - in - - - True - True - False - - - - - 0 - True - - - - - True - 6 - horizontal - - - True - 0 - gtk-dialog-info - - - False - 0 - - - - - True - 0 - True - The list of languages reflects only the languages for which you have a dictionary installed. - - - - - - 1 - - - - - False - 1 - - + False + Chat Th_eme: + True + combobox_chat_theme + + False + False + 0 + + + + + True + False + + + False + False + 1 + + + False + True + 0 + - - - True - Enable spell checking for languages: - - - - - - - - 0 - - - - - - - - 4 - - - - - True - Spell Checking - - - 4 - False - - - - - True - 12 - 18 - vertical - - - True - 0 - none - - True - 6 - 12 + + False + False + 12 - + True - 6 - vertical - - - True - 12 - horizontal - - - True - Chat Th_eme: - True - combobox_chat_theme - - - False - False - 0 - - - - - True - - - False - False - 1 - - - - - 0 - - + False + Theme Variant: + True + combobox_chat_theme_variant + + + False + False + 0 + + + + + True + False + + False + False + 1 + + + False + True + 1 + - - + + True - Appearance - - - + True + in + + + + + True + True + 2 + - - False - False - 0 - - - 5 - - - + + True - Themes + False + Appearance + + + - - 5 - False - + + True + True + 0 + + + + + 5 + + + + + True + False + Themes + + + 5 + False + + + -- cgit v1.2.3