Commit 7e371009 authored by Laurent Montel's avatar Laurent Montel 😁

Add support for comment in condition widget

parent aae747bf
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <QLabel> #include <QLabel>
#include <QWhatsThis> #include <QWhatsThis>
#include "libksieve_debug.h" #include "libksieve_debug.h"
#include "sievescriptdescriptiondialog.h"
#include <QDomElement> #include <QDomElement>
using namespace KSieveUi; using namespace KSieveUi;
...@@ -57,14 +58,14 @@ SieveConditionWidget::~SieveConditionWidget() ...@@ -57,14 +58,14 @@ SieveConditionWidget::~SieveConditionWidget()
void SieveConditionWidget::setFilterCondition(QWidget *widget) void SieveConditionWidget::setFilterCondition(QWidget *widget)
{ {
if (mLayout->itemAtPosition(1, 2)) { if (mLayout->itemAtPosition(1, 3)) {
delete mLayout->itemAtPosition(1, 2)->widget(); delete mLayout->itemAtPosition(1, 3)->widget();
} }
if (widget) { if (widget) {
mLayout->addWidget(widget, 1, 2); mLayout->addWidget(widget, 1, 3);
} else { } else {
mLayout->addWidget(new QLabel(i18n("Please select an condition."), this), 1, 2); mLayout->addWidget(new QLabel(i18n("Please select an condition."), this), 1, 3);
} }
} }
...@@ -74,7 +75,7 @@ void SieveConditionWidget::generatedScript(QString &script, QStringList &require ...@@ -74,7 +75,7 @@ void SieveConditionWidget::generatedScript(QString &script, QStringList &require
const int index = mComboBox->currentIndex(); const int index = mComboBox->currentIndex();
if (index != mComboBox->count() - 1) { if (index != mComboBox->count() - 1) {
KSieveUi::SieveCondition *widgetCondition = mConditionList.at(mComboBox->currentIndex()); KSieveUi::SieveCondition *widgetCondition = mConditionList.at(mComboBox->currentIndex());
QWidget *currentWidget = mLayout->itemAtPosition(1, 2)->widget(); QWidget *currentWidget = mLayout->itemAtPosition(1, 3)->widget();
const QStringList lstRequires = widgetCondition->needRequires(currentWidget); const QStringList lstRequires = widgetCondition->needRequires(currentWidget);
for (const QString &r : lstRequires) { for (const QString &r : lstRequires) {
if (!requires.contains(r)) { if (!requires.contains(r)) {
...@@ -118,13 +119,18 @@ void SieveConditionWidget::initWidget() ...@@ -118,13 +119,18 @@ void SieveConditionWidget::initWidget()
} }
mHelpButton = new SieveHelpButton(this); mHelpButton = new SieveHelpButton(this);
mHelpButton->setEnabled(false);
mLayout->addWidget(mHelpButton, 1, 0); mLayout->addWidget(mHelpButton, 1, 0);
connect(mHelpButton, &SieveHelpButton::clicked, this, &SieveConditionWidget::slotHelp); connect(mHelpButton, &SieveHelpButton::clicked, this, &SieveConditionWidget::slotHelp);
mCommentButton = new QToolButton(this);
mCommentButton->setToolTip(i18n("Add comment"));
mLayout->addWidget(mCommentButton, 1, 1);
mCommentButton->setIcon(QIcon::fromTheme(QStringLiteral("view-pim-notes")));
connect(mCommentButton, &QToolButton::clicked, this, &SieveConditionWidget::slotAddComment);
mComboBox->addItem(QLatin1String("")); mComboBox->addItem(QLatin1String(""));
mComboBox->setCurrentIndex(mComboBox->count() - 1); mLayout->addWidget(mComboBox, 1, 2);
mLayout->addWidget(mComboBox, 1, 1);
connect(mComboBox, static_cast<void (PimCommon::MinimumComboBox::*)(int)>(&PimCommon::MinimumComboBox::activated), this, &SieveConditionWidget::slotConditionChanged); connect(mComboBox, static_cast<void (PimCommon::MinimumComboBox::*)(int)>(&PimCommon::MinimumComboBox::activated), this, &SieveConditionWidget::slotConditionChanged);
mComboBox->setMaxCount(mComboBox->count()); mComboBox->setMaxCount(mComboBox->count());
...@@ -140,15 +146,32 @@ void SieveConditionWidget::initWidget() ...@@ -140,15 +146,32 @@ void SieveConditionWidget::initWidget()
mRemove->setIcon(QIcon::fromTheme(QStringLiteral("list-remove"))); mRemove->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
mRemove->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); mRemove->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
mLayout->addWidget(mAdd, 1, 3); mLayout->addWidget(mAdd, 1, 4);
mLayout->addWidget(mRemove, 1, 4); mLayout->addWidget(mRemove, 1, 5);
// redirect focus to the filter action combo box // redirect focus to the filter action combo box
setFocusProxy(mComboBox); setFocusProxy(mComboBox);
connect(mAdd, &QPushButton::clicked, this, &SieveConditionWidget::slotAddWidget); connect(mAdd, &QPushButton::clicked, this, &SieveConditionWidget::slotAddWidget);
connect(mRemove, &QPushButton::clicked, this, &SieveConditionWidget::slotRemoveWidget); connect(mRemove, &QPushButton::clicked, this, &SieveConditionWidget::slotRemoveWidget);
setFilterCondition(nullptr);
clear();
}
void SieveConditionWidget::slotAddComment()
{
const int index = mComboBox->currentIndex();
if (index < mConditionList.count()) {
KSieveUi::SieveCondition *condition = mConditionList.at(index);
const QString comment = condition->comment();
QPointer<SieveScriptDescriptionDialog> dlg = new SieveScriptDescriptionDialog;
dlg->setDescription(comment);
if (dlg->exec()) {
condition->setComment(dlg->description());
Q_EMIT valueChanged();
}
delete dlg;
}
} }
void SieveConditionWidget::slotHelp() void SieveConditionWidget::slotHelp()
...@@ -169,9 +192,11 @@ void SieveConditionWidget::slotConditionChanged(int index) ...@@ -169,9 +192,11 @@ void SieveConditionWidget::slotConditionChanged(int index)
KSieveUi::SieveCondition *condition = mConditionList.at(index); KSieveUi::SieveCondition *condition = mConditionList.at(index);
mHelpButton->setEnabled(!condition->help().isEmpty()); mHelpButton->setEnabled(!condition->help().isEmpty());
setFilterCondition(condition->createParamWidget(this)); setFilterCondition(condition->createParamWidget(this));
mCommentButton->setEnabled(true);
} else { } else {
setFilterCondition(nullptr); setFilterCondition(nullptr);
mHelpButton->setEnabled(false); mHelpButton->setEnabled(false);
mCommentButton->setEnabled(false);
} }
Q_EMIT valueChanged(); Q_EMIT valueChanged();
} }
...@@ -193,6 +218,7 @@ void SieveConditionWidget::clear() ...@@ -193,6 +218,7 @@ void SieveConditionWidget::clear()
mComboBox->setCurrentIndex(mComboBox->count() - 1); mComboBox->setCurrentIndex(mComboBox->count() - 1);
setFilterCondition(nullptr); setFilterCondition(nullptr);
mHelpButton->setEnabled(false); mHelpButton->setEnabled(false);
mCommentButton->setEnabled(false);
} }
void SieveConditionWidget::updateAddRemoveButton(bool addButtonEnabled, bool removeButtonEnabled) void SieveConditionWidget::updateAddRemoveButton(bool addButtonEnabled, bool removeButtonEnabled)
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
class QPushButton; class QPushButton;
class QGridLayout; class QGridLayout;
class QDomElement; class QDomElement;
class QToolButton;
namespace PimCommon { namespace PimCommon {
class MinimumComboBox; class MinimumComboBox;
...@@ -50,7 +51,8 @@ private Q_SLOTS: ...@@ -50,7 +51,8 @@ private Q_SLOTS:
void slotAddWidget(); void slotAddWidget();
void slotRemoveWidget(); void slotRemoveWidget();
void slotConditionChanged(int index); void slotConditionChanged(int index);
void slotHelp(); void slotHelp();
void slotAddComment();
Q_SIGNALS: Q_SIGNALS:
void addWidget(QWidget *w); void addWidget(QWidget *w);
...@@ -66,6 +68,7 @@ private: ...@@ -66,6 +68,7 @@ private:
PimCommon::MinimumComboBox *mComboBox; PimCommon::MinimumComboBox *mComboBox;
QGridLayout *mLayout; QGridLayout *mLayout;
SieveHelpButton *mHelpButton; SieveHelpButton *mHelpButton;
QToolButton *mCommentButton;
SieveEditorGraphicalModeWidget *mSieveGraphicalModeWidget; SieveEditorGraphicalModeWidget *mSieveGraphicalModeWidget;
}; };
......
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