File indexing completed on 2024-12-29 04:54:48
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 0008 #include "sieveinfodialog.h" 0009 #include "sieveinfowidget.h" 0010 #include <KConfigGroup> 0011 #include <KLocalizedString> 0012 #include <KSharedConfig> 0013 #include <KWindowConfig> 0014 #include <QDialogButtonBox> 0015 #include <QVBoxLayout> 0016 #include <QWindow> 0017 0018 namespace 0019 { 0020 static const char myConfigGroupName[] = "SieveInfoDialog"; 0021 } 0022 0023 using namespace KSieveUi; 0024 SieveInfoDialog::SieveInfoDialog(QWidget *parent) 0025 : QDialog(parent) 0026 , mSieveInfoWidget(new SieveInfoWidget(this)) 0027 { 0028 setWindowTitle(i18nc("@title:window", "Sieve Server Support")); 0029 auto mainLayout = new QVBoxLayout(this); 0030 mainLayout->setObjectName(QLatin1StringView("mainLayout")); 0031 0032 mSieveInfoWidget->setObjectName(QLatin1StringView("mSieveInfoWidget")); 0033 mainLayout->addWidget(mSieveInfoWidget); 0034 0035 auto button = new QDialogButtonBox(QDialogButtonBox::Close, this); 0036 button->setObjectName(QLatin1StringView("button")); 0037 mainLayout->addWidget(button); 0038 connect(button, &QDialogButtonBox::rejected, this, &SieveInfoDialog::reject); 0039 readConfig(); 0040 } 0041 0042 SieveInfoDialog::~SieveInfoDialog() 0043 { 0044 writeConfig(); 0045 } 0046 0047 void SieveInfoDialog::setServerInfo(const QStringList &serverInfos) 0048 { 0049 mSieveInfoWidget->setServerInfo(serverInfos); 0050 } 0051 0052 void SieveInfoDialog::readConfig() 0053 { 0054 create(); // ensure a window is created 0055 windowHandle()->resize(QSize(400, 300)); 0056 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigGroupName)); 0057 KWindowConfig::restoreWindowSize(windowHandle(), group); 0058 resize(windowHandle()->size()); // workaround for QTBUG-40584 0059 } 0060 0061 void SieveInfoDialog::writeConfig() 0062 { 0063 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigGroupName)); 0064 KWindowConfig::saveWindowSize(windowHandle(), group); 0065 group.sync(); 0066 } 0067 0068 #include "moc_sieveinfodialog.cpp"