Thumbnailer Qt API
|
libthumbnailer-qt.so
provides access to Unity's thumbnailer service (see the thumbnailer-service(1) man page). The implementation accesses the thumbnailer service via its DBus interface.
Methods to retrieve thumbnails are asynchronous; you can also use them synchronously by calling waitForFinished() on the Request that is returned from the asynchronous methods.
We'll use the following class definition to illustrate how to retrieve thumbnails asynchronously. (Note that this is a naive implementation; a more realistic implementation would allow multiple requests to be in progress.)
To retrieve a thumbnail asynchronously, you call the getThumbnail() method. (If you are intersted in album covers and artist images, you will also need to create methods to retrieve those. The implementation is almost identical, so we do not show it here.)
getThumbnail() does not block and returns a QSharedPointer
to a Request object, which emits emits a finished() signal once the request is complete. Therefore, our getThumbnail()
implementation connects the request's finished() signal to the requestFinished()
slot of our class. The implementation of requestFinished()
checks if the request succeeded; the caller can retrieve the actual image by calling the image()
method.
For synchronous requests, we can use the following class:
The implementation is trivial: we simple start the request and wait for it to complete before returning the image:
Note that waitForFinished() can block the calling thread for several seconds, so do not call this from the UI thread.