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)
23 SIG_INDIVIDUAL_ACTIVATED,
24 SIG_POPUP_INDIVIDUAL_MENU,
28 static guint signals[LAST_SIGNAL];
30 #define NO_GROUP "X-no-group"
31 #define UNGROUPPED _("Ungroupped")
32 #define TOP_GROUP _("Most Used")
34 struct _EmpathyRosterViewPriv
36 EmpathyIndividualManager *manager;
38 /* FolksIndividual (borrowed) -> GHashTable (
39 * (gchar * group_name) -> EmpathyRosterContact (borrowed))
41 * When not using groups, this hash just have one element mapped
42 * from the special NO_GROUP key. We could use it as a set but
43 * I prefer to stay coherent in the way this hash is managed.
45 GHashTable *roster_contacts;
46 /* (gchar *group_name) -> EmpathyRosterGroup (borrowed) */
47 GHashTable *roster_groups;
49 gboolean show_offline;
52 EmpathyLiveSearch *search;
54 EmpathyRosterViewIndividualTooltipCb individual_tooltip_cb;
55 gpointer individual_tooltip_data;
59 empathy_roster_view_get_property (GObject *object,
64 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
69 g_value_set_object (value, self->priv->manager);
71 case PROP_SHOW_OFFLINE:
72 g_value_set_boolean (value, self->priv->show_offline);
74 case PROP_SHOW_GROUPS:
75 g_value_set_boolean (value, self->priv->show_groups);
78 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
84 empathy_roster_view_set_property (GObject *object,
89 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
94 g_assert (self->priv->manager == NULL); /* construct only */
95 self->priv->manager = g_value_dup_object (value);
97 case PROP_SHOW_OFFLINE:
98 empathy_roster_view_show_offline (self, g_value_get_boolean (value));
100 case PROP_SHOW_GROUPS:
101 empathy_roster_view_show_groups (self, g_value_get_boolean (value));
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
110 roster_contact_changed_cb (GtkWidget *child,
112 EmpathyRosterView *self)
114 egg_list_box_child_changed (EGG_LIST_BOX (self), child);
118 add_roster_contact (EmpathyRosterView *self,
119 FolksIndividual *individual,
124 contact = empathy_roster_contact_new (individual, group);
126 /* Need to refilter if online is changed */
127 g_signal_connect (contact, "notify::online",
128 G_CALLBACK (roster_contact_changed_cb), self);
130 /* Need to resort if alias is changed */
131 g_signal_connect (contact, "notify::alias",
132 G_CALLBACK (roster_contact_changed_cb), self);
134 gtk_widget_show (contact);
135 gtk_container_add (GTK_CONTAINER (self), contact);
141 group_expanded_cb (EmpathyRosterGroup *group,
143 EmpathyRosterView *self)
147 widgets = empathy_roster_group_get_widgets (group);
148 for (l = widgets; l != NULL; l = g_list_next (l))
150 egg_list_box_child_changed (EGG_LIST_BOX (self), l->data);
153 g_list_free (widgets);
156 static EmpathyRosterGroup *
157 lookup_roster_group (EmpathyRosterView *self,
160 return g_hash_table_lookup (self->priv->roster_groups, group);
164 ensure_roster_group (EmpathyRosterView *self,
167 GtkWidget *roster_group;
169 roster_group = (GtkWidget *) lookup_roster_group (self, group);
170 if (roster_group != NULL)
173 roster_group = empathy_roster_group_new (group);
175 g_signal_connect (roster_group, "notify::expanded",
176 G_CALLBACK (group_expanded_cb), self);
178 gtk_widget_show (roster_group);
179 gtk_container_add (GTK_CONTAINER (self), roster_group);
181 g_hash_table_insert (self->priv->roster_groups, g_strdup (group),
186 add_to_group (EmpathyRosterView *self,
187 FolksIndividual *individual,
191 GHashTable *contacts;
193 contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
194 if (contacts == NULL)
197 if (tp_strdiff (group, NO_GROUP))
198 ensure_roster_group (self, group);
200 contact = add_roster_contact (self, individual, group);
201 g_hash_table_insert (contacts, g_strdup (group), contact);
205 individual_added (EmpathyRosterView *self,
206 FolksIndividual *individual)
208 GHashTable *contacts;
210 contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
211 if (contacts != NULL)
214 contacts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
216 g_hash_table_insert (self->priv->roster_contacts, individual, contacts);
218 if (!self->priv->show_groups)
220 add_to_group (self, individual, NO_GROUP);
226 groups = folks_group_details_get_groups (
227 FOLKS_GROUP_DETAILS (individual));
229 if (gee_collection_get_size (GEE_COLLECTION (groups)) > 0)
231 GeeIterator *iter = gee_iterable_iterator (GEE_ITERABLE (groups));
233 while (iter != NULL && gee_iterator_next (iter))
235 gchar *group = gee_iterator_get (iter);
237 add_to_group (self, individual, group);
242 g_clear_object (&iter);
246 /* No group, adds to Ungroupped */
247 add_to_group (self, individual, UNGROUPPED);
253 update_group_widgets_count (EmpathyRosterView *self,
254 EmpathyRosterGroup *group,
255 EmpathyRosterContact *contact,
260 if (empathy_roster_group_add_widget (group, GTK_WIDGET (contact)) == 1)
262 egg_list_box_child_changed (EGG_LIST_BOX (self),
268 if (empathy_roster_group_remove_widget (group, GTK_WIDGET (contact)) == 0)
270 egg_list_box_child_changed (EGG_LIST_BOX (self),
277 individual_removed (EmpathyRosterView *self,
278 FolksIndividual *individual)
280 GHashTable *contacts;
284 contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
285 if (contacts == NULL)
288 g_hash_table_iter_init (&iter, contacts);
289 while (g_hash_table_iter_next (&iter, &key, &value))
291 const gchar *group_name = key;
292 GtkWidget *contact = value;
293 EmpathyRosterGroup *group;
295 group = lookup_roster_group (self, group_name);
298 update_group_widgets_count (self, group,
299 EMPATHY_ROSTER_CONTACT (contact), FALSE);
302 gtk_container_remove (GTK_CONTAINER (self), contact);
305 g_hash_table_remove (self->priv->roster_contacts, individual);
309 members_changed_cb (EmpathyIndividualManager *manager,
310 const gchar *message,
313 TpChannelGroupChangeReason reason,
314 EmpathyRosterView *self)
318 for (l = added; l != NULL; l = g_list_next (l))
320 FolksIndividual *individual = l->data;
322 individual_added (self, individual);
325 for (l = removed; l != NULL; l = g_list_next (l))
327 FolksIndividual *individual = l->data;
329 individual_removed (self, individual);
334 compare_roster_contacts_by_alias (EmpathyRosterContact *a,
335 EmpathyRosterContact *b)
337 FolksIndividual *ind_a, *ind_b;
338 const gchar *alias_a, *alias_b;
340 ind_a = empathy_roster_contact_get_individual (a);
341 ind_b = empathy_roster_contact_get_individual (b);
343 alias_a = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_a));
344 alias_b = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_b));
346 return g_ascii_strcasecmp (alias_a, alias_b);
350 compare_individual_top_position (EmpathyRosterView *self,
351 EmpathyRosterContact *a,
352 EmpathyRosterContact *b)
354 FolksIndividual *ind_a, *ind_b;
356 gint index_a, index_b;
358 ind_a = empathy_roster_contact_get_individual (a);
359 ind_b = empathy_roster_contact_get_individual (b);
361 tops = empathy_individual_manager_get_top_individuals (self->priv->manager);
363 index_a = g_list_index (tops, ind_a);
364 index_b = g_list_index (tops, ind_b);
366 if (index_a == index_b)
375 return index_a - index_b;
379 compare_roster_contacts_no_group (EmpathyRosterView *self,
380 EmpathyRosterContact *a,
381 EmpathyRosterContact *b)
385 top = compare_individual_top_position (self, a, b);
389 return compare_roster_contacts_by_alias (a, b);
393 compare_group_names (const gchar *group_a,
394 const gchar *group_b)
396 if (!tp_strdiff (group_a, TOP_GROUP))
399 if (!tp_strdiff (group_b, TOP_GROUP))
402 return g_ascii_strcasecmp (group_a, group_b);
406 compare_roster_contacts_with_groups (EmpathyRosterView *self,
407 EmpathyRosterContact *a,
408 EmpathyRosterContact *b)
410 const gchar *group_a, *group_b;
412 group_a = empathy_roster_contact_get_group (a);
413 group_b = empathy_roster_contact_get_group (b);
415 if (!tp_strdiff (group_a, group_b))
416 /* Same group, compare the contacts */
417 return compare_roster_contacts_by_alias (a, b);
420 return compare_group_names (group_a, group_b);
424 compare_roster_contacts (EmpathyRosterView *self,
425 EmpathyRosterContact *a,
426 EmpathyRosterContact *b)
428 if (!self->priv->show_groups)
429 return compare_roster_contacts_no_group (self, a, b);
431 return compare_roster_contacts_with_groups (self, a, b);
435 compare_roster_groups (EmpathyRosterGroup *a,
436 EmpathyRosterGroup *b)
438 const gchar *name_a, *name_b;
440 name_a = empathy_roster_group_get_name (a);
441 name_b = empathy_roster_group_get_name (b);
443 return compare_group_names (name_a, name_b);
447 compare_contact_group (EmpathyRosterContact *contact,
448 EmpathyRosterGroup *group)
450 const char *contact_group, *group_name;
452 contact_group = empathy_roster_contact_get_group (contact);
453 group_name = empathy_roster_group_get_name (group);
455 if (!tp_strdiff (contact_group, group_name))
456 /* @contact is in @group, @group has to be displayed first */
459 /* @contact is in a different group, sort by group name */
460 return compare_group_names (contact_group, group_name);
464 roster_view_sort (gconstpointer a,
468 EmpathyRosterView *self = user_data;
470 if (EMPATHY_IS_ROSTER_CONTACT (a) && EMPATHY_IS_ROSTER_CONTACT (b))
471 return compare_roster_contacts (self, EMPATHY_ROSTER_CONTACT (a),
472 EMPATHY_ROSTER_CONTACT (b));
473 else if (EMPATHY_IS_ROSTER_GROUP (a) && EMPATHY_IS_ROSTER_GROUP (b))
474 return compare_roster_groups (EMPATHY_ROSTER_GROUP (a),
475 EMPATHY_ROSTER_GROUP (b));
476 else if (EMPATHY_IS_ROSTER_CONTACT (a) && EMPATHY_IS_ROSTER_GROUP (b))
477 return compare_contact_group (EMPATHY_ROSTER_CONTACT (a),
478 EMPATHY_ROSTER_GROUP (b));
479 else if (EMPATHY_IS_ROSTER_GROUP (a) && EMPATHY_IS_ROSTER_CONTACT (b))
480 return -1 * compare_contact_group (EMPATHY_ROSTER_CONTACT (b),
481 EMPATHY_ROSTER_GROUP (a));
483 g_return_val_if_reached (0);
487 update_separator (GtkWidget **separator,
494 /* No separator before the first row */
495 g_clear_object (separator);
499 if (*separator != NULL)
502 *separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
503 g_object_ref_sink (*separator);
507 is_searching (EmpathyRosterView *self)
509 if (self->priv->search == NULL)
512 return gtk_widget_get_visible (GTK_WIDGET (self->priv->search));
516 filter_contact (EmpathyRosterView *self,
517 EmpathyRosterContact *contact)
521 if (is_searching (self))
523 FolksIndividual *individual;
525 individual = empathy_roster_contact_get_individual (contact);
527 displayed = empathy_individual_match_string (individual,
528 empathy_live_search_get_text (self->priv->search),
529 empathy_live_search_get_words (self->priv->search));
533 if (self->priv->show_offline)
539 displayed = empathy_roster_contact_is_online (contact);
543 if (self->priv->show_groups)
545 const gchar *group_name;
546 EmpathyRosterGroup *group;
548 group_name = empathy_roster_contact_get_group (contact);
549 group = lookup_roster_group (self, group_name);
553 update_group_widgets_count (self, group, contact, displayed);
555 /* When searching, always display even if the group is closed */
556 if (!is_searching (self) &&
557 !gtk_expander_get_expanded (GTK_EXPANDER (group)))
566 filter_group (EmpathyRosterView *self,
567 EmpathyRosterGroup *group)
569 return empathy_roster_group_get_widgets_count (group);
573 filter_list (GtkWidget *child,
576 EmpathyRosterView *self = user_data;
578 if (EMPATHY_IS_ROSTER_CONTACT (child))
579 return filter_contact (self, EMPATHY_ROSTER_CONTACT (child));
581 else if (EMPATHY_IS_ROSTER_GROUP (child))
582 return filter_group (self, EMPATHY_ROSTER_GROUP (child));
584 g_return_val_if_reached (FALSE);
587 /* @list: GList of EmpathyRosterContact
589 * Returns: %TRUE if @list contains an EmpathyRosterContact associated with
592 individual_in_list (FolksIndividual *individual,
597 for (l = list; l != NULL; l = g_list_next (l))
599 EmpathyRosterContact *contact = l->data;
601 if (empathy_roster_contact_get_individual (contact) == individual)
609 populate_view (EmpathyRosterView *self)
611 GList *individuals, *l;
613 individuals = empathy_individual_manager_get_members (self->priv->manager);
614 for (l = individuals; l != NULL; l = g_list_next (l))
616 FolksIndividual *individual = l->data;
618 individual_added (self, individual);
621 g_list_free (individuals);
625 remove_from_group (EmpathyRosterView *self,
626 FolksIndividual *individual,
629 GHashTable *contacts;
631 EmpathyRosterGroup *roster_group;
633 contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
634 if (contacts == NULL)
637 contact = g_hash_table_lookup (contacts, group);
641 g_hash_table_remove (contacts, group);
643 if (g_hash_table_size (contacts) == 0)
645 add_to_group (self, individual, UNGROUPPED);
648 roster_group = lookup_roster_group (self, group);
650 if (roster_group != NULL)
652 update_group_widgets_count (self, roster_group,
653 EMPATHY_ROSTER_CONTACT (contact), FALSE);
656 gtk_container_remove (GTK_CONTAINER (self), contact);
660 update_top_contacts (EmpathyRosterView *self)
663 GList *to_add = NULL, *to_remove = NULL;
664 EmpathyRosterGroup *group;
666 if (!self->priv->show_groups)
668 egg_list_box_resort (EGG_LIST_BOX (self));
672 tops = empathy_individual_manager_get_top_individuals (self->priv->manager);
674 group = g_hash_table_lookup (self->priv->roster_groups, TOP_GROUP);
677 to_add = g_list_copy (tops);
683 contacts = empathy_roster_group_get_widgets (group);
685 /* Check which EmpathyRosterContact have to be removed */
686 for (l = contacts; l != NULL; l = g_list_next (l))
688 EmpathyRosterContact *contact = l->data;
689 FolksIndividual *individual;
691 individual = empathy_roster_contact_get_individual (contact);
693 if (g_list_find (tops, individual) == NULL)
694 to_remove = g_list_prepend (to_remove, individual);
697 /* Check which EmpathyRosterContact have to be added */
698 for (l = tops; l != NULL; l = g_list_next (l))
700 FolksIndividual *individual = l->data;
702 if (!individual_in_list (individual, contacts))
703 to_add = g_list_prepend (to_add, individual);
707 for (l = to_add; l != NULL; l = g_list_next (l))
708 add_to_group (self, l->data, TOP_GROUP);
710 for (l = to_remove; l != NULL; l = g_list_next (l))
711 remove_from_group (self, l->data, TOP_GROUP);
713 g_list_free (to_add);
714 g_list_free (to_remove);
718 groups_changed_cb (EmpathyIndividualManager *manager,
719 FolksIndividual *individual,
722 EmpathyRosterView *self)
724 if (!self->priv->show_groups)
729 add_to_group (self, individual, group);
733 remove_from_group (self, individual, group);
738 top_individuals_changed_cb (EmpathyIndividualManager *manager,
740 EmpathyRosterView *self)
742 update_top_contacts (self);
746 empathy_roster_view_constructed (GObject *object)
748 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
749 void (*chain_up) (GObject *) =
750 ((GObjectClass *) empathy_roster_view_parent_class)->constructed;
752 if (chain_up != NULL)
755 g_assert (EMPATHY_IS_INDIVIDUAL_MANAGER (self->priv->manager));
757 populate_view (self);
759 tp_g_signal_connect_object (self->priv->manager, "members-changed",
760 G_CALLBACK (members_changed_cb), self, 0);
761 tp_g_signal_connect_object (self->priv->manager, "groups-changed",
762 G_CALLBACK (groups_changed_cb), self, 0);
763 tp_g_signal_connect_object (self->priv->manager, "notify::top-individuals",
764 G_CALLBACK (top_individuals_changed_cb), self, 0);
766 egg_list_box_set_sort_func (EGG_LIST_BOX (self),
767 roster_view_sort, self, NULL);
769 egg_list_box_set_separator_funcs (EGG_LIST_BOX (self), update_separator,
772 egg_list_box_set_filter_func (EGG_LIST_BOX (self), filter_list, self, NULL);
774 egg_list_box_set_activate_on_single_click (EGG_LIST_BOX (self), FALSE);
778 empathy_roster_view_dispose (GObject *object)
780 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
781 void (*chain_up) (GObject *) =
782 ((GObjectClass *) empathy_roster_view_parent_class)->dispose;
784 empathy_roster_view_set_live_search (self, NULL);
785 g_clear_object (&self->priv->manager);
787 if (chain_up != NULL)
792 empathy_roster_view_finalize (GObject *object)
794 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
795 void (*chain_up) (GObject *) =
796 ((GObjectClass *) empathy_roster_view_parent_class)->finalize;
798 g_hash_table_unref (self->priv->roster_contacts);
799 g_hash_table_unref (self->priv->roster_groups);
801 if (chain_up != NULL)
806 empathy_roster_view_child_activated (EggListBox *box,
809 EmpathyRosterContact *contact;
810 FolksIndividual *individual;
812 if (!EMPATHY_IS_ROSTER_CONTACT (child))
815 contact = EMPATHY_ROSTER_CONTACT (child);
816 individual = empathy_roster_contact_get_individual (contact);
818 g_signal_emit (box, signals[SIG_INDIVIDUAL_ACTIVATED], 0, individual);
822 fire_popup_individual_menu (EmpathyRosterView *self,
827 EmpathyRosterContact *contact;
828 FolksIndividual *individual;
830 if (!EMPATHY_IS_ROSTER_CONTACT (child))
833 contact = EMPATHY_ROSTER_CONTACT (child);
834 individual = empathy_roster_contact_get_individual (contact);
836 g_signal_emit (self, signals[SIG_POPUP_INDIVIDUAL_MENU], 0,
837 individual, button, time);
841 empathy_roster_view_button_press_event (GtkWidget *widget,
842 GdkEventButton *event)
844 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
845 gboolean (*chain_up) (GtkWidget *, GdkEventButton *) =
846 ((GtkWidgetClass *) empathy_roster_view_parent_class)->button_press_event;
848 if (event->button == 3)
852 child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), event->y);
855 fire_popup_individual_menu (self, child, event->button, event->time);
858 return chain_up (widget, event);
862 empathy_roster_view_key_press_event (GtkWidget *widget,
865 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
866 gboolean (*chain_up) (GtkWidget *, GdkEventKey *) =
867 ((GtkWidgetClass *) empathy_roster_view_parent_class)->key_press_event;
869 if (event->keyval == GDK_KEY_Menu)
873 child = egg_list_box_get_selected_child (EGG_LIST_BOX (self));
876 fire_popup_individual_menu (self, child, 0, event->time);
879 return chain_up (widget, event);
883 empathy_roster_view_query_tooltip (GtkWidget *widget,
886 gboolean keyboard_mode,
889 EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
891 EmpathyRosterContact *contact;
892 FolksIndividual *individual;
894 if (self->priv->individual_tooltip_cb == NULL)
897 child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
898 if (!EMPATHY_IS_ROSTER_CONTACT (child))
901 contact = EMPATHY_ROSTER_CONTACT (child);
902 individual = empathy_roster_contact_get_individual (contact);
904 return self->priv->individual_tooltip_cb (self, individual, keyboard_mode,
905 tooltip, self->priv->individual_tooltip_data);
909 empathy_roster_view_set_individual_tooltip_cb (EmpathyRosterView *self,
910 EmpathyRosterViewIndividualTooltipCb callback,
913 self->priv->individual_tooltip_cb = callback;
914 self->priv->individual_tooltip_data = user_data;
916 gtk_widget_set_has_tooltip (GTK_WIDGET (self), callback != NULL);
920 empathy_roster_view_class_init (
921 EmpathyRosterViewClass *klass)
923 GObjectClass *oclass = G_OBJECT_CLASS (klass);
924 EggListBoxClass *box_class = EGG_LIST_BOX_CLASS (klass);
925 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
928 oclass->get_property = empathy_roster_view_get_property;
929 oclass->set_property = empathy_roster_view_set_property;
930 oclass->constructed = empathy_roster_view_constructed;
931 oclass->dispose = empathy_roster_view_dispose;
932 oclass->finalize = empathy_roster_view_finalize;
934 widget_class->button_press_event = empathy_roster_view_button_press_event;
935 widget_class->key_press_event = empathy_roster_view_key_press_event;
936 widget_class->query_tooltip = empathy_roster_view_query_tooltip;
938 box_class->child_activated = empathy_roster_view_child_activated;
940 spec = g_param_spec_object ("manager", "Manager",
941 "EmpathyIndividualManager",
942 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
943 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
944 g_object_class_install_property (oclass, PROP_MANAGER, spec);
946 spec = g_param_spec_boolean ("show-offline", "Show Offline",
947 "Show offline contacts",
949 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
950 g_object_class_install_property (oclass, PROP_SHOW_OFFLINE, spec);
952 spec = g_param_spec_boolean ("show-groups", "Show Groups",
955 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
956 g_object_class_install_property (oclass, PROP_SHOW_GROUPS, spec);
958 signals[SIG_INDIVIDUAL_ACTIVATED] = g_signal_new ("individual-activated",
959 G_OBJECT_CLASS_TYPE (klass),
963 1, FOLKS_TYPE_INDIVIDUAL);
965 signals[SIG_POPUP_INDIVIDUAL_MENU] = g_signal_new ("popup-individual-menu",
966 G_OBJECT_CLASS_TYPE (klass),
970 3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_UINT, G_TYPE_UINT);
972 g_type_class_add_private (klass, sizeof (EmpathyRosterViewPriv));
976 empathy_roster_view_init (EmpathyRosterView *self)
978 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
979 EMPATHY_TYPE_ROSTER_VIEW, EmpathyRosterViewPriv);
981 self->priv->roster_contacts = g_hash_table_new_full (NULL, NULL,
982 NULL, (GDestroyNotify) g_hash_table_unref);
983 self->priv->roster_groups = g_hash_table_new_full (g_str_hash, g_str_equal,
988 empathy_roster_view_new (EmpathyIndividualManager *manager)
990 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
992 return g_object_new (EMPATHY_TYPE_ROSTER_VIEW,
997 EmpathyIndividualManager *
998 empathy_roster_view_get_manager (EmpathyRosterView *self)
1000 return self->priv->manager;
1004 empathy_roster_view_show_offline (EmpathyRosterView *self,
1007 if (self->priv->show_offline == show)
1010 self->priv->show_offline = show;
1011 egg_list_box_refilter (EGG_LIST_BOX (self));
1013 g_object_notify (G_OBJECT (self), "show-offline");
1017 clear_view (EmpathyRosterView *self)
1019 gtk_container_foreach (GTK_CONTAINER (self),
1020 (GtkCallback) gtk_widget_destroy, NULL);
1022 g_hash_table_remove_all (self->priv->roster_contacts);
1026 empathy_roster_view_show_groups (EmpathyRosterView *self,
1029 if (self->priv->show_groups == show)
1032 self->priv->show_groups = show;
1034 /* TODO: block sort/filter? */
1036 populate_view (self);
1038 g_object_notify (G_OBJECT (self), "show-groups");
1042 select_first_contact (EmpathyRosterView *self)
1044 GList *children, *l;
1046 children = gtk_container_get_children (GTK_CONTAINER (self));
1047 for (l = children; l != NULL; l = g_list_next (l))
1049 GtkWidget *child = l->data;
1051 if (!gtk_widget_get_child_visible (child))
1054 if (!EMPATHY_IS_ROSTER_CONTACT (child))
1057 egg_list_box_select_child (EGG_LIST_BOX (self), child);
1061 g_list_free (children);
1065 search_text_notify_cb (EmpathyLiveSearch *search,
1067 EmpathyRosterView *self)
1069 egg_list_box_refilter (EGG_LIST_BOX (self));
1071 select_first_contact (self);
1075 search_activate_cb (GtkWidget *search,
1076 EmpathyRosterView *self)
1078 EggListBox *box = EGG_LIST_BOX (self);
1081 child = egg_list_box_get_selected_child (box);
1085 empathy_roster_view_child_activated (box, child);
1089 empathy_roster_view_set_live_search (EmpathyRosterView *self,
1090 EmpathyLiveSearch *search)
1092 if (self->priv->search != NULL)
1094 g_signal_handlers_disconnect_by_func (self->priv->search,
1095 search_text_notify_cb, self);
1096 g_signal_handlers_disconnect_by_func (self->priv->search,
1097 search_activate_cb, self);
1099 g_clear_object (&self->priv->search);
1105 self->priv->search = g_object_ref (search);
1107 g_signal_connect (self->priv->search, "notify::text",
1108 G_CALLBACK (search_text_notify_cb), self);
1109 g_signal_connect (self->priv->search, "activate",
1110 G_CALLBACK (search_activate_cb), self);