[TIZEN_3.0 CODE REFACTOR] Removed hard code path 42/89842/1 submit/tizen_mobile/20160927.154357 submit/tizen_mobile/20160928.134357 submit/tizen_mobile/20160929.162502 submit/tizen_mobile/20160930.120656
authorRahul Dadhich <r.dadhich@samsung.com>
Tue, 27 Sep 2016 07:12:18 +0000 (12:42 +0530)
committerRahul Dadhich <r.dadhich@samsung.com>
Tue, 27 Sep 2016 07:12:18 +0000 (12:42 +0530)
Change-Id: I66308efd01d8095c20eb89e1a94412e5583df6ed
Signed-off-by: Rahul Dadhich <r.dadhich@samsung.com>
inc/ge-data-util.h
inc/ge-data.h
inc/ge-util.h
src/data/ge-data.c
src/data/ge-local-data.c
src/gallery-efl.c
src/util/ge-db-update.c
src/util/ge-util.c

index e893d29..aca1b71 100644 (file)
@@ -44,13 +44,8 @@ extern "C" {
 #define CONDITION_LENGTH 512
 #define KEYWORD_LENGTH 128
 
-#define GE_CAMERA_PATH_PHONE "/opt/usr/media/DCIM/Camera"
-#define GE_CAMERA_PATH_MMC "/opt/storage/sdcard/DCIM/Camera"
-#define GE_DOWNLOADS_PATH "/opt/usr/media/Downloads"
-
 #define GE_ROOT_PATH_PHONE     "/opt/usr/media"
 #define GE_ROOT_PATH_MMC       "/opt/storage/sdcard"
-#define GE_DCIM "DCIM"
 
 #define GE_ALBUM_ALL_ID "GALLERY_ALBUM_ALL_ALBUMS_ID"
 
index 8d1e1b6..8b80ef4 100644 (file)
@@ -79,6 +79,7 @@ int _ge_data_finalize(ge_ugdata* ugd);
 int _ge_data_remove_sel_album(ge_ugdata *ugd, ge_sel_album_s *salbum);
 void _ge_data_get_sel_item(ge_ugdata *ugd, Eina_List **list);
 int _ge_data_get_items(int start_pos, int end_pos, Eina_List **list, ge_ugdata *ugd);
+bool _ge_data_check_root_type(const char *path, const char *root);
 
 #ifdef _cplusplus
 }
index 6cb7647..5cd03bf 100644 (file)
@@ -21,6 +21,7 @@
 #include "gallery-efl.h"
 #include "ge-icon.h"
 #include "ge-file-util.h"
+#include <storage/storage.h>
 
 #define GE_FILE_EXISTS(path) \
        (path && (1 == ge_file_exists(path)) && (ge_file_size(path) > 0))
@@ -41,5 +42,13 @@ int _ge_send_result(ge_ugdata *ugd);
 int _ge_atoi(const char *number);
 char *_ge_str(char *str_id);
 char *_ge_get_edje_path(void);
+int get_external_storage_id(void);
+int get_internal_storage_id(void);
+char * _ge_get_camera_folder_path_internal(void);
+char * _ge_get_camera_folder_path_external(void);
+char *_ge_get_downloads_folder_path(void);
+char *_ge_get_root_folder_path_internal(void);
+char *_ge_get_root_folder_path_external(void);
+
 #endif //_GE_UTIL_H_
 
index ccd55ac..1d72e40 100644 (file)
@@ -359,6 +359,7 @@ int _ge_data_get_clusters(ge_ugdata *ugd, int type)
        int all_local_cnt = 0;
        Eina_List *list = NULL;
        ge_album_s *album = NULL;
+       ge_cluster *default_album = NULL;
        ge_album_s *camera_album = NULL;
        ge_album_s *downloads_album = NULL;
        ge_cluster *camera_cluster = NULL;
