2008-08-06 Claudio Saavedra <csaavedra@igalia.com>
[hildon] / src / hildon-date-selector.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2005, 2008 Nokia Corporation.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version. or (at your option) any later version.
10  *
11  * This library 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  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 /**
22  * SECTION:hildon-date-selector
23  * @short_description: A widget to select the current date.
24  *
25  * HildonDateSelector is a date widget, equivalent to hildon-calendar, but with a multi-column
26  * approach
27  *
28  */
29
30
31 #include "hildon-date-selector.h"
32
33 #define _GNU_SOURCE     /* needed for GNU nl_langinfo_l */
34 #define __USE_GNU       /* needed for locale */
35
36 #ifdef HAVE_SYS_TIME_H
37 #include <sys/time.h>
38 #endif
39
40 #include <string.h>
41 #include <stdlib.h>
42
43 #include <libintl.h>
44 #include <time.h>
45 #include <langinfo.h>
46 #include <locale.h>
47
48 #define HILDON_DATE_SELECTOR_GET_PRIVATE(obj)                           \
49   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_DATE_SELECTOR, HildonDateSelectorPrivate))
50
51 G_DEFINE_TYPE (HildonDateSelector, hildon_date_selector, HILDON_TYPE_TOUCH_SELECTOR)
52
53 #define INIT_YEAR 100
54 #define LAST_YEAR 50    /* since current year */
55
56 #define _(String) dgettext("hildon-libs", String)
57
58 /* #define _(String) "%A %e. %B %Y"  debug purposes */
59
60 enum
61 {
62   COLUMN_STRING,
63   COLUMN_INT,
64   N_COLUMNS
65 };
66
67 enum
68 {
69   DAY,
70   MONTH,
71   YEAR
72 };
73
74 struct _HildonDateSelectorPrivate
75 {
76   GtkTreeModel *year_model;
77   GtkTreeModel *month_model;
78   GtkTreeModel *day_model;
79
80   GSList *column_order;
81   gint day_column;
82   gint month_column;
83   gint year_column;             /* it depends on the locale */
84
85   gchar *format;                /* day/month/year format, depends on locale */
86
87   gint creation_day;
88   gint creation_month;
89   gint creation_year;           /* date at creation time */
90
91   gchar *monthname[12];
92 };
93
94 static void hildon_date_selector_finalize (GObject * object);
95
96 /* private functions */
97 static GtkTreeModel *_create_day_model (HildonDateSelector * selector);
98 static GtkTreeModel *_create_year_model (HildonDateSelector * selector);
99 static GtkTreeModel *_create_month_model (HildonDateSelector * selector);
100
101 static void _get_real_date (gint * year, gint * month, gint * day);
102 static void _locales_init (HildonDateSelectorPrivate * priv);
103
104 static void _manage_selector_change_cb (HildonTouchSelector * selector,
105                                         gint num_column, gpointer data);
106
107 static GtkTreeModel *_update_day_model (HildonDateSelector * selector);
108
109 static gint _month_days (gint month, gint year);
110 static void _init_column_order (HildonDateSelector * selector);
111
112 static gchar *_custom_print_func (HildonTouchSelector * selector);
113
114 /***************************************************************************/
115 /* The following date routines are taken from the lib_date package.  Keep
116  * them separate in case we want to update them if a newer lib_date comes
117  * out with fixes.  */
118
119 typedef unsigned int N_int;
120
121 typedef unsigned long N_long;
122
123 typedef signed long Z_long;
124
125 typedef enum
126 { false = FALSE, true = TRUE } boolean;
127
128 #define                                         and &&  /* logical (boolean) operators: lower case */
129
130 #define                                         or ||
131
132 static const N_int month_length[2][13] = {
133   {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
134   {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
135 };
136
137 static const N_int days_in_months[2][14] = {
138   {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
139   {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
140 };
141
142 static Z_long _calc_days (N_int year, N_int mm, N_int dd);
143
144 static N_int _day_of_week (N_int year, N_int mm, N_int dd);
145
146 static boolean _leap (N_int year);
147
148
149 static boolean
150 _leap (N_int year)
151 {
152   return ((((year % 4) == 0) and ((year % 100) != 0)) or ((year % 400) == 0));
153 }
154
155 static N_int
156 _day_of_week (N_int year, N_int mm, N_int dd)
157 {
158   Z_long days;
159
160   days = _calc_days (year, mm, dd);
161   if (days > 0L) {
162     days--;
163     days %= 7L;
164     days++;
165   }
166   return ((N_int) days);
167 }
168
169 static Z_long
170 _year_to_days (N_int year)
171 {
172   return (year * 365L + (year / 4) - (year / 100) + (year / 400));
173 }
174
175 static Z_long
176 _calc_days (N_int year, N_int mm, N_int dd)
177 {
178   boolean lp;
179
180   if (year < 1)
181     return (0L);
182   if ((mm < 1) or (mm > 12))
183     return (0L);
184   if ((dd < 1) or (dd > month_length[(lp = _leap (year))][mm]))
185     return (0L);
186   return (_year_to_days (--year) + days_in_months[lp][mm] + dd);
187 }
188
189 static void
190 hildon_date_selector_class_init (HildonDateSelectorClass * class)
191 {
192   GObjectClass *gobject_class;
193   GtkObjectClass *object_class;
194   GtkWidgetClass *widget_class;
195   GtkContainerClass *container_class;
196
197   gobject_class = (GObjectClass *) class;
198   object_class = (GtkObjectClass *) class;
199   widget_class = (GtkWidgetClass *) class;
200   container_class = (GtkContainerClass *) class;
201
202   /* GObject */
203   gobject_class->finalize = hildon_date_selector_finalize;
204
205   /* GtkWidget */
206
207   /* GtkContainer */
208
209   /* signals */
210
211   g_type_class_add_private (object_class, sizeof (HildonDateSelectorPrivate));
212 }
213
214 static void
215 hildon_date_selector_init (HildonDateSelector * selector)
216 {
217   GSList *iter = NULL;
218   gint current_item = 0;
219
220   selector->priv = HILDON_DATE_SELECTOR_GET_PRIVATE (selector);
221
222   GTK_WIDGET_SET_FLAGS (GTK_WIDGET (selector), GTK_NO_WINDOW);
223   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (selector), FALSE);
224
225   hildon_touch_selector_set_print_func (HILDON_TOUCH_SELECTOR (selector),
226                                         _custom_print_func);
227
228   _locales_init (selector->priv);
229
230   _init_column_order (selector);
231
232   _get_real_date (&selector->priv->creation_year,
233                   &selector->priv->creation_month, &selector->priv->creation_day);
234
235   selector->priv->year_model = _create_year_model (selector);
236   selector->priv->month_model = _create_month_model (selector);
237   selector->priv->day_model = _create_day_model (selector);
238
239   /* We add the columns: FIXME: check the locale order */
240   iter = selector->priv->column_order;
241   for (iter = selector->priv->column_order; iter; iter = g_slist_next (iter)) {
242     current_item = GPOINTER_TO_INT (iter->data);
243
244     switch (current_item) {
245     case DAY:
246       hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
247                                                 selector->priv->day_model, TRUE);
248       break;
249     case MONTH:
250       hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
251                                                 selector->priv->month_model, TRUE);
252       break;
253     case YEAR:
254       hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
255                                                 selector->priv->year_model, TRUE);
256       break;
257     default:
258       g_error ("Current column order incorrect");
259       break;
260     }
261   }
262
263   g_signal_connect (G_OBJECT (selector),
264                     "changed", G_CALLBACK (_manage_selector_change_cb), NULL);
265
266   /* By default we should select the current day */
267   hildon_date_selector_select_current_date (selector, selector->priv->creation_year,
268                                             selector->priv->creation_month,
269                                             selector->priv->creation_day);
270 }
271
272 static void
273 hildon_date_selector_finalize (GObject * object)
274 {
275   HildonDateSelector *selector = NULL;
276   gint i = 0;
277
278   selector = HILDON_DATE_SELECTOR (object);
279
280   for (i = 0; i < 12; i++) {
281     g_free (selector->priv->monthname[i]);
282   }
283
284   g_slist_free (selector->priv->column_order);
285
286   g_free (selector->priv);
287
288   (*G_OBJECT_CLASS (hildon_date_selector_parent_class)->finalize) (object);
289 }
290
291 /* ------------------------------ PRIVATE METHODS ---------------------------- */
292 static gchar *
293 _custom_print_func (HildonTouchSelector * touch_selector)
294 {
295   HildonDateSelector *selector = NULL;
296   gchar *result = NULL;
297   guint year, month, day;
298   gint day_of_week = 0;
299   static gchar string[255];
300   struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
301
302   selector = HILDON_DATE_SELECTOR (touch_selector);
303
304   hildon_date_selector_get_date (selector, &year, &month, &day);
305   day_of_week = _day_of_week (year, month + 1, day) % 7;
306
307   tm.tm_mday = day;
308   tm.tm_mon = month;
309   tm.tm_year = year - 1900;
310   tm.tm_wday = day_of_week;
311
312   strftime (string, 255, _("wdgt_va_date_long"), &tm);
313
314   result = g_strdup (string);
315
316   return result;
317 }
318
319 /* This was copied from hildon-calendar */
320 static void
321 _locales_init (HildonDateSelectorPrivate * priv)
322 {
323   /* Hildon: This is not exactly portable, see
324    * http://bugzilla.gnome.org/show_bug.cgi?id=343415
325    * The labels need to be instance variables as the startup wizard changes
326    * locale on runtime.
327    */
328   locale_t l;
329
330   l = newlocale (LC_TIME_MASK, setlocale (LC_MESSAGES, NULL), NULL);
331
332   priv->monthname[0] = g_locale_to_utf8 (nl_langinfo_l (MON_1, l),
333                                          -1, NULL, NULL, NULL);
334   priv->monthname[1] = g_locale_to_utf8 (nl_langinfo_l (MON_2, l),
335                                          -1, NULL, NULL, NULL);
336   priv->monthname[2] = g_locale_to_utf8 (nl_langinfo_l (MON_3, l),
337                                          -1, NULL, NULL, NULL);
338   priv->monthname[3] = g_locale_to_utf8 (nl_langinfo_l (MON_4, l),
339                                          -1, NULL, NULL, NULL);
340   priv->monthname[4] = g_locale_to_utf8 (nl_langinfo_l (MON_5, l),
341                                          -1, NULL, NULL, NULL);
342   priv->monthname[5] = g_locale_to_utf8 (nl_langinfo_l (MON_6, l),
343                                          -1, NULL, NULL, NULL);
344   priv->monthname[6] = g_locale_to_utf8 (nl_langinfo_l (MON_7, l),
345                                          -1, NULL, NULL, NULL);
346   priv->monthname[7] = g_locale_to_utf8 (nl_langinfo_l (MON_8, l),
347                                          -1, NULL, NULL, NULL);
348   priv->monthname[8] = g_locale_to_utf8 (nl_langinfo_l (MON_9, l),
349                                          -1, NULL, NULL, NULL);
350   priv->monthname[9] = g_locale_to_utf8 (nl_langinfo_l (MON_10, l),
351                                          -1, NULL, NULL, NULL);
352   priv->monthname[10] = g_locale_to_utf8 (nl_langinfo_l (MON_11, l),
353                                           -1, NULL, NULL, NULL);
354   priv->monthname[11] = g_locale_to_utf8 (nl_langinfo_l (MON_12, l),
355                                           -1, NULL, NULL, NULL);
356
357   priv->format = g_locale_to_utf8 (nl_langinfo_l (D_FMT, l),
358                                    -1, NULL, NULL, NULL);
359
360   freelocale (l);
361 }
362
363 static void
364 _init_column_order (HildonDateSelector * selector)
365 {
366   gchar *current_order[3] = { NULL, NULL, NULL };
367   gchar *day_pos = NULL;
368   gchar *month_pos = NULL;
369   gchar *year_pos = NULL;
370   gint i, c;
371   gchar *aux = NULL;
372
373   g_debug ("Current format: %s", selector->priv->format);
374
375   /* search each token on the format */
376   day_pos = g_strrstr (selector->priv->format, "%d");
377
378   month_pos = g_strrstr (selector->priv->format, "%m");
379   year_pos = g_strrstr (selector->priv->format, "%y");
380   if (year_pos == NULL) {
381     year_pos = g_strrstr (selector->priv->format, "%Y");
382   }
383
384
385   if ((day_pos == NULL) || (month_pos == NULL) || (year_pos == NULL)) {
386     g_error ("Wrong date format");      /* so default values */
387
388     selector->priv->day_column = 0;
389     selector->priv->month_column = 1;
390     selector->priv->year_column = 2;
391     selector->priv->column_order = g_slist_append (NULL, GINT_TO_POINTER (DAY));
392     selector->priv->column_order =
393       g_slist_append (selector->priv->column_order, GINT_TO_POINTER (MONTH));
394     selector->priv->column_order =
395       g_slist_append (selector->priv->column_order, GINT_TO_POINTER (YEAR));
396   }
397
398   /* sort current_order with this values (bubble sort) */
399   current_order[0] = day_pos;
400   current_order[1] = month_pos;
401   current_order[2] = year_pos;
402
403   for (c = 1; c <= 2; c++) {
404     for (i = 0; i < 3 - c; i++) {
405       if (current_order[i] > current_order[i + 1]) {
406         aux = current_order[i];
407         current_order[i] = current_order[i + 1];
408         current_order[i + 1] = aux;
409       }
410     }
411   }
412
413   /* fill the column positions */
414   selector->priv->column_order = NULL;
415   c = 0;
416   for (i = 0; i < 3; i++) {
417     if (current_order[i] == day_pos) {
418       selector->priv->column_order =
419         g_slist_append (selector->priv->column_order, GINT_TO_POINTER (DAY));
420       selector->priv->day_column = c++;
421     }
422     if (current_order[i] == month_pos) {
423       selector->priv->column_order =
424         g_slist_append (selector->priv->column_order, GINT_TO_POINTER (MONTH));
425       selector->priv->month_column = c++;
426     }
427     if (current_order[i] == year_pos) {
428       selector->priv->column_order =
429         g_slist_append (selector->priv->column_order, GINT_TO_POINTER (YEAR));
430       selector->priv->year_column = c++;
431     }
432   }
433 }
434
435
436 static GtkTreeModel *
437 _create_day_model (HildonDateSelector * selector)
438 {
439   GtkListStore *store_days = NULL;
440   gint i = 0;
441   gchar *label = NULL;
442   GtkTreeIter iter;
443
444   store_days = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
445   for (i = 1; i < 32; i++) {
446     label = g_strdup_printf ("%d", i);
447
448     gtk_list_store_append (store_days, &iter);
449     gtk_list_store_set (store_days, &iter,
450                         COLUMN_STRING, label, COLUMN_INT, i, -1);
451     g_free (label);
452   }
453
454   return GTK_TREE_MODEL (store_days);
455 }
456
457 static GtkTreeModel *
458 _create_year_model (HildonDateSelector * selector)
459 {
460   GtkListStore *store_years = NULL;
461   gint real_year = 0;
462   gint i = 0;
463   gchar *label = NULL;
464   GtkTreeIter iter;
465
466   real_year = selector->priv->creation_year;
467
468   store_years = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
469   for (i = real_year - INIT_YEAR; i < real_year + LAST_YEAR; i++) {
470     label = g_strdup_printf ("%d", i);
471
472     gtk_list_store_append (store_years, &iter);
473     gtk_list_store_set (store_years, &iter,
474                         COLUMN_STRING, label, COLUMN_INT, i, -1);
475     g_free (label);
476   }
477
478   return GTK_TREE_MODEL (store_years);
479 }
480
481 static GtkTreeModel *
482 _create_month_model (HildonDateSelector * selector)
483 {
484   GtkTreeIter iter;
485   gint i = 0;
486   GtkListStore *store_months = NULL;
487   gchar *label = NULL;
488
489   store_months = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
490   for (i = 0; i < 12; i++) {
491     label = g_strdup_printf ("%s", selector->priv->monthname[i]);
492
493     gtk_list_store_append (store_months, &iter);
494     gtk_list_store_set (store_months, &iter, COLUMN_STRING, label,      /* the label with the month */
495                         COLUMN_INT, i,  /* the month number */
496                         -1);
497     g_free (label);
498   }
499
500   return GTK_TREE_MODEL (store_months);
501 }
502
503 static GtkTreeModel *
504 _update_day_model (HildonDateSelector * selector)
505 {
506   GtkListStore *store_days = NULL;
507   gint i = 0;
508   GtkTreeIter iter;
509   gchar *label = NULL;
510   guint current_day = 0;
511   guint current_year = 0;
512   guint current_month = 0;
513   guint num_days = 31;
514
515   hildon_date_selector_get_date (selector, NULL, NULL, &current_day);
516
517   hildon_touch_selector_get_active_iter (HILDON_TOUCH_SELECTOR (selector),
518                                          selector->priv->month_column, &iter);
519   gtk_tree_model_get (selector->priv->month_model,
520                       &iter, COLUMN_INT, &current_month, -1);
521
522   hildon_touch_selector_get_active_iter (HILDON_TOUCH_SELECTOR (selector),
523                                          selector->priv->year_column, &iter);
524   gtk_tree_model_get (selector->priv->year_model,
525                       &iter, COLUMN_INT, &current_year, -1);
526
527   num_days = _month_days (current_month, current_year);
528
529   store_days = GTK_LIST_STORE (selector->priv->day_model);
530   gtk_list_store_clear (store_days);
531
532   for (i = 1; i <= num_days; i++) {
533     label = g_strdup_printf ("%d", i);
534
535     gtk_list_store_append (store_days, &iter);
536     gtk_list_store_set (store_days, &iter,
537                         COLUMN_STRING, label, COLUMN_INT, i, -1);
538     g_free (label);
539   }
540
541   /* now we select a day */
542   if (current_day >= num_days) {
543     current_day = num_days;
544   }
545
546   hildon_date_selector_select_day (selector, current_day);
547
548   return GTK_TREE_MODEL (store_days);
549 }
550
551
552 static void
553 _get_real_date (gint * year, gint * month, gint * day)
554 {
555   time_t secs;
556   struct tm *tm = NULL;
557
558   secs = time (NULL);
559   tm = localtime (&secs);
560
561   if (year != NULL) {
562     *year = 1900 + tm->tm_year;
563   }
564
565   if (month != NULL) {
566     *month = tm->tm_mon;
567   }
568
569   if (day != NULL) {
570     *day = tm->tm_mday;
571   }
572 }
573
574
575 static void
576 _manage_selector_change_cb (HildonTouchSelector * touch_selector,
577                             gint num_column, gpointer data)
578 {
579   HildonDateSelector *selector = NULL;
580
581   g_return_if_fail (HILDON_IS_DATE_SELECTOR (touch_selector));
582   selector = HILDON_DATE_SELECTOR (touch_selector);
583
584   if ((num_column == selector->priv->month_column) ||
585       (num_column == selector->priv->year_column)) /* it is required to check that with
586                                                     * the years too,remember: leap years
587                                                     */
588   {
589     _update_day_model (selector);
590   }
591 }
592
593 static gint
594 _month_days (gint month, gint year)
595 {
596   gint month_days[2][12] = {
597     {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
598     {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
599   };
600
601   g_return_val_if_fail (month >= 0 && month <= 12, -1);
602
603   return month_days[_leap (year)][month];
604 }
605
606
607 /* ------------------------------ PUBLIC METHODS ---------------------------- */
608
609 /**
610  * hildon_date_selector_new:
611  * @:
612  *
613  * Creates a new #HildonDateSelector
614  *
615  * Returns: a new #HildonDateSelector
616  **/
617 GtkWidget *
618 hildon_date_selector_new ()
619 {
620   return g_object_new (HILDON_TYPE_DATE_SELECTOR, NULL);
621 }
622
623
624
625 /**
626  * hildon_date_selector_select_date:
627  * @selector: the #HildonDateSelector
628  * @year:  the current year
629  * @month: the current month (0-11)
630  * @day:   the current day (1-31, 1-30, 1-29, 1-28) depends on the month
631  *
632  * Sets the current active date on the #HildonDateSelector widget
633  *
634  **/
635 gboolean
636 hildon_date_selector_select_current_date (HildonDateSelector * selector,
637                                           guint year, guint month, guint day)
638 {
639   GtkTreeIter iter;
640   gint min_year = 0;
641   gint max_year = 0;
642   gint num_days = 0;
643
644   min_year = selector->priv->creation_year - INIT_YEAR;
645   max_year = selector->priv->creation_year + LAST_YEAR;
646
647   g_return_val_if_fail (year > min_year && year < max_year, FALSE);
648   g_return_val_if_fail (month >= 0 && month < 12, FALSE);
649
650   num_days = _month_days (month, year);
651   g_return_val_if_fail (day > 0 && day < num_days, FALSE);
652
653
654   gtk_tree_model_iter_nth_child (selector->priv->year_model, &iter, NULL,
655                                  year - selector->priv->creation_year +
656                                  INIT_YEAR);
657   hildon_touch_selector_set_active_iter (HILDON_TOUCH_SELECTOR (selector),
658                                          selector->priv->year_column, &iter,
659                                          FALSE);
660
661   gtk_tree_model_iter_nth_child (selector->priv->month_model, &iter, NULL,
662                                  month);
663   hildon_touch_selector_set_active_iter (HILDON_TOUCH_SELECTOR (selector),
664                                          selector->priv->month_column, &iter,
665                                          FALSE);
666
667   gtk_tree_model_iter_nth_child (selector->priv->day_model, &iter, NULL,
668                                  day - 1);
669   hildon_touch_selector_set_active_iter (HILDON_TOUCH_SELECTOR (selector),
670                                          selector->priv->day_column, &iter,
671                                          FALSE);
672
673   return TRUE;
674 }
675
676
677 /**
678  * hildon_date_selector_select_date:
679  * @selector: the #HildonDateSelector
680  * @year:  to set the current year
681  * @month: to set the current month (0-11)
682  * @day:   to the current day (1-31, 1-30, 1-29, 1-28) depends on the month
683  *
684  * Gets the current active date on the #HildonDateSelector widget
685  *
686  *
687  **/
688 void
689 hildon_date_selector_get_date (HildonDateSelector * selector,
690                                guint * year, guint * month, guint * day)
691 {
692   GtkTreeIter iter;
693
694   if (year != NULL) {
695     hildon_touch_selector_get_active_iter (HILDON_TOUCH_SELECTOR (selector),
696                                            selector->priv->year_column, &iter);
697     gtk_tree_model_get (selector->priv->year_model,
698                         &iter, COLUMN_INT, year, -1);
699   }
700
701   if (month != NULL) {
702     hildon_touch_selector_get_active_iter (HILDON_TOUCH_SELECTOR (selector),
703                                            selector->priv->month_column, &iter);
704     gtk_tree_model_get (selector->priv->month_model,
705                         &iter, COLUMN_INT, month, -1);
706   }
707
708
709   if (day != NULL) {
710     if (hildon_touch_selector_get_active_iter (HILDON_TOUCH_SELECTOR (selector),
711                                                selector->priv->day_column, &iter))
712     {
713       gtk_tree_model_get (selector->priv->day_model,
714                           &iter, COLUMN_INT, day, -1);
715     }
716 /*       *day = *day - 1;  */
717   }
718
719 }
720
721
722 void
723 hildon_date_selector_select_day (HildonDateSelector * selector, guint day)
724 {
725   GtkTreeIter iter;
726
727   gtk_tree_model_iter_nth_child (selector->priv->day_model, &iter, NULL,
728                                  day - 1);
729   hildon_touch_selector_set_active_iter (HILDON_TOUCH_SELECTOR (selector),
730                                          selector->priv->day_column, &iter,
731                                          FALSE);
732 }