diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2009-08-28 20:36:44 +0800 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2009-08-31 23:20:55 +0800 |
commit | 35aa8545a7ba5d6bef718206f11d3b391dcfc4e4 (patch) | |
tree | 4c0fc7429b2da11a7356c14c0042ebd0b3bd5ce6 | |
parent | 5ca188be7636eec84c5a20be11fb7d137c0efbc1 (diff) | |
download | gsoc2013-empathy-35aa8545a7ba5d6bef718206f11d3b391dcfc4e4.tar gsoc2013-empathy-35aa8545a7ba5d6bef718206f11d3b391dcfc4e4.tar.gz gsoc2013-empathy-35aa8545a7ba5d6bef718206f11d3b391dcfc4e4.tar.bz2 gsoc2013-empathy-35aa8545a7ba5d6bef718206f11d3b391dcfc4e4.tar.lz gsoc2013-empathy-35aa8545a7ba5d6bef718206f11d3b391dcfc4e4.tar.xz gsoc2013-empathy-35aa8545a7ba5d6bef718206f11d3b391dcfc4e4.tar.zst gsoc2013-empathy-35aa8545a7ba5d6bef718206f11d3b391dcfc4e4.zip |
Implement setting icon name to the account and to the settings.
-rw-r--r-- | libempathy/empathy-account-settings.c | 81 | ||||
-rw-r--r-- | libempathy/empathy-account-settings.h | 11 | ||||
-rw-r--r-- | libempathy/empathy-account.c | 70 | ||||
-rw-r--r-- | libempathy/empathy-account.h | 6 |
4 files changed, 166 insertions, 2 deletions
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 81a7a948e..d0858a7da 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -62,6 +62,7 @@ struct _EmpathyAccountSettingsPriv gchar *protocol; gchar *display_name; gchar *icon_name; + gboolean icon_name_set; gboolean display_name_overridden; gboolean ready; @@ -182,9 +183,13 @@ empathy_account_settings_constructed (GObject *object) g_strdup (empathy_account_get_connection_manager (priv->account)); priv->protocol = g_strdup (empathy_account_get_protocol (priv->account)); + priv->icon_name = g_strdup + (empathy_account_get_icon_name (priv->account)); + } + else + { + priv->icon_name = g_strdup_printf ("im-%s", priv->protocol); } - - priv->icon_name = g_strdup_printf ("im-%s", priv->protocol); g_assert (priv->cm_name != NULL && priv->protocol != NULL); @@ -946,6 +951,74 @@ empathy_account_settings_set_display_name_finish ( } static void +account_settings_icon_name_set_cb (GObject *src, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + EmpathyAccount *account = EMPATHY_ACCOUNT (src); + GSimpleAsyncResult *set_result = user_data; + + empathy_account_set_icon_name_finish (account, res, &error); + + if (error != NULL) + { + g_simple_async_result_set_from_error (set_result, error); + g_error_free (error); + } + + g_simple_async_result_complete (set_result); + g_object_unref (set_result); +} + +void +empathy_account_settings_set_icon_name_async ( + EmpathyAccountSettings *settings, + const gchar *name, + GAsyncReadyCallback callback, + gpointer user_data) +{ + EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); + GSimpleAsyncResult *result; + + result = g_simple_async_result_new (G_OBJECT (settings), + callback, user_data, empathy_account_settings_set_icon_name_finish); + + if (priv->account == NULL) + { + if (priv->icon_name != NULL) + g_free (priv->icon_name); + + priv->icon_name = g_strdup (name); + priv->icon_name_set = TRUE; + + g_simple_async_result_complete_in_idle (result); + + return; + } + + empathy_account_set_icon_name_async (priv->account, name, + account_settings_icon_name_set_cb, result); +} + +gboolean +empathy_account_settings_set_icon_name_finish ( + EmpathyAccountSettings *settings, + GAsyncResult *result, + GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (settings), empathy_account_settings_set_icon_name_finish), + FALSE); + + return TRUE; +} + +static void empathy_account_settings_account_updated (GObject *source, GAsyncResult *result, gpointer user_data) @@ -1046,6 +1119,10 @@ empathy_account_settings_do_create_account (EmpathyAccountSettings *settings) TP_STRUCT_TYPE_SIMPLE_PRESENCE, presence); } + if (priv->icon_name_set) + tp_asv_set_string (properties, TP_IFACE_ACCOUNT ".Icon", + priv->icon_name); + empathy_account_manager_create_account_async (priv->account_manager, priv->cm_name, priv->protocol, priv->display_name, priv->parameters, properties, diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h index 476bfb397..c7d263e3b 100644 --- a/libempathy/empathy-account-settings.h +++ b/libempathy/empathy-account-settings.h @@ -133,6 +133,17 @@ void empathy_account_settings_set_boolean (EmpathyAccountSettings *settings, gchar *empathy_account_settings_get_icon_name ( EmpathyAccountSettings *settings); +void empathy_account_settings_set_icon_name_async ( + EmpathyAccountSettings *settings, + const gchar *name, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean empathy_account_settings_set_icon_name_finish ( + EmpathyAccountSettings *settings, + GAsyncResult *result, + GError **error); + const gchar *empathy_account_settings_get_display_name ( EmpathyAccountSettings *settings); diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 0e4758baa..175bea64d 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -240,6 +240,19 @@ empathy_account_update (EmpathyAccount *account, g_object_notify (G_OBJECT (account), "display-name"); } + if (g_hash_table_lookup (properties, "Icon") != NULL) + { + const gchar *icon_name; + + icon_name = tp_asv_get_string (properties, "Icon"); + + if (!EMP_STR_EMPTY (icon_name)) + { + g_free (priv->icon_name); + priv->icon_name = g_strdup (icon_name); + } + } + if (g_hash_table_lookup (properties, "Enabled") != NULL) { gboolean enabled = tp_asv_get_boolean (properties, "Enabled", NULL); @@ -1170,6 +1183,62 @@ empathy_account_set_display_name_finish (EmpathyAccount *account, } static void +account_icon_name_set_cb (TpProxy *proxy, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) + g_simple_async_result_set_from_error (result, (GError *) error); + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +void +empathy_account_set_icon_name_async (EmpathyAccount *account, + const char *icon_name, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + GValue value = {0, }; + EmpathyAccountPriv *priv = GET_PRIV (account); + const char *icon_name_set; + + if (icon_name == NULL) + /* settings an empty icon name is allowed */ + icon_name_set = ""; + else + icon_name_set = icon_name; + + result = g_simple_async_result_new (G_OBJECT (account), callback, + user_data, empathy_account_set_icon_name_finish); + + g_value_init (&value, G_TYPE_STRING); + g_value_set_string (&value, icon_name_set); + + tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT, + "Icon", &value, account_icon_name_set_cb, result, NULL, + G_OBJECT (account)); +} + +gboolean +empathy_account_set_icon_name_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error) || + !g_simple_async_result_is_valid (result, G_OBJECT (account), + empathy_account_set_icon_name_finish)) + return FALSE; + + return TRUE; +} + +static void empathy_account_remove_cb (TpAccount *proxy, const GError *error, gpointer user_data, @@ -1232,3 +1301,4 @@ empathy_account_refresh_properties (EmpathyAccount *account) NULL, G_OBJECT (account)); } + diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h index e789ca702..66f899448 100644 --- a/libempathy/empathy-account.h +++ b/libempathy/empathy-account.h @@ -102,6 +102,12 @@ void empathy_account_set_display_name_async (EmpathyAccount *account, gboolean empathy_account_set_display_name_finish (EmpathyAccount *account, GAsyncResult *result, GError **error); +void empathy_account_set_icon_name_async (EmpathyAccount *account, + const gchar *icon_name, GAsyncReadyCallback callback, + gpointer user_data); +gboolean empathy_account_set_icon_name_finish (EmpathyAccount *account, + GAsyncResult *result, GError **error); + EmpathyAccount *empathy_account_new (TpDBusDaemon *bus_daemon, const gchar *unique_name); |