TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

addresseediffalgo.cpp 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. This file is part of libtdepim.
  3. Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <kabc/vcardconverter.h>
  18. #include "addresseediffalgo.h"
  19. using namespace KSync;
  20. static bool compareString( const TQString &left, const TQString &right )
  21. {
  22. if ( left.isEmpty() && right.isEmpty() )
  23. return true;
  24. else
  25. return left == right;
  26. }
  27. AddresseeDiffAlgo::AddresseeDiffAlgo( const KABC::Addressee &leftAddressee,
  28. const KABC::Addressee &rightAddressee )
  29. : mLeftAddressee( leftAddressee ), mRightAddressee( rightAddressee )
  30. {
  31. }
  32. AddresseeDiffAlgo::AddresseeDiffAlgo( const TQString &leftAddressee,
  33. const TQString &rightAddressee )
  34. {
  35. KABC::VCardConverter converter;
  36. mLeftAddressee = converter.parseVCard( leftAddressee );
  37. mRightAddressee = converter.parseVCard( rightAddressee );
  38. }
  39. void AddresseeDiffAlgo::run()
  40. {
  41. begin();
  42. if ( !compareString( mLeftAddressee.uid(), mRightAddressee.uid() ) )
  43. conflictField( KABC::Addressee::uidLabel(), mLeftAddressee.uid(), mRightAddressee.uid() );
  44. if ( !compareString( mLeftAddressee.name(), mRightAddressee.name() ) )
  45. conflictField( KABC::Addressee::nameLabel(), mLeftAddressee.name(), mRightAddressee.name() );
  46. if ( !compareString( mLeftAddressee.formattedName(), mRightAddressee.formattedName() ) )
  47. conflictField( KABC::Addressee::formattedNameLabel(), mLeftAddressee.formattedName(), mRightAddressee.formattedName() );
  48. if ( !compareString( mLeftAddressee.familyName(), mRightAddressee.familyName() ) )
  49. conflictField( KABC::Addressee::familyNameLabel(), mLeftAddressee.familyName(), mRightAddressee.familyName() );
  50. if ( !compareString( mLeftAddressee.givenName(), mRightAddressee.givenName() ) )
  51. conflictField( KABC::Addressee::givenNameLabel(), mLeftAddressee.givenName(), mRightAddressee.givenName() );
  52. if ( !compareString( mLeftAddressee.additionalName(), mRightAddressee.additionalName() ) )
  53. conflictField( KABC::Addressee::additionalNameLabel(), mLeftAddressee.additionalName(), mRightAddressee.additionalName() );
  54. if ( !compareString( mLeftAddressee.prefix(), mRightAddressee.prefix() ) )
  55. conflictField( KABC::Addressee::prefixLabel(), mLeftAddressee.prefix(), mRightAddressee.prefix() );
  56. if ( !compareString( mLeftAddressee.suffix(), mRightAddressee.suffix() ) )
  57. conflictField( KABC::Addressee::suffixLabel(), mLeftAddressee.suffix(), mRightAddressee.suffix() );
  58. if ( !compareString( mLeftAddressee.nickName(), mRightAddressee.nickName() ) )
  59. conflictField( KABC::Addressee::nickNameLabel(), mLeftAddressee.nickName(), mRightAddressee.nickName() );
  60. if ( mLeftAddressee.birthday() != mRightAddressee.birthday() )
  61. conflictField( KABC::Addressee::birthdayLabel(), mLeftAddressee.birthday().toString(),
  62. mRightAddressee.birthday().toString() );
  63. if ( !compareString( mLeftAddressee.mailer(), mRightAddressee.mailer() ) )
  64. conflictField( KABC::Addressee::mailerLabel(), mLeftAddressee.mailer(), mRightAddressee.mailer() );
  65. if ( mLeftAddressee.timeZone() != mRightAddressee.timeZone() )
  66. conflictField( KABC::Addressee::timeZoneLabel(), mLeftAddressee.timeZone().asString(), mRightAddressee.timeZone().asString() );
  67. if ( mLeftAddressee.geo() != mRightAddressee.geo() )
  68. conflictField( KABC::Addressee::geoLabel(), mLeftAddressee.geo().asString(), mRightAddressee.geo().asString() );
  69. if ( !compareString( mLeftAddressee.title(), mRightAddressee.title() ) )
  70. conflictField( KABC::Addressee::titleLabel(), mLeftAddressee.title(), mRightAddressee.title() );
  71. if ( !compareString( mLeftAddressee.role(), mRightAddressee.role() ) )
  72. conflictField( KABC::Addressee::roleLabel(), mLeftAddressee.role(), mRightAddressee.role() );
  73. if ( !compareString( mLeftAddressee.organization(), mRightAddressee.organization() ) )
  74. conflictField( KABC::Addressee::organizationLabel(), mLeftAddressee.organization(), mRightAddressee.organization() );
  75. if ( !compareString( mLeftAddressee.note(), mRightAddressee.note() ) )
  76. conflictField( KABC::Addressee::noteLabel(), mLeftAddressee.note(), mRightAddressee.note() );
  77. if ( !compareString( mLeftAddressee.productId(), mRightAddressee.productId() ) )
  78. conflictField( KABC::Addressee::productIdLabel(), mLeftAddressee.productId(), mRightAddressee.productId() );
  79. if ( !compareString( mLeftAddressee.sortString(), mRightAddressee.sortString() ) )
  80. conflictField( KABC::Addressee::sortStringLabel(), mLeftAddressee.sortString(), mRightAddressee.sortString() );
  81. if ( mLeftAddressee.secrecy() != mRightAddressee.secrecy() ) {
  82. conflictField( KABC::Addressee::secrecyLabel(), mLeftAddressee.secrecy().asString(), mRightAddressee.secrecy().asString() );
  83. }
  84. if ( mLeftAddressee.url()!= mRightAddressee.url() )
  85. conflictField( KABC::Addressee::urlLabel(), mLeftAddressee.url().prettyURL(),
  86. mRightAddressee.url().prettyURL() );
  87. if ( mLeftAddressee.logo() != mRightAddressee.logo() ) {
  88. }
  89. if ( mLeftAddressee.photo() != mRightAddressee.photo() ) {
  90. }
  91. diffList( "emails", mLeftAddressee.emails(), mRightAddressee.emails() );
  92. diffList( "Phone Numbers", mLeftAddressee.phoneNumbers(), mRightAddressee.phoneNumbers() );
  93. diffList( "Addresses", mLeftAddressee.addresses(), mRightAddressee.addresses() );
  94. end();
  95. }
  96. TQString AddresseeDiffAlgo::toString( const KABC::PhoneNumber &number )
  97. {
  98. return number.number();
  99. }
  100. TQString AddresseeDiffAlgo::toString( const KABC::Address &addr )
  101. {
  102. return addr.formattedAddress();
  103. }
  104. template <class L>
  105. void AddresseeDiffAlgo::diffList( const TQString &id,
  106. const TQValueList<L> &left, const TQValueList<L> &right )
  107. {
  108. for ( uint i = 0; i < left.count(); ++i ) {
  109. if ( right.find( left[ i ] ) == right.end() )
  110. additionalLeftField( id, toString( left[ i ] ) );
  111. }
  112. for ( uint i = 0; i < right.count(); ++i ) {
  113. if ( left.find( right[ i ] ) == left.end() )
  114. additionalRightField( id, toString( right[ i ] ) );
  115. }
  116. }