Assamese translation updated
[platform/upstream/evolution-data-server.git] / tests / libedataserverui / test-source-combo-box.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-source-combo-box.c - Test for ESourceComboBox.
3  *
4  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  * Author: Ettore Perazzoli <ettore@ximian.com>
21  */
22
23 #include <config.h>
24 #include <gtk/gtk.h>
25
26 #include <libedataserverui/libedataserverui.h>
27
28 static const gchar *extension_name;
29
30 static void
31 source_changed_cb (ESourceComboBox *combo_box)
32 {
33         ESource *source;
34
35         source = e_source_combo_box_ref_active (combo_box);
36         if (source != NULL) {
37                 const gchar *display_name;
38                 display_name = e_source_get_display_name (source);
39                 g_print ("source selected: \"%s\"\n", display_name);
40                 g_object_unref (source);
41         } else {
42                 g_print ("source selected: (none)\n");
43         }
44 }
45
46 static gint
47 on_idle_create_widget (ESourceRegistry *registry)
48 {
49         GtkWidget *window;
50         GtkWidget *box;
51         GtkWidget *combo_box;
52         GtkWidget *button;
53
54         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
55
56         box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
57         gtk_container_add (GTK_CONTAINER (window), box);
58
59         combo_box = e_source_combo_box_new (registry, extension_name);
60         g_signal_connect (
61                 combo_box, "changed",
62                 G_CALLBACK (source_changed_cb), NULL);
63         gtk_box_pack_start (GTK_BOX (box), combo_box, FALSE, FALSE, 0);
64
65         button = gtk_toggle_button_new_with_label ("Show Colors");
66         gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
67
68         g_object_bind_property (
69                 combo_box, "show-colors",
70                 button, "active",
71                 G_BINDING_SYNC_CREATE |
72                 G_BINDING_BIDIRECTIONAL);
73
74         gtk_widget_show_all (window);
75
76         return FALSE;
77 }
78
79 gint
80 main (gint argc,
81       gchar **argv)
82 {
83         ESourceRegistry *registry;
84         GError *error = NULL;
85
86         gtk_init (&argc, &argv);
87
88         if (argc < 2)
89                 extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
90         else
91                 extension_name = argv[1];
92
93         registry = e_source_registry_new_sync (NULL, &error);
94
95         if (error != NULL) {
96                 g_error (
97                         "Failed to load ESource registry: %s",
98                         error->message);
99                 g_assert_not_reached ();
100         }
101
102         g_idle_add ((GSourceFunc) on_idle_create_widget, registry);
103
104         gtk_main ();
105
106         return 0;
107 }