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) 2004 Novell, 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: Hans Petter Jansson <hpj@novell.com>
28 #include "e-contact-store.h"
32 entry_changed (GtkWidget *entry, EContactStore *contact_store)
37 text = gtk_entry_get_text (GTK_ENTRY (entry));
39 query = e_book_query_any_field_contains (text);
40 e_contact_store_set_query (contact_store, query);
41 e_book_query_unref (query);
44 static GtkTreeViewColumn *
45 create_text_column_for_field (EContactField field_id)
47 GtkTreeViewColumn *column;
48 GtkCellRenderer *cell_renderer;
50 column = gtk_tree_view_column_new ();
51 cell_renderer = GTK_CELL_RENDERER (gtk_cell_renderer_text_new ());
52 gtk_tree_view_column_pack_start (column, cell_renderer, TRUE);
53 gtk_tree_view_column_set_resizable (column, TRUE);
54 gtk_tree_view_column_set_title (column, e_contact_pretty_name (field_id));
55 gtk_tree_view_column_add_attribute (column, cell_renderer, "text", field_id);
56 gtk_tree_view_column_set_sort_column_id (column, field_id);
62 start_test (const char *gconf_path)
64 EContactStore *contact_store;
65 GtkTreeModel *model_sort;
66 GtkWidget *scrolled_window;
71 GtkTreeViewColumn *column;
73 EBookQuery *book_query;
75 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
77 box = gtk_vbox_new (FALSE, 2);
78 gtk_container_add (GTK_CONTAINER (window), box);
80 entry = gtk_entry_new ();
81 gtk_box_pack_start (GTK_BOX (box), entry, FALSE, TRUE, 0);
83 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
84 gtk_box_pack_start (GTK_BOX (box), scrolled_window, TRUE, TRUE, 0);
86 contact_store = e_contact_store_new ();
87 model_sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (contact_store));
88 tree_view = GTK_WIDGET (gtk_tree_view_new ());
89 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model_sort);
91 column = create_text_column_for_field (E_CONTACT_FILE_AS);
92 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
94 column = create_text_column_for_field (E_CONTACT_FULL_NAME);
95 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
97 column = create_text_column_for_field (E_CONTACT_EMAIL_1);
98 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
100 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
102 book = e_book_new_default_addressbook (NULL);
103 e_book_open (book, TRUE, NULL);
104 e_contact_store_add_book (contact_store, book);
105 g_object_unref (book);
107 book_query = e_book_query_any_field_contains ("");
108 e_contact_store_set_query (contact_store, book_query);
109 e_book_query_unref (book_query);
111 g_signal_connect (entry, "changed", G_CALLBACK (entry_changed), contact_store);
113 gtk_widget_show_all (window);
119 main (int argc, char **argv)
121 const char *gconf_path;
123 gtk_init (&argc, &argv);
126 gconf_path = "/apps/evolution/addressbook/sources";
128 gconf_path = argv [1];
130 g_idle_add ((GSourceFunc) start_test, (void *) gconf_path);