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,
131 GtkWidget *time_selector;
133 button = g_object_new (HILDON_TYPE_TIME_BUTTON,
134 "title", _("wdgt_ti_time"), "arrangement", arrangement, "size", size, NULL);
136 time_selector = hildon_time_selector_new_step (minutes_step);
138 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
139 HILDON_TOUCH_SELECTOR (time_selector));
145 * hildon_time_button_get_time:
146 * @button: a #HildonTimeButton
147 * @hours: return location for the hours of the time selected
148 * @minutes: return location for the minutes of the time selected
150 * Retrieves the time from @button.
155 hildon_time_button_get_time (HildonTimeButton * button,
156 guint * hours, guint * minutes)
158 HildonTouchSelector *selector;
160 g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
162 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
164 hildon_time_selector_get_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
168 * hildon_time_button_set_time:
169 * @button: a #HildonTimeButton
170 * @hours: the hours to be set
171 * @minutes: the time to be set
173 * Sets the time to be displayed in @button. This time will
174 * be selected by default on the #HildonTimeSelector.
179 hildon_time_button_set_time (HildonTimeButton * button,
180 guint hours, guint minutes)
182 HildonTouchSelector *selector;
185 g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
187 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
189 hildon_time_selector_set_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
191 time = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
192 hildon_button_set_value (HILDON_BUTTON (button), time);