diff options
Diffstat (limited to 'libempathy/empathy-account-settings.c')
-rw-r--r-- | libempathy/empathy-account-settings.c | 123 |
1 files changed, 121 insertions, 2 deletions
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c index 0b92ec1b1..df99ea1c5 100644 --- a/libempathy/empathy-account-settings.c +++ b/libempathy/empathy-account-settings.c @@ -72,6 +72,7 @@ struct _EmpathyAccountSettingsPriv GHashTable *parameters; GArray *unset_parameters; + GArray *required_params; gulong managers_ready_id; gulong account_ready_id; @@ -360,6 +361,23 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self) return; } + if (priv->required_params == NULL) + { + TpConnectionManagerParam *cur; + char *val; + + priv->required_params = g_array_new (TRUE, FALSE, sizeof (gchar *)); + + for (cur = priv->tp_protocol->params; cur->name != NULL; cur++) + { + if (tp_connection_manager_param_is_required (cur)) + { + val = g_strdup (cur->name); + g_array_append_val (priv->required_params, val); + } + } + } + g_object_ref (priv->manager); priv->ready = TRUE; @@ -430,13 +448,16 @@ empathy_account_settings_get_protocol (EmpathyAccountSettings *settings) return priv->protocol; } -const gchar * +gchar * empathy_account_settings_get_icon_name (EmpathyAccountSettings *settings) { EmpathyAccountSettingsPriv *priv = GET_PRIV (settings); if (priv->account != NULL) - return empathy_account_get_icon_name (priv->account); + return g_strdup (empathy_account_get_icon_name (priv->account)); + + if (priv->tp_protocol != NULL) + return g_strdup_printf ("im-%s", priv->tp_protocol->name); return NULL; } @@ -800,6 +821,26 @@ empathy_account_settings_set_boolean (EmpathyAccountSettings *settings, tp_asv_set_boolean (priv->parameters, param, value); } +static void +account_settings_display_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_display_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_display_name_async ( @@ -808,6 +849,26 @@ empathy_account_settings_set_display_name_async ( 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_display_name_finish); + + if (priv->account == NULL) + { + if (priv->display_name != NULL) + g_free (priv->display_name); + + priv->display_name = g_strdup (name); + + g_simple_async_result_complete_in_idle (result); + + return; + } + + empathy_account_set_display_name_async (priv->account, name, + account_settings_display_name_set_cb, result); } gboolean @@ -816,6 +877,12 @@ empathy_account_settings_set_display_name_finish ( 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_display_name_finish), FALSE); return TRUE; } @@ -965,3 +1032,55 @@ empathy_account_settings_apply_finish (EmpathyAccountSettings *settings, return TRUE; } + +gboolean +empathy_account_settings_has_account (EmpathyAccountSettings *settings, + EmpathyAccount *account) +{ + EmpathyAccountSettingsPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE); + g_return_val_if_fail (EMPATHY_IS_ACCOUNT (account), FALSE); + + priv = GET_PRIV (settings); + + return (account == priv->account); +} + +gboolean +empathy_account_settings_is_valid (EmpathyAccountSettings *settings) +{ + EmpathyAccountSettingsPriv *priv; + int idx; + gchar *current; + gboolean missed = FALSE; + + g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE); + + priv = GET_PRIV (settings); + + for (idx = 0; idx < priv->required_params->len; idx++) + { + current = g_array_index (priv->required_params, gchar *, idx); + + /* first, look if it's set in our own parameters */ + if (tp_asv_lookup (priv->parameters, current)) + continue; + + /* if we did not unset the parameter, look if it's in the account */ + if (priv->account != NULL && + !empathy_account_settings_is_unset (settings, current)) + { + const GHashTable *account_params; + + account_params = empathy_account_get_parameters (priv->account); + if (tp_asv_lookup (account_params, current)) + continue; + } + + missed = TRUE; + break; + } + + return !missed; +} |