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 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   size_t 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   QString label() const;
00346 
00348   virtual void correctUnreadMsgsCount();
00349 
00352   virtual int writeIndex( bool createEmptyIndex = false ) = 0;
00353 
00356   void registerWithMessageDict();
00357 
00360   void deregisterFromMessageDict();
00361 
00363   virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00364 
00366   virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00367 
00368   void removeJobs();
00369 
00371   static QString dotEscape(const QString&);
00372 
00374   virtual void readConfig();
00375 
00377   virtual void writeConfig();
00378 
00383   virtual KMFolder* trashFolder() const { return 0; }
00384 
00389   void addJob( FolderJob* ) const;
00390 
00392   bool compactable() const { return mCompactable; }
00393 
00395   // If quiet is true, the KMailIcalIface is not informed of the changed. That's usefull
00396   // for folder that are being copied around, should retain their type, but not cause
00397   // conflicts on copy because events are identical in two folders.
00398   virtual void setContentsType( KMail::FolderContentsType type, bool quiet = false );
00400   KMail::FolderContentsType contentsType() const { return mContentsType; }
00401 
00406   virtual void search( const KMSearchPattern* );
00407 
00412   virtual void search( const KMSearchPattern*, Q_UINT32 serNum );
00413 
00415   virtual bool isMoveable() const;
00416 
00417 signals:
00420   void changed();
00421 
00424   void cleared();
00425 
00428   void expunged( KMFolder* );
00429 
00431   void invalidated( KMFolder * );
00432 
00434   void nameChanged();
00435 
00439   void locationChanged( const QString &, const QString & );
00440 
00443   void contentsTypeChanged( KMail::FolderContentsType type );
00444 
00446   void readOnlyChanged(KMFolder*);
00447 
00449   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00450 
00452   void msgRemoved( int idx, QString msgIdMD5 );
00453   void msgRemoved( KMFolder* );
00454 
00456   void msgAdded(int idx);
00457   void msgAdded(KMFolder*, Q_UINT32 sernum);
00458 
00460   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00461 
00463   void msgHeaderChanged(KMFolder*, int);
00464 
00466   void statusMsg(const QString&);
00467 
00469   void numUnreadMsgsChanged( KMFolder* );
00470 
00472   void removed(KMFolder*, bool);
00473 
00479   void searchResult( KMFolder*, QValueList<Q_UINT32>,
00480                      const KMSearchPattern*, bool complete );
00481 
00486   void searchDone( KMFolder*, Q_UINT32, const KMSearchPattern*, bool );
00487 
00489   void folderSizeChanged();
00490 
00491 
00492 public slots:
00494   virtual int updateIndex() = 0;
00495 
00498   virtual void reallyAddMsg(KMMessage* aMsg);
00499 
00502   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00503 
00505   void slotEmitChangedTimer();
00506 
00507 protected slots:
00508   virtual void removeJob( QObject* );
00509 
00511   void slotProcessNextSearchBatch();
00512 
00513 protected:
00514 
00520   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00521                                   QString partSpecifier, const AttachmentStrategy *as ) const = 0;
00522   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00523                                   FolderJob::JobType jt, KMFolder *folder ) const = 0;
00524 
00528   void headerOfMsgChanged(const KMMsgBase*, int idx);
00529 
00532   virtual KMMessage* readMsg(int idx) = 0;
00533 
00534   //--------- Message Dict manipulation
00535 friend class KMMsgDict;
00539   virtual void fillMessageDict() {}
00540 
00544   void readFolderIdsFile();
00545 
00547   int writeFolderIdsFile() const;
00548 
00550   int touchFolderIdsFile();
00551 
00553   int appendToFolderIdsFile( int idx = -1 );
00554 
00558   void setRDict(KMMsgDictREntry *rentry) const;
00559 
00561   KMMsgDictREntry *rDict() const { return mRDict; }
00562 
00563 
00566   void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx );
00567 
00571   void invalidateFolder();
00572 
00576   virtual int removeContents() = 0;
00577 
00581   virtual int expungeContents() = 0;
00582 
00584   virtual bool readIndex() = 0;
00585   virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
00586   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
00587   virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
00588   virtual void truncateIndex() = 0;
00589 
00590   virtual size_t doFolderSize() const { return 0; };
00591 
00592   int mOpenCount;
00593   int mQuiet;
00594   bool mChanged :1;
00596   bool mAutoCreateIndex :1;
00599   bool mExportsSernums :1;
00601   bool mDirty :1;
00603   bool mFilesLocked :1;
00604 
00606   int mUnreadMsgs, mGuessedUnreadMsgs;
00607   int mTotalMsgs;
00608   long mSize;
00609   bool mWriteConfigEnabled :1;
00611   bool needsCompact :1;
00613   bool mCompactable :1;
00614   bool mNoContent :1;
00615   bool mNoChildren :1;
00616   bool mConvertToUtf8 :1;
00617 
00619   mutable KMMsgDictREntry *mRDict;
00621   mutable QPtrList<FolderJob> mJobList;
00622 
00623   QTimer *mDirtyTimer;
00624   enum { mDirtyTimerInterval = 600000 }; // 10 minutes
00625 
00626   ChildrenState mHasChildren;
00627 
00629   KMail::FolderContentsType mContentsType;
00630 
00631   KMFolder* mFolder;
00632 
00633   QTimer * mEmitChangedTimer;
00634 
00635   int mCurrentSearchedMsg;
00636   const KMSearchPattern* mSearchPattern;
00637 };
00638 
00639 #endif // FOLDERSTORAGE_H
KDE Home | KDE Accessibility Home | Description of Access Keys