2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "email-setting.h"
18 #include "email-setting-utils.h"
20 #include <unicode/uloc.h>
21 #include <unicode/ucal.h>
22 #include <unicode/udat.h>
23 #include <unicode/udatpg.h>
24 #include <unicode/ustring.h>
26 static email_account_t *account_data = NULL;
27 static struct viewdata *g_vd = NULL;
29 static UDateTimePatternGenerator *icu_pg = NULL;
30 static UDateFormat *icu_formatter = NULL;
31 static enum appcore_time_format icu_timeformat;
33 static int _create(struct viewdata *vd);
34 static int _update(struct viewdata *vd);
35 static int _destroy(struct viewdata *vd);
36 static int _show(struct viewdata *vd);
37 static int _hide(struct viewdata *vd);
39 static void _push_naviframe(struct viewdata *vd);
40 static void _create_list(struct viewdata *vd);
41 static void _update_account_info(struct viewdata *vd);
42 static void _get_icu_formatter(void);
43 static void _close_icu_formatter(void);
44 static void _get_date_text_with_formatter(time_t time, char *formatted_str);
46 static void _account_edit_cb(void *data, Evas_Object *obj, void *event_info);
47 static void _onoff_cb(void *data, Evas_Object *obj, void *event_info);
48 static void _refresh_cb(void *data, Evas_Object *obj, void *event_info);
49 static void _delete_cb(void *data, Evas_Object *obj, void *event_info);
50 static void _back_cb(void *data, Evas_Object *obj, void *event_info);
51 static Eina_Bool _after_delete_cb(void *data);
53 static void _popup_cancel_cb(void *data, Evas_Object *obj, void *event_info);
54 static void _popup_delete_ok_cb(void *data, Evas_Object *obj, void *event_info);
56 static char *_gl_account_text_get_cb(void *data, Evas_Object *obj, const char *part);
57 static char *_gl_onoff_text_get_cb(void *data, Evas_Object *obj, const char *part);
58 static char *_gl_sync_text_get_cb(void *data, Evas_Object *obj, const char *part);
59 static char *_gl_ex_sync_text_get_cb(void *data, Evas_Object *obj, const char *part);
60 static Evas_Object *_gl_account_content_get_cb(void *data, Evas_Object *obj, const char *part);
61 static Evas_Object *_gl_onoff_content_get_cb(void *data, Evas_Object *obj, const char *part);
62 static Evas_Object *_gl_ex_sync_content_get_cb(void *data, Evas_Object *obj, const char *part);
63 static void _gl_sel_cb(void *data, Evas_Object *obj, void *event_info);
64 static void _gl_ex_sel_cb(void *data, Evas_Object *obj, void *event_info);
65 static void _gl_ex_sync_sel_cb(void *data, Evas_Object *obj, void *event_info);
66 static void _gl_exp_cb(void *data, Evas_Object *obj, void *event_info);
67 static void _gl_con_cb(void *data, Evas_Object *obj, void *event_info);
69 static int sync_schedule[7] = { 0, 30, 60, 180, 360, 720, 1440 };
71 #define SYNC_STATUS_FINISHED 0 /* BIN 00000000 */
72 #define SYNC_STATUS_SYNCING 1 /* BIN 00000001 */
73 #define SYNC_STATUS_HAVE_NEW_MAILS 2 /* BIN 00000010 */
81 Evas_Object *l_button;
82 Evas_Object *r_button;
83 Evas_Object *tool_btn;
86 Evas_Object *sync_radio_grp;
87 Evas_Object *account_icon;
90 Elm_Genlist_Item_Class itc_account;
91 Elm_Genlist_Item_Class itc_onoff;
92 Elm_Genlist_Item_Class itc_sync;
93 Elm_Genlist_Item_Class itc_ex_sync;
94 Elm_Genlist_Item_Class itc_sep;
95 Elm_Genlist_Item_Class itc_sep2;
97 Elm_Object_Item * c_item[4];
98 Elm_Object_Item *gl_sync_item;
99 Elm_Object_Item *gl_onoff_item;
100 Elm_Object_Item *gl_account_item;
101 Elm_Object_Item *navi_it;
107 void setting_init_sync_schedule_view(struct viewdata *vd)
110 vd->type = VIEW_SYNC_SCHEDULE;
111 vd->create = _create;
112 vd->update = _update;
113 vd->destroy = _destroy;
116 vd->grp_nm = "setting_sync_schedule";
119 void setting_schedule_sync_started(struct viewdata *vd, int account_id)
122 struct priv_data *p = NULL;
123 EmailSettingUGD *ugd = vd->ugd;
127 debug_log("priv is NULL");
131 if (ugd->account_id != account_id) {
132 debug_log("not interested");
136 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
137 debug_log("failed to get account data");
141 elm_object_disabled_set(p->r_button, TRUE);
142 elm_genlist_item_update(p->gl_account_item);
145 void setting_schedule_sync_finished(struct viewdata *vd, int account_id)
148 struct priv_data *p = NULL;
149 EmailSettingUGD *ugd = vd->ugd;
153 debug_log("priv is NULL");
157 if (ugd->account_id != account_id) {
158 debug_log("not interested");
162 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
163 debug_log("failed to get account data");
167 elm_object_disabled_set(p->r_button, FALSE);
168 elm_genlist_item_update(p->gl_account_item);
171 static int _create(struct viewdata *vd)
176 debug_log("vd is NULL");
180 struct priv_data *p = NULL;
181 EmailSettingUGD *ugd = vd->ugd;
185 p = vd->priv = calloc(1, sizeof(struct priv_data));
188 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
189 debug_log("failed to get account data");
193 p->layout = setting_add_inner_layout(vd);
195 // elm_object_part_content_set(ugd->win, "elm.swallow.content", p->layout);
198 _get_icu_formatter();
207 static int _update(struct viewdata *vd)
212 debug_log("vd is NULL");
216 struct priv_data *p = NULL;
217 EmailSettingUGD *ugd = vd->ugd;
221 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
222 debug_log("failed to get account data");
225 if (account_data->sync_status & SYNC_STATUS_SYNCING) {
227 elm_object_disabled_set(p->r_button, TRUE);
230 elm_object_disabled_set(p->r_button, FALSE);
232 elm_genlist_item_update(p->gl_account_item);
238 static int _destroy(struct viewdata *vd)
243 debug_log("vd is NULL");
247 struct priv_data *p = vd->priv;
250 debug_log("priv is NULL");
254 evas_object_del(p->l_button);
255 evas_object_del(p->onoff);
256 evas_object_del(p->genlist);
257 evas_object_del(p->sync_radio_grp);
260 email_engine_free_account_list(&account_data, 1);
264 _close_icu_formatter();
269 static int _show(struct viewdata *vd)
274 debug_log("vd is NULL");
278 struct priv_data *p = vd->priv;
281 debug_log("priv is NULL");
285 EmailSettingUGD *ugd = vd->ugd;
288 email_engine_free_account_list(&account_data, 1);
292 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
293 debug_log("setting_get_acct_full_data failed");
298 elm_object_item_part_text_set(p->navi_it, "elm.text.title", account_data->account_name);
304 static int _hide(struct viewdata *vd)
309 debug_log("vd is NULL");
313 evas_object_hide(vd->ly);
318 static void _push_naviframe(struct viewdata *vd)
321 struct priv_data *p = vd->priv;
323 /*p->cbar = elm_toolbar_add(vd->ugd->navi_bar);
324 elm_toolbar_shrink_mode_set(p->cbar, ELM_TOOLBAR_SHRINK_EXPAND);
325 elm_object_style_set(p->cbar, "naviframe");
326 evas_object_show(p->cbar);
328 p->c_item[0] = elm_toolbar_item_append(p->cbar, NULL,
329 dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, vd);
330 elm_object_item_disabled_set(elm_toolbar_item_append(p->cbar, NULL, "", NULL, NULL), EINA_TRUE);
331 elm_object_item_disabled_set(elm_toolbar_item_append(p->cbar, NULL, "", NULL, NULL), EINA_TRUE);*/
333 p->r_button = elm_button_add(vd->ugd->navi_bar);
334 elm_object_style_set(p->r_button, "naviframe/title_icon");
335 /*elm_object_text_set(p->r_button, _("IDS_EMAIL_OPT_REFRESH"));*/
336 Evas_Object *ic = elm_icon_add(p->r_button);
337 elm_image_file_set(ic, TITLE_ICON_REFRESH, NULL);
338 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
339 evas_object_image_smooth_scale_set(ic, 0);
340 elm_object_content_set(p->r_button, ic);
341 evas_object_smart_callback_add(p->r_button, "clicked", _refresh_cb, vd);
342 evas_object_show(p->r_button);
344 if (account_data->sync_status & SYNC_STATUS_SYNCING) {
346 elm_object_disabled_set(p->r_button, TRUE);
349 p->l_button = elm_button_add(vd->ugd->navi_bar);
350 elm_object_style_set(p->l_button, "naviframe/back_btn/default");
351 evas_object_smart_callback_add(p->l_button, "clicked", _back_cb, vd);
353 p->tool_btn = elm_button_add(vd->ugd->navi_bar);
354 elm_object_style_set(p->tool_btn, "naviframe/toolbar/default");
355 elm_object_text_set(p->tool_btn, dgettext("sys_string", "IDS_COM_SK_DELETE"));
356 evas_object_smart_callback_add(p->tool_btn, "clicked", _delete_cb, vd);
358 account_user_data_t *user_data = (account_user_data_t *)account_data->user_data;
359 Evas_Object *title_ic = elm_icon_add(vd->ugd->navi_bar);
360 evas_object_size_hint_aspect_set(title_ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
361 elm_image_resizable_set(title_ic, EINA_TRUE, EINA_TRUE);
362 if (user_data->is_preset_account > 0) {
363 elm_image_file_set(title_ic, account_data->logo_icon_path, NULL);
365 elm_image_file_set(title_ic, ACCOUNT_ICON_OTHERS, NULL);
368 Elm_Object_Item *navi_it = NULL;
369 navi_it = elm_naviframe_item_push(vd->ugd->navi_bar, account_data->account_name, p->l_button, NULL, p->layout, NULL);
370 elm_object_item_part_content_set(navi_it, "icon", title_ic);
372 elm_object_item_part_content_set(navi_it, "title_right_btn", p->r_button);
373 elm_object_item_part_content_set(navi_it, "toolbar_button1", p->tool_btn);
374 evas_object_show(vd->ugd->navi_bar);
375 p->navi_it = navi_it;
378 static void _create_list(struct viewdata *vd)
383 debug_log("vd is NULL");
387 struct priv_data *p = vd->priv;
388 EmailSettingUGD *ugd = vd->ugd;
389 Elm_Object_Item *item = NULL;
390 Elm_Object_Item *git = NULL;
393 p->sync_radio_grp = elm_radio_add(ugd->navi_bar);
394 elm_radio_value_set(p->sync_radio_grp, 0);
395 evas_object_hide(p->sync_radio_grp);
397 p->genlist = elm_genlist_add(ugd->navi_bar);
398 elm_object_style_set(p->genlist, "dialogue");
400 p->itc_account.item_style = "dialogue/2text.1icon.10";
401 p->itc_account.func.text_get = _gl_account_text_get_cb;
402 p->itc_account.func.content_get = _gl_account_content_get_cb;
403 p->itc_account.func.state_get = NULL;
404 p->itc_account.func.del = NULL;
406 p->itc_onoff.item_style = "dialogue/2text.1icon.10";
407 p->itc_onoff.func.text_get = _gl_onoff_text_get_cb;
408 p->itc_onoff.func.content_get = _gl_onoff_content_get_cb;
409 p->itc_onoff.func.state_get = NULL;
410 p->itc_onoff.func.del = NULL;
412 p->itc_sync.item_style = "dialogue/2text.3/expandable";
413 p->itc_sync.func.text_get = _gl_sync_text_get_cb;
414 p->itc_sync.func.content_get = NULL;
415 p->itc_sync.func.state_get = NULL;
416 p->itc_sync.func.del = NULL;
418 p->itc_ex_sync.item_style = "dialogue/1text.1icon/expandable2";
419 p->itc_ex_sync.func.text_get = _gl_ex_sync_text_get_cb;
420 p->itc_ex_sync.func.content_get = _gl_ex_sync_content_get_cb;
421 p->itc_ex_sync.func.state_get = NULL;
422 p->itc_ex_sync.func.del = NULL;
424 p->itc_sep.item_style = "dialogue/separator";
425 p->itc_sep.func.text_get = NULL;
426 p->itc_sep.func.content_get = NULL;
427 p->itc_sep.func.state_get = NULL;
428 p->itc_sep.func.del = NULL;
430 p->itc_sep2.item_style = "dialogue/separator/end";
431 p->itc_sep2.func.text_get = NULL;
432 p->itc_sep2.func.content_get = NULL;
433 p->itc_sep2.func.state_get = NULL;
434 p->itc_sep2.func.del = NULL;
437 git = elm_genlist_item_append(p->genlist, &(p->itc_sep), NULL, NULL,
438 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
439 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
442 item = elm_genlist_item_append(p->genlist, &(p->itc_account), NULL, git,
443 ELM_GENLIST_ITEM_NONE, _account_edit_cb, (void *)vd);
444 p->gl_account_item = item;
447 item = elm_genlist_item_append(p->genlist, &(p->itc_sync), NULL,
448 git, ELM_GENLIST_ITEM_TREE, _gl_ex_sel_cb, (void *)vd);
449 p->gl_sync_item = item;
452 git = elm_genlist_item_append(p->genlist, &(p->itc_sep), NULL, NULL,
453 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
454 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
457 item = elm_genlist_item_append(p->genlist, &(p->itc_onoff), (void *)i,
458 git, ELM_GENLIST_ITEM_NONE, _gl_sel_cb, (void *)i);
459 p->gl_onoff_item = item;
462 git = elm_genlist_item_append(p->genlist, &(p->itc_sep2), NULL, NULL,
463 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
464 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
466 evas_object_smart_callback_add(p->genlist, "expanded", _gl_exp_cb, (void *)vd);
467 evas_object_smart_callback_add(p->genlist, "contracted", _gl_con_cb, (void *)vd);
469 elm_object_part_content_set(p->layout, "elm.swallow.content", p->genlist);
472 static void _update_account_info(struct viewdata *vd)
475 struct priv_data *p = NULL;
478 debug_log("vd is NULL");
483 debug_log("priv is NULL");
489 if (account_data == NULL) {
490 debug_log("account_data is NULL");
494 if (email_engine_update_account(account_data->account_id, account_data) == TRUE)
495 debug_log("Account updated successfully");
498 static void _get_icu_formatter(void)
501 UErrorCode status = U_ZERO_ERROR;
502 char *icu_locale = NULL;
504 uloc_setDefault(getenv("LC_TIME"), &status);
505 if (U_FAILURE(status)) {
506 debug_critical("uloc_setDefault() failed: %s\n", u_errorName(status));
510 icu_locale = (char *)uloc_getDefault();
511 debug_log("uloc_getDefault: %s", icu_locale);
512 appcore_get_timeformat(&icu_timeformat);
514 status = U_ZERO_ERROR;
515 icu_pg = udatpg_open(icu_locale, &status);
517 debug_log("udatpg_open() failed: %s", u_errorName(status));
521 char *skeleton = NULL;
522 if (icu_timeformat == APPCORE_TIME_FORMAT_12) {
523 skeleton = "EEEMMMddhmma";
525 skeleton = "EEEMMMddHmm";
528 UChar bestPattern[64] = { 0, };
529 UChar customSkeleton[64] = { 0, };
530 int32_t bestPatternCapacity;
531 int32_t bestPatternLength;
532 int skeletonLength = strlen(skeleton);
534 u_uastrncpy(customSkeleton, skeleton, skeletonLength);
536 status = U_ZERO_ERROR;
537 bestPatternCapacity = (int32_t) (sizeof(bestPattern) / sizeof(bestPattern[0]));
538 bestPatternLength = udatpg_getBestPattern(icu_pg, customSkeleton, u_strlen(customSkeleton), bestPattern, bestPatternCapacity, &status);
540 status = U_ZERO_ERROR;
541 icu_formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, icu_locale, NULL, -1, bestPattern, -1, &status);
544 static void _close_icu_formatter(void)
549 udatpg_close(icu_pg);
554 udat_close(icu_formatter);
555 icu_formatter = NULL;
559 static void _get_date_text_with_formatter(time_t time, char *formatted_str)
562 UErrorCode status = U_ZERO_ERROR;
564 UChar formatted[64] = { 0, };
565 int32_t formattedCapacity;
566 int32_t formattedLength;
568 formattedCapacity = (int32_t) (sizeof(formatted) / sizeof(formatted[0]));
569 time_t msg_time = time;
570 date = (UDate)msg_time * 1000;
572 formattedLength = udat_format(icu_formatter, date, formatted, formattedCapacity, NULL, &status);
573 u_austrncpy(formatted_str, formatted, 127);
574 debug_log("time_t: %d", time);
575 debug_log("formatted time: %s", formatted_str);
578 static void _account_edit_cb(void *data, Evas_Object *obj, void *event_info)
581 struct viewdata *vd = (struct viewdata *)data;
582 EmailSettingUGD *ugd = vd->ugd;
584 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
585 elm_genlist_item_selected_set(item, EINA_FALSE);
587 Viewtype top = ugd->view_st[ugd->view_top];
588 if (top != VIEW_SYNC_SCHEDULE) {
589 debug_log("**double clicked**");
593 debug_log("Selected account id:%d", account_data->account_id);
594 vd->ugd->account_id = account_data->account_id;
595 vd->ugd->myaccount_id = account_data->account_svc_id;
597 setting_change_view(VIEW_ACCOUNT_EDIT, ugd);
600 static void _onoff_cb(void *data, Evas_Object *obj, void *event_info)
604 struct viewdata *vd = (struct viewdata *)data;
605 struct priv_data *p = vd->priv;
607 Eina_Bool state = elm_check_state_get(obj);
610 account_data->check_interval = abs(account_data->check_interval);
611 account_data->sync_disabled = 0;
613 if (p->gl_sync_item) {
614 elm_genlist_item_update(p->gl_sync_item);
615 elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE);
618 account_data->check_interval = -(abs(account_data->check_interval));
619 account_data->sync_disabled = 1;
621 if (p->gl_sync_item) {
622 if (elm_genlist_item_expanded_get(p->gl_sync_item)) {
623 elm_genlist_item_expanded_set(p->gl_sync_item, 0);
625 elm_genlist_item_update(p->gl_sync_item);
626 elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE);
630 _update_account_info(vd);
633 static void _refresh_cb(void *data, Evas_Object *obj, void *event_info)
636 struct viewdata *vd = (struct viewdata *)data;
638 debug_log("vd is NULL");
642 struct priv_data *p = vd->priv;
644 int account_id = account_data->account_id;
648 gboolean res = FALSE;
649 email_mailbox_t *mailbox = NULL;
650 ret = email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox);
651 if (ret != EMAIL_ERROR_NONE || mailbox == NULL || mailbox->mailbox_name == NULL) {
652 debug_log("email_get_mailbox_by_mailbox_type failed");
656 res = email_engine_sync_folder(account_id, mailbox->mailbox_id, &handle);
657 debug_log("handle: %d", handle);
658 email_free_mailbox(&mailbox, 1);
661 elm_object_disabled_set(p->r_button, TRUE);
662 elm_genlist_item_update(p->gl_sync_item);
663 elm_genlist_item_update(p->gl_onoff_item);
666 static void _delete_cb(void *data, Evas_Object *obj, void *event_info)
669 struct viewdata *vd = (struct viewdata *)data;
672 debug_log("vd is NULL");
676 struct priv_data *p = vd->priv;
677 EmailSettingUGD *ugd = vd->ugd;
679 if (ugd->popup_one) {
680 evas_object_del(ugd->popup_one);
681 ugd->popup_one = NULL;
684 if (ugd->popup_validate) {
685 evas_object_del(ugd->popup_validate);
686 ugd->popup_validate = NULL;
689 vd->ugd->account_id = account_data->account_id;
691 elm_object_disabled_set(p->l_button, EINA_TRUE);
692 elm_object_disabled_set(p->tool_btn, EINA_TRUE);
694 ugd->popup_one = setting_get_notify(vd, NULL, _("IDS_EMAIL_POP_ALL_DATA_RELATED_TO_THIS_ACCOUNT_WILL_BE_DELETED_CONTINUE_Q"), 2,
695 dgettext("sys_string", "IDS_COM_SK_YES"),
697 dgettext("sys_string", "IDS_COM_SK_NO"),
701 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
705 struct viewdata *vd = data;
706 /*struct priv_data *p = vd->priv;*/
708 setting_back_to_prev_view(vd);
711 static Eina_Bool _after_delete_cb(void *data)
715 struct viewdata *vd = (struct viewdata *)data;
718 debug_log("vd is NULL");
719 return ECORE_CALLBACK_CANCEL;
722 struct priv_data *p = vd->priv;
723 EmailSettingUGD *ugd = vd->ugd;
725 if (ugd->del_timer) {
726 ecore_timer_del(ugd->del_timer);
727 ugd->del_timer = NULL;
730 status_message_post(dgettext("sys_string", "IDS_COM_POP_DELETED"));
732 if (vd->ugd->start_view_type != NULL && g_strcmp0(vd->ugd->start_view_type, "account-edit") == 0) {
733 ug_destroy_me(vd->ugd->ug);
735 if (p->account_deleted) {
736 setting_update_acct_list(vd);
737 setting_back_to_prev_nth_view(vd, 2, vd->ugd->navi_main_it);
739 setting_back_to_prev_view(vd);
742 setting_get_small_notify(vd, dgettext("sys_string", "IDS_COM_POP_DELETED"));
745 return ECORE_CALLBACK_CANCEL;
748 static void _popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
753 debug_log("data is NULL");
757 struct viewdata *vd = (struct viewdata *)data;
758 struct priv_data *p = vd->priv;
759 EmailSettingUGD *ugd = vd->ugd;
761 if (ugd->popup_one) {
762 evas_object_del(ugd->popup_one);
763 ugd->popup_one = NULL;
765 if (ugd->popup_validate) {
766 evas_object_del(ugd->popup_validate);
767 ugd->popup_validate = NULL;
770 elm_object_disabled_set(p->l_button, EINA_FALSE);
771 elm_object_disabled_set(p->tool_btn, EINA_FALSE);
774 static void _popup_delete_ok_cb(void *data, Evas_Object *obj, void *event_info)
779 debug_log("data is NULL");
783 struct viewdata *vd = (struct viewdata *)data;
784 struct priv_data *p = vd->priv;
785 EmailSettingUGD *ugd = vd->ugd;
787 if (ugd->popup_one) {
788 evas_object_del(ugd->popup_one);
789 ugd->popup_one = NULL;
791 if (ugd->popup_validate) {
792 evas_object_del(ugd->popup_validate);
793 ugd->popup_validate = NULL;
796 int account_id = vd->ugd->account_id;
797 int ret = email_engine_delete_account(account_id);
800 p->account_deleted = TRUE;
801 ugd->del_timer = ecore_timer_add(0.5, _after_delete_cb, vd);
802 debug_log("delete success");
804 ugd->popup_one = setting_get_notify(vd, dgettext("sys_string", "IDS_COM_POP_WARNING"),
805 dgettext("sys_string", "IDS_COM_POP_UNABLE_TO_DELETE"), 1,
806 dgettext("sys_string", "IDS_COM_SK_OK"),
807 _popup_cancel_cb, NULL, NULL);
808 debug_log("delete failed");
812 static char *_gl_account_text_get_cb(void *data, Evas_Object *obj, const char *part)
817 debug_log("account_data is NULL");
821 if (!g_strcmp0(part, "elm.text.1")) {
822 return g_strdup(account_data->account_name);
825 if (!g_strcmp0(part, "elm.text.2")) {
826 return g_strdup(account_data->user_email_address);
832 static char *_gl_onoff_text_get_cb(void *data, Evas_Object *obj, const char *part)
836 if (!g_strcmp0(part, "elm.text.1")) {
837 char buf[MAX_STR_LEN] = { 0, };
839 snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_EMAIL_SYNC"));
840 return g_strdup(buf);
841 } else if (!g_strcmp0(part, "elm.text.2")) {
842 char buf[MAX_STR_LEN] = { 0, };
843 email_mailbox_t *mailbox = NULL;
844 email_get_mailbox_by_mailbox_type(account_data->account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox);
846 time_t req_time = time(NULL);//mailbox->last_sync_time;
847 _get_date_text_with_formatter(req_time, buf);
848 email_free_mailbox(&mailbox, 1);
851 return g_strdup(buf);
857 static char *_gl_sync_text_get_cb(void *data, Evas_Object *obj, const char *part)
862 debug_log("account_data is NULL");
866 if (!g_strcmp0(part, "elm.text.1")) {
867 char buf[MAX_STR_LEN] = { 0, };
868 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_SYNC_SCHEDULE"));
869 return g_strdup(buf);
872 if (!g_strcmp0(part, "elm.text.2")) {
873 char buf[MAX_STR_LEN] = { 0, };
875 /*int period = abs(account_data->check_interval);*/
876 int period = account_data->check_interval;
878 if (period <= sync_schedule[0]) {
879 snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_MANUAL"));
880 } else if (period == sync_schedule[1]) {
881 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_EVERY_30_MINUTES"));
882 } else if (period == sync_schedule[2]) {
883 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_EVERY_1_HOUR"));
884 } else if (period == sync_schedule[3]) {
885 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 3);
886 } else if (period == sync_schedule[4]) {
887 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 6);
888 } else if (period == sync_schedule[5]) {
889 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 12);
890 } else if (period == sync_schedule[6]) {
891 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_ONCE_A_DAY"));
893 return g_strdup(buf);
899 static char *_gl_ex_sync_text_get_cb(void *data, Evas_Object *obj, const char *part)
902 int index = (int)data;
904 if (!g_strcmp0(part, "elm.text")) {
905 char buf[MAX_STR_LEN] = { 0, };
908 snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_MANUAL"));
909 } else if (index == 1) {
910 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_EVERY_30_MINUTES"));
911 } else if (index == 2) {
912 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_EVERY_1_HOUR"));
913 } else if (index == 3) {
914 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 3);
915 } else if (index == 4) {
916 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 6);
917 } else if (index == 5) {
918 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 12);
919 } else if (index == 6) {
920 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_ONCE_A_DAY"));
923 return g_strdup(buf);
929 static Evas_Object *_gl_account_content_get_cb(void *data, Evas_Object *obj, const char *part)
934 debug_log("account_data is NULL");
938 struct viewdata *vd = g_vd;
939 EmailSettingUGD *ugd = vd->ugd;
940 struct priv_data *p = vd->priv;
942 if (!g_strcmp0(part, "elm.icon")) {
944 Evas_Object *pb = elm_progressbar_add(ugd->navi_bar);
945 elm_object_style_set(pb, "list_process");
946 elm_progressbar_horizontal_set(pb, EINA_TRUE);
947 elm_progressbar_pulse(pb, EINA_TRUE);
955 static Evas_Object *_gl_onoff_content_get_cb(void *data, Evas_Object *obj, const char *part)
960 debug_log("account_data is NULL");
964 struct viewdata *vd = g_vd;
965 EmailSettingUGD *ugd = vd->ugd;
966 struct priv_data *p = vd->priv;
968 if (!g_strcmp0(part, "elm.icon")) {
969 Evas_Object *check = elm_check_add(ugd->navi_bar);
970 elm_object_style_set(check, "on&off");
971 evas_object_smart_callback_add(check, "changed", _onoff_cb, vd);
972 evas_object_propagate_events_set(check, EINA_FALSE);
974 if (account_data->sync_disabled) {
975 elm_check_state_set(check, EINA_FALSE);
976 elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE);
978 elm_check_state_set(check, EINA_TRUE);
979 elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE);
990 static Evas_Object *_gl_ex_sync_content_get_cb(void *data, Evas_Object *obj, const char *part)
995 debug_log("account_data is NULL");
999 int index = (int)data;
1000 struct viewdata *vd = g_vd;
1001 EmailSettingUGD *ugd = vd->ugd;
1002 struct priv_data *p = vd->priv;
1004 if (!g_strcmp0(part, "elm.icon")) {
1005 Evas_Object *radio = elm_radio_add(ugd->navi_bar);
1006 elm_radio_group_add(radio, p->sync_radio_grp);
1007 elm_radio_state_value_set(radio, index);
1009 if (sync_schedule[index] == abs(account_data->check_interval)) {
1010 elm_radio_value_set(p->sync_radio_grp, index);
1018 static void _gl_sel_cb(void *data, Evas_Object *obj, void *event_info)
1022 if (!account_data) {
1023 debug_log("account_data is NULL");
1027 struct viewdata *vd = g_vd;
1028 struct priv_data *p = vd->priv;
1030 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1031 elm_genlist_item_selected_set(item, EINA_FALSE);
1033 Eina_Bool state = elm_check_state_get(p->onoff);
1036 account_data->check_interval = -(abs(account_data->check_interval));
1037 account_data->sync_disabled = 1;
1038 elm_check_state_set(p->onoff, EINA_FALSE);
1040 if (p->gl_sync_item) {
1041 if (elm_genlist_item_expanded_get(p->gl_sync_item)) {
1042 elm_genlist_item_expanded_set(p->gl_sync_item, 0);
1044 elm_genlist_item_update(p->gl_sync_item);
1045 elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE);
1048 account_data->check_interval = abs(account_data->check_interval);
1049 account_data->sync_disabled = 0;
1050 elm_check_state_set(p->onoff, EINA_TRUE);
1052 if (p->gl_sync_item) {
1053 elm_genlist_item_update(p->gl_sync_item);
1054 elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE);
1058 _update_account_info(vd);
1061 static void _gl_ex_sel_cb(void *data, Evas_Object *obj, void *event_info)
1065 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1066 elm_genlist_item_selected_set(item, EINA_FALSE);
1068 if (!elm_genlist_item_expanded_get(item)) {
1069 elm_genlist_item_expanded_set(item, 1);
1071 elm_genlist_item_expanded_set(item, 0);
1075 static void _gl_ex_sync_sel_cb(void *data, Evas_Object *obj, void *event_info)
1079 if (!account_data) {
1080 debug_log("account_data is NULL");
1084 int index = (int)data;
1085 struct viewdata *vd = g_vd;
1086 struct priv_data *p = vd->priv;
1089 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1090 elm_genlist_item_selected_set(item, EINA_FALSE);
1092 sel_radio = elm_radio_value_get(p->sync_radio_grp);
1094 if (sel_radio == index)
1097 if (index >= 0 && index < 7)
1098 account_data->check_interval = sync_schedule[index];
1100 elm_radio_value_set(p->sync_radio_grp, index);
1102 _update_account_info(vd);
1104 elm_genlist_item_update(p->gl_sync_item);
1107 static void _gl_exp_cb(void *data, Evas_Object *obj, void *event_info)
1110 Elm_Object_Item *it = event_info;
1112 struct viewdata *vd = (struct viewdata *)data;
1113 struct priv_data *p = vd->priv;
1117 for (i = 0; i < 7; i++) {
1118 elm_genlist_item_append(p->genlist, &(p->itc_ex_sync), (void *)i,
1119 it, ELM_GENLIST_ITEM_NONE, _gl_ex_sync_sel_cb, (void *)i);
1123 static void _gl_con_cb(void *data, Evas_Object *obj, void *event_info)
1126 Elm_Object_Item *item = event_info;
1127 elm_genlist_item_subitems_clear(item);