File indexing completed on 2024-11-10 04:50:05

0001 /*
0002  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  *
0006  */
0007 
0008 #include "filteractionwithstring.h"
0009 
0010 #include <KLineEdit>
0011 
0012 using namespace MailCommon;
0013 
0014 FilterActionWithString::FilterActionWithString(const QString &name, const QString &label, QObject *parent)
0015     : FilterAction(name, label, parent)
0016 {
0017 }
0018 
0019 bool FilterActionWithString::isEmpty() const
0020 {
0021     return mParameter.trimmed().isEmpty();
0022 }
0023 
0024 QWidget *FilterActionWithString::createParamWidget(QWidget *parent) const
0025 {
0026     auto lineEdit = new KLineEdit(parent);
0027     lineEdit->setClearButtonEnabled(true);
0028     lineEdit->setObjectName(QLatin1StringView("lineedit"));
0029     lineEdit->setTrapReturnKey(true);
0030     lineEdit->setText(mParameter);
0031 
0032     connect(lineEdit, &KLineEdit::textChanged, this, &FilterActionWithString::filterActionModified);
0033 
0034     return lineEdit;
0035 }
0036 
0037 void FilterActionWithString::applyParamWidgetValue(QWidget *paramWidget)
0038 {
0039     mParameter = static_cast<KLineEdit *>(paramWidget)->text();
0040 }
0041 
0042 void FilterActionWithString::setParamWidgetValue(QWidget *paramWidget) const
0043 {
0044     static_cast<KLineEdit *>(paramWidget)->setText(mParameter);
0045 }
0046 
0047 void FilterActionWithString::clearParamWidget(QWidget *paramWidget) const
0048 {
0049     static_cast<KLineEdit *>(paramWidget)->clear();
0050 }
0051 
0052 void FilterActionWithString::argsFromString(const QString &argsStr)
0053 {
0054     mParameter = argsStr;
0055 }
0056 
0057 QString FilterActionWithString::argsAsString() const
0058 {
0059     return mParameter;
0060 }
0061 
0062 QString FilterActionWithString::displayString() const
0063 {
0064     return label() + QLatin1StringView(" \"") + argsAsString().toHtmlEscaped() + QLatin1StringView("\"");
0065 }
0066 
0067 #include "moc_filteractionwithstring.cpp"