Help: Use stable 'if' namespace instead of experimental
[empathy-mirror.git] / tests / interactive / test-empathy-roster-view.c
blobfbf09c71d556158a537fa9c33f7746303cd877db
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 gboolean show_offline = FALSE;
9 static gboolean show_groups = FALSE;
11 static GOptionEntry entries[] =
13 { "offline", 0, 0, G_OPTION_ARG_NONE, &show_offline, "Show offline contacts", NULL },
14 { "groups", 0, 0, G_OPTION_ARG_NONE, &show_groups, "Show groups", NULL },
15 { NULL }
18 static void
19 individual_activated_cb (EmpathyRosterView *self,
20 FolksIndividual *individual,
21 gpointer user_data)
23 g_assert (FOLKS_IS_INDIVIDUAL (individual));
25 g_print ("'%s' activated\n",
26 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
29 static void
30 popup_individual_menu_cb (EmpathyRosterView *self,
31 const gchar *group,
32 FolksIndividual *individual,
33 guint button,
34 guint time,
35 gpointer user_data)
37 GtkWidget *menu, *item;
39 g_print ("'%s' (group: %s) popup menu\n",
40 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)), group);
42 menu = gtk_menu_new ();
44 g_signal_connect (menu, "deactivate",
45 G_CALLBACK (gtk_widget_destroy), NULL);
47 item = gtk_menu_item_new_with_label (folks_alias_details_get_alias (
48 FOLKS_ALIAS_DETAILS (individual)));
49 gtk_widget_show (item);
51 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
53 gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (self), NULL);
55 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time);
58 static gboolean
59 individual_tooltip_cb (EmpathyRosterView *view,
60 FolksIndividual *individual,
61 gboolean keyboard_mode,
62 GtkTooltip *tooltip,
63 gpointer user_data)
65 gtk_tooltip_set_text (tooltip,
66 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
68 return TRUE;
71 static void
72 empty_cb (EmpathyRosterView *view,
73 GParamSpec *spec,
74 gpointer user_data)
76 if (empathy_roster_view_is_empty (view))
77 g_print ("view is now empty\n");
78 else
79 g_print ("view is no longer empty\n");
82 int
83 main (int argc,
84 char **argv)
86 GtkWidget *window, *view, *scrolled, *box, *search;
87 EmpathyIndividualManager *mgr;
88 GError *error = NULL;
89 GOptionContext *context;
90 EmpathyRosterModel *model;
92 gtk_init (&argc, &argv);
93 empathy_gtk_init ();
95 context = g_option_context_new ("- test tree model performance");
96 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
97 g_option_context_add_group (context, gtk_get_option_group (TRUE));
98 if (!g_option_context_parse (context, &argc, &argv, &error))
100 g_print ("option parsing failed: %s\n", error->message);
101 return 1;
104 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
106 empathy_set_css_provider (window);
108 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
110 mgr = empathy_individual_manager_dup_singleton ();
112 model = EMPATHY_ROSTER_MODEL (empathy_roster_model_manager_new (mgr));
113 view = empathy_roster_view_new (model);
115 g_object_unref (model);
116 g_signal_connect (view, "individual-activated",
117 G_CALLBACK (individual_activated_cb), NULL);
118 g_signal_connect (view, "popup-individual-menu",
119 G_CALLBACK (popup_individual_menu_cb), NULL);
120 g_signal_connect (view, "notify::empty",
121 G_CALLBACK (empty_cb), NULL);
122 g_signal_connect (view, "individual-tooltip",
123 G_CALLBACK (individual_tooltip_cb), NULL);
125 gtk_widget_set_has_tooltip (view, TRUE);
127 empathy_roster_view_show_offline (EMPATHY_ROSTER_VIEW (view), show_offline);
128 empathy_roster_view_show_groups (EMPATHY_ROSTER_VIEW (view), show_groups);
130 g_object_unref (mgr);
132 search = tpaw_live_search_new (view);
133 empathy_roster_view_set_live_search (EMPATHY_ROSTER_VIEW (view),
134 TPAW_LIVE_SEARCH (search));
136 scrolled = gtk_scrolled_window_new (NULL, NULL);
137 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
138 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
140 gtk_container_add (GTK_CONTAINER (scrolled), view);
142 gtk_box_pack_start (GTK_BOX (box), search, FALSE, TRUE, 0);
143 gtk_box_pack_start (GTK_BOX (box), scrolled, TRUE, TRUE, 0);
144 gtk_container_add (GTK_CONTAINER (window), box);
146 gtk_window_set_default_size (GTK_WINDOW (window), 300, 600);
147 gtk_widget_show_all (window);
149 g_signal_connect_swapped (window, "destroy",
150 G_CALLBACK (gtk_main_quit), NULL);
152 gtk_main ();
154 return 0;