akregator/src

articlefilter.h
1 /*
2  * articlefilter.h
3  *
4  * Copyright (c) 2004, 2005 Frerich Raabe <raabe@kde.org>
5  * 2005 Frank Osterfeld <frank.osterfeld@kdemail.net>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef ARTICLEFILTER_H
29 #define ARTICLEFILTER_H
30 
31 #include <tqstring.h>
32 #include <tqvaluelist.h>
33 #include <tqvariant.h>
34 
35 class TDEConfig;
36 
37 namespace Akregator {
38 
39 class Article;
40 
41 namespace Filters {
42 
43 class AbstractAction;
44 class AbstractMatcher;
45 class Criterion;
46 
51 {
52  public:
53 
54  ArticleFilter();
55  ArticleFilter(const AbstractMatcher& matcher, const AbstractAction& action);
56  ArticleFilter(const ArticleFilter& other);
57 
58  virtual ~ArticleFilter();
59 
61  void applyTo(Article& article) const;
62 
63 
64 
66  const TQString& name() const;
67  void setName(const TQString& name);
68 
69  int id() const;
70 
71  AbstractMatcher* matcher() const;
72  void setMatcher(const AbstractMatcher& matcher);
73 
74  AbstractAction* action() const;
75  void setAction(const AbstractAction& action);
76 
77  ArticleFilter& operator=(const ArticleFilter& other);
78  bool operator==(const ArticleFilter& other) const;
79 
80  void writeConfig(TDEConfig* config) const;
81  void readConfig(TDEConfig* config);
82 
83  private:
84  class ArticleFilterPrivate;
85  ArticleFilterPrivate* d;
86 
87 };
88 
89 class ArticleFilterList : public TQValueList<ArticleFilter>
90 {
91 public:
92 
93  void writeConfig(TDEConfig* config) const;
94  void readConfig(TDEConfig* config);
95 };
96 
101 {
102  public:
103 
104  virtual ~AbstractMatcher() {}
106  virtual AbstractMatcher* clone() const = 0;
107 
108  virtual bool matches(const Article& article) const = 0;
109 
110  virtual void writeConfig(TDEConfig* config) const = 0;
111  virtual void readConfig(TDEConfig* config) = 0;
112 
113  virtual bool operator==(const AbstractMatcher&) const = 0;
114  virtual bool operator!=(const AbstractMatcher &other) const = 0;
115 };
116 
117 class TagMatcher : public AbstractMatcher
118 {
119  public:
120 
121  TagMatcher();
122  TagMatcher(const TQString& tagID);
123  TagMatcher(const TagMatcher& other);
124 
125  virtual ~TagMatcher();
126 
127 
128  virtual bool matches(const Article& article) const;
129 
130  virtual TagMatcher* clone() const;
131 
132  virtual void writeConfig(TDEConfig* config) const;
133  virtual void readConfig(TDEConfig* config);
134 
135  TagMatcher& operator=(const TagMatcher& other);
136  virtual bool operator==(const AbstractMatcher&) const;
137  virtual bool operator!=(const AbstractMatcher &other) const;
138 
139  private:
140 
141  class TagMatcherPrivate;
142  TagMatcherPrivate* d;
143 };
144 
145 class AbstractAction
146 {
147  public:
148  AbstractAction() {}
149  virtual ~AbstractAction() {}
150 
151  public:
152  virtual void exec(Article& article) = 0;
153 
154  virtual void writeConfig(TDEConfig* config) const = 0;
155  virtual void readConfig(TDEConfig* config) = 0;
156 
157  virtual AbstractAction* clone() const = 0;
158  virtual bool operator==(const AbstractAction& other) = 0;
159 };
160 
161 class DeleteAction : public AbstractAction
162 {
163  public:
164  virtual void exec(Article& article);
165 
166  virtual void writeConfig(TDEConfig* config) const;
167  virtual void readConfig(TDEConfig* config);
168 
169  virtual DeleteAction* clone() const { return new DeleteAction; }
170  virtual bool operator==(const AbstractAction& other);
171 };
172 
173 class SetStatusAction : public AbstractAction
174 {
175  public:
176  SetStatusAction(int status=0);
177 
178  virtual void exec(Article& article);
179 
180  int status() const;
181  void setStatus(int status);
182 
183  virtual void writeConfig(TDEConfig* config) const;
184  virtual void readConfig(TDEConfig* config);
185 
186  virtual SetStatusAction* clone() const { return new SetStatusAction(*this); }
187  virtual bool operator==(const AbstractAction& other);
188 
189  private:
190  int m_status;
191 };
192 
193 class AssignTagAction : public AbstractAction
194 {
195  public:
196 
197  AssignTagAction(const TQString& tagID=TQString());
198  virtual void exec(Article& article);
199 
200  const TQString& tagID() const;
201  void setTagID(const TQString& tagID);
202 
203  virtual void writeConfig(TDEConfig* config) const;
204  virtual void readConfig(TDEConfig* config);
205 
206  virtual AssignTagAction* clone() const { return new AssignTagAction(*this); }
207  virtual bool operator==(const AbstractAction& other);
208 
209  private:
210  TQString m_tagID;
211 };
212 
217 {
218  public:
219 
220  enum Association {
221  None, LogicalAnd, LogicalOr
222  };
223 
224  ArticleMatcher();
225  ArticleMatcher( const TQValueList<Criterion> &criteria, Association assoc);
226 
227  ArticleMatcher(const ArticleMatcher& other);
228  virtual ~ArticleMatcher();
229 
234  virtual bool matchesAll() const;
235 
236  ArticleMatcher& operator=(const ArticleMatcher& other);
237  virtual ArticleMatcher* clone() const;
238  virtual bool matches(const Article &article) const;
239  virtual bool operator==(const AbstractMatcher &other) const;
240  virtual bool operator!=(const AbstractMatcher &other) const;
241 
242 
243  virtual void writeConfig(TDEConfig* config) const;
244  virtual void readConfig(TDEConfig* config);
245 
246  private:
247 
248  static Association stringToAssociation(const TQString& assocStr);
249  static TQString associationToString(Association association);
250 
251  bool anyCriterionMatches( const Article &a ) const;
252  bool allCriteriaMatch( const Article &a ) const;
253 
254  TQValueList<Criterion> m_criteria;
255  Association m_association;
256 };
257 
262 {
263  public:
264 
265  enum Subject {
266  Title, Description, Author, Link, Status, KeepFlag
267  };
268 
269  static TQString subjectToString(Subject subj);
270  static Subject stringToSubject(const TQString& subjStr);
271 
272  enum Predicate {
273  Contains = 0x01,
274  Equals = 0x02,
275  Matches = 0x03,
276  Negation = 0x80
277  };
278 
279  static TQString predicateToString(Predicate pred);
280  static Predicate stringToPredicate(const TQString& predStr);
281 
282  Criterion();
283  Criterion( Subject subject, Predicate predicate, const TQVariant &object );
284 
285  bool satisfiedBy( const Article &article ) const;
286 
287  virtual void writeConfig(TDEConfig* config) const;
288  virtual void readConfig(TDEConfig* config);
289 
290  Subject subject() const;
291  Predicate predicate() const;
292  TQVariant object() const;
293  bool operator==(const Criterion& other) const
294  { return m_subject == other.m_subject && m_predicate == other.m_predicate && m_object == other.m_object; }
295 
296  private:
297  Subject m_subject;
298  Predicate m_predicate;
299  TQVariant m_object;
300 };
301 
302 } // namespace Filters
303 } // namespace Akregator
304 
305 #endif
virtual ArticleMatcher * clone() const
returns a copy of the matcher
const TQString & name() const
name of the filter, for display in filter list
A proxy class for RSS::Article with some additional methods to assist sorting.
Definition: article.h:57
void applyTo(Article &article) const
checks whether an article matches the matcher, and executes the action if so
Abstract base class for matchers, a matcher just takes an article and checks whether the article matc...
a powerful matcher supporting multiple criterions, which can be combined via logical OR or AND
virtual bool matchesAll() const
returns whether the matcher matches all articles anyway (empty criteria list), so there is no need to...
Criterion for ArticleMatcher.
an article filter, basically a matcher and an action.
Definition: articlefilter.h:50
virtual AbstractMatcher * clone() const =0
returns a copy of the matcher