use relative directories path instead of hardcoded ones. 69/57769/2
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 21 Jan 2016 15:40:49 +0000 (16:40 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Mon, 25 Jan 2016 09:18:42 +0000 (10:18 +0100)
In Tizen 3.0 application packages can be installed per user.
It means that application working directory must be discovered on runtime
instead of using fixed paths. Patch introduces new functions for getting
absoulte path to resource directories using Tizen app framework api.

Change-Id: I53661a413791eeacb24f57584dc2ca54a8f10ab2
Signed-off-by: Lukasz Stanislawski <l.stanislaws@samsung.com>
inc/conf.h
inc/util.h
src/app_grid.c
src/app_icon.c
src/db/db.c
src/dynamic_index.c
src/folder_panel.c
src/homescreen-efl.c
src/livebox/livebox_panel.c
src/livebox_all_pages.c
src/util.c

index f813b0c..7347aab 100644 (file)
 
 /*=================================DATABASE===================================*/
 #define DATABASE_FILE \
-       "/usr/apps/org.tizen.homescreen-efl/data/homescreen-efl.db"
+       "homescreen-efl.db"
 
 /*=================================RESOURCES==================================*/
-#define DEFAULT_BG \
-       "/usr/apps/com.samsung.home-lite/res/images/default_bg.png"
-#define EDJE_DIR "/usr/apps/org.tizen.homescreen-efl/res/edje"
-#define IMAGE_DIR "/usr/apps/org.tizen.homescreen-efl/res/images"
+#define EDJE_DIR "edje"
+#define IMAGE_DIR "images"
 
 /*******************************************************************************
 *
@@ -87,7 +85,7 @@
 
 /*================================ APP_ICON.C=================================*/
 #define DEFAULT_APP_ICON  \
-       "/usr/apps/org.tizen.homescreen-efl/res/images/default.png"
+       IMAGE_DIR "/default.png"
 
 #define BADGE_REL_X 0.85
 #define BADGE_REL_Y 0.00
index 24c8f82..bc03473 100644 (file)
@@ -72,4 +72,42 @@ extern Eina_List *elm_gengrid_get_evas_objects_from_items(Evas_Object *gengrid);
  */
 Elm_Object_Item *elm_gengrid_get_item_at_index(Evas_Object *gengrid, int idx);
 
+/*
+ * @brief Application sub-directories type.
+ */
+enum app_subdir {
+       APP_DIR_DATA,
+       APP_DIR_CACHE,
+       APP_DIR_RESOURCE,
+       APP_DIR_SHARED_DATA,
+       APP_DIR_SHARED_RESOURCE,
+       APP_DIR_SHARED_TRUSTED,
+       APP_DIR_EXTERNAL_DATA,
+       APP_DIR_EXTERNAL_CACHE,
+       APP_DIR_EXTERNAL_SHARED_DATA,
+};
+
+/**
+ * @brief Returns absolute path to resource file located in applications directory.
+ *
+ * @param subdir type of subdirectory
+ * @param relative path of resource from starting from "data" dir.
+ *        eg. for DATA_DIR subdir and relative "database.db" => "/home/owner/apps/org.tizen.homescreen-efl/data/database.db"
+ * @return absolute path string.
+ */
+const char *util_get_file_path(enum app_subdir dir, const char *relative);
+
+/**
+ * @brief Convinience macros
+ */
+#define util_get_data_file_path(x) util_get_file_path(APP_DIR_DATA, (x))
+#define util_get_cache_file_path(x) util_get_file_path(APP_DIR_CACHE, (x))
+#define util_get_res_file_path(x) util_get_file_path(APP_DIR_RESOURCE, (x))
+#define util_get_shared_data_file_path(x) util_get_file_path(APP_DIR_SHARED_DATA, (x))
+#define util_get_shared_res_file_path(x) util_get_file_path(APP_DIR_SHARED_RESOURCE, (x))
+#define util_get_trusted_file_path(x) util_get_file_path(APP_DIR_SHARED_TRUSTED, (x))
+#define util_get_external_data_file_path(x) util_get_file_path(APP_DIR_EXTERNAL_DATA, (x))
+#define util_get_external_cache_file_path(x) util_get_file_path(APP_DIR_EXTERNAL_CACHE, (x))
+#define util_get_external_shared_data_file_path(x) util_get_file_path(APP_DIR_EXTERNAL_SHARED_DATA, (x))
+
 #endif /* __HOME_SCREEN_UTIL_H__ */
index bbd72df..c28456a 100644 (file)
@@ -588,8 +588,8 @@ static Evas_Object *__app_grid_create_ly(Evas_Object *parent)
                return NULL;
        }
 
