2008-08-07 Alberto Garcia <agarcia@igalia.com>
[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 #include "hildon-time-selector.h"
18 #include "hildon-touch-selector.h"
19 #include "hildon-picker-button.h"
20 #include "hildon-time-button.h"
21
22 G_DEFINE_TYPE (HildonTimeButton, hildon_time_button, HILDON_TYPE_PICKER_BUTTON)
23
24 #if 0
25 #define GET_PRIVATE(o)                                                  \
26   (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_TIME_BUTTON, HildonTimeButtonPrivate))
27 typedef struct _HildonTimeButtonPrivate HildonTimeButtonPrivate;
28
29 struct _HildonTimeButtonPrivate
30 {
31 };
32 #endif
33
34 #if 0
35 static void
36 hildon_time_button_get_property (GObject * object, guint property_id,
37                                  GValue * value, GParamSpec * pspec)
38 {
39   switch (property_id) {
40   default:
41     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
42   }
43 }
44
45 static void
46 hildon_time_button_set_property (GObject * object, guint property_id,
47                                  const GValue * value, GParamSpec * pspec)
48 {
49   switch (property_id) {
50   default:
51     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
52   }
53 }
54 #endif
55
56 static void
57 hildon_time_button_class_init (HildonTimeButtonClass * klass)
58 {
59 #if 0
60   GObjectClass *object_class = G_OBJECT_CLASS (klass);
61
62   g_type_class_add_private (klass, sizeof (HildonTimeButtonPrivate));
63
64   object_class->get_property = hildon_time_button_get_property;
65   object_class->set_property = hildon_time_button_set_property;
66 #endif
67 }
68
69 static void
70 hildon_time_button_init (HildonTimeButton * self)
71 {
72   GtkWidget *time_selector;
73
74   time_selector = hildon_time_selector_new ();
75
76   hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self),
77                                      HILDON_TOUCH_SELECTOR (time_selector));
78 }
79
80 GtkWidget *
81 hildon_time_button_new (HildonSizeType          size,
82                         HildonButtonArrangement arrangement)
83 {
84   return g_object_new (HILDON_TYPE_TIME_BUTTON,
85                        "title", "Time", "arrangement", arrangement, "size-flags", size, NULL);
86 }
87
88 void
89 hildon_time_button_get_time (HildonTimeButton * button,
90                              guint * hours, guint * minutes)
91 {
92   HildonTouchSelector *selector;
93
94   g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
95
96   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
97
98   hildon_time_selector_get_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
99 }
100
101 void
102 hildon_time_button_set_time (HildonTimeButton * button,
103                              guint hours, guint minutes)
104 {
105   HildonTouchSelector *selector;
106   gchar *time;
107
108   g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
109
110   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
111
112   hildon_time_selector_set_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
113   time = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
114
115   hildon_button_set_value (HILDON_BUTTON (button), time);
116 }