#include <stdio.h>
#include <stdlib.h>
+#include <telepathy-glib/account-manager.h>
#include <telepathy-glib/util.h>
#include <telepathy-glib/interfaces.h>
#include <telepathy-glib/gtypes.h>
#include "empathy-account-settings.h"
-#include "empathy-account-manager.h"
#include "empathy-connection-managers.h"
#include "empathy-utils.h"
+#include "empathy-idle.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
+#include <libempathy/empathy-debug.h>
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountSettings)
PROP_ACCOUNT = 1,
PROP_CM_NAME,
PROP_PROTOCOL,
+ PROP_SERVICE,
PROP_DISPLAY_NAME,
PROP_DISPLAY_NAME_OVERRIDDEN,
PROP_READY
{
gboolean dispose_has_run;
EmpathyConnectionManagers *managers;
- EmpathyAccountManager *account_manager;
- gulong account_manager_ready_id;
+ TpAccountManager *account_manager;
TpConnectionManager *manager;
- const TpConnectionManagerProtocol *tp_protocol;
- EmpathyAccount *account;
+ TpAccount *account;
gchar *cm_name;
gchar *protocol;
+ gchar *service;
gchar *display_name;
gchar *icon_name;
gboolean display_name_overridden;
gboolean ready;
+ /* Parameter name (gchar *) -> parameter value (GValue) */
GHashTable *parameters;
+ /* Keys are parameter names from the hash above (gchar *).
+ * Values are regular expresions that should match corresponding parameter
+ * values (GRegex *). Possible regexp patterns are defined in
+ * empathy-account-widget.c */
+ GHashTable *param_regexps;
GArray *unset_parameters;
- GArray *required_params;
+ GList *required_params;
gulong managers_ready_id;
- gulong account_ready_id;
GSimpleAsyncResult *apply_result;
};
/* allocate any data required by the object here */
priv->managers = empathy_connection_managers_dup_singleton ();
- priv->account_manager = empathy_account_manager_dup_singleton ();
+ priv->account_manager = tp_account_manager_dup ();
priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) tp_g_value_slice_free);
+ priv->param_regexps = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) g_regex_unref);
+
priv->unset_parameters = g_array_new (TRUE, FALSE, sizeof (gchar *));
+
+ priv->required_params = NULL;
}
static void empathy_account_settings_dispose (GObject *object);
static void empathy_account_settings_finalize (GObject *object);
-static void empathy_account_settings_ready_cb (GObject *obj,
- GParamSpec *spec, gpointer user_data);
+static void empathy_account_settings_account_ready_cb (GObject *source_object,
+ GAsyncResult *result, gpointer user_data);
+static void empathy_account_settings_managers_ready_cb (GObject *obj,
+ GParamSpec *pspec, gpointer user_data);
static void empathy_account_settings_check_readyness (
EmpathyAccountSettings *self);
case PROP_PROTOCOL:
priv->protocol = g_value_dup_string (value);
break;
+ case PROP_SERVICE:
+ priv->service = g_value_dup_string (value);
+ break;
case PROP_DISPLAY_NAME:
priv->display_name = g_value_dup_string (value);
break;
case PROP_PROTOCOL:
g_value_set_string (value, priv->protocol);
break;
+ case PROP_SERVICE:
+ g_value_set_string (value, priv->service);
+ break;
case PROP_DISPLAY_NAME:
g_value_set_string (value, priv->display_name);
break;
{
g_free (priv->cm_name);
g_free (priv->protocol);
+ g_free (priv->service);
priv->cm_name =
- g_strdup (empathy_account_get_connection_manager (priv->account));
+ g_strdup (tp_account_get_connection_manager (priv->account));
priv->protocol =
- g_strdup (empathy_account_get_protocol (priv->account));
+ g_strdup (tp_account_get_protocol (priv->account));
+ priv->service =
+ g_strdup (tp_account_get_service (priv->account));
+ priv->icon_name = g_strdup
+ (tp_account_get_icon_name (priv->account));
+ }
+ else
+ {
+ priv->icon_name = empathy_protocol_icon_name (priv->protocol);
}
-
- priv->icon_name = g_strdup_printf ("im-%s", priv->protocol);
g_assert (priv->cm_name != NULL && priv->protocol != NULL);
if (!priv->ready)
{
- g_signal_connect (priv->account, "notify::ready",
- G_CALLBACK (empathy_account_settings_ready_cb), self);
- g_signal_connect (priv->managers, "notify::ready",
- G_CALLBACK (empathy_account_settings_ready_cb), self);
+ GQuark features[] = {
+ TP_ACCOUNT_FEATURE_CORE,
+ TP_ACCOUNT_FEATURE_STORAGE,
+ 0 };
+
+ tp_proxy_prepare_async (priv->account, features,
+ empathy_account_settings_account_ready_cb, self);
+ tp_g_signal_connect_object (priv->managers, "notify::ready",
+ G_CALLBACK (empathy_account_settings_managers_ready_cb), object, 0);
}
if (G_OBJECT_CLASS (
g_object_class_install_property (object_class, PROP_ACCOUNT,
g_param_spec_object ("account",
"Account",
- "The EmpathyAccount backing these settings",
- EMPATHY_TYPE_ACCOUNT,
+ "The TpAccount backing these settings",
+ TP_TYPE_ACCOUNT,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_CM_NAME,
NULL,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class, PROP_SERVICE,
+ g_param_spec_string ("service",
+ "Service",
+ "The service of this account, or NULL",
+ NULL,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
g_object_class_install_property (object_class, PROP_DISPLAY_NAME,
g_param_spec_string ("display-name",
"display-name",
g_object_class_install_property (object_class, PROP_DISPLAY_NAME_OVERRIDDEN,
g_param_spec_boolean ("display-name-overridden",
"display-name-overridden",
- "Whether the display name for this account has been manually overridden",
+ "Whether the display name for this account has been manually "
+ "overridden",
FALSE,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
g_object_unref (priv->manager);
priv->manager = NULL;
- if (priv->account_manager_ready_id != 0)
- g_signal_handler_disconnect (priv->account_manager,
- priv->account_manager_ready_id);
- priv->account_manager_ready_id = 0;
-
if (priv->account_manager != NULL)
g_object_unref (priv->account_manager);
priv->account_manager = NULL;
- if (priv->account_ready_id != 0)
- g_signal_handler_disconnect (priv->account, priv->account_ready_id);
- priv->account_ready_id = 0;
-
if (priv->account != NULL)
g_object_unref (priv->account);
priv->account = NULL;
EmpathyAccountSettings *settings)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- int i;
+ guint i;
for (i = 0 ; i < priv->unset_parameters->len; i++)
g_free (g_array_index (priv->unset_parameters, gchar *, i));
{
EmpathyAccountSettings *self = EMPATHY_ACCOUNT_SETTINGS (object);
EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+ GList *l;
/* free any data held directly by the object here */
g_free (priv->cm_name);
g_free (priv->protocol);
+ g_free (priv->service);
g_free (priv->display_name);
g_free (priv->icon_name);
+ if (priv->required_params != NULL)
+ {
+ for (l = priv->required_params; l; l = l->next)
+ g_free (l->data);
+ g_list_free (priv->required_params);
+ }
+
g_hash_table_destroy (priv->parameters);
+ g_hash_table_destroy (priv->param_regexps);
empathy_account_settings_free_unset_parameters (self);
g_array_free (priv->unset_parameters, TRUE);
empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+ const TpConnectionManagerProtocol *tp_protocol;
if (priv->ready)
return;
- if (priv->account != NULL && !empathy_account_is_ready (priv->account))
+ if (priv->account != NULL
+ && !tp_account_is_prepared (priv->account, TP_ACCOUNT_FEATURE_CORE))
return;
if (!empathy_connection_managers_is_ready (priv->managers))
{
g_free (priv->display_name);
priv->display_name =
- g_strdup (empathy_account_get_display_name (priv->account));
+ g_strdup (tp_account_get_display_name (priv->account));
g_free (priv->icon_name);
priv->icon_name =
- g_strdup (empathy_account_get_icon_name (priv->account));
+ g_strdup (tp_account_get_icon_name (priv->account));
}
- priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager,
+ tp_protocol = tp_connection_manager_get_protocol (priv->manager,
priv->protocol);
- if (priv->tp_protocol == NULL)
+ if (tp_protocol == NULL)
{
priv->manager = NULL;
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++)
+ for (cur = 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);
+ priv->required_params = g_list_append (priv->required_params,
+ g_strdup (cur->name));
}
}
}
}
static void
-empathy_account_settings_ready_cb (GObject *obj,
- GParamSpec *spec,
+empathy_account_settings_account_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
+ TpAccount *account = TP_ACCOUNT (source_object);
+ GError *error = NULL;
+
+ if (!tp_proxy_prepare_finish (account, result, &error))
+ {
+ DEBUG ("Failed to prepare account: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ empathy_account_settings_check_readyness (settings);
+}
+
+static void
+empathy_account_settings_managers_ready_cb (GObject *object,
+ GParamSpec *pspec,
gpointer user_data)
{
EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
EmpathyAccountSettings *
empathy_account_settings_new (const gchar *connection_manager,
const gchar *protocol,
+ const gchar *service,
const char *display_name)
{
return g_object_new (EMPATHY_TYPE_ACCOUNT_SETTINGS,
"connection-manager", connection_manager,
"protocol", protocol,
+ "service", service,
"display-name", display_name,
NULL);
}
EmpathyAccountSettings *
-empathy_account_settings_new_for_account (EmpathyAccount *account)
+empathy_account_settings_new_for_account (TpAccount *account)
{
return g_object_new (EMPATHY_TYPE_ACCOUNT_SETTINGS,
"account", account,
empathy_account_settings_get_tp_params (EmpathyAccountSettings *settings)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ const TpConnectionManagerProtocol *tp_protocol;
- g_return_val_if_fail (priv->tp_protocol != NULL, NULL);
+ g_return_val_if_fail (priv->manager != NULL, NULL);
+ g_return_val_if_fail (priv->protocol != NULL, NULL);
- return priv->tp_protocol->params;
+ tp_protocol = tp_connection_manager_get_protocol (priv->manager,
+ priv->protocol);
+ if (tp_protocol == NULL)
+ {
+ DEBUG ("Can't retrieve TpConnectionManagerProtocol for protocol '%s'",
+ priv->protocol);
+ return NULL;
+ }
+
+ return tp_protocol->params;
}
gboolean
return priv->protocol;
}
+const gchar *
+empathy_account_settings_get_service (EmpathyAccountSettings *settings)
+{
+ EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+
+ return priv->service;
+}
+
gchar *
empathy_account_settings_get_icon_name (EmpathyAccountSettings *settings)
{
return priv->display_name;
}
-EmpathyAccount *
+TpAccount *
empathy_account_settings_get_account (EmpathyAccountSettings *settings)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
GArray *a;
- int i;
+ guint i;
a = priv->unset_parameters;
const gchar *param)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- int idx;
+ guint idx;
gchar *val;
for (idx = 0; idx < priv->unset_parameters->len; idx++)
p = empathy_account_settings_get_tp_param (settings, param);
+ if (p == NULL)
+ return NULL;
+
return p->dbus_signature;
}
{
const GHashTable *parameters;
- parameters = empathy_account_get_parameters (priv->account);
+ parameters = tp_account_get_parameters (priv->account);
result = tp_asv_lookup (parameters, param);
if (result != NULL)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- if (g_hash_table_size (priv->parameters) > 0)
- g_hash_table_remove_all (priv->parameters);
-
- if (priv->unset_parameters->len > 0)
- {
- g_array_remove_range (priv->unset_parameters, 0,
- priv->unset_parameters->len);
- }
+ g_hash_table_remove_all (priv->parameters);
+ empathy_account_settings_free_unset_parameters (settings);
}
const gchar *
return g_value_get_string (v);
}
+const gchar * const *
+empathy_account_settings_get_strv (EmpathyAccountSettings *settings,
+ const gchar *param)
+{
+ const GValue *v;
+
+ v = empathy_account_settings_get (settings, param);
+
+ if (v == NULL || !G_VALUE_HOLDS (v, G_TYPE_STRV))
+ return NULL;
+
+ return g_value_get_boxed (v);
+}
+
gint32
empathy_account_settings_get_int32 (EmpathyAccountSettings *settings,
const gchar *param)
ret = g_value_get_int (v);
break;
case G_TYPE_UINT:
- ret = CLAMP (G_MININT32, g_value_get_uint (v), G_MAXINT32);
+ ret = CLAMP (g_value_get_uint (v), (guint) G_MININT32,
+ G_MAXINT32);
break;
case G_TYPE_INT64:
- ret = CLAMP (G_MININT32, g_value_get_int64 (v), G_MAXINT32);
+ ret = CLAMP (g_value_get_int64 (v), G_MININT32, G_MAXINT32);
break;
case G_TYPE_UINT64:
- ret = CLAMP (G_MININT32, g_value_get_uint64 (v), G_MAXINT32);
+ ret = CLAMP (g_value_get_uint64 (v), (guint64) G_MININT32,
+ G_MAXINT32);
break;
default:
ret = 0;
ret = g_value_get_int64 (v);
break;
case G_TYPE_UINT64:
- ret = CLAMP (G_MININT64, g_value_get_uint64 (v), G_MAXINT64);
+ ret = CLAMP (g_value_get_uint64 (v), (guint64) G_MININT64, G_MAXINT64);
break;
default:
ret = 0;
guint32 ret;
v = empathy_account_settings_get (settings, param);
+ if (v == NULL)
+ return 0;
switch G_VALUE_TYPE (v)
{
ret = g_value_get_uint (v);
break;
case G_TYPE_INT64:
- ret = CLAMP (0, g_value_get_int64 (v), G_MAXUINT32);
+ ret = CLAMP (g_value_get_int64 (v), 0, G_MAXUINT32);
break;
case G_TYPE_UINT64:
- ret = CLAMP (0, g_value_get_uint64 (v), G_MAXUINT32);
+ ret = MIN (g_value_get_uint64 (v), G_MAXUINT32);
break;
default:
ret = 0;
ret = MAX (0, g_value_get_int64 (v));
break;
case G_TYPE_UINT64:
- ret = CLAMP (0, g_value_get_uint64 (v), G_MAXUINT64);
+ ret = g_value_get_uint64 (v);
break;
default:
ret = 0;
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ g_return_if_fail (param != NULL);
+ g_return_if_fail (value != NULL);
+
tp_asv_set_string (priv->parameters, g_strdup (param), value);
account_settings_remove_from_unset (settings, param);
}
+void
+empathy_account_settings_set_strv (EmpathyAccountSettings *settings,
+ const gchar *param,
+ gchar **value)
+{
+ EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+
+ g_return_if_fail (param != NULL);
+ g_return_if_fail (value != NULL);
+
+ tp_asv_set_strv (priv->parameters, g_strdup (param), value);
+
+ account_settings_remove_from_unset (settings, param);
+}
+
void
empathy_account_settings_set_int32 (EmpathyAccountSettings *settings,
const gchar *param,
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ g_return_if_fail (param != NULL);
+
tp_asv_set_int32 (priv->parameters, g_strdup (param), value);
account_settings_remove_from_unset (settings, param);
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ g_return_if_fail (param != NULL);
+
tp_asv_set_int64 (priv->parameters, g_strdup (param), value);
account_settings_remove_from_unset (settings, param);
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ g_return_if_fail (param != NULL);
+
tp_asv_set_uint32 (priv->parameters, g_strdup (param), value);
account_settings_remove_from_unset (settings, param);
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ g_return_if_fail (param != NULL);
+
tp_asv_set_uint64 (priv->parameters, g_strdup (param), value);
account_settings_remove_from_unset (settings, param);
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ g_return_if_fail (param != NULL);
+
tp_asv_set_boolean (priv->parameters, g_strdup (param), value);
account_settings_remove_from_unset (settings, param);
gpointer user_data)
{
GError *error = NULL;
- EmpathyAccount *account = EMPATHY_ACCOUNT (src);
+ TpAccount *account = TP_ACCOUNT (src);
GSimpleAsyncResult *set_result = user_data;
- empathy_account_set_display_name_finish (account, res, &error);
+ tp_account_set_display_name_finish (account, res, &error);
if (error != NULL)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
GSimpleAsyncResult *result;
+ g_return_if_fail (name != NULL);
+
result = g_simple_async_result_new (G_OBJECT (settings),
callback, user_data, empathy_account_settings_set_display_name_finish);
+ if (!tp_strdiff (name, priv->display_name))
+ {
+ /* Nothing to do */
+ g_simple_async_result_complete_in_idle (result);
+ return;
+ }
+
if (priv->account == NULL)
{
if (priv->display_name != NULL)
return;
}
- empathy_account_set_display_name_async (priv->account, name,
+ tp_account_set_display_name_async (priv->account, name,
account_settings_display_name_set_cb, result);
}
return TRUE;
}
+static void
+account_settings_icon_name_set_cb (GObject *src,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ TpAccount *account = TP_ACCOUNT (src);
+ GSimpleAsyncResult *set_result = user_data;
+
+ tp_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;
+
+ g_return_if_fail (name != NULL);
+
+ 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);
+
+ g_simple_async_result_complete_in_idle (result);
+
+ return;
+ }
+
+ tp_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,
GSimpleAsyncResult *r;
GError *error = NULL;
- if (!empathy_account_update_settings_finish (EMPATHY_ACCOUNT (source),
- result, &error))
+ if (!tp_account_update_parameters_finish (TP_ACCOUNT (source),
+ result, NULL, &error))
{
g_simple_async_result_set_from_error (priv->apply_result, error);
g_error_free (error);
}
+ else
+ {
+ empathy_account_settings_discard_changes (settings);
+ }
r = priv->apply_result;
priv->apply_result = NULL;
{
EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- EmpathyAccount *account;
+ TpAccount *account;
GError *error = NULL;
GSimpleAsyncResult *r;
- account = empathy_account_manager_create_account_finish (
- EMPATHY_ACCOUNT_MANAGER (source), result, &error);
+ account = tp_account_manager_create_account_finish (
+ TP_ACCOUNT_MANAGER (source), result, &error);
if (account == NULL)
- g_simple_async_result_set_from_error (priv->apply_result, error);
+ {
+ g_simple_async_result_set_from_error (priv->apply_result, error);
+ }
else
- priv->account = g_object_ref (account);
+ {
+ priv->account = g_object_ref (account);
+ empathy_account_settings_discard_changes (settings);
+ }
r = priv->apply_result;
priv->apply_result = NULL;
TpConnectionPresenceType type;
gchar *status;
gchar *message;
+ EmpathyIdle *idle;
properties = tp_asv_new (NULL, NULL);
- type = empathy_account_manager_get_requested_global_presence
- (priv->account_manager, &status, &message);
+ idle = empathy_idle_dup_singleton ();
+ type = empathy_idle_get_requested_presence (idle, &status, &message);
+ g_object_unref (idle);
if (type != TP_CONNECTION_PRESENCE_TYPE_UNSET)
{
TP_STRUCT_TYPE_SIMPLE_PRESENCE, presence);
}
- empathy_account_manager_create_account_async (priv->account_manager,
+ tp_asv_set_string (properties, TP_IFACE_ACCOUNT ".Icon",
+ priv->icon_name);
+
+ if (priv->service != NULL)
+ tp_asv_set_string (properties, TP_PROP_ACCOUNT_SERVICE, priv->service);
+
+ tp_account_manager_create_account_async (priv->account_manager,
priv->cm_name, priv->protocol, priv->display_name,
priv->parameters, properties,
empathy_account_settings_created_cb,
}
static void
-empathy_account_settings_manager_ready_cb (EmpathyAccountManager *manager,
- GParamSpec *spec,
+empathy_account_settings_manager_ready_cb (GObject *source_object,
+ GAsyncResult *result,
gpointer user_data)
{
EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
+ GError *error = NULL;
- if (empathy_account_manager_is_ready (manager))
+ if (!tp_account_manager_prepare_finish (account_manager, result, &error))
{
- g_assert (priv->apply_result != NULL && priv->account == NULL);
- g_signal_handler_disconnect (priv->account_manager,
- priv->account_manager_ready_id);
- priv->account_manager_ready_id = 0;
-
- empathy_account_settings_do_create_account (settings);
+ DEBUG ("Failed to prepare account manager: %s", error->message);
+ g_error_free (error);
+ return;
}
+
+ g_assert (priv->apply_result != NULL && priv->account == NULL);
+ empathy_account_settings_do_create_account (settings);
}
void
if (priv->apply_result != NULL)
{
g_simple_async_report_error_in_idle (G_OBJECT (settings),
- callback, user_data,
- G_IO_ERROR, G_IO_ERROR_PENDING, "Applying already in progress");
+ callback, user_data,
+ G_IO_ERROR, G_IO_ERROR_PENDING, "Applying already in progress");
return;
}
if (priv->account == NULL)
{
- const gchar *default_display_name;
- default_display_name = empathy_account_settings_get_string (settings,
- "account");
- empathy_account_settings_set_display_name_async (settings,
- default_display_name, NULL, NULL);
-
- if (empathy_account_manager_is_ready (priv->account_manager))
- empathy_account_settings_do_create_account (settings);
- else
- priv->account_manager_ready_id = g_signal_connect (
- priv->account_manager,
- "notify::ready",
- G_CALLBACK (empathy_account_settings_manager_ready_cb),
- settings);
+ tp_account_manager_prepare_async (priv->account_manager, NULL,
+ empathy_account_settings_manager_ready_cb, settings);
}
else
{
- empathy_account_update_settings_async (priv->account,
- priv->parameters, (const gchar **)priv->unset_parameters->data,
- empathy_account_settings_account_updated, settings);
-
- g_hash_table_remove_all (priv->parameters);
- empathy_account_settings_free_unset_parameters (settings);
+ tp_account_update_parameters_async (priv->account,
+ priv->parameters, (const gchar **)priv->unset_parameters->data,
+ empathy_account_settings_account_updated, settings);
}
}
gboolean
empathy_account_settings_has_account (EmpathyAccountSettings *settings,
- EmpathyAccount *account)
+ TpAccount *account)
{
EmpathyAccountSettingsPriv *priv;
+ const gchar *account_path;
+ const gchar *priv_account_path;
g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
- g_return_val_if_fail (EMPATHY_IS_ACCOUNT (account), FALSE);
+ g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE);
priv = GET_PRIV (settings);
- return (account == priv->account);
+ if (priv->account == NULL)
+ return FALSE;
+
+ account_path = tp_proxy_get_object_path (TP_PROXY (account));
+ priv_account_path = tp_proxy_get_object_path (TP_PROXY (priv->account));
+
+ return (!tp_strdiff (account_path, priv_account_path));
+}
+
+void
+empathy_account_settings_set_regex (EmpathyAccountSettings *settings,
+ const gchar *param,
+ const gchar *pattern)
+{
+ EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ GRegex *regex;
+
+ regex = g_regex_new (pattern, 0, 0, NULL);
+ g_hash_table_insert (priv->param_regexps, g_strdup (param), regex);
}
gboolean
-empathy_account_settings_is_valid (EmpathyAccountSettings *settings)
+empathy_account_settings_parameter_is_valid (
+ EmpathyAccountSettings *settings,
+ const gchar *param)
{
EmpathyAccountSettingsPriv *priv;
- int idx;
- gchar *current;
- gboolean missed = FALSE;
+ const GRegex *regex;
+ const gchar *value;
g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
priv = GET_PRIV (settings);
- for (idx = 0; idx < priv->required_params->len; idx++)
+ if (g_list_find_custom (priv->required_params, param, (GCompareFunc) strcmp))
{
- 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 (tp_asv_lookup (priv->parameters, param))
+ goto test_regex;
/* 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))
+ !empathy_account_settings_is_unset (settings, param))
{
const GHashTable *account_params;
- account_params = empathy_account_get_parameters (priv->account);
- if (tp_asv_lookup (account_params, current))
- continue;
+ account_params = tp_account_get_parameters (priv->account);
+ if (tp_asv_lookup (account_params, param))
+ goto test_regex;
}
- missed = TRUE;
- break;
+ return FALSE;
+ }
+
+test_regex:
+ /* test whether parameter value matches its regex */
+ regex = g_hash_table_lookup (priv->param_regexps, param);
+ if (regex)
+ {
+ value = empathy_account_settings_get_string (settings, param);
+ if (value != NULL && !g_regex_match (regex, value, 0, NULL))
+ return FALSE;
}
- return !missed;
+ return TRUE;
+}
+
+gboolean
+empathy_account_settings_is_valid (EmpathyAccountSettings *settings)
+{
+ EmpathyAccountSettingsPriv *priv;
+ const gchar *param;
+ GHashTableIter iter;
+ GList *l;
+
+ g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
+
+ priv = GET_PRIV (settings);
+
+ for (l = priv->required_params; l; l = l->next)
+ {
+ if (!empathy_account_settings_parameter_is_valid (settings, l->data))
+ return FALSE;
+ }
+
+ g_hash_table_iter_init (&iter, priv->param_regexps);
+ while (g_hash_table_iter_next (&iter, (gpointer *) ¶m, NULL))
+ {
+ if (!empathy_account_settings_parameter_is_valid (settings, param))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+const TpConnectionManagerProtocol *
+empathy_account_settings_get_tp_protocol (EmpathyAccountSettings *self)
+{
+ EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+
+ return tp_connection_manager_get_protocol (priv->manager, priv->protocol);
}