• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

libkdepim

kscoring.h

Go to the documentation of this file.
00001 /*
00002   kscoring.h
00003 
00004   Copyright (c) 2001 Mathias Waack <mathias@atoll-net.de>
00005   Copyright (C) 2005 by Volker Krause <volker.krause@rwth-aachen.de>
00006 
00007   Author: Mathias Waack <mathias@atoll-net.de>
00008 
00009   This program is free software; you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation; either version 2 of the License, or
00012   (at your option) any later version.
00013   You should have received a copy of the GNU General Public License
00014   along with this program; if not, write to the Free Software Foundation,
00015   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
00016 */
00017 
00018 #ifndef KDEPIM_KSCORING_H
00019 #define KDEPIM_KSCORING_H
00020 
00021 #include "kdepim_export.h"
00022 
00023 #include <KDialog>
00024 
00025 #include <QColor>
00026 #include <QMap>
00027 #include <QObject>
00028 #include <QRegExp>
00029 #include <QString>
00030 #include <QStringList>
00031 #include <QTextStream>
00032 #include <Q3Dict>
00033 #include <Q3PtrList>
00034 #include <Q3PtrStack>
00035 
00036 #include <unistd.h>
00037 
00038 class QDomNode;
00039 class QDomDocument;
00040 class QDomElement;
00041 class QLabel;
00042 
00043 namespace KPIM {
00044 
00052 //----------------------------------------------------------------------------
00053 class KDEPIM_EXPORT ScorableGroup
00054 {
00055 public:
00056   virtual ~ScorableGroup();
00057 };
00058 
00059 class KDEPIM_EXPORT ScorableArticle
00060 {
00061   public:
00062     virtual ~ScorableArticle();
00063 
00064     virtual void addScore( short ) {}
00065     virtual void displayMessage( const QString & );
00066     virtual void changeColor( const QColor & ) {}
00067     virtual void markAsRead() {}
00068     virtual QString from() const = 0;
00069     virtual QString subject() const = 0;
00070     virtual QString getHeaderByType( const QString & ) const = 0;
00071 };
00072 
00073 //----------------------------------------------------------------------------
00077 class KDEPIM_EXPORT ActionBase {
00078   public:
00079     ActionBase();
00080     virtual ~ActionBase();
00081     virtual QString toString() const = 0;
00082     virtual void apply( ScorableArticle & ) const = 0;
00083     virtual ActionBase *clone() const = 0;
00084     virtual int getType() const = 0;
00085     virtual QString getValueString() const { return QString(); }
00086     virtual void setValue( const QString & ) {}
00087     static ActionBase *factory( int type, const QString &value );
00088     static QStringList userNames();
00089     static QString userName( int type );
00090     static int getTypeForName( const QString &name );
00091     static int getTypeForUserName( const QString &name );
00092     QString userName() { return userName( getType() ); }
00093     enum ActionTypes {
00094       SETSCORE,
00095       NOTIFY,
00096       COLOR,
00097       MARKASREAD
00098     };
00099 };
00100 
00101 class KDEPIM_EXPORT ActionColor : public ActionBase {
00102   public:
00103     ActionColor( const QColor & );
00104     ActionColor( const QString & );
00105     ActionColor( const ActionColor & );
00106     virtual ~ActionColor();
00107     virtual QString toString() const;
00108     virtual int getType() const { return COLOR; }
00109     virtual QString getValueString() const { return color.name(); }
00110     virtual void setValue( const QString &s ) { color.setNamedColor(s); }
00111     void setValue( const QColor &c ) { color = c; }
00112     QColor value() const { return color; }
00113     virtual void apply( ScorableArticle & ) const;
00114     virtual ActionColor *clone() const;
00115 
00116   private:
00117     QColor color;
00118 };
00119 
00120 class KDEPIM_EXPORT ActionSetScore : public ActionBase {
00121   public:
00122     ActionSetScore( short );
00123     ActionSetScore( const ActionSetScore & );
00124     ActionSetScore( const QString & );
00125     virtual ~ActionSetScore();
00126     virtual QString toString() const;
00127     virtual int getType() const { return SETSCORE; }
00128     virtual QString getValueString() const { return QString::number(val); }
00129     virtual void setValue( const QString &s ) { val = s.toShort(); }
00130     void setValue( short v ) { val = v; }
00131     short value() const { return val; }
00132     virtual void apply( ScorableArticle & ) const;
00133     virtual ActionSetScore *clone() const;
00134 
00135   private:
00136     short val;
00137 };
00138 
00139 class KDEPIM_EXPORT ActionNotify : public ActionBase {
00140   public:
00141     ActionNotify( const QString & );
00142     ActionNotify( const ActionNotify & );
00143     virtual ~ActionNotify() {}
00144     virtual QString toString() const;
00145     virtual int getType() const { return NOTIFY; }
00146     virtual QString getValueString() const { return note; }
00147     virtual void setValue( const QString &s ) { note = s; }
00148     virtual void apply( ScorableArticle & ) const;
00149     virtual ActionNotify *clone() const;
00150 
00151   private:
00152     QString note;
00153 };
00154 
00155 class KDEPIM_EXPORT ActionMarkAsRead : public ActionBase {
00156     public:
00157     ActionMarkAsRead();
00158     ActionMarkAsRead( const ActionMarkAsRead & );
00159     virtual ~ActionMarkAsRead() {}
00160     virtual QString toString() const;
00161     virtual int getType() const { return MARKASREAD; }
00162     virtual void apply( ScorableArticle &article ) const;
00163     virtual ActionMarkAsRead *clone() const;
00164 };
00165 
00166 class KDEPIM_EXPORT NotifyCollection
00167 {
00168   public:
00169     NotifyCollection();
00170     ~NotifyCollection();
00171     void addNote( const ScorableArticle &, const QString & );
00172     QString collection() const;
00173     void displayCollection( QWidget *p=0 ) const;
00174   private:
00175     struct article_info {
00176       QString from;
00177       QString subject;
00178     };
00179     typedef QList<article_info> article_list;
00180     typedef Q3Dict<article_list> note_list;
00181     note_list notifyList;
00182 };
00183 
00184 //----------------------------------------------------------------------------
00185 class KDEPIM_EXPORT KScoringExpression
00186 {
00187   friend class KScoringRule;
00188   public:
00189     enum Condition {
00190       CONTAINS,
00191       MATCH,
00192       EQUALS,
00193       SMALLER,
00194       GREATER,
00195       MATCHCS
00196     };
00197 
00198     KScoringExpression( const QString &, const QString &, const QString &, const QString & );
00199     ~KScoringExpression();
00200 
00201     bool match( ScorableArticle &a ) const ;
00202     QString getTypeString() const;
00203     static QString getTypeString( int );
00204     int getType() const;
00205     QString toString() const;
00206     void write( QTextStream & ) const;
00207 
00208     bool isNeg() const { return neg; }
00209     Condition getCondition() const { return cond; }
00210     QString getExpression() const { return expr_str; }
00211     QString getHeader() const { return header; }
00212     static QStringList conditionNames();
00213     static QStringList headerNames();
00214     static int getConditionForName( const QString & );
00215     static QString getNameForCondition( int );
00216 
00217   private:
00218     bool neg;
00219     QString header;
00220     const char *c_header;
00221     Condition cond;
00222     QRegExp expr;
00223     QString expr_str;
00224     int expr_int;
00225 };
00226 
00227 //----------------------------------------------------------------------------
00228 class KDEPIM_EXPORT KScoringRule
00229 {
00230   friend class KScoringManager;
00231   public:
00232     KScoringRule( const QString &name );
00233     KScoringRule( const KScoringRule &r );
00234     ~KScoringRule();
00235 
00236     typedef Q3PtrList<KScoringExpression> ScoreExprList;
00237     typedef Q3PtrList<ActionBase> ActionList;
00238     typedef QStringList GroupList;
00239     enum LinkMode {
00240       AND,
00241       OR
00242     };
00243 
00244     QString getName() const { return name; }
00245     QStringList getGroups() const { return groups; }
00246     void setGroups( const QStringList &l ) { groups = l; }
00247     LinkMode getLinkMode() const { return link; }
00248     QString getLinkModeName() const;
00249     QString getExpireDateString() const;
00250     QDate getExpireDate() const { return expires; }
00251     void setExpireDate( const QDate &d ) { expires = d; }
00252     bool isExpired() const;
00253     ScoreExprList getExpressions() const { return expressions; }
00254     ActionList getActions() const { return actions; }
00255     void cleanExpressions();
00256     void cleanActions();
00257 
00258     bool matchGroup( const QString &group ) const ;
00259     void applyRule( ScorableArticle &a ) const;
00260     void applyRule( ScorableArticle &a, const QString &group ) const;
00261     void applyAction( ScorableArticle &a ) const;
00262 
00263     void setLinkMode( const QString &link );
00264     void setLinkMode( LinkMode m ) { link = m; }
00265     void setExpire( const QString &exp );
00266     void addExpression( KScoringExpression * );
00267     void addGroup( const QString &group ) { groups.append(group); }
00268     void addAction( int, const QString & );
00269     void addAction(ActionBase*);
00270 
00271     void updateXML( QDomElement &e, QDomDocument &d );
00272     QString toString() const;
00273 
00274     // writes the rule in XML format into the textstream
00275     void write( QTextStream & ) const;
00276 
00277   protected:
00279     void setName( const QString &n ) { name = n; }
00280 
00281   private:
00282     QString name;
00283     GroupList groups;
00284     //ServerList servers;
00285     LinkMode link;
00286     ScoreExprList expressions;
00287     ActionList actions;
00288     QDate expires;
00289 };
00290 
00295 class KDEPIM_EXPORT RuleStack
00296 {
00297   public:
00298     RuleStack();
00299     ~RuleStack();
00301     void push( Q3PtrList<KScoringRule>& );
00304     void pop( Q3PtrList<KScoringRule>& );
00306     void top( Q3PtrList<KScoringRule>& );
00308     void drop();
00309 
00310   private:
00311     Q3PtrStack< Q3PtrList<KScoringRule> > stack;
00312 };
00313 
00314 //----------------------------------------------------------------------------
00315 // Manages the score rules.
00316 class KDEPIM_EXPORT KScoringManager : public QObject
00317 {
00318   Q_OBJECT
00319   public:
00320     // this is the container for all rules
00321     typedef Q3PtrList<KScoringRule> ScoringRuleList;
00322 
00323     KScoringManager( const QString &appName = QString() );
00324     virtual ~KScoringManager();
00325 
00326     // returns a list of all available groups, must be overridden
00327     virtual QStringList getGroups() const = 0;
00328 
00331     virtual QStringList getDefaultHeaders() const;
00332 
00333     // setting current server and group and calling applyRules(ScorableArticle&)
00334     void applyRules( ScorableArticle &article, const QString &group );
00335     // assuming a properly set group
00336     void applyRules( ScorableArticle & );
00337     // same as above
00338     void applyRules( ScorableGroup *group );
00339 
00340     // pushes the current rule list onto a stack
00341     void pushRuleList();
00342     // restores the current rule list from list stored on a stack
00343     // by a previous call to pushRuleList (this implicitly deletes the
00344     // current rule list)
00345     void popRuleList();
00346     // removes the TOS from the stack of rule lists
00347     void removeTOS();
00348 
00349     KScoringRule *addRule( KScoringRule * );
00350     KScoringRule *addRule( const ScorableArticle &a, const QString &group, short score=0 );
00351     KScoringRule *addRule();
00352     void cancelNewRule( KScoringRule * );
00353     void deleteRule( KScoringRule * );
00354     void editRule( KScoringRule *e, QWidget *w=0 );
00355     KScoringRule *copyRule( KScoringRule * );
00356     void moveRuleAbove( KScoringRule *above, KScoringRule *below );
00357     void moveRuleBelow( KScoringRule *below, KScoringRule *above );
00358     void setGroup( const QString &g );
00359     // has to be called after setGroup() or initCache()
00360     bool hasRulesForCurrentGroup();
00361     QString findUniqueName() const;
00362 
00365     void editorReady();
00366 
00367     ScoringRuleList getAllRules() const { return allRules; }
00368     KScoringRule *findRule( const QString & );
00369     QStringList getRuleNames();
00370     void setRuleName( KScoringRule *, const QString & );
00371     int getRuleCount() const { return allRules.count(); }
00372     QString toString() const;
00373 
00374     bool setCacheValid( bool v );
00375     bool isCacheValid() { return cacheValid; }
00376     void initCache( const QString &group );
00377 
00378     void load();
00379     void save();
00380 
00381     //--------------- Properties
00382     virtual bool canScores() const { return true; }
00383     virtual bool canNotes() const { return true; }
00384     virtual bool canColors() const { return false; }
00385     virtual bool canMarkAsRead() const { return false; }
00386     virtual bool hasFeature( int );
00387 
00388   Q_SIGNALS:
00389     void changedRules();
00390     void changedRuleName( const QString &oldName, const QString &newName );
00391     void finishedEditing();
00392 
00393   private:
00394     void addRuleInternal( KScoringRule *e );
00395     void expireRules();
00396 
00397     QDomDocument createXMLfromInternal();
00398     void createInternalFromXML(QDomNode);
00399 
00400     // list of all Rules
00401     ScoringRuleList allRules;
00402 
00403     // the stack for temporary storing rule lists
00404     RuleStack stack;
00405 
00406     // for the cache
00407     bool cacheValid;
00408     // current rule set, ie the cache
00409     ScoringRuleList ruleList;
00410     //QString server;
00411     QString group;
00412 
00413     //ScorableServer* _s;
00414 
00415     // filename of the scorefile
00416     QString mFilename;
00417 };
00418 
00419 //----------------------------------------------------------------------------
00420 class KDEPIM_EXPORT NotifyDialog : public KDialog
00421 {
00422   Q_OBJECT
00423   public:
00424     static void display( ScorableArticle &, const QString & );
00425 
00426   protected Q_SLOTS:
00427     void slotShowAgainToggled( bool );
00428 
00429   private:
00430     NotifyDialog( QWidget *p=0 );
00431     static NotifyDialog *me;
00432 
00433     QLabel *note;
00434     QString msg;
00435     typedef QMap<QString,bool> NotesMap;
00436     static NotesMap dict;
00437 };
00438 
00439 }
00440 
00441 #endif

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal