From 49676b7823685463409a3653e00ce4707f00d226 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sun, 20 May 2007 10:26:38 +0000 Subject: [PATCH] Allow to set custom function for getting groups of a contact. Make 2007-05-20 Xavier Claessens * libempathy-gtk/gossip-contact-list-store.c: Allow to set custom function for getting groups of a contact. Make possible to have groups for presence or role/affiliation in chatroom for example. * libempathy-gtk/gossip-contact-list-store.h: Allow to set custom function to handle DnD of contact. Useful when a custom function is set for groups. * src/empathy-chat-main.c: Minor fix. * TODO: * po/POTFILES.in: Updated. svn path=/trunk/; revision=76 --- ChangeLog | 12 +++ TODO | 2 + libempathy-gtk/gossip-contact-list-store.c | 92 +++++++++++++++++++--- libempathy-gtk/gossip-contact-list-store.h | 7 ++ po/POTFILES.in | 2 +- src/empathy-chat-main.c | 8 +- 6 files changed, 103 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88a07a0f..18aa6a57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-05-20 Xavier Claessens + + * libempathy-gtk/gossip-contact-list-store.c: Allow to set custom + function for getting groups of a contact. Make possible to have groups + for presence or role/affiliation in chatroom for example. + * libempathy-gtk/gossip-contact-list-store.h: Allow to set custom + function to handle DnD of contact. Useful when a custom function is set + for groups. + * src/empathy-chat-main.c: Minor fix. + * TODO: + * po/POTFILES.in: Updated. + 2007-05-19 Xavier Claessens * libempathy-gtk/Makefile.am: diff --git a/TODO b/TODO index 1b78f283..da967a33 100644 --- a/TODO +++ b/TODO @@ -8,6 +8,8 @@ Things you can do if you want to help: - Filter channels before dispatching them. For example we need a GtkStatusIcon that blink when an event arrives (text/voip/ft channel) and tells the MC to dispatch the channel only when the user clicked the icon. Like in gossip. For that we need a filter DBus API in MC, not yet written. - Make use of NetworkManager to set the presence - Remove Quit option everywhere, empathy is a session service and shouldn't be leaved. + - Add sound events + - Import loggin system from gossip - Testing and Bugfixing. SoC projects: diff --git a/libempathy-gtk/gossip-contact-list-store.c b/libempathy-gtk/gossip-contact-list-store.c index 1536262b..a2cbae57 100644 --- a/libempathy-gtk/gossip-contact-list-store.c +++ b/libempathy-gtk/gossip-contact-list-store.c @@ -57,6 +57,9 @@ struct _GossipContactListStorePriv { gboolean is_compact; gboolean show_active; GossipContactListStoreSort sort_criterium; + + GossipContactGroupsFunc get_contact_groups; + gpointer get_contact_groups_data; }; typedef struct { @@ -622,6 +625,69 @@ gossip_contact_list_store_search_equal_func (GtkTreeModel *model, return ret; } +void +gossip_contact_list_store_set_contact_groups_func (GossipContactListStore *store, + GossipContactGroupsFunc func, + gpointer user_data) +{ + GossipContactListStorePriv *priv; + GList *contacts, *l; + + g_return_if_fail (GOSSIP_IS_CONTACT_LIST_STORE (store)); + + priv = GET_PRIV (store); + + if (func) { + priv->get_contact_groups = func; + priv->get_contact_groups_data = user_data; + } else { + priv->get_contact_groups = NULL; + priv->get_contact_groups_data = NULL; + } + + /* If we set a custom function to get contacts groups we have to + * disconnect our default notify::groups signal and wait for the user + * to call himself gossip_contact_list_store_update_contact_groups () + * when needed. If func is NULL we come back to default. + */ + contacts = empathy_contact_list_get_contacts (priv->list); + for (l = contacts; l; l = l->next) { + GossipContact *contact; + + contact = l->data; + + if (func) { + g_signal_handlers_disconnect_by_func (contact, + G_CALLBACK (contact_list_store_contact_groups_updated_cb), + store); + } else { + g_signal_connect (contact, "notify::groups", + G_CALLBACK (contact_list_store_contact_groups_updated_cb), + store); + } + + gossip_contact_list_store_update_contact_groups (store, contact); + + g_object_unref (contact); + } + g_list_free (contacts); +} + +void +gossip_contact_list_store_update_contact_groups (GossipContactListStore *store, + GossipContact *contact) +{ + gossip_debug (DEBUG_DOMAIN, "Contact:'%s' updating groups", + gossip_contact_get_name (contact)); + + /* We do this to make sure the groups are correct, if not, we + * would have to check the groups already set up for each + * contact and then see what has been updated. + */ + contact_list_store_remove_contact (store, contact); + contact_list_store_add_contact (store, contact); +} + static void contact_list_store_setup (GossipContactListStore *store) { @@ -668,9 +734,11 @@ contact_list_store_contact_added_cb (EmpathyContactList *list_iface, "Contact:'%s' added", gossip_contact_get_name (contact)); - g_signal_connect (contact, "notify::groups", - G_CALLBACK (contact_list_store_contact_groups_updated_cb), - store); + if (!priv->get_contact_groups) { + g_signal_connect (contact, "notify::groups", + G_CALLBACK (contact_list_store_contact_groups_updated_cb), + store); + } g_signal_connect (contact, "notify::presence", G_CALLBACK (contact_list_store_contact_updated_cb), store); @@ -702,7 +770,13 @@ contact_list_store_add_contact (GossipContactListStore *store, } /* If no groups just add it at the top level. */ - groups = gossip_contact_get_groups (contact); + if (priv->get_contact_groups) { + groups = priv->get_contact_groups (contact, + priv->get_contact_groups_data); + } else { + groups = gossip_contact_get_groups (contact); + } + if (!groups) { gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL); gtk_tree_store_set (GTK_TREE_STORE (store), &iter, @@ -942,15 +1016,7 @@ contact_list_store_contact_groups_updated_cb (GossipContact *contact, GParamSpec *param, GossipContactListStore *store) { - gossip_debug (DEBUG_DOMAIN, "Contact:'%s' groups updated", - gossip_contact_get_name (contact)); - - /* We do this to make sure the groups are correct, if not, we - * would have to check the groups already set up for each - * contact and then see what has been updated. - */ - contact_list_store_remove_contact (store, contact); - contact_list_store_add_contact (store, contact); + gossip_contact_list_store_update_contact_groups (store, contact); } static void diff --git a/libempathy-gtk/gossip-contact-list-store.h b/libempathy-gtk/gossip-contact-list-store.h index 66d0b46b..b2131bca 100644 --- a/libempathy-gtk/gossip-contact-list-store.h +++ b/libempathy-gtk/gossip-contact-list-store.h @@ -81,6 +81,8 @@ struct _GossipContactListStore { struct _GossipContactListStoreClass { GtkTreeStoreClass parent_class; }; +typedef GList * (*GossipContactGroupsFunc) (GossipContact *contact, + gpointer user_data); GType gossip_contact_list_store_get_type (void) G_GNUC_CONST; GossipContactListStore * gossip_contact_list_store_new (EmpathyContactList *list_iface); @@ -108,6 +110,11 @@ gboolean gossip_contact_list_store_search_equal_func (GtkTree const gchar *key, GtkTreeIter *iter, gpointer search_data); +void gossip_contact_list_store_set_contact_groups_func (GossipContactListStore*store, + GossipContactGroupsFunc func, + gpointer user_data); +void gossip_contact_list_store_update_contact_groups (GossipContactListStore *store, + GossipContact *contact); G_END_DECLS diff --git a/po/POTFILES.in b/po/POTFILES.in index 5ca5eb80..4d04ad57 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -20,7 +20,7 @@ libempathy-gtk/gossip-chat.c libempathy-gtk/gossip-chat.glade libempathy-gtk/gossip-chat-view.c libempathy-gtk/gossip-chat-window.c -libempathy-gtk/gossip-contact-list.c +libempathy-gtk/gossip-contact-list-view.c libempathy-gtk/gossip-preferences.c libempathy-gtk/gossip-preferences.glade libempathy-gtk/gossip-presence-chooser.c diff --git a/src/empathy-chat-main.c b/src/empathy-chat-main.c index 28776659..339c4d0f 100644 --- a/src/empathy-chat-main.c +++ b/src/empathy-chat-main.c @@ -128,11 +128,8 @@ new_channel_cb (EmpathyChandler *chandler, g_object_unref (tp_chat); } gossip_chat_present (chat); - - goto OUT; } - - if (tp_chan->handle_type == TP_HANDLE_TYPE_CONTACT) { + else if (tp_chan->handle_type == TP_HANDLE_TYPE_CONTACT) { EmpathyContactManager *manager; EmpathyTpContactList *list; GossipContact *contact; @@ -157,7 +154,7 @@ new_channel_cb (EmpathyChandler *chandler, g_object_unref (chat); g_object_unref (manager); } - if (tp_chan->handle_type == TP_HANDLE_TYPE_ROOM) { + else if (tp_chan->handle_type == TP_HANDLE_TYPE_ROOM) { #if 0 GossipGroupChat *chat; @@ -176,7 +173,6 @@ new_channel_cb (EmpathyChandler *chandler, #endif } -OUT: g_free (id); g_object_unref (account); g_object_unref (mc); -- 2.39.2