TizenRefApp-8179 [App Shortcut Widget] Implement shortcuts sort logic for Edit UI... 80/119380/5
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Thu, 16 Mar 2017 13:22:24 +0000 (15:22 +0200)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Mon, 20 Mar 2017 10:55:13 +0000 (12:55 +0200)
Change-Id: Ie72f96a73f27eaca11c3ddd071815a3f0c85f761

apptray-widget-app/inc/util.h
apptray-widget-app/org.tizen.apptray-widget.xml
apptray-widget-app/src/app-widget-app.c
apptray-widget/inc/apptray_widget_common_defines.h
apptray-widget/src/apptray_widget.c
apptray-widget/tizen-manifest.xml

index 00b79cc2f3821e89905b5e1032b322a04c84b790..875928fdc599495582b5be4f94edff009ae77f3f 100755 (executable)
 #define NAME_LEN 256
 #define TEXT_LEN 256
 #define LOCALE_LEN 32
-#define BUFSZE 1024
+#define BUF_SIZE 1024
 #define SPARE_LEN 128
 #define INDEX_COUNT_LEN 3
 #define PART_NAME_SIZE 128
index 81aff2e0dfcc376763411ccb822aac981422b100..1b5e5991f6cd0dababb78803d3487e7261b04d7c 100755 (executable)
@@ -21,4 +21,7 @@
         <icon>apps_widget_preview.png</icon>
         <support-size preview="apps_widget_preview.png">2x2</support-size>
     </widget-application>
+    <privileges>
+        <privilege>http://tizen.org/privilege/packagemanager.info</privilege>
+    </privileges>
 </manifest>
index 266c129e06b1a8860fe1cad3cf36a0da6441a508..ac8305ebe6d13fbaf6fa2b822e245af78a3ef38f 100755 (executable)
 #define BUNDLE_KEY_SHORTCUT_LIST               "shortcut_list"
 #define BUNDLE_KEY_WIDGET_INSTANCE_ID  "instance_id"
 
