diff --git a/ScreenPlay/qml/Monitors/Monitors.qml b/ScreenPlay/qml/Monitors/Monitors.qml index ed932a32..b5f3e6ea 100644 --- a/ScreenPlay/qml/Monitors/Monitors.qml +++ b/ScreenPlay/qml/Monitors/Monitors.qml @@ -137,11 +137,11 @@ Item { } Button { id: btnRemoveAllWallpaper - text: qsTr("Remove all wallpaper and Widgets") + text: qsTr("Remove all Wallpapers") Material.background: Material.Orange Material.foreground: "white" onClicked: { - screenPlay.closeAllConnections() + screenPlay.removeAllWallpapers() monitors.state = "inactive" } } diff --git a/ScreenPlay/src/screenplaymanager.cpp b/ScreenPlay/src/screenplaymanager.cpp index 445bd8c6..51a454fa 100644 --- a/ScreenPlay/src/screenplaymanager.cpp +++ b/ScreenPlay/src/screenplaymanager.cpp @@ -11,8 +11,7 @@ ScreenPlayManager::ScreenPlayManager(const shared_ptr& globalVa , m_monitorListModel { mlm } , m_sdkconnector { sdkc } { - loadActiveProfiles(); - QObject::connect(m_monitorListModel.get(), &MonitorListModel::monitorListChanged, this, &ScreenPlayManager::monitorListChanged); + loadWallpaperProfiles(); } void ScreenPlayManager::createWallpaper( @@ -23,7 +22,6 @@ void ScreenPlayManager::createWallpaper( const QString& fillMode, const QString& type) { - increaseActiveWallpaperCounter(); QString path = absoluteStoragePath; if (absoluteStoragePath.contains("file:///")) @@ -45,13 +43,21 @@ void ScreenPlayManager::createWallpaper( m_screenPlayWallpapers.append(wallpaper); m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex); + QJsonArray monitors; + for (const int index : monitorIndex) { + monitors.append(index); + } QJsonObject settings; - settings.insert("monitors", QJsonArray {}); + settings.insert("monitors", monitors); settings.insert("type", type); - settings.insert("volume", volume); + settings.insert("volume", static_cast(volume)); settings.insert("isLooping", true); + settings.insert("fillMode", fillMode); + settings.insert("previeImage", previewImage); + settings.insert("absolutePath", absoluteStoragePath); - saveConfigWallpaper("default", monitorIndex, settings); + saveWallpaperProfile("default", settings); + increaseActiveWallpaperCounter(); } void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QString& previewImage) @@ -70,17 +76,52 @@ void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QStr this)); } -void ScreenPlayManager::closeAllConnections() +void ScreenPlayManager::removeAllWallpapers() { if (!m_screenPlayWidgets.empty() || !m_screenPlayWallpapers.empty()) { - m_sdkconnector->closeAllConnections(); - setActiveWallpaperCounter(0); - setActiveWidgetsCounter(0); + m_sdkconnector->closeAllWallpapers(); m_screenPlayWallpapers.clear(); - m_screenPlayWidgets.clear(); m_monitorListModel->clearActiveWallpaper(); + + QString absoluteProfilesFilePath = m_globalVariables->localSettingsPath().toLocalFile() + "/profiles.json"; + auto configOptional = Util::openJsonFileToObject(absoluteProfilesFilePath); + + if (!configOptional.has_value()) { + qWarning() << "Could not load active profiles."; + return; + } + + QJsonObject configObj = configOptional.value(); + + // TODO right now we limit ourself to one default profile + QJsonArray activeProfilesTmp = configObj.value("profiles").toArray(); + + if (activeProfilesTmp.size() != 1) { + qWarning() << "We currently only support one profile!"; + return; + } + + for (const QJsonValueRef wallpaper : activeProfilesTmp) { + wallpaper.toObject().remove("wallpaper"); + wallpaper.toObject().insert("wallpaper", QJsonArray()); + } + + configObj.remove("profiles"); + configObj.insert("profiles", activeProfilesTmp); + qDebug() << configObj; + + Util::writeJsonObjectToFile(absoluteProfilesFilePath, configObj); + setActiveWallpaperCounter(0); + } +} + +void ScreenPlayManager::removeWallpaperAt(int at) +{ + if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(at)) { + m_sdkconnector->closeWallpaper(appID.value()); + m_monitorListModel->closeWallpaper(appID.value()); + decreaseActiveWallpaperCounter(); } - return; } void ScreenPlayManager::requestProjectSettingsListModelAt(const int index) @@ -98,8 +139,16 @@ void ScreenPlayManager::requestProjectSettingsListModelAt(const int index) void ScreenPlayManager::setWallpaperValue(const int index, const QString& key, const QString& value) { - if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(index)) { - m_sdkconnector->setWallpaperValue(appID.value(), key, value); + auto appID = m_monitorListModel->getAppIDByMonitorIndex(index); + if (appID.has_value()) { + return; + } + m_sdkconnector->setWallpaperValue(appID.value(), key, value); + + for (auto& wallpaper : m_screenPlayWallpapers) { + if (wallpaper->appID() == appID.value()){ + + } } } @@ -110,31 +159,13 @@ void ScreenPlayManager::setAllWallpaperValue(const QString& key, const QString& } } -void ScreenPlayManager::removeWallpaperAt(int at) +bool ScreenPlayManager::saveWallpaperProfile(const QString& profileName, const QJsonObject& newProfileObject) { - if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(at)) { - m_sdkconnector->closeWallpaper(appID.value()); - m_monitorListModel->closeWallpaper(appID.value()); - decreaseActiveWallpaperCounter(); - } -} + // Remove when implementing profiles + Q_UNUSED(profileName) -void ScreenPlayManager::monitorListChanged() -{ - for (const auto& wallpaperUnique_ptr : m_screenPlayWallpapers) { - if (wallpaperUnique_ptr->screenNumber().length() > 1) { - for (const int moitor : wallpaperUnique_ptr->screenNumber()) { - emit m_monitorListModel->setNewActiveMonitor( - moitor, - wallpaperUnique_ptr->previewImage()); - } - } - } -} - -bool ScreenPlayManager::saveConfigWallpaper(const QString& profileName, const QVector& monitors, const QJsonObject& content) -{ - auto configObj = Util::openJsonFileToObject(m_globalVariables->localSettingsPath().toLocalFile() + "/profiles.json"); + QString absoluteProfilesFilePath = m_globalVariables->localSettingsPath().toLocalFile() + "/profiles.json"; + auto configObj = Util::openJsonFileToObject(absoluteProfilesFilePath); if (!configObj.has_value()) { qWarning() << "Could not load active profiles."; @@ -149,40 +180,33 @@ bool ScreenPlayManager::saveConfigWallpaper(const QString& profileName, const QV return false; } + int i { 0 }; for (const QJsonValueRef wallpaper : activeProfilesTmp) { auto wallpaperList = wallpaper.toObject().value("wallpaper").toArray(); for (const QJsonValueRef wallpaper : wallpaperList) { - QJsonObject wallpaperObj = wallpaper.toObject(); + QJsonObject currentProfileObject = wallpaper.toObject(); - if (wallpaperObj.empty()) + if (currentProfileObject.empty()) return false; - QJsonArray monitorsArray = wallpaperObj.value("monitors").toArray(); - - // A wallpaper can span across multiple monitors - // But first we need to convert the QJsonArray to an QVector - QVector monitorsParsed; - for (const QJsonValueRef item : monitorsArray) { - int tmp = item.toInt(-1); - if (tmp == -1) { - continue; - } - monitorsParsed.append(tmp); - } - - // We need to find the right wallpaper with the same monitors. - if (monitorsParsed != monitors) { + if (currentProfileObject.value("monitors").toArray() != newProfileObject.value("monitors").toArray()) continue; - } + + wallpaperList.removeAt(i); + + wallpaperList.append(newProfileObject); + + Util::writeJsonObjectToFile(absoluteProfilesFilePath, configObj.value()); return true; } + ++i; } - return true; + return false; } -void ScreenPlayManager::loadActiveProfiles() +void ScreenPlayManager::loadWallpaperProfiles() { auto configObj = Util::openJsonFileToObject(m_globalVariables->localSettingsPath().toLocalFile() + "/profiles.json"); @@ -251,7 +275,6 @@ void ScreenPlayManager::loadActiveProfiles() QString previewImage = wallpaperObj.value("previewImage").toString(); QString file = wallpaperObj.value("file").toString(); QString type = wallpaperObj.value("type").toString(); - QString name = wallpaperObj.value("name").toString(); createWallpaper(monitors, absolutePath, previewImage, volume, fillMode, type); monitors.clear(); diff --git a/ScreenPlay/src/screenplaymanager.h b/ScreenPlay/src/screenplaymanager.h index 537f922d..571d099c 100644 --- a/ScreenPlay/src/screenplaymanager.h +++ b/ScreenPlay/src/screenplaymanager.h @@ -100,13 +100,13 @@ public slots: void createWidget(const QUrl& absoluteStoragePath, const QString& previewImage); - void closeAllConnections(); + void removeAllWallpapers(); void removeWallpaperAt(const int at = 0); void requestProjectSettingsListModelAt(const int index); void setWallpaperValue(const int index, const QString& key, const QString& value); void setAllWallpaperValue(const QString& key, const QString& value); - void monitorListChanged(); + void setActiveWallpaperCounter(int activeWallpaperCounter) { @@ -127,8 +127,9 @@ public slots: } private: - void loadActiveProfiles(); - bool saveConfigWallpaper(const QString& profileName, const QVector& monitors, const QJsonObject& content); + void loadWallpaperProfiles(); + bool saveWallpaperProfile(const QString& profileName, const QJsonObject& content); + private: const shared_ptr& m_globalVariables; diff --git a/ScreenPlay/src/screenplaywallpaper.cpp b/ScreenPlay/src/screenplaywallpaper.cpp index 751c97ab..ab6982b4 100644 --- a/ScreenPlay/src/screenplaywallpaper.cpp +++ b/ScreenPlay/src/screenplaywallpaper.cpp @@ -10,20 +10,20 @@ ScreenPlayWallpaper::ScreenPlayWallpaper( const QVector& screenNumber, const shared_ptr& globalVariables, const QString& appID, - const QString& projectPath, + const QString& absolutePath, const QString& previewImage, const float volume, const QString& fillMode, const QString& type, QObject* parent) : QObject(parent) - , m_projectSettingsListModel { make_shared(projectPath + "/project.json") } + , m_projectSettingsListModel { make_shared(absolutePath + "/project.json") } , m_globalVariables { globalVariables } , m_screenNumber { screenNumber } - , m_projectPath { projectPath } - , m_previewImage { QString { projectPath + "/" + previewImage } } + , m_previewImage { QString { absolutePath + "/" + previewImage } } , m_type { type } , m_appID { appID } + , m_absolutePath { absolutePath } { QObject::connect(&m_process, QOverload::of(&QProcess::finished), @@ -53,10 +53,11 @@ ScreenPlayWallpaper::ScreenPlayWallpaper( const QStringList proArgs { tmpScreenNumber, - m_projectPath, + m_absolutePath, QString { "appID=" + m_appID }, QString::number(static_cast(volume)), - fillMode + fillMode, + type }; qDebug() << "Creating ScreenPlayWallpaper " << proArgs; diff --git a/ScreenPlay/src/screenplaywallpaper.h b/ScreenPlay/src/screenplaywallpaper.h index abf35083..729c96e6 100644 --- a/ScreenPlay/src/screenplaywallpaper.h +++ b/ScreenPlay/src/screenplaywallpaper.h @@ -1,43 +1,44 @@ #pragma once +#include #include #include #include -#include "projectsettingslistmodel.h" #include "globalvariables.h" +#include "projectsettingslistmodel.h" namespace ScreenPlay { using std::shared_ptr, std::make_shared; -class ScreenPlayWallpaper : public QObject { +class ScreenPlayWallpaper : public QObject { Q_OBJECT Q_PROPERTY(QVector screenNumber READ screenNumber WRITE setScreenNumber NOTIFY screenNumberChanged) Q_PROPERTY(QString file READ file WRITE setFile NOTIFY fileChanged) Q_PROPERTY(QString fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) - Q_PROPERTY(QString projectPath READ projectPath WRITE setProjectPath NOTIFY projectPathChanged) + Q_PROPERTY(QString absolutePath READ absolutePath WRITE setAbsolutePath NOTIFY absolutePathChanged) Q_PROPERTY(QString previewImage READ previewImage WRITE setPreviewImage NOTIFY previewImageChanged) Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged) Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) - + Q_PROPERTY(QJsonObject profileJsonObject READ profileJsonObject WRITE setProfileJsonObject NOTIFY profileJsonObjectChanged) public: - explicit ScreenPlayWallpaper(const QVector& screenNumber, + explicit ScreenPlayWallpaper( + const QVector& screenNumber, const shared_ptr& globalVariables, const QString& appID, - const QString& projectPath, + const QString& absolutePath, const QString& previewImage, const float volume, const QString& fillMode, const QString& type, QObject* parent = nullptr); - ~ScreenPlayWallpaper() {} const shared_ptr& projectSettingsListModel() const @@ -50,11 +51,6 @@ public: return m_screenNumber; } - QString projectPath() const - { - return m_projectPath; - } - QString previewImage() const { return m_previewImage; @@ -80,16 +76,26 @@ public: return m_fillMode; } + QString absolutePath() const + { + return m_absolutePath; + } + + QJsonObject profileJsonObject() const + { + return m_profileJsonObject; + } + signals: void screenNumberChanged(QVector screenNumber); - void projectPathChanged(QString projectPath); void previewImageChanged(QString previewImage); void appIDChanged(QString appID); void typeChanged(QString type); - void fileChanged(QString file); - void fillModeChanged(QString fillMode); + void absolutePathChanged(QString absolutePath); + + void profileJsonObjectChanged(QJsonObject profileJsonObject); public slots: void setScreenNumber(QVector screenNumber) @@ -101,15 +107,6 @@ public slots: emit screenNumberChanged(m_screenNumber); } - void setProjectPath(QString projectPath) - { - if (m_projectPath == projectPath) - return; - - m_projectPath = projectPath; - emit projectPathChanged(m_projectPath); - } - void setPreviewImage(QString previewImage) { if (m_previewImage == previewImage) @@ -155,6 +152,24 @@ public slots: emit fillModeChanged(m_fillMode); } + void setAbsolutePath(QString absolutePath) + { + if (m_absolutePath == absolutePath) + return; + + m_absolutePath = absolutePath; + emit absolutePathChanged(m_absolutePath); + } + + void setProfileJsonObject(QJsonObject profileJsonObject) + { + if (m_profileJsonObject == profileJsonObject) + return; + + m_profileJsonObject = profileJsonObject; + emit profileJsonObjectChanged(m_profileJsonObject); + } + private: QProcess m_process; @@ -163,11 +178,12 @@ private: QVector m_screenNumber; - QString m_projectPath; QString m_previewImage; QString m_type; QString m_appID; QString m_file; QString m_fillMode; + QString m_absolutePath; + QJsonObject m_profileJsonObject; }; } diff --git a/ScreenPlay/src/sdkconnector.cpp b/ScreenPlay/src/sdkconnector.cpp index 50ab513f..9c876c82 100644 --- a/ScreenPlay/src/sdkconnector.cpp +++ b/ScreenPlay/src/sdkconnector.cpp @@ -1,7 +1,5 @@ #include "sdkconnector.h" -#include -#include namespace ScreenPlay { SDKConnector::SDKConnector(QObject* parent) : QObject(parent) @@ -10,7 +8,7 @@ SDKConnector::SDKConnector(QObject* parent) connect(m_server.get(), &QLocalServer::newConnection, this, &SDKConnector::newConnection); if (!m_server->listen("ScreenPlay")) { - qErrnoWarning("Could not open Local Socket with the name ScreenPlay. Usually this means another ScreenPlay instance is running!"); + qCritical("Could not open Local Socket with the name ScreenPlay. Usually this means another ScreenPlay instance is running!"); } } @@ -25,10 +23,18 @@ void SDKConnector::newConnection() void SDKConnector::closeAllConnections() { - for (int i = 0; i < m_clients.size(); ++i) { - m_clients.at(i)->close(); - m_clients.clear(); - m_clients.squeeze(); + for (auto& client : m_clients) { + client->close(); + } + m_clients.clear(); +} + +void SDKConnector::closeAllWallpapers() +{ + for (auto& client : m_clients) { + if(client->type() == "videoWallpaper"){ + client->close(); + } } } @@ -37,7 +43,6 @@ void SDKConnector::closeWallpapersAt(int at) for (const shared_ptr& refSDKConnection : m_clients) { refSDKConnection->close(); if (!refSDKConnection->monitor().empty()) { - // problem here !! if (refSDKConnection->monitor().at(0) == at) { refSDKConnection->close(); qDebug() << "Wall Closed...!"; diff --git a/ScreenPlay/src/sdkconnector.h b/ScreenPlay/src/sdkconnector.h index e0b753e6..5bba6216 100644 --- a/ScreenPlay/src/sdkconnector.h +++ b/ScreenPlay/src/sdkconnector.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include #include @@ -32,6 +34,7 @@ public slots: void readyRead(); void newConnection(); void closeAllConnections(); + void closeAllWallpapers(); void closeWallpapersAt(int at); void closeWallpaper(const QString& appID); @@ -46,6 +49,7 @@ private: class SDKConnection : public QObject { Q_OBJECT Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged) + Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) Q_PROPERTY(QVector monitor READ monitor WRITE setMonitor NOTIFY monitorChanged) public: @@ -79,11 +83,18 @@ public: return m_monitor; } + QString type() const + { + return m_type; + } + signals: void requestCloseAt(int at); void appIDChanged(QString appID); void monitorChanged(QVector monitor); + void typeChanged(QString type); + public slots: void readyRead() { @@ -92,11 +103,13 @@ public slots: // The first message allways contains the appID if (msg.startsWith("appID=")) { + QStringList args = msg.split(","); //Only use the first 32 chars for the appID - m_appID = msg.remove("appID=").mid(0, 32); - msg.remove(m_appID); - qDebug() << "###### Wallpaper width APPID created:" - << "\n######" << m_appID; + QString appID = args.at(0); + m_appID = appID.remove("appID="); + m_type = args.at(1); + qDebug() << "###### Wallpaper created:" + << "\t AppID:" << m_appID << "\t type: " << m_type; } else { qDebug() << "### Message from: " << m_appID << "\n###" << msg; } @@ -131,9 +144,19 @@ public slots: emit monitorChanged(m_monitor); } + void setType(QString type) + { + if (m_type == type) + return; + + m_type = type; + emit typeChanged(m_type); + } + private: QLocalSocket* m_socket; QString m_appID; QVector m_monitor; + QString m_type; }; } diff --git a/ScreenPlay/src/settings.cpp b/ScreenPlay/src/settings.cpp index 150c6b2c..7c67b0ef 100644 --- a/ScreenPlay/src/settings.cpp +++ b/ScreenPlay/src/settings.cpp @@ -148,13 +148,7 @@ void Settings::writeSingleSettingConfig(QString name, QVariant value) obj.value().insert(name, value.toJsonValue()); - QFile configTmp; - configTmp.setFileName(filename); - configTmp.open(QIODevice::ReadWrite | QIODevice::Truncate); - QTextStream out(&configTmp); - out << QJsonDocument(obj.value()).toJson(); - - configTmp.close(); + Util::writeJsonObjectToFile(filename,obj.value()); } void Settings::setqSetting(const QString& key, const QString& value) diff --git a/ScreenPlay/src/util.cpp b/ScreenPlay/src/util.cpp index e5703d29..56f63e55 100644 --- a/ScreenPlay/src/util.cpp +++ b/ScreenPlay/src/util.cpp @@ -112,6 +112,28 @@ std::optional Util::getVersionNumberFromString(const QString& st return QVersionNumber(major, minor, patch); } +bool Util::writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate) +{ + QFile configTmp; + configTmp.setFileName(absoluteFilePath); + QIODevice::OpenMode openMode; + if (truncate) { + openMode = QIODevice::ReadWrite | QIODevice::Truncate; + } else { + openMode = QIODevice::ReadWrite | QIODevice::Append; + } + + if (!configTmp.open(openMode)) { + return false; + } + + QTextStream out(&configTmp); + out << QJsonDocument(object).toJson(); + + configTmp.close(); + return true; +} + void Util::setNavigation(QString nav) { emit requestNavigation(nav); @@ -332,5 +354,4 @@ bool Util::saveExtractedByteArray(libzippp::ZipEntry& entry, std::string& absolu return true; } - } diff --git a/ScreenPlay/src/util.h b/ScreenPlay/src/util.h index 516dbb6a..87e3dc11 100644 --- a/ScreenPlay/src/util.h +++ b/ScreenPlay/src/util.h @@ -1,19 +1,21 @@ #pragma once #include +#include #include #include #include +#include +#include #include +#include #include #include #include #include -#include -#include -#include -#include +#include #include +#include #include #include @@ -24,20 +26,16 @@ namespace ScreenPlay { - - - class Util : public QObject { Q_OBJECT - Q_PROPERTY(bool ffmpegAvailable READ ffmpegAvailable NOTIFY ffmpegAvailableChanged) + Q_PROPERTY(bool ffmpegAvailable READ ffmpegAvailable NOTIFY ffmpegAvailableChanged) Q_PROPERTY(AquireFFMPEGStatus aquireFFMPEGStatus READ aquireFFMPEGStatus NOTIFY aquireFFMPEGStatusChanged) - Q_PROPERTY(QString debugMessages READ debugMessages NOTIFY debugMessagesChanged) + Q_PROPERTY(QString debugMessages READ debugMessages NOTIFY debugMessagesChanged) public: explicit Util(QNetworkAccessManager* networkAccessManager, QObject* parent = nullptr); - enum class AquireFFMPEGStatus { Init, Download, @@ -83,8 +81,8 @@ signals: public slots: static std::optional openJsonFileToObject(const QString& path); static std::optional openJsonFileToString(const QString& path); - static std::optional getVersionNumberFromString(const QString& str); + static bool writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate = true); static QString generateRandomString(quint32 length = 32); @@ -123,7 +121,7 @@ public slots: void appendDebugMessages(QString debugMessages) { - if(m_debugMessages.size() > 1000000) { + if (m_debugMessages.size() > 1000000) { m_debugMessages = "###### DEBUG CLEARED ######"; } @@ -143,5 +141,5 @@ private: }; // Used for redirect content from static logToGui to setDebugMessages -static Util* utilPointer {nullptr}; +static Util* utilPointer { nullptr }; } diff --git a/ScreenPlaySDK/screenplaysdk.cpp b/ScreenPlaySDK/screenplaysdk.cpp index fa3a9ff9..09901c5f 100644 --- a/ScreenPlaySDK/screenplaysdk.cpp +++ b/ScreenPlaySDK/screenplaysdk.cpp @@ -5,6 +5,22 @@ static ScreenPlaySDK* global_sdkPtr = nullptr; ScreenPlaySDK::ScreenPlaySDK(QQuickItem* parent) : QQuickItem(parent) +{ + init(); +} + +ScreenPlaySDK::ScreenPlaySDK( + const QString& appID, + const QString& type, + QQuickItem* parent) + : QQuickItem(parent) + , m_type { type } + , m_appID { appID } +{ + init(); +} + +void ScreenPlaySDK::init() { // Redirect all messages from this to ScreenPlay global_sdkPtr = this; @@ -26,6 +42,10 @@ ScreenPlaySDK::~ScreenPlaySDK() void ScreenPlaySDK::connected() { + QByteArray welcomeMessage = QString(m_appID + "," + m_type).toUtf8(); + m_socket.write(welcomeMessage); + m_socket.waitForBytesWritten(); + setIsConnected(true); emit sdkConnected(); } diff --git a/ScreenPlaySDK/screenplaysdk.h b/ScreenPlaySDK/screenplaysdk.h index 96582ff4..315b3d0c 100644 --- a/ScreenPlaySDK/screenplaysdk.h +++ b/ScreenPlaySDK/screenplaysdk.h @@ -20,15 +20,16 @@ class ScreenPlaySDK : public QQuickItem { public: ScreenPlaySDK(QQuickItem* parent = nullptr); + ScreenPlaySDK( const QString& appID, const QString& type,QQuickItem* parent = nullptr); ~ScreenPlaySDK(); - Q_PROPERTY(QString contentType READ contentType WRITE setContentType NOTIFY contentTypeChanged) + Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) Q_PROPERTY(bool isConnected READ isConnected WRITE setIsConnected NOTIFY isConnectedChanged) Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged) - QString contentType() const + QString type() const { - return m_contentType; + return m_type; } bool isConnected() const @@ -49,19 +50,13 @@ public slots: void error(QLocalSocket::LocalSocketError socketError); void redirectMessage(QByteArray& msg); - void setContentType(QString contentType) + void setType(QString type) { - if (m_contentType == contentType) + if (m_type == type) return; - m_contentType = contentType; - - if (isConnected()) { - m_socket.write(QByteArray(m_contentType.toLatin1())); - m_socket.flush(); - m_socket.waitForBytesWritten(); - } - emit contentTypeChanged(m_contentType); + m_type = type; + emit typeChanged(m_type); } void setIsConnected(bool isConnected) @@ -80,9 +75,6 @@ public slots: m_appID = appID; emit appIDChanged(m_appID); - - m_socket.write(QByteArray(appID.toUtf8())); - m_socket.waitForBytesWritten(); } static void redirectMessageOutputToMainWindow(QtMsgType type, const QMessageLogContext& context, const QString& msg); @@ -94,16 +86,19 @@ signals: void sdkConnected(); void sdkDisconnected(); - void contentTypeChanged(QString contentType); + void typeChanged(QString type); void isConnectedChanged(bool isConnected); void appIDChanged(QString appID); void newRedirectMessage(QByteArray& msg); +private: + void init(); + private: QLocalSocket m_socket; - QString m_contentType = "undefined"; + QString m_type = "undefined"; bool m_isConnected = false; QString m_appID; diff --git a/ScreenPlayWallpaper/main.cpp b/ScreenPlayWallpaper/main.cpp index f2cc7b57..54dcdec7 100644 --- a/ScreenPlayWallpaper/main.cpp +++ b/ScreenPlayWallpaper/main.cpp @@ -35,11 +35,14 @@ int main(int argc, char* argv[]) // It means we want to test a single wallpaper QStringList argumentList = app.arguments(); if (argumentList.length() == 1) { - QVector list; - list.append(0); + + //Set the monitor number to test #if defined(Q_OS_WIN) - WinWindow window(list, "test", "appid", "1", "fill"); + WinWindow window1({ 0 }, "test", "appid", "1", "fill"); + WinWindow window2({ 1 }, "test", "appid", "1", "fill"); + WinWindow window3({ 2 }, "test", "appid", "1", "fill"); + //WinWindow window(list, "D:/672870/827874818", "appid", "1", "fill"); #endif #if defined(Q_OS_LINUX) @@ -52,13 +55,13 @@ int main(int argc, char* argv[]) return app.exec(); } - // 5 parameter + 1 OS working directory default paramter - if (argumentList.length() != 6) { + // 6 parameter + 1 OS working directory default paramter + if (argumentList.length() != 7) { return -3; } - ScreenPlaySDK sdk; - sdk.setAppID(argumentList.at(3)); + // AppID, Type + ScreenPlaySDK sdk(argumentList.at(3),argumentList.at(6)); QString monitorNumbers = argumentList.at(1); QStringList activeScreensList = monitorNumbers.split(","); @@ -85,7 +88,7 @@ int main(int argc, char* argv[]) } } - // Args: which monitor, (2) path to project, (3)wallpaper secret to identify the connected socket, (4) volume, (5) fillmode + // Args: which monitor, (2) path to project, (3)wallpaper secret to identify the connected socket, (4) volume, (5) fillmode, (6) type // See screenplay.h @ScreenPlayWallpaper constructor how the args get created qDebug() << argumentList;