kmail

kmfoldersearch.h
1 /*
2  This file is part of KMail, the KDE mail client.
3  Copyright (c) 2000 Don Sanders <sanders@kde.org>
4 
5  KMail is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License, version 2, as
7  published by the Free Software Foundation.
8 
9  KMail is distributed in the hope that it will be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 // Dynamic search folder
19 
20 #ifndef kmfoldersearch_h
21 #define kmfoldersearch_h
22 
23 #include <tqguardedptr.h>
24 #include <tqvaluelist.h>
25 #include <tqvaluevector.h>
26 #include <tqvaluestack.h>
27 #include <tqmap.h>
28 #include "kmfolder.h"
29 #include "folderstorage.h"
30 
40 typedef TQValueList<TQ_UINT32> SerNumList;
41 class KMSearchPattern;
42 class KMFolderImap;
43 class KMFolderSearchJob;
44 class KMIndexSearchTarget;
45 class TQTimer;
46 
47 namespace KMail {
48  class AttachmentStrategy;
49 }
50 using KMail::AttachmentStrategy;
51 
52 class KMSearch: public TQObject
53 {
54  TQ_OBJECT
55 
56 
57 public:
58  KMSearch(TQObject * parent = 0, const char * name = 0);
59  ~KMSearch();
60 
61  bool write(TQString location) const;
62  bool read(TQString location);
63  bool recursive() const { return mRecursive; }
64  void setRecursive(bool recursive) { if (running()) stop(); mRecursive = recursive; }
65  KMFolder* root() const { return mRoot; }
66  void setRoot(KMFolder *folder) { if (running()) stop(); mRoot = folder; }
67  bool inScope(KMFolder* folder) const;
68  //Takes ownership of @searchPattern
69  void setSearchPattern(KMSearchPattern *searchPattern);
70  KMSearchPattern* searchPattern() const { return mSearchPattern; }
71  void start();
72  bool running() const { return mRunning; }
73  void stop();
74  int foundCount() const { return mFoundCount; }
75  int searchCount() const { return mSearchCount; }
76  TQString currentFolder() const { return mLastFolder; }
77 
78 public slots:
79  void indexFinished();
80 
81 signals:
82  void found(TQ_UINT32 serNum);
83  void finished(bool success);
84 
85 protected slots:
86  void slotProcessNextBatch();
87  void slotSearchFolderResult( KMFolder*, TQValueList<TQ_UINT32>,
88  const KMSearchPattern*, bool );
89 
90 protected:
91  friend class ::KMIndexSearchTarget;
92  void setRunning(bool b) { mRunning = b; }
93  void setFoundCount(int f) { mFoundCount = f; }
94  void setCurrentFolder(const TQString &f) { mLastFolder = f; }
95 
96 private:
97  int mRemainingFolders;
98  bool mRecursive, mRunning, mIdle, mRunByIndex;
99  TQGuardedPtr<KMFolder> mRoot;
100  KMSearchPattern* mSearchPattern;
101  TQValueList<TQGuardedPtr<KMFolder> > mFolders, mOpenedFolders;
102  TQValueList<TQGuardedPtr<KMFolderImap> > mIncompleteFolders;
103  SerNumList mSerNums;
104  TQString mLastFolder;
105  int mFoundCount;
106  int mSearchCount;
107  TQTimer *mProcessNextBatchTimer;
108 };
109 
110 class KMFolderSearch: public FolderStorage
111 {
112  TQ_OBJECT
113 
114  friend class ::KMFolderSearchJob;
115 public:
116  KMFolderSearch(KMFolder* folder, const char* name=0);
117  virtual ~KMFolderSearch();
118 
120  virtual KMFolderType folderType() const { return KMFolderTypeSearch; }
121 
122  // Sets and runs the search used by the folder
123  void setSearch(KMSearch *search);
124  // Returns the current search used by the folder
125  const KMSearch* search() const;
126  // Stops the current search
127  void stopSearch() { if (mSearch) mSearch->stop(); }
128 
129  virtual KMMessage* getMsg(int idx);
130  virtual void ignoreJobsForMessage( KMMessage* );
131 
132  virtual void tryReleasingFolder(KMFolder* folder);
133 
135  virtual bool isMoveable() const { return false; }
136 
137 protected slots:
138  // Reads search definition for this folder and creates a KMSearch
139  bool readSearch();
140  // Runs the current search again
141  void executeSearch();
142  // Called when the search is finished
143  void searchFinished(bool success);
144  // Look at a new message and if it matches search() add it to the cache
145  void examineAddedMessage(KMFolder *folder, TQ_UINT32 serNum);
146  // Look at a removed message and remove it from the cache
147  void examineRemovedMessage(KMFolder *folder, TQ_UINT32 serNum);
148  // Look at a message whose status has changed
149  void examineChangedMessage(KMFolder *folder, TQ_UINT32 serNum, int delta);
150  // The serial numbers for a folder have been invalidated, deal with it
151  void examineInvalidatedFolder(KMFolder *folder);
152  // A folder has been deleted, deal with it
153  void examineRemovedFolder(KMFolder *folder);
154  // Propagate the msgHeaderChanged signal
155  void propagateHeaderChanged(KMFolder *folder, int idx);
156 
157 public slots:
158  // Appends the serial number to the cached list of messages that match
159  // the search for this folder
160  void addSerNum(TQ_UINT32 serNum);
161  // Removes the serial number from the cached list of messages that match
162  // the search for this folder
163  void removeSerNum(TQ_UINT32 serNum);
164 
166  virtual int updateIndex();
167 
168  // Examine the message
169  void slotSearchExamineMsgDone( KMFolder*, TQ_UINT32 serNum,
170  const KMSearchPattern*, bool );
171 
172 public:
173  //See base class for documentation
174  virtual int addMsg(KMMessage* msg, int* index_return = 0);
175  virtual int open(const char *owner);
176  virtual int canAccess();
177  virtual void sync();
178  virtual void reallyDoClose(const char* owner);
179  virtual int create();
180  virtual int compact( bool );
181  virtual bool isReadOnly() const;
182  virtual const KMMsgBase* getMsgBase(int idx) const;
183  virtual KMMsgBase* getMsgBase(int idx);
184  virtual int find(const KMMsgBase* msg) const;
185  virtual TQString indexLocation() const;
186  virtual int writeIndex( bool createEmptyIndex = false );
187  DwString getDwString(int idx);
188  TQ_UINT32 serNum(int idx) { return mSerNums[idx]; }
189 
190 protected:
191  virtual FolderJob* doCreateJob(KMMessage *msg, FolderJob::JobType jt,
192  KMFolder *folder, TQString partSpecifier,
193  const AttachmentStrategy *as ) const;
194  virtual FolderJob* doCreateJob(TQPtrList<KMMessage>& msgList, const TQString& sets,
195  FolderJob::JobType jt, KMFolder *folder) const;
196  virtual KMMessage* readMsg(int idx);
197  virtual bool readIndex();
198  virtual int removeContents();
199  virtual int expungeContents();
200  virtual int count(bool cache = false) const;
201  virtual KMMsgBase* takeIndexEntry(int idx);
202  virtual KMMsgInfo* setIndexEntry(int idx, KMMessage *msg);
203  virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
204  virtual void truncateIndex();
205 
206 private:
207  TQValueVector<TQ_UINT32> mSerNums;
208  TQValueList<TQGuardedPtr<KMFolder> > mFolders;
209  TQValueStack<TQ_UINT32> mUnexaminedMessages;
210  FILE *mIdsStream;
211  KMSearch *mSearch;
212  bool mInvalid, mUnlinked;
213  bool mTempOpened;
214  TQTimer *mExecuteSearchTimer;
215  TQMap<const KMFolder*, unsigned int>mFoldersCurrentlyBeingSearched;
216 };
217 #endif /*kmfoldersearch_h*/
218 
The FolderStorage class is the bass class for the storage related aspects of a collection of mail (a ...
Definition: folderstorage.h:80
virtual FolderJob * doCreateJob(KMMessage *msg, FolderJob::JobType jt, KMFolder *folder, TQString partSpecifier, const AttachmentStrategy *as) const =0
These two methods actually create the jobs.
virtual int create()=0
Create a new folder with the name of this object and open it.
virtual void ignoreJobsForMessage(KMMessage *)
Removes and deletes all jobs associated with the particular message.
virtual DwString getDwString(int idx)=0
Read a message and returns a DwString.
virtual int open(const char *owner)=0
Open folder for access.
virtual TQString indexLocation() const =0
Returns full path to index file.
virtual int count(bool cache=false) const
Number of messages in this folder.
virtual bool isMoveable() const
Returns true if this folder can be moved.
virtual int updateIndex()=0
Incrementally update the index if possible else call writeIndex.
virtual bool readIndex()=0
Read index file and fill the message-info list mMsgList.
virtual int find(const KMMsgBase *msg) const =0
Returns the index of the given message or -1 if not found.
virtual KMMessage * readMsg(int idx)=0
Load message from file and store it at given index.
virtual KMFolderType folderType() const
Returns the type of this folder.
Definition: folderstorage.h:96
virtual int expungeContents()=0
Called by KMFolder::expunge() to delete the actual contents.
virtual void tryReleasingFolder(KMFolder *)
Try releasing folder if possible, something is attempting an exclusive access to it.
virtual void search(const KMSearchPattern *)
Search for messages The end is signaled with searchDone()
virtual int removeContents()=0
Called by KMFolder::remove() to delete the actual contents.
virtual void sync()=0
fsync buffers to disk
virtual int addMsg(KMMessage *msg, int *index_return=0)=0
Add the given message to the folder.
virtual int canAccess()=0
Check folder for permissions Returns zero if readable and writable.
virtual bool isReadOnly() const =0
Is the folder read-only?
virtual KMMessage * getMsg(int idx)
Read message at given index.
virtual const KMMsgBase * getMsgBase(int idx) const =0
Provides access to the basic message fields that are also stored in the index.
virtual int writeIndex(bool createEmptyIndex=false)=0
Write index to index-file.
virtual int compact(bool silent)=0
Remove deleted messages from the folder.
Mail folder.
Definition: kmfolder.h:69
This is a Mime Message.
Definition: kmmessage.h:68
This class is an abstraction of a search over messages.
folderdiaquotatab.h
Definition: aboutdata.cpp:40