void DownloadManager::abort() {
    qDebug() << "abort()";
    if (_pReply == NULL)
    {
        return;
    }
    _Timer.stop();
    disconnect(&_Timer, SIGNAL(timeout()), this, SLOT(timeout()));
    disconnect(_pReply, SIGNAL(finished()), this, SLOT(finished()));
    disconnect(_pReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
    disconnect(_pReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError)));

    _pReply->abort();
    _pFile->flush();
    _pFile->remove();
    _pReply = 0;
    _nDownloadSizeAtPause = 0;
    _nDownloadSize = 0;

    emit downloadCanceled();

    setDownloading(false);
}
Beispiel #2
0
void QgsFileDownloader::onDownloadCanceled()
{
  mDownloadCanceled = true;
  emit downloadCanceled();
  onFinished();
}
void SettingsDictionariesMenu::activateExtraDicts()
{
    qDebug() << Q_FUNC_INFO;
    bqDeviceServices* services = QBookApp::instance()->getDeviceServices();
    services->processSyncCanceled();
    b_downloadCanceled = false;

    if(!downloadDialog)
    {
        downloadDialog = new ProgressDialog(this,tr("Downloading dictionary, please wait for a few minutes."));
        downloadDialog->setHideBtn(false);
        downloadDialog->setTextValue(false);
        downloadDialog->setModal(true);
        connect(downloadDialog, SIGNAL(cancel()),               this,          SLOT(downloadCanceled()), Qt::UniqueConnection);
        connect(services,       SIGNAL(downloadProgress(int)), downloadDialog, SLOT(setProgressBar(int)), Qt::UniqueConnection);
    }

    downloadDialog->setProgressBar(0);
    bool installingPending = false;
    newDictionaryNames.clear();

    QList<DictionaryParams>::const_iterator it = pendingDictsList.constBegin();
    QList<DictionaryParams>::const_iterator itEnd = pendingDictsList.constEnd();
    while(it != itEnd)
    {
        Screen::getInstance()->setMode(Screen::MODE_SAFE,true,FLAG_FULLSCREEN_UPDATE,Q_FUNC_INFO);
        downloadDialog->show();

        if(!(*it).activationState)
        {
            int dixioSize = (*it).dixFileSize * 1024 * 1024;
            int downloadComplementSize = (*it).compFileSize * 1024 * 1024;

            QString downloadPath = Storage::getInstance()->getPrivatePartition()->getMountPoint() + QDir::separator() + "dictionaries" + QDir::separator();
            newDictionaryNames.append(downloadPath + QString((*it).downloadFileName));
            bool downloaded = services->downloadDictionary((*it).downloadUrl, downloadPath + QString((*it).downloadFileName),dixioSize);

            if(downloaded)
            {
                installingPending = true;
                if((*it).downloadUrlComp.size())
                {
                    qDebug() << Q_FUNC_INFO << "downloadUrlComp: " << (*it).downloadUrlComp;
                    downloadDialog->setText(tr("Downloading complements, please wait for a few minutes."));
                    Screen::getInstance()->refreshScreen();
                    newDictionaryNames.append(downloadPath + QString((*it).downloadFileNameComp));
                    if(!services->downloadDictionary((*it).downloadUrlComp, downloadPath + QString((*it).downloadFileNameComp), downloadComplementSize))
                    {
                        downloaded = false;
                        installingPending = false;
                    }
                }
            }

            if(!downloaded && !b_downloadCanceled)
            {
                delete downloadDialog;
                downloadDialog = NULL;
                deleteDictionaryFiles(newDictionaryNames);
                ConfirmDialog* confirmDialog = new ConfirmDialog(this,tr("Download failed. Please try again."));
                Screen::getInstance()->resetQueue();
                Screen::getInstance()->setMode(Screen::MODE_SAFE,true,FLAG_FULLSCREEN_UPDATE|FLAG_IGNORE_QUEUE,Q_FUNC_INFO);
                confirmDialog->exec();
                delete confirmDialog;
                Screen::getInstance()->refreshScreen();
                return;
            }
        }
        it++;
    }

    if(installingPending) {
        downloadDialog->setText(tr("Installing..."));
        downloadDialog->hideCancelButton();
        Screen::getInstance()->refreshScreen();
    } else {
        if(downloadDialog) {
            delete downloadDialog;
            downloadDialog = NULL;
        }
        return;
    }

    QString dixioKey = Dictionary::instance()->getDixioKey();
    qDebug() << Q_FUNC_INFO << "dixioKey: " << dixioKey;
    QString callUrl;
    QString postParameters;
    QString activationResponse;
    bool installingError = false;

    // Get activation data
    if(Dictionary::instance()->getActivation(dixioKey, callUrl, postParameters))
    {
        QString activationRequest = postParameters.split("activationRequest=")[1];
        if(services->callActivationDictionary(activationResponse, activationRequest))
        {
            qDebug() << Q_FUNC_INFO << "activationResponse: " << activationResponse;
            QString activation = QString::fromStdString(Dictionary::instance()->setActivation(dixioKey, activationResponse));
            qDebug() << Q_FUNC_INFO << "activation: " << activation;
            installingError = activation.contains("error");
        } else
            installingError = true;
    } else
        installingError = true;

    delete downloadDialog;
    downloadDialog = NULL;
    ConfirmDialog* confirmDialog;
    if(!installingError)
    {
        confirmDialog = new ConfirmDialog(this,tr("Installing success. Now the system will be turned off."));
        Screen::getInstance()->setMode(Screen::MODE_SAFE,true,FLAG_FULLSCREEN_UPDATE,Q_FUNC_INFO);
        confirmDialog->exec();
        delete confirmDialog;
        QBook::settings().setValue("setting/dictionaryAvailable", false);
        QBook::settings().sync();
        Screen::getInstance()->refreshScreen(Screen::MODE_SAFE,true);
        PowerManager::powerOffDevice(false);
    } else
    {
        deleteDictionaryFiles(newDictionaryNames);
        confirmDialog = new ConfirmDialog(this,tr("Install failed. Please try again."));
        Screen::getInstance()->setMode(Screen::MODE_SAFE,true,FLAG_FULLSCREEN_UPDATE,Q_FUNC_INFO);
        confirmDialog->exec();
        delete confirmDialog;
        Screen::getInstance()->refreshScreen();
    }
}