@@ -393,33 +394,17 @@ int _ge_data_get_clusters(ge_ugdata *ugd, int type)
        }
        GE_CHECK_VAL(ugd->cluster_list, -1);
 
-GE_DATA_AGAIN:
+       GE_DATA_AGAIN:
 
        /* Get local albums for first time and local albums is more than 9 */
        if (type == GE_ALBUM_DATA_NONE || type == GE_ALBUM_DATA_LOCAL) {
                /* Get real albums */
                memset(&filter, 0x00, sizeof(ge_filter_s));
                g_strlcpy(filter.cond, GE_CONDITION_IMAGE_VIDEO,
-                         CONDITION_LENGTH);
+                               CONDITION_LENGTH);
                filter.collate_type = MEDIA_CONTENT_COLLATE_NOCASE;
                filter.sort_type = MEDIA_CONTENT_ORDER_ASC;
                g_strlcpy(filter.sort_keyword, FOLDER_NAME, KEYWORD_LENGTH);
-               _ge_local_data_get_album_by_path(GE_CAMERA_PATH_PHONE,
-                                                &camera_album);
-               if (camera_album) {
-                       list = eina_list_append(list, camera_album);
-               }
-               camera_album = NULL;
-               _ge_local_data_get_album_by_path(GE_CAMERA_PATH_MMC,
-                                                &camera_album);
-               if (camera_album) {
-                       list = eina_list_append(list, camera_album);
-               }
-               _ge_local_data_get_album_by_path(GE_DOWNLOADS_PATH,
-                                                &downloads_album);
-               if (downloads_album) {
-                       list = eina_list_append(list, downloads_album);
-               }
                if (type == GE_ALBUM_DATA_NONE) {
 
                        filter.count = GE_ALBUMS_FIRST_COUNT;
@@ -441,16 +426,16 @@ GE_DATA_AGAIN:
                        memset(&filter, 0x00, sizeof(ge_filter_s));
                        if (ugd->file_type_mode == GE_FILE_T_IMAGE)
                                g_strlcpy(filter.cond, GE_CONDITION_IMAGE,
-                                         CONDITION_LENGTH);
+                                               CONDITION_LENGTH);
                        else if (ugd->file_type_mode == GE_FILE_T_VIDEO)
                                g_strlcpy(filter.cond, GE_CONDITION_VIDEO,
-                                         CONDITION_LENGTH);
+                                               CONDITION_LENGTH);
                        else
                                g_strlcpy(filter.cond, GE_CONDITION_IMAGE_VIDEO,
-                                         CONDITION_LENGTH);
+                                               CONDITION_LENGTH);
                        filter.sort_type = MEDIA_CONTENT_ORDER_DESC;
                        g_strlcpy(filter.sort_keyword, MEDIA_DISPLAY_NAME,
-                                 KEYWORD_LENGTH);
+                                       KEYWORD_LENGTH);
                        filter.offset = GE_GET_ALL_RECORDS;
                        filter.count = GE_GET_ALL_RECORDS;
                        filter.with_meta = false;
@@ -478,11 +463,11 @@ GE_DATA_AGAIN:
                        ge_dbgE("Invalid ge_album_s!");
                        continue;
                }
