Skip to content
Snippets Groups Projects
Commit 3a985fb0 authored by akiraohgaki's avatar akiraohgaki Committed by GitHub
Browse files

Merge pull request #39 from ocs-url/feature/config

Feature/config
parents add28573 a9f84d24
No related branches found
No related tags found
No related merge requests found
......@@ -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}
<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>
{
"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"
}
{
"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"
}
{
"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"
}
}
{
"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"
}
}
#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;
}
#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_;
};
......@@ -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());
......
......@@ -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_;
};
......@@ -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();
......
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