Scribus
Open source desktop publishing at your fingertips
filesearch.h
1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #ifndef _FILESEARCH_H
8 #define _FILESEARCH_H
9 
10 #include "scribusapi.h"
11 #include "deferredtask.h"
12 #include <QStringList>
13 #include <QStack>
14 #include <QDir>
15 
16 class QTimer;
17 
24 class SCRIBUS_API FileSearch : public DeferredTask
25 {
26  Q_OBJECT
27 
28 public:
43  FileSearch(QObject* parent, const QString & fileName, const QString & searchBase = QString::null, int depthLimit = -1, bool caseSensitive=true);
44 
45  ~FileSearch();
46 
47 public slots:
49  virtual void start();
50 
54  const QStringList & matchingFiles() const;
55 
57  int foundCount() const;
58 
60  const QString & fileName() const;
61 
66  const QDir & currentDir() const;
67 
68 signals:
74  void searchComplete(const QStringList& paths, const QString& filename);
75 
76 protected slots:
77  virtual void next();
78 
79 protected:
82  void pushStack();
83 
86  void addCurrentDirFiles();
87 
90 
92  QString m_searchBase;
93 
95  QString m_fileName;
96 
98  QStringList m_matchingFiles;
99 
104  QStack<QStringList> m_tree;
105 
109  QStack<QStringList::const_iterator> m_iter;
110 
113  QDir m_dir;
114 
116  int m_depth;
117 
120 };
121 
122 #endif
QStack< QStringList > m_tree
This stack holds a list of directories on the tree, from the base to the level we're currently search...
Definition: filesearch.h:104
QString m_searchBase
Where the search starts from.
Definition: filesearch.h:92
QDir m_dir
A QDir set to the current directory, used for listing files and directories.
Definition: filesearch.h:113
QStack< QStringList::const_iterator > m_iter
A matching stack of iterators into the lists in m_tree. We use this stack to iterate directory by dir...
Definition: filesearch.h:109
A class to do a depth-first search for a file in a directory tree efficiently and safely (I hope)...
Definition: filesearch.h:24
virtual void next()=0
Do the next small chunk of processing, then return. You must implement this method to do whatever pro...
bool m_caseSensitive
Case sensitive flag.
Definition: filesearch.h:89
int m_depth
Conveniently keep track of how deeply we've recursed.
Definition: filesearch.h:116
QString m_fileName
What the filename we're looking for is.
Definition: filesearch.h:95
virtual void start()
Starts the timer and begins processing. If you override this you must call DeferredTask::start() at t...
Definition: deferredtask.cpp:68
DeferredTask is an abstraction of a generally long-running operation that is done in small steps unde...
Definition: deferredtask.h:37
QStringList m_matchingFiles
The list of files matched in the search.
Definition: filesearch.h:98
int m_maxdepth
Maximum depth to search to.
Definition: filesearch.h:119