Libksieve

sieveactionabstractflags.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
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 "libksieveui_debug.h"
12#include <QHBoxLayout>
13#include <QXmlStreamReader>
14
15using namespace KSieveUi;
16SieveActionAbstractFlags::SieveActionAbstractFlags(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget,
17 const QString &name,
18 const QString &label,
19 QObject *parent)
20 : SieveAction(sieveGraphicalModeWidget, name, label, parent)
21{
22}
23
24QWidget *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(QLatin1StringView("flagswidget"));
33 lay->addWidget(flagsWidget);
34 return w;
35}
36
37void SieveActionAbstractFlags::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
38{
39 while (element.readNextStartElement()) {
40 const QStringView tagName = element.name();
41 if (tagName == QLatin1StringView("list")) {
42 auto flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
43 flagsWidget->setFlags(AutoCreateScriptUtil::listValue(element));
44 } else if (tagName == QLatin1StringView("str")) {
45 auto flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
46 flagsWidget->setFlags(QStringList() << element.readElementText());
47 } else if (tagName == QLatin1StringView("crlf")) {
48 element.skipCurrentElement();
49 // nothing
50 } else if (tagName == QLatin1StringView("comment")) {
51 element.skipCurrentElement();
52 // implement in the future ?
53 } else {
54 unknownTag(tagName, error);
55 qCDebug(LIBKSIEVEUI_LOG) << " SieveActionAbstractFlags::setParamWidgetValue unknown tag :" << tagName;
56 }
57 }
58}
59
60QString 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
68QStringList SieveActionAbstractFlags::needRequires(QWidget *) const
69{
70 if (sieveCapabilities().contains(QLatin1StringView("imap4flags"))) {
71 return QStringList() << QStringLiteral("imap4flags");
72 } else {
73 return QStringList() << QStringLiteral("imapflags");
74 }
75}
76
77bool SieveActionAbstractFlags::needCheckIfServerHasCapability() const
78{
79 return true;
80}
81
82QString SieveActionAbstractFlags::serverNeedsCapability() const
83{
84 if (sieveCapabilities().contains(QLatin1StringView("imap4flags"))) {
85 return QStringLiteral("imap4flags");
86 } else {
87 return QStringLiteral("imapflags");
88 }
89}
90
91#include "moc_sieveactionabstractflags.cpp"
QString name(GameStandardAction id)
QString label(StandardShortcut id)
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T findChild(const QString &name, Qt::FindChildOptions options) const const
QObject * parent() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void skipCurrentElement()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:56:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.