2 * Copyright 2012-2013 Samsung Electronics Co., Ltd/
4 * Licensed under the Flora License, Version 1.0 (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.
22 #include "smartsearch.h"
23 #include "ps_app_interface.h"
24 #include "ps_searcher.h"
25 #include <ui-gadget.h>
26 #include <contacts-ug.h>
27 #include <aul_service.h>
29 #include <app_manager.h>
32 static void __search_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode,
37 Evas_Object *base = NULL; (Evas_Object *) ug_get_layout(ug);
38 Evas_Object *win = NULL;
40 SEARCH_RET_IF(ug == NULL || priv == NULL);
42 base = (Evas_Object *)ug_get_layout(ug);
43 win = (Evas_Object *)ug_get_window();
45 SEARCH_RET_IF(base == NULL);
46 SEARCH_RET_IF(win == NULL);
49 case UG_MODE_FULLVIEW:
50 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
51 elm_win_resize_object_add(win, base);
52 evas_object_show(base);
61 static void __search_ug_closed_cb(ui_gadget_h ug, void *priv)
65 struct appdata *ad = (struct appdata *)priv;
67 SEARCH_RET_IF(ug == NULL);
68 SEARCH_RET_IF(ad == NULL);
73 elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT);
75 if (elm_object_scroll_freeze_get(ad->search_gl) > 0) {
76 elm_object_scroll_freeze_pop(ad->search_gl);
82 void search_launch_contact_view(void *data, void *record_info)
86 struct appdata *ad = (struct appdata *)data;
87 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
89 SEARCH_RET_IF(ad == NULL);
90 SEARCH_RET_IF(cur_category_mem == NULL);
92 service_h service = NULL;
94 bool err_popup_show = true;
96 Ecore_X_Window win_id = -1;
98 win_id = elm_win_xwindow_get(ad->win_main);
100 ret = service_create(&service);
101 if (ret != SERVICE_ERROR_NONE) {
102 SEARCH_DEBUG_ERROR("[Fail] service_create");
106 ret = service_set_app_id(service, "contacts-details-efl");
107 if (ret != SERVICE_ERROR_NONE) {
108 SEARCH_DEBUG_ERROR("[Fail] service_set_app_id!");
112 ret = service_set_window(service, win_id);
113 if (ret != SERVICE_ERROR_NONE) {
114 SEARCH_DEBUG_ERROR("[Fail] service_set_window!");
118 ret = service_add_extra_data(service, "type", "0");;
119 if (ret != SERVICE_ERROR_NONE) {
120 SEARCH_DEBUG_ERROR("[Fail] service_add_extra_data : type!");
124 ret = service_add_extra_data(service, "person_id", cur_category_mem->launch_param);
125 if (ret != SERVICE_ERROR_NONE) {
126 SEARCH_DEBUG_ERROR("[Fail] service_add_extra_data : person_id");
130 ret = service_send_launch_request(service, NULL, NULL);
131 if (ret != SERVICE_ERROR_NONE) {
132 SEARCH_DEBUG_ERROR("[Fail] service_send_launch_request");
135 err_popup_show = false;
139 if (err_popup_show == true) {
140 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
143 if (service != NULL) {
144 service_destroy(service);
150 void search_launch_msg_view(void *data, void *record_info)
154 struct appdata *ad = (struct appdata *)data;
155 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
157 SEARCH_RET_IF(ad == NULL);
158 SEARCH_RET_IF(cur_category_mem == NULL);
160 service_h service = NULL;
162 bool err_popup_show = true;
164 ret = service_create(&service);
165 if (ret != SERVICE_ERROR_NONE) {
166 SEARCH_DEBUG_ERROR("[Fail] service_create");
170 ret = service_set_package(service, "org.tizen.message");
171 if (ret != SERVICE_ERROR_NONE) {
172 SEARCH_DEBUG_ERROR("[Fail] service_set_package!");
176 ret = service_add_extra_data(service, "type", "msg_id");
177 if (ret != SERVICE_ERROR_NONE) {
178 SEARCH_DEBUG_ERROR("[Fail] service_set_extra_data : msg_id");
182 ret = service_add_extra_data(service, "msgId", cur_category_mem->launch_param);
183 if (ret != SERVICE_ERROR_NONE) {
184 SEARCH_DEBUG_ERROR("[Fail] service_set_extra_data : msgId parameter!");
188 ret = service_send_launch_request(service, NULL, NULL);
189 if (ret != SERVICE_ERROR_NONE) {
190 SEARCH_DEBUG_ERROR("[Fail] service_send_launch_request");
193 err_popup_show = false;
197 if (err_popup_show == true) {
198 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
201 if (service != NULL) {
202 service_destroy(service);
208 void search_launch_email_view(void *data, void *record_info)
212 char *token_param = NULL;
216 bool err_popup_show = true;
218 struct appdata *ad = (struct appdata *)data;
219 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
221 char temp_path[MAX_LENGTH_PER_PATH] = { 0, };
223 service_h service = NULL;
225 SEARCH_RET_IF(ad == NULL);
226 SEARCH_RET_IF(cur_category_mem == NULL);
228 ret = service_create(&service);
229 if (ret != SERVICE_ERROR_NONE) {
230 SEARCH_DEBUG_ERROR("Fail to create service handle!");
234 snprintf(temp_path, MAX_LENGTH_PER_PATH - 1, "%s", cur_category_mem->launch_path);
235 token_param = strtok_r(temp_path, " ", &saveptr1);
237 while (token_param != NULL) {
238 SEARCH_DEBUG_LOG("PARAMETER (%d) : %s", i, token_param);
240 ret = service_add_extra_data(service, "ACCOUNT_ID", token_param);
241 if (ret != SERVICE_ERROR_NONE) {
242 SEARCH_DEBUG_ERROR("Fail to add extra data : ACCOUND_ID!");
246 ret = service_add_extra_data(service, "MAIL_ID", token_param);
247 if (ret != SERVICE_ERROR_NONE) {
248 SEARCH_DEBUG_ERROR("Fail to add extra data : MAIL_ID!");
252 ret = service_add_extra_data(service, "MAILBOX_ID", token_param);
253 if (ret != SERVICE_ERROR_NONE) {
254 SEARCH_DEBUG_ERROR("Fail to add extra data : MAILBOX_ID!");
262 token_param = strtok_r(NULL, " ", &saveptr1);
265 ret = service_add_extra_data(service, "RUN_TYPE", "7");
266 if (ret != SERVICE_ERROR_NONE) {
267 SEARCH_DEBUG_ERROR("Fail to add extra data : RUN_TYPE!");
271 ret = service_set_package(service, "org.tizen.email");
272 if (ret != SERVICE_ERROR_NONE) {
273 SEARCH_DEBUG_ERROR("Fail to set package!");
277 ret = service_send_launch_request(service, NULL, NULL);
278 if (ret != SERVICE_ERROR_NONE) {
279 SEARCH_DEBUG_ERROR("Fail to send service!");
282 err_popup_show = false;
285 if (err_popup_show == true) {
286 search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad);
289 if (service != NULL) {
290 ret = service_destroy(service);
292 if (ret != SERVICE_ERROR_NONE) {
293 SEARCH_DEBUG_ERROR("Fail to destroy service header : [%d]", ret);
300 void search_launch_image_view(void *data, void *record_info)
304 struct appdata *ad = (struct appdata *)data;
305 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
308 SEARCH_RET_IF(ad == NULL);
309 SEARCH_RET_IF(cur_category_mem == NULL);
311 if (access(cur_category_mem->launch_path, F_OK) != 0) {
312 SEARCH_DEBUG_ERROR("image access error : %s",
313 cur_category_mem->launch_path);
314 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND,
317 SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
318 cur_category_mem->launch_path);
321 ret = service_create(&service);
324 service_set_operation(service, SERVICE_OPERATION_VIEW);
325 service_set_uri(service, cur_category_mem->launch_path);
326 ret = service_send_launch_request(service, NULL, NULL);
329 SEARCH_DEBUG_ERROR("image app service launching error(%d)", ret);
330 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
333 service_destroy(service);
340 void search_launch_video_view(void *data, void *record_info)
344 struct appdata *ad = (struct appdata *)data;
345 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
348 SEARCH_RET_IF(ad == NULL);
349 SEARCH_RET_IF(cur_category_mem == NULL);
351 if (access(cur_category_mem->launch_path, F_OK) != 0) {
352 SEARCH_DEBUG_ERROR("video access error : %s",
353 cur_category_mem->launch_path);
354 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad);
356 SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
357 cur_category_mem->launch_path);
360 ret = service_create(&service);
363 service_set_operation(service, SERVICE_OPERATION_VIEW);
364 service_set_uri(service, cur_category_mem->launch_path);
365 ret = service_send_launch_request(service, NULL, NULL);
368 SEARCH_DEBUG_ERROR("video app service launching error(%d)", ret);
369 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
372 service_destroy(service);
379 void search_launch_music_view(void *data, void *record_info)
383 struct appdata *ad = (struct appdata *)data;
384 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
387 SEARCH_RET_IF(ad == NULL);
388 SEARCH_RET_IF(cur_category_mem == NULL);
390 if (access(cur_category_mem->launch_path, F_OK) != 0) {
391 SEARCH_DEBUG_ERROR("music file access error : %s",
392 cur_category_mem->launch_path);
393 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad);
395 SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
396 cur_category_mem->launch_path);
399 ret = service_create(&service);
402 service_set_operation(service, SERVICE_OPERATION_VIEW);
403 service_set_uri(service, cur_category_mem->launch_path);
404 ret = service_send_launch_request(service, NULL, NULL);
407 SEARCH_DEBUG_ERROR("music app service launching error(%d)", ret);
408 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
411 service_destroy(service);
418 void search_launch_calendar_view(void *data, void *record_info)
422 struct appdata *ad = (struct appdata *)data;
423 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
424 ui_gadget_h ug = NULL;
425 struct ug_cbs cbs = { 0, };
427 bool err_popup_show = true;
428 service_h service = NULL;
430 SEARCH_RET_IF(ad == NULL);
431 SEARCH_RET_IF(cur_category_mem == NULL);
433 if (strlen(cur_category_mem->launch_param) <= 0) {
434 SEARCH_DEBUG_ERROR("Selected item does not have data!");
437 ret = service_create(&service);
439 if (ret != SERVICE_ERROR_NONE) {
440 SEARCH_DEBUG_ERROR("Fail to create service handle!");
444 ret = service_add_extra_data(service, "itemType", "event");
446 if (ret != SERVICE_ERROR_NONE) {
447 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
451 ret = service_add_extra_data(service, "eventId", cur_category_mem->launch_param);
453 if (ret != SERVICE_ERROR_NONE) {
454 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 2!");
458 cbs.destroy_cb = __search_ug_closed_cb;
459 cbs.layout_cb = __search_ug_layout_cb;
460 cbs.result_cb = NULL;
463 ug = ug_create(NULL, "calendar-detail-efl", UG_MODE_FULLVIEW, service, &cbs);
466 SEARCH_DEBUG_ERROR("... create_ug_calendar : failed !!!");
471 err_popup_show = false;
475 if (err_popup_show == true) {
476 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
479 if (service != NULL) {
480 service_destroy(service);
486 void search_launch_memo_view(void *data, void *record_info)
490 struct appdata *ad = (struct appdata *)data;
491 struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
492 ui_gadget_h ug = NULL;
493 struct ug_cbs cbs = { 0, };
496 bool err_popup_show = true;
498 service_h service = NULL;
500 SEARCH_RET_IF(ad == NULL);
501 SEARCH_RET_IF(cur_category_mem == NULL);
503 if (strlen(cur_category_mem->launch_param) <= 0) {
504 SEARCH_DEBUG_ERROR("Selected item does not have data!");
508 SEARCH_DEBUG_WARNING("prev ug is exist. destroy prev ug");
510 ad->detail_ug = NULL;
513 ret = service_create(&service);
515 if (ret != SERVICE_ERROR_NONE) {
516 SEARCH_DEBUG_ERROR("Fail to create service handle!");
520 ret = service_add_extra_data(service, "index", cur_category_mem->launch_param);
522 if (ret != SERVICE_ERROR_NONE) {
523 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
527 cbs.layout_cb = __search_ug_layout_cb;
528 cbs.result_cb = NULL;
529 cbs.destroy_cb = __search_ug_closed_cb;
532 ug = ug_create(NULL, "memo-efl", UG_MODE_FULLVIEW, service, &cbs);
535 SEARCH_DEBUG_ERROR("... create_ug_email : failed !!!");
540 err_popup_show = false;
544 if (err_popup_show == true) {
545 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
548 if (service != NULL) {
549 service_destroy(service);
555 void search_launch_menu_view(void *data, void *record_info)
559 struct appdata *ad = (struct appdata *)data;
560 struct search_item_sel *cur_category_mem =
561 (struct search_item_sel *)record_info;
562 char *pkg_name = NULL;
563 bool is_running = false;
566 bool err_popup_show = true;
568 service_h service = NULL;
570 SEARCH_RET_IF(ad == NULL);
571 SEARCH_RET_IF(cur_category_mem == NULL);
573 pkg_name = cur_category_mem->launch_path;
575 if (pkg_name != NULL && strlen(pkg_name)) {
576 ret = app_manager_is_running(pkg_name, &is_running);
578 if (ret != APP_MANAGER_ERROR_NONE) {
579 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_is_running [%d]", ret);
583 if (is_running == true) {
584 ret = app_manager_get_app_context(pkg_name, &app_h);
585 if (ret != APP_MANAGER_ERROR_NONE) {
586 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_get_app_context [%d]", ret);
590 ret = app_manager_resume_app(app_h);
592 if (ret != APP_MANAGER_ERROR_NONE) {
593 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_resume_app [%d]", ret);
596 err_popup_show = false;
598 ret = service_create(&service);
600 if (ret != SERVICE_ERROR_NONE) {
601 SEARCH_DEBUG_ERROR("Fail to create service header : [%d]", ret);
605 ret = service_set_operation(service, SERVICE_OPERATION_DEFAULT);
607 if (ret != SERVICE_ERROR_NONE) {
608 SEARCH_DEBUG_ERROR("Fail to set operation : [%d]", ret);
612 ret = service_set_package(service, pkg_name);
614 if (ret != SERVICE_ERROR_NONE) {
615 SEARCH_DEBUG_ERROR("Fail to set package : [%d]", ret);
619 ret = service_send_launch_request(service, NULL, NULL);
621 if (ret != SERVICE_ERROR_NONE) {
622 SEARCH_DEBUG_ERROR("Fail to send launch request : [%d]", ret);
625 err_popup_show = false;
628 SEARCH_DEBUG_ERROR("Pkg name is NULL!");
632 if (err_popup_show == true)
633 search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad);
635 if (service != NULL) {
636 ret = service_destroy(service);
638 if (ret != SERVICE_ERROR_NONE)
639 SEARCH_DEBUG_ERROR("Fail to destroy service header : [%d]", ret);
645 void search_launch_browser_view(void *data, void *record_info)
649 struct appdata *ad = (struct appdata *)data;
650 struct search_item_sel *cur_category_mem =
651 (struct search_item_sel *)record_info;
655 SEARCH_RET_IF(ad == NULL);
656 SEARCH_RET_IF(cur_category_mem == NULL);
658 SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s", cur_category_mem->launch_path);
660 ret = service_create(&service);
662 if (ret == 0 && strlen(cur_category_mem->launch_path) > 0 ) {
663 service_set_operation(service, SERVICE_OPERATION_VIEW);
664 service_set_uri(service, cur_category_mem->launch_path);
665 ret = service_send_launch_request(service, NULL, NULL);
668 SEARCH_DEBUG_ERROR("browser app service launching error(%d)", ret);
669 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
672 service_destroy(service);
677 static void __search_launch_popup_error_response_cb(void *data,
683 struct appdata *ad = (struct appdata *)data;
684 SEARCH_RET_IF(ad == NULL);
686 evas_object_del(ad->ctxpopup);
692 void search_launch_popup_error(int error_type, void *data)
697 struct appdata *ad = (struct appdata *)data;
699 SEARCH_RET_IF(ad == NULL);
701 if (error_type >= LAUNCH_ERROR_MAX) {
702 SEARCH_DEBUG_ERROR("wrong error_type : %d", error_type);
706 evas_object_del(ad->ctxpopup);
710 elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT);
712 if (elm_object_scroll_freeze_get(ad->search_gl) > 0) {
713 elm_object_scroll_freeze_pop(ad->search_gl);
716 popup = elm_popup_add(ad->win_main);
717 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
721 case LAUNCH_ERROR_FILE_NOT_FOUND:
722 elm_object_text_set(popup,
723 dgettext("sys_string",
724 "IDS_COM_POP_FILE_NOT_FOUND"));
726 case LAUNCH_ERROR_AUL_LAUNCH:
727 /* This Message String enable to be another string in the future */
728 elm_object_text_set(popup,
729 gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST"));
731 case LAUNCH_ERROR_APPSVC:
732 elm_object_text_set(popup,
733 gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST"));
737 btn1 = elm_button_add(popup);
738 elm_object_style_set(btn1, "popup_button/default");
740 elm_object_text_set(btn1,
741 dgettext("sys_string","IDS_COM_POP_CLOSE"));
742 evas_object_smart_callback_add(btn1, "clicked",
743 __search_launch_popup_error_response_cb,
746 elm_object_part_content_set(popup, "button1", btn1);
748 elm_popup_timeout_set(popup, 3.0);
750 evas_object_smart_callback_add(popup, "timeout",
751 __search_launch_popup_error_response_cb,
753 evas_object_smart_callback_add(popup, "block,clicked",
754 __search_launch_popup_error_response_cb,
756 evas_object_show(popup);
758 ad->ctxpopup = popup;