akregator/src

feed.h
00001 /*
00002     This file is part of Akregator.
00003 
00004     Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
00005                   2005 Frank Osterfeld <frank.osterfeld at kdemail.net>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of TQt, and distribute the resulting executable,
00023     without including the source code for TQt in the source distribution.
00024 */
00025 
00026 #ifndef AKREGATORFEED_H
00027 #define AKREGATORFEED_H
00028 
00029 #include "treenode.h"
00030 #include "librss/librss.h"
00031 
00032 class TQDomElement;
00033 class TQPixmap;
00034 class TQString;
00035 class TQStringList;
00036 class KURL;
00037 
00038 
00039 namespace KPIM {
00040     class ProgressItem;
00041 }
00042 
00043 // needed for slot fetchCompleted()
00044 using RSS::Document;
00045 using RSS::Loader;
00046 using RSS::Status;
00047 
00048 namespace Akregator
00049 {
00050     class Article;
00051     class FetchQueue;
00052     class Folder;
00053     class TreeNodeVisitor;
00054 
00055     namespace Backend
00056     {
00057         class FeedStorage;
00058     }
00062     class Feed : public TreeNode
00063     {
00064         friend class Article;
00065         
00066         Q_OBJECT
00067   
00068         public:
00076             enum ArchiveMode { globalDefault, keepAllArticles, disableArchiving, limitArticleNumber, limitArticleAge };
00077 
00078             // class methods
00082             static ArchiveMode stringToArchiveMode(const TQString& str);
00083 
00085             static TQString archiveModeToString(ArchiveMode mode);
00086 
00088             static Feed* fromOPML(TQDomElement e);
00089 
00091             Feed();
00092 
00093             virtual ~Feed();
00094 
00095             virtual bool accept(TreeNodeVisitor* visitor);
00096 
00098             virtual TQDomElement toOPML( TQDomElement parent, TQDomDocument document ) const;
00099 
00104             bool useCustomFetchInterval() const;
00105 
00110             void setCustomFetchIntervalEnabled(bool enabled);
00111 
00112             // FIXME is it -1 or 0 to disable interval fetching?
00115             int fetchInterval() const;
00116 
00119             void setFetchInterval(int interval);
00120 
00122             ArchiveMode archiveMode() const;
00123 
00125             void setArchiveMode(ArchiveMode archiveMode);
00126 
00129             int maxArticleAge() const;
00130 
00133             void setMaxArticleAge(int maxArticleAge);
00134             
00135 
00137             int maxArticleNumber() const;
00138 
00140             void setMaxArticleNumber(int maxArticleNumber);
00141 
00143             bool markImmediatelyAsRead() const;
00144 
00145             void setMarkImmediatelyAsRead(bool enabled);
00146 
00147             void setUseNotification(bool enabled);
00148 
00149             bool useNotification() const;
00150 
00152             void setLoadLinkedWebsite(bool enabled);
00153 
00154             bool loadLinkedWebsite() const;
00155             
00157             const TQPixmap& favicon() const;
00158 
00160             void setFavicon(const TQPixmap& p);
00161 
00163             const TQPixmap& image() const;
00164 
00166             const TQString& xmlUrl() const;
00168             void setXmlUrl(const TQString& s);
00169 
00171             const TQString& htmlUrl() const;
00173             void setHtmlUrl(const TQString& s);
00174 
00176             const TQString& description() const;
00177 
00179             void setDescription(const TQString& s);
00180 
00181             virtual TQValueList<Article> articles(const TQString& tag=TQString());
00182 
00184             virtual Article findArticle(const TQString& guid) const;
00185             
00186             virtual TQStringList tags() const;
00187             
00189             bool fetchErrorOccurred();
00190 
00192             virtual int unread() const;
00193 
00197             virtual int totalCount() const;
00198 
00200             bool isArticlesLoaded() const;
00201 
00203             virtual bool isGroup() const { return false; }
00204 
00208             virtual TreeNode* next();
00209 
00211             void loadFavicon();
00212             
00214             void loadImage();
00215             
00216         public slots:
00218             void fetch(bool followDiscovery=false);
00219 
00220             void slotAbortFetch();
00221 
00223             virtual void slotDeleteExpiredArticles();
00224 
00226             virtual void slotMarkAllArticlesAsRead();
00227 
00229             virtual void slotAddToFetchQueue(FetchQueue* queue, bool intervalFetchOnly=false);
00230 
00231         signals:
00233             void fetchStarted(Feed*);
00235             void fetched(Feed *);
00237             void fetchError(Feed *);
00239             void fetchDiscovery(Feed *);
00241             void fetchAborted(Feed *);
00242            
00243         protected:
00245             void loadArticles();
00246 
00247             void recalcUnreadCount();
00248 
00249             virtual void doArticleNotification();
00250 
00252             void setUnread(int unread);
00253 
00254             
00255         private slots:
00256 
00257             void fetchCompleted(Loader *loader, Document doc, Status status);
00258             void slotImageFetched(const TQPixmap& image);
00259 
00260         private:
00261             
00265             void setArticleDeleted(Article& a);
00266 
00271             void setArticleChanged(Article& a, int oldStatus=-1);
00272             
00273             void enforceLimitArticleNumber();
00274 
00275             void appendArticles(const RSS::Document &d);
00277             void appendArticle(const Article& a);
00278 
00280             bool isExpired(const Article& a) const;
00281 
00283             bool usesExpiryByAge() const;
00284 
00286             void tryFetch();
00287 
00288             class FeedPrivate;
00289             FeedPrivate* d;
00290     };
00291 }
00292 
00293 #endif