Commit 1ffc2ae1 authored by Laurent Montel's avatar Laurent Montel 😁

Clean up code. Remove static method usage

parent af126b73
......@@ -23,10 +23,15 @@
#include <QWidget>
#include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
using namespace KSieveUi;
SieveAction::SieveAction(const QString &name, const QString &label, QObject *parent)
: QObject(parent), mName(name), mLabel(label)
SieveAction::SieveAction(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent)
: QObject(parent),
mSieveGraphicalModeWidget(sieveGraphicalModeWidget),
mName(name),
mLabel(label)
{
}
......@@ -34,6 +39,14 @@ SieveAction::~SieveAction()
{
}
QStringList SieveAction::sieveCapabilities() const
{
if (mSieveGraphicalModeWidget) {
return mSieveGraphicalModeWidget->sieveCapabilities();
}
return {};
}
QString SieveAction::name() const
{
return mName;
......@@ -44,11 +57,6 @@ QString SieveAction::label() const
return mLabel;
}
SieveAction *SieveAction::newAction()
{
return Q_NULLPTR;
}
QWidget *SieveAction::createParamWidget(QWidget *parent) const
{
return new QWidget(parent);
......
......@@ -24,20 +24,17 @@
class QDomElement;
namespace KSieveUi
{
class SieveEditorGraphicalModeWidget;
class SieveAction : public QObject
{
Q_OBJECT
public:
SieveAction(const QString &name, const QString &label, QObject *parent = Q_NULLPTR);
SieveAction(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = Q_NULLPTR);
virtual ~SieveAction();
QString name() const;
QString label() const;
/**
* Static function that creates a filter action of this type.
*/
static SieveAction *newAction();
virtual QWidget *createParamWidget(QWidget *parent) const;
......@@ -63,6 +60,10 @@ public:
void tooManyArgument(const QString &tagName, int index, int maxValue, QString &error);
void serverDoesNotSupportFeatures(const QString &feature, QString &error);
protected:
QStringList sieveCapabilities() const;
SieveEditorGraphicalModeWidget *mSieveGraphicalModeWidget;
Q_SIGNALS:
void valueChanged();
......
......@@ -20,8 +20,8 @@
using namespace KSieveUi;
SieveActionAbstractEditHeader::SieveActionAbstractEditHeader(const QString &name, const QString &label, QObject *parent)
: SieveAction(name, label, parent)
SieveActionAbstractEditHeader::SieveActionAbstractEditHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, name, label, parent)
{
}
......
......@@ -27,7 +27,7 @@ class SieveActionAbstractEditHeader : public SieveAction
{
Q_OBJECT
public:
SieveActionAbstractEditHeader(const QString &name, const QString &label, QObject *parent = Q_NULLPTR);
SieveActionAbstractEditHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = Q_NULLPTR);
QStringList needRequires(QWidget *parent) const Q_DECL_OVERRIDE;
......
......@@ -26,8 +26,8 @@
#include "libksieve_debug.h"
using namespace KSieveUi;
SieveActionAbstractFlags::SieveActionAbstractFlags(const QString &name, const QString &label, QObject *parent)
: SieveAction(name, label, parent)
SieveActionAbstractFlags::SieveActionAbstractFlags(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, name, label, parent)
{
}
......
......@@ -26,7 +26,7 @@ class SieveActionAbstractFlags : public SieveAction
{
Q_OBJECT
public:
SieveActionAbstractFlags(const QString &name, const QString &label, QObject *parent = Q_NULLPTR);
SieveActionAbstractFlags(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = Q_NULLPTR);
QWidget *createParamWidget(QWidget *parent) const Q_DECL_OVERRIDE;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) Q_DECL_OVERRIDE;
......
......@@ -22,16 +22,11 @@
#include <KLocalizedString>
using namespace KSieveUi;
SieveActionAddFlags::SieveActionAddFlags(QObject *parent)
: SieveActionAbstractFlags(QStringLiteral("addflag"), i18n("Add Flags"), parent)
SieveActionAddFlags::SieveActionAddFlags(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveActionAbstractFlags(sieveGraphicalModeWidget, QStringLiteral("addflag"), i18n("Add Flags"), parent)
{
}
SieveAction *SieveActionAddFlags::newAction()
{
return new SieveActionAddFlags;
}
QString SieveActionAddFlags::flagsCode() const
{
return QStringLiteral("addflag");
......
......@@ -27,8 +27,7 @@ class SieveActionAddFlags : public SieveActionAbstractFlags
{
Q_OBJECT
public:
explicit SieveActionAddFlags(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionAddFlags(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString flagsCode() const Q_DECL_OVERRIDE;
QString help() const Q_DECL_OVERRIDE;
QUrl href() const Q_DECL_OVERRIDE;
......
......@@ -31,16 +31,11 @@
using namespace KSieveUi;
SieveActionAddHeader::SieveActionAddHeader(QObject *parent)
: SieveActionAbstractEditHeader(QStringLiteral("addheader"), i18n("Add header"), parent)
SieveActionAddHeader::SieveActionAddHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveActionAbstractEditHeader(sieveGraphicalModeWidget, QStringLiteral("addheader"), i18n("Add header"), parent)
{
}
SieveAction *SieveActionAddHeader::newAction()
{
return new SieveActionAddHeader;
}
QWidget *SieveActionAddHeader::createParamWidget(QWidget *parent) const
{
QWidget *w = new QWidget(parent);
......
......@@ -26,8 +26,7 @@ class SieveActionAddHeader : public SieveActionAbstractEditHeader
{
Q_OBJECT
public:
explicit SieveActionAddHeader(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionAddHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString code(QWidget *w) const Q_DECL_OVERRIDE;
QWidget *createParamWidget(QWidget *parent) const Q_DECL_OVERRIDE;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) Q_DECL_OVERRIDE;
......
......@@ -29,16 +29,11 @@
#include "libksieve_debug.h"
using namespace KSieveUi;
SieveActionBreak::SieveActionBreak(QObject *parent)
: SieveAction(QStringLiteral("break"), i18n("Break"), parent)
SieveActionBreak::SieveActionBreak(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("break"), i18n("Break"), parent)
{
}
SieveAction *SieveActionBreak::newAction()
{
return new SieveActionBreak;
}
QWidget *SieveActionBreak::createParamWidget(QWidget *parent) const
{
QWidget *w = new QWidget(parent);
......
......@@ -26,8 +26,7 @@ class SieveActionBreak : public SieveAction
{
Q_OBJECT
public:
explicit SieveActionBreak(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionBreak(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString code(QWidget *) const Q_DECL_OVERRIDE;
QString help() const Q_DECL_OVERRIDE;
QStringList needRequires(QWidget *parent) const Q_DECL_OVERRIDE;
......
......@@ -29,16 +29,11 @@
#include <QGridLayout>
using namespace KSieveUi;
SieveActionConvert::SieveActionConvert(QObject *parent)
: SieveAction(QStringLiteral("convert"), i18n("Convert"), parent)
SieveActionConvert::SieveActionConvert(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("convert"), i18n("Convert"), parent)
{
}
SieveAction *SieveActionConvert::newAction()
{
return new SieveActionConvert;
}
QWidget *SieveActionConvert::createParamWidget(QWidget *parent) const
{
QWidget *w = new QWidget(parent);
......
......@@ -27,8 +27,7 @@ class SieveActionConvert : public SieveAction
{
Q_OBJECT
public:
explicit SieveActionConvert(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionConvert(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString code(QWidget *) const Q_DECL_OVERRIDE;
QWidget *createParamWidget(QWidget *parent) const Q_DECL_OVERRIDE;
QStringList needRequires(QWidget *parent) const Q_DECL_OVERRIDE;
......
......@@ -32,16 +32,11 @@
using namespace KSieveUi;
SieveActionDeleteHeader::SieveActionDeleteHeader(QObject *parent)
: SieveActionAbstractEditHeader(QStringLiteral("deleteheader"), i18n("Delete header"), parent)
SieveActionDeleteHeader::SieveActionDeleteHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveActionAbstractEditHeader(sieveGraphicalModeWidget, QStringLiteral("deleteheader"), i18n("Delete header"), parent)
{
}
SieveAction *SieveActionDeleteHeader::newAction()
{
return new SieveActionDeleteHeader;
}
QWidget *SieveActionDeleteHeader::createParamWidget(QWidget *parent) const
{
QWidget *w = new QWidget(parent);
......
......@@ -26,8 +26,7 @@ class SieveActionDeleteHeader : public SieveActionAbstractEditHeader
{
Q_OBJECT
public:
explicit SieveActionDeleteHeader(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionDeleteHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString code(QWidget *w) const Q_DECL_OVERRIDE;
QWidget *createParamWidget(QWidget *parent) const Q_DECL_OVERRIDE;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) Q_DECL_OVERRIDE;
......
......@@ -21,16 +21,11 @@
#include <KLocalizedString>
using namespace KSieveUi;
SieveActionDiscard::SieveActionDiscard(QObject *parent)
: SieveAction(QStringLiteral("discard"), i18n("Discard"), parent)
SieveActionDiscard::SieveActionDiscard(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("discard"), i18n("Discard"), parent)
{
}
SieveAction *SieveActionDiscard::newAction()
{
return new SieveActionDiscard;
}
QString SieveActionDiscard::code(QWidget *) const
{
return QStringLiteral("discard;");
......
......@@ -26,8 +26,7 @@ class SieveActionDiscard : public SieveAction
{
Q_OBJECT
public:
explicit SieveActionDiscard(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionDiscard(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString code(QWidget *) const Q_DECL_OVERRIDE;
QString help() const Q_DECL_OVERRIDE;
QUrl href() const Q_DECL_OVERRIDE;
......
......@@ -30,16 +30,11 @@
#include <QGridLayout>
using namespace KSieveUi;
SieveActionEnclose::SieveActionEnclose(QObject *parent)
: SieveAction(QStringLiteral("enclose"), i18n("Enclose"), parent)
SieveActionEnclose::SieveActionEnclose(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("enclose"), i18n("Enclose"), parent)
{
}
SieveAction *SieveActionEnclose::newAction()
{
return new SieveActionEnclose;
}
QWidget *SieveActionEnclose::createParamWidget(QWidget *parent) const
{
QWidget *w = new QWidget(parent);
......
......@@ -26,8 +26,7 @@ class SieveActionEnclose : public SieveAction
{
Q_OBJECT
public:
explicit SieveActionEnclose(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionEnclose(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString code(QWidget *) const Q_DECL_OVERRIDE;
QWidget *createParamWidget(QWidget *parent) const Q_DECL_OVERRIDE;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) Q_DECL_OVERRIDE;
......
......@@ -29,16 +29,11 @@
#include "libksieve_debug.h"
using namespace KSieveUi;
SieveActionEReject::SieveActionEReject(QObject *parent)
: SieveAction(QStringLiteral("ereject"), i18n("E-Reject"), parent)
SieveActionEReject::SieveActionEReject(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("ereject"), i18n("E-Reject"), parent)
{
}
SieveAction *SieveActionEReject::newAction()
{
return new SieveActionEReject;
}
QWidget *SieveActionEReject::createParamWidget(QWidget *parent) const
{
QWidget *w = new QWidget(parent);
......
......@@ -26,9 +26,7 @@ class SieveActionEReject : public SieveAction
{
Q_OBJECT
public:
explicit SieveActionEReject(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionEReject(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QWidget *createParamWidget(QWidget *parent) const Q_DECL_OVERRIDE;
QString code(QWidget *) const Q_DECL_OVERRIDE;
......
......@@ -29,16 +29,11 @@
#include <QGridLayout>
using namespace KSieveUi;
SieveActionExtractText::SieveActionExtractText(QObject *parent)
: SieveAction(QStringLiteral("extracttext"), i18n("Extract Text"), parent)
SieveActionExtractText::SieveActionExtractText(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("extracttext"), i18n("Extract Text"), parent)
{
}
SieveAction *SieveActionExtractText::newAction()
{
return new SieveActionExtractText;
}
QWidget *SieveActionExtractText::createParamWidget(QWidget *parent) const
{
QWidget *w = new QWidget(parent);
......
......@@ -26,8 +26,7 @@ class SieveActionExtractText : public SieveAction
{
Q_OBJECT
public:
explicit SieveActionExtractText(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionExtractText(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QWidget *createParamWidget(QWidget *parent) const Q_DECL_OVERRIDE;
QString code(QWidget *) const Q_DECL_OVERRIDE;
QStringList needRequires(QWidget *parent) const Q_DECL_OVERRIDE;
......
......@@ -31,18 +31,13 @@
#include <QDomNode>
//Add support for adding flags
using namespace KSieveUi;
SieveActionFileInto::SieveActionFileInto(QObject *parent)
: SieveAction(QStringLiteral("fileinto"), i18n("File Into"), parent)
SieveActionFileInto::SieveActionFileInto(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("fileinto"), i18n("File Into"), parent)
{
mHasCopySupport = SieveEditorGraphicalModeWidget::sieveCapabilities().contains(QStringLiteral("copy"));
mHasMailBoxSupport = SieveEditorGraphicalModeWidget::sieveCapabilities().contains(QStringLiteral("mailbox"));
}
SieveAction *SieveActionFileInto::newAction()
{
return new SieveActionFileInto;
}
QString SieveActionFileInto::code(QWidget *w) const
{
QString result = QStringLiteral("fileinto ");
......
......@@ -26,8 +26,7 @@ class SieveActionFileInto : public SieveAction
{
Q_OBJECT
public:
explicit SieveActionFileInto(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionFileInto(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString code(QWidget *) const Q_DECL_OVERRIDE;
QWidget *createParamWidget(QWidget *parent) const Q_DECL_OVERRIDE;
QStringList needRequires(QWidget *parent) const Q_DECL_OVERRIDE;
......
......@@ -29,18 +29,13 @@
#include "libksieve_debug.h"
using namespace KSieveUi;
SieveActionKeep::SieveActionKeep(QObject *parent)
: SieveAction(QStringLiteral("keep"), i18n("Keep"), parent)
SieveActionKeep::SieveActionKeep(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("keep"), i18n("Keep"), parent)
{
mHasImapFlag4Support = SieveEditorGraphicalModeWidget::sieveCapabilities().contains(QStringLiteral("imap4flags"));
mHasFlagSupport = SieveEditorGraphicalModeWidget::sieveCapabilities().contains(QStringLiteral("imapflags")) || mHasImapFlag4Support;
}
SieveAction *SieveActionKeep::newAction()
{
return new SieveActionKeep;
}
QString SieveActionKeep::code(QWidget *w) const
{
if (mHasFlagSupport) {
......
......@@ -25,8 +25,7 @@ class SieveActionKeep : public SieveAction
{
Q_OBJECT
public:
explicit SieveActionKeep(QObject *parent = Q_NULLPTR);
static SieveAction *newAction();
explicit SieveActionKeep(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = Q_NULLPTR);
QString code(QWidget *) const Q_DECL_OVERRIDE;
QString help() const Q_DECL_OVERRIDE;
......
......@@ -40,29 +40,29 @@
#include "sieveactionsetvariable.h"
#include "sieveactionreturn.h"
QList<KSieveUi::SieveAction *> KSieveUi::SieveActionList::actionList()
QList<KSieveUi::SieveAction *> KSieveUi::SieveActionList::actionList(SieveEditorGraphicalModeWidget *graphicalModeWidget)
{
QList<KSieveUi::SieveAction *> list;
list.append(new KSieveUi::SieveActionDiscard);
list.append(new KSieveUi::SieveActionStop);
list.append(new KSieveUi::SieveActionSetFlags);
list.append(new KSieveUi::SieveActionAddFlags);
list.append(new KSieveUi::SieveActionRemoveFlags);
list.append(new KSieveUi::SieveActionFileInto);
list.append(new KSieveUi::SieveActionReject);
list.append(new KSieveUi::SieveActionEReject);
list.append(new KSieveUi::SieveActionKeep);
list.append(new KSieveUi::SieveActionRedirect);
list.append(new KSieveUi::SieveActionNotify);
list.append(new KSieveUi::SieveActionDeleteHeader);
list.append(new KSieveUi::SieveActionAddHeader);
list.append(new KSieveUi::SieveActionVacation);
list.append(new KSieveUi::SieveActionEnclose);
list.append(new KSieveUi::SieveActionReplace);
list.append(new KSieveUi::SieveActionExtractText);
list.append(new KSieveUi::SieveActionBreak);
list.append(new KSieveUi::SieveActionConvert);
list.append(new KSieveUi::SieveActionSetVariable);
list.append(new KSieveUi::SieveActionReturn);
list.append(new KSieveUi::SieveActionDiscard(graphicalModeWidget));
list.append(new KSieveUi::SieveActionStop(graphicalModeWidget));
list.append(new KSieveUi::SieveActionSetFlags(graphicalModeWidget));
list.append(new KSieveUi::SieveActionAddFlags(graphicalModeWidget));
list.append(new KSieveUi::SieveActionRemoveFlags(graphicalModeWidget));
list.append(new KSieveUi::SieveActionFileInto(graphicalModeWidget));
list.append(new KSieveUi::SieveActionReject(graphicalModeWidget));
list.append(new KSieveUi::SieveActionEReject(graphicalModeWidget));
list.append(new KSieveUi::SieveActionKeep(graphicalModeWidget));
list.append(new KSieveUi::SieveActionRedirect(graphicalModeWidget));
list.append(new KSieveUi::SieveActionNotify(graphicalModeWidget));
list.append(new KSieveUi::SieveActionDeleteHeader(graphicalModeWidget));
list.append(new KSieveUi::SieveActionAddHeader(graphicalModeWidget));
list.append(new KSieveUi::SieveActionVacation(graphicalModeWidget));
list.append(new KSieveUi::SieveActionEnclose(graphicalModeWidget));
list.append(new KSieveUi::SieveActionReplace(graphicalModeWidget));
list.append(new KSieveUi::SieveActionExtractText(graphicalModeWidget));
list.append(new KSieveUi::SieveActionBreak(graphicalModeWidget));
list.append(new KSieveUi::SieveActionConvert(graphicalModeWidget));
list.append(new KSieveUi::SieveActionSetVariable(graphicalModeWidget));
list.append(new KSieveUi::SieveActionReturn(graphicalModeWidget));
return list;
}
......@@ -24,9 +24,10 @@
namespace KSieveUi
{
class SieveAction;
class SieveEditorGraphicalModeWidget;
namespace SieveActionList
{
QList<KSieveUi::SieveAction *> actionList();
QList<KSieveUi::SieveAction *> actionList(KSieveUi::SieveEditorGraphicalModeWidget *graphicalModeWidget);
}
}
......
......@@ -31,16 +31,11 @@
using namespace KSieveUi;
SieveActionNotify::SieveActionNotify(QObject *parent)
: SieveAction(QStringLiteral("notify"), i18n("Notify"), parent)
SieveActionNotify::SieveActionNotify(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
: SieveAction(sieveGraphicalModeWidget, QStringLiteral("notify"), i18n("Notify"), parent)
{
}
SieveAction *SieveActionNotify::newAction()
{
return new SieveActionNotify;
}
QWidget *SieveActionNotify::createParamWidget(QWidget *parent) const
{
QWidget *w = new QWidget(parent);
......