File indexing completed on 2024-11-10 04:50:03

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 #include "filteractiondict.h"
0009 
0010 #include "filteractionaddheader.h"
0011 #include "filteractionaddtag.h"
0012 #include "filteractionaddtoaddressbook.h"
0013 #include "filteractioncopy.h"
0014 #include "filteractiondecrypt.h"
0015 #include "filteractiondelete.h"
0016 #include "filteractionencrypt.h"
0017 #include "filteractionexec.h"
0018 #include "filteractionmove.h"
0019 #include "filteractionpipethrough.h"
0020 #include "filteractionplaysound.h"
0021 #include "filteractionredirect.h"
0022 #include "filteractionremoveheader.h"
0023 #include "filteractionreplyto.h"
0024 #include "filteractionrewriteheader.h"
0025 #include "filteractionsendfakedisposition.h"
0026 #include "filteractionsendreceipt.h"
0027 #include "filteractionsetidentity.h"
0028 #include "filteractionsetstatus.h"
0029 #include "filteractionsettransport.h"
0030 #include "filteractionunsetstatus.h"
0031 
0032 using namespace MailCommon;
0033 
0034 //=============================================================================
0035 //
0036 //   Filter  Action  Dictionary
0037 //
0038 //=============================================================================
0039 FilterActionDict::~FilterActionDict()
0040 {
0041     qDeleteAll(mList);
0042 }
0043 
0044 void FilterActionDict::init()
0045 {
0046     insert(FilterActionMove::newAction);
0047     insert(FilterActionCopy::newAction);
0048     insert(FilterActionSetIdentity::newAction);
0049     insert(FilterActionSetStatus::newAction);
0050     insert(FilterActionAddTag::newAction);
0051     insert(FilterActionSendFakeDisposition::newAction);
0052     insert(FilterActionSetTransport::newAction);
0053     insert(FilterActionReplyTo::newAction);
0054     // Laurent disable for the moment as async doesn't work
0055     // PORT TO ASYNC insert(FilterActionForward::newAction);
0056     insert(FilterActionRedirect::newAction);
0057     insert(FilterActionSendReceipt::newAction);
0058     insert(FilterActionExec::newAction);
0059     insert(FilterActionPipeThrough::newAction);
0060     insert(FilterActionRemoveHeader::newAction);
0061     insert(FilterActionAddHeader::newAction);
0062     insert(FilterActionRewriteHeader::newAction);
0063     insert(FilterActionPlaySound::newAction);
0064     insert(FilterActionAddToAddressBook::newAction);
0065     insert(FilterActionDelete::newAction);
0066     insert(FilterActionUnsetStatus::newAction);
0067     insert(FilterActionEncrypt::newAction);
0068     insert(FilterActionDecrypt::newAction);
0069     // Register custom filter actions below this line.
0070 }
0071 
0072 // The int in the QDict constructor (41) must be a prime
0073 // and should be greater than the double number of FilterAction types
0074 FilterActionDict::FilterActionDict()
0075     : QMultiHash<QString, FilterActionDesc *>()
0076 {
0077     init();
0078 }
0079 
0080 void FilterActionDict::insert(FilterActionNewFunc aNewFunc)
0081 {
0082     FilterAction *action = aNewFunc();
0083     auto desc = new FilterActionDesc;
0084     desc->name = action->name();
0085     desc->label = action->label();
0086     desc->create = aNewFunc;
0087 
0088     QMultiHash<QString, FilterActionDesc *>::insert(desc->name, desc);
0089     QMultiHash<QString, FilterActionDesc *>::insert(desc->label, desc);
0090     mList.append(desc);
0091 
0092     delete action;
0093 }
0094 
0095 const QList<FilterActionDesc *> &FilterActionDict::list() const
0096 {
0097     return mList;
0098 }