aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-contact-manager.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-contact-manager.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-contact-manager.c')
-rw-r--r--libempathy/empathy-contact-manager.c684
1 files changed, 272 insertions, 412 deletions
diff --git a/libempathy/empathy-contact-manager.c b/libempathy/empathy-contact-manager.c
index cc00108c8..575814fab 100644
--- a/libempathy/empathy-contact-manager.c
+++ b/libempathy/empathy-contact-manager.c
@@ -39,100 +39,171 @@
struct _EmpathyContactManagerPriv {
GHashTable *lists;
MissionControl *mc;
- gboolean setup;
};
-typedef struct {
- const gchar *old_group;
- const gchar *new_group;
-} ContactManagerRenameGroupData;
-
-typedef struct {
- EmpathyContact *contact;
- const gchar *id;
-} ContactManagerFindData;
-
-static void empathy_contact_manager_class_init (EmpathyContactManagerClass *klass);
-static void contact_manager_iface_init (EmpathyContactListIface *iface);
-static void empathy_contact_manager_init (EmpathyContactManager *manager);
-static void contact_manager_finalize (GObject *object);
-static void contact_manager_setup (EmpathyContactList *manager);
-static EmpathyContact *contact_manager_find (EmpathyContactList *manager,
- const gchar *id);
-static void contact_manager_add (EmpathyContactList *manager,
- EmpathyContact *contact,
- const gchar *message);
-static void contact_manager_remove (EmpathyContactList *manager,
- EmpathyContact *contact,
- const gchar *message);
-static GList * contact_manager_get_members (EmpathyContactList *manager);
-static GList * contact_manager_get_local_pending (EmpathyContactList *manager);
-static void contact_manager_process_pending (EmpathyContactList *manager,
- EmpathyContact *contact,
- gboolean accept);
-static void contact_manager_setup_foreach (McAccount *account,
- EmpathyTpContactList *list,
- EmpathyContactManager *manager);
-static gboolean contact_manager_find_foreach (McAccount *account,
- EmpathyTpContactList *list,
- ContactManagerFindData *data);
-static void contact_manager_add_account (EmpathyContactManager *manager,
- McAccount *account);
-static void contact_manager_added_cb (EmpathyTpContactList *list,
- EmpathyContact *contact,
- EmpathyContactManager *manager);
-static void contact_manager_removed_cb (EmpathyTpContactList *list,
- EmpathyContact *contact,
- EmpathyContactManager *manager);
-static void contact_manager_local_pending_cb (EmpathyTpContactList *list,
- EmpathyContact *contact,
- const gchar *message,
- EmpathyContactManager *manager);
-static void contact_manager_destroy_cb (EmpathyTpContactList *list,
- EmpathyContactManager *manager);
-static void contact_manager_rename_group_foreach (McAccount *account,
- EmpathyTpContactList *list,
- ContactManagerRenameGroupData *data);
-static void contact_manager_get_groups_foreach (McAccount *account,
- EmpathyTpContactList *list,
- GList **all_groups);
-static void contact_manager_get_members_foreach (McAccount *account,
- EmpathyTpContactList *list,
- GList **contacts);
-static void contact_manager_get_local_pending_foreach (McAccount *account,
- EmpathyTpContactList *list,
- GList **contacts);
-static void contact_manager_status_changed_cb (MissionControl *mc,
- TelepathyConnectionStatus status,
- McPresence presence,
- TelepathyConnectionStatusReason reason,
- const gchar *unique_name,
- EmpathyContactManager *manager);
+static void empathy_contact_manager_class_init (EmpathyContactManagerClass *klass);
+static void empathy_contact_manager_init (EmpathyContactManager *manager);
+static void contact_manager_iface_init (EmpathyContactListIface *iface);
G_DEFINE_TYPE_WITH_CODE (EmpathyContactManager, empathy_contact_manager, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
contact_manager_iface_init));
static void
-empathy_contact_manager_class_init (EmpathyContactManagerClass *klass)
+contact_manager_members_changed_cb (EmpathyTpContactList *list,
+ EmpathyContact *contact,
+ EmpathyContact *actor,
+ guint reason,
+ gchar *message,
+ gboolean is_member,
+ EmpathyContactManager *manager)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ g_signal_emit_by_name (manager, "members-changed",
+ contact, actor, reason, message, is_member);
+}
- object_class->finalize = contact_manager_finalize;
+static void
+contact_manager_pendings_changed_cb (EmpathyTpContactList *list,
+ EmpathyContact *contact,
+ EmpathyContact *actor,
+ guint reason,
+ gchar *message,
+ gboolean is_pending,
+ EmpathyContactManager *manager)
+{
+ g_signal_emit_by_name (manager, "pendings-changed",
+ contact, actor, reason, message, is_pending);
+}
- g_type_class_add_private (object_class, sizeof (EmpathyContactManagerPriv));
+static void
+contact_manager_groups_changed_cb (EmpathyTpContactList *list,
+ EmpathyContact *contact,
+ gchar *group,
+ gboolean is_member,
+ EmpathyContactManager *manager)
+{
+ g_signal_emit_by_name (manager, "groups-changed",
+ contact, group, is_member);
}
+static void contact_manager_destroy_cb (EmpathyTpContactList *list,
+ EmpathyContactManager *manager);
+
static void
-contact_manager_iface_init (EmpathyContactListIface *iface)
+contact_manager_disconnect_foreach (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- iface->setup = contact_manager_setup;
- iface->find = contact_manager_find;
- iface->add = contact_manager_add;
- iface->remove = contact_manager_remove;
- iface->get_members = contact_manager_get_members;
- iface->get_local_pending = contact_manager_get_local_pending;
- iface->process_pending = contact_manager_process_pending;
+ EmpathyTpContactList *list = value;
+ EmpathyContactManager *manager = user_data;
+
+ /* Disconnect signals from the list */
+ g_signal_handlers_disconnect_by_func (list,
+ contact_manager_members_changed_cb,
+ manager);
+ g_signal_handlers_disconnect_by_func (list,
+ contact_manager_pendings_changed_cb,
+ manager);
+ g_signal_handlers_disconnect_by_func (list,
+ contact_manager_groups_changed_cb,
+ manager);
+ g_signal_handlers_disconnect_by_func (list,
+ contact_manager_destroy_cb,
+ manager);
+}
+
+static void
+contact_manager_destroy_cb (EmpathyTpContactList *list,
+ EmpathyContactManager *manager)
+{
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
+ McAccount *account;
+
+ account = empathy_tp_contact_list_get_account (list);
+
+ empathy_debug (DEBUG_DOMAIN, "Removing account: %s",
+ mc_account_get_display_name (account));
+
+ contact_manager_disconnect_foreach (account, list, manager);
+ g_hash_table_remove (priv->lists, account);
+}
+
+static void
+contact_manager_add_account (EmpathyContactManager *manager,
+ McAccount *account)
+{
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
+ EmpathyTpContactList *list;
+
+ if (g_hash_table_lookup (priv->lists, account)) {
+ return;
+ }
+
+ empathy_debug (DEBUG_DOMAIN, "Adding new account: %s",
+ mc_account_get_display_name (account));
+
+ list = empathy_tp_contact_list_new (account);
+ if (!list) {
+ return;
+ }
+
+ g_hash_table_insert (priv->lists, g_object_ref (account), list);
+
+ /* Connect signals */
+ g_signal_connect (list, "members-changed",
+ G_CALLBACK (contact_manager_members_changed_cb),
+ manager);
+ g_signal_connect (list, "pendings-changed",
+ G_CALLBACK (contact_manager_pendings_changed_cb),
+ manager);
+ g_signal_connect (list, "groups-changed",
+ G_CALLBACK (contact_manager_groups_changed_cb),
+ manager);
+ g_signal_connect (list, "destroy",
+ G_CALLBACK (contact_manager_destroy_cb),
+ manager);
+}
+
+static void
+contact_manager_status_changed_cb (MissionControl *mc,
+ TelepathyConnectionStatus status,
+ McPresence presence,
+ TelepathyConnectionStatusReason reason,
+ const gchar *unique_name,
+ EmpathyContactManager *manager)
+{
+ McAccount *account;
+
+ if (status != TP_CONN_STATUS_CONNECTED) {
+ /* We only care about newly connected accounts */
+ return;
+ }
+
+ account = mc_account_lookup (unique_name);
+ contact_manager_add_account (manager, account);
+ g_object_unref (account);
+}
+
+static void
+contact_manager_finalize (GObject *object)
+{
+ EmpathyContactManagerPriv *priv = GET_PRIV (object);
+
+ g_hash_table_foreach (priv->lists,
+ contact_manager_disconnect_foreach,
+ object);
+ g_hash_table_destroy (priv->lists);
+ g_object_unref (priv->mc);
+}
+
+static void
+empathy_contact_manager_class_init (EmpathyContactManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = contact_manager_finalize;
+
+ g_type_class_add_private (object_class, sizeof (EmpathyContactManagerPriv));
}
static void
@@ -158,27 +229,12 @@ empathy_contact_manager_init (EmpathyContactManager *manager)
/* Get ContactList for existing connections */
accounts = mission_control_get_online_connections (priv->mc, NULL);
for (l = accounts; l; l = l->next) {
- McAccount *account;
-
- account = l->data;
- contact_manager_add_account (manager, account);
-
- g_object_unref (account);
+ contact_manager_add_account (manager, l->data);
+ g_object_unref (l->data);
}
g_slist_free (accounts);
}
-static void
-contact_manager_finalize (GObject *object)
-{
- EmpathyContactManagerPriv *priv;
-
- priv = GET_PRIV (object);
-
- g_hash_table_destroy (priv->lists);
- g_object_unref (priv->mc);
-}
-
EmpathyContactManager *
empathy_contact_manager_new (void)
{
@@ -194,62 +250,28 @@ empathy_contact_manager_new (void)
return manager;
}
-static void
-contact_manager_setup (EmpathyContactList *manager)
-{
- EmpathyContactManagerPriv *priv;
-
- g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
-
- priv = GET_PRIV (manager);
-
- if (priv->setup) {
- /* Already done */
- return;
- }
-
- g_hash_table_foreach (priv->lists,
- (GHFunc) contact_manager_setup_foreach,
- manager);
-
- priv->setup = TRUE;
-}
-
-static EmpathyContact *
-contact_manager_find (EmpathyContactList *manager,
- const gchar *id)
+EmpathyTpContactList *
+empathy_contact_manager_get_list (EmpathyContactManager *manager,
+ McAccount *account)
{
- EmpathyContactManagerPriv *priv;
- ContactManagerFindData data;
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), NULL);
- g_return_val_if_fail (id != NULL, NULL);
-
- priv = GET_PRIV (manager);
-
- data.contact = NULL;
- data.id = id;
-
- g_hash_table_find (priv->lists,
- (GHRFunc) contact_manager_find_foreach,
- &data);
+ g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
- return data.contact;
+ return g_hash_table_lookup (priv->lists, account);
}
static void
contact_manager_add (EmpathyContactList *manager,
- EmpathyContact *contact,
+ EmpathyContact *contact,
const gchar *message)
{
- EmpathyContactManagerPriv *priv;
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
EmpathyContactList *list;
McAccount *account;
g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
- g_return_if_fail (EMPATHY_IS_CONTACT (contact));
-
- priv = GET_PRIV (manager);
account = empathy_contact_get_account (contact);
list = g_hash_table_lookup (priv->lists, account);
@@ -264,14 +286,11 @@ contact_manager_remove (EmpathyContactList *manager,
EmpathyContact *contact,
const gchar *message)
{
- EmpathyContactManagerPriv *priv;
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
EmpathyContactList *list;
McAccount *account;
g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
- g_return_if_fail (EMPATHY_IS_CONTACT (contact));
-
- priv = GET_PRIV (manager);
account = empathy_contact_get_account (contact);
list = g_hash_table_lookup (priv->lists, account);
@@ -281,16 +300,25 @@ contact_manager_remove (EmpathyContactList *manager,
}
}
+static void
+contact_manager_get_members_foreach (McAccount *account,
+ EmpathyTpContactList *list,
+ GList **contacts)
+{
+ GList *l;
+
+ l = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (list));
+ *contacts = g_list_concat (*contacts, l);
+}
+
static GList *
contact_manager_get_members (EmpathyContactList *manager)
{
- EmpathyContactManagerPriv *priv;
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
GList *contacts = NULL;
g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), NULL);
- priv = GET_PRIV (manager);
-
g_hash_table_foreach (priv->lists,
(GHFunc) contact_manager_get_members_foreach,
&contacts);
@@ -298,337 +326,169 @@ contact_manager_get_members (EmpathyContactList *manager)
return contacts;
}
-static GList *
-contact_manager_get_local_pending (EmpathyContactList *manager)
-{
- EmpathyContactManagerPriv *priv;
- GList *pending = NULL;
-
- g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), NULL);
-
- priv = GET_PRIV (manager);
-
- g_hash_table_foreach (priv->lists,
- (GHFunc) contact_manager_get_local_pending_foreach,
- &pending);
-
- return pending;
-}
-
static void
-contact_manager_process_pending (EmpathyContactList *manager,
- EmpathyContact *contact,
- gboolean accept)
+contact_manager_get_pendings_foreach (McAccount *account,
+ EmpathyTpContactList *list,
+ GList **contacts)
{
- EmpathyContactManagerPriv *priv;
- EmpathyContactList *list;
- McAccount *account;
-
- g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
- g_return_if_fail (EMPATHY_IS_CONTACT (contact));
-
- priv = GET_PRIV (manager);
-
- account = empathy_contact_get_account (contact);
- list = g_hash_table_lookup (priv->lists, account);
-
- if (list) {
- empathy_contact_list_process_pending (list, contact, accept);
- }
-}
-
-EmpathyTpContactList *
-empathy_contact_manager_get_list (EmpathyContactManager *manager,
- McAccount *account)
-{
- EmpathyContactManagerPriv *priv;
-
- g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), NULL);
- g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
-
- priv = GET_PRIV (manager);
+ GList *l;
- return g_hash_table_lookup (priv->lists, account);
+ l = empathy_contact_list_get_pendings (EMPATHY_CONTACT_LIST (list));
+ *contacts = g_list_concat (*contacts, l);
}
-EmpathyContact *
-empathy_contact_manager_get_user (EmpathyContactManager *manager,
- McAccount *account)
+static GList *
+contact_manager_get_pendings (EmpathyContactList *manager)
{
- EmpathyContactManagerPriv *priv;
- EmpathyTpContactList *list;
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
+ GList *contacts = NULL;
g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), NULL);
- g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
-
- priv = GET_PRIV (manager);
- list = g_hash_table_lookup (priv->lists, account);
-
- if (!list) {
- return NULL;
- }
+ g_hash_table_foreach (priv->lists,
+ (GHFunc) contact_manager_get_pendings_foreach,
+ &contacts);
- return empathy_tp_contact_list_get_user (list);
+ return contacts;
}
-EmpathyContact *
-empathy_contact_manager_create (EmpathyContactManager *manager,
- McAccount *account,
- const gchar *id)
+static void
+contact_manager_get_all_groups_foreach (McAccount *account,
+ EmpathyTpContactList *list,
+ GList **all_groups)
{
- EmpathyContactManagerPriv *priv;
- EmpathyTpContactList *list;
-
- g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), NULL);
- g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
- g_return_val_if_fail (id != NULL, NULL);
-
- priv = GET_PRIV (manager);
+ GList *groups, *l;
- list = g_hash_table_lookup (priv->lists, account);
-
- if (!list) {
- return NULL;
+ groups = empathy_contact_list_get_all_groups (EMPATHY_CONTACT_LIST (list));
+ for (l = groups; l; l = l->next) {
+ if (!g_list_find_custom (*all_groups,
+ l->data,
+ (GCompareFunc) strcmp)) {
+ *all_groups = g_list_prepend (*all_groups, l->data);
+ } else {
+ g_free (l->data);
+ }
}
- return empathy_tp_contact_list_get_from_id (list, id);
-}
-
-void
-empathy_contact_manager_rename_group (EmpathyContactManager *manager,
- const gchar *old_group,
- const gchar *new_group)
-{
- EmpathyContactManagerPriv *priv;
- ContactManagerRenameGroupData data;
-
- g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
- g_return_if_fail (old_group != NULL);
- g_return_if_fail (new_group != NULL);
-
- priv = GET_PRIV (manager);
-
- data.old_group = old_group;
- data.new_group = new_group;
-
- g_hash_table_foreach (priv->lists,
- (GHFunc) contact_manager_rename_group_foreach,
- &data);
+ g_list_free (groups);
}
-GList *
-empathy_contact_manager_get_groups (EmpathyContactManager *manager)
+static GList *
+contact_manager_get_all_groups (EmpathyContactList *manager)
{
- EmpathyContactManagerPriv *priv;
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
GList *groups = NULL;
g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), NULL);
- priv = GET_PRIV (manager);
-
g_hash_table_foreach (priv->lists,
- (GHFunc) contact_manager_get_groups_foreach,
+ (GHFunc) contact_manager_get_all_groups_foreach,
&groups);
return groups;
}
-static void
-contact_manager_setup_foreach (McAccount *account,
- EmpathyTpContactList *list,
- EmpathyContactManager *manager)
+static GList *
+contact_manager_get_groups (EmpathyContactList *manager,
+ EmpathyContact *contact)
{
- empathy_contact_list_setup (EMPATHY_CONTACT_LIST (list));
-}
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
+ EmpathyContactList *list;
+ McAccount *account;
-static gboolean
-contact_manager_find_foreach (McAccount *account,
- EmpathyTpContactList *list,
- ContactManagerFindData *data)
-{
- data->contact = empathy_contact_list_find (EMPATHY_CONTACT_LIST (list),
- data->id);
+ g_return_val_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager), NULL);
+
+ account = empathy_contact_get_account (contact);
+ list = g_hash_table_lookup (priv->lists, account);
- if (data->contact) {
- return TRUE;
+ if (list) {
+ return empathy_contact_list_get_groups (list, contact);
}
- return FALSE;
+ return NULL;
}
static void
-contact_manager_add_account (EmpathyContactManager *manager,
- McAccount *account)
+contact_manager_add_to_group (EmpathyContactList *manager,
+ EmpathyContact *contact,
+ const gchar *group)
{
- EmpathyContactManagerPriv *priv;
- EmpathyTpContactList *list;
-
- priv = GET_PRIV (manager);
-
- if (g_hash_table_lookup (priv->lists, account)) {
- return;
- }
-
- empathy_debug (DEBUG_DOMAIN, "Adding new account: %s",
- mc_account_get_display_name (account));
-
- list = empathy_tp_contact_list_new (account);
- if (!list) {
- return;
- }
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
+ EmpathyContactList *list;
+ McAccount *account;
- g_hash_table_insert (priv->lists, g_object_ref (account), list);
+ g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
- /* Connect signals */
- g_signal_connect (list, "contact-added",
- G_CALLBACK (contact_manager_added_cb),
- manager);
- g_signal_connect (list, "contact-removed",
- G_CALLBACK (contact_manager_removed_cb),
- manager);
- g_signal_connect (list, "local-pending",
- G_CALLBACK (contact_manager_local_pending_cb),
- manager);
- g_signal_connect (list, "destroy",
- G_CALLBACK (contact_manager_destroy_cb),
- manager);
+ account = empathy_contact_get_account (contact);
+ list = g_hash_table_lookup (priv->lists, account);
- if (priv->setup) {
- empathy_contact_list_setup (EMPATHY_CONTACT_LIST (list));
+ if (list) {
+ empathy_contact_list_add_to_group (list, contact, group);
}
}
static void
-contact_manager_added_cb (EmpathyTpContactList *list,
- EmpathyContact *contact,
- EmpathyContactManager *manager)
+contact_manager_remove_from_group (EmpathyContactList *manager,
+ EmpathyContact *contact,
+ const gchar *group)
{
- g_signal_emit_by_name (manager, "contact-added", contact);
-}
-
-static void
-contact_manager_removed_cb (EmpathyTpContactList *list,
- EmpathyContact *contact,
- EmpathyContactManager *manager)
-{
- g_signal_emit_by_name (manager, "contact-removed", contact);
-}
-
-static void
-contact_manager_local_pending_cb (EmpathyTpContactList *list,
- EmpathyContact *contact,
- const gchar *message,
- EmpathyContactManager *manager)
-{
- g_signal_emit_by_name (manager, "local-pending", contact, message);
-}
-
-static void
-contact_manager_destroy_cb (EmpathyTpContactList *list,
- EmpathyContactManager *manager)
-{
- EmpathyContactManagerPriv *priv;
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
+ EmpathyContactList *list;
McAccount *account;
- priv = GET_PRIV (manager);
-
- account = empathy_tp_contact_list_get_account (list);
-
- empathy_debug (DEBUG_DOMAIN, "Removing account: %s",
- mc_account_get_display_name (account));
+ g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
- /* Disconnect signals from the list */
- g_signal_handlers_disconnect_by_func (list,
- contact_manager_added_cb,
- manager);
- g_signal_handlers_disconnect_by_func (list,
- contact_manager_removed_cb,
- manager);
- g_signal_handlers_disconnect_by_func (list,
- contact_manager_local_pending_cb,
- manager);
- g_signal_handlers_disconnect_by_func (list,
- contact_manager_destroy_cb,
- manager);
+ account = empathy_contact_get_account (contact);
+ list = g_hash_table_lookup (priv->lists, account);
- g_hash_table_remove (priv->lists, account);
+ if (list) {
+ empathy_contact_list_remove_from_group (list, contact, group);
+ }
}
-static void
-contact_manager_rename_group_foreach (McAccount *account,
- EmpathyTpContactList *list,
- ContactManagerRenameGroupData *data)
-{
- empathy_tp_contact_list_rename_group (list,
- data->old_group,
- data->new_group);
-}
+typedef struct {
+ const gchar *old_group;
+ const gchar *new_group;
+} RenameGroupData;
static void
-contact_manager_get_groups_foreach (McAccount *account,
- EmpathyTpContactList *list,
- GList **all_groups)
+contact_manager_rename_group_foreach (McAccount *account,
+ EmpathyTpContactList *list,
+ RenameGroupData *data)
{
- GList *groups, *l;
-
- groups = empathy_tp_contact_list_get_groups (list);
- for (l = groups; l; l = l->next) {
- if (!g_list_find_custom (*all_groups,
- l->data,
- (GCompareFunc) strcmp)) {
- *all_groups = g_list_append (*all_groups,
- g_strdup (l->data));
- }
- g_free (l->data);
- }
-
- g_list_free (groups);
+ empathy_contact_list_rename_group (EMPATHY_CONTACT_LIST (list),
+ data->old_group,
+ data->new_group);
}
static void
-contact_manager_get_members_foreach (McAccount *account,
- EmpathyTpContactList *list,
- GList **contacts)
+contact_manager_rename_group (EmpathyContactList *manager,
+ const gchar *old_group,
+ const gchar *new_group)
{
- GList *l;
-
- l = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (list));
- *contacts = g_list_concat (*contacts, l);
-}
+ EmpathyContactManagerPriv *priv = GET_PRIV (manager);
+ RenameGroupData data;
-static void
-contact_manager_get_local_pending_foreach (McAccount *account,
- EmpathyTpContactList *list,
- GList **contacts)
-{
- GList *l;
+ g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
- l = empathy_contact_list_get_local_pending (EMPATHY_CONTACT_LIST (list));
- *contacts = g_list_concat (*contacts, l);
+ data.old_group = old_group;
+ data.new_group = new_group;
+ g_hash_table_foreach (priv->lists,
+ (GHFunc) contact_manager_rename_group_foreach,
+ &data);
}
static void
-contact_manager_status_changed_cb (MissionControl *mc,
- TelepathyConnectionStatus status,
- McPresence presence,
- TelepathyConnectionStatusReason reason,
- const gchar *unique_name,
- EmpathyContactManager *manager)
+contact_manager_iface_init (EmpathyContactListIface *iface)
{
- EmpathyContactManagerPriv *priv;
- McAccount *account;
-
- priv = GET_PRIV (manager);
-
- if (status != TP_CONN_STATUS_CONNECTED) {
- /* We only care about newly connected accounts */
- return;
- }
-
- account = mc_account_lookup (unique_name);
- contact_manager_add_account (manager, account);
-
- g_object_unref (account);
+ iface->add = contact_manager_add;
+ iface->remove = contact_manager_remove;
+ iface->get_members = contact_manager_get_members;
+ iface->get_pendings = contact_manager_get_pendings;
+ iface->get_all_groups = contact_manager_get_all_groups;
+ iface->get_groups = contact_manager_get_groups;
+ iface->add_to_group = contact_manager_add_to_group;
+ iface->remove_from_group = contact_manager_remove_from_group;
+ iface->rename_group = contact_manager_rename_group;
}