File indexing completed on 2025-02-16 04:55:56

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "selectimportancecombobox.h"
0007 #include "autocreatescripts/autocreatescriptutil_p.h"
0008 
0009 #include <KLocalizedString>
0010 
0011 using namespace KSieveUi;
0012 
0013 SelectImportanceCombobox::SelectImportanceCombobox(QWidget *parent)
0014     : QComboBox(parent)
0015 {
0016     initialize();
0017     connect(this, &SelectImportanceCombobox::activated, this, &SelectImportanceCombobox::valueChanged);
0018 }
0019 
0020 SelectImportanceCombobox::~SelectImportanceCombobox() = default;
0021 
0022 void SelectImportanceCombobox::initialize()
0023 {
0024     addItem(QString(), QString());
0025     addItem(i18n("high importance"), QStringLiteral("1"));
0026     addItem(i18n("normal importance"), QStringLiteral("2"));
0027     addItem(i18n("low importance"), QStringLiteral("3"));
0028 }
0029 
0030 QString SelectImportanceCombobox::code() const
0031 {
0032     return itemData(currentIndex()).toString();
0033 }
0034 
0035 void SelectImportanceCombobox::setCode(const QString &code, const QString &name, QString &error)
0036 {
0037     const int index = findData(code);
0038     if (index != -1) {
0039         setCurrentIndex(index);
0040     } else {
0041         AutoCreateScriptUtil::comboboxItemNotFound(code, name, error);
0042         setCurrentIndex(0);
0043     }
0044 }
0045 
0046 #include "moc_selectimportancecombobox.cpp"