-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaxknotsitemhandler.cpp
More file actions
executable file
·92 lines (75 loc) · 2.62 KB
/
Copy pathsaxknotsitemhandler.cpp
File metadata and controls
executable file
·92 lines (75 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "saxknotsitemhandler.h"
#include "knotsitem.h"
SaxKnotsItemHandler::SaxKnotsItemHandler( )
{
}
void SaxKnotsItemHandler::setItemHandler( SaxKnotsItemHandlerParserObserver* observer )
{
_observer = observer;
}
bool SaxKnotsItemHandler::startDocument()
{
_numberItems = 0;
return true;
}
bool SaxKnotsItemHandler::startElement(const QString & /* namespaceURI */,
const QString &localName,
const QString &/*qName*/,
const QXmlAttributes &/*attributes*/)
{
if( localName == "item") {
_currentItem = new KnotsItem();
_currentState = ParsingItem;
} else if( localName == "pages" ) {
_currentState = ParsingPage;
} else if( localName == "items" ) {
_currentState = ParsingItems;
}
_currentText.clear();
return true;
}
bool SaxKnotsItemHandler::endElement(const QString & /* namespaceURI */,
const QString &localName ,
const QString &/*qName*/)
{
if( _currentState == ParsingItem ) {
if( localName == "dir" ) {
_currentItem->setDirectoryId(_currentText);
} else if ( localName == "id" ) {
_currentItem->setId(_currentText);
} else if ( localName == "mediatype" ) {
_currentItem->setMediaType(_currentText);
} else if ( localName == "mid" ) {
_currentItem->setMid(_currentText);
}
// While parsing the item element, add each field to the hash table, its used later when fetching media from server.
if( localName != "item" ) {
// Store this data to the item hash fields.
_currentItem->getFields().insert(localName,_currentText);
}
//if this is the end of the item element, then call retrieveData to pull info about this item
if( localName == "item" ) {
_currentItem->retrieveData();
_observer->handleNewItem(_currentItem);
}
} else if( _currentState == ParsingPage ) {
if(localName == "current"){
_currentPage = _currentText.toInt();
} else if( localName == "total") {
_totalPages = _currentText.toInt();
} else if( localName == "pages" )
{
_observer->handlePages(_totalPages, _currentPage );
}
}
return true;
}
bool SaxKnotsItemHandler::characters(const QString &str)
{
_currentText += str;
return true;
}
bool SaxKnotsItemHandler::fatalError(const QXmlParseException &/*exception*/)
{
return false;
}