13 #include "enclosure.h"
19 #include <kurllabel.h>
22 #include <tqdatetime.h>
31 struct Article::Private :
public Shared
56 Enclosure Article::enclosure()
const
67 Article::Article(
const TQDomNode &node, Format format, Version version) : d(new Private)
73 if (!(elemText = extractTitle(node)).isNull())
79 for (n = node.firstChild(); !n.isNull(); n = n.nextSibling()) {
80 const TQDomElement e = n.toElement();
81 if ( (e.tagName()==TQString::fromLatin1(
"link")) &&
82 (e.attribute(TQString::fromLatin1(
"rel"), TQString::fromLatin1(
"alternate")) == TQString::fromLatin1(
"alternate")))
84 d->link=n.toElement().attribute(TQString::fromLatin1(
"href"));
91 if (!(elemText = extractNode(node, TQString::fromLatin1(
"link"))).isNull())
97 TQString tagName=(format==AtomFeed)? TQString::fromLatin1(
"content"): TQString::fromLatin1(
"content:encoded");
99 if (!(elemText = extractNode(node, tagName,
false)).isNull())
100 d->description = elemText;
102 if (d->description.isEmpty())
104 if (!(elemText = extractNode(node, TQString::fromLatin1(
"body"),
false)).isNull())
105 d->description = elemText;
107 if (d->description.isEmpty())
109 if (!(elemText = extractNode(node, TQString::fromLatin1((format==AtomFeed)?
"summary" :
"description"),
false)).isNull())
110 d->description = elemText;
116 if (format == AtomFeed)
118 if (version == vAtom_1_0)
119 elemText = extractNode(node, TQString::fromLatin1(
"updated"));
121 elemText = extractNode(node, TQString::fromLatin1(
"issued"));
123 if (!elemText.isNull())
124 time = parseISO8601Date(elemText);
128 elemText = extractNode(node, TQString::fromLatin1(
"pubDate"));
129 if (!elemText.isNull())
130 time = KRFCDate::parseDate(elemText);
133 if (!(elemText = extractNode(node, TQString::fromLatin1(
"dc:date"))).isNull())
135 time = parseISO8601Date(elemText);
140 d->pubDate.setTime_t(time);
142 if (!(elemText = extractNode(node, TQString::fromLatin1(
"wfw:comment"))).isNull()) {
143 d->commentsLink = elemText;
146 if (!(elemText = extractNode(node, TQString::fromLatin1(
"slash:comments"))).isNull()) {
147 d->numComments = elemText.toInt();
150 TQDomElement element = TQDomNode(node).toElement();
155 if (!element.isNull() && element.hasAttribute(TQString::fromLatin1(
"rdf:about")))
157 d->guid = element.attribute(TQString::fromLatin1(
"rdf:about"));
158 d->guidIsPermaLink =
false;
162 tagName=(format==AtomFeed)? TQString::fromLatin1(
"id"): TQString::fromLatin1(
"guid");
163 TQDomNode n = node.namedItem(tagName);
166 d->guidIsPermaLink = (format==AtomFeed)?
false :
true;
167 if (n.toElement().attribute(TQString::fromLatin1(
"isPermaLink"),
"true") ==
"false") d->guidIsPermaLink =
false;
168 if (!(elemText = extractNode(node, tagName)).isNull())
173 if(d->guid.isEmpty()) {
174 d->guidIsPermaLink =
false;
178 md5Machine.update(d->title.utf8());
179 md5Machine.update(d->description.utf8());
180 d->guid = TQString(md5Machine.hexDigest().data());
181 d->meta[TQString::fromLatin1(
"guidIsHash")] = TQString::fromLatin1(
"true");
184 TQDomNode enclosure = element.namedItem(TQString::fromLatin1(
"enclosure"));
185 if (enclosure.isElement())
186 d->enclosure = Enclosure::fromXML(enclosure.toElement());
188 d->author = parseItemAuthor(element, format, version);
190 for (TQDomNode i = node.firstChild(); !i.isNull(); i = i.nextSibling())
194 if (i.toElement().tagName() == TQString::fromLatin1(
"metaInfo:meta"))
196 TQString type = i.toElement().attribute(TQString::fromLatin1(
"type"));
197 d->meta[type] = i.toElement().text();
199 else if (i.toElement().tagName() == TQString::fromLatin1(
"category"))
201 d->categories.append(Category::fromXML(i.toElement()));
230 return d->description;
240 return d->guidIsPermaLink;
248 const KURL &Article::commentsLink()
const
250 return d->commentsLink;
253 int Article::comments()
const
255 return d->numComments;
259 TQString Article::meta(
const TQString &key)
const
266 KURLLabel *label =
new KURLLabel(d->link.url(), d->title, parent, name);
267 label->setUseTips(
true);
268 if (!d->description.isNull())
269 label->setTipText(d->description);
276 if (
this != &other) {
287 return d->guid == other.
guid();
Represents an article as stored in a RSS file.
Article & operator=(const Article &other)
Assignment operator.
TQString guid() const
RSS 2.0 and upwards.
TQValueList< Category > categories() const
returns a list of categories this article is assigned to.
bool operator==(const Article &other) const
Compares two articles.
KURLLabel * widget(TQWidget *parent=0, const char *name=0) const
TQString title() const
RSS 0.90 and upwards.
virtual ~Article()
Destructor.
bool guidIsPermaLink() const
RSS 2.0 and upwards.
TQString author() const
a string desribing the author of the item.
Article()
Default constructor.
const TQDateTime & pubDate() const
RSS 2.0 and upwards.
const KURL & link() const
RSS 0.90 and upwards.
TQString description() const
RSS 0.91 and upwards.