kmail

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 <qptrvector.h>
00040 #include <sys/types.h>
00041 #include <stdio.h>
00042 #include <kshortcut.h>
00043 
00044 class KMMessage;
00045 class KMFolderDir;
00046 class QTimer;
00047 class FolderStorage;
00048 class KMFolderTreeItem;
00049 class KMFolderJob;
00050 
00051 namespace KMail {
00052    class AttachmentStrategy;
00053 }
00054 using KMail::AttachmentStrategy;
00055 
00056 typedef QValueList<Q_UINT32> SerNumList;
00057 
00068 class KMFolder: public KMFolderNode
00069 {
00070   Q_OBJECT
00071   friend class ::KMFolderJob;
00072 public:
00073 
00089   KMFolder( KMFolderDir* parent, const QString& name,
00090                 KMFolderType aFolderType, bool withIndex = true,
00091                 bool exportedSernums = true );
00092   ~KMFolder();
00093 
00095   bool isMainInbox() {
00096     return this == KMKernel::self()->inboxFolder();
00097   }
00099   bool isOutbox() {
00100     return this == KMKernel::self()->outboxFolder();
00101   }
00104   bool isSent() {
00105     return KMKernel::self()->folderIsSentMailFolder( this );
00106   }
00109   bool isTrash() {
00110     return KMKernel::self()->folderIsTrash( this );
00111   }
00114   bool isDrafts() {
00115     return KMKernel::self()->folderIsDrafts( this );
00116   }
00117 
00118   void setAcctList( AccountList* list ) { mAcctList = list; }
00119   AccountList* acctList() { return mAcctList; }
00120 
00122   bool hasAccounts() const { return (mAcctList != 0); }
00123 
00125   void readConfig( KConfig* config );
00126 
00128   void writeConfig( KConfig* config ) const;
00129 
00130   FolderStorage* storage() { return mStorage; }
00132   const FolderStorage* storage() const { return mStorage; }
00133 
00135   KMFolderType folderType() const;
00136 
00138   QString fileName() const;
00139 
00141   QString location() const;
00142 
00144   QString indexLocation() const;
00145 
00147   QString subdirLocation() const;
00148 
00151   KMFolderDir* child() const
00152     { return mChild; }
00153 
00155   KMFolderDir* createChildFolder();
00156 
00158   void setChild( KMFolderDir* aChild );
00159 
00161   bool noContent() const;
00162 
00164   void setNoContent(bool aNoContent);
00165 
00167   bool noChildren() const;
00168 
00170   void setNoChildren(bool aNoChildren);
00171 
00173   KMMessage* getMsg(int idx);
00174 
00176   KMMsgInfo* unGetMsg(int idx);
00177 
00179   bool isMessage(int idx);
00180 
00182   QCString& getMsgString(int idx, QCString& mDest);
00183 
00185   DwString getDwString(int idx);
00186 
00190   void ignoreJobsForMessage( KMMessage* );
00191 
00196   FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
00197                         KMFolder *folder = 0, QString partSpecifier = QString::null,
00198                         const AttachmentStrategy *as = 0 ) const;
00199   FolderJob* createJob( QPtrList<KMMessage>& msgList, const QString& sets,
00200                         FolderJob::JobType jt = FolderJob::tGetMessage,
00201                         KMFolder *folder = 0 ) const;
00202 
00207   const KMMsgBase* getMsgBase(int idx) const;
00208   KMMsgBase* getMsgBase(int idx);
00209 
00211   const KMMsgBase* operator[](int idx) const;
00212 
00214   KMMsgBase* operator[](int idx);
00215 
00218   KMMessage* take(int idx);
00219   void take(QPtrList<KMMessage> msgList);
00220 
00227   int addMsg(KMMessage* msg, int* index_return = 0);
00228 
00232   int addMsgKeepUID(KMMessage* msg, int* index_return = 0);
00233 
00238   int addMsg(QPtrList<KMMessage>&, QValueList<int>& index_return);
00239 
00242   void emitMsgAddedSignals(int idx);
00243 
00245   void removeMsg(int i, bool imapQuiet = false);
00246   void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false);
00247 
00250   int expungeOldMsg(int days);
00251 
00256   int moveMsg(KMMessage* msg, int* index_return = 0);
00257   int moveMsg(QPtrList<KMMessage>, int* index_return = 0);
00258 
00260   int find(const KMMsgBase* msg) const;
00261   int find( const KMMessage * msg ) const;
00262 
00264   int count(bool cache = false) const;
00265 
00267   int countUnread();
00268 
00271   int countUnreadRecursive();
00272 
00275   void msgStatusChanged( const KMMsgStatus oldStatus,
00276                          const KMMsgStatus newStatus,
00277                          int idx);
00278 
00284   int open();
00285 
00288   int canAccess();
00289 
00292   void close(bool force=false);
00293 
00295   void sync();
00296 
00298   bool isOpened() const;
00299 
00301   void markNewAsUnread();
00302 
00304   void markUnreadAsRead();
00305 
00310   void remove();
00311 
00315   int expunge();
00316 
00317   enum CompactOptions { CompactLater, CompactNow, CompactSilentlyNow };
00324   void compact( CompactOptions options );
00325 
00328   int rename(const QString& newName, KMFolderDir *aParent = 0);
00329 
00333   bool dirty() const;
00334 
00336   void setDirty(bool f);
00337 
00339   bool needsCompacting() const;
00340   void setNeedsCompacting(bool f);
00341 
00350   void quiet(bool beQuiet);
00351 
00353   bool isReadOnly() const;
00354 
00359   bool isSystemFolder() const { return mIsSystemFolder; }
00360   void setSystemFolder(bool itIs) { mIsSystemFolder=itIs; }
00361 
00363   virtual QString label() const;
00364   void setLabel( const QString& l ) { mLabel = l; }
00365 
00367   virtual QString systemLabel() const { return mSystemLabel; }
00368   void setSystemLabel( const QString& l ) { mSystemLabel = l; }
00369 
00371   virtual QString prettyURL() const;
00372 
00374   void setMailingListEnabled( bool enabled );
00375   bool isMailingListEnabled() const { return mMailingListEnabled; }
00376 
00377   void setMailingList( const MailingList& mlist );
00378   MailingList mailingList() const
00379   { return mMailingList; }
00380   QString mailingListPostAddress() const;
00381 
00382   void setIdentity(uint identity);
00383   uint identity() const { return mIdentity; }
00384 
00386   QString whoField() const { return mWhoField; }
00387   void setWhoField(const QString& aWhoField);
00388 
00390   QString userWhoField(void) { return mUserWhoField; }
00391   void setUserWhoField(const QString &whoField,bool writeConfig=true);
00392 
00394   void correctUnreadMsgsCount();
00395 
00397   QString idString() const;
00398 
00402   void setAutoExpire(bool enabled);
00403 
00407   bool isAutoExpire() const { return mExpireMessages; }
00408 
00414   void setUnreadExpireAge(int age);
00415 
00420   void setUnreadExpireUnits(ExpireUnits units);
00421 
00427   void setReadExpireAge(int age);
00428 
00433   void setReadExpireUnits(ExpireUnits units);
00434 
00439   int getUnreadExpireAge() const { return mUnreadExpireAge; }
00440 
00445   int getReadExpireAge() const { return mReadExpireAge; }
00446 
00451   ExpireUnits getUnreadExpireUnits() const { return mUnreadExpireUnits; }
00452 
00457   ExpireUnits getReadExpireUnits() const { return mReadExpireUnits; }
00458 
00459   enum ExpireAction { ExpireDelete, ExpireMove };
00463   ExpireAction expireAction() const { return mExpireAction; }
00464   void setExpireAction( ExpireAction a );
00465 
00469   QString expireToFolderId() const { return mExpireToFolderId; }
00470   void setExpireToFolderId( const QString& id );
00471 
00476   void expireOldMessages( bool immediate );
00477 
00480   int writeIndex( bool createEmptyIndex = false );
00481 
00483   void setStatus(int idx, KMMsgStatus status, bool toggle=false);
00484 
00486   void setStatus(QValueList<int>& ids, KMMsgStatus status, bool toggle=false);
00487 
00489   bool useCustomIcons() const { return mUseCustomIcons; }
00490   void setUseCustomIcons(bool useCustomIcons) { mUseCustomIcons = useCustomIcons; }
00491   QString normalIconPath() const { return mNormalIconPath; }
00492   QString unreadIconPath() const { return mUnreadIconPath; }
00493   void setIconPaths(const QString &normalPath, const QString &unreadPath);
00494 
00495   void removeJobs();
00496 
00497   void daysToExpire( int& unreadDays, int& readDays );
00498 
00503   KMFolder* trashFolder() const;
00504 
00509   bool putRepliesInSameFolder() const { return mPutRepliesInSameFolder; }
00510   void setPutRepliesInSameFolder( bool b ) { mPutRepliesInSameFolder = b; }
00511 
00516   bool ignoreNewMail() const { return mIgnoreNewMail; }
00517   void setIgnoreNewMail( bool b ) { mIgnoreNewMail = b; }
00518 
00519   const KShortcut &shortcut() const { return mShortcut; }
00520   void setShortcut( const KShortcut& );
00521 
00523   bool isMoveable() const;
00524 
00525 signals:
00528   void changed();
00529 
00532   void cleared();
00533 
00536   void expunged( KMFolder* );
00537 
00539   void iconsChanged();
00540 
00542   void nameChanged();
00543 
00545   void shortcutChanged( KMFolder * );
00546 
00548   void msgRemoved(KMFolder*, Q_UINT32 sernum);
00549 
00551   void msgRemoved( int idx, QString msgIdMD5 );
00552   void msgRemoved(KMFolder*);
00553 
00555   void msgAdded(int idx);
00556   void msgAdded(KMFolder*, Q_UINT32 sernum);
00557 
00559   void msgChanged(KMFolder*, Q_UINT32 sernum, int delta);
00560 
00562   void msgHeaderChanged(KMFolder*, int);
00563 
00565   void statusMsg(const QString&);
00566 
00568   void numUnreadMsgsChanged( KMFolder* );
00569 
00571   void removed(KMFolder*, bool);
00572 
00574   void viewConfigChanged();
00575 
00576 public slots:
00578   int updateIndex();
00579 
00582   void reallyAddMsg(KMMessage* aMsg);
00583 
00586   void reallyAddCopyOfMsg(KMMessage* aMsg);
00587 
00588 private slots:
00590   void slotContentsTypeChanged( KMail::FolderContentsType type );
00591 
00592 private:
00593   FolderStorage* mStorage;
00594   KMFolderDir* mChild;
00595   bool mIsSystemFolder;
00596   bool mHasIndex :1;
00597   bool mExportsSernums :1;
00598 
00600   QString mLabel;
00601   QString mSystemLabel;
00602 
00604   bool         mExpireMessages;          // true if old messages are expired
00605   int          mUnreadExpireAge;         // Given in unreadExpireUnits
00606   int          mReadExpireAge;           // Given in readExpireUnits
00607   ExpireUnits  mUnreadExpireUnits;
00608   ExpireUnits  mReadExpireUnits;
00609   ExpireAction mExpireAction;
00610   QString      mExpireToFolderId;
00611 
00613   bool mUseCustomIcons;
00614   QString mNormalIconPath;
00615   QString mUnreadIconPath;
00616 
00618   bool                mMailingListEnabled;
00619   MailingList         mMailingList;
00620   
00621   AccountList* mAcctList;
00622   
00623   uint mIdentity;
00624 
00626   QString mWhoField, mUserWhoField;
00627 
00629   bool mPutRepliesInSameFolder;
00630 
00632   bool mIgnoreNewMail;
00633 
00635   KShortcut mShortcut;
00636 };
00637 
00643 class KMFolderCloser {
00644   KMFolder * f;
00645 public:
00646   KMFolderCloser( KMFolder * folder ) : f( folder ) {}
00647   ~KMFolderCloser() {
00648     if ( f ) f->close();
00649   }
00650   KMFolder * folder() const { return f; }
00651 };
00652 
00653 #endif /*kmfolder_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys