Commit 8c30cc43 authored by Laurent Montel's avatar Laurent Montel 😁

Use AbstractRegexpEditorLineEdit

parent 9247b212
......@@ -52,8 +52,9 @@ QWidget *SieveConditionBody::createParamWidget(QWidget *parent) const
matchType->setObjectName(QStringLiteral("matchtype"));
connect(matchType, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionBody::valueChanged);
QLineEdit *edit = new QLineEdit;
connect(edit, &QLineEdit::textChanged, this, &SieveConditionBody::valueChanged);
AbstractRegexpEditorLineEdit *edit = AutoCreateScriptUtil::createRegexpEditorLineEdit();
connect(edit, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionBody::valueChanged);
connect(matchType, &SelectMatchTypeComboBox::switchToRegexp, edit, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit);
edit->setClearButtonEnabled(true);
lay->addWidget(edit);
edit->setObjectName(QStringLiteral("edit"));
......@@ -69,8 +70,8 @@ QString SieveConditionBody::code(QWidget *w) const
bool isNegative = false;
const QString matchValue = matchType->code(isNegative);
QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
const QString editValue = AutoCreateScriptUtil::createAddressList(edit->text().trimmed(), false);
const AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("edit"));
const QString editValue = AutoCreateScriptUtil::createAddressList(edit->code().trimmed(), false);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("body %1 %2 %3").arg(bodyValue, matchValue, editValue)
+ AutoCreateScriptUtil::generateConditionComment(comment());
}
......@@ -150,15 +151,15 @@ bool SieveConditionBody::setParamWidgetValue(const QDomElement &element, QWidget
bodyType->setCode(tagValueList.at(0), QString(), name(), error);
SelectMatchTypeComboBox *matchType = w->findChild<SelectMatchTypeComboBox *>(QStringLiteral("matchtype"));
matchType->setCode(tagValueList.at(1), name(), error);
QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
edit->setText(wasListElement ? strValue.at(0) : AutoCreateScriptUtil::quoteStr(strValue.at(0)));
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("edit"));
edit->setCode(wasListElement ? strValue.at(0) : AutoCreateScriptUtil::quoteStr(strValue.at(0)));
} else if (strValue.count() == 2) {
SelectBodyTypeWidget *bodyType = w->findChild<SelectBodyTypeWidget *>(QStringLiteral("bodytype"));
bodyType->setCode(tagValueList.at(0), indexStr == 2 ? strValue.at(0) : QString(), name(), error);
SelectMatchTypeComboBox *matchType = w->findChild<SelectMatchTypeComboBox *>(QStringLiteral("matchtype"));
matchType->setCode(tagValueList.at(1), name(), error);
QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
edit->setText(indexStr == 1 ? AutoCreateScriptUtil::quoteStr(strValue.at(0)) : AutoCreateScriptUtil::quoteStr(strValue.at(1)));
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("edit"));
edit->setCode(indexStr == 1 ? AutoCreateScriptUtil::quoteStr(strValue.at(0)) : AutoCreateScriptUtil::quoteStr(strValue.at(1)));
}
return true;
}
......
......@@ -68,8 +68,9 @@ QWidget *SieveConditionEnvelope::createParamWidget(QWidget *parent) const
QLabel *lab = new QLabel(i18n("address:"));
grid->addWidget(lab, 1, 0);
QLineEdit *edit = new QLineEdit;
connect(edit, &QLineEdit::textChanged, this, &SieveConditionEnvelope::valueChanged);
AbstractRegexpEditorLineEdit *edit = AutoCreateScriptUtil::createRegexpEditorLineEdit();
connect(edit, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionEnvelope::valueChanged);
connect(selectMatchCombobox, &SelectMatchTypeComboBox::switchToRegexp, edit, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit);
edit->setClearButtonEnabled(true);
edit->setPlaceholderText(i18n("Use ; to separate emails"));
grid->addWidget(edit, 1, 1);
......@@ -90,8 +91,8 @@ QString SieveConditionEnvelope::code(QWidget *w) const
const SelectHeaderTypeComboBox *selectHeaderType = w->findChild<SelectHeaderTypeComboBox *>(QStringLiteral("headertypecombobox"));
const QString selectHeaderTypeStr = selectHeaderType->code();
const QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("editaddress"));
const QString addressStr = AutoCreateScriptUtil::createAddressList(edit->text().trimmed(), false);
const AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("editaddress"));
const QString addressStr = AutoCreateScriptUtil::createAddressList(edit->code().trimmed(), false);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("envelope %1 %2 %3 %4").arg(selectAddressPartStr, matchTypeStr, selectHeaderTypeStr, addressStr)
+ AutoCreateScriptUtil::generateConditionComment(comment());
}
......@@ -152,8 +153,8 @@ bool SieveConditionEnvelope::setParamWidgetValue(const QDomElement &element, QWi
SelectHeaderTypeComboBox *selectHeaderType = w->findChild<SelectHeaderTypeComboBox *>(QStringLiteral("headertypecombobox"));
selectHeaderType->setCode(e.text());
} else if (indexStr == 1) {
QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("editaddress"));
edit->setText(AutoCreateScriptUtil::quoteStr(e.text()));
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("editaddress"));
edit->setCode(AutoCreateScriptUtil::quoteStr(e.text()));
} else {
tooManyArgument(tagName, indexStr, 2, error);
qCDebug(LIBKSIEVE_LOG) << "SieveConditionEnvelope::setParamWidgetValue too many argument indexStr " << indexStr;
......@@ -164,8 +165,8 @@ bool SieveConditionEnvelope::setParamWidgetValue(const QDomElement &element, QWi
SelectHeaderTypeComboBox *selectHeaderType = w->findChild<SelectHeaderTypeComboBox *>(QStringLiteral("headertypecombobox"));
selectHeaderType->setCode(AutoCreateScriptUtil::listValueToStr(e));
} else if (indexStr == 1) {
QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("editaddress"));
edit->setText(AutoCreateScriptUtil::listValueToStr(e));
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("editaddress"));
edit->setCode(AutoCreateScriptUtil::listValueToStr(e));
}
++indexStr;
} else if (tagName == QLatin1String("crlf")) {
......
......@@ -20,6 +20,7 @@
#include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h"
#include "autocreatescripts/autocreatescriptutil_p.h"
#include "widgets/selectheadertypecombobox.h"
#include "editor/sieveeditorutil.h"
#include <KLocalizedString>
#include <QLineEdit>
......@@ -59,8 +60,9 @@ QWidget *SieveConditionHeader::createParamWidget(QWidget *parent) const
QLabel *lab = new QLabel(i18n("With value:"));
grid->addWidget(lab, 1, 0);
QLineEdit *value = new QLineEdit;
connect(value, &QLineEdit::textChanged, this, &SieveConditionHeader::valueChanged);
AbstractRegexpEditorLineEdit *value = AutoCreateScriptUtil::createRegexpEditorLineEdit();
connect(value, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionHeader::valueChanged);
connect(matchTypeCombo, &SelectMatchTypeComboBox::switchToRegexp, value, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit);
value->setObjectName(QStringLiteral("value"));
grid->addWidget(value, 1, 1);
return w;
......@@ -75,8 +77,8 @@ QString SieveConditionHeader::code(QWidget *w) const
const SelectHeaderTypeComboBox *headerType = w->findChild<SelectHeaderTypeComboBox *>(QStringLiteral("headertype"));
const QString headerStr = headerType->code();
const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
QString valueStr = value->text();
const AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
QString valueStr = edit->code();
valueStr = AutoCreateScriptUtil::fixListValue(valueStr);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("header %1 %2 %3").arg(matchString, headerStr, valueStr)
......@@ -106,9 +108,9 @@ bool SieveConditionHeader::setParamWidgetValue(const QDomElement &element, QWidg
SelectHeaderTypeComboBox *headerType = w->findChild<SelectHeaderTypeComboBox *>(QStringLiteral("headertype"));
headerType->setCode(e.text());
} else if (index == 1) {
QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
QString st = AutoCreateScriptUtil::quoteStr(e.text(), true);
value->setText(st);
value->setCode(st);
} else {
tooManyArgument(tagName, index, 2, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionHeader::setParamWidgetValue too many argument " << index;
......@@ -120,8 +122,8 @@ bool SieveConditionHeader::setParamWidgetValue(const QDomElement &element, QWidg
SelectHeaderTypeComboBox *headerType = w->findChild<SelectHeaderTypeComboBox *>(QStringLiteral("headertype"));
headerType->setCode(AutoCreateScriptUtil::listValueToStr(e));
} else if (index == 1) {
QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
value->setText(AutoCreateScriptUtil::listValueToStr(e));
AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
value->setCode(AutoCreateScriptUtil::listValueToStr(e));
} else {
tooManyArgument(tagName, index, 2, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionHeader::setParamWidgetValue too many argument " << index;
......@@ -145,7 +147,6 @@ bool SieveConditionHeader::setParamWidgetValue(const QDomElement &element, QWidg
return true;
}
QStringList KSieveUi::SieveConditionHeader::needRequires(QWidget *w) const
{
const SelectMatchTypeComboBox *matchTypeCombo = w->findChild<SelectMatchTypeComboBox *>(QStringLiteral("matchtypecombobox"));
......
......@@ -70,8 +70,9 @@ QWidget *SieveConditionMetaData::createParamWidget(QWidget *parent) const
lab = new QLabel(i18n("Value:"));
grid->addWidget(lab, 2, 0);
QLineEdit *value = new QLineEdit;
connect(value, &QLineEdit::textChanged, this, &SieveConditionMetaData::valueChanged);
AbstractRegexpEditorLineEdit *value = AutoCreateScriptUtil::createRegexpEditorLineEdit();
connect(value, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionMetaData::valueChanged);
connect(selectType, &SelectMatchTypeComboBox::switchToRegexp, value, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit);
value->setObjectName(QStringLiteral("value"));
grid->addWidget(value, 2, 1);
......@@ -96,8 +97,8 @@ QString SieveConditionMetaData::code(QWidget *w) const
result += QStringLiteral("\"%1\" ").arg(annotationStr);
const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
const QString valueStr = value->text();
const AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
const QString valueStr = value->code();
result += QStringLiteral("\"%1\"").arg(valueStr);
return result + AutoCreateScriptUtil::generateConditionComment(comment());
......@@ -151,8 +152,8 @@ bool SieveConditionMetaData::setParamWidgetValue(const QDomElement &element, QWi
}
case 2:
{
QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
value->setText(AutoCreateScriptUtil::quoteStr(tagValue));
AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
value->setCode(AutoCreateScriptUtil::quoteStr(tagValue));
break;
}
default:
......
......@@ -71,8 +71,9 @@ QWidget *SieveConditionServerMetaData::createParamWidget(QWidget *parent) const
lab = new QLabel(i18n("Value:"));
grid->addWidget(lab, 2, 0);
QLineEdit *value = new QLineEdit;
connect(value, &QLineEdit::textChanged, this, &SieveConditionServerMetaData::valueChanged);
AbstractRegexpEditorLineEdit *value = AutoCreateScriptUtil::createRegexpEditorLineEdit();
connect(value, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionServerMetaData::valueChanged);
connect(selectType, &SelectMatchTypeComboBox::switchToRegexp, value, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit);
value->setObjectName(QStringLiteral("value"));
grid->addWidget(value, 2, 1);
......@@ -97,8 +98,8 @@ QString SieveConditionServerMetaData::code(QWidget *w) const
result += QStringLiteral("\"%1\" ").arg(annotationStr);
const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
const QString valueStr = value->text();
const AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
const QString valueStr = value->code();
result += QStringLiteral("\"%1\"").arg(valueStr);
return result + AutoCreateScriptUtil::generateConditionComment(comment());
......@@ -152,8 +153,8 @@ bool SieveConditionServerMetaData::setParamWidgetValue(const QDomElement &elemen
}
case 2:
{
QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
value->setText(tagValue);
AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
value->setCode(tagValue);
break;
}
default:
......
......@@ -54,7 +54,6 @@ QString KSieveUi::RegexpEditorLineEdit::code() const
return mLineEdit->text();
}
void KSieveUi::RegexpEditorLineEdit::setClearButtonEnabled(bool b)
{
mLineEdit->setClearButtonEnabled(b);
......
......@@ -38,7 +38,6 @@ public:
virtual void setClearButtonEnabled(bool b) = 0;
virtual void setPlaceholderText(const QString &str) = 0;
Q_SIGNALS:
void textChanged(const QString &);
};
......
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