summaryrefslogtreecommitdiffstats
path: root/src/app/VFS/krquery.h
blob: 6481782a0906400bec8490f7fb9d3726df42c2bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/***************************************************************************
                                 krquery.h
                             -------------------
    copyright            : (C) 2001 by Shie Erlich & Rafi Yanai
    email                : krusader@users.sourceforge.net
    web site             : http://krusader.sourceforge.net
 ---------------------------------------------------------------------------
  Description
 ***************************************************************************

  A

     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.
     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D
     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'
     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b
     88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.
     YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD

                                                     H e a d e r    F i l e

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef KRQUERY_H
#define KRQUERY_H

#include <tqstringlist.h>
#include <tqdatetime.h>
#include <time.h>
#include <kurl.h>
#include <tdeio/jobclasses.h>
#include "vfile.h"

class KFileItem;

class KRQuery : public TQObject {
  TQ_OBJECT
  

public:
  // null query
  KRQuery();
  // query only with name filter
  KRQuery( const TQString &name, bool matchCase = true );
  // copy constructor
  KRQuery( const KRQuery & );
  // let operator
  KRQuery& operator=(const KRQuery &);
  // destructor
  virtual ~KRQuery();

  // matching a file with the query
  bool match( vfile *file ) const;// checks if the given vfile object matches the conditions
  // matching a TDEIO file with the query
  bool match( KFileItem *file ) const;// checks if the given vfile object matches the conditions
  // matching a name with the query
  bool match( const TQString &name ) const;// matching the filename only
  // matching the name of the directory
  bool matchDirName( const TQString &name ) const;

  // sets the text for name filtering
  void setNameFilter( const TQString &text, bool cs=true );
  // returns the current filter mask
  const TQString& nameFilter() const { return origFilter; }
  // returns whether the filter is case sensitive
  bool isCaseSensitive() { return matchesCaseSensitive; }

  // returns if the filter is null (was cancelled)
  bool isNull() {return bNull;};

  // sets the content part of the query
  void setContent( const TQString &content, bool cs=true, bool wholeWord=false, bool remoteSearch=false );

  // sets the minimum file size limit
  void setMinimumFileSize( TDEIO::filesize_t );
  // sets the maximum file size limit
  void setMaximumFileSize( TDEIO::filesize_t );

  // sets the time the file newer than
  void setNewerThan( time_t time );
  // sets the time the file older than
  void setOlderThan( time_t time );

  // sets the owner
  void setOwner( const TQString &ownerIn );
  // sets the group
  void setGroup( const TQString &groupIn );
  // sets the permissions
  void setPermissions( const TQString &permIn );

  // sets the mimetype for the query
  // type, must be one of the following:
  // 1. a valid mime type name
  // 2. one of: i18n("Archives"),   i18n("Directories"), i18n("Image Files")
  //            i18n("Text Files"), i18n("Video Files"), i18n("Audio Files")
  // 3. i18n("Custom") in which case you must supply a list of valid mime-types
  //    in the member TQStringList customType
  void setMimeType( const TQString &typeIn, TQStringList customList = TQStringList() );
  // true if setMimeType was called
  bool hasMimeType()  { return type.isEmpty(); }

  // sets the search in archive flag
  void setSearchInArchives( bool flag ) { inArchive = flag; }
  // gets the search in archive flag
  bool searchInArchives() { return inArchive; }
  // sets the recursive flag
  void setRecursive( bool flag ) { recurse = flag; }
  // gets the recursive flag
  bool isRecursive() { return recurse; }
  // sets whether to follow symbolic links
  void setFollowLinks( bool flag ) { followLinksP = flag; }
  // gets whether to follow symbolic links
  bool followLinks() { return followLinksP; }

  // sets the folders where the searcher will search
  void setSearchInDirs( const KURL::List &urls );
  // gets the folders where the searcher searches
  const KURL::List & searchInDirs() { return whereToSearch; }
  // sets the folders where search is not permitted
  void setDontSearchInDirs( const KURL::List &urls );
  // gets the folders where search is not permitted
  const KURL::List & dontSearchInDirs() { return whereNotToSearch; }
  // checks if a URL is excluded
  bool isExcluded( const KURL &url );
  // gives whether we search for content
  bool isContentSearched() const { return !contain.isEmpty(); }
  
  const TQString& foundText() const { return lastSuccessfulGrep; }

protected:
  // important to know whether the event processor is connected
  virtual void connectNotify ( const char * signal );
  // important to know whether the event processor is connected
  virtual void disconnectNotify ( const char * signal );

protected:
  TQStringList matches;           // what to search
  TQStringList excludes;          // what to exclude
  TQStringList includedDirs;      // what dirs to include
  TQStringList excludedDirs;      // what dirs to exclude
  bool matchesCaseSensitive;

  bool bNull;                    // flag if the query is null

  TQString contain;               // file must contain this string
  bool containCaseSensetive;
  bool containWholeWord;
  bool containOnRemote;

  TDEIO::filesize_t minSize;
  TDEIO::filesize_t maxSize;

  time_t newerThen;
  time_t olderThen;

  TQString owner;
  TQString group;
  TQString perm;

  TQString type;
  TQStringList customType;

  bool inArchive;                // if true- search in archive.
  bool recurse;                  // if true recurse ob sub-dirs...
  bool followLinksP;

  KURL::List whereToSearch;     // directorys to search
  KURL::List whereNotToSearch;  // directorys NOT to search

signals:
  void status( const TQString &name );
  void processEvents( bool & stopped );

private:
  bool matchCommon( const TQString &, const TQStringList &, const TQStringList & ) const;
  bool checkPerm(TQString perm) const;
  bool checkType(TQString mime) const;
  bool containsContent( TQString file ) const;
  bool containsContent( KURL url ) const;
  bool checkBuffer( const char *buffer, int len ) const;
  bool checkLines( const char *buffer, int len ) const;
  bool checkTimer() const;
  TQStringList split( TQString );

private slots:
  void containsContentData(TDEIO::Job *, const TQByteArray &);
  void containsContentFinished(TDEIO::Job*);

private:
  TQString                  origFilter;
  mutable bool             busy;
  mutable bool             containsContentResult;
  mutable char *           receivedBuffer;
  mutable int              receivedBufferLen;
  mutable TQString          lastSuccessfulGrep;
  mutable TQString          fileName;
  mutable TDEIO::filesize_t  receivedBytes;
  mutable TDEIO::filesize_t  totalBytes;
  mutable int              processEventsConnected;
  mutable TQTime            timer;
};

#endif