File indexing completed on 2024-12-01 04:37:05

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "teamselectdeletedroomdialog.h"
0008 #include "teamselectdeletedroomwidget.h"
0009 #include <KConfigGroup>
0010 #include <KLocalizedString>
0011 #include <KSharedConfig>
0012 #include <KWindowConfig>
0013 #include <QDialogButtonBox>
0014 #include <QVBoxLayout>
0015 #include <QWindow>
0016 namespace
0017 {
0018 const char myTeamSelectDeletedRoomDialogConfigGroupName[] = "TeamSelectDeletedRoomDialog";
0019 }
0020 TeamSelectDeletedRoomDialog::TeamSelectDeletedRoomDialog(QWidget *parent)
0021     : QDialog(parent)
0022     , mTeamSelectDeletedRoomWidget(new TeamSelectDeletedRoomWidget(this))
0023 {
0024     setWindowTitle(i18nc("@title:window", "Delete Rooms"));
0025     auto mainLayout = new QVBoxLayout(this);
0026     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0027 
0028     mTeamSelectDeletedRoomWidget->setObjectName(QStringLiteral("mTeamSelectDeletedRoomWidget"));
0029     mainLayout->addWidget(mTeamSelectDeletedRoomWidget);
0030 
0031     auto button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0032     button->setObjectName(QStringLiteral("button"));
0033     mainLayout->addWidget(button);
0034     connect(button, &QDialogButtonBox::rejected, this, &TeamSelectDeletedRoomDialog::reject);
0035     connect(button, &QDialogButtonBox::accepted, this, &TeamSelectDeletedRoomDialog::accept);
0036     readConfig();
0037 }
0038 
0039 TeamSelectDeletedRoomDialog::~TeamSelectDeletedRoomDialog()
0040 {
0041     writeConfig();
0042 }
0043 
0044 void TeamSelectDeletedRoomDialog::setTeamRooms(const QVector<TeamRoom> &rooms)
0045 {
0046     mTeamSelectDeletedRoomWidget->setTeamRooms(rooms);
0047 }
0048 
0049 void TeamSelectDeletedRoomDialog::readConfig()
0050 {
0051     create(); // ensure a window is created
0052     windowHandle()->resize(QSize(400, 300));
0053     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myTeamSelectDeletedRoomDialogConfigGroupName));
0054     KWindowConfig::restoreWindowSize(windowHandle(), group);
0055     resize(windowHandle()->size()); // workaround for QTBUG-40584
0056 }
0057 
0058 void TeamSelectDeletedRoomDialog::writeConfig()
0059 {
0060     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myTeamSelectDeletedRoomDialogConfigGroupName));
0061     KWindowConfig::saveWindowSize(windowHandle(), group);
0062 }
0063 
0064 QStringList TeamSelectDeletedRoomDialog::roomsId() const
0065 {
0066     return mTeamSelectDeletedRoomWidget->roomsId();
0067 }
0068 
0069 #include "moc_teamselectdeletedroomdialog.cpp"