Ejemplo n.º 1
0
bool PictureContent::loadFromNetwork(const QString & url, QNetworkReply * reply, const QString & title, int width, int height)
{
    dropNetworkConnection();
    delete m_photo;
    m_cachedPhoto = QPixmap();
    m_opaquePhoto = false;
    m_photo = 0;
    m_fileUrl = url;
    m_netWidth = width;
    m_netHeight = height;

    // start a download if not passed as a paramenter
    if (!reply) {
        // the QNAM will be auto-deleted on closure
        QNetworkAccessManager * nam = new QNetworkAccessManager(this);
        QNetworkRequest request(url);
        m_netReply = nam->get(request);
    } else
        m_netReply = reply;

    // set title
    if (!title.isEmpty()) {
        setFrameTextEnabled(true);
        setFrameText(title);
    }

#if QT_VERSION >= 0x040600
    // Immediate Decode: just handle the reply if done
    if (m_netReply->isFinished())
        return slotLoadNetworkData();
#else
    // No Precaching ensures signals to be emitted later
#endif

    // Deferred Decode: listen to the network job
    setAcceptHoverEvents(false);
    setControlsVisible(false);
    m_progress = 0.01;
    connect(m_netReply, SIGNAL(finished()), this, SLOT(slotLoadNetworkData()));
    connect(m_netReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotNetworkError()));
    connect(m_netReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slotNetworkProgress(qint64,qint64)));

    // reset size, if got the network one
    if (m_netWidth > 0 && m_netHeight > 0)
        resetContentsRatio();
    return true;
}
Ejemplo n.º 2
0
ShowPicture::ShowPicture(QString bigUrl, QString midUrl, QWidget *parent) :
    QWidget(parent)
{
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->bigUrl = bigUrl;
    this->midUrl = midUrl;
    if(midUrl.toUpper().endsWith(".GIF"))
        this->isGif = true;
    else
        this->isGif = false;
    this->setWindowTitle(tr("图片"));
    progressBar = new QProgressBar(this);
    progressBar->setValue(0);
    label = new QLabel(this);
    label->setText("正在下载......");
    this->showGif = new QLabel(this);
    this->showGif->hide();
    this->movie = new QMovie(this);
    this->gifImageFile = new QBuffer(&imageByteArray, this);
    layout = new QVBoxLayout(this);
    layout->addWidget(label);
    layout->addWidget(progressBar);
    
    toolBar = new QToolBar(this);
    saveFile = new QAction(this);
    bigPicture = new QAction(this);
    saveFile->setText("保存图片");
    bigPicture->setText("查看大图");

    QObject::connect(saveFile, SIGNAL(triggered()), this, SLOT(saveImage()));
    QObject::connect(bigPicture, SIGNAL(triggered()), this, SLOT(showBigPicture()));
    toolBar->addAction(saveFile);
    toolBar->addAction(bigPicture);
    toolBar->hide();
    view = new QGraphicsView(this);
    scene = new QGraphicsScene(this);
    view->setScene(scene);
    view->hide();
    
    http = new Http(this);
    QObject::connect(http, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateProgressBar(qint64,qint64)));
    //QObject::connect(http, SIGNAL(finished()), this, SLOT(showAfterDownload()));
    timer = new QTimer(this);
    timer->setSingleShot(true);
    QObject::connect(timer, SIGNAL(timeout()), this, SLOT(downloadFile()));
    timer->start(500);
}
Ejemplo n.º 3
0
void LegacyUpdate::lwjglStart()
{
	LegacyInstance *inst = (LegacyInstance *)m_inst;

	lwjglVersion = inst->lwjglVersion();
	lwjglTargetPath = PathCombine(MMC->settings()->get("LWJGLDir").toString(), lwjglVersion);
	lwjglNativesPath = PathCombine(lwjglTargetPath, "natives");

	// if the 'done' file exists, we don't have to download this again
	QFileInfo doneFile(PathCombine(lwjglTargetPath, "done"));
	if (doneFile.exists())
	{
		jarStart();
		return;
	}

	auto list = MMC->lwjgllist();
	if (!list->isLoaded())
	{
		emitFailed("Too soon! Let the LWJGL list load :)");
		return;
	}

	setStatus(tr("Downloading new LWJGL..."));
	auto version = list->getVersion(lwjglVersion);
	if (!version)
	{
		emitFailed("Game update failed: the selected LWJGL version is invalid.");
		return;
	}

	QString url = version->url();
	QUrl realUrl(url);
	QString hostname = realUrl.host();
	auto worker = MMC->qnam();
	QNetworkRequest req(realUrl);
	req.setRawHeader("Host", hostname.toLatin1());
	req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
	QNetworkReply *rep = worker->get(req);

	m_reply = std::shared_ptr<QNetworkReply>(rep);
	connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
	connect(worker.get(), SIGNAL(finished(QNetworkReply *)),
			SLOT(lwjglFinished(QNetworkReply *)));
	// connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
	// SLOT(downloadError(QNetworkReply::NetworkError)));
}
Ejemplo n.º 4
0
void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
{
	if (m_reply.get() != reply)
	{
		return;
	}
	if (reply->error() != QNetworkReply::NoError)
	{
		emitFailed("Failed to download: " + reply->errorString() +
				   "\nSometimes you have to wait a bit if you download many LWJGL versions in "
				   "a row. YMMV");
		return;
	}
	auto worker = MMC->qnam();
	// Here i check if there is a cookie for me in the reply and extract it
	QList<QNetworkCookie> cookies =
		qvariant_cast<QList<QNetworkCookie>>(reply->header(QNetworkRequest::SetCookieHeader));
	if (cookies.count() != 0)
	{
		// you must tell which cookie goes with which url
		worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net"));
	}

	// here you can check for the 302 or whatever other header i need
	QVariant newLoc = reply->header(QNetworkRequest::LocationHeader);
	if (newLoc.isValid())
	{
		QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString();
		QUrl realUrl(redirectedTo);
		QString hostname = realUrl.host();
		QNetworkRequest req(redirectedTo);
		req.setRawHeader("Host", hostname.toLatin1());
		req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
		QNetworkReply *rep = worker->get(req);
		connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
				SIGNAL(progress(qint64, qint64)));
		m_reply = std::shared_ptr<QNetworkReply>(rep);
		return;
	}
	QFile saveMe("lwjgl.zip");
	saveMe.open(QIODevice::WriteOnly);
	saveMe.write(m_reply->readAll());
	saveMe.close();
	setStatus(tr("Installing new LWJGL..."));
	extractLwjgl();
	jarStart();
}
Ejemplo n.º 5
0
void ParserAbstract::sendHttpRequest(QUrl url, QByteArray data)
{
    QNetworkRequest request;
    request.setUrl(url);
    request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
    request.setRawHeader("Cache-Control", "no-cache");

    if (data.isNull()) {
        lastRequest = NetworkManager->get(request);
    } else {
        lastRequest = NetworkManager->post(request, data);
    }

    requestTimeout->start(30000);

    connect(lastRequest, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(networkReplyDownloadProgress(qint64,qint64)));
}
/* Prepare network-reply: */
void UINetworkRequest::prepareNetworkReply()
{
    /* Make network-request: */
    m_pReply = new UINetworkReply(m_request, m_type);
    AssertMsg(m_pReply, ("Unable to make network-request!\n"));
    /* Prepare listeners for m_pReply: */
    connect(m_pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(sltHandleNetworkReplyProgress(qint64, qint64)));
    connect(m_pReply, SIGNAL(finished()), this, SLOT(sltHandleNetworkReplyFinish()));

    /* Set as running: */
    m_fRunning = true;

    /* Notify general network-requests listeners: */
    emit sigStarted(m_uuid);
    /* Notify particular network-request listeners: */
    emit sigStarted();
}
Ejemplo n.º 7
0
bool Http::get(const QString& url)
{
    m_Data.clear();
    m_Request.setUrl(url);
    m_pReply = m_NetworkManager.get(m_Request);

    QEventLoop loop;
    connect(m_pReply, SIGNAL(finished()), &loop, SLOT(quit()));
    connect(m_pReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64,qint64)));
    loop.exec();

    m_Data.append(m_pReply->readAll());
    m_Error = m_pReply->error();
    m_Message = m_pReply->errorString();

    return m_Error == QNetworkReply::NoError;
}
Ejemplo n.º 8
0
void DownLoadFun::down(STATUSID id, QString url)
{
    if(reply != NULL)
    {
        reply->abort();
    }

    m_id = id;

    QNetworkAccessManager *manager = new QNetworkAccessManager;
    reply = manager->get(QNetworkRequest(url));

    connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));

    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),
            this,SLOT(updateDataReadProgress(qint64,qint64)));
}
Ejemplo n.º 9
0
bool QgsWcsCapabilities::sendRequest( QString const & url )
{
  QgsDebugMsg( "url = " + url );
  mError = "";
  QNetworkRequest request( url );
  if ( !setAuthorization( request ) )
  {
    mError = tr( "Download of capabilities failed: network request update failed for authentication config" );
    QgsMessageLog::logMessage( mError, tr( "WCS" ) );
    return false;
  }
  request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
  request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mCacheLoadControl );
  QgsDebugMsg( QString( "mCacheLoadControl = %1" ).arg( mCacheLoadControl ) );

  QgsDebugMsg( QString( "getcapabilities: %1" ).arg( url ) );
  mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );

  connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
  connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );

  while ( mCapabilitiesReply )
  {
    QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
  }

  if ( mCapabilitiesResponse.isEmpty() )
  {
    if ( mError.isEmpty() )
    {
      mErrorFormat = "text/plain";
      mError = tr( "empty capabilities document" );
    }
    return false;
  }

  if ( mCapabilitiesResponse.startsWith( "<html>" ) ||
       mCapabilitiesResponse.startsWith( "<HTML>" ) )
  {
    mErrorFormat = "text/html";
    mError = mCapabilitiesResponse;
    return false;
  }
  return true;
}
void QQuickAnimatedImage::load()
{
    Q_D(QQuickAnimatedImage);

    if (d->url.isEmpty()) {
        if (d->progress != 0) {
            d->progress = 0;
            emit progressChanged(d->progress);
        }

        d->setImage(QImage());
        d->status = Null;
        emit statusChanged(d->status);

        if (sourceSize() != d->oldSourceSize) {
            d->oldSourceSize = sourceSize();
            emit sourceSizeChanged();
        }
        if (isPlaying() != d->oldPlaying)
            emit playingChanged();
    } else {
        QString lf = QQmlFile::urlToLocalFileOrQrc(d->url);
        if (!lf.isEmpty()) {
            d->_movie = new QMovie(lf);
            movieRequestFinished();
        } else {
            if (d->status != Loading) {
                d->status = Loading;
                emit statusChanged(d->status);
            }
            if (d->progress != 0) {
                d->progress = 0;
                emit progressChanged(d->progress);
            }
            QNetworkRequest req(d->url);
            req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);

            d->reply = qmlEngine(this)->networkAccessManager()->get(req);
            QObject::connect(d->reply, SIGNAL(finished()),
                            this, SLOT(movieRequestFinished()));
            QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
                            this, SLOT(requestProgress(qint64,qint64)));
        }
    }
}
Ejemplo n.º 11
0
/** Report download progress to the user */
void HttpClient::slotDownloadProgress( qint64 bytesReceived, qint64 bytesTotal )
{
  // qDebug() << "HttpClient::slotDownloadProgress" << bytesReceived << bytesTotal;

  if ( _progressDialog != static_cast<QProgressDialog *> (0) )
    {
      // Report results to the progress dialog.
      _progressDialog->setMaximum( bytesTotal );
      _progressDialog->setValue( bytesReceived );
    }
  else
    {
      // Emit this signal to the outside, when no progress dialog is set up.
      emit downloadProgress( bytesReceived, bytesTotal );
    }

  timer->start();
}
Ejemplo n.º 12
0
void GetFileTask::sendRequest()
{
    QNetworkRequest request(url_);
    if (!network_mgr_) {
        static QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
        network_mgr_ = manager;
        NetworkManager::instance()->addWatch(network_mgr_);
    }
    reply_ = network_mgr_->get(request);

    connect(reply_, SIGNAL(sslErrors(const QList<QSslError>&)),
            this, SLOT(onSslErrors(const QList<QSslError>&)));

    connect(reply_, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
    connect(reply_, SIGNAL(downloadProgress(qint64, qint64)),
            this, SIGNAL(progressUpdate(qint64, qint64)));
    connect(reply_, SIGNAL(finished()), this, SLOT(httpRequestFinished()));
}
Ejemplo n.º 13
0
void dbmanager::doDownload(const QVariant& v)
{
    if (v.type() == QVariant::StringList) {


        QNetworkAccessManager *manager= new QNetworkAccessManager(this);

        QUrl url = v.toStringList().at(current);

        filename = url.toString().remove("http://restbase.wikitolearn.org/en.wikitolearn.org/v1/media/math/render/svg/");
        m_network_reply = manager->get(QNetworkRequest(QUrl(url)));

        connect(m_network_reply, SIGNAL(downloadProgress (qint64, qint64)),this, SLOT(updateDownloadProgress(qint64, qint64))); // checks download progress
        connect(m_network_reply,SIGNAL(finished()),this,SLOT(downloadFinished())); // signal that download is finished


    }
}
Ejemplo n.º 14
0
bool NetworkHandler::startJSONDownload()
{
    QNetworkRequest req(m_Url);
    req.setRawHeader(m_headerName,m_headerValue);    
    m_pNetworkReply = m_Mgr.get(req);
    if(m_pNetworkReply)
    {
        QObject::connect(m_pNetworkReply,SIGNAL(finished()),this,SLOT(readFinished()));
        QObject::connect(m_pNetworkReply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64)));
        QObject::connect(m_pNetworkReply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError)));
        QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(timeout()));
    }
    else
    {
        qDebug() << "Failed to create get request!";
        emit readyRead(QByteArray());
    }
}
Ejemplo n.º 15
0
void video::download()
{
    _step = 3;
    handler->clearDownloads();

    connect(handler, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(changeProgress(qint64, qint64)));

    if (!this->_supportedQualities.at(_quality).videoUrl.isEmpty())
    {
        qDebug() << "Downloading video file: " << this->_supportedQualities.at(_quality).videoUrl;
        handler->addDownload(this->_supportedQualities.at(_quality).videoUrl, this->_supportedQualities.at(_quality).chunkedDownload);
    }
    if (!this->_supportedQualities.at(_quality).audioUrl.isEmpty())
    {
        qDebug() << "Downloading audio file: " << this->_supportedQualities.at(_quality).audioUrl;
        handler->addDownload(this->_supportedQualities.at(_quality).audioUrl, this->_supportedQualities.at(_quality).chunkedDownload);
    }
}
Ejemplo n.º 16
0
//reply finished
void Downloader::finishedSlot(){

    if (reply->error() == QNetworkReply::NoError){
        QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

        if (!possibleRedirectUrl.toUrl().isEmpty()) {
            //there is redirect
            //make new request
            //emit sendInfo("Redirected to "+possibleRedirectUrl.toUrl().toString());

            reply->deleteLater();
            reply = nam.get(QNetworkRequest(possibleRedirectUrl.toUrl())); //when this reply is finished this slot will get re-triggered

            emit sendInfo("Redirecting...");
            emit sendInfo("");
            tmpBuffer.clear(); //CLEAR THE GODDAMN BUFFER!!!!
            file->resize(0);

            //reconnect since deleting reply disconnects all slots
            QObject::connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot()));
            QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(errorSlot(QNetworkReply::NetworkError)));
            QObject::connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(progressSlot(qint64, qint64)));
        }
        else {
            //all ok
            emit sendInfo("Downloader exiting with no errors");

            //Read whatever is left
            tmpBuffer.append(reply->readAll());
            file->write(tmpBuffer);
            file->close();

            emit sendInfo("Handing off work to updater");
            emit finisheddl();
        }
    }
    else {
        if (!erroremitted) {
            emit sendInfo("Network err code: "+reply->errorString());
            erroremitted=true;
            emit finisheddl();
        }
    }
}
Ejemplo n.º 17
0
void LoginWindow::doSignIn(QString username,QString password)
{
    if(loginInProgress)
       return;

    if (!username.isEmpty() && !password.isEmpty())
    {
        QUrl m_loginUrl = QUrl ( QString(Constants::LOGIN_PATH) +
                             "u=" + username + "&p=" + password );
        reply = manager.get(QNetworkRequest(m_loginUrl));

        connect(reply, SIGNAL(finished()),
                this, SLOT(httpFinished()));
        connect(reply, SIGNAL(readyRead()),
                this, SLOT(httpReadyRead()));
        connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
                this, SLOT(updateProgress(qint64,qint64)));
    }
}
int HttpCommunicator::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: finishedRequest(); break;
        case 1: finishedSlot((*reinterpret_cast< QNetworkReply*(*)>(_a[1]))); break;
        case 2: downloadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        case 3: uploadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        case 4: downloadReadyRead(); break;
        case 5: construct2(); break;
        default: ;
        }
        _id -= 6;
    }
    return _id;
}
Ejemplo n.º 19
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.º 20
0
void ReplyFetcher::start(QNetworkAccessManager *nam, QNetworkRequest request, QByteArray postData)
{
    httpStatusCode_= 0;
    errorText_.clear();
    receivedData_.clear();
    success_ = true; // not in finished() signal handler, it might be not called according to the docs
                     // besides, I've added timeout feature
    lastNetworkTime_ = QDateTime::currentMSecsSinceEpoch();
    ticker_->start(1000);
    if(postData.isNull()) {
        reply = QSharedPointer<QNetworkReply>(nam->get(request), &QObject::deleteLater);
    } else {
        reply = QSharedPointer<QNetworkReply>(nam->post(request, postData), &QObject::deleteLater);
    }
    connect(reply.data(), SIGNAL(finished()), this, SLOT(onFinished()));
    connect(reply.data(), SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
    connect(reply.data(), SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(onSslErrors(QList<QSslError>)));
    connect(reply.data(), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64,qint64)));
}
Ejemplo n.º 21
0
void Downloader::startDownload (const QUrl& url) {
    /* Reset UI */
    m_ui->progressBar->setValue (0);
    m_ui->stopButton->setText (tr ("Stop"));
    m_ui->downloadLabel->setText (tr ("Downloading updates"));
    m_ui->timeLabel->setText (tr ("Time remaining") + ": " + tr ("unknown"));

    /* Start download */
    m_startTime = QDateTime::currentDateTime().toTime_t();
    m_reply = m_manager->get (QNetworkRequest (url));

    /* Update UI when download progress changes or download finishes */
    connect (m_reply, SIGNAL (downloadProgress (qint64, qint64)),
             this,      SLOT (updateProgress   (qint64, qint64)));
    connect (m_reply, SIGNAL (finished()),
             this,      SLOT (onDownloadFinished()));

    showNormal();
}
Ejemplo n.º 22
0
void ProgressDialog::doUrlDownload(Download download)
{
    QString userAgent = "FlashTool ";
    userAgent.append(FLASHTOOL_VERSION);
    this->reset();
    QNetworkRequest request;
    request.setUrl(download.uri);
    request.setRawHeader("User-Agent", userAgent.toLatin1());
    request.setRawHeader("Cache-Control", "no-cache");
    request.setRawHeader("Content-Type", "text/xml");

    if (download.body.isEmpty()) {
        this->m_networkRequest = this->m_networkManager->get(request);
    } else {
        this->m_networkRequest = this->m_networkManager->post(request, download.body.toLatin1());
    }
    m_downloadRequestTimeout->start(30000);
    connect(this->m_networkRequest, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(networkReplyDownloadProgress(qint64,qint64)));
}
Ejemplo n.º 23
0
void KisGmicUpdater::start()
{
    QUrl url(m_url);
    QNetworkRequest request(url);

    QString userAgent("org.krita.gmic/");

    QString version = QString("%0.%1.%2.%3").arg(gmic_version/1000).arg((gmic_version/100)%10).arg((gmic_version/10)%10).arg(gmic_version%10);

    userAgent.append(version);
    dbgPlugins << "userAgent" << userAgent.toLatin1();

    request.setRawHeader("User-Agent", userAgent.toLatin1());

    QNetworkReply * getReply = m_manager.get(request);

    connect(getReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(reportProgress(qint64,qint64)));
    connect(getReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));
}
Ejemplo n.º 24
0
void AdBlockDownloader::downloadFile(const QString& path, const QString &filename, const QString& localfile)
{
    this->_progressvalue = 0;
    this->_progresstotal = 0;

    emit connectionStarted();

    this->_localfile = localfile;
    this->_tempfile.setFileName(localfile);
    this->_tempfile.open(QFile::WriteOnly | QFile::Truncate);

    QUrl url(QString("%1/%2").arg(path, filename));
    QNetworkRequest request(url);

    this->_downloadreply = this->_networkmanager.get(request);
    connect(this->_downloadreply, SIGNAL(readyRead()), this, SLOT(onNetworkReplyReadyRead()));
    connect(this->_downloadreply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64,qint64)));
    connect(this->_downloadreply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onDownloadError(QNetworkReply::NetworkError)));
}
Ejemplo n.º 25
0
void TransferItem::start()
{
    switch (method) {
    case Get:
        reply = nam.get(request);
        connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
        connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(progress(qint64,qint64)));
        break;
    case Put:
        reply = nam.put(request, inputFile);
        connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(progress(qint64,qint64)));
        break;
    case Post:
        reply = nam.post(request, inputFile);
        connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(progress(qint64,qint64)));
        break;
    }
    connect(reply, SIGNAL(finished()), this, SLOT(finished()));
}
Ejemplo n.º 26
0
    void UpdaterDialog::doDownload(const QModelIndex &index)
    {        
        QUrl downloadURL = getDownloadUrl(index);
        if (!validateURL(downloadURL)) {
            return;
        }

        //QString targetFolder = QDir::toNativeSeparators(QApplication::applicationDirPath() + "/data/downloads");
        //QString targetName   = "test.zip";

        /**
         * Download Request
         */

        // setup Proxy
        // use system proxy (by default) "--use-proxy=on"
        //QNetworkProxyFactory::setUseSystemConfiguration(true);

        // setup Network Request
        QNetworkRequest request(downloadURL);

        // setup download folder
        QString downloadFolder(QCoreApplication::applicationDirPath()+QDir::separator()+"downloads");
        if (!QDir(downloadFolder).exists()) {
            QDir(downloadFolder).mkpath(".");
        }
        downloadManager.setDownloadFolder(downloadFolder);
        downloadManager.setDownloadMode(Downloader::DownloadItem::DownloadMode::SkipIfExists);

        // enqueue download request
        downloadManager.get(request);

        // setup progressbar
        Downloader::TransferItem *transfer = downloadManager.findTransfer(downloadURL);
        ProgressBarUpdater *progressBar = new ProgressBarUpdater(this, index.row());        
        connect(transfer, SIGNAL(downloadProgress(QMap<QString, QVariant>)),
                progressBar, SLOT(updateProgress(QMap<QString, QVariant>)));
        connect(transfer, SIGNAL(transferFinished(Downloader::TransferItem *t)),
                progressBar, SLOT(downloadFinished(Downloader::TransferItem *t)));

        // finally: invoke downloading
        QMetaObject::invokeMethod(&downloadManager, "checkForAllDone", Qt::QueuedConnection);
    }
