File indexing completed on 2024-05-05 05:12:58

0001 /*
0002     This file is part of Akregator.
0003 
0004     SPDX-FileCopyrightText: 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
0005     SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0008 */
0009 
0010 #pragma once
0011 
0012 #include "akregator_export.h"
0013 #include "types.h"
0014 
0015 #include <QSharedPointer>
0016 #include <Syndication/Person>
0017 
0018 class QDateTime;
0019 class QString;
0020 
0021 template<class T>
0022 class QList;
0023 
0024 using uint = unsigned int;
0025 
0026 class QUrl;
0027 
0028 namespace Syndication
0029 {
0030 class Enclosure;
0031 class Item;
0032 using ItemPtr = QSharedPointer<Item>;
0033 }
0034 
0035 namespace Akregator
0036 {
0037 namespace Backend
0038 {
0039 class FeedStorage;
0040 }
0041 
0042 class Feed;
0043 /** A proxy class for Syndication::ItemPtr with some additional methods to assist sorting. */
0044 class AKREGATOR_EXPORT Article
0045 {
0046     friend class ArticleDeleteJob;
0047     friend class ArticleModifyJob;
0048     friend class Feed;
0049 
0050 public:
0051     enum ContentOption {
0052         ContentAndOnlyContent, /*< returns the content field even if empty */
0053         DescriptionAsFallback /*< uses the description field as fallback if the content field is empty */
0054     };
0055 
0056     Article();
0057     /** creates am article object for an existing article.
0058         The constructor accesses the archive to load it's data
0059         */
0060     Article(const QString &guid, Feed *feed, Backend::FeedStorage *archive = nullptr);
0061 
0062     /** creates an article object from a parsed librss Article
0063         the article is added to the archive if not yet stored, or updated if stored but modified
0064     */
0065     Article(const Syndication::ItemPtr &article, Feed *feed);
0066 
0067     Article(const Syndication::ItemPtr &article, Backend::FeedStorage *archive);
0068     Article(const Article &other);
0069     ~Article();
0070 
0071     void swap(Article &other)
0072     {
0073         std::swap(d, other.d);
0074     }
0075 
0076     Article &operator=(const Article &other);
0077     bool operator==(const Article &other) const;
0078     bool operator!=(const Article &other) const;
0079 
0080     bool isNull() const;
0081 
0082     int status() const;
0083 
0084     QString title() const;
0085     QUrl link() const;
0086     QString description() const;
0087 
0088     QString content(ContentOption opt = ContentAndOnlyContent) const;
0089 
0090     QString guid() const;
0091     /** if true, the article should be kept even when expired **/
0092     bool keep() const;
0093 
0094     bool isDeleted() const;
0095 
0096     void offsetPubDate(int secs);
0097 
0098     Feed *feed() const;
0099 
0100     /** returns a hash value used to detect changes in articles with non-hash GUIDs. If the guid is a hash itself, it returns @c 0 */
0101 
0102     uint hash() const;
0103 
0104     /** returns if the guid is a hash or an ID taken from the source */
0105 
0106     bool guidIsHash() const;
0107 
0108     bool guidIsPermaLink() const;
0109 
0110     QDateTime pubDate() const;
0111 
0112     QUrl commentsLink() const;
0113 
0114     int comments() const;
0115 
0116     QString authorName() const;
0117     QString authorUri() const;
0118     QString authorEMail() const;
0119     QString authorAsHtml() const;
0120     QString authorShort() const;
0121 
0122     QSharedPointer<const Syndication::Enclosure> enclosure() const;
0123 
0124     bool operator<(const Article &other) const;
0125     bool operator<=(const Article &other) const;
0126     bool operator>(const Article &other) const;
0127     bool operator>=(const Article &other) const;
0128 
0129 private: // only for our friends
0130     void setStatus(int s);
0131     void setDeleted();
0132     void setKeep(bool keep);
0133 
0134 private:
0135     struct Private;
0136     Private *d;
0137 };
0138 } // namespace Akregator
0139 Q_DECLARE_TYPEINFO(Akregator::Article, Q_RELOCATABLE_TYPE);