summaryrefslogtreecommitdiffstats
path: root/akregator/src/feed.h
blob: d94eecaca9ac59e9590d3d5334666872758305a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
    This file is part of Akregator.

    Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
                  2005 Frank Osterfeld <frank.osterfeld at kdemail.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

#ifndef AKREGATORFEED_H
#define AKREGATORFEED_H

#include "treenode.h"
#include "librss/librss.h"

class TQDomElement;
class TQPixmap;
class TQString;
class TQStringList;
class KURL;


namespace KPIM {
    class ProgressItem;
}

// needed for slot fetchCompleted()
using RSS::Document;
using RSS::Loader;
using RSS::Status;

namespace Akregator
{
    class Article;
    class FetchQueue;
    class Folder;
    class TreeNodeVisitor;

    namespace Backend
    {
        class FeedStorage;
    }
    /**
        represents a feed
     */
    class Feed : public TreeNode
    {
        friend class Article;
        
        Q_OBJECT
        public:
            /** the archiving modes:
                - globalDefault: use default from Settings (default)
                - keepAllArticles: Don't delete any articles
                - disableArchiving: Don't save any articles except articles with keep flag set (equal to maxArticleNumber() == 0)
                - limitArticleNumber: Save maxArticleNumber() articles, plus the ones with keep flag set
                - limitArticleAge: Save articles not older than maxArticleAge() (or keep flag set)
             */
            enum ArchiveMode { globalDefault, keepAllArticles, disableArchiving, limitArticleNumber, limitArticleAge };

            // class methods
            /** converts strings to ArchiveMode value
             if parsing fails, it returns ArchiveMode::globalDefault
             */
            static ArchiveMode stringToArchiveMode(const TQString& str);

            /** converts ArchiveMode values to corresponding strings */
            static TQString archiveModeToString(ArchiveMode mode);

            /** creates a Feed object from a description in OPML format */
            static Feed* fromOPML(TQDomElement e);

            /** default constructor */
            Feed();

            virtual ~Feed();

            virtual bool accept(TreeNodeVisitor* visitor);

            /** exports the feed settings to OPML */
            virtual TQDomElement toOPML( TQDomElement parent, TQDomDocument document ) const;

            /**
              returns whether this feed uses its own fetch interval or the global setting
              @return @c true iff this feed has a custom fetch interval
             */
            bool useCustomFetchInterval() const;

            /** set if the feed has its custom fetch interval or uses the
                global setting
                @param enabled @c true: use custom interval, @c false: use global default
             */
            void setCustomFetchIntervalEnabled(bool enabled);

            // FIXME is it -1 or 0 to disable interval fetching?
            /** Returns custom auto fetch interval of this feed.
            @return custom fetch interval in minutes, 0 if disabled */
            int fetchInterval() const;

            /** Sets custom auto fetch interval.
            @param interval interval in minutes, -1 for disabling auto fetching */
            void setFetchInterval(int interval);

            /** returns the archiving mode which is used for this feed */
            ArchiveMode archiveMode() const;

            /** sets the archiving mode for this feed */
            void setArchiveMode(ArchiveMode archiveMode);

            /** returns the maximum age of articles used for expiration by age (used in @c limitArticleAge archive mode)
            @return expiry age in days */
            int maxArticleAge() const;

            /** sets the maximum age of articles used for expiration by age (used in @c limitArticleAge archive mode)
            @param maxArticleAge expiry age in days */
            void setMaxArticleAge(int maxArticleAge);
            

            /** returns the article count limit used in @c limitArticleNumber archive mode **/
            int maxArticleNumber() const;

            /** sets the article count limit used in @c limitArticleNumber archive mode **/
            void setMaxArticleNumber(int maxArticleNumber);

            /** if @c true, new articles are marked immediately as read instead of new/unread. Useful for high-traffic feeds. */
            bool markImmediatelyAsRead() const;

            void setMarkImmediatelyAsRead(bool enabled);

            void setUseNotification(bool enabled);

            bool useNotification() const;

