From: hama Date: Tue, 2 Jun 2015 21:22:25 +0000 (+0200) Subject: ReFind: anti patterns (excluding filename patterns) X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=f50fefb0388fa5f3824b850071585727d5511506;p=reqt ReFind: anti patterns (excluding filename patterns) --- diff --git a/appl/refind/filefinder.cpp b/appl/refind/filefinder.cpp index 8a754b9..a6b7a99 100644 --- a/appl/refind/filefinder.cpp +++ b/appl/refind/filefinder.cpp @@ -20,6 +20,7 @@ FileFinder::FileFinder() : m_lines(0), m_patterns(), + m_antiPatterns(), m_minSize(0), m_maxSize(-1), m_youngerThan(), @@ -67,10 +68,11 @@ QString fileSize(int64_t size){ } /** * Returns the type of the file. + * * @param info the file info * @return a string describing the text */ -QString typeOf(QFileInfo& info){ +QString typeOf(const QFileInfo& info){ QString rc; if (info.isSymLink()){ if (info.isDir()) @@ -111,15 +113,30 @@ void FileFinder::fillTable(const QString& path, int depth, QTableWidget* table, entries = dir.entryInfoList(filters, QDir::NoSort); else entries = dir.entryInfoList(m_patterns, filters, QDir::NoSort); - QList ::iterator it; QString relativePath = ReQStringUtil::nativePath( path.mid(1 + m_baseDir.length())); QString node, ext; - + QList antiPatterns; + QStringList::const_iterator it3; + for (it3 = m_antiPatterns.begin(); it3 != m_antiPatterns.end(); ++it3){ + QString pattern(*it3); + antiPatterns.append(new QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard)); + } + QList::const_iterator it2; + QList ::const_iterator it; for (it = entries.begin(); it != entries.end(); ++it){ node = it->fileName(); if (node == "." || node == "..") continue; + bool ignore = false; + for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){ + if ((*it2)->indexIn(node) >= 0){ + ignore = true; + break; + } + } + if (ignore) + continue; if (depth >= m_minDepth && isValid(*it)){ if (m_lines >= table->rowCount()){ table->setRowCount(m_lines + 500); @@ -147,6 +164,9 @@ void FileFinder::fillTable(const QString& path, int depth, QTableWidget* table, m_lines++; } } + for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){ + delete *it2; + } if (depth < m_maxDepth || m_maxDepth < 0){ entries = dir.entryInfoList( QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDir::NoSort); @@ -287,7 +307,19 @@ void FileFinder::setOlderThan(const QDateTime& olderThan){ * @param patterns the patterns to set */ void FileFinder::setPatterns(const QStringList& patterns){ - m_patterns = patterns; + m_patterns.clear(); + m_antiPatterns.clear(); + QStringList::const_iterator it; + for (it = patterns.begin(); it != patterns.end(); ++it){ + QString pattern = *it; + if (pattern.startsWith("-")){ + if (pattern.length() > 1) + m_antiPatterns.append(pattern.mid(1)); + } else { + if (pattern.length() > 0) + m_patterns.append(pattern); + } + } } /** diff --git a/appl/refind/filefinder.hpp b/appl/refind/filefinder.hpp index b9a7ef9..5de9771 100644 --- a/appl/refind/filefinder.hpp +++ b/appl/refind/filefinder.hpp @@ -40,6 +40,7 @@ private: private: int m_lines; QStringList m_patterns; + QStringList m_antiPatterns; int64_t m_minSize; int64_t m_maxSize; QDateTime m_youngerThan; diff --git a/appl/refind/mainwindow.ui b/appl/refind/mainwindow.ui index 4f7bffc..3636517 100644 --- a/appl/refind/mainwindow.ui +++ b/appl/refind/mainwindow.ui @@ -163,7 +163,7 @@ - <html><head/><body><p>A comma (',') separated list of filename patterns</p><p>Example: *.txt,*.odt</p></body></html> + <html><head/><body><p>A comma (',') separated list of filename patterns. A prefix of '-' means inversion: if a filename matches it will not be found.</p><p>Example: *.txt,*.odt</p></body></html> true