#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;
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;
{
_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)
}
_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 {
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);
#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;
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;
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);
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;
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;
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;
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);
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]);
}
}
}
_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;
{
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;
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;
}
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) {
}
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;
}
}
}
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)) {
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)
{
_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;
}
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");
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);
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);
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);
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;
}
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);
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;
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);
{
_ENTER;
+ _deinit_package_manager();
_unregister_badge_changed_callback();
}
{
_ENTER;
- widget_app_lifecycle_callback_s ops = {0,};
+ widget_app_lifecycle_callback_s ops = { NULL };
int ret;
ops.create = _widget_app_create;