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 TQt library by Trolltech AS, Norway (or with modified versions 00026 of TQt that use the same license as TQt), 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 TQt. 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 TQTimer; 00059 class KMSearchPattern; 00060 00061 namespace KMail { 00062 class AttachmentStrategy; 00063 } 00064 using KMail::AttachmentStrategy; 00065 00066 typedef TQValueList<TQ_UINT32> SerNumList; 00067 00079 class FolderStorage : public TQObject 00080 { 00081 Q_OBJECT 00082 TQ_OBJECT 00083 00084 public: 00085 00086 00090 FolderStorage( KMFolder* folder, const char* name=0 ); 00091 virtual ~FolderStorage(); 00092 00093 KMFolder* folder() const { return mFolder; } 00094 00096 virtual KMFolderType folderType() const { return KMFolderTypeUnknown; } 00097 00099 virtual TQString fileName() const; 00101 TQString location() const; 00102 00104 virtual TQString indexLocation() const = 0; 00105 00107 virtual bool noContent() const { return mNoContent; } 00108 00110 virtual void setNoContent(bool 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, TQString partSpecifier = TQString(), 00163 const AttachmentStrategy *as = 0 ) const; 00164 virtual FolderJob* createJob( TQPtrList<KMMessage>& msgList, const TQString& 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(TQPtrList<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( TQPtrList<KMMessage>&, TQValueList<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 TQPtrList<KMMsgBase>& msgList, bool imapQuiet = false); 00218 virtual void removeMsg(const TQPtrList<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(TQPtrList<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 TQ_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 TQString& 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 TQString 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(TQValueList<int>& ids, KMMsgStatus status, bool toggle=false); 00371 00372 void removeJobs(); 00373 00375 static TQString dotEscape(const TQString&); 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*, TQ_UINT32 serNum ); 00417 00419 virtual bool isMoveable() const; 00420 00421 virtual KMAccount* account() const; 00422 00423 virtual bool mailCheckInProgress() const; 00424 00425 signals: 00428 void changed(); 00429 00432 void cleared(); 00433 00436 void expunged( KMFolder* ); 00437 00439 void closed( KMFolder* ); 00440 00442 void invalidated( KMFolder * ); 00443 00445 void nameChanged(); 00446 00450 void locationChanged( const TQString &, const TQString & ); 00451 00454 void contentsTypeChanged( KMail::FolderContentsType type ); 00455 00457 void readOnlyChanged(KMFolder*); 00458 00460 void noContentChanged(); 00461 00463 void msgRemoved(KMFolder*, TQ_UINT32 sernum); 00464 00466 void msgRemoved( int idx, TQString msgIdMD5 ); 00467 void msgRemoved( KMFolder* ); 00468 00470 void msgAdded(int idx); 00471 void msgAdded(KMFolder*, TQ_UINT32 sernum); 00472 00474 void msgChanged(KMFolder*, TQ_UINT32 sernum, int delta); 00475 00477 void msgHeaderChanged(KMFolder*, int); 00478 00480 void statusMsg(const TQString&); 00481 00483 void numUnreadMsgsChanged( KMFolder* ); 00484 00486 void removed(KMFolder*, bool); 00487 00493 void searchResult( KMFolder*, TQValueList<TQ_UINT32>, 00494 const KMSearchPattern*, bool complete ); 00495 00500 void searchDone( KMFolder*, TQ_UINT32, const KMSearchPattern*, bool ); 00501 00503 void folderSizeChanged(); 00504 00509 void syncStateChanged(); 00510 00511 public slots: 00513 virtual int updateIndex() = 0; 00514 00517 virtual void reallyAddMsg(KMMessage* aMsg); 00518 00521 virtual void reallyAddCopyOfMsg(KMMessage* aMsg); 00522 00524 void slotEmitChangedTimer(); 00525 00526 protected slots: 00527 virtual void removeJob( TQObject* ); 00528 00530 void slotProcessNextSearchBatch(); 00531 00532 protected: 00533 00539 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder, 00540 TQString partSpecifier, const AttachmentStrategy *as ) const = 0; 00541 virtual FolderJob* doCreateJob( TQPtrList<KMMessage>& msgList, const TQString& sets, 00542 FolderJob::JobType jt, KMFolder *folder ) const = 0; 00543 00547 void headerOfMsgChanged(const KMMsgBase*, int idx); 00548 00551 virtual KMMessage* readMsg(int idx) = 0; 00552 00553 //--------- Message Dict manipulation 00554 friend class KMMsgDict; 00558 virtual void fillMessageDict() {} 00559 00563 void readFolderIdsFile(); 00564 00566 int writeFolderIdsFile() const; 00567 00569 int touchFolderIdsFile(); 00570 00572 int appendToFolderIdsFile( int idx = -1 ); 00573 00577 void setRDict(KMMsgDictREntry *rentry) const; 00578 00580 KMMsgDictREntry *rDict() const { return mRDict; } 00581 00582 00585 void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx ); 00586 00590 void invalidateFolder(); 00591 00595 virtual int removeContents() = 0; 00596 00600 virtual int expungeContents() = 0; 00601 00603 virtual bool readIndex() = 0; 00604 virtual KMMsgBase* takeIndexEntry( int idx ) = 0; 00605 virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0; 00606 virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0; 00607 virtual void truncateIndex() = 0; 00608 00609 virtual TQ_INT64 doFolderSize() const { return 0; }; 00610 00611 int mOpenCount; 00612 int mQuiet; 00613 bool mChanged :1; 00615 bool mAutoCreateIndex :1; 00618 bool mExportsSernums :1; 00620 bool mDirty :1; 00622 bool mFilesLocked :1; 00623 00625 int mUnreadMsgs, mGuessedUnreadMsgs; 00626 int mTotalMsgs; 00627 TQ_INT64 mSize; 00628 bool mWriteConfigEnabled :1; 00630 bool needsCompact :1; 00632 bool mCompactable :1; 00633 bool mNoContent :1; 00634 bool mNoChildren :1; 00635 bool mConvertToUtf8 :1; 00636 00638 mutable KMMsgDictREntry *mRDict; 00640 mutable TQPtrList<FolderJob> mJobList; 00641 00642 TQTimer *mDirtyTimer; 00643 enum { mDirtyTimerInterval = 600000 }; // 10 minutes 00644 00645 ChildrenState mHasChildren; 00646 00648 KMail::FolderContentsType mContentsType; 00649 00650 KMFolder* mFolder; 00651 00652 TQTimer * mEmitChangedTimer; 00653 00654 int mCurrentSearchedMsg; 00655 const KMSearchPattern* mSearchPattern; 00656 }; 00657 00658 #endif // FOLDERSTORAGE_H