~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kmail/kmfilter.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: C++; c-file-style: "gnu" -*-
2
 
 * kmail: KDE mail client
3
 
 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
4
 
 *
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.
9
 
 *
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.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 *
19
 
 */
20
 
#ifndef kmfilter_h
21
 
#define kmfilter_h
22
 
 
23
 
#include "kmsearchpattern.h"
24
 
#include "kmpopheaders.h"
25
 
 
26
 
#include <kshortcut.h>
27
 
 
28
 
class QString;
29
 
class KConfigGroup;
30
 
class KMMessage;
31
 
class KMFilterAction;
32
 
class KMFolder;
33
 
class KMMsgBase;
34
 
 
35
 
// maximum number of filter actions per filter
36
 
const int FILTER_MAX_ACTIONS = 8;
37
 
 
38
 
class KMFilter
39
 
{
40
 
public:
41
 
  /** Result codes returned by process. They mean:
42
 
 
43
 
      @param GoOn Everything OK. You are still the owner of the
44
 
      message and you should continue applying filter actions to this
45
 
      message.
46
 
 
47
 
      @param CriticalError A critical error occurred (e.g. "disk full").
48
 
 
49
 
      @param NoResult For internal use only!
50
 
 
51
 
  */
52
 
  enum ReturnCode { NoResult, GoOn, CriticalError };
53
 
 
54
 
  /** Account type codes used by setApplicability. They mean:
55
 
 
56
 
      @param All Apply to all accounts
57
 
 
58
 
      @param ButImap Apply to all but online-IMAP accounts
59
 
 
60
 
      @param Checked apply to all accounts specified by setApplyOnAccount
61
 
 
62
 
  */
63
 
  enum AccountType { All, ButImap, Checked };
64
 
 
65
 
  /** Constructor that initializes basic settings. */
66
 
  KMFilter( bool popFilter = false);
67
 
 
68
 
  /** Constructor that initializes from given config group.
69
 
    * Filters are stored one by one in config groups, i.e.
70
 
    * one filter, one group. */
71
 
  explicit KMFilter( KConfigGroup & aConfig, bool popFilter = false);
72
 
 
73
 
  /** Copy constructor. Constructs a deep copy of @p aFilter. */
74
 
  KMFilter( const KMFilter & other );
75
 
 
76
 
  /** Cleanup. */
77
 
  ~KMFilter();
78
 
 
79
 
  /** Equivalent to @pattern()->name(). @return name of the filter */
80
 
  QString name() const {
81
 
    return mPattern.name();
82
 
  }
83
 
 
84
 
  /** Execute the filter action(s) on the given message.
85
 
      Returns:
86
 
      @li 2 if a critical error occurred,
87
 
      @li 1 if the caller is still
88
 
      the owner of the message,
89
 
      @li 0 if processed successfully.
90
 
      @param msg The message to which the actions should be applied.
91
 
      @param stopIt Contains
92
 
      true if the caller may apply other filters and false if he shall
93
 
      stop the filtering of this message.
94
 
  */
95
 
  ReturnCode execActions( KMMessage* msg, bool& stopIt ) const ;
96
 
 
97
 
  /** Determines if the filter depends on the body of the message
98
 
  */
99
 
  bool requiresBody(KMMsgBase* msgBase);
100
 
 
101
 
  /** No descriptions */
102
 
  KMPopFilterAction action();
103
 
 
104
 
  /** No descriptions */
105
 
  void setAction(const KMPopFilterAction aAction);
106
 
 
107
 
  /** Write contents to given config group. */
108
 
  void writeConfig( KConfigGroup& config ) const;
109
 
 
110
 
  /** Initialize from given config group. */
111
 
  void readConfig( KConfigGroup& config );
112
 
 
113
 
  /** Remove empty rules (and actions one day). */
114
 
  void purify();
115
 
 
116
 
  /** Check for empty pattern and action list. */
117
 
  bool isEmpty() const;
118
 
 
119
 
  /** Provides a reference to the internal action list. If your used
120
 
      the @p setAction() and @p action() functions before, please
121
 
      convert to using myFilter->actions()->at() and friends now. */
122
 
  QList<KMFilterAction*>* actions() { return &mActions; }
123
 
 
124
 
  /** Provides a reference to the internal action list. Const version. */
125
 
  const QList<KMFilterAction*>* actions() const { return &mActions; }
126
 
 
127
 
  /** Provides a reference to the internal pattern. If you used the
128
 
      @p matches() function before, please convert to using
129
 
      myFilter->pattern()->matches() now. */
130
 
  KMSearchPattern* pattern() { return &mPattern; }
131
 
 
132
 
  /** Provides a reference to the internal pattern. If you used the
133
 
      @p matches() function before, please convert to using
134
 
      myFilter->pattern()->matches() now. */
135
 
  const KMSearchPattern* pattern() const { return &mPattern; }
136
 
 
137
 
  /** Set whether this filter should be applied on
138
 
      outbound messages (@p aApply == true) or not.
139
 
      See applyOnOutbound applyOnInbound setApplyOnInbound
140
 
  */
141
 
  void setApplyOnOutbound( bool aApply=true ) { bApplyOnOutbound = aApply; }
142
 
 
143
 
  /** Set whether this filter should be applied on
144
 
      outbound messages before sending (@p aApply == TRUE) or not.
145
 
      See applyOnOutbound applyOnInbound setApplyOnInbound
146
 
  */
147
 
  void setApplyBeforeOutbound( bool aApply=true ) { bApplyBeforeOutbound = aApply; }
148
 
 
149
 
  /** @return true if this filter should be applied on
150
 
      outbound messages, false otherwise.
151
 
      @see setApplyOnOutbound applyOnInbound setApplyOnInbound
152
 
  */
153
 
  bool applyOnOutbound() const { return bApplyOnOutbound; }
154
 
 
155
 
  /** @return TRUE if this filter should be applied on
156
 
      outbound messages before they are sent, FALSE otherwise.
157
 
      @see setApplyOnOutbound applyOnInbound setApplyOnInbound
158
 
  */
159
 
  bool applyBeforeOutbound() const { return bApplyBeforeOutbound; }
160
 
 
161
 
  /** Set whether this filter should be applied on
162
 
      inbound messages (@p aApply == true) or not.
163
 
      @see setApplyOnOutbound applyOnInbound applyOnOutbound
164
 
  */
165
 
  void setApplyOnInbound( bool aApply=true ) { bApplyOnInbound = aApply; }
166
 
 
167
 
  /** @return true if this filter should be applied on
168
 
      inbound messages, false otherwise.
169
 
      @see setApplyOnOutbound applyOnOutbound setApplyOnInbound
170
 
  */
171
 
  bool applyOnInbound() const { return bApplyOnInbound; }
172
 
 
173
 
  /** Set whether this filter should be applied on
174
 
      explicit (CTRL-J) filtering (@p aApply == true) or not.
175
 
      @see setApplyOnOutbound applyOnInbound applyOnOutbound
176
 
  */
177
 
  void setApplyOnExplicit( bool aApply=true ) { bApplyOnExplicit = aApply; }
178
 
 
179
 
  /** @return true if this filter should be applied on
180
 
      explicit (CTRL-J) filtering, false otherwise.
181
 
      @see setApplyOnOutbound applyOnOutbound setApplyOnInbound
182
 
  */
183
 
  bool applyOnExplicit() const { return bApplyOnExplicit; }
184
 
 
185
 
  /** Set whether this filter should be applied on
186
 
      inbound messages for all accounts (@p aApply == All) or
187
 
      inbound messages for all but nline IMAP accounts (@p aApply == ButImap) or
188
 
      for a specified set of accounts only.
189
 
      Only applicable to filters that are applied on inbound messages.
190
 
      @see setApplyOnInbound setApplyOnAccount
191
 
  */
192
 
  void setApplicability( AccountType aApply=All ) { mApplicability = aApply; }
193
 
 
194
 
  /** @return true if this filter should be applied on
195
 
      inbound messages for all accounts, or false if this filter
196
 
      is to be applied on a specified set of accounts only.
197
 
      Only applicable to filters that are applied on inbound messages.
198
 
      @see setApplicability
199
 
  */
200
 
  AccountType applicability() const { return mApplicability; }
201
 
 
202
 
  /** Set whether this filter should be applied on
203
 
      inbound messages for the account with id (@p id).
204
 
      Only applicable to filters that are only applied to a specified
205
 
      set of accounts.
206
 
      @see setApplicability applyOnAccount
207
 
  */
208
 
  void setApplyOnAccount( uint id, bool aApply=true );
209
 
 
210
 
  /** @return true if this filter should be applied on
211
 
      inbound messages from the account with id (@p id), false otherwise.
212
 
      @see setApplicability
213
 
  */
214
 
  bool applyOnAccount( uint id ) const;
215
 
 
216
 
  void setStopProcessingHere( bool aStop ) { bStopProcessingHere = aStop; }
217
 
  bool stopProcessingHere() const { return bStopProcessingHere; }
218
 
 
219
 
  /** Set whether this filter should be plugged into the filter menu.
220
 
  */
221
 
  void setConfigureShortcut( bool aShort ) {
222
 
    bConfigureShortcut = aShort;
223
 
    bConfigureToolbar = bConfigureToolbar && bConfigureShortcut;
224
 
  }
225
 
 
226
 
  /** @return true if this filter should be plugged into the filter menu,
227
 
      false otherwise.
228
 
      @see setConfigureShortcut
229
 
  */
230
 
  bool configureShortcut() const { return bConfigureShortcut; }
231
 
 
232
 
  /** Set whether this filter should be plugged into the toolbar.
233
 
      This can be done only if a shortcut is defined.
234
 
      @see setConfigureShortcut
235
 
  */
236
 
  void setConfigureToolbar( bool aTool ) {
237
 
    bConfigureToolbar = aTool && bConfigureShortcut;
238
 
  }
239
 
 
240
 
  /** @return true if this filter should be plugged into the toolbar,
241
 
      false otherwise.
242
 
      @see setConfigureToolbar
243
 
  */
244
 
  bool configureToolbar() const { return bConfigureToolbar; }
245
 
 
246
 
  /** @return The toolbar name of this filter.
247
 
   *  @see setToolbarName
248
 
   */
249
 
  QString toolbarName() const;
250
 
 
251
 
  /** This sets the toolbar name for this filter.
252
 
   *  The toolbar name is the text to be displayed underneath the toolbar icon
253
 
   *  for this filter. This is usually the same as name(),  expect when 
254
 
   *  explicitly set by this function.
255
 
   *  This is useful if the normal filter mame is too long for the toolbar.
256
 
   *  @see toolbarName, name
257
 
   */
258
 
  void setToolbarName( QString toolbarName ) {
259
 
    mToolbarName = toolbarName;
260
 
  }
261
 
 
262
 
  /** Set the shortcut to be used if plugged into the filter menu
263
 
      or toolbar. Default is no shortcut.
264
 
      @see setConfigureShortcut setConfigureToolbar
265
 
  */
266
 
  void setShortcut( const KShortcut & shortcut ) { mShortcut = shortcut; }
267
 
 
268
 
  /** @return The shortcut assigned to the filter.
269
 
      @see setShortcut
270
 
  */
271
 
  const KShortcut & shortcut() const { return mShortcut; }
272
 
 
273
 
  /** Set the icon to be used if plugged into the filter menu
274
 
      or toolbar. Default is the gear icon.
275
 
      @see setConfigureShortcut setConfigureToolbar
276
 
  */
277
 
  void setIcon( QString icon ) { mIcon = icon; }
278
 
 
279
 
  /** @return The name of the icon to be used.
280
 
      @see setIcon
281
 
  */
282
 
  QString icon() const { return mIcon; }
283
 
 
284
 
  /**
285
 
   * Called from the filter manager when a folder is moved.
286
 
   * Tests if the folder aFolder is used in any action. Changes it
287
 
   * to aNewFolder folder in this case.
288
 
   * @return true if a change in some action occurred,
289
 
   * false if no action was affected.
290
 
   */
291
 
  bool folderRemoved( KMFolder* aFolder, KMFolder* aNewFolder );
292
 
 
293
 
  /** Returns the filter in a human-readable form. useful for
294
 
      debugging but not much else. Don't use, as it may well go away
295
 
      in the future... */
296
 
#ifndef NDEBUG
297
 
  const QString asString() const;
298
 
#endif
299
 
 
300
 
  /** No descriptions */
301
 
  bool isPopFilter() const {
302
 
    return bPopFilter;
303
 
  }
304
 
 
305
 
  /** Set the mode for using automatic naming for the filter.
306
 
      If the feature is enabled, the name is derived from the
307
 
      first filter rule.
308
 
  */
309
 
  void setAutoNaming( bool useAutomaticNames ) {
310
 
    bAutoNaming = useAutomaticNames;
311
 
  }
312
 
 
313
 
  /** @return Tells, if an automatic name is used for the filter
314
 
  */
315
 
  bool isAutoNaming() const { return bAutoNaming; }
316
 
 
317
 
private:
318
 
  KMSearchPattern mPattern;
319
 
  QList<KMFilterAction*> mActions;
320
 
  QList<int> mAccounts;
321
 
  KMPopFilterAction mAction;
322
 
  QString mIcon;
323
 
  QString mToolbarName;
324
 
  KShortcut mShortcut;
325
 
  bool bPopFilter : 1;
326
 
  bool bApplyOnInbound : 1;
327
 
  bool bApplyBeforeOutbound : 1;
328
 
  bool bApplyOnOutbound : 1;
329
 
  bool bApplyOnExplicit : 1;
330
 
  bool bStopProcessingHere : 1;
331
 
  bool bConfigureShortcut : 1;
332
 
  bool bConfigureToolbar : 1;
333
 
  bool bAutoNaming : 1;
334
 
  AccountType mApplicability;
335
 
};
336
 
 
337
 
#endif /*kmfilter_h*/