Help: Use stable 'if' namespace instead of experimental
[empathy-mirror.git] / tests / interactive / test-empathy-roster-model-aggregator.c
bloba251096310383bb86473e8cfed2196da41fef8a8
1 #include "config.h"
3 #include "empathy-roster-model-aggregator.h"
4 #include "empathy-roster-model.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 static gboolean
83 filter (EmpathyRosterModel *model,
84 FolksIndividual *individual,
85 gpointer user_data)
87 if (folks_avatar_details_get_avatar (FOLKS_AVATAR_DETAILS (individual))
88 == NULL)
89 return FALSE;
91 return TRUE;
94 int
95 main (int argc,
96 char **argv)
98 GtkWidget *window, *view, *scrolled, *box, *search;
99 GError *error = NULL;
100 GOptionContext *context;
101 EmpathyRosterModel *model;
103 gtk_init (&argc, &argv);
104 empathy_gtk_init ();
106 context = g_option_context_new ("- test tree model performance");
107 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
108 g_option_context_add_group (context, gtk_get_option_group (TRUE));
109 if (!g_option_context_parse (context, &argc, &argv, &error))
111 g_print ("option parsing failed: %s\n", error->message);
112 return 1;
115 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
117 empathy_set_css_provider (window);
119 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
121 model = EMPATHY_ROSTER_MODEL (empathy_roster_model_aggregator_new (
122 filter, NULL));
123 view = empathy_roster_view_new (model);
125 g_object_unref (model);
126 g_signal_connect (view, "individual-activated",
127 G_CALLBACK (individual_activated_cb), NULL);
128 g_signal_connect (view, "popup-individual-menu",
129 G_CALLBACK (popup_individual_menu_cb), NULL);
130 g_signal_connect (view, "notify::empty",
131 G_CALLBACK (empty_cb), NULL);
132 g_signal_connect (view, "individual-tooltip",
133 G_CALLBACK (individual_tooltip_cb), NULL);
135 gtk_widget_set_has_tooltip (view, TRUE);
137 empathy_roster_view_show_offline (EMPATHY_ROSTER_VIEW (view), show_offline);
138 empathy_roster_view_show_groups (EMPATHY_ROSTER_VIEW (view), show_groups);
140 search = tpaw_live_search_new (view);
141 empathy_roster_view_set_live_search (EMPATHY_ROSTER_VIEW (view),
142 TPAW_LIVE_SEARCH (search));
144 scrolled = gtk_scrolled_window_new (NULL, NULL);
145 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
146 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
148 gtk_container_add (GTK_CONTAINER (scrolled), view);
150 gtk_box_pack_start (GTK_BOX (box), search, FALSE, TRUE, 0);
151 gtk_box_pack_start (GTK_BOX (box), scrolled, TRUE, TRUE, 0);
152 gtk_container_add (GTK_CONTAINER (window), box);
154 gtk_window_set_default_size (GTK_WINDOW (window), 300, 600);
155 gtk_widget_show_all (window);
157 g_signal_connect_swapped (window, "destroy",
158 G_CALLBACK (gtk_main_quit), NULL);
160 gtk_main ();
162 return 0;