Direct-opening a temporary file using the user's preferred application

Jan Kundrát jkt at flaska.net
Wed Apr 3 07:05:56 PDT 2013


Hi, I'd like to get an advice about the best-practices on how to direct-open a document stored in a remote location using the user's preferred application. In theory, it is trivial with downloading into a temporary file and QDesktopServices::openUrl which handles the neccessary "magic" behind the scenes, but in practice there's a problem with the lifetime of the temporary files.

My use case is an IMAP e-mail client where I'd like to allow people to open their attachments like PDF files, images or office documents via a single click. Currently I download the attachment into a temporary location, let Qt launch the desired application according to the user's preferences, and after a few seconds I delete the file. However, certain applications like Gwenview (which switches to the next image in /tmp upon deletion if there are more images in the directory) or ark (which cannot preview any more files from the .tar.gz archive after it's gone) are just hopelessly broken in this scenario. I suspect many other non-KDE apps suffer the same problem, but as I don't use them, I cannot really comment.

The alternative is to leave these files laying around and rely on some automatic cleanup of the temporary files. This smells an unreliable thing to me. Waiting for xdg-open to finish (or even for the launched binary to finish, or...) is not the way to go because many applications like LibreOffice use a shared process which handles multiple documents, so there's no guarantee that the launched app exits when the file is no longer needed, nor that it is not needed anymore after the process exits.

Pointers on how to do this in a reliable way are much welcome.

With kind regards,
Jan

[1] https://bugs.kde.org/show_bug.cgi?id=316981
-- 
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/


More information about the xdg mailing list