File indexing completed on 2024-12-22 04:45:36
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "moderationmessagesdialog.h" 0008 #include "moderationmessageswidget.h" 0009 #include "rocketchataccount.h" 0010 0011 #include <KConfigGroup> 0012 #include <KLocalizedString> 0013 #include <KSharedConfig> 0014 #include <KWindowConfig> 0015 #include <QDialogButtonBox> 0016 #include <QVBoxLayout> 0017 #include <QWindow> 0018 0019 namespace 0020 { 0021 static const char myModerationMessagesDialogGroupName[] = "ModerationMessagesDialog"; 0022 } 0023 ModerationMessagesDialog::ModerationMessagesDialog(RocketChatAccount *account, QWidget *parent) 0024 : QDialog(parent) 0025 , mModerationMessagesWidget(new ModerationMessagesWidget(account, this)) 0026 { 0027 setWindowTitle(i18nc("@title:window", "Show Moderation Messages")); 0028 auto mainLayout = new QVBoxLayout(this); 0029 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0030 0031 mModerationMessagesWidget->setObjectName(QStringLiteral("mModerationMessagesWidget")); 0032 mainLayout->addWidget(mModerationMessagesWidget); 0033 connect(mModerationMessagesWidget, &ModerationMessagesWidget::goToMessageRequested, this, &ModerationMessagesDialog::goToMessageRequested); 0034 0035 auto button = new QDialogButtonBox(QDialogButtonBox::Close, this); 0036 button->setObjectName(QStringLiteral("button")); 0037 mainLayout->addWidget(button); 0038 connect(button, &QDialogButtonBox::rejected, this, &ModerationMessagesDialog::reject); 0039 readConfig(); 0040 } 0041 0042 ModerationMessagesDialog::~ModerationMessagesDialog() 0043 { 0044 writeConfig(); 0045 } 0046 0047 void ModerationMessagesDialog::readConfig() 0048 { 0049 create(); // ensure a window is created 0050 windowHandle()->resize(QSize(800, 600)); 0051 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myModerationMessagesDialogGroupName)); 0052 KWindowConfig::restoreWindowSize(windowHandle(), group); 0053 resize(windowHandle()->size()); // workaround for QTBUG-40584 0054 } 0055 0056 void ModerationMessagesDialog::writeConfig() 0057 { 0058 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myModerationMessagesDialogGroupName)); 0059 KWindowConfig::saveWindowSize(windowHandle(), group); 0060 } 0061 0062 void ModerationMessagesDialog::setModel(CommonMessageFilterProxyModel *model) 0063 { 0064 mModerationMessagesWidget->setModel(model); 0065 } 0066 0067 #include "moc_moderationmessagesdialog.cpp"