Пример #1
0
bool LoadTokensPage::validatePage()
{
    // once the import is finished, we call next(); skip validation
    if(wizard()->hasTokensData())
        return true;

    QUrl url = QUrl::fromUserInput(urlLineEdit->text());
    if(!url.isValid())
    {
        QMessageBox::critical(this, tr("Error"), tr("The provided URL is not valid."));
        return false;
    }

    progressLabel->setText(tr("Downloading (0MB)"));
    // show an infinite progressbar
    progressBar->setMaximum(0);
    progressBar->setMinimum(0);
    progressBar->setValue(0);
    progressLabel->show();
    progressBar->show();

    wizard()->disableButtons();
    setEnabled(false);

    downloadTokensFile(url);
    return false;
}
Пример #2
0
void LoadTokensPage::actDownloadFinishedTokensFile()
{
    // check for a reply
    auto *reply = dynamic_cast<QNetworkReply *>(sender());
    QNetworkReply::NetworkError errorCode = reply->error();
    if (errorCode != QNetworkReply::NoError)
    {
        QMessageBox::critical(this, tr("Error"), tr("Network error: %1.").arg(reply->errorString()));

        wizard()->enableButtons();
        setEnabled(true);

        reply->deleteLater();
        return;
    }

    int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
    if (statusCode == 301 || statusCode == 302)
    {
        QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        qDebug() << "following redirect url:" << redirectUrl.toString();
        downloadTokensFile(redirectUrl);
        reply->deleteLater();
        return;
    }

    progressLabel->hide();
    progressBar->hide();

    // save tokens.xml url, but only if the user customized it and download was successfull
    if (urlLineEdit->text() != QString(TOKENS_URL))
    {
        wizard()->settings->setValue("tokensurl", urlLineEdit->text());
    }
    else
    {
        wizard()->settings->remove("tokensurl");
    }

    wizard()->setTokensData(reply->readAll());
    reply->deleteLater();

    wizard()->enableButtons();
    setEnabled(true);
    progressLabel->hide();
    progressBar->hide();

    wizard()->next();
}