Warning, file /network/ruqola/src/widgets/dialogs/channelinfowidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 "channelinfowidget.h"
0008 #include "channelinfoeditablewidget.h"
0009 #include "channelinforeadonlywidget.h"
0010 #include "channelrolesinfowidget.h"
0011 #include "rocketchataccount.h"
0012 #include "room.h"
0013 
0014 #include <QCheckBox>
0015 #include <QPushButton>
0016 #include <QStackedWidget>
0017 #include <QVBoxLayout>
0018 
0019 ChannelInfoWidget::ChannelInfoWidget(Room *room, RocketChatAccount *account, QWidget *parent)
0020     : QWidget(parent)
0021     , mStackedWidget(new QStackedWidget(this))
0022     , mChannelInfoEditableWidget(new ChannelInfoEditableWidget(room, account, this))
0023     , mChannelInfoReadOnlyWidget(new ChannelInfoReadOnlyWidget(account, this))
0024     , mChannelRolesInfoWidget(new ChannelRolesInfoWidget(this))
0025 {
0026     auto mainLayout = new QVBoxLayout(this);
0027     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0028     mainLayout->setContentsMargins({});
0029 
0030     mStackedWidget->setObjectName(QStringLiteral("mStackedWidget"));
0031     mainLayout->addWidget(mStackedWidget);
0032     mChannelInfoEditableWidget->setVisible(false);
0033     mChannelInfoReadOnlyWidget->setVisible(false);
0034     connect(mChannelInfoEditableWidget, &ChannelInfoEditableWidget::channelDeleted, this, &ChannelInfoWidget::channelDeleted);
0035     connect(mChannelInfoEditableWidget, &ChannelInfoEditableWidget::fnameChanged, this, &ChannelInfoWidget::fnameChanged);
0036     connect(mChannelInfoEditableWidget, &ChannelInfoEditableWidget::roomNameValid, this, &ChannelInfoWidget::roomNameValid);
0037     mainLayout->addWidget(mChannelRolesInfoWidget);
0038     mainLayout->addStretch(1);
0039     setRoom(room);
0040 }
0041 
0042 ChannelInfoWidget::~ChannelInfoWidget() = default;
0043 
0044 void ChannelInfoWidget::updateUiFromPermission()
0045 {
0046     mChannelInfoEditableWidget->updateUiFromPermission();
0047 }
0048 
0049 RocketChatRestApi::SaveRoomSettingsJob::SaveRoomSettingsInfo ChannelInfoWidget::saveRoomSettingsInfo() const
0050 {
0051     if (mRoom->canBeModify()) {
0052         return mChannelInfoEditableWidget->saveRoomSettingsInfo();
0053     }
0054     return {};
0055 }
0056 
0057 void ChannelInfoWidget::setRoom(Room *room)
0058 {
0059     mRoom = room;
0060     if (!mRoom) {
0061         return;
0062     }
0063     mChannelRolesInfoWidget->setRoom(room);
0064     auto *currentWidget = mStackedWidget->currentWidget();
0065     if (mRoom->canBeModify()) {
0066         if (currentWidget != mChannelInfoEditableWidget) {
0067             if (currentWidget) {
0068                 mStackedWidget->removeWidget(currentWidget);
0069             }
0070             mChannelInfoEditableWidget->setVisible(true);
0071             mChannelInfoReadOnlyWidget->setVisible(false);
0072             mStackedWidget->addWidget(mChannelInfoEditableWidget);
0073         }
0074 
0075         mStackedWidget->setCurrentWidget(mChannelInfoEditableWidget);
0076         mChannelInfoEditableWidget->updateEditableChannelInfo();
0077         mChannelInfoEditableWidget->updateRetentionValue();
0078         mChannelInfoEditableWidget->connectEditableWidget();
0079     } else {
0080         if (currentWidget != mChannelInfoReadOnlyWidget) {
0081             if (currentWidget) {
0082                 mStackedWidget->removeWidget(currentWidget);
0083             }
0084             mChannelInfoEditableWidget->setVisible(false);
0085             mChannelInfoReadOnlyWidget->setVisible(true);
0086             mStackedWidget->addWidget(mChannelInfoReadOnlyWidget);
0087         }
0088         mChannelInfoReadOnlyWidget->setRoom(mRoom);
0089         mStackedWidget->setCurrentWidget(mChannelInfoReadOnlyWidget);
0090     }
0091 }
0092 
0093 #include "moc_channelinfowidget.cpp"