summaryrefslogtreecommitdiff
path: root/src/ps_app_interface.cpp
blob: 83bfef07adece1e526592678563c3c77aba194e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/*

Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved 
 
This file is part of Smartsearch
Written by Junghyun Kim <jh1114.kim@samsung.com>
 
PROPRIETARY/CONFIDENTIAL
 
This software is the confidential and proprietary information of 
SAMSUNG ELECTRONICS (Confidential Information). You shall not 
disclose such Confidential Information and shall use it only in 
accordance with the terms of the license agreement you entered 
into with SAMSUNG ELECTRONICS.  

SAMSUNG make no representations or warranties about the suitability 
of the software, either express or implied, including but not limited
to the implied warranties of merchantability, fitness for a particular
purpose, or non-infringement. SAMSUNG shall not be liable for any
damages suffered by licensee as a result of using, modifying or 
distributing this software or its derivatives.
 
*/



#include "smartsearch.h"
#include "ps_app_interface.h"
#include "ps_searcher.h"
#include <ui-gadget.h>
#include <contacts-ug.h>
#include <aul_service.h>
#include <appsvc.h>
#include <bundle.h>

#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(struct ui_gadget *ug, enum ug_mode mode,
				  void *priv)
{
	SEARCH_FUNC_START;

	struct appdata *ad = (struct appdata *)priv;

	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(struct ui_gadget *ug, void *priv)
{
	SEARCH_FUNC_START;

	struct appdata *ad = (struct appdata *)priv;

#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;

	bundle *kb;

	struct ui_gadget *ug;
	struct ug_cbs cbs = { 0, };

	char buf[10] = { 0, };

	if (ad->detail_ug) {
		SEARCH_DEBUG_WARNING("prev ug is exist. destroy prev ug");
		__search_layout_ug_destroy(ad);
	}	

	kb = bundle_create();
	if (!kb) {
		SEARCH_DEBUG_ERROR("contact bundle_create");
		return;
	}

	snprintf(buf, sizeof(buf), "%d", CT_UG_REQUEST_DETAIL);
	bundle_add(kb, CT_UG_BUNDLE_TYPE, buf);
	bundle_add(kb, CT_UG_BUNDLE_ID, cur_category_mem->main_id);

#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, kb, &cbs);
	if (!ug) {
		SEARCH_DEBUG_ERROR(" ...  ug_create: failed !!!");
		search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
	} else {
		ad->detail_ug = ug;
	}	

	bundle_free(kb);

	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", 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);

		bundle* bd = NULL;
		bd = bundle_create();

		if (bd != NULL) {
			appsvc_set_operation(bd, APPSVC_OPERATION_VIEW);
			appsvc_set_uri(bd, cur_category_mem->path);
			ret = appsvc_run_service(bd, 0, NULL, NULL);

			if (ret < 0 )
				search_launch_popup_error(LAUNCH_ERROR_APPSVC,
							  ad);	
			bundle_free(bd);	
			}

		}

	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 {
		bundle* bd = NULL;
		bd = bundle_create();
		
		appsvc_set_operation(bd, APPSVC_OPERATION_VIEW);
		appsvc_set_uri(bd, cur_category_mem->path);
		ret = appsvc_run_service(bd, 0, NULL, NULL);
		
		if (ret < 0) {	
			SEARCH_DEBUG_ERROR("video app service error(%d) : %s",
					   ret, cur_category_mem->path);
			search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad);
		}

		bundle_free(bd);	
	}

	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);
		
		bundle* bd = NULL;
		bd = bundle_create();

		if (bd != NULL) {
			appsvc_set_operation(bd, APPSVC_OPERATION_VIEW);
			appsvc_set_uri(bd, cur_category_mem->path);
			ret = appsvc_run_service(bd, 0, NULL, NULL);

			if (ret < 0) {
				SEARCH_DEBUG_ERROR("music app service error(%d) : %s",
						   ret, cur_category_mem->path);				
				search_launch_popup_error(LAUNCH_ERROR_APPSVC,
							 	ad);
			}
			bundle_free(bd);	
		}
	}

	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;
	struct ui_gadget *ug;
	struct ug_cbs cbs = { 0, };

	bundle *b;
	int ret;

	if (ad->detail_ug) {
		SEARCH_DEBUG_WARNING("prev ug is exist. destroy prev ug");

		__search_layout_ug_destroy(ad);
	}

	b = bundle_create();
	if (!b)
		return;

	bundle_add(b, AUL_K_SERVICE_NAME, "view_event");
	bundle_add(b, "index", cur_category_mem->main_id);

	SEARCH_DEBUG_LOG("index : %s", cur_category_mem->main_id);

	ret = aul_launch_app("org.tizen.efl-calendar", b);
	if( (ret <= 0) && (ret != AUL_R_ETIMEOUT) ){	
		SEARCH_DEBUG_ERROR("calendar aul launch app error(%d)", ret);
		search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
	}

	bundle_free(b);	
	
	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;
	struct ui_gadget *ug;
	struct ug_cbs cbs = { 0, };

	bundle *b;	

	if (ad->detail_ug) {
		SEARCH_DEBUG_WARNING("prev ug is exist. destroy prev ug");

		__search_layout_ug_destroy(ad);
	}

	b = bundle_create();
	if (!b)
		return;

	bundle_add(b, "index", cur_category_mem->main_id);

	__search_create_effect_layout(ad->win_main, ad);

	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, b, &cbs);
	if (!ug) {
		SEARCH_DEBUG_ERROR("...  create_ug_email : failed !!!");
		search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
	}

	ad->detail_ug = ug;

	bundle_free(b);

	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;
	int ret;

	ret = aul_launch_app(cur_category_mem->path, NULL);

	SEARCH_DEBUG_WARNING("path : %s, ret : %d", cur_category_mem->path, ret);
	
	if( (ret <= 0) && (ret != AUL_R_ETIMEOUT) ){	
		SEARCH_DEBUG_ERROR("menu aul launch app error(%d) : %s", ret,
				   cur_category_mem->path);
		search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
	}

	SEARCH_FUNC_END;
}

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_set_result_list(ad);

	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,
					   dgettext("sys_string",
						    "IDS_COM_POP_SERVICE_UNAVAILABLE"));
			break;
		case LAUNCH_ERROR_APPSVC:
			elm_object_text_set(popup,
				   dgettext("sys_string",
					    "IDS_COM_POP_SERVICE_UNAVAILABLE"));
			break;
	}

	btn1 = elm_button_add(popup);
	elm_object_text_set(btn1,
				dgettext("sys_string","IDS_COM_SK_OK"));
	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;
}