3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "support/TempFile.h"
15 #include "support/debug.h"
16 #include "support/FileName.h"
17 #include "support/filetools.h"
18 #include "support/Package.h"
19 #include "support/qstring_helpers.h"
23 #include <QTemporaryFile>
30 struct TempFile::Private
33 explicit Private(QString const & mask) : f(mask)
35 LYXERR(Debug::FILES, "Temporary file in " << fromqstr(mask));
37 LYXERR(Debug::FILES, "Temporary file `"
38 << fromqstr(f.fileName()) << "' created.");
40 LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
49 TempFile::TempFile(FileName const & temp_dir, string const & mask)
51 QFileInfo tmp_fi(QDir(toqstr(temp_dir.absoluteFilePath())),
52 toqstr(onlyFileName(mask)));
53 d = new Private(tmp_fi.absoluteFilePath());
57 TempFile::TempFile(string const & mask)
59 QFileInfo tmp_fi(QDir(toqstr(package().temp_dir().absoluteFilePath())),
60 toqstr(onlyFileName(mask)));
61 d = new Private(tmp_fi.absoluteFilePath());
71 FileName TempFile::name() const
73 QString const n = d->f.fileName();
76 return FileName(fromqstr(n));
80 void TempFile::setAutoRemove(bool autoremove)
82 d->f.setAutoRemove(autoremove);
85 } // namespace support