Libksieve

selectrelationalmatchtype.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 #include "selectrelationalmatchtype.h"
20 #include "autocreatescripts/autocreatescriptutil_p.h"
21 
22 #include <QComboBox>
23 
24 #include <KLocalizedString>
25 #include <QHBoxLayout>
26 
27 using namespace KSieveUi;
28 
29 SelectRelationalMatchType::SelectRelationalMatchType(QWidget *parent)
30  : QWidget(parent)
31 {
32  initialize();
33 }
34 
35 SelectRelationalMatchType::~SelectRelationalMatchType()
36 {
37 }
38 
39 void SelectRelationalMatchType::setCode(const QString &type, const QString &comparatorStr, const QString &name, QString &error)
40 {
41  int index = mType->findData(type);
42  if (index != -1) {
43  mType->setCurrentIndex(index);
44  } else {
45  AutoCreateScriptUtil::comboboxItemNotFound(type, name, error);
46  mType->setCurrentIndex(0);
47  }
48 
49  index = mMatch->findData(comparatorStr);
50  if (index != -1) {
51  mMatch->setCurrentIndex(index);
52  } else {
53  AutoCreateScriptUtil::comboboxItemNotFound(comparatorStr, name, error);
54  mMatch->setCurrentIndex(0);
55  }
56 }
57 
58 QString SelectRelationalMatchType::code() const
59 {
60  return QStringLiteral("%1 \"%2\"").arg(mType->itemData(mType->currentIndex()).toString(), mMatch->itemData(mMatch->currentIndex()).toString());
61 }
62 
63 void SelectRelationalMatchType::initialize()
64 {
65  QHBoxLayout *lay = new QHBoxLayout(this);
66  lay->setContentsMargins(0, 0, 0, 0);
67 
68  mType = new QComboBox(this);
69  mType->addItem(i18n("Value"), QStringLiteral(":value"));
70  mType->addItem(i18n("Count"), QStringLiteral(":count"));
71  lay->addWidget(mType);
72  connect(mType, QOverload<int>::of(&QComboBox::activated), this, &SelectRelationalMatchType::valueChanged);
73 
74  mMatch = new QComboBox(this);
75  mMatch->addItem(i18n("Greater than"), QStringLiteral("gt"));
76  mMatch->addItem(i18n("Greater than or equal"), QStringLiteral("ge"));
77  mMatch->addItem(i18n("Less than"), QStringLiteral("lt"));
78  mMatch->addItem(i18n("Less than or equal"), QStringLiteral("le"));
79  mMatch->addItem(i18n("Equal to"), QStringLiteral("eq"));
80  mMatch->addItem(i18n("Not equal to"), QStringLiteral("ne"));
81  connect(mMatch, QOverload<int>::of(&QComboBox::activated), this, &SelectRelationalMatchType::valueChanged);
82  lay->addWidget(mMatch);
83 }
void setContentsMargins(int left, int top, int right, int bottom)
KCRASH_EXPORT void initialize()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void activated(int index)
QString i18n(const char *text, const TYPE &arg...)
char * toString(const T &value)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.