1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-06 09:17:07 +02:00

Merge Basic kde support via websockets

This commit is contained in:
Graphicscore 2021-10-23 16:30:13 +02:00
commit c89c3ae3e2
10 changed files with 108 additions and 94 deletions

View File

@ -32,7 +32,7 @@ py setup.py
Append this:
``` bash
CMAKE_TOOLCHAIN_FILE:STRING=%{CurrentProject:Path}/../ScreenPlay-vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake
CMAKE_TOOLCHAIN_FILE:STRING=%{CurrentProject:Path}/../ScreenPlay-vcpkg/scripts/buildsystems/vcpkg.cmake
# Only _one_ of these lines that match your OS:
VCPKG_TARGET_TRIPLET:STRING=x64-windows
VCPKG_TARGET_TRIPLET:STRING=x64-linux
@ -68,7 +68,7 @@ VCPKG_TARGET_TRIPLET:STRING=x64-osx
1. Install dependencies for your distro:
``` bash
# Debian/Ubuntu
sudo apt install build-essential libgl1-mesa-dev lld ninja-build cmake
sudo apt install build-essential libgl1-mesa-dev lld ninja-build cmake git curl pkg-config ffmpeg qml-module-qt-websockets qtwebengine5-*
# Fedora/RHEL/CentOS (yum)
sudo yum groupinstall "C Development Tools and Libraries"

View File

@ -53,8 +53,15 @@ CreateImportVideo::CreateImportVideo(const QString& videoPath, const QString& ex
void CreateImportVideo::setupFFMPEG()
{
#ifdef Q_OS_LINUX
// Use system ffmpeg
m_ffprobeExecutable = "ffprobe";
m_ffmpegExecutable = "ffmpeg";
#else
m_ffprobeExecutable = QApplication::applicationDirPath() + "/ffprobe" + ScreenPlayUtil::executableBinEnding();
m_ffmpegExecutable = QApplication::applicationDirPath() + "/ffmpeg" + ScreenPlayUtil::executableBinEnding();
#endif
if (!QFileInfo::exists(m_ffprobeExecutable)) {
qFatal("FFPROBE executable not found!");
@ -126,10 +133,9 @@ bool CreateImportVideo::createWallpaperInfo()
}
if (obj->empty()) {
qWarning() << "Error! File could not be parsed.";
qCritical() << "Error! File could not be parsed.";
emit processOutput("Error! File could not be parsed.");
emit createWallpaperStateChanged(ImportVideoState::ImportVideoState::AnalyseVideoError);
return false;
}

View File

@ -87,6 +87,18 @@ void ScreenPlayManager::init(
QObject::connect(m_websocketServer.get(), &QWebSocketServer::newConnection, this, [this]() {
qInfo() << "New Websocket Connection";
auto* socket = m_websocketServer->nextPendingConnection();
QObject::connect(socket, &QWebSocket::textMessageReceived, this, [this](const QString &message) {
qInfo() << "Message:" << message;
});
QObject::connect(socket, &QWebSocket::disconnected, this, [this,socket]() {
m_connections.removeOne(socket);
qInfo() << "Disconnected connection count: " << m_connections.count();
});
m_connections.push_back(socket);
socket->sendTextMessage("asdasd");
socket->flush();
});
}
@ -137,6 +149,22 @@ bool ScreenPlayManager::createWallpaper(
const QString path = QUrl::fromUserInput(absoluteStoragePath).toLocalFile();
const QString appID = ScreenPlayUtil::generateRandomString();
if(m_settings->desktopEnvironment() == Settings::DesktopEnvironment::KDE){
if(m_connections.empty())
return false;
QJsonObject msg;
msg.insert("command", "replace");
msg.insert("absolutePath", path);
msg.insert("type", static_cast<int>(type));
msg.insert("fillMode", static_cast<int>(fillMode));
msg.insert("volume", volume);
msg.insert("file", file);
m_connections.first()->sendTextMessage(QJsonDocument(msg).toJson());
m_connections.first()->flush();
}
// Only support remove wallpaper that spans over 1 monitor
if (monitorIndex.length() == 1) {
int i = 0;
@ -172,14 +200,16 @@ bool ScreenPlayManager::createWallpaper(
fillMode,
type,
properties,
m_settings->checkWallpaperVisible());
m_settings);
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::requestSaveProfiles);
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestClose, this, &ScreenPlayManager::removeWallpaper);
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::error, this, &ScreenPlayManager::displayErrorPopup);
if (!wallpaper->start()) {
return false;
}
if(m_settings->desktopEnvironment() != Settings::DesktopEnvironment::KDE){
if (!wallpaper->start()) {
return false;
}
}
m_screenPlayWallpapers.append(wallpaper);
m_monitorListModel->setWallpaperMonitor(wallpaper, monitorIndex);
increaseActiveWallpaperCounter();

