File indexing completed on 2024-12-08 04:34:20
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 "showdiscussionsdialog.h" 0008 #include "rocketchataccount.h" 0009 #include "ruqolawidgets_debug.h" 0010 #include "showdiscussionswidget.h" 0011 0012 #include <QDialogButtonBox> 0013 #include <QVBoxLayout> 0014 #include <QWindow> 0015 0016 #include <KConfigGroup> 0017 #include <KLocalizedString> 0018 #include <KSharedConfig> 0019 #include <KWindowConfig> 0020 0021 namespace 0022 { 0023 static const char myShowDiscussionsDialogGroupName[] = "ShowDiscussionsDialog"; 0024 } 0025 ShowDiscussionsDialog::ShowDiscussionsDialog(RocketChatAccount *account, QWidget *parent) 0026 : QDialog(parent) 0027 , mShowDiscussionsWidget(new ShowDiscussionsWidget(account, this)) 0028 , mRocketChatAccount(account) 0029 { 0030 setWindowTitle(i18nc("@title:window", "Show Discussions - %1", account ? account->accountName() : QStringLiteral("account"))); 0031 auto mainLayout = new QVBoxLayout(this); 0032 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0033 0034 mShowDiscussionsWidget->setObjectName(QStringLiteral("mShowDiscussionsWidget")); 0035 mainLayout->addWidget(mShowDiscussionsWidget); 0036 0037 auto button = new QDialogButtonBox(QDialogButtonBox::Close, this); 0038 button->setObjectName(QStringLiteral("button")); 0039 mainLayout->addWidget(button); 0040 connect(button, &QDialogButtonBox::rejected, this, &ShowDiscussionsDialog::reject); 0041 connect(mShowDiscussionsWidget, &ShowDiscussionsWidget::loadMoreDiscussion, this, &ShowDiscussionsDialog::slotLoadMoreDiscussions); 0042 readConfig(); 0043 setAttribute(Qt::WA_DeleteOnClose); 0044 } 0045 0046 ShowDiscussionsDialog::~ShowDiscussionsDialog() 0047 { 0048 writeConfig(); 0049 } 0050 0051 void ShowDiscussionsDialog::readConfig() 0052 { 0053 create(); // ensure a window is created 0054 windowHandle()->resize(QSize(800, 600)); 0055 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myShowDiscussionsDialogGroupName)); 0056 KWindowConfig::restoreWindowSize(windowHandle(), group); 0057 resize(windowHandle()->size()); // workaround for QTBUG-40584 0058 } 0059 0060 void ShowDiscussionsDialog::writeConfig() 0061 { 0062 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myShowDiscussionsDialogGroupName)); 0063 KWindowConfig::saveWindowSize(windowHandle(), group); 0064 } 0065 0066 void ShowDiscussionsDialog::slotLoadMoreDiscussions() 0067 { 0068 if (mRoomId.isEmpty()) { 0069 qCWarning(RUQOLAWIDGETS_LOG) << "RoomId is empty. It's a bug"; 0070 return; 0071 } 0072 mRocketChatAccount->loadMoreDiscussions(mRoomId); 0073 } 0074 0075 void ShowDiscussionsDialog::setRoomId(const QString &roomId) 0076 { 0077 mRoomId = roomId; 0078 } 0079 0080 void ShowDiscussionsDialog::setModel(DiscussionsFilterProxyModel *model) 0081 { 0082 mShowDiscussionsWidget->setModel(model); 0083 } 0084 0085 #include "moc_showdiscussionsdialog.cpp"