-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcont.cpp
More file actions
390 lines (341 loc) · 9.14 KB
/
Copy pathcont.cpp
File metadata and controls
390 lines (341 loc) · 9.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/* $Id: cont.cpp */
/*
* Copyright (C) 2012-2014 Dmytro Mishchenko <arkadiamail@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "cont.h"
#include "cdr.h"
#include "account.h"
#include <QStringList>
Cont::Cont() :
firstName(""),
lastName(""),
company(""),
phoneNumber(""),
#ifdef BB10_BLD
phoneNumType(AttributeSubKind::Other),
phones(),
#endif
id(0),
photoFilepath(""),
platformDisplayName(""),
platformCompanyName(""),
action(Dial),
directCallUri(""),
pjSipAccId(-1),
displayFormat("FLC")
{
}
// Build name form First Last name + company on another line
QString Cont::getDisplayName() const
{
QStringList displayName;
QStringList allNames;
bool fnDone = false;
bool lnDone = false;
for(int i = 0; i < displayFormat.length(); ++i) {
if (displayFormat[i] == QChar('F')) {
if (!firstName.isEmpty()) {
displayName << firstName;
}
fnDone = true;
}
if (displayFormat[i] == QChar('L')) {
if (!lastName.isEmpty()) {
displayName << lastName;
}
lnDone = true;
}
if (fnDone && lnDone) {
if (displayName.isEmpty() && !platformDisplayName.isEmpty()) {
displayName << platformDisplayName;
}
if (!displayName.isEmpty()) {
allNames << displayName.join(" ");
}
fnDone = lnDone = false;
}
if (displayFormat[i] == QChar('C')) {
if (!company.isEmpty()) {
allNames << company;
}
else if (!platformCompanyName.isEmpty()) {
allNames << platformCompanyName;
}
}
}
return allNames.join("\n");
}
QString Cont::getDisplayPhone() const
{
// Convert number to display format
Cdr cdr;
cdr.setNumber(phoneNumber);
QString number(cdr.getDisplayNumber());
return number;
}
QString Cont::getFirstName() const
{
return firstName;
}
QString Cont::getLastName() const
{
return lastName;
}
QString Cont::getCompany() const
{
return company;
}
QString Cont::getPhoneNumber() const
{
return phoneNumber;
}
QString Cont::getSecStagePhoneNumber() const
{
return secStagePhoneNumber;
}
int Cont::getId() const
{
return id;
}
QString Cont::getPhotoFilepath() const
{
return photoFilepath;
}
Cont::ContAction Cont::getAction() const
{
return action;
}
QString Cont::getDirectCallUri() const
{
return directCallUri;
}
int Cont::getPjSipAccId() const
{
return pjSipAccId;
}
void Cont::setAction(const ContAction act)
{
action = act;
}
void Cont::setDisplayFormat(const QString &dispFormat)
{
displayFormat = dispFormat;
}
#ifdef BB10_BLD
QString Cont::getPlatformDisplayName() const
{
return platformDisplayName;
}
QString Cont::getPlatformCompanyName() const
{
return platformCompanyName;
}
QList <ContactAttribute> Cont::getPhones() const
{
return phones;
}
#endif
void Cont::setFirstName(const QString &fn)
{
firstName = fn;
}
void Cont::setLastName(const QString &ln)
{
lastName = ln;
}
void Cont::setCompany(const QString &comp)
{
company = comp;
}
void Cont::setPhoneNumber(const QString &pn)
{
phoneNumber = pn;
}
void Cont::setSecStagePhoneNumber(const QString &pn)
{
secStagePhoneNumber = pn;
}
void Cont::setPhoneNumberAt(const int index, const QString &pn)
{
#ifdef BB10_BLD
ContactAttribute attr = phones.at(index);
AttributeSubKind::Type attrSubKind = attr.subKind();
ContactAttributeBuilder attrBuilder = attr.edit();
attrBuilder.setSubKind(attrSubKind);
attrBuilder.setValue(pn);
#else
Q_UNUSED(index);
Q_UNUSED(pn);
#endif
}
void Cont::setId(const int i)
{
id = i;
}
void Cont::setPhotoFilepath(const QString &path)
{
photoFilepath = path;
}
void Cont::setPjSipAccId(int accId)
{
pjSipAccId = accId;
}
#ifdef BB10_BLD
void Cont::setPlatformDisplayName(const QString &name)
{
platformDisplayName = name;
}
void Cont::setPlatformCompanyName(const QString &name)
{
platformCompanyName = name;
}
void Cont::setPhones(const QList<ContactAttribute> &ph)
{
phones.clear();
for (int i = 0; i < ph.size(); ++i) {
phones.append(ph.at(i));
}
}
AttributeSubKind::Type Cont::getPhoneNumType() const
{
return phoneNumType;
}
void Cont::setPhoneNumberType(AttributeSubKind::Type phType)
{
phoneNumType = phType;
}
// Convert Contact phone attribute to plain text
QString phoneType(const AttributeSubKind::Type ca)
{
QString phType;
switch (ca) {
case AttributeSubKind::Home:
phType = QObject::tr("Home");
break;
case AttributeSubKind::Work:
phType = QObject::tr("Work");
break;
case AttributeSubKind::PhoneMobile:
phType = QObject::tr("Mobile");
break;
case AttributeSubKind::FaxDirect:
phType = QObject::tr("Fax direct");
break;
case AttributeSubKind::Other:
default:
phType = QObject::tr("Other");
}
return phType;
}
#endif
bool Cont::match(const QString &searchString) const
{
QRegExp rxSearchStr(searchString, Qt::CaseInsensitive);
if (rxSearchStr.indexIn(firstName) != -1) {
return true;
}
if (rxSearchStr.indexIn(lastName) != -1) {
return true;
}
if (rxSearchStr.indexIn(company) != -1) {
return true;
}
if (rxSearchStr.indexIn(phoneNumber) != -1) {
return true;
}
return false;
}
QString Cont::buildDirectCallUri(const Account &ac, bool translateNumber)
{
directCallUri = phoneNumber;
if (directCallUri.isEmpty()) {
return directCallUri;
}
if (translateNumber) {
// Replace leading plus according Account settings
QRegExp rxPlus("^\\+");
directCallUri.replace(rxPlus, ac.contactPlusReplace);
// Prepend dial prefix
directCallUri.prepend(ac.contactPrefix);
}
// Remove all extra chars: ()-space
QRegExp rx("[\\(\\)\\s\\-]");
directCallUri.replace(rx, QString(""));
// Remove dots in number, not in domain names
QRegExp rxDotsAndNumbers("^[\\d\\.]+$");
if (directCallUri.contains(rxDotsAndNumbers)) {
QRegExp rxDots("[\\.]");
directCallUri.replace(rxDots, QString(""));
}
directCallUri.remove(QRegExp("^sip:",Qt::CaseInsensitive));
directCallUri = "sip:" + directCallUri;
if (!directCallUri.contains("@")) {
directCallUri = directCallUri + "@" + ac.domain;
}
if (!directCallUri.contains(";transport=", Qt::CaseInsensitive)) {
if ((ac.transport == "UDP") || (ac.transport == "UDP6")) {
directCallUri.append(";transport=udp");
}
else if ((ac.transport == "TCP") || (ac.transport == "TCP6")) {
directCallUri.append(";transport=tcp");
}
else if ((ac.transport == "TLS")) {
directCallUri.append(";transport=tls");
}
}
return directCallUri;
}
void Cont::copyPlatformProperties()
{
#ifdef BB10_BLD
if (firstName.isEmpty() && lastName.isEmpty()) {
firstName = platformDisplayName;
}
if (company.isEmpty()) {
company = platformCompanyName;
}
#endif
}
QDataStream & operator<<(QDataStream &out, const Cont &c)
{
return out << c.id << c.firstName << c.lastName << c.company << c.phoneNumber;
}
QDataStream & operator>>(QDataStream &in, Cont &c)
{
return in >> c.id >> c.firstName >> c.lastName >> c.company >> c.phoneNumber;
}
QDebug operator<<(QDebug dbg, const Cont &c)
{
dbg.maybeSpace() << "Id:" << c.id << "\n";
dbg.maybeSpace() << "FirstName:" << c.firstName << "\n";
dbg.maybeSpace() << "LastName:" << c.lastName << "\n";
dbg.maybeSpace() << "Company:" << c.company << "\n";
dbg.maybeSpace() << "PhoneNumber:" << c.phoneNumber << "\n";
dbg.maybeSpace() << "SecStagePhoneNumber:" << c.secStagePhoneNumber << "\n";
#ifdef BB10_BLD
dbg.maybeSpace() << "PhoneNumberType:" << phoneType(c.phoneNumType) << "\n";
for (int i = 0; i < c.phones.size(); ++i) {
dbg.maybeSpace() << "AttrList PhoneNumber:" << c.phones.at(i).value() << "\n";
dbg.maybeSpace() << "AttrList PhoneType:" << phoneType(c.phones.at(i).subKind()) << "\n";
}
dbg.maybeSpace() << "PhotoFilepath:" << c.photoFilepath << "\n";
dbg.maybeSpace() << "PlatformDisplayName:" << c.platformDisplayName << "\n";
dbg.maybeSpace() << "PlatformCompanyName:" << c.platformCompanyName << "\n";
#endif
dbg.maybeSpace() << "ContAction:" << c.action << "\n";
return dbg.maybeSpace();
}