Peter Kümmel wrote:
Andre Poenitz wrote:
#include <ctime>
+#include <vector>
Looks like I have no chance to keep that out. First Abdel, now you ;-}
Sorry, didn't know that this header is that critical at this point.
I will look for a better solution.
Seriously. dirList() is used exactly once in out code, FileName.h gets
included in almost every file, yet quite a bit of the frontend does not
need <vector>. So I'd like to keep it out. Unfortunately, forward
declaration of vector is not as straightforward as e.g. for string and
ostream.
What about this patch?
Peter
Index: Converter.cpp
===================================================================
--- Converter.cpp (revision 21898)
+++ Converter.cpp (working copy)
@@ -519,7 +519,8 @@
string const to_base = removeExtension(to.absFilename());
string const to_extension = getExtension(to.absFilename());
- vector<FileName> const files =
FileName(path).dirList(getExtension(from.absFilename()));
+ vector<FileName> const files =
+ support::dirList(FileName(path),
getExtension(from.absFilename()));
for (vector<FileName>::const_iterator it = files.begin();
it != files.end(); ++it) {
string const from2 = it->absFilename();
Index: support/FileName.cpp
===================================================================
--- support/FileName.cpp (revision 21898)
+++ support/FileName.cpp (working copy)
@@ -326,37 +326,9 @@
}
-std::vector<FileName> FileName::dirList(std::string const & ext)
+docstring const FileName::absoluteFilePath() const
{
- std::vector<FileName> 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 @@
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));
}
Index: support/filetools.cpp
===================================================================
--- support/filetools.cpp (revision 21898)
+++ support/filetools.cpp (working copy)
@@ -934,5 +934,39 @@
return cmp;
}
+
+std::vector<FileName> dirList(FileName const & filename, std::string const &
ext)
+{
+ std::vector<FileName> 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
Index: support/FileName.h
===================================================================
--- support/FileName.h (revision 21898)
+++ support/FileName.h (working copy)
@@ -15,7 +15,6 @@
#include "support/strfwd.h"
#include <ctime>
-#include <vector>
namespace lyx {
@@ -139,12 +138,11 @@
/// change to a directory, return success
bool chdir() const;
-
- /// \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;
+
+ docstring const absoluteFilePath() const;
private:
///
Index: support/filetools.h
===================================================================
--- support/filetools.h (revision 21898)
+++ support/filetools.h (working copy)
@@ -275,7 +275,10 @@
cmd_ret const runCommand(std::string const & cmd);
+/// \return list other files in the directory having optional extension 'ext'.
+std::vector<FileName> dirList(FileName const & filename, std::string const &
ext);
+
} // namespace support
} // namespace lyx