thread safety
[hildon] / hildon-widgets / hildon-date-editor.c
index f50c0ce..71891c7 100644 (file)
  *
  */
 
-/* HILDON DOC
- * @shortdesc: DateEditor is a widget for setting, getting and showing a
- * date.
- * @longdesc: The date editor consists of a GtkLabel that shows the current
- * date in localized form and an icon. Clicking on either the label or the
- * icon opens the #HildonCalendarPopup used for selecting the date.
- * Similarly, if the editor has the focus, and space or enter key is
- * pressed, the #HildonCalendarPopup will open. 
+/**
+ * SECTION:hildon-date-editor
+ * @short_description: A widget which queries a date from user or opens
+ * a HildonCalendarPopup
+ * @see_also: #HildonCalendarPopup, #HildonTimeEditor
  * 
- * @seealso: #HildonTimeEditor, #HildonCalendarPopup
+ * HildonDateEditor is a widget with three entry fields (day, month,
+ * year) and an icon (eventbox): clicking on the icon opens up a
+ * HildonCalendarPopup.
  */
 
 #include <glib.h>
@@ -49,6 +48,7 @@
 #include <hildon-widgets/hildon-input-mode-hint.h>
 #include "hildon-composite-widget.h"
 #include "hildon-marshalers.h"
+#include "hildon-libs-enum-types.h"
 
 #ifdef HAVE_CONFIG_H
 #include<config.h>
@@ -69,7 +69,7 @@
 
 #define HILDON_DATE_EDITOR_GET_PRIVATE(obj) \
         (G_TYPE_INSTANCE_GET_PRIVATE((obj),\
-        HILDON_DATE_EDITOR_TYPE, HildonDateEditorPrivate));
+        HILDON_TYPE_DATE_EDITOR, HildonDateEditorPrivate));
 
 static GtkContainerClass *parent_class;
 
@@ -230,8 +230,8 @@ hildon_date_editor_class_init(HildonDateEditorClass * editor_class)
                 G_SIGNAL_RUN_LAST,
                 G_STRUCT_OFFSET(HildonDateEditorClass, date_error),
                 g_signal_accumulator_true_handled, NULL,
