Chris@148: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@148: 
Chris@148: /*
Chris@148:     Sonic Visualiser
Chris@148:     An audio file viewer and annotation editor.
Chris@148:     Centre for Digital Music, Queen Mary, University of London.
Chris@148:     This file copyright 2006 Chris Cannam.
Chris@148:     
Chris@148:     This program is free software; you can redistribute it and/or
Chris@148:     modify it under the terms of the GNU General Public License as
Chris@148:     published by the Free Software Foundation; either version 2 of the
Chris@148:     License, or (at your option) any later version.  See the file
Chris@148:     COPYING included with this distribution for more information.
Chris@148: */
Chris@148: 
Chris@148: #include "CSVFileWriter.h"
Chris@148: 
Chris@150: #include "model/Model.h"
Chris@148: #include "model/SparseOneDimensionalModel.h"
Chris@148: #include "model/SparseTimeValueModel.h"
Chris@148: #include "model/NoteModel.h"
Chris@148: #include "model/TextModel.h"
Chris@148: 
Chris@148: #include <QFile>
Chris@148: #include <QTextStream>
Chris@148: 
Chris@148: CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) :
Chris@148:     m_path(path),
Chris@148:     m_model(model),
Chris@148:     m_error(""),
Chris@148:     m_delimiter(delimiter)
Chris@148: {
Chris@148: }
Chris@148: 
Chris@148: CSVFileWriter::~CSVFileWriter()
Chris@148: {
Chris@148: }
Chris@148: 
Chris@148: bool
Chris@148: CSVFileWriter::isOK() const
Chris@148: {
Chris@148:     return m_error == "";
Chris@148: }
Chris@148: 
Chris@148: QString
Chris@148: CSVFileWriter::getError() const
Chris@148: {
Chris@148:     return m_error;
Chris@148: }
Chris@148: 
Chris@148: void
Chris@148: CSVFileWriter::write()
Chris@148: {
Chris@148:     QFile file(m_path);
Chris@148:     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@148:         m_error = tr("Failed to open file %1 for writing").arg(m_path);
Chris@148:         return;
Chris@148:     }
Chris@148:     
Chris@148:     QTextStream out(&file);
Chris@148:     out << m_model->toDelimitedDataString(m_delimiter);
Chris@148: 
Chris@148:     file.close();
Chris@148: }
Chris@148: 
Chris@148: