summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-11-25 11:11:14 +0100
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-11-28 10:30:35 +0100
commit3e541db6511c300477103092eaf9ae7931b55fcd (patch)
treea1b6e46244a5f2673c9a3e3307a0f5f5f223591a
parent195f514b226c1a9532f19010645d80b3147da0d2 (diff)
Add tp_connection_can_set_contact_alias()
https://bugs.freedesktop.org/show_bug.cgi?id=28037
-rw-r--r--glib/docs/reference/telepathy-glib-sections.txt4
-rw-r--r--glib/telepathy-glib/Makefile.am1
-rw-r--r--glib/telepathy-glib/connection-aliasing.c110
-rw-r--r--glib/telepathy-glib/connection-internal.h9
-rw-r--r--glib/telepathy-glib/connection.c7
-rw-r--r--glib/telepathy-glib/connection.h6
-rw-r--r--glib/tests/dbus/Makefile.am6
-rw-r--r--glib/tests/dbus/connection-aliasing.c166
8 files changed, 309 insertions, 0 deletions
diff --git a/glib/docs/reference/telepathy-glib-sections.txt b/glib/docs/reference/telepathy-glib-sections.txt
index 6084e7e4c..e06524f4f 100644
--- a/glib/docs/reference/telepathy-glib-sections.txt
+++ b/glib/docs/reference/telepathy-glib-sections.txt
@@ -3626,6 +3626,7 @@ TP_CONNECTION_FEATURE_CONTACT_LIST
TP_CONNECTION_FEATURE_CONTACT_LIST_PROPERTIES
TP_CONNECTION_FEATURE_CONTACT_GROUPS
TP_CONNECTION_FEATURE_CONTACT_BLOCKING
+TP_CONNECTION_FEATURE_ALIASING
tp_connection_run_until_ready
TpConnectionWhenReadyCb
tp_connection_call_when_ready
@@ -3686,6 +3687,7 @@ tp_connection_get_feature_quark_contact_list
tp_connection_get_feature_quark_contact_list_properties
tp_connection_get_feature_quark_contact_groups
tp_connection_get_feature_quark_contact_blocking
+tp_connection_get_feature_quark_aliasing
<SUBSECTION avatar-requirements>
TP_TYPE_AVATAR_REQUIREMENTS
TpAvatarRequirements
@@ -3745,6 +3747,8 @@ tp_connection_unblock_contacts_async
tp_connection_unblock_contacts_finish
tp_connection_can_report_abusive
tp_connection_get_blocked_contacts
+<SUBSECTION aliasing>
+tp_connection_can_set_contact_alias
<SUBSECTION>
tp_cli_connection_callback_for_connect
tp_cli_connection_call_connect
diff --git a/glib/telepathy-glib/Makefile.am b/glib/telepathy-glib/Makefile.am
index fe038fa9e..58b6c1c8d 100644
--- a/glib/telepathy-glib/Makefile.am
+++ b/glib/telepathy-glib/Makefile.am
@@ -182,6 +182,7 @@ libtelepathy_glib_internal_la_SOURCES = \
client-message.c \
client-message-internal.h \
connection.c \
+ connection-aliasing.c \
connection-avatars.c \
connection-contact-info.c \
connection-contact-list.c \
diff --git a/glib/telepathy-glib/connection-aliasing.c b/glib/telepathy-glib/connection-aliasing.c
new file mode 100644
index 000000000..5a2a5669a
--- /dev/null
+++ b/glib/telepathy-glib/connection-aliasing.c
@@ -0,0 +1,110 @@
+/*
+ * Proxy for a Telepathy connection - aliasing support
+ *
+ * Copyright © 2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "telepathy-glib/connection.h"
+
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/interfaces.h>
+
+#define DEBUG_FLAG TP_DEBUG_CONNECTION
+#include "telepathy-glib/debug-internal.h"
+#include "telepathy-glib/connection-internal.h"
+#include "telepathy-glib/proxy-internal.h"
+
+/**
+ * TP_CONNECTION_FEATURE_ALIASING:
+ *
+ * Expands to a call to a function that returns a #GQuark representing the
+ * "aliasing" feature.
+ *
+ * This feature needs to be prepared in order to use
+ * tp_connection_can_set_contact_alias().
+ *
+ * One can ask for a feature to be prepared using the
+ * tp_proxy_prepare_async() function, and waiting for it to callback.
+ *
+ * Since: 0.UNRELEASED
+ */
+GQuark
+tp_connection_get_feature_quark_aliasing (void)
+{
+ return g_quark_from_static_string ("tp-connection-feature-aliasing");
+}
+
+/**
+ * tp_connection_can_set_contact_alias:
+ * @self: a #TpConnection
+ *
+ * Check if the user can set aliases on his contacts.
+ * TP_CONNECTION_FEATURE_ALIASING needs to be prepared for this function to
+ * return a meaningful value.
+ *
+ * Returns: %TRUE if the aliases of contacts on @self
+ * may be changed by the user of the service, not just by the
+ * contacts themselves; %FALSE otherwise.
+ * Since: 0.UNRELEASED
+ */
+gboolean
+tp_connection_can_set_contact_alias (TpConnection *self)
+{
+ g_return_val_if_fail (TP_IS_CONNECTION (self), FALSE);
+
+ return (self->priv->alias_flags & TP_CONNECTION_ALIAS_FLAG_USER_SET) != 0;
+}
+
+static void
+get_alias_flag_cb (TpConnection *self,
+ TpConnectionAliasFlags flags,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ GSimpleAsyncResult *result = user_data;
+
+ if (error != NULL)
+ {
+ DEBUG ("Failed to get AliasFlag : %s", error->message);
+ g_simple_async_result_set_from_error (result, error);
+ goto finally;
+ }
+
+ self->priv->alias_flags = flags;
+
+finally:
+ g_simple_async_result_complete (result);
+}
+
+void
+_tp_connection_prepare_aliasing_async (TpProxy *proxy,
+ const TpProxyFeature *feature,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ TpConnection *self = (TpConnection *) proxy;
+ GSimpleAsyncResult *result;
+
+ g_assert (self->priv->alias_flags == 0);
+
+ result = g_simple_async_result_new ((GObject *) proxy, callback, user_data,
+ _tp_connection_prepare_aliasing_async);
+
+ tp_cli_connection_interface_aliasing_call_get_alias_flags (self, -1,
+ get_alias_flag_cb, result, g_object_unref, G_OBJECT (self));
+}
diff --git a/glib/telepathy-glib/connection-internal.h b/glib/telepathy-glib/connection-internal.h
index 5b48c8f77..65a7376ae 100644
--- a/glib/telepathy-glib/connection-internal.h
+++ b/glib/telepathy-glib/connection-internal.h
@@ -100,6 +100,9 @@ struct _TpConnectionPrivate {
GPtrArray *blocked_contacts;
gboolean blocked_contacts_fetched;
+ /* Aliasing */
+ TpConnectionAliasFlags alias_flags;
+
TpProxyPendingCall *introspection_call;
unsigned ready:1;
@@ -185,6 +188,12 @@ void _tp_connection_prepare_contact_blocking_async (TpProxy *proxy,
void _tp_connection_set_contact_blocked (TpConnection *self,
TpContact *contact);
+/* connection-aliasing.c */
+void _tp_connection_prepare_aliasing_async (TpProxy *proxy,
+ const TpProxyFeature *feature,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
G_END_DECLS
#endif
diff --git a/glib/telepathy-glib/connection.c b/glib/telepathy-glib/connection.c
index 59fd7f1b0..adf8033a1 100644
--- a/glib/telepathy-glib/connection.c
+++ b/glib/telepathy-glib/connection.c
@@ -1611,6 +1611,7 @@ enum {
FEAT_CONTACT_LIST_PROPS,
FEAT_CONTACT_GROUPS,
FEAT_CONTACT_BLOCKING,
+ FEAT_ALIASING,
N_FEAT
};
@@ -1626,6 +1627,7 @@ tp_connection_list_features (TpProxyClass *cls G_GNUC_UNUSED)
static GQuark need_contact_groups[2] = {0, 0};
static GQuark need_contact_blocking[2] = {0, 0};
static GQuark depends_contact_list[2] = {0, 0};
+ static GQuark need_aliasing[2] = {0, 0};
if (G_LIKELY (features[0].name != 0))
return features;
@@ -1680,6 +1682,11 @@ tp_connection_list_features (TpProxyClass *cls G_GNUC_UNUSED)
need_contact_blocking[0] = TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING;
features[FEAT_CONTACT_BLOCKING].interfaces_needed = need_contact_blocking;
+ features[FEAT_ALIASING].name = TP_CONNECTION_FEATURE_ALIASING;
+ features[FEAT_ALIASING].prepare_async = _tp_connection_prepare_aliasing_async;
+ need_aliasing[0] = TP_IFACE_QUARK_CONNECTION_INTERFACE_ALIASING;
+ features[FEAT_ALIASING].interfaces_needed = need_aliasing;
+
/* assert that the terminator at the end is there */
g_assert (features[N_FEAT].name == 0);
diff --git a/glib/telepathy-glib/connection.h b/glib/telepathy-glib/connection.h
index c685ecc55..ada32294f 100644
--- a/glib/telepathy-glib/connection.h
+++ b/glib/telepathy-glib/connection.h
@@ -278,6 +278,12 @@ GQuark tp_connection_get_feature_quark_avatar_requirements (void) G_GNUC_CONST;
TpAvatarRequirements * tp_connection_get_avatar_requirements (
TpConnection *self);
+#define TP_CONNECTION_FEATURE_ALIASING \
+ (tp_connection_get_feature_quark_aliasing ())
+GQuark tp_connection_get_feature_quark_aliasing (void) G_GNUC_CONST;
+
+gboolean tp_connection_can_set_contact_alias (TpConnection *self);
+
#define TP_CONNECTION_FEATURE_BALANCE \
(tp_connection_get_feature_quark_balance ())
GQuark tp_connection_get_feature_quark_balance (void) G_GNUC_CONST;
diff --git a/glib/tests/dbus/Makefile.am b/glib/tests/dbus/Makefile.am
index 048f841ce..4d8826cc7 100644
--- a/glib/tests/dbus/Makefile.am
+++ b/glib/tests/dbus/Makefile.am
@@ -18,6 +18,7 @@ tests_list = \
test-cm \
test-cm-message \
test-connection \
+ test-connection-aliasing \
test-connection-balance \
test-connection-bug-18845 \
test-connection-error \
@@ -141,6 +142,11 @@ test_contact_list_client_LDADD = \
$(LDADD) \
$(top_builddir)/examples/cm/contactlist/libexample-cm-contactlist.la
+test_connection_aliasing_SOURCES = connection-aliasing.c
+test_connection_aliasing_LDADD = \
+ $(LDADD) \
+ $(top_builddir)/examples/cm/contactlist/libexample-cm-contactlist.la
+
test_connection_balance_SOURCES = connection-balance.c
test_connection_bug_18845_SOURCES = connection-bug-18845.c
diff --git a/glib/tests/dbus/connection-aliasing.c b/glib/tests/dbus/connection-aliasing.c
new file mode 100644
index 000000000..55f1b1f14
--- /dev/null
+++ b/glib/tests/dbus/connection-aliasing.c
@@ -0,0 +1,166 @@
+/* Feature test for Conn.I.Aliasing
+ *
+ * Copyright © 2007-2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright © 2007-2008 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#include <telepathy-glib/connection.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/debug.h>
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/proxy-subclass.h>
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "examples/cm/contactlist/conn.h"
+#include "tests/lib/util.h"
+
+typedef struct {
+ GMainLoop *mainloop;
+ TpDBusDaemon *dbus;
+ DBusConnection *client_libdbus;
+ DBusGConnection *client_dbusglib;
+ TpDBusDaemon *client_bus;
+ ExampleContactListConnection *service_conn;
+ TpBaseConnection *service_conn_as_base;
+ gchar *conn_name;
+ gchar *conn_path;
+ TpConnection *conn;
+
+ gboolean cwr_ready;
+ GError *cwr_error /* initialized in setup */;
+
+ GError *error /* initialized where needed */;
+ gint wait;
+} Test;
+
+static void
+setup (Test *test,
+ gconstpointer data)
+{
+ GError *error = NULL;
+ GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
+
+ g_type_init ();
+ tp_debug_set_flags ("all");
+ test->dbus = tp_tests_dbus_daemon_dup_or_die ();
+
+ test->mainloop = g_main_loop_new (NULL, FALSE);
+ test->error = NULL;
+
+ test->client_libdbus = dbus_bus_get_private (DBUS_BUS_STARTER, NULL);
+ g_assert (test->client_libdbus != NULL);
+ dbus_connection_setup_with_g_main (test->client_libdbus, NULL);
+ dbus_connection_set_exit_on_disconnect (test->client_libdbus, FALSE);
+ test->client_dbusglib = dbus_connection_get_g_connection (
+ test->client_libdbus);
+ dbus_g_connection_ref (test->client_dbusglib);
+ test->client_bus = tp_dbus_daemon_new (test->client_dbusglib);
+ g_assert (test->client_bus != NULL);
+
+ test->service_conn = tp_tests_object_new_static_class (
+ EXAMPLE_TYPE_CONTACT_LIST_CONNECTION,
+ "account", "me@example.com",
+ "protocol", "simple-protocol",
+ NULL);
+ test->service_conn_as_base = TP_BASE_CONNECTION (test->service_conn);
+ g_assert (test->service_conn != NULL);
+ g_assert (test->service_conn_as_base != NULL);
+
+ g_assert (tp_base_connection_register (test->service_conn_as_base, "simple",
+ &test->conn_name, &test->conn_path, &error));
+ g_assert_no_error (error);
+
+ test->cwr_ready = FALSE;
+ test->cwr_error = NULL;
+
+ test->conn = tp_connection_new (test->client_bus, test->conn_name,
+ test->conn_path, &error);
+ g_assert (test->conn != NULL);
+ g_assert_no_error (error);
+
+ tp_cli_connection_call_connect (test->conn, -1, NULL, NULL, NULL, NULL);
+
+ g_assert (!tp_proxy_is_prepared (test->conn, TP_CONNECTION_FEATURE_CORE));
+ g_assert (!tp_proxy_is_prepared (test->conn,
+ TP_CONNECTION_FEATURE_CONNECTED));
+ g_assert (!tp_proxy_is_prepared (test->conn, TP_CONNECTION_FEATURE_BALANCE));
+
+ tp_tests_proxy_run_until_prepared (test->conn, features);
+}
+
+static void
+teardown (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ TpConnection *conn;
+ gboolean ok;
+ GError *error = NULL;
+
+ g_clear_error (&test->error);
+ tp_clear_pointer (&test->mainloop, g_main_loop_unref);
+ tp_clear_object (&test->conn);
+
+ /* disconnect the connection so we don't leak it */
+ conn = tp_connection_new (test->dbus, test->conn_name, test->conn_path,
+ &error);
+ g_assert (conn != NULL);
+ g_assert_no_error (error);
+
+ ok = tp_cli_connection_run_disconnect (conn, -1, &error, NULL);
+ g_assert (ok);
+ g_assert_no_error (error);
+
+ g_assert (!tp_connection_run_until_ready (conn, FALSE, &error, NULL));
+ g_assert_error (error, TP_ERRORS, TP_ERROR_CANCELLED);
+ g_clear_error (&error);
+
+ test->service_conn_as_base = NULL;
+ g_object_unref (test->service_conn);
+ g_free (test->conn_name);
+ g_free (test->conn_path);
+
+ g_object_unref (test->dbus);
+ test->dbus = NULL;
+ g_object_unref (test->client_bus);
+ test->client_bus = NULL;
+
+ dbus_g_connection_unref (test->client_dbusglib);
+ dbus_connection_close (test->client_libdbus);
+ dbus_connection_unref (test->client_libdbus);
+}
+
+static void
+test_user_set (Test *test,
+ gconstpointer nil G_GNUC_UNUSED)
+{
+ GQuark features[] = { TP_CONNECTION_FEATURE_ALIASING, 0 };
+
+ g_assert (!tp_proxy_is_prepared (test->conn, TP_CONNECTION_FEATURE_ALIASING));
+ g_assert (!tp_connection_can_set_contact_alias (test->conn));
+
+ tp_tests_proxy_run_until_prepared (test->conn, features);
+
+ g_assert (tp_proxy_is_prepared (test->conn, TP_CONNECTION_FEATURE_ALIASING));
+ g_assert (tp_connection_can_set_contact_alias (test->conn));
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ g_type_init ();
+
+ tp_tests_abort_after (5);
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/conn/aliasing/user-set", Test, NULL,
+ setup, test_user_set, teardown);
+
+ return g_test_run ();
+}