akregator/src

articlefilter.h

00001 /*
00002  * articlefilter.h
00003  *
00004  * Copyright (c) 2004, 2005 Frerich Raabe <raabe@kde.org>
00005  *               2005 Frank Osterfeld <frank.osterfeld@kdemail.net>
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 #ifndef ARTICLEFILTER_H
00029 #define ARTICLEFILTER_H
00030 
00031 #include <qstring.h>
00032 #include <qvaluelist.h>
00033 #include <qvariant.h>
00034 
00035 class KConfig;
00036 
00037 namespace Akregator {
00038 
00039 class Article;
00040 
00041 namespace Filters {
00042 
00043 class AbstractAction;
00044 class AbstractMatcher;
00045 class Criterion;
00046 
00050 class ArticleFilter
00051 {
00052     public:
00053 
00054         ArticleFilter();
00055         ArticleFilter(const AbstractMatcher& matcher, const AbstractAction& action);
00056         ArticleFilter(const ArticleFilter& other);
00057 
00058         virtual ~ArticleFilter();
00059 
00061         void applyTo(Article& article) const;
00062 
00063         
00064         
00066         const QString& name() const;
00067         void setName(const QString& name);
00068 
00069         int id() const;
00070 
00071         AbstractMatcher* matcher() const;
00072         void setMatcher(const AbstractMatcher& matcher);
00073 
00074         AbstractAction* action() const;
00075         void setAction(const AbstractAction& action);
00076 
00077         ArticleFilter& operator=(const ArticleFilter& other);
00078         bool operator==(const ArticleFilter& other) const;
00079 
00080         void writeConfig(KConfig* config) const;
00081         void readConfig(KConfig* config);
00082 
00083     private:
00084         class ArticleFilterPrivate;
00085         ArticleFilterPrivate* d;
00086     
00087 };
00088 
00089 class ArticleFilterList : public QValueList<ArticleFilter>
00090 {
00091 public:
00092     
00093     void writeConfig(KConfig* config) const;
00094     void readConfig(KConfig* config);
00095 };
00096 
00100 class AbstractMatcher
00101 {
00102     public:
00103 
00104         virtual ~AbstractMatcher() {}
00106         virtual AbstractMatcher* clone() const = 0;
00107 
00108         virtual bool matches(const Article& article) const = 0;
00109 
00110         virtual void writeConfig(KConfig* config) const = 0;
00111         virtual void readConfig(KConfig* config) = 0;
00112 
00113         virtual bool operator==(const AbstractMatcher&) const = 0;
00114         virtual bool operator!=(const AbstractMatcher &other) const = 0;
00115 };
00116 
00117 class TagMatcher : public AbstractMatcher
00118 {
00119     public:
00120 
00121         TagMatcher();
00122         TagMatcher(const QString& tagID);
00123         TagMatcher(const TagMatcher& other);
00124         
00125         virtual ~TagMatcher();
00126         
00127 
00128         virtual bool matches(const Article& article) const;
00129 
00130         virtual TagMatcher* clone() const;
00131 
00132         virtual void writeConfig(KConfig* config) const;
00133         virtual void readConfig(KConfig* config);
00134 
00135         TagMatcher& operator=(const TagMatcher& other);
00136         virtual bool operator==(const AbstractMatcher&) const;
00137         virtual bool operator!=(const AbstractMatcher &other) const;
00138         
00139     private:
00140     
00141          class TagMatcherPrivate;
00142          TagMatcherPrivate* d;
00143 };
00144 
00145 class AbstractAction
00146 {
00147     public:
00148         virtual void exec(Article& article) = 0;
00149 
00150         virtual void writeConfig(KConfig* config) const = 0;
00151         virtual void readConfig(KConfig* config) = 0;
00152 
00153         virtual AbstractAction* clone() const = 0;
00154         virtual bool operator==(const AbstractAction& other) = 0;
00155 };
00156 
00157 class DeleteAction : public AbstractAction
00158 {
00159     public:
00160         virtual void exec(Article& article);
00161         
00162         virtual void writeConfig(KConfig* config) const;
00163         virtual void readConfig(KConfig* config);
00164 
00165         virtual DeleteAction* clone() const { return new DeleteAction; }
00166         virtual bool operator==(const AbstractAction& other);
00167 };
00168 
00169 class SetStatusAction : public AbstractAction
00170 {
00171     public:
00172         SetStatusAction(int status=0);
00173         
00174         virtual void exec(Article& article);
00175         
00176         int status() const;
00177         void setStatus(int status);
00178 
00179         virtual void writeConfig(KConfig* config) const;
00180         virtual void readConfig(KConfig* config);
00181 
00182         virtual SetStatusAction* clone() const { return new SetStatusAction(*this); }
00183         virtual bool operator==(const AbstractAction& other);
00184 
00185     private:
00186         int m_status;
00187 };
00188 
00189 class AssignTagAction : public AbstractAction
00190 {
00191     public:
00192 
00193         AssignTagAction(const QString& tagID=QString::null);
00194         virtual void exec(Article& article);
00195                 
00196         const QString& tagID() const;
00197         void setTagID(const QString& tagID);
00198 
00199         virtual void writeConfig(KConfig* config) const;
00200         virtual void readConfig(KConfig* config);
00201 
00202         virtual AssignTagAction* clone() const { return new AssignTagAction(*this); }
00203         virtual bool operator==(const AbstractAction& other);
00204 
00205     private:
00206         QString m_tagID;
00207 };
00208 
00212 class ArticleMatcher : public AbstractMatcher
00213 {
00214     public:
00215 
00216         enum Association {
00217             None, LogicalAnd, LogicalOr
00218         };
00219 
00220         ArticleMatcher();
00221         ArticleMatcher( const QValueList<Criterion> &criteria, Association assoc);
00222         
00223         ArticleMatcher(const ArticleMatcher& other);
00224         virtual ~ArticleMatcher();
00225 
00230         virtual bool matchesAll() const;
00231         
00232         ArticleMatcher& operator=(const ArticleMatcher& other);
00233         virtual ArticleMatcher* clone() const;
00234         virtual bool matches(const Article &article) const;
00235         virtual bool operator==(const AbstractMatcher &other) const;
00236         virtual bool operator!=(const AbstractMatcher &other) const;
00237         
00238         
00239         virtual void writeConfig(KConfig* config) const;
00240         virtual void readConfig(KConfig* config);
00241 
00242     private:
00243 
00244         static Association stringToAssociation(const QString& assocStr);
00245         static QString associationToString(Association association);
00246 
00247         bool anyCriterionMatches( const Article &a ) const;
00248         bool allCriteriaMatch( const Article &a ) const;
00249 
00250         QValueList<Criterion> m_criteria;
00251         Association m_association;
00252 };
00253 
00257 class Criterion
00258 {
00259     public:
00260 
00261         enum Subject {
00262             Title, Description, Author, Link, Status, KeepFlag
00263         };
00264 
00265         static QString subjectToString(Subject subj);
00266         static Subject stringToSubject(const QString& subjStr);
00267 
00268         enum Predicate {
00269             Contains = 0x01,
00270             Equals = 0x02,
00271             Matches = 0x03,
00272             Negation = 0x80
00273         };
00274 
00275         static QString predicateToString(Predicate pred);
00276         static Predicate stringToPredicate(const QString& predStr);
00277     
00278         Criterion();
00279         Criterion( Subject subject, Predicate predicate, const QVariant &object );
00280         
00281         bool satisfiedBy( const Article &article ) const;
00282 
00283         virtual void writeConfig(KConfig* config) const;
00284         virtual void readConfig(KConfig* config);
00285 
00286         Subject subject() const;
00287         Predicate predicate() const;
00288         QVariant object() const;
00289         bool operator==(const Criterion& other) const
00290         { return m_subject == other.m_subject && m_predicate == other.m_predicate && m_object == other.m_object; }
00291         
00292     private:
00293         Subject m_subject;
00294         Predicate m_predicate;
00295         QVariant m_object;
00296 };
00297 
00298 } // namespace Filters
00299 } // namespace Akregator
00300 
00301 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys