~ubuntu-branches/debian/sid/scribus/sid

« back to all changes in this revision

Viewing changes to scribus/filesearch.h

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2008-07-02 13:42:07 UTC
  • mto: (4.1.1 sid) (20.1.1 experimental) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080702134207-h9h384v0wxjmaf8y
Tags: upstream-1.3.3.12.dfsg
ImportĀ upstreamĀ versionĀ 1.3.3.12.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.h>
 
13
#include <qvaluestack.h>
 
14
#include <qdir.h>
 
15
 
 
16
class QTimer;
 
17
 
 
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
 
24
{
 
25
        Q_OBJECT
 
26
 
 
27
public:
 
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);
 
37
 
 
38
        ~FileSearch();
 
39
 
 
40
public slots:
 
41
        // Begin searching.
 
42
        virtual void start();
 
43
 
 
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;
 
47
 
 
48
        // Return the number of files found so far.
 
49
        int foundCount() const;
 
50
 
 
51
        // Return the name we're searching for
 
52
        const QString & fileName() const;
 
53
 
 
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;
 
58
 
 
59
signals:
 
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&);
 
65
 
 
66
protected slots:
 
67
        virtual void next();
 
68
 
 
69
protected:
 
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.
 
72
        void pushStack();
 
73
 
 
74
        // Scans the current directory (where QDir is set to) and adds its contents
 
75
        // to the list of matched files.
 
76
        void addCurrentDirFiles();
 
77
 
 
78
        // Where the search starts from
 
79
        QString m_searchBase;
 
80
 
 
81
        // What the filename we're looking for is
 
82
        QString m_fileName;
 
83
 
 
84
        // The list of files matched in the search
 
85
        QStringList m_matchingFiles;
 
86
 
 
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;
 
91
 
 
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;
 
95
 
 
96
        // A QDir set to the current directory, used for listing files and
 
97
        // directories.
 
98
        QDir m_dir;
 
99
 
 
100
        // Conveniently keep track of how deeply we've recursed.
 
101
        int m_depth;
 
102
 
 
103
        // Maximum depth to search to
 
104
        int m_maxdepth;
 
105
};
 
106
 
 
107
#endif