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>
11 EveCharacter::EveCharacter(QObject *parent) :
19 EveCharacter::EveCharacter(const EveCharacter &aOther):
20 QObject(aOther.parent()),
22 corpName(aOther.corpName),
23 characterId(aOther.characterId),
24 corpId(aOther.corpId),
27 if (aOther.characterIcon) {
28 characterIcon = new QPixmap(*(aOther.characterIcon));
32 EveCharacter::~EveCharacter()
39 EveCharacter &EveCharacter::operator =(const EveCharacter &other)
42 characterId = other.characterId;
43 corpId = other.corpId;
44 corpName = other.corpName;
45 qDebug() << "Assignment, characterIcon " << characterIcon;
46 if (characterIcon != NULL) {
50 qDebug() << " after deletion";
51 qDebug() << " other icon" << other.characterIcon;
52 if (other.characterIcon != NULL)
53 characterIcon = new QPixmap(*(other.characterIcon));
54 qDebug() << "Assignment done";
58 bool EveCharacter::fromXml(QXmlStreamReader &xml)
60 if (xml.name() != "row")
62 name = xml.attributes().value("","name").toString();
63 characterId = xml.attributes().value("","characterID").toString().toInt();
64 corpName = xml.attributes().value("","corporationName").toString();
65 corpId = xml.attributes().value("","corporationID").toString().toInt();
69 bool EveCharacter::fetchImage()
71 if (characterId == 0) {
72 qDebug() << "No character";
75 if (characterIcon != NULL) {
79 qDebug() << "Requesting image";
80 QNetworkRequest req(QUrl(QString("http://img.eve.is/serv.asp?c=%1&s=64").arg(characterId)));
81 m_reply = mgr.get(req);
82 connect(m_reply,SIGNAL(finished()),this,SLOT(imageReady()));
86 // Construct the pixmap from the reply data
87 // and delete the reply
88 void EveCharacter::imageReady()
90 qDebug() << "Image ready";
91 characterIcon = new QPixmap;
92 if (!characterIcon->loadFromData(m_reply->readAll())) {
95 qDebug() << "Cannot load image";
98 m_reply->deleteLater();