File indexing completed on 2024-12-22 04:45:37

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "moderationmessageswidget.h"
0008 #include "model/commonmessagefilterproxymodel.h"
0009 #include "rocketchataccount.h"
0010 #include "room/messagelistview.h"
0011 #include <KLocalizedString>
0012 #include <QLabel>
0013 #include <QVBoxLayout>
0014 
0015 #include "config-ruqola.h"
0016 
0017 #if HAVE_TEXT_TO_SPEECH
0018 #include <TextEditTextToSpeech/TextToSpeechContainerWidget>
0019 #endif
0020 
0021 ModerationMessagesWidget::ModerationMessagesWidget(RocketChatAccount *account, QWidget *parent)
0022     : QWidget(parent)
0023     , mSearchLabel(new QLabel(this))
0024     , mResultListWidget(new MessageListView(account, MessageListView::Mode::Moderation, this))
0025     , mCurrentRocketChatAccount(account)
0026 #if HAVE_TEXT_TO_SPEECH
0027     , mTextToSpeechWidget(new TextEditTextToSpeech::TextToSpeechContainerWidget(this))
0028 #endif
0029 {
0030     auto mainLayout = new QVBoxLayout(this);
0031     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0032     mainLayout->setContentsMargins({});
0033 
0034 #if HAVE_TEXT_TO_SPEECH
0035     mTextToSpeechWidget->setObjectName(QStringLiteral("mTextToSpeechWidget"));
0036     mainLayout->addWidget(mTextToSpeechWidget);
0037     connect(mResultListWidget, &MessageListView::textToSpeech, mTextToSpeechWidget, &TextEditTextToSpeech::TextToSpeechContainerWidget::say);
0038 #endif
0039 
0040     mResultListWidget->setObjectName(QStringLiteral("mResultListWidget"));
0041     mainLayout->addWidget(mResultListWidget);
0042     connect(mResultListWidget, &MessageListView::goToMessageRequested, this, &ModerationMessagesWidget::goToMessageRequested);
0043 }
0044 
0045 ModerationMessagesWidget::~ModerationMessagesWidget()
0046 {
0047     if (mCurrentRocketChatAccount) {
0048         mCurrentRocketChatAccount->clearSearchModel();
0049     }
0050 }
0051 
0052 void ModerationMessagesWidget::updateLabel()
0053 {
0054     if (mModel->loadCommonMessagesInProgress()) {
0055         mSearchLabel->setText(i18n("Loading..."));
0056     } else {
0057         mSearchLabel->setText(mModel->rowCount() == 0 ? i18n("No Message found") : displayShowSearch());
0058     }
0059 }
0060 
0061 QString ModerationMessagesWidget::displayShowSearch() const
0062 {
0063     const QString displayMessageStr = i18np("%1 Message in room", "%1 Messages in room", mModel->rowCount());
0064     return displayMessageStr;
0065 }
0066 
0067 void ModerationMessagesWidget::setModel(CommonMessageFilterProxyModel *model)
0068 {
0069     mResultListWidget->setModel(model);
0070     mModel = model;
0071     connect(mModel, &CommonMessageFilterProxyModel::stringNotFoundChanged, this, &ModerationMessagesWidget::updateLabel);
0072     connect(mModel, &CommonMessageFilterProxyModel::loadingInProgressChanged, this, &ModerationMessagesWidget::updateLabel);
0073     updateLabel();
0074 }
0075 
0076 #include "moc_moderationmessageswidget.cpp"