bc52175696d7b952aaf0985ef2e15c7c262ec1ce
[apps/core/preloaded/calendar.git] / ug / settings / ug-settings-view.c
1 /*
2   *
3   *  Copyright 2012  Samsung Electronics Co., Ltd
4   *
5   *  Licensed under the Flora License, Version 1.0 (the "License");
6   *  you may not use this file except in compliance with the License.
7   *  You may obtain a copy of the License at
8   *
9   *       http://floralicense.org/license/
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17
18
19 #include <fcntl.h>
20 #include <vconf.h>
21
22 #include "cld.h"
23 #include "acct-svc.h"
24 #include "ug-settings.h"
25 #include "external-ug.h"
26 #include "cld-images.h"
27
28 #define PROGRESS_BAR_TIMER_INTERVAL 0.1
29
30 typedef enum {
31         UI_SEPARATOR_TOP,
32         UI_SEPARATOR_MIDDLE,
33         UI_SEPARATOR_BOTTOM
34 }ui_separator;
35
36 typedef enum{
37         FOCUS_IN_DAILY = 1,
38         FOCUS_IN_WEEKLY
39 }focus_in_month_view_type;
40
41 typedef enum{
42         ITEM_LOCK_TIMEZONE_ON_OFF = 0,
43         ITEM_LOCK_TIMEZONE_GUIDE_TEXT,
44         ITEM_TIMEZONE,
45         ITEM_FIRST_DAY_OF_WEEK,
46         ITEM_SUNDAY,
47         ITEM_LOCALE_DEFAULT,
48         ITEM_MONDAY,
49         ITEM_SATURDAY,
50         ITEM_WEEK_NUMBER_ON_OFF,
51         ITEM_COMPLETED_TO_DO_ON_OFF,
52         ITEM_IMPORT_CALENDARS,
53         ITEM_EXPORT_CALENDARS,
54         ITEM_NONE
55 }item_type;
56
57 typedef struct
58 {
59         item_type  index;
60         int check_status;
61         Elm_Object_Item *item;
62         Evas_Object *rgd;
63         int chk_status;
64         struct ug_data *ugd;
65         Evas_Object *check;
66         char *city;
67         char *timezone;
68 }Item_data;
69
70 enum
71 {
72         SETTING_EXPORT_CALENDAR,
73         SETTING_IMPORT_CALENDAR
74 };
75
76 static Elm_Genlist_Item_Class itc_seperator = {
77         .item_style = "dialogue/separator/21/with_line",
78         .func.text_get = NULL,
79         .func.content_get = NULL,
80         .func.state_get = NULL,
81         .func.del = NULL,
82 };
83
84 static char *__cal_setting_ug_get_genlist_item_label(void *data, Evas_Object *obj, const char *part);
85 static Evas_Object *__cal_setting_ug_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part);
86 static char *__cal_setting_get_import_genlist_item_label(void *data, Evas_Object *obj, const char *part);
87 static Evas_Object* __cal_setting_get_import_genlist_icon(void *item_data, Evas_Object *obj, const char *part);
88 static void __cal_setting_gl_insert_genlist_item(struct ug_data *ugd, Evas_Object *genlist, Elm_Object_Item *item_after, int index);
89 static void __cal_setting_complete_todo_on_off_changed_callback(void *data, Evas_Object *obj, void *event_info);
90 static void __cal_setting_week_number_on_off_changed_callback(void *data, Evas_Object *obj, void *event_info);
91
92 extern void cal_setting_export_create_view(struct ug_data *data);
93
94 static Elm_Genlist_Item_Class itc_2text_1icon_2 = {
95         .item_style = "dialogue/2text.1icon.2",
96         .func.text_get = __cal_setting_get_import_genlist_item_label,
97         .func.content_get = __cal_setting_get_import_genlist_icon,
98 };
99
100 static Elm_Genlist_Item_Class itc_lock_tz = {
101         .item_style = "dialogue/1text.1icon",
102         .func.text_get = __cal_setting_ug_get_genlist_item_label,
103         .func.content_get = __cal_setting_ug_get_genlist_item_icon,
104         .func.state_get = NULL,
105         .func.del = NULL,
106 };
107
108 static Elm_Genlist_Item_Class itc_import = {
109         .item_style = "dialogue/1text",
110         .func.text_get = __cal_setting_ug_get_genlist_item_label,
111         .func.content_get = NULL,
112         .func.state_get = NULL,
113         .func.del = NULL,
114 };
115
116 static Elm_Genlist_Item_Class itc_tz = {
117         .item_style = "dialogue/2text.3",
118         .func.text_get = __cal_setting_ug_get_genlist_item_label,
119         .func.content_get = NULL,
120         .func.state_get = NULL,
121         .func.del = NULL,
122 };
123
124 static Elm_Genlist_Item_Class itc = {
125         .item_style = "dialogue/2text.3/expandable",
126         .func.text_get = __cal_setting_ug_get_genlist_item_label,
127         .func.content_get = NULL,
128         .func.state_get = NULL,
129         .func.del = NULL,
130 };
131
132 static Elm_Genlist_Item_Class itc_radio = {
133         .item_style = "dialogue/1text.1icon.2/expandable2",
134         .func.text_get = __cal_setting_ug_get_genlist_item_label,
135         .func.content_get = __cal_setting_ug_get_genlist_item_icon,
136         .func.state_get = NULL,
137         .func.del = NULL,
138 };
139
140 static Elm_Genlist_Item_Class itc_lock_tz_guide = {
141         .item_style = "multiline/1text",
142         .func.text_get = __cal_setting_ug_get_genlist_item_label,
143         .func.content_get = NULL,
144         .func.state_get = NULL,
145         .func.del = NULL,
146 };
147
148 static char *__cal_setting_get_import_genlist_item_label(void *data, Evas_Object *obj, const char *part)
149 {
150         c_retv_if(!data, NULL);
151         c_retv_if(!part, NULL);
152
153         calendar_record_h calendar_book = data;
154         char *name = NULL;
155         int cid = 0;
156         char* description = NULL;
157
158         calendar_error_e error = CALENDAR_ERROR_NONE;
159
160         if (!CAL_STRCMP(part,"elm.text.1")) {
161
162                 cid = _calendar_get_calendar_index(calendar_book);
163                 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
164                         return strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
165                 else if (cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
166                         return strdup(C_("IDS_TASK_BODY_MY_TASK"));
167                 else if (cid == DEFAULT_BIRTHDAY_CALENDAR_BOOK_ID)
168                         return strdup(C_("IDS_CLD_MBODY_CONTACTS_BIRTHDAY"));
169
170                 error = calendar_record_get_str(calendar_book, _calendar_book.name, &name);
171                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is faile(%x)", error);
172
173                 if (CAL_STRLEN(name))
174                         return name;
175                 else
176                         CAL_FREE(name);
177
178                 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
179
180         } else if (!CAL_STRCMP(part,"elm.text.2")) {
181
182                 error = calendar_record_get_int(calendar_book, _calendar_book.account_id, &cid);
183                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is faile(%x)", error);
184
185                 if (cid == _CALENDAR_LOCAL_ACCOUNT_ID)
186                         return strdup(C_("IDS_CLD_POP_MY_PHONE"));
187
188                 error = calendar_record_get_str(calendar_book, _calendar_book.description, &description);
189                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is faile(%x)", error);
190
191                 if (CAL_STRLEN(description))
192                         return description;
193                 else
194                         CAL_FREE(description);
195
196                 return strdup(S_("IDS_COM_POP_NO_ACCOUNTS"));
197         }
198
199         return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
200 }
201
202 static Evas_Object* __cal_setting_get_import_genlist_icon(void *item_data, Evas_Object *obj, const char *part)
203 {
204         c_retvm_if(!item_data, NULL, "item_data is null");
205         c_retvm_if(!obj, NULL, "obj is null");
206
207         Evas_Object *icon = NULL;
208         char* icon_path = NULL;
209         calendar_record_h calendar_book = item_data;
210         Eina_Bool r = EINA_FALSE;
211         int cid = 0;
212         int aid = 0;
213
214         calendar_error_e error = CALENDAR_ERROR_NONE;
215
216         error = calendar_record_get_int(calendar_book, _calendar_book.id, &cid);
217         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is faile(%x)", error);
218
219         error = calendar_record_get_int(calendar_book, _calendar_book.account_id, &aid);
220         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is faile(%x)", error);
221
222         if (!CAL_STRCMP(part, "elm.icon")) {
223                 icon = elm_icon_add(obj);
224
225                 if (!icon) {
226                         ERR("elm_icon_add fail");
227                         return NULL;
228                 }
229
230                 if ( aid == _CALENDAR_LOCAL_ACCOUNT_ID) {
231                         r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PHONE);
232                 } else {
233                         icon_path = cal_account_svc_get_account_icon_path(aid);
234                         if(icon_path) {
235                                 r = elm_icon_file_set(icon, icon_path, NULL);
236                                 free(icon_path);
237                         }
238                 }
239
240                 if (!r) {
241                         ERR("");
242                         evas_object_del(icon);
243                         icon = NULL;
244                 } else {
245                         evas_object_show(icon);
246                 }
247         }
248
249         return icon;
250 }
251
252 static char *__cal_setting_ug_get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
253 {
254         c_retvm_if(!data, NULL, "data is null");
255         c_retvm_if(!obj, NULL, "part is null");
256
257         Item_data *item_data = data;
258         item_type type = item_data->index;
259         struct tm tm;
260         time_t t;
261
262         t = time(NULL);
263         localtime_r(&t, &tm);
264
265         switch (type) {
266         case ITEM_TIMEZONE:
267                 if (!CAL_STRCMP(part, "elm.text.1")) {
268                         return strdup(C_("IDS_CLD_BODY_TIME_ZONE"));
269                 } else if (!CAL_STRCMP(part, "elm.text.2")) {
270                         return g_strdup_printf("%s, %s", S_(item_data->ugd->city), item_data->ugd->time_zone);
271                 }
272                 break;
273
274         case ITEM_LOCK_TIMEZONE_ON_OFF:
275                 if (!CAL_STRCMP(part, "elm.text"))
276                         return strdup(C_("IDS_CLD_MBODY_LOCK_TIME_ZONE"));
277                 break;
278
279         case ITEM_LOCK_TIMEZONE_GUIDE_TEXT:
280                 return strdup(C_("IDS_CLD_BODY_LOCK_TIME_ZONE_DESCRIPTION_MSG"));
281                 break;
282
283         case ITEM_FIRST_DAY_OF_WEEK:
284                 if (!CAL_STRCMP(part, "elm.text.1")) {
285                         return strdup(C_("IDS_CLD_BODY_FIRST_DAY_OF_WEEK"));
286                 } else if (!CAL_STRCMP(part, "elm.text.2")) {
287                         if (FIRST_DAY_LOCALE_DEFAULT == item_data->ugd->first_day_of_week) {
288                                 return strdup(C_("IDS_CLD_BODY_LOCALE_DEFAULT"));
289                         } else if (FIRST_DAY_SUNDAY == item_data->ugd->first_day_of_week) {
290                                 return strdup(C_("IDS_ST_BODY_SUNDAY"));
291                         } else if (FIRST_DAY_MONDAY == item_data->ugd->first_day_of_week) {
292                                 return strdup(C_("IDS_ST_BODY_MONDAY"));
293                         } else if (FIRST_DAY_SATURDAY == item_data->ugd->first_day_of_week) {
294                                 return strdup(S_("IDS_COM_BODY_SATURDAY"));
295                         }
296                 }
297                 break;
298
299         case ITEM_WEEK_NUMBER_ON_OFF:
300                 if (!CAL_STRCMP(part, "elm.text"))
301                         return strdup(C_("IDS_CLD_BODY_SHOW_WEEK_NUMBER"));
302                 break;
303
304         case ITEM_COMPLETED_TO_DO_ON_OFF:
305                 if (!CAL_STRCMP(part, "elm.text"))
306                         return strdup(C_("IDS_CLD_BODY_SHOW_COMPLETED_TASKS"));
307                 break;
308
309         case ITEM_LOCALE_DEFAULT:
310                 return strdup(C_("IDS_CLD_BODY_LOCALE_DEFAULT"));
311                 break;
312         case ITEM_SUNDAY:
313                 return strdup(C_("IDS_ST_BODY_SUNDAY"));
314                 break;
315         case ITEM_MONDAY:
316                 return strdup(C_("IDS_ST_BODY_MONDAY"));
317                 break;
318         case ITEM_SATURDAY:
319                 return strdup(S_("IDS_COM_BODY_SATURDAY"));
320                 break;
321         case ITEM_IMPORT_CALENDARS:
322                 if (!CAL_STRCMP(part, "elm.text"))
323                         return strdup(C_("IDS_CLD_BODY_IMPORT_EVENTS_TASKS_ABB"));
324                 break;
325
326         case ITEM_EXPORT_CALENDARS:
327                 if (!CAL_STRCMP(part, "elm.text"))
328                         return strdup(C_("IDS_CLD_BODY_EXPORT_EVENTS_TASKS_ABB"));
329                 break;
330         default:
331                 break;
332         }
333
334         return NULL;
335 }
336
337 static void __cal_setting_ug_radio_changed_callback(void *data, Evas_Object *obj, void *event_info)
338 {
339         c_retm_if(!data, "data is null");
340         c_retm_if(!obj, "part is null");
341
342         Eina_List *l;
343         Eina_List *realized_list;
344         Elm_Object_Item *it;
345         Item_data *item_data = data;
346         item_type type = item_data->index;
347         int ret;
348
349         switch (type) {
350         case ITEM_LOCALE_DEFAULT:
351                 item_data->ugd->first_day_of_week = FIRST_DAY_LOCALE_DEFAULT;
352                 ret = vconf_set_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, item_data->ugd->first_day_of_week);
353                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, 0) is failed(%d)", ret);
354                 break;
355         case ITEM_SUNDAY:
356                 item_data->ugd->first_day_of_week = FIRST_DAY_SUNDAY;
357                 ret = vconf_set_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, item_data->ugd->first_day_of_week);
358                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, 0) is failed(%d)", ret);
359                 break;
360         case ITEM_MONDAY:
361                 item_data->ugd->first_day_of_week = FIRST_DAY_MONDAY;
362                 ret = vconf_set_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, item_data->ugd->first_day_of_week);
363                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, 1) is failed(%d)", ret);
364                 break;
365         case ITEM_SATURDAY:
366                 item_data->ugd->first_day_of_week = FIRST_DAY_SATURDAY;
367                 ret = vconf_set_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, item_data->ugd->first_day_of_week);
368                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, 1) is failed(%d)", ret);
369                 break;
370         default:
371                 break;
372         }
373
374
375         elm_genlist_item_selected_set(item_data->item,0);
376
377         realized_list = elm_genlist_realized_items_get(item_data->ugd->genlist);
378         EINA_LIST_FOREACH(realized_list, l, it)
379         {
380                 item_data = elm_object_item_data_get(it);
381                 if (!item_data)
382                         continue;
383
384                 if ( type == ITEM_FIRST_DAY_OF_WEEK ||
385                                 type == ITEM_LOCALE_DEFAULT ||
386                                 type == ITEM_SUNDAY ||
387                                 type == ITEM_MONDAY ||
388                                 type == ITEM_SATURDAY) {
389                         if ( item_data->index == ITEM_FIRST_DAY_OF_WEEK ||
390                                         item_data->index == ITEM_LOCALE_DEFAULT ||
391                                         item_data->index == ITEM_SUNDAY ||
392                                         item_data->index == ITEM_MONDAY ||
393                                         item_data->index == ITEM_SATURDAY)
394                                 elm_genlist_item_update(it);
395                 }
396         }
397 }
398
399 static void __cal_setting_ug_lock_time_zone_check_changed_callback(void *data, Evas_Object *obj, void *event_info)
400 {
401         c_retm_if(!data, "data is NULL");
402         c_retm_if(!obj, "obj is NULL");
403
404         Item_data *item_data = data;
405
406         c_retm_if(!item_data->ugd, "item_data->ugd is NULL");
407         c_retm_if(!item_data->ugd->genlist, "item_data->ugd->genlist is NULL");
408         c_retm_if(!item_data->ugd->item_time_zone_on_off, "item_data->ugd->item_time_zone_on_off is NULL");
409
410         int  ret;
411
412         if (item_data->ugd->item_time_zone) {
413                 elm_object_item_del(item_data->ugd->item_time_zone);
414                 item_data->ugd->item_time_zone = NULL;
415         }
416
417         if (item_data->ugd->item_time_zone_guide) {
418                 elm_object_item_del(item_data->ugd->item_time_zone_guide);
419                 item_data->ugd->item_time_zone_guide = NULL;
420         }
421
422         if(elm_check_state_get(item_data->check)) {
423                 item_data->ugd->is_on = 1;
424
425                 ret = vconf_set_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF,item_data->ugd->is_on);
426                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, 0) is failed(%d)", ret);
427
428                 __cal_setting_gl_insert_genlist_item(item_data->ugd, item_data->ugd->genlist, item_data->ugd->item_time_zone_on_off, ITEM_TIMEZONE);
429         } else {
430                 item_data->ugd->is_on = 0;
431
432                 ret = vconf_set_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF,item_data->ugd->is_on);
433                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, 0) is failed(%d)", ret);
434
435                 __cal_setting_gl_insert_genlist_item(item_data->ugd, item_data->ugd->genlist, item_data->ugd->item_time_zone_on_off, ITEM_LOCK_TIMEZONE_GUIDE_TEXT);
436         }
437 }
438
439 static void __cal_setting_ug_lock_time_zone_check_select_callback(void *data, Evas_Object *obj, void *event_info)
440 {
441         c_retm_if(!data, "data is NULL");
442         c_retm_if(!obj, "obj is NULL");
443
444         Item_data *item_data = data;
445
446         elm_check_state_set(item_data->check, !elm_check_state_get(item_data->check));
447
448         __cal_setting_ug_lock_time_zone_check_changed_callback(data, elm_object_item_widget_get(item_data->item), event_info);
449
450         elm_genlist_item_selected_set(item_data->item,0);
451 }
452
453 static void __cal_setting_ug_show_week_num_check_select_callback(void *data, Evas_Object *obj, void *event_info)
454 {
455         c_retm_if(!data, "data is NULL");
456         c_retm_if(!obj, "obj is NULL");
457
458         Item_data *item_data = data;
459
460         elm_check_state_set(item_data->check, !elm_check_state_get(item_data->check));
461
462         __cal_setting_week_number_on_off_changed_callback(data, elm_object_item_widget_get(item_data->item), event_info);
463
464         elm_genlist_item_selected_set(item_data->item,0);
465 }
466
467 static void __cal_setting_ug_show_complete_task_check_select_callback(void *data, Evas_Object *obj, void *event_info)
468 {
469         c_retm_if(!data, "data is NULL");
470         c_retm_if(!obj, "obj is NULL");
471
472         Item_data *item_data = data;
473
474         elm_check_state_set(item_data->check, !elm_check_state_get(item_data->check));
475
476         __cal_setting_complete_todo_on_off_changed_callback(data, elm_object_item_widget_get(item_data->item), event_info);
477
478         elm_genlist_item_selected_set(item_data->item,0);
479 }
480
481 static void __cal_setting_genlist_item_select_callback(void *data, Evas_Object *obj, void *event_info)
482 {
483         c_retm_if(!data, "data is NULL");
484         c_retm_if(!obj, "obj is NULL");
485
486         Item_data *item_data = data;
487         elm_genlist_item_selected_set(item_data->item,0);
488         if(0 == elm_genlist_item_expanded_get(item_data->item)) {
489                 elm_genlist_item_expanded_set(item_data->item, 1);
490         } else {
491                 elm_genlist_item_expanded_set(item_data->item, 0);
492         }
493 }
494
495 static void __cal_setting_get_filename(char *fullpath, char *dest, int size_dest)
496 {
497         c_retm_if(!fullpath, "fullpath is NULL");
498         c_retm_if(!dest, "dest is NULL");
499
500         char* index;
501         index = strrchr(fullpath, '/');
502         snprintf(dest, size_dest, "%s", index + 1);
503 }
504
505 static void * __cal_setting_import_calendars(void* data)
506 {
507         c_retvm_if(!data, NULL,  "parameter(data) is NULL");
508
509         struct ug_data *ugd = data;
510         int ret;
511         cal_progress_info *p_info = ugd->p_info;
512         c_retvm_if(!p_info, NULL, "p_info is NULL");
513
514         char *vcalendar_stream = NULL;
515         int size = 0;
516         struct stat st = {0};
517
518         FILE * file = fopen(ugd->path, "r");
519         if (!file) {
520                 free(vcalendar_stream);
521                 ERR("Failed to open file!");
522                 p_info->completed = true;
523                 pthread_exit(NULL);
524                 return NULL;
525         }
526
527         if(stat(ugd->path, &st) != 0) {
528                 ERR("stat(ugd->path, &st) is fail!");
529                 p_info->completed = true;
530                 pthread_exit(NULL);
531                 return NULL;
532         }
533         size = st.st_size;
534
535         vcalendar_stream = calloc(size + 1, sizeof(char));
536         if (!vcalendar_stream) {
537                 ERR("vcalendar_stream is null");
538                 p_info->completed = true;
539                 pthread_exit(NULL);
540                 return NULL;
541         }
542
543         ret = fread(vcalendar_stream, 1, size, file);
544         if (ret < 0) {
545                 free(vcalendar_stream);
546                 ERR("Failed to read file!");
547                 p_info->completed = true;
548                 pthread_exit(NULL);
549                 fclose(file);
550
551                 return NULL;
552         }
553
554         fclose(file);
555
556         calendar_error_e error = CALENDAR_ERROR_NONE;
557
558         calendar_list_h list = NULL;
559
560         error = calendar_vcalendar_parse_to_calendar(vcalendar_stream, &list);
561         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_vcalendar_parse_to_calendar() is failed(%x)", error);
562
563         CAL_FREE(vcalendar_stream);
564
565         error = calendar_db_insert_records(list, NULL, NULL);
566         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_insert_records() is failed(%x)", error);
567
568         error = calendar_list_destroy(list, true);
569         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
570
571         p_info->completed = true;
572         pthread_exit(NULL);
573
574         return NULL;
575 }
576
577 static void __cal_setting_process_end(struct ug_data *ugd )
578 {
579         c_retm_if(!ugd, "parameter(ugd) is NULL");
580
581         cal_progress_info *p_info = ugd->p_info;
582         c_retm_if(!p_info, "p_info is NULL");
583
584         free(p_info);
585         ugd->p_info = NULL;
586 }
587
588 static Eina_Bool __cal_setting_backup_import_timer_cb(void *data)
589 {
590         c_retvm_if(!data, ECORE_CALLBACK_CANCEL, "parameter(data) is NULL");
591
592         struct ug_data *ugd  = data;
593         cal_progress_info *p_info;
594
595         p_info = ugd->p_info;
596         c_retvm_if(NULL == p_info , ECORE_CALLBACK_CANCEL, "p_info is NULL");
597
598
599         if (!p_info->completed) {
600
601                 if (!p_info->alive) {
602                         p_info->result = FALSE;
603                         p_info->completed = true;
604                         return ECORE_CALLBACK_RENEW;
605                 }
606
607                 return ECORE_CALLBACK_RENEW;
608         } else {
609                 const char *message;
610
611                 pthread_join(p_info->thread, NULL);
612
613                 if (p_info->result) {
614                         if (SETTING_IMPORT_CALENDAR== ugd->setting_mode) {
615                                 message = C_("IDS_CLD_POP_IMPORTED");
616                         } else {
617                                 message = C_("IDS_CLD_POP_EXPORTED");
618                         }
619                 } else {
620                         message = S_("IDS_COM_POP_FAILED");
621                 }
622
623                 evas_object_del(ugd->popup);
624
625                 __cal_setting_process_end(ugd);
626
627                 cal_util_show_small_information(ugd->layout, message, 1.0);
628
629                 return ECORE_CALLBACK_CANCEL;
630         }
631 }
632
633 static void __cal_setting_progress_popup_hide_cb(void *data, Evas_Object *obj, void *event_info)
634 {
635         c_retm_if(!data, "data is null");
636         c_retm_if(!obj, "obj is null");
637
638         Evas_Object *popup = data;
639
640         if (!strcmp(elm_object_text_get(obj), S_("IDS_COM_SK_CANCEL"))) {
641                 bool *is_alive = evas_object_data_get(popup, "data");
642                 *is_alive = false;
643         }
644
645         evas_object_del(popup);
646 }
647
648 Evas_Object* __cal_setting_progressbar_popup(Evas_Object *parent, cal_progress_info *p_info)
649 {
650         c_retvm_if(!parent, NULL, "parent is null");
651         c_retvm_if(!p_info, NULL, "p_info is null");
652
653         Evas_Object *popup;
654         Evas_Object *layout;
655         Evas_Object *title;
656         Evas_Object *progressbar;
657
658         popup = cal_util_add_popup(parent, NULL, NULL, NULL,
659                 __cal_setting_progress_popup_hide_cb, &p_info->alive, S_("IDS_COM_SK_CANCEL"), NULL);
660         c_retvm_if(!popup, NULL, "cal_util_add_popup() return NULL");
661
662         layout = cal_util_add_layout(popup, "popup_center_text_progressview");
663
664         p_info->layout = layout;
665
666         title = elm_label_add(layout);
667         c_retvm_if(NULL == title, NULL, "elm_label_add() return NULL");
668
669         elm_object_style_set(title, "popup_description/default");
670         elm_label_line_wrap_set(title, EINA_TRUE);
671         evas_object_size_hint_weight_set(title, EVAS_HINT_EXPAND, 0.0);
672         evas_object_size_hint_align_set(title, EVAS_HINT_FILL, EVAS_HINT_FILL);
673         evas_object_show(title);
674         p_info->label = title;
675
676         progressbar = elm_progressbar_add(layout);
677         c_retvm_if(NULL == progressbar, NULL, "elm_progressbar_add() return NULL");
678
679         p_info->progressbar= progressbar;
680
681         elm_object_part_content_set(layout, "elm.swallow.content", title);
682         elm_object_part_content_set(layout, "elm.swallow.end", progressbar);
683         evas_object_size_hint_align_set(progressbar, 0.5, 0.5);
684         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
685         elm_progressbar_pulse(progressbar, EINA_TRUE);
686
687         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
688         evas_object_show(progressbar);
689         elm_object_content_set(popup, layout);
690
691         return popup;
692 }
693
694 static void __cal_setting_import_calendar_ug_result(ui_gadget_h ug, service_h result, void *data)
695 {
696         c_retm_if(!ug, "parameter(ug) is NULL");
697         c_retm_if(!data, "parameter(data) is NULL");
698         c_retm_if(!result, "parameter(result) is NULL");
699
700         ug_destroy(ug);
701
702         int ret;
703         char *val;
704         struct ug_data *ugd = data;
705         cal_progress_info *p_info;
706         char title[CAL_TEXT_MAX_LEN];
707         char filepath[CAL_TEXT_SHORT_LEN];
708
709         ret = service_get_extra_data(result, "result", &val);
710         c_ret_if(ret != SERVICE_ERROR_NONE);
711
712         if (ugd->path) {
713                 free(ugd->path);
714                 ugd->path = NULL;
715         }
716         ugd->path = strdup((char *)val);
717         c_retm_if(NULL == ugd->path, "strdup() return NULL");
718
719         free(val);
720
721         p_info = calloc(1, sizeof(cal_progress_info));
722         c_retm_if(!p_info, "calloc() return NULL");
723
724         ugd->p_info = p_info;
725
726         p_info->alive = true;
727         p_info->result = TRUE;
728         p_info->completed = false;
729         __cal_setting_get_filename(ugd->path, filepath, sizeof(filepath));
730
731         snprintf(title, sizeof(title), "%s<br>%s", C_("IDS_CLD_POP_IMPORTING_ING"), filepath);
732
733         ret = pthread_create(&p_info->thread, NULL, __cal_setting_import_calendars, ugd);
734         if (0 != ret) {
735                 ERR("Thread creation failed(%d)", ret);
736                 free(p_info);
737                 ugd->p_info = NULL;
738                 return;
739         }
740
741         p_info->timer = ecore_timer_add(0.1, __cal_setting_backup_import_timer_cb, ugd);
742         if (NULL == p_info->timer) {
743                 ERR("ecore_timer_ada() return NULL");
744
745                 p_info->alive = false;
746                 pthread_join(p_info->thread, NULL);
747
748                 free(p_info);
749                 ugd->p_info = NULL;
750
751                 return;
752         }
753
754         ugd->popup = __cal_setting_progressbar_popup(ugd->naviframe, p_info);
755         elm_object_text_set(p_info->label, title);
756
757         evas_object_smart_callback_add(ugd->popup, "response", __cal_setting_progress_popup_hide_cb, &p_info->alive);
758
759 }
760
761 static void __cal_setting_import_calendar_myfile_ug(struct ug_data *ugd)
762 {
763         c_retm_if(!ugd, "ugd is null");
764
765         struct ug_cbs cbs = {0};
766         cbs.result_cb = __cal_setting_import_calendar_ug_result;
767         cbs.priv = ugd;
768
769         cal_launch_ug_with_var(ugd->ug, CAL_MYFILES_UG, &cbs, "path", "/opt/usr/media/Backup/Calendar", "select_type", "IMPORT", "file_type", "vcs", NULL);
770 }
771
772 static inline void __cal_setting_progress_fail(cal_progress_info *p_info)
773 {
774         c_retm_if(!p_info, "parameter(p_info) is NULL");
775
776         p_info->completed = true;
777         p_info->result = false;
778
779         pthread_exit(NULL);
780 }
781
782 static void * __cal_setting_export_calendars(void *data)
783 {
784         c_retvm_if(!data, NULL,  "parameter(data) is NULL");
785
786         Eina_Bool ret = EINA_TRUE;
787         int fd;
788         Eina_List *cursor;
789         calendar_record_h calendar_book;
790         struct ug_data *ugd  = data;
791         cal_progress_info *p_info = ugd->p_info;
792         char *vcs_data = NULL;
793
794         fd = open(ugd->path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
795         if (fd < 0) {
796                 ERR("open(%s) Failed(%d)", ugd->path, errno);
797                 __cal_setting_progress_fail(p_info);
798                 return NULL;
799         }
800
801         if (ugd->checked_calendar_list == NULL) {
802                 c_warn_if(1, "ugd->calendar_list is NULL");
803                 close(fd);
804                 return NULL;
805         }
806
807         int r;
808         int cid = 0;
809
810         calendar_error_e error = CALENDAR_ERROR_NONE;
811
812         calendar_filter_h filter = NULL;
813
814         error = calendar_filter_create(_calendar_event._uri, &filter);
815         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
816
817         EINA_LIST_FOREACH(ugd->checked_calendar_list, cursor, calendar_book) {
818                 if (calendar_book) {
819                         error = calendar_record_get_int(calendar_book, _calendar_book.id, &cid);
820                         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
821
822                         error = calendar_filter_add_int(filter, _calendar_event.calendar_book_id, CALENDAR_MATCH_EQUAL, cid);
823                         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
824
825                         if (eina_list_next(cursor)) {
826                                 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_OR);
827                                 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
828                         }
829                 }
830         }
831
832         calendar_query_h query = NULL;
833
834         error = calendar_query_create(_calendar_event._uri, &query);
835         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
836
837         error = calendar_query_set_filter(query, filter);
838         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_add_filter() is failed(%x)", error);
839
840         calendar_list_h list = NULL;
841
842         error = calendar_db_get_records_with_query(query, 0, 0, &list);
843         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
844
845         error = calendar_vcalendar_make_from_records(list, &vcs_data);
846         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_vcalendar_make_from_records() is failed(%x)", error);
847
848         error = calendar_list_destroy(list, true);
849         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
850
851         error = calendar_query_destroy(query);
852         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
853
854         error = calendar_filter_destroy(filter);
855         c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
856
857         if (vcs_data) {
858                 r = write(fd, vcs_data, strlen(vcs_data));
859                 if (r == -1) {
860                         ERR("write() is failed.");
861                 } else
862                         cal_util_update_media_db(ugd->path);
863
864                 p_info->completed = true;
865                 p_info->result = true;
866
867         } else {
868                 __cal_setting_progress_fail(p_info);
869         }
870
871         CAL_FREE(vcs_data);
872
873         r = fsync(fd);
874         if (0 != r) {
875                 ERR("fsync() failed(%d)", r);
876                 __cal_setting_progress_fail(p_info);
877         }
878         close(fd);
879
880         if (!p_info->result) {
881                 ret = unlink(ugd->path);
882                 if (0 != ret) {
883                         ERR("unlink(%s) failed(%d)", ugd->path, ret);
884                         __cal_setting_progress_fail(p_info);
885                 }
886         }
887
888         pthread_exit(NULL);
889
890         return NULL;
891 }
892
893 static void __cal_setting_export_myfile_ug_result(ui_gadget_h ug, service_h result, void *data)
894 {
895         c_retm_if(!ug, "parameter(ug) is NULL");
896         c_retm_if(!data, "parameter(data) is NULL");
897         c_retm_if(!result, "parameter(result) is NULL");
898
899         int ret;
900         char *val;
901         char path[CAL_TEXT_MAX_LEN];
902         char title[CAL_TEXT_MAX_LEN];
903         char filepath[CAL_TEXT_SHORT_LEN];
904         cal_progress_info *p_info;
905         struct ug_data *ugd  = data;
906
907         elm_naviframe_item_pop(ugd->naviframe);
908
909         c_retm_if(ugd->p_info, "thread is running");
910
911         ug_destroy(ug);
912
913         ret = service_get_extra_data(result, "result", &val);
914         c_ret_if(ret != SERVICE_ERROR_NONE);
915
916         p_info = calloc(1, sizeof(cal_progress_info));
917         c_retm_if(NULL == p_info, "calloc() return NULL");
918
919         ugd->p_info = p_info;
920
921         free(ugd->path);
922         snprintf(path, sizeof(path), "%s/calendars.vcs", (char *)val);
923
924         free(val);
925
926         ugd->path = strdup(path);
927
928         p_info->alive = true;
929         p_info->result = TRUE;
930         __cal_setting_get_filename(ugd->path, filepath, sizeof(filepath));
931         snprintf(title, sizeof(title), "%s<br>%s", C_("IDS_CLD_POP_EXPORTING_ING"), filepath);
932
933         ret = pthread_create(&p_info->thread, NULL, __cal_setting_export_calendars, ugd );
934         if (0 != ret) {
935                 ERR("Thread creation failed(%d)", ret);
936                 free(p_info);
937                 ugd->p_info = NULL;
938                 return;
939         }
940
941         p_info->timer = ecore_timer_add(PROGRESS_BAR_TIMER_INTERVAL, __cal_setting_backup_import_timer_cb, ugd);
942         if (NULL == p_info->timer) {
943                 ERR("ecore_timer_ada() return NULL");
944                 p_info->alive = false;
945                 pthread_join(p_info->thread, NULL);
946                 free(p_info);
947                 ugd->p_info = NULL;
948                 return;
949         }
950
951         ugd->popup = __cal_setting_progressbar_popup(ugd->naviframe, p_info);
952         elm_object_text_set(p_info->label, title);
953 }
954
955 void cal_setting_export_calendar_myfile_ug(struct ug_data *ugd)
956 {
957         CAL_FN_START;
958         c_retm_if(!ugd, "ugd is null");
959
960         struct ug_cbs cbs = {0};
961         cbs.result_cb = __cal_setting_export_myfile_ug_result;
962         cbs.priv = ugd;
963
964         cal_launch_ug_with_var(ugd->ug, CAL_MYFILES_UG, &cbs, "path", "/opt/usr/media/Backup/Calendar", "select_type", "EXPORT", "file_type", "FOLDER", NULL);
965 }
966
967 static void __cal_setting_show_export_view(Item_data *item_data)
968 {
969         CAL_FN_START;
970
971         c_retm_if(!item_data, "item_data is null");
972
973         struct ug_data *ugd = item_data->ugd;
974         c_retm_if(!ugd, "ugd is null");
975
976         cal_setting_export_create_view(ugd);
977 }
978
979 static void __cal_setting_genlist_item_import_export_select_callback(void *data, Evas_Object *obj, void *event_info)
980 {
981         c_retm_if(!data, "data is null");
982
983         Item_data *item_data = data;
984         elm_genlist_item_selected_set(item_data->item,0);
985         item_type type = item_data->index;
986         switch (type) {
987                 case ITEM_IMPORT_CALENDARS:
988
989                         item_data->ugd->setting_mode = SETTING_IMPORT_CALENDAR;
990
991                         __cal_setting_import_calendar_myfile_ug(item_data->ugd);
992                         break;
993                 case ITEM_EXPORT_CALENDARS:
994
995                         item_data->ugd->setting_mode = SETTING_EXPORT_CALENDAR;
996
997                         __cal_setting_show_export_view(item_data);
998                         break;
999                 default:
1000                         break;
1001         }
1002 }
1003
1004 static void __cal_setting_complete_todo_on_off_changed_callback(void *data, Evas_Object *obj, void *event_info)
1005 {
1006         c_retm_if(!data, "data is null");
1007
1008         Item_data *item_data = data;
1009         int  ret;
1010         if (elm_check_state_get(item_data->check)) {
1011                 item_data->ugd->is_complete_todo = 1;
1012                 ret = vconf_set_int(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF,item_data->ugd->is_complete_todo);
1013                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF, 0) is failed(%d)", ret);
1014         } else {
1015                 item_data->ugd->is_complete_todo = 0;
1016                 ret = vconf_set_int(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF,item_data->ugd->is_complete_todo);
1017                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF, 0) is failed(%d)", ret);
1018         }
1019 }
1020
1021 static void __cal_setting_week_number_on_off_changed_callback(void *data, Evas_Object *obj, void *event_info)
1022 {
1023         c_retm_if(!data, "data is null");
1024
1025         Item_data *item_data = data;
1026         int  ret;
1027
1028         c_retm_if(!item_data->check, "item_data->check is null");
1029
1030         if (elm_check_state_get(item_data->check)) {
1031                 item_data->ugd->is_display_weeknumber= 1;
1032                 ret = vconf_set_int(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF ,item_data->ugd->is_display_weeknumber);
1033                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF, 0) is failed(%d)", ret);
1034         } else {
1035                 item_data->ugd->is_display_weeknumber= 0;
1036                 ret = vconf_set_int(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF,item_data->ugd->is_display_weeknumber);
1037                 c_retm_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF, 0) is failed(%d)", ret);
1038         }
1039 }
1040
1041 static Evas_Object *__cal_setting_ug_get_genlist_item_icon(void *data, Evas_Object *obj, const char *part)
1042 {
1043         c_retvm_if(!data, NULL, "data is null");
1044         c_retvm_if(!obj, NULL, "obj is null");
1045
1046         Evas_Object *eo_begin = NULL;
1047         Item_data *item_data = data;
1048         item_type type = item_data->index;
1049
1050         if (!CAL_STRCMP(part, "elm.icon")) {
1051                 eo_begin = elm_radio_add(obj);
1052                 switch (type) {
1053                 case ITEM_LOCK_TIMEZONE_ON_OFF:
1054                         eo_begin = elm_check_add(obj);
1055                         elm_check_state_set(eo_begin, item_data->ugd->is_on);
1056                         elm_object_style_set(eo_begin, "on&off");
1057                         evas_object_propagate_events_set(eo_begin, EINA_FALSE);
1058                         item_data->check = eo_begin;
1059                         evas_object_smart_callback_add(eo_begin, "changed", __cal_setting_ug_lock_time_zone_check_changed_callback, item_data);
1060                         break;
1061                 case ITEM_LOCALE_DEFAULT:
1062                         if (FIRST_DAY_LOCALE_DEFAULT == item_data->ugd->first_day_of_week) {
1063                                 elm_radio_state_value_set(eo_begin, 0);
1064                         } else {
1065                                 elm_radio_state_value_set(eo_begin, -1);
1066                         }
1067                         break;
1068                 case ITEM_SUNDAY:
1069                         if (FIRST_DAY_SUNDAY == item_data->ugd->first_day_of_week) {
1070                                 elm_radio_state_value_set(eo_begin, 0);
1071                         } else {
1072                                 elm_radio_state_value_set(eo_begin, -1);
1073                         }
1074                         break;
1075                 case ITEM_MONDAY:
1076                         if (FIRST_DAY_MONDAY == item_data->ugd->first_day_of_week) {
1077                                 elm_radio_state_value_set(eo_begin, 0);
1078                         } else {
1079                                 elm_radio_state_value_set(eo_begin, -1);
1080                         }
1081                         break;
1082                 case ITEM_SATURDAY:
1083                         if (FIRST_DAY_SATURDAY == item_data->ugd->first_day_of_week) {
1084                                 elm_radio_state_value_set(eo_begin, 0);
1085                         } else {
1086                                 elm_radio_state_value_set(eo_begin, -1);
1087                         }
1088                         break;
1089                 case ITEM_WEEK_NUMBER_ON_OFF:
1090                         eo_begin = elm_check_add(obj);
1091                         c_retvm_if(!eo_begin , NULL, "eo_begin is null");
1092
1093                         elm_check_state_set(eo_begin, item_data->ugd->is_display_weeknumber);
1094                         elm_object_style_set(eo_begin, "on&off");
1095                         evas_object_propagate_events_set(eo_begin, EINA_FALSE);
1096                         item_data->check = eo_begin;
1097                         evas_object_smart_callback_add(eo_begin, "changed", __cal_setting_week_number_on_off_changed_callback,  item_data);
1098                         break;
1099                 case ITEM_COMPLETED_TO_DO_ON_OFF:
1100                         eo_begin = elm_check_add(obj);
1101                         elm_check_state_set(eo_begin, item_data->ugd->is_complete_todo);
1102                         elm_object_style_set(eo_begin, "on&off");
1103                         evas_object_propagate_events_set(eo_begin, EINA_FALSE);
1104                         item_data->check = eo_begin;
1105                         evas_object_smart_callback_add(eo_begin, "changed", __cal_setting_complete_todo_on_off_changed_callback, item_data);
1106                         break;
1107                 default:
1108                         break;
1109                 }
1110                 elm_radio_group_add(eo_begin, item_data->rgd);
1111
1112                 item_data->check = eo_begin;
1113         }
1114         return eo_begin;
1115 }
1116
1117 static void __cal_setting_ug_time_zone_ug_destroy_callback(ui_gadget_h ug, void *priv)
1118 {
1119         CAL_FN_START;
1120         c_retm_if(!priv, "priv is null");
1121
1122         Item_data *item_data = priv;
1123         elm_genlist_item_selected_set(item_data->item,0);
1124         if (ug)
1125                 ug_destroy(ug);
1126 }
1127
1128 static void __cal_setting_ug_time_zone_ug_result_callback(ui_gadget_h ug, service_h result, void *priv)
1129 {
1130         CAL_FN_START;
1131
1132         c_retm_if(!priv, "priv is null");
1133
1134         Item_data *item_data = priv;
1135
1136         char *city = NULL;
1137
1138         int ret = service_get_extra_data(result, "city", &city);
1139         c_ret_if(ret != SERVICE_ERROR_NONE);
1140
1141         char *timezone = NULL;
1142
1143         ret = service_get_extra_data(result, "timezone", &timezone);
1144         c_ret_if(ret != SERVICE_ERROR_NONE);
1145
1146         char *tzpath = NULL;
1147
1148         ret = service_get_extra_data(result, "tzpath", &tzpath);
1149         c_ret_if(ret != SERVICE_ERROR_NONE);
1150
1151         if (item_data->ugd->city)
1152                 free(item_data->ugd->city);
1153
1154         item_data->ugd->city = strdup(city);
1155         c_retm_if(!item_data->ugd->city, "item_data->ugd->city is null");
1156
1157         item_data->ugd->time_zone = g_strdup_printf("GMT%s", timezone);
1158         c_retm_if(!item_data->ugd->time_zone, "item_data->ugd->time_zone is null");
1159
1160         elm_genlist_item_update(item_data->item);
1161
1162         ret = vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_PATH, tzpath);
1163         c_warn_if(ret, "vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_PATH, tzpath) is failed");
1164
1165         ret = vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_CITY, city);
1166         c_warn_if(ret, "vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_CITY, tzpath) is failed");
1167
1168         ret = vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_OFFSET, timezone);
1169         c_warn_if(ret, "vconf_set_str(CAL_VCONFKEY_LOCK_TIMEZONE_OFFSET, tzpath) is failed");
1170
1171         free(city);
1172         free(timezone);
1173         free(tzpath);
1174 }
1175
1176 static void __cal_setting_ug_time_zone_ug_layout_callback(ui_gadget_h ug, enum ug_mode mode, void *priv)
1177 {
1178         CAL_FN_START;
1179         c_retm_if(!ug, "ug is null");
1180
1181         Evas_Object *base;
1182
1183         base = ug_get_layout(ug);
1184         if (!base) {
1185                 ug_destroy(ug);
1186                 return;
1187         }
1188
1189         switch (mode) {
1190         case UG_MODE_FULLVIEW:
1191                 evas_object_show(base);
1192                 break;
1193         default:
1194                 DBG("Unsupported ug layout");
1195                 break;
1196         }
1197 }
1198
1199 static void __cal_setting_ug_create_time_zone_ug(void *data, Evas_Object *obj, void *event_info)
1200 {
1201         c_retm_if(!data, "data is null");
1202
1203         Item_data *item_data = data;
1204
1205         struct ug_cbs uc;
1206
1207         memset(&uc, 0, sizeof(struct ug_cbs));
1208         uc.destroy_cb = __cal_setting_ug_time_zone_ug_destroy_callback;
1209         uc.layout_cb = __cal_setting_ug_time_zone_ug_layout_callback;
1210         uc.result_cb = __cal_setting_ug_time_zone_ug_result_callback;
1211         uc.priv = item_data;
1212
1213         ug_create(NULL, "worldclock-efl", UG_MODE_FULLVIEW, NULL, &uc);
1214
1215 }
1216
1217 static Elm_Object_Item *__cal_setting_ug_add_genlist_item(struct ug_data *ugd, Evas_Object *genlist,Eina_Bool is_seperator,int index)
1218 {
1219         c_retvm_if(!ugd, NULL, "ugd is null");
1220         c_retvm_if(!genlist, NULL, "genlist is null");
1221
1222         Elm_Object_Item *item = NULL;
1223         Item_data *item_data = NULL;
1224
1225         if(is_seperator) {
1226                 item = elm_genlist_item_append(genlist, &itc_seperator, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1227                 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1228         } else {
1229                 item_data = calloc(1, sizeof(Item_data));
1230                 c_retvm_if(!item_data, NULL, "item_data is null");
1231
1232                 item_data->ugd = ugd;
1233
1234                 switch (index) {
1235                 case ITEM_LOCK_TIMEZONE_ON_OFF:
1236                         item_data->index = index;
1237                         item_data->item = elm_genlist_item_append(genlist, &itc_lock_tz, item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_setting_ug_lock_time_zone_check_select_callback, item_data);
1238                         ugd->item_time_zone_on_off = item_data->item;
1239                         break;
1240                 case ITEM_LOCK_TIMEZONE_GUIDE_TEXT:
1241                         if (!ugd->is_on) {
1242                                 item_data->index = index;
1243                                 item_data->item = elm_genlist_item_append(genlist, &itc_lock_tz_guide, item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1244                                 elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1245                                 ugd->item_time_zone_guide = item_data->item;
1246                         } else {
1247                                 free(item_data);
1248                                 return NULL;
1249                         }
1250                         break;
1251                 case ITEM_TIMEZONE:
1252                         if (ugd->is_on) {
1253                                 item_data->index = index;
1254                                 item_data->item = elm_genlist_item_append(genlist, &itc_tz, item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_setting_ug_create_time_zone_ug, item_data);
1255                                 ugd->item_time_zone = item_data->item;
1256                         } else {
1257                                 free(item_data);
1258                                 return NULL;
1259                         }
1260                         break;
1261                 case ITEM_FIRST_DAY_OF_WEEK:
1262                         item_data->index = index;
1263                         item_data->item = elm_genlist_item_append(genlist, &itc, item_data, NULL, ELM_GENLIST_ITEM_TREE, __cal_setting_genlist_item_select_callback, item_data);
1264                         ugd->rgd_first_day = elm_radio_add((Evas_Object *)(item_data->item));
1265                         elm_radio_state_value_set(ugd->rgd_first_day, -1);
1266                         break;
1267                 case ITEM_SUNDAY:
1268                 case ITEM_MONDAY:
1269                 case ITEM_SATURDAY:
1270                 case ITEM_LOCALE_DEFAULT:
1271                         item_data->index = index;
1272                         item_data->item = elm_genlist_item_append(genlist, &itc_radio, item_data, ugd->item_first_day_of_week, ELM_GENLIST_ITEM_NONE, __cal_setting_ug_radio_changed_callback, item_data);
1273                         item_data->rgd = ugd->rgd_first_day;
1274                         break;
1275                 case ITEM_WEEK_NUMBER_ON_OFF:
1276                         item_data->index = index;
1277                         item_data->item = elm_genlist_item_append(genlist, &itc_lock_tz, item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_setting_ug_show_week_num_check_select_callback, item_data);
1278                         break;
1279                 case ITEM_COMPLETED_TO_DO_ON_OFF:
1280                         item_data->index = index;
1281                         item_data->item = elm_genlist_item_append(genlist, &itc_lock_tz, item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_setting_ug_show_complete_task_check_select_callback, item_data);
1282                         break;
1283                 case ITEM_IMPORT_CALENDARS:
1284                 case ITEM_EXPORT_CALENDARS:
1285                         item_data->index = index;
1286                         item_data->item = elm_genlist_item_append(genlist, &itc_import, item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_setting_genlist_item_import_export_select_callback, item_data);
1287                         break;
1288                 default:
1289                         free(item_data);
1290                         return NULL;
1291                 }
1292
1293                 if (item_data)
1294                         item = item_data->item;
1295         }
1296
1297         return item;
1298
1299 }
1300
1301 static void __cal_setting_ug_genlist_item_expand_callback(void *data, Evas_Object *obj, void *event_info)
1302 {
1303         c_retm_if(!data, "data is null");
1304         c_retm_if(!event_info, "event_info is null");
1305
1306         struct ug_data *ugd = data;
1307         Elm_Object_Item *it = event_info;
1308         Evas_Object *gl = elm_object_item_widget_get(it);
1309
1310         if (it == ugd->item_first_day_of_week) {
1311
1312                 __cal_setting_ug_add_genlist_item(ugd, gl, EINA_FALSE, ITEM_LOCALE_DEFAULT);
1313                 __cal_setting_ug_add_genlist_item(ugd, gl, EINA_FALSE, ITEM_SATURDAY);
1314                 __cal_setting_ug_add_genlist_item(ugd, gl, EINA_FALSE, ITEM_SUNDAY);
1315                 __cal_setting_ug_add_genlist_item(ugd, gl, EINA_FALSE, ITEM_MONDAY);
1316         }
1317 }
1318
1319 static void __cal_setting_ug_genlist_item_contract_callback(void *data, Evas_Object *obj, void *event_info)
1320 {
1321         c_retm_if(!event_info, "event_info is null");
1322
1323         Elm_Object_Item *item = event_info;
1324         elm_genlist_item_subitems_clear(item);
1325 }
1326
1327 Evas_Object* cal_setting_ug_create_view(Evas_Object *navi, struct ug_data *ugd)
1328 {
1329         c_retv_if(!navi, NULL);
1330         c_retv_if(!ugd, NULL);
1331
1332         Evas_Object *layout = cal_util_add_layout(navi, "selectioninfo");
1333         c_retv_if(!layout, NULL);
1334
1335         Evas_Object *genlist = elm_genlist_add(layout);
1336         c_retvm_if(!genlist, NULL, "genlist is null");
1337
1338         elm_genlist_clear(genlist);
1339         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1340
1341         ugd->genlist = genlist;
1342
1343         __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_TRUE, 0);
1344         __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_FALSE,ITEM_LOCK_TIMEZONE_ON_OFF);
1345         __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_FALSE,ITEM_LOCK_TIMEZONE_GUIDE_TEXT);
1346         __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_FALSE,ITEM_TIMEZONE);
1347
1348         __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_TRUE,0);
1349         ugd->item_first_day_of_week = __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_FALSE,ITEM_FIRST_DAY_OF_WEEK);
1350
1351         __cal_setting_ug_add_genlist_item(ugd, genlist, EINA_TRUE, 0);
1352         __cal_setting_ug_add_genlist_item(ugd,genlist, EINA_FALSE, ITEM_WEEK_NUMBER_ON_OFF);
1353
1354         __cal_setting_ug_add_genlist_item(ugd, genlist, EINA_TRUE, 0);
1355         __cal_setting_ug_add_genlist_item(ugd,genlist, EINA_FALSE, ITEM_COMPLETED_TO_DO_ON_OFF);
1356
1357         __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_TRUE, 0);
1358         __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_FALSE,ITEM_IMPORT_CALENDARS);
1359         __cal_setting_ug_add_genlist_item(ugd,genlist,EINA_FALSE,ITEM_EXPORT_CALENDARS);
1360
1361         __cal_setting_ug_add_genlist_item(ugd, genlist, EINA_TRUE, 0);
1362
1363         evas_object_smart_callback_add(genlist, "expanded", __cal_setting_ug_genlist_item_expand_callback, ugd);
1364         evas_object_smart_callback_add(genlist, "contracted", __cal_setting_ug_genlist_item_contract_callback, ugd);
1365
1366         elm_object_part_content_set(layout, "gen.swallow.contents", genlist);
1367
1368         return layout;
1369 }
1370
1371 static void __cal_setting_gl_insert_genlist_item(struct ug_data *ugd, Evas_Object *genlist, Elm_Object_Item *item_after, int index)
1372 {
1373         c_retm_if(!ugd, "ugd is NULL");
1374         c_retm_if(!genlist, "genlist is NULL");
1375         c_retm_if(!item_after, "item_after is NULL");
1376
1377         Item_data *item_data = calloc(1, sizeof(Item_data));
1378         c_retm_if(!item_data, "item_data is NULL");
1379
1380         item_data->ugd = ugd;
1381
1382         switch (index) {
1383         case ITEM_TIMEZONE:
1384                 if (ugd->is_on) {
1385                         item_data->index = index;
1386                         item_data->item = elm_genlist_item_insert_after(genlist, &itc_tz, item_data, NULL, item_after, ELM_GENLIST_ITEM_NONE, __cal_setting_ug_create_time_zone_ug, item_data);
1387                         ugd->item_time_zone = item_data->item;
1388                 } else {
1389                         free(item_data);
1390                 }
1391                 break;
1392         case ITEM_LOCK_TIMEZONE_GUIDE_TEXT:
1393                 if (!ugd->is_on) {
1394                         item_data->index = index;
1395                         item_data->item = elm_genlist_item_insert_after(genlist, &itc_lock_tz_guide, item_data, NULL, item_after, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1396                         elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1397                         ugd->item_time_zone_guide = item_data->item;
1398                 } else {
1399                         free(item_data);
1400                 }
1401                 break;
1402         default:
1403                 free(item_data);
1404                 break;
1405         }
1406 }