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.
20 #include "gl-albums.h"
21 #include "gl-gridview.h"
22 #include "gl-listview.h"
23 #include "gl-controlbar.h"
24 #include "gl-ui-util.h"
28 #include "gl-ext-ug-load.h"
29 #include "gl-ext-exec.h"
31 #include "gl-progressbar.h"
32 #include "gl-notify.h"
33 #include "gl-thread-util.h"
34 #include "gl-strings.h"
37 #define GL_BG_COLOR_DEFAULT 255
39 #define GL_BD_LAUNCH_TYPE "launch-type"
40 #define GL_BD_ALBUM_ID "album-id"
41 #define GL_BD_FILE_TYPE "file-type"
42 #define GL_BD_SETAS_TYPE "setas-type"
43 #define GL_BD_CALLERID_SIZE "callerid-size"
44 #define GL_BD_CALLERID_PATH "callerid-path"
45 #define GL_BD_HOMESCREEN_PATH "homescreen-path"
46 #define GL_BD_LOCKSCREEN_PATH "lockscreen-path"
47 #define GL_BD_SELECT_ALBUM "select-album"
48 #define GL_BD_SELECT_ONE "select-one"
49 #define GL_BD_SELECT_MULTIPLE "select-multiple"
50 #define GL_BD_SELECT_SETAS "select-setas"
51 #define GL_BD_FILE_TYPE_IMAGE "image"
52 #define GL_BD_FILE_TYPE_VIDEO "video"
53 #define GL_BD_FILE_TYPE_ALL "all"
54 #define GL_BD_SETAS_WALLPALER "wallpaper"
55 #define GL_BD_SETAS_CALLERID "callerid"
57 #define GL_MIME_SEP ":"
58 #define GL_MIME_TYPE_GALLERY "gallery.uri"
59 #define GL_SERVICE_OPERATION_WALLPAPER "http://tizen.org/appsvc/operation/wallpaper"
66 static struct text_part main_txt[] = {
67 {"txt_title", "Application template",},
68 {"txt_mesg", "Click to exit",},
71 /* User-defined function */
72 static int _gallery_init_app_svc(void *data);
74 static void _gallery_win_del_cb(void *data, Evas_Object *obj, void *event_info)
76 gl_dbgW("_gallery_win_del_cb!!");
82 static int _gallery_update_ts(Evas_Object *eo, struct text_part *tp, int size)
86 if (eo == NULL || tp == NULL || size < 0) {
89 for (i = 0; i < size; i++) {
90 if (tp[i].part && tp[i].msgid) {
91 edje_object_part_text_set(eo, tp[i].part,
99 static void _gallery_lang_changed_cb(void *data)
102 gl_appdata *ad = (gl_appdata *)data;
103 GL_CHECK(ad->maininfo.main_layout);
105 _gallery_update_ts(elm_layout_edje_get(ad->maininfo.main_layout),
106 main_txt, sizeof(main_txt) / sizeof(main_txt[0]));
107 _gl_lang_update(data);
110 static void _gallery_low_battery_cb(void *data)
114 /* ug_send_event(UG_EVENT_LOW_BATTERY); */
115 /* 0 : default handler, 1:user handler */
118 void _gallery_rotation_cb(app_device_orientation_e m, void *data)
121 gl_dbg("Appcore Rotation mode: %d", m);
122 gl_appdata *ad = (gl_appdata *)data;
123 GL_CHECK(ad->maininfo.win);
124 enum ug_event evt = UG_EVENT_NONE;
126 ad->maininfo.rotate_mode = m;
130 elm_win_rotation_with_resize_set(ad->maininfo.win, m);
132 int view_mode = gl_get_view_mode(ad);
133 if (ad->uginfo.ug_called_by_me) {
134 /* when ug invoked, just return. */
135 if (view_mode == GL_VIEW_THUMBS_EDIT ||
136 view_mode == GL_VIEW_VIDEOLIST_EDIT) {
137 _gl_notify_rotate_selinfo(ad);
138 } else if (view_mode == GL_VIEW_ALBUMS) {
139 _gl_notify_rotate_selinfo(ad);
144 _gl_notify_rotate_selinfo(ad);
147 static Evas_Object *_gallery_create_win(void *data, const char *name)
149 gl_dbg_launch(" _gallery_create_win:start");
152 gl_appdata *ad = (gl_appdata *)data;
153 Evas_Object *eo = NULL;
155 gl_dbg_launch(" elm_win_add:start");
156 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
157 gl_dbg_launch(" elm_win_add:end");
159 elm_win_autodel_set(eo, EINA_TRUE);
160 elm_win_title_set(eo, name);
161 evas_object_smart_callback_add(eo, "delete,request",
162 _gallery_win_del_cb, ad);
163 ad->maininfo.win_scale = elm_scale_get();
164 gl_dbg("main window scale: %f", ad->maininfo.win_scale);
167 gl_dbg("_gallery_create_win:done");
168 gl_dbg_launch(" _gallery_create_win:end");
172 static Evas_Object *_gallery_create_bg(Evas_Object *parent)
174 gl_dbg_launch(" _gallery_create_bg:start");
175 GL_CHECK_NULL(parent);
176 Evas_Object *bg = NULL;
178 gl_dbg_launch(" elm_bg_add:start");
179 bg = elm_bg_add(parent);
180 gl_dbg_launch(" elm_bg_add:end");
181 elm_bg_color_set(bg, GL_BG_COLOR_DEFAULT, GL_BG_COLOR_DEFAULT,
182 GL_BG_COLOR_DEFAULT);
184 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
186 evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
187 /* elm_win_resize_object_add(parent, bg); */
188 evas_object_show(bg);
189 gl_dbg_launch(" _gallery_create_bg:end");
194 static int _gallery_create_view_ly(gl_appdata *ad)
196 gl_dbg_launch(" _gallery_create_view_ly:start");
197 GL_CHECK_VAL(ad, -1);
198 GL_CHECK_VAL(ad->maininfo.naviframe, -1);
200 Evas_Object *layout = _gl_ui_create_view_ly(ad->maininfo.naviframe);
201 ad->albuminfo.layout = layout;
203 edje_object_signal_emit(_EDJ(layout), "elm,swallow_view,state,default",
206 gl_ui_create_title_and_push(ad, ad->maininfo.naviframe,
207 ad->albuminfo.layout, GL_NAVI_ALBUMS,
208 GL_STR_CTRL_ITEM_ALBUMS);
210 gl_dbg_launch(" _gallery_create_view_ly:end");
215 static Eina_Bool __gallery_activate_win_idler_cb(void *data)
217 GL_CHECK_CANCEL(data);
218 gl_appdata *ad = (gl_appdata *)data;
220 gl_dbgW("elm_win_activate - start!");
221 elm_win_activate(ad->maininfo.win);
222 gl_dbgW("elm_win_activate - done!");
224 if (ad->albuminfo.activate_win_idler) {
225 ecore_idler_del(ad->albuminfo.activate_win_idler);
226 ad->albuminfo.activate_win_idler = NULL;
229 return ECORE_CALLBACK_CANCEL;
232 static Eina_Bool _gallery_create_albums_idler_cb(void *data)
234 gl_dbg_launch(" _gallery_create_albums_idler_cb:start");
235 GL_CHECK_CANCEL(data);
236 gl_appdata *ad = (gl_appdata *)data;
237 gl_dbg("_gallery_create_albums_idler_cb:start");
239 if (ad->albuminfo.aul_launch_by_mime ||
240 ad->albuminfo.aul_launch_type == GL_AUL_T_VIEW_ALBUM) {
241 gl_dbgW("\tIdler: From livebox, gallery is launched!");
243 gl_dbgW("\tIdler: gallery is launched!");
245 /* Initialize libmedia-info */
247 gl_dbg("DB initialization:done");
248 /* Get cluster list from libmedia-info */
249 gl_dbg_launch(" _gl_data_get_cluster_list:start");
250 _gl_data_get_cluster_list(ad);
251 gl_dbg_launch(" _gl_data_get_cluster_list:end");
252 GL_CHECK_FALSE(ad->albuminfo.cluster_list);
253 gl_dbg("_gl_data_get_cluster_list:done");
255 gl_set_view_mode(ad, GL_VIEW_ALBUMS);
257 * Disbale 'edit' button if none editable albums
258 * (albums except 'All albums'/'Camera shot') exist.
260 if (gl_check_gallery_empty(ad) ||
261 ad->albuminfo.cluster_list->edit_cnt == 0)
262 _gl_ctrl_disable_toolbar_item(ad, true, GL_NAVI_ALBUMS,
264 /* Update albums view, append items */
265 gl_albums_update_items(ad);
268 gl_dbg("_gallery_create_albums_idler_cb:done");
270 if (ad->albuminfo.create_albums_idler) {
271 ecore_idler_del(ad->albuminfo.create_albums_idler);
272 ad->albuminfo.create_albums_idler = NULL;
275 gl_dbg_launch(" _gallery_create_albums_idler_cb:end");
276 return ECORE_CALLBACK_CANCEL;
279 static int _gallery_init_view(gl_appdata *ad)
281 gl_dbg_launch(" _gallery_init_view:start");
283 GL_CHECK_VAL(ad, -1);
286 ad->maininfo.main_layout = gl_ui_create_main_ly(ad->maininfo.win);
287 GL_CHECK_VAL(ad->maininfo.main_layout, -1);
290 ad->maininfo.bg = _gallery_create_bg(ad->maininfo.main_layout);
291 GL_CHECK_VAL(ad->maininfo.bg, -1);
293 /* Pack bg to swallow */
294 elm_object_part_content_set(ad->maininfo.main_layout, "elm.swallow.bg",
297 elm_win_indicator_mode_set(ad->maininfo.win, ELM_WIN_INDICATOR_SHOW);
298 gl_dbg("gl_ui_create_main_ly: done");
301 ad->maininfo.naviframe = gl_ui_create_navi_ly(ad->maininfo.main_layout);
302 GL_CHECK_VAL(ad->maininfo.naviframe, -1);
304 elm_object_part_content_set(ad->maininfo.main_layout, "elm.swallow.content",
305 ad->maininfo.naviframe);
307 if (gl_is_rotation_locked()) {
308 gl_dbg("Rotation is in locked state!");
310 int mode = APP_DEVICE_ORIENTATION_0;
311 mode = app_get_device_orientation();
312 ad->maininfo.rotate_mode = mode;
315 /* Albums view layout */
316 _gallery_create_view_ly(ad);
318 /* Add albums view and append nothing */
319 Evas_Object *layout_inner = NULL;
320 layout_inner = _gl_albums_add_gengrid(ad, ad->albuminfo.layout);
321 GL_CHECK_FALSE(layout_inner);
322 elm_object_part_content_set(ad->albuminfo.layout, "elm.swallow.view",
324 ad->albuminfo.view = layout_inner;
325 ad->albuminfo.gallery_launched = true;
327 gl_dbg_launch(" _gallery_init_view:end");
332 static bool _gallery_create(void *data)
334 gl_dbg_launch("create:start");
335 gl_dbgW("==Create==");
336 GL_CHECK_FALSE(data);
337 gl_appdata *ad = (gl_appdata *)data;
338 ad->maininfo.reentrant = TRUE;
339 Evas_Object *win = NULL;
341 elm_theme_extension_add(NULL, GL_EDJ_FILE);
344 win = _gallery_create_win(ad, PACKAGE);
346 ad->maininfo.win = win;
348 /* initialize gallery view */
349 if (_gallery_init_view(ad) != 0) {
350 gl_dbgE("_gallery_init_view failed");
354 gl_dbg_launch(" evas_object_show(win):start");
355 evas_object_show(win);
356 gl_dbg_launch(" evas_object_show(win):end");
357 gl_dbg("evas_object_show(win):done");
358 /* Register callbacks of DB update */
359 gl_dbg("system event cb:done");
361 gl_dbg_launch(" register callbacks:start");
362 gl_reg_db_update_noti(ad);
363 gl_dbg_launch(" register callbacks:end");
365 if (ad->albuminfo.create_albums_idler == NULL) {
366 /* Use idler to load albums view */
367 Ecore_Idler *idl = NULL;
368 idl = ecore_idler_add(_gallery_create_albums_idler_cb, ad);
369 ad->albuminfo.create_albums_idler = idl;
370 gl_dbg("create_albums_idler added: 0x%x",
371 ad->albuminfo.create_albums_idler);
374 gl_dbg_launch("create:end");
378 static int _gallery_close_app(void *data)
380 GL_CHECK_VAL(data, -1);
381 gl_appdata *ad = (gl_appdata *)data;
383 if (ad->albuminfo.create_albums_idler) {
384 ecore_idler_del(ad->albuminfo.create_albums_idler);
385 ad->albuminfo.create_albums_idler = NULL;
388 if (ad->albuminfo.activate_win_idler) {
389 ecore_idler_del(ad->albuminfo.activate_win_idler);
390 ad->albuminfo.activate_win_idler = NULL;
394 _gl_grid_del_append_idler(ad);
395 /* destroy rename album job.*/
396 if(ad->maininfo.rename_album_job) {
397 ecore_job_del(ad->maininfo.rename_album_job);
398 ad->maininfo.rename_album_job = NULL;
401 /* Destroy vibration timer */
402 if (ad->entryinfo.vibration_timer) {
403 ecore_timer_del(ad->entryinfo.vibration_timer);
404 ad->entryinfo.vibration_timer = NULL;
406 /* Free Ecore_Pipe object created */
407 if (ad->pbarinfo.sync_pipe) {
408 ecore_pipe_del(ad->pbarinfo.sync_pipe);
409 ad->pbarinfo.sync_pipe = NULL;
412 if (ad->pbarinfo.start_thread_timer) {
413 ecore_timer_del(ad->pbarinfo.start_thread_timer);
414 ad->pbarinfo.start_thread_timer = NULL;
417 if (ad->pbarinfo.del_pbar_idler) {
418 ecore_idler_del(ad->pbarinfo.del_pbar_idler);
419 ad->pbarinfo.del_pbar_idler = NULL;
422 /* Destroy timer for removing popup */
423 if (ad->popupinfo.del_timer) {
424 ecore_timer_del(ad->popupinfo.del_timer);
425 ad->popupinfo.del_timer = NULL;
428 /* Clear data in video list view */
429 _gl_list_clear_data(ad);
430 /* delete notification. */
431 _gl_notify_destroy_notiinfo(ad);
433 /* DB update callback unregister. */
434 gl_dereg_db_update_noti();
436 /* Free memory allocated for appsvc */
437 _gallery_init_app_svc(ad);
441 gl_albums_free_data(data);
443 /* disconnect with db */
444 _gl_data_finalize(ad);
446 gl_dbgW("==Exit, bye~ ==");
451 static void _gallery_terminate(void *data)
453 gl_dbgW("==Terminate==");
455 _gallery_close_app(data);
458 static void _gallery_pause(void *data)
460 gl_dbgW("==Pause==");
462 gl_appdata *ad = (gl_appdata *)data;
463 ad->maininfo.reentrant = TRUE;
467 /* For select appsvc, destory ug when HOME key is pressed */
468 gl_ext_destroy_gallery_ug(ad);
471 /* auto rotate view after resume if disabling/re-enabling rotate device */
472 static int __gallery_resume_update_rotation_mode(gl_appdata *ad)
474 GL_CHECK_VAL(ad, -1);
475 int display_mode = -1;
476 int device_mode = APP_DEVICE_ORIENTATION_0;
479 * display_mode is view mode, e.x. view is portrait normal
480 * device_mode is target mode, e.x. device is portrait normal
482 display_mode = elm_win_rotation_get(ad->maininfo.win);
483 device_mode = app_get_device_orientation();
484 gl_dbg("display_mode is %d, device_mode is %d", display_mode,
488 * disable rotate when view isn't portrait normal, then after resume,
489 * rotate view to portrait
491 if (gl_is_rotation_locked() &&
492 (display_mode != APP_DEVICE_ORIENTATION_0))
493 _gallery_rotation_cb(APP_DEVICE_ORIENTATION_0, (void*)ad);
495 * re-enable rotate when device isn't in portrait normal
496 * and view is in portrait normal, then after resume,
497 * rotate view by device_mode
499 else if (!gl_is_rotation_locked() && (device_mode != display_mode))
500 _gallery_rotation_cb(device_mode, (void*)ad);
504 static void _gallery_resume(void *data)
506 gl_dbg_launch("resume:start");
507 gl_dbgW("==Resume==");
509 gl_appdata *ad = (gl_appdata *)data;
512 /* Video palyer was close when pause Gallery */
513 ad->uginfo.app_called_by_me = false;
515 /* Show cursor and IMF if not popup showed */
516 if (ad->entryinfo.editfield && ad->popupinfo.popup == NULL) {
517 gl_dbg("Show Entry cursor and IMF.");
518 evas_object_show(ad->entryinfo.imf_entry);
519 elm_object_focus_set(ad->entryinfo.imf_entry, EINA_TRUE);
520 Ecore_IMF_Context *imf = ad->entryinfo.imf_context;
521 ecore_imf_context_input_panel_show(imf);
525 gl_update_view(ad, GL_UPDATE_VIEW_NORMAL);
527 __gallery_resume_update_rotation_mode(ad);
529 gl_dbg_launch("resume:done");
532 static int __gallery_reset_app(void *data, const char *cluster_id,
533 const char *aul_type)
535 GL_CHECK_VAL(data, -1);
536 gl_appdata *ad = (gl_appdata *)data;
537 GL_CHECK_VAL(ad->maininfo.win, -1);
538 int view_mode = gl_get_view_mode(ad);
541 if (cluster_id == NULL || aul_type == NULL) {
542 gl_dbgE("Invalid aul parameters!");
543 goto GALLERY_RESET_FAILED;
546 if (ad->pbarinfo.sync_pipe) {
547 gl_dbgW("Cancel move/delete pthread/Pipe!");
548 /* Set cancel state to make child thread exit */
549 gl_thread_set_cancel_state(ad, GL_PB_CANCEL_RESET);
553 if (view_mode == GL_VIEW_NONE) {
554 /* First launch gallery then show shortcut album*/
556 gl_dbg("Launch gallery at the first time");
557 _gl_data_get_cluster_list(ad);
558 GL_CHECK_VAL(ad->albuminfo.cluster_list, -1);
560 gl_set_view_mode(ad, GL_VIEW_ALBUMS);
562 gl_dbg("In Albums tab");
563 if (_gl_albums_reset_view(ad, cluster_id, aul_type) < 0)
564 goto GALLERY_RESET_FAILED;
567 /* Remove idler for other tabbar item */
568 if (ad->albuminfo.create_albums_idler) {
569 gl_dbgW("Remove album creation idler!");
570 ecore_idler_del(ad->albuminfo.create_albums_idler);
571 ad->albuminfo.create_albums_idler = NULL;
574 elm_win_activate(ad->maininfo.win);
577 GALLERY_RESET_FAILED:
579 elm_win_activate(ad->maininfo.win);
583 /* init appsvc launch related global variables */
584 static int _gallery_init_app_svc(void *data)
586 GL_CHECK_VAL(data, -1);
588 gl_appdata *ad = (gl_appdata *)data;
590 ad->albuminfo.aul_launch_type = GL_AUL_T_NONE;
591 ad->albuminfo.aul_file_type = GL_AUL_FILE_T_NONE;
592 ad->albuminfo.aul_setas_type = GL_AUL_SETAS_T_NONE;
593 if(ad->albuminfo.aul_id) {
594 free(ad->albuminfo.aul_id);
595 ad->albuminfo.aul_id = NULL;
597 if(ad->albuminfo.aul_type) {
598 free(ad->albuminfo.aul_type);
599 ad->albuminfo.aul_type = NULL;
602 ad->albuminfo.aul_launch_by_mime = false;
604 if(ad->albuminfo.recv_service) {
605 service_destroy(ad->albuminfo.recv_service);
606 ad->albuminfo.recv_service = NULL;
609 if(ad->albuminfo.aul_callid_size) {
610 free(ad->albuminfo.aul_callid_size);
611 ad->albuminfo.aul_callid_size = NULL;
613 if(ad->albuminfo.aul_callid_path) {
614 free(ad->albuminfo.aul_callid_path);
615 ad->albuminfo.aul_callid_path = NULL;
617 if(ad->albuminfo.aul_homescreen_path) {
618 free(ad->albuminfo.aul_homescreen_path);
619 ad->albuminfo.aul_homescreen_path = NULL;
621 if(ad->albuminfo.aul_lockscreen_path) {
622 free(ad->albuminfo.aul_lockscreen_path);
623 ad->albuminfo.aul_lockscreen_path = NULL;
628 static int _gallery_parse_launch_type(service_h service, void *data)
630 GL_CHECK_VAL(service, -1);
631 GL_CHECK_VAL(data, -1);
632 gl_appdata *ad = (gl_appdata *)data;
634 gl_aul_launch_type launch_type = GL_AUL_T_NONE;
635 char *launch_type_str = NULL;
636 char *setas_type_str = NULL;
639 /* get launch-type */
640 service_get_extra_data(service, GL_BD_LAUNCH_TYPE, &launch_type_str);
641 if (launch_type_str == NULL) {
642 gl_dbg("set to default launch type: select-one");
643 ad->albuminfo.aul_launch_type = GL_AUL_T_SELECT_ONE;
646 gl_dbg("launch-type: %s", launch_type_str);
649 if(!strcasecmp(launch_type_str, GL_BD_SELECT_ALBUM)) {
651 launch_type = GL_AUL_T_SELECT_ALBUM;
652 } else if(!strcasecmp(launch_type_str, GL_BD_SELECT_ONE)) {
654 launch_type = GL_AUL_T_SELECT_ONE;
655 } else if(!strcasecmp(launch_type_str, GL_BD_SELECT_MULTIPLE)) {
657 launch_type = GL_AUL_T_SELECT_MULTIPLE;
658 } else if(!strcasecmp(launch_type_str, GL_BD_SELECT_SETAS)) {
659 launch_type = GL_AUL_T_SELECT_SETAS;
662 service_get_extra_data(service, GL_BD_SETAS_TYPE, &setas_type_str);
663 if(setas_type_str == NULL) {
664 GL_FREE_MEM(launch_type_str);
667 gl_dbg("setas-type: %s", setas_type_str);
669 gl_aul_setas_type setas_type = GL_AUL_SETAS_T_NONE;
673 if (!strcasecmp(setas_type_str, GL_BD_SETAS_WALLPALER)) {
675 setas_type = GL_AUL_SETAS_T_WALLPAPER;
677 /* get homscreen-path */
678 service_get_extra_data(service, GL_BD_HOMESCREEN_PATH,
681 gl_dbg("homescreen-path: %s", path);
682 ad->albuminfo.aul_homescreen_path = path;
685 /* get lockscreen-path */
686 service_get_extra_data(service, GL_BD_LOCKSCREEN_PATH,
689 gl_dbg("lockscreen-path: %s", path);
690 ad->albuminfo.aul_lockscreen_path = path;
693 } else if (!strcasecmp(setas_type_str, GL_BD_SETAS_CALLERID)) {
695 setas_type = GL_AUL_SETAS_T_CALLER_ID;
696 /* get callerid-size */
697 service_get_extra_data(service, GL_BD_CALLERID_SIZE,
700 gl_dbg("callerid-size: %s", size);
701 ad->albuminfo.aul_callid_size = size;
703 /* get callerid-path */
704 service_get_extra_data(service, GL_BD_CALLERID_PATH,
707 gl_dbg("callerid-path: %s", path);
708 ad->albuminfo.aul_callid_path = path;
712 ad->albuminfo.aul_setas_type = setas_type;
713 GL_FREE_MEM(setas_type_str);
716 ad->albuminfo.aul_launch_type = launch_type;
717 GL_FREE_MEM(launch_type_str);
721 /* analysis parameters */
722 static int _gallery_parse_param(service_h service, void *data)
724 GL_CHECK_VAL(service, -1);
725 GL_CHECK_VAL(data, -1);
727 gl_appdata *ad = (gl_appdata *)data;
728 char *operation = NULL;
733 _gallery_init_app_svc(ad);
735 /* save current service handle */
736 service_clone(&ad->albuminfo.recv_service, service);
738 service_get_operation(service, &operation);
739 gl_dbg("operation: %s", operation);
741 if(!strcasecmp(operation, SERVICE_OPERATION_DEFAULT)) {
742 char *mime_type_str = NULL;
743 service_get_mime(service, &mime_type_str);
744 if(mime_type_str == NULL) {
745 gl_dbg("mime_type NULL");
748 gl_dbg("mime_type: %s", mime_type_str);
750 if(!g_strcmp0(mime_type_str, GL_MIME_TYPE_GALLERY)) {
751 char *content = NULL;
752 GL_CHECK_VAL(content, -1);
753 gl_dbg("content: %s", content);
756 char *str_buf = NULL;
757 szID = strtok_r(content, GL_MIME_SEP, &str_buf);
760 szID = strtok_r(NULL, GL_MIME_SEP, &str_buf);
761 GL_CHECK_VAL(szID, -1);
762 ad->albuminfo.aul_id = strdup(szID);
763 ad->albuminfo.aul_launch_by_mime = true;
764 gl_dbg("album_id: %s", ad->albuminfo.aul_id);
769 service_get_uri(service, &uri);
771 gl_dbg("uri: %s", uri);
772 char *str_pre = NULL;
773 char *str_suf = NULL;
774 str_pre = strtok_r(uri, GL_MIME_SEP, &str_suf);
775 gl_dbg("str_pre: %s, str_suf: %s", str_pre, str_suf);
776 GL_CHECK_VAL(str_pre, -1);
777 GL_CHECK_VAL(str_suf, -1);
778 str_pre = strtok_r(str_suf, GL_MIME_SEP, &str_suf);
779 gl_dbg("str_pre: %s, str_suf: %s", str_pre, str_suf);
780 GL_CHECK_VAL(str_pre, -1);
781 GL_CHECK_VAL(str_suf, -1);
782 ad->albuminfo.aul_id = strdup(str_suf);
783 ad->albuminfo.aul_type = strdup(str_pre);
784 ad->albuminfo.aul_launch_by_mime = true;
785 gl_dbg("Type: %s, ID: %s", ad->albuminfo.aul_type,
786 ad->albuminfo.aul_id);
791 if(!strcasecmp(operation, SERVICE_OPERATION_VIEW)) {
793 gl_ext_destroy_gallery_ug(ad);
795 ad->albuminfo.aul_launch_type = GL_AUL_T_VIEW_ALBUM;
797 /* get file-type from service */
798 char *file_type_str = NULL;
799 ad->albuminfo.aul_file_type = GL_AUL_FILE_T_ALL; /* default */
800 service_get_extra_data(service, GL_BD_FILE_TYPE, &file_type_str);
803 gl_dbg("file type: %s", file_type_str);
804 if (!g_strcmp0(file_type_str, GL_BD_FILE_TYPE_IMAGE)) {
805 ad->albuminfo.aul_file_type = GL_AUL_FILE_T_IMAGE;
806 } else if (!g_strcmp0(file_type_str, GL_BD_FILE_TYPE_VIDEO)) {
807 ad->albuminfo.aul_file_type = GL_AUL_FILE_T_VIDEO;
809 GL_FREE_MEM(file_type_str);
812 char *album_id_str = NULL;
813 service_get_extra_data(service, GL_BD_ALBUM_ID, &album_id_str);
816 gl_dbg("album-id: %s", album_id_str);
817 ad->albuminfo.aul_id = album_id_str;
819 gl_dbg("album-id is invalid, set to default (ALL)");
820 ad->albuminfo.aul_id = strdup(GL_ALBUM_ALL_ID);
822 } else if(!strcasecmp(operation, SERVICE_OPERATION_PICK)) {
825 /* get file-type from mime */
826 ad->albuminfo.aul_file_type = GL_AUL_FILE_T_ALL; /* default */
827 service_get_mime(service, &mime);
830 gl_dbg("mime: %s", mime);
831 if (!g_strcmp0(mime, GL_MIME_IMAGE_ALL)) {
832 ad->albuminfo.aul_file_type = GL_AUL_FILE_T_IMAGE;
833 } else if (!g_strcmp0(mime, GL_MIME_VIDEO_ALL)) {
834 ad->albuminfo.aul_file_type = GL_AUL_FILE_T_VIDEO;
838 _gallery_parse_launch_type(service, ad);
839 } else if (!strcasecmp(operation, GL_SERVICE_OPERATION_WALLPAPER)) {
840 ad->albuminfo.aul_file_type = GL_AUL_FILE_T_IMAGE;
841 ad->albuminfo.aul_launch_type = GL_AUL_T_SELECT_SETAS;
842 ad->albuminfo.aul_setas_type = GL_AUL_SETAS_T_CROP_WALLPAPER;
845 service_get_extra_data(service, GL_BD_HOMESCREEN_PATH, &path);
847 gl_dbg("homescreen-path: %s", path);
848 ad->albuminfo.aul_homescreen_path = path;
855 static void _gallery_reset(service_h service, void *data)
857 gl_dbgW("==Reset==");
859 gl_appdata *ad = (gl_appdata *)data;
860 GL_CHECK(ad->maininfo.win);
862 if (ad->maininfo.reentrant) {
863 ad->maininfo.reentrant = FALSE;
865 gl_dbgW("Gallery reentrant is not allowed, return!");
869 /* Destroy gallery ug */
870 if (ad->uginfo.gallery_ug_called_by_me) {
871 gl_dbgW("Destroy Gallery UG launched, show App view!");
872 ug_destroy(ad->uginfo.gallery_ug_called_by_me);
873 ad->uginfo.gallery_ug_called_by_me = NULL;
876 /* Parse parameters */
877 if(_gallery_parse_param(service, data) != 0) {
878 if (ad->albuminfo.aul_launch_by_mime == false &&
879 ad->albuminfo.aul_launch_type == GL_AUL_T_NONE) {
880 /*@@ 1. Launch Gallery from menu screen/Smart search app, albums view showed @@*/
881 int view_m = gl_get_view_mode(ad);
882 gl_dbg("view_m: %d", view_m);
883 /* Launch Gallery at the first time */
884 if (view_m == GL_VIEW_NONE) {
885 gl_dbg("Set view mode as GL_VIEW_ALBUMS");
886 gl_set_view_mode(ad, GL_VIEW_ALBUMS);
889 gl_dbgE("Failed to parse parameters!");
891 /* Rotate window if it's not APP_DEVICE_ORIENTATION_0 mode */
892 if (!gl_is_rotation_locked()) {
893 int mode = APP_DEVICE_ORIENTATION_0;
894 mode = app_get_device_orientation();
895 if (mode != APP_DEVICE_ORIENTATION_0) {
896 gl_dbg("Rotation window!");
897 _gallery_rotation_cb(mode, ad);
900 elm_win_activate(ad->maininfo.win);
904 if (ad->albuminfo.aul_launch_by_mime ||
905 ad->albuminfo.aul_launch_type == GL_AUL_T_VIEW_ALBUM) {
906 /*@@ 2. Launch Gallery from shortcut @@*/
907 __gallery_reset_app(data, ad->albuminfo.aul_id,
908 ad->albuminfo.aul_type);
910 /*@@ 3. Load Gallery UG @@*/
911 gl_dbg("Start loading Gallery UG");
912 if (gl_ext_load_gallery_ug(ad) == GL_UG_SUCCESS) {
913 if (gl_get_view_mode(ad) == GL_VIEW_NONE) {
914 gl_dbg("elm_win_activate");
915 elm_win_activate(ad->maininfo.win);
917 if (ad->albuminfo.activate_win_idler) {
918 ecore_idler_del(ad->albuminfo.activate_win_idler);
919 ad->albuminfo.activate_win_idler = NULL;
921 /* To show UG faster then app */
922 Ecore_Idler *idler = NULL;
923 idler = ecore_idler_add(__gallery_activate_win_idler_cb,
925 ad->albuminfo.activate_win_idler = idler;
931 int gallery_reset_app(void *data)
933 GL_CHECK_VAL(data, -1);
934 gl_appdata *ad = (gl_appdata *)data;
935 gl_dbg("Reset gallery[cluster ID: %s]", ad->albuminfo.aul_id);
936 return __gallery_reset_app(data, ad->albuminfo.aul_id,
937 ad->albuminfo.aul_type);
940 int main(int argc, char *argv[])
942 gl_dbg_launch("main:start");
943 gl_dbgW("==Gallery==");
947 app_event_callback_s event_callback;
949 event_callback.create = _gallery_create;
950 event_callback.terminate = _gallery_terminate;
951 event_callback.pause = _gallery_pause;
952 event_callback.resume = _gallery_resume;
953 event_callback.service = _gallery_reset;
954 event_callback.low_memory = NULL;
955 event_callback.low_battery = _gallery_low_battery_cb;
956 event_callback.device_orientation = _gallery_rotation_cb;
957 event_callback.language_changed = _gallery_lang_changed_cb;
958 event_callback.region_format_changed = NULL;
960 memset(&gl_ad, 0x00, sizeof(gl_appdata));
962 ret = app_efl_main(&argc, &argv, &event_callback, &gl_ad);
964 gl_dbg_launch("main:done");