summaryrefslogtreecommitdiff
path: root/src/util/ge-ext-ug-load.c
blob: 607aff0322317d71c1b538debf8f5427445ba4da (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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
/*
* Copyright (c) 2000-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
*
* 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 <Ecore_X.h>
#include "ge-ext-ug-load.h"
#include "ge-debug.h"
#include "ge-ui-util.h"
#include "ge-util.h"
#include "ge-albums.h"
#include "ge-gridview.h"

#define GE_IV_UG_NAME "image-viewer-efl"
#define GE_IV_STR_LEN_MAX 32
#define GE_VIEW_MODE "View Mode"
#define GE_SETAS_TYPE "Setas type"
#define GE_VIEW_BY "View By"
#define GE_MEDIA_TYPE "Media type"
#define GE_PATH "Path"
#define GE_ARGV_IV_MEDIA_ALL "All"
#define GE_ARGV_IV_VIEW_BY_FOLER "By Folder"
#define GE_ARGV_IV_ALBUM_INDEX "Album index"
#define DEFAULT_THUMB "/opt/usr/share/media/.thumb/thumb_default.png"

typedef struct _ge_thumbs_t ge_thumbs_s;

static void __ge_appcontrol_select_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
{
	GE_CHECK(user_data);
	ge_ugdata *ugd = (ge_ugdata *)user_data;
	int i;
	bool in_list = false;
	char **select_result = NULL;
	int count = 0;
	Eina_List *l = NULL;
	ge_item *data = NULL;
	int sel_count = 0;
	app_control_get_extra_data_array(reply, "Selected index", &select_result, &count);
	ge_dbg("current selection count = %d", count);

	if (select_result) {
		EINA_LIST_FOREACH(ugd->thumbs_d->medias_elist, l, data) {
			if (!data || !data->item) {
				continue;
			}
			if(!strcmp(data->item->thumb_url, DEFAULT_THUMB)){
				continue;
			}
			in_list = false;
			for (i = 0; i < count; i++) {
				if (!strcmp(select_result[i], data->item->file_url)) {
					if (!data->checked) {
						__ge_grid_append_sel_item(ugd, data);
						data->checked = true;
					}
					in_list = true;
					sel_count++;
					break;
				}
			}
			if (!in_list) {
				if (data->checked) {
					__ge_grid_remove_sel_item(ugd, data);
					data->checked = false;
				}
			}
		}
	} else {
		EINA_LIST_FOREACH(ugd->thumbs_d->medias_elist, l, data) {
			if (!data || !data->item) {
				continue;
			}
			if (data->checked) {
				__ge_grid_remove_sel_item(ugd, data);
				data->checked = false;
			}
		}
	}

	data = eina_list_nth(ugd->thumbs_d->medias_elist, 0);
	if (data && data->album && data->album->griditem) {
		elm_gengrid_item_update(data->album->griditem);
	}
	int grid_unsupported_cnt = 0;
	grid_unsupported_cnt = ugd->thumbs_d->unsupported_cnt;
	if (sel_count != (eina_list_count(ugd->thumbs_d->medias_elist) - grid_unsupported_cnt)) {
		ugd->ck_state = EINA_FALSE;
	} else {
		ugd->ck_state = EINA_TRUE;
	}
	if ((ugd->thumbs_d->medias_cnt - grid_unsupported_cnt) <= 0) {
		ugd->ck_state = false;
	}

	Evas_Object *ck = elm_object_part_content_get(ugd->thumbs_d->layout, "select.all.area.check");
	elm_check_state_set(ck, ugd->ck_state);

	_ge_ui_update_label_text(ugd->thumbs_d->nf_it, count,
					 ugd->albums_view_title);

	if (count > 0) {
		Evas_Object *btn = NULL;
		btn = elm_object_item_part_content_get (ugd->thumbs_d->nf_it , GE_NAVIFRAME_TITLE_RIGHT_BTN);
		if (btn == NULL) {
			ge_dbgE("Failed to get part information");
			return;
		}
		elm_object_disabled_set(btn, EINA_FALSE);
		_ge_add_remove_done_button_cb(btn, ugd, true);
	} else {
		Evas_Object *btn = NULL;
		btn = elm_object_item_part_content_get (ugd->thumbs_d->nf_it , GE_NAVIFRAME_TITLE_RIGHT_BTN);
		if (btn == NULL) {
			ge_dbgE("Failed to get part information");
			return;
		}
		elm_object_disabled_set(btn, EINA_TRUE);
		_ge_add_remove_done_button_cb(btn, ugd, false);
	}

	elm_gengrid_item_update(ugd->thumbs_d->album->griditem);

	for (i = 0; i < count; i++) {
		if (select_result[i]) {
			free (select_result[i]);
		}
	}
	if (select_result) {
		free(select_result);
	}
}

static void _ge_ext_destroy_me(ge_ugdata *ugd)
{
	ge_dbg("");
	GE_CHECK(ugd);
	GE_CHECK(ugd->ug_called_by_me);
	GE_CHECK(ugd->ug);
	GE_CHECK(ugd->service);
	bool send_result = false;

	if (ugd->ug_called_by_me) {
		ge_dbg("Destroy ug_called_by_me");
		ug_destroy(ugd->ug_called_by_me);
		ugd->ug_called_by_me = NULL;
	} else {
		ge_dbg("ug_called_by_me does not exist!");
	}

	if (ugd->file_select_mode == GE_FILE_SELECT_T_SLIDESHOW)
		ugd->b_destroy_me = false;

	if (!ugd->b_destroy_me) {
		ge_dbg("gallery ug is still alive");
		return;
	}
	if (ugd->file_select_mode == GE_FILE_SELECT_T_SETAS) {
		if (ugd->file_setas_image_path) {
			ge_dbg("GE_SETAS_IMAGE_PATH:%s", ugd->file_setas_image_path);
			app_control_add_extra_data(ugd->service,
					       GE_SETAS_IMAGE_PATH,
					       ugd->file_setas_image_path);

			GE_FREE(ugd->file_setas_image_path);
			send_result = true;
		}

		if (ugd->file_setas_crop_image_path &&
		   (ugd->file_select_setas_mode == GE_SETAS_T_CALLERID ||
		    ugd->file_select_setas_mode == GE_SETAS_T_CROP_WALLPAPER)) {
			ge_dbg("GE_SETAS_CALLERID_CROP_IMAGE_PATH:%s",
			       ugd->file_setas_crop_image_path);
			app_control_add_extra_data(ugd->service,
					       APP_CONTROL_DATA_SELECTED,
					       ugd->file_setas_crop_image_path);

			GE_FREE(ugd->file_setas_crop_image_path);
			send_result = true;
		}

		if (send_result) {
			ge_dbg("Call ug_send_result_full() to send result.");
			ug_send_result_full(ugd->ug, ugd->service, APP_CONTROL_RESULT_SUCCEEDED);
		}
	}

	if (ugd->b_destroy_me) {
		ge_dbg("Setting is appllied, destroy gallery UG.");
		ugd->b_destroy_me = false;
		/* Destroy self */
		if (!ugd->is_attach_panel) {
			ug_destroy_me(ugd->ug);
		}
	} else {
		ge_dbg("Cancel button tapped, back to thumbnails view.");
	}
}

