Mailcommon

filterimporterabstract.cpp
1 /*
2  SPDX-FileCopyrightText: 2012-2022 Laurent Montel <[email protected]>
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 
16 using namespace MailCommon;
17 
18 FilterImporterAbstract::FilterImporterAbstract(bool interactive)
19  : mInteractive(interactive)
20 {
21 }
22 
23 FilterImporterAbstract::~FilterImporterAbstract() = default;
24 
25 QVector<MailFilter *> FilterImporterAbstract::importFilter() const
26 {
27  return mListMailFilter;
28 }
29 
30 QStringList FilterImporterAbstract::emptyFilter() const
31 {
32  return mEmptyFilter;
33 }
34 
35 void 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 
54 void 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 
79 bool FilterImporterAbstract::loadDomElement(QDomDocument &doc, QFile *file)
80 {
81  QString errorMsg;
82  int errorRow;
83  int errorCol;
84  if (!doc.setContent(file, &errorMsg, &errorRow, &errorCol)) {
85  qCDebug(MAILCOMMON_LOG) << "Unable to load document.Parse error in line " << errorRow << ", col " << errorCol << ": " << errorMsg;
86  return false;
87  }
88  return true;
89 }
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
The MailFilter class.
Definition: mailfilter.h:30
Abstract base class for mail filter actions.
Definition: filteraction.h:38
bool isEmpty() const const
QFuture< void > filter(Sequence &sequence, KeepFunctor filterFunction)
static FilterActionDict * filterActionDict()
Returns the global filter action dictionary.
virtual bool argsFromStringInteractive(const QString &argsStr, const QString &filterName)
Read extra arguments from given string.
Auxiliary struct for FilterActionDict.
virtual void argsFromString(const QString &argsStr)=0
Read extra arguments from given string.
The filter dialog.
virtual bool isEmpty() const
Determines whether this action is valid.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.