1 #ifndef NEWSBOAT_RSSITEM_H_
2 #define NEWSBOAT_RSSITEM_H_
3 
4 #include <memory>
5 #include <mutex>
6 #include <string>
7 
8 #include "matchable.h"
9 #include "matcher.h"
10 
11 namespace newsboat {
12 
13 class Cache;
14 class RssFeed;
15 
16 struct Description {
17 	std::string text;
18 	std::string mime;
19 };
20 
21 class RssItem : public Matchable {
22 public:
23 	explicit RssItem(Cache* c);
24 	~RssItem() override;
25 
title()26 	std::string title() const
27 	{
28 		return title_;
29 	}
30 	void set_title(const std::string& t);
31 
32 	/// \brief Feed's canonical URL. Empty if feed was never fetched.
link()33 	const std::string& link() const
34 	{
35 		return link_;
36 	}
37 	void set_link(const std::string& l);
38 
author()39 	std::string author() const
40 	{
41 		return author_;
42 	}
43 	void set_author(const std::string& a);
44 
description()45 	Description description() const
46 	{
47 		std::lock_guard<std::mutex> guard(description_mutex);
48 		if (description_.has_value()) {
49 			return description_.value();
50 		}
51 		return {"", ""};
52 	}
53 	void set_description(const std::string& content, const std::string& mime_type);
54 
size()55 	unsigned int size() const
56 	{
57 		return size_;
58 	}
59 	void set_size(unsigned int size);
60 
61 	std::string length() const;
62 	std::string pubDate() const;
63 
pubDate_timestamp()64 	time_t pubDate_timestamp() const
65 	{
66 		return pubDate_;
67 	}
68 	void set_pubDate(time_t t);
69 
70 	bool operator<(const RssItem& item) const
71 	{
72 		return item.pubDate_ < this->pubDate_; // new items come first
73 	}
74 
guid()75 	const std::string& guid() const
76 	{
77 		return guid_;
78 	}
79 	void set_guid(const std::string& g);
80 
unread()81 	bool unread() const
82 	{
83 		return unread_;
84 	}
85 	void set_unread(bool u);
86 	void set_unread_nowrite(bool u);
87 	void set_unread_nowrite_notify(bool u, bool notify);
88 
set_cache(Cache * c)89 	void set_cache(Cache* c)
90 	{
91 		ch = c;
92 	}
set_feedurl(const std::string & f)93 	void set_feedurl(const std::string& f)
94 	{
95 		feedurl_ = f;
96 	}
97 
feedurl()98 	const std::string& feedurl() const
99 	{
100 		return feedurl_;
101 	}
102 
enclosure_url()103 	const std::string& enclosure_url() const
104 	{
105 		return enclosure_url_;
106 	}
enclosure_type()107 	const std::string& enclosure_type() const
108 	{
109 		return enclosure_type_;
110 	}
111 
112 	void set_enclosure_url(const std::string& url);
113 	void set_enclosure_type(const std::string& type);
114 
enqueued()115 	bool enqueued()
116 	{
117 		return enqueued_;
118 	}
set_enqueued(bool v)119 	void set_enqueued(bool v)
120 	{
121 		enqueued_ = v;
122 	}
123 
flags()124 	const std::string& flags() const
125 	{
126 		return flags_;
127 	}
oldflags()128 	const std::string& oldflags() const
129 	{
130 		return oldflags_;
131 	}
132 	void set_flags(const std::string& ff);
133 	void update_flags();
134 	void sort_flags();
135 
136 	nonstd::optional<std::string> attribute_value(const std::string& attr) const
137 	override;
138 
139 	void set_feedptr(std::shared_ptr<RssFeed> ptr);
140 	void set_feedptr(const std::weak_ptr<RssFeed>& ptr);
get_feedptr()141 	std::shared_ptr<RssFeed> get_feedptr()
142 	{
143 		return feedptr_.lock();
144 	}
145 
deleted()146 	bool deleted() const
147 	{
148 		return deleted_;
149 	}
set_deleted(bool b)150 	void set_deleted(bool b)
151 	{
152 		deleted_ = b;
153 	}
154 
set_index(unsigned int i)155 	void set_index(unsigned int i)
156 	{
157 		idx = i;
158 	}
get_index()159 	unsigned int get_index()
160 	{
161 		return idx;
162 	}
163 
set_base(const std::string & b)164 	void set_base(const std::string& b)
165 	{
166 		base = b;
167 	}
get_base()168 	const std::string& get_base()
169 	{
170 		return base;
171 	}
172 
set_override_unread(bool b)173 	void set_override_unread(bool b)
174 	{
175 		override_unread_ = b;
176 	}
override_unread()177 	bool override_unread()
178 	{
179 		return override_unread_;
180 	}
181 
unload()182 	void unload()
183 	{
184 		std::lock_guard<std::mutex> guard(description_mutex);
185 		description_.reset();
186 	}
187 
188 private:
189 	std::string title_;
190 	std::string link_;
191 	std::string author_;
192 	std::string guid_;
193 	std::string feedurl_;
194 	Cache* ch;
195 	std::string enclosure_url_;
196 	std::string enclosure_type_;
197 	std::string flags_;
198 	std::string oldflags_;
199 	std::weak_ptr<RssFeed> feedptr_;
200 	std::string base;
201 	unsigned int idx;
202 	unsigned int size_;
203 	time_t pubDate_;
204 	bool unread_;
205 	bool enqueued_;
206 	bool deleted_;
207 	bool override_unread_;
208 
209 	mutable std::mutex description_mutex;
210 	nonstd::optional<Description> description_;
211 };
212 
213 } // namespace newsboat
214 
215 #endif /* NEWSBOAT_RSSITEM_H_ */
216