aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-tp-group.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2007-08-31 00:49:52 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-08-31 00:49:52 +0800
commit0b0bb0f621d8e1cda1508d9062a279459fc3b955 (patch)
tree03ad0e8b2180f5e3d6821fbab6315b33c7baf4d8 /libempathy/empathy-tp-group.c
parent3a535643a694d0dd1bed8e0b7a2fd6fd21e6ee0c (diff)
downloadgsoc2013-empathy-0b0bb0f621d8e1cda1508d9062a279459fc3b955.tar
gsoc2013-empathy-0b0bb0f621d8e1cda1508d9062a279459fc3b955.tar.gz
gsoc2013-empathy-0b0bb0f621d8e1cda1508d9062a279459fc3b955.tar.bz2
gsoc2013-empathy-0b0bb0f621d8e1cda1508d9062a279459fc3b955.tar.lz
gsoc2013-empathy-0b0bb0f621d8e1cda1508d9062a279459fc3b955.tar.xz
gsoc2013-empathy-0b0bb0f621d8e1cda1508d9062a279459fc3b955.tar.zst
gsoc2013-empathy-0b0bb0f621d8e1cda1508d9062a279459fc3b955.zip
Completely reworked ContactList API. Fixes bug #471611, bug #467280, bug #459540 and bug #462907.
svn path=/trunk/; revision=280
Diffstat (limited to 'libempathy/empathy-tp-group.c')
-rw-r--r--libempathy/empathy-tp-group.c864
1 files changed, 583 insertions, 281 deletions
diff --git a/libempathy/empathy-tp-group.c b/libempathy/empathy-tp-group.c
index b86a00e28..1ffab9ecd 100644
--- a/libempathy/empathy-tp-group.c
+++ b/libempathy/empathy-tp-group.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2006 Xavier Claessens <xclaesse@gmail.com>
+ * Copyright (C) 2007 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -16,18 +17,22 @@
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
*/
#include <config.h>
#include <dbus/dbus-glib.h>
#include <libtelepathy/tp-chan.h>
+#include <libtelepathy/tp-chan-gen.h>
#include <libtelepathy/tp-chan-iface-group-gen.h>
#include <libtelepathy/tp-constants.h>
#include <libtelepathy/tp-conn.h>
-#include "empathy-debug.h"
#include "empathy-tp-group.h"
+#include "empathy-contact-factory.h"
+#include "empathy-debug.h"
#include "empathy-utils.h"
#include "empathy-marshal.h"
@@ -37,32 +42,27 @@
#define DEBUG_DOMAIN "TpGroup"
struct _EmpathyTpGroupPriv {
- McAccount *account;
- DBusGProxy *group_iface;
- TpChan *tp_chan;
- gchar *group_name;
+ EmpathyContactFactory *factory;
+ McAccount *account;
+ DBusGProxy *group_iface;
+ TpChan *tp_chan;
+ gchar *group_name;
+ guint self_handle;
+
+ GList *members;
+ GList *local_pendings;
+ GList *remote_pendings;
};
static void empathy_tp_group_class_init (EmpathyTpGroupClass *klass);
static void empathy_tp_group_init (EmpathyTpGroup *group);
-static void tp_group_finalize (GObject *object);
-static void tp_group_destroy_cb (DBusGProxy *proxy,
- EmpathyTpGroup *group);
-static void tp_group_members_changed_cb (DBusGProxy *group_iface,
- gchar *message,
- GArray *added,
- GArray *removed,
- GArray *local_pending,
- GArray *remote_pending,
- guint actor,
- guint reason,
- EmpathyTpGroup *group);
enum {
- MEMBERS_ADDED,
- MEMBERS_REMOVED,
+ MEMBER_ADDED,
+ MEMBER_REMOVED,
LOCAL_PENDING,
REMOTE_PENDING,
+ DESTROY,
LAST_SIGNAL
};
@@ -70,6 +70,409 @@ static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE (EmpathyTpGroup, empathy_tp_group, G_TYPE_OBJECT);
+static EmpathyContact *
+tp_group_get_contact (EmpathyTpGroup *group,
+ guint handle)
+{
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ EmpathyContact *contact = NULL;
+
+ if (handle != 0) {
+ contact = empathy_contact_factory_get_from_handle (priv->factory,
+ priv->account,
+ handle);
+ }
+
+ if (contact && empathy_contact_get_handle (contact) == priv->self_handle) {
+ empathy_contact_set_is_user (contact, TRUE);
+ }
+
+ return contact;
+}
+
+static GList *
+tp_group_get_contacts (EmpathyTpGroup *group,
+ GArray *handles)
+{
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ GList *contacts, *l;
+
+ if (!handles) {
+ return NULL;
+ }
+
+ contacts = empathy_contact_factory_get_from_handles (priv->factory,
+ priv->account,
+ handles);
+
+ /* FIXME: Only useful if the group has a different self handle than
+ * the connection, otherwise the contact factory already set that
+ * property. That can be known using group flags. */
+ for (l = contacts; l; l = l->next) {
+ if (empathy_contact_get_handle (l->data) == priv->self_handle) {
+ empathy_contact_set_is_user (l->data, TRUE);
+ }
+ }
+
+ return contacts;
+}
+
+EmpathyPendingInfo *
+empathy_pending_info_new (EmpathyContact *member,
+ EmpathyContact *actor,
+ const gchar *message)
+{
+ EmpathyPendingInfo *info;
+
+ info = g_slice_new0 (EmpathyPendingInfo);
+
+ if (member) {
+ info->member = g_object_ref (member);
+ }
+ if (actor) {
+ info->actor = g_object_ref (actor);
+ }
+ if (message) {
+ info->message = g_strdup (message);
+ }
+
+ return info;
+}
+
+void
+empathy_pending_info_free (EmpathyPendingInfo *info)
+{
+ if (!info) {
+ return;
+ }
+
+ if (info->member) {
+ g_object_unref (info->member);
+ }
+ if (info->actor) {
+ g_object_unref (info->actor);
+ }
+ g_free (info->message);
+
+ g_slice_free (EmpathyPendingInfo, info);
+}
+
+static gint
+tp_group_local_pending_find (gconstpointer a,
+ gconstpointer b)
+{
+ const EmpathyPendingInfo *info = a;
+
+ return (info->member != b);
+}
+
+static void
+tp_group_remove_from_pendings (EmpathyTpGroup *group,
+ EmpathyContact *contact)
+{
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ GList *l;
+
+ /* local pending */
+ l = g_list_find_custom (priv->local_pendings,
+ contact,
+ tp_group_local_pending_find);
+ if (l) {
+ empathy_pending_info_free (l->data);
+ priv->local_pendings = g_list_delete_link (priv->local_pendings, l);
+ }
+
+ /* remote pending */
+ l = g_list_find (priv->remote_pendings, contact);
+ if (l) {
+ g_object_unref (l->data);
+ priv->remote_pendings = g_list_delete_link (priv->remote_pendings, l);
+ }
+}
+
+static void
+tp_group_members_changed_cb (DBusGProxy *group_iface,
+ const gchar *message,
+ GArray *added,
+ GArray *removed,
+ GArray *local_pending,
+ GArray *remote_pending,
+ guint actor,
+ guint reason,
+ EmpathyTpGroup *group)
+{
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ EmpathyContact *actor_contact = NULL;
+ GList *contacts, *l, *ll;
+
+ actor_contact = tp_group_get_contact (group, actor);
+
+ empathy_debug (DEBUG_DOMAIN, "Members changed for list %s:\n"
+ " added-len=%d, current-len=%d\n"
+ " removed-len=%d\n"
+ " local-pending-len=%d, current-len=%d\n"
+ " remote-pending-len=%d, current-len=%d",
+ empathy_tp_group_get_name (group),
+ added ? added->len : 0, g_list_length (priv->members),
+ removed ? removed->len : 0,
+ local_pending ? local_pending->len : 0,
+ g_list_length (priv->local_pendings),
+ remote_pending ? remote_pending->len : 0,
+ g_list_length (priv->remote_pendings));
+
+ /* Contacts added */
+ contacts = tp_group_get_contacts (group, added);
+ for (l = contacts; l; l = l->next) {
+ tp_group_remove_from_pendings (group, l->data);
+
+ /* If the contact is not yet member, add it and emit signal */
+ if (!g_list_find (priv->members, l->data)) {
+ priv->members = g_list_prepend (priv->members,
+ g_object_ref (l->data));
+ g_signal_emit (group, signals[MEMBER_ADDED], 0,
+ l->data, actor_contact, reason, message);
+ }
+ g_object_unref (l->data);
+ }
+ g_list_free (contacts);
+
+ /* Contacts removed */
+ contacts = tp_group_get_contacts (group, removed);
+ for (l = contacts; l; l = l->next) {
+ tp_group_remove_from_pendings (group, l->data);
+
+ /* If the contact is member, remove it and emit signal */
+ if ((ll = g_list_find (priv->members, l->data))) {
+ g_object_unref (ll->data);
+ priv->members = g_list_delete_link (priv->members, ll);
+ g_signal_emit (group, signals[MEMBER_REMOVED], 0,
+ l->data, actor_contact, reason, message);
+ }
+ g_object_unref (l->data);
+ }
+ g_list_free (contacts);
+
+ /* Contacts local pending */
+ contacts = tp_group_get_contacts (group, local_pending);
+ for (l = contacts; l; l = l->next) {
+ /* If the contact is not yet local-pending, add it and emit signal */
+ if (!g_list_find_custom (priv->members, l->data,
+ tp_group_local_pending_find)) {
+ EmpathyPendingInfo *info;
+
+ info = empathy_pending_info_new (l->data,
+ actor_contact,
+ message);
+
+ priv->local_pendings = g_list_prepend (priv->local_pendings, info);
+ g_signal_emit (group, signals[LOCAL_PENDING], 0,
+ l->data, actor_contact, reason, message);
+ }
+ g_object_unref (l->data);
+ }
+ g_list_free (contacts);
+
+ /* Contacts remote pending */
+ contacts = tp_group_get_contacts (group, remote_pending);
+ for (l = contacts; l; l = l->next) {
+ /* If the contact is not yet remote-pending, add it and emit signal */
+ if (!g_list_find (priv->remote_pendings, l->data)) {
+ priv->remote_pendings = g_list_prepend (priv->remote_pendings,
+ g_object_ref (l->data));
+ g_signal_emit (group, signals[REMOTE_PENDING], 0,
+ l->data, actor_contact, reason, message);
+ }
+ g_object_unref (l->data);
+ }
+ g_list_free (contacts);
+
+ if (actor_contact) {
+ g_object_unref (actor_contact);
+ }
+
+ empathy_debug (DEBUG_DOMAIN, "Members changed done for list %s:\n"
+ " members-len=%d\n"
+ " local-pendings-len=%d\n"
+ " remote-pendings-len=%d",
+ empathy_tp_group_get_name (group),
+ g_list_length (priv->members),
+ g_list_length (priv->local_pendings),
+ g_list_length (priv->remote_pendings));
+}
+
+static void
+tp_group_destroy_cb (TpChan *tp_chan,
+ EmpathyTpGroup *group)
+{
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+
+ empathy_debug (DEBUG_DOMAIN, "Account disconnected or CM crashed");
+
+ g_object_unref (priv->tp_chan);
+ priv->group_iface = NULL;
+ priv->tp_chan = NULL;
+
+ g_signal_emit (group, signals[DESTROY], 0);
+}
+
+static void tp_group_closed_cb (DBusGProxy *proxy,
+ EmpathyTpGroup *group);
+
+static void
+tp_group_disconnect (EmpathyTpGroup *group)
+{
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+
+ if (priv->group_iface) {
+ dbus_g_proxy_disconnect_signal (priv->group_iface, "MembersChanged",
+ G_CALLBACK (tp_group_members_changed_cb),
+ group);
+ }
+ if (priv->tp_chan) {
+ g_signal_handlers_disconnect_by_func (priv->tp_chan,
+ tp_group_destroy_cb,
+ group);
+ dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->tp_chan), "Closed",
+ G_CALLBACK (tp_group_closed_cb),
+ group);
+ }
+}
+
+static void
+tp_group_closed_cb (DBusGProxy *proxy,
+ EmpathyTpGroup *group)
+{
+ tp_group_disconnect (group);
+ tp_group_destroy_cb (TELEPATHY_CHAN (proxy), group);
+}
+
+static void
+tp_group_get_members_cb (DBusGProxy *proxy,
+ GArray *handles,
+ GError *error,
+ gpointer user_data)
+{
+ EmpathyTpGroup *group = user_data;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+
+ if (error) {
+ empathy_debug (DEBUG_DOMAIN, "Failed to get members: %s",
+ error->message);
+ return;
+ }
+
+ tp_group_members_changed_cb (priv->group_iface,
+ NULL, /* message */
+ handles, /* added */
+ NULL, /* removed */
+ NULL, /* local_pending */
+ NULL, /* remote_pending */
+ 0, /* actor */
+ 0, /* reason */
+ group);
+}
+
+static void
+tp_group_get_local_pending_cb (DBusGProxy *proxy,
+ GPtrArray *array,
+ GError *error,
+ gpointer user_data)
+{
+ EmpathyTpGroup *group = user_data;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ GArray *handles;
+ guint i;
+
+ if (error) {
+ empathy_debug (DEBUG_DOMAIN, "Failed to get local pendings: %s",
+ error->message);
+ return;
+ }
+
+ handles = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
+ for (i = 0; array->len > i; i++) {
+ GValueArray *pending_struct;
+ const gchar *message;
+ guint member_handle;
+ guint actor_handle;
+ guint reason;
+
+ pending_struct = g_ptr_array_index (array, i);
+ member_handle = g_value_get_uint (g_value_array_get_nth (pending_struct, 0));
+ actor_handle = g_value_get_uint (g_value_array_get_nth (pending_struct, 1));
+ reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2));
+ message = g_value_get_string (g_value_array_get_nth (pending_struct, 3));
+
+ g_array_insert_val (handles, 0, member_handle);
+ tp_group_members_changed_cb (priv->group_iface,
+ message, /* message */
+ NULL, /* added */
+ NULL, /* removed */
+ handles, /* local_pending */
+ NULL, /* remote_pending */
+ actor_handle, /* actor */
+ reason, /* reason */
+ group);
+ }
+ g_array_free (handles, TRUE);
+}
+
+static void
+tp_group_get_remote_pending_cb (DBusGProxy *proxy,
+ GArray *handles,
+ GError *error,
+ gpointer user_data)
+{
+ EmpathyTpGroup *group = user_data;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+
+ if (error) {
+ empathy_debug (DEBUG_DOMAIN, "Failed to get remote pendings: %s",
+ error->message);
+ return;
+ }
+
+ tp_group_members_changed_cb (priv->group_iface,
+ NULL, /* message */
+ NULL, /* added */
+ NULL, /* removed */
+ NULL, /* local_pending */
+ handles, /* remote_pending */
+ 0, /* actor */
+ 0, /* reason */
+ group);
+}
+
+static void
+tp_group_finalize (GObject *object)
+{
+ EmpathyTpGroupPriv *priv = GET_PRIV (object);
+
+ tp_group_disconnect (EMPATHY_TP_GROUP (object));
+
+ if (priv->tp_chan) {
+ g_object_unref (priv->tp_chan);
+ }
+ if (priv->account) {
+ g_object_unref (priv->account);
+ }
+ if (priv->factory) {
+ g_object_unref (priv->factory);
+ }
+ g_free (priv->group_name);
+
+ g_list_foreach (priv->members, (GFunc) g_object_unref, NULL);
+ g_list_free (priv->members);
+
+ g_list_foreach (priv->local_pendings, (GFunc) empathy_pending_info_free, NULL);
+ g_list_free (priv->local_pendings);
+
+ g_list_foreach (priv->remote_pendings, (GFunc) g_object_unref, NULL);
+ g_list_free (priv->remote_pendings);
+
+ G_OBJECT_CLASS (empathy_tp_group_parent_class)->finalize (object);
+}
+
static void
empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
{
@@ -77,25 +480,25 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
object_class->finalize = tp_group_finalize;
- signals[MEMBERS_ADDED] =
- g_signal_new ("members-added",
+ signals[MEMBER_ADDED] =
+ g_signal_new ("member-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- empathy_marshal_VOID__POINTER_UINT_UINT_STRING,
+ empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
G_TYPE_NONE,
- 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING);
+ 4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
- signals[MEMBERS_REMOVED] =
- g_signal_new ("members-removed",
+ signals[MEMBER_REMOVED] =
+ g_signal_new ("member-removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- empathy_marshal_VOID__POINTER_UINT_UINT_STRING,
+ empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
G_TYPE_NONE,
- 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING);
+ 4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
signals[LOCAL_PENDING] =
g_signal_new ("local-pending",
@@ -103,9 +506,9 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- empathy_marshal_VOID__POINTER_UINT_UINT_STRING,
+ empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
G_TYPE_NONE,
- 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING);
+ 4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
signals[REMOTE_PENDING] =
g_signal_new ("remote-pending",
@@ -113,9 +516,19 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- empathy_marshal_VOID__POINTER_UINT_UINT_STRING,
+ empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
G_TYPE_NONE,
- 4, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING);
+ 4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
+
+ signals[DESTROY] =
+ g_signal_new ("destroy",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
g_type_class_add_private (object_class, sizeof (EmpathyTpGroupPriv));
}
@@ -125,36 +538,6 @@ empathy_tp_group_init (EmpathyTpGroup *group)
{
}
-static void
-tp_group_finalize (GObject *object)
-{
- EmpathyTpGroupPriv *priv;
-
- priv = GET_PRIV (object);
-
- if (priv->group_iface) {
- g_signal_handlers_disconnect_by_func (priv->group_iface,
- tp_group_destroy_cb,
- object);
- dbus_g_proxy_disconnect_signal (priv->group_iface, "MembersChanged",
- G_CALLBACK (tp_group_members_changed_cb),
- object);
- g_object_unref (priv->group_iface);
- }
-
- if (priv->account) {
- g_object_unref (priv->account);
- }
-
- if (priv->tp_chan) {
- g_object_unref (priv->tp_chan);
- }
-
- g_free (priv->group_name);
-
- G_OBJECT_CLASS (empathy_tp_group_parent_class)->finalize (object);
-}
-
EmpathyTpGroup *
empathy_tp_group_new (McAccount *account,
TpChan *tp_chan)
@@ -162,6 +545,7 @@ empathy_tp_group_new (McAccount *account,
EmpathyTpGroup *group;
EmpathyTpGroupPriv *priv;
DBusGProxy *group_iface;
+ GError *error;
g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
@@ -175,262 +559,205 @@ empathy_tp_group_new (McAccount *account,
priv->account = g_object_ref (account);
priv->tp_chan = g_object_ref (tp_chan);
- priv->group_iface = g_object_ref (group_iface);
+ priv->group_iface = group_iface;
+ priv->factory = empathy_contact_factory_new ();
+
+ if (!tp_chan_iface_group_get_self_handle (priv->group_iface,
+ &priv->self_handle,
+ &error)) {
+ empathy_debug (DEBUG_DOMAIN,
+ "Failed to get self handle: %s",
+ error ? error->message : "No error given");
+ g_clear_error (&error);
+ }
dbus_g_proxy_connect_signal (priv->group_iface, "MembersChanged",
G_CALLBACK (tp_group_members_changed_cb),
group, NULL);
- g_signal_connect (group_iface, "destroy",
+ dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_chan), "Closed",
+ G_CALLBACK (tp_group_closed_cb),
+ group, NULL);
+ g_signal_connect (priv->tp_chan, "destroy",
G_CALLBACK (tp_group_destroy_cb),
group);
+ tp_chan_iface_group_get_members_async (priv->group_iface,
+ tp_group_get_members_cb,
+ group);
+ tp_chan_iface_group_get_local_pending_members_with_info_async (priv->group_iface,
+ tp_group_get_local_pending_cb,
+ group);
+ tp_chan_iface_group_get_remote_pending_members_async (priv->group_iface,
+ tp_group_get_remote_pending_cb,
+ group);
+
return group;
}
+static void
+tp_group_async_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
+{
+ const gchar *msg = user_data;
+
+ if (error) {
+ empathy_debug (DEBUG_DOMAIN, "%s: %s", msg, error->message);
+ }
+}
+
+void
+empathy_tp_group_close (EmpathyTpGroup *group)
+{
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+
+ tp_chan_close_async (DBUS_G_PROXY (priv->tp_chan),
+ tp_group_async_cb,
+ "Failed to close");
+}
+
+static GArray *
+tp_group_get_handles (GList *contacts)
+{
+ GArray *handles;
+ guint length;
+ GList *l;
+
+ length = g_list_length (contacts);
+ handles = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);
+
+ for (l = contacts; l; l = l->next) {
+ guint handle;
+
+ handle = empathy_contact_get_handle (l->data);
+ g_array_append_val (handles, handle);
+ }
+
+ return handles;
+}
+
void
empathy_tp_group_add_members (EmpathyTpGroup *group,
- GArray *handles,
+ GList *contacts,
const gchar *message)
{
- EmpathyTpGroupPriv *priv;
- GError *error = NULL;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ GArray *handles;
g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
- g_return_if_fail (handles != NULL);
+ g_return_if_fail (contacts != NULL);
- priv = GET_PRIV (group);
+ handles = tp_group_get_handles (contacts);
+ tp_chan_iface_group_add_members_async (priv->group_iface,
+ handles,
+ message,
+ tp_group_async_cb,
+ "Failed to add members");
- if (!tp_chan_iface_group_add_members (priv->group_iface,
- handles,
- message,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Failed to add members: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- }
+ g_array_free (handles, TRUE);
}
void
empathy_tp_group_add_member (EmpathyTpGroup *group,
- guint handle,
+ EmpathyContact *contact,
const gchar *message)
{
- GArray *handles;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ GArray *handles;
+ guint handle;
+ handle = empathy_contact_get_handle (contact);
handles = g_array_new (FALSE, FALSE, sizeof (guint));
g_array_append_val (handles, handle);
- empathy_tp_group_add_members (group, handles, message);
+ tp_chan_iface_group_add_members_async (priv->group_iface,
+ handles,
+ message,
+ tp_group_async_cb,
+ "Failed to add member");
g_array_free (handles, TRUE);
}
void
empathy_tp_group_remove_members (EmpathyTpGroup *group,
- GArray *handles,
+ GList *contacts,
const gchar *message)
{
- EmpathyTpGroupPriv *priv;
- GError *error = NULL;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ GArray *handles;
g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
+ g_return_if_fail (contacts != NULL);
- priv = GET_PRIV (group);
+ handles = tp_group_get_handles (contacts);
+ tp_chan_iface_group_remove_members_async (priv->group_iface,
+ handles,
+ message,
+ tp_group_async_cb,
+ "Failed to remove members");
- if (!tp_chan_iface_group_remove_members (priv->group_iface,
- handles,
- message,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Failed to remove members: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- }
+ g_array_free (handles, TRUE);
}
void
empathy_tp_group_remove_member (EmpathyTpGroup *group,
- guint handle,
+ EmpathyContact *contact,
const gchar *message)
{
- GArray *handles;
-
- g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ GArray *handles;
+ guint handle;
+ handle = empathy_contact_get_handle (contact);
handles = g_array_new (FALSE, FALSE, sizeof (guint));
g_array_append_val (handles, handle);
- empathy_tp_group_remove_members (group, handles, message);
+ tp_chan_iface_group_remove_members_async (priv->group_iface,
+ handles,
+ message,
+ tp_group_async_cb,
+ "Failed to remove member");
g_array_free (handles, TRUE);
}
-GArray *
+GList *
empathy_tp_group_get_members (EmpathyTpGroup *group)
{
- EmpathyTpGroupPriv *priv;
- GArray *members;
- GError *error = NULL;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
- g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
+ g_list_foreach (priv->members, (GFunc) g_object_ref, NULL);
- priv = GET_PRIV (group);
-
- if (!tp_chan_iface_group_get_members (priv->group_iface,
- &members,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Couldn't get members: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- return NULL;
- }
-
- return members;
-}
-
-void
-empathy_tp_group_get_all_members (EmpathyTpGroup *group,
- GArray **members,
- GArray **local_pending,
- GArray **remote_pending)
-{
- EmpathyTpGroupPriv *priv;
- GError *error = NULL;
-
- g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
-
- priv = GET_PRIV (group);
-
- if (!tp_chan_iface_group_get_all_members (priv->group_iface,
- members,
- local_pending,
- remote_pending,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Couldn't get all members: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- }
+ return g_list_copy (priv->members);
}
GList *
-empathy_tp_group_get_local_pending_members_with_info (EmpathyTpGroup *group)
-{
- EmpathyTpGroupPriv *priv;
- GPtrArray *array;
- guint i;
- GList *infos = NULL;
- GError *error = NULL;
-
- g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
-
- priv = GET_PRIV (group);
-
- if (!tp_chan_iface_group_get_local_pending_members_with_info (priv->group_iface,
- &array,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "GetLocalPendingMembersWithInfo failed: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
-
- return NULL;
- }
-
- if (!array) {
- /* This happens with butterfly because
- * GetLocalPendingMembersWithInfo is not
- * implemented */
- return NULL;
- }
-
- for (i = 0; array->len > i; i++) {
- GValueArray *pending_struct;
- EmpathyTpGroupInfo *info;
- const gchar *message;
-
- info = g_slice_new (EmpathyTpGroupInfo);
-
- pending_struct = g_ptr_array_index (array, i);
- info->member = g_value_get_uint (g_value_array_get_nth (pending_struct, 0));
- info->actor = g_value_get_uint (g_value_array_get_nth (pending_struct, 1));
- info->reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2));
- message = g_value_get_string (g_value_array_get_nth (pending_struct, 3));
- info->message = g_strdup (message);
- g_value_array_free (pending_struct);
-
- infos = g_list_prepend (infos, info);
- }
- g_ptr_array_free (array, TRUE);
-
- return infos;
-}
-
-void
-empathy_tp_group_info_list_free (GList *infos)
+empathy_tp_group_get_local_pendings (EmpathyTpGroup *group)
{
- GList *l;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+ GList *pendings = NULL, *l;
- for (l = infos; l; l = l->next) {
- EmpathyTpGroupInfo *info;
+ for (l = priv->local_pendings; l; l = l->next) {
+ EmpathyPendingInfo *info;
+ EmpathyPendingInfo *new_info;
info = l->data;
-
- g_free (info->message);
- g_slice_free (EmpathyTpGroupInfo, info);
+ new_info = empathy_pending_info_new (info->member,
+ info->actor,
+ info->message);
+ pendings = g_list_prepend (pendings, new_info);
}
- g_list_free (infos);
-}
-
-static void
-tp_group_destroy_cb (DBusGProxy *proxy,
- EmpathyTpGroup *group)
-{
- EmpathyTpGroupPriv *priv;
-
- priv = GET_PRIV (group);
-
- g_object_unref (priv->group_iface);
- g_object_unref (priv->tp_chan);
- priv->group_iface = NULL;
- priv->tp_chan = NULL;
+ return pendings;
}
-static void
-tp_group_members_changed_cb (DBusGProxy *group_iface,
- gchar *message,
- GArray *added,
- GArray *removed,
- GArray *local_pending,
- GArray *remote_pending,
- guint actor,
- guint reason,
- EmpathyTpGroup *group)
+GList *
+empathy_tp_group_get_remote_pendings (EmpathyTpGroup *group)
{
- EmpathyTpGroupPriv *priv;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
- priv = GET_PRIV (group);
+ g_list_foreach (priv->remote_pendings, (GFunc) g_object_ref, NULL);
- /* emit signals */
- if (added->len > 0) {
- g_signal_emit (group, signals[MEMBERS_ADDED], 0,
- added, actor, reason, message);
- }
- if (removed->len > 0) {
- g_signal_emit (group, signals[MEMBERS_REMOVED], 0,
- removed, actor, reason, message);
- }
- if (local_pending->len > 0) {
- g_signal_emit (group, signals[LOCAL_PENDING], 0,
- local_pending, actor, reason, message);
- }
- if (remote_pending->len > 0) {
- g_signal_emit (group, signals[REMOTE_PENDING], 0,
- remote_pending, actor, reason, message);
- }
+ return g_list_copy (priv->remote_pendings);
}
const gchar *
@@ -443,35 +770,21 @@ empathy_tp_group_get_name (EmpathyTpGroup *group)
priv = GET_PRIV (group);
/* Lazy initialisation */
- if (priv->group_name) {
- return priv->group_name;
+ if (!priv->group_name) {
+ priv->group_name = empathy_inspect_channel (priv->account, priv->tp_chan);
}
- priv->group_name = empathy_inspect_channel (priv->account, priv->tp_chan);
-
return priv->group_name;
}
-guint
-empathy_tp_group_get_self_handle (EmpathyTpGroup *group)
+EmpathyContact *
+empathy_tp_group_get_self_contact (EmpathyTpGroup *group)
{
- EmpathyTpGroupPriv *priv;
- guint handle;
- GError *error = NULL;
-
- g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), 0 );
-
- priv = GET_PRIV (group);
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
- if (!tp_chan_iface_group_get_self_handle (priv->group_iface, &handle, &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Failed to get self handle: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- return 0;
- }
+ g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
- return handle;
+ return tp_group_get_contact (group, priv->self_handle);
}
const gchar *
@@ -488,21 +801,10 @@ empathy_tp_group_get_object_path (EmpathyTpGroup *group)
gboolean
empathy_tp_group_is_member (EmpathyTpGroup *group,
- guint handle)
+ EmpathyContact *contact)
{
- GArray *members;
- guint i;
- gboolean found = FALSE;
-
- members = empathy_tp_group_get_members (group);
- for (i = 0; i < members->len; i++) {
- if (g_array_index (members, guint, i) == handle) {
- found = TRUE;
- break;
- }
- }
- g_array_free (members, TRUE);
-
- return found;
+ EmpathyTpGroupPriv *priv = GET_PRIV (group);
+
+ return g_list_find (priv->members, contact) != NULL;
}