From 7ebfa9b04b1e9f7c7d8dfe0efc769bf45f915593 Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Wed, 23 Sep 2020 07:57:07 +0200 Subject: [PATCH] Extract widget --- .../collectiongeneralwidget.cpp | 129 +++++++++++++++++- src/collectionpage/collectiongeneralwidget.h | 10 +- 2 files changed, 137 insertions(+), 2 deletions(-) diff --git a/src/collectionpage/collectiongeneralwidget.cpp b/src/collectionpage/collectiongeneralwidget.cpp index 7a9cde6..8ef279f 100644 --- a/src/collectionpage/collectiongeneralwidget.cpp +++ b/src/collectionpage/collectiongeneralwidget.cpp @@ -5,11 +5,90 @@ */ #include "collectiongeneralwidget.h" +#include "kernel/mailkernel.h" +#include "folder/foldersettings.h" +#include "util/mailutil_p.h" +#include +#include +#include +#include +#include +#include +#include using namespace MailCommon; CollectionGeneralWidget::CollectionGeneralWidget(QWidget *parent) : QWidget(parent) { + QVBoxLayout *topLayout = new QVBoxLayout(this); + topLayout->setObjectName(QStringLiteral("topLayout")); + topLayout->setContentsMargins({}); + // should new mail in this folder be ignored? + QHBoxLayout *hbl = new QHBoxLayout(); + topLayout->addItem(hbl); + mNotifyOnNewMailCheckBox + = new QCheckBox(i18n("Act on new/unread mail in this folder"), this); + mNotifyOnNewMailCheckBox->setWhatsThis( + i18n("

If this option is enabled then you will be notified about " + "new/unread mail in this folder. Moreover, going to the " + "next/previous folder with unread messages will stop at this " + "folder.

" + "

Uncheck this option if you do not want to be notified about " + "new/unread mail in this folder and if you want this folder to " + "be skipped when going to the next/previous folder with unread " + "messages. This is useful for ignoring any new/unread mail in " + "your trash and spam folder.

