comparison 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
comparison
equal deleted inserted replaced
14:819ad579459f 15:11e298cdb9e7
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /* Sound Access
4 EASAIER client application.
5 Silogic 2007. Laure Bajard.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version. See the file
11 COPYING included with this distribution for more information.
12 */
13
14 #include "AudioSourceInfoReader.h"
15
16
17 #include <iostream>
18
19 AudioSourceInfoReader::AudioSourceInfoReader(AudioSourceInfoModel* model)
20 {
21 m_model = model;
22 }
23
24 bool AudioSourceInfoReader::parse(const QString & filename)
25 {
26 AudioSourceInfoHandler handler(m_model);
27 QXmlSimpleReader reader;
28 reader.setContentHandler(&handler);
29 reader.setErrorHandler(&handler);
30
31 QFile file(filename);
32
33 if (!file.open(QFile::ReadOnly | QFile::Text)) {
34 return false;
35 }
36
37 QXmlInputSource xmlInputSource(&file);
38 if (reader.parse(xmlInputSource))
39 {
40 return true;
41 }
42
43 return false;
44 }
45
46 AudioSourceInfoHandler::AudioSourceInfoHandler(AudioSourceInfoModel* model) : QXmlDefaultHandler()
47 {
48 m_model = model;
49 }
50
51 bool AudioSourceInfoHandler::startElement(const QString &namespaceURI, const QString &localName,
52 const QString &qName, const QXmlAttributes &attributes)
53 {
54 QString name = qName.toLower();
55 bool ok = false;
56
57 // Valid element names:
58 // easaierResource
59 // dc:identifier
60 // dc:title
61 // dc:creator...
62
63 if (name == "easaierresource") {
64 // nothing needed
65 ok = true;
66
67 } else {
68 ok = true;
69 QString id = attributes.value("id");
70 name.append(id);
71 m_model->addInfo(name, attributes.value("value"));
72
73 }
74
75 if (!ok) {
76 std::cerr << "WARNING: connexion config-XML: Failed to completely process element \""
77 << name.toLocal8Bit().data() << "\"" << std::endl;
78 }
79
80 return true;
81 }
82
83 bool AudioSourceInfoHandler::endElement(const QString &namespaceURI, const QString &localName,
84 const QString &qName)
85 {
86 return true;
87 }
88
89 bool AudioSourceInfoHandler::characters(const QString &str)
90 {
91 return true;
92 }
93
94 bool AudioSourceInfoHandler::error(const QXmlParseException &exception)
95 {
96 QString errorString;
97 errorString += QString("ERROR: connexion config-XML: %1 at line %2, column %3")
98 .arg(exception.message())
99 .arg(exception.lineNumber())
100 .arg(exception.columnNumber());
101 std::cerr << errorString.toLocal8Bit().data() << std::endl;
102 return QXmlDefaultHandler::error(exception);
103 }
104
105 bool AudioSourceInfoHandler::fatalError(const QXmlParseException &exception)
106 {
107 QString errorString;
108 errorString += QString("FATAL ERROR: connexion config-XML: %1 at line %2, column %3")
109 .arg(exception.message())
110 .arg(exception.lineNumber())
111 .arg(exception.columnNumber());
112 std::cerr << errorString.toLocal8Bit().data() << std::endl;
113 return QXmlDefaultHandler::fatalError(exception);
114 }