]> git.lyx.org Git - features.git/commitdiff
fix memory leak, cleanup FileName interface
authorPeter Kümmel <syntheticpp@gmx.net>
Sat, 1 Dec 2007 10:23:16 +0000 (10:23 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Sat, 1 Dec 2007 10:23:16 +0000 (10:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21896 a592a061-630c-0410-9148-cb99ea01b6c8

src/Converter.cpp
src/support/FileName.cpp
src/support/FileName.h
src/support/filetools.h

index fc82114308018ffbb6d284c006800b2f2e52d9ab..d927cd9c52011902c7ff509db6d2d57efb0dd76a 100644 (file)
@@ -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();
index 4418ab08840557fe4a4a023550c36b9e7a9f0194..77b3ab7edbc76837eb98a64fec623fbf56f32755 100644 (file)
@@ -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));
 }
 
 
index 3577ed9c385efc09458f347ab7724b05940e7852..f53290159f18caf4561df4a66a6a7d8927d7275f 100644 (file)
@@ -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;
index 383aeac2f8b58cf937d9ba8a56dc5cb29a9d5516..6e3e412ec62ac5975af3b33be50c985f42cbd4ac 100644 (file)
@@ -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