/* * 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. */ #ifndef UG_MODULE_API #define UG_MODULE_API __attribute__ ((visibility("default"))) #endif #include "email-composer.h" #include "email-composer-util.h" #include "email-composer-attachment.h" #include "email-composer-recipient.h" #include "email-composer-contents.h" #include "email-composer-callback.h" #include "email-composer-predictive-search.h" #include "email-composer-js.h" #include "Ecore_X.h" static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv); static void on_start(ui_gadget_h ug, service_h data, void *priv); static void on_pause(ui_gadget_h ug, service_h data, void *priv); static void on_resume(ui_gadget_h ug, service_h data, void *priv); static void on_destroy(ui_gadget_h ug, service_h data, void *priv); static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv); static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv); #if _ENABLE_ENDKEY_ static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv); #endif static Evas_Object *create_fullview(Evas_Object *parent, EmailComposerUGD *ugd); static Evas_Object *create_frameview(Evas_Object *parent, EmailComposerUGD *ugd); static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event); static void _composer_delete_evas_objects(EmailComposerUGD *ugd); static void _composer_delete_all_popup(EmailComposerUGD *ugd); static void _composer_free_email_info(EmailComposerUGD *ugd); static void _composer_popup_warning(EmailComposerUGD *ugd, char *header, char *content); static void _composer_ug_destroy_cb(void *data, Evas_Object *obj, void *event_info); static int _composer_pre_parse_bundle(EmailComposerUGD *ugd, service_h data); static void _composer_post_parse_bundle(EmailComposerUGD *ugd, service_h data); static void _composer_init_data(void *data); static int _composer_init_service(void *data); static void _composer_finish_service(void *data); static Eina_Bool _composer_set_object_focus(void *data); static Eina_Bool _composer_register_scroller_callback(void *data); static void _composer_remove_temp_folder(); static void _composer_main_scroller_reach_top_cb(void *data, Evas_Object *obj, void *event_info); static void _composer_main_scroller_reach_bottom_cb(void *data, Evas_Object *obj, void *event_info); static void _composer_main_scroller_drag_start_cb(void *data, Evas_Object *obj, void *event_info); static int _composer_dbus_receiver_setup(EmailComposerUGD *ugd); static void _on_edbus_event_composer_receive(void *data, DBusMessage * message); static void _on_edbus_remove_receiver(EmailComposerUGD *ugd); static Eina_Bool _on_edbus_popup_del(void *data); Eina_List * _composer_create_initial_recipients_list(Evas_Object *mbe); void _composer_save_initial_email_content(EmailComposerUGD *ugd); void _composer_free_initial_email_content(EmailComposerUGD *ugd); E_DBus_Connection *_g_composer_dbus_conn = NULL; E_DBus_Signal_Handler *_g_composer_signal_handler = NULL; int attach_all_cnt; EmailComposerUGD *g_ugd = NULL; UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops) { debug_log(""); EmailComposerUGD *ugd; if (!ops) return -1; ugd = calloc(1, sizeof(EmailComposerUGD)); if (!ugd) return -1; ops->create = on_create; ops->start = on_start; ops->pause = on_pause; ops->resume = on_resume; ops->destroy = on_destroy; ops->message = on_message; ops->event = on_event; #if _ENABLE_ENDKEY_ ops->key_event = on_key_event; #endif ops->priv = ugd; ops->opt = UG_OPT_INDICATOR_PORTRAIT_ONLY; //UG_OPT_INDICATOR_ENABLE return 0; } UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops) { debug_log("IN"); EmailComposerUGD *ugd; if (!ops) return; ugd = ops->priv; if (ugd) free(ugd); debug_log("OUT"); } static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv) { debug_log(""); Evas_Object *parent; EmailComposerUGD *ugd; email_address_info_list_t *addrs_info_list = NULL; if (!ug || !priv) return NULL; ugd = (EmailComposerUGD *)priv; ugd->ug_main = ug; bindtextdomain("email", LOCALEDIR); parent = ug_get_window(); if (!parent) return NULL; ugd->win_main = parent; if (mode == UG_MODE_FULLVIEW) ugd->main_layout = create_fullview(parent, ugd); else ugd->main_layout = create_frameview(parent, ugd); evas_object_smart_callback_add(ugd->win_main, "profile,changed", _win_profile_changed_cb, ugd); ugd->composer_type = RUN_TYPE_UNKNOWN; ugd->eComposerErrorType = COMPOSER_ERROR_NONE; if (!email_engine_initialize()) { ugd->eComposerErrorType = COMPOSER_ERROR_ENGINE_INIT_FAILED; return ugd->main_layout; } ugd->eComposerErrorType = _composer_init_service(ugd); if (ugd->eComposerErrorType != COMPOSER_ERROR_NONE) return ugd->main_layout; ugd->eComposerErrorType = _composer_pre_parse_bundle(ugd, data); if (ugd->eComposerErrorType == COMPOSER_ERROR_INVALID_ARG || ugd->eComposerErrorType == COMPOSER_ERROR_UNKOWN_TYPE) { return ugd->main_layout; } else if (ugd->eComposerErrorType == COMPOSER_ERROR_NO_DEFAULT_ACCOUNT) { return ugd->main_layout; } else if (ugd->eComposerErrorType == COMPOSER_ERROR_NONE) { debug_log("def account_id = %d", ugd->account_info->account_id); ugd->eComposerErrorType = _composer_get_account_list(ugd); if (ugd->eComposerErrorType == COMPOSER_ERROR_NO_ACCOUNT_LIST) { return ugd->main_layout; } ugd->has_body_html = EINA_TRUE; ugd->saved_html_path = g_strconcat(EMAIL_TMP_FOLDER, SAVE_HTML_FILE_NAME, NULL); if (ugd->composer_type == RUN_COMPOSER_EDIT || ugd->composer_type == RUN_COMPOSER_REPLY || ugd->composer_type == RUN_COMPOSER_REPLY_ALL || ugd->composer_type == RUN_COMPOSER_FORWARD) { if (email_get_mail_data(ugd->nExistingMailID, &ugd->existing_mail_info->mail_data) != EMAIL_ERROR_NONE) { debug_log("Failed to email_get_mail_data"); goto FINISH_UG; } if (email_get_attachment_data_list(ugd->nExistingMailID, &ugd->existing_mail_info->attachment_list, &ugd->existing_mail_info->mail_data->attachment_count) != EMAIL_ERROR_NONE) { debug_log("Failed to email_get_attachment_data_list"); goto FINISH_UG; } email_get_address_info_list(ugd->nExistingMailID, &addrs_info_list); if (addrs_info_list) { ugd->from_list = addrs_info_list->from; ugd->to_list = addrs_info_list->to; ugd->cc_list = addrs_info_list->cc; ugd->bcc_list = addrs_info_list->bcc; ugd->addrs_info_list = addrs_info_list; } if (NULL != ugd->existing_mail_info->mail_data->file_path_html) { debug_log("original html file path(%s)", ugd->existing_mail_info->mail_data->file_path_html); } } if (ugd->account_info->account_count > 0) { if (!email_engine_get_account_full_data(ugd->account_info->account_id, &(ugd->account_info->account))) { debug_log("Failed to Get account full data"); ugd->eComposerErrorType = COMPOSER_ERROR_NO_ACCOUNT; return ugd->main_layout; } ugd->account_info->account_type = ugd->account_info->account->incoming_server_type; ugd->account_info->account_name = _composer_get_email_addr_from_account_id(ugd, ugd->account_info->account_id); } return ugd->main_layout; } FINISH_UG: _composer_finish_service(ugd); return NULL; } static void on_start(ui_gadget_h ug, service_h data, void *priv) { debug_log("### Begin of on_start ###"); EmailComposerUGD *ugd; if (!ug || !priv) return; ugd = (EmailComposerUGD *)priv; if (ugd->eComposerErrorType != COMPOSER_ERROR_NONE) { switch (ugd->eComposerErrorType) { case COMPOSER_ERROR_ENGINE_INIT_FAILED: debug_log("Failed to initialize email engine"); _composer_popup_warning(ugd, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_FAILED_TO_START_EMAIL_APPLICATION")); elm_object_style_set(ugd->bg, "transparent"); break; case COMPOSER_ERROR_DBUS_FAIL: debug_log("Failed to setup DBUS"); _composer_popup_warning(ugd, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_UNABLE_TO_COMPOSE_EMAIL_MESSAGE")); elm_object_style_set(ugd->bg, "transparent"); break; case COMPOSER_ERROR_SERVICE_INIT_FAIL: debug_log("Failed to create temp folder"); _composer_popup_warning(ugd, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_UNABLE_TO_COMPOSE_EMAIL_MESSAGE")); elm_object_style_set(ugd->bg, "transparent"); break; case COMPOSER_ERROR_NO_DEFAULT_ACCOUNT: case COMPOSER_ERROR_NO_ACCOUNT_LIST: case COMPOSER_ERROR_NO_ACCOUNT: debug_log("Failed to get default account"); _composer_popup_warning(ugd, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_THERE_IS_NO_ACCOUNT_CREATE_A_NEW_ACCOUNT_FIRST")); elm_object_style_set(ugd->bg, "transparent"); break; case COMPOSER_ERROR_UNKOWN_TYPE: case COMPOSER_ERROR_INVALID_ARG: debug_log("Invaild argument / Unknown composer type"); _composer_popup_warning(ugd, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_UNABLE_TO_COMPOSE_EMAIL_MESSAGE")); elm_object_style_set(ugd->bg, "transparent"); break; default : break; } return; } create_composer_frame(ugd); _composer_set_mail_info(ugd); _composer_post_parse_bundle(ugd, data); _composer_save_initial_email_content(ugd); debug_log("### End of on_start ###"); } static void on_pause(ui_gadget_h ug, service_h data, void *priv) { debug_log(""); EmailComposerUGD *ugd; if (!ug || !priv) return; ugd = priv; //elm_object_focus_set(ugd->cc_btn, EINA_TRUE); if (ugd->selected_entry == ugd->body_ewkview) { evas_object_focus_set(ugd->body_ewkview, EINA_FALSE); ugd->focus_status = COMPOSER_FOCUS_STATUS_ON_PAUSE; // focus handling } ugd->is_hided = TRUE; debug_log("### is_hided ###"); } static void on_resume(ui_gadget_h ug, service_h data, void *priv) { debug_log(""); EmailComposerUGD *ugd; if (!ug || !priv) return; ugd = priv; if (!_composer_check_popup_exist(ugd)) _composer_mbe_set_focus(ugd); ugd->is_hided = FALSE; debug_log("*** is_hided: FALSE"); } static void on_destroy(ui_gadget_h ug, service_h data, void *priv) { debug_log(""); EmailComposerUGD *ugd; if (!ug || !priv) return; ugd = priv; int ret = 0; ethumb_shutdown(); debug_log("contact service end"); contacts_svc_disconnect(); _on_edbus_remove_receiver(ugd); ret = e_dbus_shutdown(); debug_log("ret: %d", ret); _composer_delete_evas_objects(ugd); _composer_free_email_info(ugd); email_engine_finalize(); /* deinitialize ewk */ debug_log("has_body_html(%d), composer_type(%d), saved_html_path(%s)", ugd->has_body_html, ugd->composer_type, ugd->saved_html_path); if (EINA_TRUE == ugd->has_body_html) { if (ugd->saved_html_path) { g_free(ugd->saved_html_path); ugd->saved_html_path = NULL; } if (ugd->saved_html_content) { g_free(ugd->saved_html_content); ugd->saved_html_content = NULL; } if (ugd->latest_html_content) { g_free(ugd->latest_html_content); ugd->latest_html_content = NULL; } if (ugd->plain_content) { g_free(ugd->plain_content); ugd->plain_content = NULL; } } _composer_remove_temp_folder(); _composer_free_initial_email_content(ugd); } static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv) { debug_log(""); } static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)priv; int win_main_angle = 0; switch (event) { case UG_EVENT_LOW_MEMORY: break; case UG_EVENT_LOW_BATTERY: break; case UG_EVENT_LANG_CHANGE: break; case UG_EVENT_ROTATE_PORTRAIT: elm_layout_theme_set(ugd->main_layout, "layout", "application", "default"); // elm_win_indicator_mode_set(ugd->win_main, ELM_WIN_INDICATOR_SHOW); ugd->isRotated = false; win_main_angle = 0; break; case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN: elm_layout_theme_set(ugd->main_layout, "layout", "application", "default"); // elm_win_indicator_mode_set(ugd->win_main, ELM_WIN_INDICATOR_SHOW); ugd->isRotated = false; win_main_angle = 180; break; case UG_EVENT_ROTATE_LANDSCAPE: elm_layout_theme_set(ugd->main_layout, "layout", "application", "noindicator"); // elm_win_indicator_mode_set(ugd->win_main, ELM_WIN_INDICATOR_HIDE); if (ugd->option_header_opened) { elm_object_item_signal_emit(ugd->navi_item, "elm,state,optionheader,close", ""); ugd->option_header_opened = FALSE; } ugd->isRotated = true; win_main_angle = 270; break; case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN: elm_layout_theme_set(ugd->main_layout, "layout", "application", "noindicator"); // elm_win_indicator_mode_set(ugd->win_main, ELM_WIN_INDICATOR_HIDE); if (ugd->option_header_opened) { elm_object_item_signal_emit(ugd->navi_item, "elm,state,optionheader,close", ""); ugd->option_header_opened = FALSE; } ugd->isRotated = true; win_main_angle = 90; break; case UG_EVENT_REGION_CHANGE: break; default: break; } // win_main_angle = elm_win_rotation_get(ugd->win_main); // win_main_angle = app_get_device_orientation(); debug_log("win_main_angle: %d, event: %d", win_main_angle, event); if (ugd->selected_entry != ugd->body_ewkview) { debug_log("webview: scroll to [0,0]"); // If there is a focus on other entry, scroll moves to it because of bringing. so webview inner scroll has to be moved to top. ewk_view_scroll_set(ugd->body_ewkview, 0, 0); // main scrolling is moved to the selected entry, so that scrolling status of main scroller and webview have to be reset ewk_view_vertical_panning_hold_set(ugd->body_ewkview, EINA_TRUE); if (elm_widget_scroll_freeze_get(ugd->main_scroller) > 0) elm_object_scroll_freeze_pop(ugd->main_scroller); } #ifdef _TEMPORARY_FIX_FOR_ROTATION_ else { if (ugd->isRotated) ugd->temporary_fix_for_rotation = true; } #else // Resize webview. // (PORTRAIT) When screen is on the bottom of webview and is rotated, we cannot see the bottom of the webview anymore. // The bottom of the main scroller is below the screen. int nWidth, nHeight; ecore_x_window_size_get(ecore_x_window_root_first_get(), &nWidth, &nHeight); if (ugd->isRotated) { // LANDSCAPE evas_object_size_hint_min_set(ugd->body_ewkview, nHeight, nWidth - COMPOSER_NAVI_HEIGHT); // screen doesn't have indicator in case of LANDSCAPRE mode } else { // PORTRAIT evas_object_size_hint_min_set(ugd->body_ewkview, nWidth, nHeight - COMPOSER_NAVI_HEIGHT - ugd->indicator_height); } #endif if (ugd->popup_win) { elm_win_rotation_with_resize_set(ugd->popup_win, win_main_angle); } elm_win_rotation_with_resize_set(ugd->win_main, win_main_angle); // ugd->bringin_timer = ecore_timer_add(0.1f, _composer_bringin_cb, ugd); } #if _ENABLE_ENDKEY_ static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv) { debug_log(""); EmailComposerUGD *ugd = priv; if (!ug) return; if (ugd->idler_save_draft) { debug_log("delete idler_save_draft"); ecore_idler_del(ugd->idler_save_draft); ugd->idler_save_draft = NULL; } switch (event) { case UG_KEY_EVENT_END: { debug_log(""); break; /* if (ugd->composer_noti) { debug_log(""); if (ugd->composer_noti) { elm_popup_response(ugd->composer_noti, ELM_POPUP_RESPONSE_OK); } } else if (ugd->to_box && ugd->delete_popup == false) { if (_composer_check_mail_is_modified(ugd)) { ugd->save_drafts = 1; } else { ugd->save_drafts = 0; } if (ugd->save_drafts) { if (!ugd->composer_noti) { ugd->composer_noti = _composer_create_noti(ugd, false, NULL, dgettext("sys_string", "IDS_COM_POP_SAVE_TO_DRAFTS_Q"), 2, dgettext("sys_string", "IDS_COM_SK_YES"), ELM_POPUP_RESPONSE_OK, dgettext("sys_string", "IDS_COM_SK_NO"), ELM_POPUP_RESPONSE_CANCEL, 1.0, _composer_save_popup_response_cb); } } else { if (elm_navigationbar_content_top_get(ugd->navi_bar) == elm_navigationbar_content_bottom_get(ugd->navi_bar)) { debug_log("UG Destroy"); ug_destroy_me(ug); } else { debug_log("navigation pop"); elm_naviframe_item_pop(ugd->navi_bar); } } } else { debug_log("ELSE"); if (elm_naviframe_top_item_get(ugd->navi_bar) == elm_naviframe_bottom_item_get(ugd->navi_bar)) { debug_log("UG Destroy"); ug_destroy_me(ug); } else { debug_log("navigation pop"); elm_naviframe_item_pop(ugd->navi_bar); } } } */ default: break; } } #endif static Evas_Object *create_fullview(Evas_Object *parent, EmailComposerUGD *ugd) { debug_log(""); Evas_Object *base; Evas_Object *bg; base = elm_layout_add(parent); if (!base) return NULL; elm_layout_theme_set(base, "layout", "application", "default"); evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(base, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_win_resize_object_add(parent, base); bg = elm_bg_add(base); evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_win_resize_object_add(parent, bg); evas_object_show(bg); ugd->bg = bg; elm_object_part_content_set(base, "elm.swallow.bg", bg); evas_object_show(base); return base; } static Evas_Object *create_frameview(Evas_Object *parent, EmailComposerUGD *ugd) { debug_log(""); Evas_Object *base; /* Create Frame view */ base = elm_layout_add(parent); if (!base) return NULL; /* In case of frameview, do not show indicator area */ elm_layout_theme_set(base, "layout", "application", "default"); evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(base); return base; } static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event) { debug_log(""); if (!data) { debug_log("data is NULL"); return; } EmailComposerUGD *ugd = (EmailComposerUGD *)data; const char *profile = elm_config_profile_get(); if (!g_strcmp0(profile, "desktop")) elm_layout_theme_set(ugd->main_layout, "layout", "application", "noindicator"); else elm_layout_theme_set(ugd->main_layout, "layout", "application", "default"); evas_object_size_hint_weight_set(ugd->main_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(ugd->win_main, ugd->main_layout); evas_object_show(ugd->main_layout); } /* Temporary folder /tmp/email is created when composer is launched. */ int _composer_create_temp_folder() { debug_log(""); if (!email_check_dir_exist(EMAIL_TMP_FOLDER)) { int nErr = -1; nErr = mkdir(EMAIL_TMP_FOLDER, EMAIL_TMP_FOLDER_PERMISSION); debug_log("errno: %d", nErr); if (nErr == -1) { debug_log("Email temp folder creation failed"); return -1; } } else debug_log("Email temp folder already exists."); return 0; } /* Temporary folder '/tmp/email' and its contents are deleted when composer is destroyed. */ static void _composer_remove_temp_folder() { debug_log(""); struct dirent *dir_entry = NULL; DIR *dir; char buffer[256]; dir = opendir(EMAIL_TMP_FOLDER); if (!dir) { debug_log("Unable to open %s", EMAIL_TMP_FOLDER); return; } while ((dir_entry = readdir(dir))) { debug_log("%s", dir_entry->d_name); if (g_strcmp0(".", dir_entry->d_name) == 0 || g_strcmp0("..", dir_entry->d_name) == 0) continue; snprintf(buffer, 256, "%s%s", EMAIL_TMP_FOLDER, dir_entry->d_name); remove(buffer); } closedir(dir); rmdir(EMAIL_TMP_FOLDER); } Eina_List * _composer_create_initial_recipients_list(Evas_Object *mbe) { debug_log(""); if (!mbe) return NULL; const Eina_List *l = NULL; Eina_List *initial_list = NULL; Elm_Object_Item *item; const Eina_List *items_list = elm_multibuttonentry_items_get(mbe); if (items_list) { EINA_LIST_FOREACH(items_list, l, item) { initial_list = eina_list_append(initial_list, item); } } return initial_list; } void _composer_save_initial_email_content(EmailComposerUGD *ugd) { debug_log(""); if (ugd->to_mbe) { ugd->to_mbe_initial_list = _composer_create_initial_recipients_list(ugd->to_mbe); } if (ugd->cc_mbe) { ugd->cc_mbe_initial_list = _composer_create_initial_recipients_list(ugd->cc_mbe); } if (ugd->bcc_mbe) { ugd->bcc_mbe_initial_list = _composer_create_initial_recipients_list(ugd->bcc_mbe); } ugd->saved_subject = g_strdup(elm_entry_entry_get(ugd->subject_entry)); Eina_List *initial_list = NULL; int nAttachmentObjListCount = eina_list_count(ugd->attachment_item_obj_list); int i = 0; for (i = 0; i < nAttachmentObjListCount; i++) initial_list = eina_list_append(initial_list, eina_list_nth(ugd->attachment_item_obj_list, i)); ugd->attach_initial_list = initial_list; } void _composer_free_initial_email_content(EmailComposerUGD *ugd) { debug_log(""); if (ugd->to_mbe_initial_list) { eina_list_free(ugd->to_mbe_initial_list); ugd->to_mbe_initial_list = NULL; } if (ugd->cc_mbe_initial_list) { eina_list_free(ugd->cc_mbe_initial_list); ugd->cc_mbe_initial_list = NULL; } if (ugd->bcc_mbe_initial_list) { eina_list_free(ugd->bcc_mbe_initial_list); ugd->bcc_mbe_initial_list = NULL; } if (ugd->attach_initial_list) { eina_list_free(ugd->attach_initial_list); ugd->attach_initial_list = NULL; } if (ugd->saved_subject) { g_free(ugd->saved_subject); ugd->saved_subject = NULL; } if (ugd->listOfImageUrls) { eina_list_free(ugd->listOfImageUrls); ugd->listOfImageUrls = NULL; } } void create_composer_frame(EmailComposerUGD *ugd) { debug_log("Begin"); if (ugd->win_main == NULL) { debug_log("ugd->win_main == NULL"); return; } Evas_Object *win; Evas_Object *cbar; Evas_Object *cancel_btn; Evas_Object *more_btn; Evas_Object *send_btn; Evas_Object *nf; Evas_Object *outer_layout; Evas_Object *inner_layout; Evas_Object *inner_sc; Evas_Object *conform; win = ugd->win_main; elm_win_conformant_set(win, EINA_TRUE); ugd->evas = evas_object_evas_get(win); nf = _composer_create_navigation_layout(ugd->main_layout); outer_layout = _composer_create_outer_layout(nf); inner_layout = _composer_create_composer_layout(nf); inner_sc = _composer_create_main_scroller(nf); conform = elm_conformant_add(win); evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(conform); elm_object_content_set(inner_sc, inner_layout); elm_object_content_set(conform, inner_sc); elm_object_part_content_set(outer_layout, "elm.swallow.content", conform); ugd->navi_bar = nf; ugd->main_scroller = inner_sc; ugd->c_layout = inner_layout; ugd->conform = conform; _composer_create_view(inner_layout, ugd); char title_str[50] = { 0, }; if (ugd->composer_type == RUN_COMPOSER_REPLY || ugd->composer_type == RUN_COMPOSER_REPLY_ALL) snprintf(title_str, sizeof(title_str), "%s", _("IDS_EMAIL_HEADER_REPLY_ABB")); else if (ugd->composer_type == RUN_COMPOSER_FORWARD) snprintf(title_str, sizeof(title_str), "%s", N_("Forward")); else if (ugd->composer_type == RUN_COMPOSER_EDIT) snprintf(title_str, sizeof(title_str), "%s", dgettext("sys_string", "IDS_COM_HEADER_EDIT")); else snprintf(title_str, sizeof(title_str), "%s", N_("New email")); ugd->navi_item = elm_naviframe_item_push(ugd->navi_bar, title_str, NULL, NULL, outer_layout, NULL); // Right : cancel button cancel_btn = elm_button_add(ugd->navi_bar); elm_object_style_set(cancel_btn, "naviframe/title/default"); elm_object_text_set(cancel_btn, dgettext("sys_string", "IDS_COM_SK_CANCEL")); elm_object_item_part_content_set(ugd->navi_item, "title_right_btn", cancel_btn); evas_object_smart_callback_add(cancel_btn, "clicked", _composer_back_button_cb, ugd); ugd->cancel_btn = cancel_btn; debug_log("cancel_btn of composer: %p", ugd->cancel_btn); elm_object_disabled_set(ugd->cancel_btn, EINA_TRUE); // It prevents clicking the cancel button before initializing. // Middle : more button more_btn = elm_button_add(ugd->navi_bar); elm_object_style_set(more_btn, "naviframe/more/default"); elm_object_focus_allow_set(more_btn, EINA_FALSE); elm_object_item_part_content_set(ugd->navi_item, "title_more_btn", more_btn); evas_object_smart_callback_add(more_btn, "clicked", _composer_more_button_cb, ugd); // Left : send button send_btn = elm_button_add(ugd->navi_bar); elm_object_style_set(send_btn, "naviframe/title/default"); elm_object_text_set(send_btn, dgettext("sys_string", "IDS_COM_SK_SEND_ABB")); elm_object_item_part_content_set(ugd->navi_item, "title_left_btn", send_btn); evas_object_smart_callback_add(send_btn, "clicked", _composer_cbar_send_clicked, ugd); ugd->send_btn = send_btn; /* upper control bar - at ELM_NAVIFRAME_ITEM_OPTIONHEADER */ cbar = elm_toolbar_add(ugd->navi_bar); if (cbar == NULL) return; elm_toolbar_shrink_mode_set(cbar, ELM_TOOLBAR_SHRINK_EXPAND); elm_object_style_set(cbar, "naviframe"); evas_object_show(cbar); elm_object_item_part_content_set(ugd->navi_item, "optionheader", cbar); ugd->option_header_opened = 0; #ifndef _CC_BCC Evas_Object *cc_btn = elm_button_add(cbar); elm_object_style_set(cc_btn, "naviframe_control/default"); evas_object_size_hint_weight_set(cc_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(cc_btn, EVAS_HINT_FILL, 0.5); elm_object_text_set(cc_btn, _("IDS_EMAIL_BODY_CC")); evas_object_show(cc_btn); ugd->cc_btn = cc_btn; Evas_Object *bcc_btn = elm_button_add(cbar); elm_object_style_set(bcc_btn, "naviframe_control/default"); evas_object_size_hint_weight_set(bcc_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(bcc_btn, EVAS_HINT_FILL, 0.5); elm_object_text_set(bcc_btn, _("IDS_EMAIL_BODY_BCC")); evas_object_show(bcc_btn); ugd->bcc_btn = bcc_btn; ugd->controlbar_item[0] = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(ugd->controlbar_item[0], "object", cc_btn); ugd->controlbar_item[1] = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(ugd->controlbar_item[1], "object", bcc_btn); #else Evas_Object *cc_btn = elm_button_add(cbar); elm_object_style_set(cc_btn, "naviframe_control/default"); evas_object_size_hint_weight_set(cc_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(cc_btn, EVAS_HINT_FILL, 0.5); if (ugd->cc_added) elm_object_text_set(cc_btn, N_("Remove Cc/Bcc")); else elm_object_text_set(cc_btn, _("IDS_EMAIL_OPT_ADD_CC_BCC")); evas_object_show(cc_btn); ugd->cc_btn = cc_btn; ugd->controlbar_item[0] = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(ugd->controlbar_item[0], "object", cc_btn); #endif evas_object_smart_callback_add(cc_btn, "clicked", _composer_cbar_cc_clicked, ugd); #ifndef _CC_BCC evas_object_smart_callback_add(bcc_btn, "clicked", _composer_cbar_bcc_clicked, ugd); #endif elm_object_item_signal_emit(ugd->navi_item, "elm,state,optionheader,close", ""); _composer_register_scroller_callback(ugd); if (_composer_check_recipient_is_empty(ugd)) { elm_object_disabled_set(ugd->send_btn, EINA_TRUE); ugd->bSendBtnDisabled = true; } debug_log("End"); } void _composer_create_view(Evas_Object *parent, EmailComposerUGD *ugd) { debug_log("Begin"); g_ugd = ugd; /* Create from field */ if (ugd->account_info->account_count > 1) { debug_log("from field is not created, create"); email_composer_create_from_field(ugd); elm_object_part_content_set(ugd->c_layout, "from_field", ugd->from_ly); edje_object_signal_emit(_EDJ(ugd->c_layout), "show.from", "from"); _composer_add_from_address(ugd); } /* Create to field */ email_composer_create_to_field(ugd); edje_object_signal_emit(_EDJ(ugd->c_layout), "show.to", "*"); edje_object_signal_emit(_EDJ(parent), "hide_to_ps", "*"); edje_object_signal_emit(_EDJ(parent), "hide_cc_ps", "*"); edje_object_signal_emit(_EDJ(parent), "hide_bcc_ps", "*"); /* Create content field */ _composer_content_create_content_field(parent, ugd); } static void _composer_init_data(void *data) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)data; ugd->send_timer = NULL; ugd->bringin_timer = NULL; ugd->mbe_unfocus_timer = NULL; ugd->focus_timer = NULL; ugd->ps_timer = NULL; ugd->sc_timer = NULL; ugd->subject_entry = NULL; ugd->priv_selected_entry = NULL; ugd->selected_entry = NULL; ugd->body_ewkview = NULL; ugd->has_body_html = EINA_FALSE; ugd->saved_html_path = NULL; ugd->saved_html_content = NULL; ugd->latest_html_content = NULL; ugd->plain_content = NULL; ugd->to_recipients_cnt = 0; ugd->cc_recipients_cnt = 0; ugd->bcc_recipients_cnt = 0; ugd->to_mbe_initial_list = NULL; ugd->cc_mbe_initial_list = NULL; ugd->bcc_mbe_initial_list = NULL; ugd->attach_initial_list = NULL; ugd->saved_subject = NULL; ugd->nExistingMailID = 0; ugd->attachment_list_compressed = EINA_FALSE; ugd->idler_save_draft = NULL; ugd->idler_set_focus = NULL; ugd->idler_show_progress = NULL; ugd->bSendBtnDisabled = false; ugd->is_hided = false; ugd->composer_noti = NULL; ugd->timeout_noti = NULL; ugd->change_addr_noti = NULL; ugd->composer_popup = NULL; ugd->dn_noti_popup = NULL; ugd->dn_prog_popup = NULL; ugd->fw_dn_cnt = 0; ugd->b_cc_ps_open = false; ugd->b_bcc_ps_open = false; ugd->b_cc_bcc = false; ugd->clipboard_on = false; ugd->b_sending = false; ugd->ps_on = false; ugd->cc_added = false; ugd->bcc_added = false; ugd->isRotated = false; ugd->is_recipient_duplicated = false; ugd->temporary_fix_for_rotation = false; ugd->is_main_scroller_scrolling = false; ugd->is_webview_scrolling = false; ecore_x_e_illume_indicator_geometry_get(ecore_x_window_root_first_get(), NULL, NULL, NULL, &ugd->indicator_height); ugd->focus_status = COMPOSER_FOCUS_STATUS_NONE; ugd->listOfImageUrls = NULL; ugd->b_load_finished = EINA_FALSE; /*Elm_Theme *th = elm_theme_new(); elm_theme_ref_set(th, NULL); ugd->th = th; elm_theme_extension_add(ugd->th, COMPOSER_EDJ_NAME);*/ if (ethumb_init() != EINA_TRUE) { debug_log("Fail to ethumb_init()"); } ugd->composer_type = RUN_TYPE_UNKNOWN; ugd->mailbox_info = (EmailComposerMailbox *) calloc(1, sizeof(EmailComposerMailbox)); ugd->existing_mail_info = (EmailComposerMail *)calloc(1, sizeof(EmailComposerMail)); memset(ugd->existing_mail_info, 0x00, sizeof(EmailComposerMail)); ugd->new_mail_info = (EmailComposerMail *)calloc(1, sizeof(EmailComposerMail)); memset(ugd->new_mail_info, 0x00, sizeof(EmailComposerMail)); ugd->new_mail_info->mail_data = (email_mail_data_t *) calloc(1, sizeof(email_mail_data_t)); ugd->account_info = (EmailComposerAccount *) calloc(1, sizeof(EmailComposerAccount)); memset(ugd->account_info, 0x00, sizeof(EmailComposerMail)); ugd->ime_height = 444; } static int _composer_init_service(void *data) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)data; COMPOSER_ERROR_TYPE_E ret = COMPOSER_ERROR_NONE; debug_log("contact service begin"); contacts_svc_connect(); /* DBUS */ if (_composer_dbus_receiver_setup(ugd) < 0) return COMPOSER_ERROR_DBUS_FAIL; if (_composer_create_temp_folder() < 0) return COMPOSER_ERROR_SERVICE_INIT_FAIL; _composer_init_data(ugd); return ret; } static void _composer_finish_service(void *data) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)data; ethumb_shutdown(); _composer_delete_evas_objects(ugd); _composer_free_email_info(ugd); email_engine_finalize(); debug_log("contact service end"); contacts_svc_disconnect(); _on_edbus_remove_receiver(ugd); int ret = e_dbus_shutdown(); debug_log("ret: %d", ret); /* deinitialize ewk */ debug_log("has_body_html(%d), composer_type(%d), saved_html_path(%s)", ugd->has_body_html, ugd->composer_type, ugd->saved_html_path); if (EINA_TRUE == ugd->has_body_html) { if (ugd->saved_html_path) { g_free(ugd->saved_html_path); ugd->saved_html_path = NULL; } if (ugd->saved_html_content) { g_free(ugd->saved_html_content); ugd->saved_html_content = NULL; } if (ugd->latest_html_content) { g_free(ugd->latest_html_content); ugd->latest_html_content = NULL; } if (ugd->plain_content) { g_free(ugd->plain_content); ugd->plain_content = NULL; } } _composer_remove_temp_folder(); } static void _composer_delete_evas_objects(EmailComposerUGD *ugd) { debug_log(""); _composer_attachment_reset(ugd); if (ugd->main_layout) { evas_object_del(ugd->main_layout); ugd->main_layout = NULL; } if (ugd->bg) { evas_object_del(ugd->bg); ugd->bg = NULL; } /*if (ugd->th) { elm_theme_extension_del(ugd->th, COMPOSER_EDJ_NAME); elm_theme_free(ugd->th); ugd->th = NULL; }*/ if (ugd->idler_save_draft) { debug_log("delete idler_save_draft"); ecore_idler_del(ugd->idler_save_draft); ugd->idler_save_draft = NULL; } if (ugd->send_timer) { debug_log("delete send_timer"); ecore_timer_del(ugd->send_timer); ugd->send_timer = NULL; } _composer_delete_all_popup(ugd); if (ugd->ps_list) { elm_genlist_clear(ugd->ps_list); evas_object_del(ugd->ps_list); ugd->ps_list = NULL; } if (ugd->from_ly) { evas_object_del(ugd->from_ly); ugd->from_ly = NULL; } if (ugd->to_ly) { evas_object_del(ugd->to_ly); ugd->to_ly = NULL; } if (ugd->cc_ly) { evas_object_del(ugd->cc_ly); ugd->cc_ly = NULL; } if (ugd->bcc_ly) { evas_object_del(ugd->bcc_ly); ugd->bcc_ly = NULL; } if (ugd->subject_entry) { evas_object_del(ugd->subject_entry); ugd->subject_entry = NULL; } if (ugd->body_ewkview) { evas_object_del(ugd->body_ewkview); ugd->body_ewkview = NULL; } if (ugd->fw_attachment_list) { debug_log("Free the existing attachments.."); int i; for (i = 0; i < g_list_length(ugd->fw_attachment_list); ++i) { EMAIL_ATTACHMENT_INFO_S *info = (EMAIL_ATTACHMENT_INFO_S *) g_list_nth_data(ugd->fw_attachment_list, i); if (info->name) free(info->name); if (info->path) free(info->path); } g_list_free(ugd->fw_attachment_list); ugd->fw_attachment_list = NULL; } } static void _composer_delete_all_popup(EmailComposerUGD *ugd) { debug_log(""); if (ugd->popup_list == NULL) return; Evas_Object * popup; EINA_LIST_FREE(ugd->popup_list, popup) { if (popup) evas_object_del(popup); } } static void _composer_free_email_info(EmailComposerUGD *ugd) { debug_log(""); if (ugd->account_info) { debug_log("free account_info: account_id(%d), account_count(%d)", ugd->account_info->account_id, ugd->account_info->account_count); if (ugd->account_info->account_list) { debug_log("free account_list: account_name(%s), account_id(%d)", ugd->account_info->account_list->account_name, ugd->account_info->account_list->account_id); if (ugd->account_info->account_name) { debug_log("free account_name(%s)", ugd->account_info->account_name); free(ugd->account_info->account_name); ugd->account_info->account_name = NULL; } email_free_account(&(ugd->account_info->account_list), ugd->account_info->account_count); } if (ugd->account_info->account) { debug_log("free account: account_name(%s), account_id(%d)", ugd->account_info->account->account_name, ugd->account_info->account->account_id); email_free_account(&(ugd->account_info->account), 1); } free(ugd->account_info); ugd->account_info = NULL; } if (ugd->mailbox_info) { email_free_mailbox(&(ugd->mailbox_info->mail_box), 1); free(ugd->mailbox_info); } if (ugd->existing_mail_info) { if (ugd->existing_mail_info->attachment_list) { email_free_attachment_data(&ugd->existing_mail_info->attachment_list, ugd->existing_mail_info->mail_data->attachment_count); ugd->existing_mail_info->attachment_list = NULL; } if (ugd->existing_mail_info->mail_data) email_free_mail_data(&(ugd->existing_mail_info->mail_data), 1); free(ugd->existing_mail_info); ugd->existing_mail_info = NULL; } if (ugd->new_mail_info) { if (ugd->new_mail_info->attachment_list) { email_free_attachment_data(&ugd->new_mail_info->attachment_list, ugd->new_mail_info->mail_data->attachment_count); ugd->new_mail_info->attachment_list = NULL; } if (ugd->new_mail_info->mail_data) email_free_mail_data(&(ugd->new_mail_info->mail_data), 1); free(ugd->new_mail_info); ugd->new_mail_info = NULL; } if (ugd->addrs_info_list) { debug_log("free addrs_info_list"); email_free_address_info_list(&ugd->addrs_info_list); } } static void _composer_popup_warning(EmailComposerUGD *ugd, char *header, char *content) { debug_log(""); Evas_Object *pu; pu = elm_popup_add(ugd->win_main); if (!pu) return; // elm_popup_mode_set(pu, ELM_POPUP_TYPE_NONE); if (header) { elm_object_part_text_set(pu, "title,text", header); } if (content) { elm_object_text_set(pu, content); } elm_popup_timeout_set(pu, 2.0); evas_object_smart_callback_add(pu, "timeout", _composer_ug_destroy_cb, ugd); evas_object_smart_callback_add(pu, "block,clicked", _composer_ug_destroy_cb, ugd); evas_object_show(pu); ugd->composer_noti = pu; } static void _composer_ug_destroy_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)data; if (ugd->composer_noti) { evas_object_del(ugd->composer_noti); ugd->composer_noti = NULL; } ug_destroy_me(ugd->ug_main); } char *_composer_parse_recipients_arg(EmailComposerUGD *ugd, const char *source) { debug_log(""); int i = 0; char buf[MAX_RECIPIENT_ADDRESSES_LEN] = { 0, }; char *item_str; char *display_name = NULL; char email_addr[MAX_RECIPIENT_ADDRESS_LEN]; gchar **vector; gchar **vector_sub; int written_size = 0; /* Newly allocated array of strings returned */ vector = g_strsplit_set(source, ";", -1); if (vector == NULL) { debug_log("vector == NULL"); return NULL; } guint recipients_num = g_strv_length(vector); debug_log("recipient number: %d", recipients_num); for (i = 0; i < recipients_num; i++) { memset(email_addr, 0x00, sizeof(email_addr)); item_str = vector[i]; if (strlen(item_str) > MAX_RECIPIENT_ADDRESS_LEN) { if (ugd->composer_noti) { evas_object_del(ugd->composer_noti); ugd->composer_noti = NULL; } ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_MAXIMUM_RECIPIENT_EMAIL_LENGTH_EXCEEDED"), 0, NULL, NULL, 2.0, _composer_noti_response_cb); continue; } if (g_strcmp0(item_str, "") != 0) { /* Newly allocated array of strings returned */ vector_sub = g_strsplit_set(item_str, "<>", -1); if (g_strv_length(vector_sub) > 2) { display_name = vector_sub[1]; written_size = snprintf(email_addr, sizeof(email_addr), "%s", vector_sub[2]); if (written_size > sizeof(email_addr)) { debug_warning("Email address data truncated"); } if (i == 0) { written_size = snprintf(buf, sizeof(buf), "<%s> %s;", display_name, email_addr); if (written_size > sizeof(buf)) { debug_warning("Display name data truncated"); } } else { written_size = snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "<%s> %s;", display_name, email_addr); if (written_size > sizeof(buf)) { debug_warning("Display name data truncated"); } } } if (g_strv_length(vector_sub) == 1) { display_name = vector_sub[0]; written_size = snprintf(email_addr, sizeof(email_addr), "%s", vector_sub[0]); if (written_size > sizeof(email_addr)) { debug_warning("Email address data truncated"); } if (i == 0) { written_size = snprintf(buf, sizeof(buf), "%s;", email_addr); if (written_size > sizeof(buf)) { debug_warning("Display name data truncated"); } } else { written_size = snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s;", email_addr); if (written_size > sizeof(buf)) { debug_warning("Display name data truncated"); } } } /* allocated array of strings freed */ g_strfreev(vector_sub); } } /* allocated array of strings freed */ g_strfreev(vector); debug_log("buf = %s", buf); return g_strdup(buf); } static int _composer_pre_parse_bundle(EmailComposerUGD *ugd, service_h data) { debug_log(""); char *argv[7] = { 0, }; if (data) { int ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_RUN_TYPE, (char **)&argv[0]); debug_log("service_get_extra_data: %d", ret); debug_log("argv[0]:%s", argv[0]); } int ret; char *operation = NULL; ret = service_get_operation(data, &operation); debug_log("service_get_operation: %d", ret); debug_log("operation = %s", operation); if (email_engine_get_default_account(&ugd->account_info->account_id) == false) return COMPOSER_ERROR_NO_DEFAULT_ACCOUNT; if (argv[0]) { debug_log("argv[0] = %s", argv[0]); ugd->composer_type = atoi(argv[0]); debug_log("composer type = %d", ugd->composer_type); if (ugd->composer_type == RUN_COMPOSER_EXTERNAL) { if (operation == NULL) { /* ug called by ug_create */ ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_TO, (char **)&argv[1]); debug_log("service_get_extra_data: %d", ret); debug_log("to:%s", argv[1]); ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_CC, (char **)&argv[2]); debug_log("service_get_extra_data: %d", ret); debug_log("cc:%s", argv[2]); ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_BCC, (char **)&argv[3]); debug_log("service_get_extra_data: %d", ret); debug_log("bcc:%s", argv[3]); ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_SUBJECT, (char **)&argv[4]); debug_log("service_get_extra_data: %d", ret); debug_log("subject:%s", argv[4]); ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_BODY, (char **)&argv[5]); debug_log("service_get_extra_data: %d", ret); debug_log("body:%s", argv[5]); } else { /* ug called by appcontrol request */ ret = service_get_extra_data(data, SERVICE_DATA_TO, (char **)&argv[1]); debug_log("service_get_extra_data: %d", ret); debug_log("to:%s", argv[1]); ret = service_get_extra_data(data, SERVICE_DATA_CC, (char **)&argv[2]); debug_log("service_get_extra_data: %d", ret); debug_log("cc:%s", argv[2]); ret = service_get_extra_data(data, SERVICE_DATA_BCC, (char **)&argv[3]); debug_log("service_get_extra_data: %d", ret); debug_log("bcc:%s", argv[3]); ret = service_get_extra_data(data, SERVICE_DATA_SUBJECT, (char **)&argv[4]); debug_log("service_get_extra_data: %d", ret); debug_log("subject:%s", argv[4]); ret = service_get_extra_data(data, SERVICE_DATA_TEXT, (char **)&argv[5]); debug_log("service_get_extra_data: %d", ret); debug_log("body:%s", argv[5]); } } else { int ret; ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&argv[1]); debug_log("service_get_extra_data: %d", ret); debug_log("account_id:%s", argv[1]); ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&argv[2]); debug_log("service_get_extra_data: %d", ret); debug_log("mailbox_id:%s", argv[2]); ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&argv[3]); debug_log("service_get_extra_data: %d", ret); debug_log("mail_id:%s", argv[3]); } switch (ugd->composer_type) { case RUN_COMPOSER_NEW: if (argv[1]) ugd->account_info->account_id = atoi(argv[1]); ugd->save_drafts = 0; break; case RUN_COMPOSER_EDIT: case RUN_COMPOSER_REPLY_ALL: case RUN_COMPOSER_REPLY: case RUN_COMPOSER_FORWARD: if (argv[1]) ugd->account_info->account_id = atoi(argv[1]); debug_log(""); if (argv[2]) ugd->mailbox_info->mailbox_id = atoi(argv[2]); debug_log(""); if (argv[3]) ugd->nExistingMailID = atoi(argv[3]); ugd->save_drafts = 1; debug_log(""); break; case RUN_COMPOSER_EXTERNAL: if (argv[1] != NULL && strlen(argv[1]) != 0) { ugd->new_mail_info->mail_data->full_address_to = _composer_parse_recipients_arg(ugd, argv[1]); } if (argv[2] != NULL && strlen(argv[2]) != 0) { ugd->new_mail_info->mail_data->full_address_cc = _composer_parse_recipients_arg(ugd, argv[2]); } if (argv[3] != NULL && strlen(argv[3]) != 0) { ugd->new_mail_info->mail_data->full_address_bcc = _composer_parse_recipients_arg(ugd, argv[3]); } if (argv[4] != NULL && strlen(argv[4]) != 0) ugd->new_mail_info->mail_data->subject = g_strdup(argv[4]); if (argv[5] != NULL && strlen(argv[5]) != 0) { ugd->new_mail_info->mail_data->file_path_plain = g_strdup(argv[5]); ugd->new_mail_info->mail_data->body_download_status = 1; } ugd->save_drafts = 1; break; default: debug_log("[email-composer] unknown composer type!!"); return COMPOSER_ERROR_UNKOWN_TYPE; break; } if (ugd->composer_type == RUN_COMPOSER_EDIT) { debug_log("Change state to READ"); // email_modify_seen_flag(&ugd->mail_info->mail_id, 1, 1, 0); email_set_flags_field(ugd->account_info->account_id, &ugd->nExistingMailID, 1, EMAIL_FLAGS_SEEN_FIELD, 1, 1); } int i; for (i = 0; i < 7;i++) { if (argv[i]) g_free(argv[i]); } return COMPOSER_ERROR_NONE; } else { if (operation == NULL) { /* ug called by ug_create */ debug_log("Invaild argument!!"); return COMPOSER_ERROR_INVALID_ARG; } else { /* ug called by appcontrol request */ /* default run type: RUN_COMPOSER_EXTERNAL */ ugd->composer_type = RUN_COMPOSER_EXTERNAL; int ret; ret = service_get_extra_data(data, SERVICE_DATA_TO, (char **)&argv[1]); debug_log("service_get_extra_data: %d", ret); debug_log("to:%s", argv[1]); ret = service_get_extra_data(data, SERVICE_DATA_CC, (char **)&argv[2]); debug_log("service_get_extra_data: %d", ret); debug_log("cc:%s", argv[2]); ret = service_get_extra_data(data, SERVICE_DATA_BCC, (char **)&argv[3]); debug_log("service_get_extra_data: %d", ret); debug_log("bcc:%s", argv[3]); ret = service_get_extra_data(data, SERVICE_DATA_SUBJECT, (char **)&argv[4]); debug_log("service_get_extra_data: %d", ret); debug_log("subject:%s", argv[4]); ret = service_get_extra_data(data, SERVICE_DATA_TEXT, (char **)&argv[5]); debug_log("service_get_extra_data: %d", ret); debug_log("body:%s", argv[5]); if (argv[1] != NULL && strlen(argv[1]) != 0) { ugd->new_mail_info->mail_data->full_address_to = _composer_parse_recipients_arg(ugd, argv[1]); } if (argv[2] != NULL && strlen(argv[2]) != 0) { ugd->new_mail_info->mail_data->full_address_cc = _composer_parse_recipients_arg(ugd, argv[2]); } if (argv[3] != NULL && strlen(argv[3]) != 0) { ugd->new_mail_info->mail_data->full_address_bcc = _composer_parse_recipients_arg(ugd, argv[3]); } if (argv[4] != NULL && strlen(argv[4]) != 0) ugd->new_mail_info->mail_data->subject = g_strdup(argv[4]); if (argv[5] != NULL && strlen(argv[5]) != 0) { ugd->new_mail_info->mail_data->file_path_plain = g_strdup(argv[5]); ugd->new_mail_info->mail_data->body_download_status = 1; } ugd->save_drafts = 1; int i; for (i = 0; i < 7;i++) { if (argv[i]) g_free(argv[i]); } return COMPOSER_ERROR_NONE; } } } static void _composer_post_parse_bundle(EmailComposerUGD *ugd, service_h data) { debug_log("composer_type: %d", ugd->composer_type); if (ugd->composer_type == RUN_COMPOSER_EXTERNAL) { char *argv[1] = { 0, }; char *item_str; gchar **vector; int i = 0; if (data) { int ret; ret = service_get_uri(data, (char **)&argv[0]); debug_log("service_get_uri: %d", ret); debug_log("attachment:%s", argv[0]); if (!argv[0]) { ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_ATTACHMENT, (char **)&argv[0]); debug_log("service_get_extra_data: %d", ret); debug_log("attachment:%s", argv[0]); } } if (argv[0] != NULL) { Eina_List *list = NULL; debug_log("str = %s", argv[0]); if (ecore_file_exists(argv[0]) && !ecore_file_is_dir(argv[0])) { if (email_drm_file_forward_lock_check(argv[0])) { if (ugd->composer_noti) { evas_object_del(ugd->composer_noti); ugd->composer_noti = NULL; } ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"), 0, NULL, NULL, 2.0, _composer_noti_response_cb); } else { list = eina_list_append(list, argv[0]); } } else { vector = g_strsplit_set(argv[0], ";\n", -1); if (vector == NULL) { debug_log("vector == NULL"); return; } guint attach_num = g_strv_length(vector); debug_log("attatchment number: %d", attach_num); for (i = 0; i < attach_num; i++) { item_str = g_strdup(vector[i]); debug_log("item_str: %s", item_str); if (g_strcmp0(item_str, "") != 0) { if (email_drm_file_forward_lock_check((item_str))) { if (ugd->composer_noti) { evas_object_del(ugd->composer_noti); ugd->composer_noti = NULL; } ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"), 0, NULL, NULL, 2.0, _composer_noti_response_cb); g_free(item_str); } else { list = eina_list_append(list, item_str); } } else { g_free(item_str); } } g_strfreev(vector); } _composer_attachment_create_list(ugd, list, EINA_FALSE); g_free(argv[0]); } } //////////////////////////////////////////////////////////////////////////////////////////////////// if (ugd->composer_type != RUN_TYPE_UNKNOWN) { int att_cnt = 0; if (ugd->fw_attachment_list) att_cnt = g_list_length(ugd->fw_attachment_list); if (elm_multibuttonentry_first_item_get(ugd->to_mbe) != NULL) { if (g_strcmp0(elm_entry_entry_get(ugd->subject_entry), "") == 0) { debug_log("To field is not empty, setting focus to subject_entry field."); if (ugd->composer_type != RUN_COMPOSER_FORWARD || !ugd->account_info->account->options.forward_with_files || !att_cnt) { if (!_composer_check_popup_exist(ugd)) ugd->focus_timer = ecore_timer_add(0.1f, _composer_set_object_focus, ugd->subject_editfield); } ugd->selected_entry = ugd->subject_entry; } else if (ugd->body_ewkview) { debug_log("To field is not empty, setting focus to body_ewkview field."); if (ugd->composer_type != RUN_COMPOSER_FORWARD || !ugd->account_info->account->options.forward_with_files || !att_cnt) { if (!_composer_check_popup_exist(ugd)) ugd->focus_timer = ecore_timer_add(0.1f, _composer_set_object_focus, ugd->body_ewkview); } ugd->selected_entry = ugd->body_ewkview; if (ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_SET_FOCUS, _composer_focus_script_executed_cb, ugd) == EINA_FALSE) debug_log("COMPOSER_JS_SET_FOCUS error."); /* Known Issue: Sometimes long mails are not rendered properly in webkit when we bring up the composer */ //ugd->bringin_timer = ecore_timer_add(0.1f, _composer_bringin_cb, ugd); } } else { debug_log("To field is empty, setting focus to 'To' field."); if (ugd->composer_type != RUN_COMPOSER_FORWARD || !ugd->account_info->account->options.forward_with_files || !att_cnt) { if (!_composer_check_popup_exist(ugd)) ugd->focus_timer = ecore_timer_add(0.2f, _composer_set_object_focus, ugd->to_mbe); } /*ugd->selected_entry = ugd->to_mbe_entry;*/ } } } static Eina_Bool _composer_set_object_focus(void *data) { debug_log(""); Evas_Object *obj = (Evas_Object *)data; if (obj == g_ugd->to_mbe) { debug_log("Focus to TO"); elm_object_focus_set(g_ugd->to_mbe, EINA_TRUE); g_ugd->selected_entry = elm_multibuttonentry_entry_get(obj); } else if (obj == g_ugd->subject_editfield) { debug_log("Focus to SUBJECT"); elm_object_focus_set(g_ugd->subject_editfield, EINA_TRUE); g_ugd->selected_entry = elm_object_part_content_get(obj, "elm.swallow.content"); } else if (obj == g_ugd->body_ewkview) { debug_log("Focus to BODY WEBKIT"); g_ugd->selected_entry = obj; } if (g_ugd->focus_timer) { ecore_timer_del(g_ugd->focus_timer); g_ugd->focus_timer = NULL; } return ECORE_CALLBACK_CANCEL; } static void _composer_main_scroller_reach_top_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)data; if (ugd->ps_list) return; /* if (ugd->account_info->account_count > 1) { if (ugd->from_box) { debug_log("from field is hidden, show"); evas_object_show(ugd->from_ly); evas_object_show(ugd->from_box); evas_object_show(ugd->from_mbe); elm_object_part_content_set(ugd->c_layout, "from_field", ugd->from_box); edje_object_signal_emit(_EDJ(ugd->c_layout), "show.from", "from"); } else { debug_log("from field is not created, create"); _composer_create_from_field(ugd); elm_object_part_content_set(ugd->c_layout, "from_field", ugd->from_box); edje_object_signal_emit(_EDJ(ugd->c_layout), "show.from", "from"); _composer_add_from_address(ugd); } } */ } static void _composer_main_scroller_reach_bottom_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)data; /* if (ugd->account_info->account_count > 1) { if (ugd->from_box) { debug_log("from field is shown, hide"); evas_object_hide(ugd->from_ly); evas_object_hide(ugd->from_box); evas_object_hide(ugd->from_mbe); elm_object_part_content_unset(ugd->c_layout, "from_field"); edje_object_signal_emit(_EDJ(ugd->c_layout), "hide.from", "from"); } } */ // It's workaround fixes to avoid a problem regarding too many signals of 'edge,bottom' for main_scroller. if (ugd->is_main_scroller_scrolling) { debug_log("Main scroller hold push"); elm_object_scroll_freeze_push(ugd->main_scroller); ewk_view_vertical_panning_hold_set(ugd->body_ewkview, EINA_FALSE); ugd->is_main_scroller_scrolling = EINA_FALSE; ugd->is_webview_scrolling = EINA_TRUE; } } static void _composer_main_scroller_drag_start_cb(void *data, Evas_Object *obj, void *event_info) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)data; ugd->is_main_scroller_scrolling = EINA_TRUE; } static Eina_Bool _composer_register_scroller_callback(void *data) { EmailComposerUGD *ugd = (EmailComposerUGD *)data; evas_object_smart_callback_add(ugd->main_scroller, "scroll,drag,start", _composer_main_scroller_drag_start_cb, ugd); evas_object_smart_callback_add(ugd->main_scroller, "edge,top", _composer_main_scroller_reach_top_cb, ugd); evas_object_smart_callback_add(ugd->main_scroller, "edge,bottom", _composer_main_scroller_reach_bottom_cb, ugd); return EINA_FALSE; } static int _composer_dbus_receiver_setup(EmailComposerUGD *ugd) { debug_log(""); int err = COMPOSER_ERROR_NONE; int ret = e_dbus_init(); debug_log("ret: %d", ret); DBusError derror; if (_g_composer_dbus_conn == NULL) { debug_log(""); dbus_error_init(&derror); _g_composer_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM); if (e_dbus_request_name(_g_composer_dbus_conn, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) { debug_log("Failed to e_dbus_request_name()"); return COMPOSER_ERROR_DBUS_FAIL; } if (_g_composer_signal_handler != NULL) { debug_log("_g_composer_signal_handler != NULL"); } _g_composer_signal_handler = e_dbus_signal_handler_add(_g_composer_dbus_conn, NULL, "/User/Email/NetworkStatus", "User.Email.NetworkStatus", "email", _on_edbus_event_composer_receive, ugd); if (_g_composer_signal_handler == NULL) { debug_log("Failed to e_dbus_signal_handler_add()"); return COMPOSER_ERROR_DBUS_FAIL; } } return err; } static void _on_edbus_event_composer_receive(void *data, DBusMessage * message) { debug_log(""); EmailComposerUGD *ugd = (EmailComposerUGD *)data; DBusError error; if (dbus_message_is_signal(message, "User.Email.NetworkStatus", "email")) { debug_log("User.Email.NetworkStatus"); int subtype = 0; int data1 = 0; char *data2 = NULL; int data3 = 0; int data4 = 0; dbus_error_init(&error); if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype, DBUS_TYPE_INT32, &data1, DBUS_TYPE_STRING, &data2, DBUS_TYPE_INT32, &data3, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID)) { debug_log("subtype: %d, data1: %d, data2: %s, data3: %d, data4: %d", subtype, data1, data2, data3, data4); switch (subtype) { case NOTI_DOWNLOAD_ATTACH_START: /* DATA1[mail_id] DATA2[file_id] DATA3[attachment_id] DATA4[percentage] */ debug_log("receive noti, DOWNLOAD_ATTACHMENT"); char buf[128] = { 0, }; if (ugd->account_info->account_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) { char buf[128] = { 0, }; snprintf(buf, sizeof(buf), "%s [%d/%d]", _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"), ugd->fw_dn_idx + 1, ugd->fw_dn_total_cnt); elm_object_text_set(ugd->fw_dn_label, buf); } else { debug_log("Download : %d / %d", data4 + (ugd->fw_dn_idx * 100), (ugd->fw_dn_total_cnt * 100)); snprintf(buf, sizeof(buf), "%s [%d/%d]", _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"), ugd->fw_dn_idx + 1, ugd->fw_dn_total_cnt); elm_object_text_set(ugd->fw_dn_label, buf); elm_progressbar_value_set(ugd->fw_dn_progress, (double)(data4 + (ugd->fw_dn_idx * 100)) / (ugd->fw_dn_total_cnt * 100)); evas_render(evas_object_evas_get(ugd->main_layout)); } break; case NOTI_DOWNLOAD_ATTACH_FINISH: /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */ debug_log("receive noti, DOWNLOAD_ATTACH_FINISH"); int idx = 0; Eina_List *list = NULL; int att_cnt = g_list_length(ugd->fw_attachment_list); if (ugd->fw_dn_cnt > 0) { ugd->fw_dn_cnt--; if (ugd->fw_dn_cnt == 0) { debug_log("Last Donwload"); _on_edbus_popup_del(ugd); _composer_update_attachment_info(ugd, data3); for (idx = 0; idx < att_cnt; idx++) { EMAIL_ATTACHMENT_INFO_S *info = g_list_nth_data(ugd->fw_attachment_list, idx); if (info == NULL) { debug_log("Attachment is NULL"); continue; } if (!info->inline_content) { if (info->downloaded) { debug_log("path %s", info->path); if (info->path) list = eina_list_append(list, info->path); } } } _composer_attachment_create_list(ugd, list, EINA_FALSE); } else { debug_log("Donwload Not Finished"); char buf[128] = { 0, }; snprintf(buf, sizeof(buf), "%s [%d/%d]", _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"), ugd->fw_dn_idx + 1, ugd->fw_dn_total_cnt); elm_object_text_set(ugd->fw_dn_label, buf); _composer_update_attachment_info(ugd, data3); ugd->fw_dn_idx++; } } break; case NOTI_DOWNLOAD_ATTACH_FAIL: /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */ debug_log("receive noti, DOWNLOAD_ATTACH_FAIL"); if (ugd->dn_prog_popup) { _on_edbus_popup_del(ugd); char fail_msg[512] = { 0, }; if (data4 != EMAIL_ERROR_CANCELLED) { char *err_msg = _composer_get_service_fail_type(data4); snprintf(fail_msg, sizeof(fail_msg), "%s
%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg); if (ugd->composer_noti) { evas_object_del(ugd->composer_noti); ugd->composer_noti = NULL; } ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), fail_msg, 1, dgettext("sys_string", "IDS_COM_SK_OK"), NULL, 0.0, _composer_noti_response_cb); free(err_msg); } } break; default: debug_log("unknown type"); break; } } else { debug_log("receive data error: %s", error.message); dbus_error_free(&error); } return; } return; } static void _on_edbus_remove_receiver(EmailComposerUGD *ugd) { debug_log(""); if (_g_composer_signal_handler != NULL) { e_dbus_signal_handler_del(_g_composer_dbus_conn, _g_composer_signal_handler); _g_composer_signal_handler = NULL; } if (_g_composer_dbus_conn != NULL) { _g_composer_dbus_conn = NULL; } } static Eina_Bool _on_edbus_popup_del(void *data) { EmailComposerUGD *ugd = (EmailComposerUGD *)data; if (ugd->dn_prog_popup) { evas_object_del(ugd->dn_prog_popup); ugd->dn_prog_popup = NULL; } return EINA_FALSE; }