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 
00242   virtual void msgStatusChanged( const KMMsgStatus oldStatus,
00243                                  const KMMsgStatus newStatus,
00244                  int idx);
00245 
00251   virtual int open(const char *owner) = 0;
00252 
00255   virtual int canAccess() = 0;
00256 
00259   virtual void close(const char * owner,bool force=FALSE) = 0;
00260 
00263   virtual void tryReleasingFolder(KMFolder*) {}
00264 
00266   virtual void sync() = 0;
00267 
00269   bool isOpened() const { return (mOpenCount>0); }
00270 
00272   virtual void markNewAsUnread();
00273 
00275   virtual void markUnreadAsRead();
00276 
00280   virtual int create() = 0;
00281 
00286   virtual void remove();
00287 
00291   virtual int expunge();
00292 
00297   virtual int compact( bool silent ) = 0;
00298 
00301   virtual int rename(const QString& newName, KMFolderDir *aParent = 0);
00302 
00304   bool autoCreateIndex() const { return mAutoCreateIndex; }
00305 
00308   virtual void setAutoCreateIndex(bool);
00309 
00313   bool dirty() const { return mDirty; }
00314 
00316   void setDirty(bool f);
00317 
00319   bool needsCompacting() const { return needsCompact; }
00320   virtual void setNeedsCompacting(bool f) { needsCompact = f; }
00321 
00330   virtual void quiet(bool beQuiet);
00331 
00333   virtual bool isReadOnly() const = 0;
00334 
00336   QString label() const;
00337 
00339   virtual void correctUnreadMsgsCount();
00340 
00343   virtual int writeIndex( bool createEmptyIndex = false ) = 0;
00344 
00347   void registerWithMessageDict();
00348 
00351   void deregisterFromMessageDict();
00352 
00354   virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00355 
00357   virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00358 
00359   void removeJobs();
00360 
00362   static QString dotEscape(const QString&);
00363 
00365   virtual void readConfig();
00366 
00368   virtual void writeConfig();
00369 
00374   virtual KMFolder* trashFolder() const { return 0; }
00375 
00380   void addJob( FolderJob* ) const;
00381 
00383   bool compactable() const { return mCompactable; }
00384 
00386   // If quiet is true, the KMailIcalIface is not informed of the changed. That's usefull
00387   // for folder that are being copied around, should retain their type, but not cause
00388   // conflicts on copy because events are identical in two folders.
00389   virtual void setContentsType( KMail::FolderContentsType type, bool quiet = false );
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 closed( KMFolder* );
00423   
00425   void invalidated( KMFolder * );
00426 
00428   void nameChanged();
00429 
00433   void locationChanged( const QString &, const QString & );
00434 
00437   void contentsTypeChanged( KMail::FolderContentsType type );
00438 
00440   void readOnlyChanged(KMFolder*);
00441 
00443   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00444 
00446   void msgRemoved( int idx, QString msgIdMD5 );
00447   void msgRemoved( KMFolder* );
00448 
00450   void msgAdded(int idx);
00451   void msgAdded(KMFolder*, Q_UINT32 sernum);
00452 
00454   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00455 
00457   void msgHeaderChanged(KMFolder*, int);
00458 
00460   void statusMsg(const QString&);
00461 
00463   void numUnreadMsgsChanged( KMFolder* );
00464 
00466   void removed(KMFolder*, bool);
00467 
00473   void searchResult( KMFolder*, QValueList<Q_UINT32>,
00474                      const KMSearchPattern*, bool complete );
00475 
00480   void searchDone( KMFolder*, Q_UINT32, const KMSearchPattern*, bool );
00481 
00482 
00483 public slots:
00485   virtual int updateIndex() = 0;
00486 
00489   virtual void reallyAddMsg(KMMessage* aMsg);
00490 
00493   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00494 
00496   void slotEmitChangedTimer();
00497 
00498 protected slots:
00499   virtual void removeJob( QObject* );
00500 
00502   void slotProcessNextSearchBatch();
00503 
00504 protected:
00505 
00511   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00512                                   QString partSpecifier, const AttachmentStrategy *as ) const = 0;
00513   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00514                                   FolderJob::JobType jt, KMFolder *folder ) const = 0;
00515 
00519   void headerOfMsgChanged(const KMMsgBase*, int idx);
00520 
00523   virtual KMMessage* readMsg(int idx) = 0;
00524 
00525   //--------- Message Dict manipulation
00526 friend class KMMsgDict;
00530   virtual void fillMessageDict() {}
00531 
00535   void readFolderIdsFile();
00536 
00538   int writeFolderIdsFile() const;
00539 
00541   int touchFolderIdsFile();
00542 
00544   int appendToFolderIdsFile( int idx = -1 );
00545 
00549   void setRDict(KMMsgDictREntry *rentry) const;
00550 
00552   KMMsgDictREntry *rDict() const { return mRDict; }
00553 
00554 
00557   void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx );
00558 
00562   void invalidateFolder();
00563 
00567   virtual int removeContents() = 0;
00568 
00572   virtual int expungeContents() = 0;
00573 
00575   virtual bool readIndex() = 0;
00576   virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
00577   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
00578   virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
00579   virtual void truncateIndex() = 0;
00580 
00581   int mOpenCount;
00582   int mQuiet;
00583   bool mChanged :1;
00585   bool mAutoCreateIndex :1;
00588   bool mExportsSernums :1;
00590   bool mDirty :1;
00592   bool mFilesLocked :1;
00593 
00595   int mUnreadMsgs, mGuessedUnreadMsgs;
00596   int mTotalMsgs;
00597   bool mWriteConfigEnabled :1;
00599   bool needsCompact :1;
00601   bool mCompactable :1;
00602   bool mNoContent :1;
00603   bool mNoChildren :1;
00604   bool mConvertToUtf8 :1;
00605 
00607   mutable KMMsgDictREntry *mRDict;
00609   mutable QPtrList<FolderJob> mJobList;
00610 
00611   QTimer *mDirtyTimer;
00612   enum { mDirtyTimerInterval = 600000 }; // 10 minutes
00613 
00614   ChildrenState mHasChildren;
00615 
00617   KMail::FolderContentsType mContentsType;
00618 
00619   KMFolder* mFolder;
00620 
00621   QTimer * mEmitChangedTimer;
00622 
00623   int mCurrentSearchedMsg;
00624   const KMSearchPattern* mSearchPattern;
00625 };
00626 
00627 #endif // FOLDERSTORAGE_H
KDE Home | KDE Accessibility Home | Description of Access Keys