24 #include <tqptrlist.h>
25 #include <tqptrstack.h>
30 #include <tqstringlist.h>
31 #include <tqdatetime.h>
37 #include <kdialogbase.h>
38 #include <klineedit.h>
39 #include <knuminput.h>
41 #include <tdemacros.h>
64 class TDE_EXPORT ScorableArticle
67 virtual ~ScorableArticle();
69 virtual void addScore(
short) {}
70 virtual void displayMessage(
const TQString&);
71 virtual void changeColor(
const TQColor&) {}
72 virtual void markAsRead() {}
73 virtual TQString from()
const = 0;
74 virtual TQString subject()
const = 0;
75 virtual TQString getHeaderByType(
const TQString&)
const = 0;
88 virtual TQString toString()
const =0;
89 virtual void apply(ScorableArticle&)
const =0;
91 virtual int getType()
const =0;
92 virtual TQString getValueString()
const {
return TQString(); }
93 virtual void setValue(
const TQString&) {}
94 static ActionBase* factory(
int type,
const TQString &value);
95 static TQStringList userNames();
96 static TQString userName(
int type);
97 static int getTypeForName(
const TQString& name);
98 static int getTypeForUserName(
const TQString& name);
99 TQString userName() {
return userName(getType()); }
100 enum ActionTypes { SETSCORE, NOTIFY, COLOR, MARKASREAD };
103 class TDE_EXPORT ActionColor :
public ActionBase {
105 ActionColor(
const TQColor&);
106 ActionColor(
const TQString&);
107 ActionColor(
const ActionColor&);
108 virtual ~ActionColor();
109 virtual TQString toString()
const;
110 virtual int getType()
const {
return COLOR; }
111 virtual TQString getValueString()
const {
return color.name(); }
112 virtual void setValue(
const TQString& s) { color.setNamedColor(s); }
113 void setValue(
const TQColor& c) { color = c; }
114 TQColor value()
const {
return color; }
115 virtual void apply(ScorableArticle&)
const;
116 virtual ActionColor* clone()
const;
121 class TDE_EXPORT ActionSetScore :
public ActionBase {
123 ActionSetScore(
short);
124 ActionSetScore(
const ActionSetScore&);
125 ActionSetScore(
const TQString&);
126 virtual ~ActionSetScore();
127 virtual TQString toString()
const;
128 virtual int getType()
const {
return SETSCORE; }
129 virtual TQString getValueString()
const {
return TQString::number(val); }
130 virtual void setValue(
const TQString& s) { val = s.toShort(); }
131 void setValue(
short v) { val = v; }
132 short value()
const {
return val; }
133 virtual void apply(ScorableArticle&)
const;
134 virtual ActionSetScore* clone()
const;
139 class TDE_EXPORT ActionNotify :
public ActionBase {
141 ActionNotify(
const TQString&);
142 ActionNotify(
const ActionNotify&);
143 virtual ~ActionNotify() {}
144 virtual TQString toString()
const;
145 virtual int getType()
const {
return NOTIFY; }
146 virtual TQString getValueString()
const {
return note; }
147 virtual void setValue(
const TQString& s) { note = s; }
148 virtual void apply(ScorableArticle&)
const;
149 virtual ActionNotify* clone()
const;
154 class TDE_EXPORT ActionMarkAsRead :
public ActionBase {
157 ActionMarkAsRead(
const ActionMarkAsRead& );
158 virtual ~ActionMarkAsRead() {}
159 virtual TQString toString()
const;
160 virtual int getType()
const {
return MARKASREAD; }
161 virtual void apply( ScorableArticle &article )
const;
162 virtual ActionMarkAsRead* clone()
const;
165 class TDE_EXPORT NotifyCollection
170 void addNote(
const ScorableArticle&,
const TQString&);
171 TQString collection()
const;
172 void displayCollection(TQWidget *p=0)
const;
174 struct article_info {
178 typedef TQValueList<article_info> article_list;
179 typedef TQDict<article_list> note_list;
180 note_list notifyList;
185 class TDE_EXPORT KScoringExpression
187 friend class KScoringRule;
189 enum Condition { CONTAINS, MATCH, EQUALS, SMALLER, GREATER, MATCHCS };
191 KScoringExpression(
const TQString&,
const TQString&,
const TQString&,
const TQString&);
192 ~KScoringExpression();
194 bool match(ScorableArticle& a)
const ;
195 TQString getTypeString()
const;
196 static TQString getTypeString(
int);
198 TQString toString()
const;
199 void write(TQTextStream& )
const;
201 bool isNeg()
const {
return neg; }
202 Condition getCondition()
const {
return cond; }
203 TQString getExpression()
const {
return expr_str; }
204 TQString getHeader()
const {
return header; }
205 static TQStringList conditionNames();
206 static TQStringList headerNames();
207 static int getConditionForName(
const TQString&);
208 static TQString getNameForCondition(
int);
212 const char* c_header;
220 class TDE_EXPORT KScoringRule
222 friend class KScoringManager;
224 KScoringRule(
const TQString& name);
225 KScoringRule(
const KScoringRule& r);
228 typedef TQPtrList<KScoringExpression> ScoreExprList;
229 typedef TQPtrList<ActionBase> ActionList;
230 typedef TQStringList GroupList;
231 enum LinkMode { AND, OR };
233 TQString getName()
const {
return name; }
234 TQStringList getGroups()
const {
return groups; }
235 void setGroups(
const TQStringList &l) { groups = l; }
236 LinkMode getLinkMode()
const {
return link; }
237 TQString getLinkModeName()
const;
238 TQString getExpireDateString()
const;
239 TQDate getExpireDate()
const {
return expires; }
240 void setExpireDate(
const TQDate &d) { expires = d; }
241 bool isExpired()
const;
242 ScoreExprList getExpressions()
const {
return expressions; }
243 ActionList getActions()
const {
return actions; }
244 void cleanExpressions();
247 bool matchGroup(
const TQString& group)
const ;
248 void applyRule(ScorableArticle& a)
const;
249 void applyRule(ScorableArticle& a,
const TQString& group)
const;
250 void applyAction(ScorableArticle& a)
const;
252 void setLinkMode(
const TQString& link);
253 void setLinkMode(LinkMode m) { link = m; }
254 void setExpire(
const TQString& exp);
255 void addExpression( KScoringExpression* );
256 void addGroup(
const TQString& group) { groups.append(group); }
258 void addAction(
int,
const TQString& );
261 void updateXML(TQDomElement& e, TQDomDocument& d);
262 TQString toString()
const;
265 void write(TQTextStream& )
const;
268 void setName(
const TQString &n) { name = n; }
274 ScoreExprList expressions;
289 void push(TQPtrList<KScoringRule>&);
292 void pop(TQPtrList<KScoringRule>&);
294 void top(TQPtrList<KScoringRule>&);
298 TQPtrStack< TQPtrList<KScoringRule> > stack;
303 class TDE_EXPORT KScoringManager :
public TQObject
310 typedef TQPtrList<KScoringRule> ScoringRuleList;
312 KScoringManager(
const TQString& appName = TQString());
313 virtual ~KScoringManager();
316 virtual TQStringList getGroups()
const =0;
320 virtual TQStringList getDefaultHeaders()
const;
323 void applyRules(ScorableArticle& article,
const TQString& group);
325 void applyRules(ScorableArticle&);
338 KScoringRule* addRule(KScoringRule *);
339 KScoringRule* addRule(
const ScorableArticle&, TQString group,
short =0);
340 KScoringRule* addRule();
341 void cancelNewRule(KScoringRule *);
342 void deleteRule(KScoringRule *);
343 void editRule(KScoringRule *e, TQWidget *w=0);
344 KScoringRule* copyRule(KScoringRule *);
345 void moveRuleAbove( KScoringRule *above, KScoringRule *below );
346 void moveRuleBelow( KScoringRule *below, KScoringRule *above );
347 void setGroup(
const TQString& g);
349 bool hasRulesForCurrentGroup();
350 TQString findUniqueName()
const;
356 ScoringRuleList getAllRules()
const {
return allRules; }
357 KScoringRule *findRule(
const TQString&);
358 TQStringList getRuleNames();
359 void setRuleName(KScoringRule *,
const TQString&);
360 int getRuleCount()
const {
return allRules.count(); }
361 TQString toString()
const;
363 bool setCacheValid(
bool v);
364 bool isCacheValid() {
return cacheValid; }
365 void initCache(
const TQString& group);
371 virtual bool canScores()
const {
return true; }
372 virtual bool canNotes()
const {
return true; }
373 virtual bool canColors()
const {
return false; }
374 virtual bool canMarkAsRead()
const {
return false; }
375 virtual bool hasFeature(
int);
379 void changedRuleName(
const TQString& oldName,
const TQString& newName);
380 void finishedEditing();
383 void addRuleInternal(KScoringRule *e);
386 TQDomDocument createXMLfromInternal();
387 void createInternalFromXML(TQDomNode);
390 ScoringRuleList allRules;
398 ScoringRuleList ruleList;
410 class TDE_EXPORT NotifyDialog :
public KDialogBase
415 static void display(ScorableArticle&,
const TQString&);
417 void slotShowAgainToggled(
bool);
419 NotifyDialog(TQWidget* p =0);
420 static NotifyDialog *me;
424 typedef TQMap<TQString,bool> NotesMap;
425 static NotesMap dict;
Base class for other Action classes.
this helper class implements a stack for lists of lists of rules.
The following classes ScorableArticle, ScorableGroup define the interface for the scoring.