Syndication

feedatomimpl.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2006 Frank Osterfeld <[email protected]>
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 
23 namespace Syndication
24 {
25 FeedAtomImpl::FeedAtomImpl(Syndication::Atom::FeedDocumentPtr doc)
26  : m_doc(doc)
27 {
28 }
29 
30 Syndication::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 
87  QList<PersonPtr> list;
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 
108 {
109  return ImageAtomImplPtr(new ImageAtomImpl(m_doc->logo()));
110 }
111 
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
QString language() const override
The language used in the feed.
Definition: feed.h:20
int count(const T &value) const const
QString copyright() const override
returns copyright information about the feed
void reserve(int alloc)
ImagePtr icon() const override
returns an icon associated with this item.
Syndication::SpecificDocumentPtr specificDocument() const override
returns the format-specific document this abstraction wraps.
int size() const const
A category for categorizing items or whole feeds.
Definition: atom/category.h:31
an Atom entry, equivalent to the "items" in the RSS world.
Definition: entry.h:38
QString title() const override
The title of the feed.
QList< Syndication::ItemPtr > items() const override
A list of items, in the order they were parsed from the feed source.
QList::const_iterator cend() const const
typename QMap< Key, T >::iterator insert(const Key &key, const T &value)
ImagePtr image() const override
returns an image associated with this item.
QString description() const override
A description of the feed.
QString link() const override
returns a link pointing to a website associated with this channel.
QList::const_iterator cbegin() const const
QMultiMap< QString, QDomElement > additionalProperties() const override
returns a list of feed metadata not covered by this class.
QList< PersonPtr > authors() const override
returns a list of persons who created the feed content.
QList< CategoryPtr > categories() const override
returns a list of categories this feed is associated with.
describes a person, with name and optional URI and e-mail address.
Definition: atom/person.h:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Dec 1 2023 03:52:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.