kmail

kmsearchpatternedit.h

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "gnu" -*-
00002 // kmfilterrulesedit.h
00003 // Author: Marc Mutz <Marc@Mutz.com>
00004 // This code is under GPL
00005 
00006 #ifndef KMFILTERRULESEDIT_H
00007 #define KMFILTERRULESEDIT_H
00008 
00009 #include "kwidgetlister.h"
00010 
00011 #include <qgroupbox.h>
00012 #include <qstringlist.h>
00013 
00014 class KMSearchRule;
00015 class KMSearchPattern;
00016 
00017 template <typename T> class QPtrList;
00018 class QString;
00019 class QComboBox;
00020 class QLineEdit;
00021 class QRadioButton;
00022 class QWidgetStack;
00023 class QLabel;
00024 class KMSearchPatternEdit;
00025 
00040 class KMSearchRuleWidget : public QWidget
00041 {
00042   Q_OBJECT
00043 public:
00046   KMSearchRuleWidget( QWidget* parent=0, KMSearchRule* aRule=0, const char* name=0, bool headersOnly = false, bool absoluteDates = false );
00047 
00048   enum { Message, Body, AnyHeader, Recipients, Size, AgeInDays, Status };
00049 
00053   void setHeadersOnly( bool headersOnly );
00059   void setRule( KMSearchRule* aRule );
00061   KMSearchRule* rule() const;
00064   void reset();
00065   static int ruleFieldToId( const QString & i18nVal );
00066 
00067 public slots:
00068   void slotFunctionChanged();
00069   void slotValueChanged();
00070 
00071 signals:
00075   void fieldChanged( const QString & );
00076 
00079   void contentsChanged( const QString & );
00080 
00081 protected:
00084   static QCString ruleFieldToEnglish(const QString & i18nVal);
00087   int indexOfRuleField( const QCString & aName ) const;
00088 
00089 protected slots:
00090   void slotRuleFieldChanged( const QString & );
00091 
00092 private:
00093   void initWidget();
00094   void initFieldList( bool headersOnly, bool absoluteDates );
00095 
00096   QStringList mFilterFieldList;
00097   QComboBox *mRuleField;
00098   QWidgetStack *mFunctionStack;
00099   QWidgetStack *mValueStack;
00100   bool mAbsoluteDates;
00101 };
00102 
00103 
00104 class KMSearchRuleWidgetLister : public KWidgetLister
00105 {
00106   Q_OBJECT
00107 
00108   friend class ::KMSearchPatternEdit;
00109 
00110 public:
00111   KMSearchRuleWidgetLister( QWidget *parent=0, const char* name=0, bool headersOnly = false, bool absoluteDates = false );
00112 
00113   virtual ~KMSearchRuleWidgetLister();
00114 
00115   void setRuleList( QPtrList<KMSearchRule> * aList );
00116   void setHeadersOnly( bool headersOnly );
00117 
00118 public slots:
00119   void reset();
00120 
00121 protected:
00122   virtual void clearWidget( QWidget *aWidget );
00123   virtual QWidget* createWidget( QWidget *parent );
00124 
00125 private:
00126   void regenerateRuleListFromWidgets();
00127   QPtrList<KMSearchRule> *mRuleList;
00128   bool mHeadersOnly;
00129   bool mAbsoluteDates;
00130 };
00131 
00132 
00165 class KMSearchPatternEdit : public QGroupBox  {
00166   Q_OBJECT
00167 public:
00170   KMSearchPatternEdit(QWidget *parent=0, const char *name=0, bool headersOnly = false, bool absoluteDates = false);
00173   KMSearchPatternEdit(const QString & title, QWidget *parent=0, const char *name=0, bool headersOnly = false, bool absoluteDates = false);
00174   ~KMSearchPatternEdit();
00175 
00180   void setSearchPattern( KMSearchPattern* aPattern );
00184   void setHeadersOnly( bool headersOnly );
00185 
00187   void updateSearchPattern() { mRuleLister->regenerateRuleListFromWidgets(); }
00188 
00189 public slots:
00192   void reset();
00193 
00194 signals:
00197   void maybeNameChanged();
00198 
00199 private slots:
00200   void slotRadioClicked(int aIdx);
00201   void slotAutoNameHack();
00202 
00203 private:
00204   void initLayout( bool headersOnly, bool absoluteDates );
00205 
00206   KMSearchPattern *mPattern;
00207   QRadioButton    *mAllRBtn, *mAnyRBtn;
00208   KMSearchRuleWidgetLister *mRuleLister;
00209 };
00210 
00211 #endif