File indexing completed on 2024-05-19 05:57:22

0001 // SPDX-FileCopyrightText: 2022 Plata Hill <plata.hill@kdemail.net>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #pragma once
0005 
0006 #include <QAbstractListModel>
0007 
0008 #include "channelfactory.h"
0009 
0010 #include <QUrl>
0011 
0012 class Channel;
0013 
0014 class ChannelsModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017     Q_PROPERTY(bool onlyFavorites READ onlyFavorites WRITE setOnlyFavorites)
0018 
0019 public:
0020     explicit ChannelsModel(QObject *parent = nullptr);
0021     ~ChannelsModel();
0022 
0023     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0024     QHash<int, QByteArray> roleNames() const override;
0025     int rowCount(const QModelIndex &parent) const override;
0026     Q_INVOKABLE void setFavorite(const QString &channelId, bool favorite);
0027     Q_INVOKABLE void move(int from, int to);
0028     Q_INVOKABLE void save();
0029 
0030     bool onlyFavorites() const;
0031     void setOnlyFavorites(bool onlyFavorites);
0032 
0033 private:
0034     void loadChannel(int index) const;
0035 
0036     mutable QVector<Channel *> m_channels;
0037     bool m_onlyFavorites;
0038     ChannelFactory m_channelFactory;
0039 };