Syndication

feedatomimpl.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 "feedatomimpl.h"
9#include "categoryatomimpl.h"
10#include "imageatomimpl.h"
11#include "itematomimpl.h"
12#include <atom/category.h>
13#include <atom/entry.h>
14#include <atom/link.h>
15#include <atom/person.h>
16#include <personimpl.h>
17
18#include <QDomElement>
19#include <QList>
20#include <QMultiMap>
21#include <QString>
22
23namespace Syndication
24{
25FeedAtomImpl::FeedAtomImpl(Syndication::Atom::FeedDocumentPtr doc)
26 : m_doc(doc)
27{
28}
29
30Syndication::SpecificDocumentPtr FeedAtomImpl::specificDocument() const
31{
32 return m_doc;
33}
34
35QList<Syndication::ItemPtr> FeedAtomImpl::items() const
36{
37 const QList<Syndication::Atom::Entry> entries = m_doc->entries();
38
39 QList<ItemPtr> items;
40 items.reserve(entries.count());
41
42 std::transform(entries.cbegin(), entries.cend(), std::back_inserter(items), [](const Syndication::Atom::Entry &entry) {
43 return ItemAtomImplPtr(new ItemAtomImpl(entry));
44 });
45
46 return items;
47}
48
49QList<Syndication::CategoryPtr> FeedAtomImpl::categories() const
50{
51 const QList<Syndication::Atom::Category> entries = m_doc->categories();
52 QList<CategoryPtr> categories;
53 categories.reserve(entries.count());
54
55 std::transform(entries.cbegin(), entries.cend(), std::back_inserter(categories), [](const Syndication::Atom::Category &entry) {
56 return CategoryAtomImplPtr(new CategoryAtomImpl(entry));
57 });
58
59 return categories;
60}
61
62QString FeedAtomImpl::title() const
63{
64 return m_doc->title();
65}
66
67QString FeedAtomImpl::link() const
68{
69 const QList<Syndication::Atom::Link> links = m_doc->links();
70 // return first link where rel="alternate"
71 // TODO: if there are multiple "alternate" links, find other criteria to choose one of them
72 auto it = std::find_if(links.cbegin(), links.cend(), [](const Syndication::Atom::Link &link) {
73 return link.rel() == QLatin1String("alternate");
74 });
75 return it != links.cend() ? it->href() : QString{};
76}
77
78QString FeedAtomImpl::description() const
79{
80 return m_doc->subtitle();
81}
82
83QList<PersonPtr> FeedAtomImpl::authors() const
84{
85 const QList<Syndication::Atom::Person> people = m_doc->authors() + m_doc->contributors();
86
88 list.reserve(people.size());
89
90 std::transform(people.cbegin(), people.cend(), std::back_inserter(list), [](const Syndication::Atom::Person &person) {
91 return PersonImplPtr(new PersonImpl(person.name(), person.uri(), person.email()));
92 });
93
94 return list;
95}
96
97QString FeedAtomImpl::language() const
98{
99 return m_doc->xmlLang();
100}
101
102QString FeedAtomImpl::copyright() const
103{
104 return m_doc->rights();
105}
106
107ImagePtr FeedAtomImpl::image() const
108{
109 return ImageAtomImplPtr(new ImageAtomImpl(m_doc->logo()));
110}
111
112ImagePtr FeedAtomImpl::icon() const
113{
114 return ImageAtomImplPtr(new ImageAtomImpl(m_doc->icon()));
115}
116
117QMultiMap<QString, QDomElement> FeedAtomImpl::additionalProperties() const
118{
120 const auto unhandledElements = m_doc->unhandledElements();
121 for (const QDomElement &i : unhandledElements) {
122 ret.insert(i.namespaceURI() + i.localName(), i);
123 }
124
125 return ret;
126}
127
128} // namespace Syndication
A category for categorizing items or whole feeds.
an Atom entry, equivalent to the "items" in the RSS world.
Definition entry.h:39
describes a person, with name and optional URI and e-mail address.
Definition atom/person.h:27
const_iterator cbegin() const const
const_iterator cend() const const
qsizetype count() const const
void reserve(qsizetype size)
qsizetype size() const const
iterator insert(const Key &key, const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.