2 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @brief EailClock implementation
25 #include <Elementary.h>
27 #include "eail_clock.h"
28 #include "eail_utils.h"
30 static void atk_value_interface_init(AtkValueIface *iface);
33 * @brief Define EailClock GObject type
35 G_DEFINE_TYPE_WITH_CODE(EailClock,
38 G_IMPLEMENT_INTERFACE(ATK_TYPE_VALUE,
39 atk_value_interface_init));
42 * @brief handler for changed event
44 * @param data passed to callback
45 * @param obj object that raised event
46 * @param event_info additional event info
50 _eail_clock_handle_changed_event(void *data,
55 (ATK_OBJECT(data), "visible-data-changed", ATK_TYPE_OBJECT);
59 * Implementation of the *AtkObject* interface
63 * @brief EailClock object initialization
65 * @param obj EailClock object
66 * @param data additional initialization data
69 eail_clock_initialize(AtkObject *obj, gpointer data)
71 Evas_Object *nested_widget = NULL;
72 ATK_OBJECT_CLASS(eail_clock_parent_class)->initialize(obj, data);
74 obj->role = ATK_ROLE_TEXT;
75 g_return_if_fail(EAIL_IS_WIDGET(obj));
77 nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
78 evas_object_smart_callback_add(nested_widget, "changed",
79 _eail_clock_handle_changed_event, obj);
83 * @brief EailClock instance initialization
85 * @param clock EailClock instance
88 eail_clock_init(EailClock *clock)
93 * @brief GObject type initialization function
95 * @param klass EailClockClass instance
98 eail_clock_class_init(EailClockClass *klass)
100 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
102 atk_class->initialize = eail_clock_initialize;
106 * Implementation of the *AtkValue* interface
110 * @brief Gets obj's current value
112 * @param obj EailClock instance
113 * @param [out] value obj's current value
116 eail_clock_get_current_value(AtkValue *obj,
120 int hour, minute, second;
121 int current_second_day;
123 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
126 elm_clock_time_get(widget, &hour, &minute, &second);
128 current_second_day = (3600 * hour) + (60 * minute) + second;
130 memset(value, 0, sizeof(GValue));
131 g_value_init(value, G_TYPE_INT);
132 g_value_set_int(value, current_second_day);
136 * @brief Gets obj's maxiumum value
138 * @param obj EailClock instance
139 * @param [out] value obj's maxiumum value
142 eail_clock_get_maximum_value(AtkValue *obj,
147 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
150 memset(value, 0, sizeof(GValue));
151 g_value_init(value, G_TYPE_INT);
152 g_value_set_int(value, 24 * 60 * 60 - 1); // 24h - 1s
156 * @brief Gets obj's minimum value
158 * @param obj EailClock instance
159 * @param [out] value obj's minimum value
162 eail_clock_get_minimum_value(AtkValue *obj,
167 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
170 memset(value, 0, sizeof(GValue));
171 g_value_init(value, G_TYPE_INT);
172 g_value_set_int(value, 0); // 0 - seconds
176 * @brief Sets obj's value
178 * @param obj EailClock instance
179 * @param value obj's new value
180 * @return TRUE if new value was set successfully, FALSE otherwise
183 eail_clock_set_current_value(AtkValue *obj,
187 int hour, minute, second;
188 int current_second_day;
190 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
191 if (!widget) return FALSE;
193 current_second_day = g_value_get_int(value);
195 if (0 > current_second_day)
198 hour = current_second_day / 3600;
199 minute = (current_second_day % 3600) / 60;
200 second = current_second_day % 60;
202 if (23 < hour || 59 < minute || 59 < second)
205 elm_clock_time_set(widget, hour, minute, second);
211 * @brief Gets obj's minimum increment
213 * @param obj EailClock instance
214 * @param [out] value obj's minimum increment
217 eail_clock_get_minimum_increment(AtkValue *obj,
222 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
225 memset(value, 0, sizeof(GValue));
226 g_value_init(value, G_TYPE_INT);
227 g_value_set_int(value, 1);
231 * @brief Initialization of AtkValue interface
233 * @brief Function called upon instance creation.
235 * It initializes AtkValue interface
236 * implementation i.e hooks method pointers in the interface structure
237 * to the implementing class's implementation.
239 * @param iface AtkObject that implements AtkValueInterface
242 atk_value_interface_init(AtkValueIface *iface)
244 g_return_if_fail(iface != NULL);
246 iface->get_current_value = eail_clock_get_current_value;
247 iface->get_maximum_value = eail_clock_get_maximum_value;
248 iface->get_minimum_value = eail_clock_get_minimum_value;
249 iface->set_current_value = eail_clock_set_current_value;
250 iface->get_minimum_increment = eail_clock_get_minimum_increment;