Assamese translation updated
[platform/upstream/evolution-data-server.git] / tests / libedataserverui / test-source-selector.c
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
3  * widget.
4  *
5  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
6  *
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.
10  *
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.
15  *
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.
20  *
21  * Author: Ettore Perazzoli <ettore@ximian.com>
22  */
23
24 #include <libedataserverui/libedataserverui.h>
25
26 static const gchar *extension_name;
27
28 static void
29 dump_selection (ESourceSelector *selector)
30 {
31         GSList *selection = e_source_selector_get_selection (selector);
32
33         g_print ("Current selection:\n");
34         if (selection == NULL) {
35                 g_print ("\t(None)\n");
36         } else {
37                 GSList *p;
38
39                 for (p = selection; p != NULL; p = p->next) {
40                         ESource *source = E_SOURCE (p->data);
41                         ESourceBackend *extension;
42
43                         extension = e_source_get_extension (
44                                 source, extension_name);
45
46                         g_print (
47                                 "\tSource %s (backend %s)\n",
48                                 e_source_get_display_name (source),
49                                 e_source_backend_get_backend_name (extension));
50                 }
51         }
52
53         e_source_selector_free_selection (selection);
54 }
55
56 static void
57 selection_changed_callback (ESourceSelector *selector)
58 {
59         g_print ("Selection changed!\n");
60         dump_selection (selector);
61 }
62
63 static gint
64 on_idle_create_widget (ESourceRegistry *registry)
65 {
66         GtkWidget *window;
67         GtkWidget *vgrid;
68         GtkWidget *selector;
69         GtkWidget *scrolled_window;
70         GtkWidget *check;
71
72         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
73         gtk_window_set_default_size (GTK_WINDOW (window), 200, 300);
74
75         g_signal_connect (
76                 window, "delete-event",
77                 G_CALLBACK (gtk_main_quit), NULL);
78
79         vgrid = g_object_new (GTK_TYPE_GRID,
80                 "orientation", GTK_ORIENTATION_VERTICAL,
81                 "column-homogeneous", FALSE,
82                 "row-spacing", 6,
83                 NULL);
84         gtk_container_add (GTK_CONTAINER (window), vgrid);
85
86         selector = e_source_selector_new (registry, extension_name);
87         g_signal_connect (
88                 selector, "selection_changed",
89                 G_CALLBACK (selection_changed_callback), NULL);
90
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);
103
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);
107
108         g_object_bind_property (
109                 selector, "show-colors",
110                 check, "active",
111                 G_BINDING_BIDIRECTIONAL |
112                 G_BINDING_SYNC_CREATE);
113
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);
117
118         g_object_bind_property (
119                 selector, "show-toggles",
120                 check, "active",
121                 G_BINDING_BIDIRECTIONAL |
122                 G_BINDING_SYNC_CREATE);
123
124         gtk_widget_show_all (window);
125
126         return FALSE;
127 }
128
129 gint
130 main (gint argc,
131       gchar **argv)
132 {
133         ESourceRegistry *registry;
134         GError *error = NULL;
135
136         gtk_init (&argc, &argv);
137
138         if (argc < 2)
139                 extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
140         else
141                 extension_name = argv[1];
142
143         registry = e_source_registry_new_sync (NULL, &error);
144
145         if (error != NULL) {
146                 g_error (
147                         "Failed to load ESource registry: %s",
148                         error->message);
149                 g_assert_not_reached ();
150         }
151
152         g_idle_add ((GSourceFunc) on_idle_create_widget, registry);
153
154         gtk_main ();
155
156         return 0;
157 }