I’ve been doing some more fiddling with EWL the last few days. Came up with an idea for an IO manager thats been commited to CVS.

Basically, it abstracts out the need for reading/writting data to get specific EWL types back. The code currently has a hack in it to determine mime types at the moment. This will eventually get changed to have correct mime type lookups.

If you want to see an example of using the IO manager take a look at the ewl/src/bin/tests/ewl_io_manager.c file. The test provides a file dialog to select your data and uses the IO manager to read the data.

It currently supports plain text and images. We’ll hopefully get more plugins in the future to read different file types.

The simple magic behind the IO manager test is the line:

t = ewl_io_manager_uri_read(path)

This will then return either an Ewl_Text widget setup with the contents of the file, an Ewl_Image widget if it’s an image or NULL if the URI can’t be read in for some reason. It’s that simple. You can do other things with the IO manager, map extensions to their icon names, lookup mime types for files, etc.

Along with the input portion of this, you can also save using the IO manager. To write out a file you’ll pass in the widget that contains the information, the URI to write too and the mime type to write the data out as. You should be able to save both plain text and images through the IO manager at the moment. (You should also be able to convert image types this way, read in a JPG and write out a PNG should, in theory, work correctly.)

What are these plugins I’m talking about? Well, the IO manager works by taking the mime type and loading in a chunk of code to handle that mime type. So, for a text/plain mime type it will look for the ewl_io_manager_text_plain_plugin.so, failing that it will look for the ewl_io_manager_text_plugin.so (it falls back down the mime type). These plugins are located in PACKAGE_LIB_DIR/plugins.

Because these plugins aren’t tied with EWL, developers can write their own plugins and install them into the lib directory. They’ll then get picked up automatically by any application that uses the IO manager.

Plugins are fairly simple to write, you can take a look in the ewl/src/plugins directory for two examples, one for text and one for images.

If you’d like to help out, there are a few ways. Send an email to the enlightenment-devel mailing list, join #ewl on irc.freenode.net or add your bugs/patches to the bug tracker at xcomputerman.com/bugs.