File indexing completed on 2024-12-08 04:34:35

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "servererrorinfomessagehistorydialog.h"
0008 #include "servererrorinfomessagehistorywidget.h"
0009 #include <KConfigGroup>
0010 #include <KLocalizedString>
0011 #include <KSharedConfig>
0012 #include <KWindowConfig>
0013 #include <QDialogButtonBox>
0014 #include <QVBoxLayout>
0015 #include <QWindow>
0016 
0017 namespace
0018 {
0019 const char myServerErrorInfoMessageHistoryDialogConfigGroupName[] = "ServerErrorInfoMessageHistoryDialog";
0020 }
0021 ServerErrorInfoMessageHistoryDialog::ServerErrorInfoMessageHistoryDialog(QWidget *parent)
0022     : QDialog(parent)
0023     , mServerErrorInfoMessageHistoryWidget(new ServerErrorInfoMessageHistoryWidget(this))
0024 {
0025     setWindowTitle(i18nc("@title:window", "Server Error Information"));
0026     auto mainLayout = new QVBoxLayout(this);
0027     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0028 
0029     mServerErrorInfoMessageHistoryWidget->setObjectName(QStringLiteral("mServerErrorInfoMessageHistoryWidget"));
0030     mainLayout->addWidget(mServerErrorInfoMessageHistoryWidget);
0031 
0032     auto button = new QDialogButtonBox(QDialogButtonBox::Close, this);
0033     button->setObjectName(QStringLiteral("button"));
0034     mainLayout->addWidget(button);
0035     connect(button, &QDialogButtonBox::rejected, this, &ServerErrorInfoMessageHistoryDialog::reject);
0036     connect(button, &QDialogButtonBox::accepted, this, &ServerErrorInfoMessageHistoryDialog::accept);
0037     readConfig();
0038 }
0039 
0040 ServerErrorInfoMessageHistoryDialog::~ServerErrorInfoMessageHistoryDialog()
0041 {
0042     writeConfig();
0043 }
0044 
0045 void ServerErrorInfoMessageHistoryDialog::addServerList(const QStringList &serverNames)
0046 {
0047     mServerErrorInfoMessageHistoryWidget->addServerList(serverNames);
0048 }
0049 
0050 void ServerErrorInfoMessageHistoryDialog::readConfig()
0051 {
0052     create(); // ensure a window is created
0053     windowHandle()->resize(QSize(400, 300));
0054     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myServerErrorInfoMessageHistoryDialogConfigGroupName));
0055     KWindowConfig::restoreWindowSize(windowHandle(), group);
0056     resize(windowHandle()->size()); // workaround for QTBUG-40584
0057 }
0058 
0059 void ServerErrorInfoMessageHistoryDialog::writeConfig()
0060 {
0061     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myServerErrorInfoMessageHistoryDialogConfigGroupName));
0062     KWindowConfig::saveWindowSize(windowHandle(), group);
0063 }
0064 
0065 #include "moc_servererrorinfomessagehistorydialog.cpp"