Libksieve

sieveactionabstractflags.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 #include "sieveactionabstractflags.h"
20 #include "autocreatescripts/autocreatescriptutil_p.h"
21 #include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
22 #include "widgets/selectflagswidget.h"
23 
24 #include <QHBoxLayout>
25 #include <QXmlStreamReader>
26 #include "libksieve_debug.h"
27 
28 using namespace KSieveUi;
29 SieveActionAbstractFlags::SieveActionAbstractFlags(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent)
30  : SieveAction(sieveGraphicalModeWidget, name, label, parent)
31 {
32 }
33 
34 QWidget *SieveActionAbstractFlags::createParamWidget(QWidget *parent) const
35 {
36  QWidget *w = new QWidget(parent);
37  QHBoxLayout *lay = new QHBoxLayout;
38  lay->setContentsMargins(0, 0, 0, 0);
39  w->setLayout(lay);
40  SelectFlagsWidget *flagsWidget = new SelectFlagsWidget;
41  connect(flagsWidget, &SelectFlagsWidget::valueChanged, this, &SieveActionAbstractFlags::valueChanged);
42  flagsWidget->setObjectName(QStringLiteral("flagswidget"));
43  lay->addWidget(flagsWidget);
44  return w;
45 }
46 
47 void SieveActionAbstractFlags::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
48 {
49  while (element.readNextStartElement()) {
50  const QStringRef tagName = element.name();
51  if (tagName == QLatin1String("list")) {
52  SelectFlagsWidget *flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
53  flagsWidget->setFlags(AutoCreateScriptUtil::listValue(element));
54  } else if (tagName == QLatin1String("str")) {
55  SelectFlagsWidget *flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
56  flagsWidget->setFlags(QStringList() << element.readElementText());
57  } else if (tagName == QLatin1String("crlf")) {
58  element.skipCurrentElement();
59  //nothing
60  } else if (tagName == QLatin1String("comment")) {
61  element.skipCurrentElement();
62  //implement in the future ?
63  } else {
64  unknownTag(tagName, error);
65  qCDebug(LIBKSIEVE_LOG) << " SieveActionAbstractFlags::setParamWidgetValue unknown tag :" << tagName;
66  }
67  }
68 }
69 
70 QString SieveActionAbstractFlags::code(QWidget *w) const
71 {
72  const SelectFlagsWidget *flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
73  const QString flagCode = flagsWidget->code();
74  const QString str = flagsCode();
75  return str + QLatin1Char(' ') + (flagCode.isEmpty() ? QStringLiteral(";") : flagCode);
76 }
77 
78 QStringList SieveActionAbstractFlags::needRequires(QWidget *) const
79 {
80  if (sieveCapabilities().contains(QLatin1String("imap4flags"))) {
81  return QStringList() << QStringLiteral("imap4flags");
82  } else {
83  return QStringList() << QStringLiteral("imapflags");
84  }
85 }
86 
87 bool SieveActionAbstractFlags::needCheckIfServerHasCapability() const
88 {
89  return true;
90 }
91 
92 QString SieveActionAbstractFlags::serverNeedsCapability() const
93 {
94  if (sieveCapabilities().contains(QLatin1String("imap4flags"))) {
95  return QStringLiteral("imap4flags");
96  } else {
97  return QStringLiteral("imapflags");
98  }
99 }
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
void skipCurrentElement()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setLayout(QLayout *layout)
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.