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

Add basic kde setup

This commit is contained in:
Elias Steurer 2022-04-24 16:38:12 +02:00
parent a270fac447
commit 12053d9531
8 changed files with 142 additions and 61 deletions

View File

@ -1,7 +1,7 @@
stages: stages:
- check
- build - build
- release - release
- check
- test - test
variables: variables:

View File

@ -213,6 +213,7 @@ void App::init()
QGuiApplication::instance()->addLibraryPath(QGuiApplication::instance()->applicationDirPath()); QGuiApplication::instance()->addLibraryPath(QGuiApplication::instance()->applicationDirPath());
if (m_settings->desktopEnvironment() == Settings::DesktopEnvironment::KDE) { if (m_settings->desktopEnvironment() == Settings::DesktopEnvironment::KDE) {
setupKDE(); setupKDE();
} }
@ -237,72 +238,110 @@ void App::exit()
QApplication::instance()->quit(); QApplication::instance()->quit();
} }
/*! bool App::isKDEInstalled()
\brief
*/
bool App::setupKDE()
{ {
QProcessEnvironment env;
qInfo() << qgetenv("KDE_FULL_SESSION");
qInfo() << qgetenv("DESKTOP_SESSION");
qInfo() << qgetenv("XDG_CURRENT_DESKTOP");
QProcess plasmaShellVersionProcess; QProcess plasmaShellVersionProcess;
plasmaShellVersionProcess.start("plasmashell", { "--version" }); plasmaShellVersionProcess.start("plasmashell", { "--version" });
plasmaShellVersionProcess.waitForFinished(); plasmaShellVersionProcess.waitForFinished();
QString versionOut = plasmaShellVersionProcess.readAll(); QString versionOut = plasmaShellVersionProcess.readAll();
if (!versionOut.contains("plasmashell ")) { if (!versionOut.contains("plasmashell ")) {
qWarning() << "Unable to read plasma shell version"; qWarning() << "Unable to read plasma shell version. ScreenPlay only works on KDE";
return false; return false;
} }
return true;
}
const QString kdeWallpaperPath = QDir(QDir::homePath() + "/.local/share/plasma/wallpapers/ScreenPlay/").canonicalPath(); void App::installKDEWallpaper()
const QFileInfo installedWallpaperMetadata(kdeWallpaperPath + "/metadata.desktop"); {
const QString appKdeWallapperPath = QGuiApplication::instance()->applicationDirPath() + "/kde";
const QFileInfo currentWallpaperMetadata(appKdeWallapperPath + "/ScreenPlay/metadata.desktop");
if (!installedWallpaperMetadata.exists()) { qInfo() << "Install ScreenPlay KDE Wallpaper";
process.setWorkingDirectory(appKdeWallapperPath); QProcess process;
process.start("plasmapkg2", { "--install", "ScreenPlay" }); process.setWorkingDirectory(m_appKdeWallapperPath);
process.waitForFinished(); process.start("plasmapkg2", { "--install", "ScreenPlay" });
process.terminate(); process.waitForFinished();
qInfo() << "Install ScreenPlay KDE Wallpaper"; process.terminate();
} else { }
QSettings installedWallpaperSettings(installedWallpaperMetadata.absoluteFilePath(), QSettings::Format::IniFormat);
installedWallpaperSettings.beginGroup("Desktop Entry");
const QString installedWallpaperVersion = installedWallpaperSettings.value("Version").toString();
installedWallpaperSettings.endGroup();
const QVersionNumber installedVersionNumber = QVersionNumber::fromString(installedWallpaperVersion);
QSettings currentWallpaperSettings(currentWallpaperMetadata.absoluteFilePath(), QSettings::Format::IniFormat); void App::upgradeKDEWallpaper()
currentWallpaperSettings.beginGroup("Desktop Entry"); {
const QString currentWallpaperVersion = currentWallpaperSettings.value("Version").toString();
currentWallpaperSettings.endGroup();
const QVersionNumber currentVersionNumber = QVersionNumber::fromString(installedWallpaperVersion);
if (installedVersionNumber.isNull() || currentVersionNumber.isNull()) { qInfo() << "Upgrade ScreenPlay KDE Wallpaper";
qCritical() << "Unable to parse version number from:" << currentWallpaperVersion << installedWallpaperVersion; QProcess process;
return false; process.setWorkingDirectory(m_appKdeWallapperPath);
} process.start("plasmapkg2", { "--upgrade", "ScreenPlay" });
process.waitForFinished();
if (installedVersionNumber <= currentVersionNumber) process.terminate();
return true; qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
}
qInfo() << "Upgrade ScreenPlay KDE Wallpaper";
process.setWorkingDirectory(appKdeWallapperPath);
process.start("plasmapkg2", { "--upgrade", "ScreenPlay" });
process.waitForFinished();
process.terminate();
qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
}
void App::restartKDE()
{
qInfo() << "Restart KDE "; qInfo() << "Restart KDE ";
QProcess process;
process.start("kquitapp5", { "plasmashell" }); process.start("kquitapp5", { "plasmashell" });
process.waitForFinished(); process.waitForFinished();
process.terminate(); process.terminate();
qInfo() << process.readAllStandardError() << process.readAllStandardOutput(); qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
process.startDetached("kstart5", { "plasmashell" }); process.startDetached("kstart5", { "plasmashell" });
qInfo() << process.readAllStandardError() << process.readAllStandardOutput(); qInfo() << process.readAllStandardError() << process.readAllStandardOutput();
return true;
} }
std::optional<bool> App::isNewestKDEWallpaperInstalled()
{
QFileInfo installedWallpaperMetadata(m_kdeWallpaperPath + "/metadata.desktop");
QSettings installedWallpaperSettings(installedWallpaperMetadata.absoluteFilePath(), QSettings::Format::IniFormat);
installedWallpaperSettings.beginGroup("Desktop Entry");
const QString installedWallpaperVersion = installedWallpaperSettings.value("Version").toString();
installedWallpaperSettings.endGroup();
const QVersionNumber installedVersionNumber = QVersionNumber::fromString(installedWallpaperVersion);
QFileInfo currentWallpaperMetadata(m_appKdeWallapperPath + "/ScreenPlay/metadata.desktop");
QSettings currentWallpaperSettings(currentWallpaperMetadata.absoluteFilePath(), QSettings::Format::IniFormat);
currentWallpaperSettings.beginGroup("Desktop Entry");
const QString currentWallpaperVersion = currentWallpaperSettings.value("Version").toString();
currentWallpaperSettings.endGroup();
const QVersionNumber currentVersionNumber = QVersionNumber::fromString(currentWallpaperVersion);
qInfo() << "installedVersionNumber" << installedVersionNumber << "currentVersionNumber " << currentVersionNumber;
if (installedVersionNumber.isNull() || currentVersionNumber.isNull()) {
qInfo() << "Unable to parse version number from:" << currentWallpaperVersion << installedWallpaperVersion;
qInfo() << "Reinstall ScreenPlay Wallpaper";
return std::nullopt;
} else {
return {installedVersionNumber >= currentVersionNumber};
}
}
/*!
\brief
*/
bool App::setupKDE()
{
m_kdeWallpaperPath = QDir(QDir::homePath() + "/.local/share/plasma/wallpapers/ScreenPlay/").canonicalPath();
m_appKdeWallapperPath = QGuiApplication::instance()->applicationDirPath() + "/kde";
if (!isKDEInstalled())
return false;
QFileInfo installedWallpaperMetadata(m_kdeWallpaperPath + "/metadata.desktop");
if (!installedWallpaperMetadata.exists()) {
installKDEWallpaper();
restartKDE();
return true;
}
if (auto isNewer = isNewestKDEWallpaperInstalled()) {
if (!isNewer.value()) {
upgradeKDEWallpaper();
return true;
}
qInfo() << "All up to date!" << isNewer.value();
return true;
} else {
return false;
}
}
} }

