File indexing completed on 2024-12-01 04:36:34

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "administratorsettingsdialog.h"
0008 #include "administratorsettingswidget.h"
0009 
0010 #include "rocketchataccount.h"
0011 
0012 #include <KConfigGroup>
0013 #include <KLocalizedString>
0014 #include <KSharedConfig>
0015 #include <KWindowConfig>
0016 #include <QDialogButtonBox>
0017 #include <QVBoxLayout>
0018 #include <QWindow>
0019 
0020 namespace
0021 {
0022 const char myAdministratorSettingsDialogGroupName[] = "AdministratorSettingsDialog";
0023 }
0024 
0025 AdministratorSettingsDialog::AdministratorSettingsDialog(RocketChatAccount *account, QWidget *parent)
0026     : QDialog(parent)
0027     , mAdministratorSettingsWidget(new AdministratorSettingsWidget(account, this))
0028 {
0029     // Use "account-name" for autotest only when account is empty
0030     setWindowTitle(i18nc("@title:window", "Administrator Server Settings - %1", account ? account->accountName() : QStringLiteral("account-name")));
0031     auto mainLayout = new QVBoxLayout(this);
0032     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0033 
0034     mAdministratorSettingsWidget->setObjectName(QStringLiteral("mAdministratorSettingsWidget"));
0035     mainLayout->addWidget(mAdministratorSettingsWidget);
0036 
0037     auto button = new QDialogButtonBox(QDialogButtonBox::Close, this);
0038     button->setObjectName(QStringLiteral("button"));
0039     mainLayout->addWidget(button);
0040     connect(button, &QDialogButtonBox::rejected, this, &AdministratorSettingsDialog::reject);
0041     connect(button, &QDialogButtonBox::accepted, this, &AdministratorSettingsDialog::accept);
0042 
0043     readConfig();
0044 }
0045 
0046 AdministratorSettingsDialog::~AdministratorSettingsDialog()
0047 {
0048     writeConfig();
0049 }
0050 
0051 void AdministratorSettingsDialog::loadSettings()
0052 {
0053     mAdministratorSettingsWidget->loadSettings();
0054 }
0055 
0056 void AdministratorSettingsDialog::readConfig()
0057 {
0058     create(); // ensure a window is created
0059     windowHandle()->resize(QSize(400, 300));
0060     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myAdministratorSettingsDialogGroupName));
0061     KWindowConfig::restoreWindowSize(windowHandle(), group);
0062     resize(windowHandle()->size()); // workaround for QTBUG-40584
0063 }
0064 
0065 void AdministratorSettingsDialog::writeConfig()
0066 {
0067     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myAdministratorSettingsDialogGroupName));
0068     KWindowConfig::saveWindowSize(windowHandle(), group);
0069 }
0070 
0071 #include "moc_administratorsettingsdialog.cpp"