mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-05 10:32:28 +01:00
Add replace wallpaper that reuses the existing ScreenPlayWallpaper process
This commit is contained in:
parent
a83d1fc491
commit
73730eaac5
@ -1,4 +1,5 @@
|
||||
#include "screenplaymanager.h"
|
||||
#include <QScopeGuard>
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
@ -47,6 +48,13 @@ void ScreenPlayManager::createWallpaper(
|
||||
const float volume,
|
||||
const bool saveToProfilesConfigFile)
|
||||
{
|
||||
auto saveToProfile = qScopeGuard([=, this] {
|
||||
// Do not save on app start
|
||||
if (saveToProfilesConfigFile) {
|
||||
saveProfiles();
|
||||
}
|
||||
});
|
||||
|
||||
if (m_telemetry) {
|
||||
m_telemetry->sendEvent("wallpaper", "start");
|
||||
}
|
||||
@ -59,10 +67,34 @@ void ScreenPlayManager::createWallpaper(
|
||||
const QString path = QUrl::fromUserInput(absoluteStoragePath).toLocalFile();
|
||||
const QString appID = Util::generateRandomString();
|
||||
|
||||
// Only support remove wallpaper that spans over 1 monitor
|
||||
if (monitorIndex.length() == 1) {
|
||||
int i = 0;
|
||||
for (auto& wallpaper : m_screenPlayWallpapers) {
|
||||
if (wallpaper->screenNumber().length() == 1) {
|
||||
if (monitors.at(0) == wallpaper->screenNumber().at(0)) {
|
||||
wallpaper->replace(
|
||||
path,
|
||||
previewImage,
|
||||
file,
|
||||
volume,
|
||||
fillMode,
|
||||
type,
|
||||
m_settings->checkWallpaperVisible());
|
||||
m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<ScreenPlayWallpaper> wallpaper;
|
||||
wallpaper = std::make_shared<ScreenPlayWallpaper>(
|
||||
monitorIndex,
|
||||
m_globalVariables,
|
||||
m_sdkconnector,
|
||||
appID,
|
||||
path,
|
||||
previewImage,
|
||||
@ -72,29 +104,9 @@ void ScreenPlayManager::createWallpaper(
|
||||
type,
|
||||
m_settings->checkWallpaperVisible());
|
||||
|
||||
// Only support remove wallpaper that spans over 1 monitor
|
||||
if (monitorIndex.length() == 1) {
|
||||
int i = 0;
|
||||
for (auto& wallpaperIterator : m_screenPlayWallpapers) {
|
||||
if (wallpaperIterator->screenNumber().length() == 1) {
|
||||
if (monitors.at(0) == wallpaperIterator->screenNumber().at(0)) {
|
||||
if (!removeWallpaperAt(i)) {
|
||||
qWarning() << "Could not remove wallpaper at index " << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
m_screenPlayWallpapers.append(wallpaper);
|
||||
m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex);
|
||||
increaseActiveWallpaperCounter();
|
||||
|
||||
// Do not save on app start
|
||||
if (saveToProfilesConfigFile) {
|
||||
saveProfiles();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -16,6 +16,7 @@ namespace ScreenPlay {
|
||||
ScreenPlayWallpaper::ScreenPlayWallpaper(
|
||||
const QVector<int>& screenNumber,
|
||||
const std::shared_ptr<GlobalVariables>& globalVariables,
|
||||
const std::shared_ptr<SDKConnector>& sdkConnector,
|
||||
const QString& appID,
|
||||
const QString& absolutePath,
|
||||
const QString& previewImage,
|
||||
@ -28,6 +29,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(
|
||||
: QObject(parent)
|
||||
, m_projectSettingsListModel { absolutePath + "/project.json" }
|
||||
, m_globalVariables { globalVariables }
|
||||
, m_sdkConnector { sdkConnector }
|
||||
, m_screenNumber { screenNumber }
|
||||
, m_previewImage { previewImage }
|
||||
, m_type { type }
|
||||
@ -114,4 +116,31 @@ ProjectSettingsListModel* ScreenPlayWallpaper::getProjectSettingsListModel()
|
||||
return &m_projectSettingsListModel;
|
||||
}
|
||||
|
||||
void ScreenPlayWallpaper::replace(
|
||||
const QString& absolutePath,
|
||||
const QString& previewImage,
|
||||
const QString& file,
|
||||
const float volume,
|
||||
const FillMode::FillMode fillMode,
|
||||
const InstalledType::InstalledType type,
|
||||
const bool checkWallpaperVisible)
|
||||
{
|
||||
m_previewImage = previewImage;
|
||||
m_type = type;
|
||||
m_fillMode = fillMode;
|
||||
m_absolutePath = absolutePath;
|
||||
m_file = file;
|
||||
|
||||
QJsonObject obj;
|
||||
obj.insert("command", "replace");
|
||||
obj.insert("type", QVariant::fromValue(type).toString());
|
||||
obj.insert("fillMode", QVariant::fromValue(fillMode).toString());
|
||||
obj.insert("volume", volume);
|
||||
obj.insert("absolutePath", absolutePath);
|
||||
obj.insert("file", file);
|
||||
obj.insert("checkWallpaperVisible", checkWallpaperVisible);
|
||||
|
||||
m_sdkConnector->replace(m_appID, obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,6 +43,7 @@
|
||||
|
||||
#include "globalvariables.h"
|
||||
#include "projectsettingslistmodel.h"
|
||||
#include "sdkconnector.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
@ -67,6 +68,7 @@ public:
|
||||
explicit ScreenPlayWallpaper(
|
||||
const QVector<int>& screenNumber,
|
||||
const std::shared_ptr<GlobalVariables>& globalVariables,
|
||||
const std::shared_ptr<SDKConnector>& sdkConnector,
|
||||
const QString& appID,
|
||||
const QString& absolutePath,
|
||||
const QString& previewImage,
|
||||
@ -126,6 +128,14 @@ public:
|
||||
|
||||
ProjectSettingsListModel* getProjectSettingsListModel();
|
||||
|
||||
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);
|
||||
|
||||
signals:
|
||||
void screenNumberChanged(QVector<int> screenNumber);
|
||||
void previewImageChanged(QString previewImage);
|
||||
@ -231,6 +241,7 @@ private:
|
||||
|
||||
ProjectSettingsListModel m_projectSettingsListModel;
|
||||
const std::shared_ptr<GlobalVariables>& m_globalVariables;
|
||||
const std::shared_ptr<SDKConnector>& m_sdkConnector;
|
||||
|
||||
QVector<int> m_screenNumber;
|
||||
|
||||
|
@ -90,14 +90,7 @@ void SDKConnector::closeAllConnections()
|
||||
*/
|
||||
void SDKConnector::closeAllWallpapers()
|
||||
{
|
||||
QStringList types {
|
||||
"VideoWallpaper",
|
||||
"QmlWallpaper",
|
||||
"HtmlWallpaper",
|
||||
"GodotWallpaper"
|
||||
};
|
||||
|
||||
closeConntectionByType(types);
|
||||
closeConntectionByType(GlobalVariables::getAvailableWallpaper());
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -110,13 +103,7 @@ void SDKConnector::closeAllWallpapers()
|
||||
*/
|
||||
void SDKConnector::closeAllWidgets()
|
||||
{
|
||||
QStringList types {
|
||||
"QmlWidget",
|
||||
"HtmlWidget",
|
||||
"StandaloneWidget"
|
||||
};
|
||||
|
||||
closeConntectionByType(types);
|
||||
closeConntectionByType(GlobalVariables::getAvailableWidgets());
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -165,4 +152,16 @@ void SDKConnector::setWallpaperValue(QString appID, QString key, QString value)
|
||||
}
|
||||
}
|
||||
|
||||
void SDKConnector::replace(const QString& appID, const QJsonObject& obj)
|
||||
{
|
||||
for (int i = 0; i < m_clients.count(); ++i) {
|
||||
if (m_clients.at(i)->appID() == appID) {
|
||||
|
||||
QByteArray send = QJsonDocument(obj).toJson();
|
||||
m_clients.at(i)->socket()->write(send);
|
||||
m_clients.at(i)->socket()->waitForBytesWritten();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ public slots:
|
||||
void closeAllWidgets();
|
||||
bool closeWallpaper(const QString& appID);
|
||||
void setWallpaperValue(QString appID, QString key, QString value);
|
||||
void replace(const QString& appID, const QJsonObject& obj);
|
||||
|
||||
private:
|
||||
std::unique_ptr<QLocalServer> m_server;
|
||||
|
@ -36,13 +36,12 @@ void ScreenPlaySDK::init()
|
||||
// If the wallpaper never connects it will never get the
|
||||
// disconnect event. We can savely assume no connection will
|
||||
// be made after 1 second timeout.
|
||||
QTimer::singleShot(1000,[this](){
|
||||
if(m_socket.state() != QLocalSocket::ConnectedState){
|
||||
m_socket.disconnectFromServer();
|
||||
emit sdkDisconnected();
|
||||
QTimer::singleShot(1000, [this]() {
|
||||
if (m_socket.state() != QLocalSocket::ConnectedState) {
|
||||
m_socket.disconnectFromServer();
|
||||
emit sdkDisconnected();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
ScreenPlaySDK::~ScreenPlaySDK()
|
||||
@ -76,19 +75,58 @@ void ScreenPlaySDK::readyRead()
|
||||
emit incommingMessageError(err.errorString());
|
||||
return;
|
||||
}
|
||||
QJsonObject ob = doc.object();
|
||||
QJsonObject obj = doc.object();
|
||||
|
||||
if(ob.size() == 1){
|
||||
if(ob.contains("command")){
|
||||
if(ob.value("command") == "quit"){
|
||||
if (obj.size() == 1) {
|
||||
if (obj.contains("command")) {
|
||||
if (obj.value("command") == "quit") {
|
||||
emit sdkDisconnected();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.contains("command")) {
|
||||
if (obj.value("command") == "replace") {
|
||||
QString type = obj.value("type").toString();
|
||||
QString fillMode = obj.value("fillMode").toString();
|
||||
QString absolutePath = obj.value("absolutePath").toString();
|
||||
QString file = obj.value("file").toString();
|
||||
bool checkWallpaperVisible = obj.value("checkWallpaperVisible").toBool();
|
||||
if (type.isEmpty()
|
||||
|| fillMode.isEmpty()
|
||||
|| absolutePath.isEmpty()
|
||||
|| file.isEmpty()
|
||||
|| (!obj.contains("volume"))) {
|
||||
qWarning() << "Command replace with incompile message received: "
|
||||
<< type
|
||||
<< fillMode
|
||||
<< absolutePath
|
||||
<< file;
|
||||
return;
|
||||
}
|
||||
|
||||
bool volumeParsedOK = false;
|
||||
float volumeParsed = QVariant(obj.value("volume").toVariant()).toFloat(&volumeParsedOK);
|
||||
if (!volumeParsedOK && (volumeParsed > 0.0 && volumeParsed <= 1.0)) {
|
||||
qWarning() << "Command replaced contained bad volume float value: " << volumeParsed;
|
||||
}
|
||||
|
||||
qWarning()
|
||||
<< type
|
||||
<< fillMode
|
||||
<< volumeParsed
|
||||
<< absolutePath
|
||||
<< file;
|
||||
|
||||
emit replaceWallpaper(absolutePath, file, volumeParsed, fillMode, type, checkWallpaperVisible);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QJsonObject::iterator iterator;
|
||||
for (iterator = ob.begin(); iterator != ob.end(); iterator++) {
|
||||
emit incommingMessage(iterator.key(), ob.value(iterator.key()).toString());
|
||||
for (iterator = obj.begin(); iterator != obj.end(); iterator++) {
|
||||
emit incommingMessage(iterator.key(), obj.value(iterator.key()).toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
@ -54,7 +55,7 @@ class ScreenPlaySDK : public QQuickItem {
|
||||
|
||||
public:
|
||||
ScreenPlaySDK(QQuickItem* parent = nullptr);
|
||||
ScreenPlaySDK( const QString& appID, const QString& type,QQuickItem* parent = nullptr);
|
||||
ScreenPlaySDK(const QString& appID, const QString& type, QQuickItem* parent = nullptr);
|
||||
~ScreenPlaySDK();
|
||||
|
||||
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
|
||||
@ -125,6 +126,14 @@ signals:
|
||||
void appIDChanged(QString appID);
|
||||
void newRedirectMessage(QByteArray& msg);
|
||||
|
||||
void replaceWallpaper(
|
||||
const QString absolutePath,
|
||||
const QString file,
|
||||
const float volume,
|
||||
const QString fillMode,
|
||||
const QString type,
|
||||
const bool checkWallpaperVisible);
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
|
@ -15,18 +15,43 @@ Item {
|
||||
WebEngine.settings.allowRunningInsecureContent = true
|
||||
WebEngine.settings.accelerated2dCanvasEnabled = true
|
||||
WebEngine.settings.javascriptCanOpenWindows = false
|
||||
WebEngine.settings.printElementBackgrounds = false
|
||||
WebEngine.settings.showScrollBars = false
|
||||
WebEngine.settings.playbackRequiresUserGesture = false
|
||||
WebEngine.settings.focusOnNavigationEnabled = true
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: window
|
||||
|
||||
function onReloadVideo() {
|
||||
webView.runJavaScript(root.getSetVideoCommand())
|
||||
}
|
||||
}
|
||||
|
||||
function getSetVideoCommand() {
|
||||
// TODO 30:
|
||||
// Currently wont work. Commit anyways til QtCreator and Qt work with js template literals
|
||||
var src = ""
|
||||
src += "var videoPlayer = document.getElementById('videoPlayer');"
|
||||
src += "var videoSource = document.getElementById('videoSource');"
|
||||
src += "videoSource.src = '" + window.fullContentPath + "';"
|
||||
src += "videoPlayer.load();"
|
||||
src += "videoPlayer.volume = " + window.volume + ";"
|
||||
src += "videoPlayer.setAttribute('style', 'object-fit :" + window.fillMode + ";');"
|
||||
src += "videoPlayer.play();"
|
||||
|
||||
return src
|
||||
}
|
||||
|
||||
WebEngineView {
|
||||
id: webView
|
||||
|
||||
anchors.fill: parent
|
||||
url: {
|
||||
|
||||
if (window.type === Wallpaper.WallpaperType.Video) {
|
||||
return Qt.resolvedUrl(window.getApplicationPath() + "/index.html")
|
||||
return Qt.resolvedUrl(window.getApplicationPath(
|
||||
) + "/index.html")
|
||||
}
|
||||
if (window.type === Wallpaper.WallpaperType.Html) {
|
||||
return Qt.resolvedUrl(window.fullContentPath + "/index.html")
|
||||
@ -37,21 +62,11 @@ Item {
|
||||
if ((loadProgress === 100)) {
|
||||
|
||||
if (window.type === Wallpaper.WallpaperType.Video) {
|
||||
// TODO 30:
|
||||
// Currently wont work. Commit anyways til QtCreator and Qt work with js template literals
|
||||
var src = ""
|
||||
src += "var videoPlayer = document.getElementById('videoPlayer');"
|
||||
src += "var videoSource = document.getElementById('videoSource');"
|
||||
src += "videoSource.src = '" + window.fullContentPath + "';"
|
||||
src += "videoPlayer.load();"
|
||||
src += "videoPlayer.volume = " + window.volume + ";"
|
||||
src += "videoPlayer.setAttribute('style', 'object-fit :"
|
||||
+ window.fillMode + ";');"
|
||||
src += "videoPlayer.play();"
|
||||
|
||||
webView.runJavaScript(src, function (result) {
|
||||
fadeInTimer.start()
|
||||
})
|
||||
webView.runJavaScript(root.getSetVideoCommand(),
|
||||
function (result) {
|
||||
fadeInTimer.start()
|
||||
})
|
||||
} else {
|
||||
fadeInTimer.start()
|
||||
}
|
||||
@ -79,7 +94,6 @@ Item {
|
||||
color: "white"
|
||||
}
|
||||
|
||||
|
||||
Timer {
|
||||
id: timerCover
|
||||
interval: 300
|
||||
@ -89,7 +103,6 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Connections {
|
||||
target: window
|
||||
|
||||
|
@ -115,6 +115,7 @@ int main(int argc, char* argv[])
|
||||
WinWindow window(list, argumentList.at(2), argumentList.at(3), argumentList.at(4), argumentList.at(5), checkWallpaperVisible);
|
||||
QObject::connect(&sdk, &ScreenPlaySDK::sdkDisconnected, &window, &WinWindow::destroyThis);
|
||||
QObject::connect(&sdk, &ScreenPlaySDK::incommingMessage, &window, &WinWindow::messageReceived);
|
||||
QObject::connect(&sdk, &ScreenPlaySDK::replaceWallpaper, &window, &WinWindow::replaceWallpaper);
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
|
@ -71,25 +71,7 @@ BaseWindow::BaseWindow(QString projectFilePath, const QVector<int> activeScreens
|
||||
|
||||
QString type = projectObject.value("type").toString().toLower();
|
||||
|
||||
if (type.contains("VideoWallpaper", Qt::CaseInsensitive)) {
|
||||
setType(BaseWindow::WallpaperType::Video);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type.contains("QmlWallpaper", Qt::CaseInsensitive)) {
|
||||
setType(BaseWindow::WallpaperType::Qml);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type.contains("HtmlWallpaper", Qt::CaseInsensitive)) {
|
||||
setType(BaseWindow::WallpaperType::Html);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type.contains("GodotWallpaper", Qt::CaseInsensitive)) {
|
||||
setType(BaseWindow::WallpaperType::Godot);
|
||||
return;
|
||||
}
|
||||
setType(parseWallpaperType(type));
|
||||
}
|
||||
|
||||
void BaseWindow::messageReceived(QString key, QString value)
|
||||
@ -152,6 +134,31 @@ void BaseWindow::messageReceived(QString key, QString value)
|
||||
emit qmlSceneValueReceived(key, value);
|
||||
}
|
||||
|
||||
void BaseWindow::replaceWallpaper(
|
||||
const QString absolutePath,
|
||||
const QString file,
|
||||
const float volume,
|
||||
const QString fillMode,
|
||||
const QString type,
|
||||
const bool checkWallpaperVisible)
|
||||
{
|
||||
setCheckWallpaperVisible(checkWallpaperVisible);
|
||||
setVolume(volume);
|
||||
setFillMode(fillMode);
|
||||
setType(parseWallpaperType(type));
|
||||
setFullContentPath("file:///" + absolutePath + "/" + file);
|
||||
qInfo( ) << file;
|
||||
|
||||
if (m_type == WallpaperType::Qml || m_type == WallpaperType::Html)
|
||||
emit reloadQML();
|
||||
|
||||
if (m_type == WallpaperType::Video)
|
||||
emit reloadVideo();
|
||||
|
||||
}
|
||||
|
||||
// Used for loading shader
|
||||
// Loading shader relative to the qml file will be available in Qt 6
|
||||
QString BaseWindow::loadFromFile(const QString& filename)
|
||||
{
|
||||
QFile file;
|
||||
@ -161,3 +168,27 @@ QString BaseWindow::loadFromFile(const QString& 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);
|
||||
}
|
||||
|
||||
qWarning() << "Could not parse Wallpaper type from value: " << type;
|
||||
|
||||
return BaseWindow::WallpaperType::Video;
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ public:
|
||||
signals:
|
||||
void qmlExit();
|
||||
void reloadQML();
|
||||
void reloadVideo();
|
||||
|
||||
void loopsChanged(bool loops);
|
||||
void volumeChanged(float volume);
|
||||
@ -204,6 +205,14 @@ public slots:
|
||||
virtual void destroyThis() { }
|
||||
virtual void setVisible(bool show) { Q_UNUSED(show) }
|
||||
virtual void messageReceived(QString key, QString value) final;
|
||||
virtual void replaceWallpaper(
|
||||
const QString absolutePath,
|
||||
const QString file,
|
||||
const float volume,
|
||||
const QString fillMode,
|
||||
const QString type,
|
||||
const bool checkWallpaperVisible) final;
|
||||
|
||||
|
||||
QString loadFromFile(const QString& filename);
|
||||
|
||||
@ -395,6 +404,9 @@ public slots:
|
||||
emit basePathChanged(m_basePath);
|
||||
}
|
||||
|
||||
private:
|
||||
BaseWindow::WallpaperType parseWallpaperType(const QString& type);
|
||||
|
||||
private:
|
||||
bool m_checkWallpaperVisible { false };
|
||||
bool m_visualsPaused { false };
|
||||
|
Loading…
Reference in New Issue
Block a user