-rw-r--r-- | kabc/addressee.cpp | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 607ae26..548305a 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -282,86 +282,126 @@ void Addressee::mergeContact( const Addressee& ad ) | |||
282 | 282 | ||
283 | detach(); | 283 | detach(); |
284 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 284 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
285 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 285 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
286 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 286 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
287 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 287 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
288 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 288 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
289 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 289 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
290 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 290 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
291 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 291 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
292 | if ( !mData->birthday.isValid() ) | 292 | if ( !mData->birthday.isValid() ) |
293 | if ( ad.mData->birthday.isValid()) | 293 | if ( ad.mData->birthday.isValid()) |
294 | mData->birthday = ad.mData->birthday; | 294 | mData->birthday = ad.mData->birthday; |
295 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 295 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
296 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 296 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
297 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 297 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
298 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 298 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
299 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 299 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
300 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 300 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
301 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 301 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
302 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 302 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
303 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 303 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
304 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 304 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
305 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 305 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
306 | PhoneNumber::List phoneAD = phoneNumbers(); | ||
307 | PhoneNumber::List::Iterator phoneItAD; | ||
308 | bool found = false; | ||
309 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | ||
306 | 310 | ||
311 | |||
312 | } | ||
307 | // pending: | 313 | // pending: |
308 | // merging phonenumbers | 314 | // merging phonenumbers |
309 | // merging addresses | 315 | // merging addresses |
310 | // merging emails; | 316 | // merging emails; |
311 | // merging categories; | 317 | // merging categories; |
312 | // merging custom; | 318 | // merging custom; |
313 | // merging keys | 319 | // merging keys |
314 | qDebug("merge contact %s ", ad.uid().latin1()); | 320 | //qDebug("merge contact %s ", ad.uid().latin1()); |
315 | setUid( ad.uid() ); | 321 | setUid( ad.uid() ); |
316 | setRevision( ad.revision() ); | 322 | setRevision( ad.revision() ); |
317 | } | 323 | } |
318 | 324 | ||
319 | bool Addressee::removeVoice() | 325 | bool Addressee::removeVoice() |
320 | { | 326 | { |
321 | PhoneNumber::List phoneN = phoneNumbers(); | 327 | PhoneNumber::List phoneN = phoneNumbers(); |
322 | PhoneNumber::List::Iterator phoneIt; | 328 | PhoneNumber::List::Iterator phoneIt; |
323 | bool found = false; | 329 | bool found = false; |
324 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 330 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
325 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 331 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
326 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 332 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
327 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 333 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
328 | insertPhoneNumber( (*phoneIt) ); | 334 | insertPhoneNumber( (*phoneIt) ); |
329 | found = true; | 335 | found = true; |
330 | } | 336 | } |
331 | } | 337 | } |
332 | 338 | ||
333 | } | 339 | } |
334 | return found; | 340 | return found; |
335 | } | 341 | } |
342 | |||
343 | bool Addressee::containsAdr(const Addressee& ad ) | ||
344 | { | ||
345 | 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; | ||
347 | 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 ; | ||
349 | 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 ; | ||
351 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; | ||
352 | |||
353 | // compare phone numbers | ||
354 | PhoneNumber::List phoneN = ad.phoneNumbers(); | ||
355 | PhoneNumber::List::Iterator phoneIt; | ||
356 | bool found = false; | ||
357 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | ||
358 | bool found = false; | ||
359 | PhoneNumber::List phoneL = ad.phoneNumbers(); | ||
360 | PhoneNumber::List::Iterator phoneItL; | ||
361 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | ||
362 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | ||
363 | found = true; | ||
364 | break; | ||
365 | } | ||
366 | } | ||
367 | if ( ! found ) | ||
368 | return false; | ||
369 | } | ||
370 | return true; | ||
371 | |||
372 | } | ||
336 | void Addressee::simplifyAddresses() | 373 | void Addressee::simplifyAddresses() |
337 | { | 374 | { |
338 | if ( mData->addresses.count() < 3 ) return ; | 375 | int max = 2; |
376 | if ( mData->url.isValid() ) | ||
377 | max = 1; | ||
378 | if ( mData->addresses.count() <= max ) return ; | ||
339 | int count = 0; | 379 | int count = 0; |
340 | Address::List list; | 380 | Address::List list; |
341 | Address::List::Iterator it; | 381 | Address::List::Iterator it; |
342 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 382 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
343 | if ( count > 1 ) | 383 | if ( count >= max ) |
344 | list.append( *it ); | 384 | list.append( *it ); |
345 | ++count; | 385 | ++count; |
346 | } | 386 | } |
347 | for( it = list.begin(); it != list.end(); ++it ) { | 387 | for( it = list.begin(); it != list.end(); ++it ) { |
348 | removeAddress( (*it) ); | 388 | removeAddress( (*it) ); |
349 | } | 389 | } |
350 | } | 390 | } |
351 | 391 | ||
352 | // removes all emails but the first | 392 | // removes all emails but the first |
353 | // needed by phone sync | 393 | // needed by phone sync |
354 | void Addressee::simplifyEmails() | 394 | void Addressee::simplifyEmails() |
355 | { | 395 | { |
356 | if ( mData->emails.count() == 0 ) return ; | 396 | if ( mData->emails.count() == 0 ) return ; |
357 | QString email = mData->emails.first(); | 397 | QString email = mData->emails.first(); |
358 | detach(); | 398 | detach(); |
359 | mData->emails.clear(); | 399 | mData->emails.clear(); |
360 | mData->emails.append( email ); | 400 | mData->emails.append( email ); |
361 | } | 401 | } |
362 | 402 | ||
363 | void Addressee::simplifyPhoneNumbers() | 403 | void Addressee::simplifyPhoneNumbers() |
364 | { | 404 | { |
365 | KABC::PhoneNumber::List removeNumbers; | 405 | KABC::PhoneNumber::List removeNumbers; |
366 | KABC::PhoneNumber::List::Iterator phoneIter; | 406 | KABC::PhoneNumber::List::Iterator phoneIter; |
367 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 407 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |