1 #include <Elementary.h>
2 #include <system_settings.h>
12 #include "main_view.h"
15 #define _EDJ(o) elm_layout_edje_get(o)
16 const char *const DATA_KEY_RESULT = "result";
17 const char *const DATA_KEY_CITY = "city";
19 struct _result_info_s {
25 typedef struct _result_info_s result_info_s;
27 const char *const ITEM_EDJE = "item.edj";
29 void _text_set_here_time(Evas_Object *item, const char *part)
31 char *timezone_str = NULL;
32 struct tm *local_time = NULL;
34 int ret = SYSTEM_SETTINGS_ERROR_NONE;
36 char time_result[PATH_LEN] = {0, };
41 local_time = localtime(&t);
44 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, &timezone_str);
45 if (ret != SYSTEM_SETTINGS_ERROR_NONE)
46 _E("cannot get the timezone string");
51 if (local_time->tm_gmtoff >= 0)
52 snprintf(time_result, sizeof(time_result), "%s, +%ld", timezone_str, local_time->tm_gmtoff / 3600);
54 snprintf(time_result, sizeof(time_result), "%s, %ld", timezone_str, local_time->tm_gmtoff / 3600);
58 elm_object_part_text_set(item, part, timezone_str);
61 static void _item_typing_down_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
63 _D("An item is down");
66 static void _item_typing_up_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
68 Evas_Object *item = obj;
69 Evas_Object *selecting_item = NULL;
70 main_view_s *main_view_info = data;
74 ret_if(!main_view_info);
75 ret_if(!main_view_info->selected_scroller);
77 _D("An item is selected");
79 city = (int) evas_object_data_get(item, DATA_KEY_CITY);
80 selecting_item = item_create_selecting(main_view_info->selected_scroller, city, 0);
81 ret_if(!selecting_item);
83 scroller_append_item(main_view_info->selected_scroller, selecting_item);
86 Evas_Object *item_create_typing(Evas_Object *parent, int city, main_view_s *main_view_info)
88 Evas_Object *item = NULL;
89 city_s *city_info = NULL;
92 char full_path[PATH_LEN] = {0, };
93 char city_str[PATH_LEN] = {0, };
95 retv_if(!parent, NULL);
97 path = app_get_resource_path();
100 snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, ITEM_EDJE);
103 item = elm_layout_add(parent);
104 retv_if(!item, NULL);
106 elm_layout_file_set(item, full_path, "item_typing");
108 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
109 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
110 evas_object_data_set(item, DATA_KEY_CITY, (void *) city);
111 evas_object_show(item);
113 city_info = city_get();
115 _E("Critical, no city information");
116 evas_object_del(item);
120 snprintf(city_str, sizeof(city_str), "%s, %s", city_info[city].name, city_info[city].nation);
121 elm_object_part_text_set(item, "city", city_str);
123 elm_object_signal_callback_add(item, "down", "item", _item_typing_down_cb, NULL);
124 elm_object_signal_callback_add(item, "up", "item", _item_typing_up_cb, main_view_info);
129 void item_destroy_typing(Evas_Object *item)
133 elm_object_signal_callback_del(item, "down", "item", _item_typing_down_cb);
134 elm_object_signal_callback_del(item, "up", "item", _item_typing_up_cb);
136 evas_object_data_del(item, DATA_KEY_CITY);
137 evas_object_del(item);
140 static void _delete_down_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
142 _D("Delete button is down");
145 static void _delete_up_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
147 Evas_Object *item= obj;
151 item_destroy_selecting(item);
154 Evas_Object *item_create_selecting(Evas_Object *parent, int city, int color)
156 Evas_Object *item = NULL;
157 city_s *city_info = NULL;
160 char full_path[PATH_LEN] = {0, };
161 char city_str[PATH_LEN] = {0, };
162 char color_str[16] = {0, };
164 retv_if(!parent, NULL);
166 _D("HELLO, city:%d, color:%d", city, color);
167 path = app_get_resource_path();
168 retv_if(!path, NULL);
170 snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, ITEM_EDJE);
173 item = elm_layout_add(parent);
174 retv_if(!item, NULL);
176 elm_layout_file_set(item, full_path, "item_selecting");
178 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
179 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
180 evas_object_show(item);
182 city_info = city_get();
184 _E("Critical, no city information");
185 evas_object_del(item);
189 snprintf(city_str, sizeof(city_str), "%s, %s", city_info[city].name, city_info[city].nation);
190 elm_object_part_text_set(item, "city", city_str);
193 snprintf(color_str, sizeof(color_str), "%d", color);
194 elm_object_signal_emit(item, color_str, "mark");
197 elm_object_signal_callback_add(item, "delete,down", "item", _delete_down_cb, NULL);
198 elm_object_signal_callback_add(item, "delete,up", "item", _delete_up_cb, NULL);
203 void item_destroy_selecting(Evas_Object *item)
207 elm_object_signal_callback_del(item, "delete,down", "item", _delete_down_cb);
208 elm_object_signal_callback_del(item, "delete,up", "item", _delete_up_cb);
210 evas_object_del(item);
213 void _text_set_local_time(Evas_Object *item, const char *part, int city, struct tm *global_time)
215 city_s *city_info = NULL;
216 int hour = global_time->tm_hour;
217 int minute = global_time->tm_min;
219 char time_result[PATH_LEN] = {0, };
224 city_info = city_get();
227 if (((double) ((int) city_info[city].timezone)) < city_info[city].timezone) {
235 snprintf(time_result, sizeof(time_result), "%d:%d", hour, minute);
236 elm_object_part_text_set(item, part, time_result);
239 static void _resize_graph_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
241 result_info_s *result_info = NULL;
245 result_info = evas_object_data_get(obj, DATA_KEY_RESULT);
246 ret_if(!result_info);
248 edje_object_part_geometry_get(_EDJ(obj), "graph_base", &x, &y, &w, &h);
250 if (result_info->start > result_info->end) {
251 evas_object_move(result_info->rect2, x, y);
252 evas_object_resize(result_info->rect2, w / 10.0, h);
253 evas_object_color_set(result_info->rect2, 0, 0, 0, 255);
254 evas_object_show(result_info->rect2);
256 evas_object_hide(result_info->rect2);
259 start_x = (result_info->start / 24.0f) * w + x;
261 evas_object_move(result_info->rect1, start_x, y);
262 evas_object_resize(result_info->rect1, x + w - start_x, h);
263 evas_object_color_set(result_info->rect1, 0, 0, 0, 255);
264 evas_object_show(result_info->rect1);
267 Evas_Object *item_create_result(Evas_Object *parent, int city, int color, int start, int end, struct tm *global_time)
269 Evas_Object *item = NULL;
270 city_s *city_info = NULL;
271 result_info_s *result_info = NULL;
275 char full_path[PATH_LEN] = {0, };
276 char city_str[PATH_LEN] = {0, };
277 char color_str[16] = {0, };
279 retv_if(!parent, NULL);
281 path = app_get_resource_path();
282 retv_if(!path, NULL);
284 snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, ITEM_EDJE);
287 result_info = calloc(1, sizeof(result_info_s));
288 retv_if(!result_info, NULL);
290 item = elm_layout_add(parent);
291 goto_if(!item, error);
293 elm_layout_file_set(item, full_path, "item_result");
295 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
296 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
297 evas_object_data_set(item, DATA_KEY_RESULT, result_info);
298 evas_object_show(item);
300 city_info = city_get();
301 goto_if(!city_info, error);
303 snprintf(city_str, sizeof(city_str), "%s, %s", city_info[city].name, city_info[city].nation);
304 elm_object_part_text_set(item, "city", city_str);
306 snprintf(color_str, sizeof(color_str), "%d", color);
307 elm_object_signal_emit(item, color_str, "mark");
309 _text_set_local_time(item, "time", city, global_time);
311 e = evas_object_evas_get(item);
314 result_info->rect1 = evas_object_rectangle_add(e);
315 goto_if(!result_info->rect1, error);
317 result_info->rect2 = evas_object_rectangle_add(e);
318 goto_if(!result_info->rect2, error);
320 result_info->start = start;
321 result_info->end = end;
323 evas_object_event_callback_add(item, EVAS_CALLBACK_RESIZE, _resize_graph_cb, result_info);
324 evas_object_event_callback_add(item, EVAS_CALLBACK_MOVE, _resize_graph_cb, result_info);
330 if (result_info->rect1)
331 evas_object_del(result_info->rect1);
332 if (result_info->rect2)
333 evas_object_del(result_info->rect2);
338 evas_object_del(item);
344 void item_destroy_result(Evas_Object *item)
346 result_info_s *result_info = NULL;
350 elm_object_signal_callback_del(item, "delete,down", "item", _delete_down_cb);
351 elm_object_signal_callback_del(item, "delete,up", "item", _delete_up_cb);
353 result_info = evas_object_data_del(item, DATA_KEY_RESULT);
355 if (result_info->rect1)
356 evas_object_del(result_info->rect1);
357 if (result_info->rect2)
358 evas_object_del(result_info->rect2);
362 evas_object_del(item);