Syndication

rdf/item.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 "item.h"
9 #include "contentvocab.h"
10 #include "document.h"
11 #include "dublincore.h"
12 #include "model.h"
13 #include "rssvocab.h"
14 #include "statement.h"
15 
16 #include <specificitemvisitor.h>
17 #include <tools.h>
18 
19 #include <QString>
20 
21 namespace Syndication
22 {
23 namespace RDF
24 {
25 class SYNDICATION_NO_EXPORT Item::Private
26 {
27 public:
28  DocumentPtr doc;
29 };
30 
31 Item::Item()
32  : ResourceWrapper()
33  , d(new Private)
34 {
35 }
36 
37 Item::Item(ResourcePtr resource, DocumentPtr doc)
38  : ResourceWrapper(resource)
39  , d(new Private)
40 {
41  d->doc = doc;
42 }
43 
44 Item::Item(const Item &other)
45  : ResourceWrapper(other)
46  , SpecificItem(other)
47  , d(new Private)
48 {
49  *d = *(other.d);
50 }
51 
53 {
54  delete d;
55 }
56 
57 Item &Item::operator=(const Item &other)
58 {
59  ResourceWrapper::operator=(other);
60  *d = *(other.d);
61  return *this;
62 }
63 
64 bool Item::operator==(const Item &other) const
65 {
66  return ResourceWrapper::operator==(other);
67 }
68 
69 QString Item::title() const
70 {
71  if (!d->doc) {
72  return originalTitle();
73  }
74 
75  bool containsMarkup = false;
76  d->doc->getItemTitleFormatInfo(&containsMarkup);
77 
78  return normalize(originalTitle(), false, containsMarkup);
79 }
80 
82 {
83  if (!d->doc) {
84  return originalDescription();
85  }
86 
87  bool containsMarkup = false;
88  d->doc->getItemDescriptionFormatInfo(&containsMarkup);
89 
90  return normalize(originalDescription(), false, containsMarkup);
91 }
92 
93 QString Item::link() const
94 {
95  return resource()->property(RSSVocab::self()->link())->asString();
96 }
97 
98 DublinCore Item::dc() const
99 {
100  return DublinCore(resource());
101 }
102 
103 QString Item::encodedContent() const
104 {
105  return resource()->property(ContentVocab::self()->encoded())->asString();
106 }
107 
108 QString Item::originalTitle() const
109 {
110  return resource()->property(RSSVocab::self()->title())->asString();
111 }
112 
113 QString Item::originalDescription() const
114 {
115  return resource()->property(RSSVocab::self()->description())->asString();
116 }
117 
118 QString Item::debugInfo() const
119 {
120  QString info = QLatin1String("### Item: ###################\n");
121  info += QLatin1String("title: #") + title() + QLatin1String("#\n");
122  info += QLatin1String("link: #") + link() + QLatin1String("#\n");
123  info += QLatin1String("description: #") + description() + QLatin1String("#\n");
124  info += QLatin1String("content:encoded: #") + encodedContent() + QLatin1String("#\n");
125  info += dc().debugInfo();
126  info += QLatin1String("### Item end ################\n");
127  return info;
128 }
129 
130 bool Item::accept(SpecificItemVisitor *visitor)
131 {
132  return visitor->visitRDFItem(this);
133 }
134 
135 } // namespace RDF
136 } // namespace Syndication
virtual ~Item()
destructor
Definition: item.cpp:18
QString normalize(QStringView str)
virtual QString title() const =0
The title of the item.
virtual QString debugInfo() const
returns a description of the item for debugging purposes
Definition: item.cpp:22
virtual QString description() const =0
returns the description of the item.
virtual QString link() const =0
returns a link to the (web) resource described by this item.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:55:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.