")); + hbl->addWidget(mNotifyOnNewMailCheckBox); + // should replies to mails in this folder be kept in this same folder? + hbl = new QHBoxLayout(); + topLayout->addItem(hbl); + mKeepRepliesInSameFolderCheckBox + = new QCheckBox(i18n("Keep replies in this folder"), this); + mKeepRepliesInSameFolderCheckBox->setWhatsThis( + i18n("Check this option if you want replies you write " + "to mails in this folder to be put in this same folder " + "after sending, instead of in the configured sent-mail folder.")); + hbl->addWidget(mKeepRepliesInSameFolderCheckBox); + hbl->addStretch(1); + // should this folder be shown in the folder selection dialog? + hbl = new QHBoxLayout(); + topLayout->addItem(hbl); + mHideInSelectionDialogCheckBox + = new QCheckBox(i18n("Hide this folder in the folder selection dialog"), this); + mHideInSelectionDialogCheckBox->setWhatsThis( + xi18nc("@info:whatsthis", + "Check this option if you do not want this folder " + "to be shown in folder selection dialogs, such as the " + "Jump to Folder dialog.")); + hbl->addWidget(mHideInSelectionDialogCheckBox); + hbl->addStretch(1); + + addLine(this, topLayout); + // use grid layout for the following combobox settings + QGridLayout *gl = new QGridLayout(); + topLayout->addItem(gl); + gl->setColumnStretch(1, 100); // make the second column use all available space + int row = -1; + + // sender identity + ++row; + mUseDefaultIdentityCheckBox = new QCheckBox(i18n("Use &default identity"), this); + gl->addWidget(mUseDefaultIdentityCheckBox); + connect(mUseDefaultIdentityCheckBox, &QCheckBox::stateChanged, this, &CollectionGeneralWidget::slotIdentityCheckboxChanged); + ++row; + QLabel *label = new QLabel(i18n("&Sender identity:"), this); + gl->addWidget(label, row, 0); + mIdentityComboBox = new KIdentityManagement::IdentityCombo(KernelIf->identityManager(), this); + label->setBuddy(mIdentityComboBox); + gl->addWidget(mIdentityComboBox, row, 1); + mIdentityComboBox->setWhatsThis( + i18n("Select the sender identity to be used when writing new mail " + "or replying to mail in this folder. This means that if you are in " + "one of your work folders, you can make KMail use the corresponding " + "sender email address, signature and signing or encryption keys " + "automatically. Identities can be set up in the main configuration " + "dialog. (Settings -> Configure KMail)")); + } @@ -18,12 +97,60 @@ CollectionGeneralWidget::~CollectionGeneralWidget() } -void CollectionGeneralWidget::save(Akonadi::Collection &col) +void CollectionGeneralWidget::addLine(QWidget *parent, QVBoxLayout *layout) { + QFrame *line = new QFrame(parent); + line->setGeometry(QRect(80, 150, 250, 20)); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + line->setFrameShape(QFrame::HLine); + layout->addWidget(line); +} + +void CollectionGeneralWidget::slotIdentityCheckboxChanged() +{ + mIdentityComboBox->setEnabled(!mUseDefaultIdentityCheckBox->isChecked()); + if (mFolderCollection && mUseDefaultIdentityCheckBox->isChecked()) { + mIdentityComboBox->setCurrentIdentity(mFolderCollection->fallBackIdentity()); + } +} + + +void CollectionGeneralWidget::save(Akonadi::Collection &collection) +{ + if (!mNotifyOnNewMailCheckBox->isChecked()) { + Akonadi::NewMailNotifierAttribute *newMailNotifierAttr = collection.attribute(Akonadi::Collection::AddIfMissing); + newMailNotifierAttr->setIgnoreNewMail(true); + } else { + collection.removeAttribute(); + } + if (mFolderCollection) { + mFolderCollection->setIdentity(mIdentityComboBox->currentIdentity()); + mFolderCollection->setUseDefaultIdentity(mUseDefaultIdentityCheckBox->isChecked()); + + mFolderCollection->setPutRepliesInSameFolder(mKeepRepliesInSameFolderCheckBox->isChecked()); + mFolderCollection->setHideInSelectionDialog(mHideInSelectionDialogCheckBox->isChecked()); + mFolderCollection->writeConfig(); + } } void CollectionGeneralWidget::load(const Akonadi::Collection &col) { + mFolderCollection = MailCommon::FolderSettings::forCollection(col); + // folder identity + mIdentityComboBox->setCurrentIdentity(mFolderCollection->identity()); + mUseDefaultIdentityCheckBox->setChecked(mFolderCollection->useDefaultIdentity()); + + // ignore new mail + mNotifyOnNewMailCheckBox->setChecked(!Util::ignoreNewMailInFolder(col)); + + const bool keepInFolder = (mFolderCollection->canCreateMessages() + && mFolderCollection->putRepliesInSameFolder()); + + mKeepRepliesInSameFolderCheckBox->setChecked(keepInFolder); + mKeepRepliesInSameFolderCheckBox->setEnabled(mFolderCollection->canCreateMessages()); + mHideInSelectionDialogCheckBox->setChecked(mFolderCollection->hideInSelectionDialog()); + } diff --git a/src/collectionpage/collectiongeneralwidget.h b/src/collectionpage/collectiongeneralwidget.h index 55e038f..9b93c03 100644 --- a/src/collectionpage/collectiongeneralwidget.h +++ b/src/collectionpage/collectiongeneralwidget.h @@ -11,7 +11,12 @@ #include "mailcommon_export.h" #include class QCheckBox; +class QVBoxLayout; +namespace KIdentityManagement { +class IdentityCombo; +} namespace MailCommon { +class FolderSettings; class MAILCOMMON_EXPORT CollectionGeneralWidget : public QWidget { Q_OBJECT @@ -21,11 +26,14 @@ public: void save(Akonadi::Collection &); void load(const Akonadi::Collection &col); private: + void addLine(QWidget *parent, QVBoxLayout *layout); + void slotIdentityCheckboxChanged(); QCheckBox *mNotifyOnNewMailCheckBox = nullptr; QCheckBox *mKeepRepliesInSameFolderCheckBox = nullptr; QCheckBox *mHideInSelectionDialogCheckBox = nullptr; QCheckBox *mUseDefaultIdentityCheckBox = nullptr; - + KIdentityManagement::IdentityCombo *mIdentityComboBox = nullptr; + QSharedPointer mFolderCollection; }; } #endif // COLLECTIONGENERALWIDGET_H