-
Notifications
You must be signed in to change notification settings - Fork 0
/
intel.cpp
121 lines (102 loc) · 3.4 KB
/
intel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "intel.h"
#include <QString>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrlQuery>
#include <openssl/aes.h>
#include <QDomDocument>
#include <QDomElement>
#include "filedownloader.h"
#include <QPixmap>
#include "intelmessages.h"
#include "intelmodel.h"
//QNetworkAccessManager *Intel::manager = new QNetworkAccessManager();
QMap<QString, QPixmap> Intel::portraitMap;
Intel::Intel(IntelMessages *intelMessage, QString system, QString reporter, QString dateTime, QString message, QString channelName, QObject *parent) : QObject(parent)
{
this->intelMessage = intelMessage;
this->channelName = channelName;
this->system = system;
this->reporter = reporter;
this->dateTime = dateTime;
this->message= message;
manager = new QNetworkAccessManager();
getPortrait(reporter);
}
QString Intel::getReporter()
{
return reporter;
}
QString Intel::getChannelName()
{
return channelName;
}
QString Intel::getMessage()
{
return message;
}
QString Intel::getDateTime()
{
return dateTime;
}
void Intel::getPortrait(QString name){
if(!manager)
manager = new QNetworkAccessManager();
if(portraitMap.contains(getReporter())){
portraitImage = portraitMap.value(getReporter());
//intelMessage->model->layoutChanged();
}
else{
QUrl url("https://api.eveonline.com/eve/CharacterID.xml.aspx");
QUrlQuery query;
query.addQueryItem("names", name);
url.setQuery(query);
QNetworkRequest request(url);
manager->get(request);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(portraitReply(QNetworkReply*)));
}
}
void Intel::portraitReply(QNetworkReply *reply)
{
QString data = reply->readAll();
QDomDocument doc = QDomDocument();
doc.setContent(data);
QDomElement docElem = doc.documentElement();
QDomElement Component=docElem.firstChild().nextSibling().firstChild().toElement();
QDomElement Child=Component.firstChild().toElement();
while (!Child.isNull())
{
if(Child.attribute("name").compare(this->getReporter()) == 0)
{
//qDebug() << Child.attribute("name");
//qDebug() << Child.attribute("characterID");
this->characterId = Child.attribute("characterID");
QUrl imageUrl("https://image.eveonline.com/Character/" + this->characterId + "_32.jpg");
m_pImgCtrl = new FileDownloader(imageUrl, this);
connect(m_pImgCtrl, SIGNAL (downloaded()), this, SLOT (loadImage()));
break;
}
Child = Child.nextSibling().toElement();
}
}
QString Intel::getIntelTextLayout()
{
QString intelMessage = "<table style=\"width:100%\"><tr>"
"<td style=\"padding:3px 8px 3px 3px;\">"
"<font style=\"font-size:10px;\">" + getDateTime() +"</font> - "
"<font style=\"font-size:10px; font-weight: bold;\">" + getReporter() +"</font> - "
"<font style=\"font-size:10px; font-style: italic;\">" + getChannelName() + "</font><br>"
"<font style=\"font-size:11px;\">" + getMessage() + "</font></td></tr>";
return intelMessage;
}
void Intel::loadImage()
{
portraitImage.loadFromData(m_pImgCtrl->downloadedData());
portraitMap.insert(getReporter(), portraitImage);
intelMessage->model->layoutChanged();
}
QPixmap Intel::getPortraitPixMap()
{
return portraitImage;
}