3 * Copyright 2012 Samsung Electronics Co., Ltd
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
9 * http://floralicense.org/license/
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.
24 #include "ug-settings.h"
25 #include "cld-images.h"
27 #define CAL_SETTING_EXPORT_ACCOUNT_LABLE_STRING_LENGTH 128
35 Evas_Object *select_all_layout;
36 Eina_Bool is_select_all_checked;
37 Evas_Object *select_all_check;
39 Eina_List *account_list;
41 Evas_Object *export_bt;
44 } cal_setting_export_data;
48 Elm_Object_Item *item;
49 calendar_record_h calendar_book;
51 Eina_Bool is_group_item;
52 } cal_setting_export_item_data;
54 static char *__cal_setting_get_export_genlist_item_label(void *data, Evas_Object *obj, const char *part);
55 static Evas_Object* __cal_setting_get_export_genlist_icon(void *item_data, Evas_Object *obj, const char *part);
56 static void __cal_setting_gl_export_genlist_del(void *data, Evas_Object *obj);
57 static char* __cal_setting_get_export_genlist_group_item_label(void *data, Evas_Object *obj, const char *part);
58 static void __cal_setting_del_export_genlist_group_item(void *data, Evas_Object *obj);
59 static char *__cal_setting_ug_export_account_guide_item_label(void *data, Evas_Object *obj, const char *part);
60 static void __cal_setting_del_export_genlist_group_item(void *data, Evas_Object *obj);
61 static void __cal_setting_check_changed_callback(void *data, Evas_Object *obj, void *event_info);
62 extern void cal_setting_export_calendar_myfile_ug(struct ug_data *ugd);
64 static Elm_Genlist_Item_Class itc_1text_2icon_2 = {
65 .item_style = "dialogue/1text.3icon.2",
66 .func.text_get = __cal_setting_get_export_genlist_item_label,
67 .func.content_get = __cal_setting_get_export_genlist_icon,
68 .func.del = __cal_setting_gl_export_genlist_del,
71 static Elm_Genlist_Item_Class it_group = {
72 .item_style = "grouptitle",
73 .func.text_get = __cal_setting_get_export_genlist_group_item_label,
74 .func.del = __cal_setting_del_export_genlist_group_item,
77 static Elm_Genlist_Item_Class itc_export_account_guide = {
78 .item_style = "multiline/1text",
79 .func.text_get = __cal_setting_ug_export_account_guide_item_label,
80 .func.content_get = NULL,
81 .func.state_get = NULL,
82 .func.del = __cal_setting_del_export_genlist_group_item,
85 static struct _acct def_at = { _CALENDAR_LOCAL_ACCOUNT_ID, "Local account", CAL_IMAGES_PHONE, NULL, NULL, };
87 static void __cal_setting_export_update_small_info(cal_setting_export_data *data)
91 cal_setting_export_data *p = data;
93 if (!p->checked_count) {
94 cal_util_hide_small_information(p->ly);
98 char lable_str[128] = { '\0'};
100 snprintf(lable_str, sizeof(lable_str), "%s (%d)", S_("IDS_COM_POP_SELECTED"), p->checked_count);
102 cal_util_show_small_information(p->ly, lable_str, 0.0);
105 static Evas_Object* __cal_setting_get_export_genlist_icon(void *item_data, Evas_Object *obj, const char *part)
107 c_retv_if(!item_data, NULL);
108 c_retv_if(!obj, NULL);
110 cal_setting_export_item_data *export_item_data = item_data;
111 Evas_Object *icon = NULL;
112 char* icon_path = NULL;
114 calendar_record_h calendar_book = export_item_data->calendar_book;
115 c_retvm_if(!calendar_book, NULL, "calendar_book is NULL");
117 Eina_Bool r = EINA_FALSE;
121 calendar_error_e error = CALENDAR_ERROR_NONE;
123 error = calendar_record_get_int(calendar_book, _calendar_book.id, &cid);
124 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
126 error = calendar_record_get_int(calendar_book, _calendar_book.account_id, &aid);
127 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
129 if (!CAL_STRCMP(part, "elm.icon.1")) {
131 icon = elm_check_add(obj);
132 c_retvm_if(icon == NULL, NULL, "elm_check_add returned null");
134 evas_object_data_set(icon, "item_data", export_item_data);
136 elm_check_state_pointer_set(icon, &export_item_data->is_checked);
137 evas_object_propagate_events_set(icon, EINA_FALSE);
139 evas_object_smart_callback_add(icon, "changed", __cal_setting_check_changed_callback, obj);
142 if (!CAL_STRCMP(part, "elm.icon.2")) {
143 icon = elm_icon_add(obj);
145 c_retvm_if(!icon, NULL, "elm_icon_add fail");
147 if ( aid == _CALENDAR_LOCAL_ACCOUNT_ID) {
148 r = elm_icon_file_set(icon, CAL_IMAGES_EDJ, CAL_IMAGES_PHONE);
150 icon_path = cal_account_svc_get_account_icon_path(aid);
152 r = elm_icon_file_set(icon, icon_path, NULL);
158 ERR("the return value of elm_icon_file_set is %d", r);
159 evas_object_del(icon);
162 evas_object_show(icon);
169 static char* __cal_setting_get_export_genlist_group_item_label(void *data, Evas_Object *obj, const char *part)
171 c_retv_if(!data, NULL);
173 cal_setting_export_item_data *item_data = data;
175 if (!CAL_STRCMP(part, "elm.text")) {
176 struct _acct *at = item_data->at;
178 if (at->id == _CALENDAR_LOCAL_ACCOUNT_ID)
179 return strdup(C_("IDS_CLD_POP_MY_PHONE"));
181 return CAL_STRDUP(at->name);
187 static char *__cal_setting_get_export_genlist_item_label(void *data, Evas_Object *obj, const char *part)
189 c_retvm_if(!data, NULL, "data is null");
190 c_retvm_if(!part, NULL, "part is null");
192 cal_setting_export_item_data *item_data = data;
194 calendar_record_h calendar_book = item_data->calendar_book;
195 c_retvm_if(!calendar_book, NULL, "calendar_book is null");
200 calendar_error_e error = CALENDAR_ERROR_NONE;
202 if (!CAL_STRCMP(part,"elm.text")) {
203 if (!calendar_book) {
204 ERR("calendar_book is null");
205 return strdup(C_("IDS_CLD_OPT_PHONE_CALENDAR"));
208 error = calendar_record_get_int(calendar_book, _calendar_book.id, &cid);
209 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
211 if (cid == DEFAULT_EVENT_CALENDAR_BOOK_ID)
212 return strdup(C_("IDS_CLD_BODY_MY_CALENDAR"));
213 else if (cid == DEFAULT_TODO_CALENDAR_BOOK_ID)
214 return strdup(C_("IDS_TASK_BODY_MY_TASK"));
215 else if (cid == DEFAULT_BIRTHDAY_CALENDAR_BOOK_ID)
216 return strdup(C_("IDS_CLD_MBODY_CONTACTS_BIRTHDAY"));
218 error = calendar_record_get_str(calendar_book, _calendar_book.name, &name);
219 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
221 if (CAL_STRLEN(name))
226 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
232 static void __cal_setting_del_export_genlist_group_item(void *data, Evas_Object *obj)
234 c_retm_if(!data, "data is null.");
236 cal_setting_export_item_data *data_item = data;
241 static void __cal_setting_export_update_select_all(Evas_Object *genlist)
243 c_retm_if(!genlist, "genlist is null");
245 cal_setting_export_data *p = CAL_UTIL_GET_PRIV_DATA(genlist);
248 Elm_Object_Item *item = elm_genlist_first_item_get(genlist);
250 p->is_select_all_checked = EINA_TRUE;
253 cal_setting_export_item_data *item_data = elm_object_item_data_get(item);
254 c_ret_if(!item_data);
256 if (item_data->is_group_item) {
257 item = elm_genlist_item_next_get(item);
261 if (!item_data->is_checked) {
262 p->is_select_all_checked = EINA_FALSE;
266 item = elm_genlist_item_next_get(item);
269 elm_check_state_set(p->select_all_check, p->is_select_all_checked);
272 static void __cal_setting_check_changed_callback(void *data, Evas_Object *obj, void *event_info)
274 c_retm_if(!data, "data is null");
275 c_retm_if(!obj, "obj is null");
277 cal_setting_export_data *p = evas_object_data_get(data, "priv");
280 cal_setting_export_item_data *item_data = evas_object_data_get(obj, "item_data");
281 c_ret_if(!item_data);
283 item_data->is_checked = elm_check_state_get(obj);
285 if (item_data->is_checked) {
291 if (0 < p->checked_count) {
292 elm_object_disabled_set(p->export_bt, EINA_FALSE);
294 elm_object_disabled_set(p->export_bt, EINA_TRUE);
297 __cal_setting_export_update_select_all(data);
299 __cal_setting_export_update_small_info(p);
302 static void __cal_setting_gl_export_genlist_del(void *data, Evas_Object *obj)
304 c_retm_if(!data, "data is NULL");
305 cal_setting_export_item_data *info = data;
310 static char *__cal_setting_ug_export_account_guide_item_label(void *data, Evas_Object *obj, const char *part)
312 return strdup(C_("IDS_CLD_BODY_EXPORT_S_PLANNER_DATA_FROM_YOUR_PHONE"));
315 static void __cal_setting_export_popup_list_sel(void *data, Evas_Object *obj, void *event_info)
317 c_retm_if(!data, "data is null");
318 c_retm_if(!obj, "obj is null");
320 cal_setting_export_item_data *item_data = data;
322 cal_setting_export_data *p = CAL_UTIL_GET_PRIV_DATA(obj);
325 Elm_Object_Item *item = elm_genlist_selected_item_get(obj);
326 c_retm_if(!item, "elm_genlist_selected_item_get() returned null");
328 elm_genlist_item_selected_set(item, EINA_FALSE);
330 item_data->is_checked = !item_data->is_checked;
331 if (item_data->is_checked) {
337 elm_genlist_item_update(item_data->item);
339 __cal_setting_export_update_select_all(obj);
341 if (p->checked_count) {
342 elm_object_disabled_set(p->export_bt, EINA_FALSE);
344 elm_object_disabled_set(p->export_bt, EINA_TRUE);
347 __cal_setting_export_update_small_info(p);
351 static void __cal_setting_select_all(cal_setting_export_data *data)
355 cal_setting_export_data *p = data;
356 Elm_Object_Item *item;
357 cal_setting_export_item_data *item_data;
359 p->checked_count = 0;
361 item = elm_genlist_first_item_get(p->genlist);
363 item_data = elm_object_item_data_get(item);
364 if (item_data->is_group_item) {
365 item = elm_genlist_item_next_get(item);
369 item_data->is_checked = p->is_select_all_checked;
370 if (item_data->is_checked) {
373 p->checked_count = 0;
375 item = elm_genlist_item_next_get(item);
377 elm_genlist_realized_items_update(p->genlist);
379 if (0 < p->checked_count) {
380 elm_object_disabled_set(p->export_bt, EINA_FALSE);
382 elm_object_disabled_set(p->export_bt, EINA_TRUE);
385 __cal_setting_export_update_small_info(p);
388 static void __cal_setting_select_all_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
394 cal_setting_export_data *p = data;
395 Evas_Event_Mouse_Up *ev = event_info;
397 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
400 evas_object_geometry_get(obj, &x, &y, &w, &h);
401 if (ev->output.y < y || y + h < ev->output.y)
404 p->is_select_all_checked = !p->is_select_all_checked;
405 elm_check_state_set(p->select_all_check, p->is_select_all_checked);
406 __cal_setting_select_all(p);
407 __cal_setting_export_update_small_info(p);
410 static void __cal_setting_select_all_check_cb(void *data, Evas_Object *obj, void *event_info)
414 __cal_setting_select_all(data);
417 static void __cal_setting_export_clear_list(cal_setting_export_data *p)
421 struct _acct *at = eina_list_data_get(p->account_list);
422 if (at && at->data) {
423 _calendar_free_record_list((Eina_List **)&at->data);
427 Eina_List *list = eina_list_next(p->account_list);
432 EINA_LIST_FOREACH(list, l, at) {
434 _calendar_free_record_list((Eina_List **)&at->data);
437 cal_account_svc_free_account_list(&list);
438 p->account_list = list;
441 p->checked_count = 0;
444 static void __cal_setting_export_layout_delete_callback(void *data, Evas *e, Evas_Object *obj, void *ei)
446 cal_setting_export_data *p = data;
449 __cal_setting_export_clear_list(p);
453 static void __cal_setting_export_button_callback(void *data, Evas_Object *obj, void *ei)
459 cal_setting_export_data *p = data;
462 Evas_Object *genlist = p->genlist;
463 c_retm_if(!genlist, "genlist is null");
465 Elm_Object_Item *item = NULL;
466 cal_setting_export_item_data *export_item_data = NULL;
467 item = elm_genlist_first_item_get(genlist);
469 export_item_data = elm_object_item_data_get(item);
470 c_retm_if(!export_item_data, "export_item_data is null");
472 if (export_item_data->is_checked) {
473 calendar_error_e error = CALENDAR_ERROR_NONE;
475 calendar_record_h calendar_book = NULL;
477 error = calendar_record_clone(export_item_data->calendar_book, &calendar_book);
478 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
480 p->ugd->checked_calendar_list = eina_list_append(p->ugd->checked_calendar_list, calendar_book);
483 item = elm_genlist_item_next_get(item);
486 if (p->ugd->checked_calendar_list)
487 cal_setting_export_calendar_myfile_ug(p->ugd);
492 static void __cal_setting_export_cancel_callback(void *data, Evas_Object *obj, void *ei)
498 cal_setting_export_data *p = data;
501 p->is_select_all_checked = EINA_FALSE;
502 p->checked_count = 0;
504 elm_object_signal_emit(p->ly, "hide,selection,info", "elm");
509 static void __cal_setting_export_create_select_all(cal_setting_export_data *p)
513 p->select_all_layout = elm_layout_add(p->ugd->naviframe);
514 if (!p->select_all_layout) {
515 ERR("elm_genlist_add(popup) returned null");
516 evas_object_del(p->box);
520 elm_layout_theme_set(p->select_all_layout, "genlist", "item", "select_all/default");
521 evas_object_size_hint_weight_set(p->select_all_layout, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
522 evas_object_size_hint_align_set(p->select_all_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
523 evas_object_event_callback_add(p->select_all_layout, EVAS_CALLBACK_MOUSE_UP, __cal_setting_select_all_mouse_up_cb, p);
525 p->select_all_check = elm_check_add(p->select_all_layout);
526 if (!p->select_all_check) {
527 ERR("elm_genlist_add(popup) returned null");
528 evas_object_del(p->box);
529 evas_object_del(p->select_all_layout);
533 elm_check_state_pointer_set(p->select_all_check, &p->is_select_all_checked);
534 evas_object_smart_callback_add(p->select_all_check, "changed", __cal_setting_select_all_check_cb, p);
535 evas_object_propagate_events_set(p->select_all_check, EINA_FALSE);
536 elm_object_part_content_set(p->select_all_layout, "elm.icon", p->select_all_check);
538 elm_object_part_text_set(p->select_all_layout, "elm.text", S_("IDS_COM_BODY_SELECT_ALL"));
539 elm_box_pack_start(p->box, p->select_all_layout);
540 evas_object_show(p->select_all_layout);
543 static inline void __cal_setting_export_set_default_account(cal_setting_export_data *p)
547 p->account_list = eina_list_append(p->account_list, &def_at);
550 static void __cal_setting_export_get_list(cal_setting_export_data *p)
557 l = cal_account_svc_get_account_list();
559 p->account_list = eina_list_merge(p->account_list, l);
561 EINA_LIST_FOREACH(p->account_list, l, at)
562 at->data = _calendar_get_calendar_book_list_with_account_id(at->id);
565 static void __cal_setting_export_update_genlist(cal_setting_export_data *p)
572 cal_setting_export_item_data *export_item_data = NULL;
574 __cal_setting_export_clear_list(p);
576 elm_genlist_clear(p->genlist);
578 __cal_setting_export_set_default_account(p);
580 __cal_setting_export_get_list(p);
582 EINA_LIST_FOREACH(p->account_list, l, at) {
584 export_item_data = calloc(1, sizeof(cal_setting_export_item_data));
585 c_ret_if(!export_item_data);
587 export_item_data->is_checked = EINA_FALSE;
588 export_item_data->at = at;
589 export_item_data->is_group_item = EINA_TRUE;
590 export_item_data->item = elm_genlist_item_append(p->genlist, &it_group, export_item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
591 c_ret_if(!export_item_data->item);
593 elm_genlist_item_select_mode_set(export_item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
595 calendar_record_h calendar_book = NULL;
597 EINA_LIST_FOREACH(at->data, ll, calendar_book) {
599 export_item_data = calloc(1, sizeof(cal_setting_export_item_data));
600 c_ret_if(!export_item_data);
602 export_item_data->is_checked = EINA_FALSE;
603 export_item_data->calendar_book = calendar_book;
604 export_item_data->is_group_item = EINA_FALSE;
605 export_item_data->item = elm_genlist_item_append(p->genlist, &itc_1text_2icon_2, export_item_data, NULL, ELM_GENLIST_ITEM_NONE, __cal_setting_export_popup_list_sel, export_item_data);
611 export_item_data = calloc(1, sizeof(cal_setting_export_item_data));
612 c_ret_if(!export_item_data);
614 export_item_data->is_group_item = EINA_TRUE;
615 export_item_data->item = elm_genlist_item_append(p->genlist, &itc_export_account_guide, export_item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
616 elm_genlist_item_select_mode_set(export_item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
619 void cal_setting_export_create_view(struct ug_data *data)
623 struct ug_data *ugd = data;
625 cal_setting_export_data *p = calloc(1, sizeof(cal_setting_export_data));
630 p->ly = cal_util_add_layout(p->ugd->naviframe, "selectioninfo");
632 ERR("p->ly is NULL!");
637 evas_object_event_callback_add(p->ly, EVAS_CALLBACK_DEL, __cal_setting_export_layout_delete_callback, p);
639 p->box = elm_box_add(p->ly);
642 ERR("elm_box_add is failed!");
643 evas_object_del(p->ly);
647 evas_object_size_hint_weight_set(p->box, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
648 evas_object_size_hint_align_set(p->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
650 __cal_setting_export_create_select_all(p);
652 p->genlist = elm_genlist_add(p->box);
654 ERR("elm_genlist_add(popup) returned null");
655 evas_object_del(p->box);
656 evas_object_del(p->select_all_layout);
660 elm_genlist_mode_set(p->genlist, ELM_LIST_COMPRESS);
662 evas_object_size_hint_weight_set(p->genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
663 evas_object_size_hint_align_set(p->genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
664 evas_object_data_set(p->genlist, "check", p->select_all_check);
665 evas_object_data_set(p->genlist, "priv", p);
667 evas_object_show(p->genlist);
668 elm_box_pack_end(p->box, p->genlist);
669 evas_object_show(p->box);
671 elm_object_part_content_set(p->ly, "gen.swallow.contents", p->box);
673 __cal_setting_export_update_genlist(p);
675 Elm_Object_Item* navi_item = elm_naviframe_item_push(ugd->naviframe, C_("IDS_CLD_BODY_EXPORT_EVENTS_TASKS_ABB"), NULL, NULL, p->ly, NULL);
676 c_ret_if(!navi_item);
678 p->export_bt = cal_util_add_toolbar_button(ugd->naviframe, "toolbar_button1", C_("IDS_RSSR_OPT_EXPORT"), __cal_setting_export_button_callback, p);
679 elm_object_disabled_set(p->export_bt, EINA_TRUE);
681 Evas_Object *back_button = elm_object_item_part_content_get(navi_item, "prev_btn");
682 c_ret_if(!back_button);
684 evas_object_smart_callback_add(back_button, "clicked", __cal_setting_export_cancel_callback, p);