1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-16 07:22:34 +02:00

More settings save reworking

This commit is contained in:
Elias Steurer 2020-07-30 21:36:40 +02:00
parent 281c3cf639
commit e1b40a7d4c
28 changed files with 519 additions and 326 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16.0) cmake_minimum_required(VERSION 3.17 )
project(ScreenPlay) project(ScreenPlay LANGUAGES CXX)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)

View File

@ -1,6 +1,6 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2 as QQC
import ScreenPlay 1.0 import ScreenPlay 1.0
Item { Item {
@ -9,11 +9,7 @@ Item {
property string headline: "dummyHeandline" property string headline: "dummyHeandline"
property string iconSource: "qrc:/assets/icons/icon_volume.svg" property string iconSource: "qrc:/assets/icons/icon_volume.svg"
property alias value: slider.value property alias slider: slider
property alias from: slider.from
property alias to: slider.to
property alias stepSize: slider.stepSize
Text { Text {
id: txtHeadline id: txtHeadline
@ -48,14 +44,14 @@ Item {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
} }
Slider { QQC.Slider {
id: slider id: slider
stepSize: 0.01 stepSize: 0.01
from: 0 from: 0
value: 1 value: 1
to: 1
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
to: 1
} }
Text { Text {

View File

@ -269,7 +269,7 @@ Item {
availableHeight: height availableHeight: height
fontSize: 11 fontSize: 11
onActiveMonitorsChanged: { onActiveMonitorsChanged: {
if(isWidget()){ if (isWidget()) {
btnSetWallpaper.enabled = true btnSetWallpaper.enabled = true
return return
} }
@ -281,10 +281,13 @@ Item {
SP.Slider { SP.Slider {
id: sliderVolume id: sliderVolume
stepSize: 0.01 slider {
from: 0 stepSize: 0.01
value: 1 from: 0
to: 1 value: 1
to: 1
}
Layout.fillWidth: true Layout.fillWidth: true
headline: qsTr("Set Volume") headline: qsTr("Set Volume")
} }
@ -374,12 +377,14 @@ Item {
ScreenPlay.screenPlayManager.createWallpaper( ScreenPlay.screenPlayManager.createWallpaper(
root.type, cbVideoFillMode.currentValue, root.type, cbVideoFillMode.currentValue,
absoluteStoragePath, previewImage, absoluteStoragePath, previewImage,
screenFile, activeMonitors, volume, true) screenFile, activeMonitors, volume,
1.0, {}, true)
} }
if (root.isWidget()) { if (root.isWidget()) {
ScreenPlay.screenPlayManager.createWidget( ScreenPlay.screenPlayManager.createWidget(
type, Qt.point(0,0), absoluteStoragePath, previewImage, true) type, Qt.point(0, 0), absoluteStoragePath,
previewImage, {}, true)
} }
root.state = "inactive" root.state = "inactive"

View File

@ -30,20 +30,24 @@ ColumnLayout {
SP.Slider { SP.Slider {
headline: qsTr("Volume") headline: qsTr("Volume")
onValueChanged: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex( slider.onMoved: {
activeMonitorIndex, "volume", value) print("MODEV")
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "volume", slider.value)
}
Layout.fillWidth: true Layout.fillWidth: true
} }
SP.Slider { SP.Slider {
headline: qsTr("Playback rate") headline: qsTr("Playback rate")
onValueChanged: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex( slider.onMoved: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "playbackRate", value) activeMonitorIndex, "playbackRate", slider.value)
Layout.fillWidth: true Layout.fillWidth: true
} }
SP.Slider { SP.Slider {
headline: qsTr("Current Video Time") headline: qsTr("Current Video Time")
onValueChanged: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex( slider.onMoved: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "currentTime", value) activeMonitorIndex, "currentTime", slider.value)
Layout.fillWidth: true Layout.fillWidth: true
} }
ColumnLayout { ColumnLayout {
@ -93,7 +97,7 @@ ColumnLayout {
"text": qsTr("Cover") "text": qsTr("Cover")
}, { }, {
"value": FillMode.Scale_Down, "value": FillMode.Scale_Down,
"text": qsTr("Scale-Down") "text": qsTr("Scale_Down")
}] }]
} }
} }

View File

@ -96,24 +96,8 @@ Item {
} }
Connections { Connections {
target: ScreenPlay.screenPlayManager target: ScreenPlay.screenPlayManager
function onProjectSettingsListModelResult(found, listModel, type) { function onProjectSettingsListModelResult(listModel) {
customPropertiesGridView.model = null
if (!found) {
videoControlWrapper.state = "hidden"
customPropertiesGridView.state = "hidden"
return
}
videoControlWrapper.state = "visible"
customPropertiesGridView.model = listModel customPropertiesGridView.model = listModel
if (type === InstalledType.VideoWallpaper) {
customPropertiesGridView.state = "hidden"
videoControlWrapper.state = "visible"
} else {
customPropertiesGridView.state = "visible"
videoControlWrapper.state = "hidden"
}
} }
} }
} }
@ -181,19 +165,6 @@ Item {
left: itmLeftWrapper.right left: itmLeftWrapper.right
} }
DefaultVideoControls {
id: videoControlWrapper
activeMonitorIndex: monitors.activeMonitorIndex
anchors {
top: parent.top
topMargin: 10
right: parent.right
rightMargin: 20
left: parent.left
leftMargin: 20
}
}
GridView { GridView {
id: customPropertiesGridView id: customPropertiesGridView
boundsBehavior: Flickable.DragOverBounds boundsBehavior: Flickable.DragOverBounds
@ -219,41 +190,6 @@ Item {
snapMode: ScrollBar.SnapOnRelease snapMode: ScrollBar.SnapOnRelease
policy: ScrollBar.AlwaysOn policy: ScrollBar.AlwaysOn
} }
states: [
State {
name: "visible"
PropertyChanges {
target: customPropertiesGridView
opacity: 1
z: 1
anchors.topMargin: 60
}
},
State {
name: "hidden"
PropertyChanges {
target: customPropertiesGridView
opacity: 0
z: -1
anchors.topMargin: -100
}
}
]
transitions: [
Transition {
from: "visible"
to: "hidden"
reversible: true
PropertyAnimation {
target: customPropertiesGridView
duration: 300
easing.type: Easing.InOutQuart
properties: "anchors.topMargin, opacity"
}
}
]
} }
} }
MouseArea { MouseArea {

View File

@ -5,7 +5,6 @@ import QtQuick.Dialogs 1.2
import QtQuick.Controls.Material 2.2 import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import ScreenPlay 1.0 import ScreenPlay 1.0
Item { Item {
@ -25,7 +24,8 @@ Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
font.family: ScreenPlay.settings.font font.family: ScreenPlay.settings.font
font.weight: Font.Normal font.weight: Font.Normal
color: root.isHeadline ? Qt.darker(Material.foreground) : Material.foreground color: root.isHeadline ? Qt.darker(
Material.foreground) : Material.foreground
anchors { anchors {
left: parent.left left: parent.left
@ -47,28 +47,33 @@ Item {
return return
} }
var obj = JSON.parse(root.value.toString()) if (root.isHeadline)
return
if (obj["text"]) {
txtDescription.text = obj["text"]
}
switch (obj["type"]) { for (let item in root.value) {
case "slider": // print(item.toString())
loader.sourceComponent = compSlider switch (item["type"]) {
loader.item.from = obj["from"] case "slider":
loader.item.to = obj["to"] loader.sourceComponent = compSlider
loader.item.value = obj["value"] loader.item.from = obj["from"]
loader.item.stepSize = obj["stepSize"] loader.item.to = obj["to"]
break loader.item.value = obj["value"]
case "bool": loader.item.stepSize = obj["stepSize"]
loader.sourceComponent = compCheckbox break
loader.item.value = obj["value"] case "bool":
break loader.sourceComponent = compCheckbox
case "color": loader.item.value = obj["value"]
loader.sourceComponent = compColorpicker break
loader.item.value = obj["value"] case "color":
break loader.sourceComponent = compColorpicker
loader.item.value = obj["value"]
break
}
if (item["text"]) {
txtDescription.text = obj["text"]
}
} }
} }
@ -88,7 +93,7 @@ Item {
right: parent.right right: parent.right
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
onCheckedChanged: { onCheckedChanged: {
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex( ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
selectedMonitor, name, checkbox.checked) selectedMonitor, name, checkbox.checked)
} }
@ -161,9 +166,9 @@ Item {
anchors { anchors {
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
right:txtSliderValue.left right: txtSliderValue.left
rightMargin: 20 rightMargin: 20
left:parent.left left: parent.left
leftMargin: 20 leftMargin: 20
} }
@ -176,7 +181,7 @@ Item {
} }
Text { Text {
id: txtSliderValue id: txtSliderValue
color: Material.foreground color: Material.foreground
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
font.family: ScreenPlay.settings.font font.family: ScreenPlay.settings.font
anchors { anchors {

View File

@ -12,4 +12,5 @@ Item {
anchors.fill: parent anchors.fill: parent
} }
} }

View File

@ -101,7 +101,7 @@ namespace FillMode {
class GlobalVariables : public QObject { class GlobalVariables : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QVersionNumber version READ version) Q_PROPERTY(QVersionNumber version READ version CONSTANT)
Q_PROPERTY(QUrl localStoragePath READ localStoragePath WRITE setLocalStoragePath NOTIFY localStoragePathChanged) Q_PROPERTY(QUrl localStoragePath READ localStoragePath WRITE setLocalStoragePath NOTIFY localStoragePathChanged)
Q_PROPERTY(QUrl localSettingsPath READ localSettingsPath WRITE setLocalSettingsPath NOTIFY localSettingsPathChanged) Q_PROPERTY(QUrl localSettingsPath READ localSettingsPath WRITE setLocalSettingsPath NOTIFY localSettingsPathChanged)
Q_PROPERTY(QUrl wallpaperExecutablePath READ wallpaperExecutablePath WRITE setWallpaperExecutablePath NOTIFY wallpaperExecutablePathChanged) Q_PROPERTY(QUrl wallpaperExecutablePath READ wallpaperExecutablePath WRITE setWallpaperExecutablePath NOTIFY wallpaperExecutablePathChanged)

View File

@ -37,7 +37,6 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QApplication>
#include <QRect> #include <QRect>
#include <QScreen> #include <QScreen>
#include <QSize> #include <QSize>
@ -110,6 +109,12 @@ public:
std::optional<QString> getAppIDByMonitorIndex(const int index) const; std::optional<QString> getAppIDByMonitorIndex(const int index) const;
QRect getAbsoluteDesktopSize() const
{
auto* app = static_cast<QApplication*>(QApplication::instance());
return app->screens().at(0)->availableVirtualGeometry();
}
signals: signals:
void monitorReloadCompleted(); void monitorReloadCompleted();
void setNewActiveMonitor(int index, QString path); void setNewActiveMonitor(int index, QString path);
@ -133,12 +138,6 @@ public slots:
reset(); reset();
} }
QRect getAbsoluteDesktopSize() const
{
auto* app = static_cast<QApplication*>(QApplication::instance());
return app->screens().at(0)->availableVirtualGeometry();
}
private: private:
void loadMonitors(); void loadMonitors();

View File

@ -34,7 +34,6 @@
#pragma once #pragma once
#include "globalvariables.h"
#include <QDebug> #include <QDebug>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
@ -44,6 +43,9 @@
#include <QVariant> #include <QVariant>
#include <QVariantList> #include <QVariantList>
#include "globalvariables.h"
#include "util.h"
/*! /*!
\class ProjectFile \class ProjectFile
\brief In ScreenPlay every Wallpaper, Scene or Widget has an project.json to store its configuration \brief In ScreenPlay every Wallpaper, Scene or Widget has an project.json to store its configuration
@ -99,42 +101,14 @@ struct ProjectFile {
if (!obj.contains("type")) if (!obj.contains("type"))
return; return;
QString type = obj.value("type").toString(); auto type = Util::getInstalledTypeFromString(obj.value("type").toString());
if (type.endsWith("Wallpaper")) { if (!type) {
if (type.startsWith("video")) { qWarning() << "Type could not parsed from: " << *type << folderName;
m_searchType = SearchType::SearchType::Wallpaper; return;
m_type = InstalledType::InstalledType::VideoWallpaper;
return;
}
m_searchType = SearchType::SearchType::Scenes;
if (type.startsWith("qml")) {
m_type = InstalledType::InstalledType::QMLWallpaper;
return;
}
if (type.startsWith("html")) {
m_type = InstalledType::InstalledType::HTMLWallpaper;
return;
}
if (type.startsWith("godot")) {
m_type = InstalledType::InstalledType::GodotWallpaper;
return;
}
} }
if (type.endsWith("Widget")) { m_type = *type;
m_searchType = SearchType::SearchType::Widget; m_searchType = Util::getSearchTypeFromInstalledType(m_type);
if (type.startsWith("qml")) {
m_type = InstalledType::InstalledType::QMLWidget;
return;
}
if (type.startsWith("html")) {
m_type = InstalledType::InstalledType::HTMLWidget;
return;
}
}
qWarning() << "Type could not parsed from: " << type << folderName;
} }
ProjectFile() { } ProjectFile() { }

View File

@ -34,7 +34,12 @@
#pragma once #pragma once
#include <QColor>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString> #include <QString>
#include <QUrl>
#include <QVariant> #include <QVariant>
namespace ScreenPlay { namespace ScreenPlay {
@ -47,20 +52,107 @@ namespace ScreenPlay {
*/ */
struct ProjectSettingsListItem { struct IListItem {
//MOC complains otherwise WTF
ProjectSettingsListItem( bool operator!=(const IListItem& val)
const QString& name,
const bool isHeadline,
const QVariant& value)
{ {
m_name = name; return true;
m_isHeadline = isHeadline; }
m_value = value; };
struct SliderItem : public IListItem {
Q_GADGET
Q_PROPERTY(double from MEMBER m_from)
Q_PROPERTY(double to MEMBER m_to)
Q_PROPERTY(double stepSize MEMBER m_stepSize)
Q_PROPERTY(double value MEMBER m_value)
public:
double m_from = { 0.0 };
double m_to = { 0.1 };
double m_stepSize = { 0.1 };
double m_value = { 0.0 };
};
struct ColorItem : public IListItem {
Q_GADGET
Q_PROPERTY(QColor color MEMBER m_color)
public:
QColor m_color = { QColor::fromRgb(0, 0, 0) };
};
struct CheckBoxItem : public IListItem {
Q_GADGET
Q_PROPERTY(bool value MEMBER m_value)
public:
bool m_value = { false };
};
struct FileItem : public IListItem {
Q_GADGET
Q_PROPERTY(QUrl file MEMBER m_file)
public:
QUrl m_file = {};
};
struct ProjectSettingsListItem {
Q_GADGET
Q_PROPERTY(IListItem item MEMBER m_item)
public:
ProjectSettingsListItem(
const QString& headline)
{
m_isHeadline = true;
m_key = headline;
} }
QString m_name; ProjectSettingsListItem(
const QString& key,
const QJsonObject& obj)
{
m_isHeadline = false;
m_key = key;
QString type = obj.value("type").toString();
qInfo() << type;
if (type == "slider") {
SliderItem item;
item.m_from = obj.value("from").toDouble(0);
item.m_to = obj.value("to").toDouble(1);
item.m_stepSize = obj.value("stepSize").toDouble(0.1);
item.m_value = obj.value("value").toDouble(1);
m_item = item;
return;
}
if (type == "file") {
FileItem item;
item.m_file = obj.value("file").toString();
m_item = item;
return;
}
if (type == "color") {
ColorItem item;
item.m_color = { obj.value("file").toString() };
m_item = item;
return;
}
if (type == "bool") {
CheckBoxItem item;
m_item = item;
return;
}
}
QString m_key;
bool m_isHeadline { false }; bool m_isHeadline { false };
QVariant m_value; QVariant m_value;
IListItem m_item;
QVariant value() const
{
return m_value;
}
}; };
} }

View File

@ -35,12 +35,40 @@ namespace ScreenPlay {
*/ */
/*! /*!
Constructor Constructor when loading properties from settings.json
*/ */
ProjectSettingsListModel::ProjectSettingsListModel(QString file, QObject* parent)
: QAbstractListModel(parent) void ProjectSettingsListModel::init(const InstalledType::InstalledType& type, const QJsonObject& properties)
{ {
init(file); if (type == InstalledType::InstalledType::VideoWallpaper) {
// beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
// m_projectSettings.append("General");
// if (properties.contains("volume"))
// append({"slider", properties.value("volume")}=;
// if (properties.contains("playbackRate"))
// append("slider", properties.value("playbackRate").toObject());
// endInsertRows();
} else {
for (QJsonObject::const_iterator itParent = properties.begin(); itParent != properties.end(); itParent++) {
// The first object is always a category
const QJsonObject category = properties.value(itParent.key()).toObject();
beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
m_projectSettings.append(ProjectSettingsListItem { itParent.key() });
endInsertRows();
// Children of this category
for (QJsonObject::const_iterator itChild = category.begin(); itChild != category.end(); itChild++) {
qInfo() << itChild.key() << itChild.value();
beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
m_projectSettings.append(ProjectSettingsListItem {itChild.key(), itChild.value().toObject() });
endInsertRows();
}
}
}
} }
int ProjectSettingsListModel::rowCount(const QModelIndex& parent) const int ProjectSettingsListModel::rowCount(const QModelIndex& parent) const
@ -63,7 +91,7 @@ QVariant ProjectSettingsListModel::data(const QModelIndex& index, int role) cons
if (index.row() < rowCount()) if (index.row() < rowCount())
switch (role) { switch (role) {
case NameRole: case NameRole:
return m_projectSettings.at(rowIndex).m_name; return m_projectSettings.at(rowIndex).m_key;
case IsHeadlineRole: case IsHeadlineRole:
return m_projectSettings.at(rowIndex).m_isHeadline; return m_projectSettings.at(rowIndex).m_isHeadline;
case ValueRole: case ValueRole:
@ -86,45 +114,26 @@ QHash<int, QByteArray> ProjectSettingsListModel::roleNames() const
return roles; return roles;
} }
/*! QJsonObject ProjectSettingsListModel::getActiveSettingsJson()
Recursively loads the content of a project.json.
See also \l {https://kelteseth.gitlab.io/ScreenPlayDocs/project/project/} .
*/
void ProjectSettingsListModel::init(const QString& file)
{ {
if (auto config = Util::openJsonFileToObject(file)) { if (m_projectSettings.isEmpty()) {
qWarning() << "Trying to read emppty projectSettings. Abort!";
QJsonObject obj = *config; return {};
QJsonObject tmpParent;
if (obj.contains("properties")) {
tmpParent = obj.value("properties").toObject();
} else {
return;
}
QJsonObject::iterator itParent, itChild;
for (itParent = tmpParent.begin(); itParent != tmpParent.end(); itParent++) {
// The first object is always a category
QJsonObject tmpChildObj = tmpParent.value(itParent.key()).toObject();
append(itParent.key(), true, "");
// Children of this category
for (itChild = tmpChildObj.begin(); itChild != tmpChildObj.end(); itChild++) {
append(itChild.key(), false, QJsonDocument(tmpChildObj.value(itChild.key()).toObject()).toJson());
}
}
} else {
qWarning() << "Could not load: " << file << " for wallpaper settings!";
} }
QJsonObject obj;
for (const auto& itemCategory : m_projectSettings) {
QJsonObject category;
if (itemCategory.m_isHeadline) {
for (const auto& itemProperties : m_projectSettings) {
if (itemProperties.m_isHeadline)
continue;
category.insert(itemProperties.m_key, QJsonValue::fromVariant(itemProperties.m_value));
}
obj.insert(itemCategory.m_key, category);
}
}
return obj;
} }
void ProjectSettingsListModel::append(QString name, bool isHeadline, QVariant value)
{
beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
ProjectSettingsListItem tmpFile(name, isHeadline, value.toString());
m_projectSettings.append(tmpFile);
endInsertRows();
}
} }

