Tinymail: asynchronous folder synchronization with the service implemented

I know I often say I try to avoid threads in tinymail. This one is inevitable: Tinymail is going to support two methods for getting the headers.

The first method has been around for a while now: normal synchronous getting all the headers in a folder. This will return you a bunch of small proxy instances that can be used in for example the custom tree model. You have the option to synchronize or not to synchronize with the service. Synchronizing of course takes a noticeable amount of time. And unless you do something about it, your user interface will block during that time.

The second method is new. The second method or the asynchronous method will launch a small thread that will, in the background, synchronize your folder instance with the server. It will callback on the GMainLoop and it will tell you about the status (status notification is in-thread, the callback-on-finished is thrown to the GMainLoop). You are supposed to reassign the model of your treeview when the on-finished callback invokes. During that reassignment you’ll ask for a new list of proxy instances using the normal synchronous method. This time you (of course) no longer have to choose the synchronization option. So it will be fast.

I also made sure camel cancellation is integrated. What is that? Well, say the user clicks per accident on a folder. He notices it’s the wrong folder and rapidly selects a new folder. Does the user want to wait for the previous folder to be loaded? Probably not! Tinymail will automatically (when using the asynchronous method) cancel the request and will fulfill the new request instead.

The result is a very snappy tinymail with a non-blocked ui. Even if you never synchronized a specific folder with the service, the ui will not block. I didn’t yet implement a progressbar for the demo-ui. But using the asynchronous method this is very easy to implement. For status notifications, you’ll have to do the gdk thread locking because at this moment is the status notification in-thread and not thrown to the GMainLoop like what I did for the on-finished callback. I’m not sure if it would be a good idea to throw it to the GMainLoop. Maybe I will.

So.. I might refactor things a little bit. And as usual is this stuff experimental. No API promises.

You can of course svn co https://svn.cronos.be/svn/tinymail/ and try this new stuff out yourself. The default compilation flags are set in such a way that libtinymail is low on memory usage (a little bit slower) while the demo-ui will use the asynchronous method for getting its header information.

A libtinymail developer will not have to worry about all this. He’ll just have to code a few simple lines: take a look at the ASYNC_HEADERS ifdef. The ifdefs also show how small the difference between using simple synchronous and asynchronous can be.