kmail

folderstorage.h

00001 /*
00002     Virtual base class for mail storage.
00003 
00004     This file is part of KMail.
00005 
00006     Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 
00023     In addition, as a special exception, the copyright holders give
00024     permission to link the code of this program with any edition of
00025     the Qt library by Trolltech AS, Norway (or with modified versions
00026     of Qt that use the same license as Qt), and distribute linked
00027     combinations including the two.  You must obey the GNU General
00028     Public License in all respects for all of the code used other than
00029     Qt.  If you modify this file, you may extend this exception to
00030     your version of the file, but you are not obligated to do so.  If
00031     you do not wish to do so, delete this exception statement from
00032     your version.
00033 */
00034 
00035 #ifndef FOLDERSTORAGE_H
00036 #define FOLDERSTORAGE_H
00037 
00038 // for large file support
00039 #include <config.h>
00040 
00041 #include "kmfoldernode.h"
00042 #include "kmfoldertype.h"
00043 #include "kmmsginfo.h"
00044 #include "kmglobal.h"
00045 #include "folderjob.h"
00046 using KMail::FolderJob;
00047 
00048 #include "mimelib/string.h"
00049 
00050 #include <sys/types.h>
00051 #include <stdio.h>
00052 
00053 class KMMessage;
00054 class KMFolderDir;
00055 class KMMsgDict; // for the rDict manipulations
00056 class KMMsgDictREntry;
00057 class QTimer;
00058 class KMSearchPattern;
00059 
00060 namespace KMail {
00061    class AttachmentStrategy;
00062 }
00063 using KMail::AttachmentStrategy;
00064 
00065 typedef QValueList<Q_UINT32> SerNumList;
00066 
00078 class FolderStorage : public QObject
00079 {
00080   Q_OBJECT
00081 
00082 public:
00083 
00084 
00088   FolderStorage( KMFolder* folder, const char* name=0 );
00089   virtual ~FolderStorage();
00090 
00091   KMFolder* folder() const { return mFolder; }
00092 
00094   virtual KMFolderType folderType() const { return KMFolderTypeUnknown; }
00095 
00097   virtual QString fileName() const;
00099   QString location() const;
00100 
00102   virtual QString indexLocation() const = 0;
00103 
00105   virtual bool noContent() const { return mNoContent; }
00106 
00108   virtual void setNoContent(bool aNoContent)
00109     { mNoContent = aNoContent; }
00110 
00112   virtual bool noChildren() const { return mNoChildren; }
00113 
00115   virtual void setNoChildren( bool aNoChildren );
00116 
00117   enum ChildrenState {
00118     HasChildren,
00119     HasNoChildren,
00120     ChildrenUnknown
00121   };
00124   virtual ChildrenState hasChildren() const { return mHasChildren; }
00125 
00127   virtual void setHasChildren( ChildrenState state )
00128     { mHasChildren = state; }
00129 
00131   virtual void updateChildrenState();
00132 
00134   virtual KMMessage* getMsg(int idx);
00135 
00137   virtual KMMsgInfo* unGetMsg(int idx);
00138 
00140   virtual bool isMessage(int idx);
00141 
00146   virtual KMMessage* readTemporaryMsg(int idx);
00147 
00149   virtual QCString& getMsgString(int idx, QCString& mDest) = 0;
00150 
00152   virtual DwString getDwString(int idx) = 0;
00153 
00157   virtual void ignoreJobsForMessage( KMMessage* );
00158 
00163   virtual FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00164                                 KMFolder *folder = 0, QString partSpecifier = QString::null,
00165                                 const AttachmentStrategy *as = 0 ) const;
00166   virtual FolderJob* createJob( QPtrList<KMMessage>& msgList, const QString& sets,
00167                                 FolderJob::JobType jt = FolderJob::tGetMessage,
00168                                 KMFolder *folder = 0 ) const;
00169 
00174   virtual const KMMsgBase* getMsgBase(int idx) const = 0;
00175   virtual KMMsgBase* getMsgBase(int idx) = 0;
00176 
00178   virtual const KMMsgBase* operator[](int idx) const { return getMsgBase(idx); }
00179 
00181   virtual KMMsgBase* operator[](int idx) { return getMsgBase(idx); }
00182 
00185   virtual KMMessage* take(int idx);
00186   virtual void take(QPtrList<KMMessage> msgList);
00187 
00194   virtual int addMsg(KMMessage* msg, int* index_return = 0) = 0;
00195 
00199   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00200     return addMsg(msg, index_return);
00201   }
00202 
00207   virtual int addMsg( QPtrList<KMMessage>&, QValueList<int>& index_return );
00208 
00211   void emitMsgAddedSignals(int idx);
00212 
00215   virtual bool canAddMsgNow(KMMessage* aMsg, int* aIndex_ret);
00216 
00218   virtual void removeMsg(int i, bool imapQuiet = FALSE);
00219   virtual void removeMsg(const QPtrList<KMMsgBase>& msgList, bool imapQuiet = FALSE);
00220   virtual void removeMsg(const QPtrList<KMMessage>& msgList, bool imapQuiet = FALSE);
00221 
00224   virtual int expungeOldMsg(int days);
00225 
00230   virtual int moveMsg(KMMessage* msg, int* index_return = 0);
00231   virtual int moveMsg(QPtrList<KMMessage>, int* index_return = 0);
00232 
00234   virtual int find(const KMMsgBase* msg) const = 0;
00235   int find( const KMMessage * msg ) const;
00236 
00238   virtual int count(bool cache = false) const;
00239 
00241   virtual int countUnread();
00242 
00245   virtual void msgStatusChanged( const KMMsgStatus oldStatus,
00246                                  const KMMsgStatus newStatus,
00247                  int idx);
00248 
00254   virtual int open() = 0;
00255 
00258   virtual int canAccess() = 0;
00259 
00262   virtual void close(bool force=FALSE) = 0;
00263 
00266   virtual void tryReleasingFolder(KMFolder*) {}
00267 
00269   virtual void sync() = 0;
00270 
00272   bool isOpened() const { return (mOpenCount>0); }
00273 
00275   virtual void markNewAsUnread();
00276 
00278   virtual void markUnreadAsRead();
00279 
00283   virtual int create() = 0;
00284 
00289   virtual void remove();
00290 
00294   virtual int expunge();
00295 
00300   virtual int compact( bool silent ) = 0;
00301 
00304   virtual int rename(const QString& newName, KMFolderDir *aParent = 0);
00305 
00307   bool autoCreateIndex() const { return mAutoCreateIndex; }
00308 
00311   virtual void setAutoCreateIndex(bool);
00312 
00316   bool dirty() const { return mDirty; }
00317 
00319   void setDirty(bool f);
00320 
00322   bool needsCompacting() const { return needsCompact; }
00323   virtual void setNeedsCompacting(bool f) { needsCompact = f; }
00324 
00333   virtual void quiet(bool beQuiet);
00334 
00336   virtual bool isReadOnly() const = 0;
00337 
00339   QString label() const;
00340 
00342   virtual void correctUnreadMsgsCount();
00343 
00346   virtual int writeIndex( bool createEmptyIndex = false ) = 0;
00347 
00350   void registerWithMessageDict();
00351 
00354   void deregisterFromMessageDict();
00355 
00357   virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00358 
00360   virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00361 
00362   void removeJobs();
00363   
00365   static QString dotEscape(const QString&);
00366 
00368   virtual void readConfig();
00369 
00371   virtual void writeConfig();
00372 
00377   virtual KMFolder* trashFolder() const { return 0; }
00378 
00383   void addJob( FolderJob* ) const;
00384 
00386   bool compactable() const { return mCompactable; }
00387 
00389   virtual void setContentsType( KMail::FolderContentsType type );
00391   KMail::FolderContentsType contentsType() const { return mContentsType; }
00392 
00397   virtual void search( const KMSearchPattern* );
00398 
00403   virtual void search( const KMSearchPattern*, Q_UINT32 serNum );
00404 
00406   virtual bool isMoveable() const;  
00407 
00408 signals:
00411   void changed();
00412 
00415   void cleared();
00416 
00419   void expunged( KMFolder* );
00420 
00422   void invalidated( KMFolder * );
00423   
00425   void nameChanged();
00426 
00430   void locationChanged( const QString &, const QString & );
00431 
00434   void contentsTypeChanged( KMail::FolderContentsType type );
00435 
00437   void readOnlyChanged(KMFolder*);
00438 
00440   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00441 
00443   void msgRemoved( int idx, QString msgIdMD5 );
00444   void msgRemoved( KMFolder* );
00445 
00447   void msgAdded(int idx);
00448   void msgAdded(KMFolder*, Q_UINT32 sernum);
00449 
00451   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00452 
00454   void msgHeaderChanged(KMFolder*, int);
00455 
00457   void statusMsg(const QString&);
00458 
00460   void numUnreadMsgsChanged( KMFolder* );
00461 
00463   void removed(KMFolder*, bool);
00464 
00470   void searchResult( KMFolder*, QValueList<Q_UINT32>, 
00471                      const KMSearchPattern*, bool complete );
00472 
00477   void searchDone( KMFolder*, Q_UINT32, const KMSearchPattern*, bool );
00478 
00479 
00480 public slots:
00482   virtual int updateIndex() = 0;
00483 
00486   virtual void reallyAddMsg(KMMessage* aMsg);
00487 
00490   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00491   
00493   void slotEmitChangedTimer();
00494 
00495 protected slots:
00496   virtual void removeJob( QObject* );
00497 
00499   void slotProcessNextSearchBatch();
00500 
00501 protected:
00502 
00508   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00509                                   QString partSpecifier, const AttachmentStrategy *as ) const = 0;
00510   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00511                                   FolderJob::JobType jt, KMFolder *folder ) const = 0;
00512 
00516   void headerOfMsgChanged(const KMMsgBase*, int idx);
00517 
00520   virtual KMMessage* readMsg(int idx) = 0;
00521 
00522   //--------- Message Dict manipulation
00523 friend class KMMsgDict;
00527   virtual void fillMessageDict() {}
00528 
00532   void readFolderIdsFile();
00533 
00535   int writeFolderIdsFile() const;
00536 
00538   int touchFolderIdsFile();
00539 
00541   int appendToFolderIdsFile( int idx = -1 );
00542 
00546   void setRDict(KMMsgDictREntry *rentry) const;
00547 
00549   KMMsgDictREntry *rDict() const { return mRDict; }
00550 
00551 
00554   void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx );
00555   
00559   void invalidateFolder();
00560 
00564   virtual int removeContents() = 0;
00565 
00569   virtual int expungeContents() = 0;
00570   
00572   virtual bool readIndex() = 0;
00573   virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
00574   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
00575   virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
00576   virtual void truncateIndex() = 0;
00577 
00578   int mOpenCount;
00579   int mQuiet;
00580   bool mChanged :1;
00582   bool mAutoCreateIndex :1;
00585   bool mExportsSernums :1;
00587   bool mDirty :1;
00589   bool mFilesLocked :1;
00590   
00592   int mUnreadMsgs, mGuessedUnreadMsgs;
00593   int mTotalMsgs;
00594   bool mWriteConfigEnabled :1;
00596   bool needsCompact :1;
00598   bool mCompactable :1;
00599   bool mNoContent :1;
00600   bool mNoChildren :1;
00601   bool mConvertToUtf8 :1;
00602 
00604   mutable KMMsgDictREntry *mRDict;
00606   mutable QPtrList<FolderJob> mJobList;
00607 
00608   QTimer *mDirtyTimer;
00609   enum { mDirtyTimerInterval = 600000 }; // 10 minutes
00610 
00611   ChildrenState mHasChildren;
00612 
00614   KMail::FolderContentsType mContentsType;
00615 
00616   KMFolder* mFolder;
00617 
00618   QTimer * mEmitChangedTimer;
00619 
00620   int mCurrentSearchedMsg;
00621   const KMSearchPattern* mSearchPattern;
00622 };
00623 
00624 #endif // FOLDERSTORAGE_H
KDE Home | KDE Accessibility Home | Description of Access Keys