Mailcommon

filterimporterabstract.cpp
1/*
2 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "filterimporterabstract.h"
8#include "filter/filteractions/filteractiondict.h"
9#include "filter/filtermanager.h"
10#include "filter/mailfilter.h"
11#include "mailcommon_debug.h"
12
13#include <QDomDocument>
14#include <QFile>
15
16using namespace MailCommon;
17
18FilterImporterAbstract::FilterImporterAbstract(bool interactive)
19 : mInteractive(interactive)
20{
21}
22
23FilterImporterAbstract::~FilterImporterAbstract() = default;
24
25QList<MailFilter *> FilterImporterAbstract::importFilter() const
26{
27 return mListMailFilter;
28}
29
30QStringList FilterImporterAbstract::emptyFilter() const
31{
32 return mEmptyFilter;
33}
34
35void FilterImporterAbstract::appendFilter(MailCommon::MailFilter *filter)
36{
37 if (!filter) {
38 return;
39 }
40
41 // TODO verify number of condition
42 filter->purify();
43 if (!filter->isEmpty()) {
44 // the filter is valid:
45 mListMailFilter << filter;
46 } else {
47 mEmptyFilter << filter->name();
48 // the filter is invalid:
49 qCDebug(MAILCOMMON_LOG) << " Empty filter";
50 delete filter;
51 }
52}
53
54void FilterImporterAbstract::createFilterAction(MailCommon::MailFilter *filter, const QString &actionName, const QString &value)
55{
56 if (!actionName.isEmpty()) {
58 if (desc) {
59 FilterAction *fa = desc->create();
60 //...create an instance...
61 if (mInteractive) {
62 fa->argsFromStringInteractive(value, filter->name());
63 } else {
64 fa->argsFromString(value);
65 }
66
67 //...check if it's empty and...
68 if (!fa->isEmpty()) {
69 //...append it if it's not and...
70 filter->actions()->append(fa);
71 } else {
72 //...delete is else.
73 delete fa;
74 }
75 }
76 }
77}
78
79bool FilterImporterAbstract::loadDomElement(QDomDocument &doc, QFile *file)
80{
81 const QDomDocument::ParseResult parseResult = doc.setContent(file);
82 if (!parseResult) {
83 qCDebug(MAILCOMMON_LOG) << "Unable to load document.Parse error in line " << parseResult.errorLine << ", col " << parseResult.errorColumn << ": "
84 << qPrintable(parseResult.errorMessage);
85 return false;
86 }
87 return true;
88}
Abstract base class for mail filter actions.
virtual void argsFromString(const QString &argsStr)=0
Read extra arguments from given string.
virtual bool isEmpty() const
Determines whether this action is valid.
virtual bool argsFromStringInteractive(const QString &argsStr, const QString &filterName)
Read extra arguments from given string.
static FilterActionDict * filterActionDict()
Returns the global filter action dictionary.
The MailFilter class.
Definition mailfilter.h:29
The filter dialog.
ParseResult setContent(QAnyStringView text, ParseOptions options)
T value(const Key &key) const const
bool isEmpty() const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
Auxiliary struct for FilterActionDict.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.