-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgmailatom.cpp
74 lines (65 loc) · 2.32 KB
/
gmailatom.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
/**
* This file is Copyright 2012
* Kristian Beres <[email protected]>
*
* Other copyrights also apply to some parts of this work. Please
* see the individual file headers for details.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version. See the file
* COPYING included with this distribution for more information.
*/
#include "gmailatom.h"
#include <QDebug>
#include <QNetworkReply>
#include <QDomDocument>
#include "email.h"
/***
<entry>
<title>email title</title>
<summary>email summary</summary>
<link rel="alternate" href="link_to_the_email" type="text/html"/>
<modified>2012-09-25T14:16:49Z</modified>
<issued>2012-09-25T14:16:49Z</issued>
<id>tag:gmail.google.com,2004:1414091358027121800</id>
<author>
<name>Kristian</name>
<email>[email protected]</email>
</author>
</entry>
*/
GmailAtom::GmailAtom(QNetworkReply *reply)
{
if(!document.setContent(reply)){
qDebug() << "Failed to load document";
}
//qDebug() << document.toString();
}
QMap<int, Email> GmailAtom::fetch(){
//qDebug() << document.toString();
QDomNodeList items = document.elementsByTagName("entry");
int cnt = items.count();
QMap<int, Email> Emails;
if(cnt > 0){
qDebug() << items.count();
//QDomElement rootOfEntry = document.firstChildElement();
for(int i=0; i < cnt; i++){
QDomElement rootOfEntry = items.at(i).toElement();
Email email;
email.setTitle(rootOfEntry.elementsByTagName("title").at(0).toElement().text().trimmed());
email.setSummary(rootOfEntry.elementsByTagName("summary").at(0).toElement().text().trimmed());
email.setAuthorName(rootOfEntry.elementsByTagName("name").at(0).toElement().text().trimmed());
email.setLink(rootOfEntry.elementsByTagName("link").at(0).toElement().attribute("href").trimmed());
email.setIssued(rootOfEntry.elementsByTagName("issued").at(0).toElement().text().trimmed());
Emails.insert(i, email);
}
document.clear();
}else{
qDebug() << "XML empty";
}
return Emails;
}
GmailAtom::~GmailAtom(){
}