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, sales@eyeos.com
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
15using namespace Akonadi;
16
18 : Akonadi::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
53
54void PhoneComboBoxType::resetToDefault()
55{
57}
58
59void 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
75void 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
85void 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.count() - 1, mType);
93 }
94 }
95 } else {
96 setType(KContacts::PhoneNumber::Type(mTypeList.at(mLastSelected)));
97 }
98 delete dlg;
99 update();
100}
101
102#include "moc_phonecomboboxtype.cpp"
PhoneComboBoxType(QWidget *parent=nullptr)
Creates a phone type combo.
void setType(KContacts::PhoneNumber::Type type)
Sets the phone number type that shall be selected.
~PhoneComboBoxType() override
Destroys the phone type combo.
KContacts::PhoneNumber::Type type() const
Returns the selected phone number type.
A dialog for editing phone number types.
QString typeLabel() const
static TypeList typeList()
QFlags< TypeFlag > Type
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
void activated(int index)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
void clear()
void setCurrentIndex(int index)
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
bool contains(const AT &value) const const
qsizetype count() const const
qsizetype indexOf(const AT &value, qsizetype from) const const
iterator insert(const_iterator before, parameter_type value)
void reserve(qsizetype size)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:20 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.