kmail

kmfoldersearch.h

00001 /*
00002     This file is part of KMail, the KDE mail client.
00003     Copyright (c) 2000 Don Sanders <sanders@kde.org>
00004 
00005     KMail is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU General Public License, version 2, as
00007     published by the Free Software Foundation.
00008 
00009     KMail is distributed in the hope that it will be useful, but
00010     WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 */
00018 // Dynamic search folder
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   //Takes ownership of @searchPattern
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   QString currentFolder() const { return mLastFolder; }
00075 
00076 public slots:
00077   void indexFinished();
00078 
00079 signals:
00080   void found(Q_UINT32 serNum);
00081   void finished(bool success);
00082 
00083 protected slots:
00084   void slotProcessNextBatch();
00085   void slotSearchFolderResult( KMFolder*, QValueList<Q_UINT32>,
00086                                const KMSearchPattern*, bool );
00087 
00088 protected:
00089   friend class ::KMIndexSearchTarget;
00090   void setRunning(bool b) { mRunning = b; }
00091   void setFoundCount(int f) { mFoundCount = f; }
00092   void setCurrentFolder(const QString &f) { mLastFolder = f; }
00093 
00094 private:
00095   int mRemainingFolders;
00096   bool mRecursive, mRunning, mIdle, mRunByIndex;
00097   QGuardedPtr<KMFolder> mRoot;
00098   KMSearchPattern* mSearchPattern;
00099   QValueList<QGuardedPtr<KMFolder> > mFolders, mOpenedFolders;
00100   QValueList<QGuardedPtr<KMFolderImap> > mIncompleteFolders;
00101   SerNumList mSerNums;
00102   QString mLastFolder;
00103   int mFoundCount;
00104   QTimer *mProcessNextBatchTimer;
00105 };
00106 
00107 class KMFolderSearch: public FolderStorage
00108 {
00109   Q_OBJECT
00110   friend class ::KMFolderSearchJob;
00111 public:
00112   KMFolderSearch(KMFolder* folder, const char* name=0);
00113   virtual ~KMFolderSearch();
00114 
00116   virtual KMFolderType folderType() const { return KMFolderTypeSearch; }
00117 
00118   // Sets and runs the search used by the folder
00119   void setSearch(KMSearch *search);
00120   // Returns the current search used by the folder
00121   const KMSearch* search() const;
00122   // Stops the current search
00123   void stopSearch() { if (mSearch) mSearch->stop(); }
00124 
00125   virtual KMMessage* getMsg(int idx);
00126   virtual void ignoreJobsForMessage( KMMessage* );
00127 
00128   virtual void tryReleasingFolder(KMFolder* folder);
00129 
00131   virtual bool isMoveable() const { return false; }
00132 
00133 protected slots:
00134   // Reads search definition for this folder and creates a KMSearch
00135   bool readSearch();
00136   // Runs the current search again
00137   void executeSearch();
00138   // Called when the search is finished
00139   void searchFinished(bool success);
00140   // Look at a new message and if it matches search() add it to the cache
00141   void examineAddedMessage(KMFolder *folder, Q_UINT32 serNum);
00142   // Look at a removed message and remove it from the cache
00143   void examineRemovedMessage(KMFolder *folder, Q_UINT32 serNum);
00144   // Look at a message whose status has changed
00145   void examineChangedMessage(KMFolder *folder, Q_UINT32 serNum, int delta);
00146   // The serial numbers for a folder have been invalidated, deal with it
00147   void examineInvalidatedFolder(KMFolder *folder);
00148   // A folder has been deleted, deal with it
00149   void examineRemovedFolder(KMFolder *folder);
00150   // Propagate the msgHeaderChanged signal
00151   void propagateHeaderChanged(KMFolder *folder, int idx);
00152 
00153 public slots:
00154   // Appends the serial number to the cached list of messages that match
00155   // the search for this folder
00156   void addSerNum(Q_UINT32 serNum);
00157   // Removes the serial number from the cached list of messages that match
00158   // the search for this folder
00159   void removeSerNum(Q_UINT32 serNum);
00160 
00162   virtual int updateIndex();
00163 
00164   // Examine the message
00165   void slotSearchExamineMsgDone( KMFolder*, Q_UINT32 serNum, 
00166                                  const KMSearchPattern*, bool );
00167 
00168 public:
00169   //See base class for documentation
00170   virtual QCString& getMsgString(int idx, QCString& mDest);
00171   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00172   virtual int open();
00173   virtual int canAccess();
00174   virtual void sync();
00175   virtual void close(bool force=FALSE);
00176   virtual int create();
00177   virtual int compact( bool );
00178   virtual bool isReadOnly() const;
00179   virtual const KMMsgBase* getMsgBase(int idx) const;
00180   virtual KMMsgBase* getMsgBase(int idx);
00181   virtual int find(const KMMsgBase* msg) const;
00182   virtual QString indexLocation() const;
00183   virtual int writeIndex( bool createEmptyIndex = false );
00184   DwString getDwString(int idx);
00185   Q_UINT32 serNum(int idx) { return mSerNums[idx]; }
00186 
00187 protected:
00188   virtual FolderJob* doCreateJob(KMMessage *msg, FolderJob::JobType jt,
00189                                  KMFolder *folder, QString partSpecifier,
00190                                  const AttachmentStrategy *as ) const;
00191   virtual FolderJob* doCreateJob(QPtrList<KMMessage>& msgList, const QString& sets,
00192                                  FolderJob::JobType jt, KMFolder *folder) const;
00193   virtual KMMessage* readMsg(int idx);
00194   virtual bool readIndex();
00195   virtual int removeContents();
00196   virtual int expungeContents();
00197   virtual int count(bool cache = false) const;
00198   virtual KMMsgBase* takeIndexEntry(int idx);
00199   virtual KMMsgInfo* setIndexEntry(int idx, KMMessage *msg);
00200   virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
00201   virtual void truncateIndex();
00202 
00203 private:
00204   QValueVector<Q_UINT32> mSerNums;
00205   QValueList<QGuardedPtr<KMFolder> > mFolders;
00206   QValueStack<Q_UINT32> mUnexaminedMessages;
00207   FILE *mIdsStream;
00208   KMSearch *mSearch;
00209   bool mInvalid, mUnlinked;
00210   bool mTempOpened;
00211   QTimer *mExecuteSearchTimer;
00212   QMap<const KMFolder*, unsigned int>mFoldersCurrentlyBeingSearched;
00213 };
00214 #endif /*kmfoldersearch_h*/
00215 
KDE Home | KDE Accessibility Home | Description of Access Keys