00001
00002
00003
00004
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"
00014
00015 class KMMessage;
00016 class KConfig;
00017 class DwBoyerMoore;
00018 class DwString;
00019
00020
00021
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
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
00209 namespace KMail {
00210
00211 struct MessageStatus {
00212 const char * const text;
00213 const char * const icon;
00214 };
00215
00216
00217 static const MessageStatus StatusValues[] = {
00218 { I18N_NOOP( "Important" ), "kmmsgflag" },
00219 { I18N_NOOP( "New" ), "kmmsgnew" },
00220 { I18N_NOOP( "Unread" ), "kmmsgunseen" },
00221 { I18N_NOOP( "Read" ), "kmmsgread" },
00222 { I18N_NOOP( "Old" ), 0 },
00223 { I18N_NOOP( "Deleted" ), "kmmsgdel" },
00224 { I18N_NOOP( "Replied" ), "kmmsgreplied" },
00225 { I18N_NOOP( "Forwarded" ), "kmmsgforwarded" },
00226 { I18N_NOOP( "Queued" ), "kmmsgqueued" },
00227 { I18N_NOOP( "Sent" ), "kmmsgsent" },
00228 { I18N_NOOP( "Watched" ), "kmmsgwatched" },
00229 { I18N_NOOP( "Ignored" ), "kmmsgignored" },
00230 { I18N_NOOP( "Spam" ), "kmmsgspam" },
00231 { I18N_NOOP( "Ham" ), "kmmsgham" },
00232 { I18N_NOOP( "To Do" ), "kmmsgtodo" },
00233 { I18N_NOOP( "Has Attachment"), "kmmsgattachment" }
00234 };
00235
00236 enum StatusValueTypes {
00237 StatusImportant = 0,
00238 StatusNew = 1,
00239 StatusUnread = 2,
00240 StatusRead = 3,
00241 StatusOld = 4,
00242 StatusDeleted = 5,
00243 StatusReplied = 6,
00244 StatusForwarded = 7,
00245 StatusQueued = 8,
00246 StatusSent = 9,
00247 StatusWatched = 10,
00248 StatusIgnored = 11,
00249 StatusSpam = 12,
00250 StatusHam = 13,
00251 StatusToDo = 14,
00252 StatusHasAttachment = 15
00253 };
00254
00255 static const int StatusValueCount =
00256 sizeof( StatusValues ) / sizeof( MessageStatus );
00257
00258
00259
00260 static const int StatusValueCountWithoutHidden = StatusValueCount - 1;
00261 }
00262
00268 class KMSearchRuleStatus : public KMSearchRule
00269 {
00270 public:
00271 KMSearchRuleStatus( const QCString & field=0, Function function=FuncContains,
00272 const QString & contents=QString::null );
00273 KMSearchRuleStatus( int status, Function function=FuncContains );
00274
00275 virtual bool isEmpty() const ;
00276 virtual bool matches( const KMMessage * msg ) const;
00277
00278 virtual bool matches( const DwString &, KMMessage &,
00279 const DwBoyerMoore *,
00280 int ) const;
00281 static KMMsgStatus statusFromEnglishName(const QString&);
00282 private:
00283 KMMsgStatus mStatus;
00284 };
00285
00286
00287
00306 class KMSearchPattern : public QPtrList<KMSearchRule>
00307 {
00308
00309 public:
00315 enum Operator { OpAnd, OpOr };
00324 KMSearchPattern( const KConfig * config=0 );
00325
00327 ~KMSearchPattern();
00328
00338 bool matches( const KMMessage * msg, bool ignoreBody = false ) const;
00339 bool matches( const DwString & str, bool ignoreBody = false ) const;
00340 bool matches( Q_UINT32 sernum, bool ignoreBody = false ) const;
00341
00344 bool requiresBody() const;
00345
00350 void purify();
00351
00364 void readConfig( const KConfig * config );
00371 void writeConfig( KConfig * config ) const;
00372
00374 QString name() const { return mName; }
00377 void setName( const QString & newName ) { mName = newName ; }
00378
00380 KMSearchPattern::Operator op() const { return mOperator; }
00382 void setOp( KMSearchPattern::Operator aOp ) { mOperator = aOp; }
00383
00385 QString asString() const;
00386
00388 const KMSearchPattern & operator=( const KMSearchPattern & aPattern );
00389
00390 private:
00398 void importLegacyConfig( const KConfig * config );
00401 void init();
00402
00403 QString mName;
00404 Operator mOperator;
00405 };
00406
00407 #endif