2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser Public License as published by
8 * the Free Software Foundation; version 2 of the license.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser Public License for more details.
19 #include "hildon-date-button.h"
20 #include "hildon-date-selector.h"
21 #include "hildon-touch-selector.h"
22 #include "hildon-picker-button-private.h"
25 dgettext("hildon-libs", String)
28 dgettext("hildon-common-strings", String)
31 * SECTION:hildon-date-button
32 * @Short_Description: Button displaying and allowing selection of a date.
33 * @See_Also: #HildonPickerButton, #HildonTimeButton
35 * #HildonDateButton is a widget that shows a text label and a date, and allows
36 * the user to select a different date. Visually, it's a button that, once clicked,
37 * presents a #HildonPickerDialog containing a #HildonDateSelector. Once the user selects
38 * a different date from the selector, this will be shown in the button.
41 G_DEFINE_TYPE (HildonDateButton, hildon_date_button, HILDON_TYPE_PICKER_BUTTON)
44 #define GET_PRIVATE(o) \
45 (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_DATE_BUTTON, HildonDateButtonPrivate))
47 typedef struct _HildonDateButtonPrivate HildonDateButtonPrivate;
49 struct _HildonDateButtonPrivate
56 hildon_date_button_get_property (GObject * object, guint property_id,
57 GValue * value, GParamSpec * pspec)
59 switch (property_id) {
61 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
66 hildon_date_button_set_property (GObject * object, guint property_id,
67 const GValue * value, GParamSpec * pspec)
69 switch (property_id) {
71 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
77 hildon_date_button_class_init (HildonDateButtonClass * klass)
80 GObjectClass *object_class = G_OBJECT_CLASS (klass);
82 g_type_class_add_private (klass, sizeof (HildonDateButtonPrivate));
84 object_class->get_property = hildon_date_button_get_property;
85 object_class->set_property = hildon_date_button_set_property;
90 hildon_date_button_init (HildonDateButton * self)
95 hildon_date_button_new_full (HildonSizeType size,
96 HildonButtonArrangement arrangement,
99 return g_object_new (HILDON_TYPE_DATE_BUTTON,
100 "title", _("wdgt_ti_date"),
101 "arrangement", arrangement,
103 "touch-selector", selector,
108 * hildon_date_button_new:
109 * @size: One of #HildonSizeType
110 * @arrangement: one of #HildonButtonArrangement
112 * Creates a new #HildonDateButton. See hildon_button_new() for details on the
115 * Returns: a new #HildonDateButton
120 hildon_date_button_new (HildonSizeType size,
121 HildonButtonArrangement arrangement)
123 GtkWidget *selector = hildon_date_selector_new ();
124 return hildon_date_button_new_full (size, arrangement, selector);
128 * hildon_date_button_new_with_year_range:
129 * @size: One of #HildonSizeType
130 * @arrangement: one of #HildonButtonArrangement
131 * @min_year: the minimum available year or -1 to ignore
132 * @max_year: the maximum available year or -1 to ignore
134 * Creates a new #HildonDateButton with a specific valid range of years.
135 * See hildon_date_selector_new_with_year_range() for details on the range.
137 * Returns: a new #HildonDateButton
142 hildon_date_button_new_with_year_range (HildonSizeType size,
143 HildonButtonArrangement arrangement,
148 selector = hildon_date_selector_new_with_year_range (min_year, max_year);
149 return hildon_date_button_new_full (size, arrangement, selector);
153 * hildon_date_button_get_date:
154 * @button: a #HildonDateButton
155 * @year: return location for the selected year
156 * @month: return location for the selected month
157 * @day: return location for the selected day
159 * Retrieves currently selected date from @button.
164 hildon_date_button_get_date (HildonDateButton * button,
165 guint * year, guint * month, guint * day)
167 HildonTouchSelector *selector;
169 g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
171 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
173 hildon_date_selector_get_date (HILDON_DATE_SELECTOR (selector), year, month, day);
177 * hildon_date_button_set_date:
178 * @button: a #HildonDateButton
179 * @year: the year to set.
180 * @month: the month number to set.
181 * @day: the day of the month to set.
183 * Sets the date in @button. The date set will be displayed
184 * and will be the default selected option on the shown #HildonDateSelector.
189 hildon_date_button_set_date (HildonDateButton * button,
190 guint year, guint month, guint day)
192 HildonTouchSelector *selector;
195 g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
197 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
199 hildon_picker_button_disable_value_changed (HILDON_PICKER_BUTTON (button), TRUE);
200 hildon_date_selector_select_current_date (HILDON_DATE_SELECTOR (selector),
202 hildon_picker_button_disable_value_changed (HILDON_PICKER_BUTTON (button), FALSE);
204 date = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
206 hildon_button_set_value (HILDON_BUTTON (button), date);
210 hildon_picker_button_value_changed (HILDON_PICKER_BUTTON (button));