Skip to content
Snippets Groups Projects
Commit 2b67ae3b authored by akiraohgaki's avatar akiraohgaki
Browse files

Config and network

parent d02cd42d
No related branches found
No related tags found
No related merge requests found
......@@ -15,13 +15,13 @@
namespace Handlers {
XdgUrl::XdgUrl(const QString &xdgUrl, Core::Config *appConfig, Core::Config *userConfig, Core::Network *asyncNetwork, QObject *parent) :
QObject(parent), _xdgUrl(xdgUrl), _appConfig(appConfig), _userConfig(userConfig), _asyncNetwork(asyncNetwork)
XdgUrl::XdgUrl(const QString &xdgUrl, Core::Config *config, Core::Network *network, QObject *parent) :
QObject(parent), _xdgUrl(xdgUrl), _config(config), _network(network)
{
_metadata = _parse();
_destinations = _loadDestinations();
connect(_asyncNetwork, &Core::Network::finished, this, &XdgUrl::_downloaded);
connect(_network, &Core::Network::finished, this, &XdgUrl::_downloaded);
}
QJsonObject XdgUrl::_parse()
......@@ -83,37 +83,20 @@ QString XdgUrl::_convertPathString(const QString &path)
QJsonObject XdgUrl::_loadDestinations()
{
QJsonObject destinations;
QJsonObject appConfigDestinations = _appConfig->get("destinations");
QJsonObject appConfigDestinationsAlias = _appConfig->get("destinations_alias");
QJsonObject userConfigDestinations = _userConfig->get("destinations");
QJsonObject userConfigDestinationsAlias = _userConfig->get("destinations_alias");
QJsonObject configDestinations = _config->get("destinations");
QJsonObject configDestinationsAlias = _config->get("destinations_alias");
foreach (const QString key, appConfigDestinations.keys()) {
destinations[key] = _convertPathString(appConfigDestinations[key].toString());
foreach (const QString key, configDestinations.keys()) {
destinations[key] = _convertPathString(configDestinations[key].toString());
}
foreach (const QString key, appConfigDestinationsAlias.keys()) {
QString value = appConfigDestinationsAlias[key].toString();
foreach (const QString key, configDestinationsAlias.keys()) {
QString value = configDestinationsAlias[key].toString();
if (destinations.contains(value)) {
destinations[key] = destinations.value(value);
}
}
if (!userConfigDestinations.isEmpty()) {
foreach (const QString key, userConfigDestinations.keys()) {
destinations[key] = _convertPathString(userConfigDestinations[key].toString());
}
}
if (!userConfigDestinationsAlias.isEmpty()) {
foreach (const QString key, userConfigDestinationsAlias.keys()) {
QString value = userConfigDestinationsAlias[key].toString();
if (destinations.contains(value)) {
destinations[key] = destinations.value(value);
}
}
}
return destinations;
}
......@@ -247,7 +230,7 @@ void XdgUrl::_downloaded(QNetworkReply *reply)
if (refreshUrl.startsWith("/")) {
refreshUrl = reply->url().authority() + refreshUrl;
}
_asyncNetwork->get(QUrl(refreshUrl));
_network->get(QUrl(refreshUrl));
return;
}
......@@ -300,7 +283,7 @@ void XdgUrl::process()
*/
if (isValid()) {
_asyncNetwork->get(QUrl(_metadata["url"].toString()));
_network->get(QUrl(_metadata["url"].toString()));
}
}
......
......@@ -19,15 +19,14 @@ class XdgUrl : public QObject
private:
QString _xdgUrl;
Core::Config *_appConfig;
Core::Config *_userConfig;
Core::Network *_asyncNetwork;
Core::Config *_config;
Core::Network *_network;
QJsonObject _metadata;
QJsonObject _destinations;
public:
explicit XdgUrl(const QString &xdgUrl, Core::Config *appConfig, Core::Config *userConfig, Core::Network *asyncNetwork, QObject *parent = 0);
explicit XdgUrl(const QString &xdgUrl, Core::Config *config, Core::Network *network, QObject *parent = 0);
private:
QJsonObject _parse();
......
......@@ -12,28 +12,26 @@
#include "core/config.h"
#include "core/network.h"
#include "handlers/xdgurl.h"
#include "utility/file.h"
int main(int argc, char *argv[])
{
// Init
//QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // Qt 5.6 or higher
QGuiApplication app(argc, argv);
Core::Config *config = new Core::Config(":/configs");
Core::Network *network = new Core::Network(true);
Core::Config *appConfig = new Core::Config(":/configs");
QJsonObject appConfigApplication = appConfig->get("application");
Core::Config *userConfig = new Core::Config(Utility::File::xdgConfigHomePath() + "/" + appConfigApplication["id"].toString());
Core::Network *asyncNetwork = new Core::Network(true);
QJsonObject configApplication = config->get("application");
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())));
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())));
// Setup CLI
QCommandLineParser clParser;
clParser.setApplicationDescription(appConfigApplication["description"].toString());
clParser.setApplicationDescription(configApplication["description"].toString());
clParser.addHelpOption();
clParser.addVersionOption();
clParser.addPositionalArgument("xdgurl", "XDG-URL");
......@@ -50,7 +48,7 @@ int main(int argc, char *argv[])
// Setup QML
QQmlApplicationEngine qmlAppEngine;
QQmlContext *qmlContext = qmlAppEngine.rootContext();
qmlContext->setContextProperty("xdgUrlHandler", new Handlers::XdgUrl(xdgUrl, appConfig, userConfig, asyncNetwork));
qmlContext->setContextProperty("xdgUrlHandler", new Handlers::XdgUrl(xdgUrl, config, network));
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