File indexing completed on 2025-01-19 04:47:00

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