27
27
#include "sflphone_const.h"
28
#include "phonenumber.h"
32
Contact::PhoneNumbers::PhoneNumbers(Contact* parent) : QVector<PhoneNumber*>(),CategorizedCompositeNode(CategorizedCompositeNode::Type::NUMBER),
37
Contact::PhoneNumbers::PhoneNumbers(Contact* parent, const QVector<PhoneNumber*>& list)
38
: QVector<PhoneNumber*>(list),CategorizedCompositeNode(CategorizedCompositeNode::Type::NUMBER),m_pParent2(parent)
42
Contact* Contact::PhoneNumbers::contact() const
30
Contact::Contact():m_pPhoto(0)
48
Contact::Contact(QObject* parent):QObject(parent),m_pPhoto(nullptr),
49
m_Numbers(this),m_DisplayPhoto(nullptr),m_Active(true)
36
54
Contact::~Contact()
39
foreach (Contact::PhoneNumber* ph, m_Numbers) {
44
///May be used in extended classes
45
void Contact::initItem()
50
///May be used in extended classes
51
void Contact::initItemWidget()
56
59
///Get the phone number list
57
PhoneNumbers Contact::getPhoneNumbers() const
60
const Contact::PhoneNumbers& Contact::phoneNumbers() const
62
65
///Get the nickname
63
const QString& Contact::getNickName() const
66
const QString& Contact::nickName() const
68
71
///Get the firstname
69
const QString& Contact::getFirstName() const
72
const QString& Contact::firstName() const
71
74
return m_FirstName;
74
77
///Get the second/family name
75
const QString& Contact::getSecondName() const
78
const QString& Contact::secondName() const
77
80
return m_SecondName;
81
const QPixmap* Contact::getPhoto() const
84
const QPixmap* Contact::photo() const
86
89
///Get the formatted name
87
const QString& Contact::getFormattedName() const
90
const QString& Contact::formattedName() const
89
92
return m_FormattedName;
92
95
///Get the organisation
93
const QString& Contact::getOrganization() const
96
const QString& Contact::organization() const
95
98
return m_Organization;
98
101
///Get the preferred email
99
const QString& Contact::getPreferredEmail() const
102
const QString& Contact::preferredEmail() const
101
104
return m_PreferredEmail;
104
107
///Get the unique identifier (used for drag and drop)
105
const QString& Contact::getUid() const
108
const QString& Contact::uid() const
111
const QString& Contact::getGroup() const
114
const QString& Contact::group() const
116
const QString& Contact::getDepartment() const
119
const QString& Contact::department() const
118
121
return m_Department;
121
///Get the contact type
122
const QString& Contact::getType() const
127
///Set the phone number (type and number)
124
///Set the phone number (type and number)
128
125
void Contact::setPhoneNumbers(PhoneNumbers numbers)
127
const int oldCount(m_Numbers.size()),newCount(numbers.size());
128
foreach(PhoneNumber* n, m_Numbers)
129
disconnect(n,SIGNAL(presentChanged(bool)),this,SLOT(slotPresenceChanged()));
131
if (newCount < oldCount) //Rows need to be removed from models first
132
emit phoneNumberCountAboutToChange(newCount,oldCount);
133
foreach(PhoneNumber* n, m_Numbers)
134
connect(n,SIGNAL(presentChanged(bool)),this,SLOT(slotPresenceChanged()));
135
if (newCount > oldCount) //Need to be updated after the data to prevent invalid memory access
136
emit phoneNumberCountChanged(newCount,oldCount);
133
140
///Set the nickname
134
141
void Contact::setNickName(const QString& name)
139
147
///Set the first name
140
148
void Contact::setFirstName(const QString& name)
151
setObjectName(formattedName());
145
155
///Set the family name
146
156
void Contact::setFamilyName(const QString& name)
148
158
m_SecondName = name;
159
setObjectName(formattedName());
151
163
///Set the Photo/Avatar
152
164
void Contact::setPhoto(QPixmap* photo)
154
166
m_pPhoto = photo;
157
170
///Set the formatted name (display name)
158
171
void Contact::setFormattedName(const QString& name)
160
173
m_FormattedName = name;
163
177
///Set the organisation / business
164
178
void Contact::setOrganization(const QString& name)
166
180
m_Organization = name;
169
184
///Set the default email
170
185
void Contact::setPreferredEmail(const QString& name)
172
187
m_PreferredEmail = name;
176
192
void Contact::setUid(const QString& id)
182
199
void Contact::setGroup(const QString& name)
187
205
///Set department
188
206
void Contact::setDepartment(const QString& name)
190
208
m_Department = name;
193
///Turn the contact into QString-QString hash
194
QHash<QString,QVariant> Contact::toHash()
196
QHash<QString,QVariant> aContact;
197
//aContact[""] = PhoneNumbers getPhoneNumbers() const;
198
aContact[ "nickName" ] = getNickName();
199
aContact[ "firstName" ] = getFirstName();
200
aContact[ "secondName" ] = getSecondName();
201
aContact[ "formattedName" ] = getFormattedName();
202
aContact[ "organization" ] = getOrganization();
203
aContact[ "uid" ] = getUid();
204
aContact[ "preferredEmail" ] = getPreferredEmail();
205
//aContact[ "Photo" ] = QVariant(*getPhoto());
206
aContact[ "type" ] = getType();
207
aContact[ "group" ] = getGroup();
208
aContact[ "department" ] = getDepartment();
213
QString& Contact::PhoneNumber::getNumber() {
217
///Return the phone number type
218
QString& Contact::PhoneNumber::getType() {
212
///If the contact have been deleted or not yet fully created
213
void Contact::setActive( bool active)
216
emit statusChanged(m_Active);
220
///Return if one of the PhoneNumber is present
221
bool Contact::isPresent() const
223
foreach(const PhoneNumber* n,m_Numbers) {
230
///Return if one of the PhoneNumber is tracked
231
bool Contact::isTracked() const
233
foreach(const PhoneNumber* n,m_Numbers) {
240
///Have this contact been deleted or doesn't exist yet
241
bool Contact::isActive() const
246
///Return if one of the PhoneNumber support presence
247
bool Contact::supportPresence() const
249
foreach(const PhoneNumber* n,m_Numbers) {
250
if (n->supportPresence())
257
QObject* Contact::PhoneNumbers::getSelf() const {
261
time_t Contact::PhoneNumbers::lastUsedTimeStamp() const
264
for (int i=0;i<size();i++) {
265
if (at(i)->lastUsed() > t)
266
t = at(i)->lastUsed();
271
///Callback when one of the phone number presence change
272
void Contact::slotPresenceChanged()