File indexing completed on 2024-12-08 04:34:04
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "administratordialog.h" 0008 #include "administratorwidget.h" 0009 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 const char myAdministratorDialogGroupName[] = "AdministratorDialog"; 0021 } 0022 0023 AdministratorDialog::AdministratorDialog(RocketChatAccount *account, QWidget *parent) 0024 : QDialog(parent) 0025 , mAdministratorWidget(new AdministratorWidget(account, this)) 0026 { 0027 setWindowTitle(i18nc("@title:window", "Administrator")); 0028 auto mainLayout = new QVBoxLayout(this); 0029 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0030 0031 mAdministratorWidget->setObjectName(QStringLiteral("mAdministratorWidget")); 0032 mainLayout->addWidget(mAdministratorWidget); 0033 0034 auto button = new QDialogButtonBox(QDialogButtonBox::Close, this); 0035 button->setObjectName(QStringLiteral("button")); 0036 mainLayout->addWidget(button); 0037 connect(button, &QDialogButtonBox::rejected, this, &AdministratorDialog::reject); 0038 connect(button, &QDialogButtonBox::accepted, this, &AdministratorDialog::accept); 0039 0040 readConfig(); 0041 } 0042 0043 AdministratorDialog::~AdministratorDialog() 0044 { 0045 writeConfig(); 0046 } 0047 0048 void AdministratorDialog::initialize() 0049 { 0050 mAdministratorWidget->updateUiFromPermission(); 0051 mAdministratorWidget->initialize(); 0052 } 0053 0054 void AdministratorDialog::readConfig() 0055 { 0056 create(); // ensure a window is created 0057 windowHandle()->resize(QSize(400, 300)); 0058 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myAdministratorDialogGroupName)); 0059 KWindowConfig::restoreWindowSize(windowHandle(), group); 0060 resize(windowHandle()->size()); // workaround for QTBUG-40584 0061 } 0062 0063 void AdministratorDialog::writeConfig() 0064 { 0065 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myAdministratorDialogGroupName)); 0066 KWindowConfig::saveWindowSize(windowHandle(), group); 0067 } 0068 0069 #include "moc_administratordialog.cpp"