View File

@ -217,6 +217,11 @@ public slots:
private: private:
bool setupKDE(); bool setupKDE();
bool isKDEInstalled();
void installKDEWallpaper();
void upgradeKDEWallpaper();
void restartKDE();
std::optional<bool> isNewestKDEWallpaperInstalled();
private: private:
QNetworkAccessManager m_networkAccessManager; QNetworkAccessManager m_networkAccessManager;
@ -229,12 +234,14 @@ private:
std::unique_ptr<Util> m_util; std::unique_ptr<Util> m_util;
std::shared_ptr<GlobalVariables> m_globalVariables; std::shared_ptr<GlobalVariables> m_globalVariables;
std::shared_ptr<Settings> m_settings;
std::shared_ptr<Settings> m_settings;
std::shared_ptr<InstalledListModel> m_installedListModel; std::shared_ptr<InstalledListModel> m_installedListModel;
std::shared_ptr<MonitorListModel> m_monitorListModel; std::shared_ptr<MonitorListModel> m_monitorListModel;
std::shared_ptr<ProfileListModel> m_profileListModel; std::shared_ptr<ProfileListModel> m_profileListModel;
std::shared_ptr<InstalledListFilter> m_installedListFilter; std::shared_ptr<InstalledListFilter> m_installedListFilter;
QProcess process;
QString m_kdeWallpaperPath;
QString m_appKdeWallapperPath;
}; };
} }

