telepathy-mission-control: Implement Set("Nickname", "") by using the normalized name instead
Simon McVittie
smcv at kemper.freedesktop.org
Tue Oct 9 09:11:35 PDT 2012
Module: telepathy-mission-control
Branch: master
Commit: 90dd8c46e8457629140397d6e6afacfe9f2eea6b
URL: http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=90dd8c46e8457629140397d6e6afacfe9f2eea6b
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Tue Oct 9 11:25:55 2012 +0100
Implement Set("Nickname", "") by using the normalized name instead
This is consistent with what we do when we first connect, and ensures
that we always have some sort of nickname.
---
src/mcd-account.c | 23 +++++++++++++++++++++++
tests/twisted/account-manager/nickname.py | 28 +++++++++++++++++++++++-----
2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/src/mcd-account.c b/src/mcd-account.c
index 4cc34f2..6041ba6 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -1324,8 +1324,28 @@ set_nickname (TpSvcDBusProperties *self, const gchar *name,
McdAccount *account = MCD_ACCOUNT (self);
McdAccountPrivate *priv = account->priv;
SetResult ret;
+ GValue replacement = G_VALUE_INIT;
DEBUG ("called for %s", priv->unique_name);
+
+ /* If we're asked to set Nickname = "", set it to our identifier
+ * (NormalizedName) instead, so that we always have some sort of nickname.
+ * This matches what we do when connecting an account.
+ *
+ * Exception: if we're not fully connected yet (and hence have no
+ * self-contact), rely on the corresponding special-case
+ * when we do become connected.
+ */
+ if (G_VALUE_HOLDS_STRING (value) &&
+ tp_str_empty (g_value_get_string (value)) &&
+ priv->self_contact != NULL)
+ {
+ g_value_init (&replacement, G_TYPE_STRING);
+ g_value_set_string (&replacement,
+ tp_contact_get_identifier (priv->self_contact));
+ value = &replacement;
+ }
+
ret = mcd_account_set_string_val (account, name, value, error);
if (ret != SET_RESULT_ERROR)
@@ -1334,6 +1354,9 @@ set_nickname (TpSvcDBusProperties *self, const gchar *name,
g_value_get_string (value));
}
+ if (value == &replacement)
+ g_value_unset (&replacement);
+
return (ret != SET_RESULT_ERROR);
}
diff --git a/tests/twisted/account-manager/nickname.py b/tests/twisted/account-manager/nickname.py
index 5a1c465..f23f072 100644
--- a/tests/twisted/account-manager/nickname.py
+++ b/tests/twisted/account-manager/nickname.py
@@ -139,8 +139,26 @@ def test(q, bus, mc, nickname):
assertEquals(nickname, account_props.Get(cs.ACCOUNT, 'Nickname'))
q.dbus_return(e.message, signature='')
- # If we set an empty nickname while connected, MC currently does use it
- # (??? this is pretty weird)
+ # Set the nickname back to something else
+ nickname = 'wjt'
+ call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname', nickname)
+ _, _, e = q.expect_many(
+ EventPattern('dbus-signal',
+ path=account.object_path,
+ signal='AccountPropertyChanged',
+ interface=cs.ACCOUNT,
+ args=[{'Nickname': nickname}]),
+ EventPattern('dbus-return', method='Set'),
+ EventPattern('dbus-method-call',
+ interface=cs.CONN_IFACE_ALIASING, method='SetAliases',
+ args=[{ conn.self_handle: nickname }],
+ handled=False)
+ )
+ assertEquals(nickname, account_props.Get(cs.ACCOUNT, 'Nickname'))
+ q.dbus_return(e.message, signature='')
+
+ # If we set an empty nickname while connected, MC uses our normalized
+ # name (identifier) instead.
call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname',
'')
_, _, e = q.expect_many(
@@ -148,14 +166,14 @@ def test(q, bus, mc, nickname):
path=account.object_path,
signal='AccountPropertyChanged',
interface=cs.ACCOUNT,
- args=[{'Nickname': ''}]),
+ args=[{'Nickname': params['account']}]),
EventPattern('dbus-return', method='Set'),
EventPattern('dbus-method-call',
interface=cs.CONN_IFACE_ALIASING, method='SetAliases',
- args=[{ conn.self_handle: '' }],
+ args=[{ conn.self_handle: params['account'] }],
handled=False)
)
- assertEquals('', account_props.Get(cs.ACCOUNT, 'Nickname'))
+ assertEquals(params['account'], account_props.Get(cs.ACCOUNT, 'Nickname'))
q.dbus_return(e.message, signature='')
def test_both(q, bus, mc):
More information about the telepathy-commits
mailing list