Make sure that all timeouts in HildonBanner are removed
[hildon] / hildon / hildon-time-button.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
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.
9  *
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.
14  *
15  */
16
17 /**
18  * SECTION:hildon-time-button
19  * @Short_Description: Button displaying and allowing selection of a time.
20  * @See_Also: #HildonPickerButton, #HildonDateButton
21  *
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.
26  */
27
28 #include <libintl.h>
29
30 #include "hildon-time-selector.h"
31 #include "hildon-touch-selector.h"
32 #include "hildon-picker-button.h"
33 #include "hildon-time-button.h"
34
35 #define                                         _(String) \
36                                                 dgettext("hildon-libs", String)
37
38 #define                                         c_(String) \
39                                                 dgettext("hildon-common-strings", String)
40
41 G_DEFINE_TYPE (HildonTimeButton, hildon_time_button, HILDON_TYPE_PICKER_BUTTON)
42
43 #if 0
44 #define GET_PRIVATE(o)                                                  \
45   (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_TIME_BUTTON, HildonTimeButtonPrivate))
46 typedef struct _HildonTimeButtonPrivate HildonTimeButtonPrivate;
47
48 struct _HildonTimeButtonPrivate
49 {
50 };
51 #endif
52
53 #if 0
54 static void
55 hildon_time_button_get_property (GObject * object, guint property_id,
56                                  GValue * value, GParamSpec * pspec)
57 {
58   switch (property_id) {
59   default:
60     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
61   }
62 }
63
64 static void
65 hildon_time_button_set_property (GObject * object, guint property_id,
66                                  const GValue * value, GParamSpec * pspec)
67 {
68   switch (property_id) {
69   default:
70     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
71   }
72 }
73 #endif
74
75 static void
76 hildon_time_button_class_init (HildonTimeButtonClass * klass)
77 {
78 #if 0
79   GObjectClass *object_class = G_OBJECT_CLASS (klass);
80
81   g_type_class_add_private (klass, sizeof (HildonTimeButtonPrivate));
82
83   object_class->get_property = hildon_time_button_get_property;
84   object_class->set_property = hildon_time_button_set_property;
85 #endif
86 }
87
88 static void
89 hildon_time_button_init (HildonTimeButton * self)
90 {
91 }
92
93 /**
94  * hildon_time_button_new:
95  * @size: One of #HildonSizeType
96  * @arrangement: one of #HildonButtonArrangement
97  *
98  * Creates a new #HildonTimeButton. See hildon_button_new() for details on the
99  * parameters.
100  *
101  * Returns: a new #HildonTimeButton
102  *
103  * Since: 2.2
104  **/
105 GtkWidget *
106 hildon_time_button_new (HildonSizeType          size,
107                         HildonButtonArrangement arrangement)
108 {
109   return hildon_time_button_new_step (size, arrangement, 1);
110 }
111
112 /**
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
117  *
118  * Creates a new #HildonTimeButton. See hildon_button_new() for details on the
119  * parameters.
120  *
121  * Returns: a new #HildonTimeButton
122  *
123  * Since: 2.2
124  **/
125 GtkWidget *
126 hildon_time_button_new_step (HildonSizeType          size,
127                              HildonButtonArrangement arrangement,
128                              guint                   minutes_step)
129 {
130   return g_object_new (HILDON_TYPE_TIME_BUTTON,
131                        "title", _("wdgt_ti_time"),
132                        "arrangement", arrangement,
133                        "size", size,
134                        "touch-selector", hildon_time_selector_new_step (minutes_step),
135                        NULL);
136 }
137
138 /**
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
143  *
144  * Retrieves the time from @button.
145  *
146  * Since: 2.2
147  **/
148 void
149 hildon_time_button_get_time (HildonTimeButton * button,
150                              guint * hours, guint * minutes)
151 {
152   HildonTouchSelector *selector;
153
154   g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
155
156   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
157
158   hildon_time_selector_get_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
159 }
160
161 /**
162  * hildon_time_button_set_time:
163  * @button: a #HildonTimeButton
164  * @hours: the hours to be set
165  * @minutes: the time to be set
166  *
167  * Sets the time to be displayed in @button. This time will
168  * be selected by default on the #HildonTimeSelector.
169  *
170  * Since: 2.2
171  **/
172 void
173 hildon_time_button_set_time (HildonTimeButton * button,
174                              guint hours, guint minutes)
175 {
176   HildonTouchSelector *selector;
177   gchar *time;
178
179   g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
180
181   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
182
183   hildon_time_selector_set_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
184
185   time = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
186   hildon_button_set_value (HILDON_BUTTON (button), time);
187   g_free (time);
188 }