File indexing completed on 2024-02-18 15:43:51

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "channelusercompleter.h"
0010 #include "libruqolacore_export.h"
0011 #include <QAbstractListModel>
0012 class RocketChatAccount;
0013 class LIBRUQOLACORE_EXPORT InputCompleterModel : public QAbstractListModel
0014 {
0015     Q_OBJECT
0016 public:
0017     enum InputCompleterRoles {
0018         DisplayName = Qt::UserRole + 1,
0019         CompleterName, // keep value in sync with EmoticonModel
0020         IconStatus,
0021         ChannelType,
0022         Description,
0023         UserName,
0024         AvatarInfo,
0025         OutsideRoom,
0026         Identifier,
0027     };
0028     Q_ENUM(InputCompleterRoles)
0029 
0030     struct SearchInfo {
0031         enum SearchType {
0032             Unknown,
0033             Users,
0034             Channels,
0035             ChannelsAndUsers,
0036         };
0037         SearchType searchType = SearchType::Unknown;
0038         QString searchString;
0039     };
0040 
0041     explicit InputCompleterModel(RocketChatAccount *account, QObject *parent = nullptr);
0042     ~InputCompleterModel() override;
0043 
0044     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0045     [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0046 
0047     void setChannels(const QVector<ChannelUserCompleter> &channels);
0048 
0049     void parseChannels(const QJsonObject &obj);
0050     void parseSearchChannels(const QJsonObject &obj);
0051 
0052     void clear();
0053 
0054     void setDefaultUserCompletion();
0055 
0056     void setSearchInfo(const SearchInfo &newSearchInfo);
0057 
0058 private:
0059     [[nodiscard]] static ChannelUserCompleter createHereChannel();
0060     [[nodiscard]] static ChannelUserCompleter createAllChannel();
0061     [[nodiscard]] static ChannelUserCompleter noFoundChannelUser();
0062     [[nodiscard]] static QString here();
0063     [[nodiscard]] static QString all();
0064     [[nodiscard]] QVector<ChannelUserCompleter> searchOpenedRooms();
0065     SearchInfo mSearchInfo;
0066     QVector<ChannelUserCompleter> mChannelUserCompleters;
0067     RocketChatAccount *const mRocketChatAccount;
0068 };