Syndication

atom/source.cpp
1/*
2 This file is part of the syndication library
3 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "source.h"
9#include "atomtools.h"
10#include "category.h"
11#include "constants.h"
12#include "generator.h"
13#include "link.h"
14#include "person.h"
15
16#include <tools.h>
17
18#include <QDomElement>
19#include <QList>
20#include <QString>
21
22namespace Syndication
23{
24namespace Atom
25{
27 : ElementWrapper()
28{
29}
30
32 : ElementWrapper(element)
33{
34}
35
37{
38 const QList<QDomElement> a = elementsByTagNameNS(atom1Namespace(), QStringLiteral("author"));
39
40 QList<Person> list;
41 list.reserve(a.count());
42
43 std::transform(a.cbegin(), a.cend(), std::back_inserter(list), [](const QDomElement &element) {
44 return Person(element);
45 });
46
47 return list;
48}
49
51{
52 const QList<QDomElement> a = elementsByTagNameNS(atom1Namespace(), QStringLiteral("contributor"));
53 QList<Person> list;
54 list.reserve(a.count());
55
56 std::transform(a.cbegin(), a.cend(), std::back_inserter(list), [](const QDomElement &element) {
57 return Person(element);
58 });
59
60 return list;
61}
62
64{
65 const QList<QDomElement> a = elementsByTagNameNS(atom1Namespace(), QStringLiteral("category"));
66 QList<Category> list;
67 list.reserve(a.count());
68
69 std::transform(a.cbegin(), a.cend(), std::back_inserter(list), [](const QDomElement &element) {
70 return Category(element);
71 });
72
73 return list;
74}
75
77{
78 return Generator(firstElementByTagNameNS(atom1Namespace(), QStringLiteral("generator")));
79}
80
82{
83 return extractElementTextNS(atom1Namespace(), QStringLiteral("icon"));
84}
85
87{
88 return extractElementTextNS(atom1Namespace(), QStringLiteral("id"));
89}
90
92{
93 const QList<QDomElement> a = elementsByTagNameNS(atom1Namespace(), QStringLiteral("link"));
94 QList<Link> list;
95 list.reserve(a.count());
96
97 std::transform(a.cbegin(), a.cend(), std::back_inserter(list), [](const QDomElement &element) {
98 return Link(element);
99 });
100
101 return list;
102}
103
105{
106 return extractElementTextNS(atom1Namespace(), QStringLiteral("logo"));
107}
108
110{
111 return extractAtomText(*this, QStringLiteral("rights"));
112}
113
115{
116 return extractAtomText(*this, QStringLiteral("subtitle"));
117}
118
120{
121 return extractAtomText(*this, QStringLiteral("title"));
122}
123
124time_t Source::updated() const
125{
126 const QString upd = extractElementTextNS(atom1Namespace(), QStringLiteral("updated"));
127 return parseDate(upd, ISODate);
128}
129
131{
132 QString info = QLatin1String("### Source: ###################\n");
133 if (!title().isEmpty()) {
134 info += QLatin1String("title: #") + title() + QLatin1String("#\n");
135 }
136 if (!subtitle().isEmpty()) {
137 info += QLatin1String("subtitle: #") + subtitle() + QLatin1String("#\n");
138 }
139 if (!id().isEmpty()) {
140 info += QLatin1String("id: #") + id() + QLatin1String("#\n");
141 }
142
143 if (!rights().isEmpty()) {
144 info += QLatin1String("rights: #") + rights() + QLatin1String("#\n");
145 }
146 if (!icon().isEmpty()) {
147 info += QLatin1String("icon: #") + icon() + QLatin1String("#\n");
148 }
149 if (!logo().isEmpty()) {
150 info += QLatin1String("logo: #") + logo() + QLatin1String("#\n");
151 }
152 if (!generator().isNull()) {
153 info += generator().debugInfo();
154 }
155
156 QString dupdated = dateTimeToString(updated());
157 if (!dupdated.isNull()) {
158 info += QLatin1String("updated: #") + dupdated + QLatin1String("#\n");
159 }
160
161 const QList<Link> dlinks = links();
162 for (const auto &link : dlinks) {
163 info += link.debugInfo();
164 }
165
166 const QList<Category> dcats = categories();
167 for (const auto &cat : dcats) {
168 info += cat.debugInfo();
169 }
170
171 info += QLatin1String("### Authors: ###################\n");
172
173 const QList<Person> dauthors = authors();
174 for (const auto &author : dauthors) {
175 info += author.debugInfo();
176 }
177
178 info += QLatin1String("### Contributors: ###################\n");
179
180 const QList<Person> dcontri = contributors();
181 for (const auto &person : dcontri) {
182 info += person.debugInfo();
183 }
184
185 info += QLatin1String("### Source end ################\n");
186
187 return info;
188}
189
190} // namespace Atom
191} // namespace Syndication
Description of the agent used to generate the feed.
Definition generator.h:26
QString debugInfo() const
a description of this generator for debugging purposes.
Definition generator.cpp:42
time_t updated() const
The datetime of the last modification of the source feed content.
QList< Person > contributors() const
contributors to the original content (optional)
QString id() const
a string that unambiguously identifies the source feed (optional)
QString title() const
source feed title (optional).
QList< Person > authors() const
authors of the original content (optional)
QString debugInfo() const
description of this source object for debugging purposes
QString subtitle() const
description or subtitle of the source feed (optional).
QString rights() const
copyright information (optional)
QString icon() const
URL of an image serving as a feed icon (optional)
Source()
creates a null source object
Generator generator() const
description of the software which generated the source feed (optional)
QString logo() const
URL of an image, the logo of the source feed (optional)
QList< Category > categories() const
categories the source feed is assigned to (optional)
QList< Link > links() const
a list of links.
QString atom1Namespace()
namespace used by Atom 1.0 elements
QString extractAtomText(const Syndication::ElementWrapper &parent, const QString &tagname)
extracts the content of an atomTextConstruct.
Definition atomtools.cpp:21
const_iterator cbegin() const const
const_iterator cend() const const
qsizetype count() const const
void reserve(qsizetype size)
bool isNull() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:15 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.