Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 217:64dfa7d6171d sv_v1.8
Use TempWriteFile when saving session files, to avoid clobbering until file save complete
author | Chris Cannam |
---|---|
date | Tue, 29 Mar 2011 17:56:32 +0100 |
parents | b96d90975f7c |
children | 85e59c901de9 |
comparison
equal
deleted
inserted
replaced
216:ee31e2f3a0f1 | 217:64dfa7d6171d |
---|---|
64 | 64 |
65 #include "base/PlayParameterRepository.h" | 65 #include "base/PlayParameterRepository.h" |
66 #include "base/XmlExportable.h" | 66 #include "base/XmlExportable.h" |
67 #include "base/Profiler.h" | 67 #include "base/Profiler.h" |
68 #include "base/Preferences.h" | 68 #include "base/Preferences.h" |
69 #include "base/TempWriteFile.h" | |
70 #include "base/Exceptions.h" | |
69 | 71 |
70 #include "data/osc/OSCQueue.h" | 72 #include "data/osc/OSCQueue.h" |
71 #include "data/midi/MIDIInput.h" | 73 #include "data/midi/MIDIInput.h" |
72 | 74 |
73 #include <QApplication> | 75 #include <QApplication> |
1888 } | 1890 } |
1889 | 1891 |
1890 bool | 1892 bool |
1891 MainWindowBase::saveSessionFile(QString path) | 1893 MainWindowBase::saveSessionFile(QString path) |
1892 { | 1894 { |
1893 BZipFileDevice bzFile(path); | 1895 try { |
1894 if (!bzFile.open(QIODevice::WriteOnly)) { | 1896 |
1895 std::cerr << "Failed to open session file \"" << path.toStdString() | 1897 TempWriteFile temp(path); |
1896 << "\" for writing: " | 1898 |
1897 << bzFile.errorString().toStdString() << std::endl; | 1899 BZipFileDevice bzFile(temp.getTemporaryFilename()); |
1900 if (!bzFile.open(QIODevice::WriteOnly)) { | |
1901 std::cerr << "Failed to open session file \"" | |
1902 << temp.getTemporaryFilename().toStdString() | |
1903 << "\" for writing: " | |
1904 << bzFile.errorString().toStdString() << std::endl; | |
1905 return false; | |
1906 } | |
1907 | |
1908 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); | |
1909 | |
1910 QTextStream out(&bzFile); | |
1911 toXml(out); | |
1912 out.flush(); | |
1913 | |
1914 QApplication::restoreOverrideCursor(); | |
1915 | |
1916 if (!bzFile.isOK()) { | |
1917 QMessageBox::critical(this, tr("Failed to write file"), | |
1918 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2") | |
1919 .arg(path).arg(bzFile.errorString())); | |
1920 bzFile.close(); | |
1921 return false; | |
1922 } | |
1923 | |
1924 bzFile.close(); | |
1925 temp.moveToTarget(); | |
1926 return true; | |
1927 | |
1928 } catch (FileOperationFailed &f) { | |
1929 | |
1930 QMessageBox::critical(this, tr("Failed to write file"), | |
1931 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2") | |
1932 .arg(path).arg(f.what())); | |
1898 return false; | 1933 return false; |
1899 } | 1934 } |
1900 | |
1901 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); | |
1902 | |
1903 QTextStream out(&bzFile); | |
1904 toXml(out); | |
1905 out.flush(); | |
1906 | |
1907 QApplication::restoreOverrideCursor(); | |
1908 | |
1909 if (!bzFile.isOK()) { | |
1910 QMessageBox::critical(this, tr("Failed to write file"), | |
1911 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2") | |
1912 .arg(path).arg(bzFile.errorString())); | |
1913 bzFile.close(); | |
1914 return false; | |
1915 } | |
1916 | |
1917 bzFile.close(); | |
1918 return true; | |
1919 } | 1935 } |
1920 | 1936 |
1921 void | 1937 void |
1922 MainWindowBase::toXml(QTextStream &out) | 1938 MainWindowBase::toXml(QTextStream &out) |
1923 { | 1939 { |