kscoring.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef KSCORING_H
00018 #define KSCORING_H
00019
00020 #include <unistd.h>
00021
00022 #include <qglobal.h>
00023 #include <qptrlist.h>
00024 #include <qptrstack.h>
00025 #include <qregexp.h>
00026
00027 #include <qobject.h>
00028 #include <qstring.h>
00029 #include <qstringlist.h>
00030 #include <qdatetime.h>
00031 #include <qcolor.h>
00032 #include <qtable.h>
00033 #include <qmap.h>
00034 #include <qdict.h>
00035
00036 #include <kdialogbase.h>
00037 #include <klineedit.h>
00038 #include <knuminput.h>
00039
00040 class QDomNode;
00041 class QDomDocument;
00042 class QDomElement;
00043 class QTextStream;
00044 class QLabel;
00045
00046
00054
00055 class ScorableGroup
00056 {
00057 public:
00058 virtual ~ScorableGroup();
00059 };
00060
00061 class ScorableArticle
00062 {
00063 public:
00064 virtual ~ScorableArticle();
00065
00066 virtual void addScore(short) {}
00067 virtual void displayMessage(const QString&);
00068 virtual void changeColor(const QColor&) {}
00069 virtual QString from() const = 0;
00070 virtual QString subject() const = 0;
00071 virtual QString getHeaderByType(const QString&) const = 0;
00072
00073 };
00074
00075
00076
00080 class ActionBase {
00081 public:
00082 ActionBase();
00083 virtual ~ActionBase();
00084 virtual QString toString() const =0;
00085 virtual void apply(ScorableArticle&) const =0;
00086 virtual ActionBase* clone() const =0;
00087 virtual int getType() const =0;
00088 virtual QString getValueString() const =0;
00089 virtual void setValue(const QString&) =0;
00090 static ActionBase* factory(int type, QString value);
00091 static QStringList userNames();
00092 static QString userName(int type);
00093 static int getTypeForName(const QString& name);
00094 static int getTypeForUserName(const QString& name);
00095 QString userName() { return userName(getType()); }
00096 enum ActionTypes { SETSCORE, NOTIFY, COLOR };
00097 };
00098
00099 class ActionColor : public ActionBase {
00100 public:
00101 ActionColor(const QColor&);
00102 ActionColor(const QString&);
00103 ActionColor(const ActionColor&);
00104 virtual ~ActionColor();
00105 virtual QString toString() const;
00106 virtual int getType() const { return COLOR; }
00107 virtual QString getValueString() const { return color.name(); }
00108 virtual void setValue(const QString& s) { color.setNamedColor(s); }
00109 void setValue(const QColor& c) { color = c; }
00110 QColor value() const { return color; }
00111 virtual void apply(ScorableArticle&) const;
00112 virtual ActionColor* clone() const;
00113 private:
00114 QColor color;
00115 };
00116
00117 class ActionSetScore : public ActionBase {
00118 public:
00119 ActionSetScore(short);
00120 ActionSetScore(const ActionSetScore&);
00121 ActionSetScore(const QString&);
00122 virtual ~ActionSetScore();
00123 virtual QString toString() const;
00124 virtual int getType() const { return SETSCORE; }
00125 virtual QString getValueString() const { return QString::number(val); }
00126 virtual void setValue(const QString& s) { val = s.toShort(); }
00127 void setValue(short v) { val = v; }
00128 short value() const { return val; }
00129 virtual void apply(ScorableArticle&) const;
00130 virtual ActionSetScore* clone() const;
00131 private:
00132 short val;
00133 };
00134
00135 class ActionNotify : public ActionBase {
00136 public:
00137 ActionNotify(const QString&);
00138 ActionNotify(const ActionNotify&);
00139 virtual ~ActionNotify() {}
00140 virtual QString toString() const;
00141 virtual int getType() const { return NOTIFY; }
00142 virtual QString getValueString() const { return note; }
00143 virtual void setValue(const QString& s) { note = s; }
00144 virtual void apply(ScorableArticle&) const;
00145 virtual ActionNotify* clone() const;
00146 private:
00147 QString note;
00148 };
00149
00150 class NotifyCollection
00151 {
00152 public:
00153 NotifyCollection();
00154 ~NotifyCollection();
00155 void addNote(const ScorableArticle&, const QString&);
00156 QString collection() const;
00157 void displayCollection(QWidget *p=0) const;
00158 private:
00159 struct article_info {
00160 QString from;
00161 QString subject;
00162 };
00163 typedef QValueList<article_info> article_list;
00164 typedef QDict<article_list> note_list;
00165 note_list notifyList;
00166 };
00167
00168
00169
00170 class KScoringExpression
00171 {
00172 friend class KScoringRule;
00173 public:
00174 enum Condition { CONTAINS, MATCH, EQUALS, SMALLER, GREATER };
00175
00176 KScoringExpression(const QString&,const QString&,const QString&, const QString&);
00177 ~KScoringExpression();
00178
00179 bool match(ScorableArticle& a) const ;
00180 QString getTypeString() const;
00181 static QString getTypeString(int);
00182 int getType() const;
00183 QString toString() const;
00184 void write(QTextStream& ) const;
00185
00186 bool isNeg() const { return neg; }
00187 Condition getCondition() const { return cond; }
00188 QString getExpression() const { return expr_str; }
00189 QString getHeader() const { return header; }
00190 static QStringList conditionNames();
00191 static QStringList headerNames();
00192 static int getConditionForName(const QString&);
00193 static QString getNameForCondition(int);
00194 private:
00195 bool neg;
00196 QString header;
00197 const char* c_header;
00198 Condition cond;
00199 QRegExp expr;
00200 QString expr_str;
00201 int expr_int;
00202 };
00203
00204
00205 class KScoringRule
00206 {
00207 friend class KScoringManager;
00208 public:
00209 KScoringRule(const QString& name);
00210 KScoringRule(const KScoringRule& r);
00211 ~KScoringRule();
00212
00213 typedef QPtrList<KScoringExpression> ScoreExprList;
00214 typedef QPtrList<ActionBase> ActionList;
00215 typedef QStringList GroupList;
00216 enum LinkMode { AND, OR };
00217
00218 QString getName() const { return name; }
00219 QStringList getGroups() const { return groups; }
00220 void setGroups(QStringList l) { groups = l; }
00221 LinkMode getLinkMode() const { return link; }
00222 QString getLinkModeName() const;
00223 QString getExpireDateString() const;
00224 QDate getExpireDate() const { return expires; }
00225 void setExpireDate(QDate d) { expires = d; }
00226 bool isExpired() const;
00227 ScoreExprList getExpressions() const { return expressions; }
00228 ActionList getActions() const { return actions; }
00229 void cleanExpressions();
00230 void cleanActions();
00231
00232 bool matchGroup(const QString& group) const ;
00233 void applyRule(ScorableArticle& a) const;
00234 void applyRule(ScorableArticle& a, const QString& group) const;
00235 void applyAction(ScorableArticle& a) const;
00236
00237 void setLinkMode(const QString& link);
00238 void setLinkMode(LinkMode m) { link = m; }
00239 void setExpire(const QString& exp);
00240 void addExpression( KScoringExpression* );
00241 void addGroup( const QString& group) { groups.append(group); }
00242
00243 void addAction(int, const QString& );
00244 void addAction(ActionBase*);
00245
00246 void updateXML(QDomElement& e, QDomDocument& d);
00247 QString toString() const;
00248
00249
00250 void write(QTextStream& ) const;
00251 protected:
00253 void setName(QString n) { name = n; }
00254 private:
00255 QString name;
00256 GroupList groups;
00257
00258 LinkMode link;
00259 ScoreExprList expressions;
00260 ActionList actions;
00261 QDate expires;
00262 };
00263
00268 class RuleStack
00269 {
00270 public:
00271 RuleStack();
00272 ~RuleStack();
00274 void push(QPtrList<KScoringRule>&);
00277 void pop(QPtrList<KScoringRule>&);
00279 void top(QPtrList<KScoringRule>&);
00281 void drop();
00282 private:
00283 QPtrStack< QPtrList<KScoringRule> > stack;
00284 };
00285
00286
00287
00288 class KScoringManager : public QObject
00289 {
00290 Q_OBJECT
00291
00292 public:
00293
00294 typedef QPtrList<KScoringRule> ScoringRuleList;
00295
00296 KScoringManager(const QString& appName = QString::null);
00297 virtual ~KScoringManager();
00298
00299
00300 virtual QStringList getGroups() const =0;
00301
00304 virtual QStringList getDefaultHeaders() const;
00305
00306
00307 void applyRules(ScorableArticle& article, const QString& group);
00308
00309 void applyRules(ScorableArticle&);
00310
00311 void applyRules(ScorableGroup* group);
00312
00313
00314 void pushRuleList();
00315
00316
00317
00318 void popRuleList();
00319
00320 void removeTOS();
00321
00322 KScoringRule* addRule(KScoringRule *);
00323 KScoringRule* addRule(const ScorableArticle&, QString group, short =0);
00324 KScoringRule* addRule();
00325 void cancelNewRule(KScoringRule *);
00326 void deleteRule(KScoringRule *);
00327 void editRule(KScoringRule *e, QWidget *w=0);
00328 KScoringRule* copyRule(KScoringRule *);
00329 void setGroup(const QString& g);
00330
00331 bool hasRulesForCurrentGroup();
00332 QString findUniqueName() const;
00333
00336 void editorReady();
00337
00338 ScoringRuleList getAllRules() const { return allRules; }
00339 KScoringRule *findRule(const QString&);
00340 QStringList getRuleNames();
00341 void setRuleName(KScoringRule *, const QString&);
00342 int getRuleCount() const { return allRules.count(); }
00343 QString toString() const;
00344
00345 bool setCacheValid(bool v);
00346 bool isCacheValid() { return cacheValid; }
00347 void initCache(const QString& group);
00348
00349 void load();
00350 void save();
00351
00352
00353 virtual bool canScores() const { return true; }
00354 virtual bool canNotes() const { return true; }
00355 virtual bool canColors() const { return false; }
00356 virtual bool hasFeature(int);
00357
00358 signals:
00359 void changedRules();
00360 void changedRuleName(const QString& oldName, const QString& newName);
00361 void finishedEditing();
00362
00363 private:
00364 void addRuleInternal(KScoringRule *e);
00365 void expireRules();
00366
00367 QDomDocument createXMLfromInternal();
00368 void createInternalFromXML(QDomNode);
00369
00370
00371 ScoringRuleList allRules;
00372
00373
00374 RuleStack stack;
00375
00376
00377 bool cacheValid;
00378
00379 ScoringRuleList ruleList;
00380
00381 QString group;
00382
00383
00384
00385
00386 QString mFilename;
00387 };
00388
00389
00390
00391 class NotifyDialog : public KDialogBase
00392 {
00393 Q_OBJECT
00394 public:
00395 static void display(ScorableArticle&,const QString&);
00396 protected slots:
00397 void slotShowAgainToggled(bool);
00398 private:
00399 NotifyDialog(QWidget* p =0);
00400 static NotifyDialog *me;
00401
00402 QLabel *note;
00403 QString msg;
00404 typedef QMap<QString,bool> NotesMap;
00405 static NotesMap dict;
00406 };
00407
00408
00409 #endif
This file is part of the documentation for libkdenetwork Library Version 3.3.2.