Mercurial > hg > easaier-soundaccess
changeset 15:11e298cdb9e7
add
- EasaierSessionManager
- Easaier menus
- Interval model
author | lbajardsilogic |
---|---|
date | Mon, 14 May 2007 13:10:49 +0000 |
parents | 819ad579459f |
children | 21f452cc3310 |
files | data/fileio/AudioSourceInfoReader.cpp data/fileio/AudioSourceInfoReader.h data/fileio/ModelReader.cpp data/fileio/ModelReader.h data/fileio/QueryConfigReader.cpp data/fileio/QueryConfigReader.h data/fileio/SparqlResultsReader.cpp data/fileio/SparqlResultsReader.h |
diffstat | 8 files changed, 1216 insertions(+), 0 deletions(-) [+] |
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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/AudioSourceInfoReader.h Mon May 14 13:10:49 2007 +0000 @@ -0,0 +1,53 @@ +/* -*- 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. +*/ + +#ifndef _AUDIO_SOURCE_INFO_READER_H_ +#define _AUDIO_SOURCE_INFO_READER_H_ + +#include <QXmlDefaultHandler> + +#include "data/model/AudioSourceInfoModel.h" + +class AudioSourceInfoReader +{ +public: + AudioSourceInfoReader(AudioSourceInfoModel* model); + virtual ~AudioSourceInfoReader(){} + + bool parse(const QString & filename); + +private: + AudioSourceInfoModel *m_model; + +}; + +class AudioSourceInfoHandler : public QXmlDefaultHandler +{ +public: + AudioSourceInfoHandler(AudioSourceInfoModel *model); + + bool startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes); + bool endElement(const QString &namespaceURI, const QString &localName, + const QString &qName); + bool characters(const QString &str); + bool error(const QXmlParseException &exception); + bool fatalError(const QXmlParseException &exception); + +private: + + AudioSourceInfoModel *m_model; + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/ModelReader.cpp Mon May 14 13:10:49 2007 +0000 @@ -0,0 +1,551 @@ +/* -*- 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 "ModelReader.h" + +#include "document/Document.h" +#include "layer/Layer.h" + +#include "data/model/EditableDenseThreeDimensionalModel.h" +#include "data/model/SparseOneDimensionalModel.h" +#include "data/model/SparseTimeValueModel.h" +#include "data/model/NoteModel.h" +#include "data/model/TextModel.h" +#include "data/model/IntervalModel.h" +#include "view/Pane.h" + +#include <iostream> + +ModelReader::ModelReader(Document *document, Layer * layer, Pane * pane) : + m_document(document), + m_layer(layer), + m_pane(pane) +{} + +bool ModelReader::parse(const QString & filename) +{ + ModelHandler handler(m_document, m_layer, m_pane); + 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; +} + +ModelHandler::ModelHandler(Document *document, Layer * layer, Pane* pane) : QXmlDefaultHandler(), + m_document(document), + m_layer(layer), + m_pane(pane), + m_model(0), + m_datasetSeparator(" "), + m_inData(false), + m_inRow(false), + m_rowNumber(0) +{} + +bool ModelHandler::startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes) +{ + + QString name = qName.toLower(); + + bool ok = false; + + // Valid element names: + // + // easaier + // data + // dataset + // model + // point + // row + // interval + + if (name == "easaier") { + + // nothing needed + ok = true; + + } else if (name == "data") { + + m_inData = true; + if (m_layer == 0) + { + ok = readLayer(attributes); + } else { + ok = true; + } + + } else if (name == "model") { + + ok = readModel(attributes); + + } else if (name == "dataset") { + + ok = readDatasetStart(attributes); + + } else if (name == "bin") { + + ok = addBinToDataset(attributes); + + } else if (name == "point") { + + ok = addPointToDataset(attributes); + + } else if (name == "row") { + + ok = addRowToDataset(attributes); + + } else if (name == "interval") { + + ok = addIntervalToDataset(attributes); + + } + + if (!ok) { + std::cerr << "WARNING: ModelReader-XML: Failed to completely process element \"" + << name.toLocal8Bit().data() << "\"" << std::endl; + } + + return true; +} + +bool ModelHandler::endElement(const QString &namespaceURI, const QString &localName, + const QString &qName) +{ + QString name = qName.toLower(); + + if (name == "dataset") + { + if ((m_model) && (m_layer)) + { + m_document->addImportedModel(m_model); + m_document->setModel(m_layer, m_model); + } + } + else if (name == "data") + { + m_inData = false; + if (m_pane && m_layer) + { + m_document->addLayerToView(m_pane, m_layer); + } + } + else if (name == "row") + { + m_inRow = false; + } + + return true; +} + +bool ModelHandler::characters(const QString &str) +{ + bool ok = false; + + if (m_inRow) { + ok = readRowData(str); + if (!ok) { + std::cerr << "WARNING: ModelReader-XML: Failed to read row data content for row " << m_rowNumber << std::endl; + } + } + + return true; +} + +bool ModelHandler::error(const QXmlParseException &exception) +{ + QString errorString; + errorString += QString("ERROR: ModelReader-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 ModelHandler::fatalError(const QXmlParseException &exception) +{ + QString errorString; + errorString += QString("FATAL ERROR: ModelReader-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); +} + +#define READ_MANDATORY(TYPE, NAME, CONVERSION) \ + TYPE NAME = attributes.value(#NAME).trimmed().CONVERSION(&ok); \ + if (!ok) { \ + std::cerr << "WARNING: ModelReader-XML: Missing or invalid mandatory " #TYPE " attribute \"" #NAME "\"" << std::endl; \ + return false; \ + } + +bool ModelHandler::readModel(const QXmlAttributes &attributes) +{ + bool ok = false; + + READ_MANDATORY(int, id, toInt); + + QString name = attributes.value("name"); + + if (m_layer->getModelName() == "") + { + m_layer->setModelName(name); + m_layer->setModelId(id); + } + + READ_MANDATORY(int, sampleRate, toInt); + + QString type = attributes.value("type").trimmed(); + bool mainModel = (attributes.value("mainModel").trimmed() == "true"); + + if (type == "dense") + { + + READ_MANDATORY(int, dimensions, toInt); + + // Currently the only dense model we support here + // is the dense 3d model. Dense time-value models + // are always file-backed waveform data, at this + // point, and they come in as the wavefile model + // type above. + + if (dimensions == 3) + { + + READ_MANDATORY(int, windowSize, toInt); + READ_MANDATORY(int, yBinCount, toInt); + + //DenseThreeDimensionalModel *model = + //new DenseThreeDimensionalModel(sampleRate, windowSize, yBinCount); + + EditableDenseThreeDimensionalModel *model = + new EditableDenseThreeDimensionalModel(sampleRate, windowSize, yBinCount); + + float minimum = attributes.value("minimum").trimmed().toFloat(&ok); + if (ok) model->setMinimumLevel(minimum); + + float maximum = attributes.value("maximum").trimmed().toFloat(&ok); + if (ok) model->setMaximumLevel(maximum); + + m_model = model; + return true; + + } else + { + std::cerr << "WARNING: ModelReader-XML: Unexpected dense model dimension (" + << dimensions << ")" << std::endl; + } + } else if (type == "sparse") + { + READ_MANDATORY(int, dimensions, toInt); + + if (dimensions == 1) + { + + READ_MANDATORY(int, resolution, toInt); + SparseOneDimensionalModel *model = new SparseOneDimensionalModel(sampleRate, resolution); + m_model = model; + + return true; + + } else if (dimensions == 2 || dimensions == 3) + { + READ_MANDATORY(int, resolution, toInt); + + float minimum = attributes.value("minimum").trimmed().toFloat(&ok); + float maximum = attributes.value("maximum").trimmed().toFloat(&ok); + float valueQuantization = attributes.value("valueQuantization").trimmed().toFloat(&ok); + + bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true"); + + QString units = attributes.value("units"); + + if (dimensions == 2) + { + if (attributes.value("subtype") == "text") + { + TextModel *model = new TextModel(sampleRate, resolution, notifyOnAdd); + m_model = model; + } else + { + SparseTimeValueModel *model = new SparseTimeValueModel(sampleRate, resolution, minimum, maximum, notifyOnAdd); + model->setScaleUnits(units); + m_model = model; + } + } else + { + NoteModel *model = new NoteModel(sampleRate, resolution, minimum, maximum, notifyOnAdd); + model->setValueQuantization(valueQuantization); + model->setScaleUnits(units); + m_model = model; + } + return true; + + } else + { + std::cerr << "WARNING: ModelReader-XML: Unexpected sparse model dimension (" + << dimensions << ")" << std::endl; + } + } else if (type == "interval") + { + READ_MANDATORY(int, dimensions, toInt); + READ_MANDATORY(int, resolution, toInt); + bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true"); + + IntervalModel * model = new IntervalModel(sampleRate, resolution, notifyOnAdd); + m_model = model; + return true; + + } else + { + std::cerr << "WARNING: ModelReader-XML: Unexpected model type \"" + << type.toLocal8Bit().data() << "\" for model id" << id << std::endl; + } + + return false; +} + +bool ModelHandler::readDatasetStart(const QXmlAttributes &attributes) +{ + bool ok = false; + + READ_MANDATORY(int, id, toInt); + READ_MANDATORY(int, dimensions, toInt); + + Model *model = m_model; + + bool good = false; + + switch (dimensions) { + case 1: + if (dynamic_cast<SparseOneDimensionalModel *>(model)) good = true; + break; + + case 2: + if (dynamic_cast<SparseTimeValueModel *>(model)) good = true; + else if (dynamic_cast<TextModel *>(model)) good = true; + break; + + case 3: + if (dynamic_cast<NoteModel *>(model)) good = true; + else if (dynamic_cast<DenseThreeDimensionalModel *>(model)) { + m_datasetSeparator = attributes.value("separator"); + good = true; + } + else if (dynamic_cast<IntervalModel *>(model)) good = true; + break; + + default: + break; + } + + if (!good) { + std::cerr << "WARNING: ModelReader-XML: Model id " << /*modelId <<*/ " has wrong number of dimensions for " << dimensions << "-D dataset " << id << std::endl; + m_model = 0; + return false; + } + + return true; +} + +bool ModelHandler::addPointToDataset(const QXmlAttributes &attributes) +{ + bool ok = false; + + READ_MANDATORY(int, frame, toInt); + + SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *> (m_model); + + if (sodm) + { + QString label = attributes.value("label"); + sodm->addPoint(SparseOneDimensionalModel::Point(frame, label)); + return true; + } + + SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *> (m_model); + + if (stvm) + { + float value = 0.0; + value = attributes.value("value").trimmed().toFloat(&ok); + QString label = attributes.value("label"); + stvm->addPoint(SparseTimeValueModel::Point(frame, value, label)); + return ok; + } + + NoteModel *nm = dynamic_cast<NoteModel *>(m_model); + + if (nm) + { + float value = 0.0; + value = attributes.value("value").trimmed().toFloat(&ok); + float duration = 0.0; + duration = attributes.value("duration").trimmed().toFloat(&ok); + QString label = attributes.value("label"); + nm->addPoint(NoteModel::Point(frame, value, duration, label)); + return ok; + } + + TextModel *tm = dynamic_cast<TextModel *>(m_model); + + if (tm) + { + float height = 0.0; + height = attributes.value("height").trimmed().toFloat(&ok); + QString label = attributes.value("label"); + tm->addPoint(TextModel::Point(frame, height, label)); + return ok; + } + + std::cerr << "WARNING: ModelReader-XML: Point element found in non-point dataset" << std::endl; + + return false; +} + +bool ModelHandler::addBinToDataset(const QXmlAttributes &attributes) +{ + //DenseThreeDimensionalModel *dtdm = dynamic_cast<DenseThreeDimensionalModel *> (m_model); + EditableDenseThreeDimensionalModel *dtdm = dynamic_cast<EditableDenseThreeDimensionalModel *>(m_model); + + if (dtdm) { + + bool ok = false; + int n = attributes.value("number").trimmed().toInt(&ok); + if (!ok) { + std::cerr << "WARNING: ModelReader-XML: Missing or invalid bin number" + << std::endl; + return false; + } + + QString name = attributes.value("name"); + + dtdm->setBinName(n, name); + return true; + } + + std::cerr << "WARNING: ModelReader-XML: Bin definition found in incompatible dataset" << std::endl; + + return false; +} + + +bool ModelHandler::addRowToDataset(const QXmlAttributes &attributes) +{ + m_inRow = false; + + bool ok = false; + m_rowNumber = attributes.value("n").trimmed().toInt(&ok); + if (!ok) { + std::cerr << "WARNING: ModelReader-XML: Missing or invalid row number" + << std::endl; + return false; + } + + m_inRow = true; + + return true; +} + +bool ModelHandler::addIntervalToDataset(const QXmlAttributes &attributes) +{ + bool ok = false; + + IntervalModel *im = dynamic_cast<IntervalModel*> (m_model); + if (im) + { + READ_MANDATORY(int, start, toInt); + READ_MANDATORY(int, end, toInt); + QString label = attributes.value("label"); + float value = 0.0; + value = attributes.value("value").trimmed().toFloat(&ok); + im->addInterval(start, end, label, value); + ok = true; + } + return ok; +} + +bool ModelHandler::readRowData(const QString &text) +{ + EditableDenseThreeDimensionalModel *dtdm = dynamic_cast<EditableDenseThreeDimensionalModel *>(m_model); + + bool warned = false; + + if (dtdm) { + QStringList data = text.split(m_datasetSeparator); + + DenseThreeDimensionalModel::Column values; + + for (QStringList::iterator i = data.begin(); i != data.end(); ++i) { + + if (values.size() == dtdm->getHeight()) { + if (!warned) { + std::cerr << "WARNING: ModelReader-XML: Too many y-bins in 3-D dataset row " + << m_rowNumber << std::endl; + warned = true; + } + } + + bool ok; + float value = i->toFloat(&ok); + if (!ok) { + std::cerr << "WARNING: ModelReader-XML: Bad floating-point value " + << i->toLocal8Bit().data() + << " in row data" << std::endl; + } else { + values.push_back(value); + } + } + + dtdm->setColumn(m_rowNumber, values); + return true; + } + + std::cerr << "WARNING: ModelReader-XML: Row data found in non-row dataset" << std::endl; + + return false; +} + +bool ModelHandler::readLayer(const QXmlAttributes &attributes) +{ + QString type = attributes.value("type"); + + m_layer = m_document->createLayer(LayerFactory::getInstance()->getLayerTypeForName(type)); + + if (!m_layer) { + std::cerr << "WARNING: modelreader-XML: Failed to add layer of type \"" + << type.toLocal8Bit().data() + << "\"" << std::endl; + return false; + } + + QString name = attributes.value("name"); + m_layer->setObjectName(name); + + return true; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/ModelReader.h Mon May 14 13:10:49 2007 +0000 @@ -0,0 +1,79 @@ +/* -*- 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. +*/ + +#ifndef _MODEL_READER_H_ +#define _MODEL_READER_H_ + +#include <QXmlDefaultHandler> + +#include <map> + +class Document; +class Layer; +class Model; +class Pane; + +class ModelReader +{ +public: + ModelReader(Document *document, Layer * layer = 0, Pane* pane = 0); + virtual ~ModelReader(){} + + bool parse(const QString & filename); + +private: + Document *m_document; + Layer *m_layer; + Pane *m_pane; + +}; + +class ModelHandler : public QXmlDefaultHandler +{ +public: + ModelHandler(Document *document, Layer * layer = 0, Pane* pane = 0); + + bool startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes); + bool endElement(const QString &namespaceURI, const QString &localName, + const QString &qName); + bool characters(const QString &str); + bool error(const QXmlParseException &exception); + bool fatalError(const QXmlParseException &exception); + + bool readModel(const QXmlAttributes &attributes); + bool readDatasetStart(const QXmlAttributes &attributes); + bool readRowData(const QString &text); + bool addPointToDataset(const QXmlAttributes &attributes); + bool addBinToDataset(const QXmlAttributes &attributes); + bool addRowToDataset(const QXmlAttributes &attributes); + bool addIntervalToDataset(const QXmlAttributes &attributes); + + bool readLayer(const QXmlAttributes &attributes); + +private: + Document *m_document; + Layer *m_layer; + Pane *m_pane; + + Model *m_model; + + bool m_inData; + bool m_inRow; + int m_rowNumber; + + QString m_datasetSeparator; + +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/QueryConfigReader.cpp Mon May 14 13:10:49 2007 +0000 @@ -0,0 +1,149 @@ +/* -*- 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 "QueryConfigReader.h" + +#include <iostream> + +#include "model/QueryModel.h" + +QueryConfigReader::QueryConfigReader(QueryModel * queryModel) : + m_queryModel(queryModel) +{} + +bool QueryConfigReader::parse(const QString & filename) +{ + QueryConfigHandler handler(m_queryModel); + 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; +} + +QueryConfigHandler::QueryConfigHandler(QueryModel * queryModel) : QXmlDefaultHandler(), + m_inTheme(false), + m_inFieldGroup(false), + m_queryModel(queryModel) +{} + +bool QueryConfigHandler::startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes) +{ + + QString name = qName.toLower(); + + bool ok = false; + + // Valid element names: + // + // easaierquery + // theme + // fieldgroup + // field + + if (name == "easaierquery") { + + // nothing needed + ok = true; + + } else if (name == "theme") { + + m_inTheme = true; + m_queryModel->addTheme(attributes.value("name"), attributes.value("label")); + ok = true; + + } else if (name == "fieldgroup") { + + m_inFieldGroup = true; + m_queryModel->newGroup(attributes.value("name"), attributes.value("label")); + ok = true; + + } else if (name == "field") { + + ok = true; + QString name = attributes.value("name"); + QString label = attributes.value("label"); + QString type = attributes.value("xsi:type"); + QString range = attributes.value("range"); + QString unit = attributes.value("unit"); + QString comment = attributes.value("comment"); + m_queryModel->addProperty(name, label, type, range, unit, comment); + + } + + if (!ok) { + std::cerr << "WARNING: QueryConfigReader-XML: Failed to completely process element \"" + << name.toLocal8Bit().data() << "\"" << std::endl; + } + + return true; +} + +bool QueryConfigHandler::endElement(const QString &namespaceURI, const QString &localName, + const QString &qName) +{ + QString name = qName.toLower(); + + if (name == "theme") + { + m_inTheme = false; + } + else if (name == "fieldgroup") + { + m_inFieldGroup = false; + } + + return true; +} + +bool QueryConfigHandler::characters(const QString &str) +{ + bool ok = false; + + return true; +} + +bool QueryConfigHandler::error(const QXmlParseException &exception) +{ + QString errorString; + errorString += QString("ERROR: QueryConfigReader-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 QueryConfigHandler::fatalError(const QXmlParseException &exception) +{ + QString errorString; + errorString += QString("FATAL ERROR: QueryConfigReader-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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/QueryConfigReader.h Mon May 14 13:10:49 2007 +0000 @@ -0,0 +1,56 @@ +/* -*- 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. +*/ + +#ifndef _QUERY_CONFIG_READER_H_ +#define _QUERY_CONFIG_READER_H_ + +#include <QXmlDefaultHandler> + +class QueryModel; + +class QueryConfigReader +{ +public: + QueryConfigReader(QueryModel * queryModel); + virtual ~QueryConfigReader(){} + + bool parse(const QString & filename); + +private: + + QueryModel *m_queryModel; +}; + +class QueryConfigHandler : public QXmlDefaultHandler +{ +public: + QueryConfigHandler(QueryModel * queryModel); + + bool startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes); + bool endElement(const QString &namespaceURI, const QString &localName, + const QString &qName); + bool characters(const QString &str); + bool error(const QXmlParseException &exception); + bool fatalError(const QXmlParseException &exception); + + +private: + + bool m_inTheme; + bool m_inFieldGroup; + + QueryModel *m_queryModel; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/SparqlResultsReader.cpp Mon May 14 13:10:49 2007 +0000 @@ -0,0 +1,158 @@ +/* -*- 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 "SparqlResultsReader.h" + +#include <iostream> + +SparqlResultsReader::SparqlResultsReader(QueryResultsWidget* resultsWidget) : + m_resultsWidget(resultsWidget) +{} + +bool SparqlResultsReader::parse(const QString & filename) +{ + SparqlResultsHandler handler(m_resultsWidget); + 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; +} + +SparqlResultsHandler::SparqlResultsHandler(QueryResultsWidget* resultsWidget) : QXmlDefaultHandler(), + m_resultsWidget(resultsWidget), + m_inBinding(false), + m_curBindingName("") +{} + +bool SparqlResultsHandler::startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes) +{ + + QString name = qName.toLower(); + + bool ok = false; + + // Valid element names: + // + // sparql + // head + // variable + // results + // result + // binding + + if (name == "sparql") { + + // nothing needed + ok = true; + + } else if (name == "head") { + + // nothing needed + ok = true; + + } else if (name == "variable") { + + // nothing needed + ok = true; + + } else if (name == "results") { + + // nothing needed + ok = true; + + } else if (name == "result") { + + m_resultsWidget->newResult(); + ok = true; + + } else if (name == "binding") { + + m_curBindingName = attributes.value("name"); + ok = true; + + } else if ( (name == "uri") || (name == "literal") ) { + m_inBinding = true; + ok = true; + } + + if (!ok) { + std::cerr << "WARNING: SparqlResultsHandler-XML: Failed to completely process element \"" + << name.toLocal8Bit().data() << "\"" << std::endl; + } + + return true; +} + +bool SparqlResultsHandler::endElement(const QString &namespaceURI, const QString &localName, + const QString &qName) +{ + QString name = qName.toLower(); + + if ( (name == "uri") || (name == "literal") ) + { + m_inBinding = false; + m_curBindingName = ""; + + } else if (name == "result") + { + m_resultsWidget->displayResult(); + } + + return true; +} + +bool SparqlResultsHandler::characters(const QString &str) +{ + if (m_inBinding) + { + m_resultsWidget->addInfo(m_curBindingName, str); + } + + return true; +} + +bool SparqlResultsHandler::error(const QXmlParseException &exception) +{ + QString errorString; + errorString += QString("ERROR: SparqlResultsHandler-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 SparqlResultsHandler::fatalError(const QXmlParseException &exception) +{ + QString errorString; + errorString += QString("FATAL ERROR: SparqlResultsHandler-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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/SparqlResultsReader.h Mon May 14 13:10:49 2007 +0000 @@ -0,0 +1,56 @@ +/* -*- 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. +*/ + +#ifndef _SPARQL_RESULTS_READER_H_ +#define _SPARQL_RESULTS_READER_H_ + +#include <QXmlDefaultHandler> + +#include "widgets/QueryResultsWidget.h" + +class SparqlResultsReader +{ +public: + SparqlResultsReader(QueryResultsWidget* resultsWidget); + virtual ~SparqlResultsReader(){} + + bool parse(const QString & filename); + +private: + + QueryResultsWidget *m_resultsWidget; +}; + +class SparqlResultsHandler : public QXmlDefaultHandler +{ +public: + SparqlResultsHandler(QueryResultsWidget* resultsWidget); + + bool startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes); + bool endElement(const QString &namespaceURI, const QString &localName, + const QString &qName); + bool characters(const QString &str); + bool error(const QXmlParseException &exception); + bool fatalError(const QXmlParseException &exception); + + +private: + + QueryResultsWidget *m_resultsWidget; + + bool m_inBinding; + QString m_curBindingName; +}; + +#endif