static void _ge_ext_iv_layout_cb(ui_gadget_h ug, enum ug_mode mode, void* priv)
{
	ge_dbg("");
	GE_CHECK(priv);
	GE_CHECK(ug);

	Evas_Object *base = (Evas_Object *)ug_get_layout(ug);
	if (!base) {
		ge_dbgE("ug_get_layout failed!");
		ug_destroy(ug);
		return;
	}

	evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	/* Disable effect to avoid BS caused by ui-gadget to
	     unset ug layout after deleting it */
	ug_disable_effect(ug);
	evas_object_show(base);
}

static void _ge_ext_iv_result_cb(ui_gadget_h ug, app_control_h result, void *priv)
{
	ge_dbg("");
	GE_CHECK(priv);
	GE_CHECK(result);
	ge_ugdata *ugd = (ge_ugdata *)priv;
	char *path = NULL;
	char *status = NULL;

	if (ugd->file_select_mode == GE_FILE_SELECT_T_SETAS) {
		/*If set wallpaper success, homescreen_path should not be null.
		And if setting wallpaper was canceled in IV, gallery-efl doesn't exit immediately*/
		app_control_get_extra_data(result, GE_BUNDLE_HOMESCREEN_PATH,
				       &path);
		if (NULL == path)
			app_control_get_extra_data(result, GE_BUNDLE_LOCKSCREEN_PATH,
					       &path);
		ge_dbg("SETAS_IMAGE_PATH");
		app_control_get_extra_data(result, "Result", &status);
		ugd->file_select_setas_mode = 0;
		if (strcmp(status, "Cancel")) {
			ugd->file_select_setas_mode = 1;
		}

		if (path) {
			ge_dbg(":%s", path);
			ugd->b_destroy_me = true;
			ugd->file_setas_image_path = path;
		} else {
			ugd->b_destroy_me = false;
		}
		/*If has got homescreen_path, setats_mode should not be callerid and
		crop wallpaper*/
		if (path == NULL &&
		    (ugd->file_select_setas_mode == GE_SETAS_T_CALLERID ||
		    ugd->file_select_setas_mode == GE_SETAS_T_CROP_WALLPAPER)) {
			app_control_get_extra_data(result, APP_CONTROL_DATA_SELECTED,
					       &path);
			ge_dbg("CALLERID_CROP_IMAGE_PATH");
			if (path) {
				ge_dbg(":%s", path);
				ugd->b_destroy_me = true;
				ugd->file_setas_crop_image_path = path;
			} else {
				ugd->b_destroy_me = false;
			}
		}
	}

	char *error_state = NULL;
	app_control_get_extra_data(result, GE_IMAGEVIEWER_RETURN_ERROR,
			       &error_state);
	if (error_state) {
		ge_dbg("error string : %s", error_state);

		if (!g_strcmp0(error_state, "not_supported_file_type")) {
			ugd->b_destroy_me = false;
			if (ugd->ug_path == NULL) {
				ge_dbgE("current item is NULL");
				GE_FREE(error_state);
				return;
			}
			app_control_h service;
			app_control_create(&service);
			GE_CHECK(service);
			app_control_set_operation(service, APP_CONTROL_OPERATION_VIEW);
			app_control_set_uri(service, ugd->ug_path);
			app_control_send_launch_request(service, NULL, NULL);
			app_control_destroy(service);
		}
		GE_FREE(error_state);
	}
}

