]> git.0d.be Git - empathy.git/blobdiff - src/empathy-preferences.c
GNOME Goal: Update icon names
[empathy.git] / src / empathy-preferences.c
index ee800543055eb220a6c53154befaab82c7380d50..6901aa9c8b88e366ed27b78d925306df0a6dbec8 100644 (file)
  *          Danielle Madeley <danielle.madeley@collabora.co.uk>
  */
 
-#include <config.h>
-
-#include <string.h>
-#include <stdio.h>
+#include "config.h"
+#include "empathy-preferences.h"
 
-#include <gtk/gtk.h>
 #include <glib/gi18n.h>
-#include <telepathy-glib/dbus.h>
-#include <telepathy-glib/util.h>
-
-#include <libempathy/empathy-gsettings.h>
-#include <libempathy/empathy-utils.h>
 
-#include <libempathy-gtk/empathy-ui-utils.h>
-#include <libempathy-gtk/empathy-theme-manager.h>
-#include <libempathy-gtk/empathy-spell.h>
-#include <libempathy-gtk/empathy-gtk-enum-types.h>
-#include <libempathy-gtk/empathy-theme-adium.h>
-
-#include "empathy-preferences.h"
+#include "empathy-client-factory.h"
+#include "empathy-gsettings.h"
+#include "empathy-spell.h"
+#include "empathy-theme-manager.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
 
