Build with clang.
[kdepim.git] / mailcommon / foldercollection.h
blob323890f639b547e1f48aacb09c34c154b6db487c
1 /*
2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 2009 Montel Laurent <montel@kde.org>
5 KMail is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License, version 2, as
7 published by the Free Software Foundation.
9 KMail is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef MAILCOMMON_FOLDERCOLLECTION_H
20 #define MAILCOMMON_FOLDERCOLLECTION_H
22 #include "mailcommon_export.h"
24 #include <kshortcut.h>
25 #include <akonadi/collection.h>
26 #include <akonadi/collectionstatistics.h>
27 #include <KIO/Job>
28 #include <ksharedconfig.h>
30 #include "messagecore/mailinglist.h"
31 using MessageCore::MailingList;
33 namespace MailCommon {
35 class Kernel;
37 class MAILCOMMON_EXPORT FolderCollection : public QObject
39 Q_OBJECT
40 public:
41 static QSharedPointer<FolderCollection> forCollection( const Akonadi::Collection& coll, bool writeConfig = true );
43 ~FolderCollection();
46 * Define the possible units to use for measuring message expiry.
47 * expireNever is used to switch off message expiry, and expireMaxUnits
48 * must always be the last in the list (for bounds checking).
50 enum ExpireUnits { ExpireNever, ExpireDays, ExpireWeeks, ExpireMonths, ExpireMaxUnits };
52 Akonadi::Collection collection() const;
55 QString configGroupName() const;
58 bool isWriteConfig() const;
59 void setWriteConfig( bool writeConfig );
61 void writeConfig() const;
62 void readConfig();
64 QString name() const;
66 QString idString() const;
68 bool isReadOnly() const;
70 bool isStructural() const;
72 bool isSystemFolder() const;
74 qint64 count() const;
76 bool canDeleteMessages() const;
78 bool canCreateMessages() const;
80 bool isValid() const;
82 Akonadi::Collection::Rights rights() const;
84 Akonadi::CollectionStatistics statistics() const;
86 enum ExpireAction { ExpireDelete, ExpireMove };
89 const KShortcut &shortcut() const { return mShortcut; }
91 void setShortcut( const KShortcut& );
93 /** Get / set whether the default identity should be used instead of the
94 * identity specified by setIdentity(). */
95 void setUseDefaultIdentity( bool useDefaultIdentity );
96 bool useDefaultIdentity() const { return mUseDefaultIdentity; }
98 void setIdentity(uint identity);
99 uint identity() const;
102 * Set whether this folder automatically expires messages.
104 void setAutoExpire(bool enabled);
107 * Does this folder automatically expire old messages?
109 bool isAutoExpire() const { return mExpireMessages; }
112 * Set the maximum age for unread messages in this folder.
113 * Age should not be negative. Units are set using
114 * setUnreadExpireUnits().
116 void setUnreadExpireAge(int age);
119 * Set units to use for expiry of unread messages.
120 * Values are 1 = days, 2 = weeks, 3 = months.
122 void setUnreadExpireUnits(ExpireUnits units);
125 * Set the maximum age for read messages in this folder.
126 * Age should not be negative. Units are set using
127 * setReadExpireUnits().
129 void setReadExpireAge(int age);
132 * Set units to use for expiry of read messages.
133 * Values are 1 = days, 2 = weeks, 3 = months.
135 void setReadExpireUnits(ExpireUnits units);
138 * Get the age at which unread messages are expired.
139 * Units are determined by getUnreadExpireUnits().
141 int getUnreadExpireAge() const { return mUnreadExpireAge; }
144 * Get the age at which read messages are expired.
145 * Units are determined by getReadExpireUnits().
147 int getReadExpireAge() const { return mReadExpireAge; }
150 * What should expiry do? Delete or move to another folder?
152 ExpireAction expireAction() const { return mExpireAction; }
153 void setExpireAction( ExpireAction a );
156 * If expiry should move to folder, return the ID of that folder
158 QString expireToFolderId() const { return mExpireToFolderId; }
159 void setExpireToFolderId( const QString& id );
162 * Units getUnreadExpireAge() is returned in.
163 * 1 = days, 2 = weeks, 3 = months.
165 ExpireUnits getUnreadExpireUnits() const { return mUnreadExpireUnits; }
168 * Units getReadExpireAge() is returned in.
169 * 1 = days, 2 = weeks, 3 = months.
171 ExpireUnits getReadExpireUnits() const { return mReadExpireUnits; }
175 /** Returns true if this folder is associated with a mailing-list. */
176 void setMailingListEnabled( bool enabled );
177 bool isMailingListEnabled() const { return mMailingListEnabled; }
179 void setMailingList( const MailingList& mlist );
180 MailingList mailingList() const
181 { return mMailingList; }
183 void daysToExpire( int& unreadDays, int& readDays );
186 * Returns true if the replies to mails from this folder should be
187 * put in the same folder.
189 bool putRepliesInSameFolder() const { return mPutRepliesInSameFolder; }
190 void setPutRepliesInSameFolder( bool b ) { mPutRepliesInSameFolder = b; }
193 * Returns true if this folder should be hidden from all folder selection dialogs
195 bool hideInSelectionDialog() const { return mHideInSelectionDialog; }
196 void setHideInSelectionDialog( bool hide ) { mHideInSelectionDialog = hide; }
199 * Returns true if the user doesn't want to get notified about new mail
200 * in this folder.
202 bool ignoreNewMail() const { return mIgnoreNewMail; }
203 void setIgnoreNewMail( bool b ) { mIgnoreNewMail = b; }
205 QString mailingListPostAddress() const;
207 void removeCollection();
208 void expireOldMessages( bool immediate );
210 protected slots:
211 void slotIdentitiesChanged();
212 void slotDeletionCollectionResult( KJob *job );
214 signals:
215 void viewConfigChanged();
217 private:
219 explicit FolderCollection( const Akonadi::Collection& col, bool writeconfig );
221 Akonadi::Collection mCollection;
222 bool mExpireMessages; // true if old messages are expired
223 int mUnreadExpireAge; // Given in unreadExpireUnits
224 int mReadExpireAge; // Given in readExpireUnits
225 ExpireUnits mUnreadExpireUnits;
226 ExpireUnits mReadExpireUnits;
227 ExpireAction mExpireAction;
228 QString mExpireToFolderId;
230 /** Mailing list attributes */
231 bool mMailingListEnabled;
232 MailingList mMailingList;
234 bool mUseDefaultIdentity;
235 uint mIdentity;
237 /** Should new mail in this folder be ignored? */
238 bool mIgnoreNewMail;
240 /** Should replies to messages in this folder be put in here? */
241 bool mPutRepliesInSameFolder;
243 /** Should this folder be hidden in the folder selection dialog? */
244 bool mHideInSelectionDialog;
246 /** shortcut associated with this folder or null, if none is configured. */
247 KShortcut mShortcut;
248 bool mWriteConfig;
250 bool mOldIgnoreNewMail;
255 #endif