1 /* -*- mode: C++; c-file-style: "gnu" -*-
3 Author: Marc Mutz <Marc@Mutz.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef KMSEARCHPATTERNEDIT_H
21 #define KMSEARCHPATTERNEDIT_H
23 #include "kwidgetlister.h"
30 class KMSearchPattern
;
31 class KMSearchPatternEdit
;
33 class QAbstractButton
;
37 /** A widget to edit a single KMSearchRule.
38 It consists of an editable KComboBox for the field,
39 a read-only KComboBox for the function and
40 a QLineEdit for the content or the pattern (in case of regexps).
41 It manages the i18n itself, so field name should be in it's english form.
43 To use, you essentially give it the reference to a KMSearchRule and
44 it does the rest. It will never delete the rule itself, as it assumes
45 that something outside of it manages this.
47 @short A widget to edit a single KMSearchRule.
48 @author Marc Mutz <Marc@Mutz.com>
51 class KMSearchRuleWidget
: public QWidget
55 /** Constructor. You can give a KMSearchRule as parameter, which will
56 be used to initialize the widget. */
57 explicit KMSearchRuleWidget( QWidget
* parent
=0, KMSearchRule
* aRule
=0, bool headersOnly
= false, bool absoluteDates
= false );
59 enum { Message
, Body
, AnyHeader
, Recipients
, Size
, AgeInDays
, Status
,
60 Subject
, From
, To
, CC
};
62 /** Set whether only header fields can be searched. If @p is true only
63 header fields can be searched otherwise \<message\> and \<body\> searches
64 are available also. */
65 void setHeadersOnly( bool headersOnly
);
66 /** Set the rule. The rule is accepted regardless of the return
67 value of KMSearchRule::isEmpty. This widget makes a shallow
68 copy of @p aRule and operates directly on it. If @p aRule is
69 0, resets itself, taks user input, but does essentially
70 nothing. If you pass 0, you should probably disable it. */
71 void setRule( KMSearchRule
* aRule
);
72 /** Return a reference to the currently-worked-on KMSearchRule. */
73 KMSearchRule
* rule() const;
74 /** Resets the rule currently worked on and updates the widget
77 static int ruleFieldToId( const QString
& i18nVal
);
80 void slotFunctionChanged();
81 void slotValueChanged();
84 /** This signal is emitted whenever the user alters the field. The
85 pseudo-headers <...> are returned in their i18n form, but stored
86 in their english form in the rule. */
87 void fieldChanged( const QString
& );
89 /** This signal is emitted whenever the user alters the
90 contents/value of the rule. */
91 void contentsChanged( const QString
& );
94 /** Used internally to translate i18n-ized pseudo-headers back to
96 static QByteArray
ruleFieldToEnglish(const QString
& i18nVal
);
97 /** Used internally to find the corresponding index into the field
98 ComboBox. Returns the index if found or -1 if the search failed, */
99 int indexOfRuleField( const QByteArray
& aName
) const;
102 void slotRuleFieldChanged( const QString
& );
106 void initFieldList( bool headersOnly
, bool absoluteDates
);
108 QStringList mFilterFieldList
;
109 KComboBox
*mRuleField
;
110 QStackedWidget
*mFunctionStack
;
111 QStackedWidget
*mValueStack
;
116 class KMSearchRuleWidgetLister
: public KPIM::KWidgetLister
120 friend class ::KMSearchPatternEdit
;
123 explicit KMSearchRuleWidgetLister( QWidget
*parent
=0, const char* name
=0, bool headersOnly
= false, bool absoluteDates
= false );
125 virtual ~KMSearchRuleWidgetLister();
127 void setRuleList( QList
<KMSearchRule
*> * aList
);
128 void setHeadersOnly( bool headersOnly
);
134 virtual void clearWidget( QWidget
*aWidget
);
135 virtual QWidget
* createWidget( QWidget
*parent
);
138 void regenerateRuleListFromWidgets();
139 QList
<KMSearchRule
*> *mRuleList
;
145 /** This widget is intended to be used in the filter configuration as
146 well as in the message search dialogs. It consists of a frame,
147 inside which there are placed two radio buttons entitled "Match
148 {all,any} of the following", followed by a vertical stack of
149 KMSearchRuleWidgets (initially two) and two buttons to add and
150 remove, resp., additional KMSearchWidget 's.
152 To set the widget according to a given KMSearchPattern, use
153 setSearchPattern; to initialize it (e.g. for a new, virgin
154 rule), use setSearchPattern with a 0 argument. The widget
155 operates directly on a shallow(!) copy of the search rule. So
156 while you actually don't really need searchPattern, because
157 you can always store a pointer to the current pattern yourself,
158 you must not modify the currently-worked-on pattern yourself while
159 this widget holds a reference to it. The only exceptions are:
161 @li If you edit a derived class, you can change aspects of the
162 class that don't interfere with the KMSearchPattern part. An
163 example is KMFilter, whose actions you can still edit while
164 the KMSearchPattern part of it is being acted upon by this
167 @li You can change the name of the pattern, but only using (this
168 widget's) setName. You cannot change the pattern's name
169 directly, although this widget in itself doesn't let the user
170 change it. This is because it auto-names the pattern to
171 "<$field>:$contents" iff the pattern begins with "<".
173 @short A widget which allows editing a set of KMSearchRule's.
174 @author Marc Mutz <Marc@Mutz.com>
177 class KMSearchPatternEdit
: public QGroupBox
{
180 /** Constructor. The parent parameter is passed to the underlying
181 QGroupBox, as usual. */
182 explicit KMSearchPatternEdit( QWidget
*parent
= 0, bool headersOnly
= false,
183 bool absoluteDates
= false );
185 /** Constructor. This one allows you to set a title different from
186 i18n("Search Criteria"). */
187 explicit KMSearchPatternEdit( const QString
&title
, QWidget
*parent
= 0,
188 bool headersOnly
= false,
189 bool absoluteDates
= false );
191 ~KMSearchPatternEdit();
193 /** Set the search pattern. Rules are inserted regardless of the
194 return value of each rules' KMSearchRule::isEmpty. This
195 widget makes a shallow copy of @p aPattern and operates directly
197 void setSearchPattern( KMSearchPattern
* aPattern
);
198 /** Set whether only header fields can be searched. If @p is true only
199 header fields can be searched otherwise \<message\> and \<body\> searches
200 are available also. */
201 void setHeadersOnly( bool headersOnly
);
203 /** Updates the search pattern according to the current widget values */
204 void updateSearchPattern() { mRuleLister
->regenerateRuleListFromWidgets(); }
207 /** Called when the widget should let go of the currently referenced
208 filter and disable itself. */
212 /** This signal is emitted whenever the name of the processed
213 search pattern may have changed. */
214 void maybeNameChanged();
217 void slotRadioClicked( QAbstractButton
*aRBtn
);
218 void slotAutoNameHack();
221 void initLayout( bool headersOnly
, bool absoluteDates
);
223 KMSearchPattern
*mPattern
;
224 QRadioButton
*mAllRBtn
, *mAnyRBtn
;
225 KMSearchRuleWidgetLister
*mRuleLister
;
228 #endif // KMSEARCHPATTERNEDIT_H