-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasteinfo.cpp
199 lines (167 loc) · 4.17 KB
/
pasteinfo.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "pasteinfo.h"
#include <QXmlStreamReader>
#include <QDebug>
PasteInfo::PasteInfo(QObject *parent)
: QObject(parent)
{
}
QString PasteInfo::key() const
{
return m_key;
}
void PasteInfo::setKey(const QString &key)
{
m_key = key;
}
QString PasteInfo::postDate() const
{
return m_postDate;
}
void PasteInfo::setPostDate(const QString &date)
{
m_postDate = date;
}
QString PasteInfo::title() const
{
return m_title;
}
void PasteInfo::setTitle(const QString &title)
{
m_title = title;
}
quint32 PasteInfo::size() const
{
return m_size;
}
void PasteInfo::setSize(quint32 size)
{
m_size = size;
}
QString PasteInfo::expireDate() const
{
return m_expireDate;
}
void PasteInfo::setExpireDate(const QString &expire)
{
m_expireDate = expire;
}
PasteInfo::Visibility PasteInfo::visibility() const
{
return m_visibility;
}
void PasteInfo::setVisibiliy(PasteInfo::Visibility visibility)
{
m_visibility = visibility;
}
QString PasteInfo::longFormat() const
{
return m_longFormat;
}
void PasteInfo::setLongFormat(const QString &format)
{
m_longFormat = format;
}
QString PasteInfo::shortFormat() const
{
return m_shortFormat;
}
void PasteInfo::setShortFormat(const QString &format)
{
m_shortFormat = format;
}
QUrl PasteInfo::url() const
{
return m_url;
}
void PasteInfo::setUrl(const QUrl &url)
{
m_url = url;
}
quint32 PasteInfo::hits() const
{
return m_hits;
}
void PasteInfo::setHits(quint32 hits)
{
m_hits = hits;
}
QList<PasteInfo* > PasteInfo::fromList(const QByteArray &data)
{
QList<PasteInfo*> pastes;
QXmlStreamReader reader(data);
while(!reader.atEnd())
{
PasteInfo* info = NULL;
if (reader.name() == "paste")
{
info = new PasteInfo;
while(!(reader.name() == "paste" && reader.isEndElement()))
{
reader.readNext();
if (reader.name().isEmpty())
continue;
if (reader.name() == "paste_key")
{
info->setKey(reader.readElementText());
}
else if (reader.name() == "paste_date")
{
info->setPostDate(reader.readElementText());
}
else if (reader.name() == "paste_title")
{
info->setTitle(reader.readElementText());
}
else if (reader.name() == "paste_size")
{
info->setSize(reader.readElementText().toInt());
}
else if (reader.name() == "paste_expire_date")
{
info->setExpireDate(reader.readElementText());
}
else if (reader.name() == "paste_private")
{
Visibility vis = (Visibility)(reader.readElementText().toInt());
info->setVisibiliy(vis);
}
else if (reader.name() == "paste_format_long")
{
info->setLongFormat(reader.readElementText());
}
else if (reader.name() == "paste_format_short")
{
info->setShortFormat(reader.readElementText());
}
else if (reader.name() == "paste_url")
{
info->setUrl(reader.readElementText());
}
else if (reader.name() == "paste_hits")
{
info->setHits(reader.readElementText().toInt());
}
}
}
// Is the paste valid?
if (info)
{
// Add it to the list
pastes.append(info);
}
reader.readNext();
}
return pastes;
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const PasteInfo* pasteinfo)
{
if (!pasteinfo)
return debug << "PasteInfo(0x0)";
debug.nospace() << pasteinfo->metaObject()->className() << '(' << (void*) pasteinfo;
if (!pasteinfo->objectName().isEmpty())
debug << ", name = " << pasteinfo->objectName();
debug << ")";
return debug.space();
}
#endif