View File

@ -52,8 +52,6 @@ class ProjectSettingsListModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
public: public:
explicit ProjectSettingsListModel(QString file, QObject* parent = nullptr);
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
@ -65,10 +63,8 @@ public:
}; };
Q_ENUM(ProjectSettingsRole) Q_ENUM(ProjectSettingsRole)
void init(const QString& file); QJsonObject getActiveSettingsJson();
void init(const InstalledType::InstalledType& type, const QJsonObject& properties);
public slots:
void append(QString name, bool isHeadline, QVariant value);
private: private:
QVector<ProjectSettingsListItem> m_projectSettings; QVector<ProjectSettingsListItem> m_projectSettings;

View File

@ -32,6 +32,15 @@ ScreenPlayManager::ScreenPlayManager(
if (!m_server->listen("ScreenPlay")) { if (!m_server->listen("ScreenPlay")) {
qCritical("Could not open Local Socket with the name ScreenPlay!"); qCritical("Could not open Local Socket with the name ScreenPlay!");
} }
// We limit the time we save via a Qtimer. This is because we can live update values like
// volume to the wallpaper very fast. This would be very imperformant for HDD user, so
// we limit ourself to m_saveLimiters interval below:
m_saveLimiter.setInterval(1000);
QObject::connect(&m_saveLimiter, &QTimer::timeout, this, &ScreenPlayManager::saveProfiles);
QObject::connect(this, &ScreenPlayManager::requestSaveProfiles, this, [this]() {
m_saveLimiter.start();
});
} }
/*! /*!
@ -76,20 +85,20 @@ void ScreenPlayManager::init(
a \a fillMode, a \a type (htmlWallpaper, qmlWallpaper etc.), a \a saveToProfilesConfigFile bool only set to flase a \a fillMode, a \a type (htmlWallpaper, qmlWallpaper etc.), a \a saveToProfilesConfigFile bool only set to flase
if we call the method when using via the settings on startup to skip a unnecessary save. if we call the method when using via the settings on startup to skip a unnecessary save.
*/ */
void ScreenPlayManager::createWallpaper( void ScreenPlayManager::createWallpaper(const InstalledType::InstalledType type,
const InstalledType::InstalledType type,
const FillMode::FillMode fillMode, const FillMode::FillMode fillMode,
const QString& absoluteStoragePath, const QString& absoluteStoragePath,
const QString& previewImage, const QString& previewImage,
const QString& file, const QString& file,
QVector<int> monitorIndex, const QVector<int>& monitorIndex,
const float volume, const float volume,
const float playbackRate, const QJsonObject& properties,
const bool saveToProfilesConfigFile) const bool saveToProfilesConfigFile)
{ {
auto saveToProfile = qScopeGuard([=, this] { auto saveToProfile = qScopeGuard([=, this] {
// Do not save on app start // Do not save on app start
if (saveToProfilesConfigFile) { if (saveToProfilesConfigFile) {
saveProfiles(); emit requestSaveProfiles();
} }
}); });
@ -128,8 +137,7 @@ void ScreenPlayManager::createWallpaper(
} }
} }
std::shared_ptr<ScreenPlayWallpaper> wallpaper; auto wallpaper = std::make_shared<ScreenPlayWallpaper>(
wallpaper = std::make_shared<ScreenPlayWallpaper>(
monitorIndex, monitorIndex,
m_globalVariables, m_globalVariables,
appID, appID,
@ -137,11 +145,13 @@ void ScreenPlayManager::createWallpaper(
previewImage, previewImage,
file, file,
volume, volume,
playbackRate,
fillMode, fillMode,
type, type,
properties,
m_settings->checkWallpaperVisible()); m_settings->checkWallpaperVisible());
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::saveProfiles); QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::requestSaveProfiles);
m_screenPlayWallpapers.append(wallpaper); m_screenPlayWallpapers.append(wallpaper);
m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex); m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex);
increaseActiveWallpaperCounter(); increaseActiveWallpaperCounter();
@ -150,17 +160,17 @@ void ScreenPlayManager::createWallpaper(
/*! /*!
\brief Creates a ScreenPlayWidget object via a \a absoluteStoragePath and a \a preview image (relative path). \brief Creates a ScreenPlayWidget object via a \a absoluteStoragePath and a \a preview image (relative path).
*/ */
void ScreenPlayManager::createWidget( void ScreenPlayManager::createWidget(const InstalledType::InstalledType type,
const InstalledType::InstalledType type,
const QPoint& position, const QPoint& position,
const QString& absoluteStoragePath, const QString& absoluteStoragePath,
const QString& previewImage, const QString& previewImage,
const QJsonObject& properties,
const bool saveToProfilesConfigFile) const bool saveToProfilesConfigFile)
{ {
auto saveToProfile = qScopeGuard([=, this] { auto saveToProfile = qScopeGuard([=, this] {
// Do not save on app start // Do not save on app start
if (saveToProfilesConfigFile) { if (saveToProfilesConfigFile) {
saveProfiles(); emit requestSaveProfiles();
} }
}); });
@ -171,8 +181,17 @@ void ScreenPlayManager::createWidget(
qInfo() << "Path is empty, Abort! String: " << absoluteStoragePath; qInfo() << "Path is empty, Abort! String: " << absoluteStoragePath;
return; return;
} }
auto widget = std::make_shared<ScreenPlayWidget>(appID, m_globalVariables, position, path, previewImage, type);
QObject::connect(widget.get(), &ScreenPlayWidget::requestSave, this, &ScreenPlayManager::saveProfiles); auto widget = std::make_shared<ScreenPlayWidget>(
appID,
m_globalVariables,
position,
path,
previewImage,
properties,
type);
QObject::connect(widget.get(), &ScreenPlayWidget::requestSave, this, &ScreenPlayManager::requestSaveProfiles);
increaseActiveWidgetsCounter(); increaseActiveWidgetsCounter();
m_screenPlayWidgets.append(widget); m_screenPlayWidgets.append(widget);
} }
@ -207,7 +226,7 @@ void ScreenPlayManager::removeAllWallpapers()
m_monitorListModel->clearActiveWallpaper(); m_monitorListModel->clearActiveWallpaper();
saveProfiles(); emit requestSaveProfiles();
setActiveWallpaperCounter(0); setActiveWallpaperCounter(0);
if (activeWallpaperCounter() != m_screenPlayWallpapers.length()) { if (activeWallpaperCounter() != m_screenPlayWallpapers.length()) {
if (m_telemetry) { if (m_telemetry) {
@ -233,7 +252,7 @@ void ScreenPlayManager::removeAllWidgets()
if (!m_screenPlayWidgets.empty()) { if (!m_screenPlayWidgets.empty()) {
closeAllWidgets(); closeAllWidgets();
m_screenPlayWidgets.clear(); m_screenPlayWidgets.clear();
saveProfiles(); emit requestSaveProfiles();
setActiveWidgetsCounter(0); setActiveWidgetsCounter(0);
} }
} }
@ -247,7 +266,7 @@ bool ScreenPlayManager::removeWallpaperAt(int index)
{ {
if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(index)) { if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(index)) {
saveProfiles(); emit requestSaveProfiles();
if (!closeWallpaper(*appID)) { if (!closeWallpaper(*appID)) {
qWarning() << "Could not close socket. Abort!"; qWarning() << "Could not close socket. Abort!";
@ -263,7 +282,7 @@ bool ScreenPlayManager::removeWallpaperAt(int index)
qWarning() << "Could not remove Wallpaper " << appIDCopy << " from wallpaper list!"; qWarning() << "Could not remove Wallpaper " << appIDCopy << " from wallpaper list!";
return false; return false;
} }
saveProfiles(); emit requestSaveProfiles();
return true; return true;
} }
if (m_telemetry) { if (m_telemetry) {
@ -282,13 +301,10 @@ void ScreenPlayManager::requestProjectSettingsAtMonitorIndex(const int index)
if (uPtrWallpaper->screenNumber()[0] == index) { if (uPtrWallpaper->screenNumber()[0] == index) {
emit projectSettingsListModelResult( emit projectSettingsListModelResult(
true, uPtrWallpaper->getProjectSettingsListModel());
uPtrWallpaper->getProjectSettingsListModel(),
uPtrWallpaper->type());
return; return;
} }
} }
emit projectSettingsListModelResult(false);
} }
/*! /*!
@ -340,7 +356,7 @@ void ScreenPlayManager::newConnection()
// Only after we receive the first message with appID and type we can set the shared reference to the // Only after we receive the first message with appID and type we can set the shared reference to the
// ScreenPlayWallpaper or ScreenPlayWidgets class // ScreenPlayWallpaper or ScreenPlayWidgets class
QObject::connect(connection.get(), &SDKConnection::appConnected, this, [this](const SDKConnection* connection) { QObject::connect(connection.get(), &SDKConnection::appConnected, this, [this](const SDKConnection* connection) {
for (const auto& client : m_clients) { for (const auto& client : qAsConst(m_clients)) {
if (client.get() == connection) { if (client.get() == connection) {
appConnected(client); appConnected(client);
return; return;
@ -350,7 +366,6 @@ void ScreenPlayManager::newConnection()
m_clients.append(connection); m_clients.append(connection);
} }
/*! /*!
\brief Closes all wallpaper connection with the following type: \brief Closes all wallpaper connection with the following type:
\list \list
@ -409,23 +424,23 @@ bool ScreenPlayManager::closeWallpaper(const QString& appID)
/*! /*!
\brief Sets a given \a value to a given \a key. The \a appID is used to identify the receiver socket. \brief Sets a given \a value to a given \a key. The \a appID is used to identify the receiver socket.
*/ */
void ScreenPlayManager::setWallpaperValue(QString appID, QString key, QString value) void ScreenPlayManager::setWallpaperValue(const QString& appID, const QString& key, const QVariant& value)
{ {
for (const auto& wallpaper : m_screenPlayWallpapers) { for (const auto& wallpaper : m_screenPlayWallpapers) {
if (wallpaper->appID() == appID) { if (wallpaper->appID() == appID) {
wallpaper->setWallpaperValue(key, value); wallpaper->setWallpaperValue(key, value, true);
} }
} }
} }
/*! /*!
\brief Saves a given wallpaper \a newProfileObject to a \a profileName. We ignore the profileName argument \brief Saves a given wallpaper \a newProfileObject to a \a profileName. We ignore the profileName argument
because we currently only support one profile. Returns \c true if successfuly saved to profiles.json, otherwise \c false. because we currently only support one profile. Returns \c true if successfuly saved to profiles.json, otherwise \c false.
*/ */
void ScreenPlayManager::saveProfiles() void ScreenPlayManager::saveProfiles()
{ {
m_saveLimiter.stop();
qInfo() << "Save profiles!";
QJsonArray wallpaper {}; QJsonArray wallpaper {};
for (const auto& activeWallpaper : m_screenPlayWallpapers) { for (const auto& activeWallpaper : m_screenPlayWallpapers) {
wallpaper.append(activeWallpaper->getActiveSettingsJson()); wallpaper.append(activeWallpaper->getActiveSettingsJson());
@ -534,13 +549,15 @@ void ScreenPlayManager::loadProfiles()
const QString absolutePath = wallpaperObj.value("absolutePath").toString(); const QString absolutePath = wallpaperObj.value("absolutePath").toString();
const QString fillModeString = wallpaperObj.value("fillMode").toString(); const QString fillModeString = wallpaperObj.value("fillMode").toString();
const QString previewImage = wallpaperObj.value("previewImage").toString(); const QString previewImage = wallpaperObj.value("previewImage").toString();
const float playbackRate = wallpaperObj.value("playbackRate").toDouble(1.0);
const QString file = wallpaperObj.value("file").toString(); const QString file = wallpaperObj.value("file").toString();
const QString typeString = wallpaperObj.value("type").toString(); const QString typeString = wallpaperObj.value("type").toString();
const QJsonObject properties = wallpaperObj.value("properties").toObject();
const auto type = QStringToEnum<InstalledType::InstalledType>(typeString, InstalledType::InstalledType::VideoWallpaper); const auto type = QStringToEnum<InstalledType::InstalledType>(typeString, InstalledType::InstalledType::VideoWallpaper);
const auto fillMode = QStringToEnum<FillMode::FillMode>(fillModeString, FillMode::FillMode::Cover); const auto fillMode = QStringToEnum<FillMode::FillMode>(fillModeString, FillMode::FillMode::Cover);
createWallpaper(type, fillMode, absolutePath, previewImage, file, monitors, volume, false); createWallpaper(type, fillMode, absolutePath, previewImage, file, monitors, volume, playbackRate, properties, false);
monitors.clear(); monitors.clear();
} }
@ -557,8 +574,9 @@ void ScreenPlayManager::loadProfiles()
const int positionY = widgetObj.value("positionY").toInt(0); const int positionY = widgetObj.value("positionY").toInt(0);
const QPoint position { positionX, positionY }; const QPoint position { positionX, positionY };
const auto type = QStringToEnum<InstalledType::InstalledType>(typeString, InstalledType::InstalledType::QMLWidget); const auto type = QStringToEnum<InstalledType::InstalledType>(typeString, InstalledType::InstalledType::QMLWidget);
const QJsonObject properties = widgetObj.value("properties").toObject();
createWidget(type, position, absolutePath, previewImage, false); createWidget(type, position, absolutePath, previewImage, properties, false);
} }
} }
} }

