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