2008-07-29 Claudio Saavedra <csaavedra@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 #include "hildon-date-selector.h"
18 #include "hildon-touch-picker.h"
19 #include "hildon-picker-button.h"
20 #include "hildon-date-button.h"
21
22 G_DEFINE_TYPE (HildonDateButton, hildon_date_button, HILDON_TYPE_PICKER_BUTTON)
23
24 #if 0
25 #define GET_PRIVATE(o)                                                  \
26   (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_DATE_BUTTON, HildonDateButtonPrivate))
27
28 typedef struct _HildonDateButtonPrivate HildonDateButtonPrivate;
29
30 struct _HildonDateButtonPrivate
31 {
32 };
33 #endif
34
35 #if 0
36 static void
37 hildon_date_button_get_property (GObject * object, guint property_id,
38                                  GValue * value, GParamSpec * pspec)
39 {
40   switch (property_id) {
41   default:
42     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
43   }
44 }
45
46 static void
47 hildon_date_button_set_property (GObject * object, guint property_id,
48                                  const GValue * value, GParamSpec * pspec)
49 {
50   switch (property_id) {
51   default:
52     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
53   }
54 }
55 #endif
56
57 static void
58 hildon_date_button_class_init (HildonDateButtonClass * klass)
59 {
60 #if 0
61   GObjectClass *object_class = G_OBJECT_CLASS (klass);
62
63   g_type_class_add_private (klass, sizeof (HildonDateButtonPrivate));
64
65   object_class->get_property = hildon_date_button_get_property;
66   object_class->set_property = hildon_date_button_set_property;
67 #endif
68 }
69
70 static void
71 hildon_date_button_init (HildonDateButton * self)
72 {
73   GtkWidget *date_selector;
74
75   date_selector = hildon_date_selector_new ();
76
77   hildon_picker_button_set_picker (HILDON_PICKER_BUTTON (self),
78                                    HILDON_TOUCH_PICKER (date_selector));
79 }
80
81 GtkWidget *
82 hildon_date_button_new (HildonButtonFlags flags)
83 {
84   return g_object_new (HILDON_TYPE_DATE_BUTTON,
85                        "title", "Date",
86                        "arrangement-flags", flags,
87                        NULL);
88 }
89
90 void
91 hildon_date_button_get_date (HildonDateButton * button,
92                              guint * year, guint * month, guint * day)
93 {
94   HildonTouchPicker *picker;
95
96   g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
97
98   picker = hildon_picker_button_get_picker (HILDON_PICKER_BUTTON (button));
99
100   hildon_date_selector_get_date (HILDON_DATE_SELECTOR (picker), year, month, day);
101 }
102
103 void
104 hildon_date_button_set_date (HildonDateButton * button,
105                              guint year, guint month, guint day)
106 {
107   HildonTouchPicker *picker;
108   gchar *date;
109
110   g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
111
112   picker = hildon_picker_button_get_picker (HILDON_PICKER_BUTTON (button));
113
114   hildon_date_selector_select_current_date (HILDON_DATE_SELECTOR (picker),
115                                             year, month, day);
116   date = hildon_touch_picker_get_current_text (HILDON_TOUCH_PICKER (picker));
117
118   hildon_button_set_value (HILDON_BUTTON (button), date);
119 }