Akonadi Contacts

phonecomboboxtype.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2016 eyeOS S.L.U., a Telefonica company, [email protected]
5  SPDX-FileCopyrightText: 2016-2020 Laurent Montel <montel.org>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "phonecomboboxtype.h"
11 #include "phonetypedialog.h"
12 #include <KLocalizedString>
13 #include <QPointer>
14 
15 using namespace ContactEditor;
16 
18  : ContactEditor::ContactEditorComboBox(parent)
19 {
20  const int nbMax = KContacts::PhoneNumber::typeList().count();
21  mTypeList.reserve(nbMax + 1);
22  for (int i = 0; i < nbMax; ++i) {
24  if (typeflag != KContacts::PhoneNumber::Pref) {
25  mTypeList.append(typeflag);
26  }
27  }
28 
29  mTypeList.append(-1); // Others...
30 
31  update();
32 
33  connect(this, &PhoneComboBoxType::activated, this, &PhoneComboBoxType::selected);
34 }
35 
37 
39 {
40  if (static_cast<int>(type) != 0) {
41  if (!mTypeList.contains(type)) {
42  mTypeList.insert(mTypeList.at(mTypeList.count() - 1), type);
43  }
44  }
45  mType = type;
46  update();
47 }
48 
50 {
51  return mType;
52 }
53 
54 void PhoneComboBoxType::resetToDefault()
55 {
56  setCurrentIndex(0);
57 }
58 
59 void PhoneComboBoxType::update()
60 {
61  clear();
62 
63  const int typeListCount(mTypeList.count());
64  for (int i = 0; i < typeListCount; ++i) {
65  if (mTypeList.at(i) == -1) { // "Other..." entry
66  addItem(i18nc("@item:inlistbox Category of contact info field", "Other..."));
67  } else {
69  }
70  }
71 
72  setCurrentIndex(mLastSelected = mTypeList.indexOf(mType));
73 }
74 
75 void PhoneComboBoxType::selected(int pos)
76 {
77  if (mTypeList.at(pos) == -1) {
78  otherSelected();
79  } else {
80  mType = KContacts::PhoneNumber::Type(mTypeList.at(pos));
81  mLastSelected = pos;
82  }
83 }
84 
85 void PhoneComboBoxType::otherSelected()
86 {
88  if (dlg->exec()) {
89  mType = dlg->type();
90  if (!mTypeList.contains(mType)) {
91  if (static_cast<int>(mType) != 0) {
92  mTypeList.insert(mTypeList.at(mTypeList.count() - 1), mType);
93  }
94  }
95  } else {
96  setType(KContacts::PhoneNumber::Type(mTypeList.at(mLastSelected)));
97  }
98  delete dlg;
99  update();
100 }
void append(const T &value)
static TypeList typeList()
A dialog for editing phone number types.
int count(const T &value) const const
void setCurrentIndex(int index)
bool contains(const T &value) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
PhoneComboBoxType(QWidget *parent=nullptr)
Creates a phone type combo.
void reserve(int alloc)
KContacts::PhoneNumber::Type type() const
Returns the selected phone number type.
QString typeLabel() const
int indexOf(const T &value, int from) const const
const T & at(int i) const const
QFlags< TypeFlag > Type
const T & at(int i) const const
void insert(int i, const T &value)
void clear()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
int count(const T &value) const const
void addItem(const QString &text, const QVariant &userData)
void activated(int index)
~PhoneComboBoxType() override
Destroys the phone type combo.
void setType(KContacts::PhoneNumber::Type type)
Sets the phone number type that shall be selected.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.