]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileName.cpp
tiger support on mac snow leopard, include Qt4 frameworks, smart build script with...
[lyx.git] / src / support / FileName.cpp
index 0684c20a54669ec6aca2df5c83d6e986d5613efc..96aa4da93feaca12e28cc7a2943ed8b377c9886e 100644 (file)
@@ -13,7 +13,6 @@
 #include "support/FileName.h"
 #include "support/FileNameList.h"
 
-#include "support/convert.h"
 #include "support/debug.h"
 #include "support/filetools.h"
 #include "support/lassert.h"
 #include <cerrno>
 #include <fcntl.h>
 
-#if defined(HAVE_MKSTEMP) && ! defined(HAVE_DECL_MKSTEMP)
-extern "C" int mkstemp(char *);
-#endif
-
-#if !defined(HAVE_MKSTEMP) && defined(HAVE_MKTEMP)
-# ifdef HAVE_IO_H
-#  include <io.h>
-# endif
-# ifdef HAVE_PROCESS_H
-#  include <process.h>
-# endif
-#endif
-
 // Three implementations of checksum(), depending on having mmap support or not.
 #if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
 #define SUM_WITH_MMAP
@@ -80,6 +66,7 @@ extern "C" int mkstemp(char *);
 #endif // SUM_WITH_MMAP
 
 using namespace std;
+using namespace lyx::support;
 
 // OK, this is ugly, but it is the only workaround I found to compile
 // with gcc (any version) on a system which uses a non-GNU toolchain.
@@ -111,11 +98,9 @@ struct FileName::Private
        ///
        inline void refresh() 
        {
-// There seems to be a bug in Qt >= 4.2.0, at least, that causes problems with
+// 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.
-// FIXME: When Trolltech fixes the bug, we will have to replace 0x999999 below
-// with the actual working minimum version.
-#if defined(_WIN32) || (QT_VERSION >= 0x999999)
+#if defined(_WIN32) || (QT_VERSION >= 0x040500)
                fi.refresh();
 #else
                fi = QFileInfo(fi.absoluteFilePath());
@@ -206,14 +191,14 @@ string FileName::absFilename() const
 
 string FileName::realPath() const
 {
-       return os::real_path(toFilesystemEncoding());
+       return os::real_path(absFilename());
 }
 
 
 void FileName::set(string const & name)
 {
-       d->name = name;
        d->fi.setFile(toqstr(name));
+       d->name = fromqstr(d->fi.absoluteFilePath());
        //LYXERR(Debug::FILES, "FileName::set(" << name << ')');
        LASSERT(empty() || isAbsolute(d->name), /**/);
 }
@@ -286,13 +271,22 @@ bool FileName::changePermission(unsigned long int mode) const
 
 string FileName::toFilesystemEncoding() const
 {
-       // FIXME: This doesn't work on Windows for non ascii file names with Qt < 4.4.
-       // Provided that Windows package uses Qt4.4, this isn't a problem.
+       // This doesn't work on Windows for non ascii file names.
        QByteArray const encoded = QFile::encodeName(d->fi.absoluteFilePath());
        return string(encoded.begin(), encoded.end());
 }
 
 
+string FileName::toSafeFilesystemEncoding(os::file_access how) const
+{
+       // This will work on Windows for non ascii file names.
+       QString const safe_path =
+               toqstr(os::safe_internal_path(absFilename(), how));
+       QByteArray const encoded = QFile::encodeName(safe_path);
+       return string(encoded.begin(), encoded.end());
+}
+
+
 FileName FileName::fromFilesystemEncoding(string const & name)
 {
        QByteArray const encoded(name.c_str(), name.length());
@@ -476,6 +470,12 @@ FileName FileName::tempPath()
 }
 
 
+void FileName::refresh() const
+{
+       d->refresh();
+}
+
+
 time_t FileName::lastModified() const
 {
        // QFileInfo caches information about the file. So, in case this file has
@@ -514,7 +514,7 @@ unsigned long FileName::checksum() const
 #if QT_VERSION >= 0x999999
        // First version of checksum uses Qt4.4 mmap support.
        // FIXME: This code is not ready with Qt4.4.2,
-       // see http://bugzilla.lyx.org/show_bug.cgi?id=5293
+       // see http://www.lyx.org/trac/ticket/5293
        // FIXME: should we check if the MapExtension extension is supported?
        // see QAbstractFileEngine::supportsExtension() and 
        // QAbstractFileEngine::MapExtension)
@@ -532,7 +532,7 @@ unsigned long FileName::checksum() const
 
 #else // QT_VERSION
 
-       string const encoded = toFilesystemEncoding();
+       string const encoded = toSafeFilesystemEncoding();
        char const * file = encoded.c_str();
 
  #ifdef SUM_WITH_MMAP