1 // Copyright (C) 2010 Jaakko Kyro <jkyro@korjaussarja.net>
2 // This file is licenced under GPL, see COPYING
3 // for full licence information
4 #include "eveskilltraining.h"
6 #include "eveaccount.h"
8 #include <QXmlStreamReader>
9 #include <QNetworkAccessManager>
10 #include <QNetworkRequest>
11 #include <QNetworkReply>
13 EveSkillTraining::EveSkillTraining(QObject *parent) :
22 bool EveSkillTraining::fromXml(QXmlStreamReader &xml)
24 xml.readNextStartElement();
25 if (xml.name() != "eveapi")
27 xml.readNextStartElement();
28 if (xml.name() != "currentTime") {
32 currentTime = QDateTime::fromString(xml.readElementText(),"yyyy-MM-dd hh:mm:ss");
33 //xml.readNextStartElement(); // end currentTime element
34 bool inResult = xml.readNextStartElement(); // start result element
35 if (xml.name() != "result") {
36 qDebug() << "Wrong element:" << xml.name();
39 inResult = xml.readNextStartElement();
40 if (!inResult || xml.name() != "rowset" ) {
41 qDebug() << "No rowset element";
44 inResult = xml.readNextStartElement();
46 if (xml.name() == "row") {
48 entry.typeId = xml.attributes().value("","typeID").toString().toInt();
49 entry.destSkillpoints = xml.attributes().value("","endSP").toString().toInt();
50 entry.startSkillpoints = xml.attributes().value("","startSP").toString().toInt();
51 entry.level = xml.attributes().value("","level").toString().toInt();
52 if (xml.attributes().hasAttribute("","startTime")) {
53 entry.startTime = QDateTime::fromString(xml.attributes().value("","startTime").toString(),
54 "yyyy-MM-dd hh:mm:ss");
55 entry.startTime.setTimeSpec(Qt::UTC);
57 if (xml.attributes().hasAttribute("","endTime")) {
58 entry.endTime = QDateTime::fromString(xml.attributes().value("","endtTime").toString(),
59 "yyyy-MM-dd hh:mm:ss");
60 entry.endTime.setTimeSpec(Qt::UTC);
62 m_trainingQueue.append(entry);
66 if (xml.name() == "cachedUntil" ) {
67 cachedUntil = QDateTime::fromString(xml.readElementText(),"yyyy-MM-dd hh:mm:ss");
68 cachedUntil.setTimeSpec(Qt::UTC);
69 qDebug() << "Cached until " << cachedUntil.toString(Qt::SystemLocaleShortDate);
71 qDebug() << "Parsing finished";
75 void EveSkillTraining::fetchInfo()
77 if (m_character == NULL || m_account == NULL)
79 if (cachedUntil.isValid()) {
80 if (cachedUntil > QDateTime::currentDateTime().toUTC() ) {
81 qDebug() << "Cached until " << cachedUntil.toString(Qt::SystemLocaleShortDate);
85 QNetworkRequest req(QUrl(QString("http://api.eveonline.com/char/SkillQueue.xml.aspx?apiKey=%1&userID=%2&characterID=%3")
86 .arg(m_account->apiKey())
87 .arg(m_account->userId())
88 .arg(m_character->characterId)));
89 m_reply = m_mgr.get(req);
90 connect(m_reply,SIGNAL(finished()),this,SLOT(infoReady()));
93 void EveSkillTraining::infoReady()
95 if (m_reply->error()) {
96 qDebug() << "Failed! " << m_reply->errorString();
99 qDebug() << "Skill reply";
100 QByteArray reply = m_reply->readAll();
101 qDebug() << "Reply ready";
103 QXmlStreamReader reader(reply);
105 m_reply->deleteLater();