mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 05:33:33 +00:00
fix memory leak, cleanup FileName interface
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21896 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ad30e45ab6
commit
4ff95a154d
@ -519,8 +519,7 @@ bool Converters::move(string const & fmt,
|
||||
string const to_base = removeExtension(to.absFilename());
|
||||
string const to_extension = getExtension(to.absFilename());
|
||||
|
||||
vector<FileName> const files =
|
||||
support::dirList(FileName(path), getExtension(from.absFilename()));
|
||||
vector<FileName> const files = FileName(path).dirList(getExtension(from.absFilename()));
|
||||
for (vector<FileName>::const_iterator it = files.begin();
|
||||
it != files.end(); ++it) {
|
||||
string const from2 = it->absFilename();
|
||||
|
@ -86,6 +86,12 @@ FileName::FileName(string const & abs_filename)
|
||||
}
|
||||
|
||||
|
||||
FileName::~FileName()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
FileName::FileName(FileName const & rhs) : d(new Private)
|
||||
{
|
||||
d->fi = rhs.d->fi;
|
||||
@ -320,15 +326,15 @@ bool FileName::createDirectory(int permission) const
|
||||
}
|
||||
|
||||
|
||||
std::vector<FileName> dirList(FileName const & dirname, std::string const & ext)
|
||||
std::vector<FileName> FileName::dirList(std::string const & ext)
|
||||
{
|
||||
std::vector<FileName> dirlist;
|
||||
if (!dirname.isDirectory()) {
|
||||
LYXERR0("Directory '" << dirname << "' does not exist!");
|
||||
if (!isDirectory()) {
|
||||
LYXERR0("Directory '" << *this << "' does not exist!");
|
||||
return dirlist;
|
||||
}
|
||||
|
||||
QDir dir(dirname.d->fi.absoluteFilePath());
|
||||
QDir dir(d->fi.absoluteFilePath());
|
||||
|
||||
if (!ext.empty()) {
|
||||
QString filter;
|
||||
@ -579,6 +585,13 @@ bool FileName::isZippedFile() const
|
||||
}
|
||||
|
||||
|
||||
docstring const FileName::relPath(string const & path) const
|
||||
{
|
||||
// FIXME UNICODE
|
||||
return makeRelPath(qstring_to_ucs4(d->fi.absoluteFilePath()), from_utf8(path));
|
||||
}
|
||||
|
||||
|
||||
bool operator==(FileName const & lhs, FileName const & rhs)
|
||||
{
|
||||
return lhs.absFilename() == rhs.absFilename();
|
||||
@ -649,7 +662,7 @@ void DocFileName::erase()
|
||||
string DocFileName::relFilename(string const & path) const
|
||||
{
|
||||
// FIXME UNICODE
|
||||
return to_utf8(makeRelPath(qstring_to_ucs4(d->fi.absoluteFilePath()), from_utf8(path)));
|
||||
return to_utf8(relPath(path));
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -43,7 +44,7 @@ public:
|
||||
///
|
||||
FileName & operator=(FileName const &);
|
||||
|
||||
virtual ~FileName() {}
|
||||
virtual ~FileName();
|
||||
/** Set a new filename.
|
||||
* \param filename the file in question. Must have an absolute path.
|
||||
* Encoding is always UTF-8.
|
||||
@ -139,8 +140,13 @@ public:
|
||||
/// change to a directory, return success
|
||||
bool chdir() const;
|
||||
|
||||
//private:
|
||||
friend class DocFileName;
|
||||
/// \return list other files in the directory having optional extension 'ext'.
|
||||
std::vector<FileName> dirList(std::string const & ext = empty_string());
|
||||
|
||||
/// \param buffer_path if empty, uses `pwd`
|
||||
docstring const relPath(std::string const & path) const;
|
||||
|
||||
private:
|
||||
///
|
||||
struct Private;
|
||||
Private * const d;
|
||||
|
@ -275,9 +275,6 @@ typedef std::pair<int, std::string> cmd_ret;
|
||||
|
||||
cmd_ret const runCommand(std::string const & cmd);
|
||||
|
||||
/// \return list files in a directory having optional extension ext..
|
||||
std::vector<FileName> dirList(FileName const & dir,
|
||||
std::string const & ext = empty_string());
|
||||
|
||||
} // namespace support
|
||||
} // namespace lyx
|
||||
|
Loading…
Reference in New Issue
Block a user