Example #1
0
CustomDownload::CustomDownload(QNetworkReply *reply,
                               QNetworkRequest request,
                               qint64 dnsLookupTime,
                               qint64 requestStartTime)
{

    this->isWaiting = true;
    this->requestStartTime = requestStartTime;
    this->waitingTime =  QDateTime::currentDateTime().toMSecsSinceEpoch();
    this->dnsLookupTime = dnsLookupTime;
    this->request = request;
    this->reply = reply;

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

    connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
                 this, SLOT(onDownloadProgress(qint64, qint64)));

    connect(reply, SIGNAL(metaDataChanged()),
                 this, SLOT(onMetaDataChanged()));

    /*
    connect(reply, SIGNAL(uploadProgress(qint64, qint64)),
                 this, SLOT(onUploadProgress(qint64, qint64)));
    */
}
Example #2
0
void
DownloadJob::onUrlRetrieved( const QVariantMap& data )
{
    tDebug() << Q_FUNC_INFO << data;
    QUrl localFile = prepareFilename();
    if ( m_file )
    {
        tLog() << "Recovering from failed download for track:" << toString() << "-" << m_retries << "retries so far.";
        m_finished = false;
        delete m_file;
        m_file = 0;
    }

    tLog() << "Saving download" << m_format.url << "to file:" << localFile << localFile.toLocalFile();

    m_file = new QFile( localFile.toString() );
    m_localFile = localFile.toString();

    if ( m_tryResuming && checkForResumedFile() )
        return;

    m_reply = Tomahawk::Utils::nam()->get( QNetworkRequest( data[ "url" ].toString() ) );

    connect( m_reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( onDownloadError( QNetworkReply::NetworkError ) ) );
    connect( m_reply, SIGNAL( downloadProgress( qint64, qint64 ) ), SLOT( onDownloadProgress( qint64, qint64 ) ) );
    connect( m_reply, SIGNAL( finished() ), SLOT( onDownloadNetworkFinished() ) );

    setState( Running );
}
Example #3
0
void CFileDownload::download(const QString& strUrl, const QString& strFolder, bool bOverWrite, bool bAutoRemoveFile)
{
    m_strFolder = strFolder;
    m_strUrl = strUrl;
    m_bOverWrite = bOverWrite;
    m_bAutoRemoveFile = bAutoRemoveFile;

    QUrl url;
    url.setEncodedUrl(m_strUrl.toAscii());
    if (!url.isValid())
    {
        emit finishedDownloadAttachmentItem(m_pAttachmentItem, tr("Error: Bad file URL"));
        return;
    }

    if(m_pAttachmentItem)
        m_pAttachmentItem->setProcessState(STATE_PS_UPLOADING);

    QNetworkRequest request(url);
    request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)");
 //   request.setRawHeader("User-Agent", "Wget");
 //   request.setRawHeader("Accept", "*/*");
  //  request.setRawHeader("Connection", "Keep-Alive");
//    request.setRawHeader("Keep-Alive", "300");

    m_pNetworkReply = m_pNetworkMgr->get(request);
    connect(m_pNetworkReply, SIGNAL(metaDataChanged()), this, SLOT(onMetaDataChanged()));
    connect(m_pNetworkReply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(m_pNetworkReply, SIGNAL(uploadProgress(qint64, qint64)), this, SIGNAL(uploadProgress(qint64, qint64)));
    connect(m_pNetworkReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64,qint64)));

    connect(m_pNetworkReply, SIGNAL(finished()), this, SLOT(onFinished()));
}
Example #4
0
QgsOSMDownloadDialog::QgsOSMDownloadDialog( QWidget* parent )
    : QDialog( parent )
    , mDownload( new QgsOSMDownload )
{
  setupUi( this );

  editXMin->setValidator( new QDoubleValidator( -180.0, 180.0, 6, this ) );
  editXMax->setValidator( new QDoubleValidator( -180.0, 180.0, 6, this ) );
  editYMin->setValidator( new QDoubleValidator( -90.0, 90.0, 6, this ) );
  editYMax->setValidator( new QDoubleValidator( -90.0, 90.0, 6, this ) );

  populateLayers();
  onExtentCanvas();

  connect( radExtentCanvas, SIGNAL( clicked() ), this, SLOT( onExtentCanvas() ) );
  connect( radExtentLayer, SIGNAL( clicked() ), this, SLOT( onExtentLayer() ) );
  connect( radExtentManual, SIGNAL( clicked() ), this, SLOT( onExtentManual() ) );
  connect( cboLayers, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onCurrentLayerChanged( int ) ) );
  connect( btnBrowse, SIGNAL( clicked() ), this, SLOT( onBrowseClicked() ) );
  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( onOK() ) );
  connect( buttonBox, SIGNAL( rejected() ), this, SLOT( onClose() ) );

  connect( mDownload, SIGNAL( finished() ), this, SLOT( onFinished() ) );
  connect( mDownload, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( onDownloadProgress( qint64, qint64 ) ) );
}
Example #5
0
void
DownloadJob::onDownloadFinished()
{
    tLog() << Q_FUNC_INFO << m_rcvdSize << m_fileSize;
    if ( state() == Paused )
    {
        m_finished = true;
        return;
    }

    if ( ( m_fileSize > 0 && m_rcvdSize < m_fileSize ) || m_rcvdSize == 0 )
    {
        onDownloadError( QNetworkReply::UnknownContentError );
        return;
    }

    disconnect( m_reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( onDownloadError( QNetworkReply::NetworkError ) ) );
    disconnect( m_reply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( onDownloadProgress( qint64, qint64 ) ) );
    disconnect( m_reply, SIGNAL( finished() ), this, SLOT( onDownloadNetworkFinished() ) );
    m_reply->abort();

    if ( m_file && m_file->isOpen() )
    {
        m_file->flush();
        m_file->close();
    }

    delete m_file;
    m_file = 0;

    m_finishedTimestamp = QDateTime::currentDateTimeUtc();
    setState( Finished );
    tLog() << Q_FUNC_INFO << "Finished downloading:" << toString();
    tLog() << Q_FUNC_INFO << m_finished;
}
Example #6
0
NATRON_NAMESPACE_ENTER

