diff --git a/src/Makefile_Efl.am b/src/Makefile_Efl.am index 83e861fb88..dff5d3cef8 100644 --- a/src/Makefile_Efl.am +++ b/src/Makefile_Efl.am @@ -127,6 +127,7 @@ lib/efl/interfaces/efl_io_writer.c \ lib/efl/interfaces/efl_io_buffer.c \ lib/efl/interfaces/efl_io_queue.c \ lib/efl/interfaces/efl_observer.c \ +lib/efl/interfaces/efl_file.c \ lib/efl/interfaces/efl_text_markup_util.c \ $(NULL) diff --git a/src/lib/efl/interfaces/efl_file.c b/src/lib/efl/interfaces/efl_file.c new file mode 100644 index 0000000000..116e49d5b0 --- /dev/null +++ b/src/lib/efl/interfaces/efl_file.c @@ -0,0 +1,69 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +typedef struct _Efl_File_Data Efl_File_Data; +struct _Efl_File_Data +{ + Eo *vo; + + Efl_Image_Load_Error error; +}; + +static Eina_Bool +_efl_file_file_set(Eo *obj, Efl_File_Data *pd, const char *file, const char *key) +{ + Eina_File *f; + Eina_Bool r = EINA_FALSE; + + pd->error = EFL_IMAGE_LOAD_ERROR_DOES_NOT_EXIST; + + if (file) + { + pd->vo = efl_vpath_manager_fetch(EFL_VPATH_MANAGER_CLASS, file); + efl_vpath_file_do(pd->vo); + // XXX:FIXME: allow this to be async + efl_vpath_file_wait(pd->vo); + file = efl_vpath_file_result_get(pd->vo); + } + + if (file) + { + f = eina_file_open(file, EINA_FALSE); + if (!f) goto on_error; + } + + pd->error = EFL_IMAGE_LOAD_ERROR_NONE; + + r = efl_file_mmap_set(obj, f, key); + if (f) eina_file_close(f); + + on_error: + if (pd->vo && (!efl_vpath_file_keep_get(pd->vo))) + { + efl_del(pd->vo); + pd->vo = NULL; + } + + return r; +} + +static void +_efl_file_file_get(Eo *obj, Efl_File_Data *pd EINA_UNUSED, const char **file, const char **key) +{ + const Eina_File *f = NULL; + + efl_file_mmap_get(obj, &f, key); + + if (f && file) *file = eina_file_filename_get(f); +} + +static Efl_Image_Load_Error +_efl_file_load_error_get(Eo *obj EINA_UNUSED, Efl_File_Data *pd) +{ + return pd->error; +} + +#include "interfaces/efl_file.eo.c" diff --git a/src/lib/efl/interfaces/efl_file.eo b/src/lib/efl/interfaces/efl_file.eo index c8c4627a58..35ac1fa4ec 100644 --- a/src/lib/efl/interfaces/efl_file.eo +++ b/src/lib/efl/interfaces/efl_file.eo @@ -1,10 +1,25 @@ import eina_types; +import efl_gfx_types; -interface Efl.File { +mixin Efl.File { [[Efl file interface]] methods { + @property load_error { + get { + [[Gets the (last) file loading error for a given Edje object + + This function is meant to be used after an Edje EDJ file + loading, what takes place with the $file_set() function. If that + function does not return $true, one should check for the reason + of failure with this one. + ]] + } + values { + error: Efl.Image.Load.Error(Efl.Image.Load.Error.none); [[The load error code.]] + } + } @property mmap { - set { + set @pure_virtual { [[Set the source mmaped file from where an image object must fetch the real image data (it must be an Eina_File). @@ -16,7 +31,7 @@ interface Efl.File { return: bool; [[$true on success, $false otherwise]] } - get { + get @pure_virtual { [[Get the source mmaped file from where an image object must fetch the real image data (it must be an Eina_File). @@ -80,7 +95,7 @@ interface Efl.File { $null, otherwise.]] } } - save @const { + save @const @pure_virtual { [[Save the given image object's contents to an (image) file. The extension suffix on $file will determine which saver diff --git a/src/lib/efl/interfaces/efl_interfaces_main.c b/src/lib/efl/interfaces/efl_interfaces_main.c index fc80036fb4..778108e699 100644 --- a/src/lib/efl/interfaces/efl_interfaces_main.c +++ b/src/lib/efl/interfaces/efl_interfaces_main.c @@ -6,7 +6,6 @@ #include "interfaces/efl_config.eo.c" #include "interfaces/efl_control.eo.c" -#include "interfaces/efl_file.eo.c" #include "interfaces/efl_image.eo.c" #include "interfaces/efl_image_animated.eo.c" #include "interfaces/efl_image_load.eo.c"