diff --git a/src/handlers/xdgurl.cpp b/src/handlers/xdgurl.cpp index 333b1030b60f9737f06752274e0d7ad3f5434944..11519f9f3328b997f94e8e6c0e329115eb87745a 100644 --- a/src/handlers/xdgurl.cpp +++ b/src/handlers/xdgurl.cpp @@ -1,4 +1,6 @@ #include <QDebug> +#include <QUrl> +#include <QUrlQuery> #include "../core/config.h" #include "../core/network.h" @@ -12,10 +14,46 @@ 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) { + _meta = _parse(); } QJsonObject XdgUrl::_parse() { + QUrl url(_xdgUrl); + QUrlQuery query(url); + QJsonObject meta; + + meta["scheme"] = QString("xdg"); + meta["command"] = QString("download"); + meta["url"] = QString(""); + meta["type"] = QString("downloads"); + meta["filename"] = QString(""); + + if (!url.scheme().isEmpty()) { + meta["scheme"] = url.scheme(); + } + + if (!url.host().isEmpty()) { + meta["command"] = url.host(); + } + + if (query.hasQueryItem("url") && !query.queryItemValue("url").isEmpty()) { + meta["url"] = query.queryItemValue("url", QUrl::FullyDecoded); + } + + if (query.hasQueryItem("type") && !query.queryItemValue("type").isEmpty()) { + meta["type"] = query.queryItemValue("type", QUrl::FullyDecoded); + } + + if (query.hasQueryItem("filename") && !query.queryItemValue("filename").isEmpty()) { + meta["filename"] = query.queryItemValue("filename", QUrl::FullyDecoded).split("?").at(0); + } + + if (!meta["url"].toString().isEmpty() && meta["filename"].toString().isEmpty()) { + meta["filename"] = QUrl(meta["url"].toString()).fileName(); + } + + return meta; } bool XdgUrl::_installPlasmapkg(const QString &path, const QString &type)