@@ -75,7 +66,7 @@ struct _EmpathyPreferencesPriv {
        GtkWidget *combobox_chat_theme_variant;
        GtkWidget *hbox_chat_theme_variant;
        GtkWidget *sw_chat_theme_preview;
-       EmpathyChatView *chat_theme_preview;
+       EmpathyThemeAdium *chat_theme_preview;
        EmpathyThemeManager *theme_manager;
 
        GSettings *gsettings;
@@ -86,7 +77,6 @@ struct _EmpathyPreferencesPriv {
        GSettings *gsettings_sound;
        GSettings *gsettings_ui;
        GSettings *gsettings_logger;
-       GSettings *gsettings_contacts;
 };
 
 static void     preferences_setup_widgets                (EmpathyPreferences      *preferences,
@@ -116,9 +106,7 @@ enum {
 
 enum {
        COL_THEME_VISIBLE_NAME,
-       COL_THEME_NAME,
-       COL_THEME_IS_ADIUM,
-       COL_THEME_ADIUM_PATH,
+       COL_THEME_ADIUM_NAME,
        COL_THEME_ADIUM_INFO,
        COL_THEME_COUNT
 };
@@ -152,36 +140,6 @@ static SoundEventEntry sound_entries [] = {
        { N_("Account disconnected"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT }
 };
 
-static gboolean
-sort_criterium_get_mapping (GValue *value,
-                           GVariant *variant,
-                           gpointer user_data)
-{
-       const char *s = g_variant_get_string (variant, NULL);
-
-       if (!tp_strdiff (s, "state"))
-               g_value_set_boolean (value, TRUE);
-       else if (!tp_strdiff (s, "name"))
-               g_value_set_boolean (value, FALSE);
-       else
-               return FALSE;
-
-       return TRUE;
-}
-
-static GVariant *
-sort_criterium_set_mapping (const GValue *value,
-                           const GVariantType *expected_type,
-                           gpointer user_data)
-{
-       gboolean b = g_value_get_boolean (value);
-
-       if (b)
-               return g_variant_new_string ("state");
-       else
-               return g_variant_new_string ("name");
-}
-
 static void
 preferences_setup_widgets (EmpathyPreferences *preferences,
                           GtkBuilder *gui)
@@ -210,16 +168,12 @@ preferences_setup_widgets (EmpathyPreferences *preferences,
 
        BIND_ACTIVE (ui, UI_SHOW_OFFLINE,
                     "checkbutton_show_offline");
-       BIND_ACTIVE (ui, UI_SHOW_PROTOCOLS,
-                    "checkbutton_show_protocols");
+       BIND_ACTIVE (ui, UI_SHOW_GROUPS,
+                    "checkbutton_show_groups");
        BIND_ACTIVE (ui, UI_SEPARATE_CHAT_WINDOWS,
                     "radiobutton_chats_new_windows");
        BIND_ACTIVE (ui, UI_EVENTS_NOTIFY_AREA,
                     "checkbutton_events_notif_area");
-       BIND_ACTIVE (ui, UI_SHOW_AVATARS,
-                    "radiobutton_normal_size_avatars");
-       BIND_ACTIVE (ui, UI_COMPACT_CONTACT_LIST,
-                    "radiobutton_compact_size");
        BIND_ACTIVE (ui, UI_SHOW_BALANCES,
                     "checkbutton_show_balances");
 
@@ -284,16 +238,6 @@ preferences_setup_widgets (EmpathyPreferences *preferences,
                                                 "checkbutton_autoconnect"),
                         "active",
                         G_SETTINGS_BIND_DEFAULT);
-
-       g_settings_bind_with_mapping (priv->gsettings_contacts,
-                        EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
-                        gtk_builder_get_object (gui,
-                                                "radiobutton_sort_by_status"),
-                        "active",
-                        G_SETTINGS_BIND_DEFAULT,
-                        sort_criterium_get_mapping,
-                        sort_criterium_set_mapping,
-                        NULL, NULL);
 }
 
 static void
@@ -631,7 +575,7 @@ preferences_languages_cell_toggled_cb (GtkCellRendererToggle *cell,
 }
 
 static void
-preferences_preview_theme_append_message (EmpathyChatView *view,
+preferences_preview_theme_append_message (EmpathyThemeAdium *view,
                                          EmpathyContact *sender,
                                          EmpathyContact *receiver,
                                          const gchar *text,
@@ -645,7 +589,7 @@ preferences_preview_theme_append_message (EmpathyChatView *view,
                "body", text,
                NULL);
 
-       empathy_chat_view_append_message (view, message, should_highlight);
+       empathy_theme_adium_append_message (view, message, should_highlight);
        g_object_unref (message);
 }
 
@@ -654,7 +598,7 @@ preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
                                      EmpathyPreferences  *preferences)
 {
        EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
-       TpDBusDaemon *dbus;
+       EmpathyClientFactory *factory;
        TpAccount *account;
        EmpathyContact *juliet;
        EmpathyContact *romeo;
@@ -672,9 +616,11 @@ preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
        /* 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);
+       factory = empathy_client_factory_dup ();
+
+       account = tp_simple_client_factory_ensure_account (
+               TP_SIMPLE_CLIENT_FACTORY (factory),
+               TP_ACCOUNT_OBJECT_PATH_BASE "cm/jabber/account", NULL, NULL);
        juliet = g_object_new (EMPATHY_TYPE_CONTACT,
                "account", account,
                "id", "juliet",
@@ -708,12 +654,12 @@ preferences_preview_theme_changed_cb (EmpathyThemeManager *manager,
                romeo, juliet, _("Shall I hear more, or shall I speak at this?"), FALSE);
 
        /* translators: Quote from Romeo & Julier, for chat theme preview */
-       empathy_chat_view_append_event (priv->chat_theme_preview, _("Juliet has disconnected"));
+       empathy_theme_adium_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);
+       g_object_unref (factory);
 }
 
 static void
@@ -881,36 +827,24 @@ preferences_theme_changed_cb (GtkComboBox        *combo,
 
        if (gtk_combo_box_get_active_iter (combo, &iter)) {
                GtkTreeModel *model;
-               gboolean      is_adium;
                gchar        *name;
-               gchar        *path;
                GHashTable   *info;
+               gboolean variant;
 
                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,
+                                   COL_THEME_ADIUM_NAME, &name,
                                    COL_THEME_ADIUM_INFO, &info,
                                    -1);
 
                g_settings_set_string (priv->gsettings_chat,
                                       EMPATHY_PREFS_CHAT_THEME,
                                       name);
-               if (is_adium) {
-                       gboolean variant;
 
-                       g_settings_set_string (priv->gsettings_chat,
-                                              EMPATHY_PREFS_CHAT_ADIUM_PATH,
-                                              path);
+               variant = preferences_theme_variants_fill (preferences, info);
+               gtk_widget_set_visible (priv->hbox_chat_theme_variant, variant);
 
-                       variant = preferences_theme_variants_fill (preferences, info);
-                       gtk_widget_set_visible (priv->hbox_chat_theme_variant, variant);
-               } else {
-                       gtk_widget_hide (priv->hbox_chat_theme_variant);
-               }
                g_free (name);
-               g_free (path);
                tp_clear_pointer (&info, g_hash_table_unref);
        }
 }
@@ -923,39 +857,31 @@ preferences_theme_notify_cb (GSettings   *gsettings,
        EmpathyPreferences *preferences = user_data;
        EmpathyPreferencesPriv *priv = GET_PRIV (preferences);
        GtkComboBox        *combo;
-       gchar              *conf_name;
-       gchar              *conf_path;
+       gchar              *theme;
        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);
+       theme = g_settings_get_string (gsettings, key);
 
        combo = GTK_COMBO_BOX (priv->combobox_chat_theme);
        model = gtk_combo_box_get_model (combo);
        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;
 
                gtk_tree_model_get (model, &iter,
-                                   COL_THEME_IS_ADIUM, &is_adium,
-                                   COL_THEME_NAME, &name,
-                                   COL_THEME_ADIUM_PATH, &path,
+                                   COL_THEME_ADIUM_NAME, &name,
                                    -1);
 
-               if (!tp_strdiff (name, conf_name) &&
-                   (!is_adium || !tp_strdiff (path, conf_path))) {
+               if (!tp_strdiff (name, theme)) {
                        found = TRUE;
                        gtk_combo_box_set_active_iter (combo, &iter);
                }
 
                g_free (name);
-               g_free (path);
        }
 
        /* Fallback to the first one. */
@@ -965,8 +891,7 @@ preferences_theme_notify_cb (GSettings   *gsettings,
                }
        }
 