View File

@ -88,29 +88,34 @@ public:
const std::shared_ptr<Settings>& settings); const std::shared_ptr<Settings>& settings);
signals: signals:
void projectSettingsListModelResult( void projectSettingsListModelResult(ScreenPlay::ProjectSettingsListModel* li = nullptr);
const bool found,
ProjectSettingsListModel* li = nullptr,
const ScreenPlay::InstalledType::InstalledType type = ScreenPlay::InstalledType::InstalledType::VideoWallpaper);
void activeWallpaperCounterChanged(int activeWallpaperCounter); void activeWallpaperCounterChanged(int activeWallpaperCounter);
void activeWidgetsCounterChanged(int activeWidgetsCounter); void activeWidgetsCounterChanged(int activeWidgetsCounter);
void requestSaveProfiles();
void requestRaise(); void requestRaise();
private slots:
void saveProfiles();
public slots: public slots:
// moc needs full enum namespace info see QTBUG-58454 // moc needs full enum namespace info see QTBUG-58454
void createWallpaper( void createWallpaper(const ScreenPlay::InstalledType::InstalledType type,
const ScreenPlay::InstalledType::InstalledType type,
const ScreenPlay::FillMode::FillMode fillMode, const ScreenPlay::FillMode::FillMode fillMode,
const QString& absoluteStoragePath, const QString& absoluteStoragePath,
const QString& previewImage, const QString& previewImage,
const QString& file, const QString& file,
QVector<int> monitorIndex, const QVector<int>& monitorIndex,
const float volume, const float volume,
const float playbackRate,
const QJsonObject& properties,
const bool saveToProfilesConfigFile); const bool saveToProfilesConfigFile);
void createWidget(const ScreenPlay::InstalledType::InstalledType type, const QPoint& position, void createWidget(
const ScreenPlay::InstalledType::InstalledType type,
const QPoint& position,
const QString& absoluteStoragePath, const QString& absoluteStoragePath,
const QString& previewImage, const QString& previewImage,
const QJsonObject& properties,
const bool saveToProfilesConfigFile); const bool saveToProfilesConfigFile);
void removeAllWallpapers(); void removeAllWallpapers();
@ -122,13 +127,12 @@ public slots:
void setAllWallpaperValue(const QString& key, const QString& value); void setAllWallpaperValue(const QString& key, const QString& value);
std::optional<std::shared_ptr<ScreenPlayWallpaper>> getWallpaperByAppID(const QString& appID); std::optional<std::shared_ptr<ScreenPlayWallpaper>> getWallpaperByAppID(const QString& appID);
void saveProfiles();
void newConnection(); void newConnection();
void closeAllWallpapers(); void closeAllWallpapers();
void closeAllWidgets(); void closeAllWidgets();
void closeConntectionByType(const QStringList& list); void closeConntectionByType(const QStringList& list);
bool closeWallpaper(const QString& appID); bool closeWallpaper(const QString& appID);
void setWallpaperValue(QString appID, QString key, QString value); void setWallpaperValue(const QString& appID, const QString& key, const QVariant& value);
void setActiveWallpaperCounter(int activeWallpaperCounter) void setActiveWallpaperCounter(int activeWallpaperCounter)
{ {
@ -198,6 +202,7 @@ private:
int m_activeWidgetsCounter { 0 }; int m_activeWidgetsCounter { 0 };
bool m_isAnotherScreenPlayInstanceRunning = false; bool m_isAnotherScreenPlayInstanceRunning = false;
QTimer m_saveLimiter;
}; };
} }

