~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to kde/src/lib/contact.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
 
 *   Copyright (C) 2009-2013 by Savoir-Faire Linux                          *
 
2
 *   Copyright (C) 2009-2014 by Savoir-Faire Linux                          *
3
3
 *   Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>          *
4
4
 *            Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
5
5
 *                                                                          *
25
25
 
26
26
//SFLPhone library
27
27
#include "sflphone_const.h"
 
28
#include "phonenumber.h"
 
29
 
 
30
 
 
31
 
 
32
Contact::PhoneNumbers::PhoneNumbers(Contact* parent) : QVector<PhoneNumber*>(),CategorizedCompositeNode(CategorizedCompositeNode::Type::NUMBER),
 
33
    m_pParent2(parent)
 
34
{
 
35
}
 
36
 
 
37
Contact::PhoneNumbers::PhoneNumbers(Contact* parent, const QVector<PhoneNumber*>& list)
 
38
: QVector<PhoneNumber*>(list),CategorizedCompositeNode(CategorizedCompositeNode::Type::NUMBER),m_pParent2(parent)
 
39
{
 
40
}
 
41
 
 
42
Contact* Contact::PhoneNumbers::contact() const
 
43
{
 
44
   return m_pParent2;
 
45
}
28
46
 
29
47
///Constructor
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)
31
50
{
32
 
   initItem();
33
51
}
34
52
 
35
53
///Destructor
36
54
Contact::~Contact()
37
55
{
38
56
   delete m_pPhoto;
39
 
   foreach (Contact::PhoneNumber* ph, m_Numbers) {
40
 
      delete ph;
41
 
   }
42
 
}
43
 
 
44
 
///May be used in extended classes
45
 
void Contact::initItem()
46
 
{
47
 
   initItemWidget();
48
 
}
49
 
 
50
 
///May be used in extended classes
51
 
void Contact::initItemWidget()
52
 
{
53
 
   
54
57
}
55
58
 
56
59
///Get the phone number list
57
 
PhoneNumbers Contact::getPhoneNumbers() const
 
60
const Contact::PhoneNumbers& Contact::phoneNumbers() const
58
61
{
59
62
   return m_Numbers;
60
63
}
61
64
 
62
65
///Get the nickname
63
 
const QString& Contact::getNickName() const
 
66
const QString& Contact::nickName() const
64
67
{
65
68
   return m_NickName;
66
69
}
67
70
 
68
71
///Get the firstname
69
 
const QString& Contact::getFirstName() const
 
72
const QString& Contact::firstName() const
70
73
{
71
74
   return m_FirstName;
72
75
}
73
76
 
74
77
///Get the second/family name
75
 
const QString& Contact::getSecondName() const
 
78
const QString& Contact::secondName() const
76
79
{
77
80
   return m_SecondName;
78
81
}
79
82
 
80
83
///Get the photo
81
 
const QPixmap* Contact::getPhoto() const
 
84
const QPixmap* Contact::photo() const
82
85
{
83
86
   return m_pPhoto;
84
87
}
85
88
 
86
89
///Get the formatted name
87
 
const QString& Contact::getFormattedName() const
 
90
const QString& Contact::formattedName() const
88
91
{
89
92
   return m_FormattedName;
90
93
}
91
94
 
92
95
///Get the organisation
93
 
const QString& Contact::getOrganization()  const
 
96
const QString& Contact::organization()  const
94
97
{
95
98
   return m_Organization;
96
99
}
97
100
 
98
101
///Get the preferred email
99
 
const QString& Contact::getPreferredEmail()  const
 
102
const QString& Contact::preferredEmail()  const
100
103
{
101
104
   return m_PreferredEmail;
102
105
}
103
106
 
104
107
///Get the unique identifier (used for drag and drop) 
105
 
const QString& Contact::getUid() const
 
108
const QString& Contact::uid() const
106
109
{
107
110
   return m_Uid;
108
111
}
109
112
 
110
113
///Get the group
111
 
const QString& Contact::getGroup() const
 
114
const QString& Contact::group() const
112
115
{
113
116
   return m_Group;
114
117
}
115
118
 
116
 
const QString& Contact::getDepartment() const
 
119
const QString& Contact::department() const
117
120
{
118
121
   return m_Department;
119
122
}
120
123
 
121
 
///Get the contact type
122
 
const QString& Contact::getType() const
123
 
{
124
 
   return m_Type;
125
 
}
126
 
 
127
 
///Set the phone number (type and number) 
 
124
///Set the phone number (type and number)
128
125
void Contact::setPhoneNumbers(PhoneNumbers numbers)
129
126
{
130
 
   m_Numbers    = 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()));
 
130
   m_Numbers = numbers;
 
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);
 
137
   emit changed();
