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.
10
#include "scribusapi.h"
11
#include "deferredtask.h"
12
#include <qstringlist.h>
13
#include <qvaluestack.h>
18
// A class to do a depth-first search for a file in a directory tree
19
// efficiently and safely (I hope). The class is fire and forget,
20
// letting you get on with other things and take action when you're informed
21
// that the search is complete.
22
// A FileSearch is single use.
23
class SCRIBUS_API FileSearch : public DeferredTask
28
// Construct a new FileSearch object to search for the specified filename.
29
// fileName should be a basename without path. Once you've created the
30
// FileSearch, connect yourself to its searchComplete(int) signal then
31
// start() it and return to the event loop. If searchBase is not specified,
32
// a search of the user's home directory is done. The caller is expected to
33
// ensure that the search base exists.
34
// depthLimit is -1 for no limit, otherwise number of levels deep to search.
35
// The base dir is level 0.
36
FileSearch(QObject* parent, const QString & fileName, const QString & searchBase = QString::null, int depthLimit = -1);
44
// Return a list of files matched. Note that it is safe to call this
45
// while the search is still running, or after it has failed.
46
const QStringList & matchingFiles() const;
48
// Return the number of files found so far.
49
int foundCount() const;
51
// Return the name we're searching for
52
const QString & fileName() const;
54
// Return a const reference to the QDir we're using to
55
// track our progress. This lets the caller get the dirname,
56
// absolute dirname, etc.
57
const QDir & currentDir() const;
60
// Emitted when the search has finished.
61
// param 1 is list of paths matched,
62
// param 2 is filename searched for.
63
// Remember you can simply discard one or both params.
64
void searchComplete(const QStringList&, const QString&);
70
// Push a list of subdirs in the current directory onto m_tree, and
71
// put an iterator pointing to the first subdir on top of m_iter.
74
// Scans the current directory (where QDir is set to) and adds its contents
75
// to the list of matched files.
76
void addCurrentDirFiles();
78
// Where the search starts from
81
// What the filename we're looking for is
84
// The list of files matched in the search
85
QStringList m_matchingFiles;
87
// This stack holds a list of directories on the tree, from the base
88
// to the level we're currently searching. We use iterators into the values
89
// of this stack to keep the search position.
90
QValueStack<QStringList> m_tree;
92
// A matching stack of iterators into the lists in m_tree. We use this stack
93
// to iterate directory by directory as we search.
94
QValueStack<QStringList::const_iterator> m_iter;
96
// A QDir set to the current directory, used for listing files and
100
// Conveniently keep track of how deeply we've recursed.
103
// Maximum depth to search to