Libksieve

selectcomparatorcombobox.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 "selectcomparatorcombobox.h"
20 #include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
21 #include "autocreatescripts/autocreatescriptutil_p.h"
22 
23 using namespace KSieveUi;
24 SelectComparatorComboBox::SelectComparatorComboBox(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QWidget *parent)
25  : QComboBox(parent)
26 {
27  connect(this, QOverload<int>::of(&SelectComparatorComboBox::activated), this, &SelectComparatorComboBox::valueChanged);
28  initialize(sieveGraphicalModeWidget->sieveCapabilities());
29 }
30 
31 SelectComparatorComboBox::~SelectComparatorComboBox()
32 {
33 }
34 
35 void SelectComparatorComboBox::initialize(const QStringList &sieveCapabilities)
36 {
37  //Default in spec
38  addItem(QStringLiteral("i;octet"), QStringLiteral("comparator-i;octet"));
39  addItem(QStringLiteral("i;ascii-casemap"), QStringLiteral("comparator-i;ascii-casemap"));
40 
41  for (const QString &capability : sieveCapabilities) {
42  if (capability.startsWith(QLatin1String("comparator-"))) {
43  QString str(capability);
44  str.remove(QStringLiteral("comparator-"));
45  addItem(str, capability);
46  }
47  }
48 }
49 
50 QString SelectComparatorComboBox::require() const
51 {
52  if (currentIndex() < 2) {
53  return QString();
54  }
55  return itemData(currentIndex()).toString();
56 }
57 
58 QString SelectComparatorComboBox::code() const
59 {
60  return QStringLiteral(":comparator \"%1\"").arg(itemText(currentIndex()));
61 }
62 
63 void SelectComparatorComboBox::setCode(const QString &code, const QString &name, QString &error)
64 {
65  const QString completCode = QLatin1String("comparator-") + code;
66  const int index = findData(completCode);
67  if (index != -1) {
68  setCurrentIndex(index);
69  } else {
70  AutoCreateScriptUtil::comboboxItemNotFound(code, name, error);
71  setCurrentIndex(0);
72  }
73 }
KCRASH_EXPORT void initialize()
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 Mon Aug 10 2020 23:12:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.