FileDownloader::FileDownloader(const QUrl& imageUrl,
                               bool useNetworkCache,
                               QObject *parent)
    : QObject(parent)
    , m_reply(0)
    , m_WebCtrl(new QNetworkAccessManager)
    , m_DownloadedData(new QByteArray)
    , m_timer( new QTimer() )
{
    m_timer->setInterval(NATRON_FILE_DOWNLOAD_HEARBEAT_TIMEOUT_MS);
    QObject::connect( m_timer.get(), SIGNAL(timeout()), this, SLOT(onTimerTimeout()) );

    connect( m_WebCtrl.get(), SIGNAL(finished(QNetworkReply*)),
             SLOT(fileDownloaded(QNetworkReply*)) );

    QNetworkRequest request(imageUrl);
    if (!useNetworkCache) {
        request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
    }

    m_reply = m_WebCtrl->get(request);
    m_timer->start();
    QObject::connect( m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SIGNAL(error()) );
    QObject::connect( m_reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64,qint64)) );
}
void MapDownloadsModel::onDownloadJobsChanged()
{
  beginResetModel();
  for (auto job:mapManager->getDownloadJobs()){
    connect(job, SIGNAL(downloadProgress()), this, SLOT(onDownloadProgress()));
  }
  endResetModel();
}
Example #8
0
void MainWindow::onStart()
{
    if (!task_)
    {
        task_ = new DownloadTask(this);
        connect(task_, SIGNAL(inited()), this, SLOT(onInit()));
        connect(task_, SIGNAL(downloadProgress(qint64, qint64, qint64)), this, SLOT(onDownloadProgress(qint64, qint64, qint64)));
        connect(task_, SIGNAL(finished()), this, SLOT(onFinished()));
        task_->init("", "http://ermaopcassist.qiniudn.com/ErmaoPcAssist2.0.0.2.exe", &mgr_);
    }
    task_->start();
}
void DownloadFragmnet::Download(QString fileURL,int start,int end)
{
    setBoubdaries(start,end);
    QNetworkRequest request;
    request.setUrl(QUrl(fileURL));
    QByteArray rangeHeaderValue = "bytes=" + QByteArray::number(startByte) + "-"+ QByteArray::number(endByte);
    request.setRawHeader("Range",rangeHeaderValue);
    reply = manager->get(request);
    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(onDownloadProgress(qint64,qint64)));
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(onFinished(QNetworkReply*)));
    connect(reply,SIGNAL(readyRead()),this,SLOT(onReadyRead()));
}
Example #10
0
void
DownloadJob::resume()
{
    tLog() << Q_FUNC_INFO << m_finished << m_rcvdSize << m_fileSize;
    if ( !m_reply )
    {
        tLog() << "Initiating paused download from previous session:" << toString();
        download();
        return;
    }

    setState( Running );
//    m_reply->setReadBufferSize( 65536 );

    onDownloadProgress( m_fileSize, m_fileSize );
}
Example #11
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;
}
int QDownloader::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: onDownloadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        case 1: onFinished((*reinterpret_cast< QNetworkReply*(*)>(_a[1]))); break;
        case 2: onReadyRead(); break;
        case 3: onReplyFinished(); break;
        default: ;
        }
        _id -= 4;
    }
    return _id;
}
Example #13
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)));
}
Example #14
0
void DownloadTask::start()
{
	Q_ASSERT(state_ != Unvalid);
	state_ = Start;

	if (name_.isEmpty())
	{
		splitName();
	}
	
	QNetworkRequest request(url_);
	QString range("bytes=%1-");
	range = range.arg(progress_);
	request.setRawHeader("Range", range.toAscii());
	QNetworkReply *reply = networkMgr_->get(request);
	connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(onDownloadProgress(qint64, qint64)));
	connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
	connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError)));
	speedTest_.lastMSecsSinceEpoch_ = QDateTime::currentMSecsSinceEpoch();
}
Example #15
0
void QDownloader::setFile(QString fileURL)
{
    QString filePath = fileURL;
    QString saveFilePath;
    QStringList filePathList = filePath.split('/');
    //QString fileName = filePathList.at(filePathList.count() - 1);
    saveFilePath = QString( imagePath + fileName );

    QNetworkRequest request;
    request.setUrl(QUrl(fileURL));
    reply = manager->get(request);

    file = new QFile;
    file->setFileName(saveFilePath);
    file->open(QIODevice::WriteOnly);

    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(onDownloadProgress(qint64,qint64)));
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(onFinished(QNetworkReply*)));
    connect(reply,SIGNAL(readyRead()),this,SLOT(onReadyRead()));
    connect(reply,SIGNAL(finished()),this,SLOT(onReplyFinished()));
}
Example #16
0
/*!
  Constructor.
*/
IAPurchase::IAPurchase(QObject *parent) :
    QObject(parent),
    m_iapClient(0),
    m_downloadMgr(0),
    m_buyProductRequestId(0),
    m_invalidProductPurchaseRequestId(0),
    m_iapReady(false)
{
    // Register new metatypes so that these can be queued in the signal
    qRegisterMetaType<Request::RequestType>("Request::RequestType");

    // Construct the download manager and connect its signals.
    m_downloadMgr = new DownloadManager(this);
    connect(m_downloadMgr, SIGNAL(downloadCompleted(Request::RequestType, QString, QString, int)),
            this, SLOT(downloadCompleted(Request::RequestType, QString, QString, int)));
    connect(m_downloadMgr, SIGNAL(productIdsCompleted(QList<QObject*>)),
            this, SLOT(productIdsCompleted(QList<QObject*>)));
    connect(m_downloadMgr, SIGNAL(downloadProgress(QString,qint64,qint64)),
            this, SLOT(onDownloadProgress(QString,qint64,qint64)));


    // Delayed creation
    QTimer::singleShot(500, this, SLOT(createIAP()));
}
Example #17
0
void DialogBare::onLinkClicked(const QUrl &url)
{
    QString firmwareFile = QFileInfo(url.toString()).fileName();

    QString filename;

    // If a IO firmware file, open save as DialogBare
    if (firmwareFile.endsWith(".bin") && firmwareFile.contains("px4io")) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
        QString path = QString(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
#else
        QString path = QString(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
#endif
        qDebug() << path;
        filename = QFileDialog::getExistingDirectory(this, tr("Select folder (microSD Card)"),
                                                path);
        filename.append("/" + firmwareFile);
    } else {

        // Make sure the user doesn't screw up flashing
        //QMessageBox msgBox;
        //msgBox.setText("Please unplug your PX4 board now");
        //msgBox.exec();

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
        filename = QString(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
#else
        filename = QString(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
#endif

        if (filename.isEmpty()) {
            qDebug() << "Falling back to temp dir";
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
        QString filename = QString(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
#else
        QString filename = QString(QDesktopServices::storageLocation(QDesktopServices::TempLocation));
#endif
            // If still empty, bail out
            if (filename.isEmpty())
                ui->upgradeLog->appendHtml(tr("FAILED storing firmware to downloads or temp directory. Harddisk not writable."));
                return;
        }

        filename += "/" + firmwareFile;
    }

    if (filename == "") {
        return;
    }

    // Else, flash the firmware
    lastFilename = filename;

    ui->upgradeLog->appendHtml(tr("Downloading firmware file <a href=\"%1\">%1</a>").arg(url.toString()));

    QNetworkRequest newRequest(url);
    newRequest.setUrl(url);
    newRequest.setAttribute(QNetworkRequest::User, filename);

    // XXX rework
    QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); //ui->webView->page()->networkAccessManager();
    QNetworkReply *reply = networkManager->get(newRequest);
    connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(onDownloadProgress(qint64, qint64)));
    connect(reply, SIGNAL(finished()), this, SLOT(onDownloadFinished()));
}
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)));
}