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 KMAccount;
00055 class KMFolderDir;
00056 class KMMsgDict; // for the rDict manipulations
00057 class KMMsgDictREntry;
00058 class QTimer;
00059 class KMSearchPattern;
00060 
00061 namespace KMail {
00062    class AttachmentStrategy;
00063 }
00064 using KMail::AttachmentStrategy;
00065 
00066 typedef QValueList<Q_UINT32> SerNumList;
00067 
00079 class FolderStorage : public QObject
00080 {
00081   Q_OBJECT
00082 
00083 public:
00084 
00085 
00089   FolderStorage( KMFolder* folder, const char* name=0 );
00090   virtual ~FolderStorage();
00091 
00092   KMFolder* folder() const { return mFolder; }
00093 
00095   virtual KMFolderType folderType() const { return KMFolderTypeUnknown; }
00096 
00098   virtual QString fileName() const;
00100   QString location() const;
00101 
00103   virtual QString indexLocation() const = 0;
00104 
00106   virtual bool noContent() const { return mNoContent; }
00107 
00109   virtual void setNoContent(bool 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 DwString getDwString(int idx) = 0;
00150 
00154   virtual void ignoreJobsForMessage( KMMessage* );
00155 
00160   virtual FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00161                                 KMFolder *folder = 0, QString partSpecifier = QString::null,
00162                                 const AttachmentStrategy *as = 0 ) const;
00163   virtual FolderJob* createJob( QPtrList<KMMessage>& msgList, const QString& sets,
00164                                 FolderJob::JobType jt = FolderJob::tGetMessage,
00165                                 KMFolder *folder = 0 ) const;
00166 
00171   virtual const KMMsgBase* getMsgBase(int idx) const = 0;
00172   virtual KMMsgBase* getMsgBase(int idx) = 0;
00173 
00175   virtual const KMMsgBase* operator[](int idx) const { return getMsgBase(idx); }
00176 
00178   virtual KMMsgBase* operator[](int idx) { return getMsgBase(idx); }
00179 
00182   virtual KMMessage* take(int idx);
00183   virtual void take(QPtrList<KMMessage> msgList);
00184 
00191   virtual int addMsg(KMMessage* msg, int* index_return = 0) = 0;
00192 
00196   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00197     return addMsg(msg, index_return);
00198   }
00199 
00204   virtual int addMsg( QPtrList<KMMessage>&, QValueList<int>& index_return );
00205 
00208   void emitMsgAddedSignals(int idx);
00209 
00212   virtual bool canAddMsgNow(KMMessage* aMsg, int* aIndex_ret);
00213 
00215   virtual void removeMsg(int i, bool imapQuiet = false);
00216   virtual void removeMsg(const QPtrList<KMMsgBase>& msgList, bool imapQuiet = false);
00217   virtual void removeMsg(const QPtrList<KMMessage>& msgList, bool imapQuiet = false);
00218 
00221   virtual int expungeOldMsg(int days);
00222 
00227   virtual int moveMsg(KMMessage* msg, int* index_return = 0);
00228   virtual int moveMsg(QPtrList<KMMessage>, int* index_return = 0);
00229 
00231   virtual int find(const KMMsgBase* msg) const = 0;
00232   int find( const KMMessage * msg ) const;
00233 
00235   virtual int count(bool cache = false) const;
00236 
00238   virtual int countUnread();
00239 
00241   Q_INT64 folderSize() const;
00242 
00245   virtual bool isCloseToQuota() const;
00246 
00249   virtual void msgStatusChanged( const KMMsgStatus oldStatus,
00250                                  const KMMsgStatus newStatus,
00251                  int idx);
00252 
00258   virtual int open(const char* owner) = 0;
00259 
00262   virtual int canAccess() = 0;
00263 
00267   void close(const char* owner, bool force=false);
00268   virtual void reallyDoClose(const char* owner) = 0;
00269 
00272   virtual void tryReleasingFolder(KMFolder*) {}
00273 
00275   virtual void sync() = 0;
00276 
00278   bool isOpened() const { return (mOpenCount>0); }
00279 
00281   virtual void markNewAsUnread();
00282 
00284   virtual void markUnreadAsRead();
00285 
00289   virtual int create() = 0;
00290 
00295   virtual void remove();
00296 
00300   virtual int expunge();
00301 
00306   virtual int compact( bool silent ) = 0;
00307 
00310   virtual int rename(const QString& newName, KMFolderDir *aParent = 0);
00311 
00313   bool autoCreateIndex() const { return mAutoCreateIndex; }
00314 
00317   virtual void setAutoCreateIndex(bool);
00318 
00322   bool dirty() const { return mDirty; }
00323 
00325   void setDirty(bool f);
00326 
00328   bool needsCompacting() const { return needsCompact; }
00329   virtual void setNeedsCompacting(bool f) { needsCompact = f; }
00330 
00339   virtual void quiet(bool beQuiet);
00340 
00342   virtual bool isReadOnly() const = 0;
00343 
00345   virtual bool canDeleteMessages() const;
00346 
00348   QString label() const;
00349 
00351   virtual void correctUnreadMsgsCount();
00352 
00355   virtual int writeIndex( bool createEmptyIndex = false ) = 0;
00356 
00359   void registerWithMessageDict();
00360 
00363   void deregisterFromMessageDict();
00364 
00366   virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00367 
00369   virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00370 
00371   void removeJobs();
00372 
00374   static QString dotEscape(const QString&);
00375 
00377   virtual void readConfig();
00378 
00380   virtual void writeConfig();
00381 
00386   virtual KMFolder* trashFolder() const { return 0; }
00387 
00392   void addJob( FolderJob* ) const;
00393 
00395   bool compactable() const { return mCompactable; }
00396 
00398   // If quiet is true, the KMailIcalIface is not informed of the changed. That's usefull
00399   // for folder that are being copied around, should retain their type, but not cause
00400   // conflicts on copy because events are identical in two folders.
00401   virtual void setContentsType( KMail::FolderContentsType type, bool quiet = false );
00403   KMail::FolderContentsType contentsType() const { return mContentsType; }
00404 
00409   virtual void search( const KMSearchPattern* );
00410 
00415   virtual void search( const KMSearchPattern*, Q_UINT32 serNum );
00416 
00418   virtual bool isMoveable() const;
00419 
00420   virtual KMAccount* account() const;
00421 
00422   virtual bool mailCheckInProgress() const;
00423 
00424 signals:
00427   void changed();
00428 
00431   void cleared();
00432 
00435   void expunged( KMFolder* );
00436 
00438   void closed( KMFolder* );
00439 
00441   void invalidated( KMFolder * );
00442 
00444   void nameChanged();
00445 
00449   void locationChanged( const QString &, const QString & );
00450 
00453   void contentsTypeChanged( KMail::FolderContentsType type );
00454 
00456   void readOnlyChanged(KMFolder*);
00457 
00459   void noContentChanged();
00460 
00462   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00463 
00465   void msgRemoved( int idx, QString msgIdMD5 );
00466   void msgRemoved( KMFolder* );
00467 
00469   void msgAdded(int idx);
00470   void msgAdded(KMFolder*, Q_UINT32 sernum);
00471 
00473   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00474 
00476   void msgHeaderChanged(KMFolder*, int);
00477 
00479   void statusMsg(const QString&);
00480 
00482   void numUnreadMsgsChanged( KMFolder* );
00483 
00485   void removed(KMFolder*, bool);
00486 
00492   void searchResult( KMFolder*, QValueList<Q_UINT32>,
00493                      const KMSearchPattern*, bool complete );
00494 
00499   void searchDone( KMFolder*, Q_UINT32, const KMSearchPattern*, bool );
00500 
00502   void folderSizeChanged();
00503 
00508   void syncStateChanged();
00509 
00510 public slots:
00512   virtual int updateIndex() = 0;
00513 
00516   virtual void reallyAddMsg(KMMessage* aMsg);
00517 
00520   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00521 
00523   void slotEmitChangedTimer();
00524 
00525 protected slots:
00526   virtual void removeJob( QObject* );
00527 
00529   void slotProcessNextSearchBatch();
00530 
00531 protected:
00532 
00538   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00539                                   QString partSpecifier, const AttachmentStrategy *as ) const = 0;
00540   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00541                                   FolderJob::JobType jt, KMFolder *folder ) const = 0;
00542 
00546   void headerOfMsgChanged(const KMMsgBase*, int idx);
00547 
00550   virtual KMMessage* readMsg(int idx) = 0;
00551 
00552   //--------- Message Dict manipulation
00553 friend class KMMsgDict;
00557   virtual void fillMessageDict() {}
00558 
00562   void readFolderIdsFile();
00563 
00565   int writeFolderIdsFile() const;
00566 
00568   int touchFolderIdsFile();
00569 
00571   int appendToFolderIdsFile( int idx = -1 );
00572 
00576   void setRDict(KMMsgDictREntry *rentry) const;
00577 
00579   KMMsgDictREntry *rDict() const { return mRDict; }
00580 
00581 
00584   void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx );
00585 
00589   void invalidateFolder();
00590 
00594   virtual int removeContents() = 0;
00595 
00599   virtual int expungeContents() = 0;
00600 
00602   virtual bool readIndex() = 0;
00603   virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
00604   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
00605   virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
00606   virtual void truncateIndex() = 0;
00607 
00608   virtual Q_INT64 doFolderSize() const { return 0; };
00609 
00610   int mOpenCount;
00611   int mQuiet;
00612   bool mChanged :1;
00614   bool mAutoCreateIndex :1;
00617   bool mExportsSernums :1;
00619   bool mDirty :1;
00621   bool mFilesLocked :1;
00622 
00624   int mUnreadMsgs, mGuessedUnreadMsgs;
00625   int mTotalMsgs;
00626   Q_INT64 mSize;
00627   bool mWriteConfigEnabled :1;
00629   bool needsCompact :1;
00631   bool mCompactable :1;
00632   bool mNoContent :1;
00633   bool mNoChildren :1;
00634   bool mConvertToUtf8 :1;
00635 
00637   mutable KMMsgDictREntry *mRDict;
00639   mutable QPtrList<FolderJob> mJobList;
00640 
00641   QTimer *mDirtyTimer;
00642   enum { mDirtyTimerInterval = 600000 }; // 10 minutes
00643 
00644   ChildrenState mHasChildren;
00645 
00647   KMail::FolderContentsType mContentsType;
00648 
00649   KMFolder* mFolder;
00650 
00651   QTimer * mEmitChangedTimer;
00652 
00653   int mCurrentSearchedMsg;
00654   const KMSearchPattern* mSearchPattern;
00655 };
00656 
00657 #endif // FOLDERSTORAGE_H
KDE Home | KDE Accessibility Home | Description of Access Keys