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 "teamconverttochanneldialog.h"
0008 #include "teamconverttochannelwidget.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 myTeamConvertToChannelDialogConfigGroupName[] = "TeamConvertToChannelDialog";
0019 }
0020 TeamConvertToChannelDialog::TeamConvertToChannelDialog(QWidget *parent)
0021     : QDialog(parent)
0022     , mTeamConvertToChannelWidget(new TeamConvertToChannelWidget(this))
0023 {
0024     setWindowTitle(i18nc("@title:window", "Convert Team to Channel"));
0025     auto mainLayout = new QVBoxLayout(this);
0026     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0027 
0028     mTeamConvertToChannelWidget->setObjectName(QStringLiteral("mTeamConvertToChannelWidget"));
0029     mainLayout->addWidget(mTeamConvertToChannelWidget);
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, &TeamConvertToChannelDialog::reject);
0035     connect(button, &QDialogButtonBox::accepted, this, &TeamConvertToChannelDialog::accept);
0036     readConfig();
0037 }
0038 
0039 TeamConvertToChannelDialog::~TeamConvertToChannelDialog()
0040 {
0041     writeConfig();
0042 }
0043 
0044 QStringList TeamConvertToChannelDialog::roomIdsToDelete() const
0045 {
0046     return mTeamConvertToChannelWidget->roomIdsToDelete();
0047 }
0048 
0049 void TeamConvertToChannelDialog::setTeamRooms(const QVector<TeamRoom> &rooms)
0050 {
0051     mTeamConvertToChannelWidget->setTeamRooms(rooms);
0052 }
0053 
0054 void TeamConvertToChannelDialog::setTeamName(const QString &name)
0055 {
0056     setWindowTitle(i18nc("@title:window", "Convert Team \'%1\' to Channel", name));
0057 }
0058 
0059 void TeamConvertToChannelDialog::readConfig()
0060 {
0061     create(); // ensure a window is created
0062     windowHandle()->resize(QSize(400, 300));
0063     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myTeamConvertToChannelDialogConfigGroupName));
0064     KWindowConfig::restoreWindowSize(windowHandle(), group);
0065     resize(windowHandle()->size()); // workaround for QTBUG-40584
0066 }
0067 
0068 void TeamConvertToChannelDialog::writeConfig()
0069 {
0070     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myTeamConvertToChannelDialogConfigGroupName));
0071     KWindowConfig::saveWindowSize(windowHandle(), group);
0072 }
0073 
0074 #include "moc_teamconverttochanneldialog.cpp"