-               _hildon_marshal_BOOLEAN__INT,
-                G_TYPE_BOOLEAN, 1, G_TYPE_INT);
+               _hildon_marshal_BOOLEAN__ENUM,
+                G_TYPE_BOOLEAN, 1, HILDON_TYPE_DATE_EDITOR_ERROR_TYPE);
 
   /**
    * HildonDateEditor:year:
@@ -667,14 +667,14 @@ static void hildon_date_editor_destroy(GtkObject * self)
 /**
  * hildon_date_editor_new:
  *
- * Creates a new time editor. The current system date
+ * Creates a new date editor. The current system date
  * is shown in the editor.
  *
- * Return value: Pointer to a new @HildonDateEditor widget.
- **/
+ * Returns: pointer to a new @HildonDateEditor widget.
+ */
 GtkWidget *hildon_date_editor_new(void)
 {
-    return GTK_WIDGET(g_object_new(HILDON_DATE_EDITOR_TYPE, NULL));
+    return GTK_WIDGET(g_object_new(HILDON_TYPE_DATE_EDITOR, NULL));
 }
 
 /**
@@ -685,7 +685,7 @@ GtkWidget *hildon_date_editor_new(void)
  * @day: day
  *
  * Sets the date shown in the editor. 
- **/
+ */
 void hildon_date_editor_set_date(HildonDateEditor * editor,
                                  guint year, guint month, guint day)
 {
@@ -752,9 +752,9 @@ void hildon_date_editor_set_date(HildonDateEditor * editor,
  * @month: month
  * @day: day
  *
- * Returns the year, month, and day currently on the
+ * Returns: the year, month, and day currently on the
  * date editor.
- **/
+ */
 void hildon_date_editor_get_date(HildonDateEditor * date,
                                  guint * year, guint * month, guint * day)
 {
@@ -913,7 +913,7 @@ hildon_date_editor_entry_validate(GtkWidget *widget, gpointer data)
     gint d, m, y, max_days;
     gboolean r;  /* temp return values for signals */
     const gchar *text;        
-    gint error_code = 0;
+    gint error_code = NO_ERROR;
 
     g_assert(HILDON_IS_DATE_EDITOR(data));
     g_assert(GTK_IS_ENTRY(widget));
@@ -990,13 +990,23 @@ hildon_date_editor_entry_validate(GtkWidget *widget, gpointer data)
            d = 1;
         }
         else if (d > max_days) {
-           /* Report range error or invalid date */
-           error_code = d > 31 ? MAX_DAY : INVALID_DATE;
-           d = max_days;
-           widget = priv->d_entry; /* Note! Change param to point day entry */
+           if (d > 31) {         
+               error_code = MAX_DAY;
+               d = max_days;
+           }
+           else {                /* the date does not exist (is invalid) */
+               error_code = INVALID_DATE;
+               /* check what was changed and restore previous value */
+               if ( widget == priv->y_entry )
+                   y = priv->year;
+               else if ( widget == priv->m_entry )
+                   m = priv->month;
+               else
+                   d = priv->day;
+           }
         }
 
-        if (error_code != 0)
+        if (error_code != NO_ERROR)
         {
             g_signal_emit(ed, date_editor_signals[DATE_ERROR], 0, error_code, &r);
 
@@ -1120,33 +1130,33 @@ hildon_date_editor_date_error(HildonDateEditor *editor,
   switch(type)
     {
     case MAX_DAY:
-      gtk_infoprintf(NULL, _("Ckct_ib_maximum_value"), 31);
+      gtk_infoprintf(NULL, _("ckct_ib_maximum_value"), 31);
       break;
     case MAX_MONTH:
-      gtk_infoprintf(NULL, _("Ckct_ib_maximum_value"), 12);
+      gtk_infoprintf(NULL, _("ckct_ib_maximum_value"), 12);
       break;
     case MAX_YEAR:
-      gtk_infoprintf(NULL, _("Ckct_ib_maximum_value"), priv->max_year);
+      gtk_infoprintf(NULL, _("ckct_ib_maximum_value"), priv->max_year);
       break;
     case MIN_DAY:
     case MIN_MONTH:
-      gtk_infoprintf(NULL, _("Ckct_ib_minimum_value"), 1);
+      gtk_infoprintf(NULL, _("ckct_ib_minimum_value"), 1);
       break;
     case MIN_YEAR:
-      gtk_infoprintf(NULL, _("Ckct_ib_minimum_value"), priv->min_year);
+      gtk_infoprintf(NULL, _("ckct_ib_minimum_value"), priv->min_year);
       break;
     case EMPTY_DAY:
-      gtk_infoprintf(NULL, _("Ckct_ib_set_a_value_within_range"), 1, 31);
+      gtk_infoprintf(NULL, _("ckct_ib_set_a_value_within_range"), 1, 31);
       break;
     case EMPTY_MONTH:
-      gtk_infoprintf(NULL, _("Ckct_ib_set_a_value_within_range"), 1, 12);
+      gtk_infoprintf(NULL, _("ckct_ib_set_a_value_within_range"), 1, 12);
       break;
     case EMPTY_YEAR:
-      gtk_infoprintf(NULL, _("Ckct_ib_set_a_value_within_range"),
+      gtk_infoprintf(NULL, _("ckct_ib_set_a_value_within_range"),
                      priv->min_year, priv->max_year);
       break;
     case INVALID_DATE:
-      gtk_infoprint(NULL, _("Ckct_ib_date_does_not_exist"));
+      gtk_infoprint(NULL, _("ckct_ib_date_does_not_exist"));
       break;
    default:
       /*default error message ?*/
@@ -1255,8 +1265,8 @@ static void hildon_date_editor_size_allocate(GtkWidget * widget,
  *
  * Sets the year shown in the editor. 
  *
- * Return: Returns TRUE if the year is valid.
- **/
+ * Returns: TRUE if the year is valid
+ */
 gboolean hildon_date_editor_set_year(HildonDateEditor *editor, guint year)
 {
   HildonDateEditorPrivate *priv;
@@ -1292,8 +1302,8 @@ gboolean hildon_date_editor_set_year(HildonDateEditor *editor, guint year)
  *
  * Sets the month shown in the editor. 
  *
- * Return: Returns TRUE if the month is valid.
- **/
+ * Returns: TRUE if the month is valid
+ */
 gboolean hildon_date_editor_set_month(HildonDateEditor *editor, guint month)
 {
   HildonDateEditorPrivate *priv;
@@ -1330,8 +1340,8 @@ gboolean hildon_date_editor_set_month(HildonDateEditor *editor, guint month)
  *
  * Sets the day shown in the editor. 
  *
- * Return: Returns TRUE if the day is valid.
- **/
+ * Returns: TRUE if the day is valid
+ */
 gboolean hildon_date_editor_set_day(HildonDateEditor *editor, guint day)
 {
   HildonDateEditorPrivate *priv;
@@ -1366,10 +1376,8 @@ gboolean hildon_date_editor_set_day(HildonDateEditor *editor, guint day)
  * hildon_date_editor_get_year:
  * @editor: the @HildonDateEditor widget
  *
- * Gets the year shown in the editor. 
- *
- * Return: Returns the current year shown in the editor.
- **/
+ * Returns: the current year shown in the editor.
+ */
 guint hildon_date_editor_get_year(HildonDateEditor *editor)
 {
   HildonDateEditorPrivate *priv;
@@ -1384,8 +1392,8 @@ guint hildon_date_editor_get_year(HildonDateEditor *editor)
  *
  * Gets the month shown in the editor. 
  *
- * Return: Returns the current month shown in the editor.
- **/
+ * Returns: the current month shown in the editor.
+ */
 
 guint hildon_date_editor_get_month(HildonDateEditor *editor)
 {
@@ -1401,8 +1409,8 @@ guint hildon_date_editor_get_month(HildonDateEditor *editor)
  *
  * Gets the day shown in the editor. 
  *
- * Return: Returns the current day shown in the editor.
- **/
+ * Returns: the current day shown in the editor
+ */
 
 guint hildon_date_editor_get_day(HildonDateEditor *editor)
 {
@@ -1416,6 +1424,8 @@ guint hildon_date_editor_get_day(HildonDateEditor *editor)
 static gboolean
 _hildon_date_editor_entry_select_all (GtkWidget *widget)
 {
+       GDK_THREADS_ENTER ();
        gtk_editable_select_region(GTK_EDITABLE(widget), 0, -1);
+       GDK_THREADS_LEAVE ();
        return FALSE;
 }