/* * Copyright 2012-2013 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://floralicense.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 static void __search_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv) { SEARCH_FUNC_START; Evas_Object *base = NULL; (Evas_Object *) ug_get_layout(ug); Evas_Object *win = NULL; SEARCH_RET_IF(ug == NULL || priv == NULL); base = (Evas_Object *)ug_get_layout(ug); win = (Evas_Object *)ug_get_window(); SEARCH_RET_IF(base == NULL); SEARCH_RET_IF(win == NULL); switch (mode) { case UG_MODE_FULLVIEW: evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(win, base); evas_object_show(base); break; default: break; } SEARCH_FUNC_END; } static void __search_ug_closed_cb(ui_gadget_h ug, void *priv) { SEARCH_FUNC_START; struct appdata *ad = (struct appdata *)priv; SEARCH_RET_IF(ug == NULL); SEARCH_RET_IF(ad == NULL); ug_destroy(ug); ad->detail_ug = NULL; elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT); if (elm_object_scroll_freeze_get(ad->search_gl) > 0) { elm_object_scroll_freeze_pop(ad->search_gl); } 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; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); service_h service = NULL; int ret = 0; bool err_popup_show = true; Ecore_X_Window win_id = -1; win_id = elm_win_xwindow_get(ad->win_main); ret = service_create(&service); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_create"); goto out_func; } ret = service_set_app_id(service, "contacts-details-efl"); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_set_app_id!"); goto out_func; } ret = service_set_window(service, win_id); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_set_window!"); goto out_func; } ret = service_add_extra_data(service, "type", "0");; if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_add_extra_data : type!"); goto out_func; } ret = service_add_extra_data(service, "person_id", cur_category_mem->launch_param); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_add_extra_data : person_id"); goto out_func; } ret = service_send_launch_request(service, NULL, NULL); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_send_launch_request"); goto out_func; } else { 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; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); service_h service = NULL; int ret = 0; bool err_popup_show = true; ret = service_create(&service); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_create"); goto out_func; } ret = service_set_package(service, "org.tizen.message"); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_set_package!"); goto out_func; } ret = service_add_extra_data(service, "type", "msg_id"); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_set_extra_data : msg_id"); goto out_func; } ret = service_add_extra_data(service, "msgId", cur_category_mem->launch_param); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_set_extra_data : msgId parameter!"); goto out_func; } ret = service_send_launch_request(service, NULL, NULL); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("[Fail] service_send_launch_request"); goto out_func; } else { 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_email_view(void *data, void *record_info) { SEARCH_FUNC_START; char *token_param = NULL; char *saveptr1; int i = 0; int ret = 0; bool err_popup_show = true; struct appdata *ad = (struct appdata *)data; struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info; char temp_path[MAX_LENGTH_PER_PATH] = { 0, }; service_h service = NULL; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); ret = service_create(&service); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to create service handle!"); goto out_func; } snprintf(temp_path, MAX_LENGTH_PER_PATH - 1, "%s", cur_category_mem->launch_path); token_param = strtok_r(temp_path, " ", &saveptr1); while (token_param != NULL) { SEARCH_DEBUG_LOG("PARAMETER (%d) : %s", i, token_param); if (i == 0) { ret = service_add_extra_data(service, "ACCOUNT_ID", token_param); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add extra data : ACCOUND_ID!"); goto out_func; } } else if (i == 1) { ret = service_add_extra_data(service, "MAIL_ID", token_param); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add extra data : MAIL_ID!"); goto out_func; } } else if (i == 2) { ret = service_add_extra_data(service, "MAILBOX_ID", token_param); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add extra data : MAILBOX_ID!"); goto out_func; } } else { break; } i++; token_param = strtok_r(NULL, " ", &saveptr1); } ret = service_add_extra_data(service, "RUN_TYPE", "7"); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add extra data : RUN_TYPE!"); goto out_func; } ret = service_set_package(service, "org.tizen.email"); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to set package!"); goto out_func; } ret = service_send_launch_request(service, NULL, NULL); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to send service!"); goto out_func; } err_popup_show = false; 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_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; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); if (access(cur_category_mem->launch_path, F_OK) != 0) { SEARCH_DEBUG_ERROR("image access error : %s", cur_category_mem->launch_path); search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad); } else { SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s", cur_category_mem->launch_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->launch_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; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); if (access(cur_category_mem->launch_path, F_OK) != 0) { SEARCH_DEBUG_ERROR("video access error : %s", cur_category_mem->launch_path); search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad); } else { SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s", cur_category_mem->launch_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->launch_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; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); if (access(cur_category_mem->launch_path, F_OK) != 0) { SEARCH_DEBUG_ERROR("music file access error : %s", cur_category_mem->launch_path); search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad); } else { SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s", cur_category_mem->launch_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->launch_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; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); if (strlen(cur_category_mem->launch_param) <= 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->launch_param); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 2!"); goto out_func; } 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; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); if (strlen(cur_category_mem->launch_param) <= 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"); ug_destroy(ug); ad->detail_ug = NULL; } 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->launch_param); if (ret != SERVICE_ERROR_NONE) { SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!"); goto out_func; } 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 = NULL; bool is_running = false; app_context_h app_h; bool err_popup_show = true; int ret; service_h service = NULL; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); pkg_name = cur_category_mem->launch_path; 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; service_h service; SEARCH_RET_IF(ad == NULL); SEARCH_RET_IF(cur_category_mem == NULL); SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s", cur_category_mem->launch_path); ret = service_create(&service); if (ret == 0 && strlen(cur_category_mem->launch_path) > 0 ) { service_set_operation(service, SERVICE_OPERATION_VIEW); service_set_uri(service, cur_category_mem->launch_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; SEARCH_RET_IF(ad == NULL); 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; SEARCH_RET_IF(ad == NULL); 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; } elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT); if (elm_object_scroll_freeze_get(ad->search_gl) > 0) { elm_object_scroll_freeze_pop(ad->search_gl); } 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; }