akregator/src
articlefilter.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ARTICLEFILTER_H
00029 #define ARTICLEFILTER_H
00030
00031 #include <tqstring.h>
00032 #include <tqvaluelist.h>
00033 #include <tqvariant.h>
00034
00035 class TDEConfig;
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 TQString& name() const;
00067 void setName(const TQString& 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(TDEConfig* config) const;
00081 void readConfig(TDEConfig* config);
00082
00083 private:
00084 class ArticleFilterPrivate;
00085 ArticleFilterPrivate* d;
00086
00087 };
00088
00089 class ArticleFilterList : public TQValueList<ArticleFilter>
00090 {
00091 public:
00092
00093 void writeConfig(TDEConfig* config) const;
00094 void readConfig(TDEConfig* 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(TDEConfig* config) const = 0;
00111 virtual void readConfig(TDEConfig* 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 TQString& 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(TDEConfig* config) const;
00133 virtual void readConfig(TDEConfig* 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 AbstractAction() {}
00149 virtual ~AbstractAction() {}
00150
00151 public:
00152 virtual void exec(Article& article) = 0;
00153
00154 virtual void writeConfig(TDEConfig* config) const = 0;
00155 virtual void readConfig(TDEConfig* config) = 0;
00156
00157 virtual AbstractAction* clone() const = 0;
00158 virtual bool operator==(const AbstractAction& other) = 0;
00159 };
00160
00161 class DeleteAction : public AbstractAction
00162 {
00163 public:
00164 virtual void exec(Article& article);
00165
00166 virtual void writeConfig(TDEConfig* config) const;
00167 virtual void readConfig(TDEConfig* config);
00168
00169 virtual DeleteAction* clone() const { return new DeleteAction; }
00170 virtual bool operator==(const AbstractAction& other);
00171 };
00172
00173 class SetStatusAction : public AbstractAction
00174 {
00175 public:
00176 SetStatusAction(int status=0);
00177
00178 virtual void exec(Article& article);
00179
00180 int status() const;
00181 void setStatus(int status);
00182
00183 virtual void writeConfig(TDEConfig* config) const;
00184 virtual void readConfig(TDEConfig* config);
00185
00186 virtual SetStatusAction* clone() const { return new SetStatusAction(*this); }
00187 virtual bool operator==(const AbstractAction& other);
00188
00189 private:
00190 int m_status;
00191 };
00192
00193 class AssignTagAction : public AbstractAction
00194 {
00195 public:
00196
00197 AssignTagAction(const TQString& tagID=TQString());
00198 virtual void exec(Article& article);
00199
00200 const TQString& tagID() const;
00201 void setTagID(const TQString& tagID);
00202
00203 virtual void writeConfig(TDEConfig* config) const;
00204 virtual void readConfig(TDEConfig* config);
00205
00206 virtual AssignTagAction* clone() const { return new AssignTagAction(*this); }
00207 virtual bool operator==(const AbstractAction& other);
00208
00209 private:
00210 TQString m_tagID;
00211 };
00212
00216 class ArticleMatcher : public AbstractMatcher
00217 {
00218 public:
00219
00220 enum Association {
00221 None, LogicalAnd, LogicalOr
00222 };
00223
00224 ArticleMatcher();
00225 ArticleMatcher( const TQValueList<Criterion> &criteria, Association assoc);
00226
00227 ArticleMatcher(const ArticleMatcher& other);
00228 virtual ~ArticleMatcher();
00229
00234 virtual bool matchesAll() const;
00235
00236 ArticleMatcher& operator=(const ArticleMatcher& other);
00237 virtual ArticleMatcher* clone() const;
00238 virtual bool matches(const Article &article) const;
00239 virtual bool operator==(const AbstractMatcher &other) const;
00240 virtual bool operator!=(const AbstractMatcher &other) const;
00241
00242
00243 virtual void writeConfig(TDEConfig* config) const;
00244 virtual void readConfig(TDEConfig* config);
00245
00246 private:
00247
00248 static Association stringToAssociation(const TQString& assocStr);
00249 static TQString associationToString(Association association);
00250
00251 bool anyCriterionMatches( const Article &a ) const;
00252 bool allCriteriaMatch( const Article &a ) const;
00253
00254 TQValueList<Criterion> m_criteria;
00255 Association m_association;
00256 };
00257
00261 class Criterion
00262 {
00263 public:
00264
00265 enum Subject {
00266 Title, Description, Author, Link, Status, KeepFlag
00267 };
00268
00269 static TQString subjectToString(Subject subj);
00270 static Subject stringToSubject(const TQString& subjStr);
00271
00272 enum Predicate {
00273 Contains = 0x01,
00274 Equals = 0x02,
00275 Matches = 0x03,
00276 Negation = 0x80
00277 };
00278
00279 static TQString predicateToString(Predicate pred);
00280 static Predicate stringToPredicate(const TQString& predStr);
00281
00282 Criterion();
00283 Criterion( Subject subject, Predicate predicate, const TQVariant &object );
00284
00285 bool satisfiedBy( const Article &article ) const;
00286
00287 virtual void writeConfig(TDEConfig* config) const;
00288 virtual void readConfig(TDEConfig* config);
00289
00290 Subject subject() const;
00291 Predicate predicate() const;
00292 TQVariant object() const;
00293 bool operator==(const Criterion& other) const
00294 { return m_subject == other.m_subject && m_predicate == other.m_predicate && m_object == other.m_object; }
00295
00296 private:
00297 Subject m_subject;
00298 Predicate m_predicate;
00299 TQVariant m_object;
00300 };
00301
00302 }
00303 }
00304
00305 #endif
|