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   void close(const char * owner, bool force=FALSE);
00260   virtual void reallyDoClose(const char * owner) = 0;
00261 
00264   virtual void tryReleasingFolder(KMFolder*) {}
00265 
00267   virtual void sync() = 0;
00268 
00270   bool isOpened() const { return (mOpenCount>0); }
00271 
00273   virtual void markNewAsUnread();
00274 
00276   virtual void markUnreadAsRead();
00277 
00281   virtual int create() = 0;
00282 
00287   virtual void remove();
00288 
00292   virtual int expunge();
00293 
00298   virtual int compact( bool silent ) = 0;
00299 
00302   virtual int rename(const QString& newName, KMFolderDir *aParent = 0);
00303 
00305   bool autoCreateIndex() const { return mAutoCreateIndex; }
00306 
00309   virtual void setAutoCreateIndex(bool);
00310 
00314   bool dirty() const { return mDirty; }
00315 
00317   void setDirty(bool f);
00318 
00320   bool needsCompacting() const { return needsCompact; }
00321   virtual void setNeedsCompacting(bool f) { needsCompact = f; }
00322 
00331   virtual void quiet(bool beQuiet);
00332 
00334   virtual bool isReadOnly() const = 0;
00335 
00337   QString label() const;
00338 
00340   virtual void correctUnreadMsgsCount();
00341 
00344   virtual int writeIndex( bool createEmptyIndex = false ) = 0;
00345 
00348   void registerWithMessageDict();
00349 
00352   void deregisterFromMessageDict();
00353 
00355   virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00356 
00358   virtual void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00359 
00360   void removeJobs();
00361 
00363   static QString dotEscape(const QString&);
00364 
00366   virtual void readConfig();
00367 
00369   virtual void writeConfig();
00370 
00375   virtual KMFolder* trashFolder() const { return 0; }
00376 
00381   void addJob( FolderJob* ) const;
00382 
00384   bool compactable() const { return mCompactable; }
00385 
00387   // If quiet is true, the KMailIcalIface is not informed of the changed. That's usefull
00388   // for folder that are being copied around, should retain their type, but not cause
00389   // conflicts on copy because events are identical in two folders.
00390   virtual void setContentsType( KMail::FolderContentsType type, bool quiet = false );
00392   KMail::FolderContentsType contentsType() const { return mContentsType; }
00393 
00398   virtual void search( const KMSearchPattern* );
00399 
00404   virtual void search( const KMSearchPattern*, Q_UINT32 serNum );
00405 
00407   virtual bool isMoveable() const;
00408 
00409 signals:
00412   void changed();
00413 
00416   void cleared();
00417 
00420   void expunged( KMFolder* );
00421 
00423   void closed( KMFolder* );
00424   
00426   void invalidated( KMFolder * );
00427 
00429   void nameChanged();
00430 
00434   void locationChanged( const QString &, const QString & );
00435 
00438   void contentsTypeChanged( KMail::FolderContentsType type );
00439 
00441   void readOnlyChanged(KMFolder*);
00442 
00444   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00445 
00447   void msgRemoved( int idx, QString msgIdMD5 );
00448   void msgRemoved( KMFolder* );
00449 
00451   void msgAdded(int idx);
00452   void msgAdded(KMFolder*, Q_UINT32 sernum);
00453 
00455   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00456 
00458   void msgHeaderChanged(KMFolder*, int);
00459 
00461   void statusMsg(const QString&);
00462 
00464   void numUnreadMsgsChanged( KMFolder* );
00465 
00467   void removed(KMFolder*, bool);
00468 
00474   void searchResult( KMFolder*, QValueList<Q_UINT32>,
00475                      const KMSearchPattern*, bool complete );
00476 
00481   void searchDone( KMFolder*, Q_UINT32, const KMSearchPattern*, bool );
00482 
00483 
00484 public slots:
00486   virtual int updateIndex() = 0;
00487 
00490   virtual void reallyAddMsg(KMMessage* aMsg);
00491 
00494   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
00495 
00497   void slotEmitChangedTimer();
00498 
00499 protected slots:
00500   virtual void removeJob( QObject* );
00501 
00503   void slotProcessNextSearchBatch();
00504 
00505 protected:
00506 
00512   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00513                                   QString partSpecifier, const AttachmentStrategy *as ) const = 0;
00514   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00515                                   FolderJob::JobType jt, KMFolder *folder ) const = 0;
00516 
00520   void headerOfMsgChanged(const KMMsgBase*, int idx);
00521 
00524   virtual KMMessage* readMsg(int idx) = 0;
00525 
00526   //--------- Message Dict manipulation
00527 friend class KMMsgDict;
00531   virtual void fillMessageDict() {}
00532 
00536   void readFolderIdsFile();
00537 
00539   int writeFolderIdsFile() const;
00540 
00542   int touchFolderIdsFile();
00543 
00545   int appendToFolderIdsFile( int idx = -1 );
00546 
00550   void setRDict(KMMsgDictREntry *rentry) const;
00551 
00553   KMMsgDictREntry *rDict() const { return mRDict; }
00554 
00555 
00558   void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx );
00559 
00563   void invalidateFolder();
00564 
00568   virtual int removeContents() = 0;
00569 
00573   virtual int expungeContents() = 0;
00574 
00576   virtual bool readIndex() = 0;
00577   virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
00578   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
00579   virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
00580   virtual void truncateIndex() = 0;
00581 
00582   int mOpenCount;
00583   int mQuiet;
00584   bool mChanged :1;
00586   bool mAutoCreateIndex :1;
00589   bool mExportsSernums :1;
00591   bool mDirty :1;
00593   bool mFilesLocked :1;
00594 
00596   int mUnreadMsgs, mGuessedUnreadMsgs;
00597   int mTotalMsgs;
00598   bool mWriteConfigEnabled :1;
00600   bool needsCompact :1;
00602   bool mCompactable :1;
00603   bool mNoContent :1;
00604   bool mNoChildren :1;
00605   bool mConvertToUtf8 :1;
00606 
00608   mutable KMMsgDictREntry *mRDict;
00610   mutable QPtrList<FolderJob> mJobList;
00611 
00612   QTimer *mDirtyTimer;
00613   enum { mDirtyTimerInterval = 600000 }; // 10 minutes
00614 
00615   ChildrenState mHasChildren;
00616 
00618   KMail::FolderContentsType mContentsType;
00619 
00620   KMFolder* mFolder;
00621 
00622   QTimer * mEmitChangedTimer;
00623 
00624   int mCurrentSearchedMsg;
00625   const KMSearchPattern* mSearchPattern;
00626 };
00627 
00628 #endif // FOLDERSTORAGE_H
KDE Home | KDE Accessibility Home | Description of Access Keys