Drag rows from iTunes into Qt app
-
Hi all,
I have an application that processes audio files; these can currently be dragged onto the application window, or onto the dock icon on the Mac.
The feature I'm trying to add is for drag and drop events (on the window and/or dock icon) to accept rows dragged from iTunes, and to do something useful with their metadata; initially on the Mac, and hopefully extending to Windows later.
Researching this has been slow; the most specific material I've found is "this":https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DragandDrop/Tasks/DraggingFiles.html, "this":http://stackoverflow.com/questions/7014734/drag-rows-out-of-itunes-into-cocoa-app and "this":http://stackoverflow.com/questions/7100450/drag-from-itunes-to-an-apps-dock-icon. It all suggests that, on the Mac at least, the information from iTunes is stored in a specific clipboard type, the NSFilesPromisePboardType.
I've been examining the contents of my QDropEvent and QClipboard data and can't find anything that suggests this information is exposed in a simple way in Qt.
Has anyone achieved this with Qt, or for that matter arrived at the conclusion that it can't be done? Is there maybe some way of getting to the (apparently OS-specific) clipboard that holds this data?
Any help or guidance appreciated. Regards,
Ib -
Hi,
I don't know how it is on the Mac, I think the general things are identical as in windows.
You get a drop event which has a mime object in. Theis Mime object contains some information about the contained data. How you encode / decode that is up to you. So if you know, how the iTunes data is encoded, you can decode it.so in general it is:
@
foo()
{
const QMimedata* pData = pDropEvent->mimeData();
pData->formats() // check the content of this for a drop from iTunes
QByteArray arr = pData->data("xxx"); // where xxx = iTunes type, perhaps: NSFilesPromisePboardType?
// now you must know how to decode this type. This is not Qt specific anymore, sorry.
}
@ -
Hi Gerolf, thanks for the quick reply!
I'm familiar with the Mime object; I already use it for accepting file drops. The strange thing is that the QDropEvent from an iTunes row is apparently empty; its formats QStringList is of size 0, and I haven't been able to extract any other information from it.
I'm just wondering whether there's some other, lower level data structure I could be interrogating, or whether there's something I may have missed. I hope so as this is a feature I'd love to offer.
From what I can tell, decoding the information should be very simple once I can get to it, as it's in Apple's plist format, which is just annoyingly un-semantic XML.
Ib
-
I've found some new and even more puzzling information on this.
On one machine I've tried, running Snow Leopard and an older version of iTunes, and Qt 4.7.4, the expected QDragEnterEvent and QDropEvent both fire, but they appear to contain no useful data.
On my main machine, running Lion, latest iTunes, and Qt 4.7.4 and 4.8.0 (makes no difference), the events don't even fire. Qt refuses to recognise the drag and drop at all, let alone provide their metadata.
Does anyone know a possible reason for the change?
-
I would expect iTunes to not put something useful into the drag and/or refusing to drag to alien applications and/or to using some special/non-public API...
-
Thanks Volker; it's certainly looking that way.
I spent some more time on this yesterday but it seems native Obj-C / Cocoa may be the only way to get this data.
-
Hi all,
did anybody find a solution for this? We have the same problem with an application that needs to process email drags from Apple Mail and contact drags from the Address Book. It seems Apple redesigned with Lion all applications to only provide File Promises instead of actual data. Only after confirming the drop by the receiving application the actual files with the data are created. The Address Book programming guide contains some information about this.
For the future this means if Qt cannot process File Promises all Qt built applications cannot receive data from any Apple standard application by drag and drop.
-
I certainly didn't find a solution; I came to the same conclusion as you though.
I noted that the Qt source code does make reference to the file promise clipboard, so it's probably not too far out to hope that this will be addressed in a coming change.
-
You have best chances, if you open a suggestion on the public "bug tracker":https://bugreports.qt-project.org/. Please have a look whether there's already a ticket open on that issue.