diff --git a/ScreenPlayWallpaper/Wallpaper.qml b/ScreenPlayWallpaper/Wallpaper.qml index 864ab7f2..73ec7939 100644 --- a/ScreenPlayWallpaper/Wallpaper.qml +++ b/ScreenPlayWallpaper/Wallpaper.qml @@ -48,7 +48,7 @@ Rectangle { loader.source = "" Wallpaper.clearComponentCache() - loader.source = Qt.resolvedUrl(Wallpaper.fullContentPath) + loader.source = Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute) } // Replace wallpaper with GIF @@ -78,23 +78,23 @@ Rectangle { case InstalledType.HTMLWallpaper: loader.setSource("qrc:/WebView.qml", { "url": Qt.resolvedUrl( - Wallpaper.fullContentPath) + Wallpaper.projectSourceFileAbsolute) }) break case InstalledType.QMLWallpaper: - loader.source = Qt.resolvedUrl(Wallpaper.fullContentPath) + loader.source = Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute) fadeIn() break case InstalledType.WebsiteWallpaper: loader.setSource("qrc:/WebsiteWallpaper.qml", { - "url": Wallpaper.fullContentPath + "url": Wallpaper.projectSourceFileAbsolute }) fadeIn() break case InstalledType.GifWallpaper: loader.setSource("qrc:/GifWallpaper.qml", { "source": Qt.resolvedUrl( - Wallpaper.fullContentPath) + Wallpaper.projectSourceFileAbsolute) }) fadeIn() break @@ -261,11 +261,11 @@ Rectangle { font.pointSize: 14 } Text { - text: "basePath " + Wallpaper.basePath + text: "projectPath " + Wallpaper.projectPath font.pointSize: 14 } Text { - text: "fullContentPath " + Wallpaper.fullContentPath + text: "projectSourceFileAbsolute " + Wallpaper.projectSourceFileAbsolute font.pointSize: 14 } Text { diff --git a/ScreenPlayWallpaper/WebView.qml b/ScreenPlayWallpaper/WebView.qml index c3cd2645..6b1ea5e0 100644 --- a/ScreenPlayWallpaper/WebView.qml +++ b/ScreenPlayWallpaper/WebView.qml @@ -26,7 +26,7 @@ Item { var src = "" src += "var videoPlayer = document.getElementById('videoPlayer');" src += "var videoSource = document.getElementById('videoSource');" - src += "videoSource.src = '" + Wallpaper.fullContentPath + "';" + src += "videoSource.src = '" + Wallpaper.projectSourceFileAbsolute + "';" src += "videoPlayer.load();" src += "videoPlayer.volume = " + Wallpaper.volume + ";" src += "videoPlayer.setAttribute('style', 'object-fit :" + Wallpaper.fillMode + ";');" diff --git a/ScreenPlayWallpaper/src/basewindow.cpp b/ScreenPlayWallpaper/src/basewindow.cpp index 9cb19b9a..4fc3a29f 100644 --- a/ScreenPlayWallpaper/src/basewindow.cpp +++ b/ScreenPlayWallpaper/src/basewindow.cpp @@ -49,12 +49,12 @@ BaseWindow::BaseWindow( } setAppID(appID); - setContentBasePath(projectFilePath); + setProjectPath(projectFilePath); setOSVersion(QSysInfo::productVersion()); if (projectFilePath == "test") { setType(ScreenPlay::InstalledType::InstalledType::QMLWallpaper); - setFullContentPath("qrc:/Test.qml"); + setProjectSourceFileAbsolute({ "qrc:/Test.qml" }); setupLiveReloading(); return; } @@ -82,16 +82,15 @@ BaseWindow::BaseWindow( qCritical() << "Cannot parse Wallpaper type from value" << project.value("type"); } - setBasePath(QUrl::fromUserInput(projectFilePath).toLocalFile()); - if (m_type == ScreenPlay::InstalledType::InstalledType::WebsiteWallpaper) { if (!project.contains("url")) { qFatal("No url was specified for a websiteWallpaper!"); QApplication::exit(-5); } - setFullContentPath(project.value("url").toString()); + setProjectSourceFileAbsolute(project.value("url").toString()); } else { - setFullContentPath("file:///" + projectFilePath + "/" + project.value("file").toString()); + setProjectSourceFile(project.value("file").toString()); + setProjectSourceFileAbsolute(QUrl::fromLocalFile(projectFilePath + "/" + projectSourceFile())); } setupLiveReloading(); @@ -181,9 +180,9 @@ void BaseWindow::replaceWallpaper( } if (type.contains("websiteWallpaper", Qt::CaseInsensitive)) { - setFullContentPath(file); + setProjectSourceFileAbsolute(file); } else { - setFullContentPath("file:///" + absolutePath + "/" + file); + setProjectSourceFileAbsolute(QUrl::fromLocalFile(absolutePath + "/" + file)); } if (m_type == ScreenPlay::InstalledType::InstalledType::QMLWallpaper || m_type == ScreenPlay::InstalledType::InstalledType::HTMLWallpaper) @@ -201,7 +200,7 @@ void BaseWindow::replaceWallpaper( */ QString BaseWindow::loadFromFile(const QString& filename) { - QFile file(basePath() + "/" + filename); + QFile file(projectPath() + "/" + filename); if (!file.open(QIODevice::ReadOnly)) { qWarning() << "Could not loadFromFile: " << file.fileName(); file.close(); @@ -238,5 +237,5 @@ void BaseWindow::setupLiveReloading() QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, timeoutLambda); QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, timeoutLambda); QObject::connect(&m_liveReloadLimiter, &QTimer::timeout, this, reloadQMLLambda); - m_fileSystemWatcher.addPaths({ m_contentBasePath }); + m_fileSystemWatcher.addPaths({ projectPath() }); } diff --git a/ScreenPlayWallpaper/src/basewindow.h b/ScreenPlayWallpaper/src/basewindow.h index 9e32bca0..f19d76c6 100644 --- a/ScreenPlayWallpaper/src/basewindow.h +++ b/ScreenPlayWallpaper/src/basewindow.h @@ -70,11 +70,12 @@ public: Q_PROPERTY(QVector activeScreensList READ activeScreensList WRITE setActiveScreensList NOTIFY activeScreensListChanged) Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged) - Q_PROPERTY(QString basePath READ basePath WRITE setBasePath NOTIFY basePathChanged) - Q_PROPERTY(QString fullContentPath READ fullContentPath WRITE setFullContentPath NOTIFY fullContentPathChanged) - Q_PROPERTY(QString contentBasePath READ contentBasePath WRITE setContentBasePath NOTIFY contentBasePathChanged) Q_PROPERTY(QString fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) + Q_PROPERTY(QString projectPath READ projectPath WRITE setProjectPath NOTIFY projectPathChanged) + Q_PROPERTY(QString projectSourceFile READ projectSourceFile WRITE setProjectSourceFile NOTIFY projectSourceFileChanged) + Q_PROPERTY(QUrl projectSourceFileAbsolute READ projectSourceFileAbsolute WRITE setProjectSourceFileAbsolute NOTIFY projectSourceFileAbsoluteChanged) + Q_PROPERTY(bool loops READ loops WRITE setLoops NOTIFY loopsChanged) Q_PROPERTY(bool isPlaying READ isPlaying WRITE setIsPlaying NOTIFY isPlayingChanged) Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged) @@ -99,7 +100,6 @@ public: bool isPlaying() const { return m_isPlaying; } float playbackRate() const { return m_playbackRate; } ScreenPlay::InstalledType::InstalledType type() const { return m_type; } - QString fullContentPath() const { return m_fullContentPath; } QString appID() const { return m_appID; } QString OSVersion() const { return m_OSVersion; } bool muted() const { return m_muted; } @@ -111,10 +111,11 @@ public: QVector activeScreensList() const { return m_activeScreensList; } bool checkWallpaperVisible() const { return m_checkWallpaperVisible; } bool visualsPaused() const { return m_visualsPaused; } - QString basePath() const { return m_basePath; } bool debugMode() const { return m_debugMode; } ScreenPlaySDK* sdk() const { return m_sdk.get(); } - const QString& contentBasePath() const { return m_contentBasePath; } + const QString& projectPath() const { return m_projectPath; } + const QString& projectSourceFile() const { return m_projectSourceFile; } + const QUrl& projectSourceFileAbsolute() const { return m_projectSourceFileAbsolute; } signals: void qmlExit(); @@ -127,7 +128,6 @@ signals: void isPlayingChanged(bool isPlaying); void playbackRateChanged(float playbackRate); void typeChanged(ScreenPlay::InstalledType::InstalledType type); - void fullContentPathChanged(QString fullContentPath); void appIDChanged(QString appID); void qmlSceneValueReceived(QString key, QString value); void OSVersionChanged(QString OSVersion); @@ -140,11 +140,11 @@ signals: void activeScreensListChanged(QVector activeScreensList); void checkWallpaperVisibleChanged(bool checkWallpaperVisible); void visualsPausedChanged(bool visualsPaused); - void basePathChanged(QString basePath); void debugModeChanged(bool debugMode); void sdkChanged(ScreenPlaySDK* sdk); - - void contentBasePathChanged(const QString&); + void projectPathChanged(const QString& rojectPath); + void projectSourceFileChanged(const QString& projectSourceFile); + void projectSourceFileAbsoluteChanged(const QUrl& rojectSourceFileAbsolute); public slots: virtual void destroyThis() { } @@ -207,14 +207,6 @@ public slots: m_type = type; emit typeChanged(m_type); } - void setFullContentPath(QString fullContentPath) - { - if (m_fullContentPath == fullContentPath) - return; - - m_fullContentPath = fullContentPath; - emit fullContentPathChanged(m_fullContentPath); - } void setAppID(QString appID) { if (m_appID == appID) @@ -319,15 +311,6 @@ public slots: m_visualsPaused = visualsPaused; emit visualsPausedChanged(m_visualsPaused); } - void setBasePath(QString basePath) - { - if (m_basePath == basePath) - return; - - m_basePath = basePath; - emit basePathChanged(m_basePath); - } - void setDebugMode(bool debugMode) { if (m_debugMode == debugMode) @@ -344,12 +327,28 @@ public slots: emit sdkChanged(sdk); } - void setContentBasePath(const QString& contentBasePath) + void setProjectPath(const QString& projectPath) { - if (m_contentBasePath == contentBasePath) + if (m_projectPath == projectPath) return; - m_contentBasePath = contentBasePath; - emit contentBasePathChanged(m_contentBasePath); + m_projectPath = projectPath; + emit projectPathChanged(m_projectPath); + } + + void setProjectSourceFile(const QString& projectSourceFile) + { + if (m_projectSourceFile == projectSourceFile) + return; + m_projectSourceFile = projectSourceFile; + emit projectSourceFileChanged(m_projectSourceFile); + } + + void setProjectSourceFileAbsolute(const QUrl& projectSourceFileAbsolute) + { + if (m_projectSourceFileAbsolute == projectSourceFileAbsolute) + return; + m_projectSourceFileAbsolute = projectSourceFileAbsolute; + emit projectSourceFileAbsoluteChanged(m_projectSourceFileAbsolute); } private: @@ -368,7 +367,6 @@ private: float m_playbackRate { 1.0f }; float m_currentTime { 0.0f }; - QString m_fullContentPath; QString m_appID; ScreenPlay::InstalledType::InstalledType m_type = ScreenPlay::InstalledType::InstalledType::Unknown; @@ -379,9 +377,11 @@ private: QVector m_activeScreensList; QFileSystemWatcher m_fileSystemWatcher; QSysInfo m_sysinfo; - QString m_basePath; bool m_debugMode = false; std::unique_ptr m_sdk; QString m_contentBasePath; QTimer m_liveReloadLimiter; + QString m_projectPath; + QString m_projectSourceFile; + QUrl m_projectSourceFileAbsolute; }; diff --git a/ScreenPlayWidget/Widget.qml b/ScreenPlayWidget/Widget.qml index 01bf230e..aecb0edb 100644 --- a/ScreenPlayWidget/Widget.qml +++ b/ScreenPlayWidget/Widget.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.3 import QtWebEngine 1.8 import ScreenPlayWidget 1.0 +import ScreenPlay.Enums.InstalledType 1.0 Item { id: mainWindow @@ -67,11 +68,13 @@ Item { anchors.fill: parent asynchronous: true Component.onCompleted: { - if (Widget.type === "QMLWidget") { - loader.source = Qt.resolvedUrl(Widget.sourcePath) - print("loader.source", loader.source) - } else if (Widget.type === "HTMLWidget") { + switch (Widget.type) { + case InstalledType.QMLWidget: + loader.source = Qt.resolvedUrl( Widget.projectSourceFileAbsolute) + break + case InstalledType.HTMLWidget: loader.sourceComponent = webViewComponent + break } } onStatusChanged: { diff --git a/ScreenPlayWidget/main.cpp b/ScreenPlayWidget/main.cpp index 46df6ec1..fba1bda1 100644 --- a/ScreenPlayWidget/main.cpp +++ b/ScreenPlayWidget/main.cpp @@ -11,13 +11,12 @@ int main(int argc, char* argv[]) QApplication app(argc, argv); - QStringList argumentList = app.arguments(); + const QStringList argumentList = app.arguments(); // If we start with only one argument (path, appID, type), // it means we want to test a single widget if (argumentList.length() == 1) { - // WidgetWindow spwmw("test", { 0, 0 }, "appid", "qmlWidget"); - //WidgetWindow spwmw("C:\\Program Files (x86)\\Steam\\steamapps\\workshop\\content\\672870\\2136442401", "appid", "qmlWidget", { 0, 0 }); + //WidgetWindow spwmw("test", "appid", "qmlWidget", { 0, 0 }); WidgetWindow spwmw("C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/2136442401", "appid", "qmlWidget", { 0, 0 }); return app.exec(); } @@ -39,8 +38,11 @@ int main(int argc, char* argv[]) positionY = 0; } - // 1. Project path, 2. AppID, 3. Type, 4. Posx, 5. PosY - WidgetWindow spwmw(argumentList.at(1), argumentList.at(2), argumentList.at(3), QPoint { positionX, positionY }); + WidgetWindow spwmw( + argumentList.at(1), // Project path, + argumentList.at(2), // AppID + argumentList.at(3), // Type + QPoint { positionX, positionY }); return app.exec(); } diff --git a/ScreenPlayWidget/src/widgetwindow.cpp b/ScreenPlayWidget/src/widgetwindow.cpp index d89e5564..4fadcbc3 100644 --- a/ScreenPlayWidget/src/widgetwindow.cpp +++ b/ScreenPlayWidget/src/widgetwindow.cpp @@ -24,21 +24,22 @@ WidgetWindow::WidgetWindow( const QPoint& position) : QObject(nullptr) , m_appID { appID } - , m_type { type } , m_position { position } + , m_sdk { std::make_unique(appID, type) } { + qRegisterMetaType(); + qmlRegisterUncreatableMetaObject(ScreenPlay::InstalledType::staticMetaObject, + "ScreenPlay.Enums.InstalledType", + 1, 0, + "InstalledType", + "Error: only enums"); + m_sdk = std::make_unique(appID, type); QObject::connect(m_sdk.get(), &ScreenPlaySDK::sdkDisconnected, this, &WidgetWindow::qmlExit); QObject::connect(m_sdk.get(), &ScreenPlaySDK::incommingMessage, this, &WidgetWindow::messageReceived); - if (!ScreenPlayUtil::getAvailableWidgets().contains(m_type, Qt::CaseSensitivity::CaseInsensitive)) { - QApplication::exit(-4); - } - - setType(type); - Qt::WindowFlags flags = m_window.flags(); m_window.setFlags(flags | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::BypassWindowManagerHint | Qt::SplashScreen); @@ -52,17 +53,23 @@ WidgetWindow::WidgetWindow( #endif if (projectPath == "test") { - setSourcePath("qrc:/test.qml"); + setProjectSourceFileAbsolute({ "qrc:/test.qml" }); + setType(ScreenPlay::InstalledType::InstalledType::QMLWidget); } else { auto projectOpt = ScreenPlayUtil::openJsonFileToObject(projectPath + "/project.json"); - if (projectOpt.has_value()) { + if (!projectOpt.has_value()) { qWarning() << "Unable to parse project file!"; - QApplication::exit(-1); } m_project = projectOpt.value(); - QString fullPath = "file:///" + projectPath + "/" + m_project.value("file").toString(); - setSourcePath(fullPath); + setProjectSourceFile(m_project.value("file").toString()); + setProjectSourceFileAbsolute(QUrl::fromLocalFile(projectPath + "/" + projectSourceFile())); + + if (auto typeOpt = ScreenPlayUtil::getInstalledTypeFromString(m_project.value("type").toString())) { + setType(typeOpt.value()); + } else { + qWarning() << "Cannot parse Wallpaper type from value" << m_project.value("type"); + } } m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering); @@ -72,6 +79,7 @@ WidgetWindow::WidgetWindow( m_window.show(); // Do not trigger position changed save reuqest on startup + sdk()->start(); QTimer::singleShot(1000, this, [=, this]() { // We limit ourself to only update the position every 500ms! auto sendPositionUpdate = [this]() { diff --git a/ScreenPlayWidget/src/widgetwindow.h b/ScreenPlayWidget/src/widgetwindow.h index 3396d6b9..e41e82f0 100644 --- a/ScreenPlayWidget/src/widgetwindow.h +++ b/ScreenPlayWidget/src/widgetwindow.h @@ -55,9 +55,9 @@ #include #endif -#include - +#include "ScreenPlayUtil/util.h" #include "screenplaysdk.h" +#include class WidgetWindow : public QObject { Q_OBJECT @@ -70,46 +70,33 @@ public: const QPoint& position); Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged) - Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) - Q_PROPERTY(QString projectConfig READ projectConfig WRITE setProjectConfig NOTIFY projectConfigChanged) - Q_PROPERTY(QString sourcePath READ sourcePath WRITE setSourcePath NOTIFY sourcePathChanged) + Q_PROPERTY(QString projectPath READ projectPath WRITE setProjectPath NOTIFY projectPathChanged) + Q_PROPERTY(QString projectSourceFile READ projectSourceFile WRITE setProjectSourceFile NOTIFY projectSourceFileChanged) + Q_PROPERTY(QUrl projectSourceFileAbsolute READ projectSourceFileAbsolute WRITE setProjectSourceFileAbsolute NOTIFY projectSourceFileAbsoluteChanged) Q_PROPERTY(QPoint position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(ScreenPlay::InstalledType::InstalledType type READ type WRITE setType NOTIFY typeChanged) + Q_PROPERTY(ScreenPlaySDK* sdk READ sdk WRITE setSdk NOTIFY sdkChanged) - QString appID() const - { - return m_appID; - } - - QString type() const - { - return m_type; - } - - QString projectConfig() const - { - return m_projectConfig; - } - - QString sourcePath() const - { - return m_sourcePath; - } - - QPoint position() const - { - return m_position; - } + QString appID() const { return m_appID; } + QPoint position() const { return m_position; } + const QString& projectPath() const { return m_projectPath; } + ScreenPlay::InstalledType::InstalledType type() const { return m_type; } + const QString& projectSourceFile() const { return m_projectSourceFile; } + const QUrl& projectSourceFileAbsolute() const { return m_projectSourceFileAbsolute; } + ScreenPlaySDK* sdk() const { return m_sdk.get(); } signals: void qmlExit(); void appIDChanged(QString appID); - void typeChanged(QString type); - void projectConfigChanged(QString projectConfig); - void sourcePathChanged(QString sourcePath); void qmlSceneValueReceived(QString key, QString value); - void positionChanged(QPoint position); + void projectPathChanged(const QString& projectPath); + void typeChanged(ScreenPlay::InstalledType::InstalledType); + void projectSourceFileChanged(const QString& projectSourceFile); + void projectSourceFileAbsoluteChanged(const QUrl& projectSourceFileAbsolute); + + void sdkChanged(ScreenPlaySDK*); public slots: void setSize(QSize size); @@ -128,30 +115,6 @@ public slots: m_appID = appID; emit appIDChanged(m_appID); } - void setType(QString type) - { - if (m_type == type) - return; - - m_type = type; - emit typeChanged(m_type); - } - void setProjectConfig(QString projectConfig) - { - if (m_projectConfig == projectConfig) - return; - - m_projectConfig = projectConfig; - emit projectConfigChanged(m_projectConfig); - } - void setSourcePath(QString sourcePath) - { - if (m_sourcePath == sourcePath) - return; - - m_sourcePath = sourcePath; - emit sourcePathChanged(m_sourcePath); - } QPointF cursorPos() { return QCursor::pos(); } @@ -168,21 +131,61 @@ public slots: emit positionChanged(m_position); } -private: - QString m_appID { "" }; - QString m_type { "qmlWidget" }; - QString m_projectConfig { "" }; - QString m_sourcePath { "" }; + void setProjectPath(const QString& projectPath) + { + if (m_projectPath == projectPath) + return; + m_projectPath = projectPath; + emit projectPathChanged(m_projectPath); + } + void setType(ScreenPlay::InstalledType::InstalledType Type) + { + if (m_type == Type) + return; + m_type = Type; + emit typeChanged(m_type); + } + + void setProjectSourceFile(const QString& ProjectSourceFile) + { + if (m_projectSourceFile == ProjectSourceFile) + return; + m_projectSourceFile = ProjectSourceFile; + emit projectSourceFileChanged(m_projectSourceFile); + } + + void setProjectSourceFileAbsolute(const QUrl& projectSourceFileAbsolute) + { + if (m_projectSourceFileAbsolute == projectSourceFileAbsolute) + return; + m_projectSourceFileAbsolute = projectSourceFileAbsolute; + emit projectSourceFileAbsoluteChanged(m_projectSourceFileAbsolute); + } + + void setSdk(ScreenPlaySDK* sdk) + { + if (m_sdk.get() == sdk) + return; + m_sdk.reset(sdk); + emit sdkChanged(sdk); + } + +private: + QString m_appID; + QString m_projectPath; QJsonObject m_project; QPoint m_clickPos = { 0, 0 }; QPoint m_lastPos = { 0, 0 }; + QPoint m_position = { 0, 0 }; QQuickView m_window; + std::unique_ptr m_sdk; + QTimer m_positionMessageLimiter; + ScreenPlay::InstalledType::InstalledType m_type; #ifdef Q_OS_WIN HWND m_hwnd; #endif - QPoint m_position; - std::unique_ptr m_sdk; - QTimer m_positionMessageLimiter; + QString m_projectSourceFile; + QUrl m_projectSourceFileAbsolute; };