Adapt ENameSelector to the new ESource API.
[platform/upstream/evolution-data-server.git] / tests / libedataserverui / test-name-selector.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3 /* test-name-selector.c - Test for name selector components.
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: Hans Petter Jansson <hpj@novell.com>
22  */
23
24 #include <libedataserverui/e-name-selector-model.h>
25 #include <libedataserverui/e-name-selector-dialog.h>
26 #include <libedataserverui/e-name-selector-entry.h>
27 #include <camel/camel.h>
28
29 static ENameSelectorDialog *name_selector_dialog;
30 static GtkWidget           *name_selector_entry_window;
31
32 static void
33 close_dialog (GtkWidget *widget,
34               gint response,
35               gpointer data)
36 {
37         gtk_widget_destroy (GTK_WIDGET (name_selector_dialog));
38         gtk_widget_destroy (name_selector_entry_window);
39
40         g_timeout_add (4000, (GSourceFunc) gtk_main_quit, NULL);
41 }
42
43 static gboolean
44 start_test (ESourceRegistry *registry)
45 {
46         ENameSelectorModel  *name_selector_model;
47         ENameSelectorEntry  *name_selector_entry;
48         EDestinationStore   *destination_store;
49         GtkWidget           *container;
50
51         destination_store = e_destination_store_new ();
52         name_selector_model = e_name_selector_model_new ();
53
54         e_name_selector_model_add_section (name_selector_model, "to", "To", destination_store);
55         e_name_selector_model_add_section (name_selector_model, "cc", "Cc", NULL);
56         e_name_selector_model_add_section (name_selector_model, "bcc", "Bcc", NULL);
57
58         name_selector_dialog = e_name_selector_dialog_new (registry);
59         e_name_selector_dialog_set_model (name_selector_dialog, name_selector_model);
60         gtk_window_set_modal (GTK_WINDOW (name_selector_dialog), FALSE);
61
62         name_selector_entry = e_name_selector_entry_new (registry);
63         e_name_selector_entry_set_destination_store (name_selector_entry, destination_store);
64
65         g_signal_connect (name_selector_dialog, "response", G_CALLBACK (close_dialog), name_selector_dialog);
66         gtk_widget_show (GTK_WIDGET (name_selector_dialog));
67
68         container = gtk_window_new (GTK_WINDOW_TOPLEVEL);
69         gtk_container_add (GTK_CONTAINER (container), GTK_WIDGET (name_selector_entry));
70         gtk_widget_show_all (container);
71
72         name_selector_entry_window = container;
73
74         g_object_unref (name_selector_model);
75         g_object_unref (destination_store);
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         camel_init (NULL, 0);
89
90         registry = e_source_registry_new_sync (NULL, &error);
91
92         if (error != NULL) {
93                 g_error ("Failed to load ESource registry: %s",
94                         error->message);
95                 g_assert_not_reached ();
96         }
97
98         g_idle_add ((GSourceFunc) start_test, registry);
99
100         gtk_main ();
101
102         return 0;
103 }