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

Rémi Denis-Courmont remi at remlab.net
Wed Apr 3 07:42:17 PDT 2013


   Hello,

On Wed, 03 Apr 2013 16:05:56 +0200, Jan Kundrát <jkt at flaska.net> wrote:
> 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.

If the file is small, you should save it to the user download directory
with a reaonable human-grokable name, and leave it there. That is what most
browsers do.

If the file is large, you should pass the URL to the application directly
to avoid cluttering local storage and waiting almost forever while the
whole file is downloaded, but obviously not all applications will support
this. You definitely should not save it in /tmp as it might be mounted as
tmpfs.

If you really want to delete the file automatically, the least problematic
time to do so would be when your application exits. But it won't be
perfect. Also keep in mind that your application or the system might crash,
so this is not going to be reliable.

-- 
Rémi Denis-Courmont
Sent from my collocated server


More information about the xdg mailing list