comparison src/MainWindow.cpp @ 314:2a2fd6eb8fa8

If user asks to save before initial analysis is complete, wait for it
author Chris Cannam
date Fri, 13 Jun 2014 12:12:27 +0100
parents eef5c50e7e34
children fd7bdb74c8ec 0862da97abc5
comparison
equal deleted inserted replaced
313:eef5c50e7e34 314:2a2fd6eb8fa8
1778 1778
1779 // else cancel 1779 // else cancel
1780 return false; 1780 return false;
1781 } 1781 }
1782 1782
1783 bool
1784 MainWindow::waitForInitialAnalysis()
1785 {
1786 // Called before saving a session. We can't safely save while the
1787 // initial analysis is happening, because then we end up with an
1788 // incomplete session on reload. There are certainly theoretically
1789 // better ways to handle this...
1790
1791 if (!m_analyser || m_analyser->getInitialAnalysisCompletion() >= 100) {
1792 return true;
1793 }
1794
1795 QMessageBox mb(QMessageBox::Information,
1796 tr("Waiting for analysis"),
1797 tr("Waiting for initial analysis to complete before saving..."),
1798 QMessageBox::Cancel,
1799 this);
1800
1801 connect(m_analyser, SIGNAL(initialAnalysisCompleted()),
1802 &mb, SLOT(accept()));
1803
1804 if (mb.exec() == QDialog::Accepted) {
1805 return true;
1806 } else {
1807 return false;
1808 }
1809 }
1810
1783 void 1811 void
1784 MainWindow::saveSession() 1812 MainWindow::saveSession()
1785 { 1813 {
1786 // We do not want to save mid-analysis regions -- that would cause 1814 // We do not want to save mid-analysis regions -- that would cause
1787 // confusion on reloading 1815 // confusion on reloading
1805 void 1833 void
1806 MainWindow::saveSessionInAudioPath() 1834 MainWindow::saveSessionInAudioPath()
1807 { 1835 {
1808 if (m_audioFile == "") return; 1836 if (m_audioFile == "") return;
1809 1837
1838 if (!waitForInitialAnalysis()) return;
1839
1810 // We do not want to save mid-analysis regions -- that would cause 1840 // We do not want to save mid-analysis regions -- that would cause
1811 // confusion on reloading 1841 // confusion on reloading
1812 m_analyser->clearReAnalysis(); 1842 m_analyser->clearReAnalysis();
1813 clearSelection(); 1843 clearSelection();
1814 1844
1831 tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path), 1861 tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
1832 QMessageBox::Ok, 1862 QMessageBox::Ok,
1833 QMessageBox::Cancel) != QMessageBox::Ok) { 1863 QMessageBox::Cancel) != QMessageBox::Ok) {
1834 return; 1864 return;
1835 } 1865 }
1866 }
1867
1868 if (!waitForInitialAnalysis()) {
1869 QMessageBox::warning(this, tr("File not saved"),
1870 tr("Wait cancelled: the session has not been saved."));
1836 } 1871 }
1837 1872
1838 if (!saveSessionFile(path)) { 1873 if (!saveSessionFile(path)) {
1839 QMessageBox::critical(this, tr("Failed to save file"), 1874 QMessageBox::critical(this, tr("Failed to save file"),
1840 tr("Session file \"%1\" could not be saved.").arg(path)); 1875 tr("Session file \"%1\" could not be saved.").arg(path));
1858 clearSelection(); 1893 clearSelection();
1859 1894
1860 QString path = getSaveFileName(FileFinder::SessionFile); 1895 QString path = getSaveFileName(FileFinder::SessionFile);
1861 1896
1862 if (path == "") { 1897 if (path == "") {
1898 return;
1899 }
1900
1901 if (!waitForInitialAnalysis()) {
1902 QMessageBox::warning(this, tr("File not saved"),
1903 tr("Wait cancelled: the session has not been saved."));
1863 return; 1904 return;
1864 } 1905 }
1865 1906
1866 if (!saveSessionFile(path)) { 1907 if (!saveSessionFile(path)) {
1867 QMessageBox::critical(this, tr("Failed to save file"), 1908 QMessageBox::critical(this, tr("Failed to save file"),