| 333 | } |
| 334 | |
| 335 | void MainWindow::handleLoadAction() |
| 336 | { |
| 337 | QString fileName = QFileDialog::getOpenFileName(nullptr, "Open project", QDir::homePath(), "CANdevStudio (*.cds)"); |
| 338 | |
| 339 | if (fileName.isEmpty()) { |
| 340 | cds_debug("Load action cancelled by the user"); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | QFile file(fileName); |
| 345 | |
| 346 | if (!file.open(QIODevice::ReadOnly)) { |
| 347 | cds_error("Could not open file"); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | QByteArray wholeFile = file.readAll(); |
| 352 | |
| 353 | // TODO nodeeditor is not validating data. Improve schema file (using required fields) to be safe. |
| 354 | if (!ProjectConfigValidator::validateConfiguration(wholeFile)) { |
| 355 | QMessageBox::warning(nullptr, "File corrupted", "Invalid file. Project loading aborted"); |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | QFileInfo fInfo(fileName); |
| 360 | |
| 361 | if (createProjectConfig(fInfo.completeBaseName())) { |
| 362 | if (_projectConfig) { |
| 363 | _projectConfig->load(wholeFile); // FIXME |
| 364 | _projectFile = fileName; |
| 365 | |
| 366 | addRecentProject(_projectName, _projectFile); |
| 367 | } else { |
| 368 | cds_error("Project config does not exist"); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | refreshRecentProjects(); |
| 373 | } |
| 374 | |
| 375 | void MainWindow::handleAboutAction() |
| 376 | { |