File indexing completed on 2024-04-21 04:01:01
0001 /* 0002 This file is part of the syndication library 0003 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "item.h" 0009 #include "contentvocab.h" 0010 #include "document.h" 0011 #include "dublincore.h" 0012 #include "model.h" 0013 #include "rssvocab.h" 0014 #include "statement.h" 0015 0016 #include <specificitemvisitor.h> 0017 #include <tools.h> 0018 0019 #include <QString> 0020 0021 namespace Syndication 0022 { 0023 namespace RDF 0024 { 0025 class SYNDICATION_NO_EXPORT Item::Private 0026 { 0027 public: 0028 DocumentPtr doc; 0029 }; 0030 0031 Item::Item() 0032 : ResourceWrapper() 0033 , d(new Private) 0034 { 0035 } 0036 0037 Item::Item(ResourcePtr resource, DocumentPtr doc) 0038 : ResourceWrapper(resource) 0039 , d(new Private) 0040 { 0041 d->doc = doc; 0042 } 0043 0044 Item::Item(const Item &other) 0045 : ResourceWrapper(other) 0046 , SpecificItem(other) 0047 , d(new Private) 0048 { 0049 *d = *(other.d); 0050 } 0051 0052 Item::~Item() = default; 0053 0054 Item &Item::operator=(const Item &other) 0055 { 0056 ResourceWrapper::operator=(other); 0057 *d = *(other.d); 0058 return *this; 0059 } 0060 0061 bool Item::operator==(const Item &other) const 0062 { 0063 return ResourceWrapper::operator==(other); 0064 } 0065 0066 QString Item::title() const 0067 { 0068 if (!d->doc) { 0069 return originalTitle(); 0070 } 0071 0072 bool containsMarkup = false; 0073 d->doc->getItemTitleFormatInfo(&containsMarkup); 0074 0075 return normalize(originalTitle(), false, containsMarkup); 0076 } 0077 0078 QString Item::description() const 0079 { 0080 if (!d->doc) { 0081 return originalDescription(); 0082 } 0083 0084 bool containsMarkup = false; 0085 d->doc->getItemDescriptionFormatInfo(&containsMarkup); 0086 0087 return normalize(originalDescription(), false, containsMarkup); 0088 } 0089 0090 QString Item::link() const 0091 { 0092 return resource()->property(RSSVocab::self()->link())->asString(); 0093 } 0094 0095 DublinCore Item::dc() const 0096 { 0097 return DublinCore(resource()); 0098 } 0099 0100 QString Item::encodedContent() const 0101 { 0102 return resource()->property(ContentVocab::self()->encoded())->asString(); 0103 } 0104 0105 QString Item::originalTitle() const 0106 { 0107 return resource()->property(RSSVocab::self()->title())->asString(); 0108 } 0109 0110 QString Item::originalDescription() const 0111 { 0112 return resource()->property(RSSVocab::self()->description())->asString(); 0113 } 0114 0115 QString Item::debugInfo() const 0116 { 0117 QString info = QLatin1String("### Item: ###################\n"); 0118 info += QLatin1String("title: #") + title() + QLatin1String("#\n"); 0119 info += QLatin1String("link: #") + link() + QLatin1String("#\n"); 0120 info += QLatin1String("description: #") + description() + QLatin1String("#\n"); 0121 info += QLatin1String("content:encoded: #") + encodedContent() + QLatin1String("#\n"); 0122 info += dc().debugInfo(); 0123 info += QLatin1String("### Item end ################\n"); 0124 return info; 0125 } 0126 0127 bool Item::accept(SpecificItemVisitor *visitor) 0128 { 0129 return visitor->visitRDFItem(this); 0130 } 0131 0132 } // namespace RDF 0133 } // namespace Syndication