File indexing completed on 2024-12-01 04:36:48
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 "showdiscussionswidget.h" 0008 #include "discussionlistview.h" 0009 #include "model/discussionsfilterproxymodel.h" 0010 #include "rocketchataccount.h" 0011 #include <KLineEditEventHandler> 0012 #include <KLocalizedString> 0013 #include <QLabel> 0014 #include <QLineEdit> 0015 #include <QVBoxLayout> 0016 0017 #include "config-ruqola.h" 0018 0019 #if HAVE_TEXT_TO_SPEECH 0020 #include <TextEditTextToSpeech/TextToSpeechContainerWidget> 0021 #endif 0022 0023 ShowDiscussionsWidget::ShowDiscussionsWidget(RocketChatAccount *account, QWidget *parent) 0024 : QWidget(parent) 0025 , mSearchDiscussionLineEdit(new QLineEdit(this)) 0026 , mDiscussionInfoLabel(new QLabel(this)) 0027 , mListDiscussionsListView(new DiscussionListView(account, this)) 0028 #if HAVE_TEXT_TO_SPEECH 0029 , mTextToSpeechWidget(new TextEditTextToSpeech::TextToSpeechContainerWidget(this)) 0030 #endif 0031 { 0032 auto mainLayout = new QVBoxLayout(this); 0033 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0034 mainLayout->setContentsMargins({}); 0035 0036 mSearchDiscussionLineEdit->setObjectName(QStringLiteral("mSearchDiscussionLineEdit")); 0037 mSearchDiscussionLineEdit->setClearButtonEnabled(true); 0038 KLineEditEventHandler::catchReturnKey(mSearchDiscussionLineEdit); 0039 mSearchDiscussionLineEdit->setPlaceholderText(i18n("Search discussion...")); 0040 connect(mSearchDiscussionLineEdit, &QLineEdit::textChanged, this, &ShowDiscussionsWidget::slotSearchMessageTextChanged); 0041 mainLayout->addWidget(mSearchDiscussionLineEdit); 0042 0043 mDiscussionInfoLabel->setObjectName(QStringLiteral("mInfo")); 0044 mDiscussionInfoLabel->setTextFormat(Qt::RichText); 0045 mainLayout->addWidget(mDiscussionInfoLabel); 0046 QFont labFont = mDiscussionInfoLabel->font(); 0047 labFont.setBold(true); 0048 mDiscussionInfoLabel->setFont(labFont); 0049 connect(mDiscussionInfoLabel, &QLabel::linkActivated, this, &ShowDiscussionsWidget::loadMoreDiscussion); 0050 0051 #if HAVE_TEXT_TO_SPEECH 0052 mTextToSpeechWidget->setObjectName(QStringLiteral("mTextToSpeechWidget")); 0053 mainLayout->addWidget(mTextToSpeechWidget); 0054 connect(mListDiscussionsListView, &DiscussionListView::textToSpeech, mTextToSpeechWidget, &TextEditTextToSpeech::TextToSpeechContainerWidget::say); 0055 #endif 0056 0057 mListDiscussionsListView->setObjectName(QStringLiteral("mListDiscussions")); 0058 mainLayout->addWidget(mListDiscussionsListView); 0059 } 0060 0061 ShowDiscussionsWidget::~ShowDiscussionsWidget() 0062 { 0063 // Don't keep in memory list of messages 0064 if (mDiscussionModel) { 0065 mDiscussionModel->clear(); 0066 } 0067 } 0068 0069 void ShowDiscussionsWidget::slotSearchMessageTextChanged(const QString &str) 0070 { 0071 mListDiscussionsListView->setSearchText(str); 0072 mDiscussionModel->setFilterString(str); 0073 updateLabel(); 0074 } 0075 0076 void ShowDiscussionsWidget::setModel(DiscussionsFilterProxyModel *model) 0077 { 0078 mListDiscussionsListView->setModel(model); 0079 mDiscussionModel = model; 0080 connect(mDiscussionModel, &DiscussionsFilterProxyModel::hasFullListChanged, this, &ShowDiscussionsWidget::updateLabel); 0081 connect(mDiscussionModel, &DiscussionsFilterProxyModel::loadingInProgressChanged, this, &ShowDiscussionsWidget::updateLabel); 0082 updateLabel(); 0083 } 0084 0085 void ShowDiscussionsWidget::updateLabel() 0086 { 0087 if (mDiscussionModel->loadMoreDiscussionsInProgress()) { 0088 mDiscussionInfoLabel->setText(i18n("Loading...")); 0089 } else { 0090 mDiscussionInfoLabel->setText(mDiscussionModel->rowCount() == 0 ? i18n("No Discussion found") : displayShowDiscussionInRoom()); 0091 } 0092 } 0093 0094 QString ShowDiscussionsWidget::displayShowDiscussionInRoom() const 0095 { 0096 QString displayMessageStr = 0097 i18np("%1 Discussion in room (Total: %2)", "%1 Discussions in room (Total: %2)", mDiscussionModel->rowCount(), mDiscussionModel->total()); 0098 if (!mDiscussionModel->hasFullList()) { 0099 displayMessageStr += QStringLiteral(" <a href=\"loadmoreelement\">%1</a>").arg(i18n("(Click here for Loading more...)")); 0100 } 0101 return displayMessageStr; 0102 } 0103 0104 #include "moc_showdiscussionswidget.cpp"