Skip to content
Snippets Groups Projects
Commit 9905e8f9 authored by akiraohgaki's avatar akiraohgaki
Browse files

Add confighandler class

parent cf1501ab
No related branches found
No related tags found
No related merge requests found
......@@ -6,10 +6,12 @@ QT += \
svg
HEADERS += \
$${PWD}/handlers/confighandler.h \
$${PWD}/handlers/ocsurlhandler.h
SOURCES += \
$${PWD}/main.cpp \
$${PWD}/handlers/confighandler.cpp \
$${PWD}/handlers/ocsurlhandler.cpp
RESOURCES += \
......
#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_;
};
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