From: Sung-jae Park Date: Fri, 29 May 2015 13:27:41 +0000 (+0900) Subject: Implement PREVIEW overriding feature X-Git-Tag: accepted/tizen/mobile/20150604.122530~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=edf20ecf7438de42a43264ccde297d0c19b2ac26;p=platform%2Fcore%2Fappfw%2Fwidget-viewer.git Implement PREVIEW overriding feature Change-Id: I5e965da9c6e475b1d707930b14e2f88d60a1033c --- diff --git a/widget_viewer_evas/include/widget_viewer_evas_internal.h b/widget_viewer_evas/include/widget_viewer_evas_internal.h index 0264b41..798708a 100644 --- a/widget_viewer_evas/include/widget_viewer_evas_internal.h +++ b/widget_viewer_evas/include/widget_viewer_evas_internal.h @@ -246,6 +246,17 @@ extern int widget_viewer_evas_set_widget_option(Evas_Object *widget, widget_opti */ extern int widget_viewer_evas_emit_text_signal(Evas_Object *widget, widget_text_signal_s event_info, void *data); +/** + * @brief Set the preview image file + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/widget.viewer + * @param[in] widget + * @param[in] preview + * @return #WIDGET_ERROR_NONE on success, otherwise a negative error value + */ +extern int widget_viewer_evas_set_preview_image(Evas_Object *widget, widget_size_type_e type, const char *preview); + #ifdef __cplusplus } #endif diff --git a/widget_viewer_evas/src/widget_viewer_evas.c b/widget_viewer_evas/src/widget_viewer_evas.c index 8f01c53..2b9dd0b 100644 --- a/widget_viewer_evas/src/widget_viewer_evas.c +++ b/widget_viewer_evas/src/widget_viewer_evas.c @@ -227,6 +227,11 @@ enum CANCEL_CLICK { CANCEL_PROCESSED = 0x02 }; +struct preview_info { + widget_size_type_e type; + char *preview; +}; + struct widget_data { enum { WIDGET_DATA_CREATED = 0x00beef00, @@ -337,6 +342,8 @@ struct widget_data { Eina_List *widget_script_object_list; Ecore_Timer *delayed_resume_timer; + + Eina_List *preview_list; }; struct script_object { @@ -415,6 +422,25 @@ static void append_gbar_dirty_object_list(struct widget_data *data, int idx); static void __widget_event_widget_updated(struct widget_data *data); static void __widget_event_gbar_updated(struct widget_data *data); +static const char *get_preview_image(struct widget_data *data, widget_size_type_e type) +{ + Eina_List *l; + struct preview_info *info; + char *preview; + + EINA_LIST_FOREACH(data->preview_list, l, info) { + if (info->type == type) { + preivew = strdup(info->preview); + if (!preview) { + ErrPrint("strdup: %d\n", errno); + } + return preview; + } + } + + return widget_service_get_preview_image_path(data->widget_id, type); +} + static struct widget_data *get_smart_data(Evas_Object *widget) { if (widget && evas_object_smart_type_check(widget, WIDGET_CLASS_NAME)) { @@ -876,6 +902,10 @@ static void dump_handle_list(void) struct widget_data *widget_unref(struct widget_data *data) { + Eina_List *l; + Eina_List *n; + struct preview_info *info; + data->refcnt--; DbgPrint("refcnt: %d (%s)\n", data->refcnt, data->widget_id); if (data->refcnt != 0) { @@ -888,6 +918,11 @@ struct widget_data *widget_unref(struct widget_data *data) free(data->cluster); free(data->category); + EINA_LIST_FOREACH_SAFE(data->preview_list, l, n, info) { + free(info->preview); + free(info); + } + if (data->overlay_timer) { ecore_timer_del(data->overlay_timer); data->overlay_timer = NULL; @@ -2875,7 +2910,7 @@ static char *get_package_icon(struct widget_data *data) if (data->size_type == WIDGET_SIZE_TYPE_UNKNOWN) { icon = widget_service_get_icon(data->widget_id, NULL); } else { - icon = widget_service_get_preview_image_path(data->widget_id, data->size_type); + icon = get_preview_image(data, data->size_type); } if (icon && access(icon, R_OK) == 0) { @@ -4778,7 +4813,7 @@ static void __widget_overlay_faulted(struct widget_data *data) if (!preview) { char *icon; - icon = widget_service_get_preview_image_path(data->widget_id, data->size_type); + icon = get_preview_image(data, data->size_type); if (icon) { preview = elm_image_add(data->widget_layout); if (preview) { @@ -7415,4 +7450,62 @@ EAPI int widget_viewer_evas_set_widget_option(Evas_Object *widget, widget_option return WIDGET_ERROR_NONE; } +EAPI int widget_viewer_evas_set_preview_image(Evas_Object *widget, widget_size_type_e type, const char *preview) +{ + struct widget_data *data; + Eina_List *l; + Eina_List *n; + struct preview_info *info; + + if (!s_info.initialized) { + return WIDGET_ERROR_FAULT; + } + + data = get_smart_data(widget); + if (!data) { + ErrPrint("Invalid object\n"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + EINA_LIST_FOREACH_SAFE(data->preview_list, l, n, info) { + if (info->type == type) { + char *tmp; + + if (preview) { + tmp = strdup(preview); + if (!tmp) { + ErrPrint("strdup: %d\n", errno); + return WIDGET_ERROR_OUT_OF_MEMORY; + } + + free(info->preview); + info->preview = tmp; + return WIDGET_ERROR_NONE; + } + + data->preview_list = eina_list_remove(data->preview_list, info); + free(info->preview); + free(info); + return WIDGET_ERROR_NONE; + } + } + + info = malloc(sizeof(*preview)); + if (!info) { + ErrPrint("malloc: %d\n", errno); + return WIDGET_ERROR_OUT_OF_MEMORY; + } + + info->type = type; + info->preview = strdup(preview); + if (!info->preview) { + ErrPrint("strdup: %d\n", errno); + free(info); + return WIDGET_ERROR_OUT_OF_MEMORY; + } + + data->preview_list = eina_list_append(data->preview_list, info); + return WIDGET_ERROR_NONE; +} + /* End of a file */