Ejemplo n.º 1
0
void FileDownloaderHandler::startNewDownload()
{
    if(m_outstandingDownloads < 1 && !m_fileDownloaderQueue.isEmpty())
    {
        QThread* thread = new QThread();
        FileDownloader* fd = new FileDownloader();

        fd->moveToThread(thread);
        thread->start();

        connect(this,
                SIGNAL(startDownload(QString,QString,QString)),
                fd,
                SLOT(downloadFile(QString,QString,QString)));

        connect(fd,
                SIGNAL(fileSaved(QString, QString)),
                this,
                SLOT(downloadComplete(QString, QString)));

        connect(fd,
                SIGNAL(fileSaved(QString, QString)),
                thread,
                SLOT(quit()));

        connect(thread,
                &QThread::finished,
                thread,
                &QThread::deleteLater);

        FileInfoStruct fis = m_fileDownloaderQueue.dequeue();
//        QString currentBaseUrl = fis.currentBaseUrl;
//        QString fileName = fis.fileName;
//        QString savePath = fis.savePath;
        qDebug() << fis.fileName;

        emit startDownload(fis.currentBaseUrl, fis.fileName, fis.savePath);
        m_outstandingDownloads++;
    }
}