libkdepim

addresseediffalgo.cpp

00001 /*
00002     This file is part of libkdepim.
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 "addresseediffalgo.h"
00023 
00024 using namespace KPIM;
00025 
00026 static bool compareString( const QString &left, const QString &right )
00027 {
00028   if ( left.isEmpty() && right.isEmpty() )
00029     return true;
00030   else
00031     return left == right;
00032 }
00033 
00034 AddresseeDiffAlgo::AddresseeDiffAlgo( const KABC::Addressee &leftAddressee,
00035                               const KABC::Addressee &rightAddressee )
00036   : mLeftAddressee( leftAddressee ), mRightAddressee( rightAddressee )
00037 {
00038 }
00039 
00040 void AddresseeDiffAlgo::run()
00041 {
00042   begin();
00043 
00044   if ( !compareString( mLeftAddressee.uid(), mRightAddressee.uid() ) )
00045     conflictField( KABC::Addressee::uidLabel(), mLeftAddressee.uid(), mRightAddressee.uid() );
00046 
00047   if ( !compareString( mLeftAddressee.name(), mRightAddressee.name() ) )
00048     conflictField( KABC::Addressee::nameLabel(), mLeftAddressee.name(), mRightAddressee.name() );
00049 
00050   if ( !compareString( mLeftAddressee.formattedName(), mRightAddressee.formattedName() ) )
00051     conflictField( KABC::Addressee::formattedNameLabel(), mLeftAddressee.formattedName(), mRightAddressee.formattedName() );
00052 
00053   if ( !compareString( mLeftAddressee.familyName(), mRightAddressee.familyName() ) )
00054     conflictField( KABC::Addressee::familyNameLabel(), mLeftAddressee.familyName(), mRightAddressee.familyName() );
00055 
00056   if ( !compareString( mLeftAddressee.givenName(), mRightAddressee.givenName() ) )
00057     conflictField( KABC::Addressee::givenNameLabel(), mLeftAddressee.givenName(), mRightAddressee.givenName() );
00058 
00059   if ( !compareString( mLeftAddressee.additionalName(), mRightAddressee.additionalName() ) )
00060     conflictField( KABC::Addressee::additionalNameLabel(), mLeftAddressee.additionalName(), mRightAddressee.additionalName() );
00061 
00062   if ( !compareString( mLeftAddressee.prefix(), mRightAddressee.prefix() ) )
00063     conflictField( KABC::Addressee::prefixLabel(), mLeftAddressee.prefix(), mRightAddressee.prefix() );
00064 
00065   if ( !compareString( mLeftAddressee.suffix(), mRightAddressee.suffix() ) )
00066     conflictField( KABC::Addressee::suffixLabel(), mLeftAddressee.suffix(), mRightAddressee.suffix() );
00067 
00068   if ( !compareString( mLeftAddressee.nickName(), mRightAddressee.nickName() ) )
00069     conflictField( KABC::Addressee::nickNameLabel(), mLeftAddressee.nickName(), mRightAddressee.nickName() );
00070 
00071   if ( mLeftAddressee.birthday() != mRightAddressee.birthday() )
00072     conflictField( KABC::Addressee::birthdayLabel(), mLeftAddressee.birthday().toString(),
00073                    mRightAddressee.birthday().toString() );
00074 
00075   if ( !compareString( mLeftAddressee.mailer(), mRightAddressee.mailer() ) )
00076     conflictField( KABC::Addressee::mailerLabel(), mLeftAddressee.mailer(), mRightAddressee.mailer() );
00077 
00078   if ( mLeftAddressee.timeZone() != mRightAddressee.timeZone() )
00079     conflictField( KABC::Addressee::timeZoneLabel(), mLeftAddressee.timeZone().asString(), mRightAddressee.timeZone().asString() );
00080 
00081   if ( mLeftAddressee.geo() != mRightAddressee.geo() )
00082     conflictField( KABC::Addressee::geoLabel(), mLeftAddressee.geo().asString(), mRightAddressee.geo().asString() );
00083 
00084   if ( !compareString( mLeftAddressee.title(), mRightAddressee.title() ) )
00085     conflictField( KABC::Addressee::titleLabel(), mLeftAddressee.title(), mRightAddressee.title() );
00086 
00087   if ( !compareString( mLeftAddressee.role(), mRightAddressee.role() ) )
00088     conflictField( KABC::Addressee::roleLabel(), mLeftAddressee.role(), mRightAddressee.role() );
00089 
00090   if ( !compareString( mLeftAddressee.organization(), mRightAddressee.organization() ) )
00091     conflictField( KABC::Addressee::organizationLabel(), mLeftAddressee.organization(), mRightAddressee.organization() );
00092 
00093   if ( !compareString( mLeftAddressee.note(), mRightAddressee.note() ) )
00094     conflictField( KABC::Addressee::noteLabel(), mLeftAddressee.note(), mRightAddressee.note() );
00095 
00096   if ( !compareString( mLeftAddressee.productId(), mRightAddressee.productId() ) )
00097     conflictField( KABC::Addressee::productIdLabel(), mLeftAddressee.productId(), mRightAddressee.productId() );
00098 
00099   if ( !compareString( mLeftAddressee.sortString(), mRightAddressee.sortString() ) )
00100     conflictField( KABC::Addressee::sortStringLabel(), mLeftAddressee.sortString(), mRightAddressee.sortString() );
00101 
00102   if ( mLeftAddressee.secrecy() != mRightAddressee.secrecy() ) {
00103     conflictField( KABC::Addressee::secrecyLabel(), mLeftAddressee.secrecy().asString(), mRightAddressee.secrecy().asString() );
00104   }
00105   if ( mLeftAddressee.url()!= mRightAddressee.url() )
00106     conflictField( KABC::Addressee::urlLabel(), mLeftAddressee.url().prettyURL(),
00107       mRightAddressee.url().prettyURL() );
00108     
00109   if ( mLeftAddressee.logo() != mRightAddressee.logo() ) {
00110   }
00111 
00112   if ( mLeftAddressee.photo() != mRightAddressee.photo() ) {
00113   }
00114 
00115   diffList( "emails", mLeftAddressee.emails(), mRightAddressee.emails() );
00116 
00117   diffList( "Phone Numbers", mLeftAddressee.phoneNumbers(), mRightAddressee.phoneNumbers() );
00118   diffList( "Addresses", mLeftAddressee.addresses(), mRightAddressee.addresses() );
00119 
00120   end();
00121 }
00122 
00123 QString AddresseeDiffAlgo::toString( const KABC::PhoneNumber &number )
00124 {
00125   return number.number();
00126 }
00127 
00128 QString AddresseeDiffAlgo::toString( const KABC::Address &addr )
00129 {
00130   return addr.formattedAddress();
00131 }
00132 
00133 template <class L>
00134 void AddresseeDiffAlgo::diffList( const QString &id,
00135                                   const QValueList<L> &left, const QValueList<L> &right )
00136 {
00137   for ( uint i = 0; i < left.count(); ++i ) {
00138     if ( right.find( left[ i ] ) == right.end() )
00139       additionalLeftField( id, toString( left[ i ] ) );
00140   }
00141 
00142   for ( uint i = 0; i < right.count(); ++i ) {
00143     if ( left.find( right[ i ] ) == left.end() )
00144       additionalRightField( id, toString( right[ i ] ) );
00145   }
00146 }
KDE Home | KDE Accessibility Home | Description of Access Keys