void QQmlNetwork::startNextDownload()
{
    if (downloadQueue.isEmpty()) {
//        qDebug() << downloadedCount << " " << totalCount << "files downloaded successfully\n";
        emit finished();
        return;
    }
    QUrl url = downloadQueue.dequeue();
    QFileInfo fileInf(url.toString());
    QString fileName = QString("%1%2").arg(m_path).arg(fileInf.fileName());




    setSavedFileName(fileName);
//    qDebug() << fileName;
    output.setFileName(fileName);

    if (output.exists()){
        if(output.remove())
        {
            qDebug() << "removed the old file";
        }
    }



    if (!output.open(QIODevice::WriteOnly)) {
        error("Problem opening save file for download");
        startNextDownload();
        return;
    }

    qDebug() << "GOING TO TRY AND DOWNLOAD " << url;

    QNetworkRequest request(url);
    currentDownload = manager.get(request);

    // FIX ME check for redirection
    connect(&manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(checkRedirection(QNetworkReply*)));

    connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)), SLOT(downloadProgress(qint64,qint64)));
    connect(currentDownload, SIGNAL(finished()), SLOT(downloadFinished()));
    connect(currentDownload, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
    connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(setNetworkError(QNetworkReply::NetworkError)));


    downloadTime.start();

}
Ejemplo n.º 2
0
/*!
 * \qmlsignal Downloader::startNextDownload()
 * Used if you want to download multiple files
 */
void Downloader::startNextDownload()
{
    if (downloadQueue.isEmpty()) {
        qDebug() << downloadedCount << " " << totalCount << "files downloaded successfully\n";
        emit started(false);
        emit finished();
        return;
    }

    QUrl url = downloadQueue.dequeue();
    QFileInfo fileInf(url.toString());
    QString fileName = QString("%1%2").arg(mPath).arg("UbuntuCodeofConduct.txt");


//    QString filename = saveFileName(fileName);

    setSavedFileName(fileName);



    qDebug() << fileName;

    output.setFileName(fileName);
    if (!output.open(QIODevice::WriteOnly)) {
        qDebug() <<  "Problem opening save file for download";
        startNextDownload();
        return;
    }

    QNetworkRequest request(url);
    currentDownload = manager.get(request);
    connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
            SLOT(downloadProgress(qint64,qint64)));
    connect(currentDownload, SIGNAL(finished()),
            SLOT(downloadFinished()));
    connect(currentDownload, SIGNAL(readyRead()),
            SLOT(downloadReadyRead()));

    // prepare the output
    qDebug () << "Downloading " <<  url.toEncoded() << "........";
    downloadTime.start();
}