Skip to content
Permalink
Browse files

Added code from @ChristianRiedl

- logger
- getcontextproperty
- update to entities class

Also fixed issue when no docks are available
  • Loading branch information
martonborzak committed Nov 19, 2019
1 parent 2381e7e commit d63b6139e422d637d4c00b9a0c6d32fc88e172e7
Showing with 259 additions and 64 deletions.
  1. +13 βˆ’0 ButtonHandler.qml
  2. +27 βˆ’25 basic_ui/MiniMediaPlayer.qml
  3. +27 βˆ’0 components/media_player/ui/Card.qml
  4. +7 βˆ’0 sources/config.h
  5. +4 βˆ’3 sources/configinterface.h
  6. +12 βˆ’6 sources/entities/entities.cpp
  7. +4 βˆ’4 sources/integrations/integrations.cpp
  8. +110 βˆ’13 sources/logger.cpp
  9. +38 βˆ’6 sources/logger.h
  10. +5 βˆ’5 sources/main.cpp
  11. +10 βˆ’2 sources/yioapi.cpp
  12. +2 βˆ’0 sources/yioapi.h
@@ -10,6 +10,19 @@ Item {
signal buttonPress(string button)
signal buttonRelease(string button)

// Simulation via YIO API
Connections {
target: api
enabled: true

onButtonPressed: {
buttonPress(button);
}
onButtonReleased: {
buttonRelease(button);
}
}

InterruptHandler {
id: interruptHandler

@@ -71,14 +71,16 @@ Item {
}
}

property var players: entities.mediaplayersPlaying

onPlayersChanged: {
if (entities.mediaplayersPlaying.length == 0) {
loader_main.state = "visible";
loader_main.item.miniMediaPlayer.height = 0;
loader_main.item.miniMediaPlayer.miniMediaPlayerLoader.source = "";
loader_main.item.miniMediaPlayer.miniMediaPlayerLoader.active = false;
Connections {
target: entities

onMediaplayersPlayingChanged: {
if (entities.mediaplayersPlaying.length == 0) {
loader_main.state = "visible";
loader_main.item.miniMediaPlayer.height = 0;
loader_main.item.miniMediaPlayer.miniMediaPlayerLoader.source = "";
loader_main.item.miniMediaPlayer.miniMediaPlayerLoader.active = false;
}
}
}

@@ -93,7 +95,7 @@ Item {
onButtonPress: {
switch (button) {
case "dpad middle":
players[mediaPlayers.currentIndex].play();
entities.mediaplayersPlaying[mediaPlayers.currentIndex].play();
break;
case "dpad right":
if (mediaPlayers.currentIndex < mediaPlayers.count-1) {
@@ -182,7 +184,7 @@ Item {

Repeater {
id: mediaPlayersRepeater
model: players.length
model: entities.mediaplayersPlaying.length

Item {
id: player
@@ -195,7 +197,7 @@ Item {

property alias player: player

property var obj: players[index]
property var obj: entities.mediaplayersPlaying[index]

state: "closed"

@@ -300,10 +302,10 @@ Item {
ColorAnimation { duration: 300 }
}

property var m_image: players[index].mediaImage
property var m_image: entities.mediaplayersPlaying[index].mediaImage

onM_imageChanged: {
mediaplayerUtils.imageURL = players[index].mediaImage
mediaplayerUtils.imageURL = entities.mediaplayersPlaying[index].mediaImage
}

CustomImageLoader {
@@ -313,7 +315,7 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 86
url: players[index].mediaImage == "" ? "qrc:/images/mini-music-player/no_image.png" : mediaplayerUtils.image //utils.miniMusicPlayerImage
url: entities.mediaplayersPlaying[index].mediaImage == "" ? "qrc:/images/mini-music-player/no_image.png" : mediaplayerUtils.image //utils.miniMusicPlayerImage
}
}

@@ -326,7 +328,7 @@ Item {
left: parent.left
leftMargin: 0
}
url: players[index].mediaImage == "" ? "qrc:/images/mini-music-player/no_image.png" : mediaplayerUtils.smallImage
url: entities.mediaplayersPlaying[index].mediaImage == "" ? "qrc:/images/mini-music-player/no_image.png" : mediaplayerUtils.smallImage
}

Item {
@@ -340,7 +342,7 @@ Item {
Text {
id: title
color: colorText
text: players[index].mediaTitle
text: entities.mediaplayersPlaying[index].friendly_name
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
wrapMode: Text.NoWrap
@@ -354,7 +356,7 @@ Item {
Text {
id: artist
color: colorText
text: players[index].friendly_name
text: entities.mediaplayersPlaying[index].mediaTitle
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
wrapMode: Text.NoWrap
@@ -384,7 +386,7 @@ Item {
Text {
id: sourceText
color: colorText
text: players[index].source
text: entities.mediaplayersPlaying[index].source
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
font.family: "Open Sans"
@@ -402,7 +404,7 @@ Item {
Text {
id: titleOpen
color: colorText
text: players[index].mediaTitle
text: entities.mediaplayersPlaying[index].mediaTitle
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
@@ -419,7 +421,7 @@ Item {
Text {
id: artistOpen
color: colorText
text: players[index].mediaArtist
text: entities.mediaplayersPlaying[index].mediaArtist
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
@@ -450,7 +452,7 @@ Item {

Text {
color: colorText
text: players[index].friendly_name
text: entities.mediaplayersPlaying[index].friendly_name
verticalAlignment: Text.AlignVCenter
font.family: "Open Sans"
font.weight: Font.Normal
@@ -525,7 +527,7 @@ Item {

onClicked: {
haptic.playEffect("click");
players[mediaPlayers.currentIndex].previous();
entities.mediaplayersPlaying[mediaPlayers.currentIndex].previous();
}
}
}
@@ -535,7 +537,7 @@ Item {
width: 120
height: 120

property bool isPlaying: players[mediaPlayers.currentIndex] && players[mediaPlayers.currentIndex].state == 3 ? true : false
property bool isPlaying: entities.mediaplayersPlaying[mediaPlayers.currentIndex] && entities.mediaplayersPlaying[mediaPlayers.currentIndex].state == 3 ? true : false

anchors {
horizontalCenter: parent.horizontalCenter
@@ -583,7 +585,7 @@ Item {

onClicked: {
haptic.playEffect("click");
players[mediaPlayers.currentIndex].play();
entities.mediaplayersPlaying[mediaPlayers.currentIndex].play();
}
}
}
@@ -617,7 +619,7 @@ Item {

onClicked: {
haptic.playEffect("click");
players[mediaPlayers.currentIndex].next();
entities.mediaplayersPlaying[mediaPlayers.currentIndex].next();
}
}
}
@@ -310,4 +310,31 @@ Rectangle {
}
}

Grid {
id: bottomMenu
width: childrenRect.width
height: 60
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
spacing: 80

Rectangle {
width: 60
height: 60
color: "red"
}

Rectangle {
width: 60
height: 60
color: "red"
}

Rectangle {
width: 60
height: 60
color: "red"
}
}

}
@@ -5,6 +5,7 @@

#include <QObject>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QJsonArray>
#include "configinterface.h"
#include "jsonfile.h"
@@ -33,6 +34,12 @@ class Config : public QObject, ConfigInterface
emit configChanged();
}

// get context property
QVariant getContextProperty(const QString& name)
{
return m_engine->rootContext()->contextProperty(name);
}

// profile
QString profile()
{
@@ -9,11 +9,12 @@ class ConfigInterface
public:
virtual ~ConfigInterface() {}

virtual QVariantMap read() = 0;
virtual void readWrite(QVariantMap config) = 0;
virtual QVariantMap read () = 0;
virtual void readWrite (QVariantMap config) = 0;
virtual QVariant getContextProperty (const QString& name) = 0;

private:
QVariantMap m_config;
QVariantMap m_config;
};

QT_BEGIN_NAMESPACE
@@ -112,7 +112,7 @@ QObject *Entities::get(const QString& entity_id)

void Entities::add(const QString& type, const QVariantMap& config, QObject *integrationObj)
{
Entity *entity;
Entity *entity = nullptr;
// Light entity
if (type == "light") {
entity = new Light(config, integrationObj, this);
@@ -129,13 +129,20 @@ void Entities::add(const QString& type, const QVariantMap& config, QObject *inte
if (type == "remote") {
entity = new Remote(config, integrationObj, this);
}
m_entities.insert(entity->entity_id(), entity);
if (entity == nullptr) {
qDebug() << "Illegal entity type: " << type;
} else {
m_entities.insert(entity->entity_id(), entity);
}
}

void Entities::update(const QString &entity_id, const QVariantMap& attributes)
{
Entity *e = (Entity*)m_entities.value(entity_id);
e->update(attributes);
Entity *e = static_cast<Entity*>(m_entities.value(entity_id));
if (e == nullptr)
qDebug() << "Entity not found: " << entity_id;
else
e->update(attributes);
}

QList<QObject *> Entities::mediaplayersPlaying()
@@ -170,9 +177,8 @@ void Entities::removeMediaplayersPlaying(const QString &entity_id)
connect(timer, &QTimer::timeout, this, [=](){
m_mediaplayersPlaying.remove(entity_id);
emit mediaplayersPlayingChanged();
emit mediaplayersPlayingChanged();
});
timer->start(120000);
timer->start(120000);

m_mediaplayersTimers.insert(entity_id, timer);
}
@@ -8,7 +8,7 @@
#include <QJsonArray>
#include <QQuickItem>

Integrations* Integrations::s_instance = NULL;
Integrations* Integrations::s_instance = nullptr;

Integrations::Integrations(QQmlApplicationEngine *engine, const QString& appPath) :
m_engine(engine),
@@ -19,7 +19,7 @@ Integrations::Integrations(QQmlApplicationEngine *engine, const QString& appPath

Integrations::~Integrations()
{
s_instance = NULL;
s_instance = nullptr;
}

void Integrations::load()
@@ -55,8 +55,8 @@ void Integrations::load()
connect(interface, &IntegrationInterface::createDone, this, &Integrations::onCreateDone);

interface->create(map, entities, notifications, api, config);
i++;
}
i++;
}

// load plugins that are not defined in config.json aka default plugins
@@ -80,8 +80,8 @@ void Integrations::load()
map.insert("type", defaultIntegrations[k]);

interface->create(map, entities, notifications, api, config);
i++;
}
i++;
}

m_integrationsToLoad = i;

0 comments on commit d63b613

Please sign in to comment.
You can’t perform that action at this time.