/* * Copyright 2012 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.tizenopensource.org/license * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "email-setting.h" #include "email-setting-utils.h" #include #include #include #include #include static email_account_t *account_data = NULL; static struct viewdata *g_vd = NULL; static UDateTimePatternGenerator *icu_pg = NULL; static UDateFormat *icu_formatter = NULL; static enum appcore_time_format icu_timeformat; static int _create(struct viewdata *vd); static int _update(struct viewdata *vd); static int _destroy(struct viewdata *vd); static int _show(struct viewdata *vd); static int _hide(struct viewdata *vd); static void _push_naviframe(struct viewdata *vd); static void _create_list(struct viewdata *vd); static void _update_account_info(struct viewdata *vd); static void _get_icu_formatter(void); static void _close_icu_formatter(void); static void _get_date_text_with_formatter(time_t time, char *formatted_str); static void _account_edit_cb(void *data, Evas_Object *obj, void *event_info); static void _onoff_cb(void *data, Evas_Object *obj, void *event_info); static void _refresh_cb(void *data, Evas_Object *obj, void *event_info); static void _delete_cb(void *data, Evas_Object *obj, void *event_info); static void _back_cb(void *data, Evas_Object *obj, void *event_info); static Eina_Bool _after_delete_cb(void *data); static void _popup_cancel_cb(void *data, Evas_Object *obj, void *event_info); static void _popup_delete_ok_cb(void *data, Evas_Object *obj, void *event_info); static char *_gl_account_text_get_cb(void *data, Evas_Object *obj, const char *part); static char *_gl_onoff_text_get_cb(void *data, Evas_Object *obj, const char *part); static char *_gl_sync_text_get_cb(void *data, Evas_Object *obj, const char *part); static char *_gl_ex_sync_text_get_cb(void *data, Evas_Object *obj, const char *part); static Evas_Object *_gl_account_content_get_cb(void *data, Evas_Object *obj, const char *part); static Evas_Object *_gl_onoff_content_get_cb(void *data, Evas_Object *obj, const char *part); static Evas_Object *_gl_ex_sync_content_get_cb(void *data, Evas_Object *obj, const char *part); static void _gl_sel_cb(void *data, Evas_Object *obj, void *event_info); static void _gl_ex_sel_cb(void *data, Evas_Object *obj, void *event_info); static void _gl_ex_sync_sel_cb(void *data, Evas_Object *obj, void *event_info); static void _gl_exp_cb(void *data, Evas_Object *obj, void *event_info); static void _gl_con_cb(void *data, Evas_Object *obj, void *event_info); static int sync_schedule[7] = { 0, 30, 60, 180, 360, 720, 1440 }; #define SYNC_STATUS_FINISHED 0 /* BIN 00000000 */ #define SYNC_STATUS_SYNCING 1 /* BIN 00000001 */ #define SYNC_STATUS_HAVE_NEW_MAILS 2 /* BIN 00000010 */ struct priv_data { struct viewdata *vd; Evas_Object *cbar; Evas_Object *onoff; Evas_Object *l_button; Evas_Object *r_button; Evas_Object *layout; Evas_Object *conform; Evas_Object *sync_radio_grp; Evas_Object *account_icon; Evas_Object *genlist; Elm_Genlist_Item_Class itc_account; Elm_Genlist_Item_Class itc_onoff; Elm_Genlist_Item_Class itc_sync; Elm_Genlist_Item_Class itc_ex_sync; Elm_Genlist_Item_Class itc_sep; Elm_Genlist_Item_Class itc_sep2; Elm_Object_Item * c_item[4]; Elm_Object_Item *gl_sync_item; Elm_Object_Item *gl_onoff_item; Elm_Object_Item *gl_account_item; int account_deleted; int syncing; }; void setting_init_sync_schedule_view(struct viewdata *vd) { debug_log(""); vd->type = VIEW_SYNC_SCHEDULE; vd->create = _create; vd->update = _update; vd->destroy = _destroy; vd->show = _show; vd->hide = _hide; vd->grp_nm = "setting_sync_schedule"; } void setting_schedule_sync_started(struct viewdata *vd, int account_id) { debug_log(""); struct priv_data *p = NULL; EmailSettingUGD *ugd = vd->ugd; p = vd->priv; if (ugd->account_id != account_id) { debug_log("not interested"); return; } if (!setting_get_acct_full_data(ugd->account_id, &account_data)) { debug_log("failed to get account data"); } p->syncing = 1; elm_object_disabled_set(p->r_button, TRUE); elm_genlist_item_update(p->gl_account_item); } void setting_schedule_sync_finished(struct viewdata *vd, int account_id) { debug_log(""); struct priv_data *p = NULL; EmailSettingUGD *ugd = vd->ugd; p = vd->priv; if (ugd->account_id != account_id) { debug_log("not interested"); return; } if (!setting_get_acct_full_data(ugd->account_id, &account_data)) { debug_log("failed to get account data"); } p->syncing = 0; elm_object_disabled_set(p->r_button, FALSE); elm_genlist_item_update(p->gl_account_item); } static int _create(struct viewdata *vd) { debug_log(""); if (!vd) { debug_log("vd is NULL"); return FALSE; } struct priv_data *p = NULL; EmailSettingUGD *ugd = vd->ugd; p = vd->priv; if (p == NULL) { p = vd->priv = calloc(1, sizeof(struct priv_data)); p->vd = vd; if (!setting_get_acct_full_data(ugd->account_id, &account_data)) { debug_log("failed to get account data"); } p->layout = setting_add_inner_layout(vd); _push_naviframe(vd); elm_win_conformant_set(ugd->win, 1); p->conform = elm_conformant_add(ugd->win); elm_object_style_set(p->conform, "internal_layout"); evas_object_show(p->conform); elm_object_part_content_set(p->layout, "elm.swallow.content", p->conform); } _get_icu_formatter(); g_vd = vd; _create_list(vd); return TRUE; } static int _update(struct viewdata *vd) { debug_log(""); if (!vd) { debug_log("vd is NULL"); return FALSE; } struct priv_data *p = NULL; EmailSettingUGD *ugd = vd->ugd; p = vd->priv; if (vd->refresh) { if (!setting_get_acct_full_data(ugd->account_id, &account_data)) { debug_log("failed to get account data"); } if (account_data->sync_status & SYNC_STATUS_SYNCING) { p->syncing = 1; elm_object_disabled_set(p->r_button, TRUE); } else { p->syncing = 0; elm_object_disabled_set(p->r_button, FALSE); } elm_genlist_item_update(p->gl_account_item); } return TRUE; } static int _destroy(struct viewdata *vd) { debug_log(""); if (!vd) { debug_log("vd is NULL"); return FALSE; } struct priv_data *p = vd->priv; if (p == NULL) { debug_log("priv is NULL"); return FALSE; } evas_object_del(p->l_button); evas_object_del(p->onoff); evas_object_del(p->genlist); evas_object_del(p->sync_radio_grp); if (account_data) { email_engine_free_account_list(&account_data, 1); account_data = NULL; } _close_icu_formatter(); return TRUE; } static int _show(struct viewdata *vd) { debug_log(""); if (!vd) { debug_log("vd is NULL"); return FALSE; } EmailSettingUGD *ugd = vd->ugd; if (account_data) { email_engine_free_account_list(&account_data, 1); account_data = NULL; } if (!setting_get_acct_full_data(ugd->account_id, &account_data)) { debug_log("setting_get_acct_full_data failed"); } return TRUE; } static int _hide(struct viewdata *vd) { debug_log(""); if (!vd) { debug_log("vd is NULL"); return FALSE; } evas_object_hide(vd->ly); return TRUE; } static void _push_naviframe(struct viewdata *vd) { debug_log(""); struct priv_data *p = vd->priv; p->cbar = elm_toolbar_add(vd->ugd->navi_bar); elm_toolbar_shrink_mode_set(p->cbar, ELM_TOOLBAR_SHRINK_EXPAND); elm_object_style_set(p->cbar, "naviframe"); evas_object_show(p->cbar); p->c_item[0] = elm_toolbar_item_append(p->cbar, NULL, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, vd); elm_object_item_disabled_set(elm_toolbar_item_append(p->cbar, NULL, "", NULL, NULL), EINA_TRUE); elm_object_item_disabled_set(elm_toolbar_item_append(p->cbar, NULL, "", NULL, NULL), EINA_TRUE); p->r_button = elm_button_add(vd->ugd->navi_bar); elm_object_style_set(p->r_button, "naviframe/title/default"); /*elm_object_text_set(p->r_button, _("IDS_EMAIL_OPT_REFRESH"));*/ Evas_Object *ic = elm_icon_add(p->r_button); elm_icon_file_set(ic, TITLE_ICON_REFRESH, NULL); elm_icon_resizable_set(ic, EINA_TRUE, EINA_TRUE); evas_object_image_smooth_scale_set(ic, 0); elm_object_content_set(p->r_button, ic); evas_object_smart_callback_add(p->r_button, "clicked", _refresh_cb, vd); evas_object_show(p->r_button); if (account_data->sync_status & SYNC_STATUS_SYNCING) { p->syncing = 1; elm_object_disabled_set(p->r_button, TRUE); } p->l_button = elm_button_add(vd->ugd->navi_bar); evas_object_smart_callback_add(p->l_button, "clicked", _back_cb, vd); elm_object_style_set(p->l_button, "naviframe/back_btn/default"); Elm_Object_Item *navi_it = NULL; navi_it = elm_naviframe_item_push(vd->ugd->navi_bar, account_data->account_name, p->l_button, NULL, p->layout, NULL); elm_object_item_part_content_set(navi_it, "title_right_btn", p->r_button); elm_object_item_part_content_set(navi_it, "controlbar", p->cbar); evas_object_show(vd->ugd->navi_bar); } static void _create_list(struct viewdata *vd) { debug_log(""); if (!vd) { debug_log("vd is NULL"); return; } struct priv_data *p = vd->priv; EmailSettingUGD *ugd = vd->ugd; Elm_Object_Item *item = NULL; Elm_Object_Item *git = NULL; int i = 0; p->sync_radio_grp = elm_radio_add(ugd->navi_bar); elm_radio_value_set(p->sync_radio_grp, 0); evas_object_hide(p->sync_radio_grp); p->genlist = elm_genlist_add(ugd->navi_bar); elm_object_style_set(p->genlist, "dialogue"); p->itc_account.item_style = "dialogue/2text.3icon"; p->itc_account.func.text_get = _gl_account_text_get_cb; p->itc_account.func.content_get = _gl_account_content_get_cb; p->itc_account.func.state_get = NULL; p->itc_account.func.del = NULL; p->itc_onoff.item_style = "dialogue/2text.1icon.6"; p->itc_onoff.func.text_get = _gl_onoff_text_get_cb; p->itc_onoff.func.content_get = _gl_onoff_content_get_cb; p->itc_onoff.func.state_get = NULL; p->itc_onoff.func.del = NULL; p->itc_sync.item_style = "dialogue/2text.3/expandable"; p->itc_sync.func.text_get = _gl_sync_text_get_cb; p->itc_sync.func.content_get = NULL; p->itc_sync.func.state_get = NULL; p->itc_sync.func.del = NULL; p->itc_ex_sync.item_style = "dialogue/1text.1icon/expandable2"; p->itc_ex_sync.func.text_get = _gl_ex_sync_text_get_cb; p->itc_ex_sync.func.content_get = _gl_ex_sync_content_get_cb; p->itc_ex_sync.func.state_get = NULL; p->itc_ex_sync.func.del = NULL; p->itc_sep.item_style = "dialogue/separator"; p->itc_sep.func.text_get = NULL; p->itc_sep.func.content_get = NULL; p->itc_sep.func.state_get = NULL; p->itc_sep.func.del = NULL; p->itc_sep2.item_style = "dialogue/separator/end"; p->itc_sep2.func.text_get = NULL; p->itc_sep2.func.content_get = NULL; p->itc_sep2.func.state_get = NULL; p->itc_sep2.func.del = NULL; /*seperator*/ git = elm_genlist_item_append(p->genlist, &(p->itc_sep), NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); /*account*/ item = elm_genlist_item_append(p->genlist, &(p->itc_account), NULL, git, ELM_GENLIST_ITEM_NONE, _account_edit_cb, (void *)vd); p->gl_account_item = item; /*sync schedule*/ item = elm_genlist_item_append(p->genlist, &(p->itc_sync), NULL, git, ELM_GENLIST_ITEM_TREE, _gl_ex_sel_cb, (void *)vd); p->gl_sync_item = item; /*seperator*/ git = elm_genlist_item_append(p->genlist, &(p->itc_sep), NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); /*sync on/off*/ item = elm_genlist_item_append(p->genlist, &(p->itc_onoff), (void *)i, git, ELM_GENLIST_ITEM_NONE, _gl_sel_cb, (void *)i); p->gl_onoff_item = item; /*seperator*/ git = elm_genlist_item_append(p->genlist, &(p->itc_sep2), NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL); elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); evas_object_smart_callback_add(p->genlist, "expanded", _gl_exp_cb, (void *)vd); evas_object_smart_callback_add(p->genlist, "contracted", _gl_con_cb, (void *)vd); elm_object_content_set(p->conform, p->genlist); } static void _update_account_info(struct viewdata *vd) { debug_log(""); struct priv_data *p = NULL; if (!vd) { debug_log("vd is NULL"); return; } if (!vd->priv) { debug_log("priv is NULL"); return; } p = vd->priv; if (account_data == NULL) { debug_log("account_data is NULL"); return; } if (email_engine_update_account(account_data->account_id, account_data) == TRUE) debug_log("Account updated successfully"); } static void _get_icu_formatter(void) { debug_log(""); UErrorCode status = U_ZERO_ERROR; char *icu_locale = NULL; uloc_setDefault(getenv("LC_TIME"), &status); if (U_FAILURE(status)) { debug_critical("uloc_setDefault() failed: %s\n", u_errorName(status)); return; } icu_locale = (char *)uloc_getDefault(); debug_log("uloc_getDefault: %s", icu_locale); appcore_get_timeformat(&icu_timeformat); status = U_ZERO_ERROR; icu_pg = udatpg_open(icu_locale, &status); if (!icu_pg) { debug_log("udatpg_open() failed: %s", u_errorName(status)); return; } char *skeleton = NULL; if (icu_timeformat == APPCORE_TIME_FORMAT_12) { skeleton = "EEEMMMddhmma"; } else { skeleton = "EEEMMMddHmm"; } UChar bestPattern[64] = { 0, }; UChar customSkeleton[64] = { 0, }; int32_t bestPatternCapacity; int32_t bestPatternLength; int skeletonLength = strlen(skeleton); u_uastrncpy(customSkeleton, skeleton, skeletonLength); status = U_ZERO_ERROR; bestPatternCapacity = (int32_t) (sizeof(bestPattern) / sizeof(bestPattern[0])); bestPatternLength = udatpg_getBestPattern(icu_pg, customSkeleton, u_strlen(customSkeleton), bestPattern, bestPatternCapacity, &status); status = U_ZERO_ERROR; icu_formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, icu_locale, NULL, -1, bestPattern, -1, &status); } static void _close_icu_formatter(void) { debug_log(""); if (icu_pg) { udatpg_close(icu_pg); icu_pg = NULL; } if (icu_formatter) { udat_close(icu_formatter); icu_formatter = NULL; } } static void _get_date_text_with_formatter(time_t time, char *formatted_str) { debug_log(""); UErrorCode status = U_ZERO_ERROR; UDate date = 0; UChar formatted[64] = { 0, }; int32_t formattedCapacity; int32_t formattedLength; formattedCapacity = (int32_t) (sizeof(formatted) / sizeof(formatted[0])); time_t msg_time = time; date = (UDate)msg_time * 1000; formattedLength = udat_format(icu_formatter, date, formatted, formattedCapacity, NULL, &status); u_austrncpy(formatted_str, formatted, 127); debug_log("time_t: %d", time); debug_log("formatted time: %s", formatted_str); } static void _account_edit_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); struct viewdata *vd = (struct viewdata *)data; EmailSettingUGD *ugd = vd->ugd; Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); Viewtype top = ugd->view_st[ugd->view_top]; if (top != VIEW_SYNC_SCHEDULE) { debug_log("**double clicked**"); return; } debug_log("Selected account id:%d", account_data->account_id); vd->ugd->account_id = account_data->account_id; vd->ugd->myaccount_id = account_data->account_svc_id; setting_change_view(VIEW_ACCOUNT_EDIT, ugd); } static void _onoff_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); struct viewdata *vd = (struct viewdata *)data; struct priv_data *p = vd->priv; Eina_Bool state = elm_check_state_get(obj); if (state) { account_data->check_interval = abs(account_data->check_interval); account_data->sync_disabled = 0; if (p->gl_sync_item) { elm_genlist_item_update(p->gl_sync_item); elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE); } } else { account_data->check_interval = -(abs(account_data->check_interval)); account_data->sync_disabled = 1; if (p->gl_sync_item) { if (elm_genlist_item_expanded_get(p->gl_sync_item)) { elm_genlist_item_expanded_set(p->gl_sync_item, 0); } elm_genlist_item_update(p->gl_sync_item); elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE); } } _update_account_info(vd); } static void _refresh_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); struct viewdata *vd = (struct viewdata *)data; if (vd == NULL) { debug_log("vd is NULL"); return; } struct priv_data *p = vd->priv; unsigned handle = 0; int account_id = account_data->account_id; /* Inbox sync */ int ret = 0; gboolean res = FALSE; email_mailbox_t *mailbox = NULL; ret = email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox); if (ret != EMAIL_ERROR_NONE || mailbox == NULL || mailbox->mailbox_name == NULL) { debug_log("email_get_mailbox_by_mailbox_type failed"); return; } res = email_engine_sync_folder(account_id, mailbox->mailbox_id, &handle); debug_log("handle: %d", handle); email_free_mailbox(&mailbox, 1); p->syncing = 1; elm_object_disabled_set(p->r_button, TRUE); elm_genlist_item_update(p->gl_sync_item); elm_genlist_item_update(p->gl_onoff_item); } static void _delete_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); struct viewdata *vd = (struct viewdata *)data; if (vd == NULL) { debug_log("vd is NULL"); return; } struct priv_data *p = vd->priv; EmailSettingUGD *ugd = vd->ugd; if (ugd->popup_one) { evas_object_del(ugd->popup_one); ugd->popup_one = NULL; } if (ugd->popup_validate) { evas_object_del(ugd->popup_validate); ugd->popup_validate = NULL; } vd->ugd->account_id = account_data->account_id; elm_object_disabled_set(p->l_button, EINA_TRUE); elm_object_item_disabled_set(p->c_item[0], EINA_TRUE); ugd->popup_one = setting_get_notify(vd, NULL, N_("All data related to this account will be deleted. Continue?"), 2, dgettext("sys_string", "IDS_COM_SK_YES"), _popup_delete_ok_cb, dgettext("sys_string", "IDS_COM_SK_NO"), _popup_cancel_cb); } static void _back_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); struct viewdata *vd = data; /*struct priv_data *p = vd->priv;*/ setting_back_to_prev_view(vd); } static Eina_Bool _after_delete_cb(void *data) { debug_log(""); struct viewdata *vd = (struct viewdata *)data; if (vd == NULL) { debug_log("vd is NULL"); return FALSE; } struct priv_data *p = vd->priv; EmailSettingUGD *ugd = vd->ugd; if (ugd->del_timer) { ecore_timer_del(ugd->del_timer); ugd->del_timer = NULL; } status_message_post(dgettext("sys_string", "IDS_COM_POP_DELETED")); if (vd->ugd->start_view_type != NULL && g_strcmp0(vd->ugd->start_view_type, "account-edit") == 0) { ug_destroy_me(vd->ugd->ug); } else { if (p->account_deleted) { setting_update_acct_list(vd); setting_back_to_prev_nth_view(vd, 2, vd->ugd->navi_main_it); } else { setting_back_to_prev_view(vd); } /*setting_get_small_notify(vd, dgettext("sys_string", "IDS_COM_POP_DELETED"));*/ } return TRUE; } static void _popup_cancel_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); if (!data) { debug_log("data is NULL"); return; } struct viewdata *vd = (struct viewdata *)data; struct priv_data *p = vd->priv; EmailSettingUGD *ugd = vd->ugd; if (ugd->popup_one) { evas_object_del(ugd->popup_one); ugd->popup_one = NULL; } if (ugd->popup_validate) { evas_object_del(ugd->popup_validate); ugd->popup_validate = NULL; } elm_object_disabled_set(p->l_button, EINA_FALSE); elm_object_item_disabled_set(p->c_item[0], EINA_FALSE); } static void _popup_delete_ok_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); if (!data) { debug_log("data is NULL"); return; } struct viewdata *vd = (struct viewdata *)data; struct priv_data *p = vd->priv; EmailSettingUGD *ugd = vd->ugd; if (ugd->popup_one) { evas_object_del(ugd->popup_one); ugd->popup_one = NULL; } if (ugd->popup_validate) { evas_object_del(ugd->popup_validate); ugd->popup_validate = NULL; } int account_id = vd->ugd->account_id; int ret = email_engine_delete_account(account_id); if (ret) { p->account_deleted = TRUE; ugd->del_timer = ecore_timer_add(0.5, _after_delete_cb, vd); debug_log("delete success"); } else { ugd->popup_one = setting_get_notify(vd, dgettext("sys_string", "IDS_COM_POP_WARNING"), dgettext("sys_string", "IDS_COM_POP_UNABLE_TO_DELETE"), 1, dgettext("sys_string", "IDS_COM_SK_OK"), _popup_cancel_cb, NULL, NULL); debug_log("delete failed"); } } static char *_gl_account_text_get_cb(void *data, Evas_Object *obj, const char *part) { debug_log(""); if (!account_data) { debug_log("account_data is NULL"); return NULL; } if (!g_strcmp0(part, "elm.text.1")) { return g_strdup(account_data->account_name); } if (!g_strcmp0(part, "elm.text.2")) { return g_strdup(account_data->user_email_address); } return NULL; } static char *_gl_onoff_text_get_cb(void *data, Evas_Object *obj, const char *part) { debug_log(""); if (!g_strcmp0(part, "elm.text.1")) { char buf[MAX_STR_LEN] = { 0, }; snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_EMAIL_SYNC")); return g_strdup(buf); } else if (!g_strcmp0(part, "elm.text.2")) { char buf[MAX_STR_LEN] = { 0, }; email_mailbox_t *mailbox = NULL; email_get_mailbox_by_mailbox_type(account_data->account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox); if (mailbox) { time_t req_time = time(NULL);//mailbox->last_sync_time; _get_date_text_with_formatter(req_time, buf); email_free_mailbox(&mailbox, 1); } return g_strdup(buf); } return NULL; } static char *_gl_sync_text_get_cb(void *data, Evas_Object *obj, const char *part) { debug_log(""); if (!account_data) { debug_log("account_data is NULL"); return NULL; } if (!g_strcmp0(part, "elm.text.1")) { char buf[MAX_STR_LEN] = { 0, }; snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_SYNC_SCHEDULE")); return g_strdup(buf); } if (!g_strcmp0(part, "elm.text.2")) { char buf[MAX_STR_LEN] = { 0, }; /*int period = abs(account_data->check_interval);*/ int period = account_data->check_interval; if (period <= sync_schedule[0]) { snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_MANUAL")); } else if (period == sync_schedule[1]) { snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_EVERY_30_MINUTES")); } else if (period == sync_schedule[2]) { snprintf(buf, sizeof(buf), "%s", N_("Every 1 hour")); } else if (period == sync_schedule[3]) { snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 3); } else if (period == sync_schedule[4]) { snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 6); } else if (period == sync_schedule[5]) { snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 12); } else if (period == sync_schedule[6]) { snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_ONCE_A_DAY")); } return g_strdup(buf); } return NULL; } static char *_gl_ex_sync_text_get_cb(void *data, Evas_Object *obj, const char *part) { debug_log(""); int index = (int)data; if (!g_strcmp0(part, "elm.text")) { char buf[MAX_STR_LEN] = { 0, }; if (index == 0) { snprintf(buf, sizeof(buf), "%s", dgettext("sys_string", "IDS_COM_BODY_MANUAL")); } else if (index == 1) { snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_EVERY_30_MINUTES")); } else if (index == 2) { snprintf(buf, sizeof(buf), "%s", N_("Every 1 hour")); } else if (index == 3) { snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 3); } else if (index == 4) { snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 6); } else if (index == 5) { snprintf(buf, sizeof(buf), _("IDS_EMAIL_BODY_EVERY_PD_HOURS"), 12); } else if (index == 6) { snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_BODY_ONCE_A_DAY")); } return g_strdup(buf); } return NULL; } static Evas_Object *_gl_account_content_get_cb(void *data, Evas_Object *obj, const char *part) { debug_log(""); if (!account_data) { debug_log("account_data is NULL"); return NULL; } struct viewdata *vd = g_vd; EmailSettingUGD *ugd = vd->ugd; struct priv_data *p = vd->priv; Evas_Object *color_bar = NULL; if (!g_strcmp0(part, "elm.icon.1")) { Evas_Object *icon = elm_icon_add(ugd->navi_bar); account_user_data_t *user_data = (account_user_data_t *)account_data->user_data; debug_log("is_preset_account:%d", user_data->is_preset_account); switch (user_data->is_preset_account) { case GMAIL: elm_icon_file_set(icon, ACCOUNT_ICON_GMAIL, NULL); break; case HOTMAIL: elm_icon_file_set(icon, ACCOUNT_ICON_HOTMAIL, NULL); break; case YAHOOMAIL: elm_icon_file_set(icon, ACCOUNT_ICON_YAHOO, NULL); break; case AOL: elm_icon_file_set(icon, ACCOUNT_ICON_AOL, NULL); break; case OTHERS: default: elm_icon_file_set(icon, ACCOUNT_ICON_OTHERS, NULL); break; } evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); p->account_icon = icon; return icon; } if (!g_strcmp0(part, "elm.icon.2")) { if (p->syncing) { Evas_Object *pb = elm_progressbar_add(ugd->navi_bar); elm_object_style_set(pb, "list_process_small"); elm_progressbar_horizontal_set(pb, EINA_TRUE); elm_progressbar_pulse(pb, EINA_TRUE); return pb; } } if (!g_strcmp0(part, "elm.swallow.colorbar")) { account_user_data_t *user_data = (account_user_data_t *)account_data->user_data; unsigned int val = user_data->index_color; int r = (val & 0xff000000) >> 24; int g = (val & 0x00ff0000) >> 16; int b = (val & 0x0000ff00) >> 8; int a = val & 0x000000ff; debug_log("R[%d] G[%d] B[%d] A[%d]", r, g, b, a); color_bar = evas_object_rectangle_add(evas_object_evas_get(obj)); evas_object_size_hint_fill_set(color_bar, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_color_set(color_bar, r, g, b, a); return color_bar; } return NULL; } static Evas_Object *_gl_onoff_content_get_cb(void *data, Evas_Object *obj, const char *part) { debug_log(""); if (!account_data) { debug_log("account_data is NULL"); return NULL; } struct viewdata *vd = g_vd; EmailSettingUGD *ugd = vd->ugd; struct priv_data *p = vd->priv; if (!g_strcmp0(part, "elm.icon")) { Evas_Object *check = elm_check_add(ugd->navi_bar); elm_object_style_set(check, "on&off"); evas_object_smart_callback_add(check, "changed", _onoff_cb, vd); evas_object_propagate_events_set(check, EINA_FALSE); if (account_data->sync_disabled) { elm_check_state_set(check, EINA_FALSE); elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE); } else { elm_check_state_set(check, EINA_TRUE); elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE); } p->onoff = check; return check; } return NULL; } static Evas_Object *_gl_ex_sync_content_get_cb(void *data, Evas_Object *obj, const char *part) { debug_log(""); if (!account_data) { debug_log("account_data is NULL"); return NULL; } int index = (int)data; struct viewdata *vd = g_vd; EmailSettingUGD *ugd = vd->ugd; struct priv_data *p = vd->priv; if (!g_strcmp0(part, "elm.icon")) { Evas_Object *radio = elm_radio_add(ugd->navi_bar); elm_radio_group_add(radio, p->sync_radio_grp); elm_radio_state_value_set(radio, index); if (sync_schedule[index] == abs(account_data->check_interval)) { elm_radio_value_set(p->sync_radio_grp, index); } return radio; } return NULL; } static void _gl_sel_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); if (!account_data) { debug_log("account_data is NULL"); return; } struct viewdata *vd = g_vd; struct priv_data *p = vd->priv; Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); Eina_Bool state = elm_check_state_get(p->onoff); if (state) { account_data->check_interval = -(abs(account_data->check_interval)); account_data->sync_disabled = 1; elm_check_state_set(p->onoff, EINA_FALSE); if (p->gl_sync_item) { if (elm_genlist_item_expanded_get(p->gl_sync_item)) { elm_genlist_item_expanded_set(p->gl_sync_item, 0); } elm_genlist_item_update(p->gl_sync_item); elm_object_item_disabled_set(p->gl_sync_item, EINA_TRUE); } } else { account_data->check_interval = abs(account_data->check_interval); account_data->sync_disabled = 0; elm_check_state_set(p->onoff, EINA_TRUE); if (p->gl_sync_item) { elm_genlist_item_update(p->gl_sync_item); elm_object_item_disabled_set(p->gl_sync_item, EINA_FALSE); } } _update_account_info(vd); } static void _gl_ex_sel_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); if (!elm_genlist_item_expanded_get(item)) { elm_genlist_item_expanded_set(item, 1); } else { elm_genlist_item_expanded_set(item, 0); } } static void _gl_ex_sync_sel_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); if (!account_data) { debug_log("account_data is NULL"); return; } int index = (int)data; struct viewdata *vd = g_vd; struct priv_data *p = vd->priv; int sel_radio = 0; Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); sel_radio = elm_radio_value_get(p->sync_radio_grp); if (sel_radio == index) return; if (index >= 0 && index < 7) account_data->check_interval = sync_schedule[index]; elm_radio_value_set(p->sync_radio_grp, index); _update_account_info(vd); elm_genlist_item_update(p->gl_sync_item); } static void _gl_exp_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); Elm_Object_Item *it = event_info; struct viewdata *vd = (struct viewdata *)data; struct priv_data *p = vd->priv; int i = 0; for (i = 0; i < 7; i++) { elm_genlist_item_append(p->genlist, &(p->itc_ex_sync), (void *)i, it, ELM_GENLIST_ITEM_NONE, _gl_ex_sync_sel_cb, (void *)i); } } static void _gl_con_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); Elm_Object_Item *item = event_info; elm_genlist_item_subitems_clear(item); } /* EOF */