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     { mNoContent = aNoContent; }
00111 
00113   virtual bool noChildren() const { return mNoChildren; }
00114 
00116   virtual void setNoChildren( bool aNoChildren );
00117 
00118   enum ChildrenState {
00119     HasChildren,
00120     HasNoChildren,
00121     ChildrenUnknown
00122   };
00125   virtual ChildrenState hasChildren() const { return mHasChildren; }
00126 
00128   virtual void setHasChildren( ChildrenState state )
00129     { mHasChildren = state; }
00130 
00132   virtual void updateChildrenState();
00133 
00135   virtual KMMessage* getMsg(int idx);
00136 
00138   virtual KMMsgInfo* unGetMsg(int idx);
00139 
00141   virtual bool isMessage(int idx);
00142 
00147   virtual KMMessage* readTemporaryMsg(int idx);
00148 
00150   virtual DwString getDwString(int idx) = 0;
00151 
00155   virtual void ignoreJobsForMessage( KMMessage* );
00156 
00161   virtual FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00162                                 KMFolder *folder = 0, QString partSpecifier = QString::null,
00163                                 const AttachmentStrategy *as = 0 ) const;
00164   virtual FolderJob* createJob( QPtrList<KMMessage>& msgList, const QString& sets,
00165                                 FolderJob::JobType jt = FolderJob::tGetMessage,
00166                                 KMFolder *folder = 0 ) const;
00167 
00172   virtual const KMMsgBase* getMsgBase(int idx) const = 0;
00173   virtual KMMsgBase* getMsgBase(int idx) = 0;
00174 
00176   virtual const KMMsgBase* operator[](int idx) const { return getMsgBase(idx); }
00177 
00179   virtual KMMsgBase* operator[](int idx) { return getMsgBase(idx); }
00180 
00183   virtual KMMessage* take(int idx);
00184   virtual void take(QPtrList<KMMessage> msgList);
00185 
00192   virtual int addMsg(KMMessage* msg, int* index_return = 0) = 0;
00193 
00197   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00198     return addMsg(msg, index_return);
00199   }
00200 
00205   virtual int addMsg( QPtrList<KMMessage>&, QValueList<int>& index_return );
00206 
00209   void emitMsgAddedSignals(int idx);
00210 
00213   virtual bool canAddMsgNow(KMMessage* aMsg, int* aIndex_ret);
00214 
00216   virtual void removeMsg(int i, bool imapQuiet = false);
00217   virtual void removeMsg(const QPtrList<KMMsgBase>& msgList, bool imapQuiet = false);
00218   virtual void removeMsg(const QPtrList<KMMessage>& msgList, bool imapQuiet = false);
00219 
00222   virtual int expungeOldMsg(int days);
00223 
00228   virtual int moveMsg(KMMessage* msg, int* index_return = 0);
00229   virtual int moveMsg(QPtrList<KMMessage>, int* index_return = 0);
00230 
00232   virtual int find(const KMMsgBase* msg) const = 0;
00233   int find( const KMMessage * msg ) const;
00234 
00236   virtual int count(bool cache = false) const;
00237 
00239   virtual int countUnread();
00240 
00242   Q_INT64 folderSize() const;
00243 
00246   virtual bool isCloseToQuota() const;
00247 
00250   virtual void msgStatusChanged( const KMMsgStatus oldStatus,
00251                                  const KMMsgStatus newStatus,
00252                  int idx);
00253 
00259   virtual int open(const char* owner) = 0;
00260 
00263   virtual int canAccess() = 0;
00264 
00268   void close(const char* owner, bool force=false);
00269   virtual void reallyDoClose(const char* owner) = 0;
00270 
00273   virtual void tryReleasingFolder(KMFolder*) {}
00274 
00276   virtual void sync() = 0;
00277 
00279   bool isOpened() const { return (mOpenCount>0); }
00280 
00282   virtual void markNewAsUnread();
00283 
00285   virtual void markUnreadAsRead();
00286 
00290   virtual int create() = 0;
00291 
00296   virtual void remove();
00297 
00301   virtual int expunge();
00302 
00307   virtual int compact( bool silent ) = 0;
00308 
00311   virtual int rename(const QString& newName, KMFolderDir *aParent = 0);
00312 
00314   bool autoCreateIndex() const { return mAutoCreateIndex; }
00315 
00318   virtual void setAutoCreateIndex(bool);
00319 
00323   bool dirty() const { return mDirty; }
00324 
00326   void setDirty(bool f);
00327 
00329   bool needsCompacting() const { return needsCompact; }
00330   virtual void setNeedsCompacting(bool f) { needsCompact = f; }
00331 
00340   virtual void quiet(bool beQuiet);
00341 
00343   virtual bool isReadOnly() const = 0;
00344 
00346   virtual bool canDeleteMessages() const;
00347 
00349   QString label() const;
00350 
00352   virtual void correctUnreadMsgsCount();
00353 
00356   virtual int writeIndex( bool createEmptyIndex = false ) = 0;
00357 
00360   void registerWithMessageDict();
00361 
00364   void deregisterFromMessageDict();
00365 
00367   virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00368 
00370   virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00371 
00372   void removeJobs();
00373 
00375   static QString dotEscape(const QString&);
00376 
00378   virtual void readConfig();
00379 
00381   virtual void writeConfig();
00382 
00387   virtual KMFolder* trashFolder() const { return 0; }
00388 
00393   void addJob( FolderJob* ) const;
00394 
00396   bool compactable() const { return mCompactable; }
00397 
00399   // If quiet is true, the KMailIcalIface is not informed of the changed. That's usefull
00400   // for folder that are being copied around, should retain their type, but not cause
00401   // conflicts on copy because events are identical in two folders.
00402   virtual void setContentsType( KMail::FolderContentsType type, bool quiet = false );
00404   KMail::FolderContentsType contentsType() const { return mContentsType; }
00405 
00410   virtual void search( const KMSearchPattern* );
00411 
00416   virtual void search( const KMSearchPattern*, Q_UINT32 serNum );
00417 
00419   virtual bool isMoveable() const;
00420 
00421   virtual KMAccount* account() const;
00422 
00423 signals:
00426   void changed();
00427 
00430   void cleared();
00431 
00434   void expunged( KMFolder* );
00435 
00437   void closed( KMFolder* );
00438 
00440   void invalidated( KMFolder * );
00441 
00443   void nameChanged();
00444 
00448   void locationChanged( const QString &, const QString & );
00449 
00452   void contentsTypeChanged( KMail::FolderContentsType type );
00453 
00455   void readOnlyChanged(KMFolder*);
00456 
00458   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00459 
00461   void msgRemoved( int idx, QString msgIdMD5 );
00462   void msgRemoved( KMFolder* );
00463 
00465   void msgAdded(int idx);
00466   void msgAdded(KMFolder*, Q_UINT32 sernum);
00467 
00469   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00470 
00472   void msgHeaderChanged(KMFolder*, int);
00473 
00475   void statusMsg(const QString&);
00476 
00478   void numUnreadMsgsChanged( KMFolder* );
00479 
00481   void removed(KMFolder*, bool);
00482 
00488   void searchResult( KMFolder*, QValueList<Q_UINT32>,
00489                      const KMSearchPattern*, bool complete );
00490 
00495   void searchDone( KMFolder*, Q_UINT32, const KMSearchPattern*, bool );
00496 
00498   void folderSizeChanged();
00499 
00500 
00501 public slots:
00503   virtual int updateIndex() = 0;
00504 
00507   virtual void reallyAddMsg(KMMessage* aMsg);
00508 
00511   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00512 
00514   void slotEmitChangedTimer();
00515 
00516 protected slots:
00517   virtual void removeJob( QObject* );
00518 
00520   void slotProcessNextSearchBatch();
00521 
00522 protected:
00523 
00529   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00530                                   QString partSpecifier, const AttachmentStrategy *as ) const = 0;
00531   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00532                                   FolderJob::JobType jt, KMFolder *folder ) const = 0;
00533 
00537   void headerOfMsgChanged(const KMMsgBase*, int idx);
00538 
00541   virtual KMMessage* readMsg(int idx) = 0;
00542 
00543   //--------- Message Dict manipulation
00544 friend class KMMsgDict;
00548   virtual void fillMessageDict() {}
00549 
00553   void readFolderIdsFile();
00554 
00556   int writeFolderIdsFile() const;
00557 
00559   int touchFolderIdsFile();
00560 
00562   int appendToFolderIdsFile( int idx = -1 );
00563 
00567   void setRDict(KMMsgDictREntry *rentry) const;
00568 
00570   KMMsgDictREntry *rDict() const { return mRDict; }
00571 
00572 
00575   void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx );
00576 
00580   void invalidateFolder();
00581 
00585   virtual int removeContents() = 0;
00586 
00590   virtual int expungeContents() = 0;
00591 
00593   virtual bool readIndex() = 0;
00594   virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
00595   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
00596   virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
00597   virtual void truncateIndex() = 0;
00598 
00599   virtual Q_INT64 doFolderSize() const { return 0; };
00600 
00601   int mOpenCount;
00602   int mQuiet;
00603   bool mChanged :1;
00605   bool mAutoCreateIndex :1;
00608   bool mExportsSernums :1;
00610   bool mDirty :1;
00612   bool mFilesLocked :1;
00613 
00615   int mUnreadMsgs, mGuessedUnreadMsgs;
00616   int mTotalMsgs;
00617   Q_INT64 mSize;
00618   bool mWriteConfigEnabled :1;
00620   bool needsCompact :1;
00622   bool mCompactable :1;
00623   bool mNoContent :1;
00624   bool mNoChildren :1;
00625   bool mConvertToUtf8 :1;
00626 
00628   mutable KMMsgDictREntry *mRDict;
00630   mutable QPtrList<FolderJob> mJobList;
00631 
00632   QTimer *mDirtyTimer;
00633   enum { mDirtyTimerInterval = 600000 }; // 10 minutes
00634 
00635   ChildrenState mHasChildren;
00636 
00638   KMail::FolderContentsType mContentsType;
00639 
00640   KMFolder* mFolder;
00641 
00642   QTimer * mEmitChangedTimer;
00643 
00644   int mCurrentSearchedMsg;
00645   const KMSearchPattern* mSearchPattern;
00646 };
00647 
00648 #endif // FOLDERSTORAGE_H
KDE Home | KDE Accessibility Home | Description of Access Keys