Skip to content
Snippets Groups Projects
xdgurl.h 1.16 KiB
Newer Older
akiraohgaki's avatar
akiraohgaki committed
#ifndef HANDLERS_XDGURL_H
#define HANDLERS_XDGURL_H

#include <QObject>
akiraohgaki's avatar
akiraohgaki committed
#include <QJsonObject>
akiraohgaki's avatar
akiraohgaki committed

akiraohgaki's avatar
akiraohgaki committed
class QNetworkReply;
akiraohgaki's avatar
akiraohgaki committed

akiraohgaki's avatar
akiraohgaki committed
namespace utils {
akiraohgaki's avatar
akiraohgaki committed
class Config;
class Network;
}

akiraohgaki's avatar
akiraohgaki committed
namespace handlers {
akiraohgaki's avatar
akiraohgaki committed

class XdgUrl : public QObject
{
    Q_OBJECT

public:
akiraohgaki's avatar
akiraohgaki committed
    explicit XdgUrl(const QString &xdgUrl, utils::Config *config, utils::Network *network, QObject *parent = 0);
akiraohgaki's avatar
akiraohgaki committed

akiraohgaki's avatar
akiraohgaki committed
signals:
    void started();
    void finished(const QJsonObject &result);
    void error(const QJsonObject &result);
    void downloadProgress(const qint64 &received, const qint64 &total);
akiraohgaki's avatar
akiraohgaki committed

public slots:
akiraohgaki's avatar
akiraohgaki committed
    void process();
akiraohgaki's avatar
akiraohgaki committed
    bool isValid();
akiraohgaki's avatar
akiraohgaki committed
    void openDestination();
    QString xdgUrl() const;
    QJsonObject metadata() const;
akiraohgaki's avatar
akiraohgaki committed

private slots:
akiraohgaki's avatar
akiraohgaki committed
    void downloaded(QNetworkReply *reply);
akiraohgaki's avatar
akiraohgaki committed

akiraohgaki's avatar
akiraohgaki committed
private:
akiraohgaki's avatar
akiraohgaki committed
    void parse();
    void loadDestinations();
    QString convertPathString(const QString &path);
    void saveDownloadedFile(QNetworkReply *reply);
    void installDownloadedFile(QNetworkReply *reply);
akiraohgaki's avatar
akiraohgaki committed

    QString xdgUrl_;
akiraohgaki's avatar
akiraohgaki committed
    utils::Config *config_;
    utils::Network *network_;
akiraohgaki's avatar
akiraohgaki committed

    QJsonObject metadata_;
    QJsonObject destinations_;
    QString destination_;
akiraohgaki's avatar
akiraohgaki committed
};

akiraohgaki's avatar
akiraohgaki committed
} // namespace handlers
akiraohgaki's avatar
akiraohgaki committed

#endif // HANDLERS_XDGURL_H