View File

@ -13,20 +13,20 @@ namespace ScreenPlay {
/*! /*!
\brief Constructor for video Wallpaper. \brief Constructor for video Wallpaper.
*/ */
ScreenPlayWallpaper::ScreenPlayWallpaper( ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
const QVector<int>& screenNumber,
const std::shared_ptr<GlobalVariables>& globalVariables, const std::shared_ptr<GlobalVariables>& globalVariables,
const QString& appID, const QString& appID,
const QString& absolutePath, const QString& absolutePath,
const QString& previewImage, const QString& previewImage,
const QString& file, const QString& file,
const float volume, const float volume,
const float playbackRate,
const FillMode::FillMode fillMode, const FillMode::FillMode fillMode,
const InstalledType::InstalledType type, const InstalledType::InstalledType type,
const QJsonObject& properties,
const bool checkWallpaperVisible, const bool checkWallpaperVisible,
QObject* parent) QObject* parent)
: QObject(parent) : QObject(parent)
, m_projectSettingsListModel { absolutePath + "/project.json" }
, m_globalVariables { globalVariables } , m_globalVariables { globalVariables }
, m_screenNumber { screenNumber } , m_screenNumber { screenNumber }
, m_previewImage { previewImage } , m_previewImage { previewImage }
@ -35,8 +35,30 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(
, m_appID { appID } , m_appID { appID }
, m_absolutePath { absolutePath } , m_absolutePath { absolutePath }
, m_file { file } , m_file { file }
, m_playbackRate { playbackRate }
{ {
{
// If
QJsonObject projectSettingsListModelProperties;
if (type == InstalledType::InstalledType::VideoWallpaper) {
projectSettingsListModelProperties.insert("volume", m_volume);
projectSettingsListModelProperties.insert("playbackRate", m_playbackRate);
} else {
if (properties.isEmpty()) {
auto obj = Util::openJsonFileToObject(absolutePath + "/project.json");
if (!obj)
return;
if (!obj->contains("properties"))
return;
projectSettingsListModelProperties = obj->value("properties").toObject();
} else {
projectSettingsListModelProperties = properties;
}
}
m_projectSettingsListModel.init(type, projectSettingsListModelProperties);
}
QObject::connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &ScreenPlayWallpaper::processExit); QObject::connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &ScreenPlayWallpaper::processExit);
QObject::connect(&m_process, &QProcess::errorOccurred, this, &ScreenPlayWallpaper::processError); QObject::connect(&m_process, &QProcess::errorOccurred, this, &ScreenPlayWallpaper::processError);
@ -66,6 +88,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(
// Fixes issue 84 media key overlay // Fixes issue 84 media key overlay
" --disable-features=HardwareMediaKeyHandling" " --disable-features=HardwareMediaKeyHandling"
}; };
qInfo() << proArgs;
m_process.setArguments(proArgs); m_process.setArguments(proArgs);
m_process.setProgram(m_globalVariables->wallpaperExecutablePath().toString()); m_process.setProgram(m_globalVariables->wallpaperExecutablePath().toString());
@ -80,14 +103,22 @@ QJsonObject ScreenPlayWallpaper::getActiveSettingsJson()
} }
QJsonObject obj; QJsonObject obj;
QJsonObject properties;
if (m_type == InstalledType::InstalledType::VideoWallpaper) {
obj.insert("fillMode", QVariant::fromValue(m_fillMode).toString());
obj.insert("isLooping", m_isLooping);
obj.insert("volume", m_volume);
obj.insert("playbackRate", m_playbackRate);
} else {
auto properties = m_projectSettingsListModel.getActiveSettingsJson();
if (!properties.isEmpty())
obj.insert("properties", properties);
}
obj.insert("file", m_file); obj.insert("file", m_file);
obj.insert("absolutePath", m_absolutePath); obj.insert("absolutePath", m_absolutePath);
obj.insert("fillMode", QVariant::fromValue(m_fillMode).toString());
obj.insert("isLooping", m_isLooping);
obj.insert("monitors", screenNumber); obj.insert("monitors", screenNumber);
obj.insert("previewImage", m_previewImage); obj.insert("previewImage", m_previewImage);
obj.insert("type", QVariant::fromValue(m_type).toString()); obj.insert("type", QVariant::fromValue(m_type).toString());
obj.insert("volume", m_volume);
return obj; return obj;
} }
@ -109,23 +140,37 @@ void ScreenPlayWallpaper::processError(QProcess::ProcessError error)
qDebug() << "EX: " << error; qDebug() << "EX: " << error;
} }
void ScreenPlayWallpaper::setWallpaperValue(const QString& key, const QString& value) void ScreenPlayWallpaper::setWallpaperValue(const QString& key, const QVariant& value, const bool save)
{ {
QJsonObject obj; QJsonObject obj;
obj.insert(key, value); obj.insert(key, value.toString());
if (key == "volume") {
setVolume(value.toFloat());
}
if (key == "playbackRate") {
setPlaybackRate(value.toFloat());
}
if (key == "fillmode") {
setFillMode(QStringToEnum<FillMode::FillMode>(value.toString(), FillMode::FillMode::Cover));
}
m_connection->sendMessage(QJsonDocument(obj).toJson(QJsonDocument::Compact)); m_connection->sendMessage(QJsonDocument(obj).toJson(QJsonDocument::Compact));
} qInfo() << "save" << save;
if (save)
ProjectSettingsListModel* ScreenPlayWallpaper::getProjectSettingsListModel() emit requestSave();
{
return &m_projectSettingsListModel;
} }
void ScreenPlayWallpaper::setSDKConnection(const std::shared_ptr<SDKConnection>& connection) void ScreenPlayWallpaper::setSDKConnection(const std::shared_ptr<SDKConnection>& connection)
{ {
m_connection = connection; m_connection = connection;
qInfo() << "App Wallpaper connected!"; qInfo() << "App Wallpaper connected!";
qInfo() << playbackRate() << (playbackRate() != 1.0);
QTimer::singleShot(500, [this]() {
if (playbackRate() != 1.0) {
setWallpaperValue("playbackRate", playbackRate(), false);
}
});
} }
void ScreenPlayWallpaper::replace( void ScreenPlayWallpaper::replace(
@ -155,9 +200,8 @@ void ScreenPlayWallpaper::replace(
obj.insert("file", file); obj.insert("file", file);
obj.insert("checkWallpaperVisible", checkWallpaperVisible); obj.insert("checkWallpaperVisible", checkWallpaperVisible);
m_connection->sendMessage(QJsonDocument(obj).toJson(QJsonDocument::Compact)); m_connection->sendMessage(QJsonDocument(obj).toJson(QJsonDocument::Compact));
emit requestSave();
} }
} }

