diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 6499c89f9b..1135b18ef0 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -750,7 +750,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, } lex.next(); - string const token(lex.getString()); + string const token = lex.getString(); if (!lex) { Alert::error(_("Document could not be read"), diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 303fe2fcb2..8d6c4d770b 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -903,7 +903,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, // when Vietnamese is used, babel must directly be loaded with the // language options, not in the class options, see // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html - int viet = language_options.str().find("vietnam"); + size_t viet = language_options.str().find("vietnam"); // viet = string::npos when not found if (lyxrc.language_global_options && !language_options.str().empty() && viet == string::npos) @@ -1575,7 +1575,7 @@ string const BufferParams::babelCall(string const & lang_opts) const // when Vietnamese is used, babel must directly be loaded with the // language options, see // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html - int viet = lang_opts.find("vietnam"); + size_t viet = lang_opts.find("vietnam"); // viet = string::npos when not found if (!lyxrc.language_global_options || viet != string::npos) return "\\usepackage[" + lang_opts + "]{babel}"; diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index b8cd5b3c43..606299ec11 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -17,8 +17,10 @@ #include "support/qstring_helpers.h" #include +#include -#include +#include +#include #include #include @@ -28,17 +30,15 @@ using std::map; using std::string; - namespace lyx { namespace support { -FileName::FileName() -{} - - -FileName::~FileName() -{} +///////////////////////////////////////////////////////////////////// +// +// FileName +// +///////////////////////////////////////////////////////////////////// FileName::FileName(string const & abs_filename) @@ -81,6 +81,25 @@ FileName const FileName::fromFilesystemEncoding(string const & name) } +bool FileName::exists() const +{ + return QFileInfo(toqstr(name_)).exists(); +} + + +bool FileName::isReadOnly() const +{ + QFileInfo const fi(toqstr(name_)); + return fi.isReadable() && !fi.isWritable(); +} + + +std::time_t FileName::lastModified() const +{ + return boost::filesystem::last_write_time(toFilesystemEncoding()); +} + + bool operator==(FileName const & lhs, FileName const & rhs) { return lhs.absFilename() == rhs.absFilename(); @@ -111,6 +130,13 @@ std::ostream & operator<<(std::ostream & os, FileName const & filename) } +///////////////////////////////////////////////////////////////////// +// +// DocFileName +// +///////////////////////////////////////////////////////////////////// + + DocFileName::DocFileName() : save_abs_path_(true) {} diff --git a/src/support/FileName.h b/src/support/FileName.h index 1d4420b61e..2fc0be4d95 100644 --- a/src/support/FileName.h +++ b/src/support/FileName.h @@ -27,7 +27,7 @@ namespace support { class FileName { public: /// Constructor for empty filenames - FileName(); + FileName() {} /** Constructor for nonempty filenames. * explicit because we don't want implicit conversion of relative * paths in function arguments (e.g. of unlink). @@ -35,7 +35,7 @@ public: * Encoding is always UTF-8. */ explicit FileName(std::string const & abs_filename); - virtual ~FileName(); + virtual ~FileName() {} /** Set a new filename. * \param filename the file in question. Must have an absolute path. * Encoding is always UTF-8. @@ -51,6 +51,14 @@ public: * Only use this for accessing the file, e.g. with an fstream. */ std::string const toFilesystemEncoding() const; + + /// returns true if the file exists + bool exists() const; + /// returns time of last write access + std::time_t lastModified() const; + /// return true when file is readable but not writabel + bool isReadOnly() const; + /** * Get a FileName from \p name in the encoding used by the file system. * Only use this for filenames you got directly from the file system, @@ -102,7 +110,7 @@ public: std::string const relFilename(std::string const & buffer_path = std::string()) const; /// \param buf_path if empty, uses `pwd` std::string const outputFilename(std::string const & buf_path = std::string()) const; - + /** @returns a mangled representation of the absolute file name * suitable for use in the temp dir when, for example, converting * an image file to another format.