1 #include <Elementary.h>
2 #include <system_settings.h>
13 #define _EDJ(o) elm_layout_edje_get(o)
14 const char *const DATA_KEY_RESULT = "result";
16 struct _result_info_s {
22 typedef struct _result_info_s result_info_s;
24 const char *const ITEM_EDJE = "item.edj";
26 void _text_set_here_time(Evas_Object *item, const char *part)
28 char *timezone_str = NULL;
29 struct tm *local_time = NULL;
31 int ret = SYSTEM_SETTINGS_ERROR_NONE;
33 char time_result[PATH_LEN] = {0, };
38 local_time = localtime(&t);
41 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, &timezone_str);
42 if (ret != SYSTEM_SETTINGS_ERROR_NONE)
43 _E("cannot get the timezone string");
48 if (local_time->tm_gmtoff >= 0)
49 snprintf(time_result, sizeof(time_result), "%s, +%ld", timezone_str, local_time->tm_gmtoff / 3600);
51 snprintf(time_result, sizeof(time_result), "%s, %ld", timezone_str, local_time->tm_gmtoff / 3600);
55 elm_object_part_text_set(item, part, timezone_str);
58 static void _item_down_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
60 _D("An item is down");
63 static void _item_up_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
65 Evas_Object *item= obj;
69 _D("An item is selected");
71 /* Append to the selecting scroller */
74 Evas_Object *item_create_typing(Evas_Object *parent, int city)
76 Evas_Object *item = NULL;
77 city_s *city_info = NULL;
80 char full_path[PATH_LEN] = {0, };
81 char city_str[PATH_LEN] = {0, };
83 retv_if(!parent, NULL);
85 path = app_get_resource_path();
88 snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, ITEM_EDJE);
91 item = elm_layout_add(parent);
94 elm_layout_file_set(item, ITEM_EDJE, "item_typing");
96 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
97 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
98 evas_object_show(item);
100 city_info = city_get();
102 _E("Critical, no city information");
103 evas_object_del(item);
107 snprintf(city_str, sizeof(city_str), "%s", city_info[city].name);
108 elm_object_part_text_set(item, "city", city_str);
110 elm_object_signal_callback_add(item, "down", "item", _item_down_cb, NULL);
111 elm_object_signal_callback_add(item, "up", "item", _item_up_cb, NULL);
116 void item_destroy_typing(Evas_Object *item)
120 elm_object_signal_callback_del(item, "down", "item", _item_down_cb);
121 elm_object_signal_callback_del(item, "up", "item", _item_up_cb);
123 evas_object_del(item);
126 static void _delete_down_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
128 _D("Delete button is down");
131 static void _delete_up_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
133 Evas_Object *item= obj;
137 item_destroy_selecting(item);
140 Evas_Object *item_create_selecting(Evas_Object *parent, int city, int color)
142 Evas_Object *item = NULL;
143 city_s *city_info = NULL;
146 char full_path[PATH_LEN] = {0, };
147 char city_str[PATH_LEN] = {0, };
148 char color_str[16] = {0, };
150 retv_if(!parent, NULL);
152 path = app_get_resource_path();
153 retv_if(!path, NULL);
155 snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, ITEM_EDJE);
158 item = elm_layout_add(parent);
159 retv_if(!item, NULL);
161 elm_layout_file_set(item, ITEM_EDJE, "item_selecting");
163 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
164 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
165 evas_object_show(item);
167 city_info = city_get();
169 _E("Critical, no city information");
170 evas_object_del(item);
174 snprintf(city_str, sizeof(city_str), "%s, %s", city_info[city].name, city_info[city].nation);
175 elm_object_part_text_set(item, "city", city_str);
177 snprintf(color_str, sizeof(color_str), "%d", color);
178 elm_object_signal_emit(item, color_str, "mark");
180 elm_object_signal_callback_add(item, "delete,down", "item", _delete_down_cb, NULL);
181 elm_object_signal_callback_add(item, "delete,up", "item", _delete_up_cb, NULL);
186 void item_destroy_selecting(Evas_Object *item)
190 elm_object_signal_callback_del(item, "delete,down", "item", _delete_down_cb);
191 elm_object_signal_callback_del(item, "delete,up", "item", _delete_up_cb);
193 evas_object_del(item);
196 void _text_set_local_time(Evas_Object *item, const char *part, int city, struct tm *global_time)
198 city_s *city_info = NULL;
199 int hour = global_time->tm_hour;
200 int minute = global_time->tm_min;
202 char time_result[PATH_LEN] = {0, };
207 city_info = city_get();
210 if (((double) ((int) city_info[city].timezone)) < city_info[city].timezone) {
218 snprintf(time_result, sizeof(time_result), "%d:%d", hour, minute);
219 elm_object_part_text_set(item, part, time_result);
222 static void _resize_graph_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
224 result_info_s *result_info = NULL;
228 result_info = evas_object_data_get(obj, DATA_KEY_RESULT);
229 ret_if(!result_info);
231 edje_object_part_geometry_get(_EDJ(obj), "graph_base", &x, &y, &w, &h);
233 if (result_info->start > result_info->end) {
234 evas_object_move(result_info->rect2, x, y);
235 evas_object_resize(result_info->rect2, w / 10.0, h);
236 evas_object_color_set(result_info->rect2, 0, 0, 0, 255);
237 evas_object_show(result_info->rect2);
239 evas_object_hide(result_info->rect2);
242 start_x = (result_info->start / 24.0f) * w + x;
244 evas_object_move(result_info->rect1, start_x, y);
245 evas_object_resize(result_info->rect1, x + w - start_x, h);
246 evas_object_color_set(result_info->rect1, 0, 0, 0, 255);
247 evas_object_show(result_info->rect1);
250 Evas_Object *item_create_result(Evas_Object *parent, int city, int color, int start, int end, struct tm *global_time)
252 Evas_Object *item = NULL;
253 city_s *city_info = NULL;
254 result_info_s *result_info = NULL;
258 char full_path[PATH_LEN] = {0, };
259 char city_str[PATH_LEN] = {0, };
260 char color_str[16] = {0, };
262 retv_if(!parent, NULL);
264 path = app_get_resource_path();
265 retv_if(!path, NULL);
267 snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, ITEM_EDJE);
270 result_info = calloc(1, sizeof(result_info_s));
271 retv_if(!result_info, NULL);
273 item = elm_layout_add(parent);
274 goto_if(!item, error);
276 elm_layout_file_set(item, ITEM_EDJE, "item_result");
278 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
279 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
280 evas_object_data_set(item, DATA_KEY_RESULT, result_info);
281 evas_object_show(item);
283 city_info = city_get();
284 goto_if(!city_info, error);
286 snprintf(city_str, sizeof(city_str), "%s, %s", city_info[city].name, city_info[city].nation);
287 elm_object_part_text_set(item, "city", city_str);
289 snprintf(color_str, sizeof(color_str), "%d", color);
290 elm_object_signal_emit(item, color_str, "mark");
292 _text_set_local_time(item, "time", city, global_time);
294 e = evas_object_evas_get(item);
297 result_info->rect1 = evas_object_rectangle_add(e);
298 goto_if(!result_info->rect1, error);
300 result_info->rect2 = evas_object_rectangle_add(e);
301 goto_if(!result_info->rect2, error);
303 result_info->start = start;
304 result_info->end = end;
306 evas_object_event_callback_add(item, EVAS_CALLBACK_RESIZE, _resize_graph_cb, result_info);
307 evas_object_event_callback_add(item, EVAS_CALLBACK_MOVE, _resize_graph_cb, result_info);
313 if (result_info->rect1)
314 evas_object_del(result_info->rect1);
315 if (result_info->rect2)
316 evas_object_del(result_info->rect2);
321 evas_object_del(item);
327 void item_destroy_result(Evas_Object *item)
329 result_info_s *result_info = NULL;
333 elm_object_signal_callback_del(item, "delete,down", "item", _delete_down_cb);
334 elm_object_signal_callback_del(item, "delete,up", "item", _delete_up_cb);
336 result_info = evas_object_data_del(item, DATA_KEY_RESULT);
338 if (result_info->rect1)
339 evas_object_del(result_info->rect1);
340 if (result_info->rect2)
341 evas_object_del(result_info->rect2);
345 evas_object_del(item);