Commit c9d83a6c authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to extract widget

parent 4c78b21f
Pipeline #27468 passed with stage
in 26 minutes and 47 seconds
......@@ -98,6 +98,7 @@ set(libmailcommon_collection_SRCS
collectionpage/collectionexpirypage.cpp
collectionpage/collectionexpirywidget.cpp
collectionpage/attributes/expirecollectionattribute.cpp
collectionpage/collectionexpiryjob.cpp
)
set(libmailcommon_folder_SRCS
......
/*
Copyright (c) 2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "collectionexpiryjob.h"
#include "util/mailutil.h"
#include "mailcommon_debug.h"
#include <AkonadiCore/Collection>
#include <AkonadiCore/CollectionModifyJob>
using namespace MailCommon;
CollectionExpiryJob::CollectionExpiryJob(QObject *parent)
: QObject(parent)
{
}
CollectionExpiryJob::~CollectionExpiryJob()
{
}
void CollectionExpiryJob::start()
{
if (mCollection.isValid()) {
Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob(mCollection, this);
connect(job, &Akonadi::CollectionModifyJob::result, this, &CollectionExpiryJob::slotCollectionModified);
} else {
qCWarning(MAILCOMMON_LOG) << "Collection is not valid";
deleteLater();
}
}
void CollectionExpiryJob::setCollection(const Akonadi::Collection &collection)
{
mCollection = collection;
}
void CollectionExpiryJob::setExpireNow(bool expireNow)
{
mExpireNow = expireNow;
}
void CollectionExpiryJob::slotCollectionModified(KJob *job)
{
if (job->error()) {
qCWarning(MAILCOMMON_LOG) << " Error when we modified collection";
deleteLater();
return;
}
// trigger immediate expiry if there is something to do
if (mExpireNow) {
Akonadi::CollectionModifyJob *modifiedJob = qobject_cast<Akonadi::CollectionModifyJob *>(job);
if (modifiedJob) {
MailCommon::Util::expireOldMessages(modifiedJob->collection(), true /*immediate*/);
} else {
qCWarning(MAILCOMMON_LOG) << " invalid pointer";
}
}
deleteLater();
}
/*
Copyright (c) 2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef COLLECTIONEXPIRYJOB_H
#define COLLECTIONEXPIRYJOB_H
#include <QObject>
#include <AkonadiCore/Collection>
class KJob;
namespace MailCommon {
class CollectionExpiryJob : public QObject
{
Q_OBJECT
public:
explicit CollectionExpiryJob(QObject *parent = nullptr);
~CollectionExpiryJob();
void start();
void setCollection(const Akonadi::Collection &collection);
void setExpireNow(bool expireNow);
private:
void slotCollectionModified(KJob *job);
bool mExpireNow = false;
Akonadi::Collection mCollection;
};
}
#endif // COLLECTIONEXPIRYJOB_H
......@@ -18,9 +18,19 @@
#include "collectionexpirywidget.h"
#include "collectionexpiryjob.h"
#include "kernel/mailkernel.h"
#include "folderrequester.h"
#include "attributes/expirecollectionattribute.h"
#include "folder/foldersettings.h"
#include "util/mailutil.h"
#include "mailcommon_debug.h"
#include <CollectionModifyJob>
#include <KPluralHandlingSpinBox>
#include <KMessageBox>
#include <QGroupBox>
#include <QRadioButton>
#include <QVBoxLayout>
......@@ -160,23 +170,8 @@ void CollectionExpiryWidget::load(const MailCommon::CollectionExpirySettings &se
slotUpdateControls();
}
CollectionExpirySettings CollectionExpiryWidget::save()
bool CollectionExpiryWidget::validateExpireFolder(bool expireNow)
{
CollectionExpirySettings settings;
settings.expiryGloballyOn = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
// we always write out days now
settings.daysToExpireRead = expireReadMailSB->value();
settings.daysToExpireUnread = expireUnreadMailSB->value();
settings.mReadExpireUnits = expireReadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays : MailCommon::ExpireCollectionAttribute::ExpireNever;
settings.mUnreadExpireUnits = expireUnreadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays : MailCommon::ExpireCollectionAttribute::ExpireNever;
if (deletePermanentlyRB->isChecked()) {
settings.mExpireAction = ExpireCollectionAttribute::ExpireDelete;
} else {
settings.mExpireAction = ExpireCollectionAttribute::ExpireMove;
}
#if 0
const bool enableGlobally = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
const Akonadi::Collection expireToFolder = folderSelector->collection();
if (enableGlobally && moveToRB->isChecked() && !expireToFolder.isValid()) {
......@@ -185,7 +180,12 @@ CollectionExpirySettings CollectionExpiryWidget::save()
deletePermanentlyRB->setChecked(true);
expireNow = false; // settings are not valid
}
return expireNow;
}
MailCommon::ExpireCollectionAttribute *CollectionExpiryWidget::assignFolderAttribute(Akonadi::Collection &collection, bool &expireNow)
{
const Akonadi::Collection expireToFolder = folderSelector->collection();
MailCommon::ExpireCollectionAttribute *attribute = nullptr;
if (expireToFolder.isValid() && moveToRB->isChecked()) {
if (expireToFolder.id() == collection.id()) {
......@@ -201,32 +201,49 @@ CollectionExpirySettings CollectionExpiryWidget::save()
if (!attribute) {
attribute = collection.attribute<MailCommon::ExpireCollectionAttribute>(Akonadi::Collection::AddIfMissing);
}
return attribute;
}
attribute->setAutoExpire(enableGlobally);
CollectionExpirySettings CollectionExpiryWidget::settings() const
{
CollectionExpirySettings settings;
settings.expiryGloballyOn = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
// we always write out days now
attribute->setReadExpireAge(expireReadMailSB->value());
attribute->setUnreadExpireAge(expireUnreadMailSB->value());
attribute->setReadExpireUnits(expireReadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays
: MailCommon::ExpireCollectionAttribute::ExpireNever);
attribute->setUnreadExpireUnits(expireUnreadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays
: MailCommon::ExpireCollectionAttribute::ExpireNever);
settings.daysToExpireRead = expireReadMailSB->value();
settings.daysToExpireUnread = expireUnreadMailSB->value();
settings.mReadExpireUnits = expireReadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays : MailCommon::ExpireCollectionAttribute::ExpireNever;
settings.mUnreadExpireUnits = expireUnreadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays : MailCommon::ExpireCollectionAttribute::ExpireNever;
if (deletePermanentlyRB->isChecked()) {
attribute->setExpireAction(ExpireCollectionAttribute::ExpireDelete);
settings.mExpireAction = ExpireCollectionAttribute::ExpireDelete;
} else {
attribute->setExpireAction(ExpireCollectionAttribute::ExpireMove);
settings.mExpireAction = ExpireCollectionAttribute::ExpireMove;
}
return settings;
}
void CollectionExpiryWidget::save(Akonadi::Collection &collection, bool saveSettings, bool expireNow)
{
expireNow = validateExpireFolder(expireNow);
const CollectionExpirySettings collectionExpirySettings = settings();
MailCommon::ExpireCollectionAttribute *attribute = assignFolderAttribute(collection, expireNow);
attribute->setAutoExpire(collectionExpirySettings.expiryGloballyOn);
// we always write out days now
attribute->setReadExpireAge(collectionExpirySettings.daysToExpireRead);
attribute->setUnreadExpireAge(collectionExpirySettings.daysToExpireUnread);
attribute->setReadExpireUnits(collectionExpirySettings.mReadExpireUnits);
attribute->setUnreadExpireUnits(collectionExpirySettings.mUnreadExpireUnits);
attribute->setExpireAction(collectionExpirySettings.mExpireAction);
if (saveSettings) {
Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob(collection, this);
job->setProperty("expireNow", expireNow);
connect(job, &Akonadi::CollectionModifyJob::result, this, &CollectionExpiryPage::slotCollectionModified);
CollectionExpiryJob *job = new CollectionExpiryJob;
job->setExpireNow(expireNow);
job->setCollection(collection);
job->start();
} else {
if (expireNow) {
MailCommon::Util::expireOldMessages(collection, true /*immediate*/);
}
}
mChanged = false;
#endif
//TODO
return settings;
Q_EMIT configChanged(false);
}
......@@ -26,6 +26,7 @@ class QCheckBox;
class KPluralHandlingSpinBox;
class QRadioButton;
class QPushButton;
class KJob;
namespace MailCommon {
class FolderRequester;
struct MAILCOMMON_EXPORT CollectionExpirySettings
......@@ -56,14 +57,18 @@ public:
~CollectionExpiryWidget();
void load(const MailCommon::CollectionExpirySettings &settings);
Q_REQUIRED_RESULT MailCommon::CollectionExpirySettings save();
void save(Akonadi::Collection &collection, bool saveSettings, bool expireNow);
Q_SIGNALS:
void saveAndExpireRequested();
void configChanged();
void configChanged(bool changed = true);
private:
Q_REQUIRED_RESULT bool validateExpireFolder(bool expireNow);
Q_REQUIRED_RESULT CollectionExpirySettings settings() const;
Q_REQUIRED_RESULT MailCommon::ExpireCollectionAttribute *assignFolderAttribute(Akonadi::Collection &collection, bool &expireNow);
void slotChanged();
void slotUpdateControls();
void slotCollectionModified(KJob *job);
QCheckBox *expireReadMailCB = nullptr;
KPluralHandlingSpinBox *expireReadMailSB = nullptr;
QCheckBox *expireUnreadMailCB = nullptr;
......
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