Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
orthanc-qt/resource.hpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
57 lines (51 sloc)
1.51 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef RESOURCE_HPP | |
#define RESOURCE_HPP | |
#include "orthancaccess.hpp" | |
#include <QJsonDocument> | |
#include <QImage> | |
#include <QTemporaryFile> | |
#include <QMimeType> | |
#include <QBuffer> | |
namespace orthanc { | |
class Resource:public QObject{ | |
Q_OBJECT | |
QString m_type; | |
QIODevice &m_target; | |
protected: | |
QNetworkReply *my_reply; | |
int m_timeout; | |
private slots: | |
void receive(qint64 bytesReceived, qint64 bytesTotal)const; | |
public: | |
Resource(QString url, QString expected_type, QIODevice &target, int timeout, QObject *parent=NULL); | |
virtual ~Resource(); | |
bool isReady() const; | |
QUrl url() const; | |
bool waitForFinished(int msec) const; | |
QMetaObject::Connection connectFinished(QObject *obj, const char *slot); | |
}; | |
class BufferedResource:public Resource{ | |
Q_OBJECT | |
QBuffer buffer; | |
public: | |
BufferedResource(QString url, QString expected_type, int timeout=1000, QObject *parent=NULL): | |
Resource(url,expected_type,buffer,timeout,parent){buffer.open(QIODevice::ReadWrite);} | |
QByteArray get()const; | |
}; | |
class JsonResource:public BufferedResource{ | |
Q_OBJECT | |
public: | |
JsonResource(QString url, int timeout=1000, QObject *parent=NULL):BufferedResource(url,"application/json",timeout,parent){} | |
QJsonDocument get()const; | |
static QJsonValue dig(QStringList path, const QJsonObject &obj); | |
QJsonValue dig(const QString &path) const; | |
}; | |
class ImageResource:public BufferedResource{ | |
Q_OBJECT | |
QImage image; | |
public: | |
ImageResource(QString url, QObject *parent=NULL):BufferedResource(url,"image/png",5000,parent){} | |
QImage get()const; | |
}; | |
} | |
#endif // RESOURCE_HPP |