kmail Library API Documentation

kmfoldersearch.h

00001 /* Dynamic search folder
00002  *
00003  * Author: Don Sanders <sanders@kde.org>
00004  * License: GPL
00005  */
00006 #ifndef kmfoldersearch_h
00007 #define kmfoldersearch_h
00008 
00009 #include <qguardedptr.h>
00010 #include <qvaluelist.h>
00011 #include <qvaluevector.h>
00012 #include <qvaluestack.h>
00013 #include "kmfolder.h"
00014 #include "folderstorage.h"
00015 
00025 typedef QValueList<Q_UINT32> SerNumList;
00026 class KMSearchPattern;
00027 class KMFolderImap;
00028 class QTimer;
00029 
00030 namespace KMail {
00031    class AttachmentStrategy;
00032 }
00033 using KMail::AttachmentStrategy;
00034 
00035 class KMSearch: public QObject
00036 {
00037   Q_OBJECT
00038 
00039 public:
00040   KMSearch(QObject * parent = 0, const char * name = 0);
00041   ~KMSearch();
00042 
00043   bool write(QString location) const;
00044   bool read(QString location);
00045   bool recursive() const { return mRecursive; }
00046   void setRecursive(bool recursive) { if (running()) stop(); mRecursive = recursive; }
00047   KMFolder* root() const { return mRoot; }
00048   void setRoot(KMFolder *folder) { if (running()) stop(); mRoot = folder; }
00049   bool inScope(KMFolder* folder) const;
00050   //Takes ownership of @searchPattern
00051   void setSearchPattern(KMSearchPattern *searchPattern);
00052   KMSearchPattern* searchPattern() const { return mSearchPattern; }
00053   void start();
00054   bool running() const { return mRunning; }
00055   void stop();
00056   int foundCount() const { return mFoundCount; }
00057   int searchedCount() const { return mSearchedCount; }
00058   QString currentFolder() const { return mLastFolder; }
00059 
00060 signals:
00061   void found(Q_UINT32 serNum);
00062   void finished(bool success);
00063 
00064 protected slots:
00065   void slotProcessNextBatch();
00066   void slotFolderComplete(KMFolderImap *folder, bool success);
00067 
00068 protected:
00069   friend class KMIndexSearchTarget;
00070   void setRunning(bool b) { mRunning = b; }
00071   void setFoundCount(int f) { mFoundCount = f; }
00072   void setSearchedCount(int f) { mSearchedCount = f; }
00073   void setCurrentFolder(const QString &f) { mLastFolder = f; }
00074 
00075 private:
00076   int mRemainingMessages;
00077   int mRemainingFolders;
00078   bool mRecursive, mRunning, mIdle, mRunByIndex;
00079   QGuardedPtr<KMFolder> mRoot;
00080   KMSearchPattern* mSearchPattern;
00081   QValueList<QGuardedPtr<KMFolder> > mFolders, mOpenedFolders;
00082   QValueList<QGuardedPtr<KMFolderImap> > mIncompleteFolders;
00083   SerNumList mSerNums;
00084   QString mLastFolder;
00085   int mSearchedCount, mFoundCount;
00086   QTimer *mProcessNextBatchTimer;
00087 };
00088 
00089 class KMFolderSearch: public FolderStorage
00090 {
00091   Q_OBJECT
00092   friend class KMFolderSearchJob;
00093 public:
00094   KMFolderSearch(KMFolder* folder, const char* name=0);
00095   virtual ~KMFolderSearch();
00096 
00098   virtual KMFolderType folderType() const { return KMFolderTypeSearch; }
00099 
00100   // Sets and runs the search used by the folder
00101   void setSearch(KMSearch *search);
00102   // Returns the current search used by the folder
00103   const KMSearch* search() const;
00104   // Stops the current search
00105   void stopSearch() { if (mSearch) mSearch->stop(); }
00106 
00107   virtual KMMessage* getMsg(int idx);
00108   virtual void ignoreJobsForMessage( KMMessage* );
00109 
00110   virtual void tryReleasingFolder(KMFolder* folder);
00111 
00112 protected slots:
00113   // Reads search definition for this folder and creates a KMSearch
00114   bool readSearch();
00115   // Runs the current search again
00116   void executeSearch();
00117   // Called when the search is finished
00118   void searchFinished(bool success);
00119   // Look at a new message and if it matches search() add it to the cache
00120   void examineAddedMessage(KMFolder *folder, Q_UINT32 serNum);
00121   // Look at all new messages in a completed (imap) folder
00122   void examineCompletedFolder(KMFolderImap *folder, bool success);
00123   // Look at a removed message and remove it from the cache
00124   void examineRemovedMessage(KMFolder *folder, Q_UINT32 serNum);
00125   // Look at a message whose status has changed
00126   void examineChangedMessage(KMFolder *folder, Q_UINT32 serNum, int delta);
00127   // The serial numbers for a folder have been invalidated, deal with it
00128   void examineInvalidatedFolder(KMFolder *folder);
00129   // A folder has been deleted, deal with it
00130   void examineRemovedFolder(KMFolder *folder);
00131   // Propagate the msgHeaderChanged signal
00132   void propagateHeaderChanged(KMFolder *folder, int idx);
00133 
00134 public slots:
00135   // Appends the serial number to the cached list of messages that match
00136   // the search for this folder
00137   void addSerNum(Q_UINT32 serNum);
00138   // Removes the serial number from the cached list of messages that match
00139   // the search for this folder
00140   void removeSerNum(Q_UINT32 serNum);
00141 
00143   virtual int updateIndex();
00144 
00145 public:
00146   //See base class for documentation
00147   virtual QCString& getMsgString(int idx, QCString& mDest);
00148   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00149   virtual int open();
00150   virtual int canAccess();
00151   virtual void sync();
00152   virtual void close(bool force=FALSE);
00153   virtual int create(bool imap = FALSE);
00154   virtual int compact( bool );
00155   virtual bool isReadOnly() const;
00156   virtual const KMMsgBase* getMsgBase(int idx) const;
00157   virtual KMMsgBase* getMsgBase(int idx);
00158   virtual int find(const KMMsgBase* msg) const;
00159   virtual QString indexLocation() const;
00160   virtual int writeIndex( bool createEmptyIndex = false );
00161   DwString getDwString(int idx);
00162   Q_UINT32 serNum(int idx) { return mSerNums[idx]; }
00163 
00164 protected:
00165   virtual FolderJob* doCreateJob(KMMessage *msg, FolderJob::JobType jt,
00166                                  KMFolder *folder, QString partSpecifier,
00167                                  const AttachmentStrategy *as ) const;
00168   virtual FolderJob* doCreateJob(QPtrList<KMMessage>& msgList, const QString& sets,
00169                                  FolderJob::JobType jt, KMFolder *folder) const;
00170   virtual KMMessage* readMsg(int idx);
00171   virtual bool readIndex();
00172   virtual int removeContents();
00173   virtual int expungeContents();
00174   virtual int count(bool cache = false) const;
00175   virtual KMMsgBase* takeIndexEntry(int idx);
00176   virtual KMMsgInfo* setIndexEntry(int idx, KMMessage *msg);
00177   virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
00178   virtual void fillDictFromIndex(KMMsgDict*);
00179   virtual void truncateIndex();
00180 
00181 private:
00182   QValueVector<Q_UINT32> mSerNums;
00183   QValueList<QGuardedPtr<KMFolder> > mFolders;
00184   QValueStack<Q_UINT32> mUnexaminedMessages;
00185   FILE *mIdsStream;
00186   KMSearch *mSearch;
00187   bool mInvalid, mUnlinked;
00188   bool mTempOpened;
00189   QTimer *mExecuteSearchTimer;
00190 };
00191 #endif /*kmfoldersearch_h*/
00192 
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 25 11:20:09 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003