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
36{
37 const QList<Syndication::Atom::Entry> entries = m_doc->entries();
38
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
50{
51 const QList<Syndication::Atom::Category> entries = m_doc->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
63{
64 return m_doc->title();
65}
66
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
79{
80 return m_doc->subtitle();
81}
82
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
98{
99 return m_doc->xmlLang();
100}
101
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
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
QList< PersonPtr > authors() const override
returns a list of persons who created the feed content.
QList< Syndication::ItemPtr > items() const override
A list of items, in the order they were parsed from the feed source.
QMultiMap< QString, QDomElement > additionalProperties() const override
returns a list of feed metadata not covered by this class.
QList< CategoryPtr > categories() const override
returns a list of categories this feed is associated with.
ImagePtr image() const override
returns an image associated with this item.
QString copyright() const override
returns copyright information about the feed
QString title() const override
The title of the feed.
Syndication::SpecificDocumentPtr specificDocument() const override
returns the format-specific document this abstraction wraps.
QString language() const override
The language used in the feed.
QString link() const override
returns a link pointing to a website associated with this channel.
ImagePtr icon() const override
returns an icon associated with this item.
QString description() const override
A description of the feed.
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-2025 The KDE developers.
Generated on Thu Jan 23 2025 19:01:16 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.