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;
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;
106 void setting_init_sync_schedule_view(struct viewdata *vd)
109 vd->type = VIEW_SYNC_SCHEDULE;
110 vd->create = _create;
111 vd->update = _update;
112 vd->destroy = _destroy;
115 vd->grp_nm = "setting_sync_schedule";
118 void setting_schedule_sync_started(struct viewdata *vd, int account_id)
121 struct priv_data *p = NULL;
122 EmailSettingUGD *ugd = vd->ugd;
125 if (ugd->account_id != account_id) {
126 debug_log("not interested");
130 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
131 debug_log("failed to get account data");
135 elm_object_disabled_set(p->r_button, TRUE);
136 elm_genlist_item_update(p->gl_account_item);
139 void setting_schedule_sync_finished(struct viewdata *vd, int account_id)
142 struct priv_data *p = NULL;
143 EmailSettingUGD *ugd = vd->ugd;
146 if (ugd->account_id != account_id) {
147 debug_log("not interested");
151 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
152 debug_log("failed to get account data");
156 elm_object_disabled_set(p->r_button, FALSE);
157 elm_genlist_item_update(p->gl_account_item);
160 static int _create(struct viewdata *vd)
165 debug_log("vd is NULL");
169 struct priv_data *p = NULL;
170 EmailSettingUGD *ugd = vd->ugd;
174 p = vd->priv = calloc(1, sizeof(struct priv_data));
177 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
178 debug_log("failed to get account data");
181 p->layout = setting_add_inner_layout(vd);
184 elm_win_conformant_set(ugd->win, 1);
185 p->conform = elm_conformant_add(ugd->win);
186 elm_object_style_set(p->conform, "internal_layout");
187 evas_object_show(p->conform);
189 elm_object_part_content_set(p->layout, "elm.swallow.content", p->conform);
192 _get_icu_formatter();
201 static int _update(struct viewdata *vd)
206 debug_log("vd is NULL");
210 struct priv_data *p = NULL;
211 EmailSettingUGD *ugd = vd->ugd;
215 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
216 debug_log("failed to get account data");
219 if (account_data->sync_status & SYNC_STATUS_SYNCING) {
221 elm_object_disabled_set(p->r_button, TRUE);
224 elm_object_disabled_set(p->r_button, FALSE);
226 elm_genlist_item_update(p->gl_account_item);
232 static int _destroy(struct viewdata *vd)
237 debug_log("vd is NULL");
241 struct priv_data *p = vd->priv;
244 debug_log("priv is NULL");
248 evas_object_del(p->l_button);
249 evas_object_del(p->onoff);
250 evas_object_del(p->genlist);
251 evas_object_del(p->sync_radio_grp);
254 email_engine_free_account_list(&account_data, 1);
258 _close_icu_formatter();
263 static int _show(struct viewdata *vd)
268 debug_log("vd is NULL");
272 EmailSettingUGD *ugd = vd->ugd;
275 email_engine_free_account_list(&account_data, 1);
279 if (!setting_get_acct_full_data(ugd->account_id, &account_data)) {
280 debug_log("setting_get_acct_full_data failed");
286 static int _hide(struct viewdata *vd)
291 debug_log("vd is NULL");
295 evas_object_hide(vd->ly);
300 static void _push_naviframe(struct viewdata *vd)
303 struct priv_data *p = vd->priv;
305 p->cbar = elm_toolbar_add(vd->ugd->navi_bar);
306 elm_toolbar_shrink_mode_set(p->cbar, ELM_TOOLBAR_SHRINK_EXPAND);
307 elm_object_style_set(p->cbar, "naviframe");
308 evas_object_show(p->cbar);
310 p->c_item[0] = elm_toolbar_item_append(p->cbar, NULL,
311 dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, vd);
312 elm_object_item_disabled_set(elm_toolbar_item_append(p->cbar, NULL, "", NULL, NULL), EINA_TRUE);
313 elm_object_item_disabled_set(elm_toolbar_item_append(p->cbar, NULL, "", NULL, NULL), EINA_TRUE);
315 p->r_button = elm_button_add(vd->ugd->navi_bar);
316 elm_object_style_set(p->r_button, "naviframe/title/default");
317 /*elm_object_text_set(p->r_button, _("IDS_EMAIL_OPT_REFRESH"));*/
318 Evas_Object *ic = elm_icon_add(p->r_button);
319 elm_icon_file_set(ic, TITLE_ICON_REFRESH, NULL);
320 elm_icon_resizable_set(ic, EINA_TRUE, EINA_TRUE);
321 evas_object_image_smooth_scale_set(ic, 0);
322 elm_object_content_set(p->r_button, ic);
323 evas_object_smart_callback_add(p->r_button, "clicked", _refresh_cb, vd);
324 evas_object_show(p->r_button);
326 if (account_data->sync_status & SYNC_STATUS_SYNCING) {
328 elm_object_disabled_set(p->r_button, TRUE);
331 p->l_button = elm_button_add(vd->ugd->navi_bar);
332 evas_object_smart_callback_add(p->l_button, "clicked", _back_cb, vd);
333 elm_object_style_set(p->l_button, "naviframe/back_btn/default");
335 Elm_Object_Item *navi_it = NULL;
336 navi_it = elm_naviframe_item_push(vd->ugd->navi_bar, account_data->account_name, p->l_button, NULL, p->layout, NULL);
337 elm_object_item_part_content_set(navi_it, "title_right_btn", p->r_button);
338 elm_object_item_part_content_set(navi_it, "controlbar", p->cbar);
339 evas_object_show(vd->ugd->navi_bar);
342 static void _create_list(struct viewdata *vd)
347 debug_log("vd is NULL");
351 struct priv_data *p = vd->priv;
352 EmailSettingUGD *ugd = vd->ugd;
353 Elm_Object_Item *item = NULL;
354 Elm_Object_Item *git = NULL;
357 p->sync_radio_grp = elm_radio_add(ugd->navi_bar);
358 elm_radio_value_set(p->sync_radio_grp, 0);
359 evas_object_hide(p->sync_radio_grp);
361 p->genlist = elm_genlist_add(ugd->navi_bar);
362 elm_object_style_set(p->genlist, "dialogue");
364 p->itc_account.item_style = "dialogue/2text.3icon";
365 p->itc_account.func.text_get = _gl_account_text_get_cb;
366 p->itc_account.func.content_get = _gl_account_content_get_cb;
367 p->itc_account.func.state_get = NULL;
368 p->itc_account.func.del = NULL;
370 p->itc_onoff.item_style = "dialogue/2text.1icon.6";
371 p->itc_onoff.func.text_get = _gl_onoff_text_get_cb;
372 p->itc_onoff.func.content_get = _gl_onoff_content_get_cb;
373 p->itc_onoff.func.state_get = NULL;
374 p->itc_onoff.func.del = NULL;
376 p->itc_sync.item_style = "dialogue/2text.3/expandable";
377 p->itc_sync.func.text_get = _gl_sync_text_get_cb;
378 p->itc_sync.func.content_get = NULL;
379 p->itc_sync.func.state_get = NULL;
380 p->itc_sync.func.del = NULL;
382 p->itc_ex_sync.item_style = "dialogue/1text.1icon/expandable2";
383 p->itc_ex_sync.func.text_get = _gl_ex_sync_text_get_cb;
384 p->itc_ex_sync.func.content_get = _gl_ex_sync_content_get_cb;
385 p->itc_ex_sync.func.state_get = NULL;
386 p->itc_ex_sync.func.del = NULL;
388 p->itc_sep.item_style = "dialogue/separator";
389 p->itc_sep.func.text_get = NULL;
390 p->itc_sep.func.content_get = NULL;
391 p->itc_sep.func.state_get = NULL;
392 p->itc_sep.func.del = NULL;
394 p->itc_sep2.item_style = "dialogue/separator/end";
395 p->itc_sep2.func.text_get = NULL;
396 p->itc_sep2.func.content_get = NULL;
397 p->itc_sep2.func.state_get = NULL;
398 p->itc_sep2.func.del = NULL;
401 git = elm_genlist_item_append(p->genlist, &(p->itc_sep), NULL, NULL,
402 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
403 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
406 item = elm_genlist_item_append(p->genlist, &(p->itc_account), NULL, git,
407 ELM_GENLIST_ITEM_NONE, _account_edit_cb, (void *)vd);
408 p->gl_account_item = item;
411 item = elm_genlist_item_append(p->genlist, &(p->itc_sync), NULL,
412 git, ELM_GENLIST_ITEM_TREE, _gl_ex_sel_cb, (void *)vd);
413 p->gl_sync_item = item;
416 git = elm_genlist_item_append(p->genlist, &(p->itc_sep), NULL, NULL,
417 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
418 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
421 item = elm_genlist_item_append(p->genlist, &(p->itc_onoff), (void *)i,
422 git, ELM_GENLIST_ITEM_NONE, _gl_sel_cb, (void *)i);
423 p->gl_onoff_item = item;
426 git = elm_genlist_item_append(p->genlist, &(p->itc_sep2), NULL, NULL,
427 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
428 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
430 evas_object_smart_callback_add(p->genlist, "expanded", _gl_exp_cb, (void *)vd);
431 evas_object_smart_callback_add(p->genlist, "contracted", _gl_con_cb, (void *)vd);
433 elm_object_content_set(p->conform, p->genlist);
436 static void _update_account_info(struct viewdata *vd)
439 struct priv_data *p = NULL;
442 debug_log("vd is NULL");
447 debug_log("priv is NULL");
453 if (account_data == NULL) {
454 debug_log("account_data is NULL");
458 if (email_engine_update_account(account_data->account_id, account_data) == TRUE)
459 debug_log("Account updated successfully");
462 static void _get_icu_formatter(void)
465 UErrorCode status = U_ZERO_ERROR;
466 char *icu_locale = NULL;
468 uloc_setDefault(getenv("LC_TIME"), &status);
469 if (U_FAILURE(status)) {
470 debug_critical("uloc_setDefault() failed: %s\n", u_errorName(status));
474 icu_locale = (char *)uloc_getDefault();
475 debug_log("uloc_getDefault: %s", icu_locale);
476 appcore_get_timeformat(&icu_timeformat);
478 status = U_ZERO_ERROR;
479 icu_pg = udatpg_open(icu_locale, &status);
481 debug_log("udatpg_open() failed: %s", u_errorName(status));
485 char *skeleton = NULL;
486 if (icu_timeformat == APPCORE_TIME_FORMAT_12) {
487 skeleton = "EEEMMMddhmma";
489 skeleton = "EEEMMMddHmm";
492 UChar bestPattern[64] = { 0, };
493 UChar customSkeleton[64] = { 0, };
494 int32_t bestPatternCapacity;
495 int32_t bestPatternLength;
496 int skeletonLength = strlen(skeleton);
498 u_uastrncpy(customSkeleton, skeleton, skeletonLength);
500 status = U_ZERO_ERROR;
501 bestPatternCapacity = (int32_t) (sizeof(bestPattern) / sizeof(bestPattern[0]));
502 bestPatternLength = udatpg_getBestPattern(icu_pg, customSkeleton, u_strlen(customSkeleton), bestPattern, bestPatternCapacity, &status);
504 status = U_ZERO_ERROR;
505 icu_formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, icu_locale, NULL, -1, bestPattern, -1, &status);
508 static void _close_icu_formatter(void)
513 udatpg_close(icu_pg);
518 udat_close(icu_formatter);
519 icu_formatter = NULL;
523 static void _get_date_text_with_formatter(time_t time, char *formatted_str)
526 UErrorCode status = U_ZERO_ERROR;
528 UChar formatted[64] = { 0, };
529 int32_t formattedCapacity;
530 int32_t formattedLength;
532 formattedCapacity = (int32_t) (sizeof(formatted) / sizeof(formatted[0]));
533 time_t msg_time = time;
534 date = (UDate)msg_time * 1000;
536 formattedLength = udat_format(icu_formatter, date, formatted, formattedCapacity, NULL, &status);
537 u_austrncpy(formatted_str, formatted, 127);
538 debug_log("time_t: %d", time);
539 debug_log("formatted time: %s", formatted_str);
542 static void _account_edit_cb(void *data, Evas_Object *obj, void *event_info)
545 struct viewdata *vd = (struct viewdata *)data;
546 EmailSettingUGD *ugd = vd->ugd;
548 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
549 elm_genlist_item_selected_set(item, EINA_FALSE);
551 Viewtype top = ugd->view_st[ugd->view_top];
552 if (top != VIEW_SYNC_SCHEDULE) {
553 debug_log("**double clicked**");
557 debug_log("Selected account id:%d", account_data->account_id);
558 vd->ugd->account_id = account_data->account_id;
559 vd->ugd->myaccount_id = account_data->account_svc_id;
561 setting_change_view(VIEW_ACCOUNT_EDIT, ugd);
564 static void _onoff_cb(void *data, Evas_Object *obj, void *event_info)
568 struct viewdata *vd = (struct viewdata *)data;
569 struct priv_data *p = vd->priv;
571 Eina_Bool state = elm_check_state_get(obj);
574 account_data->check_interval = abs(account_data->check_interval);
575 account_data->sync_disabled = 0;
577 if (p->gl_sync_item) {
578 elm_genlist_item_update(p->gl_sync_item);
579 elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE);
582 account_data->check_interval = -(abs(account_data->check_interval));
583 account_data->sync_disabled = 1;
585 if (p->gl_sync_item) {
586 if (elm_genlist_item_expanded_get(p->gl_sync_item)) {
587 elm_genlist_item_expanded_set(p->gl_sync_item, 0);
589 elm_genlist_item_update(p->gl_sync_item);
590 elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE);
594 _update_account_info(vd);
597 static void _refresh_cb(void *data, Evas_Object *obj, void *event_info)
600 struct viewdata *vd = (struct viewdata *)data;
602 debug_log("vd is NULL");
606 struct priv_data *p = vd->priv;
608 int account_id = account_data->account_id;
612 gboolean res = FALSE;
613 email_mailbox_t *mailbox = NULL;
614 ret = email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox);
615 if (ret != EMAIL_ERROR_NONE || mailbox == NULL || mailbox->mailbox_name == NULL) {
616 debug_log("email_get_mailbox_by_mailbox_type failed");
620 res = email_engine_sync_folder(account_id, mailbox->mailbox_id, &handle);
621 debug_log("handle: %d", handle);
622 email_free_mailbox(&mailbox, 1);
625 elm_object_disabled_set(p->r_button, TRUE);
626 elm_genlist_item_update(p->gl_sync_item);
627 elm_genlist_item_update(p->gl_onoff_item);
630 static void _delete_cb(void *data, Evas_Object *obj, void *event_info)
633 struct viewdata *vd = (struct viewdata *)data;
636 debug_log("vd is NULL");
640 struct priv_data *p = vd->priv;
641 EmailSettingUGD *ugd = vd->ugd;
643 if (ugd->popup_one) {
644 evas_object_del(ugd->popup_one);
645 ugd->popup_one = NULL;
648 if (ugd->popup_validate) {
649 evas_object_del(ugd->popup_validate);
650 ugd->popup_validate = NULL;
653 vd->ugd->account_id = account_data->account_id;
655 elm_object_disabled_set(p->l_button, EINA_TRUE);
656 elm_object_item_disabled_set(p->c_item[0], EINA_TRUE);
658 ugd->popup_one = setting_get_notify(vd, NULL, N_("All data related to this account will be deleted. Continue?"), 2,
659 dgettext("sys_string", "IDS_COM_SK_YES"),
661 dgettext("sys_string", "IDS_COM_SK_NO"),
665 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
669 struct viewdata *vd = data;
670 /*struct priv_data *p = vd->priv;*/
672 setting_back_to_prev_view(vd);
675 static Eina_Bool _after_delete_cb(void *data)
679 struct viewdata *vd = (struct viewdata *)data;
682 debug_log("vd is NULL");
686 struct priv_data *p = vd->priv;
687 EmailSettingUGD *ugd = vd->ugd;
689 if (ugd->del_timer) {
690 ecore_timer_del(ugd->del_timer);
691 ugd->del_timer = NULL;
694 status_message_post(dgettext("sys_string", "IDS_COM_POP_DELETED"));
696 if (vd->ugd->start_view_type != NULL && g_strcmp0(vd->ugd->start_view_type, "account-edit") == 0) {
697 ug_destroy_me(vd->ugd->ug);
699 if (p->account_deleted) {
700 setting_update_acct_list(vd);
701 setting_back_to_prev_nth_view(vd, 2, vd->ugd->navi_main_it);
703 setting_back_to_prev_view(vd);
706 setting_get_small_notify(vd, dgettext("sys_string", "IDS_COM_POP_DELETED"));
712 static void _popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
717 debug_log("data is NULL");
721 struct viewdata *vd = (struct viewdata *)data;
722 struct priv_data *p = vd->priv;
723 EmailSettingUGD *ugd = vd->ugd;
725 if (ugd->popup_one) {
726 evas_object_del(ugd->popup_one);
727 ugd->popup_one = NULL;
729 if (ugd->popup_validate) {
730 evas_object_del(ugd->popup_validate);
731 ugd->popup_validate = NULL;
734 elm_object_disabled_set(p->l_button, EINA_FALSE);
735 elm_object_item_disabled_set(p->c_item[0], EINA_FALSE);
738 static void _popup_delete_ok_cb(void *data, Evas_Object *obj, void *event_info)
743 debug_log("data is NULL");
747 struct viewdata *vd = (struct viewdata *)data;
748 struct priv_data *p = vd->priv;
749 EmailSettingUGD *ugd = vd->ugd;
751 if (ugd->popup_one) {
752 evas_object_del(ugd->popup_one);
753 ugd->popup_one = NULL;
755 if (ugd->popup_validate) {
756 evas_object_del(ugd->popup_validate);
757 ugd->popup_validate = NULL;
760 int account_id = vd->ugd->account_id;
761 int ret = email_engine_delete_account(account_id);
764 p->account_deleted = TRUE;
765 ugd->del_timer = ecore_timer_add(0.5, _after_delete_cb, vd);
766 debug_log("delete success");
768 ugd->popup_one = setting_get_notify(vd, dgettext("sys_string", "IDS_COM_POP_WARNING"),
769 dgettext("sys_string", "IDS_COM_POP_UNABLE_TO_DELETE"), 1,
770 dgettext("sys_string", "IDS_COM_SK_OK"),
771 _popup_cancel_cb, NULL, NULL);
772 debug_log("delete failed");
776 static char *_gl_account_text_get_cb(void *data, Evas_Object *obj, const char *part)
781 debug_log("account_data is NULL");
785 if (!g_strcmp0(part, "elm.text.1")) {
786 return g_strdup(account_data->account_name);
789 if (!g_strcmp0(part, "elm.text.2")) {
790 return g_strdup(account_data->user_email_address);
796 static char *_gl_onoff_text_get_cb(void *data, Evas_Object *obj, const char *part)
800 if (!g_strcmp0(part, "elm.text.1")) {
801 char buf[MAX_STR_LEN] = { 0, };
803 snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_EMAIL_SYNC"));
804 return g_strdup(buf);
805 } else if (!g_strcmp0(part, "elm.text.2")) {
806 char buf[MAX_STR_LEN] = { 0, };
807 email_mailbox_t *mailbox = NULL;
808 email_get_mailbox_by_mailbox_type(account_data->account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox);
810 time_t req_time = time(NULL);//mailbox->last_sync_time;
811 _get_date_text_with_formatter(req_time, buf);
812 email_free_mailbox(&mailbox, 1);
815 return g_strdup(buf);
821 static char *_gl_sync_text_get_cb(void *data, Evas_Object *obj, const char *part)
826 debug_log("account_data is NULL");
830 if (!g_strcmp0(part, "elm.text.1")) {
831 char buf[MAX_STR_LEN] = { 0, };
832 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_SYNC_SCHEDULE"));
833 return g_strdup(buf);
836 if (!g_strcmp0(part, "elm.text.2")) {
837 char buf[MAX_STR_LEN] = { 0, };
839 /*int period = abs(account_data->check_interval);*/
840 int period = account_data->check_interval;
842 if (period <= sync_schedule[0]) {
843 snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_MANUAL"));
844 } else if (period == sync_schedule[1]) {
845 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_EVERY_30_MINUTES"));
846 } else if (period == sync_schedule[2]) {
847 snprintf(buf, sizeof(buf), "%s", N_("Every 1 hour"));
848 } else if (period == sync_schedule[3]) {
849 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 3);
850 } else if (period == sync_schedule[4]) {
851 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 6);
852 } else if (period == sync_schedule[5]) {
853 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 12);
854 } else if (period == sync_schedule[6]) {
855 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_ONCE_A_DAY"));
857 return g_strdup(buf);
863 static char *_gl_ex_sync_text_get_cb(void *data, Evas_Object *obj, const char *part)
866 int index = (int)data;
868 if (!g_strcmp0(part, "elm.text")) {
869 char buf[MAX_STR_LEN] = { 0, };
872 snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_MANUAL"));
873 } else if (index == 1) {
874 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_EVERY_30_MINUTES"));
875 } else if (index == 2) {
876 snprintf(buf, sizeof(buf), "%s", N_("Every 1 hour"));
877 } else if (index == 3) {
878 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 3);
879 } else if (index == 4) {
880 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 6);
881 } else if (index == 5) {
882 snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 12);
883 } else if (index == 6) {
884 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_ONCE_A_DAY"));
887 return g_strdup(buf);
893 static Evas_Object *_gl_account_content_get_cb(void *data, Evas_Object *obj, const char *part)
898 debug_log("account_data is NULL");
902 struct viewdata *vd = g_vd;
903 EmailSettingUGD *ugd = vd->ugd;
904 struct priv_data *p = vd->priv;
905 Evas_Object *color_bar = NULL;
907 if (!g_strcmp0(part, "elm.icon.1")) {
908 Evas_Object *icon = elm_icon_add(ugd->navi_bar);
909 account_user_data_t *user_data = (account_user_data_t *)account_data->user_data;
911 debug_log("is_preset_account:%d", user_data->is_preset_account);
913 switch (user_data->is_preset_account) {
915 elm_icon_file_set(icon, ACCOUNT_ICON_GMAIL, NULL);
918 elm_icon_file_set(icon, ACCOUNT_ICON_HOTMAIL, NULL);
921 elm_icon_file_set(icon, ACCOUNT_ICON_YAHOO, NULL);
924 elm_icon_file_set(icon, ACCOUNT_ICON_AOL, NULL);
928 elm_icon_file_set(icon, ACCOUNT_ICON_OTHERS, NULL);
932 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
933 p->account_icon = icon;
937 if (!g_strcmp0(part, "elm.icon.2")) {
939 Evas_Object *pb = elm_progressbar_add(ugd->navi_bar);
940 elm_object_style_set(pb, "list_process_small");
941 elm_progressbar_horizontal_set(pb, EINA_TRUE);
942 elm_progressbar_pulse(pb, EINA_TRUE);
947 if (!g_strcmp0(part, "elm.swallow.colorbar")) {
948 account_user_data_t *user_data = (account_user_data_t *)account_data->user_data;
949 unsigned int val = user_data->index_color;
950 int r = (val & 0xff000000) >> 24;
951 int g = (val & 0x00ff0000) >> 16;
952 int b = (val & 0x0000ff00) >> 8;
953 int a = val & 0x000000ff;
955 debug_log("R[%d] G[%d] B[%d] A[%d]", r, g, b, a);
957 color_bar = evas_object_rectangle_add(evas_object_evas_get(obj));
958 evas_object_size_hint_fill_set(color_bar, EVAS_HINT_FILL, EVAS_HINT_FILL);
959 evas_object_color_set(color_bar, r, g, b, a);
967 static Evas_Object *_gl_onoff_content_get_cb(void *data, Evas_Object *obj, const char *part)
972 debug_log("account_data is NULL");
976 struct viewdata *vd = g_vd;
977 EmailSettingUGD *ugd = vd->ugd;
978 struct priv_data *p = vd->priv;
980 if (!g_strcmp0(part, "elm.icon")) {
981 Evas_Object *check = elm_check_add(ugd->navi_bar);
982 elm_object_style_set(check, "on&off");
983 evas_object_smart_callback_add(check, "changed", _onoff_cb, vd);
984 evas_object_propagate_events_set(check, EINA_FALSE);
986 if (account_data->sync_disabled) {
987 elm_check_state_set(check, EINA_FALSE);
988 elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE);
990 elm_check_state_set(check, EINA_TRUE);
991 elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE);
1002 static Evas_Object *_gl_ex_sync_content_get_cb(void *data, Evas_Object *obj, const char *part)
1006 if (!account_data) {
1007 debug_log("account_data is NULL");
1011 int index = (int)data;
1012 struct viewdata *vd = g_vd;
1013 EmailSettingUGD *ugd = vd->ugd;
1014 struct priv_data *p = vd->priv;
1016 if (!g_strcmp0(part, "elm.icon")) {
1017 Evas_Object *radio = elm_radio_add(ugd->navi_bar);
1018 elm_radio_group_add(radio, p->sync_radio_grp);
1019 elm_radio_state_value_set(radio, index);
1021 if (sync_schedule[index] == abs(account_data->check_interval)) {
1022 elm_radio_value_set(p->sync_radio_grp, index);
1030 static void _gl_sel_cb(void *data, Evas_Object *obj, void *event_info)
1034 if (!account_data) {
1035 debug_log("account_data is NULL");
1039 struct viewdata *vd = g_vd;
1040 struct priv_data *p = vd->priv;
1042 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1043 elm_genlist_item_selected_set(item, EINA_FALSE);
1045 Eina_Bool state = elm_check_state_get(p->onoff);
1048 account_data->check_interval = -(abs(account_data->check_interval));
1049 account_data->sync_disabled = 1;
1050 elm_check_state_set(p->onoff, EINA_FALSE);
1052 if (p->gl_sync_item) {
1053 if (elm_genlist_item_expanded_get(p->gl_sync_item)) {
1054 elm_genlist_item_expanded_set(p->gl_sync_item, 0);
1056 elm_genlist_item_update(p->gl_sync_item);
1057 elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE);
1060 account_data->check_interval = abs(account_data->check_interval);
1061 account_data->sync_disabled = 0;
1062 elm_check_state_set(p->onoff, EINA_TRUE);
1064 if (p->gl_sync_item) {
1065 elm_genlist_item_update(p->gl_sync_item);
1066 elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE);
1070 _update_account_info(vd);
1073 static void _gl_ex_sel_cb(void *data, Evas_Object *obj, void *event_info)
1077 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1078 elm_genlist_item_selected_set(item, EINA_FALSE);
1080 if (!elm_genlist_item_expanded_get(item)) {
1081 elm_genlist_item_expanded_set(item, 1);
1083 elm_genlist_item_expanded_set(item, 0);
1087 static void _gl_ex_sync_sel_cb(void *data, Evas_Object *obj, void *event_info)
1091 if (!account_data) {
1092 debug_log("account_data is NULL");
1096 int index = (int)data;
1097 struct viewdata *vd = g_vd;
1098 struct priv_data *p = vd->priv;
1101 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1102 elm_genlist_item_selected_set(item, EINA_FALSE);
1104 sel_radio = elm_radio_value_get(p->sync_radio_grp);
1106 if (sel_radio == index)
1109 if (index >= 0 && index < 7)
1110 account_data->check_interval = sync_schedule[index];
1112 elm_radio_value_set(p->sync_radio_grp, index);
1114 _update_account_info(vd);
1116 elm_genlist_item_update(p->gl_sync_item);
1119 static void _gl_exp_cb(void *data, Evas_Object *obj, void *event_info)
1122 Elm_Object_Item *it = event_info;
1124 struct viewdata *vd = (struct viewdata *)data;
1125 struct priv_data *p = vd->priv;
1129 for (i = 0; i < 7; i++) {
1130 elm_genlist_item_append(p->genlist, &(p->itc_ex_sync), (void *)i,
1131 it, ELM_GENLIST_ITEM_NONE, _gl_ex_sync_sel_cb, (void *)i);
1135 static void _gl_con_cb(void *data, Evas_Object *obj, void *event_info)
1138 Elm_Object_Item *item = event_info;
1139 elm_genlist_item_subitems_clear(item);