quicksilver/Quicksilver — pull request #1369 by skurfer (2013-02-02 20:17:49+00:00)
Title: background icon loading

@neurolepsy pointed out that the iTunes plug-in was still generating artwork and previews on the main thread. I fixed it last night. It wasn't too difficult, but when I think about every developer having to go through that process for every plug-in, I don't like it. So I started thinking about a way for all the plug-ins to get this behavior "for free" and it turns out the way things were designed allows for this pretty easily.

We already have a method that stays on the main thread and throws up an inexpensive generic icon: `setQuickIconForObject`. And `loadIconForObject` exists to take care of anything more expensive later on. Previously, we were modifying the latter in individual object sources to spawn yet another method in the background, which would post a notification when the icon is done.

I've changed things so `loadIconForObject` is itself always run on a background thread, so individual object sources don't need to worry about that.

The only hitch was that the all the plug-ins' object sources would still need to be modified to call `updateIcon` instead of `setIcon` in order to post the notification. But I think I've found a way to make `setIcon` do the right thing, eliminating the need to ever call `updateIcon`. Basically, it only posts a `QSObjectIconModified` notification if an icon was previously set, and the one being currently set is different.

As a result, the iTunes plug-in now generates artwork and previews in the background without any modifications to the plug-in itself. So will any others that make use of the two icon methods.

Seems to me like this is how it should work. :-)