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 "selectaddresspartcombobox.h"
0007 #include "autocreatescripts/autocreatescriptutil_p.h"
0008 #include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
0009 
0010 #include <KLocalizedString>
0011 
0012 using namespace KSieveUi;
0013 
0014 SelectAddressPartComboBox::SelectAddressPartComboBox(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QWidget *parent)
0015     : QComboBox(parent)
0016 {
0017     mHasSubaddressCapability = sieveGraphicalModeWidget->sieveCapabilities().contains(QLatin1StringView("subaddress"));
0018     initialize();
0019     connect(this, &SelectAddressPartComboBox::activated, this, &SelectAddressPartComboBox::valueChanged);
0020 }
0021 
0022 SelectAddressPartComboBox::~SelectAddressPartComboBox() = default;
0023 
0024 void SelectAddressPartComboBox::initialize()
0025 {
0026     addItem(i18n("all"), QStringLiteral(":all"));
0027     addItem(i18n("localpart"), QStringLiteral(":localpart"));
0028     addItem(i18n("domain"), QStringLiteral(":domain"));
0029     if (mHasSubaddressCapability) {
0030         addItem(i18n("user"), QStringLiteral(":user"));
0031         addItem(i18n("detail"), QStringLiteral(":detail"));
0032     }
0033 }
0034 
0035 QString SelectAddressPartComboBox::code() const
0036 {
0037     return itemData(currentIndex()).toString();
0038 }
0039 
0040 QStringList SelectAddressPartComboBox::extraRequire() const
0041 {
0042     QStringList lst;
0043     if (mHasSubaddressCapability) {
0044         lst << QStringLiteral("subaddress");
0045     }
0046     return lst;
0047 }
0048 
0049 void SelectAddressPartComboBox::setCode(const QString &code, const QString &name, QString &error)
0050 {
0051     const int index = findData(code);
0052     if (index != -1) {
0053         setCurrentIndex(index);
0054     } else {
0055         AutoCreateScriptUtil::comboboxItemNotFound(code, name, error);
0056         setCurrentIndex(0);
0057     }
0058 }
0059 
0060 #include "moc_selectaddresspartcombobox.cpp"