mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Introduce a new tempName() method with base directory.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25830 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c8a0b97d2e
commit
d79ee740b3
@ -17,6 +17,7 @@
|
|||||||
#include "support/debug.h"
|
#include "support/debug.h"
|
||||||
#include "support/filetools.h"
|
#include "support/filetools.h"
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
#include "support/qstring_helpers.h"
|
||||||
#include "support/os.h"
|
#include "support/os.h"
|
||||||
#include "support/Package.h"
|
#include "support/Package.h"
|
||||||
#include "support/qstring_helpers.h"
|
#include "support/qstring_helpers.h"
|
||||||
@ -141,6 +142,15 @@ FileName::FileName(FileName const & rhs) : d(new Private)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FileName::FileName(FileName const & rhs, string const & suffix) : d(new Private)
|
||||||
|
{
|
||||||
|
if (!rhs.d->fi.isDir())
|
||||||
|
d->fi.setFile(rhs.d->fi.filePath() + toqstr(suffix));
|
||||||
|
else
|
||||||
|
d->fi.setFile(rhs.d->fi.absoluteDir(), toqstr(suffix));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FileName & FileName::operator=(FileName const & rhs)
|
FileName & FileName::operator=(FileName const & rhs)
|
||||||
{
|
{
|
||||||
d->fi = rhs.d->fi;
|
d->fi = rhs.d->fi;
|
||||||
@ -353,20 +363,33 @@ FileNameList FileName::dirList(string const & ext) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static string createTempFile(QString const & mask)
|
||||||
|
{
|
||||||
|
QTemporaryFile qt_tmp(mask);
|
||||||
|
if (qt_tmp.open()) {
|
||||||
|
string const temp_file = fromqstr(qt_tmp.fileName());
|
||||||
|
LYXERR(Debug::FILES, "Temporary file `" << temp_file << "' created.");
|
||||||
|
return temp_file;
|
||||||
|
}
|
||||||
|
LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
|
||||||
|
<< qt_tmp.fileTemplate());
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FileName FileName::tempName(FileName const & temp_dir, string const & mask)
|
||||||
|
{
|
||||||
|
QFileInfo tmp_fi(temp_dir.d->fi.absoluteDir(), toqstr(mask));
|
||||||
|
return FileName(createTempFile(tmp_fi.absoluteFilePath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FileName FileName::tempName(string const & mask)
|
FileName FileName::tempName(string const & mask)
|
||||||
{
|
{
|
||||||
QFileInfo tmp_fi(toqstr(mask));
|
QFileInfo tmp_fi(toqstr(mask));
|
||||||
if (!tmp_fi.isAbsolute())
|
if (!tmp_fi.isAbsolute())
|
||||||
tmp_fi.setFile(package().temp_dir().d->fi.absoluteDir(), toqstr(mask));
|
tmp_fi.setFile(package().temp_dir().d->fi.absoluteDir(), toqstr(mask));
|
||||||
|
return FileName(createTempFile(tmp_fi.absoluteFilePath()));
|
||||||
QTemporaryFile qt_tmp(tmp_fi.absoluteFilePath());
|
|
||||||
if (qt_tmp.open()) {
|
|
||||||
FileName tmp_name(fromqstr(qt_tmp.fileName()));
|
|
||||||
LYXERR(Debug::FILES, "Temporary file `" << tmp_name << "' created.");
|
|
||||||
return tmp_name;
|
|
||||||
}
|
|
||||||
LYXERR(Debug::FILES, "LyX Error: Unable to create temporary file.");
|
|
||||||
return FileName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,6 +43,9 @@ public:
|
|||||||
/// copy constructor.
|
/// copy constructor.
|
||||||
FileName(FileName const &);
|
FileName(FileName const &);
|
||||||
|
|
||||||
|
/// constructor with base name and suffix.
|
||||||
|
FileName(FileName const & fn, std::string const & suffix);
|
||||||
|
|
||||||
///
|
///
|
||||||
FileName & operator=(FileName const &);
|
FileName & operator=(FileName const &);
|
||||||
|
|
||||||
@ -156,6 +159,8 @@ public:
|
|||||||
/// relative path, the template file will be created in the global
|
/// relative path, the template file will be created in the global
|
||||||
/// temporary directory as given by 'package().temp_dir()'.
|
/// temporary directory as given by 'package().temp_dir()'.
|
||||||
static FileName tempName(std::string const & mask = empty_string());
|
static FileName tempName(std::string const & mask = empty_string());
|
||||||
|
static FileName tempName(FileName const & temp_dir,
|
||||||
|
std::string const & mask);
|
||||||
|
|
||||||
/// get the current working directory
|
/// get the current working directory
|
||||||
static FileName getcwd();
|
static FileName getcwd();
|
||||||
|
Loading…
Reference in New Issue
Block a user