mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
create some helper functions in FileName
cosmetics; git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21022 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f1383da952
commit
3b3ac62e58
@ -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"),
|
||||
|
@ -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}";
|
||||
|
@ -17,8 +17,10 @@
|
||||
#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>
|
||||
@ -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)
|
||||
{}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user