Mercurial > hg > easaier-soundaccess
changeset 279:427272bfec3b
missing files
author | benoitrigolleau |
---|---|
date | Tue, 21 Oct 2008 15:17:16 +0000 |
parents | 65dfc1027ed6 |
children | 8bdfbd9ad418 |
files | data/fileio/FileParserThread.cpp data/fileio/FileParserThread.h data/fileio/SparqlResultsHandler.cpp data/fileio/SparqlResultsHandler.h |
diffstat | 4 files changed, 240 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/FileParserThread.cpp Tue Oct 21 15:17:16 2008 +0000 @@ -0,0 +1,27 @@ +#include "FileParserThread.h" + +#include "data/fileio/SparqlResultsReader.h" +#include "data/fileio/SparqlRelatedMediaReader.h" +#include "main/MainWindow.h" +#include "widgets/QueryResultsWidget.h" + + +FileParserThread::FileParserThread(QString filename,QObject* parent):QThread(parent){ + m_filename = filename; +} + +void FileParserThread::run(){ + QueryResultsWidget* resultsWidget = MainWindow::instance()->getQueryResultsWidget(); + resultsWidget->reset(); + + if (resultsWidget) + { + SparqlResultsReader rd; + connect(rd.getHandler(), SIGNAL(newResultDetected ()), MainWindow::instance(),SLOT(createNewResultItem()),Qt::QueuedConnection); + connect(rd.getHandler(), SIGNAL(newInfoResultDetected(QString,QString)), MainWindow::instance(),SLOT(addInfoIntoResultItem(QString,QString)),Qt::QueuedConnection); + connect(rd.getHandler(), SIGNAL(endOfResultDetected ()), MainWindow::instance(),SLOT(saveCurrentResultItem()),Qt::QueuedConnection); //Qt::DirectConnection + connect(rd.getHandler(), SIGNAL(endOfDocumentDetected ()), MainWindow::instance(),SLOT(displayResultList()),Qt::QueuedConnection); + + rd.parse(m_filename); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/FileParserThread.h Tue Oct 21 15:17:16 2008 +0000 @@ -0,0 +1,32 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* Sound Access + EASAIER client application. + Silogic 2008. Rigolleau Benoit. + + 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 _FILE_PARSER_THREAD_H_ +#define _FILE_PARSER_THREAD_H_ + +#include <QThread> + +class FileParserThread : public QThread +{ + Q_OBJECT +public: + FileParserThread(QString filename,QObject* parent = 0); + +protected: + virtual void run(); +private : + QString m_filename; + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/SparqlResultsHandler.cpp Tue Oct 21 15:17:16 2008 +0000 @@ -0,0 +1,144 @@ +#include "SparqlResultsHandler.h" + +#include <iostream> +#include <windows.h> + +SparqlResultsHandler::SparqlResultsHandler() : QXmlDefaultHandler(), + 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") { + + emit(newResultDetected()); + 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->addInfo("composer", m_composer); + m_resultsWidget->addInfo("arranger", m_arranger); + m_composer.clear(); + m_arranger.clear(); + m_composer.append(" -"); + m_arranger.append(" -");*/ + + //Sleep(500); + emit endOfResultDetected(); + + } + return true; +} + +bool SparqlResultsHandler::characters(const QString &str) +{ + if (m_inBinding) + { + /*if (m_curBindingName.contains("composer")) + { + m_composer.append(" " + str); + } + else if (m_curBindingName.contains("arranger")) + { + m_arranger.append(" " + str); + } + else + {*/ + emit newInfoResultDetected(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); +} + +bool SparqlResultsHandler::endDocument(){ + emit endOfDocumentDetected(); + return true; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/SparqlResultsHandler.h Tue Oct 21 15:17:16 2008 +0000 @@ -0,0 +1,37 @@ + +#ifndef _SPARQL_RESULTS_HANDLER_H_ +#define _SPARQL_RESULTS_HANDLER_H_ + +#include <QXmlDefaultHandler> + +class SparqlResultsHandler : public QObject, public QXmlDefaultHandler +{ + Q_OBJECT +public: + SparqlResultsHandler(); + + 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 endDocument(); + +signals : + void endOfDocumentDetected(); + void newResultDetected(); + void newInfoResultDetected(QString,QString); + void endOfResultDetected(); + +private: + + bool m_inBinding; + QString m_curBindingName; + + QString m_composer; + QString m_arranger; +}; + +#endif