|
| 1 | +/****************************************************************************** |
| 2 | + * |
| 3 | + * Copyright (C) 2020 Michael Lörcher <MichaelLoecher@web.de> |
| 4 | + * |
| 5 | + * This file is part of the YIO-Remote software project. |
| 6 | + * |
| 7 | + * YIO-Remote software is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * YIO-Remote software is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with YIO-Remote software. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + * |
| 20 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 21 | + *****************************************************************************/ |
| 22 | + |
| 23 | +#pragma once |
| 24 | + |
| 25 | +#include <QAbstractListModel> |
| 26 | +#include <QObject> |
| 27 | +#include <QVariant> |
| 28 | +#include <QtDebug> |
| 29 | + |
| 30 | +class TvChannelModelItem { |
| 31 | + public: |
| 32 | + TvChannelModelItem(const QString& key, const QString& time, const QString& title, |
| 33 | + const QString& subtitle, const QString& type, |
| 34 | + const QString& imageUrl, const QVariant& commands) |
| 35 | + : m_key(key), m_time(time), m_title(title), m_subtitle(subtitle), |
| 36 | + m_type(type), m_imageUrl(imageUrl), m_commands(commands) {} |
| 37 | + |
| 38 | + QString itemKey() const { return m_key; } |
| 39 | + QString itemTime() const { return m_time; } |
| 40 | + QString itemTitle() const { return m_title; } |
| 41 | + QString itemSubtitle() const { return m_subtitle; } |
| 42 | + QString itemType() const { return m_type; } |
| 43 | + QString itemImageUrl() const { return m_imageUrl; } |
| 44 | + QVariant itemCommands() const { return m_commands; } |
| 45 | + |
| 46 | + private: |
| 47 | + QString m_key; |
| 48 | + QString m_time; |
| 49 | + QString m_title; |
| 50 | + QString m_subtitle; |
| 51 | + QString m_type; |
| 52 | + QString m_imageUrl; |
| 53 | + QVariant m_commands; |
| 54 | +}; |
| 55 | + |
| 56 | +class ListTvChannelModel : public QAbstractListModel { |
| 57 | + Q_OBJECT |
| 58 | + Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) |
| 59 | + |
| 60 | + public: |
| 61 | + enum SearchRoles { KeyRole = Qt::UserRole + 1, TimeRole, TitleRole, SubTitleRole, |
| 62 | + TypeRole, ImageUrlRole, CommandsRole }; |
| 63 | + |
| 64 | + explicit ListTvChannelModel(QObject* parent = nullptr); |
| 65 | + ~ListTvChannelModel() {} |
| 66 | + |
| 67 | + int count() const; |
| 68 | + int rowCount(const QModelIndex& p = QModelIndex()) const; |
| 69 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; |
| 70 | + QHash<int, QByteArray> roleNames() const; |
| 71 | + |
| 72 | + void append(const TvChannelModelItem& o); |
| 73 | + |
| 74 | + public slots: // NOLINT open issue: https://github.com/cpplint/cpplint/pull/99 |
| 75 | + void setCount(int count); |
| 76 | + |
| 77 | + signals: |
| 78 | + void countChanged(int count); |
| 79 | + |
| 80 | + private: |
| 81 | + int m_count; |
| 82 | + QList<TvChannelModelItem> m_data; |
| 83 | +}; |
| 84 | + |
| 85 | +class BrowseTvChannelModel : public QObject { |
| 86 | + Q_OBJECT |
| 87 | + Q_PROPERTY(QString id READ id NOTIFY idChanged) |
| 88 | + Q_PROPERTY(QString title READ title NOTIFY titleChanged) |
| 89 | + Q_PROPERTY(QString subtitle READ subtitle NOTIFY subtitleChanged) |
| 90 | + Q_PROPERTY(QString type READ type NOTIFY typeChanged) |
| 91 | + Q_PROPERTY(QString imageUrl READ imageUrl NOTIFY imageUrlChanged) |
| 92 | + Q_PROPERTY(QObject* model READ model NOTIFY modelChanged) |
| 93 | + Q_PROPERTY(QStringList commands READ commands NOTIFY commandsChanged) |
| 94 | + |
| 95 | + public: |
| 96 | + BrowseTvChannelModel(const QString& id, const QString& time, |
| 97 | + const QString& title, const QString& subtitle, const QString& type, |
| 98 | + const QString& imageUrl, const QStringList& commands = {}, QObject* parent = nullptr) |
| 99 | + : m_id(id), m_time(time), m_title(title), m_subtitle(subtitle), m_type(type), |
| 100 | + m_imageUrl(imageUrl), m_commands(commands) {} |
| 101 | + |
| 102 | + ~BrowseTvChannelModel() {} |
| 103 | + |
| 104 | + QString id() { return m_id; } |
| 105 | + QString time() { return m_time; } |
| 106 | + QString title() { return m_title; } |
| 107 | + QString subtitle() { return m_subtitle; } |
| 108 | + QString type() { return m_type; } |
| 109 | + QString imageUrl() { return m_imageUrl; } |
| 110 | + QObject* model() { return m_model; } |
| 111 | + QStringList commands() { return m_commands; } |
| 112 | + |
| 113 | + void addtvchannelItem(const QString& key, const QString& time, const QString& title, const QString& subtitle, |
| 114 | + const QString& type, const QString& imageUrl, const QVariant& commands); |
| 115 | + |
| 116 | + signals: |
| 117 | + void idChanged(); |
| 118 | + void titleChanged(); |
| 119 | + void subtitleChanged(); |
| 120 | + void typeChanged(); |
| 121 | + void imageUrlChanged(); |
| 122 | + void modelChanged(); |
| 123 | + void commandsChanged(); |
| 124 | + |
| 125 | + private: |
| 126 | + QString m_id; |
| 127 | + QString m_time; |
| 128 | + QString m_title; |
| 129 | + QString m_subtitle; |
| 130 | + QString m_type; |
| 131 | + QString m_imageUrl; |
| 132 | + QObject* m_model = new ListTvChannelModel(); |
| 133 | + QStringList m_commands; |
| 134 | +}; |
0 commit comments