summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-14 13:45:16 (GMT)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-20 16:56:42 (GMT)
commit05f741275590cfff37cddf71232778e0a6c30182 (patch)
tree53a7a162f0335974ad5d7da6e747f7394371726d
parent4e72d3e9acfad7200f513f2e3925090f3477f8c5 (diff)
downloadtelepathy-glib-05f741275590cfff37cddf71232778e0a6c30182.tar.gz
telepathy-glib-05f741275590cfff37cddf71232778e0a6c30182.tar.xz
Add the Supersedes property and test it
Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
-rw-r--r--docs/reference/telepathy-glib-sections.txt1
-rw-r--r--telepathy-glib/account.c101
-rw-r--r--telepathy-glib/account.h6
-rw-r--r--tests/dbus/account.c16
-rw-r--r--tests/lib/simple-account.c23
5 files changed, 141 insertions, 6 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 027ac41..57881d9 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -5089,6 +5089,7 @@ tp_account_get_nickname
tp_account_set_nickname_async
tp_account_set_nickname_finish
tp_account_get_normalized_name
+tp_account_get_supersedes
tp_account_get_avatar_async
tp_account_get_avatar_finish
tp_account_set_avatar_async
diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c
index 8e545ca..fb0b242 100644
--- a/telepathy-glib/account.c
+++ b/telepathy-glib/account.c
@@ -1,7 +1,7 @@
/*
* account.c - proxy for an account in the Telepathy account manager
*
- * Copyright © 2009–2010 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright © 2009–2012 Collabora Ltd. <http://www.collabora.co.uk/>
* Copyright © 2009–2010 Nokia Corporation
*
* This library is free software; you can redistribute it and/or
@@ -121,6 +121,7 @@ struct _TpAccountPrivate {
gchar *service;
gchar *display_name;
+ GStrv supersedes;
GHashTable *parameters;
@@ -174,7 +175,9 @@ enum {
PROP_NORMALIZED_NAME,
PROP_STORAGE_PROVIDER,
PROP_STORAGE_IDENTIFIER,
- PROP_STORAGE_RESTRICTIONS
+ PROP_STORAGE_RESTRICTIONS,
+ PROP_SUPERSEDES,
+ N_PROPS
};
static void tp_account_prepare_connection_async (TpProxy *proxy,
@@ -370,6 +373,7 @@ tp_account_init (TpAccount *self)
self->priv->error = g_strdup (TP_ERROR_STR_DISCONNECTED);
self->priv->error_details = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) tp_g_value_slice_free);
+ self->priv->supersedes = g_new0 (gchar *, 1);
}
static void
@@ -760,6 +764,53 @@ _tp_account_update (TpAccount *account,
g_free (old);
}
+ if (g_hash_table_lookup (properties, "Supersedes") != NULL)
+ {
+ GStrv old = priv->supersedes;
+ GPtrArray *new_arr = tp_asv_get_boxed (properties, "Supersedes",
+ TP_ARRAY_TYPE_OBJECT_PATH_LIST);
+ gboolean changed = FALSE;
+ guint i;
+
+ if (new_arr == NULL)
+ {
+ priv->supersedes = g_new0 (gchar *, 1);
+ }
+ else
+ {
+ priv->supersedes = g_new0 (gchar *, new_arr->len + 1);
+
+ for (i = 0; i < new_arr->len; i++)
+ priv->supersedes[i] = g_strdup (g_ptr_array_index (new_arr, i));
+ }
+
+ if (new_arr == NULL || new_arr->len == 0)
+ {
+ changed = (old != NULL && *old != NULL);
+ }
+ else if (old == NULL || *old == NULL ||
+ g_strv_length (old) != new_arr->len)
+ {
+ changed = TRUE;
+ }
+ else
+ {
+ for (i = 0; i < new_arr->len; i++)
+ {
+ if (tp_strdiff (old[i], priv->supersedes[i]))
+ {
+ changed = TRUE;
+ break;
+ }
+ }
+ }
+
+ if (changed)
+ g_object_notify (G_OBJECT (account), "supersedes");
+
+ g_strfreev (old);
+ }
+
if (g_hash_table_lookup (properties, "NormalizedName") != NULL)
{
gchar *old = priv->normalized_name;
@@ -1065,6 +1116,9 @@ _tp_account_get_property (GObject *object,
case PROP_NICKNAME:
g_value_set_string (value, self->priv->nickname);
break;
+ case PROP_SUPERSEDES:
+ g_value_set_boxed (value, self->priv->supersedes);
+ break;
case PROP_AUTOMATIC_PRESENCE_TYPE:
g_value_set_uint (value, self->priv->auto_presence);
break;
@@ -1128,6 +1182,7 @@ _tp_account_finalize (GObject *object)
g_free (priv->normalized_name);
g_free (priv->nickname);
+ g_strfreev (priv->supersedes);
g_free (priv->cm_name);
g_free (priv->proto_name);
@@ -1861,6 +1916,26 @@ tp_account_class_init (TpAccountClass *klass)
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
/**
+ * TpAccount:supersedes:
+ *
+ * The object paths of previously-active accounts superseded by this one.
+ * For instance, this can be used in a logger to read old logs for an
+ * account that has been migrated from one connection manager to another.
+ *
+ * This is not guaranteed to have been retrieved until the
+ * %TP_ACCOUNT_FEATURE_CORE feature has been prepared; until then,
+ * the value is NULL.
+ *
+ * Since: 0.UNRELEASED
+ */
+ g_object_class_install_property (object_class, PROP_SUPERSEDES,
+ g_param_spec_boxed ("supersedes",
+ "Supersedes",
+ "Accounts superseded by this one",
+ G_TYPE_STRV,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
+ /**
* TpAccount::status-changed:
* @account: the #TpAccount
* @old_status: old #TpAccount:connection-status
@@ -3155,6 +3230,28 @@ tp_account_set_nickname_async (TpAccount *account,
g_value_unset (&value);
}
+/**
+ * tp_account_get_supersedes:
+ * @self: a #TpAccount
+ *
+ * Return the same thing as the #TpAccount:supersedes property, in a way
+ * that may be more convenient for C code.
+ *
+ * The returned pointers are not guaranteed to remain valid after the
+ * main loop has been re-entered.
+ *
+ * Returns: (transfer none): the same as the #TpAccount:supersedes property
+ *
+ * Since: 0.UNRELEASED
+ */
+const gchar * const *
+tp_account_get_supersedes (TpAccount *self)
+{
+ g_return_val_if_fail (TP_IS_ACCOUNT (self), NULL);
+
+ return (const gchar * const *) self->priv->supersedes;
+}
+
static void
_tp_account_got_avatar_cb (TpProxy *proxy,
const GValue *out_Value,
diff --git a/telepathy-glib/account.h b/telepathy-glib/account.h
index 8d3851c..ddcd4c1 100644
--- a/telepathy-glib/account.h
+++ b/telepathy-glib/account.h
@@ -1,7 +1,7 @@
/*
* account-manager.h - proxy for an account in the Telepathy account manager
*
- * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009-2012 Collabora Ltd. <http://www.collabora.co.uk/>
* Copyright (C) 2009 Nokia Corporation
*
* This library is free software; you can redistribute it and/or
@@ -206,6 +206,10 @@ void tp_account_set_nickname_async (TpAccount *account,
gboolean tp_account_set_nickname_finish (TpAccount *account,
GAsyncResult *result, GError **error);
+const gchar * const *
+/* ugh, gtk-doc */
+tp_account_get_supersedes (TpAccount *self);
+
void tp_account_get_avatar_async (TpAccount *account,
GAsyncReadyCallback callback, gpointer user_data);
diff --git a/tests/dbus/account.c b/tests/dbus/account.c
index 794c368..c05417c 100644
--- a/tests/dbus/account.c
+++ b/tests/dbus/account.c
@@ -1,6 +1,6 @@
/* A very basic feature test for TpAccount
*
- * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009-2012 Collabora Ltd. <http://www.collabora.co.uk/>
* Copyright (C) 2009 Nokia Corporation
*
* Copying and distribution of this file, with or without modification,
@@ -24,6 +24,7 @@
#define CONN2_PATH TP_CONN_OBJECT_PATH_BASE "what/ev/s"
#define CONN1_BUS_NAME TP_CONN_BUS_NAME_BASE "what.ev.er"
#define CONN2_BUS_NAME TP_CONN_BUS_NAME_BASE "what.ev.s"
+#define SUPERSEDED_PATH TP_ACCOUNT_OBJECT_PATH_BASE "super/seded/whatever"
static void
test_parse_failure (gconstpointer test_data)
@@ -343,6 +344,8 @@ test_prepare_success (Test *test,
gchar *status = NULL;
gchar *message = NULL;
const GHashTable *details = GUINT_TO_POINTER (666);
+ GStrv strv;
+ const gchar * const *cstrv;
test->account = tp_account_new (test->dbus, ACCOUNT_PATH, NULL);
g_assert (test->account != NULL);
@@ -453,6 +456,17 @@ test_prepare_success (Test *test,
"bob.mcbadgers@example.com");
assert_strprop (test->account, "normalized-name",
"bob.mcbadgers@example.com");
+
+ g_object_get (test->account,
+ "supersedes", &strv,
+ NULL);
+ g_assert_cmpstr (strv[0], ==, SUPERSEDED_PATH);
+ g_assert_cmpstr (strv[1], ==, NULL);
+ g_strfreev (strv);
+
+ cstrv = tp_account_get_supersedes (test->account);
+ g_assert_cmpstr (cstrv[0], ==, SUPERSEDED_PATH);
+ g_assert_cmpstr (cstrv[1], ==, NULL);
}
static void
diff --git a/tests/lib/simple-account.c b/tests/lib/simple-account.c
index ff426b7..73b47e6 100644
--- a/tests/lib/simple-account.c
+++ b/tests/lib/simple-account.c
@@ -1,7 +1,7 @@
/*
* simple-account.c - a simple account service.
*
- * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2010-2012 Collabora Ltd. <http://www.collabora.co.uk/>
*
* Copying and distribution of this file, with or without modification,
* are permitted in any medium without royalty provided the copyright
@@ -68,7 +68,9 @@ enum
PROP_STORAGE_IDENTIFIER,
PROP_STORAGE_SPECIFIC_INFORMATION,
PROP_STORAGE_RESTRICTIONS,
- PROP_AVATAR
+ PROP_AVATAR,
+ PROP_SUPERSEDES,
+ N_PROPS
};
struct _TpTestsSimpleAccountPrivate
@@ -242,6 +244,15 @@ tp_tests_simple_account_get_property (GObject *object,
g_array_unref (arr);
}
break;
+ case PROP_SUPERSEDES:
+ {
+ GPtrArray *arr = g_ptr_array_new ();
+
+ g_ptr_array_add (arr,
+ g_strdup (TP_ACCOUNT_OBJECT_PATH_BASE "super/seded/whatever"));
+ g_value_take_boxed (value, arr);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec);
break;
@@ -289,6 +300,7 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass)
{ "RequestedPresence", "requested-presence", NULL },
{ "NormalizedName", "normalized-name", NULL },
{ "HasBeenOnline", "has-been-online", NULL },
+ { "Supersedes", "supersedes", NULL },
{ NULL }
};
@@ -485,6 +497,13 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass)
g_object_class_install_property (object_class,
PROP_AVATAR, param_spec);
+ param_spec = g_param_spec_boxed ("supersedes",
+ "Supersedes", "List of superseded accounts",
+ TP_ARRAY_TYPE_OBJECT_PATH_LIST,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class,
+ PROP_SUPERSEDES, param_spec);
+
klass->dbus_props_class.interfaces = prop_interfaces;
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (TpTestsSimpleAccountClass, dbus_props_class));