]> git.lyx.org Git - lyx.git/blob - src/support/TempFile.cpp
improve language flag for Objective-C compiler call
[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/Package.h"
18 #include "support/qstring_helpers.h"
19
20 #include <QFileInfo>
21 #include <QDir>
22 #include <QTemporaryFile>
23
24 using namespace std;
25
26 namespace lyx {
27 namespace support {
28
29 struct TempFile::Private
30 {
31         ///
32         Private(QString const & mask) : f(mask)
33         {
34                 LYXERR(Debug::FILES, "Temporary file in " << fromqstr(mask));
35                 if (f.open())
36                         LYXERR(Debug::FILES, "Temporary file `"
37                                << fromqstr(f.fileName()) << "' created.");
38                 else
39                         LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
40                                << f.fileTemplate());
41         }
42
43         ///
44         QTemporaryFile f;
45 };
46
47
48 TempFile::TempFile(FileName const & temp_dir, string const & mask)
49 {
50         QFileInfo tmp_fi(QDir(toqstr(temp_dir.absoluteFilePath())), toqstr(mask));
51         d = new Private(tmp_fi.absoluteFilePath());
52 }
53
54
55 TempFile::TempFile(string const & mask)
56 {
57         QFileInfo tmp_fi(QDir(toqstr(package().temp_dir().absoluteFilePath())), toqstr(mask));
58         d = new Private(tmp_fi.absoluteFilePath());
59 }
60
61
62 TempFile::~TempFile()
63 {
64         delete d;
65 }
66
67
68 FileName TempFile::name() const
69 {
70         QString const n = d->f.fileName();
71         if (n.isNull())
72                 return FileName();
73         return FileName(fromqstr(n));
74 }
75
76
77 } // namespace support
78 } // namespace lyx