1 /*
2    SPDX-FileCopyrightText: 2018-2021 Laurent Montel <montel@kde.org>
3 
4    SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "libruqolacore_export.h"
10 #include <QAbstractListModel>
11 #include <channel.h>
12 
13 class LIBRUQOLACORE_EXPORT SearchChannelModel : public QAbstractListModel
14 {
15     Q_OBJECT
16 public:
17     enum ChannelRoles {
18         ChannelName = Qt::UserRole + 1,
19         ChannelId,
20         IconName,
21         ChannelType,
22     };
23     Q_ENUM(ChannelRoles)
24 
25     explicit SearchChannelModel(QObject *parent = nullptr);
26     ~SearchChannelModel() override;
27 
28     Q_REQUIRED_RESULT int rowCount(const QModelIndex &parent = QModelIndex()) const override;
29     Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
30 
31     void setChannels(const QVector<Channel> &channels);
32 
33     void parseChannels(const QJsonObject &obj);
34 
35     void clear();
36 
37     void parseAllChannels(const QJsonObject &obj);
38 
39 private:
40     Q_REQUIRED_RESULT QIcon channelIconName(const Channel &channel) const;
41     Q_REQUIRED_RESULT QString channelId(const Channel &channel) const;
42     Q_REQUIRED_RESULT QString channelName(const Channel &channel) const;
43     QVector<Channel> mChannel;
44 };
45 
46