initial upload for tizen 2.0 beta
[apps/home/gallery.git] / src / widget / gl-popup.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
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
7   *
8   *     http://www.tizenopensource.org/license
9   *
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.
15   */
16
17 #include "gallery.h"
18 #include "gl-popup.h"
19 #include "gl-ui-util.h"
20 #include "gl-util.h"
21 #include "gl-debug.h"
22 #include "gl-listview.h"
23 #include "gl-progressbar.h"
24 #include "gl-strings.h"
25 #include "gl-button.h"
26
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"
30
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())
34
35 #define GL_POPUP_TIMEOUT_1S 1.0
36 #define GL_POPUP_TIMEOUT_3S 3.0
37
38 static Eina_Bool __gl_popup_timeout_cb(void *data)
39 {
40         GL_CHECK_FALSE(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;
45         }
46
47         if (ad->popupinfo.popup) {
48                 evas_object_del(ad->popupinfo.popup);
49                 ad->popupinfo.popup = NULL;
50         }
51         return ECORE_CALLBACK_CANCEL;
52 }
53
54 static int __gl_popup_add_timer(void *data, double to_inc)
55 {
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;
61         }
62
63         ad->popupinfo.del_timer = ecore_timer_add(to_inc, __gl_popup_timeout_cb,
64                                                   data);
65         return 0;
66 }
67
68 static void __gl_popup_del_resp_cb(void *data, Evas_Object *obj,
69                                    void *event_info)
70 {
71         GL_CHECK(obj);
72         GL_CHECK(data);
73         gl_appdata *ad = (gl_appdata *)data;
74         const char *text = NULL;
75
76         text = elm_object_text_get(obj);
77         GL_CHECK(text);
78         gl_dbg("Button: %s, mode: %d", text, ad->popupinfo.popup_mode);
79
80         if (!g_strcmp0(text, GL_STR_DELETE)) {
81                 if (ad->popupinfo.popup_mode == GL_POPUP_ALBUM_DELETE)
82                         gl_del_albums(ad);
83         }
84
85         if (ad->popupinfo.popup) {
86                 evas_object_del(ad->popupinfo.popup);
87                 ad->popupinfo.popup = NULL;
88         }
89 }
90
91 static void _gl_popup_move_to_album(void *data)
92 {
93         GL_CHECK(data);
94         gl_appdata *ad = (gl_appdata *)data;
95         gl_dbg("");
96         /**
97         * 'move_album_id == NULL' is new album case,
98         * other move/save to some existed album.
99         */
100         if (ad->albuminfo.path)
101                 gl_move_to_album(ad);
102         else
103                 gl_ui_move_to_newalbum(ad);
104 }
105
106 static void __gl_popup_del_video_resp_cb(void *data, Evas_Object *obj,
107                                     void *event_info)
108 {
109         GL_CHECK(obj);
110         GL_CHECK(data);
111         gl_item *gitem = (gl_item *)data;
112         GL_CHECK(gitem->ad);
113         gl_appdata *ad = (gl_appdata *)gitem->ad;
114         const char *text = NULL;
115
116         text = elm_object_text_get(obj);
117         GL_CHECK(text);
118         gl_dbg("Button: %s", text);
119
120         if (!g_strcmp0(text, GL_STR_DELETE))
121                 _gl_del_video(data);
122
123         if (ad->popupinfo.popup) {
124                 evas_object_del(ad->popupinfo.popup);
125                 ad->popupinfo.popup = NULL;
126         }
127 }
128
129 static void _gl_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
130 {
131         GL_CHECK(data);
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;
136
137         text = elm_object_text_get(obj);
138         GL_CHECK(text);
139         gl_dbg("Button: %s, mode: %d", text, mode);
140
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);
154
155                         gl_ui_cancel_new_album(ad);
156                 }
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);
170                 }
171         }
172
173         if (ad->pbarinfo.pbar_popup) {
174                 evas_object_del(ad->pbarinfo.pbar_popup);
175                 ad->pbarinfo.pbar_popup = NULL;
176         }
177         if (ad->popupinfo.popup) {
178                 evas_object_del(ad->popupinfo.popup);
179                 ad->popupinfo.popup = NULL;
180         }
181 }
182
183 static char *__gl_popup_list_get_text(void *data, Evas_Object *obj, const char *part)
184 {
185         GL_CHECK_NULL(obj);
186         GL_CHECK_NULL(data);
187         /* Get 'ad' via 'popup_list_data' */
188         gl_appdata *ad = (gl_appdata *)evas_object_data_get(obj, GL_POPUP_OBJ_DATA_KEY);
189         GL_CHECK_NULL(ad);
190         //gl_dbg("");
191
192         int mode = ad->popupinfo.popup_mode;
193         const char *label = NULL;
194         /**
195         * Use index for album move ,
196         * mainly for showing 'New album'
197         */
198         int idx = 0;
199
200         if (!g_strcmp0(part, "elm.text"))
201         {
202                 switch (mode)
203                 {
204                 case GL_POPUP_THUMB_SHARE:
205                 case GL_POPUP_ALBUM_SHARE:
206                         label = (char *)data;
207                         break;
208                 case GL_POPUP_THUMB_MOVE:
209                         idx = (int)data;
210                         /* 1, Prevent pass NULL data; */
211                         idx -= 2;
212                         if (idx == -1)
213                         {
214                                 label = GL_STR_CREATE_ALBUM;    //add "New album" item.
215                         }
216                         else
217                         {
218                                 Eina_List *album_list = NULL;
219
220                                 if (ad->albuminfo.cluster_list && ad->albuminfo.cluster_list->clist)
221                                 {
222                                         album_list = ad->albuminfo.cluster_list->clist;
223                                 }
224                                 else
225                                 {
226                                         gl_dbgE("cluster list is NULL.");
227                                         return NULL;
228                                 }
229
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))
235                                         {
236                                                 label = album_item->cluster->display_name;
237                                         }
238                                         else if (_gl_data_is_root_path(ad, album_item->cluster->path))  //"root" case, set display name as "No Name"
239                                         {
240                                                 label = GL_ALBUM_PHOME_ROOT_NAME;
241                                         }
242                                         else
243                                         {
244                                                 gl_dbgE("Album name[%s] is wrong!", album_item->cluster->display_name);
245                                                 label = GL_ALBUM_PHOME_ROOT_NAME;
246                                         }
247                                 }
248                         }
249                         break;
250                 default:
251                         gl_dbg("default: wrong mode.");
252                         break;
253                 }
254
255                 if (label)
256                 {
257                         return strdup(label);
258                 }
259                 else
260                 {
261                         gl_dbgE("label is NULL");
262                         return NULL;
263                 }
264         }
265         else
266         {
267                 return NULL;
268         }
269 }
270
271 static Evas_Object *__gl_popup_create_list(void *data, Evas_Object *parent, const char *item_type)
272 {
273         GL_CHECK_NULL(parent);
274         GL_CHECK_NULL(data);
275         gl_appdata *ad = (gl_appdata *)data;
276         gl_dbg("");
277
278         if (item_type)
279         {
280                 ad->popupinfo.popuplit.item_style = item_type;
281         }
282         else
283         {
284                 ad->popupinfo.popuplit.item_style = GL_GENLIST_ITEM_STYLE_1TEXT;
285         }
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;
290
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);
294
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);
297
298         return genlist;
299 }
300
301 static void
302 _gl_popup_move_cb(void *data, Evas_Object * obj, void *event_info)
303 {
304         gl_dbg("");
305         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
306         if (item)
307         {
308                 elm_genlist_item_selected_set(item, EINA_FALSE);
309         }
310
311         /* Get 'ad' via 'GL_POPUP_OBJ_DATA_KEY' */
312         GL_CHECK(obj);
313         gl_appdata *ad = (gl_appdata *)evas_object_data_get(obj, GL_POPUP_OBJ_DATA_KEY);
314         GL_CHECK(ad);
315         if (ad->albuminfo.path) {
316                 free(ad->albuminfo.path);
317                 ad->albuminfo.path = NULL;
318         }
319         if (data)
320                 ad->albuminfo.path = strdup((char *)data);
321
322         gl_dbg("Dest album path: %s", ad->albuminfo.path);
323
324         if (ad->popupinfo.popup) {
325                 evas_object_del(ad->popupinfo.popup);
326                 ad->popupinfo.popup = NULL;
327         }
328
329         _gl_popup_move_to_album(ad);
330 }
331
332 static void
333 _gl_popup_share_cb(void *data, Evas_Object * obj, void *event_info)
334 {
335         GL_CHECK(data);
336         /* Get 'ad' via 'GL_POPUP_OBJ_DATA_KEY' */
337         GL_CHECK(obj);
338         gl_appdata *ad = (gl_appdata *)evas_object_data_get(obj, GL_POPUP_OBJ_DATA_KEY);
339         GL_CHECK(ad);
340         gl_dbg("");
341
342         g_strlcpy(ad->popupinfo.popup_item_label, (char *)data, GL_ALBUM_NAME_LEN_MAX);
343
344         if (ad->popupinfo.popup) {
345                 evas_object_del(ad->popupinfo.popup);
346                 ad->popupinfo.popup = NULL;
347         }
348
349         int view_mode = gl_get_view_mode(ad);
350         if (view_mode == GL_VIEW_ALBUMS_EDIT)
351                 _gl_share_select_album(ad);
352         else
353                 gl_share_select_item(ad);
354 }
355
356 /* Append items to list in popup for 'Share' */
357 static int _gl_popup_append_share_items(void *data, Evas_Object *genlist)
358 {
359         gl_dbg("");
360         GL_CHECK_VAL(genlist, -1);
361         GL_CHECK_VAL(data, -1);
362         gl_appdata *ad = (gl_appdata *)data;
363         const char *lb = NULL;
364         int i = 0;
365         int item_cnt = 0;
366         Elm_Genlist_Item_Class *plit = &(ad->popupinfo.popuplit);
367
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},
372 #ifdef _USE_WIFI
373                 {GL_POPUP_SHARE_WIFI, GL_SHARE_WIFI},
374 #endif
375         };
376
377         /**
378         * If there is any DRM file selected,
379         * Share option is unavailable.
380         */
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!");
385                 return -1;
386         }
387
388         int view_mode = gl_get_view_mode(ad);
389         /* Share albums */
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;
393
394                         if (g_strcmp0(lb, GL_SHARE_MESSAGE) &&
395                             g_strcmp0(lb, GL_SHARE_EMAIL) &&
396                             g_strcmp0(lb, GL_SHARE_BLUETOOTH))
397                                 continue;
398
399                         elm_genlist_item_append(genlist, plit, (void *)lb, NULL,
400                                                 ELM_GENLIST_ITEM_NONE,
401                                                 _gl_popup_share_cb, (void *)lb);
402                         item_cnt++;
403                 }
404                 return item_cnt;
405         }
406
407         for (i = 0; i < GL_POPUP_SHARE_NUM; i++) {
408                 lb = popup_share_tbl[i].label;
409                 if (lb == NULL || strlen(lb) == 0)
410                         continue;
411                 elm_genlist_item_append(genlist, plit, (void *)lb, NULL,
412                                         ELM_GENLIST_ITEM_NONE,
413                                         _gl_popup_share_cb, (void *)lb);
414                 item_cnt++;
415         }
416         return item_cnt;
417 }
418
419 /* Append items to list in popup for 'Move' */
420 static int _gl_popup_append_move_items(void *data, Evas_Object *genlist)
421 {
422         gl_dbg("");
423         GL_CHECK_VAL(genlist, -1);
424         GL_CHECK_VAL(data, -1);
425         gl_appdata *ad = (gl_appdata *)data;
426         int idx = 0;
427         int i = 0;
428         int item_cnt = 0;
429         Eina_List *album_list = NULL;
430         int all_count = 0;
431         gl_cluster *album_item = NULL;
432         Elm_Genlist_Item_Class *plit = &(ad->popupinfo.popuplit);
433         gl_cluster *current_album = ad->albuminfo.current_album;
434
435         idx++;
436         elm_genlist_item_append(genlist, plit, (void *)idx, NULL,
437                                 ELM_GENLIST_ITEM_NONE, _gl_popup_move_cb,
438                                 NULL);
439         item_cnt++;
440
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);
444         } else {
445                 gl_dbgE("cluster list is NULL");
446                 return -1;
447         }
448
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);
454
455                 idx++;
456
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.");
464                         else {
465                                 elm_genlist_item_append(genlist, plit,
466                                                         (void *)idx, NULL,
467                                                         ELM_GENLIST_ITEM_NONE,
468                                                         _gl_popup_move_cb,
469                                                         album_item->cluster->path);
470                                 item_cnt++;
471                         }
472                 }
473         }
474         return item_cnt;
475 }
476
477 int gl_popup_create_albums_del_popup(void *data)
478 {
479         GL_CHECK_VAL(data, -1);
480         gl_appdata *ad = (gl_appdata *)data;
481         gl_dbg("");
482
483         if (ad->popupinfo.popup != NULL) {
484                 gl_dbg("The existed popup is deleted");
485                 evas_object_del(ad->popupinfo.popup);
486         }
487
488         Evas_Object *popup = elm_popup_add(ad->maininfo.win);
489         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
490
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);
499
500         elm_object_text_set(popup, GL_STR_DELETE_COMFIRMATION);
501
502         evas_object_show(popup);
503         ad->popupinfo.popup = popup;
504         ad->popupinfo.popup_mode = GL_POPUP_ALBUM_DELETE;
505         return 0;
506 }
507
508 int _gl_popup_create_video_del_popup(void *data)
509 {
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;
514         gl_dbg("");
515
516         if (ad->popupinfo.popup) {
517                 gl_dbg("Remove the existed popup.");
518                 evas_object_del(ad->popupinfo.popup);
519         }
520
521         Evas_Object *popup = NULL;
522         popup = elm_popup_add(ad->maininfo.win);
523         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
524                                          EVAS_HINT_EXPAND);
525
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);
534
535         elm_object_text_set(popup, GL_STR_DELETE_COMFIRMATION);
536
537         evas_object_show(popup);
538         ad->popupinfo.popup = popup;
539         ad->popupinfo.popup_mode = GL_POPUP_VIDEO_DELETE;
540
541         return 0;
542 }
543
544 static Evas_Object *_gl_popup_set_box(Evas_Object *parent,
545                                         Evas_Object *genlist, int item_cnt)
546 {
547         GL_CHECK_NULL(parent);
548         GL_CHECK_NULL(genlist);
549         Evas_Object *box = elm_box_add(parent);
550
551         if (item_cnt < 4)
552                 evas_object_size_hint_min_set(box, GL_POPUP_MENUSTYLE_WIDTH,
553                                               GL_POPUP_MENUSTYLE_HEIGHT(item_cnt));
554         else
555                 evas_object_size_hint_min_set(box, GL_POPUP_MENUSTYLE_WIDTH,
556                                               GL_POPUP_MENUSTYLE_HEIGHT_MAX);
557
558         evas_object_show(genlist);
559         elm_box_pack_end(box, genlist);
560         return box;
561 }
562
563 int
564 gl_popup_create_title_popup(void *data, gl_popup_mode mode, char *title, char *desc)
565 {
566         GL_CHECK_VAL(data, -1);
567         gl_appdata *ad = (gl_appdata *)data;
568         gl_dbg("");
569
570         if (ad->popupinfo.popup)
571         {
572                 gl_dbg("Delete existed popup.");
573                 evas_object_del(ad->popupinfo.popup);
574         }
575
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;
583         int g_cnt = 0;
584         Evas_Object *btn1 = NULL;
585
586         switch (mode) {
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);
594
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!");
598                         goto POPUP_FAILED;
599                 }
600                 box = _gl_popup_set_box(popup, genlist, g_cnt);
601                 elm_object_content_set(popup, box);
602                 break;
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);
609
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!");
613                         goto POPUP_FAILED;
614                 }
615                 box = _gl_popup_set_box(popup, genlist, g_cnt);
616                 elm_object_content_set(popup, box);
617                 break;
618         default:
619                 gl_dbg("Unexpected mode!");
620                 break;
621         }
622
623         evas_object_show(popup);
624         return 0;
625
626  POPUP_FAILED:
627         gl_dbgE("POPUP_FAILED");
628         evas_object_del(popup);
629         ad->popupinfo.popup = NULL;
630         return -1;
631 }
632
633 int gl_popup_create_popup(void *data, gl_popup_mode mode, char *desc)
634 {
635         GL_CHECK_VAL(data, -1);
636         gl_appdata *ad = (gl_appdata *)data;
637         gl_dbg("");
638
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;
643         }
644
645         /**
646         * Pogressbar is showed during moving or deleting medias,
647         * don't delete it while show popup.
648         */
649         if (mode != GL_POPUP_NOBUT_MOV_DEL)
650                 gl_pb_del_pbar(ad);
651
652         Evas_Object *popup = elm_popup_add(ad->maininfo.win);
653         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
654                                          EVAS_HINT_EXPAND);
655         elm_object_text_set(popup, desc);
656         Evas_Object *btn1 = NULL;
657         Evas_Object *btn2 = NULL;
658
659         switch (mode) {
660         case GL_POPUP_NOBUT:
661                 __gl_popup_add_timer(ad, GL_POPUP_TIMEOUT_3S);
662                 break;
663         case GL_POPUP_NOBUT_MOV_DEL:
664                 __gl_popup_add_timer(ad, GL_POPUP_TIMEOUT_1S);
665                 break;
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);
678                 break;
679         default:
680                 gl_dbgE("Other popup mode...");
681                 break;
682         }
683
684         evas_object_show(popup);
685
686         ad->popupinfo.popup = popup;
687         ad->popupinfo.popup_mode = mode;
688
689         return 0;
690 }
691
692 /* Update popup contents */
693 int gl_popup_update_content(void *data, gl_popup_mode mode)
694 {
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);
699
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);
707         int cnt = 0;
708
709         switch (mode) {
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!");
713                         return -1;
714                 }
715                 break;
716         default:
717                 break;
718         }
719         if (cnt > 0) {
720                 if (cnt < 4)
721                         evas_object_size_hint_min_set(content,
722                                                       GL_POPUP_MENUSTYLE_WIDTH,
723                                                       GL_POPUP_MENUSTYLE_HEIGHT(cnt));
724                 else
725                         evas_object_size_hint_min_set(content,
726                                                       GL_POPUP_MENUSTYLE_WIDTH,
727                                                       GL_POPUP_MENUSTYLE_HEIGHT_MAX);
728         } else {
729                 evas_object_del(ad->popupinfo.popup);
730                 ad->popupinfo.popup = NULL;
731                 ad->popupinfo.popup_mode = 0;
732         }
733         return 0;
734 }
735