23
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
25
** If you are unsure which license is appropriate for your use, please
26
** contact the sales department at qt-sales@nokia.com.
26
** contact the sales department at http://www.qtsoftware.com/contact.
28
28
**************************************************************************/
35
35
#include <QtCore/QFutureInterface>
36
36
#include <QtCore/QtConcurrentRun>
37
37
#include <QtCore/QRegExp>
38
#include <QtGui/QApplication>
38
#include <QtCore/QCoreApplication>
40
40
#include <qtconcurrent/runextensions.h>
42
42
using namespace Core::Utils;
44
static inline QString msgCanceled(const QString &searchTerm, int numMatches, int numFilesSearched)
46
return QCoreApplication::translate("Core::Utils::FileSearch",
47
"%1: canceled. %n occurrences found in %2 files.",
48
0, QCoreApplication::CodecForTr, numMatches).
49
arg(searchTerm).arg(numFilesSearched);
52
static inline QString msgFound(const QString &searchTerm, int numMatches, int numFilesSearched)
54
return QCoreApplication::translate("Core::Utils::FileSearch",
55
"%1: %n occurrences found in %2 files.",
56
0, QCoreApplication::CodecForTr, numMatches).
57
arg(searchTerm).arg(numFilesSearched);
60
static inline QString msgFound(const QString &searchTerm, int numMatches, int numFilesSearched, int filesSize)
62
return QCoreApplication::translate("Core::Utils::FileSearch",
63
"%1: %n occurrences found in %2 of %3 files.",
64
0, QCoreApplication::CodecForTr, numMatches).
65
arg(searchTerm).arg(numFilesSearched).arg(filesSize);
46
70
void runFileSearch(QFutureInterface<FileSearchResult> &future,
71
95
if (future.isPaused())
72
96
future.waitForResume();
73
97
if (future.isCanceled()) {
74
future.setProgressValueAndText(numFilesSearched,
75
qApp->translate("FileSearch", "%1: canceled. %2 occurrences found in %3 files.").
76
arg(searchTerm).arg(numMatches).arg(numFilesSearched));
98
future.setProgressValueAndText(numFilesSearched, msgCanceled(searchTerm, numMatches, numFilesSearched));
146
168
firstChunk = false;
148
170
++numFilesSearched;
149
future.setProgressValueAndText(numFilesSearched, qApp->translate("FileSearch", "%1: %2 occurrences found in %3 of %4 files.").
150
arg(searchTerm).arg(numMatches).arg(numFilesSearched).arg(files.size()));
171
future.setProgressValueAndText(numFilesSearched, msgFound(searchTerm, numMatches, numFilesSearched, files.size()));
152
173
if (!future.isCanceled())
153
future.setProgressValueAndText(numFilesSearched, qApp->translate("FileSearch", "%1: %2 occurrences found in %3 files.").
154
arg(searchTerm).arg(numMatches).arg(numFilesSearched));
174
future.setProgressValueAndText(numFilesSearched, msgFound(searchTerm, numMatches, numFilesSearched));
157
177
void runFileSearchRegExp(QFutureInterface<FileSearchResult> &future,
163
183
int numFilesSearched = 0;
164
184
int numMatches = 0;
165
185
if (flags & QTextDocument::FindWholeWords)
166
searchTerm = QString("\\b%1\\b").arg(searchTerm);
167
Qt::CaseSensitivity caseSensitivity = (flags & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive;
168
QRegExp expression(searchTerm, caseSensitivity);
186
searchTerm = QString::fromLatin1("\\b%1\\b").arg(searchTerm);
187
const Qt::CaseSensitivity caseSensitivity = (flags & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive;
188
const QRegExp expression(searchTerm, caseSensitivity);
170
foreach (QString s, files) {
190
foreach (const QString &s, files) {
171
191
if (future.isPaused())
172
192
future.waitForResume();
173
193
if (future.isCanceled()) {
174
future.setProgressValueAndText(numFilesSearched,
175
qApp->translate("FileSearch", "%1: canceled. %2 occurrences found in %3 files.").
176
arg(searchTerm).arg(numMatches).arg(numFilesSearched));
194
future.setProgressValueAndText(numFilesSearched, msgCanceled(searchTerm, numMatches, numFilesSearched));
195
213
++numFilesSearched;
196
future.setProgressValueAndText(numFilesSearched, qApp->translate("FileSearch", "%1: %2 occurrences found in %3 of %4 files.").
197
arg(searchTerm).arg(numMatches).arg(numFilesSearched).arg(files.size()));
214
future.setProgressValueAndText(numFilesSearched, msgFound(searchTerm, numMatches, numFilesSearched, files.size()));
199
216
if (!future.isCanceled())
200
future.setProgressValueAndText(numFilesSearched, qApp->translate("FileSearch", "%1: %2 occurrences found in %3 files.").
201
arg(searchTerm).arg(numMatches).arg(numFilesSearched));
217
future.setProgressValueAndText(numFilesSearched, msgFound(searchTerm, numMatches, numFilesSearched));