Mercurial > hg > tony
comparison src/MainWindow.cpp @ 313:eef5c50e7e34
Introduce a new canSaveAs which is active whenever there is a main model; avoid silently overwriting existing session file when saving to audio path
author | Chris Cannam |
---|---|
date | Fri, 13 Jun 2014 10:37:04 +0100 |
parents | 111bf81a5c96 |
children | 2a2fd6eb8fa8 |
comparison
equal
deleted
inserted
replaced
312:111bf81a5c96 | 313:eef5c50e7e34 |
---|---|
473 icon.addPixmap(il.loadPixmap("filesaveas-22")); | 473 icon.addPixmap(il.loadPixmap("filesaveas-22")); |
474 action = new QAction(icon, tr("Save Session &As..."), this); | 474 action = new QAction(icon, tr("Save Session &As..."), this); |
475 action->setShortcut(tr("Ctrl+Shift+S")); | 475 action->setShortcut(tr("Ctrl+Shift+S")); |
476 action->setStatusTip(tr("Save the current session into a new %1 session file").arg(QApplication::applicationName())); | 476 action->setStatusTip(tr("Save the current session into a new %1 session file").arg(QApplication::applicationName())); |
477 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs())); | 477 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs())); |
478 connect(this, SIGNAL(canSaveAs(bool)), action, SLOT(setEnabled(bool))); | |
478 menu->addAction(action); | 479 menu->addAction(action); |
479 toolbar->addAction(action); | 480 toolbar->addAction(action); |
480 | 481 |
481 icon = il.load("filesave"); | 482 icon = il.load("filesave"); |
482 icon.addPixmap(il.loadPixmap("filesave-22")); | 483 icon.addPixmap(il.loadPixmap("filesave-22")); |
483 action = new QAction(icon, tr("Save Session In &Audio Path"), this); | 484 action = new QAction(icon, tr("Save Session to Audio &Path"), this); |
484 action->setShortcut(tr("Ctrl+Alt+S")); | 485 action->setShortcut(tr("Ctrl+Alt+S")); |
485 action->setStatusTip(tr("Save the current session into a %1 session file with the same path and filename but .ton extension.").arg(QApplication::applicationName())); | 486 action->setStatusTip(tr("Save the current session into a %1 session file with the same filename as the audio but a .ton extension.").arg(QApplication::applicationName())); |
486 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionInAudioPath())); | 487 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionInAudioPath())); |
487 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool))); | 488 connect(this, SIGNAL(canSaveAs(bool)), action, SLOT(setEnabled(bool))); |
488 menu->addAction(action); | 489 menu->addAction(action); |
489 | 490 |
490 menu->addSeparator(); | 491 menu->addSeparator(); |
491 | 492 |
492 action = new QAction(tr("I&mport Pitch Track Data..."), this); | 493 action = new QAction(tr("I&mport Pitch Track Data..."), this); |
1802 } | 1803 } |
1803 | 1804 |
1804 void | 1805 void |
1805 MainWindow::saveSessionInAudioPath() | 1806 MainWindow::saveSessionInAudioPath() |
1806 { | 1807 { |
1807 | |
1808 if (m_audioFile == "") return; | 1808 if (m_audioFile == "") return; |
1809 | 1809 |
1810 // We do not want to save mid-analysis regions -- that would cause | 1810 // We do not want to save mid-analysis regions -- that would cause |
1811 // confusion on reloading | 1811 // confusion on reloading |
1812 m_analyser->clearReAnalysis(); | 1812 m_analyser->clearReAnalysis(); |
1816 QString basename = QFileInfo(m_audioFile).completeBaseName(); | 1816 QString basename = QFileInfo(m_audioFile).completeBaseName(); |
1817 | 1817 |
1818 QString path = QDir(filepath).filePath(basename + ".ton"); | 1818 QString path = QDir(filepath).filePath(basename + ".ton"); |
1819 | 1819 |
1820 cerr << path << endl; | 1820 cerr << path << endl; |
1821 | |
1822 // We don't want to overwrite an existing .ton file unless we put | |
1823 // it there in the first place | |
1824 bool shouldVerify = true; | |
1825 if (m_sessionFile == path) { | |
1826 shouldVerify = false; | |
1827 } | |
1828 | |
1829 if (shouldVerify && QFileInfo(path).exists()) { | |
1830 if (QMessageBox::question(0, tr("File exists"), | |
1831 tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path), | |
1832 QMessageBox::Ok, | |
1833 QMessageBox::Cancel) != QMessageBox::Ok) { | |
1834 return; | |
1835 } | |
1836 } | |
1821 | 1837 |
1822 if (!saveSessionFile(path)) { | 1838 if (!saveSessionFile(path)) { |
1823 QMessageBox::critical(this, tr("Failed to save file"), | 1839 QMessageBox::critical(this, tr("Failed to save file"), |
1824 tr("Session file \"%1\" could not be saved.").arg(path)); | 1840 tr("Session file \"%1\" could not be saved.").arg(path)); |
1825 } else { | 1841 } else { |