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-ui-util.h"
23 #include "gl-listview.h"
24 #include "gl-progressbar.h"
25 #include "gl-strings.h"
26 #include "gl-button.h"
28 #define GL_POPUP_OBJ_DATA_KEY "popup_list_data"
29 #define GL_GENLIST_ITEM_STYLE_1TEXT "1text"
30 #define GL_GENLIST_ITEM_STYLE_1TEXT_1ICON "1text.1icon"
31 #define GL_GENLIST_ITEM_STYLE_1TEXT_1ICON_2 "1text.1icon.2"
32 #define GL_POPUP_STYLE_MIN_MENUSTYLE "min_menustyle"
34 #define GL_POPUP_MENUSTYLE_WIDTH (614*elm_config_scale_get())
35 #define GL_POPUP_MENUSTYLE_HEIGHT(x) ((113*x-1)*elm_config_scale_get())
36 #define GL_POPUP_MENUSTYLE_HEIGHT_MAX (408*elm_config_scale_get())
38 #define GL_POPUP_TIMEOUT_1S 1.0
39 #define GL_POPUP_TIMEOUT_2S 2.0
40 #define GL_POPUP_TIMEOUT_3S 3.0
42 static Eina_Bool __gl_popup_timeout_cb(void *data)
45 gl_appdata *ad = (gl_appdata *)data;
46 if (ad->popupinfo.del_timer) {
47 ecore_timer_del(ad->popupinfo.del_timer);
48 ad->popupinfo.del_timer = NULL;
51 if (ad->popupinfo.popup) {
52 evas_object_del(ad->popupinfo.popup);
53 ad->popupinfo.popup = NULL;
55 return ECORE_CALLBACK_CANCEL;
58 static int __gl_popup_add_timer(void *data, double to_inc)
60 GL_CHECK_VAL(data, -1);
61 gl_appdata *ad = (gl_appdata *)data;
62 if (ad->popupinfo.del_timer) {
63 ecore_timer_del(ad->popupinfo.del_timer);
64 ad->popupinfo.del_timer = NULL;
67 ad->popupinfo.del_timer = ecore_timer_add(to_inc, __gl_popup_timeout_cb,
72 static void __gl_popup_del_resp_cb(void *data, Evas_Object *obj,
77 gl_appdata *ad = (gl_appdata *)data;
78 const char *text = NULL;
80 text = elm_object_text_get(obj);
82 gl_dbg("Button: %s, mode: %d", text, ad->popupinfo.popup_mode);
84 if (!g_strcmp0(text, GL_STR_YES)) {
85 if (ad->popupinfo.popup_mode == GL_POPUP_ALBUM_DELETE)
89 if (ad->popupinfo.popup) {
90 evas_object_del(ad->popupinfo.popup);
91 ad->popupinfo.popup = NULL;
95 static void _gl_popup_move_to_album(void *data)
98 gl_appdata *ad = (gl_appdata *)data;
101 * 'move_album_id == NULL' is new album case,
102 * other move/save to some existed album.
104 if (ad->albuminfo.move_album_id)
105 gl_move_to_album(ad);
107 gl_ui_move_to_newalbum(ad);
110 static void _gl_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
113 gl_appdata *ad = (gl_appdata *)data;
114 int mode = ad->popupinfo.popup_mode;
115 Ecore_IMF_Context *imf = ad->entryinfo.imf_context;
116 const char *text = NULL;
118 text = elm_object_text_get(obj);
120 gl_dbg("Button: %s, mode: %d", text, mode);
122 if (mode == GL_POPUP_ALBUM_NEW_EMPTY ||
123 mode == GL_POPUP_ALBUM_NEW_DUPLICATE ||
124 mode == GL_POPUP_ALBUM_NEW_INVALID) {
125 if (!g_strcmp0(text, GL_STR_YES) ||
126 !g_strcmp0(text, GL_STR_OK)) {
127 ad->entryinfo.entry_mode = GL_ENTRY_NEW_ALBUM;
128 evas_object_show(ad->entryinfo.imf_entry);
129 elm_object_focus_set(ad->entryinfo.imf_entry, EINA_TRUE);
130 ecore_imf_context_input_panel_show(imf);
131 } else if (!g_strcmp0(text, GL_STR_NO) ||
132 !g_strcmp0(text, GL_STR_CANCEL)) {
133 if (ad->entryinfo.imf_entry)
134 ecore_imf_context_input_panel_hide(imf);
136 gl_ui_cancel_new_album(ad);
138 } else if (mode == GL_POPUP_ALBUM_RENAME_EMPTY ||
139 mode == GL_POPUP_ALBUM_RENAME_DUPLICATE ||
140 mode == GL_POPUP_ALBUM_RENAME_INVALID) {
141 if (!g_strcmp0(text, GL_STR_YES) ||
142 !g_strcmp0(text, GL_STR_OK)) {
143 evas_object_show(ad->entryinfo.imf_entry);
144 elm_object_focus_set(ad->entryinfo.imf_entry, EINA_TRUE);
145 ecore_imf_context_input_panel_show(imf);
146 } else if (!g_strcmp0(text, GL_STR_NO) ||
147 !g_strcmp0(text, GL_STR_CANCEL)) {
148 if (ad->entryinfo.imf_entry)
149 ecore_imf_context_input_panel_hide(imf);
150 gl_ui_cancel_rename_album(ad);
152 } else if (mode == GL_POPUP_NOBUT_APPEXIT) {
153 if (ad->popupinfo.popup) {
154 evas_object_del(ad->popupinfo.popup);
155 ad->popupinfo.popup = NULL;
159 } else if (mode == GL_POPUP_NOBUT_ENTRY) {
160 evas_object_show(ad->entryinfo.imf_entry);
161 elm_object_focus_set(ad->entryinfo.imf_entry, EINA_TRUE);
162 ecore_imf_context_input_panel_show(imf);
165 if (ad->popupinfo.popup) {
166 evas_object_del(ad->popupinfo.popup);
167 ad->popupinfo.popup = NULL;
173 _gl_popup_list_get_text(void *data, Evas_Object * obj, const char *part)
177 /* Get 'ad' via 'popup_list_data' */
178 gl_appdata *ad = (gl_appdata *)evas_object_data_get(obj, GL_POPUP_OBJ_DATA_KEY);
181 int mode = ad->popupinfo.popup_mode;
182 const char *label = NULL;
184 * Use index for album move,
185 * mainly for showing 'New album'
189 if (!strcmp(part, "elm.text"))
193 case GL_POPUP_THUMB_MOVE:
195 /* 1, Prevent pass NULL data */
199 label = GL_STR_NEW_ALBUM; //add "New album" item.
203 Eina_List *album_list = NULL;
205 if (ad->albuminfo.cluster_list && ad->albuminfo.cluster_list->clist)
207 album_list = ad->albuminfo.cluster_list->clist;
211 gl_dbgE("cluster list is NULL.");
215 gl_cluster *album_item = eina_list_nth(album_list, idx);
216 if (album_item && album_item->cluster &&
217 album_item->cluster->uuid &&
218 album_item->cluster->display_name) {
219 if (strlen(album_item->cluster->display_name))
221 label = album_item->cluster->display_name;
223 else if (gl_db_is_root_path(ad, album_item->cluster->uuid, NULL)) //"root" case, set display name as "No Name"
225 label = GL_ALBUM_PHOME_ROOT_NAME;
229 gl_dbgE("Album name[%s] is wrong!", album_item->cluster->display_name);
230 label = GL_ALBUM_PHOME_ROOT_NAME;
236 gl_dbg("default: wrong mode.");
242 return strdup(label);
246 gl_dbgE("label is NULL");
257 _gl_popup_list_get_icon(void *data, Evas_Object * obj, const char *part)
264 _gl_popup_create_list(void *data, Evas_Object * parent, const char *item_type)
266 GL_CHECK_NULL(parent);
268 gl_appdata *ad = (gl_appdata *)data;
273 ad->popupinfo.popuplit.item_style = item_type;
277 ad->popupinfo.popuplit.item_style = GL_GENLIST_ITEM_STYLE_1TEXT;
279 ad->popupinfo.popuplit.func.text_get = _gl_popup_list_get_text;
280 ad->popupinfo.popuplit.func.content_get = _gl_popup_list_get_icon;
281 ad->popupinfo.popuplit.func.state_get = NULL;
282 ad->popupinfo.popuplit.func.del = NULL;
284 Evas_Object *genlist = elm_genlist_add(parent);
285 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
286 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
288 /* Attach 'ad' to genlist with 'GL_POPUP_OBJ_DATA_KEY' key to prevent use global variable. */
289 evas_object_data_set(genlist, GL_POPUP_OBJ_DATA_KEY, data);
295 _gl_popup_move_cb(void *data, Evas_Object * obj, void *event_info)
298 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
301 elm_genlist_item_selected_set(item, EINA_FALSE);
304 /* Get 'ad' via 'GL_POPUP_OBJ_DATA_KEY' */
306 gl_appdata *ad = (gl_appdata *)evas_object_data_get(obj, GL_POPUP_OBJ_DATA_KEY);
308 if (ad->albuminfo.move_album_id) {
309 free(ad->albuminfo.move_album_id);
310 ad->albuminfo.move_album_id = NULL;
313 ad->albuminfo.move_album_id = strdup((char *)data);
314 gl_dbg("Dest album id: %s", ad->albuminfo.move_album_id);
316 if (ad->popupinfo.popup) {
317 evas_object_del(ad->popupinfo.popup);
318 ad->popupinfo.popup = NULL;
321 _gl_popup_move_to_album(ad);
324 /* Append items to list in popup for 'Move' */
325 static int _gl_popup_append_move_items(void *data, Evas_Object *genlist)
328 GL_CHECK_VAL(genlist, -1);
329 GL_CHECK_VAL(data, -1);
330 gl_appdata *ad = (gl_appdata *)data;
334 Eina_List *album_list = NULL;
336 gl_cluster *album_item = NULL;
337 Elm_Genlist_Item_Class *plit = &(ad->popupinfo.popuplit);
338 gl_cluster *current_album = ad->albuminfo.current_album;
339 GL_CHECK_VAL(current_album, -1);
340 GL_CHECK_VAL(current_album->cluster, -1);
341 GL_CHECK_VAL(current_album->cluster->uuid, -1);
344 elm_genlist_item_append(genlist, plit, (void *)idx, NULL,
345 ELM_GENLIST_ITEM_NONE, _gl_popup_move_cb,
349 if (ad->albuminfo.cluster_list && ad->albuminfo.cluster_list->clist) {
350 album_list = ad->albuminfo.cluster_list->clist;
351 all_count = eina_list_count(album_list);
353 gl_dbgE("cluster list is NULL");
357 for (i = 0; i < all_count; i++) {
358 album_item = eina_list_nth(album_list, i);
359 GL_CHECK_VAL(album_item, -1);
360 GL_CHECK_VAL(album_item->cluster, -1);
361 GL_CHECK_VAL(album_item->cluster->display_name, -1);
364 GL_CHECK_VAL(album_item->cluster->uuid, -1);
365 if (g_strcmp0(album_item->cluster->uuid, current_album->cluster->uuid)) {
366 /* so guaranty 'All' album is the first genlist item. */
367 if (!g_strcmp0(album_item->cluster->uuid, GL_ALBUM_ALL_ID))
368 gl_dbg("Met All album, get next.");
370 elm_genlist_item_append(genlist, plit,
372 ELM_GENLIST_ITEM_NONE,
374 album_item->cluster->uuid);
382 int gl_popup_create_albums_del_popup(void *data)
384 GL_CHECK_VAL(data, -1);
385 gl_appdata *ad = (gl_appdata *)data;
388 if (ad->popupinfo.popup != NULL) {
389 gl_dbg("The existed popup is deleted");
390 evas_object_del(ad->popupinfo.popup);
393 Evas_Object *popup = elm_popup_add(ad->maininfo.win);
394 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
396 elm_object_text_set(popup, GL_STR_DELETE_COMFIRMATION);
397 Evas_Object *btn1 = NULL;
398 Evas_Object *btn2 = NULL;
399 btn1 = _gl_but_create_but_popup(popup, GL_STR_YES,
400 __gl_popup_del_resp_cb, data);
401 btn2 = _gl_but_create_but_popup(popup, GL_STR_NO,
402 __gl_popup_del_resp_cb, data);
403 elm_object_part_content_set(popup, "button1", btn1);
404 elm_object_part_content_set(popup, "button2", btn2);
406 evas_object_show(popup);
407 ad->popupinfo.popup = popup;
408 ad->popupinfo.popup_mode = GL_POPUP_ALBUM_DELETE;
412 static Evas_Object *_gl_popup_set_box(Evas_Object *parent,
413 Evas_Object *genlist, int item_cnt)
415 GL_CHECK_NULL(parent);
416 GL_CHECK_NULL(genlist);
417 Evas_Object *box = elm_box_add(parent);
420 evas_object_size_hint_min_set(box, GL_POPUP_MENUSTYLE_WIDTH,
421 GL_POPUP_MENUSTYLE_HEIGHT(item_cnt));
423 evas_object_size_hint_min_set(box, GL_POPUP_MENUSTYLE_WIDTH,
424 GL_POPUP_MENUSTYLE_HEIGHT_MAX);
426 evas_object_show(genlist);
427 elm_box_pack_end(box, genlist);
432 gl_popup_create_title_popup(void *data, gl_popup_mode mode, char *title, char *desc)
434 GL_CHECK_VAL(data, -1);
435 gl_appdata *ad = (gl_appdata *)data;
438 if (ad->popupinfo.popup)
440 gl_dbg("Delete existed popup.");
441 evas_object_del(ad->popupinfo.popup);
444 Evas_Object *popup = elm_popup_add(ad->maininfo.win);
445 ad->popupinfo.popup = popup;
446 ad->popupinfo.popup_mode = mode;
447 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
448 elm_object_text_set(popup, desc);
449 Evas_Object *genlist = NULL;
450 Evas_Object *box = NULL;
452 Evas_Object *btn1 = NULL;
455 case GL_POPUP_THUMB_MOVE:
456 elm_object_style_set(popup, GL_POPUP_STYLE_MIN_MENUSTYLE);
457 elm_object_part_text_set(popup, "title,text", title);
458 btn1 = _gl_but_create_but_popup(popup, GL_STR_CANCEL,
459 _gl_popup_resp_cb, data);
460 elm_object_part_content_set(popup, "button1", btn1);
462 genlist = _gl_popup_create_list(ad, popup, NULL);
463 if ((g_cnt = _gl_popup_append_move_items(ad, genlist)) < 0) {
464 gl_dbgE("_gl_popup_append_move_items failed!");
467 box = _gl_popup_set_box(popup, genlist, g_cnt);
468 elm_object_content_set(popup, box);
471 gl_dbg("Unexpected mode!");
475 evas_object_show(popup);
479 gl_dbgE("POPUP_FAILED");
480 evas_object_del(popup);
481 ad->popupinfo.popup = NULL;
485 int gl_popup_create_popup(void *data, gl_popup_mode mode, char *desc)
487 GL_CHECK_VAL(data, -1);
488 gl_appdata *ad = (gl_appdata *)data;
491 if (ad->popupinfo.popup) {
492 gl_dbg("The existed popup is deleted");
493 evas_object_del(ad->popupinfo.popup);
494 ad->popupinfo.popup = NULL;
498 * Pogressbar is showed during moving or deleting medias,
499 * don't delete it while show popup.
501 if (mode != GL_POPUP_NOBUT_MOV_DEL)
504 Evas_Object *popup = elm_popup_add(ad->maininfo.win);
505 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
507 elm_object_text_set(popup, desc);
508 Evas_Object *btn1 = NULL;
509 Evas_Object *btn2 = NULL;
513 case GL_POPUP_NOBUT_APPEXIT:
514 case GL_POPUP_NOBUT_ENTRY:
515 __gl_popup_add_timer(ad, GL_POPUP_TIMEOUT_3S);
517 case GL_POPUP_NOBUT_1S:
518 case GL_POPUP_NOBUT_MOV_DEL:
519 __gl_popup_add_timer(ad, GL_POPUP_TIMEOUT_3S);
521 case GL_POPUP_ONEBUT:
522 btn1 = _gl_but_create_but_popup(popup, GL_STR_OK,
523 _gl_popup_resp_cb, data);
524 elm_object_part_content_set(popup, "button1", btn1);
526 case GL_POPUP_TWOBUT:
527 btn1 = _gl_but_create_but_popup(popup, GL_STR_OK,
528 _gl_popup_resp_cb, data);
529 elm_object_part_content_set(popup, "button1", btn1);
530 btn2 = _gl_but_create_but_popup(popup, GL_STR_CANCEL,
531 _gl_popup_resp_cb, data);
532 elm_object_part_content_set(popup, "button2", btn2);
534 case GL_POPUP_ALBUM_NEW_EMPTY:
535 case GL_POPUP_ALBUM_NEW_DUPLICATE:
536 case GL_POPUP_ALBUM_NEW_INVALID:
537 case GL_POPUP_ALBUM_RENAME_EMPTY:
538 case GL_POPUP_ALBUM_RENAME_DUPLICATE:
539 case GL_POPUP_ALBUM_RENAME_INVALID:
540 btn1 = _gl_but_create_but_popup(popup, GL_STR_YES,
541 _gl_popup_resp_cb, data);
542 elm_object_part_content_set(popup, "button1", btn1);
543 btn2 = _gl_but_create_but_popup(popup, GL_STR_NO,
544 _gl_popup_resp_cb, data);
545 elm_object_part_content_set(popup, "button2", btn2);
548 gl_dbgE("Other popup mode...");
552 evas_object_show(popup);
554 /* Focus popup and IMF hide */
555 if (mode == GL_POPUP_NOBUT_ENTRY)
556 elm_object_focus_set(popup, TRUE);
558 ad->popupinfo.popup = popup;
559 ad->popupinfo.popup_mode = mode;
564 /* Update popup contents */
565 int gl_popup_update_content(void *data, gl_popup_mode mode)
567 GL_CHECK_VAL(data, -1);
568 gl_appdata *ad = (gl_appdata *)data;
569 GL_CHECK_VAL(ad->popupinfo.popup, -1);
570 gl_dbg("mode: %d.", mode);
572 Evas_Object *content = elm_object_content_get(ad->popupinfo.popup);
573 GL_CHECK_VAL(content, -1);
574 Eina_List *chidren = elm_box_children_get(content);
575 GL_CHECK_VAL(chidren, -1);
576 Evas_Object *genlist = eina_list_nth(chidren, 0);
577 GL_CHECK_VAL(genlist, -1);
578 elm_genlist_clear(genlist);
582 case GL_POPUP_THUMB_MOVE:
583 if ((cnt = _gl_popup_append_move_items(ad, genlist)) < 0) {
584 gl_dbgE("_gl_popup_append_move_items failed!");