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.
19 #include "gl-ui-util.h"
22 #include "gl-listview.h"
23 #include "gl-progressbar.h"
24 #include "gl-strings.h"
25 #include "gl-button.h"
27 #define GL_POPUP_OBJ_DATA_KEY "popup_list_data"
28 #define GL_GENLIST_ITEM_STYLE_1TEXT "1text"
29 #define GL_POPUP_STYLE_MIN_MENUSTYLE "min_menustyle"
31 #define GL_POPUP_MENUSTYLE_WIDTH (614*elm_config_scale_get())
32 #define GL_POPUP_MENUSTYLE_HEIGHT(x) ((113*x-1)*elm_config_scale_get())
33 #define GL_POPUP_MENUSTYLE_HEIGHT_MAX (408*elm_config_scale_get())
35 #define GL_POPUP_TIMEOUT_1S 1.0
36 #define GL_POPUP_TIMEOUT_3S 3.0
38 static Eina_Bool __gl_popup_timeout_cb(void *data)
41 gl_appdata *ad = (gl_appdata *)data;
42 if (ad->popupinfo.del_timer) {
43 ecore_timer_del(ad->popupinfo.del_timer);
44 ad->popupinfo.del_timer = NULL;
47 if (ad->popupinfo.popup) {
48 evas_object_del(ad->popupinfo.popup);
49 ad->popupinfo.popup = NULL;
51 return ECORE_CALLBACK_CANCEL;
54 static int __gl_popup_add_timer(void *data, double to_inc)
56 GL_CHECK_VAL(data, -1);
57 gl_appdata *ad = (gl_appdata *)data;
58 if (ad->popupinfo.del_timer) {
59 ecore_timer_del(ad->popupinfo.del_timer);
60 ad->popupinfo.del_timer = NULL;
63 ad->popupinfo.del_timer = ecore_timer_add(to_inc, __gl_popup_timeout_cb,
68 static void __gl_popup_del_resp_cb(void *data, Evas_Object *obj,
73 gl_appdata *ad = (gl_appdata *)data;
74 const char *text = NULL;
76 text = elm_object_text_get(obj);
78 gl_dbg("Button: %s, mode: %d", text, ad->popupinfo.popup_mode);
80 if (!g_strcmp0(text, GL_STR_DELETE)) {
81 if (ad->popupinfo.popup_mode == GL_POPUP_ALBUM_DELETE)
85 if (ad->popupinfo.popup) {
86 evas_object_del(ad->popupinfo.popup);
87 ad->popupinfo.popup = NULL;
91 static void _gl_popup_move_to_album(void *data)
94 gl_appdata *ad = (gl_appdata *)data;
97 * 'move_album_id == NULL' is new album case,
98 * other move/save to some existed album.
100 if (ad->albuminfo.path)
101 gl_move_to_album(ad);
103 gl_ui_move_to_newalbum(ad);
106 static void __gl_popup_del_video_resp_cb(void *data, Evas_Object *obj,
111 gl_item *gitem = (gl_item *)data;
113 gl_appdata *ad = (gl_appdata *)gitem->ad;
114 const char *text = NULL;
116 text = elm_object_text_get(obj);
118 gl_dbg("Button: %s", text);
120 if (!g_strcmp0(text, GL_STR_DELETE))
123 if (ad->popupinfo.popup) {
124 evas_object_del(ad->popupinfo.popup);
125 ad->popupinfo.popup = NULL;
129 static void _gl_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
132 gl_appdata *ad = (gl_appdata *)data;
133 int mode = ad->popupinfo.popup_mode;
134 Ecore_IMF_Context *imf = ad->entryinfo.imf_context;
135 const char *text = NULL;
137 text = elm_object_text_get(obj);
139 gl_dbg("Button: %s, mode: %d", text, mode);
141 if (mode == GL_POPUP_ALBUM_NEW_EMPTY ||
142 mode == GL_POPUP_ALBUM_NEW_DUPLICATE ||
143 mode == GL_POPUP_ALBUM_NEW_INVALID) {
144 if (!g_strcmp0(text, GL_STR_YES) ||
145 !g_strcmp0(text, GL_STR_OK)) {
146 ad->entryinfo.entry_mode = GL_ENTRY_NEW_ALBUM;
147 evas_object_show(ad->entryinfo.imf_entry);
148 elm_object_focus_set(ad->entryinfo.imf_entry, EINA_TRUE);
149 ecore_imf_context_input_panel_show(imf);
150 } else if (!g_strcmp0(text, GL_STR_NO) ||
151 !g_strcmp0(text, GL_STR_CANCEL)) {
152 if (ad->entryinfo.imf_entry)
153 ecore_imf_context_input_panel_hide(imf);
155 gl_ui_cancel_new_album(ad);
157 } else if (mode == GL_POPUP_ALBUM_RENAME_EMPTY ||
158 mode == GL_POPUP_ALBUM_RENAME_DUPLICATE ||
159 mode == GL_POPUP_ALBUM_RENAME_INVALID) {
160 if (!g_strcmp0(text, GL_STR_YES) ||
161 !g_strcmp0(text, GL_STR_OK)) {
162 evas_object_show(ad->entryinfo.imf_entry);
163 elm_object_focus_set(ad->entryinfo.imf_entry, EINA_TRUE);
164 ecore_imf_context_input_panel_show(imf);
165 } else if (!g_strcmp0(text, GL_STR_NO) ||
166 !g_strcmp0(text, GL_STR_CANCEL)) {
167 if (ad->entryinfo.imf_entry)
168 ecore_imf_context_input_panel_hide(imf);
169 gl_ui_cancel_rename_album(ad);
173 if (ad->pbarinfo.pbar_popup) {
174 evas_object_del(ad->pbarinfo.pbar_popup);
175 ad->pbarinfo.pbar_popup = NULL;
177 if (ad->popupinfo.popup) {
178 evas_object_del(ad->popupinfo.popup);
179 ad->popupinfo.popup = NULL;
183 static char *__gl_popup_list_get_text(void *data, Evas_Object *obj, const char *part)
187 /* Get 'ad' via 'popup_list_data' */
188 gl_appdata *ad = (gl_appdata *)evas_object_data_get(obj, GL_POPUP_OBJ_DATA_KEY);
192 int mode = ad->popupinfo.popup_mode;
193 const char *label = NULL;
195 * Use index for album move ,
196 * mainly for showing 'New album'
200 if (!g_strcmp0(part, "elm.text"))
204 case GL_POPUP_THUMB_SHARE:
205 case GL_POPUP_ALBUM_SHARE:
206 label = (char *)data;
208 case GL_POPUP_THUMB_MOVE:
210 /* 1, Prevent pass NULL data; */
214 label = GL_STR_CREATE_ALBUM; //add "New album" item.
218 Eina_List *album_list = NULL;
220 if (ad->albuminfo.cluster_list && ad->albuminfo.cluster_list->clist)
222 album_list = ad->albuminfo.cluster_list->clist;
226 gl_dbgE("cluster list is NULL.");
230 gl_cluster *album_item = eina_list_nth(album_list, idx);
231 if (album_item && album_item->cluster &&
232 album_item->cluster->uuid &&
233 album_item->cluster->display_name) {
234 if (strlen(album_item->cluster->display_name))
236 label = album_item->cluster->display_name;
238 else if (_gl_data_is_root_path(ad, album_item->cluster->path)) //"root" case, set display name as "No Name"
240 label = GL_ALBUM_PHOME_ROOT_NAME;
244 gl_dbgE("Album name[%s] is wrong!", album_item->cluster->display_name);
245 label = GL_ALBUM_PHOME_ROOT_NAME;
251 gl_dbg("default: wrong mode.");
257 return strdup(label);
261 gl_dbgE("label is NULL");
271 static Evas_Object *__gl_popup_create_list(void *data, Evas_Object *parent, const char *item_type)
273 GL_CHECK_NULL(parent);
275 gl_appdata *ad = (gl_appdata *)data;
280 ad->popupinfo.popuplit.item_style = item_type;
284 ad->popupinfo.popuplit.item_style = GL_GENLIST_ITEM_STYLE_1TEXT;
286 ad->popupinfo.popuplit.func.text_get = __gl_popup_list_get_text;
287 ad->popupinfo.popuplit.func.content_get = NULL;
288 ad->popupinfo.popuplit.func.state_get = NULL;
289 ad->popupinfo.popuplit.func.del = NULL;
291 Evas_Object *genlist = elm_genlist_add(parent);
292 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
293 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
295 /* Attach 'ad' to genlist with 'GL_POPUP_OBJ_DATA_KEY' key to prevent use global variable. */
296 evas_object_data_set(genlist, GL_POPUP_OBJ_DATA_KEY, data);
302 _gl_popup_move_cb(void *data, Evas_Object * obj, void *event_info)
305 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
308 elm_genlist_item_selected_set(item, EINA_FALSE);
311 /* Get 'ad' via 'GL_POPUP_OBJ_DATA_KEY' */
313 gl_appdata *ad = (gl_appdata *)evas_object_data_get(obj, GL_POPUP_OBJ_DATA_KEY);
315 if (ad->albuminfo.path) {
316 free(ad->albuminfo.path);
317 ad->albuminfo.path = NULL;
320 ad->albuminfo.path = strdup((char *)data);
322 gl_dbg("Dest album path: %s", ad->albuminfo.path);
324 if (ad->popupinfo.popup) {
325 evas_object_del(ad->popupinfo.popup);
326 ad->popupinfo.popup = NULL;
329 _gl_popup_move_to_album(ad);
333 _gl_popup_share_cb(void *data, Evas_Object * obj, void *event_info)
336 /* Get 'ad' via 'GL_POPUP_OBJ_DATA_KEY' */
338 gl_appdata *ad = (gl_appdata *)evas_object_data_get(obj, GL_POPUP_OBJ_DATA_KEY);
342 g_strlcpy(ad->popupinfo.popup_item_label, (char *)data, GL_ALBUM_NAME_LEN_MAX);
344 if (ad->popupinfo.popup) {
345 evas_object_del(ad->popupinfo.popup);
346 ad->popupinfo.popup = NULL;
349 int view_mode = gl_get_view_mode(ad);
350 if (view_mode == GL_VIEW_ALBUMS_EDIT)
351 _gl_share_select_album(ad);
353 gl_share_select_item(ad);
356 /* Append items to list in popup for 'Share' */
357 static int _gl_popup_append_share_items(void *data, Evas_Object *genlist)
360 GL_CHECK_VAL(genlist, -1);
361 GL_CHECK_VAL(data, -1);
362 gl_appdata *ad = (gl_appdata *)data;
363 const char *lb = NULL;
366 Elm_Genlist_Item_Class *plit = &(ad->popupinfo.popuplit);
368 gl_popup_share_tbl popup_share_tbl[GL_POPUP_SHARE_NUM] = {
369 {GL_POPUP_SHARE_MESSAGE, GL_SHARE_MESSAGE},
370 {GL_POPUP_SHARE_EMAIL, GL_SHARE_EMAIL},
371 {GL_POPUP_SHARE_BT, GL_SHARE_BLUETOOTH},
373 {GL_POPUP_SHARE_WIFI, GL_SHARE_WIFI},
378 * If there is any DRM file selected,
379 * Share option is unavailable.
381 int share_mode = gl_get_share_mode(ad);
382 if (share_mode < 0 || share_mode == GL_SHARE_NONE ||
383 share_mode == GL_SHARE_DRM) {
384 gl_dbgE("Share mode is wrong!");
388 int view_mode = gl_get_view_mode(ad);
390 if (view_mode == GL_VIEW_ALBUMS_EDIT) {
391 for (i = 0; i < GL_POPUP_SHARE_NUM; i++) {
392 lb = popup_share_tbl[i].label;
394 if (g_strcmp0(lb, GL_SHARE_MESSAGE) &&
395 g_strcmp0(lb, GL_SHARE_EMAIL) &&
396 g_strcmp0(lb, GL_SHARE_BLUETOOTH))
399 elm_genlist_item_append(genlist, plit, (void *)lb, NULL,
400 ELM_GENLIST_ITEM_NONE,
401 _gl_popup_share_cb, (void *)lb);
407 for (i = 0; i < GL_POPUP_SHARE_NUM; i++) {
408 lb = popup_share_tbl[i].label;
409 if (lb == NULL || strlen(lb) == 0)
411 elm_genlist_item_append(genlist, plit, (void *)lb, NULL,
412 ELM_GENLIST_ITEM_NONE,
413 _gl_popup_share_cb, (void *)lb);
419 /* Append items to list in popup for 'Move' */
420 static int _gl_popup_append_move_items(void *data, Evas_Object *genlist)
423 GL_CHECK_VAL(genlist, -1);
424 GL_CHECK_VAL(data, -1);
425 gl_appdata *ad = (gl_appdata *)data;
429 Eina_List *album_list = NULL;
431 gl_cluster *album_item = NULL;
432 Elm_Genlist_Item_Class *plit = &(ad->popupinfo.popuplit);
433 gl_cluster *current_album = ad->albuminfo.current_album;
436 elm_genlist_item_append(genlist, plit, (void *)idx, NULL,
437 ELM_GENLIST_ITEM_NONE, _gl_popup_move_cb,
441 if (ad->albuminfo.cluster_list && ad->albuminfo.cluster_list->clist) {
442 album_list = ad->albuminfo.cluster_list->clist;
443 all_count = eina_list_count(album_list);
445 gl_dbgE("cluster list is NULL");
449 for (i = 0; i < all_count; i++) {
450 album_item = eina_list_nth(album_list, i);
451 GL_CHECK_VAL(album_item, -1);
452 GL_CHECK_VAL(album_item->cluster, -1);
453 GL_CHECK_VAL(album_item->cluster->display_name, -1);
457 GL_CHECK_VAL(album_item->cluster->uuid, -1);
458 if (current_album && current_album->cluster &&
459 album_item->cluster->uuid &&
460 g_strcmp0(album_item->cluster->uuid, current_album->cluster->uuid)) {
461 /* so guaranty 'All' album is the first genlist item. */
462 if (!g_strcmp0(album_item->cluster->uuid, GL_ALBUM_ALL_ID))
463 gl_dbg("Met All album, get next.");
465 elm_genlist_item_append(genlist, plit,
467 ELM_GENLIST_ITEM_NONE,
469 album_item->cluster->path);
477 int gl_popup_create_albums_del_popup(void *data)
479 GL_CHECK_VAL(data, -1);
480 gl_appdata *ad = (gl_appdata *)data;
483 if (ad->popupinfo.popup != NULL) {
484 gl_dbg("The existed popup is deleted");
485 evas_object_del(ad->popupinfo.popup);
488 Evas_Object *popup = elm_popup_add(ad->maininfo.win);
489 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
491 Evas_Object *btn1 = NULL;
492 Evas_Object *btn2 = NULL;
493 btn1 = _gl_but_create_but_popup(popup, GL_STR_DELETE,
494 __gl_popup_del_resp_cb, data);
495 btn2 = _gl_but_create_but_popup(popup, GL_STR_CANCEL,
496 __gl_popup_del_resp_cb, data);
497 elm_object_part_content_set(popup, "button1", btn1);
498 elm_object_part_content_set(popup, "button2", btn2);
500 elm_object_text_set(popup, GL_STR_DELETE_COMFIRMATION);
502 evas_object_show(popup);
503 ad->popupinfo.popup = popup;
504 ad->popupinfo.popup_mode = GL_POPUP_ALBUM_DELETE;
508 int _gl_popup_create_video_del_popup(void *data)
510 GL_CHECK_VAL(data, -1);
511 gl_item *gitem = (gl_item *) data;
512 GL_CHECK_VAL(gitem->ad, -1);
513 gl_appdata *ad = (gl_appdata *)gitem->ad;
516 if (ad->popupinfo.popup) {
517 gl_dbg("Remove the existed popup.");
518 evas_object_del(ad->popupinfo.popup);
521 Evas_Object *popup = NULL;
522 popup = elm_popup_add(ad->maininfo.win);
523 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
526 Evas_Object *btn1 = NULL;
527 Evas_Object *btn2 = NULL;
528 btn1 = _gl_but_create_but_popup(popup, GL_STR_DELETE,
529 __gl_popup_del_video_resp_cb, data);
530 btn2 = _gl_but_create_but_popup(popup, GL_STR_CANCEL,
531 __gl_popup_del_video_resp_cb, data);
532 elm_object_part_content_set(popup, "button1", btn1);
533 elm_object_part_content_set(popup, "button2", btn2);
535 elm_object_text_set(popup, GL_STR_DELETE_COMFIRMATION);
537 evas_object_show(popup);
538 ad->popupinfo.popup = popup;
539 ad->popupinfo.popup_mode = GL_POPUP_VIDEO_DELETE;
544 static Evas_Object *_gl_popup_set_box(Evas_Object *parent,
545 Evas_Object *genlist, int item_cnt)
547 GL_CHECK_NULL(parent);
548 GL_CHECK_NULL(genlist);
549 Evas_Object *box = elm_box_add(parent);
552 evas_object_size_hint_min_set(box, GL_POPUP_MENUSTYLE_WIDTH,
553 GL_POPUP_MENUSTYLE_HEIGHT(item_cnt));
555 evas_object_size_hint_min_set(box, GL_POPUP_MENUSTYLE_WIDTH,
556 GL_POPUP_MENUSTYLE_HEIGHT_MAX);
558 evas_object_show(genlist);
559 elm_box_pack_end(box, genlist);
564 gl_popup_create_title_popup(void *data, gl_popup_mode mode, char *title, char *desc)
566 GL_CHECK_VAL(data, -1);
567 gl_appdata *ad = (gl_appdata *)data;
570 if (ad->popupinfo.popup)
572 gl_dbg("Delete existed popup.");
573 evas_object_del(ad->popupinfo.popup);
576 Evas_Object *popup = elm_popup_add(ad->maininfo.win);
577 ad->popupinfo.popup = popup;
578 ad->popupinfo.popup_mode = mode;
579 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
580 elm_object_text_set(popup, desc);
581 Evas_Object *genlist = NULL;
582 Evas_Object *box = NULL;
584 Evas_Object *btn1 = NULL;
587 case GL_POPUP_ALBUM_SHARE:
588 case GL_POPUP_THUMB_SHARE:
589 elm_object_style_set(popup, GL_POPUP_STYLE_MIN_MENUSTYLE);
590 elm_object_part_text_set(popup, GL_POPUP_TEXT, title);
591 btn1 = _gl_but_create_but_popup(popup, GL_STR_CLOSE,
592 _gl_popup_resp_cb, data);
593 elm_object_part_content_set(popup, "button1", btn1);
595 genlist = __gl_popup_create_list(ad, popup, NULL);
596 if ((g_cnt = _gl_popup_append_share_items(ad, genlist)) < 0) {
597 gl_dbgE("_gl_popup_append_share_items failed!");
600 box = _gl_popup_set_box(popup, genlist, g_cnt);
601 elm_object_content_set(popup, box);
603 case GL_POPUP_THUMB_MOVE:
604 elm_object_style_set(popup, GL_POPUP_STYLE_MIN_MENUSTYLE);
605 elm_object_part_text_set(popup, GL_POPUP_TEXT, title);
606 btn1 = _gl_but_create_but_popup(popup, GL_STR_CANCEL,
607 _gl_popup_resp_cb, data);
608 elm_object_part_content_set(popup, "button1", btn1);
610 genlist = __gl_popup_create_list(ad, popup, NULL);
611 if ((g_cnt = _gl_popup_append_move_items(ad, genlist)) < 0) {
612 gl_dbgE("_gl_popup_append_move_items failed!");
615 box = _gl_popup_set_box(popup, genlist, g_cnt);
616 elm_object_content_set(popup, box);
619 gl_dbg("Unexpected mode!");
623 evas_object_show(popup);
627 gl_dbgE("POPUP_FAILED");
628 evas_object_del(popup);
629 ad->popupinfo.popup = NULL;
633 int gl_popup_create_popup(void *data, gl_popup_mode mode, char *desc)
635 GL_CHECK_VAL(data, -1);
636 gl_appdata *ad = (gl_appdata *)data;
639 if (ad->popupinfo.popup) {
640 gl_dbg("The existed popup is deleted");
641 evas_object_del(ad->popupinfo.popup);
642 ad->popupinfo.popup = NULL;
646 * Pogressbar is showed during moving or deleting medias,
647 * don't delete it while show popup.
649 if (mode != GL_POPUP_NOBUT_MOV_DEL)
652 Evas_Object *popup = elm_popup_add(ad->maininfo.win);
653 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
655 elm_object_text_set(popup, desc);
656 Evas_Object *btn1 = NULL;
657 Evas_Object *btn2 = NULL;
661 __gl_popup_add_timer(ad, GL_POPUP_TIMEOUT_3S);
663 case GL_POPUP_NOBUT_MOV_DEL:
664 __gl_popup_add_timer(ad, GL_POPUP_TIMEOUT_1S);
666 case GL_POPUP_ALBUM_NEW_EMPTY:
667 case GL_POPUP_ALBUM_NEW_DUPLICATE:
668 case GL_POPUP_ALBUM_NEW_INVALID:
669 case GL_POPUP_ALBUM_RENAME_EMPTY:
670 case GL_POPUP_ALBUM_RENAME_DUPLICATE:
671 case GL_POPUP_ALBUM_RENAME_INVALID:
672 btn1 = _gl_but_create_but_popup(popup, GL_STR_YES,
673 _gl_popup_resp_cb, data);
674 elm_object_part_content_set(popup, "button1", btn1);
675 btn2 = _gl_but_create_but_popup(popup, GL_STR_NO,
676 _gl_popup_resp_cb, data);
677 elm_object_part_content_set(popup, "button2", btn2);
680 gl_dbgE("Other popup mode...");
684 evas_object_show(popup);
686 ad->popupinfo.popup = popup;
687 ad->popupinfo.popup_mode = mode;
692 /* Update popup contents */
693 int gl_popup_update_content(void *data, gl_popup_mode mode)
695 GL_CHECK_VAL(data, -1);
696 gl_appdata *ad = (gl_appdata *)data;
697 GL_CHECK_VAL(ad->popupinfo.popup, -1);
698 gl_dbg("mode: %d.", mode);
700 Evas_Object *content = elm_object_content_get(ad->popupinfo.popup);
701 GL_CHECK_VAL(content, -1);
702 Eina_List *chidren = elm_box_children_get(content);
703 GL_CHECK_VAL(chidren, -1);
704 Evas_Object *genlist = eina_list_nth(chidren, 0);
705 GL_CHECK_VAL(genlist, -1);
706 elm_genlist_clear(genlist);
710 case GL_POPUP_THUMB_MOVE:
711 if ((cnt = _gl_popup_append_move_items(ad, genlist)) < 0) {
712 gl_dbgE("_gl_popup_append_move_items failed!");
721 evas_object_size_hint_min_set(content,
722 GL_POPUP_MENUSTYLE_WIDTH,
723 GL_POPUP_MENUSTYLE_HEIGHT(cnt));
725 evas_object_size_hint_min_set(content,
726 GL_POPUP_MENUSTYLE_WIDTH,
727 GL_POPUP_MENUSTYLE_HEIGHT_MAX);
729 evas_object_del(ad->popupinfo.popup);
730 ad->popupinfo.popup = NULL;
731 ad->popupinfo.popup_mode = 0;