diff --git a/src/app/app.pri b/src/app/app.pri index 6a82d4b10e072fa7c53b37fd006e0b0b95aa542b..15ac50a30c18383817997767773a4cdb59f52e32 100644 --- a/src/app/app.pri +++ b/src/app/app.pri @@ -6,12 +6,16 @@ QT += \ svg HEADERS += \ + $${PWD}/handlers/confighandler.h \ $${PWD}/handlers/ocsurlhandler.h SOURCES += \ $${PWD}/main.cpp \ + $${PWD}/handlers/confighandler.cpp \ $${PWD}/handlers/ocsurlhandler.cpp RESOURCES += \ $${PWD}/configs/configs.qrc \ $${PWD}/qml/qml.qrc + +INCLUDEPATH += $${PWD} diff --git a/src/app/configs/configs.qrc b/src/app/configs/configs.qrc index a27f28af5718bcfb48d18dd500717897c9b6e84d..496e259d7a5937ae4a51fa761a76b84b33a05daf 100644 --- a/src/app/configs/configs.qrc +++ b/src/app/configs/configs.qrc @@ -1,7 +1,7 @@ <RCC> <qresource prefix="/configs"> <file>application.json</file> - <file>destinations.json</file> - <file>destinations_alias.json</file> + <file>install_types.json</file> + <file>install_types_alias.json</file> </qresource> </RCC> diff --git a/src/app/configs/destinations.json b/src/app/configs/destinations.json deleted file mode 100644 index ed85557bb2cb708a88b695f623c97843c3315764..0000000000000000000000000000000000000000 --- a/src/app/configs/destinations.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "bin": "$HOME/.local/bin", - "downloads": "$HOME/Downloads", - "documents": "$HOME/Documents", - "pictures": "$HOME/Pictures", - "music": "$HOME/Music", - "videos": "$HOME/Videos", - "wallpapers": "$XDG_DATA_HOME/wallpapers", - "fonts": "$HOME/.fonts", - "cursors": "$HOME/.icons", - "icons": "$XDG_DATA_HOME/icons", - "emoticons": "$XDG_DATA_HOME/emoticons", - "themes": "$HOME/.themes", - "emerald_themes": "$HOME/.emerald/themes", - "enlightenment_themes": "$HOME/.e/e/themes", - "enlightenment_backgrounds": "$HOME/.e/e/backgrounds", - "fluxbox_styles": "$HOME/.fluxbox/styles", - "pekwm_themes": "$HOME/.pekwm/themes", - "icewm_themes": "$HOME/.icewm/themes", - "plasma_plasmoids": "$XDG_DATA_HOME/plasma/plasmoids", - "plasma_look_and_feel": "$XDG_DATA_HOME/plasma/look-and-feel", - "plasma_desktopthemes": "$XDG_DATA_HOME/plasma/desktoptheme", - "kwin_effects": "$XDG_DATA_HOME/kwin/effects", - "kwin_scripts": "$XDG_DATA_HOME/kwin/scripts", - "kwin_tabbox": "$XDG_DATA_HOME/kwin/tabbox", - "aurorae_themes": "$XDG_DATA_HOME/aurorae/themes", - "dekorator_themes": "$XDG_DATA_HOME/deKorator/themes", - "qtcurve": "$XDG_DATA_HOME/QtCurve", - "color_schemes": "$XDG_DATA_HOME/color-schemes", - "gnome_shell_extensions": "$XDG_DATA_HOME/gnome-shell/extensions", - "cinnamon_applets": "$XDG_DATA_HOME/cinnamon/applets", - "cinnamon_desklets": "$XDG_DATA_HOME/cinnamon/desklets", - "cinnamon_extensions": "$XDG_DATA_HOME/cinnamon/extensions", - "nautilus_scripts": "$XDG_DATA_HOME/nautilus/scripts", - "amarok_scripts": "$KDEHOME/share/apps/amarok/scripts", - "yakuake_skins": "$KDEHOME/share/apps/yakuake/skins", - "cairo_clock_themes": "$HOME/.cairo-clock/themes" -} diff --git a/src/app/configs/destinations_alias.json b/src/app/configs/destinations_alias.json deleted file mode 100644 index 438fb4dc92cf31716b7741064141b8a10a83f20d..0000000000000000000000000000000000000000 --- a/src/app/configs/destinations_alias.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "gnome_shell_themes": "themes", - "cinnamon_themes": "themes", - "gtk2_themes": "themes", - "gtk3_themes": "themes", - "metacity_themes": "themes", - "xfwm4_themes": "themes", - "openbox_themes": "themes", - "kvantum_themes": "themes", - "compiz_themes": "emerald_themes", - "beryl_themes": "emerald_themes", - "plasma4_plasmoids": "plasma_plasmoids", - "plasma5_plasmoids": "plasma_plasmoids", - "plasma5_look_and_feel": "plasma_look_and_feel", - "plasma5_desktopthemes": "plasma_desktopthemes", - "plasma_color_schemes": "color_schemes" -} diff --git a/src/app/configs/install_types.json b/src/app/configs/install_types.json new file mode 100644 index 0000000000000000000000000000000000000000..335de22350e81310a3820d1f0d79e6a5aea33037 --- /dev/null +++ b/src/app/configs/install_types.json @@ -0,0 +1,192 @@ +{ + "bin": { + "name": "Softwares", + "destination": "$HOME/.local/bin", + "generic_destination": "$APP_DATA/bin" + }, + "downloads": { + "name": "Downloads", + "destination": "$HOME/Downloads", + "generic_destination": "$APP_DATA/downloads" + }, + "documents": { + "name": "Documents", + "destination": "$HOME/Documents", + "generic_destination": "$APP_DATA/documents" + }, + "pictures": { + "name": "Pictures", + "destination": "$HOME/Pictures", + "generic_destination": "$APP_DATA/pictures" + }, + "music": { + "name": "Music", + "destination": "$HOME/Music", + "generic_destination": "$APP_DATA/music" + }, + "videos": { + "name": "Videos", + "destination": "$HOME/Videos", + "generic_destination": "$APP_DATA/videos" + }, + "wallpapers": { + "name": "Wallpapers", + "destination": "$XDG_DATA_HOME/wallpapers", + "generic_destination": "$APP_DATA/wallpapers" + }, + "fonts": { + "name": "Fonts", + "destination": "$HOME/.fonts", + "generic_destination": "$APP_DATA/fonts" + }, + "cursors": { + "name": "Cursors", + "destination": "$HOME/.icons", + "generic_destination": "$APP_DATA/cursors" + }, + "icons": { + "name": "Icons", + "destination": "$XDG_DATA_HOME/icons", + "generic_destination": "$APP_DATA/icons" + }, + "emoticons": { + "name": "Emoticons", + "destination": "$XDG_DATA_HOME/emoticons", + "generic_destination": "$APP_DATA/emoticons" + }, + "themes": { + "name": "Desktop Themes", + "destination": "$HOME/.themes", + "generic_destination": "$APP_DATA/themes" + }, + "emerald_themes": { + "name": "Emerald Themes", + "destination": "$HOME/.emerald/themes", + "generic_destination": "$APP_DATA/emerald_themes" + }, + "enlightenment_themes": { + "name": "Enlightenment Themes", + "destination": "$HOME/.e/e/themes", + "generic_destination": "$APP_DATA/enlightenment_themes" + }, + "enlightenment_backgrounds": { + "name": "Enlightenment Backgrounds", + "destination": "$HOME/.e/e/backgrounds", + "generic_destination": "$APP_DATA/enlightenment_backgrounds" + }, + "fluxbox_styles": { + "name": "Fluxbox Styles", + "destination": "$HOME/.fluxbox/styles", + "generic_destination": "$APP_DATA/fluxbox_styles" + }, + "pekwm_themes": { + "name": "PekWM Themes", + "destination": "$HOME/.pekwm/themes", + "generic_destination": "$APP_DATA/pekwm_themes" + }, + "icewm_themes": { + "name": "IceWM Themes", + "destination": "$HOME/.icewm/themes", + "generic_destination": "$APP_DATA/icewm_themes" + }, + "plasma_plasmoids": { + "name": "Plasma Plasmoids", + "destination": "$XDG_DATA_HOME/plasma/plasmoids", + "generic_destination": "$APP_DATA/plasma_plasmoids" + }, + "plasma_look_and_feel": { + "name": "Plasma Look and Feel", + "destination": "$XDG_DATA_HOME/plasma/look-and-feel", + "generic_destination": "$APP_DATA/plasma_look_and_feel" + }, + "plasma_desktopthemes": { + "name": "Plasma Desktop Themes", + "destination": "$XDG_DATA_HOME/plasma/desktoptheme", + "generic_destination": "$APP_DATA/plasma_desktopthemes" + }, + "kwin_effects": { + "name": "KWin Effects", + "destination": "$XDG_DATA_HOME/kwin/effects", + "generic_destination": "$APP_DATA/kwin_effects" + }, + "kwin_scripts": { + "name": "KWin Scripts", + "destination": "$XDG_DATA_HOME/kwin/scripts", + "generic_destination": "$APP_DATA/kwin_scripts" + }, + "kwin_tabbox": { + "name": "KWin Window Switcher", + "destination": "$XDG_DATA_HOME/kwin/tabbox", + "generic_destination": "$APP_DATA/kwin_tabbox" + }, + "aurorae_themes": { + "name": "Aurorae Themes", + "destination": "$XDG_DATA_HOME/aurorae/themes", + "generic_destination": "$APP_DATA/aurorae_themes" + }, + "dekorator_themes": { + "name": "deKorator Themes", + "destination": "$XDG_DATA_HOME/deKorator/themes", + "generic_destination": "$APP_DATA/dekorator_themes" + }, + "qtcurve": { + "name": "QtCurve Themes", + "destination": "$XDG_DATA_HOME/QtCurve", + "generic_destination": "$APP_DATA/qtcurve" + }, + "color_schemes": { + "name": "KDE Color Schemes", + "destination": "$XDG_DATA_HOME/color-schemes", + "generic_destination": "$APP_DATA/color_schemes" + }, + "gnome_shell_extensions": { + "name": "Gnome Shell Extensions", + "destination": "$XDG_DATA_HOME/gnome-shell/extensions", + "generic_destination": "$APP_DATA/gnome_shell_extensions" + }, + "cinnamon_applets": { + "name": "Cinnamon Applets", + "destination": "$XDG_DATA_HOME/cinnamon/applets", + "generic_destination": "$APP_DATA/cinnamon_applets" + }, + "cinnamon_desklets": { + "name": "Cinnamon Desklets", + "destination": "$XDG_DATA_HOME/cinnamon/desklets", + "generic_destination": "$APP_DATA/cinnamon_desklets" + }, + "cinnamon_extensions": { + "name": "Cinnamon Extensions", + "destination": "$XDG_DATA_HOME/cinnamon/extensions", + "generic_destination": "$APP_DATA/cinnamon_extensions" + }, + "nautilus_scripts": { + "name": "Nautilus Scripts", + "destination": "$XDG_DATA_HOME/nautilus/scripts", + "generic_destination": "$APP_DATA/nautilus_scripts" + }, + "amarok_scripts": { + "name": "Amarok Scripts", + "destination": "$KDEHOME/share/apps/amarok/scripts", + "generic_destination": "$APP_DATA/amarok_scripts" + }, + "yakuake_skins": { + "name": "Yakuake Skins", + "destination": "$KDEHOME/share/apps/yakuake/skins", + "generic_destination": "$APP_DATA/yakuake_skins" + }, + "cairo_clock_themes": { + "name": "Cairo-Clock Themes", + "destination": "$HOME/.cairo-clock/themes", + "generic_destination": "$APP_DATA/cairo_clock_themes" + }, + "books": { + "name": "Books", + "destination": "$APP_DATA/books", + "generic_destination": "$APP_DATA/books" + }, + "comics": { + "name": "Comics", + "destination": "$APP_DATA/comics", + "generic_destination": "$APP_DATA/comics" + } +} diff --git a/src/app/configs/install_types_alias.json b/src/app/configs/install_types_alias.json new file mode 100644 index 0000000000000000000000000000000000000000..d67bb8bdd3d57e9ca16d759627fb6e2babed23ea --- /dev/null +++ b/src/app/configs/install_types_alias.json @@ -0,0 +1,62 @@ +{ + "gnome_shell_themes": { + "base": "themes", + "name": "Gnome Shell Themes" + }, + "cinnamon_themes": { + "base": "themes", + "name": "Cinnamon Themes" + }, + "gtk2_themes": { + "base": "themes", + "name": "GTK2 Themes" + }, + "gtk3_themes": { + "base": "themes", + "name": "GTK3 Themes" + }, + "metacity_themes": { + "base": "themes", + "name": "Metacity Themes" + }, + "xfwm4_themes": { + "base": "themes", + "name": "XFWM4 Themes" + }, + "openbox_themes": { + "base": "themes", + "name": "Openbox Themes" + }, + "kvantum_themes": { + "base": "themes", + "name": "Kvantum Themes" + }, + "compiz_themes": { + "base": "emerald_themes", + "name": "Compiz Themes" + }, + "beryl_themes": { + "base": "emerald_themes", + "name": "Beryl Themes" + }, + "plasma4_plasmoids": { + "base": "plasma_plasmoids", + "name": "Plasma4 Plasmoids" + }, + "plasma5_plasmoids": { + "base": "plasma_plasmoids", + "name": "Plasma5 Plasmoids" + }, + "plasma5_look_and_feel": { + "base": "plasma_look_and_feel", + "name": "Plasma5 Look and Feel" + }, + "plasma5_desktopthemes": { + "base": "plasma_desktopthemes", + "name": "Plasma5 Desktop Themes" + }, + "plasma_color_schemes": { + "base": "color_schemes", + "name": "Plasma Color Schemes" + } +} diff --git a/src/app/handlers/confighandler.cpp b/src/app/handlers/confighandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d1111575b848823487e14cd41eeb8cdd04092ef --- /dev/null +++ b/src/app/handlers/confighandler.cpp @@ -0,0 +1,61 @@ +#include "confighandler.h" + +#include "qtlib_dir.h" + +ConfigHandler::ConfigHandler(QObject *parent) + : QObject(parent) +{ + appConfig_ = qtlib::Config(":/configs"); +} + +QJsonObject ConfigHandler::getAppConfigApplication() +{ + if (appConfigApplication_.isEmpty()) { + appConfigApplication_ = appConfig_.get("application"); + } + return appConfigApplication_; +} + +QJsonObject ConfigHandler::getAppConfigInstallTypes() +{ + if (appConfigInstallTypes_.isEmpty()) { + QJsonObject installTypes = appConfig_.get("install_types"); + foreach (const QString &key, installTypes.keys()) { + QJsonObject installtype = installTypes[key].toObject(); + installtype["destination"] = convertPathString(installtype["destination"].toString()); + installtype["generic_destination"] = convertPathString(installtype["generic_destination"].toString()); + installTypes[key] = installtype; + } + QJsonObject installTypesAlias = appConfig_.get("install_types_alias"); + foreach (const QString &key, installTypesAlias.keys()) { + QJsonObject installTypeAlias = installTypesAlias[key].toObject(); + QString baseKey = installTypeAlias["base"].toString(); + if (installTypes.contains(baseKey)) { + QJsonObject installType = installTypes[baseKey].toObject(); + installType["base"] = baseKey; + installType["name"] = installTypeAlias["name"].toString(); + installTypes[key] = installType; + } + } + appConfigInstallTypes_ = installTypes; + } + return appConfigInstallTypes_; +} + +QString ConfigHandler::convertPathString(const QString &path) +{ + QString newPath = path; + if (newPath.contains("$HOME")) { + newPath.replace("$HOME", qtlib::Dir::homePath()); + } + else if (newPath.contains("$XDG_DATA_HOME")) { + newPath.replace("$XDG_DATA_HOME", qtlib::Dir::genericDataPath()); + } + else if (newPath.contains("$KDEHOME")) { + newPath.replace("$KDEHOME", qtlib::Dir::kdehomePath()); + } + else if (newPath.contains("$APP_DATA")) { + newPath.replace("$APP_DATA", qtlib::Dir::genericDataPath() + "/" + getAppConfigApplication()["id"].toString()); + } + return newPath; +} diff --git a/src/app/handlers/confighandler.h b/src/app/handlers/confighandler.h new file mode 100644 index 0000000000000000000000000000000000000000..247afc85f936d325f4477afe8bf907a22403eb44 --- /dev/null +++ b/src/app/handlers/confighandler.h @@ -0,0 +1,25 @@ +#pragma once + +#include <QObject> +#include <QJsonObject> + +#include "qtlib_config.h" + +class ConfigHandler : public QObject +{ + Q_OBJECT + +public: + explicit ConfigHandler(QObject *parent = 0); + +public slots: + QJsonObject getAppConfigApplication(); + QJsonObject getAppConfigInstallTypes(); + +private: + QString convertPathString(const QString &path); + + qtlib::Config appConfig_; + QJsonObject appConfigApplication_; + QJsonObject appConfigInstallTypes_; +}; diff --git a/src/app/handlers/ocsurlhandler.cpp b/src/app/handlers/ocsurlhandler.cpp index 547c6c528c6a7275b0924d0f88dafcf1c12bd803..52edf33322b60e796774c52281a2836ea854d9b8 100644 --- a/src/app/handlers/ocsurlhandler.cpp +++ b/src/app/handlers/ocsurlhandler.cpp @@ -8,11 +8,12 @@ #include "qtlib_networkresource.h" #include "qtlib_package.h" -OcsUrlHandler::OcsUrlHandler(const QString &ocsUrl, const qtlib::Config &config, QObject *parent) - : QObject(parent), ocsUrl_(ocsUrl), config_(config) +#include "handlers/confighandler.h" + +OcsUrlHandler::OcsUrlHandler(const QString &ocsUrl, ConfigHandler *configHandler, QObject *parent) + : QObject(parent), ocsUrl_(ocsUrl), configHandler_(configHandler) { parse(); - loadDestinations(); } QString OcsUrlHandler::ocsUrl() const @@ -58,7 +59,7 @@ bool OcsUrlHandler::isValid() if ((scheme == "ocs" || scheme == "ocss" || scheme == "xdg" || scheme == "xdgs") && (command == "download" || command == "install") && QUrl(url).isValid() - && destinations_.contains(type) + && configHandler_->getAppConfigInstallTypes().contains(type) && !filename.isEmpty()) { return true; } @@ -68,7 +69,7 @@ bool OcsUrlHandler::isValid() void OcsUrlHandler::openDestination() { QString type = metadata_["type"].toString(); - QDesktopServices::openUrl(QUrl("file://" + destinations_[type].toString())); + QDesktopServices::openUrl(QUrl("file://" + configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString())); } void OcsUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource) @@ -126,46 +127,12 @@ void OcsUrlHandler::parse() } } -void OcsUrlHandler::loadDestinations() -{ - QJsonObject configDestinations = config_.get("destinations"); - QJsonObject configDestinationsAlias = config_.get("destinations_alias"); - - foreach (const QString &key, configDestinations.keys()) { - destinations_[key] = convertPathString(configDestinations[key].toString()); - } - - foreach (const QString &key, configDestinationsAlias.keys()) { - QString value = configDestinationsAlias[key].toString(); - if (destinations_.contains(value)) { - destinations_[key] = destinations_.value(value); - } - } -} - -QString OcsUrlHandler::convertPathString(const QString &path) -{ - QString newPath = path; - - if (newPath.contains("$HOME")) { - newPath.replace("$HOME", qtlib::Dir::homePath()); - } - else if (newPath.contains("$XDG_DATA_HOME")) { - newPath.replace("$XDG_DATA_HOME", qtlib::Dir::genericDataPath()); - } - else if (newPath.contains("$KDEHOME")) { - newPath.replace("$KDEHOME", qtlib::Dir::kdehomePath()); - } - - return newPath; -} - void OcsUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource) { QJsonObject result; QString type = metadata_["type"].toString(); - qtlib::Dir destDir(destinations_[type].toString()); + qtlib::Dir destDir(configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString()); destDir.make(); qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString()); @@ -200,7 +167,7 @@ void OcsUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource) qtlib::Package package(tempFile.path()); QString type = metadata_["type"].toString(); - qtlib::Dir destDir(destinations_[type].toString()); + qtlib::Dir destDir(configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString()); destDir.make(); qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString()); diff --git a/src/app/handlers/ocsurlhandler.h b/src/app/handlers/ocsurlhandler.h index ba56c29f535b84c8865ef44a4f2e8a50d9d9d89b..8c3f99da2d60069181862017af66386a97dfd797 100644 --- a/src/app/handlers/ocsurlhandler.h +++ b/src/app/handlers/ocsurlhandler.h @@ -3,18 +3,18 @@ #include <QObject> #include <QJsonObject> -#include "qtlib_config.h" - namespace qtlib { class NetworkResource; } +class ConfigHandler; + class OcsUrlHandler : public QObject { Q_OBJECT public: - explicit OcsUrlHandler(const QString &ocsUrl, const qtlib::Config &config, QObject *parent = 0); + explicit OcsUrlHandler(const QString &ocsUrl, ConfigHandler *configHandler, QObject *parent = 0); signals: void started(); @@ -35,13 +35,10 @@ private slots: private: void parse(); - void loadDestinations(); - QString convertPathString(const QString &path); void saveDownloadedFile(qtlib::NetworkResource *resource); void installDownloadedFile(qtlib::NetworkResource *resource); QString ocsUrl_; - qtlib::Config config_; + ConfigHandler *configHandler_; QJsonObject metadata_; - QJsonObject destinations_; }; diff --git a/src/app/main.cpp b/src/app/main.cpp index 91d81a3202d9d734fd17ccf78b440f4bd45032a0..1d84cb4cf09b3d173345339561a5039fc9a01290 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -8,8 +8,7 @@ #include <QQmlApplicationEngine> #include <QQmlContext> -#include "qtlib_config.h" - +#include "handlers/confighandler.h" #include "handlers/ocsurlhandler.h" int main(int argc, char *argv[]) @@ -17,18 +16,18 @@ int main(int argc, char *argv[]) // Init QGuiApplication app(argc, argv); - qtlib::Config config(":/configs"); - QJsonObject configApplication = config.get("application"); + ConfigHandler *configHandler = new ConfigHandler(); + QJsonObject appConfigApplication = configHandler->getAppConfigApplication(); - app.setApplicationName(configApplication["name"].toString()); - app.setApplicationVersion(configApplication["version"].toString()); - app.setOrganizationName(configApplication["organization"].toString()); - app.setOrganizationDomain(configApplication["domain"].toString()); - app.setWindowIcon(QIcon::fromTheme(configApplication["id"].toString(), QIcon(configApplication["icon"].toString()))); + app.setApplicationName(appConfigApplication["name"].toString()); + app.setApplicationVersion(appConfigApplication["version"].toString()); + app.setOrganizationName(appConfigApplication["organization"].toString()); + app.setOrganizationDomain(appConfigApplication["domain"].toString()); + app.setWindowIcon(QIcon::fromTheme(appConfigApplication["id"].toString(), QIcon(appConfigApplication["icon"].toString()))); // Setup CLI QCommandLineParser clParser; - clParser.setApplicationDescription(configApplication["description"].toString()); + clParser.setApplicationDescription(appConfigApplication["description"].toString()); clParser.addHelpOption(); clParser.addVersionOption(); clParser.addPositionalArgument("ocsurl", "OCS-URL"); @@ -45,7 +44,9 @@ int main(int argc, char *argv[]) // Setup QML QQmlApplicationEngine qmlAppEngine; QQmlContext *qmlContext = qmlAppEngine.rootContext(); - qmlContext->setContextProperty("ocsUrlHandler", new OcsUrlHandler(ocsUrl, config, &qmlAppEngine)); + configHandler->setParent(&qmlAppEngine); + qmlContext->setContextProperty("configHandler", configHandler); + qmlContext->setContextProperty("ocsUrlHandler", new OcsUrlHandler(ocsUrl, configHandler, &qmlAppEngine)); qmlAppEngine.load(QUrl("qrc:/qml/main.qml")); return app.exec();