            /** if true, the linked URL is loaded directly in the article viewer instead of showing the description */
            void setLoadLinkedWebsite(bool enabled);

            bool loadLinkedWebsite() const;
            
            /** returns the favicon */
            const TQPixmap& favicon() const;

            /** sets the favicon (used in the tree view) */
            void setFavicon(const TQPixmap& p);

            /** returns the feed image */
            const TQPixmap& image() const;

            /** returns the url of the actual feed source (rss/rdf/atom file) */
            const TQString& xmlUrl() const;
            /** sets the url of the actual feed source (rss/rdf/atom file) */
            void setXmlUrl(const TQString& s);

            /** returns the URL of the HTML page of this feed */
            const TQString& htmlUrl() const;
            /** sets the URL of the HTML page of this feed */
            void setHtmlUrl(const TQString& s);

            /** returns the description of this feed */
            const TQString& description() const;

            /** sets the description of this feed */
            void setDescription(const TQString& s);

            virtual TQValueList<Article> articles(const TQString& tag=TQString::null);

            /** returns the article with the given @c guid, or a null article if it not exists */
            virtual Article findArticle(const TQString& guid) const;
            
            virtual TQStringList tags() const;
            
            /** returns whether a fetch error has occurred */
            bool fetchErrorOccurred();

            /** returns the unread count for this feed */
            virtual int unread() const;

            /** returns the number of total articles in this feed
            @return number of articles */

            virtual int totalCount() const;

            /** returns if the article archive of this feed is loaded */
            bool isArticlesLoaded() const;

           /** returns if this node is a feed group (@c false here) */
            virtual bool isGroup() const { return false; }

            /** returns the next node in the tree.
            Calling next() unless it returns 0 iterates through the tree in pre-order
            */
            virtual TreeNode* next();

            /** downloads the favicon */
            void loadFavicon();
            
            /** load the image from the cache if it is in there */
            void loadImage();
            
        public slots:
            /** starts fetching */
            void fetch(bool followDiscovery=false);

            void slotAbortFetch();

            /** deletes expired articles */
            virtual void slotDeleteExpiredArticles();

            /** mark all articles in this feed as read */
            virtual void slotMarkAllArticlesAsRead();

            /** add this feed to the fetch queue @c queue */
            virtual void slotAddToFetchQueue(FetchQueue* queue, bool intervalFetchOnly=false);

        signals:
            /** emitted when fetching started */
            void fetchStarted(Feed*);
            /** emitted when feed finished fetching */
            void fetched(Feed *);
            /** emitted when a fetch error occurred */
            void fetchError(Feed *);
            /** emitted when a feed URL was found by auto discovery */
            void fetchDiscovery(Feed *);
            /** emitted when a fetch is aborted */
            void fetchAborted(Feed *);
           
        protected:
            /** loads articles from archive **/
            void loadArticles();

            void recalcUnreadCount();

            virtual void doArticleNotification();

            /** sets the unread count for this feed */
            void setUnread(int unread);

            
        private slots:

            void fetchCompleted(Loader *loader, Document doc, Status status);
            void slotImageFetched(const TQPixmap& image);

        private:
            
            /** notifies that article @c mya was set to "deleted".
                To be called by @ref Article
             */
            void setArticleDeleted(Article& a);

            /** notifies that article @c mya was changed
                @param oldStatus if the status was changed, it tqcontains the old status, -1 otherwise
                To be called by @ref Article
             */
            void setArticleChanged(Article& a, int oldStatus=-1);
            
            void enforceLimitArticleNumber();

            void appendArticles(const RSS::Document &d);
            /** appends article @c a to the article list */
            void appendArticle(const Article& a);

            /** checks whether article @c a is expired (considering custom and global archive mode settings) */
            bool isExpired(const Article& a) const;

            /** returns @c true if either this article uses @c limitArticleAge as custom setting or uses the global default, which is @c limitArticleAge */
            bool usesExpiryByAge() const;

            /** executes the actual fetch action */
            void tryFetch();

            class FeedPrivate;
            FeedPrivate* d;
    };
}

#endif