1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-source-list-selector.c - Test program for the ESourceListSelector
5 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2 of the GNU Lesser General Public
9 * License as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
21 * Author: Ettore Perazzoli <ettore@ximian.com>
24 #include <libedataserverui/libedataserverui.h>
26 static const gchar *extension_name;
29 dump_selection (ESourceSelector *selector)
31 GSList *selection = e_source_selector_get_selection (selector);
33 g_print ("Current selection:\n");
34 if (selection == NULL) {
35 g_print ("\t(None)\n");
39 for (p = selection; p != NULL; p = p->next) {
40 ESource *source = E_SOURCE (p->data);
41 ESourceBackend *extension;
43 extension = e_source_get_extension (
44 source, extension_name);
47 "\tSource %s (backend %s)\n",
48 e_source_get_display_name (source),
49 e_source_backend_get_backend_name (extension));
53 e_source_selector_free_selection (selection);
57 selection_changed_callback (ESourceSelector *selector)
59 g_print ("Selection changed!\n");
60 dump_selection (selector);
64 on_idle_create_widget (ESourceRegistry *registry)
69 GtkWidget *scrolled_window;
72 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
73 gtk_window_set_default_size (GTK_WINDOW (window), 200, 300);
76 window, "delete-event",
77 G_CALLBACK (gtk_main_quit), NULL);
79 vgrid = g_object_new (GTK_TYPE_GRID,
80 "orientation", GTK_ORIENTATION_VERTICAL,
81 "column-homogeneous", FALSE,
84 gtk_container_add (GTK_CONTAINER (window), vgrid);
86 selector = e_source_selector_new (registry, extension_name);
88 selector, "selection_changed",
89 G_CALLBACK (selection_changed_callback), NULL);
91 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
92 gtk_scrolled_window_set_policy (
93 GTK_SCROLLED_WINDOW (scrolled_window),
94 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
95 gtk_scrolled_window_set_shadow_type (
96 GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
97 gtk_container_add (GTK_CONTAINER (scrolled_window), selector);
98 gtk_widget_set_hexpand (scrolled_window, TRUE);
99 gtk_widget_set_halign (scrolled_window, GTK_ALIGN_FILL);
100 gtk_widget_set_vexpand (scrolled_window, TRUE);
101 gtk_widget_set_valign (scrolled_window, GTK_ALIGN_FILL);
102 gtk_container_add (GTK_CONTAINER (vgrid), scrolled_window);
104 check = gtk_check_button_new_with_label ("Show colors");
105 gtk_widget_set_halign (check, GTK_ALIGN_FILL);
106 gtk_container_add (GTK_CONTAINER (vgrid), check);
108 g_object_bind_property (
109 selector, "show-colors",
111 G_BINDING_BIDIRECTIONAL |
112 G_BINDING_SYNC_CREATE);
114 check = gtk_check_button_new_with_label ("Show toggles");
115 gtk_widget_set_halign (check, GTK_ALIGN_FILL);
116 gtk_container_add (GTK_CONTAINER (vgrid), check);
118 g_object_bind_property (
119 selector, "show-toggles",
121 G_BINDING_BIDIRECTIONAL |
122 G_BINDING_SYNC_CREATE);
124 gtk_widget_show_all (window);
133 ESourceRegistry *registry;
134 GError *error = NULL;
136 gtk_init (&argc, &argv);
139 extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
141 extension_name = argv[1];
143 registry = e_source_registry_new_sync (NULL, &error);
147 "Failed to load ESource registry: %s",
149 g_assert_not_reached ();
152 g_idle_add ((GSourceFunc) on_idle_create_widget, registry);