Honor cachedUntil when fetching current skill
authorjasu <jasu@skeletor.(none)>
Tue, 11 May 2010 07:06:21 +0000 (10:06 +0300)
committerjasu <jasu@skeletor.(none)>
Tue, 11 May 2010 07:06:21 +0000 (10:06 +0300)
src/eveaccount.cpp
src/eveskilltraining.cpp
src/eveskilltraining.h

index 10f68fa..ea32488 100644 (file)
@@ -7,6 +7,7 @@
 #include <QNetworkRequest>
 #include <QNetworkReply>
 #include <QtDebug>
+
 EveCharacter::EveCharacter(QObject *parent) :
     QObject(parent),
     characterId(0),
index c672b6a..e86fc08 100644 (file)
@@ -33,15 +33,13 @@ bool EveSkillTraining::fromXml(QXmlStreamReader &xml)
         return false;
 
     xml.readNextStartElement(); // end currentTime element
-    xml.readNextStartElement(); // start result element
+    bool inResult = xml.readNextStartElement(); // start result element
     if (xml.name() != "result") {
         qDebug() << "Wrong element:" << xml.name();
         return false;
     }
-    qDebug() << "passed, element is result";
-    bool inResult = true;
+
     while (inResult) {
-        inResult = xml.readNextStartElement();
         qDebug() << "element:" << xml.name();
         if (xml.name() == "trainingEndTime") {
             qDebug() << "Parse end time";
@@ -74,16 +72,19 @@ bool EveSkillTraining::fromXml(QXmlStreamReader &xml)
             currentTime = QDateTime::fromString(xml.readElementText(),"yyyy-MM-dd hh:mm:ss");
             startTime.setTimeSpec(Qt::UTC);
             qDebug() << "Current: " << currentTime;
-        } else
+        } if (xml.name() == "cachedUntil" ) {
+            cachedUntil = QDateTime::fromString(xml.readElementText(),"yyyy-MM-dd hh:mm:ss");
+            cachedUntil.setTimeSpec(Qt::UTC);
+            qDebug() << "Cached until " << cachedUntil.toString(Qt::SystemLocaleShortDate);
+        } else {
             // Noop
+            qDebug() << "  Skip this";
             xml.skipCurrentElement();
+        }
+        inResult = xml.readNextStartElement();
 
     } // while
-    bool cached = xml.readNextStartElement(); // cachedUntil
-    if (cached) {
-        QDateTime cachedTime = QDateTime::fromString(xml.readElementText(),"yyyy-MM-dd hh:mm:ss");
-        cachedTime.setTimeSpec(Qt::UTC);
-    }
+
     qDebug() << "Parsing finished";
     return true;
 }
@@ -92,6 +93,12 @@ void EveSkillTraining::fetchInfo()
 {
     if (m_character == NULL || m_account == NULL)
         return;
+    if (cachedUntil.isValid()) {
+        if (cachedUntil > QDateTime::currentDateTime().toUTC() ) {
+            qDebug() << "Cached until " << cachedUntil.toString(Qt::SystemLocaleShortDate);
+            return;
+        }
+    }
     QNetworkRequest req(QUrl(QString("http://api.eveonline.com/char/SkillInTraining.xml.aspx?apiKey=%1&userID=%2&characterID=%3")
                              .arg(m_account->apiKey())
                              .arg(m_account->userId())
index d48b58a..d35fe97 100644 (file)
@@ -42,6 +42,7 @@ private:
     EveModel *m_account;
     QNetworkAccessManager m_mgr;
     QNetworkReply *m_reply;
+    QDateTime cachedUntil;
 };
 
 #endif // EVESKILLTRAINING_H