]> git.lyx.org Git - lyx.git/blob - src/support/TempFile.cpp
Account for old versions of Pygments
[lyx.git] / src / support / TempFile.cpp
1 /**
2  * \file TempFile.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Georg Baum
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/TempFile.h"
14
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"
20
21 #include <QFileInfo>
22 #include <QDir>
23 #include <QTemporaryFile>
24
25 using namespace std;
26
27 namespace lyx {
28 namespace support {
29
30 struct TempFile::Private
31 {
32         ///
33         Private(QString const & mask) : f(mask)
34         {
35                 LYXERR(Debug::FILES, "Temporary file in " << fromqstr(mask));
36                 if (f.open())
37                         LYXERR(Debug::FILES, "Temporary file `"
38                                << fromqstr(f.fileName()) << "' created.");
39                 else
40                         LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
41                                << f.fileTemplate());
42         }
43
44         ///
45         QTemporaryFile f;
46 };
47
48
49 TempFile::TempFile(FileName const & temp_dir, string const & mask)
50 {
51         QFileInfo tmp_fi(QDir(toqstr(temp_dir.absoluteFilePath())),
52                          toqstr(onlyFileName(mask)));
53         d = new Private(tmp_fi.absoluteFilePath());
54 }
55
56
57 TempFile::TempFile(string const & mask)
58 {
59         QFileInfo tmp_fi(QDir(toqstr(package().temp_dir().absoluteFilePath())),
60                          toqstr(onlyFileName(mask)));
61         d = new Private(tmp_fi.absoluteFilePath());
62 }
63
64
65 TempFile::~TempFile()
66 {
67         delete d;
68 }
69
70
71 FileName TempFile::name() const
72 {
73         QString const n = d->f.fileName();
74         if (n.isNull())
75                 return FileName();
76         return FileName(fromqstr(n));
77 }
78
79
80 void TempFile::setAutoRemove(bool autoremove)
81 {
82         d->f.setAutoRemove(autoremove);
83 }
84
85 } // namespace support
86 } // namespace lyx