static void _ge_ext_iv_destroy_cb(ui_gadget_h ug, void *priv)
{
	ge_dbg("");
	GE_CHECK(priv);
	_ge_ext_destroy_me((ge_ugdata *)priv);
}

static void __ge_ext_iv_end_cb(ui_gadget_h ug, void *priv)
{
	ge_dbg("");
	GE_CHECK(priv);
	ge_ugdata *ugd = (ge_ugdata *)priv;

	if (ugd->file_select_setas_mode == 1)
		_ge_grid_sel_one(ugd, ugd->file_select_setas_path);

	if (ugd->b_hide_indicator)
		_ge_ui_hide_indicator((ge_ugdata *)priv);
}

static char **__ge_ext_get_select_index(ge_ugdata *ugd, int *size)
{
	GE_CHECK_NULL(ugd);
	GE_CHECK_NULL(ugd->selected_elist);
	char *index = NULL;
	int i = 0;
	char **media_index = NULL;
	int pos = 0;
	int sel_cnt = 0;
	ge_item *git = NULL;
	Eina_List *l = NULL;
	ge_dbg("Media count: %d", eina_list_count(ugd->selected_elist));

	sel_cnt = eina_list_count(ugd->selected_elist);
	ge_dbg("Item count: %d", sel_cnt);
	media_index = (char **)calloc(sel_cnt, sizeof(char *));
	GE_CHECK_NULL(media_index);

	EINA_LIST_FOREACH(ugd->selected_elist, l, git) {
		index = (char *)calloc(1, GE_IV_STR_LEN_MAX);
		if (git == NULL || index == NULL) {
			for (pos = 0; pos < i; ++pos) {
				GE_FREEIF(media_index[pos]);
			}

			GE_FREEIF(index);
			GE_FREE(media_index);
			return NULL;
		}
		ge_dbg("Sequence: %d", git->sequence-1);
		snprintf(index, GE_IV_STR_LEN_MAX, "%d", git->sequence-1);
		media_index[i++] = index;
		index = NULL;
		git = NULL;
	}


	if (size)
		*size = sel_cnt;

	return media_index;
}

