diff options
author | Laurent Contzen <lcontzen@gmail.com> | 2012-08-07 17:01:13 +0800 |
---|---|---|
committer | Laurent Contzen <lcontzen@gmail.com> | 2012-08-07 21:59:22 +0800 |
commit | 5ff0b2f71b6516b399deb732bfe0124e32a8a7bf (patch) | |
tree | 9b57891d1e138ba1011f4076bcdf6b83a2312faf | |
parent | e50bbed1c0ea00a62e22bd2ace2427fef4d65ada (diff) | |
download | gsoc2013-empathy-5ff0b2f71b6516b399deb732bfe0124e32a8a7bf.tar gsoc2013-empathy-5ff0b2f71b6516b399deb732bfe0124e32a8a7bf.tar.gz gsoc2013-empathy-5ff0b2f71b6516b399deb732bfe0124e32a8a7bf.tar.bz2 gsoc2013-empathy-5ff0b2f71b6516b399deb732bfe0124e32a8a7bf.tar.lz gsoc2013-empathy-5ff0b2f71b6516b399deb732bfe0124e32a8a7bf.tar.xz gsoc2013-empathy-5ff0b2f71b6516b399deb732bfe0124e32a8a7bf.tar.zst gsoc2013-empathy-5ff0b2f71b6516b399deb732bfe0124e32a8a7bf.zip |
Added top_group_members list in model, view relying on it
empathy-roster-model: no longer emits top-individuals and favourites-changed signals
empathy-roster-model-manager: new top_group_members GList with filling function. _contact_in_top uses top_group_members. top_group_members is modified when top-individuals and
favourites-changed signals are caught.
empathy-roster-view: no longer catches top-individuals or favourites-changed signals from the model
-rw-r--r-- | libempathy-gtk/empathy-roster-model-manager.c | 125 | ||||
-rw-r--r-- | libempathy-gtk/empathy-roster-model.c | 34 | ||||
-rw-r--r-- | libempathy-gtk/empathy-roster-model.h | 7 | ||||
-rw-r--r-- | libempathy-gtk/empathy-roster-view.c | 142 |
4 files changed, 110 insertions, 198 deletions
diff --git a/libempathy-gtk/empathy-roster-model-manager.c b/libempathy-gtk/empathy-roster-model-manager.c index c455c869b..0668db1d8 100644 --- a/libempathy-gtk/empathy-roster-model-manager.c +++ b/libempathy-gtk/empathy-roster-model-manager.c @@ -56,6 +56,8 @@ static guint signals[LAST_SIGNAL]; struct _EmpathyRosterModelManagerPriv { EmpathyIndividualManager *manager; + /* FolksIndividual (borrowed) */ + GList *top_group_members; }; static gboolean @@ -80,14 +82,41 @@ is_xmpp_local_contact (FolksIndividual *individual) } static gboolean -contact_is_favourite (EmpathyRosterContact *contact) +individual_in_top_group_members (EmpathyRosterModelManager *self, + FolksIndividual *individual) { - FolksIndividual *individual; + return (g_list_find (self->priv->top_group_members, individual) != NULL); +} - individual = empathy_roster_contact_get_individual (contact); +static gboolean +individual_should_be_in_top_group_members (EmpathyRosterModelManager *self, + FolksIndividual *individual) +{ + GList *tops; + + tops = empathy_individual_manager_get_top_individuals (self->priv->manager); + + return (folks_favourite_details_get_is_favourite ( + FOLKS_FAVOURITE_DETAILS (individual)) || + g_list_find (tops, individual) != NULL); +} + +static void +populate_model (EmpathyRosterModelManager *self) +{ + GList *individuals, *l; + + individuals = empathy_individual_manager_get_members (self->priv->manager); - return folks_favourite_details_get_is_favourite ( - FOLKS_FAVOURITE_DETAILS (individual)); + for (l = individuals; l != NULL; l = g_list_next (l)) + { + if (individual_should_be_in_top_group_members (self, l->data)) + self->priv->top_group_members = g_list_prepend ( + self->priv->top_group_members, l->data); + + empathy_roster_model_fire_individual_added (EMPATHY_ROSTER_MODEL (self), + l->data); + } } static void @@ -102,12 +131,22 @@ members_changed_cb (EmpathyIndividualManager *manager, for (l = added; l != NULL; l = g_list_next (l)) { + if (individual_should_be_in_top_group_members (self, l->data) && + !individual_in_top_group_members (self, l->data)) + self->priv->top_group_members = g_list_prepend ( + self->priv->top_group_members, l->data); + empathy_roster_model_fire_individual_added (EMPATHY_ROSTER_MODEL (self), l->data); } for (l = removed; l != NULL; l = g_list_next (l)) { + if (individual_in_top_group_members (self, l->data) && + !individual_should_be_in_top_group_members (self, l->data)) + self->priv->top_group_members = g_list_remove ( + self->priv->top_group_members, l->data); + empathy_roster_model_fire_individual_removed (EMPATHY_ROSTER_MODEL (self), l->data); } @@ -129,8 +168,34 @@ top_individuals_changed_cb (EmpathyIndividualManager *manager, GParamSpec *spec, EmpathyRosterModelManager *self) { - empathy_roster_model_fire_top_individuals_changed ( - EMPATHY_ROSTER_MODEL (self)); + GList *tops, *l; + + tops = empathy_individual_manager_get_top_individuals (self->priv->manager); + + for (l = tops; l != NULL; l = g_list_next (l)) + { + if (!individual_in_top_group_members (self, l->data)) + { + self->priv->top_group_members = g_list_prepend ( + self->priv->top_group_members, l->data); + + empathy_roster_model_fire_groups_changed ( + EMPATHY_ROSTER_MODEL (self), l->data, + EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP, TRUE); + } + } + for (l = self->priv->top_group_members; l != NULL; l = g_list_next (l)) + { + if (!individual_should_be_in_top_group_members (self, l->data)) + { + self->priv->top_group_members = g_list_remove ( + self->priv->top_group_members, l->data); + + empathy_roster_model_fire_groups_changed ( + EMPATHY_ROSTER_MODEL (self), l->data, + EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP, FALSE); + } + } } static void @@ -139,8 +204,25 @@ favourites_changed_cb (EmpathyIndividualManager *manager, gboolean favourite, EmpathyRosterModelManager *self) { - empathy_roster_model_fire_favourites_changed (EMPATHY_ROSTER_MODEL (self), - individual, favourite); + if (favourite && !individual_in_top_group_members (self, individual)) + { + self->priv->top_group_members = g_list_prepend ( + self->priv->top_group_members, individual); + + empathy_roster_model_fire_groups_changed ( + EMPATHY_ROSTER_MODEL (self), individual, + EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP, favourite); + } + else if (!favourite && + !individual_should_be_in_top_group_members (self, individual)) + { + self->priv->top_group_members = g_list_remove ( + self->priv->top_group_members, individual); + + empathy_roster_model_fire_groups_changed ( + EMPATHY_ROSTER_MODEL (self), individual, + EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP, favourite); + } } static void @@ -194,6 +276,8 @@ empathy_roster_model_manager_constructed (GObject *object) g_assert (EMPATHY_IS_INDIVIDUAL_MANAGER (self->priv->manager)); + populate_model (self); + tp_g_signal_connect_object (self->priv->manager, "members-changed", G_CALLBACK (members_changed_cb), self, 0); tp_g_signal_connect_object (self->priv->manager, "groups-changed", @@ -220,10 +304,12 @@ empathy_roster_model_manager_dispose (GObject *object) static void empathy_roster_model_manager_finalize (GObject *object) { - //EmpathyRosterModelManager *self = EMPATHY_ROSTER_MODEL_MANAGER (object); + EmpathyRosterModelManager *self = EMPATHY_ROSTER_MODEL_MANAGER (object); void (*chain_up) (GObject *) = ((GObjectClass *) empathy_roster_model_manager_parent_class)->finalize; + g_list_free (self->priv->top_group_members); + if (chain_up != NULL) chain_up (object); } @@ -255,6 +341,8 @@ empathy_roster_model_manager_init (EmpathyRosterModelManager *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ROSTER_MODEL_MANAGER, EmpathyRosterModelManagerPriv); + + self->priv->top_group_members = NULL; } EmpathyRosterModelManager * @@ -290,6 +378,11 @@ empathy_roster_model_manager_get_groups_for_individual ( return groups_list; } + if (individual_in_top_group_members (EMPATHY_ROSTER_MODEL_MANAGER (model), + individual)) + groups_list = g_list_prepend (groups_list, + EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP); + groups_set = folks_group_details_get_groups ( FOLKS_GROUP_DETAILS (individual)); if (gee_collection_get_size (GEE_COLLECTION (groups_set)) > 0) @@ -319,19 +412,13 @@ empathy_roster_model_manager_contact_in_top (EmpathyRosterModel *model, EmpathyRosterContact *contact) { FolksIndividual *individual; - GList *tops; + EmpathyRosterModelManager *self; - if (contact_is_favourite (contact)) - return TRUE; + self = EMPATHY_ROSTER_MODEL_MANAGER (model); individual = empathy_roster_contact_get_individual (contact); - tops = empathy_roster_model_get_top_individuals (model); - - if (g_list_index (tops, individual) != -1) - return TRUE; - - return FALSE; + return individual_in_top_group_members (self, individual); } static void diff --git a/libempathy-gtk/empathy-roster-model.c b/libempathy-gtk/empathy-roster-model.c index 3d2bef627..f1e596029 100644 --- a/libempathy-gtk/empathy-roster-model.c +++ b/libempathy-gtk/empathy-roster-model.c @@ -28,8 +28,6 @@ enum SIG_INDIVIDUAL_ADDED, SIG_INDIVIDUAL_REMOVED, SIG_GROUPS_CHANGED, - SIG_TOP_INDIVIDUALS_CHANGED, - SIG_FAVOURITES_CHANGED, LAST_SIGNAL }; @@ -63,22 +61,6 @@ empathy_roster_model_default_init (EmpathyRosterModelInterface *iface) FOLKS_TYPE_INDIVIDUAL, G_TYPE_STRING, G_TYPE_BOOLEAN); - - signals[SIG_TOP_INDIVIDUALS_CHANGED] = - g_signal_new ("top-individuals-changed", - EMPATHY_TYPE_ROSTER_MODEL, - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 0); - - signals[SIG_FAVOURITES_CHANGED] = - g_signal_new ("favourites-changed", - EMPATHY_TYPE_ROSTER_MODEL, - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 2, - FOLKS_TYPE_INDIVIDUAL, - G_TYPE_BOOLEAN); } /***** Restricted *****/ @@ -107,22 +89,6 @@ empathy_roster_model_fire_groups_changed (EmpathyRosterModel *self, is_member); } -void -empathy_roster_model_fire_top_individuals_changed (EmpathyRosterModel *self) -{ - g_signal_emit (self, signals[SIG_TOP_INDIVIDUALS_CHANGED], 0); -} - -void -empathy_roster_model_fire_favourites_changed (EmpathyRosterModel *self, - FolksIndividual *individual, - gboolean favourite) -{ - g_signal_emit (self, signals[SIG_FAVOURITES_CHANGED], 0, individual, - favourite); -} - - /***** Public *****/ /** diff --git a/libempathy-gtk/empathy-roster-model.h b/libempathy-gtk/empathy-roster-model.h index e6f39f808..dae23390e 100644 --- a/libempathy-gtk/empathy-roster-model.h +++ b/libempathy-gtk/empathy-roster-model.h @@ -79,13 +79,6 @@ void empathy_roster_model_fire_groups_changed (EmpathyRosterModel *self, const gchar *group, gboolean is_member); -void empathy_roster_model_fire_top_individuals_changed ( - EmpathyRosterModel *self); - -void empathy_roster_model_fire_favourites_changed (EmpathyRosterModel *self, - FolksIndividual *individual, - gboolean favourite); - /* Public API */ GList * empathy_roster_model_get_individuals (EmpathyRosterModel *self); diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c index e9b44af37..de14b5d97 100644 --- a/libempathy-gtk/empathy-roster-view.c +++ b/libempathy-gtk/empathy-roster-view.c @@ -304,16 +304,6 @@ individual_added (EmpathyRosterView *self, else { GList *groups, *l; - GList *tops; - - tops = empathy_roster_model_get_top_individuals (self->priv->model); - - if (folks_favourite_details_get_is_favourite ( - FOLKS_FAVOURITE_DETAILS (individual)) || - g_list_index (tops, individual) != -1) - { - add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP); - } groups = empathy_roster_model_get_groups_for_individual (self->priv->model, individual); @@ -833,27 +823,6 @@ filter_list (GtkWidget *child, g_return_val_if_reached (FALSE); } -/* @list: GList of EmpathyRosterContact - * - * Returns: %TRUE if @list contains an EmpathyRosterContact associated with - * @individual */ -static gboolean -individual_in_list (FolksIndividual *individual, - GList *list) -{ - GList *l; - - for (l = list; l != NULL; l = g_list_next (l)) - { - EmpathyRosterContact *contact = l->data; - - if (empathy_roster_contact_get_individual (contact) == individual) - return TRUE; - } - - return FALSE; -} - static void populate_view (EmpathyRosterView *self) { @@ -906,69 +875,6 @@ remove_from_group (EmpathyRosterView *self, } static void -update_top_contacts (EmpathyRosterView *self) -{ - GList *tops, *l; - GList *to_add = NULL, *to_remove = NULL; - EmpathyRosterGroup *group; - - if (!self->priv->show_groups) - { - egg_list_box_resort (EGG_LIST_BOX (self)); - return; - } - - tops = empathy_roster_model_get_top_individuals (self->priv->model); - - group = g_hash_table_lookup (self->priv->roster_groups, - EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP); - if (group == NULL) - { - to_add = g_list_copy (tops); - } - else - { - GList *contacts; - - contacts = empathy_roster_group_get_widgets (group); - - /* Check which EmpathyRosterContact have to be removed */ - for (l = contacts; l != NULL; l = g_list_next (l)) - { - EmpathyRosterContact *contact = l->data; - FolksIndividual *individual; - - if (empathy_roster_model_contact_in_top (self->priv->model, - contact)) - continue; - - individual = empathy_roster_contact_get_individual (contact); - - if (g_list_find (tops, individual) == NULL) - to_remove = g_list_prepend (to_remove, individual); - } - - /* Check which EmpathyRosterContact have to be added */ - for (l = tops; l != NULL; l = g_list_next (l)) - { - FolksIndividual *individual = l->data; - - if (!individual_in_list (individual, contacts)) - to_add = g_list_prepend (to_add, individual); - } - } - - for (l = to_add; l != NULL; l = g_list_next (l)) - add_to_group (self, l->data, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP); - - for (l = to_remove; l != NULL; l = g_list_next (l)) - remove_from_group (self, l->data, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP); - - g_list_free (to_add); - g_list_free (to_remove); -} - -static void groups_changed_cb (EmpathyRosterModel *model, FolksIndividual *individual, const gchar *group, @@ -976,7 +882,10 @@ groups_changed_cb (EmpathyRosterModel *model, EmpathyRosterView *self) { if (!self->priv->show_groups) - return; + { + egg_list_box_resort (EGG_LIST_BOX (self)); + return; + } if (is_member) { @@ -989,45 +898,6 @@ groups_changed_cb (EmpathyRosterModel *model, } static void -top_individuals_changed_cb (EmpathyRosterModel *model, - EmpathyRosterView *self) -{ - update_top_contacts (self); -} - -static void -favourites_changed_cb (EmpathyRosterModel *model, - FolksIndividual *individual, - gboolean favourite, - EmpathyRosterView *self) -{ - GHashTable *contacts; - - contacts = g_hash_table_lookup (self->priv->roster_contacts, individual); - if (contacts == NULL) - return; - - if (self->priv->show_groups) - { - if (favourite) - add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP); - else - remove_from_group (self, individual, - EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP); - } - else - { - GtkWidget *contact; - - contact = g_hash_table_lookup (contacts, NO_GROUP); - if (contact == NULL) - return; - - egg_list_box_child_changed (EGG_LIST_BOX (self), contact); - } -} - -static void empathy_roster_view_constructed (GObject *object) { EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object); @@ -1047,10 +917,6 @@ empathy_roster_view_constructed (GObject *object) G_CALLBACK (individual_removed_cb), self, 0); tp_g_signal_connect_object (self->priv->model, "groups-changed", G_CALLBACK (groups_changed_cb), self, 0); - tp_g_signal_connect_object (self->priv->model, "top-individuals-changed", - G_CALLBACK (top_individuals_changed_cb), self, 0); - tp_g_signal_connect_object (self->priv->model, "favourites-changed", - G_CALLBACK (favourites_changed_cb), self, 0); egg_list_box_set_sort_func (EGG_LIST_BOX (self), roster_view_sort, self, NULL); |