kmail

kmfolder.h
1 /* -*- mode: C++ -*-
2  * kmail: KDE mail client
3  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 #ifndef kmfolder_h
21 #define kmfolder_h
22 
23 // for large file support
24 #include <config.h>
25 
26 #include "kmfoldernode.h"
27 #include "kmfoldertype.h"
28 #include "kmmsginfo.h"
29 #include "kmglobal.h"
30 #include "kmkernel.h"
31 #include "folderjob.h"
32 using KMail::FolderJob;
33 #include "mailinglist-magic.h"
34 using KMail::MailingList;
35 #include "kmaccount.h" // for AccountList
36 
37 #include "mimelib/string.h"
38 
39 #include <tqptrvector.h>
40 #include <sys/types.h>
41 #include <stdio.h>
42 #include <kshortcut.h>
43 
44 class KMMessage;
45 class KMFolderDir;
46 class TQTimer;
47 class FolderStorage;
48 class KMFolderTreeItem;
49 class KMFolderJob;
50 
51 namespace KMail {
52  class AttachmentStrategy;
53 }
54 using KMail::AttachmentStrategy;
55 
56 typedef TQValueList<TQ_UINT32> SerNumList;
57 
68 class KMFolder: public KMFolderNode
69 {
70  Q_OBJECT
71  TQ_OBJECT
72  friend class ::KMFolderJob;
73 public:
74 
90  KMFolder( KMFolderDir* parent, const TQString& name,
91  KMFolderType aFolderType, bool withIndex = true,
92  bool exportedSernums = true );
93  ~KMFolder();
94 
96  bool isMainInbox() {
97  return this == KMKernel::self()->inboxFolder();
98  }
100  bool isOutbox() {
101  return this == KMKernel::self()->outboxFolder();
102  }
105  bool isSent() {
106  return KMKernel::self()->folderIsSentMailFolder( this );
107  }
110  bool isTrash() {
111  return KMKernel::self()->folderIsTrash( this );
112  }
115  bool isDrafts() {
116  return KMKernel::self()->folderIsDrafts( this );
117  }
120  bool isTemplates() {
121  return KMKernel::self()->folderIsTemplates( this );
122  }
123 
124  void setAcctList( AccountList* list ) { mAcctList = list; }
125  AccountList* acctList() { return mAcctList; }
126 
128  bool hasAccounts() const { return (mAcctList != 0); }
129 
131  void readConfig( KConfig* config );
132 
134  void writeConfig( KConfig* config ) const;
135 
136  FolderStorage* storage() { return mStorage; }
138  const FolderStorage* storage() const { return mStorage; }
139 
141  KMFolderType folderType() const;
142 
144  TQString fileName() const;
145 
147  TQString location() const;
148 
150  TQString indexLocation() const;
151 
153  TQString subdirLocation() const;
154 
158  { return mChild; }
159 
162 
164  void setChild( KMFolderDir* aChild );
165 
167  bool noContent() const;
168 
170  void setNoContent(bool aNoContent);
171 
173  bool noChildren() const;
174 
176  void setNoChildren(bool aNoChildren);
177 
179  KMMessage* getMsg(int idx);
180 
182  KMMsgInfo* unGetMsg(int idx);
183 
185  bool isMessage(int idx);
186 
188  DwString getDwString(int idx);
189 
194 
199  FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
200  KMFolder *folder = 0, TQString partSpecifier = TQString(),
201  const AttachmentStrategy *as = 0 ) const;
202  FolderJob* createJob( TQPtrList<KMMessage>& msgList, const TQString& sets,
203  FolderJob::JobType jt = FolderJob::tGetMessage,
204  KMFolder *folder = 0 ) const;
205 
210  const KMMsgBase* getMsgBase(int idx) const;
211  KMMsgBase* getMsgBase(int idx);
212 
214  const KMMsgBase* operator[](int idx) const;
215 
217  KMMsgBase* operator[](int idx);
218 
221  KMMessage* take(int idx);
222  void take(TQPtrList<KMMessage> msgList);
223 
230  int addMsg(KMMessage* msg, int* index_return = 0);
231 
235  int addMsgKeepUID(KMMessage* msg, int* index_return = 0);
236 
241  int addMsg(TQPtrList<KMMessage>&, TQValueList<int>& index_return);
242 
245  void emitMsgAddedSignals(int idx);
246 
248  void removeMsg(int i, bool imapQuiet = false);
249  void removeMsg(TQPtrList<KMMessage> msgList, bool imapQuiet = false);
250 
253  int expungeOldMsg(int days);
254 
259  int moveMsg(KMMessage* msg, int* index_return = 0);
260  int moveMsg(TQPtrList<KMMessage>, int* index_return = 0);
261 
263  int find(const KMMsgBase* msg) const;
264  int find( const KMMessage * msg ) const;
265 
267  int count(bool cache = false) const;
268 
270  int countUnread();
271 
274  int countUnreadRecursive();
275 
278  void msgStatusChanged( const KMMsgStatus oldStatus,
279  const KMMsgStatus newStatus,
280  int idx);
281 
287  int open(const char *owner);
288 
291  int canAccess();
292 
295  void close(const char *owner, bool force=false);
296 
298  void sync();
299 
301  bool isOpened() const;
302 
304  void markNewAsUnread();
305 
307  void markUnreadAsRead();
308 
313  void remove();
314 
318  int expunge();
319 
320  enum CompactOptions { CompactLater, CompactNow, CompactSilentlyNow };
327  void compact( CompactOptions options );
328 
331  int rename(const TQString& newName, KMFolderDir *aParent = 0);
332 
336  bool dirty() const;
337 
339  void setDirty(bool f);
340 
342  bool needsCompacting() const;
343  void setNeedsCompacting(bool f);
344 
353  void quiet(bool beQuiet);
354 
356  bool isReadOnly() const;
358  bool isWritable() const;
359 
360  bool mailCheckInProgress() const;
361 
363  bool canDeleteMessages() const;
364 
369  bool isSystemFolder() const { return mIsSystemFolder; }
370  void setSystemFolder(bool itIs) { mIsSystemFolder=itIs; }
371 
373  virtual TQString label() const;
374  void setLabel( const TQString& l ) { mLabel = l; }
375 
377  virtual TQString systemLabel() const { return mSystemLabel; }
378  void setSystemLabel( const TQString& l ) { mSystemLabel = l; }
379 
381  virtual TQString prettyURL() const;
382 
384  void setMailingListEnabled( bool enabled );
385  bool isMailingListEnabled() const { return mMailingListEnabled; }
386 
387  void setMailingList( const MailingList& mlist );
388  MailingList mailingList() const
389  { return mMailingList; }
390  TQString mailingListPostAddress() const;
391 
392  void setIdentity(uint identity);
393  uint identity() const;
394 
396  TQString whoField() const { return mWhoField; }
397  void setWhoField(const TQString& aWhoField);
398 
400  TQString userWhoField(void) { return mUserWhoField; }
401  void setUserWhoField(const TQString &whoField,bool writeConfig=true);
402 
404  void correctUnreadMsgsCount();
405 
407  TQString idString() const;
408 
412  void setAutoExpire(bool enabled);
413 
417  bool isAutoExpire() const { return mExpireMessages; }
418 
424  void setUnreadExpireAge(int age);
425 
430  void setUnreadExpireUnits(ExpireUnits units);
431 
437  void setReadExpireAge(int age);
438 
443  void setReadExpireUnits(ExpireUnits units);
444 
449  int getUnreadExpireAge() const { return mUnreadExpireAge; }
450 
455  int getReadExpireAge() const { return mReadExpireAge; }
456 
461  ExpireUnits getUnreadExpireUnits() const { return mUnreadExpireUnits; }
462 
467  ExpireUnits getReadExpireUnits() const { return mReadExpireUnits; }
468 
469  enum ExpireAction { ExpireDelete, ExpireMove };
473  ExpireAction expireAction() const { return mExpireAction; }
474  void setExpireAction( ExpireAction a );
475 
479  TQString expireToFolderId() const { return mExpireToFolderId; }
480  void setExpireToFolderId( const TQString& id );
481 
486  void expireOldMessages( bool immediate );
487 
490  int writeIndex( bool createEmptyIndex = false );
491 
493  void setStatus(int idx, KMMsgStatus status, bool toggle=false);
494 
496  void setStatus(TQValueList<int>& ids, KMMsgStatus status, bool toggle=false);
497 
499  bool useCustomIcons() const { return mUseCustomIcons; }
500  void setUseCustomIcons(bool useCustomIcons) { mUseCustomIcons = useCustomIcons; }
501  TQString normalIconPath() const { return mNormalIconPath; }
502  TQString unreadIconPath() const { return mUnreadIconPath; }
503  void setIconPaths(const TQString &normalPath, const TQString &unreadPath);
504 
505  void removeJobs();
506 
507  void daysToExpire( int& unreadDays, int& readDays );
508 
513  KMFolder* trashFolder() const;
514 
519  bool putRepliesInSameFolder() const { return mPutRepliesInSameFolder; }
520  void setPutRepliesInSameFolder( bool b ) { mPutRepliesInSameFolder = b; }
521 
526  bool ignoreNewMail() const { return mIgnoreNewMail; }
527  void setIgnoreNewMail( bool b ) { mIgnoreNewMail = b; }
528 
529  const KShortcut &shortcut() const { return mShortcut; }
530  void setShortcut( const KShortcut& );
531 
533  bool isMoveable() const;
534 
538  bool moveInProgress() const { return mMoveInProgress; }
539 
541  void setMoveInProgress( bool b ) { mMoveInProgress = b; }
542 
548  bool isValidName( const TQString &folderName, TQString &message );
549 
550 signals:
553  void changed();
554 
557  void closed();
558 
561  void cleared();
562 
565  void expunged( KMFolder* );
566 
568  void iconsChanged();
569 
571  void nameChanged();
572 
574  void shortcutChanged( KMFolder * );
575 
577  void msgRemoved(KMFolder*, TQ_UINT32 sernum);
578 
580  void msgRemoved( int idx, TQString msgIdMD5 );
581  void msgRemoved(KMFolder*);
582 
584  void msgAdded(int idx);
585  void msgAdded(KMFolder*, TQ_UINT32 sernum);
586 
588  void msgChanged(KMFolder*, TQ_UINT32 sernum, int delta);
589 
591  void msgHeaderChanged(KMFolder*, int);
592 
594  void statusMsg(const TQString&);
595 
598 
600  void removed(KMFolder*, bool);
601 
603  void viewConfigChanged();
604 
606  void folderSizeChanged( KMFolder * );
607 
609  void noContentChanged();
610 
615  void syncStateChanged();
616 
617 public slots:
619  int updateIndex();
620 
623  void reallyAddMsg(KMMessage* aMsg);
624 
627  void reallyAddCopyOfMsg(KMMessage* aMsg);
628 
629 private slots:
631  void slotContentsTypeChanged( KMail::FolderContentsType type );
633  void slotFolderSizeChanged();
634 
635 private:
636  FolderStorage* mStorage;
637  KMFolderDir* mChild;
638  bool mIsSystemFolder;
639  bool mHasIndex :1;
640  bool mExportsSernums :1;
641  bool mMoveInProgress :1;
642 
644  TQString mLabel;
645  TQString mSystemLabel;
646 
648  bool mExpireMessages; // true if old messages are expired
649  int mUnreadExpireAge; // Given in unreadExpireUnits
650  int mReadExpireAge; // Given in readExpireUnits
651  ExpireUnits mUnreadExpireUnits;
652  ExpireUnits mReadExpireUnits;
653  ExpireAction mExpireAction;
654  TQString mExpireToFolderId;
655 
657  bool mUseCustomIcons;
658  TQString mNormalIconPath;
659  TQString mUnreadIconPath;
660 
662  bool mMailingListEnabled;
663  MailingList mMailingList;
664 
665  AccountList* mAcctList;
666 
667  uint mIdentity;
668 
670  TQString mWhoField, mUserWhoField;
671 
673  bool mPutRepliesInSameFolder;
674 
676  bool mIgnoreNewMail;
677 
679  KShortcut mShortcut;
680 };
681 
682 
689  KMFolder* mFolder;
690  const char* const mOwner;
691  int mOpenRc;
692 
693 public:
694  KMFolderOpener( KMFolder* folder, const char* const owner )
695  : mFolder( folder )
696  , mOwner( owner )
697  {
698  assert( folder ); //change if that's not what you want
699  mOpenRc = folder->open( owner );
700  }
701 
702  ~KMFolderOpener()
703  {
704  if ( !mOpenRc )
705  mFolder->close( mOwner );
706  }
707 
708  KMFolder* folder() const { return mFolder; }
709 
710  int openResult() const { return mOpenRc; }
711 
712 private:
713  //we forbid construction on the heap as good as we can
714  void* operator new( size_t size );
715 };
716 
717 
718 #endif /*kmfolder_h*/