kmfolder.h
00001 /* -*- mode: C++ -*- 00002 * kmail: KDE mail client 00003 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 */ 00020 #ifndef kmfolder_h 00021 #define kmfolder_h 00022 00023 // for large file support 00024 #include <config.h> 00025 00026 #include "kmfoldernode.h" 00027 #include "kmfoldertype.h" 00028 #include "kmmsginfo.h" 00029 #include "kmglobal.h" 00030 #include "kmkernel.h" 00031 #include "folderjob.h" 00032 using KMail::FolderJob; 00033 #include "mailinglist-magic.h" 00034 using KMail::MailingList; 00035 #include "kmaccount.h" // for AccountList 00036 00037 #include "mimelib/string.h" 00038 00039 #include <tqptrvector.h> 00040 #include <sys/types.h> 00041 #include <stdio.h> 00042 #include <tdeshortcut.h> 00043 00044 class KMMessage; 00045 class KMFolderDir; 00046 class TQTimer; 00047 class FolderStorage; 00048 class KMFolderTreeItem; 00049 class KMFolderJob; 00050 00051 namespace KMail { 00052 class AttachmentStrategy; 00053 } 00054 using KMail::AttachmentStrategy; 00055 00056 typedef TQValueList<TQ_UINT32> SerNumList; 00057 00068 class KMFolder: public KMFolderNode 00069 { 00070 Q_OBJECT 00071 00072 friend class ::KMFolderJob; 00073 public: 00074 00090 KMFolder( KMFolderDir* parent, const TQString& name, 00091 KMFolderType aFolderType, bool withIndex = true, 00092 bool exportedSernums = true ); 00093 ~KMFolder(); 00094 00096 bool isMainInbox() { 00097 return this == KMKernel::self()->inboxFolder(); 00098 } 00100 bool isOutbox() { 00101 return this == KMKernel::self()->outboxFolder(); 00102 } 00105 bool isSent() { 00106 return KMKernel::self()->folderIsSentMailFolder( this ); 00107 } 00110 bool isTrash() { 00111 return KMKernel::self()->folderIsTrash( this ); 00112 } 00115 bool isDrafts() { 00116 return KMKernel::self()->folderIsDrafts( this ); 00117 } 00120 bool isTemplates() { 00121 return KMKernel::self()->folderIsTemplates( this ); 00122 } 00123 00124 void setAcctList( AccountList* list ) { mAcctList = list; } 00125 AccountList* acctList() { return mAcctList; } 00126 00128 bool hasAccounts() const { return (mAcctList != 0); } 00129 00131 void readConfig( TDEConfig* config ); 00132 00134 void writeConfig( TDEConfig* config ) const; 00135 00136 FolderStorage* storage() { return mStorage; } 00138 const FolderStorage* storage() const { return mStorage; } 00139 00141 KMFolderType folderType() const; 00142 00144 TQString fileName() const; 00145 00147 TQString location() const; 00148 00150 TQString indexLocation() const; 00151 00153 TQString subdirLocation() const; 00154 00157 KMFolderDir* child() const 00158 { return mChild; } 00159 00161 KMFolderDir* createChildFolder(); 00162 00164 void setChild( KMFolderDir* aChild ); 00165 00167 bool noContent() const; 00168 00170 void setNoContent(bool aNoContent); 00171 00173 bool noChildren() const; 00174 00176 void setNoChildren(bool aNoChildren); 00177 00179 KMMessage* getMsg(int idx); 00180 00182 KMMsgInfo* unGetMsg(int idx); 00183 00185 bool isMessage(int idx); 00186 00188 DwString getDwString(int idx); 00189 00193 void ignoreJobsForMessage( KMMessage* ); 00194 00199 FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage, 00200 KMFolder *folder = 0, TQString partSpecifier = TQString(), 00201 const AttachmentStrategy *as = 0 ) const; 00202 FolderJob* createJob( TQPtrList<KMMessage>& msgList, const TQString& sets, 00203 FolderJob::JobType jt = FolderJob::tGetMessage, 00204 KMFolder *folder = 0 ) const; 00205 00210 const KMMsgBase* getMsgBase(int idx) const; 00211 KMMsgBase* getMsgBase(int idx); 00212 00214 const KMMsgBase* operator[](int idx) const; 00215 00217 KMMsgBase* operator[](int idx); 00218 00221 KMMessage* take(int idx); 00222 void take(TQPtrList<KMMessage> msgList); 00223 00230 int addMsg(KMMessage* msg, int* index_return = 0); 00231 00235 int addMsgKeepUID(KMMessage* msg, int* index_return = 0); 00236 00241 int addMsg(TQPtrList<KMMessage>&, TQValueList<int>& index_return); 00242 00245 void emitMsgAddedSignals(int idx); 00246 00248 void removeMsg(int i, bool imapQuiet = false); 00249 void removeMsg(TQPtrList<KMMessage> msgList, bool imapQuiet = false); 00250 00253 int expungeOldMsg(int days); 00254 00259 int moveMsg(KMMessage* msg, int* index_return = 0); 00260 int moveMsg(TQPtrList<KMMessage>, int* index_return = 0); 00261 00263 int find(const KMMsgBase* msg) const; 00264 int find( const KMMessage * msg ) const; 00265 00267 int count(bool cache = false) const; 00268 00270 int countUnread(); 00271 00274 int countUnreadRecursive(); 00275 00278 void msgStatusChanged( const KMMsgStatus oldStatus, 00279 const KMMsgStatus newStatus, 00280 int idx); 00281 00287 int open(const char *owner); 00288 00291 int canAccess(); 00292 00295 void close(const char *owner, bool force=false); 00296 00298 void sync(); 00299 00301 bool isOpened() const; 00302 00304 void markNewAsUnread(); 00305 00307 void markUnreadAsRead(); 00308 00313 void remove(); 00314 00318 int expunge(); 00319 00320 enum CompactOptions { CompactLater, CompactNow, CompactSilentlyNow }; 00327 void compact( CompactOptions options ); 00328 00331 int rename(const TQString& newName, KMFolderDir *aParent = 0); 00332 00336 bool dirty() const; 00337 00339 void setDirty(bool f); 00340 00342 bool needsCompacting() const; 00343 void setNeedsCompacting(bool f); 00344 00353 void quiet(bool beQuiet); 00354 00356 bool isReadOnly() const; 00358 bool isWritable() const; 00359 00360 bool mailCheckInProgress() const; 00361 00363 bool canDeleteMessages() const; 00364 00369 bool isSystemFolder() const { return mIsSystemFolder; } 00370 void setSystemFolder(bool itIs) { mIsSystemFolder=itIs; } 00371 00373 virtual TQString label() const; 00374 void setLabel( const TQString& l ) { mLabel = l; } 00375 00377 virtual TQString systemLabel() const { return mSystemLabel; } 00378 void setSystemLabel( const TQString& l ) { mSystemLabel = l; } 00379 00381 virtual TQString prettyURL() const; 00382 00384 void setMailingListEnabled( bool enabled ); 00385 bool isMailingListEnabled() const { return mMailingListEnabled; } 00386 00387 void setMailingList( const MailingList& mlist ); 00388 MailingList mailingList() const 00389 { return mMailingList; } 00390 TQString mailingListPostAddress() const; 00391 00392 void setIdentity(uint identity); 00393 uint identity() const; 00394 00396 TQString whoField() const { return mWhoField; } 00397 void setWhoField(const TQString& aWhoField); 00398 00400 TQString userWhoField(void) { return mUserWhoField; } 00401 void setUserWhoField(const TQString &whoField,bool writeConfig=true); 00402 00404 void correctUnreadMsgsCount(); 00405 00407 TQString idString() const; 00408 00412 void setAutoExpire(bool enabled); 00413 00417 bool isAutoExpire() const { return mExpireMessages; } 00418 00424 void setUnreadExpireAge(int age); 00425 00430 void setUnreadExpireUnits(ExpireUnits units); 00431 00437 void setReadExpireAge(int age); 00438 00443 void setReadExpireUnits(ExpireUnits units); 00444 00449 int getUnreadExpireAge() const { return mUnreadExpireAge; } 00450 00455 int getReadExpireAge() const { return mReadExpireAge; } 00456 00461 ExpireUnits getUnreadExpireUnits() const { return mUnreadExpireUnits; } 00462 00467 ExpireUnits getReadExpireUnits() const { return mReadExpireUnits; } 00468 00469 enum ExpireAction { ExpireDelete, ExpireMove }; 00473 ExpireAction expireAction() const { return mExpireAction; } 00474 void setExpireAction( ExpireAction a ); 00475 00479 TQString expireToFolderId() const { return mExpireToFolderId; } 00480 void setExpireToFolderId( const TQString& id ); 00481 00486 void expireOldMessages( bool immediate ); 00487 00490 int writeIndex( bool createEmptyIndex = false ); 00491 00493 void setStatus(int idx, KMMsgStatus status, bool toggle=false); 00494 00496 void setStatus(TQValueList<int>& ids, KMMsgStatus status, bool toggle=false); 00497 00499 bool useCustomIcons() const { return mUseCustomIcons; } 00500 void setUseCustomIcons(bool useCustomIcons) { mUseCustomIcons = useCustomIcons; } 00501 TQString normalIconPath() const { return mNormalIconPath; } 00502 TQString unreadIconPath() const { return mUnreadIconPath; } 00503 void setIconPaths(const TQString &normalPath, const TQString &unreadPath); 00504 00505 void removeJobs(); 00506 00507 void daysToExpire( int& unreadDays, int& readDays ); 00508 00513 KMFolder* trashFolder() const; 00514 00519 bool putRepliesInSameFolder() const { return mPutRepliesInSameFolder; } 00520 void setPutRepliesInSameFolder( bool b ) { mPutRepliesInSameFolder = b; } 00521 00526 bool ignoreNewMail() const { return mIgnoreNewMail; } 00527 void setIgnoreNewMail( bool b ) { mIgnoreNewMail = b; } 00528 00529 const TDEShortcut &shortcut() const { return mShortcut; } 00530 void setShortcut( const TDEShortcut& ); 00531 00533 bool isMoveable() const; 00534 00538 bool moveInProgress() const { return mMoveInProgress; } 00539 00541 void setMoveInProgress( bool b ) { mMoveInProgress = b; } 00542 00548 bool isValidName( const TQString &folderName, TQString &message ); 00549 00550 signals: 00553 void changed(); 00554 00557 void closed(); 00558 00561 void cleared(); 00562 00565 void expunged( KMFolder* ); 00566 00568 void iconsChanged(); 00569 00571 void nameChanged(); 00572 00574 void shortcutChanged( KMFolder * ); 00575 00577 void msgRemoved(KMFolder*, TQ_UINT32 sernum); 00578 00580 void msgRemoved( int idx, TQString msgIdMD5 ); 00581 void msgRemoved(KMFolder*); 00582 00584 void msgAdded(int idx); 00585 void msgAdded(KMFolder*, TQ_UINT32 sernum); 00586 00588 void msgChanged(KMFolder*, TQ_UINT32 sernum, int delta); 00589 00591 void msgHeaderChanged(KMFolder*, int); 00592 00594 void statusMsg(const TQString&); 00595 00597 void numUnreadMsgsChanged( KMFolder* ); 00598 00600 void removed(KMFolder*, bool); 00601 00603 void viewConfigChanged(); 00604 00606 void folderSizeChanged( KMFolder * ); 00607 00609 void noContentChanged(); 00610 00615 void syncStateChanged(); 00616 00617 public slots: 00619 int updateIndex(); 00620 00623 void reallyAddMsg(KMMessage* aMsg); 00624 00627 void reallyAddCopyOfMsg(KMMessage* aMsg); 00628 00629 private slots: 00631 void slotContentsTypeChanged( KMail::FolderContentsType type ); 00633 void slotFolderSizeChanged(); 00634 00635 private: 00636 FolderStorage* mStorage; 00637 KMFolderDir* mChild; 00638 bool mIsSystemFolder; 00639 bool mHasIndex :1; 00640 bool mExportsSernums :1; 00641 bool mMoveInProgress :1; 00642 00644 TQString mLabel; 00645 TQString mSystemLabel; 00646 00648 bool mExpireMessages; // true if old messages are expired 00649 int mUnreadExpireAge; // Given in unreadExpireUnits 00650 int mReadExpireAge; // Given in readExpireUnits 00651 ExpireUnits mUnreadExpireUnits; 00652 ExpireUnits mReadExpireUnits; 00653 ExpireAction mExpireAction; 00654 TQString mExpireToFolderId; 00655 00657 bool mUseCustomIcons; 00658 TQString mNormalIconPath; 00659 TQString mUnreadIconPath; 00660 00662 bool mMailingListEnabled; 00663 MailingList mMailingList; 00664 00665 AccountList* mAcctList; 00666 00667 uint mIdentity; 00668 00670 TQString mWhoField, mUserWhoField; 00671 00673 bool mPutRepliesInSameFolder; 00674 00676 bool mIgnoreNewMail; 00677 00679 TDEShortcut mShortcut; 00680 }; 00681 00682 00688 class KMFolderOpener { 00689 KMFolder* mFolder; 00690 const char* const mOwner; 00691 int mOpenRc; 00692 00693 public: 00694 KMFolderOpener( KMFolder* folder, const char* const owner ) 00695 : mFolder( folder ) 00696 , mOwner( owner ) 00697 { 00698 assert( folder ); //change if that's not what you want 00699 mOpenRc = folder->open( owner ); 00700 } 00701 00702 ~KMFolderOpener() 00703 { 00704 if ( !mOpenRc ) 00705 mFolder->close( mOwner ); 00706 } 00707 00708 KMFolder* folder() const { return mFolder; } 00709 00710 int openResult() const { return mOpenRc; } 00711 00712 private: 00713 //we forbid construction on the heap as good as we can 00714 void* operator new( size_t size ); 00715 }; 00716 00717 00718 #endif /*kmfolder_h*/