Libksieve

selectcomparatorcombobox.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
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
10using namespace KSieveUi;
11SelectComparatorComboBox::SelectComparatorComboBox(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QWidget *parent)
12 : QComboBox(parent)
13{
14 connect(this, &SelectComparatorComboBox::activated, this, &SelectComparatorComboBox::valueChanged);
15 initialize(sieveGraphicalModeWidget->sieveCapabilities());
16}
17
18SelectComparatorComboBox::~SelectComparatorComboBox() = default;
19
20void SelectComparatorComboBox::initialize(const QStringList &sieveCapabilities)
21{
22 // Default in spec
23 addItem(QStringLiteral("i;octet"), QStringLiteral("comparator-i;octet"));
24 addItem(QStringLiteral("i;ascii-casemap"), QStringLiteral("comparator-i;ascii-casemap"));
25
26 for (const QString &capability : sieveCapabilities) {
27 if (capability.startsWith(QLatin1StringView("comparator-"))) {
28 QString str(capability);
29 str.remove(QStringLiteral("comparator-"));
30 addItem(str, capability);
31 }
32 }
33}
34
35QString SelectComparatorComboBox::require() const
36{
37 if (currentIndex() < 2) {
38 return {};
39 }
40 return itemData(currentIndex()).toString();
41}
42
43QString SelectComparatorComboBox::code() const
44{
45 return QStringLiteral(":comparator \"%1\"").arg(itemText(currentIndex()));
46}
47
48void SelectComparatorComboBox::setCode(const QString &code, const QString &name, QString &error)
49{
50 const QString completCode = QLatin1StringView("comparator-") + code;
51 const int index = findData(completCode);
52 if (index != -1) {
53 setCurrentIndex(index);
54 } else {
55 AutoCreateScriptUtil::comboboxItemNotFound(code, name, error);
57 }
58}
59
60#include "moc_selectcomparatorcombobox.cpp"
KCRASH_EXPORT void initialize()
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
QVariant itemData(int index, int role) const const
QString itemText(int index) const const
QString arg(Args &&... args) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:09:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.