/* Slideshow selected images */
static int __ge_ext_slideshow_selected(ge_ugdata *ugd, app_control_h service)
{
	GE_CHECK_VAL(service, -1);
	GE_CHECK_VAL(ugd, -1);
	char **media_index = NULL;
	int media_size = 0;
#define GE_SELECTED_FILES "Selected index"
#define GE_INDEX "Index"
#define GE_INDEX_VALUE "1"

	media_index = __ge_ext_get_select_index(ugd, &media_size);
	if (media_index == NULL) {
		ge_dbgE("Invalid select index!");
		return -1;
	}
	ge_dbg("Set selected medias, media_index[%p], size[%d]", media_index,
	       media_size);
	app_control_add_extra_data_array(service, GE_SELECTED_FILES,
				     (const char **)media_index, media_size);
	/*free space of the medias index*/
	int i = 0;
	for (i = 0; i < media_size; ++i) {
		ge_dbg("Set selected medias, media_index[%s]", media_index[i]);
		GE_FREEIF(media_index[i]);
	}
	GE_FREE(media_index);
	media_index = NULL;

	app_control_add_extra_data(service, GE_INDEX, GE_INDEX_VALUE);
	return 0;
}

static int __ge_ext_set_slideshow_data(ge_ugdata *ugd, char *file_url,
				       app_control_h service)
{
	GE_CHECK_VAL(service, -1);
	GE_CHECK_VAL(file_url, -1);
	GE_CHECK_VAL(ugd, -1);

	app_control_add_extra_data(service, GE_PATH, file_url);
	app_control_add_extra_data(service, GE_VIEW_MODE, "SLIDESHOW");
	app_control_add_extra_data(service, "Sort By", "DateDesc");
	if (ugd->file_type_mode == GE_FILE_T_IMAGE)
		app_control_add_extra_data(service, GE_MEDIA_TYPE, "Image");
	else if (ugd->file_type_mode == GE_FILE_T_VIDEO)
		app_control_add_extra_data(service, GE_MEDIA_TYPE, "Video");
	else
		app_control_add_extra_data(service, GE_MEDIA_TYPE, "All");
	if (__ge_ext_slideshow_selected(ugd, service) != 0) {
		ge_dbgE("Create UG failed!");
		return -1;
	}

	switch (ugd->slideshow_viewby) {
	case GE_VIEW_BY_ALL:
	case GE_VIEW_BY_ALBUMS:
		if (ugd->slideshow_album_id == NULL) {
			ge_dbgE("Create UG failed!");
			return -1;
		}
		app_control_add_extra_data(service, "Album index", ugd->slideshow_album_id);
		if (!g_strcmp0(ugd->slideshow_album_id, GE_ALBUM_ALL_ID))
			app_control_add_extra_data(service, GE_VIEW_BY, "All");
		else
			app_control_add_extra_data(service, GE_VIEW_BY, "By Folder");
		break;
	default:
		return -1;
	}
	return 0;
}

