Libksieve

selectaddresspartcombobox.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 "selectaddresspartcombobox.h"
7#include "autocreatescripts/autocreatescriptutil_p.h"
8#include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
9
10#include <KLocalizedString>
11
12using namespace KSieveUi;
13
14SelectAddressPartComboBox::SelectAddressPartComboBox(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QWidget *parent)
15 : QComboBox(parent)
16{
17 mHasSubaddressCapability = sieveGraphicalModeWidget->sieveCapabilities().contains(QLatin1StringView("subaddress"));
18 initialize();
19 connect(this, &SelectAddressPartComboBox::activated, this, &SelectAddressPartComboBox::valueChanged);
20}
21
22SelectAddressPartComboBox::~SelectAddressPartComboBox() = default;
23
24void SelectAddressPartComboBox::initialize()
25{
26 addItem(i18n("all"), QStringLiteral(":all"));
27 addItem(i18n("localpart"), QStringLiteral(":localpart"));
28 addItem(i18n("domain"), QStringLiteral(":domain"));
29 if (mHasSubaddressCapability) {
30 addItem(i18n("user"), QStringLiteral(":user"));
31 addItem(i18n("detail"), QStringLiteral(":detail"));
32 }
33}
34
35QString SelectAddressPartComboBox::code() const
36{
37 return itemData(currentIndex()).toString();
38}
39
40QStringList SelectAddressPartComboBox::extraRequire() const
41{
42 QStringList lst;
43 if (mHasSubaddressCapability) {
44 lst << QStringLiteral("subaddress");
45 }
46 return lst;
47}
48
49void SelectAddressPartComboBox::setCode(const QString &code, const QString &name, QString &error)
50{
51 const int index = findData(code);
52 if (index != -1) {
53 setCurrentIndex(index);
54 } else {
55 AutoCreateScriptUtil::comboboxItemNotFound(code, name, error);
57 }
58}
59
60#include "moc_selectaddresspartcombobox.cpp"
QString i18n(const char *text, const TYPE &arg...)
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
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 Sat Dec 21 2024 16:57:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.