initial upload for tizen 2.0 beta
[apps/home/gallery.git] / src / widget / gl-nocontents.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 "gl-nocontents.h"
18 #include "gl-gridview.h"
19 #include "gl-listview.h"
20 #include "gl-controlbar.h"
21 #include "gl-ui-util.h"
22 #include "gl-util.h"
23 #include "gl-strings.h"
24 #include "gl-debug.h"
25
26 /**
27  * Create Nocontents.
28  */
29 Evas_Object *_gl_nocontents_create(void *data)
30 {
31         GL_CHECK_NULL(data);
32         gl_appdata *ad = (gl_appdata *)data;
33         Evas_Object *noc_lay = NULL;
34         char label_str[GL_POPUP_DESC_LEN_MAX] = { 0, };
35
36         int grid_mode = ad->gridinfo.grid_view_mode;
37         switch (grid_mode) {
38         case GL_GRID_ALL:
39                 snprintf(label_str, sizeof(label_str), "%s",
40                                  (char *)(GL_STR_NO_ITEMS));
41                 break;
42         case GL_GRID_VIDEOS:
43                 snprintf(label_str, sizeof(label_str), "%s",
44                                  (char *)(GL_STR_NO_VIDEOS));
45                 break;
46         case GL_GRID_IMAGES:
47                 snprintf(label_str, sizeof(label_str), "%s",
48                                  (char *)(GL_STR_NO_IMAGES));
49                 break;
50         case GL_GRID_ALBUMS:
51                 snprintf(label_str, sizeof(label_str), "%s",
52                          (char *)(GL_STR_NO_ALBUMS));
53                 break;
54         default:
55                 snprintf(label_str, sizeof(label_str), "%s",
56                          (char *)(GL_STR_NO_CONTENTS));
57                 break;
58         }
59
60         gl_dbg("Nocontents label: %s", label_str);
61         /* Full view nocontents */
62         noc_lay = elm_layout_add(ad->maininfo.naviframe);
63         GL_CHECK_NULL(noc_lay);
64         elm_object_part_text_set(noc_lay, GL_NOCONTENTS_TEXT, label_str);
65         elm_layout_theme_set(noc_lay, "layout", "nocontents", "gallery");
66
67         return noc_lay;
68 }
69
70 /**
71  * Update label of Nocontents.
72  */
73 bool _gl_nocontents_update_label(Evas_Object *noc, const char *new_label)
74 {
75         GL_CHECK_VAL(new_label, -1);
76         GL_CHECK_VAL(noc, -1);
77         const char *label = NULL;
78
79         label = elm_object_part_text_get(noc, GL_NOCONTENTS_TEXT);
80         GL_CHECK_VAL(label, -1);
81         gl_dbg("Nocontents label: %s", label);
82         /* Update label if they're different */
83         if (g_strcmp0(label, GL_STR_NO_ALBUMS)) {
84                 gl_dbgW("Update nocontents label!");
85                 elm_object_part_text_set(noc, GL_NOCONTENTS_TEXT, new_label);
86                 return true;
87         }
88         return false;
89 }
90
91 /**
92  * Show Nocontents in All/Images/Videos segment.
93  */
94 bool _gl_nocontents_show(void *data)
95 {
96         GL_CHECK_FALSE(data);
97         gl_appdata *ad = (gl_appdata *)data;
98         bool b_video_exist = false;
99         bool b_image_exist = false;
100         int seg_mode = ad->maininfo.seg_mode;
101         gl_item *gitem = NULL;
102         int i = 0;
103         bool ret = false;
104         int view_mode = gl_get_view_mode(ad);
105         /* Get all medias count of current album */
106         int cnt = ad->maininfo.medias_cnt;
107
108         if (seg_mode == GL_CTRL_SEG_VIDEOS ||
109                    seg_mode == GL_CTRL_SEG_IMAGES) {
110                 /* check in video or image segment. */
111                 for (i = 1; i <= cnt; i++) {
112                         _gl_data_get_item_by_index(ad, i, false, &gitem);
113                         if (gitem == NULL || gitem->item == NULL) {
114                                 gl_dbgE("gitem == NULL || gitem->item == NULL");
115                                 continue;
116                         }
117
118                         if (seg_mode == GL_CTRL_SEG_VIDEOS && !b_video_exist &&
119                             gitem->item->type == MEDIA_CONTENT_TYPE_VIDEO) {
120                                 b_video_exist = true;
121                                 break;
122                         } else if (seg_mode == GL_CTRL_SEG_IMAGES &&
123                                    !b_image_exist &&
124                                    gitem->item->type == MEDIA_CONTENT_TYPE_IMAGE) {
125                                 b_image_exist = true;
126                                 break;
127                         }
128
129                 }
130
131                 gl_dbg("video file exists->%d, image file exists->%d",
132                        b_video_exist, b_image_exist);
133                 if (seg_mode == GL_CTRL_SEG_VIDEOS && !b_video_exist) {
134                         if (view_mode == GL_VIEW_VIDEOLIST_EDIT) {
135                                 gl_dbg("In edit mode, change to normal view.");
136                                 gl_ui_edit_cancel(ad);
137                         }
138
139                         gl_dbg("None video files, show nocontents...");
140                         ret = true;
141                 } else if (seg_mode == GL_CTRL_SEG_IMAGES && !b_image_exist) {
142                         if (view_mode == GL_VIEW_THUMBS_EDIT) {
143                                 gl_dbg("In edit mode, change to normal view.");
144                                 gl_ui_edit_cancel(ad);
145                         }
146
147                         gl_dbg("None image files, show nocontents...");
148                         Evas_Object *noc = _gl_nocontents_create(ad);
149                         if (ad->gridinfo.images_view) {
150                                 evas_object_del(ad->gridinfo.images_view);
151                                 ad->gridinfo.images_view = NULL;
152                         }
153                         ad->gridinfo.images_view = noc;
154                         ad->gridinfo.images_nocontents = noc;
155                         elm_object_part_content_unset(ad->gridinfo.layout,
156                                                       "elm.swallow.view");
157                         evas_object_hide(ad->listinfo.videos_view);
158                         evas_object_hide(ad->gridinfo.all_view);
159                         evas_object_show(ad->gridinfo.images_view);
160                         elm_object_part_content_set(ad->gridinfo.layout,
161                                                     "elm.swallow.view",
162                                                     ad->gridinfo.images_view);
163                         _gl_ctrl_disable_toolbar_item(ad, true, GL_NAVI_THUMBS,
164                                                       false);
165                         ret = true;
166                 }
167         }
168
169         return ret;
170 }
171