OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / libs / utils / filesearch.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef FILESEARCH_H
35 #define FILESEARCH_H
36
37 #include "utils_global.h"
38
39 #include <QtCore/QStringList>
40 #include <QtCore/QFuture>
41 #include <QtCore/QMap>
42 #include <QtCore/QStack>
43 #include <QtCore/QDir>
44 #include <QtCore/QTextCodec>
45 #include <QtGui/QTextDocument>
46
47 namespace Utils {
48
49 class QTCREATOR_UTILS_EXPORT FileIterator
50 {
51 public:
52     FileIterator();
53     explicit FileIterator(const QStringList &fileList,
54                           const QList<QTextCodec *> encodings);
55     ~FileIterator();
56
57     virtual bool hasNext() const;
58     virtual QString next();
59     virtual QTextCodec *encoding() const;
60     virtual int maxProgress() const;
61     virtual int currentProgress() const;
62
63 private:
64     QStringList m_list;
65     QStringListIterator *m_iterator;
66     QList<QTextCodec *> m_encodings;
67     int m_index;
68 };
69
70 class QTCREATOR_UTILS_EXPORT SubDirFileIterator : public FileIterator
71 {
72 public:
73     SubDirFileIterator(const QStringList &directories, const QStringList &filters,
74                        QTextCodec *encoding = 0);
75
76     bool hasNext() const;
77     QString next();
78     QTextCodec *encoding() const;
79     int maxProgress() const;
80     int currentProgress() const;
81
82 private:
83     QStringList m_filters;
84     QTextCodec *m_encoding;
85     mutable QStack<QDir> m_dirs;
86     mutable QStack<qreal> m_progressValues;
87     mutable QStack<bool> m_processedValues;
88     mutable qreal m_progress;
89     mutable QStringList m_currentFiles;
90 };
91
92 class QTCREATOR_UTILS_EXPORT FileSearchResult
93 {
94 public:
95     FileSearchResult() {}
96     FileSearchResult(QString fileName, int lineNumber, QString matchingLine,
97                      int matchStart, int matchLength,
98                      QStringList regexpCapturedTexts)
99             : fileName(fileName),
100             lineNumber(lineNumber),
101             matchingLine(matchingLine),
102             matchStart(matchStart),
103             matchLength(matchLength),
104             regexpCapturedTexts(regexpCapturedTexts)
105     {
106     }
107     QString fileName;
108     int lineNumber;
109     QString matchingLine;
110     int matchStart;
111     int matchLength;
112     QStringList regexpCapturedTexts;
113 };
114
115 typedef QList<FileSearchResult> FileSearchResultList;
116
117 QTCREATOR_UTILS_EXPORT QFuture<FileSearchResultList> findInFiles(const QString &searchTerm, FileIterator *files,
118     QTextDocument::FindFlags flags, QMap<QString, QString> fileToContentsMap = QMap<QString, QString>());
119
120 QTCREATOR_UTILS_EXPORT QFuture<FileSearchResultList> findInFilesRegExp(const QString &searchTerm, FileIterator *files,
121     QTextDocument::FindFlags flags, QMap<QString, QString> fileToContentsMap = QMap<QString, QString>());
122
123 QTCREATOR_UTILS_EXPORT QString expandRegExpReplacement(const QString &replaceText, const QStringList &capturedTexts);
124
125 } // namespace Utils
126
127 #endif // FILESEARCH_H