From a4e9658e708c13b5d4ad2b05119aa35c9480f77c Mon Sep 17 00:00:00 2001 From: Vitor Sousa Date: Tue, 5 May 2015 13:16:19 +0100 Subject: [PATCH] elm_photocam: use Efl.File in Elm_Photocam Summary: Address the issue: - Elm photocam and the file interface clash on file_set. Specified in the page: https://phab.enlightenment.org/w/efl_interfaces/ Reviewers: felipealmeida, tasn Differential Revision: https://phab.enlightenment.org/D2351 --- legacy/elementary/src/lib/elm_photocam.c | 71 +++++++++++++++++-- legacy/elementary/src/lib/elm_photocam.eo | 35 +-------- .../elementary/src/lib/elm_photocam_legacy.h | 32 +++++++++ 3 files changed, 101 insertions(+), 37 deletions(-) diff --git a/legacy/elementary/src/lib/elm_photocam.c b/legacy/elementary/src/lib/elm_photocam.c index 96e98af48e..c4ae9b6408 100644 --- a/legacy/elementary/src/lib/elm_photocam.c +++ b/legacy/elementary/src/lib/elm_photocam.c @@ -76,6 +76,13 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = { {NULL, NULL} }; +static Eina_Error PHOTO_FILE_LOAD_ERROR_GENERIC; +static Eina_Error PHOTO_FILE_LOAD_ERROR_DOES_NOT_EXIST; +static Eina_Error PHOTO_FILE_LOAD_ERROR_PERMISSION_DENIED; +static Eina_Error PHOTO_FILE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; +static Eina_Error PHOTO_FILE_LOAD_ERROR_CORRUPT_FILE; +static Eina_Error PHOTO_FILE_LOAD_ERROR_UNKNOWN_FORMAT; + static Eina_Bool _key_action_move(Evas_Object *obj, const char *params); static Eina_Bool _key_action_zoom(Evas_Object *obj, const char *params); @@ -1617,8 +1624,8 @@ static const char *remote_uri[] = { "http://", "https://", "ftp://" }; -EOLIAN static Evas_Load_Error -_elm_photocam_file_set(Eo *obj, Elm_Photocam_Data *sd, const char *file) +static Evas_Load_Error +_elm_photocam_file_set_internal(Eo *obj, Elm_Photocam_Data *sd, const char *file) { Evas_Load_Error ret = EVAS_LOAD_ERROR_NONE; unsigned int i; @@ -1664,10 +1671,57 @@ _elm_photocam_file_set(Eo *obj, Elm_Photocam_Data *sd, const char *file) return ret; } -EOLIAN static const char* -_elm_photocam_file_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd) +EOLIAN static Eina_Bool +_elm_photocam_efl_file_file_set(Eo *obj, Elm_Photocam_Data *sd, const char *file, const char *key EINA_UNUSED) { - return sd->file; + Evas_Load_Error ret = _elm_photocam_file_set_internal(obj, sd, file); + + if (ret == EVAS_LOAD_ERROR_NONE) return EINA_TRUE; + + eina_error_set( + ret == EVAS_LOAD_ERROR_DOES_NOT_EXIST ? PHOTO_FILE_LOAD_ERROR_DOES_NOT_EXIST : + ret == EVAS_LOAD_ERROR_PERMISSION_DENIED ? PHOTO_FILE_LOAD_ERROR_PERMISSION_DENIED : + ret == EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED ? PHOTO_FILE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED : + ret == EVAS_LOAD_ERROR_CORRUPT_FILE ? PHOTO_FILE_LOAD_ERROR_CORRUPT_FILE : + ret == EVAS_LOAD_ERROR_UNKNOWN_FORMAT ? PHOTO_FILE_LOAD_ERROR_UNKNOWN_FORMAT : + PHOTO_FILE_LOAD_ERROR_GENERIC + ); + return EINA_FALSE; +} + +EAPI Evas_Load_Error +elm_photocam_file_set(Elm_Photocam *obj, const char *file) +{ + Eina_Bool ret; + if (eo_do_ret(obj, ret, efl_file_set(file, NULL))) return EVAS_LOAD_ERROR_NONE; + + Eina_Error err = eina_error_get(); + return err == PHOTO_FILE_LOAD_ERROR_DOES_NOT_EXIST ? + EVAS_LOAD_ERROR_DOES_NOT_EXIST : + err == PHOTO_FILE_LOAD_ERROR_PERMISSION_DENIED ? + EVAS_LOAD_ERROR_PERMISSION_DENIED : + err == PHOTO_FILE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED ? + EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED : + err == PHOTO_FILE_LOAD_ERROR_CORRUPT_FILE ? + EVAS_LOAD_ERROR_CORRUPT_FILE : + err == PHOTO_FILE_LOAD_ERROR_UNKNOWN_FORMAT ? + EVAS_LOAD_ERROR_UNKNOWN_FORMAT : + EVAS_LOAD_ERROR_GENERIC; +} + +EOLIAN static void +_elm_photocam_efl_file_file_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd, const char **file, const char **key) +{ + if (file) *file = sd->file; + if (key) *key = NULL; +} + +EAPI const char* +elm_photocam_file_get(const Elm_Photocam *obj) +{ + const char *ret = NULL; + eo_do(obj, efl_file_get(&ret, NULL)); + return ret; } EOLIAN static void @@ -2145,6 +2199,13 @@ static void _elm_photocam_class_constructor(Eo_Class *klass) { evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass); + + PHOTO_FILE_LOAD_ERROR_GENERIC = eina_error_msg_static_register("Generic load error"); + PHOTO_FILE_LOAD_ERROR_DOES_NOT_EXIST = eina_error_msg_static_register("File does not exist"); + PHOTO_FILE_LOAD_ERROR_PERMISSION_DENIED = eina_error_msg_static_register("Permission denied to an existing file"); + PHOTO_FILE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED = eina_error_msg_static_register("Allocation of resources failure prevented load"); + PHOTO_FILE_LOAD_ERROR_CORRUPT_FILE = eina_error_msg_static_register("File corrupt (but was detected as a known format)"); + PHOTO_FILE_LOAD_ERROR_UNKNOWN_FORMAT = eina_error_msg_static_register("File is not a known format"); } EOLIAN const Elm_Atspi_Action * diff --git a/legacy/elementary/src/lib/elm_photocam.eo b/legacy/elementary/src/lib/elm_photocam.eo index 166b4d636e..7dc638b0f9 100644 --- a/legacy/elementary/src/lib/elm_photocam.eo +++ b/legacy/elementary/src/lib/elm_photocam.eo @@ -1,5 +1,5 @@ class Elm.Photocam (Elm.Widget, Elm_Interface_Scrollable, - Elm_Interface_Atspi_Widget_Action) + Elm_Interface_Atspi_Widget_Action, Efl.File) { eo_prefix: elm_obj_photocam; properties { @@ -31,37 +31,6 @@ class Elm.Photocam (Elm.Widget, Elm_Interface_Scrollable, bool paused; /*@ The pause state to set */ } } - file { - set { - /*@ - @brief Set the photo file to be shown - - @return The return error (see EVAS_LOAD_ERROR_NONE, EVAS_LOAD_ERROR_GENERIC etc.) - - This sets (and shows) the specified file (with a relative or absolute - path) and will return a load error (same error that - evas_object_image_load_error_get() will return). The image will change and - adjust its size at this point and begin a background load process for this - photo that at some time in the future will be displayed at the full - quality needed. - - @ingroup Photocam */ - return: Evas_Load_Error; - } - get { - /*@ - @brief Returns the path of the current image file - - @return Returns the path - - @see elm_photocam_file_set() - - @ingroup Photocam */ - } - values { - const(char)* file; /*@ The photo file */ - } - } gesture_enabled { set { /*@ @@ -266,6 +235,8 @@ class Elm.Photocam (Elm.Widget, Elm_Interface_Scrollable, Elm.Widget.event; Elm_Interface_Scrollable.region_bring_in; Elm_Interface_Atspi_Widget_Action.elm_actions.get; + Efl.File.file.set; + Efl.File.file.get; } events { clicked; diff --git a/legacy/elementary/src/lib/elm_photocam_legacy.h b/legacy/elementary/src/lib/elm_photocam_legacy.h index 246de4cc1d..c4c206e1ea 100644 --- a/legacy/elementary/src/lib/elm_photocam_legacy.h +++ b/legacy/elementary/src/lib/elm_photocam_legacy.h @@ -23,4 +23,36 @@ EAPI Evas_Object *elm_photocam_add(Evas_Object *parent); */ EAPI void elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h); +/** + * + * @brief Set the photo file to be shown + * + * @return The return error (see EVAS_LOAD_ERROR_NONE, EVAS_LOAD_ERROR_GENERIC etc.) + * + * This sets (and shows) the specified file (with a relative or absolute + * path) and will return a load error (same error that + * evas_object_image_load_error_get() will return). The image will change and + * adjust its size at this point and begin a background load process for this + * photo that at some time in the future will be displayed at the full + * quality needed. + * + * @ingroup Photocam + * + * @param[in] file The photo file + */ +EAPI Evas_Load_Error elm_photocam_file_set(Evas_Object *obj, const char *file); + +/** + * + * @brief Returns the path of the current image file + * + * @return Returns the path + * + * @see elm_photocam_file_set() + * + * @ingroup Photocam + * + */ +EAPI const char *elm_photocam_file_get(const Evas_Object *obj); + #include "elm_photocam.eo.legacy.h" \ No newline at end of file