2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-12-09 13:33:12 +01:00
|
|
|
#include "algorithm.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "filesearch.h"
|
2016-12-09 13:33:12 +01:00
|
|
|
#include "fileutils.h"
|
2016-02-08 11:31:02 +01:00
|
|
|
#include "mapreduce.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
2015-05-15 03:48:07 +02:00
|
|
|
#include <QMutex>
|
2016-12-09 13:33:12 +01:00
|
|
|
#include <QRegExp>
|
2015-05-15 03:48:07 +02:00
|
|
|
#include <QRegularExpression>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTextCodec>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-03-23 16:31:08 +01:00
|
|
|
#include <cctype>
|
2015-03-23 10:56:39 +01:00
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-30 16:09:57 +02:00
|
|
|
static inline QString msgCanceled(const QString &searchTerm, int numMatches, int numFilesSearched)
|
|
|
|
|
{
|
2009-10-05 11:06:05 +02:00
|
|
|
return QCoreApplication::translate("Utils::FileSearch",
|
2009-04-30 16:09:57 +02:00
|
|
|
"%1: canceled. %n occurrences found in %2 files.",
|
2014-08-28 17:33:47 +02:00
|
|
|
0, numMatches).arg(searchTerm).arg(numFilesSearched);
|
2009-04-30 16:09:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString msgFound(const QString &searchTerm, int numMatches, int numFilesSearched)
|
|
|
|
|
{
|
2009-10-05 11:06:05 +02:00
|
|
|
return QCoreApplication::translate("Utils::FileSearch",
|
2009-04-30 16:09:57 +02:00
|
|
|
"%1: %n occurrences found in %2 files.",
|
2014-08-28 17:33:47 +02:00
|
|
|
0, numMatches).arg(searchTerm).arg(numFilesSearched);
|
2009-04-30 16:09:57 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace {
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2011-10-27 14:25:18 +02:00
|
|
|
const int MAX_LINE_SIZE = 400;
|
|
|
|
|
|
|
|
|
|
QString clippedText(const QString &text, int maxLength)
|
|
|
|
|
{
|
|
|
|
|
if (text.length() > maxLength)
|
|
|
|
|
return text.left(maxLength) + QChar(0x2026); // '...'
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 16:31:08 +01:00
|
|
|
// returns success
|
|
|
|
|
bool openStream(const QString &filePath, QTextCodec *encoding, QTextStream *stream, QFile *file,
|
|
|
|
|
QString *tempString,
|
|
|
|
|
const QMap<QString, QString> &fileToContentsMap)
|
|
|
|
|
{
|
|
|
|
|
if (fileToContentsMap.contains(filePath)) {
|
|
|
|
|
*tempString = fileToContentsMap.value(filePath);
|
|
|
|
|
stream->setString(tempString);
|
|
|
|
|
} else {
|
|
|
|
|
file->setFileName(filePath);
|
|
|
|
|
if (!file->open(QIODevice::ReadOnly))
|
|
|
|
|
return false;
|
|
|
|
|
stream->setDevice(file);
|
|
|
|
|
stream->setCodec(encoding);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-13 11:26:28 +02:00
|
|
|
class FileSearch
|
2008-12-02 14:09:21 +01:00
|
|
|
{
|
2015-03-23 10:56:39 +01:00
|
|
|
public:
|
|
|
|
|
FileSearch(const QString &searchTerm, QTextDocument::FindFlags flags,
|
2017-04-14 10:12:30 +02:00
|
|
|
const QMap<QString, QString> &fileToContentsMap);
|
2016-02-08 11:03:28 +01:00
|
|
|
void operator()(QFutureInterface<FileSearchResultList> &futureInterface,
|
|
|
|
|
const FileIterator::Item &item) const;
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2015-03-23 10:56:39 +01:00
|
|
|
private:
|
2015-03-23 16:31:08 +01:00
|
|
|
QMap<QString, QString> fileToContentsMap;
|
2015-03-23 10:56:39 +01:00
|
|
|
QString searchTermLower;
|
|
|
|
|
QString searchTermUpper;
|
|
|
|
|
int termMaxIndex;
|
|
|
|
|
const QChar *termData;
|
|
|
|
|
const QChar *termDataLower;
|
|
|
|
|
const QChar *termDataUpper;
|
|
|
|
|
bool caseSensitive;
|
|
|
|
|
bool wholeWord;
|
|
|
|
|
};
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2015-05-13 11:26:28 +02:00
|
|
|
class FileSearchRegExp
|
2015-03-23 10:56:39 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FileSearchRegExp(const QString &searchTerm, QTextDocument::FindFlags flags,
|
2017-04-14 10:12:30 +02:00
|
|
|
const QMap<QString, QString> &fileToContentsMap);
|
2015-12-16 14:58:04 +01:00
|
|
|
FileSearchRegExp(const FileSearchRegExp &other);
|
2016-02-08 11:03:28 +01:00
|
|
|
void operator()(QFutureInterface<FileSearchResultList> &futureInterface,
|
|
|
|
|
const FileIterator::Item &item) const;
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2015-03-23 10:56:39 +01:00
|
|
|
private:
|
2015-05-15 03:48:07 +02:00
|
|
|
QRegularExpressionMatch doGuardedMatch(const QString &line, int offset) const;
|
|
|
|
|
|
2015-03-23 16:31:08 +01:00
|
|
|
QMap<QString, QString> fileToContentsMap;
|
2015-05-15 03:48:07 +02:00
|
|
|
QRegularExpression expression;
|
|
|
|
|
mutable QMutex mutex;
|
2015-03-23 10:56:39 +01:00
|
|
|
};
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2015-03-23 10:56:39 +01:00
|
|
|
FileSearch::FileSearch(const QString &searchTerm, QTextDocument::FindFlags flags,
|
2017-04-14 10:12:30 +02:00
|
|
|
const QMap<QString, QString> &fileToContentsMap)
|
2015-03-23 10:56:39 +01:00
|
|
|
{
|
2015-03-23 16:31:08 +01:00
|
|
|
this->fileToContentsMap = fileToContentsMap;
|
2015-03-23 10:56:39 +01:00
|
|
|
caseSensitive = (flags & QTextDocument::FindCaseSensitively);
|
|
|
|
|
wholeWord = (flags & QTextDocument::FindWholeWords);
|
|
|
|
|
searchTermLower = searchTerm.toLower();
|
|
|
|
|
searchTermUpper = searchTerm.toUpper();
|
|
|
|
|
termMaxIndex = searchTerm.length() - 1;
|
|
|
|
|
termData = searchTerm.constData();
|
|
|
|
|
termDataLower = searchTermLower.constData();
|
|
|
|
|
termDataUpper = searchTermUpper.constData();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 11:03:28 +01:00
|
|
|
void FileSearch::operator()(QFutureInterface<FileSearchResultList> &futureInterface,
|
|
|
|
|
const FileIterator::Item &item) const
|
2015-03-23 10:56:39 +01:00
|
|
|
{
|
2015-12-16 14:58:04 +01:00
|
|
|
if (futureInterface.isCanceled())
|
2016-02-08 11:03:28 +01:00
|
|
|
return;
|
|
|
|
|
futureInterface.setProgressRange(0, 1);
|
|
|
|
|
futureInterface.setProgressValue(0);
|
|
|
|
|
FileSearchResultList results;
|
2015-03-23 16:31:08 +01:00
|
|
|
QFile file;
|
|
|
|
|
QTextStream stream;
|
|
|
|
|
QString tempString;
|
2016-02-08 11:03:28 +01:00
|
|
|
if (!openStream(item.filePath, item.encoding, &stream, &file, &tempString, fileToContentsMap)) {
|
|
|
|
|
futureInterface.cancel(); // failure
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-03-23 16:31:08 +01:00
|
|
|
int lineNr = 0;
|
2010-10-11 11:34:17 +02:00
|
|
|
|
2015-03-23 10:56:39 +01:00
|
|
|
while (!stream.atEnd()) {
|
|
|
|
|
++lineNr;
|
|
|
|
|
const QString chunk = stream.readLine();
|
|
|
|
|
const QString resultItemText = clippedText(chunk, MAX_LINE_SIZE);
|
|
|
|
|
int chunkLength = chunk.length();
|
|
|
|
|
const QChar *chunkPtr = chunk.constData();
|
|
|
|
|
const QChar *chunkEnd = chunkPtr + chunkLength - 1;
|
|
|
|
|
for (const QChar *regionPtr = chunkPtr; regionPtr + termMaxIndex <= chunkEnd; ++regionPtr) {
|
|
|
|
|
const QChar *regionEnd = regionPtr + termMaxIndex;
|
|
|
|
|
if ( /* optimization check for start and end of region */
|
|
|
|
|
// case sensitive
|
|
|
|
|
(caseSensitive && *regionPtr == termData[0]
|
|
|
|
|
&& *regionEnd == termData[termMaxIndex])
|
|
|
|
|
||
|
|
|
|
|
// case insensitive
|
|
|
|
|
(!caseSensitive && (*regionPtr == termDataLower[0]
|
|
|
|
|
|| *regionPtr == termDataUpper[0])
|
|
|
|
|
&& (*regionEnd == termDataLower[termMaxIndex]
|
|
|
|
|
|| *regionEnd == termDataUpper[termMaxIndex]))
|
|
|
|
|
) {
|
|
|
|
|
bool equal = true;
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2015-03-23 10:56:39 +01:00
|
|
|
// whole word check
|
|
|
|
|
const QChar *beforeRegion = regionPtr - 1;
|
|
|
|
|
const QChar *afterRegion = regionEnd + 1;
|
|
|
|
|
if (wholeWord
|
|
|
|
|
&& (((beforeRegion >= chunkPtr)
|
|
|
|
|
&& (beforeRegion->isLetterOrNumber()
|
|
|
|
|
|| ((*beforeRegion) == QLatin1Char('_'))))
|
|
|
|
|
||
|
|
|
|
|
((afterRegion <= chunkEnd)
|
|
|
|
|
&& (afterRegion->isLetterOrNumber()
|
|
|
|
|
|| ((*afterRegion) == QLatin1Char('_'))))
|
2010-10-11 11:34:17 +02:00
|
|
|
)) {
|
2015-03-23 10:56:39 +01:00
|
|
|
equal = false;
|
|
|
|
|
} else {
|
|
|
|
|
// check all chars
|
|
|
|
|
int regionIndex = 1;
|
|
|
|
|
for (const QChar *regionCursor = regionPtr + 1;
|
|
|
|
|
regionCursor < regionEnd;
|
|
|
|
|
++regionCursor, ++regionIndex) {
|
|
|
|
|
if ( // case sensitive
|
|
|
|
|
(caseSensitive
|
|
|
|
|
&& *regionCursor != termData[regionIndex])
|
|
|
|
|
||
|
|
|
|
|
// case insensitive
|
|
|
|
|
(!caseSensitive
|
|
|
|
|
&& *regionCursor != termDataLower[regionIndex]
|
|
|
|
|
&& *regionCursor != termDataUpper[regionIndex])
|
|
|
|
|
) {
|
|
|
|
|
equal = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-02 14:09:21 +01:00
|
|
|
}
|
2015-03-23 10:56:39 +01:00
|
|
|
}
|
|
|
|
|
if (equal) {
|
2015-03-23 16:31:08 +01:00
|
|
|
results << FileSearchResult(item.filePath, lineNr, resultItemText,
|
2015-03-23 10:56:39 +01:00
|
|
|
regionPtr - chunkPtr, termMaxIndex + 1,
|
|
|
|
|
QStringList());
|
|
|
|
|
regionPtr += termMaxIndex; // another +1 done by for-loop
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-16 14:58:04 +01:00
|
|
|
if (futureInterface.isPaused())
|
|
|
|
|
futureInterface.waitForResume();
|
|
|
|
|
if (futureInterface.isCanceled())
|
2015-03-23 10:56:39 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2015-03-23 16:31:08 +01:00
|
|
|
if (file.isOpen())
|
|
|
|
|
file.close();
|
2016-02-08 11:03:28 +01:00
|
|
|
if (!futureInterface.isCanceled()) {
|
|
|
|
|
futureInterface.reportResult(results);
|
|
|
|
|
futureInterface.setProgressValue(1);
|
|
|
|
|
}
|
2015-03-23 10:56:39 +01:00
|
|
|
}
|
2010-10-11 11:34:17 +02:00
|
|
|
|
2015-03-23 10:56:39 +01:00
|
|
|
FileSearchRegExp::FileSearchRegExp(const QString &searchTerm, QTextDocument::FindFlags flags,
|
2017-04-14 10:12:30 +02:00
|
|
|
const QMap<QString, QString> &fileToContentsMap)
|
2015-03-23 10:56:39 +01:00
|
|
|
{
|
2015-03-23 16:31:08 +01:00
|
|
|
this->fileToContentsMap = fileToContentsMap;
|
2015-03-23 10:56:39 +01:00
|
|
|
QString term = searchTerm;
|
|
|
|
|
if (flags & QTextDocument::FindWholeWords)
|
|
|
|
|
term = QString::fromLatin1("\\b%1\\b").arg(term);
|
2015-05-15 03:48:07 +02:00
|
|
|
const QRegularExpression::PatternOptions patternOptions = (flags & QTextDocument::FindCaseSensitively)
|
|
|
|
|
? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption;
|
|
|
|
|
expression = QRegularExpression(term, patternOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 14:58:04 +01:00
|
|
|
FileSearchRegExp::FileSearchRegExp(const FileSearchRegExp &other)
|
|
|
|
|
: fileToContentsMap(other.fileToContentsMap),
|
|
|
|
|
expression(other.expression)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-15 03:48:07 +02:00
|
|
|
QRegularExpressionMatch FileSearchRegExp::doGuardedMatch(const QString &line, int offset) const
|
|
|
|
|
{
|
|
|
|
|
QMutexLocker lock(&mutex);
|
|
|
|
|
return expression.match(line, offset);
|
2015-03-23 10:56:39 +01:00
|
|
|
}
|
2010-10-11 11:34:17 +02:00
|
|
|
|
2016-02-08 11:03:28 +01:00
|
|
|
void FileSearchRegExp::operator()(QFutureInterface<FileSearchResultList> &futureInterface,
|
|
|
|
|
const FileIterator::Item &item) const
|
2015-03-23 10:56:39 +01:00
|
|
|
{
|
2015-12-16 14:58:04 +01:00
|
|
|
if (futureInterface.isCanceled())
|
2016-02-08 11:03:28 +01:00
|
|
|
return;
|
|
|
|
|
futureInterface.setProgressRange(0, 1);
|
|
|
|
|
futureInterface.setProgressValue(0);
|
|
|
|
|
FileSearchResultList results;
|
2015-03-23 16:31:08 +01:00
|
|
|
QFile file;
|
|
|
|
|
QTextStream stream;
|
|
|
|
|
QString tempString;
|
2016-02-08 11:03:28 +01:00
|
|
|
if (!openStream(item.filePath, item.encoding, &stream, &file, &tempString, fileToContentsMap)) {
|
|
|
|
|
futureInterface.cancel(); // failure
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-03-23 16:31:08 +01:00
|
|
|
int lineNr = 0;
|
2010-10-11 11:34:17 +02:00
|
|
|
|
2015-03-23 10:56:39 +01:00
|
|
|
QString line;
|
2015-05-15 03:48:07 +02:00
|
|
|
QRegularExpressionMatch match;
|
2015-03-23 10:56:39 +01:00
|
|
|
while (!stream.atEnd()) {
|
2015-04-02 17:02:27 +02:00
|
|
|
++lineNr;
|
2015-03-23 10:56:39 +01:00
|
|
|
line = stream.readLine();
|
|
|
|
|
const QString resultItemText = clippedText(line, MAX_LINE_SIZE);
|
|
|
|
|
int lengthOfLine = line.size();
|
|
|
|
|
int pos = 0;
|
2015-05-15 03:48:07 +02:00
|
|
|
while ((match = doGuardedMatch(line, pos)).hasMatch()) {
|
|
|
|
|
pos = match.capturedStart();
|
2015-03-23 16:31:08 +01:00
|
|
|
results << FileSearchResult(item.filePath, lineNr, resultItemText,
|
2015-05-15 03:48:07 +02:00
|
|
|
pos, match.capturedLength(),
|
|
|
|
|
match.capturedTexts());
|
|
|
|
|
if (match.capturedLength() == 0)
|
2015-03-23 10:56:39 +01:00
|
|
|
break;
|
2015-05-15 03:48:07 +02:00
|
|
|
pos += match.capturedLength();
|
2015-03-23 10:56:39 +01:00
|
|
|
if (pos >= lengthOfLine)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-12-16 14:58:04 +01:00
|
|
|
if (futureInterface.isPaused())
|
|
|
|
|
futureInterface.waitForResume();
|
|
|
|
|
if (futureInterface.isCanceled())
|
2015-03-23 10:56:39 +01:00
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2015-03-23 16:31:08 +01:00
|
|
|
if (file.isOpen())
|
|
|
|
|
file.close();
|
2016-02-08 11:03:28 +01:00
|
|
|
if (!futureInterface.isCanceled()) {
|
|
|
|
|
futureInterface.reportResult(results);
|
|
|
|
|
futureInterface.setProgressValue(1);
|
|
|
|
|
}
|
2008-12-02 14:09:21 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-12-16 14:58:04 +01:00
|
|
|
struct SearchState
|
2008-12-02 14:09:21 +01:00
|
|
|
{
|
2015-12-16 14:58:04 +01:00
|
|
|
SearchState(const QString &term, FileIterator *iterator) : searchTerm(term), files(iterator) {}
|
|
|
|
|
QString searchTerm;
|
|
|
|
|
FileIterator *files = 0;
|
|
|
|
|
FileSearchResultList cachedResults;
|
|
|
|
|
int numFilesSearched = 0;
|
|
|
|
|
int numMatches = 0;
|
2015-03-23 16:31:08 +01:00
|
|
|
};
|
2015-03-23 10:56:39 +01:00
|
|
|
|
2015-12-16 14:58:04 +01:00
|
|
|
SearchState initFileSearch(QFutureInterface<FileSearchResultList> &futureInterface,
|
|
|
|
|
const QString &searchTerm, FileIterator *files)
|
2015-03-23 16:31:08 +01:00
|
|
|
{
|
2015-12-16 14:58:04 +01:00
|
|
|
futureInterface.setProgressRange(0, files->maxProgress());
|
|
|
|
|
futureInterface.setProgressValueAndText(files->currentProgress(), msgFound(searchTerm, 0, 0));
|
|
|
|
|
return SearchState(searchTerm, files);
|
2015-03-23 16:31:08 +01:00
|
|
|
}
|
2015-03-23 10:56:39 +01:00
|
|
|
|
2015-12-16 14:58:04 +01:00
|
|
|
void collectSearchResults(QFutureInterface<FileSearchResultList> &futureInterface,
|
|
|
|
|
SearchState &state,
|
|
|
|
|
const FileSearchResultList &results)
|
|
|
|
|
{
|
|
|
|
|
state.numMatches += results.size();
|
|
|
|
|
state.cachedResults << results;
|
|
|
|
|
state.numFilesSearched += 1;
|
|
|
|
|
if (futureInterface.isProgressUpdateNeeded()
|
|
|
|
|
|| futureInterface.progressValue() == 0 /*workaround for regression in Qt*/) {
|
|
|
|
|
if (!state.cachedResults.isEmpty()) {
|
|
|
|
|
futureInterface.reportResult(state.cachedResults);
|
|
|
|
|
state.cachedResults.clear();
|
|
|
|
|
}
|
|
|
|
|
futureInterface.setProgressRange(0, state.files->maxProgress());
|
|
|
|
|
futureInterface.setProgressValueAndText(state.files->currentProgress(),
|
|
|
|
|
msgFound(state.searchTerm,
|
|
|
|
|
state.numMatches,
|
|
|
|
|
state.numFilesSearched));
|
2015-03-23 16:31:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-23 10:56:39 +01:00
|
|
|
|
2015-12-16 14:58:04 +01:00
|
|
|
void cleanUpFileSearch(QFutureInterface<FileSearchResultList> &futureInterface,
|
|
|
|
|
SearchState &state)
|
2015-03-23 16:31:08 +01:00
|
|
|
{
|
2015-12-16 14:58:04 +01:00
|
|
|
if (!state.cachedResults.isEmpty()) {
|
|
|
|
|
futureInterface.reportResult(state.cachedResults);
|
|
|
|
|
state.cachedResults.clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2015-12-16 14:58:04 +01:00
|
|
|
if (futureInterface.isCanceled()) {
|
|
|
|
|
futureInterface.setProgressValueAndText(state.files->currentProgress(),
|
|
|
|
|
msgCanceled(state.searchTerm,
|
|
|
|
|
state.numMatches,
|
|
|
|
|
state.numFilesSearched));
|
|
|
|
|
} else {
|
|
|
|
|
futureInterface.setProgressValueAndText(state.files->currentProgress(),
|
|
|
|
|
msgFound(state.searchTerm,
|
|
|
|
|
state.numMatches,
|
|
|
|
|
state.numFilesSearched));
|
2010-06-25 10:18:44 +02:00
|
|
|
}
|
2015-12-16 14:58:04 +01:00
|
|
|
delete state.files;
|
2015-03-23 10:56:39 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
2010-06-25 09:16:30 +02:00
|
|
|
QFuture<FileSearchResultList> Utils::findInFiles(const QString &searchTerm, FileIterator *files,
|
2017-04-14 10:12:30 +02:00
|
|
|
QTextDocument::FindFlags flags, const QMap<QString, QString> &fileToContentsMap)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-02-15 16:26:11 +01:00
|
|
|
return mapReduce(files->begin(), files->end(),
|
2015-12-16 14:58:04 +01:00
|
|
|
[searchTerm, files](QFutureInterface<FileSearchResultList> &futureInterface) {
|
|
|
|
|
return initFileSearch(futureInterface, searchTerm, files);
|
|
|
|
|
},
|
|
|
|
|
FileSearch(searchTerm, flags, fileToContentsMap),
|
|
|
|
|
&collectSearchResults,
|
|
|
|
|
&cleanUpFileSearch);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-06-25 09:16:30 +02:00
|
|
|
QFuture<FileSearchResultList> Utils::findInFilesRegExp(const QString &searchTerm, FileIterator *files,
|
2017-04-14 10:12:30 +02:00
|
|
|
QTextDocument::FindFlags flags, const QMap<QString, QString> &fileToContentsMap)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-02-15 16:26:11 +01:00
|
|
|
return mapReduce(files->begin(), files->end(),
|
2015-12-16 14:58:04 +01:00
|
|
|
[searchTerm, files](QFutureInterface<FileSearchResultList> &futureInterface) {
|
|
|
|
|
return initFileSearch(futureInterface, searchTerm, files);
|
|
|
|
|
},
|
|
|
|
|
FileSearchRegExp(searchTerm, flags, fileToContentsMap),
|
|
|
|
|
&collectSearchResults,
|
|
|
|
|
&cleanUpFileSearch);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-06-11 08:57:38 +02:00
|
|
|
|
|
|
|
|
QString Utils::expandRegExpReplacement(const QString &replaceText, const QStringList &capturedTexts)
|
|
|
|
|
{
|
2010-11-03 11:37:04 +01:00
|
|
|
// handles \1 \\ \& & \t \n
|
2010-06-11 08:57:38 +02:00
|
|
|
QString result;
|
2010-10-19 08:55:55 +02:00
|
|
|
const int numCaptures = capturedTexts.size() - 1;
|
2010-06-11 08:57:38 +02:00
|
|
|
for (int i = 0; i < replaceText.length(); ++i) {
|
|
|
|
|
QChar c = replaceText.at(i);
|
|
|
|
|
if (c == QLatin1Char('\\') && i < replaceText.length() - 1) {
|
|
|
|
|
c = replaceText.at(++i);
|
|
|
|
|
if (c == QLatin1Char('\\')) {
|
|
|
|
|
result += QLatin1Char('\\');
|
|
|
|
|
} else if (c == QLatin1Char('&')) {
|
|
|
|
|
result += QLatin1Char('&');
|
2010-10-06 16:17:30 +02:00
|
|
|
} else if (c == QLatin1Char('t')) {
|
|
|
|
|
result += QLatin1Char('\t');
|
2010-11-03 11:37:04 +01:00
|
|
|
} else if (c == QLatin1Char('n')) {
|
|
|
|
|
result += QLatin1Char('\n');
|
2010-06-11 08:57:38 +02:00
|
|
|
} else if (c.isDigit()) {
|
|
|
|
|
int index = c.unicode()-'1';
|
|
|
|
|
if (index < numCaptures) {
|
|
|
|
|
result += capturedTexts.at(index+1);
|
|
|
|
|
} else {
|
|
|
|
|
result += QLatin1Char('\\');
|
|
|
|
|
result += c;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result += QLatin1Char('\\');
|
|
|
|
|
result += c;
|
|
|
|
|
}
|
|
|
|
|
} else if (c == QLatin1Char('&')) {
|
|
|
|
|
result += capturedTexts.at(0);
|
|
|
|
|
} else {
|
|
|
|
|
result += c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2010-06-24 15:44:46 +02:00
|
|
|
|
2012-11-30 16:15:07 +01:00
|
|
|
namespace Utils {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
QString matchCaseReplacement(const QString &originalText, const QString &replaceText)
|
|
|
|
|
{
|
2014-03-03 14:27:42 +01:00
|
|
|
if (originalText.isEmpty() || replaceText.isEmpty())
|
2013-02-24 18:59:26 -05:00
|
|
|
return replaceText;
|
|
|
|
|
|
2012-11-30 16:15:07 +01:00
|
|
|
//Now proceed with actual case matching
|
|
|
|
|
bool firstIsUpperCase = originalText.at(0).isUpper();
|
|
|
|
|
bool firstIsLowerCase = originalText.at(0).isLower();
|
|
|
|
|
bool restIsLowerCase = true; // to be verified
|
|
|
|
|
bool restIsUpperCase = true; // to be verified
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < originalText.length(); ++i) {
|
|
|
|
|
if (originalText.at(i).isUpper())
|
|
|
|
|
restIsLowerCase = false;
|
|
|
|
|
else if (originalText.at(i).isLower())
|
|
|
|
|
restIsUpperCase = false;
|
|
|
|
|
|
|
|
|
|
if (!restIsLowerCase && !restIsUpperCase)
|
2017-03-08 16:34:32 +01:00
|
|
|
break;
|
2012-11-30 16:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (restIsLowerCase) {
|
|
|
|
|
QString res = replaceText.toLower();
|
|
|
|
|
if (firstIsUpperCase)
|
|
|
|
|
res.replace(0, 1, res.at(0).toUpper());
|
|
|
|
|
return res;
|
2017-03-08 16:34:32 +01:00
|
|
|
} else if (restIsUpperCase) {
|
2012-11-30 16:15:07 +01:00
|
|
|
QString res = replaceText.toUpper();
|
|
|
|
|
if (firstIsLowerCase)
|
|
|
|
|
res.replace(0, 1, res.at(0).toLower());
|
|
|
|
|
return res;
|
2017-03-08 16:34:32 +01:00
|
|
|
} else {
|
|
|
|
|
return replaceText; // mixed
|
2012-11-30 16:15:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-12-09 13:33:12 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
static QList<QRegExp> filtersToRegExps(const QStringList &filters)
|
|
|
|
|
{
|
|
|
|
|
return Utils::transform(filters, [](const QString &filter) {
|
|
|
|
|
return QRegExp(filter, Qt::CaseInsensitive, QRegExp::Wildcard);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool matches(const QList<QRegExp> &exprList, const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
return Utils::anyOf(exprList, [&filePath](QRegExp reg) {
|
|
|
|
|
return (reg.exactMatch(filePath)
|
|
|
|
|
|| reg.exactMatch(Utils::FileName::fromString(filePath).fileName()));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool isFileIncluded(const QList<QRegExp> &filterRegs, const QList<QRegExp> &exclusionRegs,
|
|
|
|
|
const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
const bool isIncluded = filterRegs.isEmpty() || matches(filterRegs, filePath);
|
|
|
|
|
return isIncluded && (exclusionRegs.isEmpty() || !matches(exclusionRegs, filePath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::function<bool(const QString &)>
|
|
|
|
|
filterFileFunction(const QStringList &filters, const QStringList &exclusionFilters)
|
|
|
|
|
{
|
|
|
|
|
const QList<QRegExp> filterRegs = filtersToRegExps(filters);
|
|
|
|
|
const QList<QRegExp> exclusionRegs = filtersToRegExps(exclusionFilters);
|
|
|
|
|
return [filterRegs, exclusionRegs](const QString &filePath) {
|
|
|
|
|
return isFileIncluded(filterRegs, exclusionRegs, filePath);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::function<QStringList(const QStringList &)>
|
|
|
|
|
filterFilesFunction(const QStringList &filters, const QStringList &exclusionFilters)
|
|
|
|
|
{
|
|
|
|
|
const QList<QRegExp> filterRegs = filtersToRegExps(filters);
|
|
|
|
|
const QList<QRegExp> exclusionRegs = filtersToRegExps(exclusionFilters);
|
|
|
|
|
return [filterRegs, exclusionRegs](const QStringList &filePaths) {
|
|
|
|
|
return Utils::filtered(filePaths, [&filterRegs, &exclusionRegs](const QString &filePath) {
|
|
|
|
|
return isFileIncluded(filterRegs, exclusionRegs, filePath);
|
|
|
|
|
});
|
|
|
|
|
};
|
2012-11-30 16:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-23 15:42:36 +01:00
|
|
|
QStringList splitFilterUiText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
const QStringList parts = text.split(',');
|
|
|
|
|
const QStringList trimmedPortableParts = Utils::transform(parts, [](const QString &s) {
|
|
|
|
|
return QDir::fromNativeSeparators(s.trimmed());
|
|
|
|
|
});
|
|
|
|
|
return Utils::filtered(trimmedPortableParts, [](const QString &s) { return !s.isEmpty(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString msgFilePatternLabel()
|
|
|
|
|
{
|
|
|
|
|
return QCoreApplication::translate("Utils::FileSearch", "Fi&le pattern:");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString msgExclusionPatternLabel()
|
|
|
|
|
{
|
2017-03-04 19:09:51 +02:00
|
|
|
return QCoreApplication::translate("Utils::FileSearch", "Excl&usion pattern:");
|
2017-02-23 15:42:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString msgFilePatternToolTip()
|
|
|
|
|
{
|
|
|
|
|
return QCoreApplication::translate("Utils::FileSearch",
|
|
|
|
|
"List of comma separated wildcard filters. "
|
|
|
|
|
"Files with file name or full file path matching any filter are included.");
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 15:19:42 +01:00
|
|
|
QString matchCaseReplacement(const QString &originalText, const QString &replaceText)
|
2012-11-30 16:15:07 +01:00
|
|
|
{
|
|
|
|
|
if (originalText.isEmpty())
|
|
|
|
|
return replaceText;
|
|
|
|
|
|
|
|
|
|
//Find common prefix & suffix: these will be unaffected
|
|
|
|
|
const int replaceTextLen = replaceText.length();
|
|
|
|
|
const int originalTextLen = originalText.length();
|
|
|
|
|
|
|
|
|
|
int prefixLen = 0;
|
2013-02-24 18:59:26 -05:00
|
|
|
for (; prefixLen < replaceTextLen && prefixLen < originalTextLen; ++prefixLen)
|
2012-11-30 16:15:07 +01:00
|
|
|
if (replaceText.at(prefixLen).toLower() != originalText.at(prefixLen).toLower())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
int suffixLen = 0;
|
2013-02-24 18:59:26 -05:00
|
|
|
for (; suffixLen < replaceTextLen - prefixLen && suffixLen < originalTextLen - prefixLen; ++suffixLen)
|
2012-11-30 16:15:07 +01:00
|
|
|
if (replaceText.at(replaceTextLen - 1 - suffixLen).toLower() != originalText.at(originalTextLen- 1 - suffixLen).toLower())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//keep prefix and suffix, and do actual replacement on the 'middle' of the string
|
|
|
|
|
return originalText.left(prefixLen)
|
|
|
|
|
+ Internal::matchCaseReplacement(originalText.mid(prefixLen, originalTextLen - prefixLen - suffixLen),
|
|
|
|
|
replaceText.mid(prefixLen, replaceTextLen - prefixLen - suffixLen))
|
|
|
|
|
+ originalText.right(suffixLen);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-24 15:44:46 +02:00
|
|
|
// #pragma mark -- FileIterator
|
|
|
|
|
|
2015-12-16 14:58:04 +01:00
|
|
|
void FileIterator::advance(FileIterator::const_iterator *it) const
|
2015-03-23 15:19:42 +01:00
|
|
|
{
|
|
|
|
|
if (it->m_index < 0) // == end
|
|
|
|
|
return;
|
|
|
|
|
++it->m_index;
|
2015-12-16 14:58:04 +01:00
|
|
|
const_cast<FileIterator *>(this)->update(it->m_index);
|
2016-02-22 12:23:43 +01:00
|
|
|
if (it->m_index >= currentFileCount())
|
2015-03-23 15:19:42 +01:00
|
|
|
it->m_index = -1; // == end
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 14:58:04 +01:00
|
|
|
FileIterator::const_iterator FileIterator::begin() const
|
2010-06-24 15:44:46 +02:00
|
|
|
{
|
2015-12-16 14:58:04 +01:00
|
|
|
const_cast<FileIterator *>(this)->update(0);
|
2015-03-23 15:19:42 +01:00
|
|
|
if (currentFileCount() == 0)
|
|
|
|
|
return end();
|
2016-02-22 12:23:43 +01:00
|
|
|
return FileIterator::const_iterator(this, 0/*index*/);
|
2010-06-24 15:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 14:58:04 +01:00
|
|
|
FileIterator::const_iterator FileIterator::end() const
|
2015-03-23 15:19:42 +01:00
|
|
|
{
|
2016-02-22 12:23:43 +01:00
|
|
|
return FileIterator::const_iterator(this, -1/*end*/);
|
2015-03-23 15:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// #pragma mark -- FileListIterator
|
|
|
|
|
|
2017-04-14 10:12:30 +02:00
|
|
|
QTextCodec *encodingAt(const QList<QTextCodec *> &encodings, int index)
|
2016-02-22 12:23:43 +01:00
|
|
|
{
|
|
|
|
|
if (index >= 0 && index < encodings.size())
|
|
|
|
|
return encodings.at(index);
|
|
|
|
|
return QTextCodec::codecForLocale();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 15:19:42 +01:00
|
|
|
FileListIterator::FileListIterator(const QStringList &fileList,
|
|
|
|
|
const QList<QTextCodec *> encodings)
|
2016-02-22 12:23:43 +01:00
|
|
|
: m_maxIndex(-1)
|
2015-03-23 15:19:42 +01:00
|
|
|
{
|
2016-02-22 12:23:43 +01:00
|
|
|
m_items.reserve(fileList.size());
|
|
|
|
|
for (int i = 0; i < fileList.size(); ++i)
|
|
|
|
|
m_items.append(Item(fileList.at(i), encodingAt(encodings, i)));
|
2015-03-23 15:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileListIterator::update(int requestedIndex)
|
2010-06-24 15:44:46 +02:00
|
|
|
{
|
2015-03-23 15:19:42 +01:00
|
|
|
if (requestedIndex > m_maxIndex)
|
|
|
|
|
m_maxIndex = requestedIndex;
|
2010-06-24 15:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-23 15:19:42 +01:00
|
|
|
int FileListIterator::currentFileCount() const
|
2010-06-24 15:44:46 +02:00
|
|
|
{
|
2016-02-22 12:23:43 +01:00
|
|
|
return m_items.size();
|
2010-06-24 15:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 12:23:43 +01:00
|
|
|
const FileIterator::Item &FileListIterator::itemAt(int index) const
|
2010-06-24 15:44:46 +02:00
|
|
|
{
|
2016-02-22 12:23:43 +01:00
|
|
|
return m_items.at(index);
|
2010-06-24 15:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-23 15:19:42 +01:00
|
|
|
int FileListIterator::maxProgress() const
|
2010-06-24 15:44:46 +02:00
|
|
|
{
|
2016-02-22 12:23:43 +01:00
|
|
|
return m_items.size();
|
2010-06-24 15:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-23 15:19:42 +01:00
|
|
|
int FileListIterator::currentProgress() const
|
2010-06-24 15:44:46 +02:00
|
|
|
{
|
2015-03-23 15:19:42 +01:00
|
|
|
return m_maxIndex + 1;
|
2010-10-11 11:34:17 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-24 15:44:46 +02:00
|
|
|
// #pragma mark -- SubDirFileIterator
|
|
|
|
|
|
|
|
|
|
namespace {
|
2010-06-25 10:18:44 +02:00
|
|
|
const int MAX_PROGRESS = 1000;
|
2010-06-24 15:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 11:34:17 +02:00
|
|
|
SubDirFileIterator::SubDirFileIterator(const QStringList &directories, const QStringList &filters,
|
2016-12-09 13:33:12 +01:00
|
|
|
const QStringList &exclusionFilters, QTextCodec *encoding)
|
|
|
|
|
: m_filterFiles(filterFilesFunction(filters, exclusionFilters)),
|
|
|
|
|
m_progress(0)
|
2010-06-24 15:44:46 +02:00
|
|
|
{
|
2010-10-11 11:34:17 +02:00
|
|
|
m_encoding = (encoding == 0 ? QTextCodec::codecForLocale() : encoding);
|
2014-05-19 18:26:05 +03:00
|
|
|
qreal maxPer = qreal(MAX_PROGRESS) / directories.count();
|
2010-06-24 15:44:46 +02:00
|
|
|
foreach (const QString &directoryEntry, directories) {
|
|
|
|
|
if (!directoryEntry.isEmpty()) {
|
|
|
|
|
m_dirs.push(QDir(directoryEntry));
|
|
|
|
|
m_progressValues.push(maxPer);
|
|
|
|
|
m_processedValues.push(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 12:23:43 +01:00
|
|
|
SubDirFileIterator::~SubDirFileIterator()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_items);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 15:19:42 +01:00
|
|
|
void SubDirFileIterator::update(int index)
|
2010-06-24 15:44:46 +02:00
|
|
|
{
|
2016-02-22 12:23:43 +01:00
|
|
|
if (index < m_items.size())
|
2015-03-23 15:19:42 +01:00
|
|
|
return;
|
|
|
|
|
// collect files from the directories until we have enough for the given index
|
2016-02-22 12:23:43 +01:00
|
|
|
while (!m_dirs.isEmpty() && index >= m_items.size()) {
|
2010-06-24 15:44:46 +02:00
|
|
|
QDir dir = m_dirs.pop();
|
2010-10-19 08:55:55 +02:00
|
|
|
const qreal dirProgressMax = m_progressValues.pop();
|
|
|
|
|
const bool processed = m_processedValues.pop();
|
2010-06-24 15:44:46 +02:00
|
|
|
if (dir.exists()) {
|
2016-12-09 13:33:12 +01:00
|
|
|
const QString dirPath = dir.path();
|
2010-06-24 15:44:46 +02:00
|
|
|
QStringList subDirs;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!processed)
|
2010-06-24 15:44:46 +02:00
|
|
|
subDirs = dir.entryList(QDir::Dirs|QDir::Hidden|QDir::NoDotAndDotDot);
|
|
|
|
|
if (subDirs.isEmpty()) {
|
2016-12-09 13:33:12 +01:00
|
|
|
const QStringList allFileEntries = dir.entryList(QDir::Files|QDir::Hidden);
|
|
|
|
|
const QStringList allFilePaths = Utils::transform(allFileEntries,
|
|
|
|
|
[&dirPath](const QString &entry) {
|
|
|
|
|
return QString(dirPath + '/' + entry);
|
|
|
|
|
});
|
|
|
|
|
const QStringList filePaths = m_filterFiles(allFilePaths);
|
|
|
|
|
m_items.reserve(m_items.size() + filePaths.size());
|
|
|
|
|
Utils::reverseForeach(filePaths, [this](const QString &file) {
|
|
|
|
|
m_items.append(new Item(file, m_encoding));
|
|
|
|
|
});
|
2010-06-24 15:44:46 +02:00
|
|
|
m_progress += dirProgressMax;
|
|
|
|
|
} else {
|
2010-06-25 10:18:44 +02:00
|
|
|
qreal subProgress = dirProgressMax/(subDirs.size()+1);
|
2010-06-24 15:44:46 +02:00
|
|
|
m_dirs.push(dir);
|
2010-06-25 10:18:44 +02:00
|
|
|
m_progressValues.push(subProgress);
|
2010-06-24 15:44:46 +02:00
|
|
|
m_processedValues.push(true);
|
|
|
|
|
QStringListIterator it(subDirs);
|
|
|
|
|
it.toBack();
|
|
|
|
|
while (it.hasPrevious()) {
|
|
|
|
|
const QString &directory = it.previous();
|
2016-12-09 13:33:12 +01:00
|
|
|
m_dirs.push(QDir(dirPath + QLatin1Char('/') + directory));
|
2010-06-24 15:44:46 +02:00
|
|
|
m_progressValues.push(subProgress);
|
|
|
|
|
m_processedValues.push(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
m_progress += dirProgressMax;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-22 12:23:43 +01:00
|
|
|
if (index >= m_items.size())
|
2010-06-24 15:44:46 +02:00
|
|
|
m_progress = MAX_PROGRESS;
|
2015-03-23 15:19:42 +01:00
|
|
|
}
|
2010-06-24 15:44:46 +02:00
|
|
|
|
2015-03-23 15:19:42 +01:00
|
|
|
int SubDirFileIterator::currentFileCount() const
|
|
|
|
|
{
|
2016-02-22 12:23:43 +01:00
|
|
|
return m_items.size();
|
2015-03-23 15:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 12:23:43 +01:00
|
|
|
const FileIterator::Item &SubDirFileIterator::itemAt(int index) const
|
2015-03-23 15:19:42 +01:00
|
|
|
{
|
2016-02-22 12:23:43 +01:00
|
|
|
return *m_items.at(index);
|
2010-06-24 15:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SubDirFileIterator::maxProgress() const
|
|
|
|
|
{
|
|
|
|
|
return MAX_PROGRESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SubDirFileIterator::currentProgress() const
|
|
|
|
|
{
|
2010-06-25 10:18:44 +02:00
|
|
|
return qMin(qRound(m_progress), MAX_PROGRESS);
|
2010-06-24 15:44:46 +02:00
|
|
|
}
|
2010-10-11 11:34:17 +02:00
|
|
|
|
|
|
|
|
}
|