-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofileshandler.cpp
More file actions
executable file
·115 lines (85 loc) · 2.75 KB
/
profileshandler.cpp
File metadata and controls
executable file
·115 lines (85 loc) · 2.75 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <QVector>
#include "profileshandler.h"
#include "profile.h"
#include "knots.h"
ProfilesHandler::ProfilesHandler( QObject* parent )
: QObject( parent )
{
connect(&Knots::instance().serverConnection(), SIGNAL(finished(QNetworkReply*)), this, SLOT(onProfilesFetched(QNetworkReply*)));
}
bool ProfilesHandler::startDocument()
{
qDeleteAll(_profiles->begin(), _profiles->end());
return true;
}
void ProfilesHandler::loadProfiles() {
try {
_profiles = new ProfileListImpl();
QUrl requestAddress = Knots::instance().serverAddress();
requestAddress.setPath(+ "/external/transcoding_profiles");
QNetworkRequest request( requestAddress );
_profileFetch = Knots::instance().serverConnection().get(request);
}
catch(...)
{
qWarning() << "Failed to fetch profiles";
}
}
void ProfilesHandler::onProfilesFetched( QNetworkReply* reply )
{
if( reply == _profileFetch )
{
_xmlSource = new QXmlInputSource( _profileFetch );
_xmlReader = new QXmlSimpleReader;
_xmlReader->setContentHandler(this);
qWarning() << "Fetched from " << reply->url() ;
qWarning() << "Read " << reply->bytesAvailable() << " Bytes";
qWarning() << reply->peek( 256 );
_xmlReader->parse(_xmlSource );
delete _xmlSource;
delete _xmlReader;
_xmlReader = 0;
_profileFetch->deleteLater();
emit profilesChanged(_profiles);
}
}
bool ProfilesHandler::startElement(const QString & /* namespaceURI */,
const QString & /* localName */,
const QString &qName,
const QXmlAttributes &/*attributes*/)
{
if( qName == "item") {
_currentItem = new Profile();
}
_currentText.clear();
return true;
}
bool ProfilesHandler::endElement(const QString & /* namespaceURI */,
const QString &localName ,
const QString &/*qName*/)
{
if (localName =="id") {
_currentItem->setId( _currentText);
} else if( localName == "video_format") {
_currentItem->setCodec(_currentText);
} else if( localName == "video_bitrate") {
_currentItem->setBitrate(_currentText);
} else if( localName == "name") {
_currentItem->setName(_currentText);
} else if( localName == "item" )
(*_profiles)[_currentItem->getId()] = _currentItem;
return true;
}
bool ProfilesHandler::characters(const QString &str)
{
_currentText += str;
return true;
}
bool ProfilesHandler::fatalError(const QXmlParseException &/*exception*/)
{
return false;
}
ProfileListImpl* ProfilesHandler::profiles()
{
return _profiles;
}