2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <vconf-keys.h>
21 #include <media-thumbnail.h>
23 #include "ge-albums.h"
24 #include "ge-gridview.h"
27 #include "ge-ui-util.h"
29 #define GE_TIME_MSEC_PER_SEC 1000
30 #define GE_TIME_SEC_PER_MIN 60
31 #define GE_TIME_MIN_PER_HOUR 60
32 #define GE_TIME_SEC_PER_HOUR (GE_TIME_MIN_PER_HOUR * GE_TIME_SEC_PER_MIN)
34 /* Global evas objects, which is used in the entire application */
35 static ge_item* ge_current_mb_item;
36 static ge_cluster* ge_current_album_item;
37 static int ge_ug_iv_enter = 0;
39 ge_item* _ge_get_current_item(void)
41 return ge_current_mb_item;
44 void _ge_set_current_item(ge_item* gitem)
46 ge_current_mb_item = gitem;
49 ge_cluster* _ge_get_current_album(void)
51 return ge_current_album_item;
54 void _ge_set_current_album(ge_cluster* album_item)
56 ge_current_album_item = album_item;
59 int _ge_ug_iv_get(void)
61 return ge_ug_iv_enter;
64 void _ge_ug_iv_set(int ug_iv_state)
66 ge_ug_iv_enter = ug_iv_state;
69 static int _ge_refresh_albums_list(ge_ugdata *ugd)
71 GE_CHECK_VAL(ugd, -1);
72 ge_cluster* old_cur_cluster = _ge_get_current_album();
73 char cluster_id[GE_MTYPE_ITEN_ID_LEN_MAX] = { 0, };
75 ge_cluster *current = NULL;
76 bool b_get_cur_album = false;
78 if(old_cur_cluster && old_cur_cluster->cluster &&
79 old_cur_cluster->cluster->uuid)
81 g_strlcpy(cluster_id, old_cur_cluster->cluster->uuid,
82 GE_MTYPE_ITEN_ID_LEN_MAX);
83 b_get_cur_album = true;
87 ge_dbg("None album selected, current album is unavailable\n");
89 _ge_data_get_clusters_list(ugd);
91 GE_CHECK_VAL(ugd->cluster_list, -1);
92 int length = eina_list_count(ugd->cluster_list->clist);
93 ge_dbg("album length: %d, current album id: %s", length, cluster_id);
95 //need to reset current cluster
96 _ge_set_current_album(NULL);
99 for (i = 0; i < length; i++)
101 current = eina_list_nth(ugd->cluster_list->clist, i);
102 if(current && current->cluster &&
103 current->cluster->uuid) {
104 ge_dbg("current album : %s", current->cluster->display_name);
106 ge_dbgE("Current is NULL");
109 if(!g_strcmp0(current->cluster->uuid, cluster_id))
111 _ge_data_update_items_list(ugd, current);
112 _ge_set_current_album(current);
116 /* Current album was removed, clear items list */
117 if (_ge_data_get_selected_list())
118 _ge_data_selected_list_finalize();
119 _ge_data_free_items_list();
125 static void _ge_db_update_noti_cb(keynode_t *key, void* data)
127 ge_dbgW("VCONFKEY_FILEMANAGER_DB_STATUS changed!");
129 ge_ugdata* ugd = (ge_ugdata*)data;
131 int mode = GE_UPDATE_NONE;
133 vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmc_state);
134 if(mmc_state == -1) {
135 ge_dbgE("vconf_get_int failed!");
139 if (mmc_state == VCONFKEY_SYSMAN_MMC_MOUNTED) {
140 ge_dbg("mmc_state[%d]: VCONFKEY_SYSMAN_MMC_MOUNTED", mmc_state);
141 mode = GE_UPDATE_MMC_ADDED;
142 } else if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED ||
143 mmc_state == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
144 ge_dbg("mmc_state[%d]: VCONFKEY_SYSMAN_MMC_REMOVED", mmc_state);
145 mode = GE_UPDATE_MMC_REMOVED;
149 ge_update_view(ugd, mode);
152 Eina_Bool ge_update_view(ge_ugdata* ugd, int mode)
154 ge_dbg("mode: %d", mode);
156 int view_mode = _ge_get_view_mode();
157 ge_dbg("view_mode: %d", view_mode);
159 if (view_mode == GE_AlbumsView_Mode)
161 _ge_refresh_albums_list(ugd);
162 ge_albums_update_view(ugd);
164 else if (view_mode == GE_ThumbnailView_Mode)
166 _ge_refresh_albums_list(ugd);
167 if(_ge_get_current_album() == NULL)
169 ge_dbg("current album is empty, back to albums view!");
170 ge_albums_back_to_view(ugd);
171 elm_naviframe_item_pop(ugd->navi_bar);
176 ge_grid_update_view(ugd);
178 else if (view_mode == GE_ThumbnailEdit_Mode)
180 ge_cluster* cur_album = _ge_get_current_album();
183 if(mode == GE_UPDATE_MMC_REMOVED && cur_album &&
184 cur_album->cluster &&
185 cur_album->cluster->type == GE_MMC) {
186 ge_dbgW("MMC album, change to albums view!");
187 _ge_refresh_albums_list(ugd);
188 ge_albums_back_to_view(ugd);
189 elm_naviframe_item_pop(ugd->navi_bar);
193 /* Update albums list and items list */
194 _ge_refresh_albums_list(ugd);
195 if(_ge_data_get_count_all() <= 0) {
196 ge_dbgW("current album is empty, back to albums view!");
197 ge_albums_back_to_view(ugd);
198 elm_naviframe_item_pop(ugd->navi_bar);
202 ge_grid_update_view(ugd);
204 if(_ge_data_get_count_all() <= 0) {
205 ge_dbgW("current album is empty, back to albums view!");
206 ge_albums_back_to_view(ugd);
207 elm_naviframe_item_pop(ugd->navi_bar);
215 int ge_reg_db_update_noti(ge_ugdata* ugd)
218 GE_CHECK_VAL(ugd, -1);
221 error_code = vconf_notify_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS,
222 _ge_db_update_noti_cb, ugd);
224 ge_dbgE("vconf_notify_key_changed FAIL!");
229 int ge_dereg_db_update_noti(void)
234 error_code = vconf_ignore_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS,
235 _ge_db_update_noti_cb);
237 ge_dbgE("vconf_ignore_key_changed FAIL!");
242 bool _ge_is_image_valid(void *data, char *filepath)
244 GE_CHECK_FALSE(data);
245 ge_ugdata *ugd = (ge_ugdata *)data;
246 GE_CHECK_FALSE(filepath);
248 Evas_Object *image = NULL;
253 evas = evas_object_evas_get(ugd->win);
254 GE_CHECK_FALSE(evas);
256 image = evas_object_image_add(evas);
257 GE_CHECK_FALSE(image);
259 evas_object_image_filled_set(image, 0);
260 evas_object_image_load_scale_down_set(image, 0);
261 evas_object_image_file_set(image, filepath, NULL);
262 evas_object_image_size_get(image, &width, &height);
264 evas_object_del(image);
268 if (width <= 0 || height <= 0) {
269 ge_dbg("Cannot load file : %s", filepath);
276 /* Fetch thumbnail from media-service, if it's invalid, generate new one */
277 int _ge_get_thumb(const char *file_path, char **thumb_path)
279 GE_CHECK_VAL(thumb_path, -1);
280 GE_CHECK_VAL(file_path, -1);
281 /* Return if thumbnail is valid */
282 if (*thumb_path && ecore_file_exists(*thumb_path) &&
283 (ecore_file_size(*thumb_path) > 0)) {
287 /* Free allocated memory first */
289 ge_dbgW("Wrong thumb path[%s]", *thumb_path);
293 ge_dbg("File[%s]", file_path);
295 char *new_path = calloc(1, GE_FILE_PATH_LEN_MAX);
296 GE_CHECK_VAL(new_path, -1);
298 /* Generate thumbnail via thumbnail-service */
300 ret = thumbnail_request_from_db(file_path, new_path,
301 GE_FILE_PATH_LEN_MAX);
303 ge_dbgE("thumbnail_request_from_db failed!");
307 *thumb_path = new_path;
308 ge_dbg("Request thumbnail[%s]", new_path);
312 /* Change int to char * of video duration, caller need to free the allocated memory */
313 char *_ge_get_duration_string(unsigned int v_dur)
315 char *dur_str = calloc(1, GE_FILE_PATH_LEN_MAX);
316 GE_CHECK_NULL(dur_str);
318 int duration = floor(v_dur / GE_TIME_MSEC_PER_SEC);
324 if (duration >= GE_TIME_SEC_PER_HOUR) {
325 dur_sec = duration % GE_TIME_SEC_PER_MIN;
326 tmp = floor(duration / GE_TIME_SEC_PER_MIN);
327 dur_min = tmp % GE_TIME_MIN_PER_HOUR;
328 dur_hr = floor(tmp / GE_TIME_MIN_PER_HOUR);
329 } else if (duration >= GE_TIME_SEC_PER_MIN) {
331 dur_min = floor(duration / GE_TIME_SEC_PER_MIN);
332 dur_sec = duration % GE_TIME_SEC_PER_MIN;
336 dur_sec = duration % GE_TIME_SEC_PER_MIN;
339 snprintf(dur_str, GE_FILE_PATH_LEN_MAX, "%02d:%02d:%02d",
340 dur_hr, dur_min, dur_sec);
342 snprintf(dur_str, GE_FILE_PATH_LEN_MAX, "00:00:00");
344 dur_str[strlen(dur_str)] = '\0';