2008-08-11 Alberto Garcia <agarcia@igalia.com>
[hildon] / src / hildon-date-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-date-button
19  * @Short_Description: Button displaying and allowing selection of a date.
20  * @See_Also: #HildonPickerButton, #HildonTimeButton
21  *
22  * #HildonDateButton is a widget that shows a text label and a date, and allows
23  * the user to select a different date. Visually, it's a button that, once clicked,
24  * presents a #HildonPickerDialog containing a #HildonDateSelector. Once the user selects
25  * a different date from the selector, this will be shown in the button.
26  */
27
28 #include "hildon-date-selector.h"
29 #include "hildon-touch-selector.h"
30 #include "hildon-picker-button.h"
31 #include "hildon-date-button.h"
32
33 G_DEFINE_TYPE (HildonDateButton, hildon_date_button, HILDON_TYPE_PICKER_BUTTON)
34
35 #if 0
36 #define GET_PRIVATE(o)                                                  \
37   (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_DATE_BUTTON, HildonDateButtonPrivate))
38
39 typedef struct _HildonDateButtonPrivate HildonDateButtonPrivate;
40
41 struct _HildonDateButtonPrivate
42 {
43 };
44 #endif
45
46 #if 0
47 static void
48 hildon_date_button_get_property (GObject * object, guint property_id,
49                                  GValue * value, GParamSpec * pspec)
50 {
51   switch (property_id) {
52   default:
53     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
54   }
55 }
56
57 static void
58 hildon_date_button_set_property (GObject * object, guint property_id,
59                                  const GValue * value, GParamSpec * pspec)
60 {
61   switch (property_id) {
62   default:
63     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
64   }
65 }
66 #endif
67
68 static void
69 hildon_date_button_class_init (HildonDateButtonClass * klass)
70 {
71 #if 0
72   GObjectClass *object_class = G_OBJECT_CLASS (klass);
73
74   g_type_class_add_private (klass, sizeof (HildonDateButtonPrivate));
75
76   object_class->get_property = hildon_date_button_get_property;
77   object_class->set_property = hildon_date_button_set_property;
78 #endif
79 }
80
81 static void
82 hildon_date_button_init (HildonDateButton * self)
83 {
84   GtkWidget *date_selector;
85
86   date_selector = hildon_date_selector_new ();
87
88   hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self),
89                                      HILDON_TOUCH_SELECTOR (date_selector));
90 }
91
92 /**
93  * hildon_date_button_new:
94  * @size: One of #HildonSizeType
95  * @arrangement: one of #HildonButtonArrangement
96  *
97  * Creates a new #HildonDateButton. See hildon_button_new() for details on the
98  * parameters.
99  *
100  * Returns: a new #HildonDateButton
101  **/
102 GtkWidget *
103 hildon_date_button_new (HildonSizeType          size,
104                         HildonButtonArrangement arrangement)
105 {
106   return g_object_new (HILDON_TYPE_DATE_BUTTON,
107                        "title", "Date",
108                        "arrangement", arrangement,
109                        "size", size,
110                        NULL);
111 }
112
113 /**
114  * hildon_date_button_get_date:
115  * @button: a #HildonDateButton
116  * @year: return location for the selected year
117  * @month: return location for the selected month
118  * @day: return location for the selected day
119  *
120  * Retrieves currently selected date from @button.
121  **/
122 void
123 hildon_date_button_get_date (HildonDateButton * button,
124                              guint * year, guint * month, guint * day)
125 {
126   HildonTouchSelector *selector;
127
128   g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
129
130   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
131
132   hildon_date_selector_get_date (HILDON_DATE_SELECTOR (selector), year, month, day);
133 }
134
135 /**
136  * hildon_date_button_set_date:
137  * @button: a #HildonDateButton
138  * @year: the year to set.
139  * @month: the month number to set.
140  * @day: the day of the month to set.
141  *
142  * Sets the date in @button. The date set will be displayed
143  * and will be the default selected option on the shown #HildonDateSelector.
144  *
145  **/
146 void
147 hildon_date_button_set_date (HildonDateButton * button,
148                              guint year, guint month, guint day)
149 {
150   HildonTouchSelector *selector;
151   gchar *date;
152
153   g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
154
155   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
156
157   hildon_date_selector_select_current_date (HILDON_DATE_SELECTOR (selector),
158                                             year, month, day);
159   date = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
160
161   hildon_button_set_value (HILDON_BUTTON (button), date);
162 }