131
138
}
132
139
 
133
140
///Set the nickname
134
141
void Contact::setNickName(const QString& name)
135
142
{
136
 
   m_NickName   = name;
 
143
   m_NickName = name;
 
144
   emit changed();
137
145
}
138
146
 
139
147
///Set the first name
140
148
void Contact::setFirstName(const QString& name)
141
149
{
142
 
   m_FirstName  = name;
 
150
   m_FirstName = name;
 
151
   setObjectName(formattedName());
 
152
   emit changed();
143
153
}
144
154
 
145
155
///Set the family name
146
156
void Contact::setFamilyName(const QString& name)
147
157
{
148
158
   m_SecondName = name;
 
159
   setObjectName(formattedName());
 
160
   emit changed();
149
161
}
150
162
 
151
163
///Set the Photo/Avatar
152
164
void Contact::setPhoto(QPixmap* photo)
153
165
{
154
166
   m_pPhoto = photo;
 
167
   emit changed();
155
168
}
156
169
 
157
170
///Set the formatted name (display name)
158
171
void Contact::setFormattedName(const QString& name)
159
172
{
160
173
   m_FormattedName = name;
 
174
   emit changed();
161
175
}
162
176
 
163
177
///Set the organisation / business
164
178
void Contact::setOrganization(const QString& name)
165
179
{
166
180
   m_Organization = name;
 
181
   emit changed();
167
182
}
168
183
 
169
184
///Set the default email
170
185
void Contact::setPreferredEmail(const QString& name)
171
186
{
172
187
   m_PreferredEmail = name;
 
188
   emit changed();
173
189
}
174
190
 
175
191
///Set UID
176
192
void Contact::setUid(const QString& id)
177
193
{
178
194
   m_Uid = id;
 
195
   emit changed();
179
196
}
180
197
 
181
198
///Set Group
182
199
void Contact::setGroup(const QString& name)
183
200
{
184
201
   m_Group = name;
 
202
   emit changed();
185
203
}
186
204
 
187
205
///Set department
188
206
void Contact::setDepartment(const QString& name)
189
207
{
190
208
   m_Department = name;
191
 
}
192
 
 
193
 
///Turn the contact into QString-QString hash
194
 
QHash<QString,QVariant> Contact::toHash()
195
 
{
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();
209
 
   return aContact;
210
 
}
211
 
 
212
 
///Return the number
213
 
QString& Contact::PhoneNumber::getNumber() {
214
 
   return m_Number ;
215
 
}
216
 
 
217
 
///Return the phone number type
218
 
QString& Contact::PhoneNumber::getType() {
219
 
   return m_Type   ;
 
209
   emit changed();
 
210
}
 
211
 
 
212
///If the contact have been deleted or not yet fully created
 
213
void Contact::setActive( bool active)
 
214
{
 
215
   m_Active = active;
 
216
   emit statusChanged(m_Active);
 
217
   emit changed();
 
218
}
 
219
 
 
220
///Return if one of the PhoneNumber is present
 
221
bool Contact::isPresent() const
 
222
{
 
223
   foreach(const PhoneNumber* n,m_Numbers) {
 
224
      if (n->isPresent())
 
225
         return true;
 
226
   }
 
227
   return false;
 
228
}
 
229
 
 
230
///Return if one of the PhoneNumber is tracked
 
231
bool Contact::isTracked() const
 
232
{
 
233
   foreach(const PhoneNumber* n,m_Numbers) {
 
234
      if (n->isTracked())
 
235
         return true;
 
236
   }
 
237
   return false;
 
238
}
 
239
 
 
240
///Have this contact been deleted or doesn't exist yet
 
241
bool Contact::isActive() const
 
242
{
 
243
   return m_Active;
 
244
}
 
245
 
 
246
///Return if one of the PhoneNumber support presence
 
247
bool Contact::supportPresence() const
 
248
{
 
249
   foreach(const PhoneNumber* n,m_Numbers) {
 
250
      if (n->supportPresence())
 
251
         return true;
 
252
   }
 
253
   return false;
 
254
}
 
255
 
 
256
 
 
257
QObject* Contact::PhoneNumbers::getSelf() const {
 
258
   return m_pParent2;
 
259
}
 
260
 
 
261
time_t Contact::PhoneNumbers::lastUsedTimeStamp() const
 
262
{
 
263
   time_t t = 0;
 
264
   for (int i=0;i<size();i++) {
 
265
      if (at(i)->lastUsed() > t)
 
266
         t = at(i)->lastUsed();
 
267
   }
 
268
   return t;
 
269
}
 
270
 
 
271
///Callback when one of the phone number presence change
 
272
void Contact::slotPresenceChanged()
 
273
{
 
274
   emit changed();
220
275
}