Skip to content
Snippets Groups Projects
Commit 12e47d24 authored by akiraohgaki's avatar akiraohgaki
Browse files

Update qtlib

parent 8d1b7817
No related branches found
No related tags found
No related merge requests found
......@@ -216,6 +216,16 @@ void NetworkResource::replyFinished()
emit finished(this);
}
void NetworkResource::replyDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
emit downloadProgress(id(), bytesReceived, bytesTotal);
}
void NetworkResource::replyUploadProgress(qint64 bytesSent, qint64 bytesTotal)
{
emit uploadProgress(id(), bytesSent, bytesTotal);
}
void NetworkResource::setManager(QNetworkAccessManager *manager)
{
manager_ = manager;
......@@ -266,8 +276,8 @@ NetworkResource *NetworkResource::send(const QUrl &url, bool async)
Q_ASSERT(false);
}
connect(reply(), &QNetworkReply::finished, this, &NetworkResource::replyFinished);
connect(reply(), &QNetworkReply::downloadProgress, this, &NetworkResource::downloadProgress);
connect(reply(), &QNetworkReply::uploadProgress, this, &NetworkResource::uploadProgress);
connect(reply(), &QNetworkReply::downloadProgress, this, &NetworkResource::replyDownloadProgress);
connect(reply(), &QNetworkReply::uploadProgress, this, &NetworkResource::replyUploadProgress);
if (!async) {
QEventLoop eventLoop;
connect(this, &NetworkResource::finished, &eventLoop, &QEventLoop::quit);
......
......@@ -56,14 +56,16 @@ public:
signals:
void finished(NetworkResource *resource);
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
void downloadProgress(QString id, qint64 bytesReceived, qint64 bytesTotal);
void uploadProgress(QString id, qint64 bytesSent, qint64 bytesTotal);
public slots:
void abort();
private slots:
void replyFinished();
void replyDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void replyUploadProgress(qint64 bytesSent, qint64 bytesTotal);
private:
void setManager(QNetworkAccessManager *manager);
......
......@@ -16,7 +16,8 @@ public:
Test() {}
virtual ~Test() {}
void start() {
void start()
{
qDebug() << "Start";
qtlib::NetworkResource *resource = new qtlib::NetworkResource(
......@@ -24,27 +25,35 @@ public:
QUrl("https://api.opensource.org/license/LGPL-3.0"),
false,
this);
connect(resource, &qtlib::NetworkResource::downloadProgress, this, &Test::downloadProgress);
QJsonObject result = qtlib::Json(resource->get()->readData()).toObject();
qDebug() << resource->id() << ":" << result["name"].toString();
connect(resource, &qtlib::NetworkResource::finished, this, &Test::finished);
resource->setId(result["name"].toString());
resource->setUrl(QUrl(result["text"].toArray()[0].toObject()["url"].toString()));
resource->setAsync(true);
connect(resource, &qtlib::NetworkResource::finished, this, &Test::finished);
resource->get();
}
public slots:
void finished(qtlib::NetworkResource *resource) {
void finished(qtlib::NetworkResource *resource)
{
QString path = qtlib::Dir::tempPath() + "/" + resource->url().fileName();
resource->saveData(path);
resource->deleteLater();
qDebug() << "Downloaded" << resource->id() << ":" << path;
qDebug() << "Finished";
resource->deleteLater();
QCoreApplication::exit();
}
void downloadProgress(QString id, qint64 bytesReceived, qint64 bytesTotal)
{
qDebug() << "Progress" << id << ":" << bytesReceived << "/" << bytesTotal;
}
};
int main(int argc, char *argv[])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment