~lucio.torre/ubuntuone-client/windows-port

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
 *
 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "u1-contacts-picker.h"

static void
dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer data)
{
	GtkWidget *picker = GTK_WIDGET (data);

	if (response_id == GTK_RESPONSE_OK) {
		GSList *selection, *l;
		GtkWidget *msg_dialog;
		GString *str = NULL;

		selection = u1_contacts_picker_get_selected_emails (U1_CONTACTS_PICKER (picker));
		for (l = selection; l != NULL; l = l->next) {
			if (str == NULL) {
				str = g_string_new ("Selected items:\n\t");
				str = g_string_append (str, (const gchar *) l->data);
			} else {
				str = g_string_append (str, "\n\t");
				str = g_string_append (str, (const gchar *) l->data);
			}
		}

		u1_contacts_picker_free_selection_list (selection);

		/* Display selection to the user */
		if (str != NULL) {
			msg_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
							     0,
							     GTK_MESSAGE_INFO,
							     GTK_BUTTONS_OK,
							     "%s", str->str);
			g_string_free (str, FALSE);
		} else {
			msg_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
							     0,
							     GTK_MESSAGE_INFO,
							     GTK_BUTTONS_OK,
							     "Nothing has been selected");
		}

		gtk_dialog_run (GTK_DIALOG (msg_dialog));
	}

	gtk_main_quit ();
}

int
main (int argc, char *argv[])
{
	GtkWidget *window, *picker;

	gtk_init (&argc, &argv);
	g_thread_init (NULL);

	/* Create the main window */
	window = gtk_dialog_new_with_buttons ("Test contacts picker",
					      NULL,
					      GTK_DIALOG_NO_SEPARATOR,
					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					      GTK_STOCK_OK, GTK_RESPONSE_OK,
					      NULL);
	gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_OK);

	picker = u1_contacts_picker_new ();
	gtk_widget_show (picker);
	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), picker, TRUE, TRUE, 6);

	g_signal_connect (G_OBJECT (window), "response", G_CALLBACK (dialog_response_cb), picker);
	
	/* Run the application */
	gtk_widget_show (window);
	gtk_widget_set_size_request (window, 400, 250);
	gtk_main ();

	return 0;
}