1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-06 02:52:29 +01:00
ScreenPlay/ScreenPlaySDK/screenplaysdk.h

106 lines
2.4 KiB
C
Raw Normal View History

#pragma once
2018-04-18 18:39:25 +02:00
#include <QByteArray>
#include <QJsonDocument>
2018-04-18 18:39:25 +02:00
#include <QJsonObject>
#include <QJsonParseError>
2018-04-18 18:39:25 +02:00
#include <QLocalServer>
#include <QLocalSocket>
#include <QObject>
#include <QQuickItem>
#include <QSharedDataPointer>
#include <QSharedPointer>
#include <QTimer>
2018-04-18 18:39:25 +02:00
class ScreenPlaySDK : public QQuickItem {
Q_OBJECT
Q_DISABLE_COPY(ScreenPlaySDK)
public:
2018-04-18 18:39:25 +02:00
ScreenPlaySDK(QQuickItem* parent = nullptr);
~ScreenPlaySDK();
Q_PROPERTY(QString contentType READ contentType WRITE setContentType NOTIFY contentTypeChanged)
Q_PROPERTY(bool isConnected READ isConnected WRITE setIsConnected NOTIFY isConnectedChanged)
2018-03-12 16:20:48 +01:00
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
QString contentType() const
{
return m_contentType;
}
bool isConnected() const
{
return m_isConnected;
}
2018-03-12 16:20:48 +01:00
QString appID() const
{
return m_appID;
}
public slots:
void connected();
void disconnected();
void bytesWritten(qint64 bytes);
void readyRead();
void error(QLocalSocket::LocalSocketError socketError);
void setContentType(QString contentType)
{
if (m_contentType == contentType)
return;
m_contentType = contentType;
2018-04-18 18:39:25 +02:00
if (isConnected()) {
m_socket.data()->write(QByteArray(m_contentType.toLatin1()));
m_socket.data()->flush();
m_socket.data()->waitForBytesWritten();
}
emit contentTypeChanged(m_contentType);
}
void setIsConnected(bool isConnected)
{
if (m_isConnected == isConnected)
return;
m_isConnected = isConnected;
emit isConnectedChanged(m_isConnected);
}
2018-03-12 16:20:48 +01:00
void setAppID(QString appID)
{
if (m_appID == appID)
return;
m_appID = appID;
emit appIDChanged(m_appID);
2018-04-18 18:39:25 +02:00
2018-03-12 16:20:48 +01:00
m_socket.data()->write(QByteArray(appID.toUtf8()));
m_socket.data()->waitForBytesWritten();
}
signals:
2018-03-12 16:20:48 +01:00
void incommingMessage(QString key, QString value);
void incommingMessageError(QString msg);
void sdkConnected();
void sdkDisconnected();
void sdkSocketError(QString type);
void contentTypeChanged(QString contentType);
void isConnectedChanged(bool isConnected);
2018-03-12 16:20:48 +01:00
void appIDChanged(QString appID);
private:
QSharedPointer<QLocalSocket> m_socket;
QString m_contentType = "undefined";
bool m_isConnected = false;
2018-03-12 16:20:48 +01:00
QString m_appID;
};