#include <stdlib.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"
PROP_CM_NAME,
PROP_PROTOCOL,
PROP_DISPLAY_NAME,
+ PROP_DISPLAY_NAME_OVERRIDDEN,
PROP_READY
};
gchar *cm_name;
gchar *protocol;
gchar *display_name;
+ gchar *icon_name;
+ gboolean display_name_overridden;
gboolean ready;
GHashTable *parameters;
priv->managers = empathy_connection_managers_dup_singleton ();
priv->account_manager = empathy_account_manager_dup_singleton ();
- priv->parameters = tp_asv_new (NULL, NULL);
+ priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) tp_g_value_slice_free);
+
priv->unset_parameters = g_array_new (TRUE, FALSE, sizeof (gchar *));
}
case PROP_DISPLAY_NAME:
priv->display_name = g_value_dup_string (value);
break;
+ case PROP_DISPLAY_NAME_OVERRIDDEN:
+ priv->display_name_overridden = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_DISPLAY_NAME:
g_value_set_string (value, priv->display_name);
break;
+ case PROP_DISPLAY_NAME_OVERRIDDEN:
+ g_value_set_boolean (value, priv->display_name_overridden);
+ break;
case PROP_READY:
g_value_set_boolean (value, priv->ready);
break;
{
g_free (priv->cm_name);
g_free (priv->protocol);
- g_free (priv->display_name);
priv->cm_name =
g_strdup (empathy_account_get_connection_manager (priv->account));
priv->protocol =
g_strdup (empathy_account_get_protocol (priv->account));
- priv->display_name =
- g_strdup (empathy_account_get_display_name (priv->account));
+ priv->icon_name = g_strdup
+ (empathy_account_get_icon_name (priv->account));
+ }
+ else
+ {
+ priv->icon_name = empathy_protocol_icon_name (priv->protocol);
}
- g_assert (priv->cm_name != NULL && priv->protocol != NULL
- && priv->display_name != NULL);
+ g_assert (priv->cm_name != NULL && priv->protocol != NULL);
empathy_account_settings_check_readyness (self);
NULL,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ 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",
+ FALSE,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
+
g_object_class_install_property (object_class, PROP_READY,
g_param_spec_boolean ("ready",
"Ready",
g_free (priv->cm_name);
g_free (priv->protocol);
g_free (priv->display_name);
+ g_free (priv->icon_name);
g_hash_table_destroy (priv->parameters);
if (priv->manager == NULL)
return;
+ if (priv->account != NULL)
+ {
+ g_free (priv->display_name);
+ priv->display_name =
+ g_strdup (empathy_account_get_display_name (priv->account));
+
+ g_free (priv->icon_name);
+ priv->icon_name =
+ g_strdup (empathy_account_get_icon_name (priv->account));
+ }
+
priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager,
priv->protocol);
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- if (priv->account != NULL)
- 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;
+ return priv->icon_name;
}
const gchar *
return NULL;
}
+static void
+account_settings_remove_from_unset (EmpathyAccountSettings *settings,
+ const gchar *param)
+{
+ EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ int idx;
+ gchar *val;
+
+ for (idx = 0; idx < priv->unset_parameters->len; idx++)
+ {
+ val = g_array_index (priv->unset_parameters, gchar *, idx);
+
+ if (!tp_strdiff (val, param))
+ {
+ priv->unset_parameters =
+ g_array_remove_index (priv->unset_parameters, idx);
+ g_free (val);
+
+ break;
+ }
+ }
+}
+
const GValue *
empathy_account_settings_get_default (EmpathyAccountSettings *settings,
const gchar *param)
}
const gchar *
-empathy_settings_get_dbus_signature (EmpathyAccountSettings *settings,
+empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings,
const gchar *param)
{
TpConnectionManagerParam *p;
return empathy_account_settings_get_default (settings, param);
}
-
void
empathy_account_settings_unset (EmpathyAccountSettings *settings,
const gchar *param)
g_hash_table_remove (priv->parameters, param);
}
+void
+empathy_account_settings_discard_changes (EmpathyAccountSettings *settings)
+{
+ EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+
+ g_hash_table_remove_all (priv->parameters);
+ empathy_account_settings_free_unset_parameters (settings);
+}
+
const gchar *
empathy_account_settings_get_string (EmpathyAccountSettings *settings,
const gchar *param)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- tp_asv_set_string (priv->parameters, param, value);
+ tp_asv_set_string (priv->parameters, g_strdup (param), value);
+
+ account_settings_remove_from_unset (settings, param);
}
void
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- tp_asv_set_int32 (priv->parameters, param, value);
+ tp_asv_set_int32 (priv->parameters, g_strdup (param), value);
+
+ account_settings_remove_from_unset (settings, param);
}
void
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- tp_asv_set_int64 (priv->parameters, param, value);
+ tp_asv_set_int64 (priv->parameters, g_strdup (param), value);
+
+ account_settings_remove_from_unset (settings, param);
}
void
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- tp_asv_set_uint32 (priv->parameters, param, value);
+ tp_asv_set_uint32 (priv->parameters, g_strdup (param), value);
+
+ account_settings_remove_from_unset (settings, param);
}
void
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- tp_asv_set_uint64 (priv->parameters, param, value);
+ tp_asv_set_uint64 (priv->parameters, g_strdup (param), value);
+
+ account_settings_remove_from_unset (settings, param);
}
void
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- tp_asv_set_boolean (priv->parameters, param, value);
+ tp_asv_set_boolean (priv->parameters, g_strdup (param), value);
+
+ account_settings_remove_from_unset (settings, param);
}
static void
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);
+ G_OBJECT (settings), empathy_account_settings_set_display_name_finish),
+ FALSE);
+
+ return TRUE;
+}
+
+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);
+
+ 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;
}
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;
else
{
priv->account = g_object_ref (account);
+ empathy_account_settings_discard_changes (settings);
}
r = priv->apply_result;
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
GHashTable *properties;
+ TpConnectionPresenceType type;
+ gchar *status;
+ gchar *message;
+
+ properties = tp_asv_new (NULL, NULL);
+
+ type = empathy_account_manager_get_requested_global_presence
+ (priv->account_manager, &status, &message);
+
+ if (type != TP_CONNECTION_PRESENCE_TYPE_UNSET)
+ {
+ /* Create the account with the requested presence the same as the current
+ * global requested presence, but don't enable it */
+ GValueArray *presence;
+ GValue vtype = { 0, };
+ GValue vstatus = { 0, };
+ GValue vmessage = { 0, };
- properties = g_hash_table_new (NULL, NULL);
+ presence = g_value_array_new (3);
+
+ g_value_init (&vtype, G_TYPE_UINT);
+ g_value_set_uint (&vtype, type);
+ g_value_array_append (presence, &vtype);
+
+ g_value_init (&vstatus, G_TYPE_STRING);
+ g_value_take_string (&vstatus, status);
+ g_value_array_append (presence, &vstatus);
+
+ g_value_init (&vmessage, G_TYPE_STRING);
+ g_value_take_string (&vmessage, message);
+ g_value_array_append (presence, &vmessage);
+
+ tp_asv_take_boxed (properties, TP_IFACE_ACCOUNT ".RequestedPresence",
+ TP_STRUCT_TYPE_SIMPLE_PRESENCE, presence);
+ }
+
+ 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,
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);
}
}