View File

@ -44,6 +44,7 @@
#include "globalvariables.h" #include "globalvariables.h"
#include "projectsettingslistmodel.h" #include "projectsettingslistmodel.h"
#include "sdkconnection.h" #include "sdkconnection.h"
#include "util.h"
namespace ScreenPlay { namespace ScreenPlay {
@ -53,6 +54,7 @@ class ScreenPlayWallpaper : public QObject {
Q_PROPERTY(QVector<int> screenNumber READ screenNumber WRITE setScreenNumber NOTIFY screenNumberChanged) Q_PROPERTY(QVector<int> screenNumber READ screenNumber WRITE setScreenNumber NOTIFY screenNumberChanged)
Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged) Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(float playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
Q_PROPERTY(bool isLooping READ isLooping WRITE setIsLooping NOTIFY isLoopingChanged) Q_PROPERTY(bool isLooping READ isLooping WRITE setIsLooping NOTIFY isLoopingChanged)
@ -65,22 +67,29 @@ class ScreenPlayWallpaper : public QObject {
Q_PROPERTY(InstalledType::InstalledType type READ type WRITE setType NOTIFY typeChanged) Q_PROPERTY(InstalledType::InstalledType type READ type WRITE setType NOTIFY typeChanged)
public: public:
explicit ScreenPlayWallpaper( explicit ScreenPlayWallpaper(const QVector<int>& screenNumber,
const QVector<int>& screenNumber,
const std::shared_ptr<GlobalVariables>& globalVariables, const std::shared_ptr<GlobalVariables>& globalVariables,
const QString& appID, const QString& appID,
const QString& absolutePath, const QString& absolutePath,
const QString& previewImage, const QString& previewImage,
const QString& file, const QString& file,
const float volume, const float volume, const float playbackRate,
const FillMode::FillMode fillMode, const FillMode::FillMode fillMode,
const InstalledType::InstalledType type, const InstalledType::InstalledType type, const QJsonObject& properties,
const bool checkWallpaperVisible, const bool checkWallpaperVisible,
QObject* parent = nullptr); QObject* parent = nullptr);
QJsonObject getActiveSettingsJson(); void replace(const QString& absolutePath,
const QString& previewImage,
const QString& file,
const float volume,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const bool checkWallpaperVisible);
bool m_isAnotherScreenPlayInstanceRunning { false }; void setSDKConnection(const std::shared_ptr<SDKConnection>& connection);
QJsonObject getActiveSettingsJson();
QVector<int> screenNumber() const QVector<int> screenNumber() const
{ {
@ -127,17 +136,15 @@ public:
return m_isLooping; return m_isLooping;
} }
ProjectSettingsListModel* getProjectSettingsListModel(); ProjectSettingsListModel* getProjectSettingsListModel()
{
return &m_projectSettingsListModel;
}
void setSDKConnection(const std::shared_ptr<SDKConnection>& connection); float playbackRate() const
{
void replace(const QString& absolutePath, return m_playbackRate;
const QString& previewImage, }
const QString& file,
const float volume,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const bool checkWallpaperVisible);
signals: signals:
void screenNumberChanged(QVector<int> screenNumber); void screenNumberChanged(QVector<int> screenNumber);
@ -151,11 +158,12 @@ signals:
void volumeChanged(float volume); void volumeChanged(float volume);
void isLoopingChanged(bool isLooping); void isLoopingChanged(bool isLooping);
void requestSave(); void requestSave();
void playbackRateChanged(float playbackRate);
public slots: public slots:
void processExit(int exitCode, QProcess::ExitStatus exitStatus); void processExit(int exitCode, QProcess::ExitStatus exitStatus);
void processError(QProcess::ProcessError error); void processError(QProcess::ProcessError error);
void setWallpaperValue(const QString &key, const QString &value); void setWallpaperValue(const QString& key, const QVariant& value, const bool save = false);
void setScreenNumber(QVector<int> screenNumber) void setScreenNumber(QVector<int> screenNumber)
{ {
@ -241,6 +249,15 @@ public slots:
emit isLoopingChanged(m_isLooping); emit isLoopingChanged(m_isLooping);
} }
void setPlaybackRate(float playbackRate)
{
if (playbackRate < 0.0f || playbackRate > 1.0f)
return;
m_playbackRate = playbackRate;
emit playbackRateChanged(m_playbackRate);
}
private: private:
const std::shared_ptr<GlobalVariables>& m_globalVariables; const std::shared_ptr<GlobalVariables>& m_globalVariables;
std::shared_ptr<SDKConnection> m_connection; std::shared_ptr<SDKConnection> m_connection;
@ -256,5 +273,6 @@ private:
QString m_file; QString m_file;
float m_volume { 1.0f }; float m_volume { 1.0f };
bool m_isLooping { true }; bool m_isLooping { true };
float m_playbackRate { 1.0f };
}; };
} }

