Friday, November 19, 2010

Foray into Qt Models with libferris

Version 1.5.2 of libferris, released yesterday, includes both a QAbstractTableModel and QSortFilterProxyModel targeted at exposing libferris to the world of all things Qt. In libferris a great amount of information is exposed as virtual Extended Attributes for a file. As you can see in the below shot, the md5 as well as "ls -lh" size is available directly as attributes. Before you wonder, the md5 is only calculated on demand and is then cached relative to the mtime of the file.

Each file has thousands of attributes on my machine, these include tagging, geospatial information, extracted metadata, and RDF. In my GTK+2 model/view pair I allow the user to "sort" on a column but really have the view sort on another one. For example, as you see below, sorting on size-human-readable either means Qt or some class you provide needs to know how to properly sort on size strings like 14.2k etc. Instead of this, the QSortFilterProxyModel converts some column names into others, so a size-human-readable sort becomes a sort on the "size" column. As the latter is simply a number Qt knows how to do the right thing (TM). Although both columns are shown in the example shot, there is no need to have the size column visible too.

The mtime is actually converted to a QDateTime by the model. It is stored internally as an epoch integer. Thus the mtime-display column was added in libferris which shows you a human readable version. This is handy for command line tools and others which do not want to know about presentation etc and just want something nice to show the user. Most of these attributes in libferris have schema information, which makes it possible to pass them on to Qt in a nice way. Tags should come through as checkboxes etc.

The next logical step is to get at this from QML. I'll wait until I update to Fedora 14 which has Qt 4.7 in it. With the model, and some way to play back audio I should be able to make an audio player in QML. Two things help here; searches can return their results as a virtual filesystem which can then be shown in the QAbstractTableModel, and filesystem "selections" can be built as filesystems which can also be then displayed in the same way. So I have search and playlist support already from that and ffmpeg or some low battery way to make ogg into air oscillation then completes the loop.

No comments: