Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / 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) 2002 Ximian, Inc.
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 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "e-source-selector.h"
29
30 #include <gtk/gtkmain.h>
31 #include <gtk/gtkcheckbutton.h>
32 #include <gtk/gtkvbox.h>
33 #include <gtk/gtkscrolledwindow.h>
34 #include <gtk/gtkwindow.h>
35
36 static void
37 dump_selection (ESourceSelector *selector)
38 {
39         GSList *selection = e_source_selector_get_selection (selector);
40
41         g_print ("Current selection:\n");
42         if (selection == NULL) {
43                 g_print ("\t(None)\n");
44         } else {
45                 GSList *p;
46
47                 for (p = selection; p != NULL; p = p->next) {
48                         ESource *source = E_SOURCE (p->data);
49
50                         g_print ("\tSource %s (group %s)\n",
51                                  e_source_peek_name (source),
52                                  e_source_group_peek_name (e_source_peek_group (source)));
53                 }
54         }
55
56         e_source_selector_free_selection (selection);
57 }
58
59 static void
60 selection_changed_callback (ESourceSelector *selector,
61                             void *unused_data)
62 {
63         g_print ("Selection changed!\n");
64         dump_selection (selector);
65 }
66
67 static void
68 check_toggled_callback (GtkToggleButton *button,
69                         ESourceSelector *selector)
70 {
71         e_source_selector_show_selection (selector, gtk_toggle_button_get_active (button));
72 }
73
74 static int
75 on_idle_create_widget (const char *gconf_path)
76 {
77         GtkWidget *window;
78         GtkWidget *vbox;
79         GtkWidget *selector;
80         GtkWidget *scrolled_window;
81         GtkWidget *check;
82         ESourceList *list;
83         GConfClient *gconf_client;
84
85         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
86         gtk_window_set_default_size (GTK_WINDOW (window), 200, 300);
87
88         vbox = gtk_vbox_new (FALSE, 3);
89         gtk_container_add (GTK_CONTAINER (window), vbox);
90
91         gconf_client = gconf_client_get_default ();
92         list = e_source_list_new_for_gconf (gconf_client, gconf_path);
93         selector = e_source_selector_new (list);
94         g_signal_connect (selector, "selection_changed", G_CALLBACK (selection_changed_callback), NULL);
95
96         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
97         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
98         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
99         gtk_container_add (GTK_CONTAINER (scrolled_window), selector);
100         gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 3);
101
102         check = gtk_check_button_new_with_label ("Show checkboxes");
103         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
104                                       e_source_selector_selection_shown (E_SOURCE_SELECTOR (selector)));
105         g_signal_connect (check, "toggled", G_CALLBACK (check_toggled_callback), selector);
106         gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, TRUE, 3);
107
108         gtk_widget_show_all (window);
109
110         g_object_unref (gconf_client);
111         return FALSE;
112 }
113
114
115 int
116 main (int argc, char **argv)
117 {
118         const char *gconf_path;
119
120         gtk_init (&argc, &argv);
121         if (argc < 2)
122                 gconf_path = "/apps/evolution/calendar/sources";
123         else
124                 gconf_path = argv [1];
125
126         g_idle_add ((GSourceFunc) on_idle_create_widget, (void *) gconf_path);
127
128         gtk_main ();
129
130         return 0;
131 }