Warning, file /pim/mailcommon/src/collectionpage/collectionexpirypage.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2009-2024 Laurent Montel <montel@kde.org> 0003 SPDX-FileCopyrightText: 2013 Jonathan Marten <jjm@keelhaul.me.uk> 0004 0005 SPDX-License-Identifier: GPL-2.0-only 0006 */ 0007 0008 #include "collectionexpirypage.h" 0009 #include "collectionexpirywidget.h" 0010 0011 #include "attributes/expirecollectionattribute.h" 0012 0013 #include <KLocalizedString> 0014 #include <QVBoxLayout> 0015 0016 using namespace Akonadi; 0017 using namespace MailCommon; 0018 0019 CollectionExpiryPage::CollectionExpiryPage(QWidget *parent) 0020 : CollectionPropertiesPage(parent) 0021 { 0022 setObjectName(QLatin1StringView("MailCommon::CollectionExpiryPage")); 0023 setPageTitle(i18nc("@title:tab Expiry settings for a folder.", "Expiry")); 0024 } 0025 0026 CollectionExpiryPage::~CollectionExpiryPage() = default; 0027 0028 bool CollectionExpiryPage::canHandle(const Akonadi::Collection &col) const 0029 { 0030 return CollectionExpiryWidget::canHandle(col); 0031 } 0032 0033 void CollectionExpiryPage::init() 0034 { 0035 auto globalVBox = new QVBoxLayout(this); 0036 mCollectionExpiryWidget = new CollectionExpiryWidget(this); 0037 connect(mCollectionExpiryWidget, &CollectionExpiryWidget::saveAndExpireRequested, this, &CollectionExpiryPage::slotSaveAndExpire); 0038 connect(mCollectionExpiryWidget, &CollectionExpiryWidget::configChanged, this, &CollectionExpiryPage::slotConfigChanged); 0039 globalVBox->addWidget(mCollectionExpiryWidget); 0040 0041 globalVBox->addStretch(100); // eat all superfluous space 0042 } 0043 0044 void CollectionExpiryPage::slotConfigChanged(bool changed) 0045 { 0046 mChanged = changed; 0047 } 0048 0049 void CollectionExpiryPage::load(const Akonadi::Collection &collection) 0050 { 0051 mCollection = collection; 0052 init(); 0053 const auto *attr = collection.attribute<MailCommon::ExpireCollectionAttribute>(); 0054 if (attr) { 0055 int daysToExpireRead; 0056 int daysToExpireUnread; 0057 attr->daysToExpire(daysToExpireUnread, daysToExpireRead); 0058 MailCommon::CollectionExpirySettings settings; 0059 settings.expiryGloballyOn = attr->isAutoExpire(); 0060 settings.daysToExpireRead = daysToExpireRead; 0061 settings.daysToExpireUnread = daysToExpireUnread; 0062 settings.mUnreadExpireUnits = attr->unreadExpireUnits(); 0063 settings.mReadExpireUnits = attr->readExpireUnits(); 0064 settings.mExpireAction = attr->expireAction(); 0065 settings.mExpireToFolderId = attr->expireToFolderId(); 0066 0067 mCollectionExpiryWidget->load(settings); 0068 } else { 0069 mCollectionExpiryWidget->load({}); 0070 } 0071 mChanged = false; 0072 } 0073 0074 void CollectionExpiryPage::save(Akonadi::Collection &collection) 0075 { 0076 if (mChanged) { 0077 saveAndExpire(collection, false, true); 0078 } 0079 } 0080 0081 void CollectionExpiryPage::saveAndExpire(Akonadi::Collection &collection, bool saveSettings, bool expireNow) 0082 { 0083 mCollectionExpiryWidget->save(collection, saveSettings, expireNow); 0084 mChanged = false; 0085 } 0086 0087 void CollectionExpiryPage::slotSaveAndExpire() 0088 { 0089 saveAndExpire(mCollection, true, true); // save and start expire job 0090 } 0091 0092 void CollectionExpiryPage::slotChanged() 0093 { 0094 mChanged = true; 0095 } 0096 0097 #include "moc_collectionexpirypage.cpp"