View File

@ -19,6 +19,7 @@ ScreenPlayWidget::ScreenPlayWidget(
const QPoint& position, const QPoint& position,
const QString& absolutePath, const QString& absolutePath,
const QString& previewImage, const QString& previewImage,
const QJsonObject& properties,
const InstalledType::InstalledType type) const InstalledType::InstalledType type)
: QObject { nullptr } : QObject { nullptr }
, m_globalVariables { globalVariables } , m_globalVariables { globalVariables }
@ -28,6 +29,25 @@ ScreenPlayWidget::ScreenPlayWidget(
, m_type { type } , m_type { type }
, m_absolutePath { absolutePath } , m_absolutePath { absolutePath }
{ {
{
// If
QJsonObject projectSettingsListModelProperties;
if (properties.isEmpty()) {
auto obj = Util::openJsonFileToObject(absolutePath + "/project.json");
if (!obj)
return;
if (!obj->contains("properties"))
return;
projectSettingsListModelProperties = obj->value("properties").toObject();
} else {
projectSettingsListModelProperties = properties;
}
m_projectSettingsListModel.init(type, projectSettingsListModelProperties);
}
const QStringList proArgs { const QStringList proArgs {
m_absolutePath, m_absolutePath,
QString { "appID=" + m_appID }, QString { "appID=" + m_appID },
@ -39,8 +59,6 @@ ScreenPlayWidget::ScreenPlayWidget(
m_process.setArguments(proArgs); m_process.setArguments(proArgs);
m_process.setProgram(m_globalVariables->widgetExecutablePath().path()); m_process.setProgram(m_globalVariables->widgetExecutablePath().path());
qDebug() << proArgs;
QObject::connect(&m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) { QObject::connect(&m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) {
qDebug() << "error: " << error; qDebug() << "error: " << error;
}); });
@ -62,6 +80,11 @@ void ScreenPlayWidget::setSDKConnection(const std::shared_ptr<SDKConnection>& co
QJsonObject ScreenPlayWidget::getActiveSettingsJson() QJsonObject ScreenPlayWidget::getActiveSettingsJson()
{ {
QJsonObject obj; QJsonObject obj;
auto properties = m_projectSettingsListModel.getActiveSettingsJson();
if (!properties.isEmpty())
obj.insert("properties", properties);
obj.insert("previewImage", m_previewImage); obj.insert("previewImage", m_previewImage);
obj.insert("absolutePath", m_absolutePath); obj.insert("absolutePath", m_absolutePath);
obj.insert("positionX", m_position.x()); obj.insert("positionX", m_position.x());

View File

@ -45,6 +45,7 @@
#include <memory> #include <memory>
#include "globalvariables.h" #include "globalvariables.h"
#include "projectsettingslistmodel.h"
#include "sdkconnection.h" #include "sdkconnection.h"
namespace ScreenPlay { namespace ScreenPlay {
@ -63,7 +64,7 @@ public:
const std::shared_ptr<GlobalVariables>& globalVariables, const std::shared_ptr<GlobalVariables>& globalVariables,
const QPoint& position, const QPoint& position,
const QString& absolutePath, const QString& absolutePath,
const QString& previewImage, const QString& previewImage, const QJsonObject& properties,
const InstalledType::InstalledType type); const InstalledType::InstalledType type);
~ScreenPlayWidget() { } ~ScreenPlayWidget() { }
@ -98,6 +99,11 @@ public:
public slots: public slots:
QJsonObject getActiveSettingsJson(); QJsonObject getActiveSettingsJson();
ProjectSettingsListModel* getProjectSettingsListModel()
{
return &m_projectSettingsListModel;
}
void setPreviewImage(QString previewImage) void setPreviewImage(QString previewImage)
{ {
if (m_previewImage == previewImage) if (m_previewImage == previewImage)
@ -154,6 +160,7 @@ signals:
private: private:
const std::shared_ptr<GlobalVariables>& m_globalVariables; const std::shared_ptr<GlobalVariables>& m_globalVariables;
std::shared_ptr<SDKConnection> m_connection; std::shared_ptr<SDKConnection> m_connection;
ProjectSettingsListModel m_projectSettingsListModel;
QProcess m_process; QProcess m_process;
QString m_previewImage; QString m_previewImage;

View File

@ -98,7 +98,7 @@ signals:
void typeChanged(QString type); void typeChanged(QString type);
void requestDecreaseWidgetCount(); void requestDecreaseWidgetCount();
void requestRaise(); void requestRaise();
void appConnected(const SDKConnection* connection); void appConnected(const ScreenPlay::SDKConnection* connection);
void jsonMessageReceived(const QJsonObject obj); void jsonMessageReceived(const QJsonObject obj);
public slots: public slots:

View File

@ -197,9 +197,9 @@ signals:
void anonymousTelemetryChanged(bool anonymousTelemetry); void anonymousTelemetryChanged(bool anonymousTelemetry);
void checkWallpaperVisibleChanged(bool checkWallpaperVisible); void checkWallpaperVisibleChanged(bool checkWallpaperVisible);
void videoFillModeChanged(ScreenPlay::FillMode::FillMode videoFillMode); void videoFillModeChanged(ScreenPlay::FillMode::FillMode videoFillMode);
void languageChanged(Language language); void languageChanged(ScreenPlay::Settings::Language language);
void fontChanged(QString font); void fontChanged(QString font);
void themeChanged(Theme theme); void themeChanged(ScreenPlay::Settings::Theme theme);
public slots: public slots:
void writeJsonFileFromResource(const QString& filename); void writeJsonFileFromResource(const QString& filename);
@ -325,7 +325,7 @@ public slots:
emit videoFillModeChanged(m_videoFillMode); emit videoFillModeChanged(m_videoFillMode);
} }
void setLanguage(Language language) void setLanguage(ScreenPlay::Settings::Language language)
{ {
if (m_language == language) if (m_language == language)
return; return;
@ -345,7 +345,7 @@ public slots:
emit fontChanged(m_font); emit fontChanged(m_font);
} }
void setTheme(Theme theme) void setTheme(ScreenPlay::Settings::Theme theme)
{ {
if (m_theme == theme) if (m_theme == theme)
return; return;

View File

@ -175,7 +175,7 @@ bool Util::writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObj
QString Util::toString(const QStringList& list) QString Util::toString(const QStringList& list)
{ {
QString out; QString out;
for (const auto &string : list) { for (const auto& string : list) {
out += " " + string; out += " " + string;
} }
return out; return out;
@ -326,8 +326,8 @@ void Util::downloadFFMPEG()
ZipEntry entryFFMPEG; ZipEntry entryFFMPEG;
std::string entryFFMPEGPath; std::string entryFFMPEGPath;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
entryFFMPEG = archive->getEntry(ffmpegVersion.toStdString() + "-win64-static/bin/ffmpeg.exe"); entryFFMPEG = archive->getEntry(ffmpegVersion.toStdString() + "-win64-static/bin/ffmpeg.exe");
entryFFMPEGPath = path + "ffmpeg.exe"; entryFFMPEGPath = path + "ffmpeg.exe";
#elif defined(Q_OS_OSX) #elif defined(Q_OS_OSX)
entryFFMPEG = archive->getEntry(ffmpegVersion.toStdString() +"-macos64-static/bin/ffmpeg"); entryFFMPEG = archive->getEntry(ffmpegVersion.toStdString() +"-macos64-static/bin/ffmpeg");
entryFFMPEGPath = path + "ffmpeg"; entryFFMPEGPath = path + "ffmpeg";
@ -347,8 +347,8 @@ void Util::downloadFFMPEG()
return; return;
} }
ZipEntry entryFFPROBE; ZipEntry entryFFPROBE;
std::string entryFFPROBEPath; std::string entryFFPROBEPath;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
entryFFPROBE = archive->getEntry(ffmpegVersion.toStdString() + "-win64-static/bin/ffprobe.exe"); entryFFPROBE = archive->getEntry(ffmpegVersion.toStdString() + "-win64-static/bin/ffprobe.exe");
entryFFPROBEPath = path + "ffprobe.exe"; entryFFPROBEPath = path + "ffprobe.exe";
@ -377,6 +377,56 @@ void Util::downloadFFMPEG()
}); });
} }
SearchType::SearchType Util::getSearchTypeFromInstalledType(const InstalledType::InstalledType type)
{
using InstalledType::InstalledType;
using SearchType::SearchType;
switch (type) {
case InstalledType::GodotWallpaper:
case InstalledType::HTMLWallpaper:
case InstalledType::QMLWallpaper:
return SearchType::Scenes;
case InstalledType::VideoWallpaper:
return SearchType::Wallpaper;
case InstalledType::HTMLWidget:
case InstalledType::QMLWidget:
return SearchType::Widget;
case InstalledType::Unknown:
default:
return SearchType::All;
}
}
std::optional<InstalledType::InstalledType> Util::getInstalledTypeFromString(const QString& type)
{
if (type.endsWith("Wallpaper")) {
if (type.startsWith("video", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::VideoWallpaper;
}
if (type.startsWith("qml", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::QMLWallpaper;
}
if (type.startsWith("html", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::HTMLWallpaper;
}
if (type.startsWith("godot", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::GodotWallpaper;
}
}
if (type.endsWith("Widget")) {
if (type.startsWith("qml", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::QMLWidget;
}
if (type.startsWith("html", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::HTMLWidget;
}
}
return std::nullopt;
}
/*! /*!
\brief Basic logging to the GUI. No logging is done to a log file for now. This string can be copied \brief Basic logging to the GUI. No logging is done to a log file for now. This string can be copied
in the settings tab in the UI. in the settings tab in the UI.

View File

@ -126,7 +126,7 @@ signals:
void allLicenseLoaded(QString licensesText); void allLicenseLoaded(QString licensesText);
void allDataProtectionLoaded(QString dataProtectionText); void allDataProtectionLoaded(QString dataProtectionText);
void ffmpegAvailableChanged(bool ffmpegAvailable); void ffmpegAvailableChanged(bool ffmpegAvailable);
void aquireFFMPEGStatusChanged(AquireFFMPEGStatus aquireFFMPEGStatus); void aquireFFMPEGStatusChanged(ScreenPlay::Util::AquireFFMPEGStatus aquireFFMPEGStatus);
void debugMessagesChanged(QString debugMessages); void debugMessagesChanged(QString debugMessages);
public slots: public slots:
@ -138,6 +138,8 @@ public slots:
void downloadFFMPEG(); void downloadFFMPEG();
static SearchType::SearchType getSearchTypeFromInstalledType(const InstalledType::InstalledType type);
static std::optional<InstalledType::InstalledType> getInstalledTypeFromString(const QString& type);
static std::optional<QJsonObject> parseQByteArrayToQJsonObject(const QByteArray& byteArray); static std::optional<QJsonObject> parseQByteArrayToQJsonObject(const QByteArray& byteArray);
static std::optional<QJsonObject> openJsonFileToObject(const QString& path); static std::optional<QJsonObject> openJsonFileToObject(const QString& path);
static std::optional<QString> openJsonFileToString(const QString& path); static std::optional<QString> openJsonFileToString(const QString& path);
@ -173,7 +175,7 @@ public slots:
emit ffmpegAvailableChanged(m_ffmpegAvailable); emit ffmpegAvailableChanged(m_ffmpegAvailable);
} }
void setAquireFFMPEGStatus(AquireFFMPEGStatus aquireFFMPEGStatus) void setAquireFFMPEGStatus(ScreenPlay::Util::AquireFFMPEGStatus aquireFFMPEGStatus)
{ {
if (m_aquireFFMPEGStatus == aquireFFMPEGStatus) if (m_aquireFFMPEGStatus == aquireFFMPEGStatus)
return; return;

View File

@ -1,4 +1,6 @@
project(ScreenPlaySDK) cmake_minimum_required(VERSION 3.17 )
project(ScreenPlaySDK LANGUAGES CXX)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)

View File

@ -1,4 +1,6 @@
project(ScreenPlaySysInfo) cmake_minimum_required(VERSION 3.17 )
project(ScreenPlaySysInfo LANGUAGES CXX)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)

View File

@ -1,4 +1,6 @@
project(ScreenPlayWallpaper) cmake_minimum_required(VERSION 3.17 )
project(ScreenPlayWallpaper LANGUAGES CXX)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)

View File

@ -1,4 +1,6 @@
project(ScreenPlayWidget) cmake_minimum_required(VERSION 3.17 )
project(ScreenPlayWidget LANGUAGES CXX)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)

View File

@ -29,26 +29,6 @@ WidgetWindow::WidgetWindow(
setType(type); setType(type);
{
// We limit ourself to only update the position every 500ms!
auto sendPositionUpdate = [this]() {
m_positionMessageLimiter.stop();
if (!m_sdk->isConnected())
return;
QJsonObject obj;
obj.insert("messageType", "positionUpdate");
obj.insert("positionX", m_window.x());
obj.insert("positionY", m_window.y());
m_sdk->sendMessage(obj);
};
m_positionMessageLimiter.setInterval(500);
QObject::connect(&m_positionMessageLimiter, &QTimer::timeout, this, sendPositionUpdate);
QObject::connect(&m_window, &QWindow::xChanged, this, [this]() { m_positionMessageLimiter.start(); });
QObject::connect(&m_window, &QWindow::yChanged, this, [this]() { m_positionMessageLimiter.start(); });
}
Qt::WindowFlags flags = m_window.flags(); Qt::WindowFlags flags = m_window.flags();
m_window.setFlags(flags | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::BypassWindowManagerHint | Qt::SplashScreen); m_window.setFlags(flags | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::BypassWindowManagerHint | Qt::SplashScreen);
@ -87,6 +67,27 @@ WidgetWindow::WidgetWindow(
m_window.setSource(QUrl("qrc:/Widget.qml")); m_window.setSource(QUrl("qrc:/Widget.qml"));
m_window.setPosition(m_position); m_window.setPosition(m_position);
m_window.show(); m_window.show();
// Do not trigger position changed save reuqest on startup
QTimer::singleShot(1000, [=, this]() {
// We limit ourself to only update the position every 500ms!
auto sendPositionUpdate = [this]() {
m_positionMessageLimiter.stop();
if (!m_sdk->isConnected())
return;
QJsonObject obj;
obj.insert("messageType", "positionUpdate");
obj.insert("positionX", m_window.x());
obj.insert("positionY", m_window.y());
m_sdk->sendMessage(obj);
};
m_positionMessageLimiter.setInterval(500);
QObject::connect(&m_positionMessageLimiter, &QTimer::timeout, this, sendPositionUpdate);
QObject::connect(&m_window, &QWindow::xChanged, this, [this]() { m_positionMessageLimiter.start(); });
QObject::connect(&m_window, &QWindow::yChanged, this, [this]() { m_positionMessageLimiter.start(); });
});
} }
void WidgetWindow::setSize(QSize size) void WidgetWindow::setSize(QSize size)