From c5ec7e7bff3b9e3982d9338bba78eb8e6ba79bc8 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Fri, 20 Jan 2023 14:42:48 +0100 Subject: [PATCH] WIP refactor ScreenPlayWallpaper This is Windows only for now: Make Classes default constructible. We now have: setup(): - Can return status of the input data. This is most important, because we can now properly exit if this fails - We now use the same ProjectFile struct as we do in InstalledListModel - Gets called on all platforms start(): - Platform specific code Move argument parsing into main --- .vscode/launch.json | 21 ++- ScreenPlay/inc/public/ScreenPlay/util.h | 7 +- ScreenPlay/main.cpp | 8 +- ScreenPlay/src/installedlistmodel.cpp | 4 +- ScreenPlay/src/screenplaywallpaper.cpp | 3 +- ScreenPlaySDK/src/screenplaysdk.cpp | 5 + .../inc/public/ScreenPlayUtil/projectfile.h | 6 +- ScreenPlayUtil/src/projectfile.cpp | 166 ++++++++++-------- ScreenPlayWallpaper/main.cpp | 138 ++++++++------- ScreenPlayWallpaper/src/basewindow.cpp | 104 ++++------- ScreenPlayWallpaper/src/basewindow.h | 21 ++- .../src/windowsdesktopproperties.cpp | 2 +- .../src/windowsdesktopproperties.h | 2 +- ScreenPlayWallpaper/src/winwindow.cpp | 92 +++------- ScreenPlayWallpaper/src/winwindow.h | 11 +- 15 files changed, 274 insertions(+), 316 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1949243e..9ce73c3f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ }, { - "name": "Windows Debug ScreenPlay", + "name": "ScreenPlay Windows Debug", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/../build_ScreenPlay_Qt_6.4.2_MSVC_Debug/bin/ScreenPlay.exe", @@ -34,7 +34,7 @@ "visualizerFile": "${workspaceFolder}/.vscode/qt.natvis.xml" }, { - "name": "Windows RelWithDebInfo ScreenPlay", + "name": "ScreenPlay Windows RelWithDebInfo", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/../build_ScreenPlay_Qt_6.4.2_MSVC_RelWithDebInfo/bin/ScreenPlay.exe", @@ -48,6 +48,23 @@ } ], "visualizerFile": "${workspaceFolder}/.vscode/qt.natvis.xml" + }, + { + + "name": "ScreenPlayWallpaper Windows Debug", + "type": "cppvsdbg", + "request": "launch", + "program": "${workspaceFolder}/../build_ScreenPlay_Qt_6.4.2_MSVC_Debug/bin/ScreenPlayWallpaper.exe", + "args": [], + "preLaunchTask": "CMake: build", + "cwd": "${workspaceFolder}", + "environment": [ + { + "name": "Path", + "value": "${env:Path};${workspaceFolder}\\..\\aqt\\6.4.2\\msvc2019_64\\bin\\;${workspaceFolder}\\..\\aqt\\6.4.2\\msvc2019_64\\modules\\;${workspaceFolder}\\..\\aqt\\6.4.2\\msvc2019_64\\qml\\;" + } + ], + "visualizerFile": "${workspaceFolder}/.vscode/qt.natvis.xml" } ] } \ No newline at end of file diff --git a/ScreenPlay/inc/public/ScreenPlay/util.h b/ScreenPlay/inc/public/ScreenPlay/util.h index 8a6be3b3..15cf3e78 100644 --- a/ScreenPlay/inc/public/ScreenPlay/util.h +++ b/ScreenPlay/inc/public/ScreenPlay/util.h @@ -31,8 +31,8 @@ #include namespace QArchive { - class DiskCompressor; - class DiskExtractor; +class DiskCompressor; +class DiskExtractor; } namespace ScreenPlay { @@ -84,7 +84,7 @@ public slots: QString toLocal(const QString& url) const; bool exportProject(QString contentPath, QString exportFileName); bool importProject(QString archivePath, QString extractionPath); - void requestAllLicenses() ; + void requestAllLicenses(); void requestDataProtection(); bool fileExists(const QString& filePath) const; @@ -121,7 +121,6 @@ public slots: emit debugMessagesChanged(m_debugMessages); } - private: QString m_debugMessages {}; QFuture m_requestAllLicensesFuture; diff --git a/ScreenPlay/main.cpp b/ScreenPlay/main.cpp index f6a640bf..0120e010 100644 --- a/ScreenPlay/main.cpp +++ b/ScreenPlay/main.cpp @@ -17,10 +17,10 @@ Q_IMPORT_QML_PLUGIN(ScreenPlayWorkshopPlugin) int main(int argc, char* argv[]) { - #if defined(Q_OS_WIN) - // https://bugreports.qt.io/browse/QTBUG-72028 - qputenv("QT_QPA_PLATFORM", "windows:darkmode=2"); - #endif +#if defined(Q_OS_WIN) + // https://bugreports.qt.io/browse/QTBUG-72028 + qputenv("QT_QPA_PLATFORM", "windows:darkmode=2"); +#endif QApplication qtGuiApp(argc, argv); ScreenPlay::App app; diff --git a/ScreenPlay/src/installedlistmodel.cpp b/ScreenPlay/src/installedlistmodel.cpp index 989ba550..6ce6014c 100644 --- a/ScreenPlay/src/installedlistmodel.cpp +++ b/ScreenPlay/src/installedlistmodel.cpp @@ -193,8 +193,8 @@ void InstalledListModel::append(const QString& projectJsonFilePath) beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size()); ProjectFile projectFile; projectFile.projectJsonFilePath = QFileInfo(projectJsonFilePath); - if(!projectFile.init()){ - qWarning() << "Invalid project at "<< projectJsonFilePath; + if (!projectFile.init()) { + qWarning() << "Invalid project at " << projectJsonFilePath; return; } m_screenPlayFiles.append(std::move(projectFile)); diff --git a/ScreenPlay/src/screenplaywallpaper.cpp b/ScreenPlay/src/screenplaywallpaper.cpp index 9359b8e4..3a51cd06 100644 --- a/ScreenPlay/src/screenplaywallpaper.cpp +++ b/ScreenPlay/src/screenplaywallpaper.cpp @@ -158,9 +158,8 @@ void ScreenPlayWallpaper::close() */ void ScreenPlayWallpaper::processExit(int exitCode, QProcess::ExitStatus exitStatus) { - Q_UNUSED(exitStatus) if (exitCode != 0) - qWarning() << "WARNING EXIT CODE: " << exitCode; + qWarning() << "WARNING EXIT CODE: " << exitCode << exitStatus; } /*! diff --git a/ScreenPlaySDK/src/screenplaysdk.cpp b/ScreenPlaySDK/src/screenplaysdk.cpp index fe036e7f..6a7bf1da 100644 --- a/ScreenPlaySDK/src/screenplaysdk.cpp +++ b/ScreenPlaySDK/src/screenplaysdk.cpp @@ -54,6 +54,11 @@ void ScreenPlaySDK::sendMessage(const QJsonObject& obj) void ScreenPlaySDK::connected() { m_firstConnectionTimer.stop(); + if (m_appID.isEmpty() || m_type.isEmpty()) { + qCritical() << "Unable to connect with empyt: " << m_appID << m_type; + emit disconnected(); + return; + } QByteArray welcomeMessage = QString(m_appID + "," + m_type).toUtf8(); m_socket.write(welcomeMessage); diff --git a/ScreenPlayUtil/inc/public/ScreenPlayUtil/projectfile.h b/ScreenPlayUtil/inc/public/ScreenPlayUtil/projectfile.h index ed39ac83..c1cfe5c9 100644 --- a/ScreenPlayUtil/inc/public/ScreenPlayUtil/projectfile.h +++ b/ScreenPlayUtil/inc/public/ScreenPlayUtil/projectfile.h @@ -34,13 +34,17 @@ struct ProjectFile { QString title; QString description; // Filenames - QString file; + QString file; // myFancyVideo.mp QString preview; QString previewGIF; // Path to project.json QFileInfo projectJsonFilePath; // Folder name QString folderName; + // Website Wallpaper + QUrl url; + // Video Wallpaper + ScreenPlay::VideoCodec::VideoCodec videoCodec; QVariant publishedFileID { 0 }; QStringList tags; diff --git a/ScreenPlayUtil/src/projectfile.cpp b/ScreenPlayUtil/src/projectfile.cpp index 40852f1c..d84c141e 100644 --- a/ScreenPlayUtil/src/projectfile.cpp +++ b/ScreenPlayUtil/src/projectfile.cpp @@ -2,89 +2,111 @@ namespace ScreenPlay { - bool ProjectFile::init() - { - if(!isValid()) +bool ProjectFile::init() +{ + if (!isValid()) + return false; + + const auto jsonObjOpt = ScreenPlayUtil::openJsonFileToObject(projectJsonFilePath.absoluteFilePath()); + QDir folder = projectJsonFilePath.dir(); + folderName = folder.dirName(); + QFileInfo folderInfo(folder.path()); + lastModified = folderInfo.birthTime(); + if (folderInfo.birthTime().date() == QDateTime::currentDateTime().date()) + isNew = true; + + if (!jsonObjOpt.has_value()) + return false; + + const QJsonObject& obj = jsonObjOpt.value(); + if (obj.isEmpty()) + return false; + + // Required: + if (!obj.contains("description")) + return false; + description = obj.value("description").toString(); + + if (!obj.contains("file")) + return false; + file = obj.value("file").toString(); + + if (!obj.contains("title")) + return false; + title = obj.value("title").toString(); + + if (!obj.contains("type")) + return false; + + // Optional: + if (obj.contains("previewGIF")) + previewGIF = obj.value("previewGIF").toString(); + + if (obj.contains("url")) + url = QUrl(obj.value("url").toString()); + + if (obj.contains("workshopid")) + publishedFileID = obj.value("workshopid").toInt(0); + + if (obj.contains("previewThumbnail")) { + preview = obj.value("previewThumbnail").toString(); + } else { + if (!obj.contains("preview")) { return false; - - const auto jsonObjOpt = ScreenPlayUtil::openJsonFileToObject(projectJsonFilePath.absoluteFilePath()); - QDir folder = projectJsonFilePath.dir(); - folderName = folder.dirName(); - QFileInfo folderInfo(folder.path()); - lastModified = folderInfo.birthTime(); - if (folderInfo.birthTime().date() == QDateTime::currentDateTime().date()) - isNew = true; - - if(!jsonObjOpt.has_value()) - return false; - - const QJsonObject& obj =jsonObjOpt.value(); - if (obj.isEmpty()) - return false; - - //Required: - if (!obj.contains("description")) - return false; - description = obj.value("description").toString(); - - if (!obj.contains("file")) - return false; - file = obj.value("file").toString(); - - - if (!obj.contains("title")) - return false; - title = obj.value("title").toString(); - - if (!obj.contains("type")) - return false; - - // Optional: - if (obj.contains("previewGIF")) - previewGIF = obj.value("previewGIF").toString(); - - if (obj.contains("workshopid")) - publishedFileID = obj.value("workshopid").toInt(0); - - if (obj.contains("previewThumbnail")) { - preview = obj.value("previewThumbnail").toString(); - } else { - if (!obj.contains("preview")) { - return false; - } - preview = obj.value("preview").toString(); } + preview = obj.value("preview").toString(); + } - if (obj.contains("tags")) { - if (obj.value("tags").isArray()) { - auto tagArray = obj.value("tags").toArray(); - if (tagArray.size() > 0) { - for (const auto& tag : tagArray) { - tags.append(tag.toString()); - } + if (obj.contains("tags")) { + if (obj.value("tags").isArray()) { + auto tagArray = obj.value("tags").toArray(); + if (tagArray.size() > 0) { + for (const auto& tag : tagArray) { + tags.append(tag.toString()); } } } + } - auto typeParsed = ScreenPlayUtil::getInstalledTypeFromString(obj.value("type").toString()); - if (!typeParsed) { - qWarning() << "Type could not parsed from: " << *typeParsed; + auto typeParsed = ScreenPlayUtil::getInstalledTypeFromString(obj.value("type").toString()); + if (!typeParsed) { + qWarning() << "Type could not parsed from: " << *typeParsed; + return false; + } + + type = typeParsed.value(); + if (type == InstalledType::InstalledType::GifWallpaper) { + preview = previewGIF; + } + if (type == ScreenPlay::InstalledType::InstalledType::WebsiteWallpaper) { + if (url.isEmpty()) { + qWarning() << "No url was specified for a websiteWallpaper!"; return false; } + } - type = *typeParsed; - if (type == InstalledType::InstalledType::GifWallpaper) { - preview = previewGIF; + searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(type); + + if (obj.contains("codec")) { + if (auto videoCodecOpt = ScreenPlayUtil::getVideoCodecFromString(obj.value("codec").toString())) { + videoCodec = videoCodecOpt.value(); + } + } else if (type == ScreenPlay::InstalledType::InstalledType::VideoWallpaper) { + qWarning("No videoCodec was specified inside the json object!"); + if (file.endsWith(".mp4")) { + videoCodec = ScreenPlay::VideoCodec::VideoCodec::H264; + } else if (file.endsWith(".webm")) { + videoCodec = ScreenPlay::VideoCodec::VideoCodec::VP8; } - searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(type); - - return true; } - bool ProjectFile::isValid() - { - if(!projectJsonFilePath.isFile()) - return false; - return true; - } + return true; +} +bool ProjectFile::isValid() +{ + if (!projectJsonFilePath.isFile()) + return false; + + return true; +} } diff --git a/ScreenPlayWallpaper/main.cpp b/ScreenPlayWallpaper/main.cpp index 936d49b9..d2e9d5f4 100644 --- a/ScreenPlayWallpaper/main.cpp +++ b/ScreenPlayWallpaper/main.cpp @@ -25,8 +25,13 @@ int main(int argc, char* argv[]) QApplication app(argc, argv); - // This gives us nice clickable output in QtCreator - qSetMessagePattern("%{if-category}%{category}: %{endif}%{message}\n Loc: [%{file}:%{line}]"); +#if defined(Q_OS_WIN) + WinWindow window; +#elif defined(Q_OS_LINUX) + LinuxWindow window; +#elif defined(Q_OS_OSX) + MacWindow window; +#endif // If we start with only one argument (app path) // It means we want to test a single wallpaper @@ -34,74 +39,73 @@ int main(int argc, char* argv[]) // For testing purposes when starting the ScreenPlayWallpaper directly. if (argumentList.length() == 1) { -#if defined(Q_OS_WIN) - // WinWindow window1({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", true, true); - WinWindow window1({ 1 }, "C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/26092021185017", "appID=test", "1", "fill", "videoWallpaper", true, true); -#elif defined(Q_OS_LINUX) - LinuxWindow window({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", false, true); -#elif defined(Q_OS_OSX) - MacWindow window({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", true, true); -#endif - return app.exec(); + window.setActiveScreensList({ 0 }); + // window.setProjectPath("test"); + window.setProjectPath("C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/1958068741"); + window.setAppID("test"); + window.setVolume(1); + window.setFillMode("fill"); + window.setType(ScreenPlay::InstalledType::InstalledType::VideoWallpaper); + window.setCheckWallpaperVisible(true); + window.setDebugMode(true); + } else { + // 8 parameter + 1 OS working directory as the first default paramter + if (argumentList.length() != 9) { + return -3; + } + + const auto activeScreensList = ScreenPlayUtil::parseStringToIntegerList(argumentList.at(1)); + + if (!activeScreensList.has_value()) { + qCritical("Could not activeScreensList"); + return -1; + } + + auto installedType = ScreenPlay::InstalledType::InstalledType::Unknown; + if (auto typeOpt = ScreenPlayUtil::getInstalledTypeFromString(argumentList.at(6))) { + installedType = typeOpt.value(); + } else { + qCritical() << "Cannot parse Wallpaper type from value" << argumentList.at(6); + return -6; + } + + bool okParseCheckWallpaperVisible = false; + const bool checkWallpaperVisible = argumentList.at(7).toInt(&okParseCheckWallpaperVisible); + if (!okParseCheckWallpaperVisible) { + qCritical("Could not parse checkWallpaperVisible"); + return -5; + } + bool okParseVolume = 0.0f; + const float volume = argumentList.at(4).toFloat(&okParseVolume); + if (!okParseVolume) { + qCritical("Could not parse Volume"); + return -6; + } + + QString appID = argumentList.at(3); + if (!appID.startsWith("appID=")) { + qCritical("Invalid appID"); + return -6; + } + appID = appID.remove("appID="); + + window.setActiveScreensList(activeScreensList.value()); + window.setProjectPath(argumentList.at(2)); + window.setAppID(appID); + window.setVolume(volume); + window.setFillMode(argumentList.at(5)); + window.setType(installedType); + window.setCheckWallpaperVisible(checkWallpaperVisible); + window.setDebugMode(false); } - // 8 parameter + 1 OS working directory as the first default paramter - if (argumentList.length() != 9) { - return -3; + const auto setupStatus = window.setup(); + if (setupStatus != BaseWindow::ExitCode::Success) { + return static_cast(setupStatus); } - - const bool debugMode = false; - - const auto activeScreensList = ScreenPlayUtil::parseStringToIntegerList(argumentList.at(1)); - - if (!activeScreensList.has_value()) - return -4; - - // See ScreenPlayWallpaper m_appArgumentsList constructor how the args get created - const QString projectFilePath = argumentList.at(2); - const QString appID = argumentList.at(3); - const QString volume = argumentList.at(4); - const QString fillmode = argumentList.at(5); - const QString type = argumentList.at(6); - - bool okParseCheckWallpaperVisible = false; - bool checkWallpaperVisible = argumentList.at(7).toInt(&okParseCheckWallpaperVisible); - if (!okParseCheckWallpaperVisible) { - qFatal("Could not parse checkWallpaperVisible"); - return -5; + const auto startStatus = window.start(); + if (startStatus != BaseWindow::ExitCode::Success) { + return static_cast(startStatus); } - -#if defined(Q_OS_WIN) - WinWindow window( - activeScreensList.value(), - projectFilePath, - appID, - volume, - fillmode, - type, - checkWallpaperVisible, - debugMode); -#elif defined(Q_OS_LINUX) - LinuxWindow window( - activeScreensList.value(), - projectFilePath, - appID, - volume, - fillmode, - type, - checkWallpaperVisible, - debugMode); -#elif defined(Q_OS_OSX) - MacWindow window( - activeScreensList.value(), - projectFilePath, - appID, - volume, - fillmode, - type, - checkWallpaperVisible, - debugMode); -#endif - return app.exec(); } diff --git a/ScreenPlayWallpaper/src/basewindow.cpp b/ScreenPlayWallpaper/src/basewindow.cpp index ed4e67f6..9582c9b4 100644 --- a/ScreenPlayWallpaper/src/basewindow.cpp +++ b/ScreenPlayWallpaper/src/basewindow.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only #include "basewindow.h" +#include "ScreenPlayUtil/projectfile.h" #include "ScreenPlayUtil/util.h" /*! @@ -15,23 +16,7 @@ \brief . */ -BaseWindow::BaseWindow(QObject* parent) - : QObject(parent) -{ -} - -BaseWindow::BaseWindow( - const QVector activeScreensList, - const QString& projectFilePath, - const QString& type, - const bool checkWallpaperVisible, - const QString& appID, - const bool debugMode) - : QObject(nullptr) - , m_checkWallpaperVisible(checkWallpaperVisible) - , m_activeScreensList(activeScreensList) - , m_debugMode(debugMode) - , m_sdk(std::make_unique(appID, type)) +BaseWindow::BaseWindow() { QApplication::instance()->installEventFilter(this); @@ -50,74 +35,49 @@ BaseWindow::BaseWindow( qmlRegisterType("ScreenPlay.Wallpaper", 1, 0, "Wallpaper"); - if (!appID.contains("appID=")) { - qInfo() << "Invalid appID: " << appID; - qFatal("AppID does not contain appID="); - } - - setAppID(appID); - setProjectPath(projectFilePath); setOSVersion(QSysInfo::productVersion()); +} - if (projectFilePath == "test") { +BaseWindow::ExitCode BaseWindow::setup() +{ + + if (projectPath() == "test") { setType(ScreenPlay::InstalledType::InstalledType::QMLWallpaper); setProjectSourceFileAbsolute({ "qrc:/qml/ScreenPlayWallpaper/qml/Test.qml" }); setupLiveReloading(); - return; + return BaseWindow::Success; + } + ScreenPlay::ProjectFile projectFile; + projectFile.projectJsonFilePath = QFileInfo(projectPath() + "/project.json"); + if (!projectFile.init()) { + qWarning() << "Invalid project at " << projectPath(); + return BaseWindow::ParsingError; } - auto projectOpt = ScreenPlayUtil::openJsonFileToObject(projectFilePath + "/project.json"); - - if (!projectOpt.has_value()) { - QApplication::exit(-5); - } - const QJsonObject project = projectOpt.value(); - - if (!project.contains("type")) { - qFatal("No type was specified inside the json object!"); - QApplication::exit(-3); - } - - if (!project.contains("file") && !project.contains("url")) { - qFatal("No file was specified inside the json object!"); - QApplication::exit(-4); - } - - if (auto typeOpt = ScreenPlayUtil::getInstalledTypeFromString(project.value("type").toString())) { - setType(typeOpt.value()); - - if (this->type() == ScreenPlay::InstalledType::InstalledType::VideoWallpaper) { - if (auto videoCodecOpt = ScreenPlayUtil::getVideoCodecFromString(project.value("videoCodec").toString())) { - setVideoCodec(videoCodecOpt.value()); - } else { - qCritical() << "Cannot parse Wallpaper video codec from value" << project.value("type"); - } - } else if (!project.contains("videoCodec") && this->type() == ScreenPlay::InstalledType::InstalledType::VideoWallpaper) { - qWarning("No videoCodec was specified inside the json object!"); - const QString filename = project.value("file").toString(); - if (filename.endsWith(".mp4")) { - setVideoCodec(ScreenPlay::VideoCodec::VideoCodec::H264); - } else if (filename.endsWith(".webm")) { - setVideoCodec(ScreenPlay::VideoCodec::VideoCodec::VP8); - } - } - - } else { - qCritical() << "Cannot parse Wallpaper type from value" << project.value("type"); - } + setProjectSourceFile(projectFile.file); if (m_type == ScreenPlay::InstalledType::InstalledType::WebsiteWallpaper) { - if (!project.contains("url")) { - qFatal("No url was specified for a websiteWallpaper!"); - QApplication::exit(-5); - } - setProjectSourceFileAbsolute(project.value("url").toString()); + setProjectSourceFileAbsolute(projectFile.url); } else { - setProjectSourceFile(project.value("file").toString()); - setProjectSourceFileAbsolute(QUrl::fromLocalFile(projectFilePath + "/" + projectSourceFile())); + setProjectSourceFileAbsolute(QUrl::fromLocalFile(projectPath() + "/" + projectSourceFile())); } setupLiveReloading(); + + // Debug mode means we start the ScreenPlayWallpaper + // directly without an running ScreenPlay + if (!debugMode()) { + m_sdk = std::make_unique(appID(), QVariant::fromValue(type()).toString()); + // QObject::connect(m_sdk.get(), &ScreenPlaySDK::sdkDisconnected, this, [this]() { + // destroyThis(); + // }); + connect(sdk(), &ScreenPlaySDK::sdkDisconnected, this, &BaseWindow::destroyThis); + connect(sdk(), &ScreenPlaySDK::incommingMessage, this, &BaseWindow::messageReceived); + connect(sdk(), &ScreenPlaySDK::replaceWallpaper, this, &BaseWindow::replaceWallpaper); + sdk()->start(); + } + + return BaseWindow::Success; } /*! diff --git a/ScreenPlayWallpaper/src/basewindow.h b/ScreenPlayWallpaper/src/basewindow.h index 61866910..aa1c4f7b 100644 --- a/ScreenPlayWallpaper/src/basewindow.h +++ b/ScreenPlayWallpaper/src/basewindow.h @@ -24,14 +24,18 @@ class BaseWindow : public QObject { Q_OBJECT public: - BaseWindow(QObject* parent = nullptr); - BaseWindow( - const QVector activeScreensList, - const QString& projectFilePath, - const QString& type, - const bool checkWallpaperVisible, - const QString& appID, - const bool debugMode); + BaseWindow(); + + enum ExitCode { + Success = 0, + ParsingError = 1, + Error = 3, + }; + Q_ENUM(ExitCode) + + virtual BaseWindow::ExitCode setup() final; + + virtual BaseWindow::ExitCode start() = 0; Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) @@ -339,7 +343,6 @@ private: float m_playbackRate { 1.0f }; float m_currentTime { 0.0f }; - QString m_contentBasePath; QString m_projectPath; QString m_projectSourceFile; QString m_appID; diff --git a/ScreenPlayWallpaper/src/windowsdesktopproperties.cpp b/ScreenPlayWallpaper/src/windowsdesktopproperties.cpp index effeb774..ed07b3c0 100644 --- a/ScreenPlayWallpaper/src/windowsdesktopproperties.cpp +++ b/ScreenPlayWallpaper/src/windowsdesktopproperties.cpp @@ -20,7 +20,7 @@ WindowsDesktopProperties::WindowsDesktopProperties(QObject* parent) setIsTiled(settings.value("TileWallpaper").toBool()); QFileInfo defaultBackgroundImageInfo(m_wallpaperPath); - if(defaultBackgroundImageInfo.exists()){ + if (defaultBackgroundImageInfo.exists()) { QImage backgroundImage(defaultBackgroundImageInfo.absoluteFilePath()); setDefaultWallpaperSize(backgroundImage.size()); } diff --git a/ScreenPlayWallpaper/src/windowsdesktopproperties.h b/ScreenPlayWallpaper/src/windowsdesktopproperties.h index bd2ede90..79a805be 100644 --- a/ScreenPlayWallpaper/src/windowsdesktopproperties.h +++ b/ScreenPlayWallpaper/src/windowsdesktopproperties.h @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/ScreenPlayWallpaper/src/winwindow.cpp b/ScreenPlayWallpaper/src/winwindow.cpp index f9dbb920..6c059e9c 100644 --- a/ScreenPlayWallpaper/src/winwindow.cpp +++ b/ScreenPlayWallpaper/src/winwindow.cpp @@ -1,10 +1,17 @@ // SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only #include "winwindow.h" +#include "ScreenPlayUtil/projectfile.h" #include "qqml.h" #include #include #include +/*! + \class WinWindow + \inmodule ScreenPlayWallpaper + \brief ScreenPlayWindow used for the Windows implementation. +*/ + /*! \brief Searches for the worker window for our window to parent to. */ @@ -104,68 +111,21 @@ void WinWindow::setupWindowMouseHook() } } -/*! - \class WinWindow - \inmodule ScreenPlayWallpaper - \brief ScreenPlayWindow used for the Windows implementation. -*/ - -/*! - \brief Creates a window on Windows from the give parameters: - \a activeScreensList - \a projectFilePath - \a appID - \a volume - \a fillmode - \a type - \a checkWallpaperVisible - \a debugMode - */ -WinWindow::WinWindow( - const QVector& activeScreensList, - const QString& projectFilePath, - const QString& appID, - const QString& volume, - const QString& fillmode, - const QString& type, - const bool checkWallpaperVisible, - const bool debugMode) - : BaseWindow( - activeScreensList, - projectFilePath, - type, - checkWallpaperVisible, - appID, - debugMode) - +BaseWindow::ExitCode WinWindow::start() { - auto* guiAppInst = dynamic_cast(QApplication::instance()); - connect(this, &BaseWindow::reloadQML, this, [this]() { - clearComponentCache(); - }); connect( - &m_window, &QQuickView::statusChanged, - this, [](auto status) { - if (status == QQuickView::Status::Error) - QCoreApplication::exit(-1); - }, - Qt::QueuedConnection); - connect(guiAppInst, &QApplication::screenAdded, this, &WinWindow::configureWindowGeometry); - connect(guiAppInst, &QApplication::screenRemoved, this, &WinWindow::configureWindowGeometry); - connect(guiAppInst, &QApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry); - connect(sdk(), &ScreenPlaySDK::sdkDisconnected, this, &WinWindow::destroyThis); - connect(sdk(), &ScreenPlaySDK::incommingMessage, this, &WinWindow::messageReceived); - connect(sdk(), &ScreenPlaySDK::replaceWallpaper, this, &WinWindow::replaceWallpaper); - connect(&m_checkForFullScreenWindowTimer, &QTimer::timeout, this, &WinWindow::checkForFullScreenWindow); - connect( - &m_window, &QQuickView::statusChanged, - this, [](auto status) { + &m_window, &QQuickView::statusChanged, this, [this](auto status) { if (status == QQuickView::Status::Error) { - qInfo() << status; - QCoreApplication::exit(-1); + destroyThis(); } }, Qt::QueuedConnection); + auto* guiAppInst = dynamic_cast(QApplication::instance()); + connect(guiAppInst, &QApplication::screenAdded, this, &WinWindow::configureWindowGeometry); + connect(guiAppInst, &QApplication::screenRemoved, this, &WinWindow::configureWindowGeometry); + connect(guiAppInst, &QApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry); + connect(this, &BaseWindow::reloadQML, this, &WinWindow::clearComponentCache); + connect(&m_checkForFullScreenWindowTimer, &QTimer::timeout, this, &WinWindow::checkForFullScreenWindow); const auto screens = QApplication::screens(); for (const auto& screen : screens) { @@ -175,27 +135,18 @@ WinWindow::WinWindow( m_windowsDesktopProperties = std::make_unique(); m_windowHandle = reinterpret_cast(m_window.winId()); if (!IsWindow(m_windowHandle)) { - qFatal("Could not get a valid window handle!"); + qCritical("Could not get a valid window handle!"); + return BaseWindow::ExitCode::Error; } qRegisterMetaType(); qRegisterMetaType(); - - bool ok = false; - float volumeParsed = volume.toFloat(&ok); - if (!ok) { - qFatal("Could not parse volume"); - } - - setVolume(volumeParsed); - setFillMode(fillmode); - qmlRegisterSingletonInstance("ScreenPlayWallpaper", 1, 0, "Wallpaper", this); configureWindowGeometry(); // We do not support autopause for multi monitor wallpaper if (this->activeScreensList().length() == 1) { - if (checkWallpaperVisible) { + if (checkWallpaperVisible()) { m_checkForFullScreenWindowTimer.start(10); } } @@ -204,9 +155,9 @@ WinWindow::WinWindow( setupWindowMouseHook(); }); - if (!debugMode) - sdk()->start(); + return BaseWindow::ExitCode::Success; } + /*! \brief Calls ShowWindow function to set the main window in/visible. */ @@ -228,6 +179,7 @@ void WinWindow::setVisible(bool show) nice fade out animation first. Then the UI is responsible for calling WinWindow::terminate(). */ + void WinWindow::destroyThis() { emit qmlExit(); diff --git a/ScreenPlayWallpaper/src/winwindow.h b/ScreenPlayWallpaper/src/winwindow.h index 3231bf76..1bee0fa7 100644 --- a/ScreenPlayWallpaper/src/winwindow.h +++ b/ScreenPlayWallpaper/src/winwindow.h @@ -26,17 +26,10 @@ class WinWindow : public BaseWindow { Q_PROPERTY(WindowsDesktopProperties* windowsDesktopProperties READ windowsDesktopProperties WRITE setWindowsDesktopProperties NOTIFY windowsDesktopPropertiesChanged) public: - explicit WinWindow( - const QVector& activeScreensList, - const QString& projectFilePath, - const QString& appID, - const QString& volume, - const QString& fillmode, const QString& type, - const bool checkWallpaperVisible, - const bool debugMode = false); - WindowsDesktopProperties* windowsDesktopProperties() const { return m_windowsDesktopProperties.get(); } + BaseWindow::ExitCode start() override; + public slots: void setVisible(bool show) override; void destroyThis() override;