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) 2002 Ximian, Inc.
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>
28 #include "e-source-selector.h"
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>
37 dump_selection (ESourceSelector *selector)
39 GSList *selection = e_source_selector_get_selection (selector);
41 g_print ("Current selection:\n");
42 if (selection == NULL) {
43 g_print ("\t(None)\n");
47 for (p = selection; p != NULL; p = p->next) {
48 ESource *source = E_SOURCE (p->data);
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)));
56 e_source_selector_free_selection (selection);
60 selection_changed_callback (ESourceSelector *selector,
63 g_print ("Selection changed!\n");
64 dump_selection (selector);
68 check_toggled_callback (GtkToggleButton *button,
69 ESourceSelector *selector)
71 e_source_selector_show_selection (selector, gtk_toggle_button_get_active (button));
75 on_idle_create_widget (const char *gconf_path)
80 GtkWidget *scrolled_window;
83 GConfClient *gconf_client;
85 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
86 gtk_window_set_default_size (GTK_WINDOW (window), 200, 300);
88 vbox = gtk_vbox_new (FALSE, 3);
89 gtk_container_add (GTK_CONTAINER (window), vbox);
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);
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);
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);
108 gtk_widget_show_all (window);
110 g_object_unref (gconf_client);
116 main (int argc, char **argv)
118 const char *gconf_path;
120 gtk_init (&argc, &argv);
122 gconf_path = "/apps/evolution/calendar/sources";
124 gconf_path = argv [1];
126 g_idle_add ((GSourceFunc) on_idle_create_widget, (void *) gconf_path);