File indexing completed on 2024-12-29 04:54:41
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "selectmimecombobox.h" 0007 #include "autocreatescripts/autocreatescriptutil_p.h" 0008 0009 #include <KLocalizedString> 0010 0011 using namespace KSieveUi; 0012 0013 SelectMimeComboBox::SelectMimeComboBox(QWidget *parent) 0014 : QComboBox(parent) 0015 { 0016 initialize(); 0017 connect(this, &SelectMimeComboBox::activated, this, &SelectMimeComboBox::valueChanged); 0018 } 0019 0020 SelectMimeComboBox::~SelectMimeComboBox() = default; 0021 0022 void SelectMimeComboBox::initialize() 0023 { 0024 addItem(i18n("Type"), QStringLiteral(":type")); 0025 addItem(i18n("Subtype"), QStringLiteral(":subtype")); 0026 addItem(i18n("Anychild"), QStringLiteral(":anychild")); 0027 addItem(i18n("Parameters"), QStringLiteral(":param")); 0028 } 0029 0030 QString SelectMimeComboBox::code() const 0031 { 0032 return QStringLiteral(":mime \"%1\"").arg(itemData(currentIndex()).toString()); 0033 } 0034 0035 QString SelectMimeComboBox::require() const 0036 { 0037 return QStringLiteral("mime"); 0038 } 0039 0040 void SelectMimeComboBox::setCode(const QString &code, const QString &name, QString &error) 0041 { 0042 const int index = findData(code); 0043 if (index != -1) { 0044 setCurrentIndex(index); 0045 } else { 0046 AutoCreateScriptUtil::comboboxItemNotFound(code, name, error); 0047 setCurrentIndex(0); 0048 } 0049 } 0050 0051 #include "moc_selectmimecombobox.cpp"