Mailcommon

collectionexpirypage.cpp
1 /*
2  SPDX-FileCopyrightText: 2009-2022 Laurent Montel <[email protected]>
3  SPDX-FileCopyrightText: 2013 Jonathan Marten <[email protected]>
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 #include "folder/foldersettings.h"
13 #include "kernel/mailkernel.h"
14 #include "mailcommon_debug.h"
15 #include "util/mailutil.h"
16 
17 #include <KLocalizedString>
18 #include <QVBoxLayout>
19 
20 using namespace Akonadi;
21 using namespace MailCommon;
22 
23 CollectionExpiryPage::CollectionExpiryPage(QWidget *parent)
24  : CollectionPropertiesPage(parent)
25 {
26  setObjectName(QStringLiteral("MailCommon::CollectionExpiryPage"));
27  setPageTitle(i18nc("@title:tab Expiry settings for a folder.", "Expiry"));
28 }
29 
30 CollectionExpiryPage::~CollectionExpiryPage() = default;
31 
32 bool CollectionExpiryPage::canHandle(const Akonadi::Collection &col) const
33 {
34  return CollectionExpiryWidget::canHandle(col);
35 }
36 
37 void CollectionExpiryPage::init()
38 {
39  auto globalVBox = new QVBoxLayout(this);
40  mCollectionExpiryWidget = new CollectionExpiryWidget(this);
41  connect(mCollectionExpiryWidget, &CollectionExpiryWidget::saveAndExpireRequested, this, &CollectionExpiryPage::slotSaveAndExpire);
42  connect(mCollectionExpiryWidget, &CollectionExpiryWidget::configChanged, this, &CollectionExpiryPage::slotConfigChanged);
43  globalVBox->addWidget(mCollectionExpiryWidget);
44 
45  globalVBox->addStretch(100); // eat all superfluous space
46 }
47 
48 void CollectionExpiryPage::slotConfigChanged(bool changed)
49 {
50  mChanged = changed;
51 }
52 
53 void CollectionExpiryPage::load(const Akonadi::Collection &collection)
54 {
55  mCollection = collection;
56  init();
57  const auto *attr = collection.attribute<MailCommon::ExpireCollectionAttribute>();
58  if (attr) {
59  int daysToExpireRead;
60  int daysToExpireUnread;
61  attr->daysToExpire(daysToExpireUnread, daysToExpireRead);
62  MailCommon::CollectionExpirySettings settings;
63  settings.expiryGloballyOn = attr->isAutoExpire();
64  settings.daysToExpireRead = daysToExpireRead;
65  settings.daysToExpireUnread = daysToExpireUnread;
66  settings.mUnreadExpireUnits = attr->unreadExpireUnits();
67  settings.mReadExpireUnits = attr->readExpireUnits();
68  settings.mExpireAction = attr->expireAction();
69  settings.mExpireToFolderId = attr->expireToFolderId();
70 
71  mCollectionExpiryWidget->load(settings);
72  } else {
73  mCollectionExpiryWidget->load({});
74  }
75  mChanged = false;
76 }
77 
78 void CollectionExpiryPage::save(Akonadi::Collection &collection)
79 {
80  if (mChanged) {
81  saveAndExpire(collection, false, true);
82  }
83 }
84 
85 void CollectionExpiryPage::saveAndExpire(Akonadi::Collection &collection, bool saveSettings, bool expireNow)
86 {
87  mCollectionExpiryWidget->save(collection, saveSettings, expireNow);
88  mChanged = false;
89 }
90 
91 void CollectionExpiryPage::slotSaveAndExpire()
92 {
93  saveAndExpire(mCollection, true, true); // save and start expire job
94 }
95 
96 void CollectionExpiryPage::slotChanged()
97 {
98  mChanged = true;
99 }
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
const T * attribute() const
void setObjectName(const QString &name)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.