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

Code cleanup

parent 3bb2afed
No related branches found
No related tags found
No related merge requests found
...@@ -66,9 +66,7 @@ bool XdgUrlHandler::isValid() ...@@ -66,9 +66,7 @@ bool XdgUrlHandler::isValid()
void XdgUrlHandler::openDestination() void XdgUrlHandler::openDestination()
{ {
if (!destination_.isEmpty()) { QDesktopServices::openUrl(QUrl("file://" + destinations_[metadata_["type"].toString()].toString()));
QDesktopServices::openUrl(QUrl("file://" + destination_));
}
} }
void XdgUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource) void XdgUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource)
...@@ -77,8 +75,8 @@ void XdgUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource) ...@@ -77,8 +75,8 @@ void XdgUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource)
QJsonObject result; QJsonObject result;
result["status"] = QString("error_network"); result["status"] = QString("error_network");
result["message"] = resource->reply()->errorString(); result["message"] = resource->reply()->errorString();
resource->deleteLater();
emit finishedWithError(result); emit finishedWithError(result);
resource->deleteLater();
return; return;
} }
...@@ -173,18 +171,16 @@ void XdgUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource) ...@@ -173,18 +171,16 @@ void XdgUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
if (!resource->saveData(path)) { if (!resource->saveData(path)) {
result["status"] = QString("error_save"); result["status"] = QString("error_save");
result["message"] = QString("Failed to save data as " + path); result["message"] = QString("Failed to save data as " + path);
resource->deleteLater();
emit finishedWithError(result); emit finishedWithError(result);
resource->deleteLater();
return; return;
} }
resource->deleteLater();
destination_ = destination;
result["status"] = QString("success_download"); result["status"] = QString("success_download");
result["message"] = QString("The file has been stored into " + destination); result["message"] = QString("The file has been stored into " + destination);
emit finishedWithSuccess(result); emit finishedWithSuccess(result);
resource->deleteLater();
} }
void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource) void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
...@@ -196,15 +192,13 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource) ...@@ -196,15 +192,13 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
if (!resource->saveData(tempPath)) { if (!resource->saveData(tempPath)) {
result["status"] = QString("error_save"); result["status"] = QString("error_save");
result["message"] = QString("Failed to save data as " + tempPath); result["message"] = QString("Failed to save data as " + tempPath);
resource->deleteLater();
emit finishedWithError(result); emit finishedWithError(result);
resource->deleteLater();
return; return;
} }
resource->deleteLater();
qtlib::Package package(tempPath);
qtlib::File tempFile(tempPath); qtlib::File tempFile(tempPath);
qtlib::Package package(tempPath);
QString type = metadata_["type"].toString(); QString type = metadata_["type"].toString();
QString destination = destinations_[type].toString(); QString destination = destinations_[type].toString();
...@@ -247,17 +241,16 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource) ...@@ -247,17 +241,16 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
result["message"] = QString("The file has been installed into " + destination); result["message"] = QString("The file has been installed into " + destination);
} }
else { else {
tempFile.remove();
result["status"] = QString("error_install"); result["status"] = QString("error_install");
result["message"] = QString("Failed to installation"); result["message"] = QString("Failed to installation");
emit finishedWithError(result); emit finishedWithError(result);
tempFile.remove();
return; return;
} }
tempFile.remove();
destination_ = destination;
result["status"] = QString("success_install"); result["status"] = QString("success_install");
emit finishedWithSuccess(result); emit finishedWithSuccess(result);
tempFile.remove();
resource->deleteLater();
} }
...@@ -44,5 +44,4 @@ private: ...@@ -44,5 +44,4 @@ private:
qtlib::Config config_; qtlib::Config config_;
QJsonObject metadata_; QJsonObject metadata_;
QJsonObject destinations_; QJsonObject destinations_;
QString destination_;
}; };
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