static int __ge_ext_set_setas_data(ge_ugdata *ugd, char *file_url,
				   app_control_h service)
{
	GE_CHECK_VAL(service, -1);
	GE_CHECK_VAL(file_url, -1);
	GE_CHECK_VAL(ugd, -1);

	if (file_url) {
		app_control_add_extra_data(service, GE_PATH, file_url);
		GE_FREEIF(ugd->ug_path);
		ugd->ug_path = strdup(file_url);
	}
	app_control_add_extra_data(service, GE_VIEW_MODE, "SETAS");

	if (ugd->file_select_setas_mode == GE_SETAS_T_WALLPAPER) {
		app_control_add_extra_data(service, GE_SETAS_TYPE, "Wallpaper");
	} else if (ugd->file_select_setas_mode == GE_SETAS_T_LOCKPAPER) {
		app_control_add_extra_data(service, GE_SETAS_TYPE, "Lockscreen");
	} else if (ugd->file_select_setas_mode == GE_SETAS_T_WALLPAPER_LOCKPAPER) {
		app_control_add_extra_data(service, GE_SETAS_TYPE, "Wallpaper & Lockscreen");
	} else if (ugd->file_select_setas_mode == GE_SETAS_T_CROP_WALLPAPER) {
		app_control_add_extra_data(service, GE_SETAS_TYPE, "Wallpaper Crop");
		app_control_add_extra_data(service, "Fixed ratio", "TRUE");

		int w = 0;
		int h = 0;
		ecore_x_window_size_get(ecore_x_window_root_first_get(),
					&w, &h);
		char *reso_str = (char *)calloc(1, GE_IV_STR_LEN_MAX);
		if (reso_str == NULL) {
			ge_dbgE("Calloc failed!");
			return -1;
		}
		snprintf(reso_str, GE_IV_STR_LEN_MAX, "%dx%d", w, h);
		ge_dbgW("Window Resolution: %dx%d, %s", w, h, reso_str);
		app_control_add_extra_data(service, "Resolution", reso_str);
		GE_FREE(reso_str);
	} else if (ugd->file_select_setas_mode == GE_SETAS_T_CALLERID) {
		app_control_add_extra_data(service, GE_SETAS_TYPE, "CallerID");
	}
	return 0;
}

static int __ge_ext_albums_set_iv_select_mode(void *data, app_control_h service, int type)
{
	GE_CHECK_VAL(service, GE_UG_FAIL);
	GE_CHECK_VAL(data, GE_UG_FAIL);
	ge_ugdata *ugd = (ge_ugdata *)data;
	ge_cluster *cur_album = ugd->album_item;
	GE_CHECK_NULL(ugd->album_item);
	ge_dbg("type: %d", type);

	/* 2.0, Local file */
	app_control_add_extra_data(service, GE_VIEW_MODE, "SELECT");
	app_control_add_extra_data(service, GE_MEDIA_TYPE, GE_ARGV_IV_MEDIA_ALL);
	app_control_set_mime(service, "image/*");

	if (cur_album && cur_album->cluster && cur_album->cluster->uuid) {
		app_control_add_extra_data(service, GE_VIEW_BY, GE_ARGV_IV_VIEW_BY_FOLER);
		app_control_add_extra_data(service, GE_ARGV_IV_ALBUM_INDEX,
				cur_album->cluster->uuid);
	}
	return GE_UG_SUCCESS;
}

