]> vaikene.ee Git - evaf/blob - src/apps/FileFinder/Engine/ifilefinder.h
Warning fixes and copyright update.
[evaf] / src / apps / FileFinder / Engine / ifilefinder.h
1 /**
2 * @file FileFinder/Engine/ifilefinder.h
3 * @brief Interface for the file finder engine
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011-2019 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #ifndef __FILEFINDER_ENGINE_IFILEFINDER_H
21 # define __FILEFINDER_ENGINE_IFILEFINDER_H
22
23 #include <QObject>
24 #include <QString>
25
26 namespace eVaf {
27 namespace FileFinder {
28
29 /**
30 * File filter defining patterns for file names and contents.
31 *
32 * File name patterns are wildcards (QRegExp::WildcardUnix). Multiple patterns can be separated by comma like,
33 * for example, "*.cpp,*.h". To include a comma in the pattern, escape it with '\'.
34 *
35 * Content patterns are regular expressions (QRegExp::RegExp).
36 *
37 * A file matches the filter if:
38 * @li file name matches the includeNames pattern or the includeNames pattern is empty;
39 * @li and; file name does not match the excludeNames pattern or the excludeNames pattern is empty;
40 * @li and; file content matches the includeContent pattern or the includeContent pattern is empty;
41 * @li and; file content does not match the excludeContent pattern or the excludeContent patytern is empty.
42 */
43 struct Filter
44 {
45 Filter()
46 {}
47
48 Filter(QString const & in, QString const & en, QString const & ic, QString const & ec)
49 : includeNames(in)
50 , excludeNames(en)
51 , includeContent(ic)
52 , excludeContent(ec)
53 {}
54
55 /// QRegExp expression specifying file names that are included in the search result
56 QString includeNames;
57
58 /// QRegExp expression specifying file names that are excluded from the search result
59 QString excludeNames;
60
61 /// QRegExp expression specifying file content that is included in the search result
62 QString includeContent;
63
64 /// QRegExp expression specifying file content that is excluded from the search result
65 QString excludeContent;
66 };
67
68 /**
69 * File finder interface.
70 *
71 * The iFileFinder interface is used to search for files using name and content filters.
72 */
73 class iFileFinder : public QObject
74 {
75 Q_OBJECT
76
77 public:
78
79 /// Interface constructor
80 iFileFinder() : QObject() {}
81
82 /// Empty virtual destructor
83 virtual ~iFileFinder() {}
84
85 /**
86 * Starts a file search in the directory dir using filter.
87 * @param dir Directory where to search
88 * @param recursive If True, searches also in sub-directories
89 * @param filter File name and content filter
90 *
91 * The search() function searches for files matching the given filter. The search is started
92 * in the directory dir and continues recursively into sub-directories if the recursive flag
93 * is set to true.
94 *
95 * The function is non-blocking and returns immediately. Results of the search are reported
96 * with found() signals and the finished() signal indicates that the search is either finished
97 * or canceled.
98 *
99 * If a new search is started before the current search is finished, then the current search is canceled.
100 */
101 virtual void search(QString const & dir, bool recursive, Filter const & filter) = 0;
102
103 /**
104 * Cancels an ongoing search.
105 */
106 virtual void cancel() = 0;
107
108 /**
109 * Indicates that a search is ongoing
110 */
111 virtual bool busy() const = 0;
112
113
114 signals:
115
116 /**
117 * Signal emitted for every file found during the search.
118 * @param fileName name of the file with a path relative to the search directory
119 * @param dir Search directory
120 */
121 void found(QString const & fileName, QString const & dir);
122
123 /**
124 * Signal emitted when the search is finished
125 * @param canceled True if the search was canceled instead of finished
126 */
127 void finished(bool canceled);
128
129 };
130
131
132 } // namespace eVaf::FileFinder
133 } // namespace eVaf
134
135 Q_DECLARE_INTERFACE(eVaf::FileFinder::iFileFinder, "eVaf.FileFinder.iFileFinder/1.0")
136
137 #endif // ifilefinder.h