]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileName.cpp
Fix problem with python and change of PATH
[lyx.git] / src / support / FileName.cpp
index 5d05b13a7e1c1bdca65c807edc38ab58e879bf47..f0489309d549ae44a61df42c888225eb23eadfe5 100644 (file)
@@ -98,13 +98,7 @@ struct FileName::Private
        ///
        inline void refresh() 
        {
-// There seems to be a bug in Qt >= 4.2.0 and < 4.5.0, that causes problems with
-// QFileInfo::refresh() on *nix. So we recreate the object in that case.
-#if defined(_WIN32) || (QT_VERSION >= 0x040500)
                fi.refresh();
-#else
-               fi = QFileInfo(fi.absoluteFilePath());
-#endif
        }
 
 
@@ -137,7 +131,7 @@ FileName::FileName(string const & abs_filename)
        : d(abs_filename.empty() ? new Private : new Private(abs_filename))
 {
        //LYXERR(Debug::FILES, "FileName(" << abs_filename << ')');
-       LASSERT(empty() || isAbsolute(d->name), /**/);
+       LATTEST(empty() || isAbsolute(d->name));
 }
 
 
@@ -200,7 +194,7 @@ void FileName::set(string const & name)
        d->fi.setFile(toqstr(name));
        d->name = fromqstr(d->fi.absoluteFilePath());
        //LYXERR(Debug::FILES, "FileName::set(" << name << ')');
-       LASSERT(empty() || isAbsolute(d->name), /**/);
+       LATTEST(empty() || isAbsolute(d->name));
 }
 
 
@@ -212,7 +206,7 @@ void FileName::set(FileName const & rhs, string const & suffix)
                d->fi.setFile(QDir(rhs.d->fi.absoluteFilePath()), toqstr(suffix));
        d->name = fromqstr(d->fi.absoluteFilePath());
        //LYXERR(Debug::FILES, "FileName::set(" << d->name << ')');
-       LASSERT(empty() || isAbsolute(d->name), /**/);
+       LATTEST(empty() || isAbsolute(d->name));
 }
 
 
@@ -443,7 +437,13 @@ FileNameList FileName::dirList(string const & ext) const
 
 static string createTempFile(QString const & mask)
 {
-       QTemporaryFile qt_tmp(mask);
+       // FIXME: This is not safe. QTemporaryFile creates a file in open(),
+       //        but the file is deleted when qt_tmp goes out of scope.
+       //        Therefore the next call to createTempFile() may create the
+       //        same file again. To make this safe the QTemporaryFile object
+       //        needs to be kept for the whole life time of the temp file name.
+       //        This can be achieved by using the TempFile class.
+       QTemporaryFile qt_tmp(mask + ".XXXXXXXXXXXX");
        if (qt_tmp.open()) {
                string const temp_file = fromqstr(qt_tmp.fileName());
                LYXERR(Debug::FILES, "Temporary file `" << temp_file << "' created.");
@@ -729,7 +729,7 @@ docstring FileName::displayName(int threshold) const
 docstring FileName::fileContents(string const & encoding) const
 {
        if (!isReadableFile()) {
-               LYXERR0("File '" << *this << "' is not redable!");
+               LYXERR0("File '" << *this << "' is not readable!");
                return docstring();
        }
 
@@ -752,7 +752,11 @@ docstring FileName::fileContents(string const & encoding) const
        if (encoding.empty() || encoding == "UTF-8")
                s = QString::fromUtf8(contents.data());
        else if (encoding == "ascii")
+#if (QT_VERSION < 0x050000)
                s = QString::fromAscii(contents.data());
+#else
+               s = QString::fromLatin1(contents.data());
+#endif
        else if (encoding == "local8bit")
                s = QString::fromLocal8Bit(contents.data());
        else if (encoding == "latin1")