Help: Use stable 'if' namespace instead of experimental
[empathy-mirror.git] / tests / interactive / test-empathy-dual-roster-view.c
blob0d4b889d3dfa4edda5efdbf66311c0e9f85bfe1d
1 #include "config.h"
3 #include "empathy-roster-model.h"
4 #include "empathy-roster-model-manager.h"
5 #include "empathy-roster-view.h"
6 #include "empathy-ui-utils.h"
8 static void
9 individual_activated_cb (EmpathyRosterView *self,
10 FolksIndividual *individual,
11 gpointer user_data)
13 g_assert (FOLKS_IS_INDIVIDUAL (individual));
15 g_print ("'%s' activated\n",
16 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
19 static void
20 popup_individual_menu_cb (EmpathyRosterView *self,
21 const gchar *group,
22 FolksIndividual *individual,
23 guint button,
24 guint time,
25 gpointer user_data)
27 GtkWidget *menu, *item;
29 g_print ("'%s' (group: %s) popup menu\n",
30 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)), group);
32 menu = gtk_menu_new ();
34 g_signal_connect (menu, "deactivate",
35 G_CALLBACK (gtk_widget_destroy), NULL);
37 item = gtk_menu_item_new_with_label (folks_alias_details_get_alias (
38 FOLKS_ALIAS_DETAILS (individual)));
39 gtk_widget_show (item);
41 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
43 gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (self), NULL);
45 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time);
48 static gboolean
49 individual_tooltip_cb (EmpathyRosterView *view,
50 FolksIndividual *individual,
51 gboolean keyboard_mode,
52 GtkTooltip *tooltip,
53 gpointer user_data)
55 gtk_tooltip_set_text (tooltip,
56 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
58 return TRUE;
61 static void
62 empty_cb (EmpathyRosterView *view,
63 GParamSpec *spec,
64 gpointer user_data)
66 if (empathy_roster_view_is_empty (view))
67 g_print ("view is now empty\n");
68 else
69 g_print ("view is no longer empty\n");
72 static GtkWidget *
73 create_view_box (EmpathyRosterModel *model,
74 gboolean show_offline,
75 gboolean show_groups)
77 GtkWidget *view, *scrolled, *box, *search;
79 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
81 view = empathy_roster_view_new (model);
83 g_signal_connect (view, "individual-activated",
84 G_CALLBACK (individual_activated_cb), NULL);
85 g_signal_connect (view, "popup-individual-menu",
86 G_CALLBACK (popup_individual_menu_cb), NULL);
87 g_signal_connect (view, "notify::empty",
88 G_CALLBACK (empty_cb), NULL);
89 g_signal_connect (view, "individual-tooltip",
90 G_CALLBACK (individual_tooltip_cb), NULL);
92 gtk_widget_set_has_tooltip (view, TRUE);
94 empathy_roster_view_show_offline (EMPATHY_ROSTER_VIEW (view), show_offline);
95 empathy_roster_view_show_groups (EMPATHY_ROSTER_VIEW (view), show_groups);
97 search = tpaw_live_search_new (view);
98 empathy_roster_view_set_live_search (EMPATHY_ROSTER_VIEW (view),
99 TPAW_LIVE_SEARCH (search));
101 scrolled = gtk_scrolled_window_new (NULL, NULL);
102 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
103 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
105 gtk_container_add (GTK_CONTAINER (scrolled), view);
107 gtk_box_pack_start (GTK_BOX (box), search, FALSE, TRUE, 0);
108 gtk_box_pack_start (GTK_BOX (box), scrolled, TRUE, TRUE, 0);
110 return box;
114 main (int argc,
115 char **argv)
117 GtkWidget *window, *view1, *view2, *box_horiz;
118 EmpathyIndividualManager *mgr;
119 EmpathyRosterModel *model;
121 gtk_init (&argc, &argv);
122 empathy_gtk_init ();
124 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
126 empathy_set_css_provider (window);
128 box_horiz = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
130 mgr = empathy_individual_manager_dup_singleton ();
132 model = EMPATHY_ROSTER_MODEL (empathy_roster_model_manager_new (mgr));
134 view1 = create_view_box (model, TRUE, TRUE);
135 view2 = create_view_box (model, FALSE, FALSE);
137 g_object_unref (model);
138 g_object_unref (mgr);
140 gtk_box_pack_start (GTK_BOX (box_horiz), view1, FALSE, TRUE, 0);
141 gtk_box_pack_start (GTK_BOX (box_horiz), view2, FALSE, TRUE, 0);
142 gtk_container_add (GTK_CONTAINER (window), box_horiz);
144 gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
145 gtk_widget_show_all (window);
147 g_signal_connect_swapped (window, "destroy",
148 G_CALLBACK (gtk_main_quit), NULL);
150 gtk_main ();
152 return 0;