Mailcommon

filteractiondict.h
1 /*
2  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <[email protected]>
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  *
6  */
7 
8 #pragma once
9 
10 #include "mailcommon_export.h"
11 
12 #include <QMultiHash>
13 #include <QString>
14 #include <QVector>
15 namespace MailCommon
16 {
17 class FilterAction;
18 
19 using FilterActionNewFunc = FilterAction *(*)();
20 
21 /**
22  * @short Auxiliary struct for FilterActionDict.
23  */
25  QString label, name;
26  FilterActionNewFunc create;
27 };
28 
29 /**
30  * @short List of known FilterAction-types.
31  *
32  * Dictionary that contains a list of all registered filter actions
33  * with their creation functions. They are hard-coded into the
34  * constructor. If you want to add a new FilterAction, make
35  * sure you add the details of it in init, too.
36  *
37  * You will be able to find a description of a FilterAction by
38  * looking up either it's (english) name or it's (i18n) label:
39  * <pre>
40  * FilterActionDict dict;
41  * // get name of the action with label "move into folder":
42  * dict[i18n("move into folder")]->name; // == "transfer"
43  * // create one such action:
44  * FilterAction *action = dict["transfer"]->create();
45  * </pre>
46  *
47  * You can iterate over all known filter actions by using list.
48  *
49  * @author Marc Mutz <[email protected]>, based on work by Stefan Taferner <[email protected]>
50  * @see FilterAction FilterActionDesc Filter
51  */
52 class FilterActionDict : public QMultiHash<QString, FilterActionDesc *>
53 {
54 public:
55  /**
56  * Creates the filter action dictionary.
57  */
58  MAILCOMMON_EXPORT FilterActionDict();
59 
60  /**
61  * Destroys the filter action dictionary.
62  */
63  MAILCOMMON_EXPORT virtual ~FilterActionDict();
64 
65  /**
66  * Overloaded member function, provided for convenience. Thin
67  * wrapper around QDict::insert and QPtrList::insert.
68  * Inserts the resulting FilterActionDesc
69  * thrice: First with the name, then with the label as key into the
70  * QDict, then into the QPtrList. For that, it creates an
71  * instance of the action internally and deletes it again after
72  * querying it for name and label.
73  */
74  MAILCOMMON_EXPORT void insert(FilterActionNewFunc aNewFunc);
75 
76  /**
77  * Provides read-only access to a list of all known filter
78  * actions.
79  */
80  MAILCOMMON_EXPORT const QVector<FilterActionDesc *> &list() const;
81 
82 protected:
83  /**
84  * Populate the dictionary with all known FilterAction
85  * types. Called automatically from the constructor.
86  */
87  virtual void init();
88 
89 private:
91 };
92 }
List of known FilterAction-types.
MAILCOMMON_EXPORT void insert(FilterActionNewFunc aNewFunc)
Overloaded member function, provided for convenience.
MAILCOMMON_EXPORT FilterActionDict()
Creates the filter action dictionary.
Auxiliary struct for FilterActionDict.
virtual MAILCOMMON_EXPORT ~FilterActionDict()
Destroys the filter action dictionary.
const MAILCOMMON_EXPORT QVector< FilterActionDesc * > & list() const
Provides read-only access to a list of all known filter actions.
The filter dialog.
virtual void init()
Populate the dictionary with all known FilterAction types.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Oct 1 2022 04:00:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.