eVaf
engine.h
Go to the documentation of this file.
1 
20 #ifndef __FILEFINDER_ENGINE_ENGINE_H
21 # define __FILEFINDER_ENGINE_ENGINE_H
22 
23 #include "ifilefinder.h"
24 #include "version.h"
25 
26 #include <Plugins/iPlugin>
27 
28 #include <QDir>
29 #include <QRegExp>
30 #include <QVector>
31 #include <QThread>
32 #include <QMutex>
33 #include <QWaitCondition>
34 #include <QStringList>
35 
36 
37 namespace eVaf {
38 
42 namespace FileFinder {
43 
47 namespace Engine {
48 
52 namespace Internal {
53  class Engine;
54 } // namespace eVaf::FileFinder::Engine::Internal
55 
62 class Module : public Plugins::iPlugin
63 {
64  Q_OBJECT
65  Q_INTERFACES(eVaf::Plugins::iPlugin)
66  Q_PLUGIN_METADATA(IID VER_MODULE_NAME_STR)
67 
68 public:
69 
70  Module();
71 
72  virtual ~Module();
73 
74  virtual bool init(QString const & args);
75 
76  virtual void done();
77 
78  virtual bool isReady() const { return mReady; }
79 
80 
81 private: // Members
82 
84  bool mReady;
85 
87  Internal::Engine * mEngine;
88 
89 };
90 
91 
92 namespace Internal {
93 
94 class Worker;
95 
102 class Engine : public iFileFinder
103 {
104  Q_OBJECT
105  Q_INTERFACES(eVaf::FileFinder::iFileFinder)
106 
107 public:
108 
109  Engine();
110 
111  virtual ~Engine();
112 
113  bool init();
114 
115  void done();
116 
117  virtual void search(QString const & dir, bool recursive, Filter const & filter);
118 
119  virtual void cancel();
120 
121  virtual bool busy() const;
122 
123 
124 private: // Members
125 
127  Worker * mWorker;
128 
129 };
130 
135 {
136 public:
137 
139  : mValid(false)
140  {}
141 
142  ~RegExpChain();
143 
144  void setPattern(QString const & pattern);
145 
146  void clear();
147 
148  bool isEmpty() const { return mPatterns.isEmpty(); }
149 
150  bool isValid() const { return mValid; }
151 
152  bool exactMatch(QString const & str) const;
153 
154 
155 private:
156 
157  QVector<QRegExp *> mPatterns;
158 
159  bool mValid;
160 
169  QStringList split(QString const & str);
170 };
171 
178 class Worker : public QThread
179 {
180  Q_OBJECT
181 
182 public:
183 
184  Worker(QObject * parent = 0);
185 
186  virtual ~Worker();
187 
200  void search(QString const & dir, bool recursive, Filter const & filter);
201 
205  bool busy() const;
206 
210  void cancel();
211 
215  void stop();
216 
217 
218 signals:
219 
225  void found(QString const & fileName, QString const & dir);
226 
231  void finished(bool canceled);
232 
233 
234 protected:
235 
236  virtual void run();
237 
238 
239 private: // Members
240 
242  static int const ReadBufferSize;
243 
245  mutable QMutex mLock;
246 
248  QWaitCondition mSomethingToDo;
249 
250  QString mNewDir;
251  QDir mDir;
252 
253  bool mNewRecursive;
254  bool mRecursive;
255 
256  Filter mNewFilter;
257  RegExpChain mRxIncludeNames;
258  RegExpChain mRxExcludeNames;
259  QRegExp mRxIncludeContent;
260  QRegExp mRxExcludeContent;
261 
262  bool mDoSearch;
263 
264  bool mDoTerminate;
265 
266  bool mDoCancel;
267 
268  bool mBusy;
269 
270 
271 private: // Methods
272 
281  void recursiveSearch(QString const & path);
282 
283 };
284 
285 } // namespace eVaf::FileFinder::Engine::Internal
286 } // namespace eVaf::FileFinder::Engine
287 } // namespace eVaf::FileFinder
288 } // namespace eVaf
289 
290 #endif // engine.h
Interface for the file finder engine.
File finder interface.
Definition: ifilefinder.h:73
Worker thread searching for files.
Definition: engine.h:178
Module for the FileFinder application that searches for files.
Definition: engine.h:62
bool COMMON_EXPORT init()
eVaf common library initialized
#define VER_MODULE_NAME_STR
Module/library name (shall end with \0)
Definition: version.h:38
Implements the iFileFinder interface.
Definition: engine.h:102
Global eVaf namespace.
Definition: engine.h:37
Version information for eVaf modules.
A chain of QRegExp patterns.
Definition: engine.h:134
Common interface for all the eVaf modules.
Definition: iplugin.h:38
File filter defining patterns for file names and contents.
Definition: ifilefinder.h:43