File indexing completed on 2025-01-19 10:48: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 "prunemessagesdialog.h" 0008 #include "prunemessageswidget.h" 0009 0010 #include <KConfigGroup> 0011 #include <KLocalizedString> 0012 #include <KSharedConfig> 0013 #include <KWindowConfig> 0014 #include <QDialogButtonBox> 0015 #include <QPushButton> 0016 #include <QVBoxLayout> 0017 #include <QWindow> 0018 0019 namespace 0020 { 0021 const char myPruneMessagesDialogConfigGroupName[] = "PruneMessagesDialog"; 0022 } 0023 0024 PruneMessagesDialog::PruneMessagesDialog(RocketChatAccount *account, QWidget *parent) 0025 : QDialog(parent) 0026 , mPruneMessageWidget(new PruneMessagesWidget(account, this)) 0027 { 0028 setWindowTitle(i18nc("@title:window", "Prune Messages")); 0029 auto mainLayout = new QVBoxLayout(this); 0030 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0031 0032 mPruneMessageWidget->setObjectName(QStringLiteral("mPruneMessageWidget")); 0033 mainLayout->addWidget(mPruneMessageWidget); 0034 0035 auto button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0036 button->setObjectName(QStringLiteral("button")); 0037 mainLayout->addWidget(button); 0038 connect(button, &QDialogButtonBox::rejected, this, &PruneMessagesDialog::reject); 0039 connect(button, &QDialogButtonBox::accepted, this, &PruneMessagesDialog::accept); 0040 0041 QPushButton *okButton = button->button(QDialogButtonBox::Ok); 0042 okButton->setText(i18n("Prune")); 0043 okButton->setEnabled(false); 0044 connect(mPruneMessageWidget, &PruneMessagesWidget::updateOkButton, okButton, &QPushButton::setEnabled); 0045 readConfig(); 0046 } 0047 0048 PruneMessagesDialog::~PruneMessagesDialog() 0049 { 0050 writeConfig(); 0051 } 0052 0053 RocketChatRestApi::RoomsCleanHistoryJob::CleanHistoryInfo PruneMessagesDialog::cleanHistoryInfo() const 0054 { 0055 return mPruneMessageWidget->cleanHistoryInfo(); 0056 } 0057 0058 void PruneMessagesDialog::setRoomName(const QString &roomName) 0059 { 0060 mPruneMessageWidget->setRoomName(roomName); 0061 } 0062 0063 void PruneMessagesDialog::readConfig() 0064 { 0065 create(); // ensure a window is created 0066 windowHandle()->resize(QSize(400, 300)); 0067 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myPruneMessagesDialogConfigGroupName)); 0068 KWindowConfig::restoreWindowSize(windowHandle(), group); 0069 resize(windowHandle()->size()); // workaround for QTBUG-40584 0070 } 0071 0072 void PruneMessagesDialog::writeConfig() 0073 { 0074 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myPruneMessagesDialogConfigGroupName)); 0075 KWindowConfig::saveWindowSize(windowHandle(), group); 0076 } 0077 0078 #include "moc_prunemessagesdialog.cpp"