~ubuntu-branches/ubuntu/karmic/qtcreator/karmic-security

« back to all changes in this revision

Viewing changes to src/libs/utils/filesearch.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-07-19 16:23:52 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090719162352-oni0h8hrrkdd3sil
Tags: 1.2.1-1ubuntu1
* Merge from debian unstable (LP: #399414), remaining changes:
  - Add qt-creator transitional package.
* debian/control: Conflicts on qt-creator (<< 1.2.1-1ubuntu1).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
**
5
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6
6
**
7
 
** Contact:  Qt Software Information (qt-info@nokia.com)
 
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8
8
**
9
9
** Commercial Usage
10
10
**
23
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
24
**
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.
27
27
**
28
28
**************************************************************************/
29
29
 
35
35
#include <QtCore/QFutureInterface>
36
36
#include <QtCore/QtConcurrentRun>
37
37
#include <QtCore/QRegExp>
38
 
#include <QtGui/QApplication>
 
38
#include <QtCore/QCoreApplication>
39
39
 
40
40
#include <qtconcurrent/runextensions.h>
41
41
 
42
42
using namespace Core::Utils;
43
43
 
 
44
static inline QString msgCanceled(const QString &searchTerm, int numMatches, int numFilesSearched)
 
45
{
 
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);
 
50
}
 
51
 
 
52
static inline QString msgFound(const QString &searchTerm, int numMatches, int numFilesSearched)
 
53
{
 
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);
 
58
}
 
59
 
 
60
static inline QString msgFound(const QString &searchTerm, int numMatches, int numFilesSearched, int filesSize)
 
61
{
 
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);
 
66
}
 
67
 
44
68
namespace {
45
69
 
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));
77
99
            break;
78
100
        }
79
101
        QFile file(s);
146
168
            firstChunk = false;
147
169
        }
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()));
151
172
    }
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));
155
175
}
156
176
 
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);
169
189
 
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));
177
195
            break;
178
196
        }
179
197
        QFile file(s);
193
211
            ++lineNr;
194
212
        }
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()));
198
215
    }
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));
202
218
}
203
219
 
204
220
} // namespace