1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /* test-contact-store.c - Test program for EContactStore.
5 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
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: Hans Petter Jansson <hpj@novell.com>
24 #include <libedataserverui/libedataserverui.h>
27 entry_changed (GtkWidget *entry,
28 EContactStore *contact_store)
33 text = gtk_entry_get_text (GTK_ENTRY (entry));
35 query = e_book_query_any_field_contains (text);
36 e_contact_store_set_query (contact_store, query);
37 e_book_query_unref (query);
40 static GtkTreeViewColumn *
41 create_text_column_for_field (EContactField field_id)
43 GtkTreeViewColumn *column;
44 GtkCellRenderer *cell_renderer;
46 column = gtk_tree_view_column_new ();
47 cell_renderer = GTK_CELL_RENDERER (gtk_cell_renderer_text_new ());
48 gtk_tree_view_column_pack_start (column, cell_renderer, TRUE);
49 gtk_tree_view_column_set_resizable (column, TRUE);
50 gtk_tree_view_column_set_title (column, e_contact_pretty_name (field_id));
51 gtk_tree_view_column_add_attribute (column, cell_renderer, "text", field_id);
52 gtk_tree_view_column_set_sort_column_id (column, field_id);
58 start_test (const gchar *param)
60 EContactStore *contact_store;
61 GtkTreeModel *model_sort;
62 GtkWidget *scrolled_window;
67 GtkTreeViewColumn *column;
68 EBookClient *book_client;
69 EBookQuery *book_query;
71 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
73 vgrid = g_object_new (GTK_TYPE_GRID,
74 "orientation", GTK_ORIENTATION_VERTICAL,
75 "column-homogeneous", FALSE,
78 gtk_container_add (GTK_CONTAINER (window), vgrid);
80 entry = gtk_entry_new ();
81 gtk_widget_set_halign (entry, GTK_ALIGN_FILL);
82 gtk_container_add (GTK_CONTAINER (vgrid), entry);
84 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
85 gtk_widget_set_hexpand (scrolled_window, TRUE);
86 gtk_widget_set_halign (scrolled_window, GTK_ALIGN_FILL);
87 gtk_widget_set_vexpand (scrolled_window, TRUE);
88 gtk_widget_set_valign (scrolled_window, GTK_ALIGN_FILL);
89 gtk_container_add (GTK_CONTAINER (vgrid), scrolled_window);
91 contact_store = e_contact_store_new ();
92 model_sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (contact_store));
93 tree_view = GTK_WIDGET (gtk_tree_view_new ());
94 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model_sort);
96 column = create_text_column_for_field (E_CONTACT_FILE_AS);
97 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
99 column = create_text_column_for_field (E_CONTACT_FULL_NAME);
100 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
102 column = create_text_column_for_field (E_CONTACT_EMAIL_1);
103 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
105 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
107 #if 0 /* ACCOUNT_MGMT */
108 book_client = e_book_client_new_default (NULL);
109 g_warn_if_fail (e_client_open_sync (E_CLIENT (book_client), TRUE, NULL, NULL));
110 e_contact_store_add_client (contact_store, book_client);
111 g_object_unref (book_client);
112 #endif /* ACCOUNT_MGMT */
114 book_query = e_book_query_any_field_contains ("");
115 e_contact_store_set_query (contact_store, book_query);
116 e_book_query_unref (book_query);
118 g_signal_connect (entry, "changed", G_CALLBACK (entry_changed), contact_store);
120 gtk_widget_show_all (window);
131 gtk_init (&argc, &argv);
138 g_idle_add ((GSourceFunc) start_test, (gpointer) param);