3 #include "empathy-roster-view.h"
5 #include <glib/gi18n-lib.h>
7 #include <libempathy-gtk/empathy-roster-contact.h>
8 #include <libempathy-gtk/empathy-roster-group.h>
9 #include <libempathy-gtk/empathy-ui-utils.h>
11 G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, EGG_TYPE_LIST_BOX)
24 SIG_INDIVIDUAL_ACTIVATED,
25 SIG_POPUP_INDIVIDUAL_MENU,
29 static guint signals[LAST_SIGNAL];
31 #define NO_GROUP "X-no-group"
32 #define UNGROUPPED _("Ungroupped")
33 #define TOP_GROUP _("Most Used")
35 struct _EmpathyRosterViewPriv
37 EmpathyIndividualManager *manager;
39 /* FolksIndividual (borrowed) -> GHashTable (
40 * (gchar * group_name) -> EmpathyRosterContact (borrowed))
42 * When not using groups, this hash just have one element mapped
43 * from the special NO_GROUP key. We could use it as a set but
44 * I prefer to stay coherent in the way this hash is managed.
46 GHashTable *roster_contacts;
47 /* (gchar *group_name) -> EmpathyRosterGroup (borrowed) */
48 GHashTable *roster_groups;
49 /* Hash of the EmpathyRosterContact currently displayed */
50 GHashTable *displayed_contacts;
52 gboolean show_offline;
56 EmpathyLiveSearch *search;
58 EmpathyRosterViewIndividualTooltipCb individual_tooltip_cb;
59 gpointer individual_tooltip_data;
63 empathy_roster_view_get_property (GObject *object,
68 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
73 g_value_set_object (value, self->priv->manager);
75 case PROP_SHOW_OFFLINE:
76 g_value_set_boolean (value, self->priv->show_offline);
78 case PROP_SHOW_GROUPS:
79 g_value_set_boolean (value, self->priv->show_groups);
82 g_value_set_boolean (value, self->priv->empty);
85 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
91 empathy_roster_view_set_property (GObject *object,
96 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
101 g_assert (self->priv->manager == NULL); /* construct only */
102 self->priv->manager = g_value_dup_object (value);
104 case PROP_SHOW_OFFLINE:
105 empathy_roster_view_show_offline (self, g_value_get_boolean (value));
107 case PROP_SHOW_GROUPS:
108 empathy_roster_view_show_groups (self, g_value_get_boolean (value));
111 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
117 roster_contact_changed_cb (GtkWidget *child,
119 EmpathyRosterView *self)
121 egg_list_box_child_changed (EGG_LIST_BOX (self), child);
125 add_roster_contact (EmpathyRosterView *self,
126 FolksIndividual *individual,
131 contact = empathy_roster_contact_new (individual, group);
133 /* Need to refilter if online is changed */
134 g_signal_connect (contact, "notify::online",
135 G_CALLBACK (roster_contact_changed_cb), self);
137 /* Need to resort if alias is changed */
138 g_signal_connect (contact, "notify::alias",
139 G_CALLBACK (roster_contact_changed_cb), self);
141 gtk_widget_show (contact);
142 gtk_container_add (GTK_CONTAINER (self), contact);
148 group_expanded_cb (EmpathyRosterGroup *group,
150 EmpathyRosterView *self)
154 widgets = empathy_roster_group_get_widgets (group);
155 for (l = widgets; l != NULL; l = g_list_next (l))
157 egg_list_box_child_changed (EGG_LIST_BOX (self), l->data);
160 g_list_free (widgets);
163 static EmpathyRosterGroup *
164 lookup_roster_group (EmpathyRosterView *self,
167 return g_hash_table_lookup (self->priv->roster_groups, group);
171 ensure_roster_group (EmpathyRosterView *self,
174 GtkWidget *roster_group;
176 roster_group = (GtkWidget *) lookup_roster_group (self, group);
177 if (roster_group != NULL)
180 roster_group = empathy_roster_group_new (group);
182 g_signal_connect (roster_group, "notify::expanded",
183 G_CALLBACK (group_expanded_cb), self);
185 gtk_widget_show (roster_group);
186 gtk_container_add (GTK_CONTAINER (self), roster_group);
188 g_hash_table_insert (self->priv->roster_groups, g_strdup (group),
193 add_to_group (EmpathyRosterView *self,
194 FolksIndividual *individual,
198 GHashTable *contacts;
200 contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
201 if (contacts == NULL)
204 if (tp_strdiff (group, NO_GROUP))
205 ensure_roster_group (self, group);
207 contact = add_roster_contact (self, individual, group);
208 g_hash_table_insert (contacts, g_strdup (group), contact);
212 individual_added (EmpathyRosterView *self,
213 FolksIndividual *individual)
215 GHashTable *contacts;
217 contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
218 if (contacts != NULL)
221 contacts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
223 g_hash_table_insert (self->priv->roster_contacts, individual, contacts);
225 if (!self->priv->show_groups)
227 add_to_group (self, individual, NO_GROUP);
233 groups = folks_group_details_get_groups (
234 FOLKS_GROUP_DETAILS (individual));
236 if (gee_collection_get_size (GEE_COLLECTION (groups)) > 0)
238 GeeIterator *iter = gee_iterable_iterator (GEE_ITERABLE (groups));
240 while (iter != NULL && gee_iterator_next (iter))
242 gchar *group = gee_iterator_get (iter);
244 add_to_group (self, individual, group);
249 g_clear_object (&iter);
253 /* No group, adds to Ungroupped */
254 add_to_group (self, individual, UNGROUPPED);
260 update_group_widgets_count (EmpathyRosterView *self,
261 EmpathyRosterGroup *group,
262 EmpathyRosterContact *contact,
267 if (empathy_roster_group_add_widget (group, GTK_WIDGET (contact)) == 1)
269 egg_list_box_child_changed (EGG_LIST_BOX (self),
275 if (empathy_roster_group_remove_widget (group, GTK_WIDGET (contact)) == 0)
277 egg_list_box_child_changed (EGG_LIST_BOX (self),
284 individual_removed (EmpathyRosterView *self,
285 FolksIndividual *individual)
287 GHashTable *contacts;
291 contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
292 if (contacts == NULL)
295 g_hash_table_iter_init (&iter, contacts);
296 while (g_hash_table_iter_next (&iter, &key, &value))
298 const gchar *group_name = key;
299 GtkWidget *contact = value;
300 EmpathyRosterGroup *group;
302 group = lookup_roster_group (self, group_name);
305 update_group_widgets_count (self, group,
306 EMPATHY_ROSTER_CONTACT (contact), FALSE);
309 gtk_container_remove (GTK_CONTAINER (self), contact);
312 g_hash_table_remove (self->priv->roster_contacts, individual);
316 members_changed_cb (EmpathyIndividualManager *manager,
317 const gchar *message,
320 TpChannelGroupChangeReason reason,
321 EmpathyRosterView *self)
325 for (l = added; l != NULL; l = g_list_next (l))
327 FolksIndividual *individual = l->data;
329 individual_added (self, individual);
332 for (l = removed; l != NULL; l = g_list_next (l))
334 FolksIndividual *individual = l->data;
336 individual_removed (self, individual);
341 compare_roster_contacts_by_alias (EmpathyRosterContact *a,
342 EmpathyRosterContact *b)
344 FolksIndividual *ind_a, *ind_b;
345 const gchar *alias_a, *alias_b;
347 ind_a = empathy_roster_contact_get_individual (a);
348 ind_b = empathy_roster_contact_get_individual (b);
350 alias_a = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_a));
351 alias_b = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_b));
353 return g_ascii_strcasecmp (alias_a, alias_b);
357 compare_individual_top_position (EmpathyRosterView *self,
358 EmpathyRosterContact *a,
359 EmpathyRosterContact *b)
361 FolksIndividual *ind_a, *ind_b;
363 gint index_a, index_b;
365 ind_a = empathy_roster_contact_get_individual (a);
366 ind_b = empathy_roster_contact_get_individual (b);
368 tops = empathy_individual_manager_get_top_individuals (self->priv->manager);
370 index_a = g_list_index (tops, ind_a);
371 index_b = g_list_index (tops, ind_b);
373 if (index_a == index_b)
382 return index_a - index_b;
386 compare_roster_contacts_no_group (EmpathyRosterView *self,
387 EmpathyRosterContact *a,
388 EmpathyRosterContact *b)
392 top = compare_individual_top_position (self, a, b);
396 return compare_roster_contacts_by_alias (a, b);
400 compare_group_names (const gchar *group_a,
401 const gchar *group_b)
403 if (!tp_strdiff (group_a, TOP_GROUP))
406 if (!tp_strdiff (group_b, TOP_GROUP))
409 return g_ascii_strcasecmp (group_a, group_b);
413 compare_roster_contacts_with_groups (EmpathyRosterView *self,
414 EmpathyRosterContact *a,
415 EmpathyRosterContact *b)
417 const gchar *group_a, *group_b;
419 group_a = empathy_roster_contact_get_group (a);
420 group_b = empathy_roster_contact_get_group (b);
422 if (!tp_strdiff (group_a, group_b))
423 /* Same group, compare the contacts */
424 return compare_roster_contacts_by_alias (a, b);
427 return compare_group_names (group_a, group_b);
431 compare_roster_contacts (EmpathyRosterView *self,
432 EmpathyRosterContact *a,
433 EmpathyRosterContact *b)
435 if (!self->priv->show_groups)
436 return compare_roster_contacts_no_group (self, a, b);
438 return compare_roster_contacts_with_groups (self, a, b);
442 compare_roster_groups (EmpathyRosterGroup *a,
443 EmpathyRosterGroup *b)
445 const gchar *name_a, *name_b;
447 name_a = empathy_roster_group_get_name (a);
448 name_b = empathy_roster_group_get_name (b);
450 return compare_group_names (name_a, name_b);
454 compare_contact_group (EmpathyRosterContact *contact,
455 EmpathyRosterGroup *group)
457 const char *contact_group, *group_name;
459 contact_group = empathy_roster_contact_get_group (contact);
460 group_name = empathy_roster_group_get_name (group);
462 if (!tp_strdiff (contact_group, group_name))
463 /* @contact is in @group, @group has to be displayed first */
466 /* @contact is in a different group, sort by group name */
467 return compare_group_names (contact_group, group_name);
471 roster_view_sort (gconstpointer a,
475 EmpathyRosterView *self = user_data;
477 if (EMPATHY_IS_ROSTER_CONTACT (a) && EMPATHY_IS_ROSTER_CONTACT (b))
478 return compare_roster_contacts (self, EMPATHY_ROSTER_CONTACT (a),
479 EMPATHY_ROSTER_CONTACT (b));
480 else if (EMPATHY_IS_ROSTER_GROUP (a) && EMPATHY_IS_ROSTER_GROUP (b))
481 return compare_roster_groups (EMPATHY_ROSTER_GROUP (a),
482 EMPATHY_ROSTER_GROUP (b));
483 else if (EMPATHY_IS_ROSTER_CONTACT (a) && EMPATHY_IS_ROSTER_GROUP (b))
484 return compare_contact_group (EMPATHY_ROSTER_CONTACT (a),
485 EMPATHY_ROSTER_GROUP (b));
486 else if (EMPATHY_IS_ROSTER_GROUP (a) && EMPATHY_IS_ROSTER_CONTACT (b))
487 return -1 * compare_contact_group (EMPATHY_ROSTER_CONTACT (b),
488 EMPATHY_ROSTER_GROUP (a));
490 g_return_val_if_reached (0);
494 update_separator (GtkWidget **separator,
501 /* No separator before the first row */
502 g_clear_object (separator);
506 if (*separator != NULL)
509 *separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
510 g_object_ref_sink (*separator);
514 is_searching (EmpathyRosterView *self)
516 if (self->priv->search == NULL)
519 return gtk_widget_get_visible (GTK_WIDGET (self->priv->search));
523 update_empty (EmpathyRosterView *self,
526 if (self->priv->empty == empty)
529 self->priv->empty = empty;
530 g_object_notify (G_OBJECT (self), "empty");
534 add_to_displayed (EmpathyRosterView *self,
535 EmpathyRosterContact *contact)
537 g_hash_table_add (self->priv->displayed_contacts, contact);
538 update_empty (self, FALSE);
542 remove_from_displayed (EmpathyRosterView *self,
543 EmpathyRosterContact *contact)
545 g_hash_table_remove (self->priv->displayed_contacts, contact);
547 if (g_hash_table_size (self->priv->displayed_contacts) == 0)
548 update_empty (self, TRUE);
552 filter_contact (EmpathyRosterView *self,
553 EmpathyRosterContact *contact)
557 if (is_searching (self))
559 FolksIndividual *individual;
561 individual = empathy_roster_contact_get_individual (contact);
563 displayed = empathy_individual_match_string (individual,
564 empathy_live_search_get_text (self->priv->search),
565 empathy_live_search_get_words (self->priv->search));
569 if (self->priv->show_offline)
575 displayed = empathy_roster_contact_is_online (contact);
579 if (self->priv->show_groups)
581 const gchar *group_name;
582 EmpathyRosterGroup *group;
584 group_name = empathy_roster_contact_get_group (contact);
585 group = lookup_roster_group (self, group_name);
589 update_group_widgets_count (self, group, contact, displayed);
591 /* When searching, always display even if the group is closed */
592 if (!is_searching (self) &&
593 !gtk_expander_get_expanded (GTK_EXPANDER (group)))
600 add_to_displayed (self, contact);
604 remove_from_displayed (self, contact);
611 filter_group (EmpathyRosterView *self,
612 EmpathyRosterGroup *group)
614 return empathy_roster_group_get_widgets_count (group);
618 filter_list (GtkWidget *child,
621 EmpathyRosterView *self = user_data;
623 if (EMPATHY_IS_ROSTER_CONTACT (child))
624 return filter_contact (self, EMPATHY_ROSTER_CONTACT (child));
626 else if (EMPATHY_IS_ROSTER_GROUP (child))
627 return filter_group (self, EMPATHY_ROSTER_GROUP (child));
629 g_return_val_if_reached (FALSE);
632 /* @list: GList of EmpathyRosterContact
634 * Returns: %TRUE if @list contains an EmpathyRosterContact associated with
637 individual_in_list (FolksIndividual *individual,
642 for (l = list; l != NULL; l = g_list_next (l))
644 EmpathyRosterContact *contact = l->data;
646 if (empathy_roster_contact_get_individual (contact) == individual)
654 populate_view (EmpathyRosterView *self)
656 GList *individuals, *l;
658 individuals = empathy_individual_manager_get_members (self->priv->manager);
659 for (l = individuals; l != NULL; l = g_list_next (l))
661 FolksIndividual *individual = l->data;
663 individual_added (self, individual);
666 g_list_free (individuals);
670 remove_from_group (EmpathyRosterView *self,
671 FolksIndividual *individual,
674 GHashTable *contacts;
676 EmpathyRosterGroup *roster_group;
678 contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
679 if (contacts == NULL)
682 contact = g_hash_table_lookup (contacts, group);
686 g_hash_table_remove (contacts, group);
688 if (g_hash_table_size (contacts) == 0)
690 add_to_group (self, individual, UNGROUPPED);
693 roster_group = lookup_roster_group (self, group);
695 if (roster_group != NULL)
697 update_group_widgets_count (self, roster_group,
698 EMPATHY_ROSTER_CONTACT (contact), FALSE);
701 gtk_container_remove (GTK_CONTAINER (self), contact);
705 update_top_contacts (EmpathyRosterView *self)
708 GList *to_add = NULL, *to_remove = NULL;
709 EmpathyRosterGroup *group;
711 if (!self->priv->show_groups)
713 egg_list_box_resort (EGG_LIST_BOX (self));
717 tops = empathy_individual_manager_get_top_individuals (self->priv->manager);
719 group = g_hash_table_lookup (self->priv->roster_groups, TOP_GROUP);
722 to_add = g_list_copy (tops);
728 contacts = empathy_roster_group_get_widgets (group);
730 /* Check which EmpathyRosterContact have to be removed */
731 for (l = contacts; l != NULL; l = g_list_next (l))
733 EmpathyRosterContact *contact = l->data;
734 FolksIndividual *individual;
736 individual = empathy_roster_contact_get_individual (contact);
738 if (g_list_find (tops, individual) == NULL)
739 to_remove = g_list_prepend (to_remove, individual);
742 /* Check which EmpathyRosterContact have to be added */
743 for (l = tops; l != NULL; l = g_list_next (l))
745 FolksIndividual *individual = l->data;
747 if (!individual_in_list (individual, contacts))
748 to_add = g_list_prepend (to_add, individual);
752 for (l = to_add; l != NULL; l = g_list_next (l))
753 add_to_group (self, l->data, TOP_GROUP);
755 for (l = to_remove; l != NULL; l = g_list_next (l))
756 remove_from_group (self, l->data, TOP_GROUP);
758 g_list_free (to_add);
759 g_list_free (to_remove);
763 groups_changed_cb (EmpathyIndividualManager *manager,
764 FolksIndividual *individual,
767 EmpathyRosterView *self)
769 if (!self->priv->show_groups)
774 add_to_group (self, individual, group);
778 remove_from_group (self, individual, group);
783 top_individuals_changed_cb (EmpathyIndividualManager *manager,
785 EmpathyRosterView *self)
787 update_top_contacts (self);
791 empathy_roster_view_constructed (GObject *object)
793 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
794 void (*chain_up) (GObject *) =
795 ((GObjectClass *) empathy_roster_view_parent_class)->constructed;
797 if (chain_up != NULL)
800 g_assert (EMPATHY_IS_INDIVIDUAL_MANAGER (self->priv->manager));
802 populate_view (self);
804 tp_g_signal_connect_object (self->priv->manager, "members-changed",
805 G_CALLBACK (members_changed_cb), self, 0);
806 tp_g_signal_connect_object (self->priv->manager, "groups-changed",
807 G_CALLBACK (groups_changed_cb), self, 0);
808 tp_g_signal_connect_object (self->priv->manager, "notify::top-individuals",
809 G_CALLBACK (top_individuals_changed_cb), self, 0);
811 egg_list_box_set_sort_func (EGG_LIST_BOX (self),
812 roster_view_sort, self, NULL);
814 egg_list_box_set_separator_funcs (EGG_LIST_BOX (self), update_separator,
817 egg_list_box_set_filter_func (EGG_LIST_BOX (self), filter_list, self, NULL);
819 egg_list_box_set_activate_on_single_click (EGG_LIST_BOX (self), FALSE);
823 empathy_roster_view_dispose (GObject *object)
825 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
826 void (*chain_up) (GObject *) =
827 ((GObjectClass *) empathy_roster_view_parent_class)->dispose;
829 empathy_roster_view_set_live_search (self, NULL);
830 g_clear_object (&self->priv->manager);
832 if (chain_up != NULL)
837 empathy_roster_view_finalize (GObject *object)
839 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
840 void (*chain_up) (GObject *) =
841 ((GObjectClass *) empathy_roster_view_parent_class)->finalize;
843 g_hash_table_unref (self->priv->roster_contacts);
844 g_hash_table_unref (self->priv->roster_groups);
845 g_hash_table_unref (self->priv->displayed_contacts);
847 if (chain_up != NULL)
852 empathy_roster_view_child_activated (EggListBox *box,
855 EmpathyRosterContact *contact;
856 FolksIndividual *individual;
858 if (!EMPATHY_IS_ROSTER_CONTACT (child))
861 contact = EMPATHY_ROSTER_CONTACT (child);
862 individual = empathy_roster_contact_get_individual (contact);
864 g_signal_emit (box, signals[SIG_INDIVIDUAL_ACTIVATED], 0, individual);
868 fire_popup_individual_menu (EmpathyRosterView *self,
873 EmpathyRosterContact *contact;
874 FolksIndividual *individual;
876 if (!EMPATHY_IS_ROSTER_CONTACT (child))
879 contact = EMPATHY_ROSTER_CONTACT (child);
880 individual = empathy_roster_contact_get_individual (contact);
882 g_signal_emit (self, signals[SIG_POPUP_INDIVIDUAL_MENU], 0,
883 individual, button, time);
887 empathy_roster_view_button_press_event (GtkWidget *widget,
888 GdkEventButton *event)
890 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
891 gboolean (*chain_up) (GtkWidget *, GdkEventButton *) =
892 ((GtkWidgetClass *) empathy_roster_view_parent_class)->button_press_event;
894 if (event->button == 3)
898 child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), event->y);
901 fire_popup_individual_menu (self, child, event->button, event->time);
904 return chain_up (widget, event);
908 empathy_roster_view_key_press_event (GtkWidget *widget,
911 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
912 gboolean (*chain_up) (GtkWidget *, GdkEventKey *) =
913 ((GtkWidgetClass *) empathy_roster_view_parent_class)->key_press_event;
915 if (event->keyval == GDK_KEY_Menu)
919 child = egg_list_box_get_selected_child (EGG_LIST_BOX (self));
922 fire_popup_individual_menu (self, child, 0, event->time);
925 return chain_up (widget, event);
929 empathy_roster_view_query_tooltip (GtkWidget *widget,
932 gboolean keyboard_mode,
935 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
937 EmpathyRosterContact *contact;
938 FolksIndividual *individual;
940 if (self->priv->individual_tooltip_cb == NULL)
943 child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
944 if (!EMPATHY_IS_ROSTER_CONTACT (child))
947 contact = EMPATHY_ROSTER_CONTACT (child);
948 individual = empathy_roster_contact_get_individual (contact);
950 return self->priv->individual_tooltip_cb (self, individual, keyboard_mode,
951 tooltip, self->priv->individual_tooltip_data);
955 empathy_roster_view_set_individual_tooltip_cb (EmpathyRosterView *self,
956 EmpathyRosterViewIndividualTooltipCb callback,
959 self->priv->individual_tooltip_cb = callback;
960 self->priv->individual_tooltip_data = user_data;
962 gtk_widget_set_has_tooltip (GTK_WIDGET (self), callback != NULL);
966 empathy_roster_view_remove (GtkContainer *container,
969 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (container);
970 void (*chain_up) (GtkContainer *, GtkWidget *) =
971 ((GtkContainerClass *) empathy_roster_view_parent_class)->remove;
973 chain_up (container, widget);
975 if (EMPATHY_IS_ROSTER_CONTACT (widget))
976 remove_from_displayed (self, (EmpathyRosterContact *) widget);
980 empathy_roster_view_class_init (
981 EmpathyRosterViewClass *klass)
983 GObjectClass *oclass = G_OBJECT_CLASS (klass);
984 EggListBoxClass *box_class = EGG_LIST_BOX_CLASS (klass);
985 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
986 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
989 oclass->get_property = empathy_roster_view_get_property;
990 oclass->set_property = empathy_roster_view_set_property;
991 oclass->constructed = empathy_roster_view_constructed;
992 oclass->dispose = empathy_roster_view_dispose;
993 oclass->finalize = empathy_roster_view_finalize;
995 widget_class->button_press_event = empathy_roster_view_button_press_event;
996 widget_class->key_press_event = empathy_roster_view_key_press_event;
997 widget_class->query_tooltip = empathy_roster_view_query_tooltip;
999 container_class->remove = empathy_roster_view_remove;
1001 box_class->child_activated = empathy_roster_view_child_activated;
1003 spec = g_param_spec_object ("manager", "Manager",
1004 "EmpathyIndividualManager",
1005 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1006 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1007 g_object_class_install_property (oclass, PROP_MANAGER, spec);
1009 spec = g_param_spec_boolean ("show-offline", "Show Offline",
1010 "Show offline contacts",
1012 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1013 g_object_class_install_property (oclass, PROP_SHOW_OFFLINE, spec);
1015 spec = g_param_spec_boolean ("show-groups", "Show Groups",
1018 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1019 g_object_class_install_property (oclass, PROP_SHOW_GROUPS, spec);
1021 spec = g_param_spec_boolean ("empty", "Empty",
1022 "Is the view currently empty?",
1024 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1025 g_object_class_install_property (oclass, PROP_EMPTY, spec);
1027 signals[SIG_INDIVIDUAL_ACTIVATED] = g_signal_new ("individual-activated",
1028 G_OBJECT_CLASS_TYPE (klass),
1030 0, NULL, NULL, NULL,
1032 1, FOLKS_TYPE_INDIVIDUAL);
1034 signals[SIG_POPUP_INDIVIDUAL_MENU] = g_signal_new ("popup-individual-menu",
1035 G_OBJECT_CLASS_TYPE (klass),
1037 0, NULL, NULL, NULL,
1039 3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_UINT, G_TYPE_UINT);
1041 g_type_class_add_private (klass, sizeof (EmpathyRosterViewPriv));
1045 empathy_roster_view_init (EmpathyRosterView *self)
1047 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1048 EMPATHY_TYPE_ROSTER_VIEW, EmpathyRosterViewPriv);
1050 self->priv->roster_contacts = g_hash_table_new_full (NULL, NULL,
1051 NULL, (GDestroyNotify) g_hash_table_unref);
1052 self->priv->roster_groups = g_hash_table_new_full (g_str_hash, g_str_equal,
1054 self->priv->displayed_contacts = g_hash_table_new (NULL, NULL);
1056 self->priv->empty = TRUE;
1060 empathy_roster_view_new (EmpathyIndividualManager *manager)
1062 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1064 return g_object_new (EMPATHY_TYPE_ROSTER_VIEW,
1069 EmpathyIndividualManager *
1070 empathy_roster_view_get_manager (EmpathyRosterView *self)
1072 return self->priv->manager;
1076 empathy_roster_view_show_offline (EmpathyRosterView *self,
1079 if (self->priv->show_offline == show)
1082 self->priv->show_offline = show;
1083 egg_list_box_refilter (EGG_LIST_BOX (self));
1085 g_object_notify (G_OBJECT (self), "show-offline");
1089 clear_view (EmpathyRosterView *self)
1091 gtk_container_foreach (GTK_CONTAINER (self),
1092 (GtkCallback) gtk_widget_destroy, NULL);
1094 g_hash_table_remove_all (self->priv->roster_contacts);
1098 empathy_roster_view_show_groups (EmpathyRosterView *self,
1101 if (self->priv->show_groups == show)
1104 self->priv->show_groups = show;
1106 /* TODO: block sort/filter? */
1108 populate_view (self);
1110 g_object_notify (G_OBJECT (self), "show-groups");
1114 select_first_contact (EmpathyRosterView *self)
1116 GList *children, *l;
1118 children = gtk_container_get_children (GTK_CONTAINER (self));
1119 for (l = children; l != NULL; l = g_list_next (l))
1121 GtkWidget *child = l->data;
1123 if (!gtk_widget_get_child_visible (child))
1126 if (!EMPATHY_IS_ROSTER_CONTACT (child))
1129 egg_list_box_select_child (EGG_LIST_BOX (self), child);
1133 g_list_free (children);
1137 search_text_notify_cb (EmpathyLiveSearch *search,
1139 EmpathyRosterView *self)
1141 egg_list_box_refilter (EGG_LIST_BOX (self));
1143 select_first_contact (self);
1147 search_activate_cb (GtkWidget *search,
1148 EmpathyRosterView *self)
1150 EggListBox *box = EGG_LIST_BOX (self);
1153 child = egg_list_box_get_selected_child (box);
1157 empathy_roster_view_child_activated (box, child);
1161 empathy_roster_view_set_live_search (EmpathyRosterView *self,
1162 EmpathyLiveSearch *search)
1164 if (self->priv->search != NULL)
1166 g_signal_handlers_disconnect_by_func (self->priv->search,
1167 search_text_notify_cb, self);
1168 g_signal_handlers_disconnect_by_func (self->priv->search,
1169 search_activate_cb, self);
1171 g_clear_object (&self->priv->search);
1177 self->priv->search = g_object_ref (search);
1179 g_signal_connect (self->priv->search, "notify::text",
1180 G_CALLBACK (search_text_notify_cb), self);
1181 g_signal_connect (self->priv->search, "activate",
1182 G_CALLBACK (search_activate_cb), self);
1186 empathy_roster_view_is_empty (EmpathyRosterView *self)
1188 return self->priv->empty;
1192 empathy_roster_view_is_searching (EmpathyRosterView *self)
1194 return (self->priv->search != NULL &&
1195 gtk_widget_get_visible (GTK_WIDGET (self->priv->search)));