Example #1
0
bool LoadSetsPage::validatePage()
{
    // once the import is finished, we call next(); skip validation
    if (wizard()->importer->getSets().count() > 0)
    {
        return true;
    }

    // else, try to import sets
    if (urlRadioButton->isChecked())
    {
        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);

        downloadSetsFile(url);
    }
    else if (fileRadioButton->isChecked())
    {
        QFile setsFile(fileLineEdit->text());
        if (!setsFile.exists())
        {
            QMessageBox::critical(this, tr("Error"), tr("Please choose a file."));
            return false;
        }

        if (!setsFile.open(QIODevice::ReadOnly))
        {
            QMessageBox::critical(nullptr, tr("Error"), tr("Cannot open file '%1'.").arg(fileLineEdit->text()));
            return false;
        }

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

        readSetsFromByteArray(setsFile.readAll());

    }

    return false;
}
Example #2
0
void LoadSetsPage::actDownloadFinishedSetsFile()
{
    // 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();
        downloadSetsFile(redirectUrl);
        reply->deleteLater();
        return;
    }

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

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

    readSetsFromByteArray(reply->readAll());
    reply->deleteLater();
}
Example #3
0
WindowMain::WindowMain(QWidget *parent)
	: QMainWindow(parent)
{
	importer = new OracleImporter(QDesktopServices::storageLocation(QDesktopServices::DataLocation), this);
	nam = new QNetworkAccessManager(this);
	
	checkBoxLayout = new QVBoxLayout;
	
	QWidget *checkboxFrame = new QWidget;
	checkboxFrame->setLayout(checkBoxLayout);
	
	QScrollArea *checkboxArea = new QScrollArea;
	checkboxArea->setWidget(checkboxFrame);
	checkboxArea->setWidgetResizable(true);
	
	checkAllButton = new QPushButton(tr("&Check all"));
	connect(checkAllButton, SIGNAL(clicked()), this, SLOT(actCheckAll()));
	uncheckAllButton = new QPushButton(tr("&Uncheck all"));
	connect(uncheckAllButton, SIGNAL(clicked()), this, SLOT(actUncheckAll()));
	
	QHBoxLayout *checkAllButtonLayout = new QHBoxLayout;
	checkAllButtonLayout->addWidget(checkAllButton);
	checkAllButtonLayout->addWidget(uncheckAllButton);
	
	startButton = new QPushButton(tr("&Start download"));
	connect(startButton, SIGNAL(clicked()), this, SLOT(actStart()));
	
	QVBoxLayout *settingsLayout = new QVBoxLayout;
	settingsLayout->addWidget(checkboxArea);
	settingsLayout->addLayout(checkAllButtonLayout);
	settingsLayout->addWidget(startButton);
	
	totalLabel = new QLabel(tr("Total progress:"));
	totalProgressBar = new QProgressBar;
	nextSetLabel1 = new QLabel(tr("Current file:"));
	nextSetLabel2 = new QLabel;
	fileLabel = new QLabel(tr("Progress:"));
	fileProgressBar = new QProgressBar;
	
	messageLog = new QTextEdit;
	messageLog->setReadOnly(true);
	
	QGridLayout *grid = new QGridLayout;
	grid->addWidget(totalLabel, 0, 0);
	grid->addWidget(totalProgressBar, 0, 1);
	grid->addWidget(nextSetLabel1, 1, 0);
	grid->addWidget(nextSetLabel2, 1, 1);
	grid->addWidget(fileLabel, 2, 0);
	grid->addWidget(fileProgressBar, 2, 1);
	grid->addWidget(messageLog, 3, 0, 1, 2);
	
	QHBoxLayout *mainLayout = new QHBoxLayout;
	mainLayout->addLayout(settingsLayout, 6);
	mainLayout->addSpacing(10);
	mainLayout->addLayout(grid, 10);
	
	QWidget *centralWidget = new QWidget;
	centralWidget->setLayout(mainLayout);
	setCentralWidget(centralWidget);
	
	connect(importer, SIGNAL(setIndexChanged(int, int, const QString &)), this, SLOT(updateTotalProgress(int, int, const QString &)));
	connect(importer, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateFileProgress(int, int)));
	
	aLoadSetsFile = new QAction(tr("Load sets information from &file..."), this);
	connect(aLoadSetsFile, SIGNAL(triggered()), this, SLOT(actLoadSetsFile()));
	aDownloadSetsFile = new QAction(tr("&Download sets information..."), this);
	connect(aDownloadSetsFile, SIGNAL(triggered()), this, SLOT(actDownloadSetsFile()));
	aExit = new QAction(tr("E&xit"), this);
	connect(aExit, SIGNAL(triggered()), this, SLOT(close()));
	
	fileMenu = menuBar()->addMenu(tr("&File"));
	fileMenu->addAction(aLoadSetsFile);
	fileMenu->addAction(aDownloadSetsFile);
	fileMenu->addSeparator();
	fileMenu->addAction(aExit);
	
	setWindowTitle(tr("Oracle importer"));
	setMinimumSize(750, 500);

	QStringList args = qApp->arguments();
	if (args.contains("-dlsets"))
		downloadSetsFile(defaultSetsUrl);
	
	statusLabel = new QLabel;
	statusBar()->addWidget(statusLabel);
	statusLabel->setText(tr("Sets data not loaded."));
}
Example #4
0
void WindowMain::actDownloadSetsFile()
{
	QString url = QInputDialog::getText(this, tr("Load sets from URL"), tr("Please enter the URL of the sets file:"), QLineEdit::Normal, defaultSetsUrl);
	if (!url.isEmpty())
		downloadSetsFile(url);
}