diff --git a/ScreenPlay/src/util.h b/ScreenPlay/src/util.h index 27379616..3fd4380d 100644 --- a/ScreenPlay/src/util.h +++ b/ScreenPlay/src/util.h @@ -93,7 +93,7 @@ signals: void requestNavigation(QString nav); void requestNavigationActive(bool isActive); void requestToggleWallpaperConfiguration(); - void setSidebarItem(QString folderName, InstalledType::InstalledType type); + void setSidebarItem(QString folderName, ScreenPlay::InstalledType::InstalledType type); void allLicenseLoaded(QString licensesText); void allDataProtectionLoaded(QString dataProtectionText); void debugMessagesChanged(QString debugMessages); diff --git a/ScreenPlayWallpaper/CMakeLists.txt b/ScreenPlayWallpaper/CMakeLists.txt index 110ac918..b09d11ac 100644 --- a/ScreenPlayWallpaper/CMakeLists.txt +++ b/ScreenPlayWallpaper/CMakeLists.txt @@ -41,7 +41,7 @@ if(APPLE) set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE true) endif() -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Quick Qt5::Gui Qt5::Widgets Qt5::Core Qt5::WebEngine ScreenPlaySDK) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Quick Qt5::Gui Qt5::Widgets Qt5::Core Qt5::WebEngine ScreenPlaySDK ScreenPlayUtil) if(APPLE) target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Cocoa") diff --git a/ScreenPlayWallpaper/Wallpaper.qml b/ScreenPlayWallpaper/Wallpaper.qml index b59fb627..0337ffe4 100644 --- a/ScreenPlayWallpaper/Wallpaper.qml +++ b/ScreenPlayWallpaper/Wallpaper.qml @@ -1,6 +1,7 @@ import QtQuick 2.14 import QtQml 2.14 import ScreenPlayWallpaper 1.0 +import ScreenPlay.Enums.InstalledType 1.0 import ScreenPlay.Shader 1.0 import "ShaderWrapper" as ShaderWrapper @@ -56,7 +57,7 @@ Rectangle { function onReloadVideo(oldType) { // We need to check if the old type // was also Video not get called twice - if (oldType === Wallpaper.WallpaperType.Video) + if (oldType === InstalledType.VideoWallpaper) return imgCover.state = "in" @@ -66,33 +67,33 @@ Rectangle { function init() { switch (Wallpaper.type) { - case Wallpaper.WallpaperType.Video: + case InstalledType.VideoWallpaper: loader.source = "qrc:/WebView.qml" break - case Wallpaper.WallpaperType.Html: - loader.webViewUrl = Qt.resolvedUrl(Wallpaper.fullContentPath) - loader.source = "qrc:/WebView.qml" - fadeIn() + case InstalledType.HTMLWallpaper: + loader.setSource("qrc:/WebView.qml", { + "url": Qt.resolvedUrl( + Wallpaper.fullContentPath) + }) break - case Wallpaper.WallpaperType.Qml: + case InstalledType.QMLWallpaper: loader.source = Qt.resolvedUrl(Wallpaper.fullContentPath) - imgCover.state = "out" - fadeIn() + print(loader.source) break - case Wallpaper.WallpaperType.Website: + case InstalledType.WebsiteWallpaper: loader.setSource("qrc:/WebsiteWallpaper.qml", { "url": Wallpaper.fullContentPath }) - fadeIn() break - case Wallpaper.WallpaperType.Gif: + case InstalledType.GifWallpaper: loader.setSource("qrc:/GifWallpaper.qml", { "source": Qt.resolvedUrl( Wallpaper.fullContentPath) }) - fadeIn() break } + + fadeIn() } function fadeIn() { @@ -107,16 +108,7 @@ Rectangle { Loader { id: loader anchors.fill: parent - property string webViewUrl - onStatusChanged: { - if (loader.status === Loader.Ready) { - if (Wallpaper.type === Wallpaper.WallpaperType.Html) { - loader.item.url = loader.webViewUrl - print(loader.item.url, " --- ", loader.webViewUrl) - } - } - } - + onStatusChanged: print(status) Connections { ignoreUnknownSignals: true target: loader.item @@ -135,6 +127,7 @@ Rectangle { right: parent.right } state: "in" + onStateChanged: print(state) sourceSize.width: Wallpaper.width sourceSize.height: Wallpaper.height diff --git a/ScreenPlayWallpaper/WebView.qml b/ScreenPlayWallpaper/WebView.qml index b55b3661..bc341ea1 100644 --- a/ScreenPlayWallpaper/WebView.qml +++ b/ScreenPlayWallpaper/WebView.qml @@ -1,6 +1,6 @@ import QtQuick 2.0 import QtWebEngine 1.8 - +import ScreenPlay.Enums.InstalledType 1.0 import ScreenPlayWallpaper 1.0 Item { @@ -42,9 +42,7 @@ Item { onJavaScriptConsoleMessage: print(lineNumber, message) onLoadProgressChanged: { if ((loadProgress === 100)) { - - if (Wallpaper.type === Wallpaper.WallpaperType.Video) { - + if (Wallpaper.type === InstalledType.VideoWallpaper) { webView.runJavaScript(root.getSetVideoCommand(), function (result) { fadeInTimer.start() @@ -89,7 +87,6 @@ Item { target: Wallpaper function onReloadVideo(oldType) { - webView.runJavaScript(root.getSetVideoCommand()) } diff --git a/ScreenPlayWallpaper/src/basewindow.cpp b/ScreenPlayWallpaper/src/basewindow.cpp index 07326e1a..ca34e133 100644 --- a/ScreenPlayWallpaper/src/basewindow.cpp +++ b/ScreenPlayWallpaper/src/basewindow.cpp @@ -15,14 +15,19 @@ BaseWindow::BaseWindow( { QApplication::instance()->installEventFilter(this); - qRegisterMetaType(); + qRegisterMetaType(); + qmlRegisterUncreatableMetaObject(ScreenPlay::InstalledType::staticMetaObject, + "ScreenPlay.Enums.InstalledType", + 1, 0, + "InstalledType", + "Error: only enums"); qmlRegisterType("ScreenPlay.Wallpaper", 1, 0, "Wallpaper"); setOSVersion(QSysInfo::productVersion()); if (projectFilePath == "test") { - setType(BaseWindow::WallpaperType::Qml); + setType(ScreenPlay::InstalledType::InstalledType::QMLWallpaper); setFullContentPath("qrc:/Test.qml"); setupLiveReloading(); return; @@ -70,10 +75,15 @@ BaseWindow::BaseWindow( QApplication::exit(-4); } - setType(parseWallpaperType(project.value("type").toString().toLower())); + if (auto typeOpt = ScreenPlayUtil::getInstalledTypeFromString(project.value("type").toString())) { + setType(typeOpt.value()); + } else { + qCritical() << "Cannot parse Wallpaper type from value" << project.value("type"); + } + setBasePath(QUrl::fromUserInput(projectFilePath).toLocalFile()); - if (m_type == WallpaperType::Website) { + if (m_type == ScreenPlay::InstalledType::InstalledType::WebsiteWallpaper) { if (!project.contains("url")) { qFatal("No url was specified for a websiteWallpaper!"); QApplication::exit(-5); @@ -154,22 +164,24 @@ void BaseWindow::replaceWallpaper( const QString type, const bool checkWallpaperVisible) { - const WallpaperType oldType = this->type(); + const ScreenPlay::InstalledType::InstalledType oldType = this->type(); setCheckWallpaperVisible(checkWallpaperVisible); setVolume(volume); setFillMode(fillMode); - setType(parseWallpaperType(type)); + if (auto typeOpt = ScreenPlayUtil::getInstalledTypeFromString(type)) { + setType(typeOpt.value()); + } + if (type.contains("websiteWallpaper", Qt::CaseInsensitive)) { setFullContentPath(file); } else { setFullContentPath("file:///" + absolutePath + "/" + file); } - qInfo() << file; - if (m_type == WallpaperType::Qml || m_type == WallpaperType::Html) + if (m_type == ScreenPlay::InstalledType::InstalledType::QMLWallpaper || m_type == ScreenPlay::InstalledType::InstalledType::HTMLWallpaper) emit reloadQML(oldType); - if (m_type == WallpaperType::Video) + if (m_type == ScreenPlay::InstalledType::InstalledType::VideoWallpaper) emit reloadVideo(oldType); } @@ -177,49 +189,15 @@ void BaseWindow::replaceWallpaper( // Loading shader relative to the qml file will be available in Qt 6 QString BaseWindow::loadFromFile(const QString& filename) { - QFile file; - file.setFileName(basePath() + "/" + filename); - qWarning() << " loadFromFile: " << file.fileName() << file.readAll(); - if (file.open(QIODevice::ReadOnly)) { - const QString content = file.readAll(); + QFile file(basePath() + "/" + filename); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "Could not loadFromFile: " << file.fileName(); file.close(); - return content; + return ""; } + const QString content = file.readAll(); file.close(); - qWarning() << "Could not loadFromFile: " << file.fileName(); - return ""; -} - -BaseWindow::WallpaperType BaseWindow::parseWallpaperType(const QString& type) -{ - - if (type.contains("videoWallpaper", Qt::CaseInsensitive)) { - return (BaseWindow::WallpaperType::Video); - } - - if (type.contains("qmlWallpaper", Qt::CaseInsensitive)) { - return (BaseWindow::WallpaperType::Qml); - } - - if (type.contains("htmlWallpaper", Qt::CaseInsensitive)) { - return (BaseWindow::WallpaperType::Html); - } - - if (type.contains("godotWallpaper", Qt::CaseInsensitive)) { - return (BaseWindow::WallpaperType::Godot); - } - - if (type.contains("gifWallpaper", Qt::CaseInsensitive)) { - return (BaseWindow::WallpaperType::Gif); - } - - if (type.contains("websiteWallpaper", Qt::CaseInsensitive)) { - return (BaseWindow::WallpaperType::Website); - } - - qWarning() << "Could not parse Wallpaper type from value: " << type; - - return BaseWindow::WallpaperType::Video; + return content; } void BaseWindow::setupLiveReloading() diff --git a/ScreenPlayWallpaper/src/basewindow.h b/ScreenPlayWallpaper/src/basewindow.h index f9e6a43f..d1abb8d5 100644 --- a/ScreenPlayWallpaper/src/basewindow.h +++ b/ScreenPlayWallpaper/src/basewindow.h @@ -46,6 +46,8 @@ #include #include +#include "ScreenPlayUtil/util.h" + class BaseWindow : public QObject { Q_OBJECT @@ -75,19 +77,9 @@ public: Q_PROPERTY(float playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) Q_PROPERTY(float currentTime READ currentTime WRITE setCurrentTime NOTIFY currentTimeChanged) - Q_PROPERTY(WallpaperType type READ type WRITE setType NOTIFY typeChanged) + Q_PROPERTY(ScreenPlay::InstalledType::InstalledType type READ type WRITE setType NOTIFY typeChanged) Q_PROPERTY(QString OSVersion READ OSVersion WRITE setOSVersion NOTIFY OSVersionChanged) - enum class WallpaperType { - Video, - Html, - Godot, - Qml, - Gif, - Website - }; - Q_ENUM(WallpaperType) - bool loops() const { return m_loops; @@ -108,7 +100,7 @@ public: return m_playbackRate; } - BaseWindow::WallpaperType type() const + ScreenPlay::InstalledType::InstalledType type() const { return m_type; } @@ -180,14 +172,14 @@ public: signals: void qmlExit(); - void reloadQML(const BaseWindow::WallpaperType oldType); - void reloadVideo(const BaseWindow::WallpaperType oldType); + void reloadQML(const ScreenPlay::InstalledType::InstalledType oldType); + void reloadVideo(const ScreenPlay::InstalledType::InstalledType oldType); void loopsChanged(bool loops); void volumeChanged(float volume); void isPlayingChanged(bool isPlaying); void playbackRateChanged(float playbackRate); - void typeChanged(BaseWindow::WallpaperType type); + void typeChanged(ScreenPlay::InstalledType::InstalledType type); void fullContentPathChanged(QString fullContentPath); void appIDChanged(QString appID); void qmlSceneValueReceived(QString key, QString value); @@ -261,7 +253,7 @@ public slots: emit playbackRateChanged(m_playbackRate); } - void setType(BaseWindow::WallpaperType type) + void setType(ScreenPlay::InstalledType::InstalledType type) { if (m_type == type) return; @@ -406,8 +398,6 @@ public slots: } private: - BaseWindow::WallpaperType parseWallpaperType(const QString& type); - void setupLiveReloading(); private: @@ -426,7 +416,7 @@ private: QString m_fullContentPath; QString m_appID; - WallpaperType m_type = BaseWindow::WallpaperType::Qml; + ScreenPlay::InstalledType::InstalledType m_type = ScreenPlay::InstalledType::InstalledType::Unknown; QString m_OSVersion; QString m_fillMode; int m_width { 0 }; diff --git a/ScreenPlayWallpaper/src/winwindow.cpp b/ScreenPlayWallpaper/src/winwindow.cpp index 277a0bed..8a23db84 100644 --- a/ScreenPlayWallpaper/src/winwindow.cpp +++ b/ScreenPlayWallpaper/src/winwindow.cpp @@ -75,7 +75,7 @@ LRESULT __stdcall MouseHookCallback(int nCode, WPARAM wParam, LPARAM lParam) void WinWindow::setupWindowMouseHook() { // MUST be called before setting hook for events! - if (type() != BaseWindow::WallpaperType::Video) { + if (type() != ScreenPlay::InstalledType::InstalledType::VideoWallpaper) { qInfo() << "Enable mousehook"; g_winGlobalHook = &m_window;