Ejemplo n.º 27
0
void FvUpdater::startDownloadFeed(QUrl url)
{
	m_xml.clear();

	// Check SSL Fingerprint if required
	if(url.scheme()=="https" && !m_requiredSslFingerprint.isEmpty())
		if( !checkSslFingerPrint(url) )	// check failed
		{	
			qWarning() << "Update aborted.";
			return;
		}


	m_reply = m_qnam.get(QNetworkRequest(url));

	connect(m_reply, SIGNAL(readyRead()), this, SLOT(httpFeedReadyRead()));
	connect(m_reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(httpFeedUpdateDataReadProgress(qint64, qint64)));
	connect(m_reply, SIGNAL(finished()), this, SLOT(httpFeedDownloadFinished()));
}
void QGitHubReleaseAPIPrivate::downloaded(const FileDownloader &fd) {

	QObject::connect(m_apiDownloader, SIGNAL(error(QString)), this, SLOT(fdError(QString)));
	QObject::connect(m_apiDownloader, SIGNAL(downloaded(FileDownloader)),
					 this, SLOT(downloaded(FileDownloader)));
	QObject::connect(m_apiDownloader, SIGNAL(progress(qint64,qint64)),
					 this, SLOT(downloadProgress(qint64,qint64)));

	m_jsonData = fd.downloadedData();

	foreach(const FileDownloader::RAWHEADERPAIR &pair, fd.rawHeaderPairs()) {

		if(pair.first == "ETag") m_eTag = pair.second.mid(2);

		if(pair.first == "X-RateLimit-Reset") {
			m_rateLimitReset = QDateTime::fromTime_t(QString(pair.second).toUInt());
		}

		if(pair.first == "X-RateLimit-Limit") m_rateLimit = QString(pair.second).toUInt();

		if(pair.first == "X-RateLimit-Remaining") {
			m_rateLimitRemaining = QString(pair.second).toUInt();
		}
	}

	QVariant va(parseJSon(m_jsonData, m_errorString));

	if(m_errorString.isNull()) {

		if(m_singleEntryRequested) {
			m_vdata.append(va);
		} else if((m_vdata = va.toList()).isEmpty()) {
			m_errorString = va.toMap()["message"].toString();
			emit error(m_errorString);
			return;
		}

		emit available();

	} else {
		emit error(m_errorString);
	}
}
Ejemplo n.º 29
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.º 30
0
void UINetworkRequest::prepareNetworkReply()
{
    /* Create network-reply: */
    m_pReply = new UINetworkReply(m_type, m_url, m_requestHeaders);
    AssertPtrReturnVoid(m_pReply.data());
    {
        /* Prepare network-reply: */
        connect(m_pReply, SIGNAL(downloadProgress(qint64, qint64)),
                this, SLOT(sltHandleNetworkReplyProgress(qint64, qint64)));
        connect(m_pReply, SIGNAL(finished()), this, SLOT(sltHandleNetworkReplyFinish()));

        /* Mark network-reply as running: */
        m_fRunning = true;

        /* Notify common network-request listeners: */
        emit sigStarted(m_uuid);
        /* Notify own network-request listeners: */
        emit sigStarted();
    }
}