-rw-r--r-- | kabc/addressee.cpp | 123 |
1 files changed, 103 insertions, 20 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 548305a..cb10160 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -139,276 +139,359 @@ bool Addressee::operator==( const Addressee &a ) const | |||
139 | if ( mData->givenName != a.mData->givenName ) return false; | 139 | if ( mData->givenName != a.mData->givenName ) return false; |
140 | if ( mData->additionalName != a.mData->additionalName ) return false; | 140 | if ( mData->additionalName != a.mData->additionalName ) return false; |
141 | if ( mData->prefix != a.mData->prefix ) return false; | 141 | if ( mData->prefix != a.mData->prefix ) return false; |
142 | if ( mData->suffix != a.mData->suffix ) return false; | 142 | if ( mData->suffix != a.mData->suffix ) return false; |
143 | if ( mData->nickName != a.mData->nickName ) return false; | 143 | if ( mData->nickName != a.mData->nickName ) return false; |
144 | if ( mData->birthday != a.mData->birthday ) return false; | 144 | if ( mData->birthday != a.mData->birthday ) return false; |
145 | if ( mData->mailer != a.mData->mailer ) return false; | 145 | if ( mData->mailer != a.mData->mailer ) return false; |
146 | if ( mData->timeZone != a.mData->timeZone ) return false; | 146 | if ( mData->timeZone != a.mData->timeZone ) return false; |
147 | if ( mData->geo != a.mData->geo ) return false; | 147 | if ( mData->geo != a.mData->geo ) return false; |
148 | if ( mData->title != a.mData->title ) return false; | 148 | if ( mData->title != a.mData->title ) return false; |
149 | if ( mData->role != a.mData->role ) return false; | 149 | if ( mData->role != a.mData->role ) return false; |
150 | if ( mData->organization != a.mData->organization ) return false; | 150 | if ( mData->organization != a.mData->organization ) return false; |
151 | if ( mData->note != a.mData->note ) return false; | 151 | if ( mData->note != a.mData->note ) return false; |
152 | if ( mData->productId != a.mData->productId ) return false; | 152 | if ( mData->productId != a.mData->productId ) return false; |
153 | //if ( mData->revision != a.mData->revision ) return false; | 153 | //if ( mData->revision != a.mData->revision ) return false; |
154 | if ( mData->sortString != a.mData->sortString ) return false; | 154 | if ( mData->sortString != a.mData->sortString ) return false; |
155 | if ( mData->secrecy != a.mData->secrecy ) return false; | 155 | if ( mData->secrecy != a.mData->secrecy ) return false; |
156 | if ( mData->logo != a.mData->logo ) return false; | 156 | if ( mData->logo != a.mData->logo ) return false; |
157 | if ( mData->photo != a.mData->photo ) return false; | 157 | if ( mData->photo != a.mData->photo ) return false; |
158 | if ( mData->sound != a.mData->sound ) return false; | 158 | if ( mData->sound != a.mData->sound ) return false; |
159 | if ( mData->agent != a.mData->agent ) return false; | 159 | if ( mData->agent != a.mData->agent ) return false; |
160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && | 160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && |
161 | ( mData->url != a.mData->url ) ) return false; | 161 | ( mData->url != a.mData->url ) ) return false; |
162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; | 162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; |
163 | if ( mData->addresses != a.mData->addresses ) return false; | 163 | if ( mData->addresses != a.mData->addresses ) return false; |
164 | if ( mData->keys != a.mData->keys ) return false; | 164 | if ( mData->keys != a.mData->keys ) return false; |
165 | if ( mData->emails != a.mData->emails ) return false; | 165 | if ( mData->emails != a.mData->emails ) return false; |
166 | if ( mData->categories != a.mData->categories ) return false; | 166 | if ( mData->categories != a.mData->categories ) return false; |
167 | if ( mData->custom != a.mData->custom ) return false; | 167 | if ( mData->custom != a.mData->custom ) return false; |
168 | 168 | ||
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | 171 | ||
172 | bool Addressee::operator!=( const Addressee &a ) const | 172 | bool Addressee::operator!=( const Addressee &a ) const |
173 | { | 173 | { |
174 | return !( a == *this ); | 174 | return !( a == *this ); |
175 | } | 175 | } |
176 | 176 | ||
177 | bool Addressee::isEmpty() const | 177 | bool Addressee::isEmpty() const |
178 | { | 178 | { |
179 | return mData->empty; | 179 | return mData->empty; |
180 | } | 180 | } |
181 | ulong Addressee::getCsum4List( const QStringList & attList) | 181 | ulong Addressee::getCsum4List( const QStringList & attList) |
182 | { | 182 | { |
183 | int max = attList.count(); | 183 | int max = attList.count(); |
184 | ulong cSum = 0; | 184 | ulong cSum = 0; |
185 | int j,k,i; | 185 | int j,k,i; |
186 | int add; | 186 | int add; |
187 | for ( i = 0; i < max ; ++i ) { | 187 | for ( i = 0; i < max ; ++i ) { |
188 | QString s = attList[i]; | 188 | QString s = attList[i]; |
189 | if ( ! s.isEmpty() ){ | 189 | if ( ! s.isEmpty() ){ |
190 | j = s.length(); | 190 | j = s.length(); |
191 | for ( k = 0; k < j; ++k ) { | 191 | for ( k = 0; k < j; ++k ) { |
192 | int mul = k +1; | 192 | int mul = k +1; |
193 | add = s[k].unicode (); | 193 | add = s[k].unicode (); |
194 | if ( k < 16 ) | 194 | if ( k < 16 ) |
195 | mul = mul * mul; | 195 | mul = mul * mul; |
196 | int ii = i+1; | 196 | int ii = i+1; |
197 | add = add * mul *ii*ii*ii; | 197 | add = add * mul *ii*ii*ii; |
198 | cSum += add; | 198 | cSum += add; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | } | 202 | } |
203 | //QString dump = attList.join(","); | 203 | //QString dump = attList.join(","); |
204 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 204 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
205 | 205 | ||
206 | return cSum; | 206 | return cSum; |
207 | 207 | ||
208 | } | 208 | } |
209 | void Addressee::computeCsum(const QString &dev) | 209 | void Addressee::computeCsum(const QString &dev) |
210 | { | 210 | { |
211 | QStringList l; | 211 | QStringList l; |
212 | if ( !mData->name.isEmpty() ) l.append(mData->name); | 212 | if ( !mData->name.isEmpty() ) l.append(mData->name); |
213 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); | 213 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); |
214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); | 214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); |
215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); | 215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); |
216 | if ( !mData->additionalName ) l.append( mData->additionalName ); | 216 | if ( !mData->additionalName ) l.append( mData->additionalName ); |
217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); | 217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); |
218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); | 218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); |
219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); | 219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); |
220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); | 220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); |
221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); | 221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); |
222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); | 222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); |
223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); | 223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); |
224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); | 224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); |
225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); | 225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); |
226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); | 226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); |
227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); | 227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); |
228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); | 228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); |
229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); | 229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); |
230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); | 230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); |
231 | // if ( !mData->logo.isEmpty() ) l.append( ); | 231 | // if ( !mData->logo.isEmpty() ) l.append( ); |
232 | //if ( !mData->photo.isEmpty() ) l.append( ); | 232 | //if ( !mData->photo.isEmpty() ) l.append( ); |
233 | //if ( !mData->sound.isEmpty() ) l.append( ); | 233 | //if ( !mData->sound.isEmpty() ) l.append( ); |
234 | //if ( !mData->agent.isEmpty() ) l.append( ); | 234 | //if ( !mData->agent.isEmpty() ) l.append( ); |
235 | //if ( mData->url.isValid() ) l.append( ); | 235 | if ( mData->url.isValid() ) |
236 | #if 0 | 236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); |
237 | if ( !mData->phoneNumbers.isEmpty() ) l.append( ); | ||
238 | if ( !mData->addresses.isEmpty() ) l.append( ); | ||
239 | //if ( !mData->keys.isEmpty() ) l.append( ); | ||
240 | if ( !mData->emails.isEmpty() ) l.append( ); | ||
241 | if ( !mData->categories .isEmpty() ) l.append( ); | ||
242 | if ( !mData->custom.isEmpty() ) l.append( ); | ||
243 | #endif | ||
244 | KABC::PhoneNumber::List phoneNumbers; | 237 | KABC::PhoneNumber::List phoneNumbers; |
245 | KABC::PhoneNumber::List::Iterator phoneIter; | 238 | KABC::PhoneNumber::List::Iterator phoneIter; |
246 | 239 | ||
247 | QStringList t; | 240 | QStringList t; |
248 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
249 | ++phoneIter ) | 242 | ++phoneIter ) |
250 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); | 243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); |
251 | t.sort(); | 244 | t.sort(); |
252 | uint iii; | 245 | uint iii; |
253 | for ( iii = 0; iii < t.count(); ++iii) | 246 | for ( iii = 0; iii < t.count(); ++iii) |
254 | l.append( t[iii] ); | 247 | l.append( t[iii] ); |
255 | t = mData->emails; | 248 | t = mData->emails; |
256 | t.sort(); | 249 | t.sort(); |
257 | for ( iii = 0; iii < t.count(); ++iii) | 250 | for ( iii = 0; iii < t.count(); ++iii) |
258 | l.append( t[iii] ); | 251 | l.append( t[iii] ); |
259 | t = mData->categories; | 252 | t = mData->categories; |
260 | t.sort(); | 253 | t.sort(); |
261 | for ( iii = 0; iii < t.count(); ++iii) | 254 | for ( iii = 0; iii < t.count(); ++iii) |
262 | l.append( t[iii] ); | 255 | l.append( t[iii] ); |
263 | t = mData->custom; | 256 | t = mData->custom; |
264 | t.sort(); | 257 | t.sort(); |
265 | for ( iii = 0; iii < t.count(); ++iii) | 258 | for ( iii = 0; iii < t.count(); ++iii) |
266 | l.append( t[iii] ); | 259 | l.append( t[iii] ); |
267 | KABC::Address::List::Iterator addressIter; | 260 | KABC::Address::List::Iterator addressIter; |
268 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 261 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
269 | ++addressIter ) { | 262 | ++addressIter ) { |
270 | t = (*addressIter).asList(); | 263 | t = (*addressIter).asList(); |
271 | t.sort(); | 264 | t.sort(); |
272 | for ( iii = 0; iii < t.count(); ++iii) | 265 | for ( iii = 0; iii < t.count(); ++iii) |
273 | l.append( t[iii] ); | 266 | l.append( t[iii] ); |
274 | } | 267 | } |
275 | uint cs = getCsum4List(l); | 268 | uint cs = getCsum4List(l); |
276 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); | 269 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); |
277 | setCsum( dev, QString::number (cs )); | 270 | setCsum( dev, QString::number (cs )); |
278 | } | 271 | } |
279 | 272 | ||
280 | void Addressee::mergeContact( const Addressee& ad ) | 273 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) |
281 | { | 274 | { |
282 | 275 | ||
283 | detach(); | 276 | detach(); |
284 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 277 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
285 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 278 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
286 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 279 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
287 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 280 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
288 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 281 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
289 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 282 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
290 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 283 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
291 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 284 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
292 | if ( !mData->birthday.isValid() ) | 285 | if ( !mData->birthday.isValid() ) |
293 | if ( ad.mData->birthday.isValid()) | 286 | if ( ad.mData->birthday.isValid()) |
294 | mData->birthday = ad.mData->birthday; | 287 | mData->birthday = ad.mData->birthday; |
295 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 288 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
296 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 289 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
297 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 290 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
298 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 291 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
299 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 292 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
300 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 293 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
301 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 294 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
302 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 295 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
303 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 296 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
304 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 297 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
305 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 298 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
306 | PhoneNumber::List phoneAD = phoneNumbers(); | 299 | QStringList t; |
307 | PhoneNumber::List::Iterator phoneItAD; | 300 | QStringList tAD; |
308 | bool found = false; | 301 | uint iii; |
309 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | 302 | if ( isSubSet ) { |
303 | // ********** phone numbers | ||
304 | PhoneNumber::List phoneAD = ad.phoneNumbers(); | ||
305 | PhoneNumber::List::Iterator phoneItAD; | ||
306 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | ||
307 | bool found = false; | ||
308 | PhoneNumber::List::Iterator it; | ||
309 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | ||
310 | if ( (*it) == ( *phoneItAD ) ) { | ||
311 | found = true; | ||
312 | break; | ||
313 | } | ||
314 | } | ||
315 | if ( ! found ) | ||
316 | mData->phoneNumbers.append( *phoneItAD ); | ||
317 | } | ||
318 | // ************* emails; | ||
319 | t = mData->emails; | ||
320 | tAD = ad.mData->emails; | ||
321 | for ( iii = 0; iii < tAD.count(); ++iii) | ||
322 | if ( !t.contains(tAD[iii] ) ) | ||
323 | mData->emails.append( tAD[iii] ); | ||
324 | // ************* categories; | ||
325 | t = mData->categories; | ||
326 | tAD = ad.mData->categories; | ||
327 | for ( iii = 0; iii < tAD.count(); ++iii) | ||
328 | if ( !t.contains(tAD[iii] ) ) | ||
329 | mData->categories.append( tAD[iii] ); | ||
310 | 330 | ||
311 | 331 | ||
332 | } | ||
333 | |||
334 | QStringList::ConstIterator it; | ||
335 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { | ||
336 | QString qualifiedName = (*it).left( (*it).find( ":" )); | ||
337 | bool found = false; | ||
338 | QStringList::ConstIterator itL; | ||
339 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { | ||
340 | if ( (*itL).startsWith( qualifiedName ) ) { | ||
341 | found = true; | ||
342 | break; | ||
343 | } | ||
344 | } | ||
345 | if ( ! found ) { | ||
346 | mData->custom.append( *it ); | ||
347 | } | ||
348 | } | ||
349 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; | ||
350 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; | ||
351 | if ( !mData->sound.isIntern() ) { | ||
352 | if ( mData->sound.url().isEmpty() ) { | ||
353 | mData->sound = ad.mData->sound; | ||
354 | } | ||
355 | } | ||
356 | if ( !mData->agent.isIntern() ) { | ||
357 | if ( mData->agent.url().isEmpty() ) { | ||
358 | mData->agent = ad.mData->agent; | ||
359 | } | ||
312 | } | 360 | } |
361 | |||
362 | #if 0 | ||
363 | |||
364 | if ( mData->url.isValid() ) | ||
365 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); | ||
366 | KABC::PhoneNumber::List phoneNumbers; | ||
367 | KABC::PhoneNumber::List::Iterator phoneIter; | ||
368 | |||
369 | QStringList t; | ||
370 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
371 | ++phoneIter ) | ||
372 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); | ||
373 | t.sort(); | ||
374 | uint iii; | ||
375 | for ( iii = 0; iii < t.count(); ++iii) | ||
376 | l.append( t[iii] ); | ||
377 | t = mData->emails; | ||
378 | t.sort(); | ||
379 | for ( iii = 0; iii < t.count(); ++iii) | ||
380 | l.append( t[iii] ); | ||
381 | t = mData->categories; | ||
382 | t.sort(); | ||
383 | for ( iii = 0; iii < t.count(); ++iii) | ||
384 | l.append( t[iii] ); | ||
385 | t = mData->custom; | ||
386 | t.sort(); | ||
387 | for ( iii = 0; iii < t.count(); ++iii) | ||
388 | l.append( t[iii] ); | ||
389 | KABC::Address::List::Iterator addressIter; | ||
390 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | ||
391 | ++addressIter ) { | ||
392 | t = (*addressIter).asList(); | ||
393 | t.sort(); | ||
394 | for ( iii = 0; iii < t.count(); ++iii) | ||
395 | l.append( t[iii] ); | ||
396 | } | ||
397 | |||
398 | #endif | ||
399 | |||
313 | // pending: | 400 | // pending: |
314 | // merging phonenumbers | ||
315 | // merging addresses | 401 | // merging addresses |
316 | // merging emails; | ||
317 | // merging categories; | ||
318 | // merging custom; | ||
319 | // merging keys | 402 | // merging keys |
320 | //qDebug("merge contact %s ", ad.uid().latin1()); | 403 | //qDebug("merge contact %s ", ad.uid().latin1()); |
321 | setUid( ad.uid() ); | 404 | setUid( ad.uid() ); |
322 | setRevision( ad.revision() ); | 405 | setRevision( ad.revision() ); |
323 | } | 406 | } |
324 | 407 | ||
325 | bool Addressee::removeVoice() | 408 | bool Addressee::removeVoice() |
326 | { | 409 | { |
327 | PhoneNumber::List phoneN = phoneNumbers(); | 410 | PhoneNumber::List phoneN = phoneNumbers(); |
328 | PhoneNumber::List::Iterator phoneIt; | 411 | PhoneNumber::List::Iterator phoneIt; |
329 | bool found = false; | 412 | bool found = false; |
330 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 413 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
331 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 414 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
332 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 415 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
333 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 416 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
334 | insertPhoneNumber( (*phoneIt) ); | 417 | insertPhoneNumber( (*phoneIt) ); |
335 | found = true; | 418 | found = true; |
336 | } | 419 | } |
337 | } | 420 | } |
338 | 421 | ||
339 | } | 422 | } |
340 | return found; | 423 | return found; |
341 | } | 424 | } |
342 | 425 | ||
343 | bool Addressee::containsAdr(const Addressee& ad ) | 426 | bool Addressee::containsAdr(const Addressee& ad ) |
344 | { | 427 | { |
345 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; | 428 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; |
346 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; | 429 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; |
347 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; | 430 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; |
348 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; | 431 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; |
349 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; | 432 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; |
350 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; | 433 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; |
351 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; | 434 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; |
352 | 435 | ||
353 | // compare phone numbers | 436 | // compare phone numbers |
354 | PhoneNumber::List phoneN = ad.phoneNumbers(); | 437 | PhoneNumber::List phoneN = ad.phoneNumbers(); |
355 | PhoneNumber::List::Iterator phoneIt; | 438 | PhoneNumber::List::Iterator phoneIt; |
356 | bool found = false; | 439 | bool found = false; |
357 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 440 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
358 | bool found = false; | 441 | bool found = false; |
359 | PhoneNumber::List phoneL = ad.phoneNumbers(); | 442 | PhoneNumber::List phoneL = ad.phoneNumbers(); |
360 | PhoneNumber::List::Iterator phoneItL; | 443 | PhoneNumber::List::Iterator phoneItL; |
361 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | 444 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { |
362 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | 445 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { |
363 | found = true; | 446 | found = true; |
364 | break; | 447 | break; |
365 | } | 448 | } |
366 | } | 449 | } |
367 | if ( ! found ) | 450 | if ( ! found ) |
368 | return false; | 451 | return false; |
369 | } | 452 | } |
370 | return true; | 453 | return true; |
371 | 454 | ||
372 | } | 455 | } |
373 | void Addressee::simplifyAddresses() | 456 | void Addressee::simplifyAddresses() |
374 | { | 457 | { |
375 | int max = 2; | 458 | int max = 2; |
376 | if ( mData->url.isValid() ) | 459 | if ( mData->url.isValid() ) |
377 | max = 1; | 460 | max = 1; |
378 | if ( mData->addresses.count() <= max ) return ; | 461 | if ( mData->addresses.count() <= max ) return ; |
379 | int count = 0; | 462 | int count = 0; |
380 | Address::List list; | 463 | Address::List list; |
381 | Address::List::Iterator it; | 464 | Address::List::Iterator it; |
382 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 465 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
383 | if ( count >= max ) | 466 | if ( count >= max ) |
384 | list.append( *it ); | 467 | list.append( *it ); |
385 | ++count; | 468 | ++count; |
386 | } | 469 | } |
387 | for( it = list.begin(); it != list.end(); ++it ) { | 470 | for( it = list.begin(); it != list.end(); ++it ) { |
388 | removeAddress( (*it) ); | 471 | removeAddress( (*it) ); |
389 | } | 472 | } |
390 | } | 473 | } |
391 | 474 | ||
392 | // removes all emails but the first | 475 | // removes all emails but the first |
393 | // needed by phone sync | 476 | // needed by phone sync |
394 | void Addressee::simplifyEmails() | 477 | void Addressee::simplifyEmails() |
395 | { | 478 | { |
396 | if ( mData->emails.count() == 0 ) return ; | 479 | if ( mData->emails.count() == 0 ) return ; |
397 | QString email = mData->emails.first(); | 480 | QString email = mData->emails.first(); |
398 | detach(); | 481 | detach(); |
399 | mData->emails.clear(); | 482 | mData->emails.clear(); |
400 | mData->emails.append( email ); | 483 | mData->emails.append( email ); |
401 | } | 484 | } |
402 | 485 | ||
403 | void Addressee::simplifyPhoneNumbers() | 486 | void Addressee::simplifyPhoneNumbers() |
404 | { | 487 | { |
405 | KABC::PhoneNumber::List removeNumbers; | 488 | KABC::PhoneNumber::List removeNumbers; |
406 | KABC::PhoneNumber::List::Iterator phoneIter; | 489 | KABC::PhoneNumber::List::Iterator phoneIter; |
407 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 490 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
408 | ++phoneIter ) { | 491 | ++phoneIter ) { |
409 | if ( ! ( *phoneIter ).simplifyNumber() ) | 492 | if ( ! ( *phoneIter ).simplifyNumber() ) |
410 | removeNumbers.append( ( *phoneIter ) ); | 493 | removeNumbers.append( ( *phoneIter ) ); |
411 | } | 494 | } |
412 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 495 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
413 | ++phoneIter ) { | 496 | ++phoneIter ) { |
414 | removePhoneNumber(( *phoneIter )); | 497 | removePhoneNumber(( *phoneIter )); |