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.
28 #include "hildon-time-selector.h"
29 #include "hildon-touch-selector.h"
30 #include "hildon-picker-button.h"
31 #include "hildon-time-button.h"
33 G_DEFINE_TYPE (HildonTimeButton, hildon_time_button, HILDON_TYPE_PICKER_BUTTON)
36 #define GET_PRIVATE(o) \
37 (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_TIME_BUTTON, HildonTimeButtonPrivate))
38 typedef struct _HildonTimeButtonPrivate HildonTimeButtonPrivate;
40 struct _HildonTimeButtonPrivate
47 hildon_time_button_get_property (GObject * object, guint property_id,
48 GValue * value, GParamSpec * pspec)
50 switch (property_id) {
52 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
57 hildon_time_button_set_property (GObject * object, guint property_id,
58 const GValue * value, GParamSpec * pspec)
60 switch (property_id) {
62 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68 hildon_time_button_class_init (HildonTimeButtonClass * klass)
71 GObjectClass *object_class = G_OBJECT_CLASS (klass);
73 g_type_class_add_private (klass, sizeof (HildonTimeButtonPrivate));
75 object_class->get_property = hildon_time_button_get_property;
76 object_class->set_property = hildon_time_button_set_property;
81 hildon_time_button_init (HildonTimeButton * self)
83 GtkWidget *time_selector;
85 time_selector = hildon_time_selector_new ();
87 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self),
88 HILDON_TOUCH_SELECTOR (time_selector));
92 * hildon_time_button_new:
93 * @size: One of #HildonSizeType
94 * @arrangement: one of #HildonButtonArrangement
96 * Creates a new #HildonTimeButton. See hildon_button_new() for details on the
99 * Returns: a new #HildonTimeButton
102 hildon_time_button_new (HildonSizeType size,
103 HildonButtonArrangement arrangement)
105 return g_object_new (HILDON_TYPE_TIME_BUTTON,
106 "title", "Time", "arrangement", arrangement, "size", size, NULL);
110 * hildon_time_button_get_time:
111 * @button: a #HildonTimeButton
112 * @hours: return location for the hours of the time selected
113 * @minutes: return location for the minutes of the time selected
115 * Retrieves the time from @button.
118 hildon_time_button_get_time (HildonTimeButton * button,
119 guint * hours, guint * minutes)
121 HildonTouchSelector *selector;
123 g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
125 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
127 hildon_time_selector_get_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
131 * hildon_time_button_set_time:
132 * @button: a #HildonTimeButton
133 * @hours: the hours to be set
134 * @minutes: the time to be set
136 * Sets the time to be displayed in @button. This time will
137 * be selected by default on the #HildonTimeSelector.
140 hildon_time_button_set_time (HildonTimeButton * button,
141 guint hours, guint minutes)
143 HildonTouchSelector *selector;
146 g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
148 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
150 hildon_time_selector_set_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
152 time = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
153 hildon_button_set_value (HILDON_BUTTON (button), time);