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

kmail

kmsearchpattern.h

Go to the documentation of this file.
00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002   kmsearchpattern.h
00003   Author: Marc Mutz <Marc@Mutz.com>
00004 
00005   This program is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   This program is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013   GNU General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License along
00016   with this program; if not, write to the Free Software Foundation, Inc.,
00017   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef _kmsearchpattern_h_
00021 #define _kmsearchpattern_h_
00022 
00023 #include <klocale.h>
00024 #include <messagestatus.h>
00025 using KPIM::MessageStatus;
00026 
00027 #include <QList>
00028 #include <QString>
00029 
00030 class KMMessage;
00031 class KConfigGroup;
00032 class DwBoyerMoore;
00033 class DwString;
00034 
00035 
00036 // maximum number of filter rules per filter
00037 const int FILTER_MAX_RULES=8;
00038 
00046 class KMSearchRule
00047 {
00048 public:
00056   enum Function { FuncNone = -1,
00057                   FuncContains=0, FuncContainsNot,
00058                   FuncEquals, FuncNotEqual,
00059                   FuncRegExp, FuncNotRegExp,
00060                   FuncIsGreater, FuncIsLessOrEqual,
00061                   FuncIsLess, FuncIsGreaterOrEqual,
00062                   FuncIsInAddressbook, FuncIsNotInAddressbook,
00063                   FuncIsInCategory, FuncIsNotInCategory,
00064                   FuncHasAttachment, FuncHasNoAttachment};
00065   explicit KMSearchRule ( const QByteArray & field=0, Function=FuncContains,
00066                  const QString &contents=QString() );
00067   KMSearchRule ( const KMSearchRule &other );
00068 
00069   const KMSearchRule & operator=( const KMSearchRule & other );
00070 
00073   static KMSearchRule* createInstance( const QByteArray & field=0,
00074                                       Function function=FuncContains,
00075                                       const QString & contents=QString() );
00076 
00077   static KMSearchRule* createInstance( const QByteArray & field,
00078                                        const char * function,
00079                                        const QString & contents );
00080 
00081   static KMSearchRule * createInstance( const KMSearchRule & other );
00082 
00088   static KMSearchRule* createInstanceFromConfig( const KConfigGroup & config, int aIdx );
00089 
00090   virtual ~KMSearchRule() {}
00091 
00096   virtual bool matches( const KMMessage * msg ) const = 0;
00097 
00102   virtual bool matches( const DwString & str, KMMessage & msg,
00103                         const DwBoyerMoore * headerField=0,
00104                         int headerLen=-1 ) const;
00105 
00110   virtual bool isEmpty() const = 0;
00111 
00114   virtual bool requiresBody() const { return true; }
00115 
00116 
00122   void writeConfig( KConfigGroup & config, int aIdx ) const;
00123 
00126   Function function() const { return mFunction; }
00127 
00129   void setFunction( Function aFunction ) { mFunction = aFunction; }
00130 
00141   QByteArray field() const { return mField; }
00142 
00145   void setField( const QByteArray & field ) { mField = field; }
00146 
00149   QString contents() const { return mContents; }
00151   void setContents( const QString & aContents ) { mContents = aContents; }
00152 
00154   const QString asString() const;
00155 
00156 private:
00157   static Function configValueToFunc( const char * str );
00158   static QString functionToString( Function function );
00159 
00160   QByteArray mField;
00161   Function mFunction;
00162   QString  mContents;
00163 };
00164 
00165 
00166 // subclasses representing the different kinds of searches
00167 
00173 class KMSearchRuleString : public KMSearchRule
00174 {
00175 public:
00176   explicit KMSearchRuleString( const QByteArray & field=0,
00177                 Function function=FuncContains, const QString & contents=QString() );
00178   KMSearchRuleString( const KMSearchRuleString & other );
00179   const KMSearchRuleString & operator=( const KMSearchRuleString & other );
00180 
00181   virtual ~KMSearchRuleString();
00182   virtual bool isEmpty() const ;
00183   virtual bool requiresBody() const;
00184 
00185   virtual bool matches( const KMMessage * msg ) const;
00186 
00190   virtual bool matches( const DwString & str, KMMessage & msg,
00191                         const DwBoyerMoore * headerField=0,
00192                         int headerLen=-1 ) const;
00193 
00195   bool matchesInternal( const QString & msgContents ) const;
00196 
00197 private:
00198   const DwBoyerMoore *mBmHeaderField;
00199 };
00200 
00201 
00207 class KMSearchRuleNumerical : public KMSearchRule
00208 {
00209 public:
00210   explicit KMSearchRuleNumerical( const QByteArray & field=0,
00211                          Function function=FuncContains, const QString & contents=QString() );
00212   virtual bool isEmpty() const ;
00213 
00214   virtual bool matches( const KMMessage * msg ) const;
00215 
00216   // Optimized matching not implemented, will use the unoptimized matching
00217   // from KMSearchRule
00218   using KMSearchRule::matches;
00219 
00221   bool matchesInternal( long numericalValue, long numericalMsgContents,
00222                         const QString & msgContents ) const;
00223 };
00224 
00225 
00226 namespace KMail {
00227 // The below are used in several places and here so they are accessible.
00228   struct MessageStatus {
00229     const char * const text;
00230     const char * const icon;
00231   };
00232 
00233   // If you change the ordering here; also do it in the enum below
00234   static const MessageStatus StatusValues[] = {
00235     { I18N_NOOP2( "message status", "Important" ),              "emblem-important"    },
00236     { I18N_NOOP2( "message status", "Action Item" ),            "mail-task"           },
00237     { I18N_NOOP2( "message status", "New" ),                    "mail-unread-new"     },
00238     { I18N_NOOP2( "message status", "Unread" ),                 "mail-unread"         },
00239     { I18N_NOOP2( "message status", "Read" ),                   "mail-read"           },
00240     { I18N_NOOP2( "message status", "Deleted" ),                "mail-deleted"        },
00241     { I18N_NOOP2( "message status", "Replied" ),                "mail-replied"        },
00242     { I18N_NOOP2( "message status", "Forwarded" ),              "mail-forwarded"      },
00243     { I18N_NOOP2( "message status", "Queued" ),                 "mail-queued"         },
00244     { I18N_NOOP2( "message status", "Sent" ),                   "mail-sent"           },
00245     { I18N_NOOP2( "message status", "Watched" ),                "mail-thread-watch"   },
00246     { I18N_NOOP2( "message status", "Ignored" ),                "mail-thread-ignored" },
00247     { I18N_NOOP2( "message status", "Spam" ),                   "mail-mark-junk"      },
00248     { I18N_NOOP2( "message status", "Ham" ),                    "mail-mark-notjunk"   },
00249     { I18N_NOOP2( "message status", "Has Attachment"),          "mail-attachment"     } //must be last
00250   };
00251   // If you change the ordering here; also do it in the array above
00252   enum StatusValueTypes {
00253     StatusImportant = 0,
00254     StatusToAct = 1,
00255     StatusNew = 2,
00256     StatusUnread = 3,
00257     StatusRead = 4,
00258     StatusDeleted = 5,
00259     StatusReplied = 6,
00260     StatusForwarded = 7,
00261     StatusQueued = 8,
00262     StatusSent = 9,
00263     StatusWatched = 10,
00264     StatusIgnored = 11,
00265     StatusSpam = 12,
00266     StatusHam = 13,
00267     StatusHasAttachment = 14 //must be last
00268   };
00269 
00270   static const int StatusValueCount =
00271     sizeof( StatusValues ) / sizeof( MessageStatus );
00272   // we want to show all status entries in the quick search bar, but only the
00273   // ones up to attachment in the search/filter dialog, because there the
00274   // attachment case is handled separately.
00275   static const int StatusValueCountWithoutHidden = StatusValueCount - 1;
00276 }
00277 
00283 class KMSearchRuleStatus : public KMSearchRule
00284 {
00285 public:
00286    explicit KMSearchRuleStatus( const QByteArray & field=0, Function function=FuncContains,
00287                                 const QString & contents=QString() );
00288    KMSearchRuleStatus( MessageStatus status, Function function=FuncContains );
00289 
00290    virtual bool isEmpty() const ;
00291    virtual bool matches( const KMMessage * msg ) const;
00292 
00293    //Not possible to implement optimized form for status searching
00294    using KMSearchRule::matches;
00295 
00296 
00297    static MessageStatus statusFromEnglishName(const QString&);
00298 private:
00299    MessageStatus mStatus;
00300 };
00301 
00302 // ------------------------------------------------------------------------
00303 
00322 class KMSearchPattern : public QList<KMSearchRule*>
00323 {
00324 
00325 public:
00331   enum Operator { OpAnd, OpOr };
00332 
00338   KMSearchPattern();
00339 
00344   KMSearchPattern( const KConfigGroup & config );
00345 
00347   ~KMSearchPattern();
00348 
00358   bool matches( const KMMessage * msg, bool ignoreBody = false ) const;
00359   bool matches( const DwString & str, bool ignoreBody = false ) const;
00360   bool matches( quint32 sernum, bool ignoreBody = false ) const;
00361 
00364   bool requiresBody() const;
00365 
00370   void purify();
00371 
00383   void readConfig( const KConfigGroup & config );
00384 
00391   void writeConfig( KConfigGroup & config ) const;
00392 
00394   QString name() const { return mName; }
00397   void setName( const QString & newName ) { mName = newName ; }
00398 
00400   KMSearchPattern::Operator op() const { return mOperator; }
00402   void setOp( KMSearchPattern::Operator aOp ) { mOperator = aOp; }
00403 
00405   QString asString() const;
00406 
00408   const KMSearchPattern & operator=( const KMSearchPattern & aPattern );
00409 
00410 private:
00418   void importLegacyConfig( const KConfigGroup & config );
00419 
00422   void init();
00423 
00424   QString  mName;
00425   Operator mOperator;
00426 };
00427 
00428 #endif /* _kmsearchpattern_h_ */

kmail

Skip menu "kmail"
  • Main Page
  • 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