Skip to content
Snippets Groups Projects
Commit 8c73ce4a authored by akiraohgaki's avatar akiraohgaki
Browse files

Add function to evalute script with plasmashell

parent 7e3d8e04
No related branches found
No related tags found
No related merge requests found
...@@ -64,8 +64,8 @@ bool SystemHandler::openUrl(const QString &url) const ...@@ -64,8 +64,8 @@ bool SystemHandler::openUrl(const QString &url) const
QString SystemHandler::desktopEnvironment() const QString SystemHandler::desktopEnvironment() const
{ {
QString desktop = ""; QString desktop;
QString currentDesktop = ""; QString currentDesktop;
if (!qgetenv("XDG_CURRENT_DESKTOP").isEmpty()) { if (!qgetenv("XDG_CURRENT_DESKTOP").isEmpty()) {
currentDesktop = QString::fromLocal8Bit(qgetenv("XDG_CURRENT_DESKTOP").constData()).toLower(); currentDesktop = QString::fromLocal8Bit(qgetenv("XDG_CURRENT_DESKTOP").constData()).toLower();
...@@ -168,10 +168,21 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c ...@@ -168,10 +168,21 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c
#endif #endif
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
bool SystemHandler::applyKdeWallpaper(const QString &path) const bool SystemHandler::evaluateScriptWithPlasmaShell(const QString &script) const
{ {
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript"); auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
message.setArguments(QVariantList() << QVariant(script));
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
return false;
}
return true;
}
bool SystemHandler::applyKdeWallpaper(const QString &path) const
{
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
out << "for (var key in desktops()) {" out << "for (var key in desktops()) {"
...@@ -181,24 +192,12 @@ bool SystemHandler::applyKdeWallpaper(const QString &path) const ...@@ -181,24 +192,12 @@ bool SystemHandler::applyKdeWallpaper(const QString &path) const
<< "d.writeConfig('Image', 'file://" + path + "');" << "d.writeConfig('Image', 'file://" + path + "');"
<< "}"; << "}";
QVariantList arguments; return evaluateScriptWithPlasmaShell(script);
arguments << QVariant(script);
message.setArguments(arguments);
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
return false;
}
return true;
} }
bool SystemHandler::applyKdeIcon(const QString &path) const bool SystemHandler::applyKdeIcon(const QString &path) const
{ {
auto themeName = QFileInfo(path).fileName(); auto themeName = QFileInfo(path).fileName();
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
...@@ -206,27 +205,17 @@ bool SystemHandler::applyKdeIcon(const QString &path) const ...@@ -206,27 +205,17 @@ bool SystemHandler::applyKdeIcon(const QString &path) const
<< "c.group = 'Icons';" << "c.group = 'Icons';"
<< "c.writeEntry('Theme', '" + themeName + "');"; << "c.writeEntry('Theme', '" + themeName + "');";
QVariantList arguments; if (evaluateScriptWithPlasmaShell(script)) {
arguments << QVariant(script); QProcess::startDetached("kquitapp5 plasmashell");
message.setArguments(arguments); QProcess::startDetached("kstart5 plasmashell");
return true;
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
return false;
} }
return false;
QProcess::startDetached("kquitapp5 plasmashell");
QProcess::startDetached("kstart5 plasmashell");
return true;
} }
bool SystemHandler::applyKdeCursor(const QString &path) const bool SystemHandler::applyKdeCursor(const QString &path) const
{ {
auto themeName = QFileInfo(path).fileName(); auto themeName = QFileInfo(path).fileName();
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
...@@ -234,24 +223,12 @@ bool SystemHandler::applyKdeCursor(const QString &path) const ...@@ -234,24 +223,12 @@ bool SystemHandler::applyKdeCursor(const QString &path) const
<< "c.group = 'Mouse';" << "c.group = 'Mouse';"
<< "c.writeEntry('cursorTheme', '" + themeName + "');"; << "c.writeEntry('cursorTheme', '" + themeName + "');";
QVariantList arguments; return evaluateScriptWithPlasmaShell(script);
arguments << QVariant(script);
message.setArguments(arguments);
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
return false;
}
return true;
} }
bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &path) const bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &path) const
{ {
auto themeName = QFileInfo(path).fileName(); auto themeName = QFileInfo(path).fileName();
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
...@@ -259,27 +236,17 @@ bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &path) const ...@@ -259,27 +236,17 @@ bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &path) const
<< "c.group = 'Theme';" << "c.group = 'Theme';"
<< "c.writeEntry('name', '" + themeName + "');"; << "c.writeEntry('name', '" + themeName + "');";
QVariantList arguments; if (evaluateScriptWithPlasmaShell(script)) {
arguments << QVariant(script); QProcess::startDetached("kquitapp5 plasmashell");
message.setArguments(arguments); QProcess::startDetached("kstart5 plasmashell");
return true;
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
return false;
} }
return false;
QProcess::startDetached("kquitapp5 plasmashell");
QProcess::startDetached("kstart5 plasmashell");
return true;
} }
bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const
{ {
auto themeName = QFileInfo(path).fileName(); auto themeName = QFileInfo(path).fileName();
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
...@@ -288,21 +255,12 @@ bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const ...@@ -288,21 +255,12 @@ bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const
<< "c.writeEntry('library', 'org.kde.kwin.aurorae');" << "c.writeEntry('library', 'org.kde.kwin.aurorae');"
<< "c.writeEntry('theme', '__aurorae__svg__" + themeName + "');"; << "c.writeEntry('theme', '__aurorae__svg__" + themeName + "');";
QVariantList arguments; if (evaluateScriptWithPlasmaShell(script)) {
arguments << QVariant(script); auto refreshMessage = QDBusMessage::createMethodCall("org.kde.KWin", "/KWin", "org.kde.KWin", "reconfigure");
message.setArguments(arguments); QDBusConnection::sessionBus().call(refreshMessage);
return true;
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
return false;
} }
return false;
auto refreshMessage = QDBusMessage::createMethodCall("org.kde.KWin", "/KWin", "org.kde.KWin", "reconfigure");
QDBusConnection::sessionBus().call(refreshMessage);
return true;
} }
bool SystemHandler::applyGnomeWallpaper(const QString &path) const bool SystemHandler::applyGnomeWallpaper(const QString &path) const
......
...@@ -23,6 +23,7 @@ public slots: ...@@ -23,6 +23,7 @@ public slots:
private: private:
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
bool evaluateScriptWithPlasmaShell(const QString &script) const;
bool applyKdeWallpaper(const QString &path) const; bool applyKdeWallpaper(const QString &path) const;
bool applyKdeIcon(const QString &path) const; bool applyKdeIcon(const QString &path) const;
bool applyKdeCursor(const QString &path) const; bool applyKdeCursor(const QString &path) const;
......
...@@ -15,6 +15,7 @@ WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &se ...@@ -15,6 +15,7 @@ WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &se
: QObject(parent), configHandler_(configHandler), serverName_(serverName), serverPort_(serverPort) : QObject(parent), configHandler_(configHandler), serverName_(serverName), serverPort_(serverPort)
{ {
wsServer_ = new QWebSocketServer(serverName_, QWebSocketServer::NonSecureMode, this); wsServer_ = new QWebSocketServer(serverName_, QWebSocketServer::NonSecureMode, this);
connect(wsServer_, &QWebSocketServer::newConnection, this, &WebSocketServer::wsNewConnection); connect(wsServer_, &QWebSocketServer::newConnection, this, &WebSocketServer::wsNewConnection);
connect(wsServer_, &QWebSocketServer::closed, this, &WebSocketServer::stopped); connect(wsServer_, &QWebSocketServer::closed, this, &WebSocketServer::stopped);
...@@ -22,6 +23,7 @@ WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &se ...@@ -22,6 +23,7 @@ WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &se
systemHandler_ = new SystemHandler(this); systemHandler_ = new SystemHandler(this);
ocsApiHandler_ = new OcsApiHandler(configHandler_, this); ocsApiHandler_ = new OcsApiHandler(configHandler_, this);
itemHandler_ = new ItemHandler(configHandler_, this); itemHandler_ = new ItemHandler(configHandler_, this);
connect(itemHandler_, &ItemHandler::metadataSetChanged, this, &WebSocketServer::itemMetadataSetChanged); connect(itemHandler_, &ItemHandler::metadataSetChanged, this, &WebSocketServer::itemMetadataSetChanged);
connect(itemHandler_, &ItemHandler::downloadStarted, this, &WebSocketServer::itemDownloadStarted); connect(itemHandler_, &ItemHandler::downloadStarted, this, &WebSocketServer::itemDownloadStarted);
connect(itemHandler_, &ItemHandler::downloadFinished, this, &WebSocketServer::itemDownloadFinished); connect(itemHandler_, &ItemHandler::downloadFinished, this, &WebSocketServer::itemDownloadFinished);
...@@ -75,9 +77,11 @@ QUrl WebSocketServer::serverUrl() const ...@@ -75,9 +77,11 @@ QUrl WebSocketServer::serverUrl() const
void WebSocketServer::wsNewConnection() void WebSocketServer::wsNewConnection()
{ {
auto *wsClient = wsServer_->nextPendingConnection(); auto *wsClient = wsServer_->nextPendingConnection();
connect(wsClient, &QWebSocket::disconnected, this, &WebSocketServer::wsDisconnected); connect(wsClient, &QWebSocket::disconnected, this, &WebSocketServer::wsDisconnected);
connect(wsClient, &QWebSocket::textMessageReceived, this, &WebSocketServer::wsTextMessageReceived); connect(wsClient, &QWebSocket::textMessageReceived, this, &WebSocketServer::wsTextMessageReceived);
connect(wsClient, &QWebSocket::binaryMessageReceived, this, &WebSocketServer::wsBinaryMessageReceived); connect(wsClient, &QWebSocket::binaryMessageReceived, this, &WebSocketServer::wsBinaryMessageReceived);
wsClients_ << wsClient; wsClients_ << wsClient;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment