Commit 56f147c5 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Extract CollectionExpiryWidget

parent aa2d7660
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.15.40")
set(PIM_VERSION "5.15.41")
project(mailcommon VERSION ${PIM_VERSION})
......
......@@ -96,6 +96,7 @@ set(libmailcommon_collection_SRCS
collectionpage/attributeregistrar.cpp
collectionpage/collectiongeneralpage.cpp
collectionpage/collectionexpirypage.cpp
collectionpage/collectionexpirywidget.cpp
collectionpage/attributes/expirecollectionattribute.cpp
)
......@@ -393,6 +394,7 @@ ecm_generate_headers(MailCommon_Camelcasecollectionpage_HEADERS
HEADER_NAMES
CollectionGeneralPage
CollectionExpiryPage
CollectionExpiryWidget
REQUIRED_HEADERS MailCommon_collectionpage_HEADERS
PREFIX MailCommon
RELATIVE collectionpage
......
......@@ -33,6 +33,7 @@ class QRadioButton;
namespace MailCommon {
class FolderRequester;
class CollectionExpiryWidget;
/**
* @brief The CollectionExpiryPage class
* @author Laurent Montel <montel@kde.org>
......@@ -62,6 +63,7 @@ private:
void saveAndExpire(Akonadi::Collection &collection, bool saveSettings, bool _expirenow);
private:
CollectionExpiryWidget *mCollectionExpiryWidget = nullptr;
QCheckBox *expireReadMailCB = nullptr;
KPluralHandlingSpinBox *expireReadMailSB = nullptr;
QCheckBox *expireUnreadMailCB = nullptr;
......
/*
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 "collectionexpirywidget.h"
#include "folderrequester.h"
#include <KPluralHandlingSpinBox>
#include <QGroupBox>
#include <QRadioButton>
#include <QVBoxLayout>
#include <QCheckBox>
#include <QPushButton>
using namespace MailCommon;
CollectionExpiryWidget::CollectionExpiryWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *globalVBox = new QVBoxLayout(this);
QGridLayout *daysBox = new QGridLayout;
expireReadMailCB = new QCheckBox(this);
expireReadMailCB->setText(i18n("Expire read messages after"));
connect(expireReadMailCB, &QCheckBox::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
daysBox->addWidget(expireReadMailCB, 0, 0, Qt::AlignLeft);
expireReadMailSB = new KPluralHandlingSpinBox(this);
expireReadMailSB->setMaximum(999999);
expireReadMailSB->setValue(30);
expireReadMailSB->setSuffix(ki18ncp("Expire messages after %1", " day", " days"));
daysBox->addWidget(expireReadMailSB, 0, 1);
connect(expireReadMailSB, QOverload<int>::of(&KPluralHandlingSpinBox::valueChanged), this, &CollectionExpiryWidget::slotChanged);
expireUnreadMailCB = new QCheckBox(this);
expireUnreadMailCB->setText(i18n("Expire unread messages after"));
connect(expireUnreadMailCB, &QCheckBox::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
daysBox->addWidget(expireUnreadMailCB, 1, 0, Qt::AlignLeft);
expireUnreadMailSB = new KPluralHandlingSpinBox(this);
expireUnreadMailSB->setMaximum(99999);
expireUnreadMailSB->setValue(30);
expireUnreadMailSB->setSuffix(ki18ncp("Expire messages after %1", " day", " days"));
daysBox->addWidget(expireUnreadMailSB, 1, 1);
connect(expireUnreadMailSB, QOverload<int>::of(&KPluralHandlingSpinBox::valueChanged), this, &CollectionExpiryWidget::slotChanged);
daysBox->setColumnStretch(3, 1);
globalVBox->addLayout(daysBox);
globalVBox->addSpacing(30);
QGroupBox *actionsGroup = new QGroupBox(this);
actionsGroup->setFlat(true); // for mutual exclusion of the radio buttons
QHBoxLayout *moveToHBox = new QHBoxLayout();
moveToHBox->setContentsMargins(0, 0, 0, 0);
moveToHBox->setSpacing(6);
moveToRB = new QRadioButton(actionsGroup);
moveToRB->setText(i18n("Move expired messages to:"));
connect(moveToRB, &QRadioButton::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
moveToHBox->addWidget(moveToRB);
folderSelector = new FolderRequester(this);
folderSelector->setMustBeReadWrite(true);
folderSelector->setShowOutbox(false);
moveToHBox->addWidget(folderSelector);
globalVBox->addLayout(moveToHBox);
connect(folderSelector, &FolderRequester::folderChanged, this, &CollectionExpiryWidget::slotChanged);
deletePermanentlyRB = new QRadioButton(actionsGroup);
deletePermanentlyRB->setText(i18n("Delete expired messages permanently"));
connect(deletePermanentlyRB, &QRadioButton::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
globalVBox->addWidget(deletePermanentlyRB);
globalVBox->addSpacing(30);
expireNowPB = new QPushButton(i18n("Save Settings and Expire Now"), this);
connect(expireNowPB, &QPushButton::clicked, this, &CollectionExpiryWidget::saveAndExpireRequested);
globalVBox->addWidget(expireNowPB, 0, Qt::AlignRight);
globalVBox->addStretch(100); // eat all superfluous space
}
CollectionExpiryWidget::~CollectionExpiryWidget()
{
}
void CollectionExpiryWidget::slotChanged()
{
mChanged = true;
}
void CollectionExpiryWidget::slotUpdateControls()
{
const bool showExpiryActions = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
moveToRB->setEnabled(showExpiryActions);
folderSelector->setEnabled(showExpiryActions && moveToRB->isChecked());
deletePermanentlyRB->setEnabled(showExpiryActions);
expireReadMailSB->setEnabled(expireReadMailCB->isChecked());
expireUnreadMailSB->setEnabled(expireUnreadMailCB->isChecked());
expireNowPB->setEnabled(showExpiryActions);
mChanged = true;
}
/*
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 COLLECTIONEXPIRYWIDGET_H
#define COLLECTIONEXPIRYWIDGET_H
#include "mailcommon_export.h"
#include <QWidget>
class QCheckBox;
class KPluralHandlingSpinBox;
class QRadioButton;
class QPushButton;
namespace MailCommon {
class FolderRequester;
class MAILCOMMON_EXPORT CollectionExpiryWidget : public QWidget
{
Q_OBJECT
public:
explicit CollectionExpiryWidget(QWidget *parent = nullptr);
~CollectionExpiryWidget();
Q_SIGNALS:
void saveAndExpireRequested();
void configChanged();
private:
void slotChanged();
void slotUpdateControls();
QCheckBox *expireReadMailCB = nullptr;
KPluralHandlingSpinBox *expireReadMailSB = nullptr;
QCheckBox *expireUnreadMailCB = nullptr;
KPluralHandlingSpinBox *expireUnreadMailSB = nullptr;
QRadioButton *moveToRB = nullptr;
FolderRequester *folderSelector = nullptr;
QRadioButton *deletePermanentlyRB = nullptr;
QPushButton *expireNowPB = nullptr;
bool mChanged = false;
};
}
#endif // COLLECTIONEXPIRYWIDGET_H
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