+#define APP_SLOTS_MAX_COUNT 4
+
 typedef enum {
        APPTRAY_WGT_APP_LAUNCH_TYPE_UNDEFINED = 0,
        APPTRAY_WGT_APP_LAUNCH_TYPE_MAIN,
        APPTRAY_WGT_APP_LAUNCH_TYPE_PICK
-} apptray_wgt_app_launch_type_e;
+} _apptray_wgt_launch_type_e;
+
+typedef enum {
+       APPTRAY_WGT_APP_SLOT_1 = 1,
+       APPTRAY_WGT_APP_SLOT_2 = 2,
+       APPTRAY_WGT_APP_SLOT_3 = 4,
+       APPTRAY_WGT_APP_SLOT_4 = 8,
+} _apptray_wgt_app_slot_mask_e;
+
+typedef struct {
+       int slot_seq_arr[APP_SLOTS_MAX_COUNT];
+} _apptray_wgt_app_slot_convertor;
+
+static _apptray_wgt_app_slot_convertor _output_slot_conv[16] = {
+               { 0, 1, 2, 3 },
+               { 0, 1, 2, 3 },
+               { 1, 0, 2, 3 },
+               { 0, 1, 2, 3 },
+               { 2, 1, 3, 4 },
+               { 0, 2, 1, 3 },
+               { 2, 1, 3, 4 },
+               { 0, 2, 1, 3 },
+               { 3, 0, 1, 2 },
+               { 3, 0, 1, 2 },
+               { 3, 1, 0, 2 },
+               { 0, 3, 1, 2 },
+               { 3, 2, 0, 1 },
+               { 0, 3, 2, 1 },
+               { 3, 2, 1, 0 },
+               { 0, 3, 1, 2 }
+};
+
+static _apptray_wgt_app_slot_convertor _input_slot_conv[5] = {
+               { 0, 1, 2, 3 },
+               { 0, 1, 2, 3 },
+               { 3, 1, 0, 2 },
+               { 0, 3, 1, 2 },
+               { 0, 3, 1, 2 }
+};
 
 typedef struct appdata {
        Evas_Object *edit_win;
@@ -61,14 +101,14 @@ typedef struct appdata {
        Evas_Object *scroller;
        Evas_Object *title;
        char *widget_instance_id;
-       apptray_wgt_app_launch_type_e launch_type;
+       _apptray_wgt_launch_type_e launch_type;
        char *index;
        Ecore_Event_Handler *press_handler;
        Ecore_Event_Handler *release_handler;
        Eina_List *app_list;
        Eina_List *item_list;
-       char *appid_list[5];
-       char *applabel_list[5];
+       char *appid_list[APP_SLOTS_MAX_COUNT];
+       char *applabel_list[APP_SLOTS_MAX_COUNT];
 } appdata_s;
 
 char *widget_id = NULL;
@@ -111,32 +151,42 @@ static void _update_content(void)
 {
        _ENTER;
 
-       if (g_info) {
-               int res = 0;
-               char content[1024] = {0};
-
-               snprintf(content, sizeof(content), "%s %s %s %s",
-                               g_info->appid_list[0],
-                               g_info->appid_list[1],
-                               g_info->appid_list[2],
-                               g_info->appid_list[3]);
-
-               bundle *b_tmp = bundle_create();
-               if (!b_tmp) {
-                       _E("bundle_create failed");
-                       return;
-               }
-               bundle_add_str(b_tmp, BUNDLE_KEY_SHORTCUT_LIST, content);
-               res = widget_service_trigger_update(APP_WIDGET_CONTENT_KEY, g_info->widget_instance_id, b_tmp, 1);
-               if (res != WIDGET_ERROR_NONE) {
-                       _E("Update widget instance [%s] of wgt app [%s] failed. res[%d]", g_info->widget_instance_id, APP_WIDGET_CONTENT_KEY, res);
-               }
-               bundle_free(b_tmp);
-
+       int res = 0;
+       char content[BUF_SIZE] = { 0 };
+       int slot_mask = 0;
 
-       } else {
+       if (!g_info) {
                _E("g_info is NULL");
+               return;
+       }
+
+       if (strcmp(g_info->appid_list[0], "empty"))
+               slot_mask |= APPTRAY_WGT_APP_SLOT_1;
+       if (strcmp(g_info->appid_list[1], "empty"))
+               slot_mask |= APPTRAY_WGT_APP_SLOT_2;
+       if (strcmp(g_info->appid_list[2], "empty"))
+               slot_mask |= APPTRAY_WGT_APP_SLOT_3;
+       if (strcmp(g_info->appid_list[3], "empty"))
+               slot_mask |= APPTRAY_WGT_APP_SLOT_4;
+
+       snprintf(content, sizeof(content), "%s %s %s %s",
+                       g_info->appid_list[_output_slot_conv[slot_mask].slot_seq_arr[0]],
+                       g_info->appid_list[_output_slot_conv[slot_mask].slot_seq_arr[1]],
+                       g_info->appid_list[_output_slot_conv[slot_mask].slot_seq_arr[2]],
+                       g_info->appid_list[_output_slot_conv[slot_mask].slot_seq_arr[3]]);
+
+       bundle *b_tmp = bundle_create();
+       if (!b_tmp) {
+               _E("bundle_create failed");
+               return;
+       }
+       bundle_add_str(b_tmp, BUNDLE_KEY_SHORTCUT_LIST, content);
+       res = widget_service_trigger_update(APP_WIDGET_CONTENT_KEY, g_info->widget_instance_id, b_tmp, 1);
+       if (res != WIDGET_ERROR_NONE) {
+               _E("Update widget instance [%s] of wgt app [%s] failed. res[%d]", g_info->widget_instance_id, APP_WIDGET_CONTENT_KEY, res);
        }
+       bundle_free(b_tmp);
+
 }
 
 char *_get_date(void)
@@ -1201,7 +1251,7 @@ static void _process_pick_operation(appdata_s *info, app_control_h service)
        }
        _D("Content [%s]", content);
 
-       for (i = 0 ; i < 4 ; i++) {
+       for (i = 0 ; i < APP_SLOTS_MAX_COUNT ; i++) {
                if (i == 0) {
                        _set_app_slot(strtok_r(content, " ",&save), i);
                } else {
@@ -1220,25 +1270,42 @@ static void _process_main_operation(appdata_s *info, app_control_h service, cons
 
        char *content = NULL;
        char *save = NULL;
+       char *app_name = NULL;
+       char *app_list_array[APP_SLOTS_MAX_COUNT] = { NULL };
+       int app_count = 0;
        int i = 0;
 
        _create_edit_layout(info);
        evas_object_show(info->edit_win);
 
        content = strdup_s(app_list);
-
        if (!content) {
                _D("Content is NULL. Set default applist");
                content = strdup(DEFAULT_APP_ORDER);
        }
        _D("Content [%s]", content);
 
-       for (i = 0 ; i < 4 ; i++) {
+       for (i = 0 ; i < APP_SLOTS_MAX_COUNT ; i++) {
+               app_name = NULL;
                if (i == 0) {
-                       _set_app_slot(strtok_r(content, " ",&save), i);
+                       app_name = strtok_r(content, " ", &save);
                } else {
-                       _set_app_slot(strtok_r(NULL, " ",&save), i);
+                       app_name = strtok_r(NULL, " ", &save);
                }
+
+               if (app_name) {
+                       if (strcmp(app_name, "empty")) {
+                               app_count++;
+                       }
+                       app_list_array[i] = strdup(app_name);
+               } else {
+                       app_list_array[i] = strdup("empty");
+               }
+       }
+
+       for (i = 0 ; i < APP_SLOTS_MAX_COUNT ; i++) {
+               _set_app_slot(app_list_array[i], _input_slot_conv[app_count].slot_seq_arr[i]);
+               free(app_list_array[i]);
        }
 
        free(content);
index 4b89191b5aa7303b997856c80e932e9dd80ba141..61e7c3f35f2e6699c3fc35d95dd2683d74e2fa63 100644 (file)
 #define APP_LAUNCH_KEY "launch_apps"
 #define WHOME_APP_CONTROL "home_op"
 
-#define DEFAULT_APP_ORDER "org.tizen.apptray-widget-app empty org.tizen.watch-setting empty"
+#define DEFAULT_APP_ORDER "org.tizen.apptray-widget-app org.tizen.watch-setting empty empty"
 #define BADGE_SIGNAL_LEN 16
 #define MAX_BADGE_COUNT 999
 #define SHORTCUT_W 123
 #define SHORTCUT_H 123
 #define WIDGET_SLOTS_MAX_COUNT 4
 
+#define BUFF_GIANT_SIZE 1024
 #define BUFF_SMALL_SIZE 128
 
 #define ARRAY_ITEMS_COUNT(x) sizeof(x)/sizeof(x[0])
index f957c7bff0738cfc862a8d242877c72598577bad..2c0a7f539866bfdfb5ed785684ed5acd007de6d2 100755 (executable)
@@ -24,6 +24,7 @@
 #include <package-manager.h>
 #include <aul.h>
 #include <badge.h>
+#include <package_manager.h>
 
 #ifndef TELEPHONY_DISABLE
 #include <feedback.h>
 
 #define SLOT_INDEX_BUF_SIZE 10
 
-#define BUNDLE_KEY_SHORTCUT_LIST               "shortcut_list"
-#define BUNDLE_KEY_WIDGET_INSTANCE_ID  "instance_id"
+#define BUNDLE_KEY_SHORTCUT_LIST       "shortcut_list"
+#define BUNDLE_KEY_WIDGET_INSTANCE_ID  "instance_id"
+#define BUNDLE_KEY_CONTENT_INFO        "content_info"
+static Eina_List *s_list = NULL;
+package_manager_h s_pkg_manager = NULL;
 
-static Eina_List *s_list;
-
-struct object_info {
+struct slot_info {
        char *appid;
        char *icon;
        char *label;
@@ -59,7 +61,7 @@ struct info {
        Evas_Object *win;
        Evas_Object *bg;
        Evas_Object *layout;
-       struct object_info obj[WIDGET_SLOTS_MAX_COUNT];
+       struct slot_info slot[WIDGET_SLOTS_MAX_COUNT];
        int first_loaded;
        char *content_app_list[WIDGET_SLOTS_MAX_COUNT];
        bundle *content;
@@ -69,9 +71,9 @@ static struct info *_find_instance_info(const char* id);
 
 static void _check_slots_on_package_remove_callback(const char *package);
 
-static void _show_slot_item_badge(struct object_info *item, int count);
-static void _hide_slot_item_badge(struct object_info *item);
-static int _get_slot_item_badge_count(struct object_info *item);
+static void _show_slot_item_badge(struct slot_info *item, int count);
+static void _hide_slot_item_badge(struct slot_info *item);
+static int _get_slot_item_badge_count(struct slot_info *item);
 
 static void _register_badge_changed_callback(void);
 static void _unregister_badge_changed_callback(void);
@@ -112,6 +114,12 @@ static int _widget_instance_resize(widget_context_h context, int w, int h, void
 static void _init_slots_data(struct info *info);
 static void _update_slots_data(struct info *info, bundle *content);
 
+static void _init_package_manager();
+static void _deinit_package_manager();
+void _package_manager_event_cb(const char *type, const char *package, package_manager_event_type_e event_type,
+         package_manager_event_state_e event_state, int progress,
+         package_manager_error_e error, void *user_data);
+
 static inline struct info *_find_instance_info(const char* id)
 {
        _ENTER;
@@ -135,50 +143,52 @@ static inline struct info *_find_instance_info(const char* id)
 static void _check_slots_on_package_remove_callback(const char *package)
 {
        _ENTER;
+
        _D("remove %s", package);
-       Eina_List *l;
-       struct info *item;
-       bool update = false;
+       Eina_List *l = NULL;
+       struct info *item= NULL;
+       bool need_update = false;
        int i = 0;
 
        EINA_LIST_FOREACH(s_list, l, item) {
                for (i = 0 ; i < WIDGET_SLOTS_MAX_COUNT ; i++) {
-                       if (strcmp(item->obj[i].appid, "empty")) {
-
-                               pkgmgrinfo_appinfo_h appinfo_h = NULL;
-                               char *pkgid = NULL;
-
-                               int ret = pkgmgrinfo_appinfo_get_appinfo(item->content_app_list[i], &appinfo_h);
-                               if (ret != PMINFO_R_OK) {
-                                       _E("get appinfo failed. ret[%d]", ret);
-                                       return;
-                               }
-
-                               ret = pkgmgrinfo_appinfo_get_pkgid(appinfo_h, &pkgid);
-                               if (ret != PMINFO_R_OK) {
-                                       _E("get pkgid failed. ret[%d]", ret);
-                                       pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
-                                       return;
-                               }
-
-                               if (!strcmp(pkgid, package)) {
-                                       free(item->content_app_list[i]);
-                                       item->content_app_list[i] = strdup("empty");
-                                       update = true;
-                               }
-                               free(pkgid);
+                       if (!strcmp(item->slot[i].appid, "empty")) {
+                               continue;
+                       }
+
+                       pkgmgrinfo_appinfo_h appinfo_h = NULL;
+                       char *pkgid = NULL;
+
+                       int ret = pkgmgrinfo_appinfo_get_appinfo(item->content_app_list[i], &appinfo_h);
+                       if (ret != PMINFO_R_OK) {
+                               _E("get appinfo failed. ret[%d]", ret);
+                               return;
+                       }
+
+                       ret = pkgmgrinfo_appinfo_get_pkgid(appinfo_h, &pkgid);
+                       if (ret != PMINFO_R_OK) {
+                               _E("get pkgid failed. ret[%d]", ret);
                                pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+                               return;
+                       }
+
+                       if (!strcmp(pkgid, package)) {
+                               free(item->content_app_list[i]);
+                               item->content_app_list[i] = strdup("empty");
+                               need_update = true;
                        }
+                       free(pkgid);
+                       pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
                }
-               if (update) {
-                       update = 0;
+               if (need_update) {
+                       need_update = 0;
                        _update_all_slots(item);
                        _update_widget_content_app_list(item);
                }
        }
 }
 
-static int _get_slot_item_badge_count(struct object_info *item)
+static int _get_slot_item_badge_count(struct slot_info *item)
 {
        _ENTER;
        unsigned int is_display = 0;
@@ -203,7 +213,7 @@ static int _get_slot_item_badge_count(struct object_info *item)
        return (int)count;
 }
 
-static void _show_slot_item_badge(struct object_info *item, int count)
+static void _show_slot_item_badge(struct slot_info *item, int count)
 {
        _ENTER;
        char *str = NULL;
@@ -238,7 +248,7 @@ static void _show_slot_item_badge(struct object_info *item, int count)
        free(str);
 }
 
-static void _hide_slot_item_badge(struct object_info *item)
+static void _hide_slot_item_badge(struct slot_info *item)
 {
        _ENTER;
        ret_if(!item);
@@ -273,11 +283,11 @@ static void _badge_changed_cb(unsigned int action, const char *appid, unsigned i
 
        EINA_LIST_FOREACH(s_list, l, item) {
                for(i = 0 ; i < WIDGET_SLOTS_MAX_COUNT ; i++){
-                       if(!strcmp(item->obj[i].appid, appid)){
+                       if(!strcmp(item->slot[i].appid, appid)){
                                if (count)
-                                       _show_slot_item_badge(&item->obj[i], count);
+                                       _show_slot_item_badge(&item->slot[i], count);
                                else
-                                       _hide_slot_item_badge(&item->obj[i]);
+                                       _hide_slot_item_badge(&item->slot[i]);
                        }
                }
        }
@@ -302,13 +312,13 @@ static void _slot_clicked_cb(void *data, Evas_Object *obj, const char *emission,
        _ENTER;
 
        struct info *item = (struct info *)data;
-       struct object_info *info = NULL;
+       struct slot_info *info = NULL;
 
        int index = -1;
        sscanf(source, "slot_%d", &index);
        ret_if(index <= 0);
 
-       info = &item->obj[index - 1];
+       info = &item->slot[index - 1];
        if(!strcmp(info->appid, APPS_PKG)) {
                app_control_h service = NULL;
                char *type = APP_LAUNCH_KEY;
@@ -388,12 +398,12 @@ static Evas_Object *_create_slot_app_icon(struct info *item, int pos)
 {
        Evas_Object *icon = NULL;
 
-       icon = evas_object_image_add(evas_object_evas_get(item->obj[pos].eo));
+       icon = evas_object_image_add(evas_object_evas_get(item->slot[pos].eo));
        retv_if(!icon, NULL);
        evas_object_repeat_events_set(icon, EINA_TRUE);
-       evas_object_image_file_set(icon, item->obj[pos].icon, NULL);
+       evas_object_image_file_set(icon, item->slot[pos].icon, NULL);
        evas_object_image_filled_set(icon, EINA_TRUE);
-       elm_object_part_content_set(item->obj[pos].eo, "icon", icon);
+       elm_object_part_content_set(item->slot[pos].eo, "icon", icon);
        evas_object_show(icon);
 
        return icon;
@@ -419,10 +429,10 @@ static bool _set_slot(struct info *item, const char *appid, int pos)
                return false;
        }
 
-       item->obj[pos].appid = strdup(appid);
+       item->slot[pos].appid = strdup(appid);
 
-       item->obj[pos].eo = _create_slot_layout(item, pos);
-       if (!item->obj[pos].eo) {
+       item->slot[pos].eo = _create_slot_layout(item, pos);
+       if (!item->slot[pos].eo) {
                _E("Create slot layout failed");
                goto fail_return;
        }
@@ -445,17 +455,17 @@ static bool _set_slot(struct info *item, const char *appid, int pos)
                goto fail_return;
        }
 
-       item->obj[pos].pkgid = strdup(pkgid);
+       item->slot[pos].pkgid = strdup(pkgid);
 
        ret = pkgmgrinfo_appinfo_get_label(appinfo_h, &label);
        if (ret != PMINFO_R_OK) {
                _E("get label failed. ret[%d]", ret);
-               item->obj[pos].label = strdup("");
+               item->slot[pos].label = strdup("");
        } else {
-               item->obj[pos].label = strdup(label);
+               item->slot[pos].label = strdup(label);
        }
 
-       elm_object_part_text_set(item->obj[pos].eo, "name", item->obj[pos].label);
+       elm_object_part_text_set(item->slot[pos].eo, "name", item->slot[pos].label);
 
        ret = pkgmgrinfo_pkginfo_get_type(pkghandle, &type);
        if (ret != PMINFO_R_OK) {
@@ -463,9 +473,9 @@ static bool _set_slot(struct info *item, const char *appid, int pos)
        }
        if (type) {
                if (!strncmp(type, APP_TYPE_WGT, strlen(APP_TYPE_WGT))) {
-                       item->obj[pos].open_app = 1;
+                       item->slot[pos].open_app = 1;
                } else {
-                       item->obj[pos].open_app = 0;
+                       item->slot[pos].open_app = 0;
                }
        }
 
@@ -475,12 +485,12 @@ static bool _set_slot(struct info *item, const char *appid, int pos)
        }
        if (icon_path_tmp) {
                if (strlen(icon_path_tmp) > 0) {
-                       item->obj[pos].icon = strdup(icon_path_tmp);
+                       item->slot[pos].icon = strdup(icon_path_tmp);
                } else {
-                       item->obj[pos].icon = strdup(DEFAULT_ICON);
+                       item->slot[pos].icon = strdup(DEFAULT_ICON);
                }
        } else {
-               item->obj[pos].icon = strdup(DEFAULT_ICON);
+               item->slot[pos].icon = strdup(DEFAULT_ICON);
        }
 
        if (!_create_slot_app_icon(item, pos)) {
@@ -488,11 +498,11 @@ static bool _set_slot(struct info *item, const char *appid, int pos)
                goto fail_return;
        }
 
-       badge_count = _get_slot_item_badge_count(&item->obj[pos]);
+       badge_count = _get_slot_item_badge_count(&item->slot[pos]);
        if (badge_count) {
-               _show_slot_item_badge(&item->obj[pos], badge_count);
+               _show_slot_item_badge(&item->slot[pos], badge_count);
        } else {
-               _hide_slot_item_badge(&item->obj[pos]);
+               _hide_slot_item_badge(&item->slot[pos]);
        }
 
        if (appinfo_h)
@@ -522,20 +532,20 @@ static void _reset_slot_info(struct info *item, int index)
 {
        _ENTER;
 
-       FREE(item->obj[index].appid);
-       FREE(item->obj[index].icon);
-       FREE(item->obj[index].label);
-       FREE(item->obj[index].pkgid);
-       FREE(item->obj[index].dbox_id);
-       item->obj[index].open_app = 0;
+       FREE(item->slot[index].appid);
+       FREE(item->slot[index].icon);
+       FREE(item->slot[index].label);
+       FREE(item->slot[index].pkgid);
+       FREE(item->slot[index].dbox_id);
+       item->slot[index].open_app = 0;
 
        char index_str[10] = { 0 };
        snprintf(index_str, sizeof(index_str), "slot_%d", index + 1);
        elm_object_part_content_unset(item->layout, index_str);
-       if(item->obj[index].eo) {
-               evas_object_del(item->obj[index].eo);
+       if(item->slot[index].eo) {
+               evas_object_del(item->slot[index].eo);
        }
-       item->obj[index].eo = NULL;
+       item->slot[index].eo = NULL;
 
        _EXIT;
 }
@@ -621,9 +631,16 @@ static void _add_application_clicked_cb(void *data, Evas_Object *obj, const char
        ret_if(!service);
 
        app_control_set_operation(service, APP_CONTROL_OPERATION_PICK);
-       app_control_add_extra_data(service, BUNDLE_KEY_WIDGET_INSTANCE_ID, item->id);
        app_control_set_app_id(service, APPS_PKG);
 
+       bundle_raw *bndl_raw = NULL;
+       int bndl_raw_len = 0;
+       bundle_encode(item->content, &bndl_raw, &bndl_raw_len);
+       app_control_add_extra_data(service, BUNDLE_KEY_CONTENT_INFO, (const char *)bndl_raw);
+       free(bndl_raw);
+
+       app_control_add_extra_data(service, BUNDLE_KEY_WIDGET_INSTANCE_ID, item->id);
+
        int ret = app_control_send_launch_request(service, NULL, NULL);
        if (ret != APP_CONTROL_ERROR_NONE) {
                _E("Failed to launch application");
@@ -637,6 +654,7 @@ static void _create_add_app_layout(struct info *item)
        char full_path[PATH_MAX] = { 0 };
        apptray_wgt_utils_get_resource(EDJE_FILE, full_path, sizeof(full_path));
        elm_layout_file_set(eo, full_path, "add_app_shorcuts");
+
        // TODO: need translation
        elm_object_translatable_part_text_set(eo, "txt", "Add app shortcuts");
        evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -744,14 +762,14 @@ static bool _create_main_ly(struct info *info)
 
 static void _update_widget_content_app_list(struct info *info)
 {
-       char tmp[1024] = { 0 };
+       char tmp[BUFF_GIANT_SIZE] = { 0 };
        int ret = WIDGET_ERROR_NONE;
 
        snprintf(tmp, sizeof(tmp), "%s %s %s %s",
-                       (info->obj[0].appid ? info->obj[0].appid : "empty"),
-                       (info->obj[1].appid ? info->obj[1].appid : "empty"),
-                       (info->obj[2].appid ? info->obj[2].appid : "empty"),
-                       (info->obj[3].appid ? info->obj[3].appid : "empty"));
+                       (info->slot[0].appid ? info->slot[0].appid : "empty"),
+                       (info->slot[1].appid ? info->slot[1].appid : "empty"),
+                       (info->slot[2].appid ? info->slot[2].appid : "empty"),
+                       (info->slot[3].appid ? info->slot[3].appid : "empty"));
 
        bundle_del(info->content, BUNDLE_KEY_SHORTCUT_LIST);
        bundle_add_str(info->content, BUNDLE_KEY_SHORTCUT_LIST, tmp);
@@ -788,18 +806,13 @@ static struct info * _create_widget_instance_info(widget_context_h context, bund
 
        if (content) {
                _D("Widget instance content exists");
-               char *tmp = NULL;
                instance_info->content = bundle_dup(content);
-               bundle_get_str(instance_info->content, BUNDLE_KEY_WIDGET_INSTANCE_ID, &tmp);
-               if (!tmp) {
-                       _D("Instance id not found in content. Set instance_id to content");
-                       bundle_add_str(instance_info->content, BUNDLE_KEY_WIDGET_INSTANCE_ID, instance_id);
-               }
+               bundle_del(instance_info->content, BUNDLE_KEY_WIDGET_INSTANCE_ID);
        } else {
                _D("Widget instance content not exists. Create new one");
                instance_info->content = bundle_create();
-               bundle_add_str(instance_info->content, BUNDLE_KEY_WIDGET_INSTANCE_ID, instance_id);
        }
+       bundle_add_str(instance_info->content, BUNDLE_KEY_WIDGET_INSTANCE_ID, instance_id);
 
        _D("Set widget instance content");
        ret = widget_app_context_set_content_info(instance_info->context, instance_info->content);
@@ -812,20 +825,10 @@ static struct info * _create_widget_instance_info(widget_context_h context, bund
 
 static bool _create_ui_content(struct info *info)
 {
-       if (!_create_win(info)) {
-               _E("Create window failed");
-               return false;
-       }
-
-       if (!_create_bg(info)) {
-               _E("Create background failed");
-               return false;
-       }
+       retv_if(!_create_win(info), false);
+       retv_if(!_create_bg(info), false);
+       retv_if(!_create_main_ly(info), false);
 
-       if (!_create_main_ly(info)) {
-               _E("Create background failed");
-               return false;
-       }
        return true;
 }
 
@@ -834,10 +837,10 @@ static void _init_slots_data(struct info *info)
        char *content_list = NULL;
        bundle_get_str(info->content, BUNDLE_KEY_SHORTCUT_LIST, &content_list);
        if (!content_list) {
-               _D("CONTENT DEFAULT");
+               _D("Default content");
                _update_content_list(info, DEFAULT_APP_ORDER);
        } else {
-               _D("CONTENT RESTORED");
+               _D("Content restored");
                _update_content_list(info, content_list);
        }
        _update_all_slots(info);
@@ -969,6 +972,50 @@ static int _widget_instance_resize(widget_context_h context, int w, int h, void
         return WIDGET_ERROR_NONE;
 }
 
+void _package_manager_event_cb(const char *type, const char *package, package_manager_event_type_e event_type,
+         package_manager_event_state_e event_state, int progress,
+         package_manager_error_e error, void *user_data)
+{
+       if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL
+                       && event_state == PACKAGE_MANAGER_EVENT_STATE_STARTED) {
+               _check_slots_on_package_remove_callback(package);
+       }
+}
+
+static void _init_package_manager()
+{
+       _deinit_package_manager();
+
+       int ret = package_manager_create(&s_pkg_manager);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               _E("Package manager create failed. ret [%d]", ret);
+               return;
+       }
+
+       ret = package_manager_set_event_status(s_pkg_manager, PACKAGE_MANAGER_STATUS_TYPE_UNINSTALL);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               _E("Package manager set event status failed. ret [%d]", ret);
+               _deinit_package_manager();
+               return;
+       }
+
+       ret = package_manager_set_event_cb(s_pkg_manager, _package_manager_event_cb, NULL);
+       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               _E("Package manager set event callback failed. ret [%d]", ret);
+               _deinit_package_manager();
+               return;
+       }
+}
+
+static void _deinit_package_manager()
+{
+       if (s_pkg_manager) {
+               package_manager_unset_event_cb(s_pkg_manager);
+               package_manager_destroy(s_pkg_manager);
+               s_pkg_manager = NULL;
+       }
+}
+
 static widget_class_h _widget_app_create(void *user_data)
 {
        _ENTER;
@@ -976,6 +1023,7 @@ static widget_class_h _widget_app_create(void *user_data)
        app_event_handler_h handlers[5] = { NULL };
 
        _register_badge_changed_callback();
+       _init_package_manager();
 
        widget_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED],
                APP_EVENT_LANGUAGE_CHANGED, _widget_app_lang_changed, user_data);
@@ -1003,6 +1051,7 @@ static void _widget_app_terminate(void *user_data)
 {
        _ENTER;
 
+       _deinit_package_manager();
        _unregister_badge_changed_callback();
 }
 
@@ -1025,7 +1074,7 @@ int main(int argc, char *argv[])
 {
        _ENTER;
 
-       widget_app_lifecycle_callback_s ops = {0,};
+       widget_app_lifecycle_callback_s ops = { NULL };
        int ret;
 
        ops.create = _widget_app_create;
index 9cc652949e9183959308ae7c5af6e69de78c02f5..16201d8861df92fc3abda51dc60b9e978346ef4a 100644 (file)
@@ -6,4 +6,7 @@
         <icon>apps_widget_preview.png</icon>
         <support-size preview="apps_widget_preview.png">2x2</support-size>
     </widget-application>
+    <privileges>
+        <privilege>http://tizen.org/privilege/packagemanager.info</privilege>
+    </privileges>
 </manifest>