-               ge_sdbg("Cluster ID: %s.", album->uuid);
+               ge_sdbg("Cluster name : %s.", album->display_name);
 
                err = _ge_local_data_get_media_count(album->uuid,
-                                                    &filter,
-                                                    &medias_cnt);
+                               &filter,
+                               &medias_cnt);
                if (err == 0 && medias_cnt > 0) {
                        album->count = medias_cnt;
                        all_local_cnt += medias_cnt;
@@ -501,12 +486,43 @@ GE_DATA_AGAIN:
                gcluster->cluster = album;
                gcluster->ugd = ugd;
                length += album->count;
-
-               clist = eina_list_append(clist, gcluster);
-               if (type == GE_ALBUM_DATA_NONE) {
-                       if (_ge_data_is_camera_album(album)) {
-                               camera_cluster = gcluster;
+               if (_ge_data_is_camera_album(album)) {
+                       camera_cluster = gcluster;
+                       /**
+                        * Default album: Camera
+                        * Now Camera Shot is located in Phone/MMC.
+                        * If user can determine the location of default album,
+                        * here we should get the path and check it's in Phone or MMC.
+                        */
+                       if (default_album) {
+                               /* album 'Camera' is in phone, set it before MMC album 'Camera' */
+                               char *phone_root_path = _ge_get_root_folder_path_internal();
+                               if (phone_root_path && _ge_data_check_root_type(album->path, phone_root_path)) {
+                                       clist = eina_list_prepend(clist,
+                                                       gcluster);
+                               } else {
+                                       clist = eina_list_append_relative(clist,
+                                                       gcluster,
+                                                       default_album);
+                                       default_album = gcluster;
+                               }
+                               GE_FREEIF(phone_root_path);
+                       } else {
+                               default_album = gcluster;
+                               clist = eina_list_prepend(clist,
+                                               gcluster);
                        }
+               } else if (_ge_data_is_default_album(GE_ALBUM_DOWNLOADS_NAME, album)) {
+                       if (default_album)
+                               clist = eina_list_append_relative(clist,
+                                               gcluster,
+                                               default_album);
+                       else
+                               clist = eina_list_prepend(clist,
+                                               gcluster);
+               } else {
+                       clist = eina_list_append(clist,
+                                       gcluster);
                }
                ugd->cluster_list->clist = clist;
        }
@@ -518,7 +534,7 @@ GE_DATA_AGAIN:
 
                if (camera_cluster) {
                        clist = eina_list_append_relative(clist, gcluster,
-                                                         camera_cluster);
+                                       camera_cluster);
                } else {
                        clist = eina_list_prepend(clist, gcluster);
                }
@@ -876,8 +892,13 @@ bool _ge_data_is_default_album(const char *match_folder, ge_album_s *album)
                ge_dbg("Parent path: %s", parent_path);
 
                /* Parent directory is same as Phone root path, it's default folder */
-               ret = g_strcmp0(parent_path, GE_ROOT_PATH_PHONE);
+               char *path = _ge_get_root_folder_path_internal();
+               if (!path) {
+                       return false;
+               }
+               ret = g_strcmp0(parent_path, path);
                GE_FREE(parent_path);
+               GE_FREE(path);
 
                if (ret == 0) {
                        ge_dbgW("Default folder!");
@@ -900,39 +921,38 @@ bool _ge_data_is_camera_album(ge_album_s *mcluster)
        if (!g_strcmp0(mcluster->display_name, GE_ALBUM_CAMERA_NAME)) {
                const char *root = NULL;
                if (mcluster->type == GE_PHONE) {
-                       root = GE_ROOT_PATH_PHONE;
+                       char * path = _ge_get_camera_folder_path_internal();
                } else {
-                       root = GE_ROOT_PATH_MMC;
+                       char * path = _ge_get_camera_folder_path_external();
                }
-
                ge_dbg("Full path: %s", mcluster->path);
                char *parent_path = ge_file_dir_get(mcluster->path);
                GE_CHECK_FALSE(parent_path);
                ge_dbg("Parent path: %s.", parent_path);
-
-               char *dcim_path = g_strdup_printf("%s/%s", root, GE_DCIM);
-               if (dcim_path == NULL) {
-                       GE_GFREE(parent_path);
-                       return false;
-               }
                /* And parent folder is Phone root path, it's default folder */
                bool ret = false;
-               ret = !g_strcmp0(dcim_path, parent_path);
-
-               GE_GFREE(dcim_path);
-               GE_GFREE(parent_path);
-               return ret;
+               if (!g_strcmp0(root, mcluster->path)) {
+                       GE_GFREE(parent_path);
+                       GE_FREEIF(root);
+                       return true;
+               }
        }
-
        return false;
 }
 
 bool _ge_data_is_root_path(const char *path)
 {
        GE_CHECK_FALSE(path);
-
-       if (!g_strcmp0(GE_ROOT_PATH_PHONE, path) ||
-               !g_strcmp0(GE_ROOT_PATH_MMC, path)) {
+       char *path_internal= NULL;
+       char *path_external= NULL;
+       if(get_internal_storage_id() != -1) {
+               storage_get_root_directory(get_internal_storage_id(), &path_internal);
+       }
+       if (get_external_storage_id() != -1) {
+               storage_get_root_directory(get_external_storage_id(), &path_external);
+       }
+       if ((path_internal && !g_strcmp0(path_internal, path)) ||
+                       (path_external && !g_strcmp0(path_external, path))) {
                ge_dbg("Root path: %s", path);
                return true;
        }
@@ -1047,3 +1067,17 @@ int _ge_data_get_items(int start_pos, int end_pos, Eina_List **list, ge_ugdata *
        ge_dbg("Error code: %d", err);
        return err;
 }
+
+bool _ge_data_check_root_type(const char *path, const char *root)
+{
+       if (path == NULL || root == NULL) {
+               return false;
+       }
+
+       if (!strncmp(root, path, strlen(root))) {
+               ge_sdbg("Root path: %s", path);
+               return true;
+       }
+
+       return false;
+}
index e5d78a2..f10024d 100644 (file)
@@ -99,16 +99,6 @@ static bool __ge_local_data_get_album_list_cb(media_folder_h folder,
        }
        GE_CHECK_FALSE(path);
 
-       if (tmp_data->list_type != GE_ALBUM_LIST_PATH) {
-               if (!g_strcmp0(GE_CAMERA_PATH_PHONE, path) ||
-                       !g_strcmp0(GE_CAMERA_PATH_MMC, path) ||
-                       !g_strcmp0(GE_DOWNLOADS_PATH, path)) {
-                       ge_dbgW("Camera or Downloads!");
-                       GE_FREE(path);
-                       return true;
-               }
-       }
-
        __ge_local_data_clone_album(folder, false, &album);
        if (album == NULL) {
                GE_FREE(path);
index 3b7fdda..cc291eb 100644 (file)
@@ -118,14 +118,6 @@ static int _ge_create_view(ge_ugdata *ugd)
                ge_dbgE("view is intialized !!!!!!!!!!!!!");
        }
 
-       /* Register MMC changed callback */
-       if (ge_reg_db_update_noti(ugd) != 0) {
-               ge_dbgE("reg_db_update_noti failed!");
-               return -1;
-       } else {
-               ge_dbgE("reg_db is updated storage state change");
-       }
-
        return 0;
 }
 
@@ -409,6 +401,13 @@ static bool _ge_create(void *priv)
        snprintf(locale, 1024, "%s%s", path, "locale");
        bindtextdomain("ug-gallery-efl" , locale);
        free(path);
+       /* Register MMC changed callback */
+       if (ge_reg_db_update_noti(ugd) != 0) {
+               ge_dbgE("reg_db_update_noti failed!");
+               return -1;
+       } else {
+               ge_dbgE("reg_db is updated storage state change");
+       }
        /* Reset inited flag, it would be set as TRUE if albums view created */
        _ge_ui_get_indicator_state(ugd);
        /* Add window rotation callback to rotate view as fast as possible */
index d6a7e54..f402968 100644 (file)
@@ -107,10 +107,12 @@ static int __ge_db_update_op(media_content_error_e error, int pid,
                ge_dbg("old: %d, new: %d", db_noti->count, cnt);
                if (cnt == db_noti->count) {
                        ge_dbg("Nothing changed");
-                       if (path &&
-                               !strcmp(path, GE_ROOT_PATH_MMC)) {
+                       char * sd_root_path = _ge_get_root_folder_path_external();
+                       if (sd_root_path && path &&
+                               !strcmp(path, sd_root_path)) {
                                ge_dbg("MMC insert or remove!");
                        } else if (path) {
+                               GE_FREEIF(sd_root_path);
                                ge_album_s *album = NULL;
                                _ge_local_data_get_album_by_path(path, &album);
                                if (!album) {
@@ -120,8 +122,10 @@ static int __ge_db_update_op(media_content_error_e error, int pid,
                                        ge_dbgW("Updated album contains images");
                                }
                        } else {
+                               GE_FREEIF(sd_root_path);
                                return -1;
                        }
+                       GE_FREEIF(sd_root_path);
                } else {
                        db_noti->count = cnt;
                }
index 2b7ec91..9857c52 100644 (file)
@@ -37,7 +37,8 @@
 
 #define GE_PERIOD_LIVEBOX 30.0
 
-static int __externalStorageId = 0;
+static int __externalStorageId = -1;
+static int __internalStorageId = 0;
 
 bool getSupportedStorages_cb(int storageId, storage_type_e type, storage_state_e state, const char *path, void *userData)
 {
@@ -46,6 +47,9 @@ bool getSupportedStorages_cb(int storageId, storage_type_e type, storage_state_e
        if (type == STORAGE_TYPE_EXTERNAL) {
                __externalStorageId = storageId;
                return false;
+       } else if (type == STORAGE_TYPE_INTERNAL) {
+               __internalStorageId = storageId;
+               return false;
        }
 
        return true;
@@ -380,3 +384,81 @@ char *_ge_get_edje_path(void)
        return path;
 }
 
+int get_external_storage_id(void)
+{
+       return __externalStorageId;
+}
+
+int get_internal_storage_id(void)
+{
+       return __internalStorageId;
+}
+
+static char *__ge_get_folder_path(int storage_id, int directory)
+{
+       char *path = NULL;
+               if (storage_id != -1) {
+                       char *path_camera = NULL;
+                       storage_get_directory(storage_id, directory, &path_camera);
+                       if (path_camera) {
+                               path = strdup(path_camera);
+                               GE_FREEIF(path_camera);
+                       } else {
+                               path = strdup("");
+                       }
+               } else {
+                       path = strdup("");
+               }
+               return path;
+}
+
+char * _ge_get_camera_folder_path_internal(void)
+{
+       return __ge_get_folder_path(__internalStorageId, STORAGE_DIRECTORY_CAMERA);
+}
+
+char * _ge_get_camera_folder_path_external(void)
+{
+       return __ge_get_folder_path(__externalStorageId, STORAGE_DIRECTORY_CAMERA);
+}
+
+char *_ge_get_downloads_folder_path(void)
+{
+       return __ge_get_folder_path(__internalStorageId, STORAGE_DIRECTORY_DOWNLOADS);
+}
+
+char * _ge_get_root_folder_path_internal(void)
+{
+       char *path = NULL;
+       if (get_internal_storage_id() != -1) {
+               char *path_root = NULL;
+               storage_get_root_directory(get_external_storage_id(), &path_root);
+               if (path_root) {
+                       path = strdup(path_root);
+                       GE_FREEIF(path_root);
+               }  else {
+                       path = strdup(GE_ROOT_PATH_PHONE);
+               }
+       } else {
+               path = strdup(GE_ROOT_PATH_PHONE);
+       }
+       return path;
+}
+
+char * _ge_get_root_folder_path_external(void)
+{
+       char *path = NULL;
+       if (get_external_storage_id() != -1) {
+               char *path_root = NULL;
+               storage_get_root_directory(get_external_storage_id(), &path_root);
+               if (path_root) {
+                       path = strdup(path_root);
+                       GE_FREEIF(path_root);
+               } else {
+                       path = strdup(GE_ROOT_PATH_MMC);
+               }
+       } else {
+               path = strdup(GE_ROOT_PATH_MMC);
+       }
+       return path;
+}