f180f8addae93efea96fd013c6da7c37d5516214
[hildon] / src / 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   GtkWidget *button;
131   GtkWidget *time_selector;
132
133   button = g_object_new (HILDON_TYPE_TIME_BUTTON,
134                          "title", _("wdgt_ti_time"), "arrangement", arrangement, "size", size, NULL);
135
136   time_selector = hildon_time_selector_new_step (minutes_step);
137
138   hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
139                                      HILDON_TOUCH_SELECTOR (time_selector));
140
141   return button;
142 }
143
144 /**
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
149  *
150  * Retrieves the time from @button.
151  *
152  * Since: 2.2
153  **/
154 void
155 hildon_time_button_get_time (HildonTimeButton * button,
156                              guint * hours, guint * minutes)
157 {
158   HildonTouchSelector *selector;
159
160   g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
161
162   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
163
164   hildon_time_selector_get_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
165 }
166
167 /**
168  * hildon_time_button_set_time:
169  * @button: a #HildonTimeButton
170  * @hours: the hours to be set
171  * @minutes: the time to be set
172  *
173  * Sets the time to be displayed in @button. This time will
174  * be selected by default on the #HildonTimeSelector.
175  *
176  * Since: 2.2
177  **/
178 void
179 hildon_time_button_set_time (HildonTimeButton * button,
180                              guint hours, guint minutes)
181 {
182   HildonTouchSelector *selector;
183   gchar *time;
184
185   g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
186
187   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
188
189   hildon_time_selector_set_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
190
191   time = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
192   hildon_button_set_value (HILDON_BUTTON (button), time);
193   g_free (time);
194 }