Mercurial > hg > easaier-soundaccess
diff data/fileio/AudioSourceInfoReader.cpp @ 15:11e298cdb9e7
add
- EasaierSessionManager
- Easaier menus
- Interval model
author | lbajardsilogic |
---|---|
date | Mon, 14 May 2007 13:10:49 +0000 |
parents | |
children | 87495ac7710a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/AudioSourceInfoReader.cpp Mon May 14 13:10:49 2007 +0000 @@ -0,0 +1,114 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* Sound Access + EASAIER client application. + Silogic 2007. Laure Bajard. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "AudioSourceInfoReader.h" + + +#include <iostream> + +AudioSourceInfoReader::AudioSourceInfoReader(AudioSourceInfoModel* model) +{ + m_model = model; +} + +bool AudioSourceInfoReader::parse(const QString & filename) +{ + AudioSourceInfoHandler handler(m_model); + QXmlSimpleReader reader; + reader.setContentHandler(&handler); + reader.setErrorHandler(&handler); + + QFile file(filename); + + if (!file.open(QFile::ReadOnly | QFile::Text)) { + return false; + } + + QXmlInputSource xmlInputSource(&file); + if (reader.parse(xmlInputSource)) + { + return true; + } + + return false; +} + +AudioSourceInfoHandler::AudioSourceInfoHandler(AudioSourceInfoModel* model) : QXmlDefaultHandler() +{ + m_model = model; +} + +bool AudioSourceInfoHandler::startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes) +{ + QString name = qName.toLower(); + bool ok = false; + + // Valid element names: + // easaierResource + // dc:identifier + // dc:title + // dc:creator... + + if (name == "easaierresource") { + // nothing needed + ok = true; + + } else { + ok = true; + QString id = attributes.value("id"); + name.append(id); + m_model->addInfo(name, attributes.value("value")); + + } + + if (!ok) { + std::cerr << "WARNING: connexion config-XML: Failed to completely process element \"" + << name.toLocal8Bit().data() << "\"" << std::endl; + } + + return true; +} + +bool AudioSourceInfoHandler::endElement(const QString &namespaceURI, const QString &localName, + const QString &qName) +{ + return true; +} + +bool AudioSourceInfoHandler::characters(const QString &str) +{ + return true; +} + +bool AudioSourceInfoHandler::error(const QXmlParseException &exception) +{ + QString errorString; + errorString += QString("ERROR: connexion config-XML: %1 at line %2, column %3") + .arg(exception.message()) + .arg(exception.lineNumber()) + .arg(exception.columnNumber()); + std::cerr << errorString.toLocal8Bit().data() << std::endl; + return QXmlDefaultHandler::error(exception); +} + +bool AudioSourceInfoHandler::fatalError(const QXmlParseException &exception) +{ + QString errorString; + errorString += QString("FATAL ERROR: connexion config-XML: %1 at line %2, column %3") + .arg(exception.message()) + .arg(exception.lineNumber()) + .arg(exception.columnNumber()); + std::cerr << errorString.toLocal8Bit().data() << std::endl; + return QXmlDefaultHandler::fatalError(exception); +} \ No newline at end of file