kmail

folderstorage.h
1 /*
2  Virtual base class for mail storage.
3 
4  This file is part of KMail.
5 
6  Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 
23  In addition, as a special exception, the copyright holders give
24  permission to link the code of this program with any edition of
25  the TQt library by Trolltech AS, Norway (or with modified versions
26  of TQt that use the same license as TQt), and distribute linked
27  combinations including the two. You must obey the GNU General
28  Public License in all respects for all of the code used other than
29  TQt. If you modify this file, you may extend this exception to
30  your version of the file, but you are not obligated to do so. If
31  you do not wish to do so, delete this exception statement from
32  your version.
33 */
34 
35 #ifndef FOLDERSTORAGE_H
36 #define FOLDERSTORAGE_H
37 
38 // for large file support
39 #include <config.h>
40 
41 #include "kmfoldernode.h"
42 #include "kmfoldertype.h"
43 #include "kmmsginfo.h"
44 #include "kmglobal.h"
45 #include "folderjob.h"
46 using KMail::FolderJob;
47 
48 #include "mimelib/string.h"
49 
50 #include <sys/types.h>
51 #include <stdio.h>
52 
53 class KMMessage;
54 class KMAccount;
55 class KMFolderDir;
56 class KMMsgDict; // for the rDict manipulations
57 class KMMsgDictREntry;
58 class TQTimer;
59 class KMSearchPattern;
60 
61 namespace KMail {
62  class AttachmentStrategy;
63 }
64 using KMail::AttachmentStrategy;
65 
66 typedef TQValueList<TQ_UINT32> SerNumList;
67 
79 class FolderStorage : public TQObject
80 {
81  Q_OBJECT
82  TQ_OBJECT
83 
84 public:
85 
86 
90  FolderStorage( KMFolder* folder, const char* name=0 );
91  virtual ~FolderStorage();
92 
93  KMFolder* folder() const { return mFolder; }
94 
96  virtual KMFolderType folderType() const { return KMFolderTypeUnknown; }
97 
99  virtual TQString fileName() const;
101  TQString location() const;
102 
104  virtual TQString indexLocation() const = 0;
105 
107  virtual bool noContent() const { return mNoContent; }
108 
110  virtual void setNoContent(bool aNoContent);
111 
113  virtual bool noChildren() const { return mNoChildren; }
114 
116  virtual void setNoChildren( bool aNoChildren );
117 
118  enum ChildrenState {
119  HasChildren,
120  HasNoChildren,
121  ChildrenUnknown
122  };
125  virtual ChildrenState hasChildren() const { return mHasChildren; }
126 
128  virtual void setHasChildren( ChildrenState state )
129  { mHasChildren = state; }
130 
132  virtual void updateChildrenState();
133 
135  virtual KMMessage* getMsg(int idx);
136 
138  virtual KMMsgInfo* unGetMsg(int idx);
139 
141  virtual bool isMessage(int idx);
142 
147  virtual KMMessage* readTemporaryMsg(int idx);
148 
150  virtual DwString getDwString(int idx) = 0;
151 
155  virtual void ignoreJobsForMessage( KMMessage* );
156 
161  virtual FolderJob* createJob( KMMessage *msg, FolderJob::JobType jt = FolderJob::tGetMessage,
162  KMFolder *folder = 0, TQString partSpecifier = TQString(),
163  const AttachmentStrategy *as = 0 ) const;
164  virtual FolderJob* createJob( TQPtrList<KMMessage>& msgList, const TQString& sets,
165  FolderJob::JobType jt = FolderJob::tGetMessage,
166  KMFolder *folder = 0 ) const;
167 
172  virtual const KMMsgBase* getMsgBase(int idx) const = 0;
173  virtual KMMsgBase* getMsgBase(int idx) = 0;
174 
176  virtual const KMMsgBase* operator[](int idx) const { return getMsgBase(idx); }
177 
179  virtual KMMsgBase* operator[](int idx) { return getMsgBase(idx); }
180 
183  virtual KMMessage* take(int idx);
184  virtual void take(TQPtrList<KMMessage> msgList);
185 
192  virtual int addMsg(KMMessage* msg, int* index_return = 0) = 0;
193 
197  virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
198  return addMsg(msg, index_return);
199  }
200 
205  virtual int addMsg( TQPtrList<KMMessage>&, TQValueList<int>& index_return );
206 
209  void emitMsgAddedSignals(int idx);
210 
213  virtual bool canAddMsgNow(KMMessage* aMsg, int* aIndex_ret);
214 
216  virtual void removeMsg(int i, bool imapQuiet = false);
217  virtual void removeMsg(const TQPtrList<KMMsgBase>& msgList, bool imapQuiet = false);
218  virtual void removeMsg(const TQPtrList<KMMessage>& msgList, bool imapQuiet = false);
219 
222  virtual int expungeOldMsg(int days);
223 
228  virtual int moveMsg(KMMessage* msg, int* index_return = 0);
229  virtual int moveMsg(TQPtrList<KMMessage>, int* index_return = 0);
230 
232  virtual int find(const KMMsgBase* msg) const = 0;
233  int find( const KMMessage * msg ) const;
234 
236  virtual int count(bool cache = false) const;
237 
239  virtual int countUnread();
240 
242  TQ_INT64 folderSize() const;
243 
246  virtual bool isCloseToQuota() const;
247 
250  virtual void msgStatusChanged( const KMMsgStatus oldStatus,
251  const KMMsgStatus newStatus,
252  int idx);
253 
259  virtual int open(const char* owner) = 0;
260 
263  virtual int canAccess() = 0;
264 
268  void close(const char* owner, bool force=false);
269  virtual void reallyDoClose(const char* owner) = 0;
270 
273  virtual void tryReleasingFolder(KMFolder*) {}
274 
276  virtual void sync() = 0;
277 
279  bool isOpened() const { return (mOpenCount>0); }
280 
282  virtual void markNewAsUnread();
283 
285  virtual void markUnreadAsRead();
286 
290  virtual int create() = 0;
291 
296  virtual void remove();
297 
301  virtual int expunge();
302 
307  virtual int compact( bool silent ) = 0;
308 
311  virtual int rename(const TQString& newName, KMFolderDir *aParent = 0);
312 
314  bool autoCreateIndex() const { return mAutoCreateIndex; }
315 
318  virtual void setAutoCreateIndex(bool);
319 
323  bool dirty() const { return mDirty; }
324 
326  void setDirty(bool f);
327 
329  bool needsCompacting() const { return needsCompact; }
330  virtual void setNeedsCompacting(bool f) { needsCompact = f; }
331 
340  virtual void quiet(bool beQuiet);
341 
343  virtual bool isReadOnly() const = 0;
344 
346  virtual bool canDeleteMessages() const;
347 
349  TQString label() const;
350 
352  virtual void correctUnreadMsgsCount();
353 
356  virtual int writeIndex( bool createEmptyIndex = false ) = 0;
357 
361 
365 
367  virtual void setStatus(int idx, KMMsgStatus status, bool toggle=false);
368 
370  virtual void setStatus(TQValueList<int>& ids, KMMsgStatus status, bool toggle=false);
371 
372  void removeJobs();
373 
375  static TQString dotEscape(const TQString&);
376 
378  virtual void readConfig();
379 
381  virtual void writeConfig();
382 
387  virtual KMFolder* trashFolder() const { return 0; }
388 
393  void addJob( FolderJob* ) const;
394 
396  bool compactable() const { return mCompactable; }
397 
399  // If quiet is true, the KMailIcalIface is not informed of the changed. That's usefull
400  // for folder that are being copied around, should retain their type, but not cause
401  // conflicts on copy because events are identical in two folders.
402  virtual void setContentsType( KMail::FolderContentsType type, bool quiet = false );
404  KMail::FolderContentsType contentsType() const { return mContentsType; }
405 
410  virtual void search( const KMSearchPattern* );
411 
416  virtual void search( const KMSearchPattern*, TQ_UINT32 serNum );
417 
419  virtual bool isMoveable() const;
420 
421  virtual KMAccount* account() const;
422 
423  virtual bool mailCheckInProgress() const;
424 
425 signals:
428  void changed();
429 
432  void cleared();
433 
436  void expunged( KMFolder* );
437 
439  void closed( KMFolder* );
440 
442  void invalidated( KMFolder * );
443 
445  void nameChanged();
446 
450  void locationChanged( const TQString &, const TQString & );
451 
454  void contentsTypeChanged( KMail::FolderContentsType type );
455 
457  void readOnlyChanged(KMFolder*);
458 
460  void noContentChanged();
461 
463  void msgRemoved(KMFolder*, TQ_UINT32 sernum);
464 
466  void msgRemoved( int idx, TQString msgIdMD5 );
467  void msgRemoved( KMFolder* );
468 
470  void msgAdded(int idx);
471  void msgAdded(KMFolder*, TQ_UINT32 sernum);
472 
474  void msgChanged(KMFolder*, TQ_UINT32 sernum, int delta);
475 
477  void msgHeaderChanged(KMFolder*, int);
478 
480  void statusMsg(const TQString&);
481 
484 
486  void removed(KMFolder*, bool);
487 
493  void searchResult( KMFolder*, TQValueList<TQ_UINT32>,
494  const KMSearchPattern*, bool complete );
495 
500  void searchDone( KMFolder*, TQ_UINT32, const KMSearchPattern*, bool );
501 
503  void folderSizeChanged();
504 
509  void syncStateChanged();
510 
511 public slots:
513  virtual int updateIndex() = 0;
514 
517  virtual void reallyAddMsg(KMMessage* aMsg);
518 
521  virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
522 
524  void slotEmitChangedTimer();
525 
526 protected slots:
527  virtual void removeJob( TQObject* );
528 
531 
532 protected:
533 
539  virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
540  TQString partSpecifier, const AttachmentStrategy *as ) const = 0;
541  virtual FolderJob* doCreateJob( TQPtrList<KMMessage>& msgList, const TQString& sets,
542  FolderJob::JobType jt, KMFolder *folder ) const = 0;
543 
547  void headerOfMsgChanged(const KMMsgBase*, int idx);
548 
551  virtual KMMessage* readMsg(int idx) = 0;
552 
553  //--------- Message Dict manipulation
554 friend class KMMsgDict;
558  virtual void fillMessageDict() {}
559 
563  void readFolderIdsFile();
564 
566  int writeFolderIdsFile() const;
567 
569  int touchFolderIdsFile();
570 
572  int appendToFolderIdsFile( int idx = -1 );
573 
577  void setRDict(KMMsgDictREntry *rentry) const;
578 
580  KMMsgDictREntry *rDict() const { return mRDict; }
581 
582 
585  void replaceMsgSerNum( unsigned long sernum, KMMsgBase* msg, int idx );
586 
590  void invalidateFolder();
591 
595  virtual int removeContents() = 0;
596 
600  virtual int expungeContents() = 0;
601 
603  virtual bool readIndex() = 0;
604  virtual KMMsgBase* takeIndexEntry( int idx ) = 0;
605  virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg ) = 0;
606  virtual void clearIndex(bool autoDelete=true, bool syncDict = false) = 0;
607  virtual void truncateIndex() = 0;
608 
609  virtual TQ_INT64 doFolderSize() const { return 0; };
610 
611  int mOpenCount;
612  int mQuiet;
613  bool mChanged :1;
620  bool mDirty :1;
622  bool mFilesLocked :1;
623 
625  int mUnreadMsgs, mGuessedUnreadMsgs;
626  int mTotalMsgs;
627  TQ_INT64 mSize;
628  bool mWriteConfigEnabled :1;
630  bool needsCompact :1;
632  bool mCompactable :1;
633  bool mNoContent :1;
634  bool mNoChildren :1;
635  bool mConvertToUtf8 :1;
636 
638  mutable KMMsgDictREntry *mRDict;
640  mutable TQPtrList<FolderJob> mJobList;
641 
642  TQTimer *mDirtyTimer;
643  enum { mDirtyTimerInterval = 600000 }; // 10 minutes
644 
645  ChildrenState mHasChildren;
646 
648  KMail::FolderContentsType mContentsType;
649 
650  KMFolder* mFolder;
651 
652  TQTimer * mEmitChangedTimer;
653 
654  int mCurrentSearchedMsg;
655  const KMSearchPattern* mSearchPattern;
656 };
657 
658 #endif // FOLDERSTORAGE_H