From 2ead9670ff27acfe78de6fd6fa90f1f7b2af722a Mon Sep 17 00:00:00 2001 From: kelteseth Date: Mon, 10 Jul 2017 15:09:43 +0200 Subject: [PATCH] Videos working again! --- ScreenPlay.pro | 6 ++- qml/Components/Screens/ScreenVideo.qml | 43 ++++++++++---------- src/installedlistmodel.cpp | 54 ++++++++++---------------- src/installedlistmodel.h | 27 ++++--------- src/monitorlistmodel.cpp | 1 + src/profilelistmodel.cpp | 2 + src/profilelistmodel.h | 1 + src/projectfile.cpp | 22 +++++++++++ src/projectfile.h | 25 ++++++++++++ src/settings.cpp | 27 +++++++++---- src/settings.h | 10 +++-- src/wallpaper.cpp | 12 ++++-- src/wallpaper.h | 33 +++++++++++++--- 13 files changed, 167 insertions(+), 96 deletions(-) create mode 100644 src/projectfile.cpp create mode 100644 src/projectfile.h diff --git a/ScreenPlay.pro b/ScreenPlay.pro index 97cd9d47..baa1aded 100644 --- a/ScreenPlay.pro +++ b/ScreenPlay.pro @@ -12,7 +12,8 @@ SOURCES += main.cpp \ src/packagefilehandler.cpp \ src/wallpaper.cpp \ src/profilelistmodel.cpp \ - src/profile.cpp + src/profile.cpp \ + src/projectfile.cpp RESOURCES += qml.qrc @@ -25,7 +26,8 @@ HEADERS += \ src/packagefilehandler.h \ src/wallpaper.h \ src/profilelistmodel.h \ - src/profile.h + src/profile.h \ + src/projectfile.h INCLUDEPATH += \ $$PWD/ThirdParty/ \ diff --git a/qml/Components/Screens/ScreenVideo.qml b/qml/Components/Screens/ScreenVideo.qml index 536a16fd..eaf96a8f 100644 --- a/qml/Components/Screens/ScreenVideo.qml +++ b/qml/Components/Screens/ScreenVideo.qml @@ -1,26 +1,29 @@ -import QtQuick 2.0 -//import QtAV 1.07 +import QtQuick 2.7 +import QtAV 1.07 + Rectangle { - color: "orange" + color: "gray" + visible: true + + Video { + id: video + anchors.fill: parent + videoCodecPriority: ["CUDA", "D3D11", "DXVA", "VAAPI", "FFmpeg"] + onPlaybackStateChanged: { + + } + + Component.onCompleted: { + + video.source = Qt.resolvedUrl("file:///" + wallpaper.absoluteFilePath.toString()) + video.play() + } + onStopped: { + video.play() + } -// height: parent.height -// width: parent.width - - -// Connections { -// target: installedListModel -// onSetScreenToVideo:{ -// installedListModel.setScreenVisibleFromQml(true) -// video.stop() -// video.source = absolutePath; -// video.play(); -// } -// } -// Video { -// id: video -// anchors.fill: parent -// } + } } diff --git a/src/installedlistmodel.cpp b/src/installedlistmodel.cpp index 08082538..bef9e799 100644 --- a/src/installedlistmodel.cpp +++ b/src/installedlistmodel.cpp @@ -18,13 +18,13 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const if (index.row() < rowCount()) switch (role) { case TitleRole: - return m_screenPlayFiles.at(index.row())._title; + return m_screenPlayFiles.at(index.row()).m_title; case PreviewRole: - return m_screenPlayFiles.at(index.row())._preview; + return m_screenPlayFiles.at(index.row()).m_preview; case FolderIdRole: - return m_screenPlayFiles.at(index.row())._folderId; + return m_screenPlayFiles.at(index.row()).m_folderId; case FileIdRole: - return m_screenPlayFiles.at(index.row())._file; + return m_screenPlayFiles.at(index.row()).m_file; default: return QVariant(); } @@ -42,13 +42,24 @@ QHash InstalledListModel::roleNames() const return roles; } +bool InstalledListModel::getProjectByName(QString profileName, ProjectFile *spf) +{ + for (int i = 0; i < m_screenPlayFiles.size(); i++) { + if (m_screenPlayFiles.at(i).m_folderId == profileName) { + *spf = m_screenPlayFiles.at(i); + return true; + } + } + return false; +} + void InstalledListModel::append(const QJsonObject obj, const QString folderName) { int row = 0; beginInsertRows(QModelIndex(), row, row); - ScreenPlayFile tmpFile(obj, folderName); + ProjectFile tmpFile(obj, folderName); m_screenPlayFiles.append(tmpFile); endInsertRows(); @@ -89,39 +100,14 @@ QVariantMap InstalledListModel::get(QString folderId) for (int i = 0; i < m_screenPlayFiles.count(); i++) { - if (m_screenPlayFiles[i]._folderId == folderId) { - map.insert("screenTitle", m_screenPlayFiles[i]._title); - map.insert("screenPreview", m_screenPlayFiles[i]._preview); - map.insert("screenFile", m_screenPlayFiles[i]._file); + if (m_screenPlayFiles[i].m_folderId == folderId) { + map.insert("screenTitle", m_screenPlayFiles[i].m_title); + map.insert("screenPreview", m_screenPlayFiles[i].m_preview); + map.insert("screenFile", m_screenPlayFiles[i].m_file); } } return map; } -void InstalledListModel::setScreenVisibleFromQml(bool visible) -{ - emit setScreenVisible(visible); -} -void InstalledListModel::setScreenToVideoFromQml(QString absolutePath) -{ - emit setScreenToVideo(absolutePath); -} - -ScreenPlayFile::ScreenPlayFile(QJsonObject obj, QString folderName) -{ - if (obj.contains("description")) - _description = obj.value("description"); - - if (obj.contains("file")) - _file = obj.value("file"); - - if (obj.contains("preview")) - _preview = obj.value("preview"); - - if (obj.contains("title")) - _title = obj.value("title"); - - _folderId = folderName; -} diff --git a/src/installedlistmodel.h b/src/installedlistmodel.h index 36ad2d82..abe7d83a 100644 --- a/src/installedlistmodel.h +++ b/src/installedlistmodel.h @@ -15,8 +15,10 @@ #include #include #include +#include "profilelistmodel.h" +#include "projectfile.h" + -class ScreenPlayFile; class InstalledListModel : public QAbstractListModel { Q_OBJECT @@ -29,12 +31,13 @@ public: QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; void append(const QJsonObject, const QString); QHash roleNames() const override; + bool getProjectByName(QString profileName, ProjectFile* spf); Q_INVOKABLE void loadScreens(); Q_INVOKABLE QVariantMap get(QString folderId); - Q_INVOKABLE void setScreenVisibleFromQml(bool visible); - Q_INVOKABLE void setScreenToVideoFromQml(QString absolutePath); Q_PROPERTY(QUrl absoluteStoragePath READ absoluteStoragePath WRITE setabsoluteStoragePath NOTIFY absoluteStoragePathChanged) + + enum InstalledRole { TitleRole, PreviewRole, @@ -66,24 +69,8 @@ signals: void absoluteStoragePathChanged(QUrl absoluteStoragePath); private: - QList m_screenPlayFiles; + QList m_screenPlayFiles; QUrl m_absoluteStoragePath; }; -class ScreenPlayFile { - -public: - ScreenPlayFile(); - ScreenPlayFile(QJsonObject obj, QString folderName); - - QVariant _description; - QVariant _file; - QVariant _preview; - QVariant _title; - QString _folderId; - QUrl _absolutePath; - - QVariantList _tags; //TODO: Implement me! -}; - #endif // INSTALLEDLISTMODEL_H diff --git a/src/monitorlistmodel.cpp b/src/monitorlistmodel.cpp index 22d20b9c..2cf4aa64 100644 --- a/src/monitorlistmodel.cpp +++ b/src/monitorlistmodel.cpp @@ -6,6 +6,7 @@ MonitorListModel::MonitorListModel(QObject *parent) loadMonitors(); } + QHash MonitorListModel::roleNames() const { static const QHash roles{ diff --git a/src/profilelistmodel.cpp b/src/profilelistmodel.cpp index 706d0677..960bfe13 100644 --- a/src/profilelistmodel.cpp +++ b/src/profilelistmodel.cpp @@ -94,6 +94,8 @@ void ProfileListModel::loadProfiles() if (profileObj.contains("isLooping")) tmpProfile.m_isLooping = profileObj.value("isLooping").toBool(); + tmpProfile.m_absolutePath = m_absoluteStoragePath; + m_profileList.append(tmpProfile); } diff --git a/src/profilelistmodel.h b/src/profilelistmodel.h index 4ebfd25b..0c1fcaa5 100644 --- a/src/profilelistmodel.h +++ b/src/profilelistmodel.h @@ -24,6 +24,7 @@ public: NumberRole = Qt::UserRole + 2 }; + int rowCount(const QModelIndex& parent = QModelIndex()) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; virtual QHash roleNames() const override; diff --git a/src/projectfile.cpp b/src/projectfile.cpp new file mode 100644 index 00000000..ce2ab151 --- /dev/null +++ b/src/projectfile.cpp @@ -0,0 +1,22 @@ +#include "projectfile.h" + +ProjectFile::ProjectFile() +{ + +} +ProjectFile::ProjectFile(QJsonObject obj, QString folderName) +{ + if (obj.contains("description")) + m_description = obj.value("description"); + + if (obj.contains("file")) + m_file = obj.value("file"); + + if (obj.contains("preview")) + m_preview = obj.value("preview"); + + if (obj.contains("title")) + m_title = obj.value("title"); + + m_folderId = folderName; +} diff --git a/src/projectfile.h b/src/projectfile.h new file mode 100644 index 00000000..b409b69f --- /dev/null +++ b/src/projectfile.h @@ -0,0 +1,25 @@ +#ifndef PROJECTFILE_H +#define PROJECTFILE_H + +#include +#include +#include +#include + +class ProjectFile +{ +public: + ProjectFile(); + ProjectFile(QJsonObject obj, QString folderName); + + QVariant m_description; + QVariant m_file; + QVariant m_preview; + QVariant m_title; + QString m_folderId; + QUrl m_absolutePath; + + QVariantList m_tags; //TODO: Implement me! +}; + +#endif // PROJECTFILE_H diff --git a/src/settings.cpp b/src/settings.cpp index 868138e9..6029fb1e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -8,7 +8,6 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo m_mlm = mlm; m_ilm = ilm; - QFile configTmp; QString appConfigLocation = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); @@ -27,7 +26,6 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo createDefaultConfig(); } - QJsonDocument configJsonDocument; QJsonParseError parseError; QJsonObject configObj; @@ -55,8 +53,7 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo return; } - - if(QString(configObj.value("absoluteStoragePath").toString()).isEmpty()){ + if (QString(configObj.value("absoluteStoragePath").toString()).isEmpty()) { m_absoluteStoragePath = appConfigLocation; } else { m_absoluteStoragePath = configObj.value("absoluteStoragePath").toString(); @@ -65,7 +62,6 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo m_ilm->setabsoluteStoragePath(m_absoluteStoragePath); m_plm->m_absoluteStoragePath = m_absoluteStoragePath; - //Create default folders if (!QDir(m_absoluteStoragePath.toString() + "/ProfilePackages").exists()) { if (!QDir().mkdir(appConfigLocation + "/ProfilePackages")) { @@ -96,16 +92,19 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo m_highPriorityStart = configObj.value("highPriorityStart").toBool(); m_sendStatistics = configObj.value("sendStatistics").toBool(); m_renderer = static_cast(configObj.value("renderer-value").toInt()); +} +Settings::~Settings() +{ } void Settings::createNewProfile(int screenNumber) { } -void Settings::constructWallpaper(Profile profile, QString monitorID) +void Settings::constructWallpaper(Profile profile, QString monitorID, ProjectFile pf) { - m_wallpapers.append(QSharedPointer(new Wallpaper(profile))); + m_wallpapers.append(QSharedPointer(new Wallpaper(profile,pf))); } void Settings::loadActiveProfiles() @@ -129,15 +128,27 @@ void Settings::loadActiveProfiles() QString profileName = activeProfilesTmp.at(i).toObject().value("profile").toString(); QString monitorID = activeProfilesTmp.at(i).toObject().value("monitorID").toString(); Profile profile; + ProjectFile spf; if (!m_plm->getProfileByName(profileName, &profile)) continue; + if (!m_ilm->getProjectByName(profile.m_wallpaperId, &spf)) + continue; - constructWallpaper(profile, monitorID); + + + + constructWallpaper(profile, monitorID, spf); } } } +void Settings::removeAll() +{ + qDebug() << "destruct settings"; + m_wallpapers.clear(); +} + void Settings::createDefaultConfig() { diff --git a/src/settings.h b/src/settings.h index 173b919b..1fe5b1a5 100644 --- a/src/settings.h +++ b/src/settings.h @@ -7,7 +7,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include + #include "monitorlistmodel.h" #include "installedlistmodel.h" #include "profilelistmodel.h" @@ -30,7 +32,7 @@ class Settings : public QObject { Q_OBJECT public: explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, QObject* parent = nullptr); - + ~Settings(); Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged) Q_PROPERTY(bool highPriorityStart READ highPriorityStart WRITE setHighPriorityStart NOTIFY highPriorityStartChanged) Q_PROPERTY(Renderer renderer READ renderer WRITE setRenderer NOTIFY rendererChanged) @@ -38,8 +40,9 @@ public: Q_PROPERTY(Version version READ version) Q_INVOKABLE void createNewProfile(int screenNumber); - Q_INVOKABLE void constructWallpaper(Profile profile, QString monitorID); + Q_INVOKABLE void constructWallpaper(Profile profile, QString monitorID, ProjectFile spf); void loadActiveProfiles(); + void removeAll(); enum Renderer { @@ -151,6 +154,7 @@ private: ProfileListModel* m_plm; InstalledListModel* m_ilm; MonitorListModel* m_mlm; + QThread m_thread; QVector> m_wallpapers; QVector> m_activeProfiles; diff --git a/src/wallpaper.cpp b/src/wallpaper.cpp index 340e0903..2b00a996 100644 --- a/src/wallpaper.cpp +++ b/src/wallpaper.cpp @@ -18,17 +18,21 @@ Wallpaper::Wallpaper(QWindow* parent) { } -Wallpaper::Wallpaper(Profile profile) +Wallpaper::Wallpaper(Profile profile, ProjectFile projf) { m_profile = profile; + m_project = projf; + QString tmp = profile.m_absolutePath.toString() + "/Wallpaper/" + profile.m_wallpaperId + "/" + projf.m_file.toString(); + tmp.replace("/","\\\\"); + setAbsoluteFilePath(tmp); + this->setX(m_profile.m_rect.x()); this->setY(m_profile.m_rect.y()); this->setWidth(m_profile.m_rect.width()); this->setHeight(m_profile.m_rect.height()); this->m_hwnd = (HWND)this->winId(); - HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager"); // Spawn new worker window below desktop (using some undocumented Win32 magic) @@ -55,9 +59,9 @@ Wallpaper::Wallpaper(Profile profile) m_quickRenderer = new QQuickView(this); m_quickRenderer->setWidth(this->width()); m_quickRenderer->setHeight(this->height()); + m_context = m_quickRenderer->rootContext(); + m_context->setContextProperty("wallpaper", this); m_quickRenderer->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView); m_quickRenderer->setSource(QUrl("qrc:/qml/Components/Screens/ScreenVideo.qml")); - m_context = m_quickRenderer->rootContext(); m_quickRenderer->show(); } -} diff --git a/src/wallpaper.h b/src/wallpaper.h index 63e9567c..ee823e5d 100644 --- a/src/wallpaper.h +++ b/src/wallpaper.h @@ -8,25 +8,48 @@ #include #include #include +#include #include "profile.h" +#include "projectfile.h" class Wallpaper : public QWindow { Q_OBJECT public: explicit Wallpaper(QWindow* parent = 0); - Wallpaper(Profile profile); - ~Wallpaper(); - QQmlContext* context() const; + Wallpaper(Profile profile, ProjectFile projf); + Q_PROPERTY(QString absoluteFilePath READ absoluteFilePath WRITE setAbsoluteFilePath NOTIFY absoluteFilePathChanged) + + + QString absoluteFilePath() const + { + return m_absoluteFilePath; + } + +public slots: + void setAbsoluteFilePath(QString absoluteFilePath) + { + if (m_absoluteFilePath == absoluteFilePath) + return; + + m_absoluteFilePath = absoluteFilePath; + emit absoluteFilePathChanged(m_absoluteFilePath); + } + +signals: + void absoluteFilePathChanged(QString absoluteFilePath); + private: - HWND m_hwnd = nullptr; - HWND m_worker_hwnd = nullptr; + HWND m_hwnd; + HWND m_worker_hwnd; QQuickView* m_quickRenderer = nullptr; QQmlContext* m_context = nullptr; Profile m_profile; + ProjectFile m_project; + QString m_absoluteFilePath; }; #endif // WALLPAPER_H