8#include "foldersettings.h"
9#include "kernel/mailkernel.h"
10#include "util/resourcereadconfigfile.h"
11#include <Akonadi/CollectionModifyJob>
12#include <Akonadi/ItemFetchJob>
13#include <Akonadi/ItemFetchScope>
14#include <Akonadi/NewMailNotifierAttribute>
15#include <PimCommon/PimUtil>
19#include <KIdentityManagementCore/Identity>
20#include <KIdentityManagementCore/IdentityManager>
23#include <QMutexLocker>
24#include <QSharedPointer>
39 fcMap.insert(coll.
id(), sptr);
41 sptr->setCollection(coll);
42 if (!sptr->isWriteConfig() && writeConfig) {
43 sptr->setWriteConfig(
true);
52 , mWriteConfig(writeconfig)
55 mIdentity = KernelIf->identityManager()->defaultIdentity().uoid();
61FolderSettings::~FolderSettings()
69MessageViewer::Viewer::DisplayFormatMessage FolderSettings::formatMessage()
const
71 return mFormatMessage;
74void FolderSettings::setFormatMessage(MessageViewer::Viewer::DisplayFormatMessage formatMessage)
76 mFormatMessage = formatMessage;
79void FolderSettings::clearCache()
85void FolderSettings::resetHtmlFormat()
89 while (i != fcMap.constEnd()) {
90 i.
value()->setFormatMessage(MessageViewer::Viewer::UseGlobalSetting);
95bool FolderSettings::isWriteConfig()
const
100void FolderSettings::setWriteConfig(
bool writeConfig)
102 mWriteConfig = writeConfig;
105QString FolderSettings::name()
const
107 return mCollection.name();
110bool FolderSettings::isSystemFolder()
const
112 return Kernel::self()->isSystemFolderCollection(mCollection);
115bool FolderSettings::isStructural()
const
117 return mCollection.contentMimeTypes().
isEmpty();
120bool FolderSettings::isReadOnly()
const
125bool FolderSettings::canDeleteMessages()
const
130bool FolderSettings::canCreateMessages()
const
135qint64 FolderSettings::count()
const
137 return mCollection.statistics().count();
140Akonadi::Collection::Rights FolderSettings::rights()
const
142 return mCollection.rights();
147 return mCollection.statistics();
152 mCollection = collection;
155void FolderSettings::slotIdentitiesChanged()
157 uint defaultIdentity = KernelIf->identityManager()->defaultIdentity().uoid();
159 if (mUseDefaultIdentity) {
160 mIdentity = defaultIdentity;
164 if (KernelIf->identityManager()->identityForUoid(mIdentity).isNull()) {
165 mIdentity = defaultIdentity;
166 mUseDefaultIdentity =
true;
175void FolderSettings::readConfig()
177 KConfigGroup configGroup(KernelIf->config(), configGroupName(mCollection));
178 mMailingListEnabled = configGroup.readEntry(
"MailingListEnabled",
false);
179 mMailingList.readConfig(configGroup);
181 mUseDefaultIdentity = configGroup.readEntry(
"UseDefaultIdentity",
true);
182 uint defaultIdentity = KernelIf->identityManager()->defaultIdentity().uoid();
183 mIdentity = configGroup.readEntry(
"Identity", defaultIdentity);
184 slotIdentitiesChanged();
186 mPutRepliesInSameFolder = configGroup.readEntry(
"PutRepliesInSameFolder",
false);
187 mHideInSelectionDialog = configGroup.readEntry(
"HideInSelectionDialog",
false);
189 if (configGroup.hasKey(QStringLiteral(
"IgnoreNewMail"))) {
190 if (configGroup.readEntry(QStringLiteral(
"IgnoreNewMail"),
false)) {
193 newMailNotifierAttr->setIgnoreNewMail(
true);
197 configGroup.deleteEntry(
"IgnoreNewMail");
206 mFormatMessage =
static_cast<MessageViewer::Viewer::DisplayFormatMessage
>(
207 configGroup.readEntry(
"displayFormatOverride",
static_cast<int>(MessageViewer::Viewer::UseGlobalSetting)));
209 mFolderHtmlLoadExtPreference = configGroup.readEntry(
"htmlLoadExternalOverride",
false);
212bool FolderSettings::isValid()
const
214 return mCollection.isValid();
217void FolderSettings::writeConfig()
const
219 const QString res = resource();
223 KConfigGroup configGroup(KernelIf->config(), configGroupName(mCollection));
225 if (mMailingListEnabled) {
226 configGroup.writeEntry(
"MailingListEnabled", mMailingListEnabled);
228 configGroup.deleteEntry(
"MailingListEnabled");
230 mMailingList.writeConfig(configGroup);
232 if (!mUseDefaultIdentity) {
233 configGroup.writeEntry(
"UseDefaultIdentity", mUseDefaultIdentity);
234 uint defaultIdentityId = -1;
236 if (PimCommon::Util::isImapResource(res)) {
237 MailCommon::ResourceReadConfigFile resourceFile(res);
240 defaultIdentityId = grp.
readEntry(QStringLiteral(
"AccountIdentity"), -1);
243 defaultIdentityId = KernelIf->identityManager()->defaultIdentity().uoid();
246 if (mIdentity != defaultIdentityId) {
247 configGroup.writeEntry(
"Identity", mIdentity);
249 configGroup.deleteEntry(
"Identity");
252 configGroup.deleteEntry(
"Identity");
253 configGroup.deleteEntry(
"UseDefaultIdentity");
256 if (mPutRepliesInSameFolder) {
257 configGroup.writeEntry(
"PutRepliesInSameFolder", mPutRepliesInSameFolder);
259 configGroup.deleteEntry(
"PutRepliesInSameFolder");
261 if (mHideInSelectionDialog) {
262 configGroup.writeEntry(
"HideInSelectionDialog", mHideInSelectionDialog);
264 configGroup.deleteEntry(
"HideInSelectionDialog");
267 if (!mShortcut.isEmpty()) {
268 configGroup.writeEntry(
"Shortcut", mShortcut.toString());
270 configGroup.deleteEntry(
"Shortcut");
273 if (mFormatMessage != MessageViewer::Viewer::Unknown) {
274 if (mFormatMessage == MessageViewer::Viewer::UseGlobalSetting) {
275 configGroup.deleteEntry(
"displayFormatOverride");
277 configGroup.writeEntry(
"displayFormatOverride",
static_cast<int>(mFormatMessage));
280 if (mFolderHtmlLoadExtPreference) {
281 configGroup.writeEntry(
"htmlLoadExternalOverride", mFolderHtmlLoadExtPreference);
283 configGroup.deleteEntry(
"htmlLoadExternalOverride");
297void FolderSettings::setUseDefaultIdentity(
bool useDefaultIdentity)
299 if (mUseDefaultIdentity != useDefaultIdentity) {
300 mUseDefaultIdentity = useDefaultIdentity;
301 if (mUseDefaultIdentity) {
302 mIdentity = KernelIf->identityManager()->defaultIdentity().uoid();
304 KernelIf->syncConfig();
308bool FolderSettings::useDefaultIdentity()
const
310 return mUseDefaultIdentity;
313void FolderSettings::setIdentity(uint identity)
315 if (mIdentity != identity) {
316 mIdentity = identity;
317 KernelIf->syncConfig();
321QString FolderSettings::resource()
const
323 const QString resource = mCollection.resource();
325 const Collection col = CommonKernel->collectionFromId(mCollection.id());
334bool FolderSettings::folderHtmlLoadExtPreference()
const
336 return mFolderHtmlLoadExtPreference;
339void FolderSettings::setFolderHtmlLoadExtPreference(
bool folderHtmlLoadExtPreference)
341 mFolderHtmlLoadExtPreference = folderHtmlLoadExtPreference;
344uint FolderSettings::fallBackIdentity()
const
347 MailCommon::ResourceReadConfigFile resourceFile(resource());
350 const bool useDefault = grp.
readEntry(QStringLiteral(
"UseDefaultIdentity"),
true);
354 const int remoteAccountIdent = grp.
readEntry(QStringLiteral(
"AccountIdentity"), -1);
355 if (remoteAccountIdent > 0) {
356 identityId = remoteAccountIdent;
359 if (identityId != -1 && !KernelIf->identityManager()->identityForUoid(identityId).isNull()) {
365uint FolderSettings::identity()
const
367 if (mUseDefaultIdentity) {
368 return fallBackIdentity();
373QString FolderSettings::mailingListPostAddress()
const
381 const QString protocol = (*it).scheme();
390void FolderSettings::setMailingListEnabled(
bool enabled)
392 if (mMailingListEnabled != enabled) {
393 mMailingListEnabled = enabled;
398bool FolderSettings::isMailingListEnabled()
const
400 return mMailingListEnabled;
403void FolderSettings::setMailingList(
const MailingList &mlist)
405 if (mMailingList == mlist) {
409 mMailingList = mlist;
418bool FolderSettings::putRepliesInSameFolder()
const
420 return mPutRepliesInSameFolder;
423void FolderSettings::setPutRepliesInSameFolder(
bool b)
425 mPutRepliesInSameFolder = b;
428bool FolderSettings::hideInSelectionDialog()
const
430 return mHideInSelectionDialog;
433void FolderSettings::setHideInSelectionDialog(
bool hide)
435 mHideInSelectionDialog = hide;
439#include "moc_foldersettings.cpp"
KConfigGroup group(const QString &group)
QString readEntry(const char *key, const char *aDefault=nullptr) const
const QList< QKeySequence > & end()
const QList< QKeySequence > & shortcut(StandardShortcut id)
const_iterator constBegin() const const
const_iterator constEnd() const const
T value(const Key &key, const T &defaultValue) const const
bool isNull() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)