1 #include "eveaccount.h"
2 #include "QXmlStreamReader"
3 #include <QNetworkAccessManager>
4 #include <QNetworkRequest>
5 #include <QNetworkReply>
7 EveCharacter::EveCharacter(QObject *parent) :
15 EveCharacter::EveCharacter(const EveCharacter &aOther):
16 QObject(aOther.parent()),
18 corpName(aOther.corpName),
19 characterId(aOther.characterId),
20 corpId(aOther.corpId),
23 if (aOther.characterIcon) {
24 characterIcon = new QPixmap(*(aOther.characterIcon));
28 EveCharacter::~EveCharacter()
35 EveCharacter &EveCharacter::operator =(const EveCharacter &other)
38 characterId = other.characterId;
39 corpId = other.corpId;
40 corpName = other.corpName;
41 qDebug() << "Assignment, characterIcon " << characterIcon;
42 if (characterIcon != NULL) {
46 qDebug() << " after deletion";
47 qDebug() << " other icon" << other.characterIcon;
48 if (other.characterIcon != NULL)
49 characterIcon = new QPixmap(*(other.characterIcon));
50 qDebug() << "Assignment done";
54 bool EveCharacter::fromXml(QXmlStreamReader &xml)
56 if (xml.name() != "row")
58 name = xml.attributes().value("","name").toString();
59 characterId = xml.attributes().value("","characterID").toString().toInt();
60 corpName = xml.attributes().value("","corporationName").toString();
61 corpId = xml.attributes().value("","corporationID").toString().toInt();
65 bool EveCharacter::fetchImage()
67 if (characterId == 0) {
68 qDebug() << "No character";
71 if (characterIcon != NULL) {
75 qDebug() << "Requesting image";
76 QNetworkRequest req(QUrl(QString("http://img.eve.is/serv.asp?c=%1&s=64").arg(characterId)));
77 m_reply = mgr.get(req);
78 connect(m_reply,SIGNAL(finished()),this,SLOT(imageReady()));
82 // Construct the pixmap from the reply data
83 // and delete the reply
84 void EveCharacter::imageReady()
86 qDebug() << "Image ready";
87 characterIcon = new QPixmap;
88 if (!characterIcon->loadFromData(m_reply->readAll())) {
91 qDebug() << "Cannot load image";
94 m_reply->deleteLater();