File indexing completed on 2025-01-19 04:46:43

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "confirmaddressconfiguretabwidget.h"
0008 #include "confirmaddresssimplestringlisteditor.h"
0009 #include <KConfigGroup>
0010 #include <KLocalizedString>
0011 #include <QGroupBox>
0012 #include <QRadioButton>
0013 #include <QVBoxLayout>
0014 
0015 ConfirmAddressConfigureTabWidget::ConfirmAddressConfigureTabWidget(QWidget *parent)
0016     : QWidget(parent)
0017 {
0018     auto mainLayout = new QVBoxLayout(this);
0019     mainLayout->setObjectName(QLatin1StringView("mainlayout"));
0020     mainLayout->setContentsMargins({});
0021 
0022     auto groupBoxDomainName = new QGroupBox(this);
0023     groupBoxDomainName->setObjectName(QLatin1StringView("groupboxdomainname"));
0024     mainLayout->addWidget(groupBoxDomainName);
0025     auto layoutDomainName = new QVBoxLayout(groupBoxDomainName);
0026     layoutDomainName->setObjectName(QLatin1StringView("layoutdomainname"));
0027 
0028     auto radioButtonLayout = new QHBoxLayout;
0029     layoutDomainName->addLayout(radioButtonLayout);
0030     radioButtonLayout->setAlignment(Qt::AlignHCenter);
0031 
0032     mAcceptedDomain = new QRadioButton(i18n("Accepted Domain Name"), this);
0033     mAcceptedDomain->setObjectName(QLatin1StringView("acceptdomainname"));
0034     radioButtonLayout->addWidget(mAcceptedDomain);
0035     mAcceptedDomain->setChecked(true);
0036 
0037     mRejectedDomain = new QRadioButton(i18n("Rejected Domain Name"), this);
0038     mRejectedDomain->setObjectName(QLatin1StringView("rejectdomainname"));
0039     radioButtonLayout->addWidget(mRejectedDomain);
0040 
0041     auto buttonCode = static_cast<PimCommon::SimpleStringListEditor::ButtonCode>(
0042         PimCommon::SimpleStringListEditor::Add | PimCommon::SimpleStringListEditor::Remove | PimCommon::SimpleStringListEditor::Modify);
0043     mDomainNameListEditor = new ConfirmAddressSimpleStringListEditor(groupBoxDomainName,
0044                                                                      buttonCode,
0045                                                                      i18n("A&dd..."),
0046                                                                      i18n("Re&move"),
0047                                                                      i18n("Mod&ify..."),
0048                                                                      i18n("Enter new domain name:"));
0049     mDomainNameListEditor->setObjectName(QLatin1StringView("domainnamelisteditor"));
0050     mDomainNameListEditor->setRemoveDialogLabel(i18n("Do you want to remove this domain?"));
0051     connect(mDomainNameListEditor, &ConfirmAddressSimpleStringListEditor::changed, this, &ConfirmAddressConfigureTabWidget::configureChanged);
0052     layoutDomainName->addWidget(mDomainNameListEditor);
0053 
0054     auto groupBoxWhiteList = new QGroupBox(i18n("Whitelist of Addresses"), this);
0055     groupBoxWhiteList->setObjectName(QLatin1StringView("groupboxwhitelist"));
0056     mainLayout->addWidget(groupBoxWhiteList);
0057     auto layoutWhiteList = new QVBoxLayout(groupBoxWhiteList);
0058     layoutWhiteList->setObjectName(QLatin1StringView("layoutwhitelist"));
0059 
0060     buttonCode = static_cast<PimCommon::SimpleStringListEditor::ButtonCode>(PimCommon::SimpleStringListEditor::Add | PimCommon::SimpleStringListEditor::Remove
0061                                                                             | PimCommon::SimpleStringListEditor::Modify);
0062     mWhiteListEditor = new ConfirmAddressSimpleStringListEditor(groupBoxWhiteList,
0063                                                                 buttonCode,
0064                                                                 i18n("A&dd..."),
0065                                                                 i18n("Re&move"),
0066                                                                 i18n("Mod&ify..."),
0067                                                                 i18n("Enter new email address:"));
0068     mWhiteListEditor->setObjectName(QLatin1StringView("whitelisteditor"));
0069     mWhiteListEditor->setRemoveDialogLabel(i18n("Do you want to remove this email address?"));
0070     layoutWhiteList->addWidget(mWhiteListEditor);
0071     connect(mWhiteListEditor, &ConfirmAddressSimpleStringListEditor::changed, this, &ConfirmAddressConfigureTabWidget::configureChanged);
0072 }
0073 
0074 ConfirmAddressConfigureTabWidget::~ConfirmAddressConfigureTabWidget() = default;
0075 
0076 void ConfirmAddressConfigureTabWidget::resetSettings()
0077 {
0078     mDomainNameListEditor->setStringList({});
0079     mWhiteListEditor->setStringList({});
0080 }
0081 
0082 void ConfirmAddressConfigureTabWidget::loadSettings(const KConfigGroup &grp)
0083 {
0084     KConfigGroup identityGroup = grp.group(QStringLiteral("Confirm Address %1").arg(mIdentity));
0085     mDomainNameListEditor->setStringList(identityGroup.readEntry("Domains", QStringList()));
0086     mWhiteListEditor->setStringList(identityGroup.readEntry("Emails", QStringList()));
0087     const bool rejectedDomain = identityGroup.readEntry("RejectDomain", false);
0088     if (rejectedDomain) {
0089         mRejectedDomain->setChecked(true);
0090     } else {
0091         mAcceptedDomain->setChecked(true);
0092     }
0093 }
0094 
0095 void ConfirmAddressConfigureTabWidget::saveSettings(KConfigGroup &grp)
0096 {
0097     KConfigGroup identityGroup = grp.group(QStringLiteral("Confirm Address %1").arg(mIdentity));
0098     identityGroup.writeEntry("Domains", mDomainNameListEditor->stringList());
0099     identityGroup.writeEntry("Emails", mWhiteListEditor->stringList());
0100     identityGroup.writeEntry("RejectDomain", mRejectedDomain->isChecked());
0101 }
0102 
0103 void ConfirmAddressConfigureTabWidget::setIdentity(uint identity)
0104 {
0105     mIdentity = identity;
0106 }
0107 
0108 #include "moc_confirmaddressconfiguretabwidget.cpp"