# HG changeset patch # User Chris Cannam # Date 1168001991 0 # Node ID d82e332cb178e6bed37eb840994e34617be3f887 # Parent 911c0bd745cdeb6c0c6365e23a299e03199e8ab8 * Fix #1491849 strange behaviour on Cancel during query on new file load diff -r 911c0bd745cd -r d82e332cb178 main/MainWindow.cpp --- a/main/MainWindow.cpp Fri Jan 05 12:37:14 2007 +0000 +++ b/main/MainWindow.cpp Fri Jan 05 12:59:51 2007 +0000 @@ -2050,7 +2050,7 @@ QString path = getOpenFileName(AudioFile); if (path != "") { - if (!openAudioFile(path, ReplaceMainModel)) { + if (openAudioFile(path, ReplaceMainModel) == FileOpenFailed) { QMessageBox::critical(this, tr("Failed to open file"), tr("Audio file \"%1\" could not be opened").arg(path)); } @@ -2063,7 +2063,7 @@ QString path = getOpenFileName(AudioFile); if (path != "") { - if (!openAudioFile(path, CreateAdditionalModel)) { + if (openAudioFile(path, CreateAdditionalModel) == FileOpenFailed) { QMessageBox::critical(this, tr("Failed to open file"), tr("Audio file \"%1\" could not be opened").arg(path)); } @@ -2198,7 +2198,7 @@ if (path != "") { - if (!openLayerFile(path)) { + if (openLayerFile(path) == FileOpenFailed) { QMessageBox::critical(this, tr("Failed to open file"), tr("File %1 could not be opened.").arg(path)); return; @@ -2206,7 +2206,7 @@ } } -bool +MainWindow::FileOpenStatus MainWindow::openLayerFile(QString path) { Pane *pane = m_paneStack->getCurrentPane(); @@ -2214,13 +2214,13 @@ if (!pane) { // shouldn't happen, as the menu action should have been disabled std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl; - return false; + return FileOpenFailed; } if (!getMainModel()) { // shouldn't happen, as the menu action should have been disabled std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl; - return false; + return FileOpenFailed; } if (path.endsWith(".svl") || path.endsWith(".xml")) { @@ -2232,7 +2232,7 @@ std::cerr << "ERROR: MainWindow::openLayerFile(" << path.toStdString() << "): Failed to open file for reading" << std::endl; - return false; + return FileOpenFailed; } SVFileReader reader(m_document, callback); @@ -2246,12 +2246,12 @@ << path.toStdString() << "): Failed to read XML file: " << reader.getErrorString().toStdString() << std::endl; - return false; + return FileOpenFailed; } m_recentFiles.addFile(path); registerLastOpenedFilePath(LayerFile, path); // for file dialog - return true; + return FileOpenSucceeded; } else { @@ -2262,12 +2262,12 @@ if (newLayer) { m_document->addLayerToView(pane, newLayer); m_recentFiles.addFile(path); - return true; + return FileOpenSucceeded; } } } - return false; + return FileOpenFailed; } void @@ -2331,13 +2331,13 @@ } } -bool +MainWindow::FileOpenStatus MainWindow::openAudioFile(QString path, AudioFileOpenMode mode) { if (!(QFileInfo(path).exists() && QFileInfo(path).isFile() && QFileInfo(path).isReadable())) { - return false; + return FileOpenFailed; } m_openingAudioFile = true; @@ -2347,7 +2347,7 @@ if (!newModel->isOK()) { delete newModel; m_openingAudioFile = false; - return false; + return FileOpenFailed; } bool setAsMain = true; @@ -2370,7 +2370,7 @@ if (!ok || item.isEmpty()) { delete newModel; m_openingAudioFile = false; - return false; + return FileOpenCancelled; } setAsMain = (item == items[0]); @@ -2443,7 +2443,7 @@ registerLastOpenedFilePath(AudioFile, path); // for file dialog m_openingAudioFile = false; - return true; + return FileOpenSucceeded; } void @@ -2582,7 +2582,7 @@ if (path.isEmpty()) return; - if (!openSessionFile(path)) { + if (openSessionFile(path) == FileOpenFailed) { QMessageBox::critical(this, tr("Failed to open file"), tr("Session file \"%1\" could not be opened").arg(path)); } @@ -2607,16 +2607,16 @@ if (!checkSaveModified()) return; - if (!openSessionFile(path)) { + if (openSessionFile(path) == FileOpenFailed) { QMessageBox::critical(this, tr("Failed to open file"), tr("Session file \"%1\" could not be opened").arg(path)); } } else { - if (!openAudioFile(path, AskUser)) { - - if (!canImportLayer || !openLayerFile(path)) { + if (openAudioFile(path, AskUser) == FileOpenFailed) { + + if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) { QMessageBox::critical(this, tr("Failed to open file"), tr("File \"%1\" could not be opened").arg(path)); @@ -2644,20 +2644,20 @@ if (!checkSaveModified()) return ; - if (!openSessionFile(path)) { + if (openSessionFile(path) == FileOpenFailed) { QMessageBox::critical(this, tr("Failed to open file"), tr("Session file \"%1\" could not be opened").arg(path)); } } else { - if (!openAudioFile(path, AskUser)) { + if (openAudioFile(path, AskUser) == FileOpenFailed) { bool canImportLayer = (getMainModel() != 0 && m_paneStack != 0 && m_paneStack->getCurrentPane() != 0); - if (!canImportLayer || !openLayerFile(path)) { + if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) { QMessageBox::critical(this, tr("Failed to open file"), tr("File \"%1\" could not be opened").arg(path)); @@ -2666,26 +2666,28 @@ } } -bool +MainWindow::FileOpenStatus MainWindow::openSomeFile(QString path, AudioFileOpenMode mode) { - if (openAudioFile(path, mode)) { - return true; - } else if (openSessionFile(path)) { - return true; + FileOpenStatus status; + + if ((status = openAudioFile(path, mode)) != FileOpenFailed) { + return status; + } else if ((status = openSessionFile(path)) != FileOpenFailed) { + return status; } else { - return false; + return FileOpenFailed; } } -bool +MainWindow::FileOpenStatus MainWindow::openSessionFile(QString path) { BZipFileDevice bzFile(path); if (!bzFile.open(QIODevice::ReadOnly)) { std::cerr << "Failed to open session file \"" << path.toStdString() << "\": " << bzFile.errorString().toStdString() << std::endl; - return false; + return FileOpenFailed; } QString error; @@ -2722,7 +2724,7 @@ setWindowTitle(tr("Sonic Visualiser")); } - return ok; + return ok ? FileOpenSucceeded : FileOpenFailed; } void @@ -3731,7 +3733,7 @@ if (message.getArgCount() == 1 && message.getArg(0).canConvert(QVariant::String)) { QString path = message.getArg(0).toString(); - if (!openSomeFile(path, ReplaceMainModel)) { + if (openSomeFile(path, ReplaceMainModel) != FileOpenSucceeded) { std::cerr << "MainWindow::handleOSCMessage: File open failed for path \"" << path.toStdString() << "\"" << std::endl; } @@ -3744,7 +3746,7 @@ if (message.getArgCount() == 1 && message.getArg(0).canConvert(QVariant::String)) { QString path = message.getArg(0).toString(); - if (!openSomeFile(path, CreateAdditionalModel)) { + if (openSomeFile(path, CreateAdditionalModel) != FileOpenSucceeded) { std::cerr << "MainWindow::handleOSCMessage: File open failed for path \"" << path.toStdString() << "\"" << std::endl; } @@ -3761,7 +3763,7 @@ } std::vector recent = m_recentFiles.getRecent(); if (n >= 0 && n < recent.size()) { - if (!openSomeFile(recent[n], ReplaceMainModel)) { + if (openSomeFile(recent[n], ReplaceMainModel) != FileOpenSucceeded) { std::cerr << "MainWindow::handleOSCMessage: File open failed for path \"" << recent[n].toStdString() << "\"" << std::endl; } diff -r 911c0bd745cd -r d82e332cb178 main/MainWindow.h --- a/main/MainWindow.h Fri Jan 05 12:37:14 2007 +0000 +++ b/main/MainWindow.h Fri Jan 05 12:59:51 2007 +0000 @@ -67,10 +67,17 @@ AskUser }; - bool openSomeFile(QString path, AudioFileOpenMode = AskUser); - bool openAudioFile(QString path, AudioFileOpenMode = AskUser); - bool openLayerFile(QString path); - bool openSessionFile(QString path); + enum FileOpenStatus { + FileOpenSucceeded, + FileOpenFailed, + FileOpenCancelled + }; + + FileOpenStatus openSomeFile(QString path, AudioFileOpenMode = AskUser); + FileOpenStatus openAudioFile(QString path, AudioFileOpenMode = AskUser); + FileOpenStatus openLayerFile(QString path); + FileOpenStatus openSessionFile(QString path); + bool saveSessionFile(QString path); bool commitData(bool mayAskUser); // on session shutdown diff -r 911c0bd745cd -r d82e332cb178 main/main.cpp --- a/main/main.cpp Fri Jan 05 12:37:14 2007 +0000 +++ b/main/main.cpp Fri Jan 05 12:59:51 2007 +0000 @@ -150,7 +150,7 @@ for (QStringList::iterator i = args.begin(); i != args.end(); ++i) { - bool success = false; + MainWindow::FileOpenStatus status = MainWindow::FileOpenSucceeded; if (i == args.begin()) continue; if (i->startsWith('-')) continue; @@ -159,25 +159,25 @@ if (path.endsWith("sv")) { if (!haveSession) { - success = gui.openSessionFile(path); - if (success) { + status = gui.openSessionFile(path); + if (status == MainWindow::FileOpenSucceeded) { haveSession = true; haveMainModel = true; } } else { std::cerr << "WARNING: Ignoring additional session file argument \"" << path.toStdString() << "\"" << std::endl; - success = true; + status = MainWindow::FileOpenSucceeded; } } - if (!success) { + if (status != MainWindow::FileOpenSucceeded) { if (!haveMainModel) { - success = gui.openSomeFile(path, MainWindow::ReplaceMainModel); - if (success) haveMainModel = true; + status = gui.openSomeFile(path, MainWindow::ReplaceMainModel); + if (status == MainWindow::FileOpenSucceeded) haveMainModel = true; } else { - success = gui.openSomeFile(path, MainWindow::CreateAdditionalModel); + status = gui.openSomeFile(path, MainWindow::CreateAdditionalModel); } } - if (!success) { + if (status == MainWindow::FileOpenFailed) { QMessageBox::critical (&gui, QMessageBox::tr("Failed to open file"), QMessageBox::tr("File \"%1\" could not be opened").arg(path));