Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit 0230478

Browse files
authored
feat: Adding additional tv channel card to the media player model (#13)
Adding a media player remote for sending commands to a media player
1 parent b3bd73f commit 0230478

File tree

5 files changed

+266
-13
lines changed

5 files changed

+266
-13
lines changed

src/yio-interface/entities/mediaplayerinterface.h

+25-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,20 @@ class MediaPlayerDef : public QObject {
7777
F_VOLUME_DOWN,
7878
F_VOLUME_SET,
7979
F_VOLUME_UP,
80+
F_UP,
81+
F_DOWN,
82+
F_LEFT,
83+
F_RIGHT,
84+
F_OK,
85+
F_CHANNEL_UP,
86+
F_CHANNEL_DOWN,
87+
F_BACK,
88+
F_MENU,
8089
F_LIST,
81-
F_SPEAKER_CONTROL
90+
F_SPEAKER_CONTROL,
91+
F_TVCHANNELLIST,
92+
F_MEDIAPLAYERREMOTE,
93+
F_MEDIAPLAYEREPGVIEW
8294
};
8395
Q_ENUM(Features)
8496

@@ -93,13 +105,25 @@ class MediaPlayerDef : public QObject {
93105
C_VOLUME_SET,
94106
C_VOLUME_UP,
95107
C_VOLUME_DOWN,
108+
C_UP,
109+
C_DOWN,
110+
C_LEFT,
111+
C_RIGHT,
112+
C_OK,
113+
C_MENU,
114+
C_CHANNEL_UP,
115+
C_CHANNEL_DOWN,
96116
C_MUTE,
97117
C_BROWSE,
98118
C_SEARCH,
119+
C_MEDIAPLAYERTEXTINPUT,
99120
C_SEARCH_ITEM,
100121
C_PLAY_ITEM,
101122
C_GETALBUM,
102123
C_GETPLAYLIST,
124+
C_GETTVCHANNELLIST,
125+
C_GETMEDIAPLAYERREMOTE,
126+
C_GETMEDIAPLAYEREPGVIEW,
103127
C_QUEUE
104128
};
105129
Q_ENUM(Commands)

src/yio-interface/entities/remoteinterface.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ class RemoteDef : public QObject {
7171
F_DIGIT_ENTER,
7272

7373
// navigation
74-
F_CURSOR_UP,
75-
F_CURSOR_DOWN,
76-
F_CURSOR_LEFT,
77-
F_CURSOR_RIGHT,
78-
F_CURSOR_OK,
74+
F_UP,
75+
F_DOWN,
76+
F_LEFT,
77+
F_RIGHT,
78+
F_OK,
7979
F_BACK,
8080
F_HOME,
8181
F_MENU,
@@ -173,11 +173,11 @@ class RemoteDef : public QObject {
173173
C_DIGIT_ENTER,
174174

175175
// navigation
176-
C_CURSOR_UP,
177-
C_CURSOR_DOWN,
178-
C_CURSOR_LEFT,
179-
C_CURSOR_RIGHT,
180-
C_CURSOR_OK,
176+
C_UP,
177+
C_DOWN,
178+
C_LEFT,
179+
C_RIGHT,
180+
C_OK,
181181
C_BACK,
182182
C_HOME,
183183
C_MENU,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
#include "tvchannelmodel_mediaplayer.h"
24+
25+
ListTvChannelModel::ListTvChannelModel(QObject *parent) : QAbstractListModel(parent), m_count(0) {}
26+
27+
int ListTvChannelModel::count() const { return m_count; }
28+
29+
int ListTvChannelModel::rowCount(const QModelIndex &p) const {
30+
Q_UNUSED(p)
31+
return m_data.size();
32+
}
33+
34+
QVariant ListTvChannelModel::data(const QModelIndex &index, int role) const {
35+
if (index.row() < 0 || index.row() >= m_data.count()) return QVariant();
36+
const TvChannelModelItem &item = m_data[index.row()];
37+
switch (role) {
38+
case KeyRole:
39+
return item.itemKey();
40+
case TimeRole:
41+
return item.itemTime();
42+
case TitleRole:
43+
return item.itemTitle();
44+
case SubTitleRole:
45+
return item.itemSubtitle();
46+
case TypeRole:
47+
return item.itemType();
48+
case ImageUrlRole:
49+
return item.itemImageUrl();
50+
case CommandsRole:
51+
return item.itemCommands();
52+
}
53+
return QVariant();
54+
}
55+
56+
QHash<int, QByteArray> ListTvChannelModel::roleNames() const {
57+
QHash<int, QByteArray> roles;
58+
roles[KeyRole] = "item_key";
59+
roles[TimeRole] = "item_time";
60+
roles[TitleRole] = "item_title";
61+
roles[SubTitleRole] = "item_subtitle";
62+
roles[TypeRole] = "item_type";
63+
roles[ImageUrlRole] = "item_image";
64+
roles[CommandsRole] = "item_commands";
65+
return roles;
66+
}
67+
68+
void ListTvChannelModel::append(const TvChannelModelItem &o) {
69+
int i = m_data.size();
70+
beginInsertRows(QModelIndex(), i, i);
71+
m_data.append(o);
72+
73+
// Emit changed signals
74+
emit countChanged(count());
75+
76+
endInsertRows();
77+
}
78+
79+
void ListTvChannelModel::setCount(int count) {
80+
if (m_count == count) return;
81+
82+
m_count = count;
83+
emit countChanged(m_count);
84+
}
85+
86+
void BrowseTvChannelModel::addtvchannelItem(const QString &key, const QString &time,
87+
const QString &title, const QString &subtitle, const QString &type,
88+
const QString &imageUrl, const QVariant &commands) {
89+
ListTvChannelModel *model = static_cast<ListTvChannelModel *>(m_model);
90+
TvChannelModelItem item = TvChannelModelItem(key, time, title, subtitle, type, imageUrl, commands);
91+
model->append(item);
92+
emit modelChanged();
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
};

yio-model-mediaplayer.pri

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ INCLUDEPATH += $$PWD/src
77
# Model files
88
HEADERS += \
99
$$PWD/src/yio-model/mediaplayer/albummodel_mediaplayer.h \
10-
$$PWD/src/yio-model/mediaplayer/searchmodel_mediaplayer.h
10+
$$PWD/src/yio-model/mediaplayer/searchmodel_mediaplayer.h \
11+
$$PWD/src/yio-model/mediaplayer/tvchannelmodel_mediaplayer.h
1112

1213
SOURCES += \
1314
$$PWD/src/yio-model/mediaplayer/albummodel_mediaplayer.cpp \
14-
$$PWD/src/yio-model/mediaplayer/searchmodel_mediaplayer.cpp
15+
$$PWD/src/yio-model/mediaplayer/searchmodel_mediaplayer.cpp \
16+
$$PWD/src/yio-model/mediaplayer/tvchannelmodel_mediaplayer.cpp

0 commit comments

Comments
 (0)