diff --git a/app/configs/application.json b/app/configs/application.json index 2533be21b101c51543364db86f3ba1de079d6c21..562652bbc03967f29bf47ef5565b9901455ff2ef 100644 --- a/app/configs/application.json +++ b/app/configs/application.json @@ -1,7 +1,7 @@ { "id": "ocs-manager", "name": "ocs-manager", - "version": "0.3.1", + "version": "0.3.2", "organization": "Opendesktop.org", "domain": "org.opendesktop.ocs-manager", "icon": "", diff --git a/app/src/handlers/itemhandler.h b/app/src/handlers/itemhandler.h index 43d50683190b3038c4833204144c3dd43227cadc..83ebe3a187e3d6ea3be885142e95620ecc2e28dc 100644 --- a/app/src/handlers/itemhandler.h +++ b/app/src/handlers/itemhandler.h @@ -31,9 +31,9 @@ signals: public slots: QJsonObject metadataSet() const; - void getItem(const QString &command, const QString &url, const QString &installType, const QString &filename = "", - const QString &providerKey = "", const QString &contentId = ""); - void getItemByOcsUrl(const QString &ocsUrl, const QString &providerKey = "", const QString &contentId = ""); + void getItem(const QString &command, const QString &url, const QString &installType, const QString &filename = QString(), + const QString &providerKey = QString(), const QString &contentId = QString()); + void getItemByOcsUrl(const QString &ocsUrl, const QString &providerKey = QString(), const QString &contentId = QString()); void uninstall(const QString &itemKey); private slots: diff --git a/app/src/handlers/ocsapihandler.h b/app/src/handlers/ocsapihandler.h index 9e59f9ec51bf0d6924d76e5e6df773656cc313ff..c761f4b69704bb2bdd87fc1f592e7e22e7443b75 100644 --- a/app/src/handlers/ocsapihandler.h +++ b/app/src/handlers/ocsapihandler.h @@ -17,9 +17,9 @@ public slots: bool removeProvider(const QString &providerKey) const; bool updateAllCategories(bool force = false) const; bool updateCategories(const QString &providerKey, bool force = false) const; - QJsonObject getContents(const QString &providerKeys = "", const QString &categoryKeys = "", - const QString &xdgTypes = "", const QString &packageTypes = "", - const QString &search = "", const QString &sortmode = "new", int pagesize = 25, int page = 0) const; + QJsonObject getContents(const QString &providerKeys = QString(), const QString &categoryKeys = QString(), + const QString &xdgTypes = QString(), const QString &packageTypes = QString(), + const QString &search = QString(), const QString &sortmode = QString("new"), int pagesize = 25, int page = 0) const; QJsonObject getContent(const QString &providerKey, const QString &contentId) const; private: diff --git a/app/src/handlers/systemhandler.cpp b/app/src/handlers/systemhandler.cpp index a719dac8e7d019ec79b3f0eeaf7c925acc23f07e..64540080ff06be4992a161e822694761956c2413 100644 --- a/app/src/handlers/systemhandler.cpp +++ b/app/src/handlers/systemhandler.cpp @@ -64,8 +64,8 @@ bool SystemHandler::openUrl(const QString &url) const QString SystemHandler::desktopEnvironment() const { - QString desktop = ""; - QString currentDesktop = ""; + QString desktop; + QString currentDesktop; if (!qgetenv("XDG_CURRENT_DESKTOP").isEmpty()) { currentDesktop = QString::fromLocal8Bit(qgetenv("XDG_CURRENT_DESKTOP").constData()).toLower(); @@ -110,7 +110,11 @@ bool SystemHandler::isApplicableType(const QString &installType) const << "gnome_shell_themes"; } else if (desktop == "xfce") { - applicableTypes << "wallpapers"; + applicableTypes << "wallpapers" + << "icons" + << "cursors" + << "gtk2_themes" + << "xfwm4_themes"; } return applicableTypes.contains(installType); @@ -121,22 +125,23 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c { if (QFileInfo::exists(path) && isApplicableType(installType)) { auto desktop = desktopEnvironment(); + auto themeName = QFileInfo(path).fileName(); if (desktop == "kde") { if (installType == "wallpapers") { return applyKdeWallpaper(path); } else if (installType == "icons") { - return applyKdeIcon(path); + return applyKdeIcon(themeName); } else if (installType == "cursors") { - return applyKdeCursor(path); + return applyKdeCursor(themeName); } else if (installType == "plasma5_desktopthemes") { - return applyKdePlasmaDesktoptheme(path); + return applyKdePlasmaDesktoptheme(themeName); } else if (installType == "aurorae_themes") { - return applyKdeAuroraeTheme(path); + return applyKdeAuroraeTheme(themeName); } } else if (desktop == "gnome") { @@ -144,22 +149,34 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c return applyGnomeWallpaper(path); } else if (installType == "icons") { - return applyGnomeIcon(path); + return applyGnomeIcon(themeName); } else if (installType == "cursors") { - return applyGnomeCursor(path); + return applyGnomeCursor(themeName); } else if (installType == "gtk3_themes") { - return applyGnomeGtk3Theme(path); + return applyGnomeGtk3Theme(themeName); } else if (installType == "gnome_shell_themes") { - return applyGnomeGnomeShellTheme(path); + return applyGnomeGnomeShellTheme(themeName); } } else if (desktop == "xfce") { if (installType == "wallpapers") { return applyXfceWallpaper(path); } + else if (installType == "icons") { + return applyXfceIcon(themeName); + } + else if (installType == "cursors") { + return applyXfceCursor(themeName); + } + else if (installType == "gtk2_themes") { + return applyXfceGtk2Theme(themeName); + } + else if (installType == "xfwm4_themes") { + return applyXfceXfwm4Theme(themeName); + } } } @@ -168,10 +185,21 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c #endif #ifdef QTLIB_UNIX -bool SystemHandler::applyKdeWallpaper(const QString &path) const +bool SystemHandler::setConfigWithPlasmaShell(const QString &script) const { 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; QTextStream out(&script); out << "for (var key in desktops()) {" @@ -181,106 +209,52 @@ bool SystemHandler::applyKdeWallpaper(const QString &path) const << "d.writeConfig('Image', 'file://" + path + "');" << "}"; - QVariantList arguments; - arguments << QVariant(script); - message.setArguments(arguments); - - auto reply = QDBusConnection::sessionBus().call(message); - - if (reply.type() == QDBusMessage::ErrorMessage) { - qWarning() << reply.errorMessage(); - return false; - } - - return true; + return setConfigWithPlasmaShell(script); } -bool SystemHandler::applyKdeIcon(const QString &path) const +bool SystemHandler::applyKdeIcon(const QString &themeName) const { - auto themeName = QFileInfo(path).fileName(); - auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript"); - QString script; QTextStream out(&script); out << "var c = ConfigFile('kdeglobals');" << "c.group = 'Icons';" << "c.writeEntry('Theme', '" + themeName + "');"; - QVariantList arguments; - arguments << QVariant(script); - message.setArguments(arguments); - - auto reply = QDBusConnection::sessionBus().call(message); - - if (reply.type() == QDBusMessage::ErrorMessage) { - qWarning() << reply.errorMessage(); - return false; + if (setConfigWithPlasmaShell(script)) { + QProcess::startDetached("kquitapp5 plasmashell && kstart5 plasmashell"); + return true; } - - QProcess::startDetached("kquitapp5 plasmashell"); - QProcess::startDetached("kstart5 plasmashell"); - - return true; + return false; } -bool SystemHandler::applyKdeCursor(const QString &path) const +bool SystemHandler::applyKdeCursor(const QString &themeName) const { - auto themeName = QFileInfo(path).fileName(); - auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript"); - QString script; QTextStream out(&script); out << "var c = ConfigFile('kcminputrc');" << "c.group = 'Mouse';" << "c.writeEntry('cursorTheme', '" + themeName + "');"; - QVariantList arguments; - arguments << QVariant(script); - message.setArguments(arguments); - - auto reply = QDBusConnection::sessionBus().call(message); - - if (reply.type() == QDBusMessage::ErrorMessage) { - qWarning() << reply.errorMessage(); - return false; - } - - return true; + return setConfigWithPlasmaShell(script); } -bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &path) const +bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &themeName) const { - auto themeName = QFileInfo(path).fileName(); - auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript"); - QString script; QTextStream out(&script); out << "var c = ConfigFile('plasmarc');" << "c.group = 'Theme';" << "c.writeEntry('name', '" + themeName + "');"; - QVariantList arguments; - arguments << QVariant(script); - message.setArguments(arguments); - - auto reply = QDBusConnection::sessionBus().call(message); - - if (reply.type() == QDBusMessage::ErrorMessage) { - qWarning() << reply.errorMessage(); - return false; + if (setConfigWithPlasmaShell(script)) { + QProcess::startDetached("kquitapp5 plasmashell && kstart5 plasmashell"); + return true; } - - QProcess::startDetached("kquitapp5 plasmashell"); - QProcess::startDetached("kstart5 plasmashell"); - - return true; + return false; } -bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const +bool SystemHandler::applyKdeAuroraeTheme(const QString &themeName) const { - auto themeName = QFileInfo(path).fileName(); - auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript"); - QString script; QTextStream out(&script); out << "var c = ConfigFile('kwinrc');" @@ -288,77 +262,79 @@ bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const << "c.writeEntry('library', 'org.kde.kwin.aurorae');" << "c.writeEntry('theme', '__aurorae__svg__" + themeName + "');"; - QVariantList arguments; - arguments << QVariant(script); - message.setArguments(arguments); - - auto reply = QDBusConnection::sessionBus().call(message); - - if (reply.type() == QDBusMessage::ErrorMessage) { - qWarning() << reply.errorMessage(); - return false; + if (setConfigWithPlasmaShell(script)) { + auto message = QDBusMessage::createMethodCall("org.kde.KWin", "/KWin", "org.kde.KWin", "reconfigure"); + QDBusConnection::sessionBus().call(message); + return true; } + return false; +} - auto refreshMessage = QDBusMessage::createMethodCall("org.kde.KWin", "/KWin", "org.kde.KWin", "reconfigure"); - QDBusConnection::sessionBus().call(refreshMessage); - - return true; +bool SystemHandler::setConfigWithGsettings(const QString &schema, const QString &key, const QString &value) const +{ + return QProcess::startDetached("gsettings", QStringList() << "set" << schema << key << value); } bool SystemHandler::applyGnomeWallpaper(const QString &path) const { - QStringList arguments{"set", "org.gnome.desktop.background", "picture-uri", "file://" + path}; - return QProcess::startDetached("gsettings", arguments); + return setConfigWithGsettings("org.gnome.desktop.background", "picture-uri", "file://" + path); } -bool SystemHandler::applyGnomeIcon(const QString &path) const +bool SystemHandler::applyGnomeIcon(const QString &themeName) const { - auto themeName = QFileInfo(path).fileName(); - QStringList arguments{"set", "org.gnome.desktop.interface", "icon-theme", themeName}; - return QProcess::startDetached("gsettings", arguments); + return setConfigWithGsettings("org.gnome.desktop.interface", "icon-theme", themeName); } -bool SystemHandler::applyGnomeCursor(const QString &path) const +bool SystemHandler::applyGnomeCursor(const QString &themeName) const { - auto themeName = QFileInfo(path).fileName(); - QStringList arguments{"set", "org.gnome.desktop.interface", "cursor-theme", themeName}; - return QProcess::startDetached("gsettings", arguments); + return setConfigWithGsettings("org.gnome.desktop.interface", "cursor-theme", themeName); } -bool SystemHandler::applyGnomeGtk3Theme(const QString &path) const +bool SystemHandler::applyGnomeGtk3Theme(const QString &themeName) const { - auto themeName = QFileInfo(path).fileName(); - QStringList arguments{"set", "org.gnome.desktop.interface", "gtk-theme", themeName}; - return QProcess::startDetached("gsettings", arguments); + return setConfigWithGsettings("org.gnome.desktop.interface", "gtk-theme", themeName); } -bool SystemHandler::applyGnomeGnomeShellTheme(const QString &path) const +bool SystemHandler::applyGnomeGnomeShellTheme(const QString &themeName) const { - auto themeName = QFileInfo(path).fileName(); - QStringList arguments{"set", "org.gnome.shell.extensions.user-theme", "name", themeName}; - return QProcess::startDetached("gsettings", arguments); + return setConfigWithGsettings("org.gnome.shell.extensions.user-theme", "name", themeName); } -bool SystemHandler::applyXfceWallpaper(const QString &path) const +bool SystemHandler::setConfigWithXfconf(const QString &channel, const QString &property, const QString &value) const { auto message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty"); - - QString channelValue = "xfce4-desktop"; - //QString propertyValue = "/backdrop/screen0/monitor0/image-path"; - QString propertyValue = "/backdrop/screen0/monitor0/workspace0/last-image"; - QDBusVariant valueValue(path); - - QVariantList arguments; - arguments << QVariant(channelValue) << QVariant(propertyValue) << QVariant::fromValue(valueValue); - message.setArguments(arguments); - + message.setArguments(QVariantList() << QVariant(channel) << QVariant(property) << QVariant::fromValue(QDBusVariant(value))); auto reply = QDBusConnection::sessionBus().call(message); if (reply.type() == QDBusMessage::ErrorMessage) { qWarning() << reply.errorMessage(); return false; } - return true; } + +bool SystemHandler::applyXfceWallpaper(const QString &path) const +{ + return setConfigWithXfconf("xfce4-desktop", "/backdrop/screen0/monitor0/workspace0/last-image", path); +} + +bool SystemHandler::applyXfceIcon(const QString &themeName) const +{ + return setConfigWithXfconf("xsettings", "/Net/IconThemeName", themeName); +} + +bool SystemHandler::applyXfceCursor(const QString &themeName) const +{ + return setConfigWithXfconf("xsettings", "/Gtk/CursorThemeName", themeName); +} + +bool SystemHandler::applyXfceGtk2Theme(const QString &themeName) const +{ + return setConfigWithXfconf("xsettings", "/Net/ThemeName", themeName); +} + +bool SystemHandler::applyXfceXfwm4Theme(const QString &themeName) const +{ + return setConfigWithXfconf("xfwm4", "/general/theme", themeName); +} #endif diff --git a/app/src/handlers/systemhandler.h b/app/src/handlers/systemhandler.h index f9bd1ee4082652a9bb0c6b5c6941f026ae2b006d..8a346191ae947cd31c3533d7ebf1e9af01e5c1e5 100644 --- a/app/src/handlers/systemhandler.h +++ b/app/src/handlers/systemhandler.h @@ -23,18 +23,25 @@ public slots: private: #ifdef QTLIB_UNIX + bool setConfigWithPlasmaShell(const QString &script) const; bool applyKdeWallpaper(const QString &path) const; - bool applyKdeIcon(const QString &path) const; - bool applyKdeCursor(const QString &path) const; - bool applyKdePlasmaDesktoptheme(const QString &path) const; - bool applyKdeAuroraeTheme(const QString &path) const; + bool applyKdeIcon(const QString &themeName) const; + bool applyKdeCursor(const QString &themeName) const; + bool applyKdePlasmaDesktoptheme(const QString &themeName) const; + bool applyKdeAuroraeTheme(const QString &themeName) const; + bool setConfigWithGsettings(const QString &schema, const QString &key, const QString &value) const; bool applyGnomeWallpaper(const QString &path) const; - bool applyGnomeIcon(const QString &path) const; - bool applyGnomeCursor(const QString &path) const; - bool applyGnomeGtk3Theme(const QString &path) const; - bool applyGnomeGnomeShellTheme(const QString &path) const; + bool applyGnomeIcon(const QString &themeName) const; + bool applyGnomeCursor(const QString &themeName) const; + bool applyGnomeGtk3Theme(const QString &themeName) const; + bool applyGnomeGnomeShellTheme(const QString &themeName) const; + bool setConfigWithXfconf(const QString &channel, const QString &property, const QString &value) const; bool applyXfceWallpaper(const QString &path) const; + bool applyXfceIcon(const QString &themeName) const; + bool applyXfceCursor(const QString &themeName) const; + bool applyXfceGtk2Theme(const QString &themeName) const; + bool applyXfceXfwm4Theme(const QString &themeName) const; #endif }; diff --git a/app/src/websockets/websocketserver.cpp b/app/src/websockets/websocketserver.cpp index 8eb69e9cc8b80a2ae88e2ce8b0fad6676afb012d..59f8f78005f3951dc477efeb2c1ab091ed7fd18f 100644 --- a/app/src/websockets/websocketserver.cpp +++ b/app/src/websockets/websocketserver.cpp @@ -15,6 +15,7 @@ WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &se : QObject(parent), configHandler_(configHandler), serverName_(serverName), serverPort_(serverPort) { wsServer_ = new QWebSocketServer(serverName_, QWebSocketServer::NonSecureMode, this); + connect(wsServer_, &QWebSocketServer::newConnection, this, &WebSocketServer::wsNewConnection); connect(wsServer_, &QWebSocketServer::closed, this, &WebSocketServer::stopped); @@ -22,6 +23,7 @@ WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &se systemHandler_ = new SystemHandler(this); ocsApiHandler_ = new OcsApiHandler(configHandler_, this); itemHandler_ = new ItemHandler(configHandler_, this); + connect(itemHandler_, &ItemHandler::metadataSetChanged, this, &WebSocketServer::itemMetadataSetChanged); connect(itemHandler_, &ItemHandler::downloadStarted, this, &WebSocketServer::itemDownloadStarted); connect(itemHandler_, &ItemHandler::downloadFinished, this, &WebSocketServer::itemDownloadFinished); @@ -75,9 +77,11 @@ QUrl WebSocketServer::serverUrl() const void WebSocketServer::wsNewConnection() { auto *wsClient = wsServer_->nextPendingConnection(); + connect(wsClient, &QWebSocket::disconnected, this, &WebSocketServer::wsDisconnected); connect(wsClient, &QWebSocket::textMessageReceived, this, &WebSocketServer::wsTextMessageReceived); connect(wsClient, &QWebSocket::binaryMessageReceived, this, &WebSocketServer::wsBinaryMessageReceived); + wsClients_ << wsClient; } diff --git a/app/src/websockets/websocketserver.h b/app/src/websockets/websocketserver.h index 350903a064f95bd72cbf2d98118eb8cb9d611fa2..cfd2bcacb99a42610e5c12f363e680dbedf0f723 100644 --- a/app/src/websockets/websocketserver.h +++ b/app/src/websockets/websocketserver.h @@ -18,7 +18,7 @@ class WebSocketServer : public QObject Q_OBJECT public: - explicit WebSocketServer(ConfigHandler *configHandler, const QString &serverName = "WebSocketServer", quint16 serverPort = 0, QObject *parent = nullptr); + explicit WebSocketServer(ConfigHandler *configHandler, const QString &serverName = QString("WebSocketServer"), quint16 serverPort = 0, QObject *parent = nullptr); ~WebSocketServer(); signals: diff --git a/scripts/import.sh b/scripts/import.sh index 8fd990fb00c40f44aa290fc4138b94f14e0a6236..daddb4d66d7ecf78f88ce04e881555babed97dcf 100644 --- a/scripts/import.sh +++ b/scripts/import.sh @@ -7,5 +7,5 @@ PROJDIR="$(cd "$(dirname "${0}")/../" && pwd)" if [ ! -d "${PROJDIR}/lib/qtlib" ]; then - git clone https://github.com/akiraohgaki/qtlib.git -b release-0.2.0 --single-branch --depth=1 "${PROJDIR}/lib/qtlib" + git clone https://github.com/akiraohgaki/qtlib.git -b release-0.2.1 --single-branch --depth=1 "${PROJDIR}/lib/qtlib" fi