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

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "dkimauthenticationverifiedserverdialog.h"
0008 #include "dkimauthenticationverifiedserverwidget.h"
0009 #include <KConfigGroup>
0010 #include <KLocalizedString>
0011 #include <KSharedConfig>
0012 #include <KWindowConfig>
0013 #include <QDialogButtonBox>
0014 #include <QVBoxLayout>
0015 #include <QWindow>
0016 namespace
0017 {
0018 static const char myConfigGroupName[] = "DKIMAuthenticationVerifiedServerDialog";
0019 }
0020 
0021 DKIMAuthenticationVerifiedServerDialog::DKIMAuthenticationVerifiedServerDialog(QWidget *parent)
0022     : QDialog(parent)
0023     , mAuthenticationVerifiedWidget(new DKIMAuthenticationVerifiedServerWidget(this))
0024 {
0025     setWindowTitle(i18nc("@title:window", "Configure Authentication Verified Server"));
0026     auto mainLayout = new QVBoxLayout(this);
0027     mainLayout->setObjectName(QLatin1StringView("mainlayout"));
0028 
0029     mAuthenticationVerifiedWidget->setObjectName(QLatin1StringView("mAuthenticationVerifiedWidget"));
0030     mainLayout->addWidget(mAuthenticationVerifiedWidget);
0031 
0032     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0033     buttonBox->setObjectName(QLatin1StringView("buttonBox"));
0034     mainLayout->addWidget(buttonBox);
0035 
0036     connect(buttonBox, &QDialogButtonBox::accepted, this, &DKIMAuthenticationVerifiedServerDialog::slotAccepted);
0037     connect(buttonBox, &QDialogButtonBox::rejected, this, &DKIMAuthenticationVerifiedServerDialog::reject);
0038     mAuthenticationVerifiedWidget->loadSettings();
0039     readConfig();
0040 }
0041 
0042 DKIMAuthenticationVerifiedServerDialog::~DKIMAuthenticationVerifiedServerDialog()
0043 {
0044     writeConfig();
0045 }
0046 
0047 void DKIMAuthenticationVerifiedServerDialog::slotAccepted()
0048 {
0049     mAuthenticationVerifiedWidget->saveSettings();
0050     accept();
0051 }
0052 
0053 void DKIMAuthenticationVerifiedServerDialog::readConfig()
0054 {
0055     create(); // ensure a window is created
0056     windowHandle()->resize(QSize(600, 400));
0057     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigGroupName));
0058     KWindowConfig::restoreWindowSize(windowHandle(), group);
0059     resize(windowHandle()->size()); // workaround for QTBUG-40584
0060 }
0061 
0062 void DKIMAuthenticationVerifiedServerDialog::writeConfig()
0063 {
0064     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigGroupName));
0065     KWindowConfig::saveWindowSize(windowHandle(), group);
0066     group.sync();
0067 }
0068 
0069 #include "moc_dkimauthenticationverifiedserverdialog.cpp"