File indexing completed on 2025-01-05 04:49:42
0001 /* 0002 SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "scamconfiguresettingsdialog.h" 0008 #include "scamconfiguresettingswidget.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 myScamConfigureSettingsDialogConfigGroupName[] = "ScamConfigureSettingsDialog"; 0019 } 0020 ScamConfigureSettingsDialog::ScamConfigureSettingsDialog(QWidget *parent) 0021 : QDialog(parent) 0022 , mScamConfigureSettingsWidget(new ScamConfigureSettingsWidget(this)) 0023 { 0024 auto mainLayout = new QVBoxLayout(this); 0025 mainLayout->setObjectName(QLatin1StringView("mainLayout")); 0026 setWindowTitle(i18nc("@title:window", "Configure Scam Settings")); 0027 0028 mScamConfigureSettingsWidget->setObjectName(QLatin1StringView("mScamConfigureSettingsWidget")); 0029 mainLayout->addWidget(mScamConfigureSettingsWidget); 0030 0031 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0032 buttonBox->setObjectName(QLatin1StringView("buttonBox")); 0033 mainLayout->addWidget(buttonBox); 0034 0035 connect(buttonBox, &QDialogButtonBox::accepted, this, &ScamConfigureSettingsDialog::slotAccepted); 0036 connect(buttonBox, &QDialogButtonBox::rejected, this, &ScamConfigureSettingsDialog::reject); 0037 mScamConfigureSettingsWidget->loadSettings(); 0038 0039 readConfig(); 0040 } 0041 0042 ScamConfigureSettingsDialog::~ScamConfigureSettingsDialog() 0043 { 0044 writeConfig(); 0045 } 0046 0047 void ScamConfigureSettingsDialog::slotAccepted() 0048 { 0049 mScamConfigureSettingsWidget->saveSettings(); 0050 accept(); 0051 } 0052 0053 void ScamConfigureSettingsDialog::readConfig() 0054 { 0055 create(); // ensure a window is created 0056 windowHandle()->resize(QSize(300, 200)); 0057 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myScamConfigureSettingsDialogConfigGroupName)); 0058 KWindowConfig::restoreWindowSize(windowHandle(), group); 0059 resize(windowHandle()->size()); // workaround for QTBUG-40584 0060 } 0061 0062 void ScamConfigureSettingsDialog::writeConfig() 0063 { 0064 KConfigGroup grp(KSharedConfig::openStateConfig(), QLatin1StringView(myScamConfigureSettingsDialogConfigGroupName)); 0065 KWindowConfig::saveWindowSize(windowHandle(), grp); 0066 grp.sync(); 0067 } 0068 0069 #include "moc_scamconfiguresettingsdialog.cpp"