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.
18 #include "gl-ui-util.h"
20 #include "gl-albums.h"
21 #include "gl-listview.h"
22 #include "gl-ext-ug-load.h"
23 #include "gl-ext-exec.h"
26 #include "gl-controlbar.h"
27 #include "gl-button.h"
28 #include "gl-nocontents.h"
29 #include "gl-notify.h"
30 #include "gl-progressbar.h"
32 #include "gl-strings.h"
35 static void __gl_list_item_check_changed(void *data, Evas_Object * obj, void *event_info)
39 gl_item *gitem = (gl_item *) data;
41 GL_CHECK(gitem->item);
43 gl_appdata *ad = (gl_appdata *)gitem->ad;
44 int view_mode = gl_get_view_mode(ad);
47 if (view_mode != GL_VIEW_VIDEOLIST_EDIT)
49 gl_dbg("ViewMode.%d. now return.", view_mode);
58 Eina_Bool checked = elm_check_state_get(obj);
59 gitem->checked = checked;
62 gl_dbg("Append:%s", gitem->item->file_url);
63 _gl_data_selected_list_append(ad, gitem);
67 gl_dbg("Remove:%s", gitem->item->file_url);
68 _gl_data_selected_list_remove(ad, gitem);
71 cnt = _gl_data_selected_list_count(ad);
73 /* Display selectioninfo */
74 _gl_notify_create_selinfo(ad, ad->gridinfo.edit_layout,
75 ad->gridinfo.nf_it_edit,
76 ad->listinfo.videos_cnt, cnt, false);
79 static void __gl_list_share_cb(void *data, Evas_Object *obj, void *event_info)
83 gl_item *gitem = (gl_item *)data;
85 gl_popup_create_title_popup(gitem->ad, GL_POPUP_THUMB_SHARE,
89 static void __gl_list_del_cb(void *data, Evas_Object *obj, void *event_info)
93 _gl_popup_create_video_del_popup(data);
96 static char *__gl_list_get_text(void *data, Evas_Object *obj, const char *part)
100 gl_item *gitem = (gl_item *) data;
101 GL_CHECK_NULL(gitem->item);
102 GL_CHECK_NULL(gitem->ad);
104 if (!g_strcmp0(part, GL_VIDEO_PART_TITLE) ||
105 !g_strcmp0(part, GL_VIDEO_PART_SLIDE_TITLE)) {
106 if (gitem->item->display_name) {
107 return strdup(gitem->item->display_name);
109 gl_dbgE("Invalid name!");
112 } else if (!g_strcmp0(part, GL_VIDEO_PART_DURATION)) {
113 /* Running time of the video */
114 unsigned int v_dur = 0;
116 if (gitem->item->video_info == NULL) {
118 v_dur = gitem->item->video_info->duration;
121 char *dur_str = _gl_get_duration_string(v_dur);
128 static Evas_Object *__gl_list_get_content(void *data, Evas_Object *obj, const char *part)
133 gl_item *gitem = (gl_item *) data;
134 GL_CHECK_NULL(gitem->item);
135 GL_CHECK_NULL(gitem->ad);
136 gl_appdata *ad = (gl_appdata *)gitem->ad;
137 bool is_expired_drm = false;
139 if (!g_strcmp0(part, GL_VIDEO_PART_CHECKBOX)) {
140 Evas_Object *ck = NULL;
141 ck = _gl_video_show_part_checkbox(obj, gitem->checked,
142 __gl_list_item_check_changed,
144 gitem->check_obj = ck;
146 } else if (!g_strcmp0(part, GL_VIDEO_PART_ICON)) {
147 /* Is it DRM file? Has a valid RO? */
149 if(gl_drm_is_drm_file(gitem->item->file_url) &&
150 gl_drm_check_valid_ro(gitem->item->file_url, gl_drm_get_permtype(gitem->item->type)) == false) {
151 path = GL_DEFAULT_THUMB_ICON;
152 is_expired_drm = true;
154 path = _GETICON(gitem->item->thumb_url);
157 Evas_Object *bg = NULL;
158 bg = _gl_video_show_part_icon(obj, path, 0, GL_VIDEO_ICON_WIDTH,
159 GL_VIDEO_ICON_HEIGHT);
161 } else if (!g_strcmp0(part, GL_VIDEO_PART_PLAY)) {
162 Evas_Object *icon = NULL;
163 icon = _gl_video_show_part_play(obj);
165 } else if (!g_strcmp0(part, GL_VIDEO_PART_BOOKMARK)) {
166 Evas_Object *icon = NULL;
168 if (gitem->item->video_info)
169 bk_len = gitem->item->video_info->bookmarks;
171 gl_dbg("%s has %d bookmark(s)", gitem->item->file_url, bk_len);
173 icon = _gl_video_show_part_bookmark(obj);
176 } else if (!g_strcmp0(part, GL_VIDEO_PART_PBAR)) {
177 return _gl_video_show_pbar(obj, gitem);
178 } else if (!g_strcmp0(part, GL_VIDEO_PART_SLIDE1)) {
179 Evas_Object *share_btn = NULL;
180 share_btn = _gl_but_create_but(obj, GL_BUT_SHARE,
181 GL_BUTTON_STYLE_SWEEP);
182 GL_CHECK_NULL(share_btn);
183 evas_object_smart_callback_add(share_btn, "clicked",
184 __gl_list_share_cb, data);
186 if (ad->listinfo.sweep_file_path) {
187 free(ad->listinfo.sweep_file_path);
188 ad->listinfo.sweep_file_path = NULL;
190 /* Save sweep item */
191 if (gitem->item->file_url)
192 ad->listinfo.sweep_file_path = strdup(gitem->item->file_url);
193 ad->listinfo.share_btn = share_btn;
195 } else if (!g_strcmp0(part, GL_VIDEO_PART_SLIDE3)) {
196 Evas_Object *del_btn = NULL;
197 del_btn = _gl_but_create_but(obj, GL_BUT_DEL,
198 GL_BUTTON_STYLE_SWEEP_DELETE);
199 GL_CHECK_NULL(del_btn);
200 evas_object_smart_callback_add(del_btn, "clicked",
201 __gl_list_del_cb, data);
202 ad->listinfo.del_btn = del_btn;
209 static void __gl_list_del(void *data, Evas_Object *obj)
214 static void __gl_list_genlist_sel(void *data, Evas_Object * obj, void *event_info)
219 static void __gl_list_flick_left_cb(void *data, Evas_Object *obj, void *event_info)
221 elm_object_scroll_freeze_push(obj);
224 static void __gl_list_flick_right_cb(void *data, Evas_Object *obj, void *event_info)
226 elm_object_scroll_freeze_push(obj);
229 static void __gl_list_flick_stop_cb(void *data, Evas_Object *obj, void *event_info)
231 elm_object_scroll_freeze_pop(obj);
234 static void __gl_list_set_sweep(void *data, Evas_Object *obj, void *event_info)
238 GL_CHECK(event_info);
240 gl_appdata *ad = (gl_appdata *)data;
241 /* Disable sweep if in wrong view mode */
242 if (gl_get_view_mode(ad) != GL_VIEW_VIDEOLIST) {
243 gl_dbgE("Wrong view mode!");
246 /* Finish other swept item */
247 Elm_Object_Item *it = NULL;
248 it = (Elm_Object_Item *)elm_genlist_decorated_item_get(obj);
250 gl_dbg("Reset previous swept item first.");
251 elm_genlist_item_decorate_mode_set(it, "slide", EINA_FALSE);
252 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DEFAULT);
254 /* Start genlist sweep */
255 elm_genlist_item_decorate_mode_set(event_info, "slide", EINA_TRUE);
256 elm_genlist_item_select_mode_set(event_info, ELM_OBJECT_SELECT_MODE_NONE);
259 static void __gl_list_unset_sweep(void *data, Evas_Object *obj, void *event_info)
263 GL_CHECK(event_info);
265 gl_appdata *ad = (gl_appdata *)data;
266 /* Disable sweep if in wrong view mode */
267 if (gl_get_view_mode(ad) != GL_VIEW_VIDEOLIST) {
268 gl_dbgE("Wrong view mode!");
271 if (ad->listinfo.sweep_file_path) {
272 free(ad->listinfo.sweep_file_path);
273 ad->listinfo.sweep_file_path = NULL;
275 /* Finish genlist sweep */
276 elm_genlist_item_decorate_mode_set(event_info, "slide", EINA_FALSE);
277 elm_genlist_item_select_mode_set(event_info, ELM_OBJECT_SELECT_MODE_DEFAULT);
280 static void __gl_list_cancel_sweep(void *data, Evas_Object *obj, void *event_info)
285 gl_appdata *ad = (gl_appdata *)data;
286 if (ad->listinfo.sweep_file_path) {
287 free(ad->listinfo.sweep_file_path);
288 ad->listinfo.sweep_file_path = NULL;
290 /* Get sweeped item */
291 Elm_Object_Item *it = NULL;
292 it = (Elm_Object_Item *)elm_genlist_decorated_item_get(obj);
293 /* Finish genlist sweep */
295 elm_genlist_item_decorate_mode_set(it, "slide", EINA_FALSE);
296 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DEFAULT);
300 static int __gl_list_add_sweep_cbs(void *data, Evas_Object *obj)
302 GL_CHECK_VAL(obj, -1);
303 /* Stop flicking(up/down direction) when sweep list item*/
304 evas_object_smart_callback_add(obj, "drag,start,left",
305 __gl_list_flick_left_cb, data);
306 evas_object_smart_callback_add(obj, "drag,start,right",
307 __gl_list_flick_right_cb, data);
308 evas_object_smart_callback_add(obj, "drag,stop",
309 __gl_list_flick_stop_cb, data);
310 /* Add callback for sweeping */
311 evas_object_smart_callback_add(obj, "drag,start,right",
312 __gl_list_set_sweep, data);
313 evas_object_smart_callback_add(obj, "drag,start,left",
314 __gl_list_unset_sweep, data);
315 evas_object_smart_callback_add(obj, "drag,start,up",
316 __gl_list_cancel_sweep, data);
317 evas_object_smart_callback_add(obj, "drag,start,down",
318 __gl_list_cancel_sweep, data);
323 _gl_list_sel(void *data, Evas_Object * obj, void *event_info)
327 gl_item *gitem = (gl_item *) data;
328 GL_CHECK(gitem->item);
330 gl_appdata *ad = (gl_appdata *)gitem->ad;
331 int view_mode = gl_get_view_mode(ad);
334 Elm_Object_Item *gen_item = elm_genlist_selected_item_get(obj);
337 elm_genlist_item_selected_set(gen_item, EINA_FALSE);
340 if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
342 if (gitem->check_obj == NULL)
344 gl_dbg("item or check_obj is NULL");
348 gitem->checked = !gitem->checked;
349 elm_check_state_set(gitem->check_obj, gitem->checked);
353 gl_dbg("Append:%s", gitem->item->file_url);
354 _gl_data_selected_list_append(ad, gitem);
358 gl_dbg("Remove:%s", gitem->item->file_url);
359 _gl_data_selected_list_remove(ad, gitem);
362 int cnt = _gl_data_selected_list_count(ad);
363 /* Display selectioninfo */
364 _gl_notify_create_selinfo(ad, ad->gridinfo.edit_layout,
365 ad->gridinfo.nf_it_edit,
366 ad->listinfo.videos_cnt, cnt, false);
370 /* Finish other swept item */
371 Elm_Object_Item *it = NULL;
372 it = (Elm_Object_Item *)elm_genlist_decorated_item_get(obj);
374 gl_dbg("Reset previous sweeped item first.");
375 elm_genlist_item_decorate_mode_set(it, "slide", EINA_FALSE);
376 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DEFAULT);
379 GL_CHECK(gitem->item->uuid);
380 if (ad->listinfo.played_uuid) {
381 free(ad->listinfo.played_uuid);
382 ad->listinfo.played_uuid = NULL;
384 ad->listinfo.played_uuid = strdup(gitem->item->uuid);
385 /* Starting to play the video */
386 gl_dbg("Starting to play the video");
387 gl_ext_exec(data, GL_APP_VIDEOPLAYER);
392 _gl_list_update_view(void *data, Evas_Object * obj, void *event_info)
396 gl_appdata *ad = (gl_appdata *)data;
397 Evas_Object *genlist = obj;
399 int view_mode = gl_get_view_mode(ad);
402 elm_genlist_clear(genlist);
404 /* Get all medias count of current album */
405 int cnt = ad->maininfo.medias_cnt;
407 gl_item *gitem = NULL;
408 bool it_showed = false;
409 Elm_Genlist_Item_Class *plic = NULL;
410 if (view_mode == GL_VIEW_VIDEOLIST_EDIT) {
411 plic = &(ad->listinfo.videolic);
412 ad->listinfo.videolic.item_style = GL_GENLIST_ITEM_STYLE_VIDEO_EDIT;
414 ad->listinfo.videolic.item_style = GL_GENLIST_ITEM_STYLE_VIDEO;
415 plic = &(ad->listinfo.sweeplic);
418 for (i = 1; i <= cnt; i++) {
419 _gl_data_get_item_by_index(ad, i, false, &gitem);
420 if (gitem == NULL || gitem->item == NULL) {
421 gl_dbgE("gitem == NULL || gitem->item == NULL");
424 if (gitem->item->type == MEDIA_CONTENT_TYPE_VIDEO) {
425 gl_dbg("%s inserted", gitem->item->file_url);
426 gitem->elm_item = elm_genlist_item_append(genlist, plic,
429 ELM_GENLIST_ITEM_NONE,
433 gitem->sequence = item_cnt;
434 if (ad->listinfo.played_uuid && !it_showed &&
435 !g_strcmp0(ad->listinfo.played_uuid, gitem->item->uuid)) {
437 /*Move played item to middle position of view */
438 elm_genlist_item_show(gitem->elm_item,
439 ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
444 if (ad->listinfo.played_uuid) {
445 free(ad->listinfo.played_uuid);
446 ad->listinfo.played_uuid = NULL;
449 if (ad->listinfo.sweep_file_path) {
450 if (ecore_file_exists(ad->listinfo.sweep_file_path) &&
451 (ecore_file_size(ad->listinfo.sweep_file_path) > 0)) {
452 if (ad->popupinfo.popup) {
454 evas_object_del(ad->popupinfo.popup);
455 ad->popupinfo.popup = NULL;
458 free(ad->listinfo.sweep_file_path);
459 ad->listinfo.sweep_file_path = NULL;
462 ad->listinfo.videos_cnt = item_cnt;
464 evas_object_smart_callback_add(genlist, "selected",
465 __gl_list_genlist_sel, NULL);
467 if (view_mode != GL_VIEW_VIDEOLIST_EDIT) {
468 if (ad->listinfo.videos_nocontents)
470 evas_object_hide(ad->listinfo.videos_nocontents);
471 gl_list_clear_view(ad);
473 ad->listinfo.videos_view = genlist;
475 ad->gridinfo.edit_view = genlist;
478 evas_object_del(genlist);
480 if (view_mode == GL_VIEW_VIDEOLIST_EDIT) {
481 ad->gridinfo.edit_view = NULL;
482 ad->gridinfo.edit_layout = NULL;
483 elm_naviframe_item_pop(ad->maininfo.naviframe);
486 if (ad->listinfo.videos_nocontents) {
487 gl_dbg("Nocontents view already created...");
491 if (ad->listinfo.videos_view) {
492 evas_object_hide(ad->listinfo.videos_view);
493 gl_list_clear_view(ad);
496 _gl_ctrl_disable_toolbar_item(ad, true, GL_NAVI_THUMBS,
498 Evas_Object *noc = _gl_nocontents_create(ad);
499 evas_object_show(noc);
500 ad->listinfo.videos_view = noc;
501 ad->listinfo.videos_nocontents = noc;
503 elm_object_part_content_unset(ad->gridinfo.layout,
505 elm_object_part_content_set(ad->gridinfo.layout,
507 ad->listinfo.videos_view);
511 int _gl_list_clear_data(void *data)
513 GL_CHECK_VAL(data, -1);
514 gl_appdata *ad = (gl_appdata *)data;
516 if (ad->listinfo.played_uuid) {
517 free(ad->listinfo.played_uuid);
518 ad->listinfo.played_uuid = NULL;
521 if (ad->listinfo.sweep_file_path) {
522 free(ad->listinfo.sweep_file_path);
523 ad->listinfo.sweep_file_path = NULL;
529 gl_list_create_view(void *data, Evas_Object * parent)
532 gl_appdata *ad = (gl_appdata *)data;
533 Evas_Object *genlist = NULL;
535 gl_item *gitem = NULL;
536 /* Get all medias count of current album */
537 int cnt = ad->maininfo.medias_cnt;
538 int view_mode = gl_get_view_mode(ad);
540 Elm_Genlist_Item_Class *plic = NULL;
542 gl_dbg("view mode=%d", view_mode);
543 if (view_mode == GL_VIEW_VIDEOLIST_EDIT) {
544 ad->listinfo.videolic.item_style = GL_GENLIST_ITEM_STYLE_VIDEO_EDIT;
545 plic = &(ad->listinfo.videolic);
547 ad->listinfo.videolic.item_style = GL_GENLIST_ITEM_STYLE_VIDEO;
549 ad->listinfo.sweeplic.item_style = GL_GENLIST_ITEM_STYLE_VIDEO;
550 ad->listinfo.sweeplic.decorate_item_style = GL_GENLIST_ITEM_STYLE_SWEEP3;
551 ad->listinfo.sweeplic.func.text_get = __gl_list_get_text;
552 ad->listinfo.sweeplic.func.content_get = __gl_list_get_content;
553 plic = &(ad->listinfo.sweeplic);
555 ad->listinfo.videolic.func.text_get = __gl_list_get_text;
556 ad->listinfo.videolic.func.content_get = __gl_list_get_content;
557 ad->listinfo.videolic.func.del = __gl_list_del;
559 genlist = _gl_video_add_genlist(parent);
561 for (i = 1; i <= cnt; i++) {
562 _gl_data_get_item_by_index(ad, i, false, &gitem);
563 if (gitem == NULL || gitem->item == NULL ||
564 gitem->item->uuid == NULL ) {
565 gl_dbgE("Invalid gitem!");
569 if (gitem->item->type == MEDIA_CONTENT_TYPE_VIDEO) {
570 gl_dbg("%s inserted", gitem->item->file_url);
571 gitem->elm_item = elm_genlist_item_append(genlist, plic,
574 ELM_GENLIST_ITEM_NONE,
578 gitem->sequence = item_cnt;
583 ad->listinfo.videos_cnt = item_cnt;
585 if (view_mode == GL_VIEW_VIDEOLIST)
586 __gl_list_add_sweep_cbs(ad, genlist);
588 evas_object_smart_callback_add(genlist, "selected",
589 __gl_list_genlist_sel, ad);
590 ad->listinfo.videos_nocontents = NULL;
594 /* There are none video files, show nocontents */
595 evas_object_del(genlist);
598 Evas_Object *noc = _gl_nocontents_create(ad);
599 evas_object_show(noc);
600 ad->listinfo.videos_nocontents = noc;
604 int gl_list_clear_view(void *data)
606 GL_CHECK_VAL(data, -1);
607 gl_appdata *ad = (gl_appdata *)data;
608 ad->listinfo.share_btn = NULL;
609 ad->listinfo.del_btn = NULL;
611 if (ad->listinfo.played_uuid) {
612 free(ad->listinfo.played_uuid);
613 ad->listinfo.played_uuid = NULL;
616 if (ad->listinfo.sweep_file_path) {
617 free(ad->listinfo.sweep_file_path);
618 ad->listinfo.sweep_file_path = NULL;
621 if (ad->listinfo.videos_view) {
622 evas_object_del(ad->listinfo.videos_view);
623 ad->listinfo.videos_view = NULL;
624 ad->listinfo.videos_nocontents = NULL;
630 /* Update normal list view */
631 int gl_list_update_view(void *data)
633 GL_CHECK_VAL(data, -1);
634 gl_appdata *ad = (gl_appdata *)data;
636 if (ad->listinfo.videos_view == NULL ||
637 ad->listinfo.videos_nocontents) {
638 gl_dbgW("Remove list nocontents view!");
639 if (ad->listinfo.videos_nocontents) {
640 evas_object_hide(ad->listinfo.videos_nocontents);
641 gl_list_clear_view(ad);
644 Evas_Object *list_view = NULL;
645 list_view = gl_list_create_view(ad, ad->maininfo.naviframe);
646 ad->listinfo.videos_view = list_view;
648 /* Enable edit button if it's not nocontents view */
649 if (ad->listinfo.videos_nocontents == NULL)
650 _gl_ctrl_disable_toolbar_item(ad, false, GL_NAVI_THUMBS,
653 elm_object_part_content_unset(ad->gridinfo.layout,
655 evas_object_show(ad->listinfo.videos_view);
656 elm_object_part_content_set(ad->gridinfo.layout,
658 ad->listinfo.videos_view);
660 _gl_list_update_view(ad, ad->listinfo.videos_view, NULL);
666 int gl_list_change_to_edit(void *data)
668 GL_CHECK_VAL(data, -1);
669 gl_appdata *ad = (gl_appdata *)data;
671 gl_set_view_mode(ad, GL_VIEW_VIDEOLIST_EDIT);
672 _gl_list_update_view(ad, ad->gridinfo.edit_view, NULL);
676 int gl_list_change_to_view(void *data)
678 GL_CHECK_VAL(data, -1);
679 gl_appdata *ad = (gl_appdata *)data;
682 if (ad->uginfo.ug_called_by_me == NULL && ad->listinfo.videos_view == NULL)
684 //special process when cancel edit after hide effect in _gl_ext_destroy_ug()
685 ad->listinfo.videos_view = gl_list_create_view(ad, ad->maininfo.naviframe);
686 evas_object_show(ad->listinfo.videos_view);
687 elm_object_part_content_set(ad->gridinfo.layout,
689 ad->listinfo.videos_view);
693 gl_set_view_mode(ad, GL_VIEW_VIDEOLIST);
694 _gl_list_update_view(ad, ad->listinfo.videos_view, NULL);