kitchensync

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