static int _ge_ext_load_iv_selected_list(app_control_h service, void *data, ge_media_s *item)
{
	GE_CHECK_VAL(data, GE_UG_FAIL);
	GE_CHECK_VAL(service, GE_UG_FAIL);
	GE_CHECK_NULL(item);
	ge_ugdata *ugd = (ge_ugdata *)data;
	int i;
	ge_item *gitem = NULL;
	int count = _ge_data_get_sel_cnt(ugd);

	char **value = NULL;
	if (count > 0) {
		(value) = (char**)malloc(count * sizeof(char *));
		if (!value) {
			return GE_UG_FAIL;
		}
	}
	Eina_List *sel_ids = NULL;
	_ge_data_get_sel_item(ugd, &sel_ids);
	if (!sel_ids) {
		ge_dbgW("Invalid selection!!");

		if (value) {
			free(value);
		}
		return GE_UG_FAIL;
	}

	ge_sel_item_s *sit = NULL;

	for (i = 0; i < count; i++) {
		sit = eina_list_nth(sel_ids, i);
		if (sit) {
			if (sit->file_url) {
				(value)[i] = strdup(sit->file_url);
			}
		}
	}

	if (count > 0) {
		app_control_add_extra_data_array(service, "Selected index",
				value, count);
	}

	if (value) {
		for (i = 0; i < count; i++) {
			free(value[i]);
		}
		free(value);
	}

	return GE_UG_SUCCESS;
}

int _ge_ext_load_iv_ug_select_mode(void *data, ge_media_s *item, ge_ext_iv_type type)
{
	GE_CHECK_VAL(item, GE_UG_FAIL);
	GE_CHECK_VAL(data, GE_UG_FAIL);
	ge_ugdata *ugd = (ge_ugdata *)data;
	app_control_h service = NULL;

	if (ugd->uginfo.ug) {
		ge_dbgE("Already exits some UG called by me, type(%d)!", type);
		return GE_UG_FAIL;
	}

	app_control_create(&service);
	GE_CHECK_VAL(service, GE_UG_FAIL);

	ugd->uginfo.ug_type = GE_UG_IMAGEVIEWER;
	ugd->uginfo.iv_type = type;

	int ret = GE_UG_FAIL;
	ret = __ge_ext_albums_set_iv_select_mode(data, service, type);

	if (ret == GE_UG_FAIL) {
		ge_dbgW("Service data setting failed!");
		app_control_destroy(service);
		return GE_UG_FAIL;
	}

	if (!item->file_url) {
		ge_dbgW("Invalid file selected!!");
		app_control_destroy(service);
		return GE_UG_FAIL;
	}
	app_control_add_extra_data(service, GE_PATH, item->file_url);
	_ge_ext_load_iv_selected_list(service, ugd, item);
	ret = app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_GROUP);
	if (ret != APP_CONTROL_ERROR_NONE) {
		ge_dbgE("set launch mode failed");
	}
	ret = app_control_set_app_id(service, GE_IV_UG_NAME);
	if (ret != APP_CONTROL_ERROR_NONE) {
		ge_dbgE("set appid failed");
	}

	if (ugd->file_type_mode == GE_FILE_T_IMAGE) {
		ret = app_control_add_extra_data(service, GE_MEDIA_TYPE, "Image");
	} else if (ugd->file_type_mode == GE_FILE_T_VIDEO) {
		ret = app_control_add_extra_data(service, GE_MEDIA_TYPE, "Video");
	} else {
		ret = app_control_add_extra_data(service, GE_MEDIA_TYPE, "All");
	}

	if (ret != APP_CONTROL_ERROR_NONE) {
		ge_dbgE("Setting the Media type failed");
	}
	ret = app_control_send_launch_request(service, __ge_appcontrol_select_result_cb, (void *)ugd);

	app_control_destroy(service);

	if (ret != APP_CONTROL_ERROR_NONE) {
		ge_dbgE("ug_create failed!");
		return GE_UG_FAIL;
	} else {
		elm_object_tree_focus_allow_set(ugd->ly_main, EINA_FALSE);
		ugd->uginfo.b_ug_launched = true;
		return GE_UG_SUCCESS;
	}
}

