File indexing completed on 2024-05-19 16:00:10

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 "createnewchanneldialog.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 
0018 namespace
0019 {
0020 static const char myCreateNewChannelDialogGroupName[] = "CreateNewChannelDialog";
0021 }
0022 CreateNewChannelDialog::CreateNewChannelDialog(RocketChatAccount *account, QWidget *parent)
0023     : QDialog(parent)
0024     , mCreateNewChannelWidget(new CreateNewChannelWidget(account, this))
0025 {
0026     setWindowTitle(i18nc("@title:window", "Create Channel"));
0027     auto mainLayout = new QVBoxLayout(this);
0028     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0029 
0030     mCreateNewChannelWidget->setObjectName(QStringLiteral("mCreateNewChannelWidget"));
0031     mainLayout->addWidget(mCreateNewChannelWidget);
0032 
0033     auto button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0034     button->setObjectName(QStringLiteral("button"));
0035     mainLayout->addWidget(button);
0036     connect(button, &QDialogButtonBox::accepted, this, &CreateNewChannelDialog::accept);
0037     connect(button, &QDialogButtonBox::rejected, this, &CreateNewChannelDialog::reject);
0038     readConfig();
0039     mOkButton = button->button(QDialogButtonBox::Ok);
0040     mOkButton->setEnabled(false);
0041     connect(mCreateNewChannelWidget, &CreateNewChannelWidget::updateOkButton, mOkButton, &QPushButton::setEnabled);
0042 }
0043 
0044 CreateNewChannelDialog::~CreateNewChannelDialog()
0045 {
0046     writeConfig();
0047 }
0048 
0049 RocketChatRestApi::CreateChannelTeamInfo CreateNewChannelDialog::channelInfo(bool userMemberUserId) const
0050 {
0051     RocketChatRestApi::CreateChannelTeamInfo info;
0052     info.members = mCreateNewChannelWidget->members(userMemberUserId);
0053     info.name = mCreateNewChannelWidget->channelName();
0054     info.readOnly = mCreateNewChannelWidget->readOnly();
0055     info.broadcast = mCreateNewChannelWidget->broadCast();
0056     info.encrypted = mCreateNewChannelWidget->encryptedRoom();
0057     info.description = mCreateNewChannelWidget->topic();
0058     info.privateChannel = mCreateNewChannelWidget->privateChannel();
0059     return info;
0060 }
0061 
0062 void CreateNewChannelDialog::readConfig()
0063 {
0064     create(); // ensure a window is created
0065     windowHandle()->resize(QSize(800, 600));
0066     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myCreateNewChannelDialogGroupName));
0067     KWindowConfig::restoreWindowSize(windowHandle(), group);
0068     resize(windowHandle()->size()); // workaround for QTBUG-40584
0069 }
0070 
0071 void CreateNewChannelDialog::writeConfig()
0072 {
0073     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myCreateNewChannelDialogGroupName));
0074     KWindowConfig::saveWindowSize(windowHandle(), group);
0075 }
0076 
0077 void CreateNewChannelDialog::setFeatures(CreateNewChannelWidget::Features features)
0078 {
0079     mCreateNewChannelWidget->setFeatures(features);
0080 }
0081 
0082 #include "moc_createnewchanneldialog.cpp"