Commit b1db294a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Reduce duplicate code

parent 08374752
......@@ -121,7 +121,8 @@ set(ksieveui_autocreatescripts_LIB_SRCS
autocreatescripts/commonwidgets/selectconvertparameterwidget.cpp
autocreatescripts/commonwidgets/selectmatchtypecombobox.cpp
autocreatescripts/commonwidgets/selectmimetypecombobox.cpp
autocreatescripts/commonwidgets/sievehelpbutton.cpp
autocreatescripts/commonwidgets/sievehelpbutton.cpp
autocreatescripts/commonwidgets/sievecommonactioncondition.cpp
autocreatescripts/sieveconditions/sievecondition.cpp
autocreatescripts/sieveconditions/sieveconditionheader.cpp
autocreatescripts/sieveconditions/sieveconditionlist.cpp
......
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "sievecommonactioncondition.h"
#include "libksieve_debug.h"
#include <KLocalizedString>
#include <QUrl>
#include <QWidget>
#include <QXmlStreamReader>
#include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
using namespace KSieveUi;
SieveCommonActionCondition::SieveCommonActionCondition(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent)
: QObject(parent)
, mSieveGraphicalModeWidget(sieveGraphicalModeWidget)
, mName(name)
, mLabel(label)
{
}
SieveCommonActionCondition::~SieveCommonActionCondition()
{
}
KSieveUi::SieveImapAccountSettings SieveCommonActionCondition::sieveImapAccountSettings() const
{
if (mSieveGraphicalModeWidget) {
return mSieveGraphicalModeWidget->sieveImapAccountSettings();
}
qCWarning(LIBKSIEVE_LOG) << "SieveCommonActionCondition::sieveImapAccountSettings Problem during initialize mSieveGraphicalModeWidget ";
return {};
}
QStringList SieveCommonActionCondition::sieveCapabilities() const
{
if (mSieveGraphicalModeWidget) {
return mSieveGraphicalModeWidget->sieveCapabilities();
}
qCWarning(LIBKSIEVE_LOG) << "SieveCommonActionCondition::sieveCapabilities Problem during initialize mSieveGraphicalModeWidget ";
return {};
}
QString SieveCommonActionCondition::name() const
{
return mName;
}
QString SieveCommonActionCondition::label() const
{
return mLabel;
}
QString SieveCommonActionCondition::code(QWidget *) const
{
return QString();
}
QStringList SieveCommonActionCondition::needRequires(QWidget *parent) const
{
Q_UNUSED(parent);
return QStringList();
}
bool SieveCommonActionCondition::needCheckIfServerHasCapability() const
{
return false;
}
QString SieveCommonActionCondition::serverNeedsCapability() const
{
return QString();
}
QString SieveCommonActionCondition::help() const
{
return QString();
}
QString SieveCommonActionCondition::comment() const
{
return mComment;
}
void SieveCommonActionCondition::setComment(const QString &comment)
{
mComment = comment;
}
void SieveCommonActionCondition::unknownTag(const QStringRef &tag, QString &error)
{
error += i18n("An unknown tag \"%1\" was found during parsing action \"%2\".", *tag.string(), name()) + QLatin1Char('\n');
}
void SieveCommonActionCondition::unknownTagValue(const QString &tagValue, QString &error)
{
error += i18n("An unknown tag value \"%1\" was found during parsing action \"%2\".", tagValue, name()) + QLatin1Char('\n');
}
void SieveCommonActionCondition::tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error)
{
error += i18n("Too many arguments found for \"%1\", max value is %2, number of value found %3 for %4", name(), maxValue, index, *tagName.string()) + QLatin1Char('\n');
}
void SieveCommonActionCondition::serverDoesNotSupportFeatures(const QString &feature, QString &error)
{
error += i18n("A feature \"%1\" in condition \"%2\" is not supported by server", feature, name()) + QLatin1Char('\n');
}
QUrl SieveCommonActionCondition::href() const
{
return QUrl();
}
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef SIEVECOMMONACTIONCONDITION_H
#define SIEVECOMMONACTIONCONDITION_H
#include <QObject>
class QXmlStreamReader;
namespace KSieveUi {
class SieveImapAccountSettings;
class SieveEditorGraphicalModeWidget;
class SieveCommonActionCondition : public QObject
{
Q_OBJECT
public:
explicit SieveCommonActionCondition(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = nullptr);
~SieveCommonActionCondition() override;
Q_REQUIRED_RESULT QString name() const;
Q_REQUIRED_RESULT QString label() const;
Q_REQUIRED_RESULT virtual QString code(QWidget *parent) const;
Q_REQUIRED_RESULT virtual QStringList needRequires(QWidget *parent) const;
Q_REQUIRED_RESULT virtual bool needCheckIfServerHasCapability() const;
Q_REQUIRED_RESULT virtual QString serverNeedsCapability() const;
Q_REQUIRED_RESULT virtual QString help() const;
Q_REQUIRED_RESULT virtual QUrl href() const;
virtual void unknownTag(const QStringRef &tag, QString &error);
virtual void unknownTagValue(const QString &tagValue, QString &error);
virtual void tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error);
virtual void serverDoesNotSupportFeatures(const QString &feature, QString &error);
Q_REQUIRED_RESULT QString comment() const;
void setComment(const QString &comment);
Q_REQUIRED_RESULT QString generateComment() const;
protected:
Q_REQUIRED_RESULT KSieveUi::SieveImapAccountSettings sieveImapAccountSettings() const;
Q_REQUIRED_RESULT QStringList sieveCapabilities() const;
SieveEditorGraphicalModeWidget *mSieveGraphicalModeWidget = nullptr;
Q_SIGNALS:
void valueChanged();
private:
Q_DISABLE_COPY(SieveCommonActionCondition)
QString mName;
QString mLabel;
QString mComment;
};
}
#endif // SIEVECOMMONACTIONCONDITION_H
......@@ -29,10 +29,7 @@
using namespace KSieveUi;
SieveAction::SieveAction(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent)
: QObject(parent)
, mSieveGraphicalModeWidget(sieveGraphicalModeWidget)
, mName(name)
, mLabel(label)
: SieveCommonActionCondition(sieveGraphicalModeWidget, name, label, parent)
{
}
......@@ -40,15 +37,6 @@ SieveAction::~SieveAction()
{
}
KSieveUi::SieveImapAccountSettings SieveAction::sieveImapAccountSettings() const
{
if (mSieveGraphicalModeWidget) {
return mSieveGraphicalModeWidget->sieveImapAccountSettings();
}
qCWarning(LIBKSIEVE_LOG) << "SieveAction::sieveImapAccountSettings Problem during initialize mSieveGraphicalModeWidget ";
return {};
}
QStringList SieveAction::listOfIncludeFile() const
{
if (mSieveGraphicalModeWidget) {
......@@ -67,63 +55,17 @@ QStringList SieveAction::sieveCapabilities() const
return {};
}
QString SieveAction::name() const
{
return mName;
}
QString SieveAction::label() const
{
return mLabel;
}
QWidget *SieveAction::createParamWidget(QWidget *parent) const
{
return new QWidget(parent);
}
QString SieveAction::code(QWidget *) const
{
return QString();
}
QStringList SieveAction::needRequires(QWidget *parent) const
{
Q_UNUSED(parent);
return QStringList();
}
bool SieveAction::needCheckIfServerHasCapability() const
{
return false;
}
QString SieveAction::serverNeedsCapability() const
{
return QString();
}
QString SieveAction::help() const
{
return QString();
}
bool SieveAction::setParamWidgetValue(QXmlStreamReader &n, QWidget *, QString &)
{
n.skipCurrentElement();
return true;
}
QString SieveAction::comment() const
{
return mComment;
}
void SieveAction::setComment(const QString &comment)
{
mComment = comment;
}
void SieveAction::unknownTag(const QStringRef &tag, QString &error)
{
error += i18n("An unknown tag \"%1\" was found during parsing action \"%2\".", *tag.string(), name()) + QLatin1Char('\n');
......@@ -144,7 +86,3 @@ void SieveAction::serverDoesNotSupportFeatures(const QString &feature, QString &
error += i18n("A feature \"%1\" in condition \"%2\" is not supported by server", feature, name()) + QLatin1Char('\n');
}
QUrl SieveAction::href() const
{
return QUrl();
}
......@@ -21,58 +21,31 @@
#include <QObject>
#include <QUrl>
#include "autocreatescripts/commonwidgets/sievecommonactioncondition.h"
class QXmlStreamReader;
namespace KSieveUi {
class SieveImapAccountSettings;
class SieveEditorGraphicalModeWidget;
class SieveAction : public QObject
class SieveAction : public SieveCommonActionCondition
{
Q_OBJECT
public:
SieveAction(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = nullptr);
~SieveAction() override;
Q_REQUIRED_RESULT QString name() const;
Q_REQUIRED_RESULT QString label() const;
Q_REQUIRED_RESULT virtual QWidget *createParamWidget(QWidget *parent) const;
Q_REQUIRED_RESULT virtual bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error);
Q_REQUIRED_RESULT virtual QString code(QWidget *) const;
Q_REQUIRED_RESULT virtual QStringList needRequires(QWidget *parent) const;
Q_REQUIRED_RESULT virtual bool needCheckIfServerHasCapability() const;
Q_REQUIRED_RESULT virtual QString serverNeedsCapability() const;
Q_REQUIRED_RESULT virtual QString help() const;
Q_REQUIRED_RESULT virtual QUrl href() const;
Q_REQUIRED_RESULT QString comment() const;
void setComment(const QString &comment);
void unknownTag(const QStringRef &tag, QString &error);
void unknownTagValue(const QString &tagValue, QString &error);
void tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error);
void serverDoesNotSupportFeatures(const QString &feature, QString &error);
void unknownTag(const QStringRef &tag, QString &error) override;
void unknownTagValue(const QString &tagValue, QString &error) override;
void tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error) override;
void serverDoesNotSupportFeatures(const QString &feature, QString &error) override;
protected:
Q_REQUIRED_RESULT SieveImapAccountSettings sieveImapAccountSettings() const;
Q_REQUIRED_RESULT QStringList listOfIncludeFile() const;
Q_REQUIRED_RESULT QStringList sieveCapabilities() const;
SieveEditorGraphicalModeWidget *mSieveGraphicalModeWidget = nullptr;
Q_SIGNALS:
void valueChanged();
private:
Q_DISABLE_COPY(SieveAction)
QString mName;
QString mLabel;
QString mComment;
};
}
......
......@@ -28,10 +28,7 @@
using namespace KSieveUi;
SieveCondition::SieveCondition(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent)
: QObject(parent)
, mSieveGraphicalModeWidget(sieveGraphicalModeWidget)
, mName(name)
, mLabel(label)
: SieveCommonActionCondition(sieveGraphicalModeWidget, name, label, parent)
{
}
......@@ -39,33 +36,6 @@ SieveCondition::~SieveCondition()
{
}
KSieveUi::SieveImapAccountSettings SieveCondition::sieveImapAccountSettings() const
{
if (mSieveGraphicalModeWidget) {
return mSieveGraphicalModeWidget->sieveImapAccountSettings();
}
qCWarning(LIBKSIEVE_LOG) << "SieveAction::sieveImapAccountSettings Problem during initialize mSieveGraphicalModeWidget ";
return {};
}
QStringList SieveCondition::sieveCapabilities() const
{
if (mSieveGraphicalModeWidget) {
return mSieveGraphicalModeWidget->sieveCapabilities();
}
return {};
}
QString SieveCondition::name() const
{
return mName;
}
QString SieveCondition::label() const
{
return mLabel;
}
SieveCondition *SieveCondition::newAction()
{
return nullptr;
......@@ -76,33 +46,6 @@ QWidget *SieveCondition::createParamWidget(QWidget *parent) const
return new QWidget(parent);
}
QString SieveCondition::code(QWidget *parent) const
{
Q_UNUSED(parent);
return QString();
}
QStringList SieveCondition::needRequires(QWidget *parent) const
{
Q_UNUSED(parent);
return QStringList();
}
bool SieveCondition::needCheckIfServerHasCapability() const
{
return false;
}
QString SieveCondition::serverNeedsCapability() const
{
return QString();
}
QString SieveCondition::help() const
{
return QString();
}
bool SieveCondition::setParamWidgetValue(QXmlStreamReader & /*element*/, QWidget * /*parent*/, bool /*notCondition*/, QString & /*error*/)
{
return true;
......@@ -133,22 +76,3 @@ void SieveCondition::serverDoesNotSupportFeatures(const QString &feature, QStrin
error += i18n("A feature \"%1\" in condition \"%2\" is not supported by server", feature, name()) + QLatin1Char('\n');
}
QUrl SieveCondition::href() const
{
return QUrl();
}
QString SieveCondition::comment() const
{
return mComment;
}
void SieveCondition::setComment(const QString &comment)
{
mComment = comment;
}
QString SieveCondition::generateComment() const
{
return {};
}
......@@ -22,21 +22,18 @@
#include <QObject>
#include <QUrl>
#include "autocreatescripts/commonwidgets/sievecommonactioncondition.h"
class QXmlStreamReader;
namespace KSieveUi {
class SieveImapAccountSettings;
class SieveEditorGraphicalModeWidget;
class SieveCondition : public QObject
class SieveCondition : public SieveCommonActionCondition
{
Q_OBJECT
public:
SieveCondition(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = nullptr);
~SieveCondition() override;
QString name() const;
QString label() const;
/**
* Static function that creates a filter action of this type.
*/
......@@ -44,44 +41,14 @@ public:
Q_REQUIRED_RESULT virtual QWidget *createParamWidget(QWidget *parent) const;
Q_REQUIRED_RESULT virtual QString code(QWidget *parent) const;
Q_REQUIRED_RESULT virtual QStringList needRequires(QWidget *parent) const;
Q_REQUIRED_RESULT virtual bool needCheckIfServerHasCapability() const;
Q_REQUIRED_RESULT virtual QString serverNeedsCapability() const;
Q_REQUIRED_RESULT virtual QString help() const;
Q_REQUIRED_RESULT virtual QUrl href() const;
Q_REQUIRED_RESULT virtual bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, bool notCondition, QString &error);
void unknownTag(const QStringRef &tag, QString &error);
void unknownTagValue(const QString &tagValue, QString &error);
void tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error);
void unknownTag(const QStringRef &tag, QString &error) override;
void unknownTagValue(const QString &tagValue, QString &error) override;
void tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error) override;
void tooManyArguments(const QString &tagName, int index, int maxValue, QString &error);
void serverDoesNotSupportFeatures(const QString &feature, QString &error);
Q_REQUIRED_RESULT QString comment() const;
void setComment(const QString &comment);
Q_REQUIRED_RESULT QString generateComment() const;
protected:
Q_REQUIRED_RESULT KSieveUi::SieveImapAccountSettings sieveImapAccountSettings() const;
Q_REQUIRED_RESULT QStringList sieveCapabilities() const;
SieveEditorGraphicalModeWidget *mSieveGraphicalModeWidget = nullptr;
Q_SIGNALS:
void valueChanged();
void serverDoesNotSupportFeatures(const QString &feature, QString &error) override;
private:
Q_DISABLE_COPY(SieveCondition)
QString mName;
QString mLabel;
QString mComment;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment