kmail
kmfoldersearch.hGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef kmfoldersearch_h
00021 #define kmfoldersearch_h
00022
00023 #include <qguardedptr.h>
00024 #include <qvaluelist.h>
00025 #include <qvaluevector.h>
00026 #include <qvaluestack.h>
00027 #include <qmap.h>
00028 #include "kmfolder.h"
00029 #include "folderstorage.h"
00030
00040 typedef QValueList<Q_UINT32> SerNumList;
00041 class KMSearchPattern;
00042 class KMFolderImap;
00043 class KMFolderSearchJob;
00044 class KMIndexSearchTarget;
00045 class QTimer;
00046
00047 namespace KMail {
00048 class AttachmentStrategy;
00049 }
00050 using KMail::AttachmentStrategy;
00051
00052 class KMSearch: public QObject
00053 {
00054 Q_OBJECT
00055
00056 public:
00057 KMSearch(QObject * parent = 0, const char * name = 0);
00058 ~KMSearch();
00059
00060 bool write(QString location) const;
00061 bool read(QString location);
00062 bool recursive() const { return mRecursive; }
00063 void setRecursive(bool recursive) { if (running()) stop(); mRecursive = recursive; }
00064 KMFolder* root() const { return mRoot; }
00065 void setRoot(KMFolder *folder) { if (running()) stop(); mRoot = folder; }
00066 bool inScope(KMFolder* folder) const;
00067
00068 void setSearchPattern(KMSearchPattern *searchPattern);
00069 KMSearchPattern* searchPattern() const { return mSearchPattern; }
00070 void start();
00071 bool running() const { return mRunning; }
00072 void stop();
00073 int foundCount() const { return mFoundCount; }
00074 int searchCount() const { return mSearchCount; }
00075 QString currentFolder() const { return mLastFolder; }
00076
00077 public slots:
00078 void indexFinished();
00079
00080 signals:
00081 void found(Q_UINT32 serNum);
00082 void finished(bool success);
00083
00084 protected slots:
00085 void slotProcessNextBatch();
00086 void slotSearchFolderResult( KMFolder*, QValueList<Q_UINT32>,
00087 const KMSearchPattern*, bool );
00088
00089 protected:
00090 friend class ::KMIndexSearchTarget;
00091 void setRunning(bool b) { mRunning = b; }
00092 void setFoundCount(int f) { mFoundCount = f; }
00093 void setCurrentFolder(const QString &f) { mLastFolder = f; }
00094
00095 private:
00096 int mRemainingFolders;
00097 bool mRecursive, mRunning, mIdle, mRunByIndex;
00098 QGuardedPtr<KMFolder> mRoot;
00099 KMSearchPattern* mSearchPattern;
00100 QValueList<QGuardedPtr<KMFolder> > mFolders, mOpenedFolders;
00101 QValueList<QGuardedPtr<KMFolderImap> > mIncompleteFolders;
00102 SerNumList mSerNums;
00103 QString mLastFolder;
00104 int mFoundCount;
00105 int mSearchCount;
00106 QTimer *mProcessNextBatchTimer;
00107 };
00108
00109 class KMFolderSearch: public FolderStorage
00110 {
00111 Q_OBJECT
00112 friend class ::KMFolderSearchJob;
00113 public:
00114 KMFolderSearch(KMFolder* folder, const char* name=0);
00115 virtual ~KMFolderSearch();
00116
00118 virtual KMFolderType folderType() const { return KMFolderTypeSearch; }
00119
00120
00121 void setSearch(KMSearch *search);
00122
00123 const KMSearch* search() const;
00124
00125 void stopSearch() { if (mSearch) mSearch->stop(); }
00126
00127 virtual KMMessage* getMsg(int idx);
00128 virtual void ignoreJobsForMessage( KMMessage* );
00129
00130 virtual void tryReleasingFolder(KMFolder* folder);
00131
00133 virtual bool isMoveable() const { return false; }
00134
00135 protected slots:
00136
00137 bool readSearch();
00138
00139 void executeSearch();
00140
00141 void searchFinished(bool success);
00142
00143 void examineAddedMessage(KMFolder *folder, Q_UINT32 serNum);
00144
00145 void examineRemovedMessage(KMFolder *folder, Q_UINT32 serNum);
00146
00147 void examineChangedMessage(KMFolder *folder, Q_UINT32 serNum, int delta);
00148
00149 void examineInvalidatedFolder(KMFolder *folder);
00150
00151 void examineRemovedFolder(KMFolder *folder);
00152
00153 void propagateHeaderChanged(KMFolder *folder, int idx);
00154
00155 public slots:
00156
00157
00158 void addSerNum(Q_UINT32 serNum);
00159
00160
00161 void removeSerNum(Q_UINT32 serNum);
00162
00164 virtual int updateIndex();
00165
00166
00167 void slotSearchExamineMsgDone( KMFolder*, Q_UINT32 serNum,
00168 const KMSearchPattern*, bool );
00169
00170 public:
00171
00172 virtual int addMsg(KMMessage* msg, int* index_return = 0);
00173 virtual int open(const char *owner);
00174 virtual int canAccess();
00175 virtual void sync();
00176 virtual void reallyDoClose(const char* owner);
00177 virtual int create();
00178 virtual int compact( bool );
00179 virtual bool isReadOnly() const;
00180 virtual const KMMsgBase* getMsgBase(int idx) const;
00181 virtual KMMsgBase* getMsgBase(int idx);
00182 virtual int find(const KMMsgBase* msg) const;
00183 virtual QString indexLocation() const;
00184 virtual int writeIndex( bool createEmptyIndex = false );
00185 DwString getDwString(int idx);
00186 Q_UINT32 serNum(int idx) { return mSerNums[idx]; }
00187
00188 protected:
00189 virtual FolderJob* doCreateJob(KMMessage *msg, FolderJob::JobType jt,
00190 KMFolder *folder, QString partSpecifier,
00191 const AttachmentStrategy *as ) const;
00192 virtual FolderJob* doCreateJob(QPtrList<KMMessage>& msgList, const QString& sets,
00193 FolderJob::JobType jt, KMFolder *folder) const;
00194 virtual KMMessage* readMsg(int idx);
00195 virtual bool readIndex();
00196 virtual int removeContents();
00197 virtual int expungeContents();
00198 virtual int count(bool cache = false) const;
00199 virtual KMMsgBase* takeIndexEntry(int idx);
00200 virtual KMMsgInfo* setIndexEntry(int idx, KMMessage *msg);
00201 virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
00202 virtual void truncateIndex();
00203
00204 private:
00205 QValueVector<Q_UINT32> mSerNums;
00206 QValueList<QGuardedPtr<KMFolder> > mFolders;
00207 QValueStack<Q_UINT32> mUnexaminedMessages;
00208 FILE *mIdsStream;
00209 KMSearch *mSearch;
00210 bool mInvalid, mUnlinked;
00211 bool mTempOpened;
00212 QTimer *mExecuteSearchTimer;
00213 QMap<const KMFolder*, unsigned int>mFoldersCurrentlyBeingSearched;
00214 };
00215 #endif
00216
|