int _ge_ext_load_iv_ug(ge_ugdata *ugd, char *file_url, char *album_index, int image_index)
{
	GE_CHECK_VAL(file_url, -1);
	GE_CHECK_VAL(ugd, -1);
	struct ug_cbs cbs;
	ui_gadget_h ug = NULL;
	app_control_h service = NULL;

	if (ugd->ug_called_by_me) {
		ge_dbgW("Already exits some UG called by me!");
		return -1;
	}

	memset(&cbs, 0x00, sizeof(struct ug_cbs));
	cbs.layout_cb = _ge_ext_iv_layout_cb;
	cbs.result_cb = _ge_ext_iv_result_cb;
	cbs.destroy_cb = _ge_ext_iv_destroy_cb;
	cbs.end_cb = __ge_ext_iv_end_cb;
	cbs.priv = ugd;

	app_control_create(&service);
	GE_CHECK_VAL(service, -1);

	if (ugd->file_select_mode == GE_FILE_SELECT_T_SLIDESHOW) {
		if (__ge_ext_set_slideshow_data(ugd, file_url, service) < 0) {
			ge_dbgE("Set slideshow data failed!");
			app_control_destroy(service);
			return -1;
		}
	} else {
		if (__ge_ext_set_setas_data(ugd, file_url, service) < 0) {
			ge_dbgE("Set setas data failed!");
			app_control_destroy(service);
			return -1;
		}
	}

	evas_object_smart_callback_call(ugd->naviframe, "gallery,freeze,resize", (void *)1);
	app_control_add_extra_data(service, "View By", "All");
	app_control_add_extra_data(service, "Album index", album_index);
	app_control_add_extra_data(service, "Path", file_url);
	app_control_add_extra_data(service, "Sort By", "Name");
	char image_index_str[12];
	eina_convert_itoa(image_index, image_index_str);
	app_control_add_extra_data(service, "Index", image_index_str);

	app_control_set_app_id(service, GE_IV_UG_NAME);
	ug = ug_create(ugd->ug, GE_IV_UG_NAME, UG_MODE_FULLVIEW, service, &cbs);
	ugd->ug_called_by_me = ug;

	app_control_destroy(service);
	if (!ug) {
		ge_dbgE("Create UG failed!");
		return -1;
	} else {
		ge_dbg("Create UG successully");
		return 0;
	}

}

int _ge_ext_load_iv_ug_for_help(ge_ugdata *ugd, const char *uri)
{
	GE_CHECK_VAL(ugd, -1);
	struct ug_cbs cbs;
	ui_gadget_h ug = NULL;
	app_control_h service = NULL;

	if (ugd->ug_called_by_me) {
		ge_dbgW("Already exits some UG called by me!");
		return -1;
	}

	memset(&cbs, 0x00, sizeof(struct ug_cbs));
	cbs.layout_cb = _ge_ext_iv_layout_cb;
	cbs.result_cb = _ge_ext_iv_result_cb;
	cbs.destroy_cb = _ge_ext_iv_destroy_cb;
	cbs.end_cb = __ge_ext_iv_end_cb;
	cbs.priv = ugd;

	app_control_create(&service);
	GE_CHECK_VAL(service, -1);

	/* Set "HELP" to "View Mode" */
	app_control_add_extra_data(service, GE_VIEW_MODE, "HELP");

	/* Set help uri to file path */
	app_control_add_extra_data(service, GE_PATH, uri);

	ug = ug_create(ugd->ug, GE_IV_UG_NAME, UG_MODE_FULLVIEW, service, &cbs);
	ugd->ug_called_by_me = ug;
	app_control_destroy(service);
	if (ug != NULL) {
		ge_dbg("Create UG successully");
		return 0;
	} else {
		ge_dbgE("Create UG failed!");
		return -1;
	}
}