File indexing completed on 2024-12-29 04:54:40
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "selectcomparatorcombobox.h" 0007 #include "autocreatescripts/autocreatescriptutil_p.h" 0008 #include "autocreatescripts/sieveeditorgraphicalmodewidget.h" 0009 0010 using namespace KSieveUi; 0011 SelectComparatorComboBox::SelectComparatorComboBox(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QWidget *parent) 0012 : QComboBox(parent) 0013 { 0014 connect(this, &SelectComparatorComboBox::activated, this, &SelectComparatorComboBox::valueChanged); 0015 initialize(sieveGraphicalModeWidget->sieveCapabilities()); 0016 } 0017 0018 SelectComparatorComboBox::~SelectComparatorComboBox() = default; 0019 0020 void SelectComparatorComboBox::initialize(const QStringList &sieveCapabilities) 0021 { 0022 // Default in spec 0023 addItem(QStringLiteral("i;octet"), QStringLiteral("comparator-i;octet")); 0024 addItem(QStringLiteral("i;ascii-casemap"), QStringLiteral("comparator-i;ascii-casemap")); 0025 0026 for (const QString &capability : sieveCapabilities) { 0027 if (capability.startsWith(QLatin1StringView("comparator-"))) { 0028 QString str(capability); 0029 str.remove(QStringLiteral("comparator-")); 0030 addItem(str, capability); 0031 } 0032 } 0033 } 0034 0035 QString SelectComparatorComboBox::require() const 0036 { 0037 if (currentIndex() < 2) { 0038 return {}; 0039 } 0040 return itemData(currentIndex()).toString(); 0041 } 0042 0043 QString SelectComparatorComboBox::code() const 0044 { 0045 return QStringLiteral(":comparator \"%1\"").arg(itemText(currentIndex())); 0046 } 0047 0048 void SelectComparatorComboBox::setCode(const QString &code, const QString &name, QString &error) 0049 { 0050 const QString completCode = QLatin1StringView("comparator-") + code; 0051 const int index = findData(completCode); 0052 if (index != -1) { 0053 setCurrentIndex(index); 0054 } else { 0055 AutoCreateScriptUtil::comboboxItemNotFound(code, name, error); 0056 setCurrentIndex(0); 0057 } 0058 } 0059 0060 #include "moc_selectcomparatorcombobox.cpp"