View File

@ -182,6 +182,7 @@ private:
std::shared_ptr<Settings> m_settings;
std::unique_ptr<QLocalServer> m_server;
std::unique_ptr<QWebSocketServer> m_websocketServer;
QVector<QWebSocket*> m_connections;
QVector<std::shared_ptr<ScreenPlayWallpaper>> m_screenPlayWallpapers;
QVector<std::shared_ptr<ScreenPlayWidget>> m_screenPlayWidgets;

View File

@ -24,7 +24,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const QJsonObject& properties,
const bool checkWallpaperVisible,
const std::shared_ptr<Settings>& settings,
QObject* parent)
: QObject(parent)
, m_globalVariables { globalVariables }
@ -37,6 +37,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
, m_file { file }
, m_volume { volume }
, m_playbackRate { playbackRate }
, m_settings { settings }
{
QJsonObject projectSettingsListModelProperties;
@ -81,7 +82,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
QString::number(static_cast<double>(volume)),
QVariant::fromValue(fillMode).toString(),
QVariant::fromValue(type).toString(),
QString::number(checkWallpaperVisible),
QString::number(m_settings->checkWallpaperVisible()),
// Fixes issue 84 media key overlay
" --disable-features=HardwareMediaKeyHandling"
};

View File

@ -45,6 +45,7 @@
#include "projectsettingslistmodel.h"
#include "sdkconnection.h"
#include "util.h"
#include "settings.h"
namespace ScreenPlay {
@ -76,12 +77,15 @@ public:
const QString& absolutePath,
const QString& previewImage,
const QString& file,
const float volume, const float playbackRate,
const float volume,
const float playbackRate,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type, const QJsonObject& properties,
const bool checkWallpaperVisible,
const InstalledType::InstalledType type,
const QJsonObject& properties,
const std::shared_ptr<Settings>& settings,
QObject* parent = nullptr);
bool start();
void replace(
@ -228,6 +232,7 @@ public slots:
private:
const std::shared_ptr<GlobalVariables> m_globalVariables;
std::unique_ptr<SDKConnection> m_connection;
const std::shared_ptr<Settings> m_settings;
ProjectSettingsListModel m_projectSettingsListModel;
QVector<int> m_screenNumber;

View File

@ -6,6 +6,8 @@ Will not work because KDE uses the kpluginindex.json (that is actually a bz2 fil
#### Installation
```
sudo apt install qml-module-qt-websockets qtwebengine5-*
plasmapkg2 --install ScreenPlay
```
@ -21,3 +23,6 @@ Because Wallpaper and Widgets are already a different application we can extend
1. Open Desktop Settings
- Select Wallpaper type ScreenPlay
```
plasmapkg2 --upgrade ScreenPlay ; kquitapp5 plasmashell; kstart5 plasmashell
```

View File

@ -1,13 +1,14 @@
import QtQuick
import QtQuick.Controls as QQC
import QtQuick.Window
import Qt5Compat.GraphicalEffects
import QtQuick 2.11
import QtQuick.Controls 2.4 as QQC
import QtQuick.Window 2.0
import QtGraphicalEffects 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.wallpapers.image 2.0 as Wallpaper
import org.kde.kcm 1.1 as KCM
import org.kde.kirigami 2.4 as Kirigami
import org.kde.newstuff 1.1 as NewStuff
Column {
id: root

View File

@ -1,11 +1,13 @@
import QtQuick
import Qt5Compat.GraphicalEffects
import QtQuick.Window
import QtQuick 2.11
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
import QtQuick.Window 2.15
import Qt.WebSockets 1.15
import QtWebEngine
import QtWebEngine 1.8
Rectangle {
id: root
color: "orange"
property string fullContentPath
property real volume: 1
@ -15,28 +17,25 @@ Rectangle {
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 = '" + root.fullContentPath + "';";
src += "videoPlayer.load();";
src += "videoPlayer.volume = " + root.volume + ";";
src += "videoPlayer.setAttribute('style', 'object-fit :" + root.fillMode + ";');";
src += "videoPlayer.play();";
print(src);
return src;
var src = ""
src += "var videoPlayer = document.getElementById('videoPlayer');"
src += "var videoSource = document.getElementById('videoSource');"
src += "videoSource.src = '" + root.fullContentPath + "';"
src += "videoPlayer.load();"
src += "videoPlayer.volume = " + root.volume + ";"
src += "videoPlayer.setAttribute('style', 'object-fit :" + root.fillMode + ";');"
src += "videoPlayer.play();"
return src
}
color: "#333333"
Component.onCompleted: {
WebEngine.settings.localContentCanAccessFileUrls = true;
WebEngine.settings.localContentCanAccessRemoteUrls = true;
WebEngine.settings.allowRunningInsecureContent = true;
WebEngine.settings.accelerated2dCanvasEnabled = true;
WebEngine.settings.javascriptCanOpenWindows = false;
WebEngine.settings.showScrollBars = false;
WebEngine.settings.playbackRequiresUserGesture = false;
WebEngine.settings.focusOnNavigationEnabled = true;
WebEngine.settings.localContentCanAccessFileUrls = true
WebEngine.settings.localContentCanAccessRemoteUrls = true
WebEngine.settings.allowRunningInsecureContent = true
WebEngine.settings.accelerated2dCanvasEnabled = true
WebEngine.settings.javascriptCanOpenWindows = false
WebEngine.settings.showScrollBars = false
WebEngine.settings.playbackRequiresUserGesture = false
WebEngine.settings.focusOnNavigationEnabled = true
}
WebSocket {
@ -45,21 +44,25 @@ Rectangle {
url: "ws://127.0.0.1:16395"
active: true
onStatusChanged: {
if (socket.status === WebSocket.Error)
messageBox.text = "Error: " + socket.errorString;
else if (socket.status === WebSocket.Open)
socket.sendTextMessage("Hello World");
else if (socket.status === WebSocket.Closed)
messageBox.text += "Socket closed";
if (socket.status === WebSocket.Open)
socket.sendTextMessage("Hello World from QML wallpaper")
}
onTextMessageReceived: {
var obj = JSON.parse(message);
socket.sendTextMessage(message)
print(message)
var obj = JSON.parse(message)
if (obj.command === "replace") {
root.type = obj.type;
root.fillMode = obj.fillMode;
root.volume = obj.volume;
root.fullContentPath = obj.absolutePath + "/" + obj.file;
webView.setVideo();
socket.sendTextMessage("replace")
root.type = obj.type
//root.fillMode = obj.fillMode
root.volume = obj.volume
root.fullContentPath = obj.absolutePath + "/" + obj.file
const msg = "JSON: " +root.type + root.fillMode + root.volume + root.fullContentPath;
socket.sendTextMessage(root.getSetVideoCommand())
webView.setVideo()
}
}
}
@ -70,31 +73,8 @@ Rectangle {
function setVideo() {
webView.runJavaScript(root.getSetVideoCommand());
}
url:"index.html"
anchors.fill: parent
opacity: loadProgress === 100 ? 1 : 0
onLoadProgressChanged: {
if (loadProgress === 100)
setVideo();
}
}
Rectangle {
id: infoWrapper
width: 300
height: 200
opacity: 0
anchors.centerIn: parent
Text {
id: messageBox
text: qsTr("text")
anchors.centerIn: parent
}
}
}

View File

@ -46,24 +46,9 @@ LinuxWindow::LinuxWindow(
setHeight(m_window.height());
m_window.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_window.rootContext()->setContextProperty("window", this);
//m_window.rootContext()->setContextProperty("desktopProperties", &m_windowsDesktopProperties);
// Instead of setting "renderType: Text.NativeRendering" every time
// we can set it here once :)
qmlRegisterSingletonInstance<LinuxWindow>("ScreenPlayWallpaper", 1, 0, "Wallpaper", this);
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
m_window.setSource(QUrl("qrc:/mainWindow.qml"));
// WARNING: Setting Window flags must be called *here*!
Qt::WindowFlags flags = m_window.flags();
m_window.setFlags(flags | Qt::FramelessWindowHint | Qt::Desktop);
m_window.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_window.rootContext()->setContextProperty("window", this);
// Instead of setting "renderType: Text.NativeRendering" every time
// we can set it here once :)
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
m_window.setSource(QUrl("qrc:/Wallpaper.qml"));
m_window.setSource(QUrl("qrc:/ScreenPlayWallpaper/qml/Wallpaper.qml"));
}
void LinuxWindow::setupWallpaperForOneScreen(int activeScreen)