2009-03-19 Alejandro G. Castro <alex@igalia.com>
[hildon] / src / hildon-date-button.c
index 0252bfe..a27b996 100644 (file)
  *
  */
 
+#include <libintl.h>
+
+#include "hildon-date-button.h"
 #include "hildon-date-selector.h"
 #include "hildon-touch-selector.h"
-#include "hildon-picker-button.h"
-#include "hildon-date-button.h"
+#include "hildon-picker-button-private.h"
+
+#define                                         _(String) \
+                                                dgettext("hildon-libs", String)
+
+#define                                         c_(String) \
+                                                dgettext("hildon-common-strings", String)
+
+/**
+ * SECTION:hildon-date-button
+ * @Short_Description: Button displaying and allowing selection of a date.
+ * @See_Also: #HildonPickerButton, #HildonTimeButton
+ *
+ * #HildonDateButton is a widget that shows a text label and a date, and allows
+ * the user to select a different date. Visually, it's a button that, once clicked,
+ * presents a #HildonPickerDialog containing a #HildonDateSelector. Once the user selects
+ * a different date from the selector, this will be shown in the button.
+ */
 
 G_DEFINE_TYPE (HildonDateButton, hildon_date_button, HILDON_TYPE_PICKER_BUTTON)
 
@@ -78,15 +97,75 @@ hildon_date_button_init (HildonDateButton * self)
                                      HILDON_TOUCH_SELECTOR (date_selector));
 }
 
-GtkWidget *
-hildon_date_button_new (HildonButtonFlags flags)
+static GtkWidget *
+hildon_date_button_new_full (HildonSizeType           size,
+                             HildonButtonArrangement  arrangement,
+                             GtkWidget               *selector)
 {
   return g_object_new (HILDON_TYPE_DATE_BUTTON,
-                       "title", "Date",
-                       "arrangement-flags", flags,
+                       "title", _("wdgt_ti_date"),
+                       "arrangement", arrangement,
+                       "size", size,
+                       "touch-selector", selector,
                        NULL);
 }
 
+/**
+ * hildon_date_button_new:
+ * @size: One of #HildonSizeType
+ * @arrangement: one of #HildonButtonArrangement
+ *
+ * Creates a new #HildonDateButton. See hildon_button_new() for details on the
+ * parameters.
+ *
+ * Returns: a new #HildonDateButton
+ *
+ * Since: 2.2
+ **/
+GtkWidget *
+hildon_date_button_new (HildonSizeType          size,
+                        HildonButtonArrangement arrangement)
+{
+  GtkWidget *selector = hildon_date_selector_new ();
+  return hildon_date_button_new_full (size, arrangement, selector);
+}
+
+/**
+ * hildon_date_button_new_with_year_range:
+ * @size: One of #HildonSizeType
+ * @arrangement: one of #HildonButtonArrangement
+ * @min_year: the minimum available year or -1 to ignore
+ * @max_year: the maximum available year or -1 to ignore
+ *
+ * Creates a new #HildonDateButton with a specific valid range of years.
+ * See hildon_date_selector_new_with_year_range() for details on the range.
+ *
+ * Returns: a new #HildonDateButton
+ *
+ * Since: 2.2
+ **/
+GtkWidget *
+hildon_date_button_new_with_year_range (HildonSizeType size,
+                                        HildonButtonArrangement arrangement,
+                                        gint min_year,
+                                        gint max_year)
+{
+  GtkWidget *selector;
+  selector = hildon_date_selector_new_with_year_range (min_year, max_year);
+  return hildon_date_button_new_full (size, arrangement, selector);
+}
+
+/**
+ * hildon_date_button_get_date:
+ * @button: a #HildonDateButton
+ * @year: return location for the selected year
+ * @month: return location for the selected month
+ * @day: return location for the selected day
+ *
+ * Retrieves currently selected date from @button.
+ *
+ * Since: 2.2
+ **/
 void
 hildon_date_button_get_date (HildonDateButton * button,
                              guint * year, guint * month, guint * day)
@@ -97,9 +176,23 @@ hildon_date_button_get_date (HildonDateButton * button,
 
   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
 
+  g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
+
   hildon_date_selector_get_date (HILDON_DATE_SELECTOR (selector), year, month, day);
 }
 
+/**
+ * hildon_date_button_set_date:
+ * @button: a #HildonDateButton
+ * @year: the year to set.
+ * @month: the month number to set.
+ * @day: the day of the month to set.
+ *
+ * Sets the date in @button. The date set will be displayed
+ * and will be the default selected option on the shown #HildonDateSelector.
+ *
+ * Since: 2.2
+ **/
 void
 hildon_date_button_set_date (HildonDateButton * button,
                              guint year, guint month, guint day)
@@ -111,9 +204,18 @@ hildon_date_button_set_date (HildonDateButton * button,
 
   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
 
+  g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
+
+  hildon_picker_button_disable_value_changed (HILDON_PICKER_BUTTON (button), TRUE);
   hildon_date_selector_select_current_date (HILDON_DATE_SELECTOR (selector),
                                             year, month, day);
+  hildon_picker_button_disable_value_changed (HILDON_PICKER_BUTTON (button), FALSE);
+
   date = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
 
   hildon_button_set_value (HILDON_BUTTON (button), date);
+
+  g_free (date);
+
+  hildon_picker_button_value_changed (HILDON_PICKER_BUTTON (button));
 }