Ejemplo n.º 1
0
void Downloader::doHttpRequest(QString url){

    QNetworkRequest request;
    request.setUrl(QUrl(url));
    request.setRawHeader( "User-Agent" , "Mozilla Firefox" ); // :) Probabilly is not really need!

    qInfo() << endl << "Starting http request to" << url;
    reply.reset( httpClient.get(request));
    if(reply->error() != QNetworkReply::NoError){
        throw std::runtime_error(reply->errorString().toStdString());
    }

    connect(reply.data(), SIGNAL(finished()), this, SIGNAL(downloadFinished()));
    connect(reply.data(), SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgressed(qint64,qint64)));
    connect(reply.data(), SIGNAL(readyRead()), this, SLOT(bytesAvailable()));
    connect(reply.data(), SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError)));

    emit downloadStarted();
}
Ejemplo n.º 2
0
void UBHttpGet::get(QUrl pUrl, QPointF pPos, QSize pSize, bool isBackground)
{
    mPos = pPos;
    mSize = pSize;
    mIsBackground = isBackground;

        if (mReply)
                delete mReply;

    UBNetworkAccessManager * nam = UBNetworkAccessManager::defaultAccessManager();
    mReply = nam->get(QNetworkRequest(pUrl)); //mReply deleted by this destructor

    mDownloadedBytes.clear();

    connect(mReply, SIGNAL(finished()), this, SLOT(requestFinished()));
    connect(mReply, SIGNAL(readyRead()), this, SLOT(readyRead()));
    connect(mReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgressed(qint64, qint64)));

}
Ejemplo n.º 3
0
void WebImageView::setUrl(const QUrl url) {
	if(url != mUrl){
		resetImage();
		mUrl = url;
		QIODevice *temp = diskCache->data(url);
		if(temp){
			setImage(Image(temp->readAll()));
			mLoading = 1;
			emit loadingChanged();
		} else{
			mLoading = 0.01;
			emit loadingChanged();
			if(defaultImageUrl!=QUrl(""))
				setImage(Image(defaultImageUrl));
			urls.push_back(url);
			replies.push_back(mNetManager->get(QNetworkRequest(url)));
			connect(replies.back(),SIGNAL(finished()), this, SLOT(imageLoaded()));
			connect(replies.back(),SIGNAL(downloadProgress ( qint64 , qint64  )), this, SLOT(downloadProgressed(qint64,qint64)));
		}
		emit urlChanged();
	}
}
Ejemplo n.º 4
0
void WebImageView::imageLoaded() {
	QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
	if (reply->error() == QNetworkReply::NoError) {
		QVariant repliestatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
		int i=replies.indexOf(reply);
		// HANDLES REDIRECTIONS
		if (repliestatus == 301 || repliestatus == 302)
		{
			QString redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
			replies[i]=mNetManager->get(QNetworkRequest(redirectUrl));
			connect(replies[i],SIGNAL(finished()), this, SLOT(imageLoaded()));
			connect(replies[i],SIGNAL(downloadProgress ( qint64 , qint64  )), this, SLOT(downloadProgressed(qint64,qint64)));
		} else {
			if(urls.at(i)==mUrl)
				setImage(Image(reply->readAll()));
			urls.removeAt(i);
			replies.removeAt(i);
		}
	}
	mLoading = 1;
	emit loadingChanged();
	reply->deleteLater();
}