test-nautilus-widgets.c 6.89 KB
Newer Older
1

2
#include <config.h>
3
4
5
6
7
8

#include "nautilus-caption-table.h"
#include "nautilus-password-dialog.h"
#include "nautilus-radio-button-group.h"
#include "nautilus-string-picker.h"
#include "nautilus-text-caption.h"
9

10
11
#include <gtk/gtk.h>

12
13
static void test_radio_group                     (void);
static void test_caption_table                   (void);
14
static void test_password_dialog                 (void);
15
static void test_string_picker                   (void);
16
17
18
static void test_text_caption                    (void);

/* Callbacks */
19
20
21
22
static void test_radio_changed_callback          (GtkWidget *button_group,
						  gpointer   user_data);
static void test_authenticate_boink_callback     (GtkWidget *button,
						  gpointer   user_data);
23
24
25
static void string_picker_changed_callback       (GtkWidget *string_picker,
						  gpointer   user_data);
static void text_caption_changed_callback        (GtkWidget *text_caption,
26
27
28
29
						  gpointer   user_data);
static void test_caption_table_activate_callback (GtkWidget *button_group,
						  gint       active_index,
						  gpointer   user_data);
30

31
32
33
int
main (int argc, char * argv[])
{
34
	gnome_init ("foo", "bar", argc, argv);
35

36
	test_radio_group ();
37
	test_caption_table ();
38
	test_password_dialog ();
39
	test_string_picker ();
40
	test_text_caption ();
41

42
43
44
45
46
47
48
49
50
51
52
	gtk_main ();

	return 0;
}

static void
test_radio_group (void)
{
	GtkWidget * window;
	GtkWidget * buttons;

53

54
55
56
57
58
59
60
61
62
63
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	buttons = nautilus_radio_button_group_new ();

	nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Apples");
	nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Oranges");
	nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (buttons), "Strawberries");

	gtk_signal_connect (GTK_OBJECT (buttons),
			    "changed",
64
			    GTK_SIGNAL_FUNC (test_radio_changed_callback),
65
66
67
68
69
70
71
72
73
			    (gpointer) NULL);

	gtk_container_add (GTK_CONTAINER (window), buttons);

	gtk_widget_show (buttons);

	gtk_widget_show (window);
}

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
static void
test_caption_table (void)
{
	GtkWidget * window;
	GtkWidget * table;

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	table = nautilus_caption_table_new (4);

	nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (table),
					     0,
					     "Something",
					     "Text",
					     TRUE,
					     FALSE);

	nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (table),
					     1,
					     "ReadOnly",
					     "Cant Change Me",
					     TRUE,
					     TRUE);

	nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (table),
					     2,
					     "Password",
					     "sekret",
					     FALSE,
					     FALSE);

	nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (table),
					     3,
					     "This is a very long label",
					     "Text",
					     TRUE,
					     FALSE);

	gtk_signal_connect (GTK_OBJECT (table),
			    "activate",
			    GTK_SIGNAL_FUNC (test_caption_table_activate_callback),
			    (gpointer) NULL);

	gtk_container_add (GTK_CONTAINER (window), table);

	gtk_widget_show (table);

	gtk_widget_show (window);
}

124
125
126
127
128
129
130
131
132
133
134
static void
test_string_picker (void)
{
	GtkWidget		*window;
	GtkWidget		*picker;
	NautilusStringList	*font_list;
	
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	picker = nautilus_string_picker_new ();
	
135
	nautilus_caption_set_title_label (NAUTILUS_CAPTION (picker), "Icon Font Family:");
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

	font_list = nautilus_string_list_new ();

	nautilus_string_list_insert (font_list, "Helvetica");
	nautilus_string_list_insert (font_list, "Times");
	nautilus_string_list_insert (font_list, "Courier");
	nautilus_string_list_insert (font_list, "Lucida");
	nautilus_string_list_insert (font_list, "Fixed");

	nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (picker), font_list);

	nautilus_string_list_free (font_list);

	gtk_container_add (GTK_CONTAINER (window), picker);

	gtk_signal_connect (GTK_OBJECT (picker),
			    "changed",
			    GTK_SIGNAL_FUNC (string_picker_changed_callback),
			    (gpointer) NULL);

	gtk_widget_show_all (window);
}

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
static void
test_text_caption (void)
{
	GtkWidget		*window;
	GtkWidget		*picker;
	
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	picker = nautilus_text_caption_new ();
	
	nautilus_caption_set_title_label (NAUTILUS_CAPTION (picker), "Home Page:");

	nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (picker), "file:///tmp");
	
	gtk_container_add (GTK_CONTAINER (window), picker);
	
	gtk_signal_connect (GTK_OBJECT (picker),
			    "changed",
			    GTK_SIGNAL_FUNC (text_caption_changed_callback),
			    (gpointer) NULL);

	gtk_widget_show_all (window);
}

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
static void
test_authenticate_boink_callback (GtkWidget *button, gpointer user_data)
{
	GtkWidget *dialog;
	gboolean  rv;
	char	  *username;
	char	  *password;

	dialog = nautilus_password_dialog_new ("Authenticate Me",
					       "foouser",
					       "sekret",
					       FALSE);

	rv = nautilus_password_dialog_run_and_block (NAUTILUS_PASSWORD_DIALOG (dialog));

	username = nautilus_password_dialog_get_username (NAUTILUS_PASSWORD_DIALOG (dialog));
	password = nautilus_password_dialog_get_password (NAUTILUS_PASSWORD_DIALOG (dialog));

	g_assert (username != NULL);
	g_assert (password != NULL);

	g_print ("test_authenticate_boink_callback (rv=%d , username='%s' , password='%s')\n",
		 rv,
		 username,
		 password);

	g_free (username);
	g_free (password);
}

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
static void
string_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
{
	char	  *text;

	g_assert (string_picker != NULL);
	g_assert (NAUTILUS_IS_STRING_PICKER (string_picker));

	text = nautilus_string_picker_get_text (NAUTILUS_STRING_PICKER (string_picker));

	g_print ("string_picker_changed_callback(%s)\n", text);
	
	g_free (text);
}

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
static void
text_caption_changed_callback (GtkWidget *text_caption, gpointer user_data)
{
	char	  *text;

	g_assert (text_caption != NULL);
	g_assert (NAUTILUS_IS_TEXT_CAPTION (text_caption));

	text = nautilus_text_caption_get_text (NAUTILUS_TEXT_CAPTION (text_caption));

	g_print ("text_caption_changed_callback(%s)\n", text);
	
	g_free (text);
}

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
static void
test_password_dialog (void)
{
	GtkWidget * window;
	GtkWidget * button;

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	button = gtk_button_new_with_label ("Boink me to authenticate");

	gtk_signal_connect (GTK_OBJECT (button),
			    "clicked",
			    GTK_SIGNAL_FUNC (test_authenticate_boink_callback),
			    (gpointer) NULL);

	gtk_container_add (GTK_CONTAINER (window), button);

	gtk_widget_show (button);

	gtk_widget_show (window);
}

265
static void
266
test_radio_changed_callback (GtkWidget *buttons, gpointer user_data)
267
268
269
270
271
{
	gint i;

	i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons));

272
273
274
275
276
277
278
279
280
	g_print ("test_radio_changed_callback (%d)\n", i);
}

static void
test_caption_table_activate_callback (GtkWidget  *button_group,
				      gint        active_index,
				      gpointer    user_data)
{
	g_print ("test_caption_table_activate_callback (active_index=%d)\n", active_index);
281
}