Libksieve

sieveactionabstractflags.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "sieveactionabstractflags.h"
7 #include "autocreatescripts/autocreatescriptutil_p.h"
8 #include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
9 #include "widgets/selectflagswidget.h"
10 
11 #include "libksieve_debug.h"
12 #include <QHBoxLayout>
13 #include <QXmlStreamReader>
14 
15 using namespace KSieveUi;
16 SieveActionAbstractFlags::SieveActionAbstractFlags(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget,
17  const QString &name,
18  const QString &label,
19  QObject *parent)
20  : SieveAction(sieveGraphicalModeWidget, name, label, parent)
21 {
22 }
23 
24 QWidget *SieveActionAbstractFlags::createParamWidget(QWidget *parent) const
25 {
26  auto w = new QWidget(parent);
27  auto lay = new QHBoxLayout;
28  lay->setContentsMargins({});
29  w->setLayout(lay);
30  auto flagsWidget = new SelectFlagsWidget;
31  connect(flagsWidget, &SelectFlagsWidget::valueChanged, this, &SieveActionAbstractFlags::valueChanged);
32  flagsWidget->setObjectName(QStringLiteral("flagswidget"));
33  lay->addWidget(flagsWidget);
34  return w;
35 }
36 
37 void SieveActionAbstractFlags::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
38 {
39  while (element.readNextStartElement()) {
40  const QStringRef tagName = element.name();
41  if (tagName == QLatin1String("list")) {
42  auto flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
43  flagsWidget->setFlags(AutoCreateScriptUtil::listValue(element));
44  } else if (tagName == QLatin1String("str")) {
45  auto flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
46  flagsWidget->setFlags(QStringList() << element.readElementText());
47  } else if (tagName == QLatin1String("crlf")) {
48  element.skipCurrentElement();
49  // nothing
50  } else if (tagName == QLatin1String("comment")) {
51  element.skipCurrentElement();
52  // implement in the future ?
53  } else {
54  unknownTag(tagName, error);
55  qCDebug(LIBKSIEVE_LOG) << " SieveActionAbstractFlags::setParamWidgetValue unknown tag :" << tagName;
56  }
57  }
58 }
59 
60 QString SieveActionAbstractFlags::code(QWidget *w) const
61 {
62  const SelectFlagsWidget *flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
63  const QString flagCode = flagsWidget->code();
64  const QString str = flagsCode();
65  return str + QLatin1Char(' ') + (flagCode.isEmpty() ? QStringLiteral(";") : flagCode);
66 }
67 
68 QStringList SieveActionAbstractFlags::needRequires(QWidget *) const
69 {
70  if (sieveCapabilities().contains(QLatin1String("imap4flags"))) {
71  return QStringList() << QStringLiteral("imap4flags");
72  } else {
73  return QStringList() << QStringLiteral("imapflags");
74  }
75 }
76 
77 bool SieveActionAbstractFlags::needCheckIfServerHasCapability() const
78 {
79  return true;
80 }
81 
82 QString SieveActionAbstractFlags::serverNeedsCapability() const
83 {
84  if (sieveCapabilities().contains(QLatin1String("imap4flags"))) {
85  return QStringLiteral("imap4flags");
86  } else {
87  return QStringLiteral("imapflags");
88  }
89 }
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
void skipCurrentElement()
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QStringRef name() const const
T findChild(const QString &name, Qt::FindChildOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.