Libksieve

selectaddresspartcombobox.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
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 
12 using namespace KSieveUi;
13 
14 SelectAddressPartComboBox::SelectAddressPartComboBox(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QWidget *parent)
15  : QComboBox(parent)
16 {
17  mHasSubaddressCapability = sieveGraphicalModeWidget->sieveCapabilities().contains(QLatin1String("subaddress"));
18  initialize();
19  connect(this, QOverload<int>::of(&SelectAddressPartComboBox::activated), this, &SelectAddressPartComboBox::valueChanged);
20 }
21 
22 SelectAddressPartComboBox::~SelectAddressPartComboBox()
23 {
24 }
25 
26 void SelectAddressPartComboBox::initialize()
27 {
28  addItem(i18n("all"), QStringLiteral(":all"));
29  addItem(i18n("localpart"), QStringLiteral(":localpart"));
30  addItem(i18n("domain"), QStringLiteral(":domain"));
31  if (mHasSubaddressCapability) {
32  addItem(i18n("user"), QStringLiteral(":user"));
33  addItem(i18n("detail"), QStringLiteral(":detail"));
34  }
35 }
36 
37 QString SelectAddressPartComboBox::code() const
38 {
39  return itemData(currentIndex()).toString();
40 }
41 
42 QStringList SelectAddressPartComboBox::extraRequire() const
43 {
44  QStringList lst;
45  if (mHasSubaddressCapability) {
46  lst << QStringLiteral("subaddress");
47  }
48  return lst;
49 }
50 
51 void SelectAddressPartComboBox::setCode(const QString &code, const QString &name, QString &error)
52 {
53  const int index = findData(code);
54  if (index != -1) {
55  setCurrentIndex(index);
56  } else {
57  AutoCreateScriptUtil::comboboxItemNotFound(code, name, error);
58  setCurrentIndex(0);
59  }
60 }
KCRASH_EXPORT void initialize()
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 11 2021 23:09:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.