kmail Library API Documentation

kmsearchpattern.h

00001 // -*- mode: C++; c-file-style: "gnu" -*-
00002 // kmsearchpattern.h
00003 // Author: Marc Mutz <Marc@Mutz.com>
00004 // This code is under GPL!
00005 
00006 #ifndef _kmsearchpattern_h_
00007 #define _kmsearchpattern_h_
00008 
00009 #include <klocale.h>
00010 #include <qptrlist.h>
00011 #include <qstring.h>
00012 #include <qcstring.h>
00013 #include "kmmsgbase.h" // for KMMsgStatus
00014 
00015 class KMMessage;
00016 class KConfig;
00017 class DwBoyerMoore;
00018 class DwString;
00019 
00020 
00021 // maximum number of filter rules per filter
00022 const int FILTER_MAX_RULES=8;
00023 
00031 class KMSearchRule
00032 {
00033 public:
00041   enum Function { FuncNone = -1,
00042                   FuncContains=0, FuncContainsNot,
00043           FuncEquals, FuncNotEqual,
00044           FuncRegExp, FuncNotRegExp,
00045           FuncIsGreater, FuncIsLessOrEqual,
00046           FuncIsLess, FuncIsGreaterOrEqual,
00047           FuncIsInAddressbook, FuncIsNotInAddressbook,
00048                   FuncIsInCategory, FuncIsNotInCategory,
00049           FuncHasAttachment, FuncHasNoAttachment};
00050   KMSearchRule ( const QCString & field=0, Function=FuncContains,
00051                  const QString &contents=QString::null );
00052   KMSearchRule ( const KMSearchRule &other );
00053 
00054   const KMSearchRule & operator=( const KMSearchRule & other );
00055 
00058   static KMSearchRule* createInstance( const QCString & field=0,
00059                                       Function function=FuncContains,
00060                               const QString & contents=QString::null );
00061 
00062   static KMSearchRule* createInstance( const QCString & field,
00063                                        const char * function,
00064                                        const QString & contents );
00065 
00066   static KMSearchRule * createInstance( const KMSearchRule & other );
00067 
00073   static KMSearchRule* createInstanceFromConfig( const KConfig * config, int aIdx );
00074 
00075   virtual ~KMSearchRule() {};
00076 
00081   virtual bool matches( const KMMessage * msg ) const = 0;
00082 
00087    virtual bool matches( const DwString & str, KMMessage & msg,
00088                          const DwBoyerMoore * headerField=0,
00089                          int headerLen=-1 ) const;
00090 
00095   virtual bool isEmpty() const = 0;
00096 
00099   virtual bool requiresBody() const { return true; }
00100 
00101 
00107   void writeConfig( KConfig * config, int aIdx ) const;
00108 
00111   Function function() const { return mFunction; }
00112 
00114   void setFunction( Function aFunction ) { mFunction = aFunction; }
00115 
00126   QCString field() const { return mField; }
00127 
00130   void setField( const QCString & field ) { mField = field; }
00131 
00134   QString contents() const { return mContents; }
00136   void setContents( const QString & aContents ) { mContents = aContents; }
00137 
00139   const QString asString() const;
00140 
00141 private:
00142   static Function configValueToFunc( const char * str );
00143   static QString functionToString( Function function );
00144 
00145   QCString mField;
00146   Function mFunction;
00147   QString  mContents;
00148 };
00149 
00150 
00151 // subclasses representing the different kinds of searches
00152 
00159 class KMSearchRuleString : public KMSearchRule
00160 {
00161 public:
00162   KMSearchRuleString( const QCString & field=0, Function function=FuncContains,
00163         const QString & contents=QString::null );
00164   KMSearchRuleString( const KMSearchRuleString & other );
00165   const KMSearchRuleString & operator=( const KMSearchRuleString & other );
00166 
00167   virtual ~KMSearchRuleString();
00168   virtual bool isEmpty() const ;
00169   virtual bool requiresBody() const;
00170 
00171   virtual bool matches( const KMMessage * msg ) const;
00172 
00176   virtual bool matches( const DwString & str, KMMessage & msg,
00177                         const DwBoyerMoore * headerField=0,
00178                         int headerLen=-1 ) const;
00179 
00181   bool matchesInternal( const QString & msgContents ) const;
00182 
00183 private:
00184   const DwBoyerMoore *mBmHeaderField;
00185 };
00186 
00187 
00194 class KMSearchRuleNumerical : public KMSearchRule
00195 {
00196 public:
00197   KMSearchRuleNumerical( const QCString & field=0, Function function=FuncContains,
00198                  const QString & contents=QString::null );
00199   virtual bool isEmpty() const ;
00200 
00201   virtual bool matches( const KMMessage * msg ) const;
00202 
00204   bool matchesInternal( long numericalValue, long numericalMsgContents,
00205                         const QString & msgContents ) const;
00206 };
00207 
00208 
00214 namespace KMail {
00215 // The below are used in several places and here so they are accessible.
00216   static const char * const StatusValues[] = {
00217     I18N_NOOP( "important" ),
00218     I18N_NOOP( "new" ),
00219     I18N_NOOP( "unread" ),
00220     I18N_NOOP( "read" ),
00221     I18N_NOOP( "old" ),
00222     I18N_NOOP( "deleted" ),
00223     I18N_NOOP( "replied" ),
00224     I18N_NOOP( "forwarded" ),
00225     I18N_NOOP( "queued" ),
00226     I18N_NOOP( "sent" ),
00227     I18N_NOOP( "watched" ),
00228     I18N_NOOP( "ignored" ),
00229     I18N_NOOP( "spam" ),
00230     I18N_NOOP( "ham" ),
00231     I18N_NOOP( "has an attachment"),
00232     I18N_NOOP( "todo" )
00233   };
00234   static const int StatusValueCount =
00235     sizeof( StatusValues ) / sizeof( *StatusValues ) -1 ;
00236   // we want to show all status entries in the quick search bar, but only the
00237   // ones up to attachment in the search/filter dialog, because there the
00238   // attachment case is handled separately.
00239   // Todo is hidden for both because it can currently not be set anywhere
00240   static const int StatusValueCountWithoutHidden = StatusValueCount - 2;
00241 }
00242 
00243 class KMSearchRuleStatus : public KMSearchRule
00244 {
00245 public:
00246    KMSearchRuleStatus( const QCString & field=0, Function function=FuncContains,
00247                const QString & contents=QString::null );
00248   virtual bool isEmpty() const ;
00249   virtual bool matches( const KMMessage * msg ) const;
00250   //Not possible to implement this form for status searching
00251   virtual bool matches( const DwString &, KMMessage &,
00252                         const DwBoyerMoore *,
00253             int ) const;
00254   static KMMsgStatus statusFromEnglishName(const QString&);
00255   private:
00256   KMMsgStatus mStatus;
00257 };
00258 
00259 // ------------------------------------------------------------------------
00260 
00280 class KMSearchPattern : public QPtrList<KMSearchRule>
00281 {
00282 
00283 public:
00288   enum Operator { OpAnd, OpOr };
00297   KMSearchPattern( const KConfig * config=0 );
00298 
00300   ~KMSearchPattern();
00301 
00311   bool matches( const KMMessage * msg ) const;
00312   bool matches( const DwString & str ) const;
00313   bool matches( Q_UINT32 sernum ) const;
00314 
00317   bool requiresBody() const;
00318 
00324   void purify();
00325 
00339   void readConfig( const KConfig * config );
00346   void writeConfig( KConfig * config ) const;
00347 
00349   QString name() const { return mName; }
00352   void setName( const QString & newName ) { mName = newName ; }
00353 
00355   KMSearchPattern::Operator op() const { return mOperator; }
00357   void setOp( KMSearchPattern::Operator aOp ) { mOperator = aOp; }
00358 
00360   QString asString() const;
00361 
00363   const KMSearchPattern & operator=( const KMSearchPattern & aPattern );
00364 
00365 private:
00372   void importLegacyConfig( const KConfig * config );
00375   void init();
00376 
00377   QString  mName;
00378   Operator mOperator;
00379 };
00380 
00381 #endif /* _kmsearchpattern_h_ */
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:21:31 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003