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