Mailcommon

filteractionwithurl.cpp
1 /*
2  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <[email protected]>
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  *
6  */
7 
8 #include "filteractionwithurl.h"
9 
10 #include <KLocalizedString>
11 #include <KUrlRequester>
12 #include <QUrl>
13 
14 #include <QHBoxLayout>
15 #include <QWhatsThis>
16 
17 using namespace MailCommon;
18 
19 FilterActionWithUrlHelpButton::FilterActionWithUrlHelpButton(QWidget *parent)
20  : QToolButton(parent)
21 {
22  setToolTip(i18n("Help"));
23  setIcon(QIcon::fromTheme(QStringLiteral("help-hint")));
24 }
25 
26 FilterActionWithUrlHelpButton::~FilterActionWithUrlHelpButton() = default;
27 
28 FilterActionWithUrl::FilterActionWithUrl(const QString &name, const QString &label, QObject *parent)
29  : FilterAction(name, label, parent)
30  , mHelpButton(nullptr)
31 {
32 }
33 
34 FilterActionWithUrl::~FilterActionWithUrl() = default;
35 
36 bool FilterActionWithUrl::isEmpty() const
37 {
38  return mParameter.trimmed().isEmpty();
39 }
40 
41 QWidget *FilterActionWithUrl::createParamWidget(QWidget *parent) const
42 {
43  auto widget = new QWidget(parent);
44  auto layout = new QHBoxLayout;
45  layout->setContentsMargins({});
46  layout->setSpacing(0);
47  widget->setLayout(layout);
48  auto requester = new KUrlRequester(parent);
49  requester->setUrl(QUrl::fromLocalFile(mParameter));
50  requester->setObjectName(QStringLiteral("requester"));
51  layout->addWidget(requester);
52  mHelpButton = new FilterActionWithUrlHelpButton(parent);
53  mHelpButton->setObjectName(QStringLiteral("helpbutton"));
54  connect(mHelpButton, &QAbstractButton::clicked, this, &FilterActionWithUrl::slotHelp);
55  layout->addWidget(mHelpButton);
56 
57  connect(requester, &KUrlRequester::textChanged, this, &FilterActionWithUrl::filterActionModified);
58 
59  return widget;
60 }
61 
62 void FilterActionWithUrl::slotHelp()
63 {
64  const QString fullWhatsThis = i18n("You can get specific header when you use %{headername}.");
65  QWhatsThis::showText(QCursor::pos(), fullWhatsThis, mHelpButton);
66 }
67 
68 void FilterActionWithUrl::applyParamWidgetValue(QWidget *paramWidget)
69 {
70  auto *requester = paramWidget->findChild<KUrlRequester *>(QStringLiteral("requester"));
71  Q_ASSERT(requester);
72 
73  mParameter = requester->text();
74 }
75 
76 void FilterActionWithUrl::setParamWidgetValue(QWidget *paramWidget) const
77 {
78  auto *requester = paramWidget->findChild<KUrlRequester *>(QStringLiteral("requester"));
79  Q_ASSERT(requester);
80 
81  requester->setText(mParameter);
82 }
83 
84 void FilterActionWithUrl::clearParamWidget(QWidget *paramWidget) const
85 {
86  auto *requester = paramWidget->findChild<KUrlRequester *>(QStringLiteral("requester"));
87  Q_ASSERT(requester);
88  requester->clear();
89 }
90 
91 void FilterActionWithUrl::argsFromString(const QString &argsStr)
92 {
93  mParameter = argsStr;
94 }
95 
96 QString FilterActionWithUrl::argsAsString() const
97 {
98  return mParameter;
99 }
100 
101 QString FilterActionWithUrl::displayString() const
102 {
103  return label() + QLatin1String(" \"") + argsAsString().toHtmlEscaped() + QLatin1String("\"");
104 }
void showText(const QPoint &pos, const QString &text, QWidget *w)
void clicked(bool checked)
QIcon fromTheme(const QString &name)
void textChanged(const QString &)
Abstract base class for mail filter actions.
Definition: filteraction.h:38
QString i18n(const char *text, const TYPE &arg...)
QUrl fromLocalFile(const QString &localFile)
QPoint pos()
Abstract base class for filter actions with a command line as parameter.
T findChild(const QString &name, Qt::FindChildOptions options) const const
QString label(StandardShortcut id)
QString name(StandardShortcut id)
void setContentsMargins(int left, int top, int right, int bottom)
The filter dialog.
virtual bool isEmpty() const
Determines whether this action is valid.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.