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

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 "registeruserdialog.h"
0008 #include "registeruserwidget.h"
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 
0018 namespace
0019 {
0020 const char myRegisterUserDialogConfigGroupName[] = "RegisterUserDialog";
0021 }
0022 
0023 RegisterUserDialog::RegisterUserDialog(QWidget *parent)
0024     : QDialog(parent)
0025     , mRegisterUserWidget(new RegisterUserWidget(this))
0026 {
0027     setWindowTitle(i18nc("@title:window", "Register User"));
0028     auto mainLayout = new QVBoxLayout(this);
0029     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0030 
0031     mRegisterUserWidget->setObjectName(QStringLiteral("mRegisterUserWidget"));
0032     mainLayout->addWidget(mRegisterUserWidget);
0033 
0034     auto button = new QDialogButtonBox(QDialogButtonBox::Close, this);
0035     button->setObjectName(QStringLiteral("button"));
0036     mainLayout->addWidget(button);
0037     connect(button, &QDialogButtonBox::rejected, this, &RegisterUserDialog::reject);
0038     readConfig();
0039 }
0040 
0041 RegisterUserDialog::~RegisterUserDialog()
0042 {
0043     writeConfig();
0044 }
0045 
0046 void RegisterUserDialog::readConfig()
0047 {
0048     create(); // ensure a window is created
0049     windowHandle()->resize(QSize(400, 300));
0050     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myRegisterUserDialogConfigGroupName));
0051     KWindowConfig::restoreWindowSize(windowHandle(), group);
0052     resize(windowHandle()->size()); // workaround for QTBUG-40584
0053 }
0054 
0055 void RegisterUserDialog::writeConfig()
0056 {
0057     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myRegisterUserDialogConfigGroupName));
0058     KWindowConfig::saveWindowSize(windowHandle(), group);
0059 }
0060 
0061 RocketChatRestApi::RegisterUserJob::RegisterUserInfo RegisterUserDialog::registerUserInfo() const
0062 {
0063     return mRegisterUserWidget->registerUserInfo();
0064 }
0065 
0066 #include "moc_registeruserdialog.cpp"