]> git.lyx.org Git - lyx.git/commitdiff
Introduce a new tempName() method with base directory.
authorAbdelrazak Younes <younes@lyx.org>
Wed, 23 Jul 2008 09:23:23 +0000 (09:23 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 23 Jul 2008 09:23:23 +0000 (09:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25830 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/FileName.cpp
src/support/FileName.h

index 70c7b8ba87b670bfecec9cd0e81310dd010404b1..8e01df441001ad2be8c09bf9d4f204ec5aa8b23e 100644 (file)
@@ -17,6 +17,7 @@
 #include "support/debug.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
+#include "support/qstring_helpers.h"
 #include "support/os.h"
 #include "support/Package.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)
 {
        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)
 {
        QFileInfo tmp_fi(toqstr(mask));
        if (!tmp_fi.isAbsolute())
                tmp_fi.setFile(package().temp_dir().d->fi.absoluteDir(), toqstr(mask));
-
-       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();
+       return FileName(createTempFile(tmp_fi.absoluteFilePath()));
 }
 
 
index bb635f3ce6cd2fa5bb8aa70031976348395e6973..9a8659054f2abe702bbefecb1a8ec86244cd5a0e 100644 (file)
@@ -43,6 +43,9 @@ public:
        /// copy constructor.
        FileName(FileName const &);
 
+       /// constructor with base name and suffix.
+       FileName(FileName const & fn, std::string const & suffix);
+
        ///
        FileName & operator=(FileName const &);
 
@@ -156,6 +159,8 @@ public:
        /// relative path, the template file will be created in the global
        /// temporary directory as given by 'package().temp_dir()'.
        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
        static FileName getcwd();