File indexing completed on 2024-05-12 16:27:13

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 "createnewchannelwidget.h"
0008 #include "channelnamevalidlineedit.h"
0009 #include "channelnamevalidlinewidget.h"
0010 #include "misc/adduserswidget.h"
0011 #include "misc/lineeditcatchreturnkey.h"
0012 #include <KAuthorized>
0013 #include <KLocalizedString>
0014 #include <QCheckBox>
0015 #include <QFormLayout>
0016 #include <QLineEdit>
0017 
0018 CreateNewChannelWidget::CreateNewChannelWidget(RocketChatAccount *account, QWidget *parent)
0019     : QWidget(parent)
0020     , mChannelName(new ChannelNameValidLineWidget(account, this))
0021     , mUsers(new AddUsersWidget(account, this))
0022     , mReadOnly(new QCheckBox(this))
0023     , mBroadcast(new QCheckBox(this))
0024     , mPrivate(new QCheckBox(this))
0025     , mEncryptedRoom(new QCheckBox(this))
0026     , mTopicLineEdit(new QLineEdit(this))
0027     , mMainLayout(new QFormLayout(this))
0028 {
0029     mMainLayout->setObjectName(QStringLiteral("mainLayout"));
0030     mMainLayout->setContentsMargins({});
0031 
0032     mChannelName->setObjectName(QStringLiteral("mChannelName"));
0033     mMainLayout->addRow(i18n("Name:"), mChannelName);
0034 
0035     mTopicLineEdit->setObjectName(QStringLiteral("mTopicLineEdit"));
0036     mMainLayout->addRow(i18n("Topic:"), mTopicLineEdit);
0037     new LineEditCatchReturnKey(mTopicLineEdit, this);
0038 
0039     mUsers->setObjectName(QStringLiteral("mUsers"));
0040     mUsers->setPlaceholderText(i18n("Invite users..."));
0041     mMainLayout->addRow(i18n("Users:"), mUsers);
0042 
0043     mReadOnly->setObjectName(QStringLiteral("mReadOnly"));
0044     mReadOnly->setChecked(false);
0045     mReadOnly->setToolTip(i18n("All users in this team can write messages"));
0046     mMainLayout->addRow(i18n("Read-Only:"), mReadOnly);
0047 
0048     mBroadcast->setObjectName(QStringLiteral("mBroadcast"));
0049     mBroadcast->setChecked(false);
0050     mBroadcast->setToolTip(i18n("Only authorized users can write new messages, but the other users will be able to reply"));
0051     mMainLayout->addRow(i18n("Broadcast:"), mBroadcast);
0052 
0053     mPrivate->setObjectName(QStringLiteral("mPrivate"));
0054     mPrivate->setChecked(false);
0055     mPrivate->setToolTip(i18n("Only invited people can join"));
0056 
0057     mMainLayout->addRow(i18n("Private Room:"), mPrivate);
0058 
0059     mEncryptedRoom->setObjectName(QStringLiteral("mEncryptedRoom"));
0060     mEncryptedRoom->setChecked(false);
0061     mMainLayout->addRow(i18n("Encrypted Room:"), mEncryptedRoom);
0062 
0063     connect(mChannelName, &ChannelNameValidLineWidget::channelIsValid, this, &CreateNewChannelWidget::slotChangeOkButtonEnabled);
0064 }
0065 
0066 CreateNewChannelWidget::~CreateNewChannelWidget() = default;
0067 
0068 void CreateNewChannelWidget::slotChangeOkButtonEnabled(bool state)
0069 {
0070     Q_EMIT updateOkButton(/*!mChannelName->text().trimmed().isEmpty()*/ state);
0071 }
0072 
0073 QString CreateNewChannelWidget::channelName() const
0074 {
0075     return mChannelName->text();
0076 }
0077 
0078 QStringList CreateNewChannelWidget::members(bool userId) const
0079 {
0080     if (userId) {
0081         return mUsers->userIds();
0082     } else {
0083         return mUsers->userNames();
0084     }
0085 }
0086 
0087 bool CreateNewChannelWidget::readOnly() const
0088 {
0089     return mReadOnly->isChecked();
0090 }
0091 
0092 bool CreateNewChannelWidget::broadCast() const
0093 {
0094     return mBroadcast->isChecked();
0095 }
0096 
0097 bool CreateNewChannelWidget::privateChannel() const
0098 {
0099     return mPrivate->isChecked();
0100 }
0101 
0102 bool CreateNewChannelWidget::encryptedRoom() const
0103 {
0104     return mEncryptedRoom->isChecked();
0105 }
0106 
0107 QString CreateNewChannelWidget::topic() const
0108 {
0109     return mTopicLineEdit->text();
0110 }
0111 
0112 void CreateNewChannelWidget::setFeatures(CreateNewChannelWidget::Features features)
0113 {
0114     bool visible = features & CreateNewChannelWidget::Feature::BroadCast;
0115 
0116     mBroadcast->setVisible(visible);
0117     mMainLayout->labelForField(mBroadcast)->setVisible(visible);
0118 
0119     visible = features & CreateNewChannelWidget::Feature::Encrypted;
0120 
0121     mEncryptedRoom->setVisible(visible);
0122     mMainLayout->labelForField(mEncryptedRoom)->setVisible(visible);
0123 }
0124 
0125 #include "moc_createnewchannelwidget.cpp"