Libksieve

selectcomparatorcombobox.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "selectcomparatorcombobox.h"
7 #include "autocreatescripts/autocreatescriptutil_p.h"
8 #include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
9 
10 using namespace KSieveUi;
11 SelectComparatorComboBox::SelectComparatorComboBox(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QWidget *parent)
12  : QComboBox(parent)
13 {
14  connect(this, QOverload<int>::of(&SelectComparatorComboBox::activated), this, &SelectComparatorComboBox::valueChanged);
15  initialize(sieveGraphicalModeWidget->sieveCapabilities());
16 }
17 
18 SelectComparatorComboBox::~SelectComparatorComboBox()
19 {
20 }
21 
22 void SelectComparatorComboBox::initialize(const QStringList &sieveCapabilities)
23 {
24  // Default in spec
25  addItem(QStringLiteral("i;octet"), QStringLiteral("comparator-i;octet"));
26  addItem(QStringLiteral("i;ascii-casemap"), QStringLiteral("comparator-i;ascii-casemap"));
27 
28  for (const QString &capability : sieveCapabilities) {
29  if (capability.startsWith(QLatin1String("comparator-"))) {
30  QString str(capability);
31  str.remove(QStringLiteral("comparator-"));
32  addItem(str, capability);
33  }
34  }
35 }
36 
37 QString SelectComparatorComboBox::require() const
38 {
39  if (currentIndex() < 2) {
40  return QString();
41  }
42  return itemData(currentIndex()).toString();
43 }
44 
45 QString SelectComparatorComboBox::code() const
46 {
47  return QStringLiteral(":comparator \"%1\"").arg(itemText(currentIndex()));
48 }
49 
50 void SelectComparatorComboBox::setCode(const QString &code, const QString &name, QString &error)
51 {
52  const QString completCode = QLatin1String("comparator-") + code;
53  const int index = findData(completCode);
54  if (index != -1) {
55  setCurrentIndex(index);
56  } else {
57  AutoCreateScriptUtil::comboboxItemNotFound(code, name, error);
58  setCurrentIndex(0);
59  }
60 }
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-2021 The KDE developers.
Generated on Sat Apr 17 2021 23:09:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.