Modify logic to set Home screen wallpaper.
[apps/native/menu-screen.git] / src / menu_screen.c
old mode 100755 (executable)
new mode 100644 (file)
index 6da58bd..66765d8
@@ -20,9 +20,7 @@
  *
  */
 
-#include <ail.h>
 #include <app.h>
-#include <appcore-efl.h>
 #include <aul.h>
 #include <Elementary.h>
 #include <stdbool.h>
@@ -30,7 +28,7 @@
 #include <vconf.h>
 #include <app_preference.h>
 #include <system_settings.h>
-#include <pkgmgr-info.h>
+#include <app_manager.h>
 
 #include "conf.h"
 #include "item.h"
 #include "util.h"
 
 #define MENU_SCREEN_ENGINE "file/private/org.tizen.menu-screen/engine"
-
-#define LAYOUT_EDJE_PORTRAIT EDJEDIR"/layout_portrait.edj"
 #define LAYOUT_GROUP_NAME "layout"
 
 
-
 // Define prototype of the "hidden API of AUL"
 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
 static struct {
        int state;
        int root_width;
        int root_height;
-       int is_tts;
-       int booting_state;
        Evas *evas;
        Ecore_Evas *ee;
        Evas_Object *win;
@@ -66,8 +59,6 @@ static struct {
        bool is_done;
 } menu_screen_info = {
        .state = APP_STATE_PAUSE,
-       .is_tts = false,
-       .booting_state = 0,
        .evas = NULL,
        .ee = NULL,
        .win = NULL,
@@ -133,57 +124,6 @@ HAPI int menu_screen_get_state(void)
 
 
 
-HAPI int menu_screen_is_tts(void)
-{
-       return menu_screen_info.is_tts;
-}
-
-
-static Eina_Bool _appcore_flush_cb(void *data)
-{
-       if (APP_STATE_PAUSE != menu_screen_info.state) return ECORE_CALLBACK_CANCEL;
-       if (0 != appcore_flush_memory()) _E("Cannot flush memory");
-       return ECORE_CALLBACK_CANCEL;
-}
-
-
-
-HAPI void menu_screen_inc_booting_state(void)
-{
-       menu_screen_info.booting_state++;
-       if (BOOTING_STATE_DONE > menu_screen_info.booting_state) return;
-
-       menu_screen_error_e ret = MENU_SCREEN_ERROR_OK;
-       do {
-               ret = pkgmgr_reserve_list_pop_request();
-       } while (MENU_SCREEN_ERROR_OK == ret);
-
-       /*  Cache memory is cleared when the application paused (every time, after 5 seconds (in appcore)),
-       *  but after running in a minimized mode (HIDE_LAUNCH) application have status AS_RUNNING.
-       *  Application have status AS_PAUSED only after change of visibility to hidden condition by user (on hiding window)
-       *  Cleaning must be performed only once after application loading in hidden condition
-       *  (and stay in a hidden condition at time of cleaning).
-       */
-       if (APP_STATE_PAUSE == menu_screen_info.state)
-               ecore_timer_add(5, _appcore_flush_cb, NULL);
-}
-
-
-
-HAPI void menu_screen_dec_booting_state(void)
-{
-       menu_screen_info.booting_state --;
-}
-
-
-
-HAPI int menu_screen_get_booting_state(void)
-{
-       return menu_screen_info.booting_state;
-}
-
-
-
 static bool _is_emulator_on(void)
 {
        int ret;
@@ -229,27 +169,20 @@ static menu_screen_error_e _create_canvas(char *name, char *title)
                }
        }
 
-       menu_screen_info.win = elm_win_add(NULL, name, ELM_WIN_BASIC);
+       menu_screen_info.win = elm_win_util_standard_add(name, name);
        retv_if(NULL == menu_screen_info.win, MENU_SCREEN_ERROR_FAIL);
 
        if (title) {
                elm_win_title_set(menu_screen_info.win, title);
        }
+       _D("elm_scale: %f", elm_app_base_scale_get());
+       _D("config_scale: %f", elm_config_scale_get());
+
        elm_win_borderless_set(menu_screen_info.win, EINA_TRUE);
        elm_win_screen_size_get(menu_screen_info.win, NULL, NULL, &menu_screen_info.root_width, &menu_screen_info.root_height);
-
-#if 0
-       ecore_x_icccm_name_class_set(elm_win_xwindow_get(menu_screen_info.win), "MENU_SCREEN", "MENU_SCREEN");
-       ATOM_WM_WINDOW_ROLE = ecore_x_atom_get("WM_WINDOW_ROLE");
-       if (ATOM_WM_WINDOW_ROLE) {
-               ecore_x_window_prop_string_set(elm_win_xwindow_get(menu_screen_info.win), ATOM_WM_WINDOW_ROLE, "MENU_SCREEN");
-       } else {
-               _D("Failed to set the window role as MENU_SCREEN");
-       }
-#endif
+       _D("menu-screen window size:: width: %d, height: %d", menu_screen_info.root_width, menu_screen_info.root_height);
 
        elm_win_role_set(menu_screen_info.win, "MENU_SCREEN");
-       evas_object_resize(menu_screen_info.win, menu_screen_get_root_width(), menu_screen_get_root_height());
 
        menu_screen_info.evas = evas_object_evas_get(menu_screen_info.win);
        if (!menu_screen_info.evas) {
@@ -261,9 +194,6 @@ static menu_screen_error_e _create_canvas(char *name, char *title)
                _E("[%s] Failed to get ecore_evas object", __func__);
        }
 
-       evas_object_size_hint_min_set(menu_screen_info.win, menu_screen_info.root_width, menu_screen_info.root_height);
-       evas_object_size_hint_max_set(menu_screen_info.win, menu_screen_info.root_width, menu_screen_info.root_height);
-       evas_object_resize(menu_screen_info.win, menu_screen_info.root_width, menu_screen_info.root_height);
        evas_object_show(menu_screen_info.win);
 
        return MENU_SCREEN_ERROR_OK;
@@ -300,15 +230,21 @@ static void _create_bg(void)
 
        width = menu_screen_get_root_width();
        height = menu_screen_get_root_height();
+       _D("width : %d, height : %d FOR BG", width, height);
 
        bg = evas_object_data_get(menu_screen_get_win(), "bg");
        if (!bg) {
+               _D("BG is NULL, Create!!");
                Evas_Object *rect;
 
                rect = evas_object_rectangle_add(menu_screen_get_evas());
-               ret_if(!rect);
+               if (NULL == rect) {
+                       free(buf);
+                       return;
+               }
                evas_object_data_set(menu_screen_get_win(), "rect", rect);
                evas_object_color_set(rect, 0, 0, 0, 255);
+               evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
                evas_object_size_hint_min_set(rect, width, height);
                evas_object_size_hint_max_set(rect, width, height);
                elm_win_resize_object_add(menu_screen_get_win(), rect);
@@ -326,10 +262,15 @@ static void _create_bg(void)
        elm_image_fill_outside_set(bg, EINA_TRUE);
        elm_image_preload_disabled_set(bg, EINA_FALSE);
 
+       evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_min_set(bg, width, height);
        evas_object_size_hint_max_set(bg, width, height);
-       if (!elm_image_file_set(bg, buf, NULL)) {
+       if (buf == NULL || !elm_image_file_set(bg, buf, NULL)) {
                _E("Failed to set image file : %s", buf);
+               if (!elm_image_file_set(bg, util_get_file_path(IMAGE_DIR"/home_001.png"), NULL)) {
+                       _E("Failed to set default image file: %s", util_get_file_path(IMAGE_DIR"/home_001.png"));
+                       return;
+               }
        }
 
        elm_win_resize_object_add(menu_screen_get_win(), bg);
@@ -367,14 +308,14 @@ static void _init_theme(void)
 {
        menu_screen_info.theme = elm_theme_new();
        elm_theme_ref_set(menu_screen_info.theme, NULL);
-       elm_theme_extension_add(menu_screen_info.theme, EDJEDIR"/index.edj");
+       elm_theme_extension_add(menu_screen_info.theme, util_get_file_path(EDJE_DIR"/index.edj"));
 }
 
 
 
 static void _fini_theme(void)
 {
-       elm_theme_extension_del(menu_screen_info.theme, EDJEDIR"/index.edj");
+       elm_theme_extension_del(menu_screen_info.theme, util_get_file_path(EDJE_DIR"/index.edj"));
        elm_theme_free(menu_screen_info.theme);
        menu_screen_info.theme = NULL;
 
@@ -385,12 +326,19 @@ static void _fini_theme(void)
 static Evas_Object *_create_conformant(Evas_Object *win)
 {
        Evas_Object *conformant;
+       char *device_profile;
 
        conformant = elm_conformant_add(win);
        retv_if(NULL == conformant, NULL);
 
        evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
+       device_profile = util_get_device_profile();
+       if (device_profile) {
+               if (!strcmp(device_profile, "mobile")) {
+                       elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
+                       elm_win_indicator_opacity_set(menu_screen_info.win, ELM_WIN_INDICATOR_TRANSLUCENT);
+               }
+       }
        elm_object_signal_emit(conformant, "elm,state,indicator,overlap", "elm");
        evas_object_data_set(conformant, "win", win);
        evas_object_show(conformant);
@@ -398,6 +346,9 @@ static Evas_Object *_create_conformant(Evas_Object *win)
        elm_win_resize_object_add(win, conformant);
        elm_win_conformant_set(win, EINA_TRUE);
 
+       if (device_profile)
+               free(device_profile);
+
        return conformant;
 }
 
@@ -410,51 +361,6 @@ static void _destroy_conformant(Evas_Object *conformant)
 }
 
 
-static char *_replace_str(char *str, const char *before, const char *after)
-{
-       retv_if(NULL == str, NULL);
-       retv_if(NULL == before, NULL);
-       retv_if(NULL == after, NULL);
-
-       size_t before_len = strlen(before);
-       retv_if(before_len < 1, str);
-
-       size_t after_len = strlen(after);
-       size_t i, count = 0;
-       if (after_len != before_len) {
-               for (i = 0; str[i] != '\0';) {
-                       if (0 == memcmp(&str[i], before, before_len)) {
-                               count++;
-                               i += before_len;
-                       } else {
-                               i++;
-                       }
-               }
-       } else {
-               i = strlen(str);
-       }
-
-       char *result;
-       result = malloc(i + 1 + count * (after_len - before_len));
-       retv_if(result == NULL, NULL);
-
-       char *sr;
-       sr = result;
-       while (*str) {
-               if (0 == memcmp(str, before, before_len)) {
-                       memcpy(sr, after, after_len);
-                       sr += after_len;
-                       str += before_len;
-               } else {
-                       *sr++ = *str++;
-               }
-       }
-       *sr = '\0';
-
-       return result;
-}
-
-
 
 static bool _create_cb(void *data)
 {
@@ -473,8 +379,7 @@ static bool _create_cb(void *data)
        evas_object_data_set(menu_screen_info.win, "conformant", conformant);
 
        Evas_Object *layout;
-       layout = layout_create(conformant, LAYOUT_EDJE_PORTRAIT,
-                               LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
+       layout = layout_create(conformant, util_get_file_path(EDJE_DIR"/layout_portrait.edj"), LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
        if (NULL == layout) {
                _E("Failed to load an edje object");
                evas_object_del(menu_screen_info.win);
@@ -502,7 +407,6 @@ static void _terminate_cb(void *data)
        Evas_Object *layout;
 
        // FIXME : This will be enabled after rebuilding the routine for appid <-> pkgid.
-       pkgmgr_fini();
 
        if (system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN) < 0) {
                _E("Failed to remove bgset [%s]\n", SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
@@ -605,37 +509,39 @@ static void _language_changed_cb(app_event_info_h event_info, void *data)
 
        count = page_scroller_count_page(scroller);
        page_max_app = (unsigned int) evas_object_data_get(scroller, "page_max_app");
-       for (i = 0; i < count; i ++) {
+       for (i = 0; i < count; i++) {
                page = page_scroller_get_page_at(scroller, i);
                if (!page) continue;
                if (mapbuf_is_enabled(page)) {
                        mapbuf_disable(page, 1);
                }
 
-               for (j = 0; j < page_max_app; j ++) {
-                       pkgmgrinfo_appinfo_h appinfo_h = NULL;
+               for (j = 0; j < page_max_app; j++) {
+                       app_info_h app_info = NULL;
                        char *name;
+                       int ret;
+                       char *package;
 
                        item = page_get_item_at(page, j);
                        if (!item) continue;
 
-                       if (pkgmgrinfo_appinfo_get_appinfo(item_get_package(item), &appinfo_h) < 0) {
-                               pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
-                               continue;
-                       }
-                       if (pkgmgrinfo_appinfo_get_label(appinfo_h, &name) < 0) {
-                               pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+                       package = item_get_package(item);
+                       if (!package) continue;
+
+                       ret = app_manager_get_app_info(package, &app_info);
+                       if (ret != APP_MANAGER_ERROR_NONE || !app_info) {
+                               _E("Failed to get app info");
                                continue;
                        }
-
-                       if (!name) {
-                               _D("Failed to get name for %s", item_get_package(item));
-                               pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+                       ret = app_info_get_label(app_info, &name);
+                       if (APP_MANAGER_ERROR_NONE != ret) {
+                               _E("Failed to get label from : %s", item_get_package(item));
                                continue;
                        }
+                       _D("Changed Language name: %s", name);
+                       
 
                        item_set_name(item, name, 0);
-                       pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
                }
 
                mapbuf_enable(page, 1);
@@ -674,15 +580,8 @@ static void _fini(app_event_handler_h *event_handlers)
 
 
 
-static void _init_reference_value(void)
-{
-       preference_set_string(MENU_SCREEN_ENGINE, "gl");
-}
-
-
 int main(int argc, char *argv[])
 {
-       char *buf;
        ui_app_lifecycle_callback_s lifecycle_callback = {0, };
        app_event_handler_h event_handlers[5] = {NULL, };