evolution-3.6.4/widgets/misc/test-dateedit.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Damon Chaplin <damon@ximian.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 /*
 24  * test-dateedit - tests the EDateEdit widget.
 25  */
 26 
 27 #ifdef HAVE_CONFIG_H
 28 #include <config.h>
 29 #endif
 30 
 31 #include <gtk/gtk.h>
 32 #include "e-dateedit.h"
 33 
 34 static void delete_event_cb		(GtkWidget	*widget,
 35 					 GdkEventAny	*event,
 36 					 GtkWidget	*window);
 37 static void on_get_date_clicked		(GtkWidget	*button,
 38 					 EDateEdit	*dedit);
 39 static void on_toggle_24_hour_clicked	(GtkWidget	*button,
 40 					 EDateEdit	*dedit);
 41 static void on_changed			(EDateEdit	*dedit,
 42 					 gchar		*name);
 43 #if 0
 44 static void on_date_changed		(EDateEdit	*dedit,
 45 					 gchar		*name);
 46 static void on_time_changed		(EDateEdit	*dedit,
 47 					 gchar		*name);
 48 #endif
 49 
 50 gint
 51 main (gint argc,
 52       gchar **argv)
 53 {
 54 	GtkWidget *window;
 55 	EDateEdit *dedit;
 56 	GtkWidget *table, *button;
 57 
 58 	gtk_init (&argc, &argv);
 59 
 60 	puts ("here");
 61 
 62 	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 63 	gtk_window_set_title (GTK_WINDOW (window), "EDateEdit Test");
 64 	gtk_window_set_default_size (GTK_WINDOW (window), 300, 200);
 65 	gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
 66 	gtk_container_set_border_width (GTK_CONTAINER (window), 8);
 67 
 68 	g_signal_connect (
 69 		window, "delete_event",
 70 		G_CALLBACK (delete_event_cb), window);
 71 
 72 	table = gtk_table_new (3, 3, FALSE);
 73 	gtk_table_set_row_spacings (GTK_TABLE (table), 4);
 74 	gtk_table_set_col_spacings (GTK_TABLE (table), 4);
 75 	gtk_widget_show (table);
 76 
 77 	gtk_container_add (GTK_CONTAINER (window), table);
 78 
 79 	/* EDateEdit 1. */
 80 	dedit = E_DATE_EDIT (e_date_edit_new ());
 81 	gtk_table_attach (
 82 		GTK_TABLE (table), GTK_WIDGET (dedit),
 83 		0, 1, 0, 1, GTK_FILL, GTK_EXPAND, 0, 0);
 84 	gtk_widget_show (GTK_WIDGET (dedit));
 85 
 86 #if 0
 87 	g_signal_connect (
 88 		dedit, "date_changed",
 89 		G_CALLBACK (on_date_changed), (gpointer) "1");
 90 	g_signal_connect (
 91 		dedit, "time_changed",
 92 		G_CALLBACK (on_time_changed), (gpointer) "1");
 93 #else
 94 	g_signal_connect (
 95 		dedit, "changed",
 96 		G_CALLBACK (on_changed), (gpointer) "1");
 97 #endif
 98 
 99 	button = gtk_button_new_with_label ("Print Date");
100 	gtk_table_attach (
101 		GTK_TABLE (table), button,
102 		1, 2, 0, 1, 0, 0, 0, 0);
103 	gtk_widget_show (button);
104 	g_signal_connect (
105 		button, "clicked",
106 		G_CALLBACK (on_get_date_clicked), dedit);
107 
108 	/* EDateEdit 2. */
109 	dedit = E_DATE_EDIT (e_date_edit_new ());
110 	gtk_table_attach (
111 		GTK_TABLE (table), (GtkWidget *) dedit,
112 		0, 1, 1, 2, GTK_FILL, GTK_EXPAND, 0, 0);
113 	gtk_widget_show ((GtkWidget *) (dedit));
114 	e_date_edit_set_week_start_day (dedit, 1);
115 	e_date_edit_set_show_week_numbers (dedit, TRUE);
116 	e_date_edit_set_use_24_hour_format (dedit, FALSE);
117 	e_date_edit_set_time_popup_range (dedit, 8, 18);
118 	e_date_edit_set_show_time (dedit, FALSE);
119 
120 #if 0
121 	g_signal_connect (
122 		dedit, "date_changed",
123 		G_CALLBACK (on_date_changed), (gpointer) "2");
124 	g_signal_connect (
125 		dedit, "time_changed",
126 		G_CALLBACK (on_time_changed), (gpointer) "2");
127 #else
128 	g_signal_connect (
129 		dedit, "changed",
130 		G_CALLBACK (on_changed), (gpointer) "2");
131 #endif
132 
133 	button = gtk_button_new_with_label ("Print Date");
134 	gtk_table_attach (
135 		GTK_TABLE (table), button,
136 		1, 2, 1, 2, 0, 0, 0, 0);
137 	gtk_widget_show (button);
138 	g_signal_connect (
139 		button, "clicked",
140 		G_CALLBACK (on_get_date_clicked), dedit);
141 
142 	/* EDateEdit 3. */
143 	dedit = E_DATE_EDIT (e_date_edit_new ());
144 	gtk_table_attach (
145 		GTK_TABLE (table), (GtkWidget *) dedit,
146 		0, 1, 2, 3, GTK_FILL, GTK_EXPAND, 0, 0);
147 	gtk_widget_show ((GtkWidget *) (dedit));
148 	e_date_edit_set_week_start_day (dedit, 1);
149 	e_date_edit_set_show_week_numbers (dedit, TRUE);
150 	e_date_edit_set_use_24_hour_format (dedit, FALSE);
151 	e_date_edit_set_time_popup_range (dedit, 8, 18);
152 	e_date_edit_set_allow_no_date_set (dedit, TRUE);
153 
154 #if 0
155 	g_signal_connect (
156 		dedit, "date_changed",
157 		G_CALLBACK (on_date_changed), (gpointer) "3");
158 	g_signal_connect (
159 		dedit, "time_changed",
160 		G_CALLBACK (on_time_changed), (gpointer) "3");
161 #else
162 	g_signal_connect (
163 		dedit, "changed",
164 		G_CALLBACK (on_changed), (gpointer) "3");
165 #endif
166 
167 	button = gtk_button_new_with_label ("Print Date");
168 	gtk_table_attach (
169 		GTK_TABLE (table), button,
170 		1, 2, 2, 3, 0, 0, 0, 0);
171 	gtk_widget_show (button);
172 	g_signal_connect (
173 		button, "clicked",
174 		G_CALLBACK (on_get_date_clicked), dedit);
175 
176 	button = gtk_button_new_with_label ("Toggle 24-hour");
177 	gtk_table_attach (
178 		GTK_TABLE (table), button,
179 		2, 3, 2, 3, 0, 0, 0, 0);
180 	gtk_widget_show (button);
181 	g_signal_connect (
182 		button, "clicked",
183 		G_CALLBACK (on_toggle_24_hour_clicked), dedit);
184 
185 	gtk_widget_show (window);
186 
187 	gtk_main ();
188 
189 	return 0;
190 }
191 
192 static void
193 delete_event_cb (GtkWidget *widget,
194                  GdkEventAny *event,
195                  GtkWidget *window)
196 {
197 	gtk_widget_destroy (window);
198 
199 	gtk_main_quit ();
200 }
201 
202 static void
203 on_get_date_clicked (GtkWidget *button,
204                      EDateEdit *dedit)
205 {
206 	time_t t;
207 
208 	t = e_date_edit_get_time (dedit);
209 	if (t == -1)
210 		g_print ("Time: None\n");
211 	else
212 		g_print ("Time: %s", ctime (&t));
213 
214 	if (!e_date_edit_date_is_valid (dedit))
215 		g_print ("  Date invalid\n");
216 
217 	if (!e_date_edit_time_is_valid (dedit))
218 		g_print ("  Time invalid\n");
219 }
220 
221 static void
222 on_toggle_24_hour_clicked (GtkWidget *button,
223                            EDateEdit *dedit)
224 {
225 	gboolean use_24_hour_format;
226 
227 	use_24_hour_format = e_date_edit_get_use_24_hour_format (dedit);
228 	e_date_edit_set_use_24_hour_format (dedit, !use_24_hour_format);
229 }
230 
231 #if 0
232 static void
233 on_date_changed (EDateEdit *dedit,
234                  gchar *name)
235 {
236 	gint year, month, day;
237 
238 	if (e_date_edit_date_is_valid (dedit)) {
239 		if (e_date_edit_get_date (dedit, &year, &month, &day)) {
240 			g_print (
241 				"Date %s changed to: %i/%i/%i (M/D/Y)\n",
242 				name, month, day, year);
243 		} else {
244 			g_print ("Date %s changed to: None\n", name);
245 		}
246 	} else {
247 		g_print ("Date %s changed to: Not Valid\n", name);
248 	}
249 }
250 
251 static void
252 on_time_changed (EDateEdit *dedit,
253                  gchar *name)
254 {
255 	gint hour, minute;
256 
257 	if (e_date_edit_time_is_valid (dedit)) {
258 		if (e_date_edit_get_time_of_day (dedit, &hour, &minute)) {
259 			g_print (
260 				"Time %s changed to: %02i:%02i\n", name,
261 				hour, minute);
262 		} else {
263 			g_print ("Time %s changed to: None\n", name);
264 		}
265 	} else {
266 		g_print ("Time %s changed to: Not Valid\n", name);
267 	}
268 }
269 #endif
270 
271 static void
272 on_changed (EDateEdit *dedit,
273             gchar *name)
274 {
275 	gint year, month, day, hour, minute;
276 
277 	g_print ("Date %s changed ", name);
278 
279 	if (e_date_edit_date_is_valid (dedit)) {
280 		if (e_date_edit_get_date (dedit, &year, &month, &day)) {
281 			g_print ("M/D/Y: %i/%i/%i", month, day, year);
282 		} else {
283 			g_print ("None");
284 		}
285 	} else {
286 		g_print ("Date Invalid");
287 	}
288 
289 	if (e_date_edit_time_is_valid (dedit)) {
290 		if (e_date_edit_get_time_of_day (dedit, &hour, &minute)) {
291 			g_print (" %02i:%02i\n", hour, minute);
292 		} else {
293 			g_print (" None\n");
294 		}
295 	} else {
296 		g_print (" Time Invalid\n");
297 	}
298 }