Akonadi Contacts

phonecomboboxtype.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
5  Copyright (C) 2016-2020 Laurent Montel <montel.org>
6 
7  This library is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Library General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but WITHOUT
13  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to the
19  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  02110-1301, USA.
21 */
22 
23 #include "phonecomboboxtype.h"
24 #include "phonetypedialog.h"
25 #include <KLocalizedString>
26 #include <QPointer>
27 
28 using namespace ContactEditor;
29 
31  : ContactEditor::ContactEditorComboBox(parent)
32  , mType(KContacts::PhoneNumber::Home)
33  , mLastSelected(0)
34 {
35  const int nbMax = KContacts::PhoneNumber::typeList().count();
36  mTypeList.reserve(nbMax + 1);
37  for (int i = 0; i < nbMax; ++i) {
39  if (typeflag != KContacts::PhoneNumber::Pref) {
40  mTypeList.append(typeflag);
41  }
42  }
43 
44  mTypeList.append(-1); // Others...
45 
46  update();
47 
48  connect(this, QOverload<int>::of(&PhoneComboBoxType::activated), this, &PhoneComboBoxType::selected);
49 }
50 
52 {
53 }
54 
56 {
57  if (static_cast<int>(type) != 0) {
58  if (!mTypeList.contains(type)) {
59  mTypeList.insert(mTypeList.at(mTypeList.count() - 1), type);
60  }
61  }
62  mType = type;
63  update();
64 }
65 
67 {
68  return mType;
69 }
70 
71 void PhoneComboBoxType::resetToDefault()
72 {
73  setCurrentIndex(0);
74 }
75 
76 void PhoneComboBoxType::update()
77 {
78  clear();
79 
80  const int typeListCount(mTypeList.count());
81  for (int i = 0; i < typeListCount; ++i) {
82  if (mTypeList.at(i) == -1) { // "Other..." entry
83  addItem(i18nc("@item:inlistbox Category of contact info field", "Other..."));
84  } else {
86  }
87  }
88 
89  setCurrentIndex(mLastSelected = mTypeList.indexOf(mType));
90 }
91 
92 void PhoneComboBoxType::selected(int pos)
93 {
94  if (mTypeList.at(pos) == -1) {
95  otherSelected();
96  } else {
97  mType = KContacts::PhoneNumber::Type(mTypeList.at(pos));
98  mLastSelected = pos;
99  }
100 }
101 
102 void PhoneComboBoxType::otherSelected()
103 {
105  if (dlg->exec()) {
106  mType = dlg->type();
107  if (!mTypeList.contains(mType)) {
108  if (static_cast<int>(mType) != 0) {
109  mTypeList.insert(mTypeList.at(mTypeList.count() - 1), mType);
110  }
111  }
112  } else {
113  setType(KContacts::PhoneNumber::Type(mTypeList.at(mLastSelected)));
114  }
115  delete dlg;
116  update();
117 }
A dialog for editing phone number types.
QFlags< TypeFlag > Type
void reserve(int alloc)
const T & at(int i) const const
void clear()
static TypeList typeList()
int indexOf(const T &value, int from) const const
void addItem(const QString &text, const QVariant &userData)
int count(const T &value) const const
void append(const T &value)
void setType(KContacts::PhoneNumber::Type type)
Sets the phone number type that shall be selected.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KContacts::PhoneNumber::Type type() const
Returns the selected phone number type.
void activated(int index)
QPoint pos() const const
bool contains(const T &value) const const
QString typeLabel() const
const T & at(int i) const const
~PhoneComboBoxType()
Destroys the phone type combo.
void insert(int i, const T &value)
int count(const T &value) const const
void setCurrentIndex(int index)
PhoneComboBoxType(QWidget *parent=nullptr)
Creates a phone type combo.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 3 2020 23:07:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.