From Murray Cumming <murrayc@murrayc.com>.
authorMarius Vollmer <marius.vollmer@nokia.com>
Mon, 24 Apr 2006 13:24:46 +0000 (13:24 +0000)
committerMarius Vollmer <marius.vollmer@nokia.com>
Mon, 24 Apr 2006 13:24:46 +0000 (13:24 +0000)
* hildon-widgets/hildon-calendar-popup.c:
(hildon_calendar_popup_new): Use only g_object_new(), passing
it properties, so that language bindings can do the same.
(hildon_calendar_popup_set_date): Veryify the date here,
instead of only in the _new() function.
(hildon_calendar_popup_set_property): Use get/set_date() to
verify the new date and to select it.
(hildon_calendar_popup_get_property): Remove unused variables.
* ut/hildon-widgets_tests.c (test45): New.

ChangeLog
hildon-widgets/hildon-calendar-popup.c
ut/hildon-widgets_tests.c

index 62e999d..50fcd69 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2006-04-24  Marius Vollmer  <marius.vollmer@nokia.com>
+
+        From Murray Cumming  <murrayc@murrayc.com>.
+
+       * hildon-widgets/hildon-calendar-popup.c:
+       (hildon_calendar_popup_new): Use only g_object_new(), passing 
+       it properties, so that language bindings can do the same.
+       (hildon_calendar_popup_set_date): Veryify the date here, 
+       instead of only in the _new() function.
+       (hildon_calendar_popup_set_property): Use get/set_date() to 
+       verify the new date and to select it.
+       (hildon_calendar_popup_get_property): Remove unused variables.
+       * ut/hildon-widgets_tests.c (test45): New.
+       
 2006-04-21  Luc Pionchon  <luc.pionchon@nokia.com>
 
        * configure.ac: 0.12.11
index 55c02ef..6784d88 100644 (file)
@@ -131,23 +131,16 @@ GtkWidget *hildon_calendar_popup_new(GtkWindow * parent, guint year,
                                      guint month, guint day)
 {
     HildonCalendarPopup *cal = NULL;
-    HildonCalendarPopupPrivate *priv;
-    guint dtmp, mtmp, ytmp;
-
-    init_dmy(year, month, day, &dtmp, &mtmp, &ytmp);
 
     /* Create new HildonCalendarPopup */
-    cal = HILDON_CALENDAR_POPUP(g_object_new(HILDON_TYPE_CALENDAR_POPUP, NULL));
-    priv = HILDON_CALENDAR_POPUP_GET_PRIVATE(cal);
+    cal = HILDON_CALENDAR_POPUP(g_object_new(HILDON_TYPE_CALENDAR_POPUP,
+                                             "year", year, "month", month, "day", day,
+                                            NULL));
 
     if (parent) {
         gtk_window_set_transient_for(GTK_WINDOW(cal), parent);
     }
 
-    /* Select day, month, year */
-    gtk_calendar_select_month(GTK_CALENDAR(priv->cal), mtmp - 1, ytmp);
-    gtk_calendar_select_day(GTK_CALENDAR(priv->cal), dtmp);
-
     return GTK_WIDGET(cal);
 }
 
@@ -164,18 +157,23 @@ void
 hildon_calendar_popup_set_date(HildonCalendarPopup * cal,
                                guint year, guint month, guint day)
 {
+    guint dtmp, mtmp, ytmp = 0;
     HildonCalendarPopupPrivate *priv;
 
     g_return_if_fail(HILDON_IS_CALENDAR_POPUP(cal));
 
     priv = HILDON_CALENDAR_POPUP_GET_PRIVATE(cal);
 
+    /* Choose current date if the date is invalid: 
+     */
+    init_dmy(year, month, day, &dtmp, &mtmp, &ytmp);
+
     /* Remove all visual markers */
     gtk_calendar_clear_marks(GTK_CALENDAR(priv->cal));
 
     /* Set a new date */
-    gtk_calendar_select_month(GTK_CALENDAR(priv->cal), month - 1, year);
-    gtk_calendar_select_day(GTK_CALENDAR(priv->cal), day);
+    gtk_calendar_select_month(GTK_CALENDAR(priv->cal), mtmp - 1, ytmp);
+    gtk_calendar_select_day(GTK_CALENDAR(priv->cal), dtmp);
 }
 
 /**
@@ -374,19 +372,38 @@ hildon_calendar_selected_date(GtkWidget * self, gpointer cal_popup)
 static void hildon_calendar_popup_set_property(GObject * object, guint property_id,
                                     const GValue * value, GParamSpec * pspec)
 {
+    HildonCalendarPopup *popup = HILDON_CALENDAR_POPUP (object);
     HildonCalendarPopupPrivate *priv = 
        HILDON_CALENDAR_POPUP_GET_PRIVATE(HILDON_CALENDAR_POPUP (object));
 
     switch (property_id) {
     case PROP_DAY:
-        g_object_set_property(G_OBJECT(priv->cal), pspec->name, value);
+    {
+        guint year, month, day = 0;
+        hildon_calendar_popup_get_date(popup, &year, &month, &day);
+
+        /*Verifies that the date is valid: */
+        hildon_calendar_popup_set_date(popup, year, month, g_value_get_int(value));
         break;
+    }
     case PROP_MONTH:
-        g_object_set_property(G_OBJECT(priv->cal), pspec->name, value);
+    {
+        guint year, month, day = 0;
+        hildon_calendar_popup_get_date(popup, &year, &month, &day);
+
+        /*Verifies that the date is valid: */
+        hildon_calendar_popup_set_date(popup, year, g_value_get_int(value), day);
         break;
+    }
     case PROP_YEAR:
-        g_object_set_property(G_OBJECT(priv->cal), pspec->name, value);
+    {
+        guint year, month, day = 0;
+        hildon_calendar_popup_get_date(popup, &year, &month, &day);
+
+        /*Verifies that the date is valid: */
+        hildon_calendar_popup_set_date(popup, g_value_get_int(value), month, day);
         break;
+    }
     case PROP_MIN_YEAR:
         g_object_set_property(G_OBJECT(priv->cal), "min-year", value);
         break;
index 624b3fc..96831db 100644 (file)
@@ -342,6 +342,7 @@ int test41a(void);
 int test42 (void);
 int test43 (void);
 int test44 (void);
+int test45 (void);
 
 /* this has to be like this (not static). outo
    calls for this! */
@@ -2961,6 +2962,18 @@ int test44 ()
   return 1;
 }
 
+int test45 ()
+{
+  GtkWidget *dialog;
+
+  dialog = hildon_calendar_popup_new (NULL, 1973, 5, 11);
+
+  g_assert (dialog);
+
+  return 1;
+}
+
+
 testcase tcases[] =
 {
     {*test1a, "hildon_controlbar_new", EXPECT_OK},
@@ -3187,6 +3200,7 @@ testcase tcases[] =
     { test42, "hildon_caption_new", EXPECT_OK },
     { test43, "hildon_get_password_dialog_new", EXPECT_OK },
     { test44, "hildon_get_password_dialog_new_with_default", EXPECT_OK },
+    { test45, "hildon_calendor_popup_new", EXPECT_OK },
 
     {0} /*REMEMBER THE TERMINATING NULL*/
 };