From: Xavier Claessens Date: Sun, 20 Jan 2008 21:42:01 +0000 (+0000) Subject: Add a property to have or not groups on EmpathyContactListStore X-Git-Url: https://git.0d.be/?p=empathy.git;a=commitdiff_plain;h=eccbc4d73eca63fd700d89f9bc31dcad7cb17edc Add a property to have or not groups on EmpathyContactListStore svn path=/trunk/; revision=586 --- diff --git a/libempathy-gtk/empathy-contact-list-store.c b/libempathy-gtk/empathy-contact-list-store.c index 5cc0aa88..b430addd 100644 --- a/libempathy-gtk/empathy-contact-list-store.c +++ b/libempathy-gtk/empathy-contact-list-store.c @@ -54,6 +54,7 @@ typedef struct { EmpathyContactList *list; gboolean show_offline; gboolean show_avatars; + gboolean show_groups; gboolean is_compact; gboolean show_active; EmpathyContactListStoreSort sort_criterium; @@ -155,14 +156,63 @@ static gboolean contact_list_store_update_list_mode_foreach (GtkTreeMod enum { PROP_0, + PROP_CONTACT_LIST, PROP_SHOW_OFFLINE, PROP_SHOW_AVATARS, + PROP_SHOW_GROUPS, PROP_IS_COMPACT, PROP_SORT_CRITERIUM }; G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE); + +static gboolean +contact_list_store_iface_setup (gpointer user_data) +{ + EmpathyContactListStore *store = user_data; + EmpathyContactListStorePriv *priv = GET_PRIV (store); + GList *contacts, *l; + + /* Signal connection. */ + g_signal_connect (priv->list, + "members-changed", + G_CALLBACK (contact_list_store_members_changed_cb), + store); + g_signal_connect (priv->list, + "groups-changed", + G_CALLBACK (contact_list_store_groups_changed_cb), + store); + + /* Add contacts already created. */ + contacts = empathy_contact_list_get_members (priv->list); + for (l = contacts; l; l = l->next) { + contact_list_store_members_changed_cb (priv->list, l->data, + NULL, 0, NULL, + TRUE, + store); + + g_object_unref (l->data); + } + g_list_free (contacts); + + return FALSE; +} + + +static void +contact_list_store_set_contact_list (EmpathyContactListStore *store, + EmpathyContactList *list_iface) +{ + EmpathyContactListStorePriv *priv = GET_PRIV (store); + + priv->list = g_object_ref (list_iface); + + /* Let a chance to have all properties set before populating */ + g_idle_add (contact_list_store_iface_setup, + store); +} + static void empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass) { @@ -172,6 +222,14 @@ empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass) object_class->get_property = contact_list_store_get_property; object_class->set_property = contact_list_store_set_property; + g_object_class_install_property (object_class, + PROP_CONTACT_LIST, + g_param_spec_object ("contact-list", + "The contact list iface", + "The contact list iface", + EMPATHY_TYPE_CONTACT_LIST, + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_SHOW_OFFLINE, g_param_spec_boolean ("show-offline", @@ -188,6 +246,14 @@ empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass) "avatars for contacts", TRUE, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_SHOW_GROUPS, + g_param_spec_boolean ("show-groups", + "Show Groups", + "Whether contact list should display " + "contact groups", + TRUE, + G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_IS_COMPACT, g_param_spec_boolean ("is-compact", @@ -216,9 +282,11 @@ empathy_contact_list_store_init (EmpathyContactListStore *store) priv = GET_PRIV (store); priv->show_avatars = TRUE; + priv->show_groups = TRUE; priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME, (GSourceFunc) contact_list_store_inibit_active_cb, store); + contact_list_store_setup (store); } static void @@ -260,12 +328,18 @@ contact_list_store_get_property (GObject *object, priv = GET_PRIV (object); switch (param_id) { + case PROP_CONTACT_LIST: + g_value_set_object (value, priv->list); + break; case PROP_SHOW_OFFLINE: g_value_set_boolean (value, priv->show_offline); break; case PROP_SHOW_AVATARS: g_value_set_boolean (value, priv->show_avatars); break; + case PROP_SHOW_GROUPS: + g_value_set_boolean (value, priv->show_groups); + break; case PROP_IS_COMPACT: g_value_set_boolean (value, priv->is_compact); break; @@ -289,6 +363,10 @@ contact_list_store_set_property (GObject *object, priv = GET_PRIV (object); switch (param_id) { + case PROP_CONTACT_LIST: + contact_list_store_set_contact_list (EMPATHY_CONTACT_LIST_STORE (object), + g_value_get_object (value)); + break; case PROP_SHOW_OFFLINE: empathy_contact_list_store_set_show_offline (EMPATHY_CONTACT_LIST_STORE (object), g_value_get_boolean (value)); @@ -297,6 +375,10 @@ contact_list_store_set_property (GObject *object, empathy_contact_list_store_set_show_avatars (EMPATHY_CONTACT_LIST_STORE (object), g_value_get_boolean (value)); break; + case PROP_SHOW_GROUPS: + empathy_contact_list_store_set_show_groups (EMPATHY_CONTACT_LIST_STORE (object), + g_value_get_boolean (value)); + break; case PROP_IS_COMPACT: empathy_contact_list_store_set_is_compact (EMPATHY_CONTACT_LIST_STORE (object), g_value_get_boolean (value)); @@ -312,43 +394,15 @@ contact_list_store_set_property (GObject *object, } EmpathyContactListStore * -empathy_contact_list_store_new (EmpathyContactList *list_iface) +empathy_contact_list_store_new (EmpathyContactList *list_iface, + gboolean show_groups) { - EmpathyContactListStore *store; - EmpathyContactListStorePriv *priv; - GList *contacts, *l; - g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list_iface), NULL); - store = g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE, NULL); - priv = GET_PRIV (store); - - contact_list_store_setup (store); - priv->list = g_object_ref (list_iface); - - /* Signal connection. */ - g_signal_connect (priv->list, - "members-changed", - G_CALLBACK (contact_list_store_members_changed_cb), - store); - g_signal_connect (priv->list, - "groups-changed", - G_CALLBACK (contact_list_store_groups_changed_cb), - store); - - /* Add contacts already created. */ - contacts = empathy_contact_list_get_members (priv->list); - for (l = contacts; l; l = l->next) { - contact_list_store_members_changed_cb (priv->list, l->data, - NULL, 0, NULL, - TRUE, - store); - - g_object_unref (l->data); - } - g_list_free (contacts); - - return store; + return g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE, + "contact-list", list_iface, + "show-groups", show_groups, + NULL); } EmpathyContactList * @@ -403,6 +457,8 @@ empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store, /* Restore to original setting. */ priv->show_active = show_active; + + g_object_notify (G_OBJECT (store), "show-offline"); } gboolean @@ -436,6 +492,54 @@ empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store, (GtkTreeModelForeachFunc) contact_list_store_update_list_mode_foreach, store); + + g_object_notify (G_OBJECT (store), "show-avatars"); +} + +gboolean +empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store) +{ + EmpathyContactListStorePriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE); + + priv = GET_PRIV (store); + + return priv->show_groups; +} + +void +empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store, + gboolean show_groups) +{ + EmpathyContactListStorePriv *priv; + GList *contacts, *l; + + g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store)); + + priv = GET_PRIV (store); + + if (priv->show_groups == show_groups) { + return; + } + + priv->show_groups = show_groups; + + /* Remove all contacts and add them back, not optimized but that's the + * easy way :) */ + gtk_tree_store_clear (GTK_TREE_STORE (store)); + contacts = empathy_contact_list_get_members (priv->list); + for (l = contacts; l; l = l->next) { + contact_list_store_members_changed_cb (priv->list, l->data, + NULL, 0, NULL, + TRUE, + store); + + g_object_unref (l->data); + } + g_list_free (contacts); + + g_object_notify (G_OBJECT (store), "show-groups"); } gboolean @@ -469,6 +573,8 @@ empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store, (GtkTreeModelForeachFunc) contact_list_store_update_list_mode_foreach, store); + + g_object_notify (G_OBJECT (store), "is-compact"); } EmpathyContactListStoreSort @@ -508,6 +614,8 @@ empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore *stor GTK_SORT_ASCENDING); break; } + + g_object_notify (G_OBJECT (store), "sort-criterium"); } gboolean @@ -767,7 +875,7 @@ contact_list_store_add_contact (EmpathyContactListStore *store, { EmpathyContactListStorePriv *priv; GtkTreeIter iter; - GList *groups, *l; + GList *groups = NULL, *l; priv = GET_PRIV (store); @@ -775,7 +883,9 @@ contact_list_store_add_contact (EmpathyContactListStore *store, return; } - groups = empathy_contact_list_get_groups (priv->list, contact); + if (priv->show_groups) { + groups = empathy_contact_list_get_groups (priv->list, contact); + } /* If no groups just add it at the top level. */ if (!groups) { diff --git a/libempathy-gtk/empathy-contact-list-store.h b/libempathy-gtk/empathy-contact-list-store.h index 214f5be6..0dd6e43a 100644 --- a/libempathy-gtk/empathy-contact-list-store.h +++ b/libempathy-gtk/empathy-contact-list-store.h @@ -73,7 +73,8 @@ struct _EmpathyContactListStoreClass { }; GType empathy_contact_list_store_get_type (void) G_GNUC_CONST; -EmpathyContactListStore * empathy_contact_list_store_new (EmpathyContactList *list_iface); +EmpathyContactListStore * empathy_contact_list_store_new (EmpathyContactList *list_iface, + gboolean show_groups); EmpathyContactList * empathy_contact_list_store_get_list_iface (EmpathyContactListStore *store); gboolean empathy_contact_list_store_get_show_offline (EmpathyContactListStore *store); void empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store, @@ -81,6 +82,9 @@ void empathy_contact_list_store_set_show_offline (Empath gboolean empathy_contact_list_store_get_show_avatars (EmpathyContactListStore *store); void empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store, gboolean show_avatars); +gboolean empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store); +void empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store, + gboolean show_groups); gboolean empathy_contact_list_store_get_is_compact (EmpathyContactListStore *store); void empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store, gboolean is_compact); diff --git a/libempathy-gtk/empathy-group-chat.c b/libempathy-gtk/empathy-group-chat.c index 534f66c2..8f361237 100644 --- a/libempathy-gtk/empathy-group-chat.c +++ b/libempathy-gtk/empathy-group-chat.c @@ -526,7 +526,7 @@ group_chat_set_tp_chat (EmpathyChat *chat, } /* Create contact list */ - priv->store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat)); + priv->store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat), TRUE); priv->view = empathy_contact_list_view_new (priv->store, EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT | EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL | diff --git a/libempathy-gtk/empathy-main-window.c b/libempathy-gtk/empathy-main-window.c index d0353419..03f11e58 100644 --- a/libempathy-gtk/empathy-main-window.c +++ b/libempathy-gtk/empathy-main-window.c @@ -284,7 +284,7 @@ empathy_main_window_show (void) empathy_status_presets_get_all (); list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ()); - window->list_store = empathy_contact_list_store_new (list_iface); + window->list_store = empathy_contact_list_store_new (list_iface, TRUE); window->list_view = empathy_contact_list_view_new (window->list_store, EMPATHY_CONTACT_LIST_FEATURE_ALL); g_object_unref (list_iface); diff --git a/libempathy/empathy-contact-list.c b/libempathy/empathy-contact-list.c index 5164ccf1..510e4195 100644 --- a/libempathy/empathy-contact-list.c +++ b/libempathy/empathy-contact-list.c @@ -41,6 +41,8 @@ empathy_contact_list_get_type (void) type = g_type_register_static (G_TYPE_INTERFACE, "EmpathyContactList", &type_info, 0); + + g_type_interface_add_prerequisite (type, G_TYPE_OBJECT); } return type; diff --git a/megaphone/src/megaphone-applet.c b/megaphone/src/megaphone-applet.c index 17ae2c50..5c499ac2 100644 --- a/megaphone/src/megaphone-applet.c +++ b/megaphone/src/megaphone-applet.c @@ -358,7 +358,7 @@ megaphone_applet_show_preferences (MegaphoneApplet *applet) /* Show all contacts, even offline and sort alphabetically */ contact_manager = empathy_contact_manager_new (); - contact_store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (contact_manager)); + contact_store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (contact_manager), TRUE); g_object_set (contact_store, "is-compact", TRUE, "show-avatars", TRUE, diff --git a/python/pyempathygtk/pyempathygtk.defs b/python/pyempathygtk/pyempathygtk.defs index e3a9b637..f168800d 100644 --- a/python/pyempathygtk/pyempathygtk.defs +++ b/python/pyempathygtk/pyempathygtk.defs @@ -199,8 +199,10 @@ (c-name "EmpathyContactListFeatures") (gtype-id "EMPATHY_TYPE_CONTACT_LIST_FEATURES") (values - '("groups-show" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SHOW") - '("groups-modify" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_MODIFY") + '("none" "EMPATHY_CONTACT_LIST_FEATURE_NONE") + '("groups-save" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE") + '("groups-rename" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME") + '("groups-remove" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE") '("contact-chat" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT") '("contact-call" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL") '("contact-log" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG") @@ -209,6 +211,9 @@ '("contact-edit" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT") '("contact-info" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO") '("contact-remove" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE") + '("contact-drop" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP") + '("contact-drag" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG") + '("all" "EMPATHY_CONTACT_LIST_FEATURE_ALL") ) ) @@ -1047,6 +1052,9 @@ (of-object "EmpathyContactList") (c-name "empathy_contact_list_store_new") (return-type "EmpathyContactListStore*") + (parameters + '("gboolean" "show_groups") + ) ) (define-method get_list_iface @@ -1085,6 +1093,21 @@ ) ) +(define-method get_show_groups + (of-object "EmpathyContactListStore") + (c-name "empathy_contact_list_store_get_show_groups") + (return-type "gboolean") +) + +(define-method set_show_groups + (of-object "EmpathyContactListStore") + (c-name "empathy_contact_list_store_set_show_groups") + (return-type "none") + (parameters + '("gboolean" "show_groups") + ) +) + (define-method get_is_compact (of-object "EmpathyContactListStore") (c-name "empathy_contact_list_store_get_is_compact")