File indexing completed on 2024-05-12 16:27:15
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 "showattachmentdialog.h" 0008 #include "rocketchataccount.h" 0009 #include "ruqolawidgets_debug.h" 0010 #include "showattachmentwidget.h" 0011 0012 #include <KConfigGroup> 0013 #include <KLocalizedString> 0014 #include <KSharedConfig> 0015 #include <KWindowConfig> 0016 #include <QDialogButtonBox> 0017 #include <QVBoxLayout> 0018 #include <QWindow> 0019 namespace 0020 { 0021 static const char myShowAttachmentDialogGroupName[] = "ShowAttachmentDialog"; 0022 } 0023 0024 ShowAttachmentDialog::ShowAttachmentDialog(RocketChatAccount *account, QWidget *parent) 0025 : QDialog(parent) 0026 , mShowAttachmentWidget(new ShowAttachmentWidget(account, this)) 0027 , mRocketChatAccount(account) 0028 { 0029 setWindowTitle(i18nc("@title:window", "Show Attachments - %1", account ? account->accountName() : QStringLiteral("account"))); 0030 auto mainLayout = new QVBoxLayout(this); 0031 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0032 setAttribute(Qt::WA_DeleteOnClose); 0033 0034 mShowAttachmentWidget->setObjectName(QStringLiteral("mShowAttachmentWidget")); 0035 mainLayout->addWidget(mShowAttachmentWidget); 0036 0037 auto button = new QDialogButtonBox(QDialogButtonBox::Close, this); 0038 button->setObjectName(QStringLiteral("button")); 0039 mainLayout->addWidget(button); 0040 connect(button, &QDialogButtonBox::rejected, this, &ShowAttachmentDialog::reject); 0041 connect(mShowAttachmentWidget, &ShowAttachmentWidget::loadMoreFileAttachment, this, &ShowAttachmentDialog::slotLoadMoreAttachment); 0042 connect(mShowAttachmentWidget, &ShowAttachmentWidget::deleteAttachment, this, &ShowAttachmentDialog::slotDeleteAttachment); 0043 readConfig(); 0044 } 0045 0046 ShowAttachmentDialog::~ShowAttachmentDialog() 0047 { 0048 writeConfig(); 0049 } 0050 0051 void ShowAttachmentDialog::slotDeleteAttachment(const QString &fileId) 0052 { 0053 mRocketChatAccount->deleteFileMessage(mRoomId, fileId, mRoomType); 0054 } 0055 0056 void ShowAttachmentDialog::setModel(FilesForRoomFilterProxyModel *model) 0057 { 0058 mShowAttachmentWidget->setModel(model); 0059 } 0060 0061 void ShowAttachmentDialog::setRoomId(const QString &roomId) 0062 { 0063 mRoomId = roomId; 0064 } 0065 0066 QString ShowAttachmentDialog::roomId() const 0067 { 0068 return mRoomId; 0069 } 0070 0071 void ShowAttachmentDialog::readConfig() 0072 { 0073 create(); // ensure a window is created 0074 windowHandle()->resize(QSize(800, 600)); 0075 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myShowAttachmentDialogGroupName)); 0076 KWindowConfig::restoreWindowSize(windowHandle(), group); 0077 resize(windowHandle()->size()); // workaround for QTBUG-40584 0078 } 0079 0080 void ShowAttachmentDialog::writeConfig() 0081 { 0082 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myShowAttachmentDialogGroupName)); 0083 KWindowConfig::saveWindowSize(windowHandle(), group); 0084 } 0085 0086 void ShowAttachmentDialog::slotLoadMoreAttachment() 0087 { 0088 if (mRoomId.isEmpty()) { 0089 qCWarning(RUQOLAWIDGETS_LOG) << "RoomId is empty. It's a bug"; 0090 return; 0091 } 0092 mRocketChatAccount->loadMoreFileAttachments(mRoomId, mRoomType); 0093 } 0094 0095 Room::RoomType ShowAttachmentDialog::roomType() const 0096 { 0097 return mRoomType; 0098 } 0099 0100 void ShowAttachmentDialog::setRoomType(Room::RoomType roomType) 0101 { 0102 mRoomType = roomType; 0103 } 0104 0105 #include "moc_showattachmentdialog.cpp"