Mailcommon

collectionexpirypage.cpp
1/*
2 SPDX-FileCopyrightText: 2009-2024 Laurent Montel <montel@kde.org>
3 SPDX-FileCopyrightText: 2013 Jonathan Marten <jjm@keelhaul.me.uk>
4
5 SPDX-License-Identifier: GPL-2.0-only
6*/
7
8#include "collectionexpirypage.h"
9#include "collectionexpirywidget.h"
10
11#include "attributes/expirecollectionattribute.h"
12
13#include <KLocalizedString>
14#include <QVBoxLayout>
15
16using namespace Akonadi;
17using namespace MailCommon;
18
19CollectionExpiryPage::CollectionExpiryPage(QWidget *parent)
21{
22 setObjectName(QLatin1StringView("MailCommon::CollectionExpiryPage"));
23 setPageTitle(i18nc("@title:tab Expiry settings for a folder.", "Expiry"));
24}
25
26CollectionExpiryPage::~CollectionExpiryPage() = default;
27
28bool CollectionExpiryPage::canHandle(const Akonadi::Collection &col) const
29{
30 return CollectionExpiryWidget::canHandle(col);
31}
32
33void CollectionExpiryPage::init()
34{
35 auto globalVBox = new QVBoxLayout(this);
36 mCollectionExpiryWidget = new CollectionExpiryWidget(this);
37 connect(mCollectionExpiryWidget, &CollectionExpiryWidget::saveAndExpireRequested, this, &CollectionExpiryPage::slotSaveAndExpire);
38 connect(mCollectionExpiryWidget, &CollectionExpiryWidget::configChanged, this, &CollectionExpiryPage::slotConfigChanged);
39 globalVBox->addWidget(mCollectionExpiryWidget);
40
41 globalVBox->addStretch(100); // eat all superfluous space
42}
43
44void CollectionExpiryPage::slotConfigChanged(bool changed)
45{
46 mChanged = changed;
47}
48
49void CollectionExpiryPage::load(const Akonadi::Collection &collection)
50{
51 mCollection = collection;
52 init();
53 const auto *attr = collection.attribute<MailCommon::ExpireCollectionAttribute>();
54 if (attr) {
55 int daysToExpireRead;
56 int daysToExpireUnread;
57 attr->daysToExpire(daysToExpireUnread, daysToExpireRead);
58 MailCommon::CollectionExpirySettings settings;
59 settings.expiryGloballyOn = attr->isAutoExpire();
60 settings.daysToExpireRead = daysToExpireRead;
61 settings.daysToExpireUnread = daysToExpireUnread;
62 settings.mUnreadExpireUnits = attr->unreadExpireUnits();
63 settings.mReadExpireUnits = attr->readExpireUnits();
64 settings.mExpireAction = attr->expireAction();
65 settings.mExpireToFolderId = attr->expireToFolderId();
66
67 mCollectionExpiryWidget->load(settings);
68 } else {
69 mCollectionExpiryWidget->load({});
70 }
71 mChanged = false;
72}
73
74void CollectionExpiryPage::save(Akonadi::Collection &collection)
75{
76 if (mChanged) {
77 saveAndExpire(collection, false, true);
78 }
79}
80
81void CollectionExpiryPage::saveAndExpire(Akonadi::Collection &collection, bool saveSettings, bool expireNow)
82{
83 mCollectionExpiryWidget->save(collection, saveSettings, expireNow);
84 mChanged = false;
85}
86
87void CollectionExpiryPage::slotSaveAndExpire()
88{
89 saveAndExpire(mCollection, true, true); // save and start expire job
90}
91
92void CollectionExpiryPage::slotChanged()
93{
94 mChanged = true;
95}
96
97#include "moc_collectionexpirypage.cpp"
const T * attribute() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
The filter dialog.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:04:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.