Skip to content
Snippets Groups Projects
xdgurl.cpp 2 KiB
Newer Older
akiraohgaki's avatar
akiraohgaki committed
#include <QDebug>
akiraohgaki's avatar
akiraohgaki committed
#include <QUrl>
#include <QUrlQuery>
akiraohgaki's avatar
akiraohgaki committed

#include "../core/config.h"
#include "../core/network.h"
#include "../utility/file.h"
#include "../utility/json.h"

#include "xdgurl.h"

namespace Handlers {

akiraohgaki's avatar
akiraohgaki committed
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)
akiraohgaki's avatar
akiraohgaki committed
{
akiraohgaki's avatar
akiraohgaki committed
    _meta = _parse();
akiraohgaki's avatar
akiraohgaki committed
}

akiraohgaki's avatar
akiraohgaki committed
QJsonObject XdgUrl::_parse()
{
akiraohgaki's avatar
akiraohgaki committed
    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;
akiraohgaki's avatar
akiraohgaki committed
}

bool XdgUrl::_installPlasmapkg(const QString &path, const QString &type)
{
akiraohgaki's avatar
akiraohgaki committed
    return true;
akiraohgaki's avatar
akiraohgaki committed
}

bool XdgUrl::_uncompressArchive(const QString &path, const QString &targetDir)
{
akiraohgaki's avatar
akiraohgaki committed
    return true;
akiraohgaki's avatar
akiraohgaki committed
bool XdgUrl::_download()
{
akiraohgaki's avatar
akiraohgaki committed
    return true;
akiraohgaki's avatar
akiraohgaki committed
}

bool XdgUrl::_install()
{
akiraohgaki's avatar
akiraohgaki committed
    return true;
akiraohgaki's avatar
akiraohgaki committed
}

/**
 * Private slots
 */

/**
 * Public slots
 */

bool XdgUrl::process()
{
akiraohgaki's avatar
akiraohgaki committed
    return true;
akiraohgaki's avatar
akiraohgaki committed
} // namespace Handlers