summaryrefslogtreecommitdiffstats
path: root/kmail/kmfoldermgr.h
blob: d4ec786e0156b119548adf2bd5a666bfbbec3f43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* KMail Folder Manager
 *
 */
#ifndef kmfoldermgr_h
#define kmfoldermgr_h

#include <tqstring.h>
#include <tqvaluelist.h>
#include <tqobject.h>
#include <tqguardedptr.h>

#include "kmfolderdir.h"

class KMFolder;

class KMFolderMgr: public QObject
{
  Q_OBJECT

public:
  KMFolderMgr(const TQString& basePath, KMFolderDirType dirType = KMStandardDir);
  virtual ~KMFolderMgr();

  /** Returns path to directory where all the folders live. */
  TQString basePath() const { return mBasePath; }

  /** Set base path. Also calls reload() on the base directory. */
  virtual void setBasePath(const TQString&);

  /** Provides access to base directory */
  KMFolderRootDir& dir();

  /** Searches folder and returns it. Skips directories
    (objects of type KMFolderDir) if foldersOnly is TRUE. */
  virtual KMFolder* find(const TQString& folderName, bool foldersOnly=TRUE);

  /** Searches for a folder with the given id, recurses into directories */
  virtual KMFolder* findIdString(const TQString& folderId,
     const uint id = 0, KMFolderDir *dir = 0);

  /** Uses find() to find given folder. If not found the folder is
   * created. Directories are skipped.
   * If an id is passed this searches for it
   */
  virtual KMFolder* findOrCreate(const TQString& folderName, bool sysFldr=TRUE,
      const uint id = 0);

  /** Searches folder by id and returns it. Skips directories
    (objects of type KMFolderDir) */
  virtual KMFolder* findById(const uint id);

  virtual void        getFolderURLS( TQStringList& flist,
                                     const TQString& prefix=TQString::null,
                                     KMFolderDir *adir=0 );
  virtual KMFolder*   getFolderByURL( const TQString& vpath,
                                      const TQString& prefix=TQString::null,
                                      KMFolderDir *adir=0 );

  /** Create a mail folder in the root folder directory dir()
    with given name. Returns Folder on success. */
  virtual KMFolder* createFolder(const TQString& fName, bool sysFldr=FALSE,
				 KMFolderType aFolderType=KMFolderTypeMbox,
				 KMFolderDir *aFolderDir = 0);

  /** Physically remove given folder and delete the given folder object. */
  virtual void remove(KMFolder* obsoleteFolder);

  /** emits changed() signal */
  virtual void contentsChanged(void);

  /** Reloads all folders, discarding the existing ones. */
  virtual void reload(void);

  /** Create a list of formatted formatted folder labels and corresponding
   folders*/
  virtual void createFolderList( TQStringList *str,
				 TQValueList<TQGuardedPtr<KMFolder> > *folders );

  /** Auxillary function to facilitate creating a list of formatted
      folder names, suitable for showing in TQComboBox */
  virtual void createFolderList( TQStringList *str,
 				 TQValueList<TQGuardedPtr<KMFolder> > *folders,
  				 KMFolderDir *adir,
  				 const TQString& prefix,
				 bool i18nized=FALSE );

  /** Create a list of formatted formatted folder labels and corresponding
   folders. The system folder names are translated */
  virtual void createI18nFolderList( TQStringList *str,
				 TQValueList<TQGuardedPtr<KMFolder> > *folders );

  /** fsync all open folders to disk */
  void syncAllFolders( KMFolderDir *adir = 0 );

  /** Compact all folders that need to be, either immediately or scheduled as a background task */
  void compactAllFolders( bool immediate, KMFolderDir *adir = 0 );

  /** Expire old messages in all folders, either immediately or scheduled as a background task */
  void expireAllFolders( bool immediate, KMFolderDir *adir = 0 );

  /** Enable, disable changed() signals */
  void quiet(bool);

  /** Number of folders for purpose of progres report */
  int folderCount(KMFolderDir *dir=0);

  /** Try closing @p folder if possible, something is attempting an exclusive access to it.
      Currently used for KMFolderSearch and the background tasks like expiry */
  void tryReleasingFolder(KMFolder* folder, KMFolderDir *Dir=0);

  /** Create a new unique ID */
  uint createId();

  /** Move a folder */
  void moveFolder( KMFolder* folder, KMFolderDir* newParent );

  /** Rename or move a folder */
  void renameFolder( KMFolder* folder, const TQString& newName, 
      KMFolderDir* newParent = 0 );
  
  /** Copy a folder */
  void copyFolder( KMFolder* folder, KMFolderDir* newParent );

  /** Returns the parent Folder for the given folder or 0 on failure.  */
  KMFolder* parentFolder( KMFolder* folder );

public slots:
  /** GUI action: compact all folders that need to be compacted */
  void compactAll() { compactAllFolders( true ); }

  /** GUI action: expire all folders configured as such */
  void expireAll();

  /** Called from KMFolder::remove when the folderstorage was removed */
  void removeFolderAux(KMFolder* obsoleteFolder, bool success);

  /** Called when the renaming of a folder is done */
  void slotRenameDone( TQString newName, bool success );

signals:
  /** Emitted when the list of folders has changed. This signal is a hook
    where clients like the KMFolderTree tree-view can connect. The signal
    is meant to be emitted whenever the code using the folder-manager
    changed things. */
  void changed();

  /** Emitted, when a folder is about to be removed. */
  void folderRemoved(KMFolder*);

  /** Emitted, when a folder has been added. */
  void folderAdded(KMFolder*);

  /** Emitted, when serial numbers for a folder have been invalidated. */
  void folderInvalidated(KMFolder*);

  /** Emitted, when a message has been appended to a folder */
  void msgAdded(KMFolder*, Q_UINT32);

  /** Emitted, when a message has been removed from a folder */
  void msgRemoved(KMFolder*, Q_UINT32);

  /** Emitted, when the status of a message is changed */
  void msgChanged(KMFolder*, Q_UINT32, int delta);

  /** Emitted when a field of the header of a specific message changed. */
  void msgHeaderChanged(KMFolder*, int idx);

  /** Emitted when a folder has been moved or copied */
  void folderMoveOrCopyOperationFinished();

protected:

  /** Auxillary function to facilitate removal of a folder */
  void removeFolder(KMFolder* aFolder);

  /** Auxillary function to facilitate removal of a folder directory */
  void removeDirAux(KMFolderDir* aFolderDir);

  TQString mBasePath;
  KMFolderRootDir mDir;
  int mQuiet;
  bool mChanged;
  KMFolder* mRemoveOrig;
};

#endif /*kmfoldermgr_h*/