bool PGNImporter::importFromFile(const QString& fileName)
{
    pgn::GameCollection games;

    std::ifstream pgnfile(fileName.toStdString().c_str());

    std::cout << "\"" << fileName.toStdString() << "\"" << std::endl;
    std::cout << "Called: " << pgnfile.is_open() << std::endl;
    emit onProgress(1);


    try
    {
        pgnfile >> games;
    }
    catch(pgn::ParseException& ex)
    {
        std::clog << "Parse error: " << ex.what() << std::endl;

        QMessageBox msg;
        msg.setIcon(QMessageBox::Critical);
        msg.setText(QString("Parse error: \"%1\" - document can not be imported").arg(ex.what()));
        msg.exec();

        return false;
    }

    return import(games);
}
Example #2
0
void MainWindow::slotFileNew()
{
	QString file = QFileDialog::getSaveFileName(this, tr("New database"),
			AppSettings->value("/General/databasePath").toString(),
			tr("PGN database (*.pgn)"));
	if (file.isEmpty())
		return;
	if (!file.endsWith(".pgn"))
		file += ".pgn";
	QFile pgnfile(file);
	if (!pgnfile.open(QIODevice::WriteOnly))
		MessageDialog::warning(tr("Cannot create ChessX database."), tr("New database"));
	else {
		pgnfile.close();
		openDatabase(file);
		AppSettings->setValue("/General/databasePath",
				QFileInfo(file).absolutePath());
	}
}