Newer
Older
#include "qtil_file.h"
#include "qtil_dir.h"
#include "qtil_networkresource.h"
#include "qtil_package.h"
#include "handlers/confighandler.h"
OcsUrlHandler::OcsUrlHandler(const QString &ocsUrl, ConfigHandler *configHandler, QObject *parent)
: QObject(parent), ocsUrl_(ocsUrl), configHandler_(configHandler)
// ocss scheme is a reserved name, so the process of ocss
// is the same process of the ocs scheme currently.
if (!isValid()) {
QJsonObject result;
result["status"] = QString("error_validation");
auto *resource = new Qtil::NetworkResource(url, QUrl(url), true, this);
connect(resource, &Qtil::NetworkResource::downloadProgress, this, &OcsUrlHandler::downloadProgress);
connect(resource, &Qtil::NetworkResource::finished, this, &OcsUrlHandler::networkResourceFinished);
{
QString scheme = metadata_["scheme"].toString();
QString command = metadata_["command"].toString();
QString url = metadata_["url"].toString();
QString type = metadata_["type"].toString();
QString filename = metadata_["filename"].toString();
&& (command == "download" || command == "install")
&& QUrl(url).isValid()
&& configHandler_->getAppConfigInstallTypes().contains(type)
&& !filename.isEmpty()) {
return true;
}
return false;
}
void OcsUrlHandler::openDestination() const
QDesktopServices::openUrl(QUrl("file://" + configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString()));
void OcsUrlHandler::networkResourceFinished(Qtil::NetworkResource *resource)
QJsonObject result;
result["status"] = QString("error_network");
return;
}
if (metadata_["command"].toString() == "download") {
metadata_["command"] = QString("download");
metadata_["url"] = QString("");
metadata_["type"] = QString("downloads");
metadata_["filename"] = QString("");
}
if (query.hasQueryItem("url") && !query.queryItemValue("url").isEmpty()) {
metadata_["url"] = query.queryItemValue("url", QUrl::FullyDecoded);
}
if (query.hasQueryItem("type") && !query.queryItemValue("type").isEmpty()) {
metadata_["type"] = query.queryItemValue("type", QUrl::FullyDecoded);
}
if (query.hasQueryItem("filename") && !query.queryItemValue("filename").isEmpty()) {
metadata_["filename"] = QUrl(query.queryItemValue("filename", QUrl::FullyDecoded)).fileName();
if (!metadata_["url"].toString().isEmpty() && metadata_["filename"].toString().isEmpty()) {
metadata_["filename"] = QUrl(metadata_["url"].toString()).fileName();
void OcsUrlHandler::saveDownloadedFile(Qtil::NetworkResource *resource)
Qtil::Dir destDir(configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString());
Qtil::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
result["message"] = tr("The file has been downloaded");
void OcsUrlHandler::installDownloadedFile(Qtil::NetworkResource *resource)
Qtil::File tempFile(Qtil::Dir::tempPath() + "/" + metadata_["filename"].toString());
Qtil::Dir destDir(configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString());
Qtil::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
result["message"] = tr("The file has been installed as program");
}
else if ((type == "plasma_plasmoids" || type == "plasma4_plasmoids" || type == "plasma5_plasmoids")
result["message"] = tr("The plasmoid has been installed");
}
else if ((type == "plasma_look_and_feel" || type == "plasma5_look_and_feel")
result["message"] = tr("The plasma look and feel has been installed");
}
else if ((type == "plasma_desktopthemes" || type == "plasma5_desktopthemes")
result["message"] = tr("The plasma desktop theme has been installed");
result["message"] = tr("The KWin effect has been installed");
result["message"] = tr("The KWin script has been installed");
result["message"] = tr("The KWin window switcher has been installed");
result["message"] = tr("The archive file has been extracted");
result["message"] = tr("The file has been installed");
result["message"] = tr("Failed to installation");