File indexing completed on 2024-09-22 04:49:59
0001 /* 0002 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 * 0006 */ 0007 0008 #pragma once 0009 0010 #include "mailcommon_export.h" 0011 0012 #include <QList> 0013 #include <QMultiHash> 0014 #include <QString> 0015 namespace MailCommon 0016 { 0017 class FilterAction; 0018 0019 using FilterActionNewFunc = FilterAction *(*)(); 0020 0021 /** 0022 * @short Auxiliary struct for FilterActionDict. 0023 */ 0024 struct FilterActionDesc { 0025 QString label, name; 0026 FilterActionNewFunc create; 0027 }; 0028 0029 /** 0030 * @short List of known FilterAction-types. 0031 * 0032 * Dictionary that contains a list of all registered filter actions 0033 * with their creation functions. They are hard-coded into the 0034 * constructor. If you want to add a new FilterAction, make 0035 * sure you add the details of it in init, too. 0036 * 0037 * You will be able to find a description of a FilterAction by 0038 * looking up either it's (english) name or it's (i18n) label: 0039 * <pre> 0040 * FilterActionDict dict; 0041 * // get name of the action with label "move into folder": 0042 * dict[i18n("move into folder")]->name; // == "transfer" 0043 * // create one such action: 0044 * FilterAction *action = dict["transfer"]->create(); 0045 * </pre> 0046 * 0047 * You can iterate over all known filter actions by using list. 0048 * 0049 * @author Marc Mutz <mutz@kde.org>, based on work by Stefan Taferner <taferner@kde.org> 0050 * @see FilterAction FilterActionDesc Filter 0051 */ 0052 class FilterActionDict : public QMultiHash<QString, FilterActionDesc *> 0053 { 0054 public: 0055 /** 0056 * Creates the filter action dictionary. 0057 */ 0058 MAILCOMMON_EXPORT FilterActionDict(); 0059 0060 /** 0061 * Destroys the filter action dictionary. 0062 */ 0063 MAILCOMMON_EXPORT virtual ~FilterActionDict(); 0064 0065 /** 0066 * Overloaded member function, provided for convenience. Thin 0067 * wrapper around QDict::insert and QPtrList::insert. 0068 * Inserts the resulting FilterActionDesc 0069 * thrice: First with the name, then with the label as key into the 0070 * QDict, then into the QPtrList. For that, it creates an 0071 * instance of the action internally and deletes it again after 0072 * querying it for name and label. 0073 */ 0074 MAILCOMMON_EXPORT void insert(FilterActionNewFunc aNewFunc); 0075 0076 /** 0077 * Provides read-only access to a list of all known filter 0078 * actions. 0079 */ 0080 MAILCOMMON_EXPORT const QList<FilterActionDesc *> &list() const; 0081 0082 protected: 0083 /** 0084 * Populate the dictionary with all known FilterAction 0085 * types. Called automatically from the constructor. 0086 */ 0087 virtual void init(); 0088 0089 private: 0090 QList<FilterActionDesc *> mList; 0091 }; 0092 }