]> git.lyx.org Git - features.git/commitdiff
create some helper functions in FileName
authorAndré Pönitz <poenitz@gmx.net>
Wed, 17 Oct 2007 22:21:50 +0000 (22:21 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 17 Oct 2007 22:21:50 +0000 (22:21 +0000)
cosmetics;

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21022 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/BufferParams.cpp
src/support/FileName.cpp
src/support/FileName.h

index 6499c89f9bc461d91e97e4575fb036d22a51f08e..1135b18ef0f00d1566bbc75e1a69992ba0d8d1fd 100644 (file)
@@ -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"),
index 303fe2fcb229f7e7b595d00df85464dc0979cd24..8d6c4d770be0c175b5dbec22f09bc84aa95ed32e 100644 (file)
@@ -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}";
index b8cd5b3c4379d78ab97329d1d886b9af78547e07..606299ec11273e585cec782ad3e431ec5691372a 100644 (file)
 #include "support/qstring_helpers.h"
 
 #include <QFile>
+#include <QFileInfo>
 
-#include <boost/assert.hpp>
+#include <boost/filesystem/exception.hpp>
+#include <boost/filesystem/operations.hpp>
 
 #include <map>
 #include <sstream>
 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)
 {}
index 1d4420b61ee1474e1cce91fcf4fe49d5b3419e62..2fc0be4d95e39364dc646dd83f2ee3d7ff44fa60 100644 (file)
@@ -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.