]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileName.cpp
Fix layout bug. Pasting text into a cell tried to set Standard layout, because
[lyx.git] / src / support / FileName.cpp
index 6b3ac68e7186f3a31a49933b0cce3dd43feeb1e1..5e1ae84b90b56b573637d6eaa6478b19a8a9e392 100644 (file)
@@ -393,10 +393,7 @@ FileName FileName::tempName(FileName const & temp_dir, string const & mask)
 
 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));
-       return FileName(createTempFile(tmp_fi.absoluteFilePath()));
+       return tempName(package().temp_dir(), mask);
 }
 
 
@@ -811,13 +808,39 @@ docstring const FileName::relPath(string const & path) const
 
 bool operator==(FileName const & lhs, FileName const & rhs)
 {
-       return lhs.absFilename() == rhs.absFilename();
+       // FIXME: We need to solve this warning from Qt documentation:
+       // * Long and short file names that refer to the same file on Windows are
+       //   treated as if they referred to different files.
+       // This is supposed to be fixed for Qt5.
+
+       if (lhs.empty())
+               // QFileInfo::operator==() returns false if the two QFileInfo are empty.
+               return rhs.empty();
+
+       if (rhs.empty())
+               // Avoid unnecessary checks below.
+               return false;
+
+       lhs.d->refresh();
+       rhs.d->refresh();
+       
+       if (!lhs.d->fi.isSymLink() && !rhs.d->fi.isSymLink())
+               return lhs.d->fi == rhs.d->fi;
+
+       // FIXME: When/if QFileInfo support symlink comparison, remove this code.
+       QFileInfo fi1(lhs.d->fi);
+       if (fi1.isSymLink())
+               fi1 = QFileInfo(fi1.symLinkTarget());
+       QFileInfo fi2(rhs.d->fi);
+       if (fi2.isSymLink())
+               fi2 = QFileInfo(fi2.symLinkTarget());
+       return fi1 == fi2;
 }
 
 
 bool operator!=(FileName const & lhs, FileName const & rhs)
 {
-       return lhs.absFilename() != rhs.absFilename();
+       return !(operator==(lhs, rhs));
 }
 
 
@@ -972,7 +995,8 @@ string DocFileName::unzippedFilename() const
 
 bool operator==(DocFileName const & lhs, DocFileName const & rhs)
 {
-       return lhs.absFilename() == rhs.absFilename()
+       return static_cast<FileName const &>(lhs)
+               == static_cast<FileName const &>(rhs)
                && lhs.saveAbsPath() == rhs.saveAbsPath();
 }