-       g_free (conf_name);
-       g_free (conf_path);
+       g_free (theme);
 }
 
 static void
@@ -977,9 +902,7 @@ preferences_themes_setup (EmpathyPreferences *preferences)
        GtkCellLayout *cell_layout;
        GtkCellRenderer *renderer;
        GtkListStore  *store;
-       const gchar  **themes;
        GList         *adium_themes;
-       gint           i;
 
        preferences_theme_variants_setup (preferences);
 
@@ -989,43 +912,32 @@ preferences_themes_setup (EmpathyPreferences *preferences)
        /* Create the model */
        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 */
                                    G_TYPE_HASH_TABLE); /* Adium theme info */
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
                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_THEME_VISIBLE_NAME, _(themes[i + 1]),
-                       COL_THEME_NAME, themes[i],
-                       COL_THEME_IS_ADIUM, FALSE,
-                       -1);
-       }
-
        adium_themes = empathy_theme_manager_get_adium_themes ();
        while (adium_themes != NULL) {
                GHashTable *info;
-               const gchar *name;
-               const gchar *path;
+               const gchar *visible_name;
+               gchar *name;
 
                info = adium_themes->data;
-               name = tp_asv_get_string (info, "CFBundleName");
-               path = tp_asv_get_string (info, "path");
+               visible_name = tp_asv_get_string (info, "CFBundleName");
+               name = empathy_theme_manager_dup_theme_name_from_path (
+                       tp_asv_get_string (info, "path"));
 
-               if (name != NULL && path != NULL) {
+               if (visible_name != NULL && name != NULL) {
                        gtk_list_store_insert_with_values (store, NULL, -1,
-                               COL_THEME_VISIBLE_NAME, name,
-                               COL_THEME_NAME, "adium",
-                               COL_THEME_IS_ADIUM, TRUE,
-                               COL_THEME_ADIUM_PATH, path,
+                               COL_THEME_VISIBLE_NAME, visible_name,
+                               COL_THEME_ADIUM_NAME, name,
                                COL_THEME_ADIUM_INFO, info,
                                -1);
                }
                g_hash_table_unref (info);
+               g_free (name);
                adium_themes = g_list_delete_link (adium_themes, adium_themes);
        }
 
@@ -1046,13 +958,9 @@ preferences_themes_setup (EmpathyPreferences *preferences)
        preferences_theme_notify_cb (priv->gsettings_chat,
                                     EMPATHY_PREFS_CHAT_THEME,
                                     preferences);
-       g_signal_connect (priv->gsettings_chat,
-                         "changed::" EMPATHY_PREFS_CHAT_THEME,
-                         G_CALLBACK (preferences_theme_notify_cb),
-                         preferences);
 
        g_signal_connect (priv->gsettings_chat,
-                         "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH,
+                         "changed::" EMPATHY_PREFS_CHAT_THEME,
                          G_CALLBACK (preferences_theme_notify_cb),
                          preferences);
 }
@@ -1079,7 +987,6 @@ empathy_preferences_finalize (GObject *self)
        g_object_unref (priv->gsettings_sound);
        g_object_unref (priv->gsettings_ui);
        g_object_unref (priv->gsettings_logger);
-       g_object_unref (priv->gsettings_contacts);
 
        G_OBJECT_CLASS (empathy_preferences_parent_class)->finalize (self);
 }
@@ -1117,7 +1024,7 @@ empathy_preferences_init (EmpathyPreferences *preferences)
        gtk_window_set_role (GTK_WINDOW (preferences), "preferences");
        gtk_window_set_position (GTK_WINDOW (preferences),
                                 GTK_WIN_POS_CENTER_ON_PARENT);
-       gtk_window_set_icon_name (GTK_WINDOW (preferences), "gtk-preferences");
+       gtk_window_set_icon_name (GTK_WINDOW (preferences), "preferences-desktop");
 
        filename = empathy_file_lookup ("empathy-preferences.ui", "src");
        gui = empathy_builder_get_file (filename,
@@ -1144,7 +1051,6 @@ empathy_preferences_init (EmpathyPreferences *preferences)
        priv->gsettings_sound = g_settings_new (EMPATHY_PREFS_SOUNDS_SCHEMA);
        priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
        priv->gsettings_logger = g_settings_new (EMPATHY_PREFS_LOGGER_SCHEMA);
-       priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
 
        /* Create chat theme preview, and track changes */
        priv->theme_manager = empathy_theme_manager_dup_singleton ();