File indexing completed on 2024-12-22 04:45:37
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 "administratoroauthcreatedialog.h" 0008 0009 #include <KConfigGroup> 0010 #include <KLocalizedString> 0011 #include <KSharedConfig> 0012 #include <KWindowConfig> 0013 #include <QDialogButtonBox> 0014 #include <QPushButton> 0015 #include <QVBoxLayout> 0016 #include <QWindow> 0017 namespace 0018 { 0019 static const char myConfigAdministratorOauthCreateDialogGroupName[] = "AdministratorOauthCreateDialog"; 0020 } 0021 AdministratorOauthCreateDialog::AdministratorOauthCreateDialog(QWidget *parent) 0022 : QDialog(parent) 0023 , mCreateWidget(new AdministratorOauthCreateWidget(this)) 0024 { 0025 setWindowTitle(i18nc("@title:window", "Add Oauth Apps")); 0026 auto mainLayout = new QVBoxLayout(this); 0027 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0028 0029 mCreateWidget->setObjectName(QStringLiteral("mCreateWidget")); 0030 mainLayout->addWidget(mCreateWidget); 0031 0032 auto button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0033 button->setObjectName(QStringLiteral("button")); 0034 mainLayout->addWidget(button); 0035 connect(button, &QDialogButtonBox::rejected, this, &AdministratorOauthCreateDialog::reject); 0036 connect(button, &QDialogButtonBox::accepted, this, &AdministratorOauthCreateDialog::accept); 0037 mOkButton = button->button(QDialogButtonBox::Ok); 0038 mOkButton->setObjectName(QStringLiteral("mOkButton")); 0039 mOkButton->setEnabled(false); 0040 connect(mCreateWidget, &AdministratorOauthCreateWidget::enableOkButton, mOkButton, &QPushButton::setEnabled); 0041 readConfig(); 0042 } 0043 0044 AdministratorOauthCreateDialog::~AdministratorOauthCreateDialog() 0045 { 0046 writeConfig(); 0047 } 0048 0049 AdministratorOauthCreateWidget::OauthCreateInfo AdministratorOauthCreateDialog::oauthInfo() const 0050 { 0051 return mCreateWidget->oauthInfo(); 0052 } 0053 0054 void AdministratorOauthCreateDialog::setOauthInfo(const AdministratorOauthCreateWidget::OauthCreateInfo &info) 0055 { 0056 mCreateWidget->setOauthInfo(info); 0057 } 0058 0059 void AdministratorOauthCreateDialog::readConfig() 0060 { 0061 create(); // ensure a window is created 0062 windowHandle()->resize(QSize(800, 300)); 0063 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigAdministratorOauthCreateDialogGroupName)); 0064 KWindowConfig::restoreWindowSize(windowHandle(), group); 0065 resize(windowHandle()->size()); // workaround for QTBUG-40584 0066 } 0067 0068 void AdministratorOauthCreateDialog::writeConfig() 0069 { 0070 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigAdministratorOauthCreateDialogGroupName)); 0071 KWindowConfig::saveWindowSize(windowHandle(), group); 0072 } 0073 0074 #include "moc_administratoroauthcreatedialog.cpp"