#include <config.h>
#include <string.h>
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
-#include <libtelepathy/tp-conn.h>
-#include <libtelepathy/tp-chan.h>
-#include <libtelepathy/tp-chan-type-contact-list-gen.h>
+#include <telepathy-glib/channel.h>
+#include <telepathy-glib/connection.h>
#include <telepathy-glib/util.h>
#include <telepathy-glib/dbus.h>
#include "empathy-tp-contact-list.h"
#include "empathy-contact-list.h"
#include "empathy-tp-group.h"
-#include "empathy-debug.h"
#include "empathy-utils.h"
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- EMPATHY_TYPE_TP_CONTACT_LIST, EmpathyTpContactListPriv))
-
-#define DEBUG_DOMAIN "TpContactList"
+#define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CONTACT
+#include "empathy-debug.h"
-struct _EmpathyTpContactListPriv {
- TpConn *tp_conn;
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpContactList)
+typedef struct {
McAccount *account;
- MissionControl *mc;
+ TpConnection *connection;
const gchar *protocol_group;
+ gboolean ready;
EmpathyTpGroup *publish;
EmpathyTpGroup *subscribe;
GList *groups;
GHashTable *contacts_groups;
-};
+} EmpathyTpContactListPriv;
typedef enum {
TP_CONTACT_LIST_TYPE_PUBLISH,
TP_CONTACT_LIST_TYPE_UNKNOWN
} TpContactListType;
-static void empathy_tp_contact_list_class_init (EmpathyTpContactListClass *klass);
-static void empathy_tp_contact_list_init (EmpathyTpContactList *list);
static void tp_contact_list_iface_init (EmpathyContactListIface *iface);
enum {
LAST_SIGNAL
};
+enum {
+ PROP_0,
+ PROP_ACCOUNT,
+};
+
static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE_WITH_CODE (EmpathyTpContactList, empathy_tp_contact_list, G_TYPE_OBJECT,
{
EmpathyTpContactListPriv *priv = GET_PRIV (list);
- empathy_debug (DEBUG_DOMAIN, "Group destroyed: %s",
- empathy_tp_group_get_name (group));
+ DEBUG ("Group destroyed: %s", empathy_tp_group_get_name (group));
priv->groups = g_list_remove (priv->groups, group);
g_object_unref (group);
group_name = empathy_tp_group_get_name (group);
if (!g_list_find_custom (*groups, group_name, (GCompareFunc) strcmp)) {
- empathy_debug (DEBUG_DOMAIN, "Contact %s (%d) added to group %s",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact),
- group_name);
+ DEBUG ("Contact %s (%d) added to group %s",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_handle (contact),
+ group_name);
*groups = g_list_prepend (*groups, g_strdup (group_name));
g_signal_emit_by_name (list, "groups-changed", contact,
group_name,
group_name = empathy_tp_group_get_name (group);
if ((l = g_list_find_custom (*groups, group_name, (GCompareFunc) strcmp))) {
- empathy_debug (DEBUG_DOMAIN, "Contact %s (%d) removed from group %s",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact),
- group_name);
+ DEBUG ("Contact %s (%d) removed from group %s",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_handle (contact),
+ group_name);
*groups = g_list_delete_link (*groups, l);
g_signal_emit_by_name (list, "groups-changed", contact,
group_name,
TpContactListType list_type;
list_type = tp_contact_list_get_type (list, group);
- empathy_debug (DEBUG_DOMAIN, "Contact %s (%d) added to list type %d",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact),
- list_type);
+ DEBUG ("Contact %s (%d) added to list type %d",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_handle (contact),
+ list_type);
/* We now get the presence of that contact, add it to members */
if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE &&
TpContactListType list_type;
list_type = tp_contact_list_get_type (list, group);
- empathy_debug (DEBUG_DOMAIN, "Contact %s (%d) removed from list type %d",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact),
- list_type);
+ DEBUG ("Contact %s (%d) removed from list type %d",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_handle (contact),
+ list_type);
/* This contact refuses to send us his presence, remove from members. */
if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE &&
TpContactListType list_type;
list_type = tp_contact_list_get_type (list, group);
- empathy_debug (DEBUG_DOMAIN, "Contact %s (%d) pending in list type %d",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact),
- list_type);
+ DEBUG ("Contact %s (%d) pending in list type %d",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_handle (contact),
+ list_type);
/* We want this contact in our contact list but we don't get its
* presence yet. Add to members anyway. */
}
static void
-tp_contact_list_group_ready_cb (EmpathyTpGroup *group,
- gpointer unused,
+tp_contact_list_invalidated_cb (TpConnection *connection,
+ guint domain,
+ gint code,
+ gchar *message,
EmpathyTpContactList *list)
{
EmpathyTpContactListPriv *priv = GET_PRIV (list);
- guint handle_type;
- TpChan *tp_chan;
+ GList *l;
- tp_chan = empathy_tp_group_get_channel (group);
- handle_type = tp_chan->handle_type;
+ DEBUG ("Connection invalidated");
- if (handle_type == TP_HANDLE_TYPE_LIST) {
- TpContactListType list_type;
- GList *contacts, *l;
+ /* Remove all contacts */
+ for (l = priv->members; l; l = l->next) {
+ g_signal_emit_by_name (list, "members-changed", l->data,
+ NULL, 0, NULL,
+ FALSE);
+ g_object_unref (l->data);
+ }
+ for (l = priv->pendings; l; l = l->next) {
+ g_signal_emit_by_name (list, "pendings-changed", l->data,
+ NULL, 0, NULL,
+ FALSE);
+ g_object_unref (l->data);
+ }
+ g_list_free (priv->members);
+ g_list_free (priv->pendings);
+ priv->members = NULL;
+ priv->pendings = NULL;
- list_type = tp_contact_list_get_type (list, group);
- if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH && !priv->publish) {
- priv->publish = g_object_ref (group);
+ /* Tell the world to not use us anymore */
+ g_signal_emit (list, signals[DESTROY], 0);
+}
- /* Publish is the list of contacts to who we send our
- * presence. Makes no sense to be in remote-pending */
- g_signal_connect (group, "local-pending",
- G_CALLBACK (tp_contact_list_pending_cb),
- list);
+static void
+tp_contact_list_group_list_free (GList **groups)
+{
+ g_list_foreach (*groups, (GFunc) g_free, NULL);
+ g_list_free (*groups);
+ g_slice_free (GList*, groups);
+}
- contacts = empathy_tp_group_get_local_pendings (group);
- for (l = contacts; l; l = l->next) {
- EmpathyPendingInfo *info = l->data;
+static void
+tp_contact_list_add_channel (EmpathyTpContactList *list,
+ const gchar *object_path,
+ const gchar *channel_type,
+ TpHandleType handle_type,
+ guint handle)
+{
+ EmpathyTpContactListPriv *priv = GET_PRIV (list);
+ TpChannel *channel;
+ EmpathyTpGroup *group;
+ const gchar *group_name;
+ GList *contacts, *l;
- tp_contact_list_pending_cb (group,
- info->member,
- info->actor,
- 0,
- info->message,
- list);
- empathy_pending_info_free (info);
- }
- g_list_free (contacts);
- }
- else if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE && !priv->subscribe) {
- priv->subscribe = g_object_ref (group);
-
- /* Subscribe is the list of contacts from who we
- * receive presence. Makes no sense to be in
- * local-pending */
- g_signal_connect (group, "remote-pending",
- G_CALLBACK (tp_contact_list_pending_cb),
- list);
+ if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST) != 0 ||
+ handle_type != TP_HANDLE_TYPE_GROUP) {
+ return;
+ }
- contacts = empathy_tp_group_get_remote_pendings (group);
- for (l = contacts; l; l = l->next) {
- tp_contact_list_pending_cb (group,
- l->data,
- NULL, 0,
- NULL, list);
- g_object_unref (l->data);
- }
- g_list_free (contacts);
- } else {
- empathy_debug (DEBUG_DOMAIN,
- "Type of contact list channel unknown "
- "or aleady have that list: %s",
- empathy_tp_group_get_name (group));
- goto OUT;
- }
- empathy_debug (DEBUG_DOMAIN,
- "New contact list channel of type: %d",
- list_type);
+ channel = tp_channel_new (priv->connection,
+ object_path, channel_type,
+ handle_type, handle, NULL);
- g_signal_connect (group, "member-added",
- G_CALLBACK (tp_contact_list_added_cb),
- list);
- g_signal_connect (group, "member-removed",
- G_CALLBACK (tp_contact_list_removed_cb),
- list);
+ group = empathy_tp_group_new (channel);
+ empathy_run_until_ready (group);
+ g_object_unref (channel);
- contacts = empathy_tp_group_get_members (group);
- for (l = contacts; l; l = l->next) {
- tp_contact_list_added_cb (group,
- l->data,
- NULL, 0, NULL,
- list);
- g_object_unref (l->data);
- }
- g_list_free (contacts);
+ /* Check if already exists */
+ group_name = empathy_tp_group_get_name (group);
+ if (tp_contact_list_find_group (list, group_name)) {
+ g_object_unref (group);
+ return;
}
- else if (handle_type == TP_HANDLE_TYPE_GROUP) {
- const gchar *group_name;
- GList *contacts, *l;
-
- /* Check if already exists */
- group_name = empathy_tp_group_get_name (group);
- if (tp_contact_list_find_group (list, group_name)) {
- goto OUT;
- }
- empathy_debug (DEBUG_DOMAIN, "New server-side group channel: %s",
- group_name);
+ /* Add the group */
+ DEBUG ("New server-side group: %s", group_name);
+ priv->groups = g_list_prepend (priv->groups, group);
+ g_signal_connect (group, "member-added",
+ G_CALLBACK (tp_contact_list_group_member_added_cb),
+ list);
+ g_signal_connect (group, "member-removed",
+ G_CALLBACK (tp_contact_list_group_member_removed_cb),
+ list);
+ g_signal_connect (group, "destroy",
+ G_CALLBACK (tp_contact_list_group_destroy_cb),
+ list);
- priv->groups = g_list_prepend (priv->groups, g_object_ref (group));
+ /* Get initial members */
+ contacts = empathy_tp_group_get_members (group);
+ for (l = contacts; l; l = l->next) {
+ tp_contact_list_group_member_added_cb (group, l->data,
+ NULL, 0, NULL,
+ list);
+ g_object_unref (l->data);
+ }
+ g_list_free (contacts);
+}
- g_signal_connect (group, "member-added",
- G_CALLBACK (tp_contact_list_group_member_added_cb),
- list);
- g_signal_connect (group, "member-removed",
- G_CALLBACK (tp_contact_list_group_member_removed_cb),
- list);
- g_signal_connect (group, "destroy",
- G_CALLBACK (tp_contact_list_group_destroy_cb),
- list);
+static void
+tp_contact_list_new_channel_cb (TpConnection *proxy,
+ const gchar *object_path,
+ const gchar *channel_type,
+ guint handle_type,
+ guint handle,
+ gboolean suppress_handler,
+ gpointer user_data,
+ GObject *list)
+{
+ EmpathyTpContactListPriv *priv = GET_PRIV (list);
- contacts = empathy_tp_group_get_members (group);
- for (l = contacts; l; l = l->next) {
- tp_contact_list_group_member_added_cb (group, l->data,
- NULL, 0, NULL,
- list);
- g_object_unref (l->data);
- }
- g_list_free (contacts);
- } else {
- empathy_debug (DEBUG_DOMAIN,
- "Unknown handle type (%d) for contact list channel",
- handle_type);
+ if (!suppress_handler && priv->ready) {
+ tp_contact_list_add_channel (EMPATHY_TP_CONTACT_LIST (list),
+ object_path, channel_type,
+ handle_type, handle);
}
-
-OUT:
- g_object_unref (group);
- g_object_unref (list);
}
static void
-tp_contact_list_newchannel_cb (DBusGProxy *proxy,
- const gchar *object_path,
- const gchar *channel_type,
- TpHandleType handle_type,
- guint channel_handle,
- gboolean suppress_handler,
- EmpathyTpContactList *list)
+tp_contact_list_list_channels_cb (TpConnection *connection,
+ const GPtrArray *channels,
+ const GError *error,
+ gpointer user_data,
+ GObject *list)
{
EmpathyTpContactListPriv *priv = GET_PRIV (list);
- EmpathyTpGroup *group;
- TpChan *new_chan;
- const gchar *bus_name;
+ guint i;
- if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST) != 0 ||
- suppress_handler ||
- (handle_type != TP_HANDLE_TYPE_LIST &&
- handle_type != TP_HANDLE_TYPE_GROUP)) {
+ if (error) {
+ DEBUG ("Error: %s", error->message);
return;
}
- bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn));
- new_chan = tp_chan_new (tp_get_bus (),
- bus_name,
- object_path,
- channel_type,
- handle_type,
- channel_handle);
- g_return_if_fail (TELEPATHY_IS_CHAN (new_chan));
-
- group = empathy_tp_group_new (priv->account, new_chan);
- g_object_unref (new_chan);
-
- /* We give a ref of group and list to the callback */
- if (empathy_tp_group_is_ready (group)) {
- tp_contact_list_group_ready_cb (group, NULL, g_object_ref (list));
- } else {
- g_signal_connect (group, "notify::ready",
- G_CALLBACK (tp_contact_list_group_ready_cb),
- g_object_ref (list));
+ for (i = 0; i < channels->len; i++) {
+ GValueArray *chan_struct;
+ const gchar *object_path;
+ const gchar *channel_type;
+ TpHandleType handle_type;
+ guint handle;
+
+ chan_struct = g_ptr_array_index (channels, i);
+ object_path = g_value_get_boxed (g_value_array_get_nth (chan_struct, 0));
+ channel_type = g_value_get_string (g_value_array_get_nth (chan_struct, 1));
+ handle_type = g_value_get_uint (g_value_array_get_nth (chan_struct, 2));
+ handle = g_value_get_uint (g_value_array_get_nth (chan_struct, 3));
+
+ tp_contact_list_add_channel (EMPATHY_TP_CONTACT_LIST (list),
+ object_path, channel_type,
+ handle_type, handle);
}
+
+ priv->ready = TRUE;
}
static void
-tp_contact_list_destroy_cb (TpConn *tp_conn,
- EmpathyTpContactList *list)
+tp_contact_list_request_channel_cb (TpConnection *connection,
+ const gchar *object_path,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
{
+ EmpathyTpContactList *list = EMPATHY_TP_CONTACT_LIST (weak_object);
EmpathyTpContactListPriv *priv = GET_PRIV (list);
- GList *l;
+ EmpathyTpGroup *group;
+ TpChannel *channel;
+ TpContactListType list_type;
+ GList *contacts, *l;
- empathy_debug (DEBUG_DOMAIN, "Account disconnected or CM crashed");
+ if (error) {
+ DEBUG ("Error: %s", error->message);
+ return;
+ }
- /* DBus proxie should NOT be used anymore */
- g_object_unref (priv->tp_conn);
- priv->tp_conn = NULL;
+ channel = tp_channel_new (connection, object_path,
+ TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
+ TP_HANDLE_TYPE_LIST,
+ GPOINTER_TO_UINT (user_data),
+ NULL);
+ group = empathy_tp_group_new (channel);
+ empathy_run_until_ready (group);
- /* Remove all contacts */
- for (l = priv->members; l; l = l->next) {
- g_signal_emit_by_name (list, "members-changed", l->data,
- NULL, 0, NULL,
- FALSE);
- g_object_unref (l->data);
- }
- for (l = priv->pendings; l; l = l->next) {
- g_signal_emit_by_name (list, "pendings-changed", l->data,
- NULL, 0, NULL,
- FALSE);
- g_object_unref (l->data);
+ list_type = tp_contact_list_get_type (list, group);
+ if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH && !priv->publish) {
+ DEBUG ("Got publish list");
+ priv->publish = group;
+
+ /* Publish is the list of contacts to who we send our
+ * presence. Makes no sense to be in remote-pending */
+ g_signal_connect (group, "local-pending",
+ G_CALLBACK (tp_contact_list_pending_cb),
+ list);
+
+ contacts = empathy_tp_group_get_local_pendings (group);
+ for (l = contacts; l; l = l->next) {
+ EmpathyPendingInfo *info = l->data;
+ tp_contact_list_pending_cb (group,
+ info->member,
+ info->actor,
+ 0,
+ info->message,
+ list);
+ empathy_pending_info_free (info);
+ }
+ g_list_free (contacts);
}
- g_list_free (priv->members);
- g_list_free (priv->pendings);
- priv->members = NULL;
- priv->pendings = NULL;
+ else if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE && !priv->subscribe) {
+ DEBUG ("Got subscribe list");
+ priv->subscribe = group;
+
+ /* Subscribe is the list of contacts from who we
+ * receive presence. Makes no sense to be in
+ * local-pending */
+ g_signal_connect (group, "remote-pending",
+ G_CALLBACK (tp_contact_list_pending_cb),
+ list);
- /* Tell the world to not use us anymore */
- g_signal_emit (list, signals[DESTROY], 0);
-}
+ contacts = empathy_tp_group_get_remote_pendings (group);
+ for (l = contacts; l; l = l->next) {
+ tp_contact_list_pending_cb (group,
+ l->data,
+ NULL, 0,
+ NULL, list);
+ g_object_unref (l->data);
+ }
+ g_list_free (contacts);
+ } else {
+ DEBUG ("Type of contact list channel unknown or aleady "
+ "have that list: %s",
+ empathy_tp_group_get_name (group));
+ g_object_unref (group);
+ return;
+ }
-static void
-tp_contact_list_disconnect (EmpathyTpContactList *list)
-{
- EmpathyTpContactListPriv *priv = GET_PRIV (list);
+ /* For all list types when need to get members */
+ g_signal_connect (group, "member-added",
+ G_CALLBACK (tp_contact_list_added_cb),
+ list);
+ g_signal_connect (group, "member-removed",
+ G_CALLBACK (tp_contact_list_removed_cb),
+ list);
- if (priv->tp_conn) {
- g_signal_handlers_disconnect_by_func (priv->tp_conn,
- tp_contact_list_destroy_cb,
- list);
- dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
- G_CALLBACK (tp_contact_list_newchannel_cb),
- list);
+ contacts = empathy_tp_group_get_members (group);
+ for (l = contacts; l; l = l->next) {
+ tp_contact_list_added_cb (group,
+ l->data,
+ NULL, 0, NULL,
+ list);
+ g_object_unref (l->data);
}
+ g_list_free (contacts);
}
static void
-tp_contact_list_status_changed_cb (MissionControl *mc,
- TpConnectionStatus status,
- McPresence presence,
- TpConnectionStatusReason reason,
- const gchar *unique_name,
- EmpathyTpContactList *list)
+tp_contact_list_request_handle_cb (TpConnection *connection,
+ const GArray *handles,
+ const GError *error,
+ gpointer user_data,
+ GObject *list)
{
- EmpathyTpContactListPriv *priv = GET_PRIV (list);
- McAccount *account;
-
- account = mc_account_lookup (unique_name);
- if (status != TP_CONNECTION_STATUS_CONNECTED &&
- empathy_account_equal (account, priv->account)) {
- /* We are disconnected */
- tp_contact_list_disconnect (list);
- tp_contact_list_destroy_cb (priv->tp_conn, list);
+ guint handle;
+
+ if (error) {
+ DEBUG ("Error: %s", error->message);
+ return;
}
- g_object_unref (account);
+ handle = g_array_index (handles, guint, 0);
+ tp_cli_connection_call_request_channel (connection, -1,
+ TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
+ TP_HANDLE_TYPE_LIST,
+ handle,
+ TRUE,
+ tp_contact_list_request_channel_cb,
+ GUINT_TO_POINTER (handle), NULL,
+ list);
}
static void
-tp_contact_list_group_list_free (GList **groups)
+tp_contact_list_request_list (EmpathyTpContactList *list,
+ const gchar *type)
{
- g_list_foreach (*groups, (GFunc) g_free, NULL);
- g_list_free (*groups);
- g_slice_free (GList*, groups);
+ EmpathyTpContactListPriv *priv = GET_PRIV (list);
+ const gchar *names[] = {type, NULL};
+
+ tp_cli_connection_call_request_handles (priv->connection,
+ -1,
+ TP_HANDLE_TYPE_LIST,
+ names,
+ tp_contact_list_request_handle_cb,
+ NULL, NULL,
+ G_OBJECT (list));
}
static void
list = EMPATHY_TP_CONTACT_LIST (object);
priv = GET_PRIV (list);
- empathy_debug (DEBUG_DOMAIN, "finalize: %p", object);
-
- tp_contact_list_disconnect (list);
-
- if (priv->mc) {
- dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc),
- "AccountStatusChanged",
- G_CALLBACK (tp_contact_list_status_changed_cb),
- list);
- g_object_unref (priv->mc);
- }
+ DEBUG ("finalize: %p", object);
if (priv->subscribe) {
g_object_unref (priv->subscribe);
if (priv->account) {
g_object_unref (priv->account);
}
- if (priv->tp_conn) {
- g_object_unref (priv->tp_conn);
+ if (priv->connection) {
+ g_signal_handlers_disconnect_by_func (priv->connection,
+ tp_contact_list_invalidated_cb,
+ object);
+ g_object_unref (priv->connection);
}
g_hash_table_destroy (priv->contacts_groups);
}
static void
-empathy_tp_contact_list_class_init (EmpathyTpContactListClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = tp_contact_list_finalize;
-
- 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 (EmpathyTpContactListPriv));
-}
-
-static void
-empathy_tp_contact_list_init (EmpathyTpContactList *list)
-{
-}
-
-static void
-tp_contact_list_setup (EmpathyTpContactList *list)
+tp_contact_list_connection_ready (TpConnection *connection,
+ const GError *error,
+ gpointer list)
{
EmpathyTpContactListPriv *priv = GET_PRIV (list);
- GPtrArray *channels;
- guint i;
- GError *error = NULL;
- g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
-
- /* Get existing channels */
- if (!tp_conn_list_channels (DBUS_G_PROXY (priv->tp_conn),
- &channels,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Failed to get list of open channels: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
+ if (error) {
+ tp_contact_list_invalidated_cb (connection,
+ error->domain,
+ error->code,
+ error->message,
+ EMPATHY_TP_CONTACT_LIST (list));
return;
}
- for (i = 0; i < channels->len; i++) {
- GValueArray *chan_struct;
- const gchar *object_path;
- const gchar *chan_iface;
- TpHandleType handle_type;
- guint handle;
+ g_signal_connect (priv->connection, "invalidated",
+ G_CALLBACK (tp_contact_list_invalidated_cb),
+ list);
- chan_struct = g_ptr_array_index (channels, i);
- object_path = g_value_get_boxed (g_value_array_get_nth (chan_struct, 0));
- chan_iface = g_value_get_string (g_value_array_get_nth (chan_struct, 1));
- handle_type = g_value_get_uint (g_value_array_get_nth (chan_struct, 2));
- handle = g_value_get_uint (g_value_array_get_nth (chan_struct, 3));
+ tp_contact_list_request_list (list, "publish");
+ tp_contact_list_request_list (list, "subscribe");
- tp_contact_list_newchannel_cb (DBUS_G_PROXY (priv->tp_conn),
- object_path, chan_iface,
- handle_type, handle,
- FALSE,
- list);
+ tp_cli_connection_call_list_channels (priv->connection, -1,
+ tp_contact_list_list_channels_cb,
+ NULL, NULL,
+ list);
- g_value_array_free (chan_struct);
- }
- g_ptr_array_free (channels, TRUE);
+ tp_cli_connection_connect_to_new_channel (priv->connection,
+ tp_contact_list_new_channel_cb,
+ NULL, NULL,
+ list, NULL);
}
-EmpathyTpContactList *
-empathy_tp_contact_list_new (McAccount *account)
+static void
+tp_contact_list_constructed (GObject *list)
{
- EmpathyTpContactListPriv *priv;
- EmpathyTpContactList *list;
+
+ EmpathyTpContactListPriv *priv = GET_PRIV (list);
MissionControl *mc;
- TpConn *tp_conn = NULL;
+ guint status;
McProfile *profile;
const gchar *protocol_name;
- g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
-
- mc = empathy_mission_control_new ();
-
- /* status==0 means CONNECTED */
- if (mission_control_get_connection_status (mc, account, NULL) == 0) {
- tp_conn = mission_control_get_connection (mc, account, NULL);
- }
- if (!tp_conn) {
- /* The account is not connected, nothing to do. */
- g_object_unref (mc);
- return NULL;
- }
-
- list = g_object_new (EMPATHY_TYPE_TP_CONTACT_LIST, NULL);
- priv = GET_PRIV (list);
+ /* Get the connection. status==0 means CONNECTED */
+ mc = empathy_mission_control_dup_singleton ();
+ status = mission_control_get_connection_status (mc, priv->account, NULL);
+ g_return_if_fail (status == 0);
+ priv->connection = mission_control_get_tpconnection (mc, priv->account, NULL);
+ g_return_if_fail (priv->connection != NULL);
+ g_object_unref (mc);
- priv->tp_conn = tp_conn;
- priv->account = g_object_ref (account);
- priv->mc = mc;
- priv->contacts_groups = g_hash_table_new_full (g_direct_hash,
- g_direct_equal,
- (GDestroyNotify) g_object_unref,
- (GDestroyNotify) tp_contact_list_group_list_free);
+ tp_connection_call_when_ready (priv->connection,
+ tp_contact_list_connection_ready,
+ list);
/* Check for protocols that does not support contact groups. We can
* put all contacts into a special group in that case.
* FIXME: Default group should be an information in the profile */
- profile = mc_account_get_profile (account);
+ profile = mc_account_get_profile (priv->account);
protocol_name = mc_profile_get_protocol_name (profile);
if (strcmp (protocol_name, "local-xmpp") == 0) {
priv->protocol_group = _("People nearby");
}
g_object_unref (profile);
+}
- /* Connect signals */
- dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
- "AccountStatusChanged",
- G_CALLBACK (tp_contact_list_status_changed_cb),
- list, NULL);
- dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
- G_CALLBACK (tp_contact_list_newchannel_cb),
- list, NULL);
- g_signal_connect (priv->tp_conn, "destroy",
- G_CALLBACK (tp_contact_list_destroy_cb),
- list);
+static void
+tp_contact_list_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyTpContactListPriv *priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_ACCOUNT:
+ g_value_set_object (value, priv->account);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
- tp_contact_list_setup (list);
+static void
+tp_contact_list_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyTpContactListPriv *priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_ACCOUNT:
+ priv->account = g_object_ref (g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
- return list;
+static void
+empathy_tp_contact_list_class_init (EmpathyTpContactListClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tp_contact_list_finalize;
+ object_class->constructed = tp_contact_list_constructed;
+ object_class->get_property = tp_contact_list_get_property;
+ object_class->set_property = tp_contact_list_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_ACCOUNT,
+ g_param_spec_object ("account",
+ "The Account",
+ "The account associated with the contact list",
+ MC_TYPE_ACCOUNT,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ 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 (EmpathyTpContactListPriv));
+}
+
+static void
+empathy_tp_contact_list_init (EmpathyTpContactList *list)
+{
+ EmpathyTpContactListPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (list,
+ EMPATHY_TYPE_TP_CONTACT_LIST, EmpathyTpContactListPriv);
+
+ list->priv = priv;
+ priv->contacts_groups = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ (GDestroyNotify) g_object_unref,
+ (GDestroyNotify) tp_contact_list_group_list_free);
+}
+
+EmpathyTpContactList *
+empathy_tp_contact_list_new (McAccount *account)
+{
+ return g_object_new (EMPATHY_TYPE_TP_CONTACT_LIST,
+ "account", account,
+ NULL);
}
McAccount *
g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
- empathy_tp_group_add_member (priv->subscribe, contact, message);
- if (g_list_find (priv->pendings, contact)) {
+ if (priv->subscribe) {
+ empathy_tp_group_add_member (priv->subscribe, contact, message);
+ }
+
+ if (priv->publish && g_list_find (priv->pendings, contact)) {
empathy_tp_group_add_member (priv->publish, contact, message);
}
}
g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
- empathy_tp_group_remove_member (priv->subscribe, contact, message);
- empathy_tp_group_remove_member (priv->publish, contact, message);
+ if (priv->subscribe) {
+ empathy_tp_group_remove_member (priv->subscribe, contact, message);
+ }
+ if (priv->publish) {
+ empathy_tp_group_remove_member (priv->publish, contact, message);
+ }
}
static GList *
return tp_group;
}
- empathy_debug (DEBUG_DOMAIN, "creating new group: %s", group);
+ DEBUG ("creating new group: %s", group);
- if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
- TP_HANDLE_TYPE_GROUP,
- names,
- &handles,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Failed to RequestHandles: %s",
- error ? error->message : "No error given");
+ if (!tp_cli_connection_run_request_handles (priv->connection, -1,
+ TP_HANDLE_TYPE_GROUP,
+ names,
+ &handles,
+ &error, NULL)) {
+ DEBUG ("Failed to RequestHandles: %s",
+ error ? error->message : "No error given");
g_clear_error (&error);
return NULL;
}
handle = g_array_index (handles, guint, 0);
g_array_free (handles, TRUE);
- if (!tp_conn_request_channel (DBUS_G_PROXY (priv->tp_conn),
- TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
- TP_HANDLE_TYPE_GROUP,
- handle,
- TRUE,
- &object_path,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Failed to RequestChannel: %s",
- error ? error->message : "No error given");
+ if (!tp_cli_connection_run_request_channel (priv->connection, -1,
+ TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
+ TP_HANDLE_TYPE_GROUP,
+ handle,
+ TRUE,
+ &object_path,
+ &error, NULL)) {
+ DEBUG ("Failed to RequestChannel: %s",
+ error ? error->message : "No error given");
g_clear_error (&error);
return NULL;
}
- tp_contact_list_newchannel_cb (DBUS_G_PROXY (priv->tp_conn),
- object_path,
- TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
- TP_HANDLE_TYPE_GROUP,
- handle, FALSE,
- list);
+ tp_contact_list_add_channel (EMPATHY_TP_CONTACT_LIST (list),
+ object_path,
+ TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
+ TP_HANDLE_TYPE_GROUP, handle);
+
g_free (object_path);
return tp_contact_list_find_group (list, group);
tp_group = tp_contact_list_get_group (EMPATHY_TP_CONTACT_LIST (list),
group);
- empathy_tp_group_add_member (tp_group, contact, "");
+ if (tp_group) {
+ empathy_tp_group_add_member (tp_group, contact, "");
+ }
}
static void
return;
}
- empathy_debug (DEBUG_DOMAIN, "rename group %s to %s", old_group, new_group);
+ DEBUG ("rename group %s to %s", old_group, new_group);
/* Remove all members from the old group */
members = empathy_tp_group_get_members (tp_group);
return;
}
- empathy_debug (DEBUG_DOMAIN, "remove group %s", group);
+ DEBUG ("remove group %s", group);
/* Remove all members of the group */
members = empathy_tp_group_get_members (tp_group);
iface->remove_group = tp_contact_list_remove_group;
}
+gboolean
+empathy_tp_contact_list_can_add (EmpathyTpContactList *list)
+{
+ EmpathyTpContactListPriv *priv;
+ TpChannelGroupFlags flags;
+
+ g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), FALSE);
+
+ priv = GET_PRIV (list);
+
+ if (priv->subscribe == NULL)
+ return FALSE;
+
+ flags = empathy_tp_group_get_flags (priv->subscribe);
+ return (flags & TP_CHANNEL_GROUP_FLAG_CAN_ADD) != 0;
+}