/* * 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 "smartsearch.h" #include "ps_app_interface.h" #include "ps_searcher.h" #include #include #include #include #include #include #define UG_NAME_LEN 50 static void __search_layout_ug_destroy(void *data) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; //D. Because the ug will be able to remove the base object, unset the content from the effect layout. elm_object_part_content_unset(ad->effect_layout, (char *)ug_get_layout(ad->detail_ug)); evas_object_del(ad->effect_layout); ug_destroy(ad->detail_ug); ad->detail_ug = NULL; ad->effect_layout = NULL; SEARCH_FUNC_END; } static void __search_effect_layout_signal_hide_finished(void *data, Evas_Object * obj, const char *emission, const char *source) { SEARCH_FUNC_START; __search_layout_ug_destroy(data); SEARCH_FUNC_END; } static void __search_effect_layout_render_flush_post_cb(void *data, Evas * e, void *event_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; if (!ad) return; //UG Show Effect edje_object_signal_emit(elm_layout_edje_get(ad->effect_layout), "elm,state,show", ""); //B.Remove the EVAS_RENDER_FLUSH_POST callback again. evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, __search_effect_layout_render_flush_post_cb); SEARCH_FUNC_END; } static void __search_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv) { SEARCH_FUNC_START; Evas_Object *base = (Evas_Object *) ug_get_layout(ug); if (!base) return; #ifdef ENABLE_UG_EFFECT if (!ad->effect_layout) return; elm_object_part_content_set(ad->effect_layout, "elm.swallow.content", base); //B. Add the callback event for the EVAS_RENDER_FLUSH_POST //B. This is one method to not skip the total effect time in creating the ug object. evas_event_callback_add(evas_object_evas_get(ad->effect_layout), EVAS_CALLBACK_RENDER_FLUSH_POST, __search_effect_layout_render_flush_post_cb, ad); #else evas_object_show(base); #endif SEARCH_FUNC_END; } static void __search_ug_closed_cb(ui_gadget_h ug, void *priv) { SEARCH_FUNC_START; #ifdef ENABLE_UG_EFFECT edje_object_signal_emit(elm_layout_edje_get(ad->effect_layout), "elm,state,hide", ""); #else Evas_Object *base = (Evas_Object *) ug_get_layout(ug); evas_object_hide(base); #endif SEARCH_FUNC_END; } static void __search_create_effect_layout(Evas_Object * parent, struct appdata *ad) { SEARCH_FUNC_START; int ret; //Create the layout then apply the edj Evas_Object *ly = elm_layout_add(ad->win_main); if (!ly) return; evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(ad->win_main, ly); ret = elm_layout_file_set(ly, SEARCH_EDJ, "ug_effect"); //Add a signal callback function which will be called after terminating hide effect. edje_object_signal_callback_add(elm_layout_edje_get(ly), "elm,action,hide,finished", "", __search_effect_layout_signal_hide_finished, ad); //store the layout object to refer it at hide effect ad->effect_layout = ly; evas_object_show(ly); SEARCH_FUNC_END; } void search_launch_contact_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; service_h service = NULL; int ret = 0; bool err_popup_show = true; ui_gadget_h ug = NULL; struct ug_cbs cbs = { 0, }; char buf[10] = { 0, }; if (!cur_category_mem || strlen(cur_category_mem->main_id) < 0 ) { SEARCH_DEBUG_ERROR("Selected item does not have data!"); goto out_func; } else { if (ad->detail_ug) { SEARCH_DEBUG_WARNING("\n prev ug is exist. destroy prev ug"); __search_layout_ug_destroy(ad); } ret = service_create(&service); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to create service handle!"); goto out_func; } snprintf(buf, sizeof(buf), "%d", CT_UG_REQUEST_DETAIL); ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, buf); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!"); goto out_func; } ret = service_add_extra_data(service, CT_UG_BUNDLE_ID, cur_category_mem->main_id); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 2!"); goto out_func; } #ifdef ENABLE_UG_EFFECT __search_create_effect_layout(ad->win_main, ad); #endif cbs.layout_cb = __search_ug_layout_cb; cbs.result_cb = NULL; cbs.destroy_cb = __search_ug_closed_cb; cbs.priv = ad; ug = ug_create(NULL, UG_CONTACTS_DETAILS, UG_MODE_FULLVIEW, service, &cbs); if (!ug) { SEARCH_DEBUG_ERROR(" ... ug_create: failed !!!"); goto out_func; } else { ad->detail_ug = ug; err_popup_show = false; } } out_func: if (err_popup_show == true) search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad); if (service != NULL) service_destroy(service); SEARCH_FUNC_END; } void search_launch_msg_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; bundle *b; int ret = 0; b = bundle_create(); if (!b) { SEARCH_DEBUG_ERROR("search_launch_msg_view : bundle_create failed"); return; } bundle_add(b, "type", "msg_id"); bundle_add(b, "msgId", cur_category_mem->main_id); ret = aul_launch_app("org.tizen.message", b); if( (ret <= 0) && (ret != AUL_R_ETIMEOUT) ){ SEARCH_DEBUG_ERROR("msg aul launch app error(%d)", ret); search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad); } bundle_free(b); SEARCH_FUNC_END; } void search_launch_email_view(void *data, void *record_info) { SEARCH_FUNC_START; bundle *b; char *token_param = NULL; char *saveptr1; int i = 0; int ret = 0; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; b = bundle_create(); if (!b) return; char livemagazine[2] = { 0, }; char temp_path[MAX_LENGTH_PER_PATH] = { 0, }; livemagazine[0] = '0'; snprintf(temp_path, MAX_LENGTH_PER_PATH - 1, "%s", cur_category_mem->path); token_param = strtok_r(temp_path, " ", &saveptr1); while (token_param != NULL) { if (i == 0) { bundle_add(b, "ACCOUNT_ID", token_param); //account_id } else if (i == 1) { bundle_add(b, "MAIL_ID", token_param); //mail_id } else if (i == 2) { bundle_add(b, "MAILBOX_ID", token_param); //mailbox } else { break; } i++; token_param = strtok_r(NULL, " ", &saveptr1); } bundle_add(b, "bLiveMagazine", livemagazine); char runType[2] = { 0 }; snprintf(runType, sizeof(runType), "%d", 7); bundle_add(b, "RUN_TYPE", runType); ret = aul_launch_app("org.tizen.email", b); if( (ret <= 0) && (ret != AUL_R_ETIMEOUT) ){ SEARCH_DEBUG_ERROR("email aul launch app error(%d)", ret); search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad); } bundle_free(b); SEARCH_FUNC_END; } void search_launch_image_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; int ret; if (access(cur_category_mem->path, F_OK) != 0) { SEARCH_DEBUG_ERROR("image access error : %s", cur_category_mem->path); search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad); } else { SEARCH_DEBUG_LOG("cur_category_mem->path : %s", cur_category_mem->path); service_h service; ret = service_create(&service); if (ret == 0) { service_set_operation(service, SERVICE_OPERATION_VIEW); service_set_uri(service, cur_category_mem->path); ret = service_send_launch_request(service, NULL, NULL); if (ret != 0) { SEARCH_DEBUG_ERROR("image app service launching error(%d)", ret); search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad); } service_destroy(service); } } SEARCH_FUNC_END; } void search_launch_video_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; int ret; if (access(cur_category_mem->path, F_OK) != 0) { SEARCH_DEBUG_ERROR("video access error : %s", cur_category_mem->path); search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad); } else { SEARCH_DEBUG_LOG("cur_category_mem->path : %s", cur_category_mem->path); service_h service; ret = service_create(&service); if (ret == 0) { service_set_operation(service, SERVICE_OPERATION_VIEW); service_set_uri(service, cur_category_mem->path); ret = service_send_launch_request(service, NULL, NULL); if (ret != 0) { SEARCH_DEBUG_ERROR("video app service launching error(%d)", ret); search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad); } service_destroy(service); } } SEARCH_FUNC_END; } void search_launch_music_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; int ret; if (access(cur_category_mem->path, F_OK) != 0) { SEARCH_DEBUG_ERROR("music file access error : %s", cur_category_mem->path); search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad); } else { SEARCH_DEBUG_LOG("cur_category_mem->path : %s", cur_category_mem->path); service_h service; ret = service_create(&service); if (ret == 0) { service_set_operation(service, SERVICE_OPERATION_VIEW); service_set_uri(service, cur_category_mem->path); ret = service_send_launch_request(service, NULL, NULL); if (ret != 0) { SEARCH_DEBUG_ERROR("music app service launching error(%d)", ret); search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad); } service_destroy(service); } } SEARCH_FUNC_END; } void search_launch_calendar_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; ui_gadget_h ug = NULL; struct ug_cbs cbs = { 0, }; int ret = 0; bool err_popup_show = true; service_h service = NULL; if (!cur_category_mem && strlen(cur_category_mem->main_id) < 0) { SEARCH_DEBUG_ERROR("Selected item does not have data!"); goto out_func; } else { ret = service_create(&service); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to create service handle!"); goto out_func; } ret = service_add_extra_data(service, "itemType", "event"); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!"); goto out_func; } ret = service_add_extra_data(service, "eventID", cur_category_mem->main_id); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 2!"); goto out_func; } #ifdef ENABLE_UG_EFFECT __search_create_effect_layout(ad->win_main, ad); #endif cbs.destroy_cb = __search_ug_closed_cb; cbs.layout_cb = __search_ug_layout_cb; cbs.result_cb = NULL; cbs.priv = ad; ug = ug_create(NULL, "calendar-detail-efl", UG_MODE_FULLVIEW, service, &cbs); if (!ug) { SEARCH_DEBUG_ERROR("... create_ug_calendar : failed !!!"); goto out_func; } ad->detail_ug = ug; err_popup_show = false; } out_func: if (err_popup_show == true) search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad); if (service != NULL) service_destroy(service); SEARCH_FUNC_END; } void search_launch_memo_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; ui_gadget_h ug = NULL; struct ug_cbs cbs = { 0, }; int ret = 0; bool err_popup_show = true; service_h service = NULL; if (!cur_category_mem && strlen(cur_category_mem->main_id) < 0) { SEARCH_DEBUG_ERROR("Selected item does not have data!"); goto out_func; } else { if (ad->detail_ug) { SEARCH_DEBUG_WARNING("prev ug is exist. destroy prev ug"); __search_layout_ug_destroy(ad); } ret = service_create(&service); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to create service handle!"); goto out_func; } ret = service_add_extra_data(service, "index", cur_category_mem->main_id); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!"); goto out_func; } #ifdef ENABLE_UG_EFFECT __search_create_effect_layout(ad->win_main, ad); #endif cbs.layout_cb = __search_ug_layout_cb; cbs.result_cb = NULL; cbs.destroy_cb = __search_ug_closed_cb; cbs.priv = ad; ug = ug_create(NULL, "memo-efl", UG_MODE_FULLVIEW, service, &cbs); if (!ug) { SEARCH_DEBUG_ERROR("... create_ug_email : failed !!!"); goto out_func; } ad->detail_ug = ug; err_popup_show = false; } out_func: if (err_popup_show == true) search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad); if (service != NULL) service_destroy(service); SEARCH_FUNC_END; } void search_launch_menu_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; char *pkg_name = cur_category_mem->path; bool is_running = false; app_context_h app_h; bool err_popup_show = true; int ret; service_h service = NULL; if (pkg_name != NULL && strlen(pkg_name)) { ret = app_manager_is_running(pkg_name, &is_running); if (ret != APP_MANAGER_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to get info : app_manager_is_running [%d]", ret); goto out_func; } if (is_running == true) { ret = app_manager_get_app_context(pkg_name, &app_h); if (ret != APP_MANAGER_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to get info : app_manager_get_app_context [%d]", ret); goto out_func; } ret = app_manager_resume_app(app_h); if (ret != APP_MANAGER_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to get info : app_manager_resume_app [%d]", ret); goto out_func; } err_popup_show = false; } else { ret = service_create(&service); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to create service header : [%d]", ret); goto out_func; } ret = service_set_operation(service, SERVICE_OPERATION_DEFAULT); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to set operation : [%d]", ret); goto out_func; } ret = service_set_package(service, pkg_name); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to set package : [%d]", ret); goto out_func; } ret = service_send_launch_request(service, NULL, NULL); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to send launch request : [%d]", ret); goto out_func; } err_popup_show = false; } } else { SEARCH_DEBUG_ERROR("Pkg name is NULL!"); } out_func: if (err_popup_show == true) search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad); if (service != NULL) { ret = service_destroy(service); if (ret != SERVICE_ERROR_NONE) SEARCH_DEBUG_ERROR("Fail to destroy service header : [%d]", ret); } SEARCH_FUNC_END; } void search_launch_browser_view(void *data, void *record_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; int ret; SEARCH_DEBUG_LOG("cur_category_mem->path : %s", cur_category_mem->path); service_h service; ret = service_create(&service); if (ret == 0 && strlen(cur_category_mem->path) > 0 ) { service_set_operation(service, SERVICE_OPERATION_VIEW); service_set_uri(service, cur_category_mem->path); ret = service_send_launch_request(service, NULL, NULL); if (ret != 0) { SEARCH_DEBUG_ERROR("browser app service launching error(%d)", ret); search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad); } service_destroy(service); } } static void __search_launch_popup_error_response_cb(void *data, Evas_Object * obj, void *event_info) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)data; evas_object_del(ad->ctxpopup); ad->ctxpopup = NULL; SEARCH_FUNC_END; } void search_launch_popup_error(int error_type, void *data) { Evas_Object *popup; Evas_Object *btn1; struct appdata *ad = (struct appdata *)data; if (error_type >= LAUNCH_ERROR_MAX) { SEARCH_DEBUG_ERROR("wrong error_type : %d", error_type); } if (ad->ctxpopup) { evas_object_del(ad->ctxpopup); ad->ctxpopup = NULL; } popup = elm_popup_add(ad->win_main); evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); switch(error_type) { case LAUNCH_ERROR_FILE_NOT_FOUND: elm_object_text_set(popup, dgettext("sys_string", "IDS_COM_POP_FILE_NOT_FOUND")); break; case LAUNCH_ERROR_AUL_LAUNCH: /* This Message String enable to be another string in the future */ elm_object_text_set(popup, gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST")); break; case LAUNCH_ERROR_APPSVC: elm_object_text_set(popup, gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST")); break; } btn1 = elm_button_add(popup); elm_object_style_set(btn1, "popup_button/default"); elm_object_text_set(btn1, dgettext("sys_string","IDS_COM_POP_CLOSE")); evas_object_smart_callback_add(btn1, "clicked", __search_launch_popup_error_response_cb, ad); elm_object_part_content_set(popup, "button1", btn1); elm_popup_timeout_set(popup, 3.0); evas_object_smart_callback_add(popup, "timeout", __search_launch_popup_error_response_cb, ad); evas_object_smart_callback_add(popup, "block,clicked", __search_launch_popup_error_response_cb, ad); evas_object_show(popup); ad->ctxpopup = popup; }