addresseediffalgo.cpp
00001 /* 00002 This file is part of libtdepim. 00003 00004 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include <tdeabc/vcardconverter.h> 00023 00024 #include "addresseediffalgo.h" 00025 00026 using namespace KSync; 00027 00028 static bool compareString( const TQString &left, const TQString &right ) 00029 { 00030 if ( left.isEmpty() && right.isEmpty() ) 00031 return true; 00032 else 00033 return left == right; 00034 } 00035 00036 AddresseeDiffAlgo::AddresseeDiffAlgo( const TDEABC::Addressee &leftAddressee, 00037 const TDEABC::Addressee &rightAddressee ) 00038 : mLeftAddressee( leftAddressee ), mRightAddressee( rightAddressee ) 00039 { 00040 } 00041 00042 AddresseeDiffAlgo::AddresseeDiffAlgo( const TQString &leftAddressee, 00043 const TQString &rightAddressee ) 00044 { 00045 TDEABC::VCardConverter converter; 00046 00047 mLeftAddressee = converter.parseVCard( leftAddressee ); 00048 mRightAddressee = converter.parseVCard( rightAddressee ); 00049 } 00050 00051 void AddresseeDiffAlgo::run() 00052 { 00053 begin(); 00054 00055 if ( !compareString( mLeftAddressee.uid(), mRightAddressee.uid() ) ) 00056 conflictField( TDEABC::Addressee::uidLabel(), mLeftAddressee.uid(), mRightAddressee.uid() ); 00057 00058 if ( !compareString( mLeftAddressee.name(), mRightAddressee.name() ) ) 00059 conflictField( TDEABC::Addressee::nameLabel(), mLeftAddressee.name(), mRightAddressee.name() ); 00060 00061 if ( !compareString( mLeftAddressee.formattedName(), mRightAddressee.formattedName() ) ) 00062 conflictField( TDEABC::Addressee::formattedNameLabel(), mLeftAddressee.formattedName(), mRightAddressee.formattedName() ); 00063 00064 if ( !compareString( mLeftAddressee.familyName(), mRightAddressee.familyName() ) ) 00065 conflictField( TDEABC::Addressee::familyNameLabel(), mLeftAddressee.familyName(), mRightAddressee.familyName() ); 00066 00067 if ( !compareString( mLeftAddressee.givenName(), mRightAddressee.givenName() ) ) 00068 conflictField( TDEABC::Addressee::givenNameLabel(), mLeftAddressee.givenName(), mRightAddressee.givenName() ); 00069 00070 if ( !compareString( mLeftAddressee.additionalName(), mRightAddressee.additionalName() ) ) 00071 conflictField( TDEABC::Addressee::additionalNameLabel(), mLeftAddressee.additionalName(), mRightAddressee.additionalName() ); 00072 00073 if ( !compareString( mLeftAddressee.prefix(), mRightAddressee.prefix() ) ) 00074 conflictField( TDEABC::Addressee::prefixLabel(), mLeftAddressee.prefix(), mRightAddressee.prefix() ); 00075 00076 if ( !compareString( mLeftAddressee.suffix(), mRightAddressee.suffix() ) ) 00077 conflictField( TDEABC::Addressee::suffixLabel(), mLeftAddressee.suffix(), mRightAddressee.suffix() ); 00078 00079 if ( !compareString( mLeftAddressee.nickName(), mRightAddressee.nickName() ) ) 00080 conflictField( TDEABC::Addressee::nickNameLabel(), mLeftAddressee.nickName(), mRightAddressee.nickName() ); 00081 00082 if ( mLeftAddressee.birthday() != mRightAddressee.birthday() ) 00083 conflictField( TDEABC::Addressee::birthdayLabel(), mLeftAddressee.birthday().toString(), 00084 mRightAddressee.birthday().toString() ); 00085 00086 if ( !compareString( mLeftAddressee.mailer(), mRightAddressee.mailer() ) ) 00087 conflictField( TDEABC::Addressee::mailerLabel(), mLeftAddressee.mailer(), mRightAddressee.mailer() ); 00088 00089 if ( mLeftAddressee.timeZone() != mRightAddressee.timeZone() ) 00090 conflictField( TDEABC::Addressee::timeZoneLabel(), mLeftAddressee.timeZone().asString(), mRightAddressee.timeZone().asString() ); 00091 00092 if ( mLeftAddressee.geo() != mRightAddressee.geo() ) 00093 conflictField( TDEABC::Addressee::geoLabel(), mLeftAddressee.geo().asString(), mRightAddressee.geo().asString() ); 00094 00095 if ( !compareString( mLeftAddressee.title(), mRightAddressee.title() ) ) 00096 conflictField( TDEABC::Addressee::titleLabel(), mLeftAddressee.title(), mRightAddressee.title() ); 00097 00098 if ( !compareString( mLeftAddressee.role(), mRightAddressee.role() ) ) 00099 conflictField( TDEABC::Addressee::roleLabel(), mLeftAddressee.role(), mRightAddressee.role() ); 00100 00101 if ( !compareString( mLeftAddressee.organization(), mRightAddressee.organization() ) ) 00102 conflictField( TDEABC::Addressee::organizationLabel(), mLeftAddressee.organization(), mRightAddressee.organization() ); 00103 00104 if ( !compareString( mLeftAddressee.note(), mRightAddressee.note() ) ) 00105 conflictField( TDEABC::Addressee::noteLabel(), mLeftAddressee.note(), mRightAddressee.note() ); 00106 00107 if ( !compareString( mLeftAddressee.productId(), mRightAddressee.productId() ) ) 00108 conflictField( TDEABC::Addressee::productIdLabel(), mLeftAddressee.productId(), mRightAddressee.productId() ); 00109 00110 if ( !compareString( mLeftAddressee.sortString(), mRightAddressee.sortString() ) ) 00111 conflictField( TDEABC::Addressee::sortStringLabel(), mLeftAddressee.sortString(), mRightAddressee.sortString() ); 00112 00113 if ( mLeftAddressee.secrecy() != mRightAddressee.secrecy() ) { 00114 conflictField( TDEABC::Addressee::secrecyLabel(), mLeftAddressee.secrecy().asString(), mRightAddressee.secrecy().asString() ); 00115 } 00116 if ( mLeftAddressee.url()!= mRightAddressee.url() ) 00117 conflictField( TDEABC::Addressee::urlLabel(), mLeftAddressee.url().prettyURL(), 00118 mRightAddressee.url().prettyURL() ); 00119 00120 if ( mLeftAddressee.logo() != mRightAddressee.logo() ) { 00121 } 00122 00123 if ( mLeftAddressee.photo() != mRightAddressee.photo() ) { 00124 } 00125 00126 diffList( "emails", mLeftAddressee.emails(), mRightAddressee.emails() ); 00127 00128 diffList( "Phone Numbers", mLeftAddressee.phoneNumbers(), mRightAddressee.phoneNumbers() ); 00129 diffList( "Addresses", mLeftAddressee.addresses(), mRightAddressee.addresses() ); 00130 00131 end(); 00132 } 00133 00134 TQString AddresseeDiffAlgo::toString( const TDEABC::PhoneNumber &number ) 00135 { 00136 return number.number(); 00137 } 00138 00139 TQString AddresseeDiffAlgo::toString( const TDEABC::Address &addr ) 00140 { 00141 return addr.formattedAddress(); 00142 } 00143 00144 template <class L> 00145 void AddresseeDiffAlgo::diffList( const TQString &id, 00146 const TQValueList<L> &left, const TQValueList<L> &right ) 00147 { 00148 for ( uint i = 0; i < left.count(); ++i ) { 00149 if ( right.find( left[ i ] ) == right.end() ) 00150 additionalLeftField( id, toString( left[ i ] ) ); 00151 } 00152 00153 for ( uint i = 0; i < right.count(); ++i ) { 00154 if ( left.find( right[ i ] ) == left.end() ) 00155 additionalRightField( id, toString( right[ i ] ) ); 00156 } 00157 }