From 6c40e9ab53f7d938d9875777c173823a0d30cf06 Mon Sep 17 00:00:00 2001 From: Akira Ohgaki <akiraohgaki@gmail.com> Date: Fri, 21 Oct 2016 16:12:51 +0900 Subject: [PATCH] Return json object --- src/handlers/xdgurl.cpp | 21 ++++++++++----------- src/handlers/xdgurl.h | 6 +++--- src/qml/main.qml | 4 +--- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/handlers/xdgurl.cpp b/src/handlers/xdgurl.cpp index 444b9a3..35ebbb2 100644 --- a/src/handlers/xdgurl.cpp +++ b/src/handlers/xdgurl.cpp @@ -7,7 +7,6 @@ #include "../core/config.h" #include "../core/network.h" #include "../utility/file.h" -#include "../utility/json.h" #include "../utility/package.h" #include "xdgurl.h" @@ -103,7 +102,7 @@ void XdgUrl::_saveDownloadedFile(QNetworkReply *reply) if (!temporaryFile.open() || temporaryFile.write(reply->readAll()) == -1) { result["status"] = QString("error_save"); result["message"] = temporaryFile.errorString(); - emit error(Utility::Json::convertObjToStr(result)); + emit error(result); return; } @@ -117,7 +116,7 @@ void XdgUrl::_saveDownloadedFile(QNetworkReply *reply) if (!temporaryFile.copy(path)) { result["status"] = QString("error_save"); result["message"] = temporaryFile.errorString(); - emit error(Utility::Json::convertObjToStr(result)); + emit error(result); return; } @@ -125,7 +124,7 @@ void XdgUrl::_saveDownloadedFile(QNetworkReply *reply) result["status"] = QString("success_download"); result["message"] = QString("The file has been stored into " + destination); - emit finished(Utility::Json::convertObjToStr(result)); + emit finished(result); } void XdgUrl::_installDownloadedFile(QNetworkReply *reply) @@ -137,7 +136,7 @@ void XdgUrl::_installDownloadedFile(QNetworkReply *reply) if (!temporaryFile.open() || temporaryFile.write(reply->readAll()) == -1) { result["status"] = QString("error_save"); result["message"] = temporaryFile.errorString(); - emit error(Utility::Json::convertObjToStr(result)); + emit error(result); return; } @@ -185,14 +184,14 @@ void XdgUrl::_installDownloadedFile(QNetworkReply *reply) else { result["status"] = QString("error_install"); result["message"] = temporaryFile.errorString(); - emit error(Utility::Json::convertObjToStr(result)); + emit error(result); return; } _destination = destination; result["status"] = QString("success_install"); - emit finished(Utility::Json::convertObjToStr(result)); + emit finished(result); } /** @@ -210,7 +209,7 @@ void XdgUrl::process() QJsonObject result; result["status"] = QString("error_validation"); result["message"] = QString("Invalid XDG-URL " + _xdgUrl); - emit error(Utility::Json::convertObjToStr(result)); + emit error(result); return; } @@ -249,9 +248,9 @@ QString XdgUrl::getXdgUrl() return _xdgUrl; } -QString XdgUrl::getMetadata() +QJsonObject XdgUrl::getMetadata() { - return Utility::Json::convertObjToStr(_metadata); + return _metadata; } void XdgUrl::_downloaded(QNetworkReply *reply) @@ -260,7 +259,7 @@ void XdgUrl::_downloaded(QNetworkReply *reply) QJsonObject result; result["status"] = QString("error_network"); result["message"] = reply->errorString(); - emit error(Utility::Json::convertObjToStr(result)); + emit error(result); return; } diff --git a/src/handlers/xdgurl.h b/src/handlers/xdgurl.h index 03ce745..4aa1979 100644 --- a/src/handlers/xdgurl.h +++ b/src/handlers/xdgurl.h @@ -41,15 +41,15 @@ public slots: void openDestination(); bool isValid(); QString getXdgUrl(); - QString getMetadata(); + QJsonObject getMetadata(); private slots: void _downloaded(QNetworkReply *reply); signals: void started(); - void finished(const QString &result); - void error(const QString &result); + void finished(const QJsonObject &result); + void error(const QJsonObject &result); void downloadProgress(const qint64 &received, const qint64 &total); }; diff --git a/src/qml/main.qml b/src/qml/main.qml index 674523a..c931004 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -98,7 +98,7 @@ Window { } Component.onCompleted: { - var metadata = JSON.parse(xdgUrlHandler.getMetadata()); + var metadata = xdgUrlHandler.getMetadata(); var primaryMessages = { 'success_download': 'Download successfull', 'success_install': 'Installation successfull', @@ -114,7 +114,6 @@ Window { xdgUrlHandler.finished.connect(function(result) { progressDialog.close(); - result = JSON.parse(result); infoDialog.text = primaryMessages[result.status]; infoDialog.informativeText = metadata.filename; infoDialog.detailedText = result.message; @@ -123,7 +122,6 @@ Window { xdgUrlHandler.error.connect(function(result) { progressDialog.close(); - result = JSON.parse(result); errorDialog.text = primaryMessages[result.status]; errorDialog.informativeText = metadata.filename; errorDialog.detailedText = result.message; -- GitLab