2 * Copyright 2012-2013 Samsung Electronics Co., Ltd/
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include "smartsearch.h"
24 #include "ps_app_interface.h"
25 #include "ps_searcher.h"
26 #include <ui-gadget.h>
27 #include <contacts-ug.h>
28 #include <aul_service.h>
30 #include <app_manager.h>
33 static void __search_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode,
38 Evas_Object *base = NULL; (Evas_Object *) ug_get_layout(ug);
39 Evas_Object *win = NULL;
41 SEARCH_RET_IF(ug == NULL || priv == NULL);
43 base = (Evas_Object *)ug_get_layout(ug);
44 win = (Evas_Object *)ug_get_window();
46 SEARCH_RET_IF(base == NULL);
47 SEARCH_RET_IF(win == NULL);
50 case UG_MODE_FULLVIEW:
51 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
52 elm_win_resize_object_add(win, base);
53 evas_object_show(base);
62 static void __search_ug_closed_cb(ui_gadget_h ug, void *priv)
66 struct appdata *ad = (struct appdata *)priv;
68 SEARCH_RET_IF(ug == NULL);
69 SEARCH_RET_IF(ad == NULL);
74 elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT);
76 if (elm_object_scroll_freeze_get(ad->search_gl) > 0) {
77 elm_object_scroll_freeze_pop(ad->search_gl);
83 void search_launch_contact_view(void *data, void *record_info)
87 struct appdata *ad = (struct appdata *)data;
88 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
90 SEARCH_RET_IF(ad == NULL);
91 SEARCH_RET_IF(cur_category_mem == NULL);
93 service_h service = NULL;
95 bool err_popup_show = true;
97 Ecore_X_Window win_id = -1;
99 win_id = elm_win_xwindow_get(ad->win_main);
101 ret = service_create(&service);
102 if (ret != SERVICE_ERROR_NONE) {
103 SEARCH_DEBUG_ERROR("[Fail] service_create");
107 ret = service_set_app_id(service, "contacts-details-efl");
108 if (ret != SERVICE_ERROR_NONE) {
109 SEARCH_DEBUG_ERROR("[Fail] service_set_app_id!");
113 ret = service_set_window(service, win_id);
114 if (ret != SERVICE_ERROR_NONE) {
115 SEARCH_DEBUG_ERROR("[Fail] service_set_window!");
119 ret = service_add_extra_data(service, "type", "0");;
120 if (ret != SERVICE_ERROR_NONE) {
121 SEARCH_DEBUG_ERROR("[Fail] service_add_extra_data : type!");
125 ret = service_add_extra_data(service, "person_id", cur_category_mem->launch_param);
126 if (ret != SERVICE_ERROR_NONE) {
127 SEARCH_DEBUG_ERROR("[Fail] service_add_extra_data : person_id");
131 ret = service_send_launch_request(service, NULL, NULL);
132 if (ret != SERVICE_ERROR_NONE) {
133 SEARCH_DEBUG_ERROR("[Fail] service_send_launch_request");
136 err_popup_show = false;
140 if (err_popup_show == true) {
141 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
144 if (service != NULL) {
145 service_destroy(service);
151 void search_launch_msg_view(void *data, void *record_info)
155 struct appdata *ad = (struct appdata *)data;
156 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
158 SEARCH_RET_IF(ad == NULL);
159 SEARCH_RET_IF(cur_category_mem == NULL);
161 service_h service = NULL;
163 bool err_popup_show = true;
165 ret = service_create(&service);
166 if (ret != SERVICE_ERROR_NONE) {
167 SEARCH_DEBUG_ERROR("[Fail] service_create");
171 ret = service_set_package(service, "org.tizen.message");
172 if (ret != SERVICE_ERROR_NONE) {
173 SEARCH_DEBUG_ERROR("[Fail] service_set_package!");
177 ret = service_add_extra_data(service, "type", "msg_id");
178 if (ret != SERVICE_ERROR_NONE) {
179 SEARCH_DEBUG_ERROR("[Fail] service_set_extra_data : msg_id");
183 ret = service_add_extra_data(service, "msgId", cur_category_mem->launch_param);
184 if (ret != SERVICE_ERROR_NONE) {
185 SEARCH_DEBUG_ERROR("[Fail] service_set_extra_data : msgId parameter!");
189 ret = service_send_launch_request(service, NULL, NULL);
190 if (ret != SERVICE_ERROR_NONE) {
191 SEARCH_DEBUG_ERROR("[Fail] service_send_launch_request");
194 err_popup_show = false;
198 if (err_popup_show == true) {
199 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
202 if (service != NULL) {
203 service_destroy(service);
209 void search_launch_email_view(void *data, void *record_info)
213 char *token_param = NULL;
217 bool err_popup_show = true;
219 struct appdata *ad = (struct appdata *)data;
220 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
222 char temp_path[MAX_LENGTH_PER_PATH] = { 0, };
224 service_h service = NULL;
226 SEARCH_RET_IF(ad == NULL);
227 SEARCH_RET_IF(cur_category_mem == NULL);
229 ret = service_create(&service);
230 if (ret != SERVICE_ERROR_NONE) {
231 SEARCH_DEBUG_ERROR("Fail to create service handle!");
235 snprintf(temp_path, MAX_LENGTH_PER_PATH - 1, "%s", cur_category_mem->launch_path);
236 token_param = strtok_r(temp_path, " ", &saveptr1);
238 while (token_param != NULL) {
239 SEARCH_DEBUG_LOG("PARAMETER (%d) : %s", i, token_param);
241 ret = service_add_extra_data(service, "ACCOUNT_ID", token_param);
242 if (ret != SERVICE_ERROR_NONE) {
243 SEARCH_DEBUG_ERROR("Fail to add extra data : ACCOUND_ID!");
247 ret = service_add_extra_data(service, "MAIL_ID", token_param);
248 if (ret != SERVICE_ERROR_NONE) {
249 SEARCH_DEBUG_ERROR("Fail to add extra data : MAIL_ID!");
253 ret = service_add_extra_data(service, "MAILBOX_ID", token_param);
254 if (ret != SERVICE_ERROR_NONE) {
255 SEARCH_DEBUG_ERROR("Fail to add extra data : MAILBOX_ID!");
263 token_param = strtok_r(NULL, " ", &saveptr1);
266 ret = service_add_extra_data(service, "RUN_TYPE", "7");
267 if (ret != SERVICE_ERROR_NONE) {
268 SEARCH_DEBUG_ERROR("Fail to add extra data : RUN_TYPE!");
272 ret = service_set_package(service, "org.tizen.email");
273 if (ret != SERVICE_ERROR_NONE) {
274 SEARCH_DEBUG_ERROR("Fail to set package!");
278 ret = service_send_launch_request(service, NULL, NULL);
279 if (ret != SERVICE_ERROR_NONE) {
280 SEARCH_DEBUG_ERROR("Fail to send service!");
283 err_popup_show = false;
286 if (err_popup_show == true) {
287 search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad);
290 if (service != NULL) {
291 ret = service_destroy(service);
293 if (ret != SERVICE_ERROR_NONE) {
294 SEARCH_DEBUG_ERROR("Fail to destroy service header : [%d]", ret);
301 void search_launch_image_view(void *data, void *record_info)
305 struct appdata *ad = (struct appdata *)data;
306 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
309 SEARCH_RET_IF(ad == NULL);
310 SEARCH_RET_IF(cur_category_mem == NULL);
312 if (access(cur_category_mem->launch_path, F_OK) != 0) {
313 SEARCH_DEBUG_ERROR("image access error : %s",
314 cur_category_mem->launch_path);
315 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND,
318 SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
319 cur_category_mem->launch_path);
322 ret = service_create(&service);
325 service_set_operation(service, SERVICE_OPERATION_VIEW);
326 service_set_uri(service, cur_category_mem->launch_path);
327 ret = service_send_launch_request(service, NULL, NULL);
330 SEARCH_DEBUG_ERROR("image app service launching error(%d)", ret);
331 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
334 service_destroy(service);
341 void search_launch_video_view(void *data, void *record_info)
345 struct appdata *ad = (struct appdata *)data;
346 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
349 SEARCH_RET_IF(ad == NULL);
350 SEARCH_RET_IF(cur_category_mem == NULL);
352 if (access(cur_category_mem->launch_path, F_OK) != 0) {
353 SEARCH_DEBUG_ERROR("video access error : %s",
354 cur_category_mem->launch_path);
355 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad);
357 SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
358 cur_category_mem->launch_path);
361 ret = service_create(&service);
364 service_set_operation(service, SERVICE_OPERATION_VIEW);
365 service_set_uri(service, cur_category_mem->launch_path);
366 ret = service_send_launch_request(service, NULL, NULL);
369 SEARCH_DEBUG_ERROR("video app service launching error(%d)", ret);
370 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
373 service_destroy(service);
380 void search_launch_music_view(void *data, void *record_info)
384 struct appdata *ad = (struct appdata *)data;
385 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
388 SEARCH_RET_IF(ad == NULL);
389 SEARCH_RET_IF(cur_category_mem == NULL);
391 if (access(cur_category_mem->launch_path, F_OK) != 0) {
392 SEARCH_DEBUG_ERROR("music file access error : %s",
393 cur_category_mem->launch_path);
394 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad);
396 SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
397 cur_category_mem->launch_path);
400 ret = service_create(&service);
403 service_set_operation(service, SERVICE_OPERATION_VIEW);
404 service_set_uri(service, cur_category_mem->launch_path);
405 ret = service_send_launch_request(service, NULL, NULL);
408 SEARCH_DEBUG_ERROR("music app service launching error(%d)", ret);
409 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
412 service_destroy(service);
419 void search_launch_calendar_view(void *data, void *record_info)
423 struct appdata *ad = (struct appdata *)data;
424 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
425 ui_gadget_h ug = NULL;
426 struct ug_cbs cbs = { 0, };
428 bool err_popup_show = true;
429 service_h service = NULL;
431 SEARCH_RET_IF(ad == NULL);
432 SEARCH_RET_IF(cur_category_mem == NULL);
434 if (strlen(cur_category_mem->launch_param) <= 0) {
435 SEARCH_DEBUG_ERROR("Selected item does not have data!");
438 ret = service_create(&service);
440 if (ret != SERVICE_ERROR_NONE) {
441 SEARCH_DEBUG_ERROR("Fail to create service handle!");
445 ret = service_add_extra_data(service, "itemType", "event");
447 if (ret != SERVICE_ERROR_NONE) {
448 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
452 ret = service_add_extra_data(service, "eventId", cur_category_mem->launch_param);
454 if (ret != SERVICE_ERROR_NONE) {
455 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 2!");
459 cbs.destroy_cb = __search_ug_closed_cb;
460 cbs.layout_cb = __search_ug_layout_cb;
461 cbs.result_cb = NULL;
464 ug = ug_create(NULL, "calendar-detail-efl", UG_MODE_FULLVIEW, service, &cbs);
467 SEARCH_DEBUG_ERROR("... create_ug_calendar : failed !!!");
472 err_popup_show = false;
476 if (err_popup_show == true) {
477 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
480 if (service != NULL) {
481 service_destroy(service);
487 void search_launch_memo_view(void *data, void *record_info)
491 struct appdata *ad = (struct appdata *)data;
492 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
493 ui_gadget_h ug = NULL;
494 struct ug_cbs cbs = { 0, };
497 bool err_popup_show = true;
499 service_h service = NULL;
501 SEARCH_RET_IF(ad == NULL);
502 SEARCH_RET_IF(cur_category_mem == NULL);
504 if (strlen(cur_category_mem->launch_param) <= 0) {
505 SEARCH_DEBUG_ERROR("Selected item does not have data!");
509 SEARCH_DEBUG_WARNING("prev ug is exist. destroy prev ug");
511 ad->detail_ug = NULL;
514 ret = service_create(&service);
516 if (ret != SERVICE_ERROR_NONE) {
517 SEARCH_DEBUG_ERROR("Fail to create service handle!");
521 ret = service_add_extra_data(service, "index", cur_category_mem->launch_param);
523 if (ret != SERVICE_ERROR_NONE) {
524 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
528 cbs.layout_cb = __search_ug_layout_cb;
529 cbs.result_cb = NULL;
530 cbs.destroy_cb = __search_ug_closed_cb;
533 ug = ug_create(NULL, "memo-efl", UG_MODE_FULLVIEW, service, &cbs);
536 SEARCH_DEBUG_ERROR("... create_ug_email : failed !!!");
541 err_popup_show = false;
545 if (err_popup_show == true) {
546 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
549 if (service != NULL) {
550 service_destroy(service);
556 void search_launch_menu_view(void *data, void *record_info)
560 struct appdata *ad = (struct appdata *)data;
561 struct search_item_sel *cur_category_mem =
562 (struct search_item_sel *)record_info;
563 char *pkg_name = NULL;
564 bool is_running = false;
567 bool err_popup_show = true;
569 service_h service = NULL;
571 SEARCH_RET_IF(ad == NULL);
572 SEARCH_RET_IF(cur_category_mem == NULL);
574 pkg_name = cur_category_mem->launch_path;
576 if (pkg_name != NULL && strlen(pkg_name)) {
577 ret = app_manager_is_running(pkg_name, &is_running);
579 if (ret != APP_MANAGER_ERROR_NONE) {
580 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_is_running [%d]", ret);
584 if (is_running == true) {
585 ret = app_manager_get_app_context(pkg_name, &app_h);
586 if (ret != APP_MANAGER_ERROR_NONE) {
587 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_get_app_context [%d]", ret);
591 ret = app_manager_resume_app(app_h);
593 if (ret != APP_MANAGER_ERROR_NONE) {
594 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_resume_app [%d]", ret);
597 err_popup_show = false;
599 ret = service_create(&service);
601 if (ret != SERVICE_ERROR_NONE) {
602 SEARCH_DEBUG_ERROR("Fail to create service header : [%d]", ret);
606 ret = service_set_operation(service, SERVICE_OPERATION_DEFAULT);
608 if (ret != SERVICE_ERROR_NONE) {
609 SEARCH_DEBUG_ERROR("Fail to set operation : [%d]", ret);
613 ret = service_set_package(service, pkg_name);
615 if (ret != SERVICE_ERROR_NONE) {
616 SEARCH_DEBUG_ERROR("Fail to set package : [%d]", ret);
620 ret = service_send_launch_request(service, NULL, NULL);
622 if (ret != SERVICE_ERROR_NONE) {
623 SEARCH_DEBUG_ERROR("Fail to send launch request : [%d]", ret);
626 err_popup_show = false;
629 SEARCH_DEBUG_ERROR("Pkg name is NULL!");
633 if (err_popup_show == true)
634 search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad);
636 if (service != NULL) {
637 ret = service_destroy(service);
639 if (ret != SERVICE_ERROR_NONE)
640 SEARCH_DEBUG_ERROR("Fail to destroy service header : [%d]", ret);
646 void search_launch_browser_view(void *data, void *record_info)
650 struct appdata *ad = (struct appdata *)data;
651 struct search_item_sel *cur_category_mem =
652 (struct search_item_sel *)record_info;
656 SEARCH_RET_IF(ad == NULL);
657 SEARCH_RET_IF(cur_category_mem == NULL);
659 SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s", cur_category_mem->launch_path);
661 ret = service_create(&service);
663 if (ret == 0 && strlen(cur_category_mem->launch_path) > 0 ) {
664 service_set_operation(service, SERVICE_OPERATION_VIEW);
665 service_set_uri(service, cur_category_mem->launch_path);
666 ret = service_send_launch_request(service, NULL, NULL);
669 SEARCH_DEBUG_ERROR("browser app service launching error(%d)", ret);
670 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
673 service_destroy(service);
678 static void __search_launch_popup_error_response_cb(void *data,
684 struct appdata *ad = (struct appdata *)data;
685 SEARCH_RET_IF(ad == NULL);
687 evas_object_del(ad->ctxpopup);
693 void search_launch_popup_error(int error_type, void *data)
698 struct appdata *ad = (struct appdata *)data;
700 SEARCH_RET_IF(ad == NULL);
702 if (error_type >= LAUNCH_ERROR_MAX) {
703 SEARCH_DEBUG_ERROR("wrong error_type : %d", error_type);
707 evas_object_del(ad->ctxpopup);
711 elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT);
713 if (elm_object_scroll_freeze_get(ad->search_gl) > 0) {
714 elm_object_scroll_freeze_pop(ad->search_gl);
717 popup = elm_popup_add(ad->win_main);
718 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
722 case LAUNCH_ERROR_FILE_NOT_FOUND:
723 elm_object_text_set(popup,
724 dgettext("sys_string",
725 "IDS_COM_POP_FILE_NOT_FOUND"));
727 case LAUNCH_ERROR_AUL_LAUNCH:
728 /* This Message String enable to be another string in the future */
729 elm_object_text_set(popup,
730 gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST"));
732 case LAUNCH_ERROR_APPSVC:
733 elm_object_text_set(popup,
734 gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST"));
738 btn1 = elm_button_add(popup);
739 elm_object_style_set(btn1, "popup_button/default");
741 elm_object_text_set(btn1,
742 dgettext("sys_string","IDS_COM_POP_CLOSE"));
743 evas_object_smart_callback_add(btn1, "clicked",
744 __search_launch_popup_error_response_cb,
747 elm_object_part_content_set(popup, "button1", btn1);
749 elm_popup_timeout_set(popup, 3.0);
751 evas_object_smart_callback_add(popup, "timeout",
752 __search_launch_popup_error_response_cb,
754 evas_object_smart_callback_add(popup, "block,clicked",
755 __search_launch_popup_error_response_cb,
757 evas_object_show(popup);
759 ad->ctxpopup = popup;