tizen 2.4 release
[apps/home/attach-panel-gallery.git] / src / view / ge-albums.c
1 /*
2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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
18 #include "ge-albums.h"
19 #include "ge-gridview.h"
20 #include "ge-ui-util.h"
21 #include "ge-util.h"
22 #include "ge-data.h"
23 #include "ge-icon.h"
24 #include "ge-tile.h"
25 #include "ge-rotate-bg.h"
26 #include "ge-button.h"
27 #include "ge-main-view.h"
28 #include "ge-strings.h"
29 #include "ge-ugdata.h"
30 #include <notification.h>
31
32 static Elm_Gengrid_Item_Class *gic_first = NULL;
33 static Elm_Gengrid_Item_Class *no_content = NULL;
34
35
36 #define DEFAULT_THUMBNAIL "/opt/usr/share/media/.thumb/thumb_default.png"
37
38 /* Only for local medias */
39 static void __ge_albums_create_thumb_cb(media_content_error_e error,
40                                         const char *path, void *user_data)
41 {
42         if (GE_FILE_EXISTS(path) && error == MEDIA_CONTENT_ERROR_NONE) {
43                 GE_CHECK(user_data);
44                 ge_cluster *album= (ge_cluster *)user_data;
45                 album->cover->item->b_create_thumb = false;
46                 GE_CHECK(album->griditem);
47                 elm_gengrid_item_update(album->griditem);
48         } else {
49                 ge_dbgE("Error number[%d]", error);
50         }
51 }
52
53 /* Use file to create new thumb if possible */
54 static int __ge_albums_create_thumb(ge_item *gitem, ge_cluster *album)
55 {
56         GE_CHECK_VAL(gitem, -1);
57         GE_CHECK_VAL(gitem->item, -1);
58         GE_CHECK_VAL(gitem->item->file_url, -1);
59         GE_CHECK_VAL(album, -1);
60
61         if (GE_FILE_EXISTS(gitem->item->file_url)) {
62                 _ge_data_create_thumb(gitem->item, __ge_albums_create_thumb_cb,
63                                       album);
64                 return 0;
65         }
66         return -1;
67 }
68
69 static void __ge_split_albums_realized(void *data, Evas_Object *obj, void *ei)
70 {
71         GE_CHECK(data);
72         ge_ugdata *ugd = (ge_ugdata *)data;
73         GE_CHECK(ei);
74         Elm_Object_Item *it = (Elm_Object_Item *)ei;
75         ge_cluster *album = elm_object_item_data_get(it);
76         GE_CHECK(album);
77         GE_CHECK(album->cluster);
78         GE_CHECK(album->cover);
79         GE_CHECK(album->cover->item);
80         ge_dbg("realized");
81         if (album->select) {
82                 elm_object_item_signal_emit((Elm_Object_Item *)ei, "elm,state,focused", "elm");
83                 ugd->selected_griditem = it;
84                 album->select = false;
85         }
86         int sel_cnt;
87         _ge_data_get_album_sel_cnt(ugd, album->cluster->uuid, &sel_cnt);
88         if (sel_cnt > 0) {
89                 elm_object_item_signal_emit((Elm_Object_Item *)ei,
90                                 "elm,state,elm.text.badge,visible",
91                                 "elm");
92                 album->sel_cnt = sel_cnt;
93         } else {
94                 album->sel_cnt = 0;
95                 elm_object_item_signal_emit((Elm_Object_Item *)ei,
96                                 "elm,state,elm.text.badge,hidden",
97                                 "elm");
98         }
99 }
100
101 static void __ge_albums_realized(void *data, Evas_Object *obj, void *ei)
102 {
103         GE_CHECK(ei);
104         Elm_Object_Item *it = (Elm_Object_Item *)ei;
105         ge_cluster *album = elm_object_item_data_get(it);
106         GE_CHECK(album);
107         GE_CHECK(album->cluster);
108         GE_CHECK(album->cover);
109         GE_CHECK(album->cover->item);
110
111         ge_dbg("realized");
112         if (!GE_FILE_EXISTS(album->cover->item->thumb_url) &&
113             GE_FILE_EXISTS(album->cover->item->file_url) &&
114             (album->cluster->type == GE_PHONE ||
115              album->cluster->type == GE_MMC ||
116              album->cluster->type == GE_ALL))
117                 __ge_albums_create_thumb(album->cover, album);
118
119         GE_CHECK(album->ugd);
120         ge_ugdata *ugd = album->ugd;
121         if (ugd->b_multifile) {
122                 if (album->sel_cnt > 0)
123                         elm_object_item_signal_emit(album->griditem,
124                                                     "elm,state,elm.text.badge,visible",
125                                                     "elm");
126                 else
127                         elm_object_item_signal_emit(album->griditem,
128                                                     "elm,state,elm.text.badge,hidden",
129                                                     "elm");
130         }
131 }
132
133 static void __ge_albums_unrealized(void *data, Evas_Object *obj, void *ei)
134 {
135         ge_dbg("unrealized");
136         GE_CHECK(ei);
137         Elm_Object_Item *it = (Elm_Object_Item *)ei;
138         ge_cluster *album = elm_object_item_data_get(it);
139         GE_CHECK(album);
140         GE_CHECK(album->cluster);
141         GE_CHECK(album->cover);
142         GE_CHECK(album->cover->item);
143
144         /* Checking for local files only */
145         if (album->cluster->type == GE_PHONE ||
146             album->cluster->type == GE_MMC ||
147             album->cluster->type == GE_ALL) {
148                 if (album->cover->item->b_create_thumb) {
149                         _ge_data_cancel_thumb(album->cover->item);
150
151                         ge_dbgW("in the if part");
152                 }
153         }
154 }
155
156 static int __ge_albums_open_album(ge_cluster *album)
157 {
158         GE_CHECK_VAL(album, -1);
159         GE_CHECK_VAL(album->cluster, -1);
160         GE_CHECK_VAL(album->ugd, -1);
161         ge_ugdata *ugd = album->ugd;
162         ge_sdbg("Album: %s", album->cluster->display_name);
163
164         if (_ge_get_view_mode(ugd) != GE_VIEW_ALBUMS) {
165                 ge_dbgE("Wrong mode!");
166                 ugd->view_mode = GE_VIEW_ALBUMS;
167                 //return -1;
168                 ge_dbgE("new mode album view is assigned");
169         }
170
171         if (ugd->album_select_mode == GE_ALBUM_SELECT_T_ONE) {
172                 ge_dbg("One album selected, return album id");
173                 app_control_add_extra_data(ugd->service,
174                                        GE_ALBUM_SELECT_RETURN_PATH,
175                                        album->cluster->path);
176                 ge_dbg("return folder-path: %s", album->cluster->path);
177                 ug_send_result_full(ugd->ug, ugd->service, APP_CONTROL_RESULT_SUCCEEDED);
178                 if (!ugd->is_attach_panel) {
179                         ug_destroy_me(ugd->ug);
180                         ugd->ug = NULL;
181                 }
182                 return 0;
183         }
184
185         /* Add thumbnails view */
186         _ge_grid_create_thumb(album);
187         ge_dbg("Done");
188         return 0;
189 }
190
191 static int __ge_split_albums_open_album(ge_cluster *album)
192 {
193         GE_CHECK_VAL(album, -1);
194         GE_CHECK_VAL(album->cluster, -1);
195         GE_CHECK_VAL(album->ugd, -1);
196         ge_sdbg("Album: %s", album->cluster->display_name);
197
198         /* Add thumbnails view */
199         _ge_grid_create_split_view_thumb(album);
200         ge_dbg("Done");
201         return 0;
202 }
203
204 /* Add idler to make mouse click sound, other sound couldn' be played */
205 static Eina_Bool __ge_albums_sel_idler_cb(void *data)
206 {
207         ge_dbg("Select album ---");
208         GE_CHECK_FALSE(data);
209         ge_cluster *album_item = (ge_cluster*)data;
210         GE_CHECK_FALSE(album_item->cluster);
211         GE_CHECK_FALSE(album_item->ugd);
212         ge_ugdata *ugd = album_item->ugd;
213         if (ugd->ug == NULL) {
214                 ge_dbg("UG already destroyed, return!");
215                 goto GE_ALBUMS_DONE;
216         }
217
218         if (album_item->cover) {
219                 _ge_data_util_free_item(album_item->cover);
220                 album_item->cover = NULL;
221         }
222
223         __ge_albums_open_album(album_item);
224
225  GE_ALBUMS_DONE:
226
227         ecore_idler_del(ugd->sel_album_idler);
228         ugd->sel_album_idler = NULL;
229         ge_dbg("Select album +++");
230         return ECORE_CALLBACK_CANCEL;
231 }
232
233 static Eina_Bool __ge_split_albums_sel_idler_cb(void *data)
234 {
235         ge_dbg("Select album ---");
236         GE_CHECK_FALSE(data);
237         ge_cluster *album_item = (ge_cluster*)data;
238         GE_CHECK_FALSE(album_item->cluster);
239         GE_CHECK_FALSE(album_item->ugd);
240         ge_ugdata *ugd = album_item->ugd;
241         if (ugd->ug == NULL) {
242                 ge_dbg("UG already destroyed, return!");
243                 goto GE_ALBUMS_DONE;
244         }
245         if (album_item->cover) {
246                 _ge_data_util_free_item(album_item->cover);
247                 album_item->cover = NULL;
248         }
249         __ge_split_albums_open_album(album_item);
250
251  GE_ALBUMS_DONE:
252         ecore_idler_del(ugd->sel_album_idler);
253         ugd->sel_album_idler = NULL;
254         ge_dbg("Select album +++");
255         return ECORE_CALLBACK_CANCEL;
256 }
257
258 static void __ge_albums_sel_cb(void *data, Evas_Object *obj, void *ei)
259 {
260         GE_CHECK(data);
261         ge_cluster *album_item = (ge_cluster*)data;
262         GE_CHECK(album_item->cluster);
263         GE_CHECK(album_item->ugd);
264         ge_ugdata *ugd = album_item->ugd;
265         if (ugd->ug == NULL) {
266                 ge_dbg("UG already destroyed, return!");
267                 return;
268         }
269         ugd->album_item = album_item;
270         ge_dbg("");
271         if (ugd->sel_album_idler) {
272                 ge_dbg("Has selected an album");
273                 return;
274         }
275
276         elm_gengrid_item_selected_set(ei, EINA_FALSE);
277
278         Ecore_Idler *idl = NULL;
279         idl = ecore_idler_add(__ge_albums_sel_idler_cb, data);
280         ugd->sel_album_idler = idl;
281         /* Save scroller position before clearing gengrid */
282         _ge_ui_save_scroller_pos(obj);
283 }
284
285 static void __ge_split_albums_sel_cb(void *data, Evas_Object *obj, void *ei)
286 {
287         GE_CHECK(data);
288         ge_cluster *album_item = (ge_cluster*)data;
289         GE_CHECK(album_item->cluster);
290         GE_CHECK(album_item->ugd);
291         ge_ugdata *ugd = album_item->ugd;
292         if (ugd->ug == NULL) {
293                 ge_dbg("UG already destroyed, return!");
294                 return;
295         }
296         ugd->album_item = album_item;
297         ge_dbg("");
298         if (ugd->sel_album_idler) {
299                 ge_dbg("Has selected an album");
300                 return;
301         }
302         elm_gengrid_item_selected_set(ei, EINA_FALSE);
303         Ecore_Idler *idl = NULL;
304         idl = ecore_idler_add(__ge_split_albums_sel_idler_cb, data);
305         ugd->sel_album_idler = idl;
306         /* Save scroller position before clearing gengrid */
307         _ge_ui_save_scroller_pos(obj);
308 }
309
310 static char *__ge_albums_get_text(void *data, Evas_Object *obj, const char *part)
311 {
312         GE_CHECK_NULL(part);
313         GE_CHECK_NULL(data);
314         ge_cluster *album = (ge_cluster *)data;
315         GE_CHECK_NULL(album->cluster);
316         GE_CHECK_NULL(album->cluster->uuid);
317         GE_CHECK_NULL(album->ugd);
318         ge_ugdata *ugd = album->ugd;
319         char buf[GE_FILE_PATH_LEN_MAX] = { 0, };
320
321         if (!g_strcmp0(part, "elm.text.name")) {
322                 GE_CHECK_NULL(album->cluster->display_name);
323                 if (_ge_data_is_root_path(album->cluster->path)) {
324                         snprintf(buf, sizeof(buf), "%s", GE_ALBUM_ROOT_NAME);
325                         buf[strlen(buf)] = '\0';
326                 } else if (album->cluster->display_name &&
327                           strlen(album->cluster->display_name)) {
328                         char *new_name = _ge_ui_get_i18n_album_name(album->cluster);
329                         snprintf(buf, sizeof(buf), "%s", new_name);
330                         buf[strlen(buf)] = '\0';
331                 }
332
333                 /* Show blue folder name */
334                 if (!g_strcmp0(album->cluster->uuid, GE_ALBUM_ALL_ID)) {
335                         Elm_Object_Item *grid_it = album->griditem;
336                         Evas_Object *it_obj = NULL;
337                         it_obj = elm_object_item_widget_get(grid_it);
338                         GE_CHECK_NULL(it_obj);
339                         edje_object_signal_emit(it_obj, "elm,name,show,blue",
340                                                 "elm");
341                         edje_object_message_signal_process(it_obj);
342                 }
343         } else if (!g_strcmp0(part, "elm.text.date")) {
344                 if (album->cover) {
345                         _ge_data_util_free_item(album->cover);
346                         album->cover = NULL;
347                 }
348
349                 ge_item *item = NULL;
350                 _ge_data_get_album_cover(ugd, album, &item,
351                                          MEDIA_CONTENT_ORDER_DESC);
352                 if (item == NULL || item->item == NULL) {
353                         album->cover_thumbs_cnt = 0;
354                         _ge_data_util_free_item(item);
355                         return NULL;
356                 }
357
358                 album->cover = item;
359                 album->cover_thumbs_cnt = GE_ALBUM_COVER_THUMB_NUM;
360         } else if (!g_strcmp0(part, "elm.text.count")) {
361                 _ge_data_update_items_cnt(ugd, album);
362                 snprintf(buf, sizeof(buf), "%d", (int)(album->cluster->count));
363                 buf[strlen(buf)] = '\0';
364         } else if (!g_strcmp0(part, "elm.text.badge") && ugd->b_multifile) {
365                 int sel_cnt = 0;
366                 _ge_data_get_album_sel_cnt(ugd, album->cluster->uuid, &sel_cnt);
367                 ge_dbg("count :%d", sel_cnt);
368                 if (sel_cnt > 0) {
369                         album->sel_cnt = sel_cnt;
370                         snprintf(buf, sizeof(buf), "%d", sel_cnt);
371                 } else {
372                         album->sel_cnt = 0;
373                 }
374         }
375         return strdup(buf);
376 }
377
378 static char *__ge_split_albums_get_text(void *data, Evas_Object *obj, const char *part)
379 {
380         GE_CHECK_NULL(part);
381         GE_CHECK_NULL(data);
382         ge_cluster *album = (ge_cluster *)data;
383         GE_CHECK_NULL(album->cluster);
384         GE_CHECK_NULL(album->cluster->uuid);
385         GE_CHECK_NULL(album->ugd);
386         ge_ugdata *ugd = album->ugd;
387         char buf[GE_FILE_PATH_LEN_MAX] = { 0, };
388
389         if (!g_strcmp0(part, "elm.text.name")) {
390                 GE_CHECK_NULL(album->cluster->display_name);
391                 int len;
392                 if (_ge_data_is_root_path(album->cluster->path)) {
393                         _ge_data_update_items_cnt(ugd, album);
394                         len = strlen(GE_ALBUM_ROOT_NAME);
395                         snprintf(buf, sizeof(buf), "%d", (int)(album->cluster->count));
396                         if (len > 5) {
397                                 snprintf(buf, sizeof(buf), "%.5s... %d", GE_ALBUM_ROOT_NAME, (int)(album->cluster->count));
398                         }
399                         else {
400                                 snprintf(buf, sizeof(buf), "%s %d", GE_ALBUM_ROOT_NAME, (int)(album->cluster->count));
401                         }
402                         buf[strlen(buf)] = '\0';
403                 } else if (album->cluster->display_name &&
404                                 strlen(album->cluster->display_name)) {
405                         char *new_name = _ge_ui_get_i18n_album_name(album->cluster);
406                         _ge_data_update_items_cnt(ugd, album);
407                         len = strlen(new_name);
408                         snprintf(buf, sizeof(buf), "%d", (int)(album->cluster->count));
409                         if (len > 5) {
410                                 snprintf(buf, sizeof(buf), "%.5s... %d", new_name, (int)(album->cluster->count));
411                         } else {
412                                 snprintf(buf, sizeof(buf), "%s %d", new_name, (int)(album->cluster->count));
413                         }
414                         buf[strlen(buf)] = '\0';
415                 }
416
417                 /* Show blue folder name */
418                 if (!g_strcmp0(album->cluster->uuid, GE_ALBUM_ALL_ID) ||
419                                 _ge_data_is_camera_album(album->cluster)) {
420                         Elm_Object_Item *grid_it = album->griditem;
421                         Evas_Object *it_obj = NULL;
422                         it_obj = elm_object_item_widget_get(grid_it);
423                         GE_CHECK_NULL(it_obj);
424                         edje_object_signal_emit(it_obj, "elm,name,show,blue",
425                                         "elm");
426                         edje_object_message_signal_process(it_obj);
427                 }
428         } else if (!g_strcmp0(part, "elm.text.date")) {
429                 if (album->cover) {
430                         _ge_data_util_free_item(album->cover);
431                         album->cover = NULL;
432                 }
433
434                 ge_item *item = NULL;
435                 _ge_data_get_album_cover(ugd, album, &item,
436                                 MEDIA_CONTENT_ORDER_DESC);
437                 if (item == NULL || item->item == NULL) {
438                         album->cover_thumbs_cnt = 0;
439                         _ge_data_util_free_item(item);
440                         return NULL;
441                 }
442
443                 album->cover = item;
444                 album->cover_thumbs_cnt = GE_ALBUM_COVER_THUMB_NUM;
445         } else if (!g_strcmp0(part, "elm.text.count")) {
446                 _ge_data_update_items_cnt(ugd, album);
447                 snprintf(buf, sizeof(buf), "%d", (int)(album->cluster->count));
448                 buf[strlen(buf)] = '\0';
449         } else if (!g_strcmp0(part, "elm.text.badge") && ugd->b_multifile) {
450                 int sel_cnt = 0;
451                 _ge_data_get_album_sel_cnt(ugd, album->cluster->uuid, &sel_cnt);
452                 ge_dbg("count :%d", sel_cnt);
453                 if (sel_cnt > 0) {
454                         elm_object_item_signal_emit(album->griditem,
455                                         "elm,state,elm.text.badge,visible",
456                                         "elm");
457                         album->sel_cnt = sel_cnt;
458                         snprintf(buf, sizeof(buf), "%d", sel_cnt);
459                 } else {
460                         album->sel_cnt = 0;
461                         elm_object_item_signal_emit(album->griditem,
462                                         "elm,state,elm.text.badge,hidden",
463                                         "elm");
464                 }
465         }
466         return strdup(buf);
467 }
468
469 static ge_icon_type __ge_albums_set_bg_file(Evas_Object *bg, void *data)
470 {
471         GE_CHECK_VAL(data, -1);
472         ge_item *git =  (ge_item *)data;
473         GE_CHECK_VAL(git->album, -1);
474         ge_cluster *album = git->album;
475         char *bg_path = GE_ICON_NO_THUMBNAIL;
476         ge_icon_type ret_val = GE_ICON_CORRUPTED_FILE;
477
478         if (git == NULL || git->item == NULL) {
479                 ge_dbgE("Invalid item :%p", git);
480                 goto GE_ALBUMS_FAILED;
481         }
482
483         ret_val= GE_ICON_NORMAL;
484         if (GE_FILE_EXISTS(git->item->thumb_url))
485                 bg_path = git->item->thumb_url;
486         else if (album && (album->cluster->type == GE_MMC ||
487                  album->cluster->type == GE_PHONE ||
488                  album->cluster->type == GE_ALL))
489                 __ge_albums_create_thumb(git, album);
490         else
491                 ret_val = -1;
492
493  GE_ALBUMS_FAILED:
494
495 #ifdef _USE_ROTATE_BG_GE
496         _ge_rotate_bg_set_image_file(bg, bg_path);
497 #else
498         elm_bg_file_set(bg, bg_path, NULL);
499 #endif
500
501         return ret_val;
502 }
503
504 static Evas_Object *__ge_albums_get_type_icon(Evas_Object *obj, ge_cluster *album)
505 {
506         GE_CHECK_NULL(album);
507         GE_CHECK_NULL(album->cluster);
508         GE_CHECK_NULL(obj);
509         Evas_Object *_obj = NULL;
510
511         if (_ge_data_is_camera_album(album->cluster))
512                 _obj = _ge_tile_show_part_type_icon(obj,
513                                                     GE_TILE_TYPE_CAMERA);
514         else if (_ge_data_is_default_album(GE_ALBUM_DOWNLOADS_NAME, album->cluster))
515                 _obj = _ge_tile_show_part_type_icon(obj,
516                                                     GE_TILE_TYPE_DOWNLOAD);
517         else
518                 _obj = _ge_tile_show_part_type_icon(obj,
519                                                     GE_TILE_TYPE_FOLDER);
520         return _obj;
521 }
522
523 static Evas_Object *__ge_albums_get_content(void *data, Evas_Object *obj, const char *part)
524 {
525         GE_CHECK_NULL(part);
526         GE_CHECK_NULL(strlen(part));
527         GE_CHECK_NULL(data);
528         ge_cluster *album = (ge_cluster *)data;
529         GE_CHECK_NULL(album->cluster);
530         GE_CHECK_NULL(album->cluster->uuid);
531         ge_dbg("");
532
533         Evas_Object *_obj = NULL;
534         if (!g_strcmp0(part, GE_TILE_ICON)) {
535                 _obj = _ge_tile_show_part_icon(obj, part,
536                                                album->cover_thumbs_cnt,
537                                                __ge_albums_set_bg_file,
538                                                (void *)album->cover);
539         } else if (!g_strcmp0(part, GE_TILE_TYPE_ICON)) {
540                 _obj = __ge_albums_get_type_icon(obj, album);
541         }
542         return _obj;
543 }
544
545 static Evas_Object *__ge_split_albums_get_content(void *data, Evas_Object *obj, const char *part)
546 {
547         GE_CHECK_NULL(part);
548         GE_CHECK_NULL(strlen(part));
549         GE_CHECK_NULL(data);
550         ge_cluster *album = (ge_cluster *)data;
551         GE_CHECK_NULL(album->cluster);
552         GE_CHECK_NULL(album->cluster->uuid);
553         ge_dbg("");
554
555         Evas_Object *_obj = NULL;
556         if (!g_strcmp0(part, GE_TILE_ICON)) {
557                 _obj = _ge_tile_show_part_icon(obj, part,
558                                 album->cover_thumbs_cnt,
559                                 __ge_albums_set_bg_file,
560                                 (void *)album->cover);
561         }
562         return _obj;
563 }
564
565 static int __ge_albums_append(ge_ugdata *ugd, ge_cluster *album)
566 {
567         GE_CHECK_VAL(album, -1);
568         GE_CHECK_VAL(album->cluster, -1);
569         GE_CHECK_VAL(ugd, -1);
570
571         album->griditem = elm_gengrid_item_append(ugd->albums_view,
572                                                   ugd->album_gic, album,
573                                                   __ge_albums_sel_cb, album);
574         ge_sdbg("Append [%s], id[%s]", album->cluster->display_name,
575                album->cluster->uuid);
576         _ge_tile_update_item_size(ugd, ugd->albums_view, ugd->rotate_mode,
577                                   false);
578         album->index = elm_gengrid_items_count(ugd->albums_view);
579         return 0;
580 }
581
582 int __ge_split_albums_append(ge_ugdata *ugd, ge_cluster *album)
583 {
584         GE_CHECK_VAL(album, -1);
585         GE_CHECK_VAL(album->cluster, -1);
586         GE_CHECK_VAL(ugd, -1);
587
588         album->griditem = elm_gengrid_item_append(ugd->albums_view,
589                         ugd->album_gic, album,
590                         __ge_split_albums_sel_cb, album);
591         ge_sdbg("Append [%s], id[%s]", album->cluster->display_name,
592                         album->cluster->uuid);
593         _ge_tile_update_item_size(ugd, ugd->albums_view, ugd->rotate_mode,
594                         false);
595         album->index = elm_gengrid_items_count(ugd->albums_view);
596         return 0;
597 }
598
599 static Eina_Bool __ge_albums_append_idler_cb(void *data)
600 {
601         ge_dbg("Append album ---");
602         GE_CHECK_VAL(data, -1);
603         ge_ugdata *ugd = (ge_ugdata *)data;
604         GE_CHECK_VAL(ugd->cluster_list, -1);
605
606         int old_cnt = eina_list_count(ugd->cluster_list->clist);
607         _ge_data_get_clusters(ugd, ugd->cluster_list->data_type);
608         ugd->cluster_list->data_type = GE_ALBUM_DATA_NONE;
609         int new_cnt = eina_list_count(ugd->cluster_list->clist);
610         if (old_cnt != new_cnt)
611                 _ge_tile_update_item_size(ugd, ugd->albums_view,
612                                           ugd->rotate_mode, false);
613         ecore_idler_del(ugd->album_idler);
614         ugd->album_idler = NULL;
615         ge_dbg("Append album +++");
616         return ECORE_CALLBACK_CANCEL;
617 }
618
619 Eina_Bool __ge_split_albums_append_idler_cb(void *data)
620 {
621         ge_dbg("Append album ---");
622         GE_CHECK_VAL(data, -1);
623         ge_ugdata *ugd = (ge_ugdata *)data;
624         GE_CHECK_VAL(ugd->cluster_list, -1);
625
626         int old_cnt = eina_list_count(ugd->cluster_list->clist);
627         ge_dbg("Albums list length old: %d", old_cnt);
628         _ge_data_get_clusters(ugd, ugd->cluster_list->data_type);
629         ugd->cluster_list->data_type = GE_ALBUM_DATA_NONE;
630         int new_cnt = eina_list_count(ugd->cluster_list->clist);
631         ge_dbg("Albums list length new: %d", new_cnt);
632         ecore_idler_del(ugd->album_idler);
633         ugd->album_idler = NULL;
634         ge_dbg("Append album +++");
635         return ECORE_CALLBACK_CANCEL;
636 }
637
638 static Eina_Bool __ge_albums_create_idler_cb(void *data)
639 {
640         ge_dbg("Create album ---");
641         GE_CHECK_VAL(data, -1);
642         ge_ugdata *ugd = (ge_ugdata *)data;
643         int length = eina_list_count(ugd->cluster_list->clist);
644         int i = 0;
645         ge_cluster *album = NULL;
646         ge_dbg("Albums list length: %d", length);
647
648         /* First 8 albums is got from DB, and plus 'All albums', it's 9 totally */
649         for (i = GE_ALBUMS_FIRST_COUNT + 1; i < length; i++) {
650                 album = eina_list_nth(ugd->cluster_list->clist, i);
651                 __ge_albums_append(ugd, album);
652         }
653         /* Restore previous position of scroller */
654         _ge_ui_restore_scroller_pos(ugd->albums_view);
655
656         ecore_idler_del(ugd->album_idler);
657         ugd->album_idler = NULL;
658         ge_dbg("Create album +++");
659         return ECORE_CALLBACK_CANCEL;
660 }
661
662 Eina_Bool __ge_split_view_albums_create_idler_cb(void *data)
663 {
664         ge_dbg("Create album ---");
665         GE_CHECK_VAL(data, -1);
666         ge_ugdata *ugd = (ge_ugdata *)data;
667         int length = eina_list_count(ugd->cluster_list->clist);
668         int i = 0;
669         ge_cluster *album = NULL;
670         ge_dbg("Albums list length: %d", length);
671
672         /* First 8 albums is got from DB, and plus 'All albums', it's 9 totally */
673         for (i = GE_ALBUMS_FIRST_COUNT + 1; i < length; i++) {
674                 album = eina_list_nth(ugd->cluster_list->clist, i);
675                 __ge_split_albums_append(ugd, album);
676         }
677         /* Restore previous position of scroller */
678         _ge_ui_restore_scroller_pos(ugd->albums_view);
679
680         ecore_idler_del(ugd->album_idler);
681         ugd->album_idler = NULL;
682         ge_dbg("Create album +++");
683         return ECORE_CALLBACK_CANCEL;
684 }
685
686 int __ge_split_view_append_albums(ge_ugdata *ugd, Evas_Object *parent, bool is_update)
687 {
688         GE_CHECK_VAL(parent, -1);
689         GE_CHECK_VAL(ugd, -1);
690         int i = 0;
691         ge_cluster *album = NULL;
692         int length = 0;
693         if (elm_gengrid_items_count(parent) > 0) {
694                 /* Save scroller position before clearing gengrid */
695                 _ge_ui_save_scroller_pos(parent);
696                 elm_gengrid_clear(parent);
697         }
698         if (is_update)
699                 _ge_data_get_clusters(ugd, GE_ALBUM_DATA_NONE);
700         if (ugd->cluster_list && ugd->cluster_list->clist)
701                 length = eina_list_count(ugd->cluster_list->clist);
702         else
703                 return -1;
704         ge_dbg("Albums list length: %d", length);
705
706         if (ugd->th)
707                 elm_object_theme_set(parent, ugd->th);
708         int grid_cnt = 0;
709         Elm_Gengrid_Item_Class *gic = elm_gengrid_item_class_new();
710         if (gic == NULL) {
711                 return -1;
712         }
713         gic->item_style = "gallery_efl/albums_split_view";
714         gic->func.text_get = __ge_split_albums_get_text;
715         gic->func.content_get = __ge_split_albums_get_content;
716         for (i = 0; i < length; i++) {
717                 album = eina_list_nth(ugd->cluster_list->clist, i);
718                 if (!album || !album->cluster || !album->cluster->display_name) {
719                         ge_dbgE("Invalid parameter, return ERROR code!");
720                         elm_gengrid_clear(parent);
721
722                         if (gic) {
723                                 elm_gengrid_item_class_free(gic);
724                                 gic = NULL;
725                         }
726                         return -1;
727                 }
728
729                 if (album->cluster->type == GE_ALL) {
730                         continue;
731                 }
732
733                 album->griditem = elm_gengrid_item_append(parent,
734                                 gic,
735                                 album,
736                                 __ge_split_albums_sel_cb,
737                                 album);
738                 if (!strcmp(album->cluster->uuid, ugd->album_item->cluster->uuid)) {
739                         album->select = true;
740                 } else {
741                         album->select = false;
742                 }
743                 album->index = grid_cnt;
744                 grid_cnt++;
745                 ge_sdbg("Append [%s], id=%s.", album->cluster->display_name,
746                                 album->cluster->uuid);
747         }
748         /* Restore previous position of scroller */
749         _ge_ui_restore_scroller_pos(parent);
750
751         if (gic) {
752                 elm_gengrid_item_class_free(gic);
753                 gic = NULL;
754         }
755         /* NOT jsut for updating view, but for updating view and data together */
756         if (ugd->cluster_list->data_type == GE_ALBUM_DATA_LOCAL ||
757                         ugd->cluster_list->data_type == GE_ALBUM_DATA_WEB) {
758                 if (ugd->album_idler) {
759                         ecore_idler_del(ugd->album_idler);
760                         ugd->album_idler = NULL;
761                 }
762                 Ecore_Idler *idl = NULL;
763                 idl = ecore_idler_add(__ge_split_albums_append_idler_cb, ugd);
764                 ugd->album_idler = idl;
765         }
766         if (grid_cnt) {
767                 return 0;
768         } else {
769                 ge_dbgW("None albums appended to view!");
770                 return -1;
771         }
772 }
773
774 static int __ge_albums_append_albums(ge_ugdata *ugd, Evas_Object *parent, bool is_update)
775 {
776         GE_CHECK_VAL(parent, -1);
777         GE_CHECK_VAL(ugd, -1);
778         int i = 0;
779         ge_cluster *album = NULL;
780         int length = 0;
781
782         if (elm_gengrid_items_count(parent) > 0) {
783                 /* Save scroller position before clearing gengrid */
784                 _ge_ui_save_scroller_pos(parent);
785                 elm_gengrid_clear(parent);
786         }
787         if (is_update)
788                 _ge_data_get_clusters(ugd, GE_ALBUM_DATA_NONE);
789         if (ugd->cluster_list && ugd->cluster_list->clist)
790                 length = eina_list_count(ugd->cluster_list->clist);
791         else
792                 return -1;
793         ge_dbg("Albums list length: %d", length);
794
795         if (ugd->th)
796                 elm_object_theme_set(parent, ugd->th);
797
798         /* Jus for updating view, not updating data and view together */
799         if (ugd->cluster_list->data_type == GE_ALBUM_DATA_NONE &&
800             length > GE_ALBUMS_FIRST_COUNT + 1) {
801                 length = GE_ALBUMS_FIRST_COUNT + 1;
802                 if (ugd->album_idler) {
803                         ecore_idler_del(ugd->album_idler);
804                         ugd->album_idler = NULL;
805                 }
806                 Ecore_Idler *idl = NULL;
807                 idl = ecore_idler_add(__ge_albums_create_idler_cb, ugd);
808                 ugd->album_idler = idl;
809         }
810
811         int grid_cnt = 0;
812         for (i = 0; i < length; i++) {
813                 album = eina_list_nth(ugd->cluster_list->clist, i);
814                 GE_CHECK_VAL(album, -1);
815                 GE_CHECK_VAL(album->cluster, -1);
816                 GE_CHECK_VAL(album->cluster->display_name, -1);
817
818                 if (album->cluster->type == GE_ALL)
819                         continue;
820
821                 album->griditem = elm_gengrid_item_append(parent,
822                                                           ugd->album_gic,
823                                                           album,
824                                                           __ge_albums_sel_cb,
825                                                           album);
826                 album->index = grid_cnt;
827                 grid_cnt++;
828                 ge_sdbg("Append [%s], id=%s.", album->cluster->display_name,
829                        album->cluster->uuid);
830         }
831         /* Restore previous position of scroller */
832         _ge_ui_restore_scroller_pos(parent);
833
834         /* NOT jsut for updating view, but for updating view and data together */
835         if (ugd->cluster_list->data_type == GE_ALBUM_DATA_LOCAL ||
836             ugd->cluster_list->data_type == GE_ALBUM_DATA_WEB) {
837                 if (ugd->album_idler) {
838                         ecore_idler_del(ugd->album_idler);
839                         ugd->album_idler = NULL;
840                 }
841                 Ecore_Idler *idl = NULL;
842                 idl = ecore_idler_add(__ge_albums_append_idler_cb, ugd);
843                 ugd->album_idler = idl;
844         }
845
846         if (grid_cnt) {
847                 _ge_tile_update_item_size(ugd, parent, ugd->rotate_mode, false);
848                 return 0;
849         } else {
850                 ge_dbgW("None albums appended to view!");
851                 return -1;
852         }
853 }
854
855 static int __ge_albums_del_cbs(Evas_Object *view)
856 {
857         if (view == NULL)
858                 return -1;
859         ge_dbg("Delete albums callbacks!");
860         evas_object_smart_callback_del(view, "realized",
861                                        __ge_albums_realized);
862         evas_object_smart_callback_del(view, "unrealized",
863                                        __ge_albums_unrealized);
864         return 0;
865 }
866
867 static int __ge_albums_rotate_view(ge_ugdata *ugd)
868 {
869         if (ugd->albums_view && ugd->albums_view != ugd->nocontents) {
870                 _ge_tile_update_item_size(ugd, ugd->albums_view,
871                                           ugd->rotate_mode, false);
872                 return 0;
873         }
874         return -1;
875 }
876
877 /* Free data after layout deleted */
878 static void __ge_albums_del_layout_cb(void *data, Evas *e, Evas_Object *obj,
879                                          void *ei)
880 {
881         ge_dbg("Delete layout ---");
882 /*      evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL,
883                                        __ge_albums_del_layout_cb);*/
884         GE_CHECK(data);
885         ge_ugdata *ugd = (ge_ugdata *)data;
886
887         if (ugd->album_idler) {
888                 ecore_idler_del(ugd->album_idler);
889                 ugd->album_idler = NULL;
890         }
891         if (ugd->sel_album_idler) {
892                 ecore_idler_del(ugd->sel_album_idler);
893                 ugd->sel_album_idler = NULL;
894         }
895         if (ugd->albums_view && ugd->albums_view != ugd->nocontents) {
896                 elm_gengrid_clear(ugd->albums_view);
897                 __ge_albums_del_cbs(ugd->albums_view);
898                 _ge_ui_del_scroller_pos(ugd->albums_view);
899         }
900         ugd->albums_view = NULL;
901         ugd->albums_view_ly = NULL;
902         if (ugd->album_gic) {
903                 elm_gengrid_item_class_free(ugd->album_gic);
904                 ugd->album_gic = NULL;
905         }
906         ugd->rotate_cbs = eina_list_remove(ugd->rotate_cbs,
907                                            __ge_albums_rotate_view);
908         /* Clear view data */
909         _ge_data_free_sel_albums(ugd);
910         _ge_data_free_clusters(data);
911         ge_dbg("Delete layout +++");
912 }
913
914 static void _ge_grid_move_stop_cb(void *data, Evas_Object *obj, void *ei)
915 {
916         ge_dbg("");
917         GE_CHECK(data);
918         ge_ugdata *ugd = (ge_ugdata *)data;
919         int x, y, w, h;
920         int ret;
921         elm_scroller_region_get(obj, &x, &y, &w, &h);
922
923         app_control_h app_control = NULL;
924         ret = app_control_create(&app_control);
925         if (ret == APP_CONTROL_ERROR_NONE) {
926                 if (y == 0) {
927                         app_control_add_extra_data(app_control, ATTACH_PANEL_FLICK_MODE_KEY, ATTACH_PANEL_FLICK_MODE_ENABLE);
928                 } else {
929                         app_control_add_extra_data(app_control, ATTACH_PANEL_FLICK_MODE_KEY, ATTACH_PANEL_FLICK_MODE_DISABLE);
930                 }
931                 ret = ug_send_result_full(ugd->ug, app_control, APP_CONTROL_RESULT_SUCCEEDED);
932         }
933         app_control_destroy(app_control);
934 }
935
936 Evas_Object* __ge_add_albums_split_view(ge_ugdata *ugd, Evas_Object *parent)
937 {
938         ge_dbg("");
939         GE_CHECK_NULL(parent);
940         GE_CHECK_NULL(ugd);
941         Evas_Object *grid = elm_gengrid_add(parent);
942         GE_CHECK_NULL(grid);
943         _ge_ui_reset_scroller_pos(grid);
944         elm_gengrid_align_set(grid, 0.5f, 0.0);
945         elm_gengrid_horizontal_set(grid, EINA_FALSE);
946         elm_scroller_bounce_set(grid, EINA_FALSE, EINA_TRUE);
947         elm_scroller_policy_set(grid, ELM_SCROLLER_POLICY_OFF,
948                         ELM_SCROLLER_POLICY_AUTO);
949         elm_gengrid_multi_select_set(grid, EINA_TRUE);
950         evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
951         evas_object_smart_callback_add(grid, "unrealized",
952                         __ge_albums_unrealized, ugd);
953         evas_object_smart_callback_add(grid, "realized", __ge_split_albums_realized,
954                         ugd);
955         if (__ge_split_view_append_albums(ugd, grid, false) != 0) {
956                 ge_dbgW("Failed to append album items!");
957                 __ge_albums_del_cbs(grid);
958                 evas_object_del(grid);
959                 grid = NULL;
960         } else {
961                 evas_object_show(grid);
962         }
963         return grid;
964 }
965
966 static Evas_Object* __ge_albums_add_view(ge_ugdata *ugd, Evas_Object *parent)
967 {
968         ge_dbg("");
969         GE_CHECK_NULL(parent);
970         Evas_Object *layout = ge_ui_load_edj(parent, GE_EDJ_FILE,
971                                              GE_GRP_ALBUMVIEW);
972         GE_CHECK_NULL(layout);
973         evas_object_show (layout);
974         return layout;
975 }
976
977 static Eina_Bool __ge_main_back_cb(void *data, Elm_Object_Item *it)
978 {
979         ge_dbg("");
980         GE_CHECK_FALSE(data);
981         ge_ugdata *ugd = (ge_ugdata *)data;
982         Eina_List *l = NULL;
983         ge_item *gitem = NULL;
984
985         void *pop_cb = evas_object_data_get(ugd->naviframe,
986                                             GE_NAVIFRAME_POP_CB_KEY);
987         if (pop_cb) {
988                 Eina_Bool (*_pop_cb) (void *ugd);
989                 _pop_cb = pop_cb;
990
991                 if (_pop_cb(ugd)) {
992                         /* Just pop edit view, dont destroy me */
993                         return EINA_FALSE;
994                 }
995         }
996
997         app_control_h app_control = NULL;
998         app_control_create(&app_control);
999         app_control_add_extra_data(app_control, GE_FILE_SELECT_RETURN_COUNT, "0");
1000         app_control_add_extra_data(app_control, GE_FILE_SELECT_RETURN_PATH, NULL);
1001         app_control_add_extra_data(app_control, APP_CONTROL_DATA_SELECTED, NULL);
1002         app_control_add_extra_data_array(app_control, APP_CONTROL_DATA_PATH, NULL, 0);
1003         ug_send_result_full(ugd->ug, app_control, APP_CONTROL_RESULT_FAILED);
1004         app_control_destroy(app_control);
1005
1006         if (!ugd->is_attach_panel) {
1007                 ug_destroy_me(ugd->ug);
1008                 ge_dbg("ug_destroy_me");
1009         }
1010
1011         EINA_LIST_FOREACH(ugd->thumbs_d->medias_elist, l, gitem) {
1012                 gitem->checked = false;
1013         }
1014
1015         ugd->selected_elist = eina_list_free(ugd->selected_elist);
1016         /*If return ture, ug will pop naviframe first.*/
1017         return EINA_FALSE;
1018 }
1019
1020 void AppGetResource(const char *edj_file_in, char *edj_path_out, int edj_path_max)
1021 {
1022         char *res_path = app_get_resource_path();
1023         if (res_path) {
1024                 snprintf(edj_path_out, edj_path_max, "%s%s", res_path, edj_file_in);
1025                 free(res_path);
1026         }
1027 }
1028
1029 Evas_Object *ge_thumb_show_part_icon_image(Evas_Object *obj, char *path,
1030                                                 int item_w, int item_h)
1031 {
1032         GE_CHECK_NULL(obj);
1033
1034         Evas_Object *layout = elm_layout_add(obj);
1035         GE_CHECK_NULL(layout);
1036
1037         Evas_Object *bg = elm_bg_add(layout);
1038         if (bg == NULL) {
1039                 evas_object_del(layout);
1040                 return NULL;
1041         }
1042
1043         elm_bg_file_set(bg, path, NULL);
1044         elm_bg_load_size_set(bg, item_w, item_h);
1045         evas_object_size_hint_max_set(bg, item_w, item_h);
1046         evas_object_size_hint_aspect_set(bg, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1047         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1048         evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
1049
1050
1051         elm_layout_theme_set(layout, "gengrid", "photoframe",
1052                                                  "default_layout");
1053         elm_object_part_content_set(layout, "elm.swallow.icon", bg);
1054
1055         evas_object_show(layout);
1056         return layout;
1057 }
1058
1059 static void
1060 __ge_grid_done_cb(void *data, Evas_Object *obj, void *ei)
1061 {
1062         ge_dbgE("Transferring Data to caller");
1063         ge_ugdata *ugd = (ge_ugdata*)data;
1064         GE_CHECK_VAL(ugd, -1);
1065
1066         /* file selection mode */
1067         char *paths = NULL;
1068         char **path_array = NULL; /* the array size is sel_cnt */
1069         bool send_success = false;
1070         int sel_cnt = 0;
1071         int i = 0;
1072
1073         _ge_data_get_sel_paths(ugd, &paths, &path_array, &sel_cnt);
1074         if (sel_cnt <= 0) {
1075                 ge_dbgE("Invalid selected path count!");
1076                 send_success = false;
1077                 goto GE_SEND_RESULT_FINISHED;
1078         }
1079
1080         char t_str[32] = { 0, };
1081         eina_convert_itoa(sel_cnt, t_str);
1082
1083         app_control_add_extra_data(ugd->service,
1084                                                            GE_FILE_SELECT_RETURN_COUNT, t_str);
1085         app_control_add_extra_data(ugd->service, GE_FILE_SELECT_RETURN_PATH,
1086                                                            paths);
1087         app_control_add_extra_data_array(ugd->service, APP_CONTROL_DATA_SELECTED,
1088                                                                          (const char **)path_array, sel_cnt);
1089         app_control_add_extra_data_array(ugd->service, APP_CONTROL_DATA_PATH,
1090                                                                          (const char **)path_array, sel_cnt);
1091         ug_send_result_full(ugd->ug, ugd->service, APP_CONTROL_RESULT_SUCCEEDED);
1092         send_success = true;
1093         ugd->selected_elist = eina_list_free(ugd->selected_elist);
1094 GE_SEND_RESULT_FINISHED:
1095
1096         if (paths) {
1097                 g_free(paths);
1098                 paths = NULL;
1099         }
1100         if (path_array) {
1101                 for (i = 0; i < sel_cnt; i++) {
1102                         GE_FREEIF(path_array[i]);
1103                 }
1104                 GE_FREE(path_array);
1105         }
1106
1107         if (!ugd->is_attach_panel) {
1108                 ug_destroy_me(ugd->ug);
1109         }
1110 }
1111
1112 static void
1113 __ge_check_state_changed_cb(void *data, Evas_Object *obj, void *ei)
1114 {
1115         GE_CHECK(obj);
1116         GE_CHECK(data);
1117         ge_item *gitem = (ge_item *)data;
1118         GE_CHECK(gitem->item);
1119         GE_CHECK(gitem->item->file_url);
1120         GE_CHECK(gitem->ugd);
1121         ge_ugdata *ugd = gitem->ugd;
1122         GE_CHECK(ugd->service);
1123         GE_CHECK(ugd->thumbs_d);
1124         Eina_List *l = NULL;
1125         ge_sel_item_s *sit = NULL;
1126         ge_sel_item_s *sit1 = NULL;
1127         Eina_Bool state = elm_check_state_get(obj);
1128
1129         sit = _ge_data_util_new_sel_item(gitem);
1130         GE_CHECK(sit);
1131 #ifdef FEATURE_SIZE_CHECK
1132         struct stat stFileInfo;
1133         stat(sit->file_url, &stFileInfo);
1134 #endif
1135         if (state == EINA_TRUE) {
1136                 if (!g_strcmp0(gitem->item->thumb_url, DEFAULT_THUMBNAIL)) {
1137                         elm_check_state_set(obj, EINA_FALSE);
1138                         char *pStrWarning = g_strdup_printf(
1139                                         GE_STR_UNSUPPORTED_FILE,
1140                                         NULL);
1141                         notification_status_message_post(pStrWarning);
1142                         GE_FREE(pStrWarning);
1143                         _ge_data_util_free_sel_item(sit);
1144                         return;
1145                 }
1146                 if ((ugd->max_count != -1) && (gitem->ugd->thumbs_d->tot_selected + 1 > ugd->max_count)) {
1147                         elm_check_state_set(obj, EINA_FALSE);
1148                         char *pStrWarning = g_strdup_printf(
1149                                         GE_STR_MAX_PICTURES_SELECTED,
1150                                         ugd->max_count);
1151                         notification_status_message_post(pStrWarning);
1152                         GE_FREE(pStrWarning);
1153                         _ge_data_util_free_sel_item(sit);
1154                         return;
1155                 }
1156 #ifdef FEATURE_SIZE_CHECK
1157                 if (ugd->selsize + stFileInfo.st_size > ugd->limitsize) {
1158                         elm_check_state_set(obj, EINA_FALSE);
1159                         notification_status_message_post("maximum of 2MB can be selected");
1160                         _ge_data_util_free_sel_item(sit);
1161                         return;
1162                 }
1163 #endif
1164                 ge_sdbg("append Path: %s", sit->file_url);
1165                 ugd->selected_elist = eina_list_append(ugd->selected_elist, sit);
1166                 ugd->thumbs_d->tot_selected++;
1167 #ifdef FEATURE_SIZE_CHECK
1168                 ugd->selsize += stFileInfo.st_size;
1169 #endif
1170                 gitem->checked = TRUE;
1171         } else {
1172                 ge_sdbg("remove Path: %s", sit->file_url);
1173                 EINA_LIST_FOREACH(ugd->selected_elist, l, sit1) {
1174                         if (!strcmp(sit->file_url, sit1->file_url)) {
1175                                 ugd->selected_elist = eina_list_remove(ugd->selected_elist, sit1);
1176                                 _ge_data_util_free_sel_item(sit1);
1177                         }
1178                 }
1179                 ugd->thumbs_d->tot_selected--;
1180 #ifdef FEATURE_SIZE_CHECK
1181                 ugd->selsize -= stFileInfo.st_size;
1182 #endif
1183                 gitem->checked = FALSE;
1184                 _ge_data_util_free_sel_item(sit);
1185         }
1186
1187         char *pd_selected = GE_STR_PD_SELECTED;
1188         char *text = NULL;
1189         Evas_Object *btn = NULL;
1190
1191         btn = elm_object_item_part_content_get (ugd->nf_it , GE_NAVIFRAME_TITLE_RIGHT_BTN);
1192         if (btn == NULL) {
1193                 ge_dbgE("Failed to get part information");
1194         }
1195
1196         if (ugd->thumbs_d->tot_selected == 0) {
1197                 elm_object_disabled_set(btn, EINA_TRUE);
1198         } else {
1199                 elm_object_disabled_set(btn, EINA_FALSE);
1200         }
1201
1202         /* Update the label text */
1203         if (ugd->thumbs_d->tot_selected >= 0) {
1204                 text = g_strdup_printf(pd_selected, ugd->thumbs_d->tot_selected);
1205                 elm_object_item_text_set(ugd->nf_it, text);
1206         }
1207 }
1208
1209 static Evas_Object *
1210 __ge_nocontent_get(void *data, Evas_Object *obj, const char *part)
1211 {
1212         ge_ugdata *ugd = (ge_ugdata *)data;
1213
1214         Evas_Object *layout = ge_ui_load_edj(ugd->albums_view, GE_EDJ_FILE,
1215                                              "nocontent");
1216         ge_dbg("Nocontents label: %s", GE_STR_NO_ITEMS);
1217         /* Full view nocontents */
1218         Evas_Object *noc_lay = elm_layout_add(layout);
1219         GE_CHECK_NULL(noc_lay);
1220
1221         elm_layout_theme_set(noc_lay, "layout", "nocontents", "text");
1222
1223         _ge_ui_set_translate_part_str(noc_lay, "elm.text", GE_STR_NO_ITEMS);
1224         _ge_ui_set_translate_part_str(noc_lay, "elm.help.text", GE_STR_NO_ITEMS_HELP_TEXT);
1225
1226         elm_layout_signal_emit(noc_lay, "text,disabled", "");
1227         elm_layout_signal_emit(noc_lay, "align.center", "elm");
1228         elm_object_part_content_set(layout, "swallow", noc_lay);
1229         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1230         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1231         GE_CHECK_NULL(layout);
1232         evas_object_show (layout);
1233         return layout;
1234
1235 }
1236
1237
1238 static Evas_Object *
1239 __ge_gengrid_item_content_get(void *data, Evas_Object *obj, const char *part)
1240 {
1241         ge_item *gitem = NULL;
1242
1243         if (strlen(part) <= 0) {
1244                 ge_dbgE("part length <= 0");
1245                 return NULL;
1246         }
1247
1248         gitem = (ge_item*)data;
1249         GE_CHECK_NULL(gitem->item);
1250         GE_CHECK_NULL(gitem->ugd);
1251         ge_ugdata *ugd = gitem->ugd;
1252         GE_CHECK_NULL(ugd->thumbs_d);
1253
1254         Evas_Object *layout = NULL;
1255         char *path = NULL;
1256         char *sd_card_image_path = GE_ICON_MEMORY_CARD;
1257         Evas_Object *icon;
1258
1259         if (!g_strcmp0(part, "content_swallow")) {
1260
1261                 /* Use default image */
1262                 if (!g_strcmp0(gitem->item->thumb_url, DEFAULT_THUMBNAIL)) {
1263                         path = GE_ICON_CONTENTS_BROKEN;
1264                 } else {
1265                         path = gitem->item->thumb_url;
1266                 }
1267
1268                 if (gitem->item->type == MEDIA_CONTENT_TYPE_IMAGE) {
1269                         layout = ge_thumb_show_part_icon_image(obj, path,
1270                                                                                                    ugd->thumbs_d->icon_w,
1271                                                                                                    ugd->thumbs_d->icon_h);
1272                 }
1273
1274
1275                 return layout;
1276
1277         } else if (!g_strcmp0(part, "checkbox_swallow") && ugd->thumbs_d->b_editmode == true) {
1278                 Evas_Object* ck = NULL;
1279                 ck = elm_check_add(obj);
1280                 GE_CHECK_NULL(ck);
1281
1282                 evas_object_propagate_events_set(ck, EINA_FALSE);
1283                 evas_object_repeat_events_set(ck, EINA_FALSE);
1284                 elm_check_state_set(ck, gitem->checked);
1285                 ugd->thumbs_d->check = ck;
1286                 evas_object_smart_callback_add(ck, "changed",
1287                                 __ge_check_state_changed_cb, gitem);
1288                 evas_object_show(ck);
1289
1290                 return ck;
1291         } else if (!g_strcmp0(part, "sd_card_icon")) {
1292                 if (gitem->item->storage_type == GE_MMC) {
1293                         icon = elm_icon_add(obj);
1294                         elm_icon_file_set(icon, sd_card_image_path, NULL);
1295                         evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1296                         return icon;
1297                 }
1298         }
1299
1300         return layout;
1301 }
1302
1303 static char*
1304 __ge_gengrid_text_get_cb(void *data, Evas_Object *obj, const char *part)
1305 {
1306                 return strdup(GE_STR_GALLERY);
1307 }
1308
1309 static void
1310 __ge_gallery_ug_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *data)
1311 {
1312         ge_ugdata *ugd=(ge_ugdata *)data;
1313         char **pathArray = NULL;
1314         int arrayLength = 0;
1315         int i = 0;
1316         bool send_success = false;
1317
1318         if ((result != APP_CONTROL_ERROR_NONE) || !reply) {
1319                 ge_dbgE("ug-gallery-efl data get failed.");
1320                 return;
1321         }
1322
1323         app_control_get_extra_data_array(reply, APP_CONTROL_DATA_PATH, &pathArray, &arrayLength);
1324
1325         if (arrayLength != 0) {
1326                 ge_dbg("Receiving data from ug-gallery-efl.");
1327                 char t_str[32] = { 0, };
1328                 eina_convert_itoa(arrayLength, t_str);
1329
1330                 app_control_add_extra_data(ugd->service,
1331                                            GE_FILE_SELECT_RETURN_COUNT, t_str);
1332                 app_control_add_extra_data_array(ugd->service, APP_CONTROL_DATA_SELECTED,
1333                                                          (const char **)pathArray, arrayLength);
1334                 app_control_add_extra_data_array(ugd->service, APP_CONTROL_DATA_PATH,
1335                                                                  (const char **)pathArray, arrayLength);
1336                 ug_send_result_full(ugd->ug, ugd->service, APP_CONTROL_RESULT_SUCCEEDED);
1337                 send_success = true;
1338
1339         GE_SEND_RESULT_FINISHED:
1340                 if (pathArray) {
1341                         for (i = 0; i < arrayLength; i++) {
1342                                 GE_FREEIF(pathArray[i]);
1343                         }
1344                         GE_FREE(pathArray);
1345                 }
1346
1347                 if (!ugd->is_attach_panel) {
1348                         ug_destroy_me(ugd->ug);
1349                 }
1350         }
1351 }
1352
1353 static void
1354 __ge_launch_ug_gallery(void *data, Evas_Object *obj, void *ei)
1355 {
1356         ge_ugdata *ugd=(ge_ugdata *)data;
1357         GE_CHECK_VAL(ugd, -1);
1358
1359         char maximum_count [10];
1360         snprintf (maximum_count, 10, "%d", ugd->max_count);
1361
1362         app_control_h svc_handle = NULL;
1363
1364         if (!app_control_create(&svc_handle)) {
1365                 app_control_set_operation(svc_handle, APP_CONTROL_OPERATION_PICK);
1366                 app_control_set_launch_mode(svc_handle, APP_CONTROL_LAUNCH_MODE_GROUP);
1367                 app_control_set_app_id(svc_handle,  "ug-gallery-efl");
1368                 app_control_set_mime(svc_handle, "image/*");
1369                 app_control_add_extra_data(svc_handle, APP_CONTROL_DATA_TOTAL_COUNT, maximum_count);
1370                 app_control_add_extra_data(svc_handle, "launch-type", "select-multiple");
1371                 app_control_add_extra_data(svc_handle, "file-type","image");
1372                 app_control_add_extra_data(svc_handle, "hide-personal", "true");
1373                 app_control_send_launch_request(svc_handle, __ge_gallery_ug_result_cb, data);
1374                 int ret = app_control_destroy(svc_handle);
1375
1376                 if (ret == 0) {
1377                         ge_dbg("Launched ug-gallery-efl successfully.");
1378                 } else {
1379                         ge_dbgE("Launching ug-gallery-efl Failed.");
1380                 }
1381         } else {
1382                 ge_dbgE("app_control_service_handle creation failed. Unable to Launch ug-gallery-efl.");
1383         }
1384 }
1385
1386 static int
1387 __ge_grid_select_one(ge_item *gitem, char *file_url)
1388 {
1389         GE_CHECK_VAL(file_url, -1);
1390         GE_CHECK_VAL(gitem, -1);
1391         ge_ugdata *ugd = (ge_ugdata *)gitem->ugd;
1392         GE_CHECK_VAL(ugd, -1);
1393         ge_sdbg("Service add:%s", file_url);
1394
1395         int ret = -1;
1396
1397         if (!g_strcmp0(gitem->item->thumb_url, DEFAULT_THUMBNAIL)) {
1398                 char *pStrWarning = g_strdup_printf(GE_STR_UNSUPPORTED_FILE, NULL);
1399                 notification_status_message_post(pStrWarning);
1400                 GE_FREE(pStrWarning);
1401                 return ret;
1402         }
1403
1404         char **path_array = (char **)calloc(1, sizeof(char *));
1405         if (!path_array) {
1406                 ge_dbgW("failed to allocate path");
1407                 return ret;
1408         }
1409         path_array[0] = strdup(file_url);
1410
1411         ret = app_control_add_extra_data(ugd->service, GE_FILE_SELECT_RETURN_PATH, file_url);
1412
1413         if (ret != APP_CONTROL_ERROR_NONE) {
1414                 ge_dbgW("Add file path failed!");
1415         }
1416         ret = app_control_add_extra_data_array(ugd->service, APP_CONTROL_DATA_SELECTED,
1417                                          (const char **)path_array, 1);
1418         ret = app_control_add_extra_data_array(ugd->service, APP_CONTROL_DATA_PATH,
1419                                          (const char **)path_array, 1);
1420         if (ret != APP_CONTROL_ERROR_NONE) {
1421                 ge_dbgW("Add selected path failed!");
1422         }
1423         ret = ug_send_result_full(ugd->ug, ugd->service,
1424                                   APP_CONTROL_RESULT_SUCCEEDED);
1425         if (ret != 0) {
1426                 ge_dbgW("Send result failed!");
1427         }
1428         if (!ugd->is_attach_panel) {
1429                 ug_destroy_me(ugd->ug);
1430         }
1431
1432         GE_FREEIF(path_array[0]);
1433         GE_FREEIF(path_array);
1434         return ret;
1435 }
1436
1437 static void
1438 __ge_gengrid_item_sel_cb(void *data, Evas_Object *obj, void *ei)
1439 {
1440
1441         GE_CHECK(data);
1442         ge_item *gitem = (ge_item*)data;
1443         GE_CHECK(gitem->item);
1444         GE_CHECK(gitem->ugd);
1445         ge_ugdata *ugd = gitem->ugd;
1446         char *pd_selected = GE_STR_PD_SELECTED;
1447         char *text = NULL;
1448         Evas_Object *btn = NULL;
1449         Eina_List *l = NULL;
1450         ge_sel_item_s *sit = NULL;
1451         ge_sel_item_s *sit1 = NULL;
1452
1453         elm_gengrid_item_selected_set(ei, EINA_FALSE);
1454
1455         if (ugd->file_select_mode == GE_FILE_SELECT_T_ONE){
1456                 int ret = __ge_grid_select_one(gitem, gitem->item->file_url);
1457
1458                 if (ret != 0) {
1459                         ge_dbgE("Data Transfer Failed.");
1460                 }
1461         } else if (ugd->file_select_mode == GE_FILE_SELECT_T_MULTIPLE) {
1462                 Evas_Object *ck = elm_object_item_part_content_get((Elm_Object_Item *) ei, "checkbox_swallow");
1463
1464                 Eina_Bool *bl = elm_check_state_get(ck);
1465
1466                 if (bl == EINA_FALSE) {
1467                         if (!g_strcmp0(gitem->item->thumb_url, DEFAULT_THUMBNAIL)) {
1468                                 char *pStrWarning = g_strdup_printf(
1469                                         GE_STR_UNSUPPORTED_FILE,
1470                                         NULL);
1471                                 notification_status_message_post(pStrWarning);
1472                                 GE_FREE(pStrWarning);
1473                                 return;
1474                         }
1475                         if ((ugd->max_count != -1) && (gitem->ugd->thumbs_d->tot_selected + 1 > ugd->max_count)) {
1476                                 char *pStrWarning = g_strdup_printf(
1477                                         GE_STR_MAX_PICTURES_SELECTED,
1478                                         ugd->max_count);
1479                                 notification_status_message_post(pStrWarning);
1480                                 GE_FREE(pStrWarning);
1481                                 return;
1482                         }
1483                         sit = _ge_data_util_new_sel_item(gitem);
1484                         if (!sit) {
1485                                 ge_dbgE("Invalid select item");
1486                                 return;
1487                         }
1488 #ifdef FEATURE_SIZE_CHECK
1489                         struct stat stFileInfo;
1490                         stat(sit->file_url, &stFileInfo);
1491                         if (ugd->selsize + stFileInfo.st_size > ugd->limitsize) {
1492                                 notification_status_message_post("maximum of 2MB can be selected");
1493                                 _ge_data_util_free_sel_item(sit);
1494                                 return;
1495                         }
1496 #endif
1497                         ge_sdbg("append Path: %s", sit->file_url);
1498                         ugd->selected_elist = eina_list_append(ugd->selected_elist, sit);
1499                         elm_check_state_set(ck, EINA_TRUE);
1500                         gitem->ugd->thumbs_d->tot_selected++;
1501 #ifdef FEATURE_SIZE_CHECK
1502                         ugd->selsize += stFileInfo.st_size;
1503 #endif
1504                         gitem->checked = TRUE;
1505                 } else {
1506                         sit = _ge_data_util_new_sel_item(gitem);
1507                         if (!sit) {
1508                                 ge_dbgE("Invalid select item");
1509                                 return;
1510                         }
1511 #ifdef FEATURE_SIZE_CHECK
1512                         struct stat stFileInfo;
1513                         stat(sit->file_url, &stFileInfo);
1514 #endif
1515                         ge_sdbg("remove Path: %s", sit->file_url);
1516                         EINA_LIST_FOREACH(ugd->selected_elist, l, sit1) {
1517                                 if (!strcmp(sit->file_url, sit1->file_url)) {
1518                                         ugd->selected_elist = eina_list_remove(ugd->selected_elist, sit1);
1519                                         _ge_data_util_free_sel_item(sit1);
1520                                 }
1521                         }
1522                         elm_check_state_set(ck, EINA_FALSE);
1523                         gitem->ugd->thumbs_d->tot_selected--;
1524 #ifdef FEATURE_SIZE_CHECK
1525                         ugd->selsize -= stFileInfo.st_size;
1526 #endif
1527                         gitem->checked = FALSE;
1528                         _ge_data_util_free_sel_item(sit);
1529                 }
1530
1531                 btn = elm_object_item_part_content_get (ugd->nf_it , GE_NAVIFRAME_TITLE_RIGHT_BTN);
1532                 if (btn == NULL) {
1533                         ge_dbgE("Failed to get part information");
1534                 }
1535
1536                 if (ugd->thumbs_d->tot_selected == 0) {
1537                         elm_object_disabled_set(btn, EINA_TRUE);
1538                 } else {
1539                         elm_object_disabled_set(btn, EINA_FALSE);
1540                 }
1541
1542                 if (gitem->ugd->thumbs_d->tot_selected >= 0) {
1543                         text = g_strdup_printf(pd_selected, gitem->ugd->thumbs_d->tot_selected);
1544                         elm_object_item_text_set(gitem->ugd->nf_it, text);
1545                 }
1546         }
1547 }
1548
1549 static void
1550 __ge_cancel_cb(void *data, Evas_Object *obj, void *ei)
1551 {
1552         ge_ugdata *app_data=(ge_ugdata *)data;
1553         Eina_List *l = NULL;
1554         ge_item *gitem = NULL;
1555
1556         if (app_data->is_attach_panel && (app_data->attach_panel_display_mode == ATTACH_PANEL_FULL_MODE)) {
1557
1558                         int ret;
1559                         app_control_h app_control = NULL;
1560                         ret = app_control_create(&app_control);
1561                         if (ret == APP_CONTROL_ERROR_NONE) {
1562                                 app_control_add_extra_data(app_control, ATTACH_PANEL_FLICK_MODE_KEY, ATTACH_PANEL_FLICK_MODE_ENABLE);
1563                                 app_control_add_extra_data_array(app_control, APP_CONTROL_DATA_PATH,
1564                                                                          NULL, 0);
1565                                 /*ret = app_control_add_extra_data(app_control, "__ATTACH_PANEL_SHOW_PANEL__", "false");
1566
1567                                 if (ret != APP_CONTROL_ERROR_NONE) {
1568                                         ge_dbgW("Attach panel show failed");
1569                                 }*/
1570                                 ret = ug_send_result_full(app_data->ug, app_control, APP_CONTROL_RESULT_FAILED);
1571                         }
1572                         app_control_destroy(app_control);
1573         }
1574
1575         EINA_LIST_FOREACH(app_data->thumbs_d->medias_elist, l, gitem) {
1576                 gitem->checked = false;
1577         }
1578
1579         app_data->selected_elist = eina_list_free(app_data->selected_elist);
1580         elm_naviframe_item_pop (app_data->naviframe);
1581 }
1582
1583 int
1584 ge_update_gengrid(ge_ugdata *ugd)
1585 {
1586         GE_CHECK_VAL(ugd, -1);
1587         GE_CHECK_VAL(ugd->thumbs_d, -1);
1588
1589         int ret = 0;
1590         int i = 0;
1591         ge_item* gitem = NULL;
1592         int item_cnt = 0;
1593         char *pd_selected = GE_STR_PD_SELECTED;
1594         ge_sel_item_s *sit = NULL;
1595         Eina_List *l = NULL;
1596         int win_x = 0;
1597         int win_y = 0;
1598         int win_w = 0;
1599         int win_h = 0;
1600
1601         elm_win_screen_size_get(ugd->win, &win_x, &win_y, &win_w, &win_h);
1602
1603         int size = (win_w / 4);
1604         if (ugd->thumbs_d->medias_elist) {
1605                 _ge_data_util_free_mtype_items(&ugd->thumbs_d->medias_elist);
1606         }
1607
1608         ugd->thumbs_d->medias_cnt = 0;
1609
1610         ugd->thumbs_d->tot_selected = 0;
1611
1612         ret = _ge_data_get_medias(ugd, ugd->thumbs_d->album_uuid,
1613                                                           GE_ALL,
1614                                                           0,
1615                                                           GE_GET_UNTIL_LAST_RECORD,
1616                                                           &(ugd->thumbs_d->medias_elist),
1617                                                           NULL, NULL);
1618
1619         if (ret != 0) {
1620                 ge_dbgE("###Get items list over[%d]###", ret);
1621                 return ret;
1622         }
1623
1624         ugd->thumbs_d->medias_cnt = eina_list_count(ugd->thumbs_d->medias_elist);
1625         ge_dbg("Grid view updated media count: %d", ugd->thumbs_d->medias_cnt);
1626
1627         elm_gengrid_clear(ugd->thumbs_d->gengrid);
1628         if (ugd->thumbs_d->medias_cnt > 0) {
1629                 if (ugd->nocontents) {
1630                         evas_object_del(ugd->nocontents);
1631                         ugd->nocontents = NULL;
1632                 }
1633                 elm_gengrid_item_size_set(ugd->thumbs_d->gengrid, size, size);
1634                 elm_gengrid_item_append(ugd->thumbs_d->gengrid,
1635                                                                 gic_first,
1636                                                                 NULL, __ge_launch_ug_gallery,
1637                                                                 ugd);
1638
1639                 for (i = 0; i < ugd->thumbs_d->medias_cnt; i++) {
1640                         gitem = eina_list_nth(ugd->thumbs_d->medias_elist, i);
1641                         if (gitem == NULL || gitem->item == NULL ||
1642                                         gitem->item->uuid == NULL) {
1643                                 ge_dbgE("Invalid gitem!");
1644                                 continue;
1645                         }
1646
1647                         if (!gitem->item->file_url) {
1648                                 ge_dbgE("file_url is invalid!");
1649                                 _ge_data_del_media_by_id(ugd, gitem->item->uuid);
1650                                 _ge_data_util_free_item(gitem);
1651                                 ugd->thumbs_d->medias_cnt--;
1652                                 i--;
1653                                 gitem = NULL;
1654                                 continue;
1655                         }
1656
1657                         if (ugd->selected_elist) {
1658                                 EINA_LIST_FOREACH(ugd->selected_elist, l, sit) {
1659                                         if (strcmp(sit->file_url, gitem->item->file_url) == 0) {
1660                                                 gitem->checked = true;
1661                                                 ugd->thumbs_d->tot_selected++;
1662                                         }
1663                                 }
1664                         }
1665
1666                         gitem->ugd = ugd;
1667                         gitem->elm_item = elm_gengrid_item_append(ugd->thumbs_d->gengrid,
1668                                                                                                           ugd->thumbs_d->gic,
1669                                                                                                           gitem, __ge_gengrid_item_sel_cb,
1670                                                                                                           gitem);
1671
1672                         item_cnt++;
1673                         gitem->sequence = item_cnt + 1;
1674                 }
1675         } else {
1676                 if (ugd->attach_panel_display_mode == ATTACH_PANEL_FULL_MODE) {
1677                                         elm_gengrid_item_size_set(ugd->thumbs_d->gengrid, win_w, FULL_MODE_PORTRAIT_HEIGHT);
1678                 } else {
1679                         elm_gengrid_item_size_set(ugd->thumbs_d->gengrid, win_w, HALF_MODE_PORTRAIT_HEIGHT);
1680                 }
1681
1682                 ugd->nocontents = _ge_nocontents_create(ugd);
1683                 elm_gengrid_item_append(ugd->thumbs_d->gengrid,
1684                                                                         no_content      ,
1685                                                                         ugd, NULL,
1686                                                                         ugd);
1687         }
1688
1689
1690         char *text = g_strdup_printf(pd_selected, ugd->thumbs_d->tot_selected);
1691         elm_object_item_text_set(ugd->nf_it, text);
1692
1693         return 0;
1694 }
1695
1696 int
1697 ge_create_gengrid(ge_ugdata *ugd)
1698 {
1699         ge_dbgE("");
1700         GE_CHECK_VAL(ugd, -1);
1701
1702         ugd->albums_view = __ge_albums_add_view(ugd, ugd->albums_view_ly);
1703
1704         ugd->attach_panel_display_mode = ATTACH_PANEL_HALF_MODE;
1705
1706         ge_dbgE("!!!!! album view !!!!!!!! is pushed in the naviframe instead of content set");
1707
1708         int i = 0;
1709         ge_item* gitem = NULL;
1710         int item_cnt = 0;
1711         int ret = -1;
1712
1713         ge_thumbs_s *thumbs_d = NULL;
1714         thumbs_d = (ge_thumbs_s *)calloc(1, sizeof(ge_thumbs_s));
1715         GE_CHECK_VAL(thumbs_d, -1);
1716         ugd->thumbs_d = thumbs_d;
1717         ugd->thumbs_d->store_type = GE_ALL;
1718         ugd->thumbs_d->b_multifile = true;
1719         ugd->thumbs_d->b_mainview = true;
1720         ugd->thumbs_d->b_editmode = false;
1721         ugd->thumbs_d->tot_selected = 0;
1722
1723         ugd->attach_panel_display_mode = ATTACH_PANEL_HALF_MODE;
1724         ugd->file_select_mode = GE_FILE_SELECT_T_ONE;
1725
1726         ret = _ge_data_get_medias(ugd, ugd->thumbs_d->album_uuid,
1727                                   GE_ALL,
1728                                   0,
1729                                   GE_GET_UNTIL_LAST_RECORD,
1730                                   &(ugd->thumbs_d->medias_elist),
1731                                   NULL, NULL);
1732
1733         if (ret != 0) {
1734                 ge_dbgE("###Get items list over[%d]###", ret);
1735         }
1736
1737         ugd->thumbs_d->medias_cnt = eina_list_count(ugd->thumbs_d->medias_elist);
1738         ge_dbg("Grid view all medias count: %d", ugd->thumbs_d->medias_cnt);
1739
1740         Evas_Object *gengrid;
1741         char edj_path[PATH_MAX] = {0, };
1742
1743
1744         AppGetResource(GE_EDJ_FILE, edj_path, (int)PATH_MAX);
1745
1746         gengrid = elm_gengrid_add(ugd->albums_view);
1747         ugd->thumbs_d->gengrid = gengrid;
1748         elm_theme_extension_add(NULL, edj_path);
1749
1750         int win_x = 0;
1751         int win_y = 0;
1752         int win_w = 0;
1753         int win_h = 0;
1754
1755         elm_win_screen_size_get(ugd->win, &win_x, &win_y, &win_w, &win_h);
1756         int size = (win_w / 4);
1757
1758         _ge_ui_reset_scroller_pos(gengrid);
1759         elm_gengrid_align_set(gengrid, 0.0, 0.0);
1760 #ifdef _USE_SCROL_HORIZONRAL
1761         /* horizontal scrolling */
1762         elm_gengrid_horizontal_set(gengrid, EINA_TRUE);
1763         elm_scroller_bounce_set(gengrid, EINA_TRUE, EINA_FALSE);
1764 #else
1765         elm_gengrid_horizontal_set(gengrid, EINA_FALSE);
1766         elm_scroller_bounce_set(gengrid, EINA_FALSE, EINA_TRUE);
1767 #endif
1768         elm_scroller_policy_set(gengrid, ELM_SCROLLER_POLICY_OFF,
1769                                 ELM_SCROLLER_POLICY_AUTO);
1770         evas_object_size_hint_weight_set(gengrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1771
1772         if (ugd->is_attach_panel && (ugd->attach_panel_display_mode != ATTACH_PANEL_FULL_MODE)) {
1773                 elm_scroller_movement_block_set(gengrid, ELM_SCROLLER_MOVEMENT_BLOCK_VERTICAL);
1774         }
1775
1776         if (ugd->is_attach_panel) {
1777                 evas_object_smart_callback_add(gengrid, "scroll,anim,stop",
1778                                    _ge_grid_move_stop_cb, ugd);
1779                 evas_object_smart_callback_add(gengrid, "scroll,drag,stop",
1780                                    _ge_grid_move_stop_cb, ugd);
1781         }
1782
1783         ugd->thumbs_d->gic = elm_gengrid_item_class_new();
1784
1785         if (ugd->thumbs_d->gic) {
1786                 ugd->thumbs_d->gic->item_style = "gengrid_items";
1787                 ugd->thumbs_d->gic->func.text_get = NULL;
1788                 ugd->thumbs_d->gic->func.content_get = __ge_gengrid_item_content_get;
1789                 ugd->thumbs_d->gic->func.state_get = NULL;
1790                 ugd->thumbs_d->gic->func.del = NULL;
1791         }
1792
1793         gic_first = elm_gengrid_item_class_new();
1794
1795         if (gic_first) {
1796                 gic_first->item_style = "gengrid_first_item";
1797                 gic_first->func.text_get = __ge_gengrid_text_get_cb;
1798                 gic_first->func.content_get = NULL;
1799                 gic_first->func.state_get = NULL;
1800                 gic_first->func.del = NULL;
1801
1802         }
1803
1804         no_content = elm_gengrid_item_class_new();
1805
1806         if (no_content) {
1807                 no_content->item_style = "no_content";
1808                 no_content->func.text_get = NULL;
1809                 no_content->func.content_get = __ge_nocontent_get;
1810                 no_content->func.state_get = NULL;
1811                 no_content->func.del = NULL;
1812         }
1813
1814         if (ugd->thumbs_d->medias_cnt > 0) {
1815                 elm_gengrid_item_size_set(gengrid, size, size);
1816                 elm_gengrid_item_append(gengrid,
1817                                                                 gic_first,
1818                                                                 NULL, __ge_launch_ug_gallery,
1819                                                                 ugd);
1820                 /* From zeroth IMAGE item to last one */
1821                 for (i = 0; i < ugd->thumbs_d->medias_cnt; i++) {
1822                         gitem = eina_list_nth(ugd->thumbs_d->medias_elist, i);
1823                         if (gitem == NULL || gitem->item == NULL ||
1824                                         gitem->item->uuid == NULL) {
1825                                 ge_dbgE("Invalid gitem!");
1826                                 continue;
1827                         }
1828
1829                         if (!gitem->item->file_url) {
1830                                 ge_dbgE("file_url is invalid!");
1831                                 _ge_data_del_media_by_id(ugd, gitem->item->uuid);
1832                                 _ge_data_util_free_item(gitem);
1833                                 ugd->thumbs_d->medias_cnt--;
1834                                 i--;
1835                                 gitem = NULL;
1836                                 continue;
1837                         }
1838
1839                         gitem->ugd = ugd;
1840                         gitem->elm_item = elm_gengrid_item_append(gengrid,
1841                                                                                                           ugd->thumbs_d->gic,
1842                                                                                                           gitem, __ge_gengrid_item_sel_cb,
1843                                                                                                           gitem);
1844
1845                         item_cnt++;
1846                         gitem->sequence = item_cnt + 1;
1847                 }
1848         } else {
1849                 ugd->nocontents = _ge_nocontents_create(ugd);
1850                 elm_gengrid_item_size_set(gengrid, win_w, HALF_MODE_PORTRAIT_HEIGHT);
1851                 elm_gengrid_item_append(gengrid,
1852                                                                 no_content,
1853                                                                 ugd, NULL,
1854                                                                 ugd);
1855         }
1856         evas_object_show(gengrid);
1857
1858         elm_object_part_content_set(ugd->albums_view, "contents", gengrid);
1859
1860         char *pd_selected = GE_STR_PD_SELECTED;
1861         ugd->nf_it = elm_naviframe_item_push(ugd->naviframe, g_strdup_printf(pd_selected, ugd->thumbs_d->tot_selected), NULL, NULL, ugd->albums_view, "basic/transparent");
1862
1863         /* Cancel Button */
1864         Evas_Object *btn1 = elm_button_add(ugd->naviframe);
1865         elm_object_style_set(btn1, "naviframe/title_left");
1866         //elm_object_text_set(btn1, GE_STR_ID_CANCEL_CAP);
1867         _ge_ui_set_translate_str(btn1, "IDS_TPLATFORM_ACBUTTON_CANCEL_ABB");
1868         elm_object_item_part_content_set(ugd->nf_it, GE_NAVIFRAME_TITLE_LEFT_BTN, btn1);
1869         evas_object_show(btn1);
1870         evas_object_smart_callback_add(btn1, "clicked", __ge_cancel_cb, ugd);
1871
1872         /* Done Button*/
1873         Evas_Object *btn2 = elm_button_add(ugd->naviframe);
1874         elm_object_style_set(btn2, "naviframe/title_right");
1875         //elm_object_text_set(btn2, GE_STR_ID_DONE_CAP);
1876         _ge_ui_set_translate_str(btn2, "IDS_TPLATFORM_ACBUTTON_DONE_ABB");
1877         elm_object_disabled_set(btn2, EINA_TRUE);
1878         elm_object_item_part_content_set(ugd->nf_it, GE_NAVIFRAME_TITLE_RIGHT_BTN, btn2);
1879         evas_object_show(btn2);
1880         evas_object_smart_callback_add(btn2, "clicked", __ge_grid_done_cb, (void *)ugd);
1881
1882         elm_naviframe_item_title_enabled_set(ugd->nf_it, EINA_FALSE, EINA_FALSE);
1883
1884         elm_naviframe_item_pop_cb_set(ugd->nf_it, __ge_main_back_cb, ugd);
1885
1886         return 0;
1887 }
1888
1889 int _ge_albums_update_view(ge_ugdata *ugd)
1890 {
1891         ge_dbg("");
1892         GE_CHECK_VAL(ugd, -1);
1893         GE_CHECK_VAL(ugd->cluster_list, -1);
1894         int sel_cnt = 0;
1895
1896         /* Reset view mode */
1897         _ge_set_view_mode(ugd, GE_VIEW_ALBUMS);
1898
1899         /* Changed to show no contents if needed */
1900         if (!ugd->cluster_list->clist ||
1901                         (eina_list_count(ugd->cluster_list->clist) == 0)) {
1902                 _ge_data_get_clusters(ugd, GE_ALBUM_DATA_NONE);
1903                 ugd->cluster_list->append_cb = __ge_albums_append;
1904                 if (!ugd->cluster_list->clist ||
1905                                         (eina_list_count(ugd->cluster_list->clist) == 0)) {
1906                 ge_dbgW("Clusters list is empty!");
1907                 goto ALBUMS_FAILED;
1908                 }
1909         }
1910
1911         if (ugd->nocontents && ugd->nocontents == ugd->albums_view) {
1912                 /* It is nocontents, unset it first then create albums view*/
1913                 evas_object_del(ugd->nocontents);
1914                 ugd->nocontents = NULL;
1915
1916                 ugd->albums_view = __ge_albums_add_view(ugd, ugd->naviframe);
1917                 GE_CHECK_VAL(ugd->albums_view, -1);
1918                 Evas_Object *tmp=NULL;
1919                 tmp=elm_object_part_content_get(ugd->albums_view_ly,"contents");
1920                 if (tmp!=NULL) {
1921                         ge_dbgE("tmp was not empty MULKUKU:------------------------------>");
1922                         elm_object_part_content_unset(ugd->albums_view_ly, "contents");
1923                         evas_object_hide(tmp);
1924                 }
1925
1926                 elm_object_part_content_set(ugd->albums_view_ly, "contents",
1927                                 ugd->albums_view);
1928
1929                 ge_dbgE("!!!!! album view !!!!!!!! is pushed in the naviframe instead of content set");
1930                 ugd->nf_it = elm_naviframe_item_push(ugd->naviframe, GE_ALBUM_NAME, NULL, NULL, ugd->albums_view, NULL );
1931
1932                 if (ugd->nf_it != NULL) {
1933                         ge_dbgE("!!!! album view !!!!! is push successfully in the nf");
1934                 }
1935                 else
1936                         ge_dbgE("!!!!!! album view !!!!!1111 failed to push in nf ");
1937
1938
1939
1940                 evas_object_show(ugd->albums_view);
1941         } else {
1942                 if (__ge_albums_append_albums(ugd, ugd->albums_view, true) != 0)
1943                         goto ALBUMS_FAILED;
1944                 else {
1945                         elm_naviframe_item_pop(ugd->naviframe);
1946                         ugd->nf_it = elm_naviframe_item_push(ugd->naviframe, GE_ALBUM_NAME, NULL, NULL, ugd->albums_view, NULL );
1947
1948                         if (ugd->nf_it != NULL) {
1949                                 ge_dbgE("!!!! album view !!!!! is push successfully in the nf");
1950                         }
1951                         else
1952                                 ge_dbgE("!!!!!! album view !!!!!1111 failed to push in nf ");
1953                 }
1954         }
1955
1956         sel_cnt = _ge_data_get_sel_cnt(ugd);
1957         if (ugd->done_it != NULL) {
1958                 if (sel_cnt > 0 && (ugd->max_count < 0 || sel_cnt <= ugd->max_count))
1959                         _ge_ui_disable_item(ugd->done_it, false);
1960                 else
1961                         _ge_ui_disable_item(ugd->done_it, true);
1962         } else {
1963                 ge_dbgW("done item is NULL");
1964         }
1965
1966         Elm_Object_Item *nf_it = elm_naviframe_bottom_item_get(ugd->naviframe);
1967         _ge_ui_update_label_text(nf_it, sel_cnt, ugd->albums_view_title);
1968         return 0;
1969
1970         ALBUMS_FAILED:
1971
1972         sel_cnt = _ge_data_get_sel_cnt(ugd);
1973         if (ugd->done_it != NULL) {
1974                 if (sel_cnt > 0 && (ugd->max_count < 0 || sel_cnt <= ugd->max_count))
1975                         _ge_ui_disable_item(ugd->done_it, false);
1976                 else
1977                         _ge_ui_disable_item(ugd->done_it, true);
1978         } else {
1979                 ge_dbgW("done item is NULL");
1980         }
1981
1982         if (ugd->albums_view && ugd->albums_view != ugd->nocontents)
1983                 __ge_albums_del_cbs(ugd->albums_view);
1984
1985         evas_object_del(ugd->albums_view);
1986
1987         ge_dbgW("@@@@@@@  To create nocontents view @@@@@@@@");
1988         ugd->nocontents = ge_ui_create_nocontents(ugd);
1989         ugd->albums_view = ugd->nocontents;
1990         GE_CHECK_VAL(ugd->albums_view, -1);
1991         evas_object_show(ugd->albums_view);
1992
1993         elm_object_part_content_set(ugd->albums_view_ly, "contents",
1994                         ugd->albums_view);
1995
1996
1997         ge_dbgE("!!!!! album view !!!!!!!! is pushed in the naviframe instead of content set");
1998         ugd->nf_it = elm_naviframe_item_push(ugd->naviframe, GE_ALBUM_NAME, NULL, NULL,ugd->albums_view, NULL );
1999
2000         if (ugd->nf_it != NULL) {
2001                 ge_dbgE("!!!! album view !!!!! is push successfully in the nf");
2002         }
2003         else
2004                 ge_dbgE("!!!!!! album view !!!!!1111 failed to push in nf ");
2005
2006         return -1;
2007 }
2008