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