2 * Copyright 2012 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://www.tizenopensource.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 #define UG_NAME_LEN 50
34 static void __search_layout_ug_destroy(void *data)
38 struct appdata *ad = (struct appdata *)data;
40 //D. Because the ug will be able to remove the base object, unset the content from the effect layout.
41 elm_object_part_content_unset(ad->effect_layout,
42 (char *)ug_get_layout(ad->detail_ug));
44 evas_object_del(ad->effect_layout);
46 ug_destroy(ad->detail_ug);
49 ad->effect_layout = NULL;
54 static void __search_effect_layout_signal_hide_finished(void *data,
61 __search_layout_ug_destroy(data);
66 static void __search_effect_layout_render_flush_post_cb(void *data, Evas * e,
71 struct appdata *ad = (struct appdata *)data;
76 edje_object_signal_emit(elm_layout_edje_get(ad->effect_layout),
77 "elm,state,show", "");
79 //B.Remove the EVAS_RENDER_FLUSH_POST callback again.
80 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST,
81 __search_effect_layout_render_flush_post_cb);
86 static void __search_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode,
91 Evas_Object *base = (Evas_Object *) ug_get_layout(ug);
96 #ifdef ENABLE_UG_EFFECT
97 if (!ad->effect_layout)
100 elm_object_part_content_set(ad->effect_layout, "elm.swallow.content", base);
101 //B. Add the callback event for the EVAS_RENDER_FLUSH_POST
102 //B. This is one method to not skip the total effect time in creating the ug object.
103 evas_event_callback_add(evas_object_evas_get(ad->effect_layout),
104 EVAS_CALLBACK_RENDER_FLUSH_POST,
105 __search_effect_layout_render_flush_post_cb,
108 evas_object_show(base);
114 static void __search_ug_closed_cb(ui_gadget_h ug, void *priv)
118 #ifdef ENABLE_UG_EFFECT
119 edje_object_signal_emit(elm_layout_edje_get(ad->effect_layout),
120 "elm,state,hide", "");
122 Evas_Object *base = (Evas_Object *) ug_get_layout(ug);
124 evas_object_hide(base);
130 static void __search_create_effect_layout(Evas_Object * parent,
137 //Create the layout then apply the edj
138 Evas_Object *ly = elm_layout_add(ad->win_main);
143 evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
145 elm_win_resize_object_add(ad->win_main, ly);
147 ret = elm_layout_file_set(ly, SEARCH_EDJ, "ug_effect");
149 //Add a signal callback function which will be called after terminating hide effect.
150 edje_object_signal_callback_add(elm_layout_edje_get(ly),
151 "elm,action,hide,finished", "",
152 __search_effect_layout_signal_hide_finished,
155 //store the layout object to refer it at hide effect
156 ad->effect_layout = ly;
158 evas_object_show(ly);
163 void search_launch_contact_view(void *data, void *record_info)
167 struct appdata *ad = (struct appdata *)data;
168 struct search_item_sel *cur_category_mem =
169 (struct search_item_sel *)record_info;
171 service_h service = NULL;
173 bool err_popup_show = true;
175 ui_gadget_h ug = NULL;
176 struct ug_cbs cbs = { 0, };
178 char buf[10] = { 0, };
180 if (!cur_category_mem || strlen(cur_category_mem->main_id) < 0 ) {
181 SEARCH_DEBUG_ERROR("Selected item does not have data!");
185 SEARCH_DEBUG_WARNING("\n prev ug is exist. destroy prev ug");
186 __search_layout_ug_destroy(ad);
189 ret = service_create(&service);
191 if (ret != SERVICE_ERROR_NONE) {
192 SEARCH_DEBUG_ERROR("Fail to create service handle!");
196 snprintf(buf, sizeof(buf), "%d", CT_UG_REQUEST_DETAIL);
197 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, buf);
199 if (ret != SERVICE_ERROR_NONE) {
200 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
204 ret = service_add_extra_data(service, CT_UG_BUNDLE_ID,
205 cur_category_mem->main_id);
207 if (ret != SERVICE_ERROR_NONE) {
208 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 2!");
212 #ifdef ENABLE_UG_EFFECT
213 __search_create_effect_layout(ad->win_main, ad);
216 cbs.layout_cb = __search_ug_layout_cb;
217 cbs.result_cb = NULL;
218 cbs.destroy_cb = __search_ug_closed_cb;
221 ug = ug_create(NULL, UG_CONTACTS_DETAILS, UG_MODE_FULLVIEW, service, &cbs);
224 SEARCH_DEBUG_ERROR(" ... ug_create: failed !!!");
228 err_popup_show = false;
233 if (err_popup_show == true)
234 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
237 service_destroy(service);
242 void search_launch_msg_view(void *data, void *record_info)
246 struct appdata *ad = (struct appdata *)data;
247 struct search_item_sel *cur_category_mem =
248 (struct search_item_sel *)record_info;
255 SEARCH_DEBUG_ERROR("search_launch_msg_view : bundle_create failed");
259 bundle_add(b, "type", "msg_id");
260 bundle_add(b, "msgId", cur_category_mem->main_id);
261 ret = aul_launch_app("org.tizen.message", b);
262 if( (ret <= 0) && (ret != AUL_R_ETIMEOUT) ){
263 SEARCH_DEBUG_ERROR("msg aul launch app error(%d)", ret);
264 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
272 void search_launch_email_view(void *data, void *record_info)
277 char *token_param = NULL;
281 struct appdata *ad = (struct appdata *)data;
282 struct search_item_sel *cur_category_mem =
283 (struct search_item_sel *)record_info;
289 char livemagazine[2] = { 0, };
290 char temp_path[MAX_LENGTH_PER_PATH] = { 0, };
291 livemagazine[0] = '0';
293 snprintf(temp_path, MAX_LENGTH_PER_PATH - 1, "%s",
294 cur_category_mem->path);
296 token_param = strtok_r(temp_path, " ", &saveptr1);
298 while (token_param != NULL) {
300 bundle_add(b, "ACCOUNT_ID", token_param); //account_id
302 bundle_add(b, "MAIL_ID", token_param); //mail_id
304 bundle_add(b, "MAILBOX_ID", token_param); //mailbox
310 token_param = strtok_r(NULL, " ", &saveptr1);
313 bundle_add(b, "bLiveMagazine", livemagazine);
315 char runType[2] = { 0 };
316 snprintf(runType, sizeof(runType), "%d", 7);
317 bundle_add(b, "RUN_TYPE", runType);
318 ret = aul_launch_app("org.tizen.email", b);
319 if( (ret <= 0) && (ret != AUL_R_ETIMEOUT) ){
320 SEARCH_DEBUG_ERROR("email aul launch app error(%d)", ret);
321 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
329 void search_launch_image_view(void *data, void *record_info)
333 struct appdata *ad = (struct appdata *)data;
334 struct search_item_sel *cur_category_mem =
335 (struct search_item_sel *)record_info;
338 if (access(cur_category_mem->path, F_OK) != 0) {
339 SEARCH_DEBUG_ERROR("image access error : %s",
340 cur_category_mem->path);
341 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND,
344 SEARCH_DEBUG_LOG("cur_category_mem->path : %s",
345 cur_category_mem->path);
348 ret = service_create(&service);
351 service_set_operation(service, SERVICE_OPERATION_VIEW);
352 service_set_uri(service, cur_category_mem->path);
353 ret = service_send_launch_request(service, NULL, NULL);
356 SEARCH_DEBUG_ERROR("image app service launching error(%d)", ret);
357 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
360 service_destroy(service);
367 void search_launch_video_view(void *data, void *record_info)
371 struct appdata *ad = (struct appdata *)data;
372 struct search_item_sel *cur_category_mem =
373 (struct search_item_sel *)record_info;
376 if (access(cur_category_mem->path, F_OK) != 0) {
377 SEARCH_DEBUG_ERROR("video access error : %s",
378 cur_category_mem->path);
379 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad);
381 SEARCH_DEBUG_LOG("cur_category_mem->path : %s",
382 cur_category_mem->path);
385 ret = service_create(&service);
388 service_set_operation(service, SERVICE_OPERATION_VIEW);
389 service_set_uri(service, cur_category_mem->path);
390 ret = service_send_launch_request(service, NULL, NULL);
393 SEARCH_DEBUG_ERROR("video app service launching error(%d)", ret);
394 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
397 service_destroy(service);
404 void search_launch_music_view(void *data, void *record_info)
408 struct appdata *ad = (struct appdata *)data;
409 struct search_item_sel *cur_category_mem =
410 (struct search_item_sel *)record_info;
413 if (access(cur_category_mem->path, F_OK) != 0) {
414 SEARCH_DEBUG_ERROR("music file access error : %s",
415 cur_category_mem->path);
416 search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad);
418 SEARCH_DEBUG_LOG("cur_category_mem->path : %s",
419 cur_category_mem->path);
422 ret = service_create(&service);
425 service_set_operation(service, SERVICE_OPERATION_VIEW);
426 service_set_uri(service, cur_category_mem->path);
427 ret = service_send_launch_request(service, NULL, NULL);
430 SEARCH_DEBUG_ERROR("music app service launching error(%d)", ret);
431 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
434 service_destroy(service);
441 void search_launch_calendar_view(void *data, void *record_info)
445 struct appdata *ad = (struct appdata *)data;
446 struct search_item_sel *cur_category_mem =
447 (struct search_item_sel *)record_info;
448 ui_gadget_h ug = NULL;
449 struct ug_cbs cbs = { 0, };
451 bool err_popup_show = true;
452 service_h service = NULL;
454 if (!cur_category_mem && strlen(cur_category_mem->main_id) < 0) {
455 SEARCH_DEBUG_ERROR("Selected item does not have data!");
458 ret = service_create(&service);
460 if (ret != SERVICE_ERROR_NONE) {
461 SEARCH_DEBUG_ERROR("Fail to create service handle!");
465 ret = service_add_extra_data(service, "itemType", "event");
467 if (ret != SERVICE_ERROR_NONE) {
468 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
472 ret = service_add_extra_data(service, "eventId", cur_category_mem->main_id);
474 if (ret != SERVICE_ERROR_NONE) {
475 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 2!");
479 #ifdef ENABLE_UG_EFFECT
480 __search_create_effect_layout(ad->win_main, ad);
482 cbs.destroy_cb = __search_ug_closed_cb;
483 cbs.layout_cb = __search_ug_layout_cb;
484 cbs.result_cb = NULL;
487 ug = ug_create(NULL, "calendar-detail-efl", UG_MODE_FULLVIEW, service, &cbs);
490 SEARCH_DEBUG_ERROR("... create_ug_calendar : failed !!!");
495 err_popup_show = false;
499 if (err_popup_show == true)
500 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
503 service_destroy(service);
508 void search_launch_memo_view(void *data, void *record_info)
512 struct appdata *ad = (struct appdata *)data;
513 struct search_item_sel *cur_category_mem =
514 (struct search_item_sel *)record_info;
515 ui_gadget_h ug = NULL;
516 struct ug_cbs cbs = { 0, };
519 bool err_popup_show = true;
521 service_h service = NULL;
523 if (!cur_category_mem && strlen(cur_category_mem->main_id) < 0) {
524 SEARCH_DEBUG_ERROR("Selected item does not have data!");
528 SEARCH_DEBUG_WARNING("prev ug is exist. destroy prev ug");
529 __search_layout_ug_destroy(ad);
532 ret = service_create(&service);
534 if (ret != SERVICE_ERROR_NONE) {
535 SEARCH_DEBUG_ERROR("Fail to create service handle!");
539 ret = service_add_extra_data(service, "index", cur_category_mem->main_id);
541 if (ret != SERVICE_ERROR_NONE) {
542 SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
546 #ifdef ENABLE_UG_EFFECT
547 __search_create_effect_layout(ad->win_main, ad);
549 cbs.layout_cb = __search_ug_layout_cb;
550 cbs.result_cb = NULL;
551 cbs.destroy_cb = __search_ug_closed_cb;
554 ug = ug_create(NULL, "memo-efl", UG_MODE_FULLVIEW, service, &cbs);
557 SEARCH_DEBUG_ERROR("... create_ug_email : failed !!!");
562 err_popup_show = false;
566 if (err_popup_show == true)
567 search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
570 service_destroy(service);
575 void search_launch_menu_view(void *data, void *record_info)
579 struct appdata *ad = (struct appdata *)data;
580 struct search_item_sel *cur_category_mem =
581 (struct search_item_sel *)record_info;
582 char *pkg_name = cur_category_mem->path;
583 bool is_running = false;
586 bool err_popup_show = true;
588 service_h service = NULL;
590 if (pkg_name != NULL && strlen(pkg_name)) {
591 ret = app_manager_is_running(pkg_name, &is_running);
593 if (ret != APP_MANAGER_ERROR_NONE) {
594 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_is_running [%d]", ret);
598 if (is_running == true) {
599 ret = app_manager_get_app_context(pkg_name, &app_h);
600 if (ret != APP_MANAGER_ERROR_NONE) {
601 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_get_app_context [%d]", ret);
605 ret = app_manager_resume_app(app_h);
607 if (ret != APP_MANAGER_ERROR_NONE) {
608 SEARCH_DEBUG_ERROR("Fail to get info : app_manager_resume_app [%d]", ret);
611 err_popup_show = false;
613 ret = service_create(&service);
615 if (ret != SERVICE_ERROR_NONE) {
616 SEARCH_DEBUG_ERROR("Fail to create service header : [%d]", ret);
620 ret = service_set_operation(service, SERVICE_OPERATION_DEFAULT);
622 if (ret != SERVICE_ERROR_NONE) {
623 SEARCH_DEBUG_ERROR("Fail to set operation : [%d]", ret);
627 ret = service_set_package(service, pkg_name);
629 if (ret != SERVICE_ERROR_NONE) {
630 SEARCH_DEBUG_ERROR("Fail to set package : [%d]", ret);
634 ret = service_send_launch_request(service, NULL, NULL);
636 if (ret != SERVICE_ERROR_NONE) {
637 SEARCH_DEBUG_ERROR("Fail to send launch request : [%d]", ret);
640 err_popup_show = false;
643 SEARCH_DEBUG_ERROR("Pkg name is NULL!");
647 if (err_popup_show == true)
648 search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad);
650 if (service != NULL) {
651 ret = service_destroy(service);
653 if (ret != SERVICE_ERROR_NONE)
654 SEARCH_DEBUG_ERROR("Fail to destroy service header : [%d]", ret);
660 void search_launch_browser_view(void *data, void *record_info)
664 struct appdata *ad = (struct appdata *)data;
665 struct search_item_sel *cur_category_mem =
666 (struct search_item_sel *)record_info;
669 SEARCH_DEBUG_LOG("cur_category_mem->path : %s",
670 cur_category_mem->path);
673 ret = service_create(&service);
675 if (ret == 0 && strlen(cur_category_mem->path) > 0 ) {
676 service_set_operation(service, SERVICE_OPERATION_VIEW);
677 service_set_uri(service, cur_category_mem->path);
678 ret = service_send_launch_request(service, NULL, NULL);
681 SEARCH_DEBUG_ERROR("browser app service launching error(%d)", ret);
682 search_launch_popup_error(LAUNCH_ERROR_APPSVC,
685 service_destroy(service);
690 static void __search_launch_popup_error_response_cb(void *data,
696 struct appdata *ad = (struct appdata *)data;
698 evas_object_del(ad->ctxpopup);
704 void search_launch_popup_error(int error_type, void *data)
709 struct appdata *ad = (struct appdata *)data;
711 if (error_type >= LAUNCH_ERROR_MAX) {
712 SEARCH_DEBUG_ERROR("wrong error_type : %d", error_type);
716 evas_object_del(ad->ctxpopup);
720 popup = elm_popup_add(ad->win_main);
721 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
725 case LAUNCH_ERROR_FILE_NOT_FOUND:
726 elm_object_text_set(popup,
727 dgettext("sys_string",
728 "IDS_COM_POP_FILE_NOT_FOUND"));
730 case LAUNCH_ERROR_AUL_LAUNCH:
731 /* This Message String enable to be another string in the future */
732 elm_object_text_set(popup,
733 gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST"));
735 case LAUNCH_ERROR_APPSVC:
736 elm_object_text_set(popup,
737 gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST"));
741 btn1 = elm_button_add(popup);
742 elm_object_style_set(btn1, "popup_button/default");
744 elm_object_text_set(btn1,
745 dgettext("sys_string","IDS_COM_POP_CLOSE"));
746 evas_object_smart_callback_add(btn1, "clicked",
747 __search_launch_popup_error_response_cb,
750 elm_object_part_content_set(popup, "button1", btn1);
752 elm_popup_timeout_set(popup, 3.0);
754 evas_object_smart_callback_add(popup, "timeout",
755 __search_launch_popup_error_response_cb,
757 evas_object_smart_callback_add(popup, "block,clicked",
758 __search_launch_popup_error_response_cb,
760 evas_object_show(popup);
762 ad->ctxpopup = popup;