2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "ge-albums.h"
21 #include "ge-gridview.h"
22 #include "ge-db-handler.h"
24 #include "ge-ui-util.h"
26 #define GE_TIMER_INTERVAL_UMS_UPDATE 2.0
28 /* Global evas objects, which is used in the entire application */
30 static ge_item* ge_current_mb_item;
31 static ge_cluster* ge_current_album_item;
32 static int ge_ug_iv_enter = 0;
34 ge_item* _ge_get_current_item(void)
36 return ge_current_mb_item;
39 void _ge_set_current_item(ge_item* gitem)
41 ge_current_mb_item = gitem;
44 ge_cluster* _ge_get_current_album(void)
46 return ge_current_album_item;
49 void _ge_set_current_album(ge_cluster* album_item)
51 ge_current_album_item = album_item;
54 int _ge_ug_iv_get(void)
56 return ge_ug_iv_enter;
59 void _ge_ug_iv_set(int ug_iv_state)
61 ge_ug_iv_enter = ug_iv_state;
64 static int _ge_refresh_albums_list(ge_ugdata *ugd)
66 GE_CHECK_VAL(ugd, -1);
67 ge_cluster* old_cur_cluster = _ge_get_current_album();
68 char cluster_id[GE_MTYPE_ITEN_ID_LEN_MAX] = { 0, };
70 ge_cluster *current = NULL;
71 bool b_get_cur_album = false;
73 if(old_cur_cluster && old_cur_cluster->cluster &&
74 old_cur_cluster->cluster->uuid)
76 g_strlcpy(cluster_id, old_cur_cluster->cluster->uuid,
77 GE_MTYPE_ITEN_ID_LEN_MAX);
78 b_get_cur_album = true;
82 ge_dbg("None album selected, current album is unavailable\n");
84 ge_db_get_clusters_list(ugd);
86 GE_CHECK_VAL(ugd->cluster_list, -1);
87 int length = eina_list_count(ugd->cluster_list->clist);
88 ge_dbg("album length: %d, current album id: %s", length, cluster_id);
90 //need to reset current cluster
91 _ge_set_current_album(NULL);
94 for (i = 0; i < length; i++)
96 current = eina_list_nth(ugd->cluster_list->clist, i);
97 if(current && current->cluster &&
98 current->cluster->uuid) {
99 ge_dbg("current album : %s", current->cluster->display_name);
101 ge_dbgE("Current is NULL");
104 if(!g_strcmp0(current->cluster->uuid, cluster_id))
106 ge_db_update_items_list(ugd, current);
107 ugd->cluster_list->cur_pos = i;
108 _ge_set_current_album(current);
112 /* Current album was removed, clear items list */
113 if (ge_db_selected_list_get())
114 ge_db_selected_list_finalize();
115 ge_db_clear_items_list();
121 static void _ge_db_update_noti_cb(keynode_t *key, void* data)
123 ge_dbgW("VCONFKEY_FILEMANAGER_DB_STATUS changed!");
125 ge_ugdata* ugd = (ge_ugdata*)data;
127 int mode = GE_UPDATE_NONE;
129 vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmc_state);
130 if(mmc_state == -1) {
131 ge_dbgE("vconf_get_int failed!");
135 if (mmc_state == VCONFKEY_SYSMAN_MMC_MOUNTED) {
136 ge_dbg("mmc_state[%d]: VCONFKEY_SYSMAN_MMC_MOUNTED", mmc_state);
137 mode = GE_UPDATE_MMC_ADDED;
138 } else if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED ||
139 mmc_state == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
140 ge_dbg("mmc_state[%d]: VCONFKEY_SYSMAN_MMC_REMOVED", mmc_state);
141 mode = GE_UPDATE_MMC_REMOVED;
144 if (ugd->ums_update_timer) {
146 * MMC noti callback also would be invoked
147 * if USB disconnected in UMS mode,
148 * Return to prevent from refreshing view twice.
150 ge_dbgW("View would be update in _ge_ums_update_timer_cb.");
154 ge_update_view(ugd, mode);
157 static Eina_Bool _ge_ums_update_timer_cb(void *data)
159 ge_dbg("Timer callback invoked, try to update view.");
160 GE_CHECK_CANCEL(data);
161 ge_ugdata* ugd = (ge_ugdata*)data;
163 ge_update_view(ugd, GE_UPDATE_NORMAL);
165 GE_DEL_TIMER(ugd->ums_update_timer)
167 return ECORE_CALLBACK_CANCEL;
170 static void _ge_ums_noti_cb(keynode_t *key, void* data)
174 ge_ugdata* ugd = (ge_ugdata*)data;
178 vconf_get_int(VCONFKEY_USB_STORAGE_STATUS, &ums_mode);
179 if (ums_mode == -1) {
180 ge_dbgE("Error when check MASS STORAGE Status");
184 if (ums_mode == VCONFKEY_USB_STORAGE_STATUS_UMS_ON ||
185 ums_mode == VCONFKEY_USB_STORAGE_STATUS_UMS_MMC_ON) {
186 ge_dbg("VCONFKEY_USB_STORAGE_STATUS_UMS_ON");
187 /* Destroy UG if UMS on */
188 ugd->ug_exit_mode = GE_UG_EXIT_MASS_STORAGE;
189 ug_destroy_me(ugd->ug);
190 } else if (ums_mode == VCONFKEY_USB_STORAGE_STATUS_OFF) {
191 ge_dbg("VCONFKEY_USB_STORAGE_STATUS_OFF,update view in 2secs.");
193 * Update view in 2 seconds,
194 * media-server scan file system and insert records to DB,
195 * it takes some time.
197 ugd->ug_exit_mode = GE_UG_EXIT_NONE;
198 Ecore_Timer *ums_timer = NULL;
199 GE_DEL_TIMER(ugd->ums_update_timer)
200 ums_timer = ecore_timer_add(GE_TIMER_INTERVAL_UMS_UPDATE,
201 _ge_ums_update_timer_cb, data);
202 ugd->ums_update_timer = ums_timer;
206 Eina_Bool ge_update_view(ge_ugdata* ugd, int mode)
208 ge_dbg("mode: %d", mode);
210 int view_mode = _ge_get_view_mode();
211 ge_dbg("view_mode: %d", view_mode);
213 if (view_mode == GE_AlbumsView_Mode)
215 _ge_refresh_albums_list(ugd);
216 ge_albums_update_view(ugd);
218 else if (view_mode == GE_ThumbnailView_Mode)
220 _ge_refresh_albums_list(ugd);
221 if(_ge_get_current_album() == NULL)
223 ge_dbg("current album is empty, back to albums view!");
224 ge_albums_back_to_view(ugd);
225 elm_naviframe_item_pop(ugd->navi_bar);
230 ge_grid_update_view(ugd);
232 else if (view_mode == GE_ThumbnailEdit_Mode)
234 ge_cluster* cur_album = _ge_get_current_album();
237 if(mode == GE_UPDATE_MMC_REMOVED && cur_album &&
238 cur_album->cluster &&
239 cur_album->cluster->type == MINFO_MMC) {
240 ge_dbgW("MMC album, change to albums view!");
241 _ge_refresh_albums_list(ugd);
242 ge_albums_back_to_view(ugd);
243 elm_naviframe_item_pop(ugd->navi_bar);
247 /* Update albums list and items list */
248 _ge_refresh_albums_list(ugd);
249 if(ge_db_get_count_all() <= 0) {
250 ge_dbgW("current album is empty, back to albums view!");
251 ge_albums_back_to_view(ugd);
252 elm_naviframe_item_pop(ugd->navi_bar);
256 ge_grid_update_view(ugd);
258 if(ge_db_get_count_all() <= 0) {
259 ge_dbgW("current album is empty, back to albums view!");
260 ge_albums_back_to_view(ugd);
261 elm_naviframe_item_pop(ugd->navi_bar);
269 int ge_reg_db_update_noti(ge_ugdata* ugd)
272 GE_CHECK_VAL(ugd, -1);
275 error_code = vconf_notify_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS,
276 _ge_db_update_noti_cb, ugd);
278 ge_dbgE("vconf_notify_key_changed FAIL!");
283 int ge_dereg_db_update_noti(void)
288 error_code = vconf_ignore_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS,
289 _ge_db_update_noti_cb);
291 ge_dbgE("vconf_ignore_key_changed FAIL!");
296 int ge_reg_ums_noti(ge_ugdata* ugd)
298 GE_CHECK_VAL(ugd, -1);
301 error_code = vconf_notify_key_changed(VCONFKEY_USB_STORAGE_STATUS,
302 _ge_ums_noti_cb, ugd);
303 if(error_code == -1) {
304 ge_dbgE("vconf_notify_key_changed FAIL!");
310 int ge_dereg_ums_noti(void)
314 error_code = vconf_ignore_key_changed(VCONFKEY_USB_STORAGE_STATUS,
316 if (error_code == -1)
317 ge_dbgE("_gl_vconf_loaded_mass_storage_noti_cb FAIL!");
322 int ge_get_ums_state(ge_ugdata* ugd)
325 GE_CHECK_VAL(ugd, -1);
327 int exit_mode = GE_UG_EXIT_NONE;
329 if(!vconf_get_int(VCONFKEY_USB_STORAGE_STATUS, &ums_mode)) {
330 ge_dbg("UMS mode: %d.", ums_mode);
331 if(ums_mode == VCONFKEY_USB_STORAGE_STATUS_UMS_ON ||
332 ums_mode == VCONFKEY_USB_STORAGE_STATUS_UMS_MMC_ON) {
333 ge_dbgW("ums_mode[%d]: UMS_ON", ums_mode);
334 /* Usb mass storage mode activated */
335 exit_mode = GE_UG_EXIT_MASS_STORAGE;
339 ugd->ug_exit_mode = exit_mode;