-       if (!elm_layout_file_set(ly, EDJE_DIR"/app_grid.edj", GROUP_APP_GRID)) {
-               LOGE("[FAILED][elm_layout_file_set][%s]", EDJE_DIR"/app_grid.edj");
+       if (!elm_layout_file_set(ly, util_get_res_file_path(EDJE_DIR"/app_grid.edj)"), GROUP_APP_GRID)) {
+               LOGE("[FAILED][elm_layout_file_set][%s]", util_get_res_file_path(EDJE_DIR"/app_grid.edj"));
                evas_object_del(ly);
                return NULL;
        }
@@ -782,8 +782,8 @@ static Evas_Object *__app_grid_create_item_container(Evas_Object *parent)
 
        container = elm_layout_add(parent);
 
-       if (!elm_layout_file_set(container, EDJE_DIR"/app_grid.edj", GROUP_APP_GRID_ITEM_CONTAINER)) {
-               LOGE("[FAILED][elm_layout_file_set][%s]", EDJE_DIR"/app_grid.edj");
+       if (!elm_layout_file_set(container, util_get_res_file_path(EDJE_DIR"/app_grid.edj"), GROUP_APP_GRID_ITEM_CONTAINER)) {
+               LOGE("[FAILED][elm_layout_file_set][%s]", util_get_res_file_path(EDJE_DIR"/app_grid.edj"));
                evas_object_del(container);
                return NULL;
        }
index 1596ae9..e6583e9 100644 (file)
@@ -81,7 +81,7 @@ HAPI Evas_Object *app_icon_create(Tree_node_t *tree_data, app_icon_type_t type)
        }
 
        if (type == APP_ICON_TYPE_APP || type == APP_ICON_TYPE_FOLDER) {
-               icon_layout = util_create_edje_layout(parent, EDJE_DIR"/icon.edj", GROUP_ICON_LY);
+               icon_layout = util_create_edje_layout(parent, util_get_res_file_path(EDJE_DIR"/icon.edj"), GROUP_ICON_LY);
                if (!icon_layout) {
                        LOGE("Failed to create icon layout");
                        return NULL;
@@ -118,7 +118,7 @@ HAPI Evas_Object *app_icon_create(Tree_node_t *tree_data, app_icon_type_t type)
                        return NULL;
                }
 
-               if (!elm_layout_file_set(folder_icon_layout, EDJE_DIR"/folder.edj", GROUP_FOLDER_ICON_LAYOUT)) {
+               if (!elm_layout_file_set(folder_icon_layout, util_get_res_file_path(EDJE_DIR"/folder.edj"), GROUP_FOLDER_ICON_LAYOUT)) {
                        LOGE("Failed to load edje file for layout");
                        evas_object_del(folder_icon_layout);
                        evas_object_del(icon_layout);
@@ -578,7 +578,7 @@ Evas_Object *__app_icon_load(Evas_Object *parent, const char *icon_path)
                return NULL;
        }
 
-       if ((strncmp("", icon_path, strlen(icon_path)) && elm_image_file_set(icon_image, icon_path, NULL)) || elm_image_file_set(icon_image, DEFAULT_APP_ICON, NULL))
+       if ((strncmp("", icon_path, strlen(icon_path)) && elm_image_file_set(icon_image, icon_path, NULL)) || elm_image_file_set(icon_image, util_get_res_file_path(DEFAULT_APP_ICON), NULL))
                return icon_image;
 
        evas_object_del(icon_image);
index 5c137d2..0503aca 100644 (file)
@@ -274,7 +274,7 @@ bool _db_open(void)
        if (db_info.db)
                return true;
 
-       if (!_db_is_success(sqlite3_open(DATABASE_FILE, &db_info.db)))
+       if (!_db_is_success(sqlite3_open(util_get_data_file_path(DATABASE_FILE), &db_info.db)))
                return false;
 
        if (sqlite3_exec(db_info.db, "BEGIN IMMEDIATE TRANSACTION", NULL,
index 37cc2f7..cd6712c 100644 (file)
@@ -145,7 +145,7 @@ static Evas_Object *__dynamic_index_create_indice(Evas_Object *box)
                return NULL;
        }
 
-       if (!elm_layout_file_set(layout, INDEX_EDJE, GROUP_INDEX_ELEMENT)) {
+       if (!elm_layout_file_set(layout, util_get_res_file_path(INDEX_EDJE), GROUP_INDEX_ELEMENT)) {
                evas_object_del(layout);
                return NULL;
        }
index a516f43..3f6aa73 100644 (file)
@@ -96,7 +96,7 @@ HAPI void folder_panel_init_module(void)
                }
 
                elm_theme_ref_set(s_info.folder_entry_theme, NULL);
-               elm_theme_extension_add(s_info.folder_entry_theme, EDJE_DIR"/folder_entry.edj");
+               elm_theme_extension_add(s_info.folder_entry_theme, util_get_res_file_path(EDJE_DIR"/folder_entry.edj"));
        }
 }
 
@@ -409,7 +409,7 @@ static bool __folder_panel_create_layout(Evas_Object *parent, app_item_t *folder
                return false;
        }
 
-       if (!elm_layout_file_set(s_info.opened_folder_window, EDJE_DIR"/folder.edj", GROUP_FOLDER_WINDOW)) {
+       if (!elm_layout_file_set(s_info.opened_folder_window, util_get_res_file_path(EDJE_DIR"/folder.edj"), GROUP_FOLDER_WINDOW)) {
                LOGE("Failed to load edje file for layout");
                evas_object_del(s_info.opened_folder_window);
                s_info.opened_folder_window = NULL;
@@ -607,7 +607,7 @@ static Evas_Object* __folder_panel_create_add_icon(app_item_t *folder)
        Evas_Object *add_icon = NULL;
        LOGI("");
 
-       icon_layout = util_create_edje_layout(home_screen_get_win(), EDJE_DIR"/icon.edj", GROUP_ICON_LY);
+       icon_layout = util_create_edje_layout(home_screen_get_win(), util_get_res_file_path(EDJE_DIR"/icon.edj"), GROUP_ICON_LY);
        if (!icon_layout) {
                LOGE("Failed to create icon layout");
                return NULL;
@@ -620,7 +620,7 @@ static Evas_Object* __folder_panel_create_add_icon(app_item_t *folder)
                return NULL;
        }
 
-       if (!elm_layout_file_set(add_icon, EDJE_DIR"/folder.edj", GROUP_FOLDER_ADD_ICON)) {
+       if (!elm_layout_file_set(add_icon, util_get_res_file_path(EDJE_DIR"/folder.edj"), GROUP_FOLDER_ADD_ICON)) {
                LOGE("Failed to load edje file for layout");
                evas_object_del(add_icon);
                evas_object_del(icon_layout);
@@ -661,7 +661,7 @@ static Evas_Object *__folder_panel_create_popup(Evas_Object *parent, app_item_t
                return NULL;
        }
 
-       if (!elm_layout_file_set(folder_popup, EDJE_DIR"/folder.edj", GROUP_FOLDER_POPUP)) {
+       if (!elm_layout_file_set(folder_popup, util_get_res_file_path(EDJE_DIR"/folder.edj"), GROUP_FOLDER_POPUP)) {
                LOGE("Failed to set folder popup");
                evas_object_del(folder_popup);
                return NULL;
index 89cd777..31c39c0 100644 (file)
@@ -311,7 +311,7 @@ static Evas_Object *_create_conformant(void)
 static void __homescreen_efl_create_base_gui(void)
 {
        char edj_path[PATH_MAX] = {0, };
-       const char *bg_path = IMAGE_DIR"/default_bg.png";
+       const char *bg_path = util_get_res_file_path(IMAGE_DIR"/default_bg.png");
        char trbuf[PATH_MAX] = {0, };
        char *buf = NULL;
        int ret = -1;
@@ -345,7 +345,7 @@ static void __homescreen_efl_create_base_gui(void)
        // s_info.conformant = _create_conformant();
 
        // /* Base Layout */
-       snprintf(edj_path, sizeof(edj_path), EDJE_DIR"/home.edj");
+       snprintf(edj_path, sizeof(edj_path), "%s", util_get_res_file_path(EDJE_DIR"/home.edj"));
        s_info.layout = elm_layout_add(s_info.win);
        elm_layout_file_set(s_info.layout, edj_path, GROUP_HOME_LY);
        evas_object_size_hint_weight_set(s_info.layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
index cb59dc9..901daff 100644 (file)
@@ -941,8 +941,9 @@ static Evas_Object *__livebox_panel_create_page(Evas_Object *livebox_scroller)
 {
        Evas_Object *grid = NULL;
        Evas_Object *rect = NULL;
+
        Evas_Object *livebox_container = util_create_edje_layout(
-               livebox_scroller, EDJE_LIVEBOX_CONTAINER_FILENAME,
+               livebox_scroller, util_get_res_file_path(EDJE_LIVEBOX_CONTAINER_FILENAME),
                GROUP_LIVEBOX_CONTAINER);
 
        if (!livebox_container) {
index bb6bfee..68468bb 100644 (file)
@@ -122,7 +122,7 @@ HAPI Evas_Object *livebox_all_pages_show(void)
                return NULL;
        }
 
-       all_pages_layout = util_create_edje_layout(win, EDJE_DIR"/page_edit.edj", GROUP_ALL_PAGES);
+       all_pages_layout = util_create_edje_layout(win, util_get_res_file_path(EDJE_DIR"/page_edit.edj"), GROUP_ALL_PAGES);
        if (!all_pages_layout) {
                LOGE("[FAILED][util_edje_layout_create]");
                return NULL;
@@ -555,13 +555,13 @@ static Evas_Object *__livebox_all_pages_create_thumb(Evas_Object *page, bool is_
        w = THUMB_W_REL * w;
        h = THUMB_H_REL * h;
 
-       ly_grid_item = util_create_edje_layout(win, EDJE_DIR"/page_edit.edj", GROUP_GRID_ITEM);
+       ly_grid_item = util_create_edje_layout(win, util_get_res_file_path(EDJE_DIR"/page_edit.edj"), GROUP_GRID_ITEM);
        if (!ly_grid_item) {
                LOGE("[FAILED][util_edje_layout_create]");
                return NULL;
        }
 
-       ly_thumb = util_create_edje_layout(win, EDJE_DIR"/page_edit.edj", GROUP_THUMB);
+       ly_thumb = util_create_edje_layout(win, util_get_res_file_path(EDJE_DIR"/page_edit.edj"), GROUP_THUMB);
        if (!ly_thumb) {
                LOGE("[FAILED][util_edje_layout_create]");
                evas_object_del(ly_grid_item);
@@ -647,14 +647,14 @@ static Evas_Object *__livebox_all_pages_create_add_icon_layout(void)
        }
        evas_object_color_set(add_icon, 0, 0, 0, 0);
 
-       ly_grid_item = util_create_edje_layout(win, EDJE_DIR"/page_edit.edj", GROUP_GRID_ITEM);
+       ly_grid_item = util_create_edje_layout(win, util_get_res_file_path(EDJE_DIR"/page_edit.edj"), GROUP_GRID_ITEM);
        if (!ly_grid_item) {
                LOGE("[FAILED][util_edje_layout_create]");
                evas_object_del(add_icon);
                return NULL;
        }
 
-       ly_thumb = util_create_edje_layout(win, EDJE_DIR"/page_edit.edj", GROUP_THUMB);
+       ly_thumb = util_create_edje_layout(win, util_get_res_file_path(EDJE_DIR"/page_edit.edj"), GROUP_THUMB);
        if (!ly_thumb) {
                LOGE("[FAILED][util_edje_layout_create]");
                evas_object_del(add_icon);
index 37dcfad..c63a21c 100644 (file)
@@ -162,3 +162,50 @@ HAPI Elm_Object_Item *elm_gengrid_get_item_at_index(Evas_Object *gengrid, int id
 
        return found;
 }
+
+const char *util_get_file_path(enum app_subdir dir, const char *relative)
+{
+       static char buf[PATH_MAX];
+       char *prefix;
+
+       switch (dir) {
+       case APP_DIR_DATA:
+               prefix = app_get_data_path();
+               break;
+       case APP_DIR_CACHE:
+               prefix = app_get_cache_path();
+               break;
+       case APP_DIR_RESOURCE:
+               prefix = app_get_resource_path();
+               break;
+       case APP_DIR_SHARED_DATA:
+               prefix = app_get_shared_data_path();
+               break;
+       case APP_DIR_SHARED_RESOURCE:
+               prefix = app_get_shared_resource_path();
+               break;
+       case APP_DIR_SHARED_TRUSTED:
+               prefix = app_get_shared_trusted_path();
+               break;
+       case APP_DIR_EXTERNAL_DATA:
+               prefix = app_get_external_data_path();
+               break;
+       case APP_DIR_EXTERNAL_CACHE:
+               prefix = app_get_external_cache_path();
+               break;
+       case APP_DIR_EXTERNAL_SHARED_DATA:
+               prefix = app_get_external_shared_data_path();
+               break;
+       default:
+               LOGE("Not handled directory type.");
+               return NULL;
+       }
+       size_t res = eina_file_path_join(buf, sizeof(buf), prefix, relative);
+       free(prefix);
+       if (res > sizeof(buf)) {
+               LOGE("Path exceeded PATH_MAX");
+               return NULL;
+       }
+
+       return &buf[0];
+}