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:
Peter Kümmel 2007-12-01 10:23:16 +00:00
parent ad30e45ab6
commit 4ff95a154d
4 changed files with 28 additions and 13 deletions

View File

@ -519,8 +519,7 @@ bool Converters::move(string const & fmt,
string const to_base = removeExtension(to.absFilename()); string const to_base = removeExtension(to.absFilename());
string const to_extension = getExtension(to.absFilename()); string const to_extension = getExtension(to.absFilename());
vector<FileName> const files = vector<FileName> const files = FileName(path).dirList(getExtension(from.absFilename()));
support::dirList(FileName(path), getExtension(from.absFilename()));
for (vector<FileName>::const_iterator it = files.begin(); for (vector<FileName>::const_iterator it = files.begin();
it != files.end(); ++it) { it != files.end(); ++it) {
string const from2 = it->absFilename(); string const from2 = it->absFilename();

View File

@ -86,6 +86,12 @@ FileName::FileName(string const & abs_filename)
} }
FileName::~FileName()
{
delete d;
}
FileName::FileName(FileName const & rhs) : d(new Private) FileName::FileName(FileName const & rhs) : d(new Private)
{ {
d->fi = rhs.d->fi; 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; std::vector<FileName> dirlist;
if (!dirname.isDirectory()) { if (!isDirectory()) {
LYXERR0("Directory '" << dirname << "' does not exist!"); LYXERR0("Directory '" << *this << "' does not exist!");
return dirlist; return dirlist;
} }
QDir dir(dirname.d->fi.absoluteFilePath()); QDir dir(d->fi.absoluteFilePath());
if (!ext.empty()) { if (!ext.empty()) {
QString filter; 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) bool operator==(FileName const & lhs, FileName const & rhs)
{ {
return lhs.absFilename() == rhs.absFilename(); return lhs.absFilename() == rhs.absFilename();
@ -649,7 +662,7 @@ void DocFileName::erase()
string DocFileName::relFilename(string const & path) const string DocFileName::relFilename(string const & path) const
{ {
// FIXME UNICODE // FIXME UNICODE
return to_utf8(makeRelPath(qstring_to_ucs4(d->fi.absoluteFilePath()), from_utf8(path))); return to_utf8(relPath(path));
} }

View File

@ -15,6 +15,7 @@
#include "support/strfwd.h" #include "support/strfwd.h"
#include <ctime> #include <ctime>
#include <vector>
namespace lyx { namespace lyx {
@ -43,7 +44,7 @@ public:
/// ///
FileName & operator=(FileName const &); FileName & operator=(FileName const &);
virtual ~FileName() {} virtual ~FileName();
/** Set a new filename. /** Set a new filename.
* \param filename the file in question. Must have an absolute path. * \param filename the file in question. Must have an absolute path.
* Encoding is always UTF-8. * Encoding is always UTF-8.
@ -139,8 +140,13 @@ public:
/// change to a directory, return success /// change to a directory, return success
bool chdir() const; bool chdir() const;
//private: /// \return list other files in the directory having optional extension 'ext'.
friend class DocFileName; 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; struct Private;
Private * const d; Private * const d;

View File

@ -275,9 +275,6 @@ typedef std::pair<int, std::string> cmd_ret;
cmd_ret const runCommand(std::string const & cmd); 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 support
} // namespace lyx } // namespace lyx