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 
0007 #include "selectvacationcombobox.h"
0008 #include "autocreatescripts/autocreatescriptutil_p.h"
0009 
0010 #include <KLocalizedString>
0011 
0012 using namespace KSieveUi;
0013 SelectVacationComboBox::SelectVacationComboBox(QWidget *parent)
0014     : QComboBox(parent)
0015 {
0016     initialize();
0017     connect(this, &SelectVacationComboBox::activated, this, &SelectVacationComboBox::valueChanged);
0018 }
0019 
0020 SelectVacationComboBox::~SelectVacationComboBox() = default;
0021 
0022 void SelectVacationComboBox::initialize()
0023 {
0024     addItem(i18n("days"), QStringLiteral(":days"));
0025     addItem(i18n("seconds"), QStringLiteral(":seconds"));
0026 }
0027 
0028 QString SelectVacationComboBox::code() const
0029 {
0030     return itemData(currentIndex()).toString();
0031 }
0032 
0033 void SelectVacationComboBox::setCode(const QString &code, const QString &name, QString &error)
0034 {
0035     const int index = findData(code);
0036     if (index != -1) {
0037         setCurrentIndex(index);
0038     } else {
0039         AutoCreateScriptUtil::comboboxItemNotFound(code, name, error);
0040         setCurrentIndex(0);
0041     }
0042 }
0043 
0044 #include "moc_selectvacationcombobox.cpp"