View File

@ -93,10 +93,12 @@ void ScreenPlayManager::init(
}); });
QObject::connect(socket, &QWebSocket::disconnected, this, [this, socket]() { QObject::connect(socket, &QWebSocket::disconnected, this, [this, socket]() {
m_connections.removeOne(socket); m_connections.removeOne(socket);
setIsKDEConnected(false);
qInfo() << "Disconnected connection count: " << m_connections.count(); qInfo() << "Disconnected connection count: " << m_connections.count();
}); });
m_connections.push_back(socket); m_connections.push_back(socket);
setIsKDEConnected(true);
// socket->flush(); // socket->flush();
}); });
} }
@ -470,6 +472,7 @@ void ScreenPlayManager::newConnection()
m_unconnectedClients.push_back(std::move(connection)); m_unconnectedClients.push_back(std::move(connection));
} }
/*! /*!
\brief Removes a wallpaper from the given appID. Returns true on success. \brief Removes a wallpaper from the given appID. Returns true on success.
*/ */
@ -726,4 +729,18 @@ TEST_CASE("Loads profiles.json")
GlobalVariables globalVariables; GlobalVariables globalVariables;
ScreenPlayManager manager; ScreenPlayManager manager;
} }
bool ScreenPlayManager::isKDEConnected() const
{
return m_isKDEConnected;
}
void ScreenPlayManager::setIsKDEConnected(bool isKDEConnected)
{
if (m_isKDEConnected == isKDEConnected)
return;
m_isKDEConnected = isKDEConnected;
emit isKDEConnectedChanged(isKDEConnected);
}
} }

View File

