Mercurial > hg > svcore
diff data/fileio/CSVFileWriter.cpp @ 742:c10cb8782576 coreaudio_tests
Merge from branch "default"
author | Chris Cannam |
---|---|
date | Sun, 01 Jul 2012 11:53:00 +0100 |
parents | 341e4e1a6ed3 |
children | 38bb7c8e415d |
line wrap: on
line diff
--- a/data/fileio/CSVFileWriter.cpp Mon Nov 29 12:45:39 2010 +0000 +++ b/data/fileio/CSVFileWriter.cpp Sun Jul 01 11:53:00 2012 +0100 @@ -21,6 +21,9 @@ #include "model/NoteModel.h" #include "model/TextModel.h" +#include "base/TempWriteFile.h" +#include "base/Exceptions.h" + #include <QFile> #include <QTextStream> @@ -51,16 +54,25 @@ void CSVFileWriter::write() { - QFile file(m_path); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - m_error = tr("Failed to open file %1 for writing").arg(m_path); - return; + try { + TempWriteFile temp(m_path); + + QFile file(temp.getTemporaryFilename()); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + m_error = tr("Failed to open file %1 for writing") + .arg(temp.getTemporaryFilename()); + return; + } + + QTextStream out(&file); + out << m_model->toDelimitedDataString(m_delimiter); + + file.close(); + temp.moveToTarget(); + + } catch (FileOperationFailed &f) { + m_error = f.what(); } - - QTextStream out(&file); - out << m_model->toDelimitedDataString(m_delimiter); - - file.close(); }