[folks] Add the PersonaStore:can-alias-personas property.
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Add the PersonaStore:can-alias-personas property.
- Date: Wed, 13 Oct 2010 18:37:59 +0000 (UTC)
commit 6d52e4eddefff01ff97faf548a698b56f5f55311
Author: Travis Reitter <travis reitter collabora co uk>
Date: Mon Oct 11 10:58:24 2010 -0700
Add the PersonaStore:can-alias-personas property.
Helps bgo#626179.
backends/key-file/kf-persona-store.vala | 12 ++++
backends/telepathy/lib/tp-lowlevel.c | 74 +++++++++++++++++++++++
backends/telepathy/lib/tp-lowlevel.h | 13 ++++
backends/telepathy/lib/tpf-persona-store.vala | 36 +++++++++++
folks/persona-store.vala | 11 ++++
tests/telepathy/persona-store-capabilities.vala | 22 +++++++
6 files changed, 168 insertions(+), 0 deletions(-)
---
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index 008e6ba..ee4fc68 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -66,6 +66,18 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
}
/**
+ * Whether this PersonaStore can set the alias of { link Folks.Persona}s.
+ *
+ * See { link Folks.PersonaStore.can_alias_personas}.
+ *
+ * @since 0.3.1
+ */
+ public override MaybeBool can_alias_personas
+ {
+ get { return MaybeBool.TRUE; }
+ }
+
+ /**
* Whether this PersonaStore can remove { link Folks.Persona}s.
*
* See { link Folks.PersonaStore.can_remove_personas}.
diff --git a/backends/telepathy/lib/tp-lowlevel.c b/backends/telepathy/lib/tp-lowlevel.c
index 4ab461d..327fafa 100644
--- a/backends/telepathy/lib/tp-lowlevel.c
+++ b/backends/telepathy/lib/tp-lowlevel.c
@@ -131,6 +131,80 @@ folks_tp_lowlevel_connection_open_contact_list_channel_finish (
}
static void
+connection_get_alias_flags_cb (TpConnection *conn,
+ guint flags,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
+
+ if (error != NULL)
+ {
+ g_simple_async_result_set_from_error (simple, error);
+ }
+ else
+ {
+ g_simple_async_result_set_op_res_gpointer (simple,
+ GUINT_TO_POINTER (flags), NULL);
+ }
+
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+void
+folks_tp_lowlevel_connection_get_alias_flags_async (
+ FolksTpLowlevel *tp_lowlevel,
+ TpConnection *conn,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (conn), callback, user_data,
+ folks_tp_lowlevel_connection_get_alias_flags_finish);
+
+ tp_cli_connection_interface_aliasing_call_get_alias_flags (conn, -1,
+ connection_get_alias_flags_cb, result, NULL, G_OBJECT (conn));
+}
+
+/**
+ * folks_tp_lowlevel_connection_get_alias_flags_finish:
+ * @lowlevel: a #FolksTpLowlevel
+ * @result: a #GAsyncResult
+ * @error: return location for a #GError, or %NULL
+ *
+ * Determine the alias-related capabilities of the #TpConnection.
+ *
+ * Returns: the #TpConnectionAliasFlags
+ */
+TpConnectionAliasFlags
+folks_tp_lowlevel_connection_get_alias_flags_finish (
+ FolksTpLowlevel *lowlevel,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
+ TpConnection *conn;
+
+ g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), FALSE);
+
+ conn = TP_CONNECTION (g_async_result_get_source_object (result));
+ g_return_val_if_fail (TP_IS_CONNECTION (conn), FALSE);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return 0;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result,
+ G_OBJECT (conn), folks_tp_lowlevel_connection_get_alias_flags_finish),
+ 0);
+
+ return (TpConnectionAliasFlags) (g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (result)));
+}
+
+static void
get_contacts_by_handle_cb (TpConnection *conn,
guint n_contacts,
TpContact * const *contacts,
diff --git a/backends/telepathy/lib/tp-lowlevel.h b/backends/telepathy/lib/tp-lowlevel.h
index ecac64e..d0c7222 100644
--- a/backends/telepathy/lib/tp-lowlevel.h
+++ b/backends/telepathy/lib/tp-lowlevel.h
@@ -116,6 +116,19 @@ folks_tp_lowlevel_connection_open_contact_list_channel_finish (
GError **error);
void
+folks_tp_lowlevel_connection_get_alias_flags_async (
+ FolksTpLowlevel *tp_lowlevel,
+ TpConnection *conn,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+TpConnectionAliasFlags
+folks_tp_lowlevel_connection_get_alias_flags_finish (
+ FolksTpLowlevel *lowlevel,
+ GAsyncResult *result,
+ GError **error);
+
+void
folks_tp_lowlevel_connection_get_contacts_by_handle_async (
FolksTpLowlevel *tp_lowlevel,
TpConnection *conn,
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index ef853d4..5b1ae44 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -66,6 +66,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
private Logger logger;
private Contact self_contact;
private MaybeBool _can_add_personas = MaybeBool.UNSET;
+ private MaybeBool _can_alias_personas = MaybeBool.UNSET;
private MaybeBool _can_remove_personas = MaybeBool.UNSET;
private bool _is_prepared = false;
@@ -116,6 +117,18 @@ public class Tpf.PersonaStore : Folks.PersonaStore
}
/**
+ * Whether this PersonaStore can set the alias of { link Folks.Persona}s.
+ *
+ * See { link Folks.PersonaStore.can_alias_personas}.
+ *
+ * @since 0.3.1
+ */
+ public override MaybeBool can_alias_personas
+ {
+ get { return this._can_alias_personas; }
+ }
+
+ /**
* Whether this PersonaStore can remove { link Folks.Persona}s.
*
* See { link Folks.PersonaStore.can_remove_personas}.
@@ -449,6 +462,29 @@ public class Tpf.PersonaStore : Folks.PersonaStore
this.ll.connection_connect_to_new_group_channels (c,
this.new_group_channels_cb);
+ this.ll.connection_get_alias_flags_async.begin (c, (s2, res) =>
+ {
+ var new_can_alias = MaybeBool.FALSE;
+ try
+ {
+ var flags = this.ll.connection_get_alias_flags_async.end (res);
+ if ((flags &
+ ConnectionAliasFlags.CONNECTION_ALIAS_FLAG_USER_SET) > 0)
+ {
+ new_can_alias = MaybeBool.TRUE;
+ }
+ }
+ catch (GLib.Error e)
+ {
+ GLib.warning ("failed to determine whether we can set " +
+ "aliases on Telepathy account %s: %s",
+ this.display_name, e.message);
+ }
+
+ this._can_alias_personas = new_can_alias;
+ this.notify_property ("can-alias-personas");
+ });
+
this.add_standard_channel (c, "publish");
this.add_standard_channel (c, "stored");
this.add_standard_channel (c, "subscribe");
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index ad67c27..15e7db5 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -183,6 +183,17 @@ public abstract class Folks.PersonaStore : Object
public abstract MaybeBool can_add_personas { get; default = MaybeBool.UNSET; }
/**
+ * Whether this { link PersonaStore} can set the alias of { link Persona}s.
+ *
+ * @since 0.3.1
+ */
+ public abstract MaybeBool can_alias_personas
+ {
+ get;
+ default = MaybeBool.UNSET;
+ }
+
+ /**
* Whether this { link PersonaStore} can remove { link Persona}s.
*
* @since 0.3.1
diff --git a/tests/telepathy/persona-store-capabilities.vala b/tests/telepathy/persona-store-capabilities.vala
index cd2a5f8..8a39e26 100644
--- a/tests/telepathy/persona-store-capabilities.vala
+++ b/tests/telepathy/persona-store-capabilities.vala
@@ -193,6 +193,12 @@ public class PersonaStoreCapabilitiesTests : Folks.TestCase
else
store.notify["can-remove-personas"].connect (
this.can_remove_personas_cb);
+
+ if (store.can_alias_personas != MaybeBool.UNSET)
+ can_alias_personas_cb (store, null);
+ else
+ store.notify["can-alias-personas"].connect (
+ this.can_alias_personas_cb);
}
catch (GLib.Error e)
{
@@ -233,6 +239,22 @@ public class PersonaStoreCapabilitiesTests : Folks.TestCase
this.can_remove_personas_cb);
}
}
+
+ private void can_alias_personas_cb (GLib.Object s, ParamSpec? p)
+ {
+ assert (s is Tpf.PersonaStore);
+ var store = (Tpf.PersonaStore) s;
+
+ if (store.can_alias_personas != MaybeBool.UNSET)
+ {
+ assert (store.can_alias_personas == MaybeBool.TRUE);
+
+ this.group_flags_received.add ("can-alias-personas");
+
+ store.notify["can-alias-personas"].disconnect (
+ this.can_alias_personas_cb);
+ }
+ }
}
public int main (string[] args)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]