File indexing completed on 2024-05-19 05:04:05

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "searchmessagewithdelaylineedit.h"
0007 #include "rocketchataccount.h"
0008 #include <QCompleter>
0009 #include <QStringListModel>
0010 #define MAX_COMPLETION_ITEMS 20
0011 SearchMessageWithDelayLineEdit::SearchMessageWithDelayLineEdit(RocketChatAccount *account, QWidget *parent)
0012     : SearchWithDelayLineEdit(parent)
0013     , mCompleter(new QCompleter(this))
0014     , mCompleterListModel(new QStringListModel(this))
0015     , mCurrentRocketChatAccount(account)
0016 {
0017     mCompleter->setObjectName(QStringLiteral("mCompleter"));
0018     mCompleterListModel->setObjectName(QStringLiteral("mCompleterListModel"));
0019 
0020     mCompleter->setModel(mCompleterListModel);
0021     setCompleter(mCompleter);
0022 
0023     if (mCurrentRocketChatAccount) {
0024         const QStringList lst = mCurrentRocketChatAccount->searchListCompletion();
0025         mCompleterListModel->setStringList(lst);
0026     }
0027 }
0028 
0029 SearchMessageWithDelayLineEdit::~SearchMessageWithDelayLineEdit() = default;
0030 
0031 void SearchMessageWithDelayLineEdit::addCompletionItem(const QString &str)
0032 {
0033     mListCompetion.removeAll(str);
0034     mListCompetion.prepend(str);
0035     while (mListCompetion.size() > MAX_COMPLETION_ITEMS) {
0036         mListCompetion.removeLast();
0037     }
0038     mCompleterListModel->setStringList(mListCompetion);
0039     if (mCurrentRocketChatAccount) {
0040         mCurrentRocketChatAccount->setSearchListCompletion(mListCompetion);
0041     }
0042 }
0043 
0044 #include "moc_searchmessagewithdelaylineedit.cpp"