Newer
Older
#include "qtlib_file.h"
#include "qtlib_dir.h"
#include "qtlib_networkresource.h"
#include "qtlib_package.h"
OcsUrlHandler::OcsUrlHandler(const QString &ocsUrl, const qtlib::Config &config, QObject *parent)
: QObject(parent), ocsUrl_(ocsUrl), config_(config)
// 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");
result["message"] = QString("Invalid OCS-URL " + ocsUrl_);
qtlib::NetworkResource *resource = new qtlib::NetworkResource(url, QUrl(url), true, this);
connect(resource, &qtlib::NetworkResource::downloadProgress, this, &OcsUrlHandler::downloadProgress);
connect(resource, &qtlib::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()
&& destinations_.contains(type)
&& !filename.isEmpty()) {
return true;
}
return false;
}
QString type = metadata_["type"].toString();
QDesktopServices::openUrl(QUrl("file://" + destinations_[type].toString()));
void OcsUrlHandler::networkResourceFinished(qtlib::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();
QJsonObject configDestinations = config_.get("destinations");
QJsonObject configDestinationsAlias = config_.get("destinations_alias");
destinations_[key] = convertPathString(configDestinations[key].toString());
foreach (const QString &key, configDestinationsAlias.keys()) {
QString value = configDestinationsAlias[key].toString();
if (destinations_.contains(value)) {
destinations_[key] = destinations_.value(value);
QString OcsUrlHandler::convertPathString(const QString &path)
newPath.replace("$XDG_DATA_HOME", qtlib::Dir::genericDataPath());
void OcsUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
qtlib::Dir destDir(destinations_[type].toString());
destDir.make();
qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
result["message"] = QString("Failed to save data as " + destFile.path());
result["message"] = QString("The file has been stored into " + destDir.path());
void OcsUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
qtlib::File tempFile(qtlib::Dir::tempPath() + "/" + metadata_["filename"].toString());
result["message"] = QString("Failed to save data as " + tempFile.path());
qtlib::Dir destDir(destinations_[type].toString());
destDir.make();
qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
&& package.installAsProgram(destFile.path())) {
result["message"] = QString("The file has been installed into " + destDir.path());
}
else if ((type == "plasma_plasmoids" || type == "plasma4_plasmoids" || type == "plasma5_plasmoids")
result["message"] = QString("The plasmoid has been installed");
}
else if ((type == "plasma_look_and_feel" || type == "plasma5_look_and_feel")
result["message"] = QString("The plasma look and feel has been installed");
}
else if ((type == "plasma_desktopthemes" || type == "plasma5_desktopthemes")
result["message"] = QString("The plasma desktop theme has been installed");
result["message"] = QString("The KWin effect has been installed");
result["message"] = QString("The KWin script has been installed");
result["message"] = QString("The KWin window switcher has been installed");
else if (package.installAsArchive(destDir.path())) {
result["message"] = QString("The archive file has been extracted into " + destDir.path());
else if (package.installAsFile(destFile.path())) {
result["message"] = QString("The file has been installed into " + destDir.path());