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 "eveaccount.h"
5 #include "QXmlStreamReader"
6 #include <QNetworkAccessManager>
7 #include <QNetworkRequest>
8 #include <QNetworkReply>
10 EveCharacter::EveCharacter(QObject *parent) :
18 EveCharacter::EveCharacter(const EveCharacter &aOther):
19 QObject(aOther.parent()),
21 corpName(aOther.corpName),
22 characterId(aOther.characterId),
23 corpId(aOther.corpId),
26 if (aOther.characterIcon) {
27 characterIcon = new QPixmap(*(aOther.characterIcon));
31 EveCharacter::~EveCharacter()
38 EveCharacter &EveCharacter::operator =(const EveCharacter &other)
41 characterId = other.characterId;
42 corpId = other.corpId;
43 corpName = other.corpName;
44 qDebug() << "Assignment, characterIcon " << characterIcon;
45 if (characterIcon != NULL) {
49 qDebug() << " after deletion";
50 qDebug() << " other icon" << other.characterIcon;
51 if (other.characterIcon != NULL)
52 characterIcon = new QPixmap(*(other.characterIcon));
53 qDebug() << "Assignment done";
57 bool EveCharacter::fromXml(QXmlStreamReader &xml)
59 if (xml.name() != "row")
61 name = xml.attributes().value("","name").toString();
62 characterId = xml.attributes().value("","characterID").toString().toInt();
63 corpName = xml.attributes().value("","corporationName").toString();
64 corpId = xml.attributes().value("","corporationID").toString().toInt();
68 bool EveCharacter::fetchImage()
70 if (characterId == 0) {
71 qDebug() << "No character";
74 if (characterIcon != NULL) {
78 qDebug() << "Requesting image";
79 QNetworkRequest req(QUrl(QString("http://img.eve.is/serv.asp?c=%1&s=64").arg(characterId)));
80 m_reply = mgr.get(req);
81 connect(m_reply,SIGNAL(finished()),this,SLOT(imageReady()));
85 // Construct the pixmap from the reply data
86 // and delete the reply
87 void EveCharacter::imageReady()
89 qDebug() << "Image ready";
90 characterIcon = new QPixmap;
91 if (!characterIcon->loadFromData(m_reply->readAll())) {
94 qDebug() << "Cannot load image";
97 m_reply->deleteLater();