File indexing completed on 2024-05-19 05:04:01
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 "channelinfodialog.h" 0008 #include "channelinfowidget.h" 0009 #include "room.h" 0010 0011 #include <KConfigGroup> 0012 #include <KLocalizedString> 0013 #include <KSharedConfig> 0014 #include <KWindowConfig> 0015 #include <QDialogButtonBox> 0016 #include <QPushButton> 0017 #include <QVBoxLayout> 0018 #include <QWindow> 0019 0020 namespace 0021 { 0022 static const char myConfigChannelInfoDialogGroupName[] = "ChannelInfoDialog"; 0023 } 0024 0025 ChannelInfoDialog::ChannelInfoDialog(Room *room, RocketChatAccount *account, QWidget *parent) 0026 : QDialog(parent) 0027 , mChannelInfoWidget(new ChannelInfoWidget(room, account, this)) 0028 , mButtonBox(new QDialogButtonBox(this)) 0029 { 0030 setWindowTitle(i18nc("@title:window", "Channel Info")); 0031 auto mainLayout = new QVBoxLayout(this); 0032 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0033 0034 mChannelInfoWidget->setObjectName(QStringLiteral("mChannelInfoWidget")); 0035 mainLayout->addWidget(mChannelInfoWidget); 0036 mChannelInfoWidget->updateUiFromPermission(); 0037 0038 connect(mButtonBox, &QDialogButtonBox::rejected, this, &ChannelInfoDialog::reject); 0039 connect(mButtonBox, &QDialogButtonBox::accepted, this, &ChannelInfoDialog::accept); 0040 mainLayout->addWidget(mButtonBox); 0041 connect(mChannelInfoWidget, &ChannelInfoWidget::channelDeleted, this, &ChannelInfoDialog::close); 0042 connect(mChannelInfoWidget, &ChannelInfoWidget::fnameChanged, this, &ChannelInfoDialog::slotFnameChanged); 0043 connect(mChannelInfoWidget, &ChannelInfoWidget::roomNameValid, this, &ChannelInfoDialog::slotRoomNameValid); 0044 0045 mButtonBox->setStandardButtons(room->canBeModify() ? QDialogButtonBox::Ok | QDialogButtonBox::Cancel : QDialogButtonBox::Close); 0046 mOkButton = mButtonBox->button(QDialogButtonBox::Ok); 0047 mIsATeam = room->teamInfo().mainTeam(); 0048 slotFnameChanged(room->displayFName()); 0049 readConfig(); 0050 } 0051 0052 ChannelInfoDialog::~ChannelInfoDialog() 0053 { 0054 writeConfig(); 0055 } 0056 0057 RocketChatRestApi::SaveRoomSettingsJob::SaveRoomSettingsInfo ChannelInfoDialog::saveRoomSettingsInfo() const 0058 { 0059 return mChannelInfoWidget->saveRoomSettingsInfo(); 0060 } 0061 0062 void ChannelInfoDialog::slotFnameChanged(const QString &fname) 0063 { 0064 setWindowTitle(mIsATeam ? i18nc("@title:window", "Team Info about \'%1\'", fname) : i18nc("@title:window", "Channel Info about \'%1\'", fname)); 0065 } 0066 0067 void ChannelInfoDialog::slotRoomNameValid(bool state) 0068 { 0069 Q_ASSERT(mOkButton); 0070 mOkButton->setEnabled(state); 0071 } 0072 0073 void ChannelInfoDialog::readConfig() 0074 { 0075 create(); // ensure a window is created 0076 windowHandle()->resize(QSize(600, 400)); 0077 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigChannelInfoDialogGroupName)); 0078 KWindowConfig::restoreWindowSize(windowHandle(), group); 0079 resize(windowHandle()->size()); // workaround for QTBUG-40584 0080 } 0081 0082 void ChannelInfoDialog::writeConfig() 0083 { 0084 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigChannelInfoDialogGroupName)); 0085 KWindowConfig::saveWindowSize(windowHandle(), group); 0086 } 0087 0088 #include "moc_channelinfodialog.cpp"