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

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 "myaccountconfiguredialog.h"
0008 #include "myaccountconfigurewidget.h"
0009 
0010 #include <KConfigGroup>
0011 #include <KLocalizedString>
0012 #include <KSharedConfig>
0013 #include <KWindowConfig>
0014 #include <QDialogButtonBox>
0015 #include <QVBoxLayout>
0016 #include <QWindow>
0017 namespace
0018 {
0019 const char myMyAccountConfigureDialogConfigGroupName[] = "RegisterUserDialog";
0020 }
0021 
0022 MyAccountConfigureDialog::MyAccountConfigureDialog(RocketChatAccount *account, QWidget *parent)
0023     : QDialog(parent)
0024     , mMyAccountConfigWidget(new MyAccountConfigureWidget(account, this))
0025 {
0026     setWindowTitle(i18nc("@title:window", "Configure my Account"));
0027     auto mainLayout = new QVBoxLayout(this);
0028     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0029 
0030     mMyAccountConfigWidget->setObjectName(QStringLiteral("mMyAccountConfigWidget"));
0031     mainLayout->addWidget(mMyAccountConfigWidget);
0032 
0033     auto button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0034     button->setObjectName(QStringLiteral("button"));
0035     mainLayout->addWidget(button);
0036     connect(button, &QDialogButtonBox::rejected, this, &MyAccountConfigureDialog::reject);
0037     connect(button, &QDialogButtonBox::accepted, this, &MyAccountConfigureDialog::slotAccept);
0038 
0039     readConfig();
0040 }
0041 
0042 MyAccountConfigureDialog::~MyAccountConfigureDialog()
0043 {
0044     writeConfig();
0045 }
0046 
0047 void MyAccountConfigureDialog::initialize()
0048 {
0049     mMyAccountConfigWidget->initialize();
0050     mMyAccountConfigWidget->load();
0051 }
0052 
0053 void MyAccountConfigureDialog::slotAccept()
0054 {
0055     mMyAccountConfigWidget->save();
0056     accept();
0057 }
0058 
0059 void MyAccountConfigureDialog::readConfig()
0060 {
0061     create(); // ensure a window is created
0062     windowHandle()->resize(QSize(400, 300));
0063     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myMyAccountConfigureDialogConfigGroupName));
0064     KWindowConfig::restoreWindowSize(windowHandle(), group);
0065     resize(windowHandle()->size()); // workaround for QTBUG-40584
0066 }
0067 
0068 void MyAccountConfigureDialog::writeConfig()
0069 {
0070     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myMyAccountConfigureDialogConfigGroupName));
0071     KWindowConfig::saveWindowSize(windowHandle(), group);
0072 }
0073 
0074 #include "moc_myaccountconfiguredialog.cpp"