@ -61,6 +61,7 @@ class ScreenPlayManager : public QObject {
Q_PROPERTY(int activeWallpaperCounter READ activeWallpaperCounter WRITE setActiveWallpaperCounter NOTIFY activeWallpaperCounterChanged) Q_PROPERTY(int activeWallpaperCounter READ activeWallpaperCounter WRITE setActiveWallpaperCounter NOTIFY activeWallpaperCounterChanged)
Q_PROPERTY(int activeWidgetsCounter READ activeWidgetsCounter WRITE setActiveWidgetsCounter NOTIFY activeWidgetsCounterChanged) Q_PROPERTY(int activeWidgetsCounter READ activeWidgetsCounter WRITE setActiveWidgetsCounter NOTIFY activeWidgetsCounterChanged)
Q_PROPERTY(bool isKDEConnected READ isKDEConnected WRITE setIsKDEConnected NOTIFY isKDEConnectedChanged)
public: public:
explicit ScreenPlayManager(QObject* parent = nullptr); explicit ScreenPlayManager(QObject* parent = nullptr);
@ -74,6 +75,9 @@ public:
int activeWidgetsCounter() const { return m_activeWidgetsCounter; } int activeWidgetsCounter() const { return m_activeWidgetsCounter; }
bool isAnotherScreenPlayInstanceRunning() { return m_isAnotherScreenPlayInstanceRunning; } bool isAnotherScreenPlayInstanceRunning() { return m_isAnotherScreenPlayInstanceRunning; }
bool isKDEConnected() const;
void setIsKDEConnected(bool isKDEConnected);
signals: signals:
void activeWallpaperCounterChanged(int activeWallpaperCounter); void activeWallpaperCounterChanged(int activeWallpaperCounter);
void activeWidgetsCounterChanged(int activeWidgetsCounter); void activeWidgetsCounterChanged(int activeWidgetsCounter);
@ -85,6 +89,8 @@ signals:
void profilesSaved(); void profilesSaved();
void displayErrorPopup(const QString& msg); void displayErrorPopup(const QString& msg);
void isKDEConnectedChanged(bool isKDEConnected);
private slots: private slots:
bool saveProfiles(); bool saveProfiles();
@ -196,6 +202,7 @@ private:
QTimer m_saveLimiter; QTimer m_saveLimiter;
const quint16 m_webSocketPort = 16395; const quint16 m_webSocketPort = 16395;
bool m_isKDEConnected = false;
}; };
} }

View File

@ -6,9 +6,9 @@
<kcfgfile name=""/> <kcfgfile name=""/>
<group name="General"> <group name="General">
<entry name="StopWallpaperIfHidden" type="Bool"> <entry name="MonitorIndex" type="int">
<label>Stop Wallpaper if not visible</label> <label>Monitor Index aaa</label>
<default>false</default> <default>0</default>
</entry> </entry>
</group> </group>

View File

@ -12,7 +12,8 @@ import org.kde.newstuff 1.1 as NewStuff
Column { Column {
id: root id: root
property alias cfg_StopWallpaperIfHidden: stopWallpaperIfHidden.checked property alias cfg_MonitorIndex: monitorIndex.text
anchors.fill: parent anchors.fill: parent
spacing: units.largeSpacing spacing: units.largeSpacing
@ -21,12 +22,12 @@ Column {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
spacing: units.largeSpacing spacing: units.largeSpacing
QQC.CheckBox { QQC.TextField {
id: stopWallpaperIfHidden id: monitorIndex
text: "0"
text: i18nd("plasma_applet_org.kde.image", "Stop animation when a window is maximized")
} }
} }
} }

View File

@ -5,6 +5,7 @@ import QtWebEngine 1.8
import QtMultimedia 5.12 import QtMultimedia 5.12
import Qt.labs.settings 1.1 import Qt.labs.settings 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
Rectangle { Rectangle {
id:root id:root
@ -22,7 +23,7 @@ Rectangle {
wallpaper.type = settings.value("SP_type") wallpaper.type = settings.value("SP_type")
wallpaper.fillMode = settings.value("SP_fillMode") wallpaper.fillMode = settings.value("SP_fillMode")
wallpaper.volume = settings.value("SP_volume") //wallpaper.volume = settings.value("SP_volume")
wallpaper.play() wallpaper.play()
} }
@ -101,12 +102,21 @@ Rectangle {
} }
Text { Text {
color: "white" color: "white"
text:wallpaper.type + wallpaper.projectSourceFileAbsolute text: "wallpaper.type: " + wallpaper.type
} }
Text { Text {
color: "white" color: "white"
text:"Actitve: " +socket.active +" status: "+ socket.status + " reconnectTimer.retryCounter : "+ reconnectTimer.retryCounter text: "projectSourceFileAbsolute " + wallpaper.projectSourceFileAbsolute
}arrier
Text {
color: "white"
text:"reconnectTimer.retryCounter : "+ reconnectTimer.retryCounter
} }
Text {
color: "white"
text: "MonitorIndex: " + wallpaper.configuration.MonitorIndex
}
} }