Commit 8da33a4a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add save/load method

parent 56f147c5
Pipeline #27435 passed with stage
in 72 minutes and 55 seconds
......@@ -18,7 +18,7 @@
#include "collectionexpirywidget.h"
#include "kernel/mailkernel.h"
#include "folderrequester.h"
#include <KPluralHandlingSpinBox>
#include <QGroupBox>
......@@ -106,7 +106,7 @@ CollectionExpiryWidget::~CollectionExpiryWidget()
void CollectionExpiryWidget::slotChanged()
{
mChanged = true;
Q_EMIT configChanged();
}
void CollectionExpiryWidget::slotUpdateControls()
......@@ -121,5 +121,48 @@ void CollectionExpiryWidget::slotUpdateControls()
expireNowPB->setEnabled(showExpiryActions);
mChanged = true;
Q_EMIT configChanged();
}
void CollectionExpiryWidget::load(const MailCommon::CollectionExpirySettings &settings)
{
if (settings.isValid()) {
// Load the values from the folder
bool expiryGloballyOn = settings.expiryGloballyOn;
if (expiryGloballyOn
&& settings.mReadExpireUnits != ExpireCollectionAttribute::ExpireNever
&& settings.daysToExpireRead >= 0) {
expireReadMailCB->setChecked(true);
expireReadMailSB->setValue(settings.daysToExpireRead);
}
if (expiryGloballyOn
&& settings.mUnreadExpireUnits != ExpireCollectionAttribute::ExpireNever
&& settings.daysToExpireUnread >= 0) {
expireUnreadMailCB->setChecked(true);
expireUnreadMailSB->setValue(settings.daysToExpireUnread);
}
if (settings.mExpireAction == ExpireCollectionAttribute::ExpireDelete) {
deletePermanentlyRB->setChecked(true);
} else {
moveToRB->setChecked(true);
}
Akonadi::Collection::Id destFolderID = settings.mExpireToFolderId;
if (destFolderID > 0) {
Akonadi::Collection destFolder = Kernel::self()->collectionFromId(destFolderID);
if (destFolder.isValid()) {
folderSelector->setCollection(destFolder);
}
}
} else {
deletePermanentlyRB->setChecked(true);
}
slotUpdateControls();
}
CollectionExpirySettings CollectionExpiryWidget::save()
{
//TODO
return {};
}
......@@ -20,6 +20,7 @@
#define COLLECTIONEXPIRYWIDGET_H
#include "mailcommon_export.h"
#include <MailCommon/ExpireCollectionAttribute>
#include <QWidget>
class QCheckBox;
class KPluralHandlingSpinBox;
......@@ -27,6 +28,26 @@ class QRadioButton;
class QPushButton;
namespace MailCommon {
class FolderRequester;
struct MAILCOMMON_EXPORT CollectionExpirySettings
{
Q_REQUIRED_RESULT bool isValid() const {
return daysToExpireRead != -1 ||
daysToExpireUnread != -1 ||
mUnreadExpireUnits != ExpireCollectionAttribute::ExpireNever ||
mReadExpireUnits != ExpireCollectionAttribute::ExpireNever ||
mExpireAction != ExpireCollectionAttribute::ExpireDelete ||
mExpireToFolderId != -1;
}
bool expiryGloballyOn = false;
int daysToExpireRead = -1;
int daysToExpireUnread = -1;
ExpireCollectionAttribute::ExpireUnits mUnreadExpireUnits = ExpireCollectionAttribute::ExpireNever;
ExpireCollectionAttribute::ExpireUnits mReadExpireUnits = ExpireCollectionAttribute::ExpireNever;
ExpireCollectionAttribute::ExpireAction mExpireAction = ExpireCollectionAttribute::ExpireDelete;
Akonadi::Collection::Id mExpireToFolderId = -1;
};
class MAILCOMMON_EXPORT CollectionExpiryWidget : public QWidget
{
Q_OBJECT
......@@ -34,6 +55,8 @@ public:
explicit CollectionExpiryWidget(QWidget *parent = nullptr);
~CollectionExpiryWidget();
void load(const MailCommon::CollectionExpirySettings &settings);
Q_REQUIRED_RESULT MailCommon::CollectionExpirySettings save();
Q_SIGNALS:
void saveAndExpireRequested();
void configChanged();
......@@ -49,7 +72,6 @@ private:
FolderRequester *folderSelector = nullptr;
QRadioButton *deletePermanentlyRB = nullptr;
QPushButton *expireNowPB = nullptr;
bool mChanged = false;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment