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.
18 * SECTION:hildon-time-button
19 * @Short_Description: Button displaying and allowing selection of a time.
20 * @See_Also: #HildonPickerButton, #HildonDateButton
22 * #HildonTimeButton is a widget that shows a text label and a time, and allows
23 * the user to select a different time. Visually, it's a button that, once clicked,
24 * presents a #HildonPickerDialog containing a #HildonTimeSelector. Once the user selects
25 * a different time from the selector, this will be shown in the button.
30 #include "hildon-time-selector.h"
31 #include "hildon-touch-selector.h"
32 #include "hildon-picker-button.h"
33 #include "hildon-time-button.h"
36 dgettext("hildon-libs", String)
39 dgettext("hildon-common-strings", String)
41 G_DEFINE_TYPE (HildonTimeButton, hildon_time_button, HILDON_TYPE_PICKER_BUTTON)
44 #define GET_PRIVATE(o) \
45 (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_TIME_BUTTON, HildonTimeButtonPrivate))
46 typedef struct _HildonTimeButtonPrivate HildonTimeButtonPrivate;
48 struct _HildonTimeButtonPrivate
55 hildon_time_button_get_property (GObject * object, guint property_id,
56 GValue * value, GParamSpec * pspec)
58 switch (property_id) {
60 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
65 hildon_time_button_set_property (GObject * object, guint property_id,
66 const GValue * value, GParamSpec * pspec)
68 switch (property_id) {
70 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
76 hildon_time_button_class_init (HildonTimeButtonClass * klass)
79 GObjectClass *object_class = G_OBJECT_CLASS (klass);
81 g_type_class_add_private (klass, sizeof (HildonTimeButtonPrivate));
83 object_class->get_property = hildon_time_button_get_property;
84 object_class->set_property = hildon_time_button_set_property;
89 hildon_time_button_init (HildonTimeButton * self)
94 * hildon_time_button_new:
95 * @size: One of #HildonSizeType
96 * @arrangement: one of #HildonButtonArrangement
98 * Creates a new #HildonTimeButton. See hildon_button_new() for details on the
101 * Returns: a new #HildonTimeButton
106 hildon_time_button_new (HildonSizeType size,
107 HildonButtonArrangement arrangement)
109 return hildon_time_button_new_step (size, arrangement, 1);
113 * hildon_time_button_new_step:
114 * @size: One of #HildonSizeType
115 * @arrangement: one of #HildonButtonArrangement
116 * @minutes_step: step between the minutes in the selector options
118 * Creates a new #HildonTimeButton. See hildon_button_new() for details on the
121 * Returns: a new #HildonTimeButton
126 hildon_time_button_new_step (HildonSizeType size,
127 HildonButtonArrangement arrangement,
130 return g_object_new (HILDON_TYPE_TIME_BUTTON,
131 "title", _("wdgt_ti_time"),
132 "arrangement", arrangement,
134 "touch-selector", hildon_time_selector_new_step (minutes_step),
139 * hildon_time_button_get_time:
140 * @button: a #HildonTimeButton
141 * @hours: return location for the hours of the time selected
142 * @minutes: return location for the minutes of the time selected
144 * Retrieves the time from @button.
149 hildon_time_button_get_time (HildonTimeButton * button,
150 guint * hours, guint * minutes)
152 HildonTouchSelector *selector;
154 g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
156 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
158 hildon_time_selector_get_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
162 * hildon_time_button_set_time:
163 * @button: a #HildonTimeButton
164 * @hours: the hours to be set
165 * @minutes: the time to be set
167 * Sets the time to be displayed in @button. This time will
168 * be selected by default on the #HildonTimeSelector.
173 hildon_time_button_set_time (HildonTimeButton * button,
174 guint hours, guint minutes)
176 HildonTouchSelector *selector;
179 g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
181 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
183 hildon_time_selector_set_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
185 time = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
186 hildon_button_set_value (HILDON_BUTTON (button), time);