From aef7e129e79ce210c8a3778e5257ae088fe23843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=BCmmel?= Date: Sun, 2 Dec 2007 09:19:43 +0000 Subject: [PATCH] move funtion with std::vector to filetools git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21903 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Converter.cpp | 3 ++- src/support/FileName.cpp | 34 +++------------------------------- src/support/FileName.h | 6 ++---- src/support/filetools.cpp | 34 ++++++++++++++++++++++++++++++++++ src/support/filetools.h | 3 +++ 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/Converter.cpp b/src/Converter.cpp index d927cd9c52..fc82114308 100644 --- a/src/Converter.cpp +++ b/src/Converter.cpp @@ -519,7 +519,8 @@ bool Converters::move(string const & fmt, string const to_base = removeExtension(to.absFilename()); string const to_extension = getExtension(to.absFilename()); - vector const files = FileName(path).dirList(getExtension(from.absFilename())); + vector const files = + support::dirList(FileName(path), getExtension(from.absFilename())); for (vector::const_iterator it = files.begin(); it != files.end(); ++it) { string const from2 = it->absFilename(); diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index 77b3ab7edb..e45c805661 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -326,37 +326,9 @@ bool FileName::createDirectory(int permission) const } -std::vector FileName::dirList(std::string const & ext) +docstring const FileName::absoluteFilePath() const { - std::vector dirlist; - if (!isDirectory()) { - LYXERR0("Directory '" << *this << "' does not exist!"); - return dirlist; - } - - QDir dir(d->fi.absoluteFilePath()); - - if (!ext.empty()) { - QString filter; - switch (ext[0]) { - case '.': filter = "*" + toqstr(ext); break; - case '*': filter = toqstr(ext); break; - default: filter = "*." + toqstr(ext); - } - dir.setNameFilters(QStringList(filter)); - LYXERR(Debug::FILES, "filtering on extension " - << fromqstr(filter) << " is requested."); - } - - QFileInfoList list = dir.entryInfoList(); - for (int i = 0; i != list.size(); ++i) { - FileName fi; - fi.d->fi = list.at(i); - dirlist.push_back(fi); - LYXERR(Debug::FILES, "found file " << fi); - } - - return dirlist; + return qstring_to_ucs4(d->fi.absoluteFilePath()); } @@ -588,7 +560,7 @@ 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)); + return makeRelPath(absoluteFilePath(), from_utf8(path)); } diff --git a/src/support/FileName.h b/src/support/FileName.h index f53290159f..519ba896ac 100644 --- a/src/support/FileName.h +++ b/src/support/FileName.h @@ -15,7 +15,6 @@ #include "support/strfwd.h" #include -#include namespace lyx { @@ -139,12 +138,11 @@ public: /// change to a directory, return success bool chdir() const; - - /// \return list other files in the directory having optional extension 'ext'. - std::vector dirList(std::string const & ext = empty_string()); /// \param buffer_path if empty, uses `pwd` docstring const relPath(std::string const & path) const; + + docstring const absoluteFilePath() const; private: /// diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 1bc4c6105e..8b9258cfe1 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -934,5 +934,39 @@ int compare_timestamps(FileName const & file1, FileName const & file2) return cmp; } + +std::vector dirList(FileName const & filename, std::string const & ext) +{ + std::vector dirlist; + if (!filename.isDirectory()) { + LYXERR0("Directory '" << filename << "' does not exist!"); + return dirlist; + } + + QDir dir(toqstr(filename.absoluteFilePath())); + + if (!ext.empty()) { + QString filter; + switch (ext[0]) { + case '.': filter = "*" + toqstr(ext); break; + case '*': filter = toqstr(ext); break; + default: filter = "*." + toqstr(ext); + } + dir.setNameFilters(QStringList(filter)); + LYXERR(Debug::FILES, "filtering on extension " + << fromqstr(filter) << " is requested."); + } + + QFileInfoList list = dir.entryInfoList(); + for (int i = 0; i != list.size(); ++i) { + FileName fi(fromqstr(list.at(i).absoluteFilePath())); + dirlist.push_back(fi); + LYXERR(Debug::FILES, "found file " << fi); + } + + return dirlist; +} + + } //namespace support } // namespace lyx diff --git a/src/support/filetools.h b/src/support/filetools.h index 6e3e412ec6..dce6e6979d 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -275,6 +275,9 @@ typedef std::pair cmd_ret; cmd_ret const runCommand(std::string const & cmd); +/// \return list other files in the directory having optional extension 'ext'. +std::vector dirList(FileName const & filename, std::string const & ext); + } // namespace support } // namespace lyx