b2926cfda78364805137608b5188dabbeb81173d
[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 (HildonButtonFlags flags)
82 {
83   return g_object_new (HILDON_TYPE_TIME_BUTTON,
84                        "title", "Time", "arrangement-flags", flags, NULL);
85 }
86
87 void
88 hildon_time_button_get_time (HildonTimeButton * button,
89                              guint * hours, guint * minutes)
90 {
91   HildonTouchSelector *selector;
92
93   g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
94
95   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
96
97   hildon_time_selector_get_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
98 }
99
100 void
101 hildon_time_button_set_time (HildonTimeButton * button,
102                              guint hours, guint minutes)
103 {
104   HildonTouchSelector *selector;
105   gchar *time;
106
107   g_return_if_fail (HILDON_IS_TIME_BUTTON (button));
108
109   selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
110
111   hildon_time_selector_set_time (HILDON_TIME_SELECTOR (selector), hours, minutes);
112   time = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
113
114   hildon_button_set_value (HILDON_BUTTON (button), time);
115 }