~ubuntu-branches/ubuntu/vivid/krusader/vivid-proposed

« back to all changes in this revision

Viewing changes to krusader/VFS/krquery.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-05-05 22:26:37 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505222637-ydv3cwjwy365on2r
Tags: 1:2.1.0~beta1-1ubuntu1
* Merge from Debian Unstable.  Remaining changes:
  - Retain Kubuntu doc path

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#ifndef KRQUERY_H
31
31
#define KRQUERY_H
32
32
 
33
 
#include <qstringlist.h>
34
 
#include <qdatetime.h>
 
33
#include <QtCore/QStringList>
 
34
#include <QtCore/QDateTime>
35
35
#include <time.h>
36
36
#include <kurl.h>
37
37
#include <kio/jobclasses.h>
40
40
class KFileItem;
41
41
class QTextCodec;
42
42
 
43
 
class KRQuery : public QObject {
44
 
  Q_OBJECT
 
43
class KRQuery : public QObject
 
44
{
 
45
    Q_OBJECT
45
46
 
46
47
public:
47
 
  // null query
48
 
  KRQuery();
49
 
  // query only with name filter
50
 
  KRQuery( const QString &name, bool matchCase = true );
51
 
  // copy constructor
52
 
  KRQuery( const KRQuery & );
53
 
  // let operator
54
 
  KRQuery& operator=(const KRQuery &);
55
 
  // destructor
56
 
  virtual ~KRQuery();
57
 
 
58
 
  // matching a file with the query
59
 
  bool match( vfile *file ) const;// checks if the given vfile object matches the conditions
60
 
  // matching a KIO file with the query
61
 
  bool match( KFileItem *file ) const;// checks if the given vfile object matches the conditions
62
 
  // matching a name with the query
63
 
  bool match( const QString &name ) const;// matching the filename only
64
 
  // matching the name of the directory
65
 
  bool matchDirName( const QString &name ) const;
66
 
 
67
 
  // sets the text for name filtering
68
 
  void setNameFilter( const QString &text, bool cs=true );
69
 
  // returns the current filter mask
70
 
  const QString& nameFilter() const { return origFilter; }
71
 
  // returns whether the filter is case sensitive
72
 
  bool isCaseSensitive() { return matchesCaseSensitive; }
73
 
 
74
 
  // returns if the filter is null (was cancelled)
75
 
  bool isNull() {return bNull;};
76
 
 
77
 
  // sets the content part of the query
78
 
  void setContent( const QString &content, bool cs=true, bool wholeWord=false, bool remoteSearch=false, QString encoding=QString(), bool regExp=false);
79
 
 
80
 
  // sets the minimum file size limit
81
 
  void setMinimumFileSize( KIO::filesize_t );
82
 
  // sets the maximum file size limit
83
 
  void setMaximumFileSize( KIO::filesize_t );
84
 
 
85
 
  // sets the time the file newer than
86
 
  void setNewerThan( time_t time );
87
 
  // sets the time the file older than
88
 
  void setOlderThan( time_t time );
89
 
 
90
 
  // sets the owner
91
 
  void setOwner( const QString &ownerIn );
92
 
  // sets the group
93
 
  void setGroup( const QString &groupIn );
94
 
  // sets the permissions
95
 
  void setPermissions( const QString &permIn );
96
 
 
97
 
  // sets the mimetype for the query
98
 
  // type, must be one of the following:
99
 
  // 1. a valid mime type name
100
 
  // 2. one of: i18n("Archives"),   i18n("Directories"), i18n("Image Files")
101
 
  //            i18n("Text Files"), i18n("Video Files"), i18n("Audio Files")
102
 
  // 3. i18n("Custom") in which case you must supply a list of valid mime-types
103
 
  //    in the member QStringList customType
104
 
  void setMimeType( const QString &typeIn, QStringList customList = QStringList() );
105
 
  // true if setMimeType was called
106
 
  bool hasMimeType()  { return type.isEmpty(); }
107
 
 
108
 
  // sets the search in archive flag
109
 
  void setSearchInArchives( bool flag ) { inArchive = flag; }
110
 
  // gets the search in archive flag
111
 
  bool searchInArchives() { return inArchive; }
112
 
  // sets the recursive flag
113
 
  void setRecursive( bool flag ) { recurse = flag; }
114
 
  // gets the recursive flag
115
 
  bool isRecursive() { return recurse; }
116
 
  // sets whether to follow symbolic links
117
 
  void setFollowLinks( bool flag ) { followLinksP = flag; }
118
 
  // gets whether to follow symbolic links
119
 
  bool followLinks() { return followLinksP; }
120
 
 
121
 
  // sets the folders where the searcher will search
122
 
  void setSearchInDirs( const KUrl::List &urls );
123
 
  // gets the folders where the searcher searches
124
 
  const KUrl::List & searchInDirs() { return whereToSearch; }
125
 
  // sets the folders where search is not permitted
126
 
  void setDontSearchInDirs( const KUrl::List &urls );
127
 
  // gets the folders where search is not permitted
128
 
  const KUrl::List & dontSearchInDirs() { return whereNotToSearch; }
129
 
  // checks if a URL is excluded
130
 
  bool isExcluded( const KUrl &url );
131
 
  // gives whether we search for content
132
 
  bool isContentSearched() const { return !contain.isEmpty(); }
133
 
  
134
 
  const QString& foundText() const { return lastSuccessfulGrep; }
135
 
 
136
 
protected:
137
 
  // important to know whether the event processor is connected
138
 
  virtual void connectNotify ( const char * signal );
139
 
  // important to know whether the event processor is connected
140
 
  virtual void disconnectNotify ( const char * signal );
141
 
 
142
 
protected:
143
 
  QStringList matches;           // what to search
144
 
  QStringList excludes;          // what to exclude
145
 
  QStringList includedDirs;      // what dirs to include
146
 
  QStringList excludedDirs;      // what dirs to exclude
147
 
  bool matchesCaseSensitive;
148
 
 
149
 
  bool bNull;                    // flag if the query is null
150
 
 
151
 
  QString contain;               // file must contain this string
152
 
  bool containCaseSensetive;
153
 
  bool containWholeWord;
154
 
  bool containRegExp;
155
 
  bool containOnRemote;
156
 
 
157
 
  KIO::filesize_t minSize;
158
 
  KIO::filesize_t maxSize;
159
 
 
160
 
  time_t newerThen;
161
 
  time_t olderThen;
162
 
 
163
 
  QString owner;
164
 
  QString group;
165
 
  QString perm;
166
 
 
167
 
  QString type;
168
 
  QStringList customType;
169
 
 
170
 
  bool inArchive;                // if true- search in archive.
171
 
  bool recurse;                  // if true recurse ob sub-dirs...
172
 
  bool followLinksP;
173
 
 
174
 
  KUrl::List whereToSearch;     // directorys to search
175
 
  KUrl::List whereNotToSearch;  // directorys NOT to search
 
48
    // null query
 
49
    KRQuery();
 
50
    // query only with name filter
 
51
    KRQuery(const QString &name, bool matchCase = true);
 
52
    // copy constructor
 
53
    KRQuery(const KRQuery &);
 
54
    // let operator
 
55
    KRQuery& operator=(const KRQuery &);
 
56
    // destructor
 
57
    virtual ~KRQuery();
 
58
 
 
59
    // matching a file with the query
 
60
    bool match(vfile *file) const;  // checks if the given vfile object matches the conditions
 
61
    // matching a KIO file with the query
 
62
    bool match(KFileItem *file) const;  // checks if the given vfile object matches the conditions
 
63
    // matching a name with the query
 
64
    bool match(const QString &name) const;  // matching the filename only
 
65
    // matching the name of the directory
 
66
    bool matchDirName(const QString &name) const;
 
67
 
 
68
    // sets the text for name filtering
 
69
    void setNameFilter(const QString &text, bool cs = true);
 
70
    // returns the current filter mask
 
71
    const QString& nameFilter() const {
 
72
        return origFilter;
 
73
    }
 
74
    // returns whether the filter is case sensitive
 
75
    bool isCaseSensitive() {
 
76
        return matchesCaseSensitive;
 
77
    }
 
78
 
 
79
    // returns if the filter is null (was cancelled)
 
80
    bool isNull() {
 
81
        return bNull;
 
82
    };
 
83
 
 
84
    // sets the content part of the query
 
85
    void setContent(const QString &content, bool cs = true, bool wholeWord = false, bool remoteSearch = false, QString encoding = QString(), bool regExp = false);
 
86
 
 
87
    // sets the minimum file size limit
 
88
    void setMinimumFileSize(KIO::filesize_t);
 
89
    // sets the maximum file size limit
 
90
    void setMaximumFileSize(KIO::filesize_t);
 
91
 
 
92
    // sets the time the file newer than
 
93
    void setNewerThan(time_t time);
 
94
    // sets the time the file older than
 
95
    void setOlderThan(time_t time);
 
96
 
 
97
    // sets the owner
 
98
    void setOwner(const QString &ownerIn);
 
99
    // sets the group
 
100
    void setGroup(const QString &groupIn);
 
101
    // sets the permissions
 
102
    void setPermissions(const QString &permIn);
 
103
 
 
104
    // sets the mimetype for the query
 
105
    // type, must be one of the following:
 
106
    // 1. a valid mime type name
 
107
    // 2. one of: i18n("Archives"),   i18n("Directories"), i18n("Image Files")
 
108
    //            i18n("Text Files"), i18n("Video Files"), i18n("Audio Files")
 
109
    // 3. i18n("Custom") in which case you must supply a list of valid mime-types
 
110
    //    in the member QStringList customType
 
111
    void setMimeType(const QString &typeIn, QStringList customList = QStringList());
 
112
    // true if setMimeType was called
 
113
    bool hasMimeType()  {
 
114
        return type.isEmpty();
 
115
    }
 
116
 
 
117
    // sets the search in archive flag
 
118
    void setSearchInArchives(bool flag) {
 
119
        inArchive = flag;
 
120
    }
 
121
    // gets the search in archive flag
 
122
    bool searchInArchives() {
 
123
        return inArchive;
 
124
    }
 
125
    // sets the recursive flag
 
126
    void setRecursive(bool flag) {
 
127
        recurse = flag;
 
128
    }
 
129
    // gets the recursive flag
 
130
    bool isRecursive() {
 
131
        return recurse;
 
132
    }
 
133
    // sets whether to follow symbolic links
 
134
    void setFollowLinks(bool flag) {
 
135
        followLinksP = flag;
 
136
    }
 
137
    // gets whether to follow symbolic links
 
138
    bool followLinks() {
 
139
        return followLinksP;
 
140
    }
 
141
 
 
142
    // sets the folders where the searcher will search
 
143
    void setSearchInDirs(const KUrl::List &urls);
 
144
    // gets the folders where the searcher searches
 
145
    const KUrl::List & searchInDirs() {
 
146
        return whereToSearch;
 
147
    }
 
148
    // sets the folders where search is not permitted
 
149
    void setDontSearchInDirs(const KUrl::List &urls);
 
150
    // gets the folders where search is not permitted
 
151
    const KUrl::List & dontSearchInDirs() {
 
152
        return whereNotToSearch;
 
153
    }
 
154
    // checks if a URL is excluded
 
155
    bool isExcluded(const KUrl &url);
 
156
    // gives whether we search for content
 
157
    bool isContentSearched() const {
 
158
        return !contain.isEmpty();
 
159
    }
 
160
 
 
161
    bool checkLine(const QString &line, bool backwards = false) const;
 
162
    const QString& foundText() const {
 
163
        return lastSuccessfulGrep;
 
164
    }
 
165
    int matchIndex() const {
 
166
        return lastSuccessfulGrepMatchIndex;
 
167
    }
 
168
    int matchLength() const {
 
169
        return lastSuccessfulGrepMatchLength;
 
170
    }
 
171
 
 
172
protected:
 
173
    // important to know whether the event processor is connected
 
174
    virtual void connectNotify(const char * signal);
 
175
    // important to know whether the event processor is connected
 
176
    virtual void disconnectNotify(const char * signal);
 
177
 
 
178
protected:
 
179
    QStringList matches;           // what to search
 
180
    QStringList excludes;          // what to exclude
 
181
    QStringList includedDirs;      // what dirs to include
 
182
    QStringList excludedDirs;      // what dirs to exclude
 
183
    bool matchesCaseSensitive;
 
184
 
 
185
    bool bNull;                    // flag if the query is null
 
186
 
 
187
    QString contain;               // file must contain this string
 
188
    bool containCaseSensetive;
 
189
    bool containWholeWord;
 
190
    bool containRegExp;
 
191
    bool containOnRemote;
 
192
 
 
193
    KIO::filesize_t minSize;
 
194
    KIO::filesize_t maxSize;
 
195
 
 
196
    time_t newerThen;
 
197
    time_t olderThen;
 
198
 
 
199
    QString owner;
 
200
    QString group;
 
201
    QString perm;
 
202
 
 
203
    QString type;
 
204
    QStringList customType;
 
205
 
 
206
    bool inArchive;                // if true- search in archive.
 
207
    bool recurse;                  // if true recurse ob sub-dirs...
 
208
    bool followLinksP;
 
209
 
 
210
    KUrl::List whereToSearch;     // directories to search
 
211
    KUrl::List whereNotToSearch;  // directories NOT to search
176
212
 
177
213
signals:
178
 
  void status( const QString &name );
179
 
  void processEvents( bool & stopped );
 
214
    void status(const QString &name);
 
215
    void processEvents(bool & stopped);
180
216
 
181
217
private:
182
 
  bool matchCommon( const QString &, const QStringList &, const QStringList & ) const;
183
 
  bool checkPerm(QString perm) const;
184
 
  bool checkType(QString mime) const;
185
 
  bool containsContent( QString file ) const;
186
 
  bool containsContent( KUrl url ) const;
187
 
  bool checkBuffer( const char * data, int len ) const;
188
 
  bool checkLine( const QString &line ) const;
189
 
  bool checkTimer() const;
190
 
  QStringList split( QString );
 
218
    bool matchCommon(const QString &, const QStringList &, const QStringList &) const;
 
219
    bool checkPerm(QString perm) const;
 
220
    bool checkType(QString mime) const;
 
221
    bool containsContent(QString file) const;
 
222
    bool containsContent(KUrl url) const;
 
223
    bool checkBuffer(const char * data, int len) const;
 
224
    bool checkTimer() const;
 
225
    QStringList split(QString);
191
226
 
192
227
private slots:
193
 
  void containsContentData(KIO::Job *, const QByteArray &);
194
 
  void containsContentFinished(KJob*);
 
228
    void containsContentData(KIO::Job *, const QByteArray &);
 
229
    void containsContentFinished(KJob*);
195
230
 
196
231
private:
197
 
  QString                  origFilter;
198
 
  mutable bool             busy;
199
 
  mutable bool             containsContentResult;
200
 
  mutable char *           receivedBuffer;
201
 
  mutable int              receivedBufferLen;
202
 
  mutable QString          lastSuccessfulGrep;
203
 
  mutable QString          fileName;
204
 
  mutable KIO::filesize_t  receivedBytes;
205
 
  mutable KIO::filesize_t  totalBytes;
206
 
  mutable int              processEventsConnected;
207
 
  mutable QTime            timer;
208
 
 
209
 
  QTextCodec *             codec;
210
 
 
211
 
  const char *             encodedEnter;
212
 
  int                      encodedEnterLen;
213
 
  QByteArray               encodedEnterArray;
 
232
    QString                  origFilter;
 
233
    mutable bool             busy;
 
234
    mutable bool             containsContentResult;
 
235
    mutable char *           receivedBuffer;
 
236
    mutable int              receivedBufferLen;
 
237
    mutable QString          lastSuccessfulGrep;
 
238
    mutable int              lastSuccessfulGrepMatchIndex;
 
239
    mutable int              lastSuccessfulGrepMatchLength;
 
240
    mutable QString          fileName;
 
241
    mutable KIO::filesize_t  receivedBytes;
 
242
    mutable KIO::filesize_t  totalBytes;
 
243
    mutable int              processEventsConnected;
 
244
    mutable QTime            timer;
 
245
 
 
246
    QTextCodec *             codec;
 
247
 
 
248
    const char *             encodedEnter;
 
249
    int                      encodedEnterLen;
 
250
    QByteArray               encodedEnterArray;
214
251
};
215
252
 
216
253
#endif