libtdepim

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 "addresseediffalgo.h"
23 
24 using namespace KPIM;
25 
26 static bool compareString( const TQString &left, const TQString &right )
27 {
28  if ( left.isEmpty() && right.isEmpty() )
29  return true;
30  else
31  return left == right;
32 }
33 
34 AddresseeDiffAlgo::AddresseeDiffAlgo( const TDEABC::Addressee &leftAddressee,
35  const TDEABC::Addressee &rightAddressee )
36  : mLeftAddressee( leftAddressee ), mRightAddressee( rightAddressee )
37 {
38 }
39 
40 void AddresseeDiffAlgo::run()
41 {
42  begin();
43 
44  if ( !compareString( mLeftAddressee.uid(), mRightAddressee.uid() ) )
45  conflictField( TDEABC::Addressee::uidLabel(), mLeftAddressee.uid(), mRightAddressee.uid() );
46 
47  if ( !compareString( mLeftAddressee.name(), mRightAddressee.name() ) )
48  conflictField( TDEABC::Addressee::nameLabel(), mLeftAddressee.name(), mRightAddressee.name() );
49 
50  if ( !compareString( mLeftAddressee.formattedName(), mRightAddressee.formattedName() ) )
51  conflictField( TDEABC::Addressee::formattedNameLabel(), mLeftAddressee.formattedName(), mRightAddressee.formattedName() );
52 
53  if ( !compareString( mLeftAddressee.familyName(), mRightAddressee.familyName() ) )
54  conflictField( TDEABC::Addressee::familyNameLabel(), mLeftAddressee.familyName(), mRightAddressee.familyName() );
55 
56  if ( !compareString( mLeftAddressee.givenName(), mRightAddressee.givenName() ) )
57  conflictField( TDEABC::Addressee::givenNameLabel(), mLeftAddressee.givenName(), mRightAddressee.givenName() );
58 
59  if ( !compareString( mLeftAddressee.additionalName(), mRightAddressee.additionalName() ) )
60  conflictField( TDEABC::Addressee::additionalNameLabel(), mLeftAddressee.additionalName(), mRightAddressee.additionalName() );
61 
62  if ( !compareString( mLeftAddressee.prefix(), mRightAddressee.prefix() ) )
63  conflictField( TDEABC::Addressee::prefixLabel(), mLeftAddressee.prefix(), mRightAddressee.prefix() );
64 
65  if ( !compareString( mLeftAddressee.suffix(), mRightAddressee.suffix() ) )
66  conflictField( TDEABC::Addressee::suffixLabel(), mLeftAddressee.suffix(), mRightAddressee.suffix() );
67 
68  if ( !compareString( mLeftAddressee.nickName(), mRightAddressee.nickName() ) )
69  conflictField( TDEABC::Addressee::nickNameLabel(), mLeftAddressee.nickName(), mRightAddressee.nickName() );
70 
71  if ( mLeftAddressee.birthday() != mRightAddressee.birthday() )
72  conflictField( TDEABC::Addressee::birthdayLabel(), mLeftAddressee.birthday().toString(),
73  mRightAddressee.birthday().toString() );
74 
75  if ( !compareString( mLeftAddressee.mailer(), mRightAddressee.mailer() ) )
76  conflictField( TDEABC::Addressee::mailerLabel(), mLeftAddressee.mailer(), mRightAddressee.mailer() );
77 
78  if ( mLeftAddressee.timeZone() != mRightAddressee.timeZone() )
79  conflictField( TDEABC::Addressee::timeZoneLabel(), mLeftAddressee.timeZone().asString(), mRightAddressee.timeZone().asString() );
80 
81  if ( mLeftAddressee.geo() != mRightAddressee.geo() )
82  conflictField( TDEABC::Addressee::geoLabel(), mLeftAddressee.geo().asString(), mRightAddressee.geo().asString() );
83 
84  if ( !compareString( mLeftAddressee.title(), mRightAddressee.title() ) )
85  conflictField( TDEABC::Addressee::titleLabel(), mLeftAddressee.title(), mRightAddressee.title() );
86 
87  if ( !compareString( mLeftAddressee.role(), mRightAddressee.role() ) )
88  conflictField( TDEABC::Addressee::roleLabel(), mLeftAddressee.role(), mRightAddressee.role() );
89 
90  if ( !compareString( mLeftAddressee.organization(), mRightAddressee.organization() ) )
91  conflictField( TDEABC::Addressee::organizationLabel(), mLeftAddressee.organization(), mRightAddressee.organization() );
92 
93  if ( !compareString( mLeftAddressee.note(), mRightAddressee.note() ) )
94  conflictField( TDEABC::Addressee::noteLabel(), mLeftAddressee.note(), mRightAddressee.note() );
95 
96  if ( !compareString( mLeftAddressee.productId(), mRightAddressee.productId() ) )
97  conflictField( TDEABC::Addressee::productIdLabel(), mLeftAddressee.productId(), mRightAddressee.productId() );
98 
99  if ( !compareString( mLeftAddressee.sortString(), mRightAddressee.sortString() ) )
100  conflictField( TDEABC::Addressee::sortStringLabel(), mLeftAddressee.sortString(), mRightAddressee.sortString() );
101 
102  if ( mLeftAddressee.secrecy() != mRightAddressee.secrecy() ) {
103  conflictField( TDEABC::Addressee::secrecyLabel(), mLeftAddressee.secrecy().asString(), mRightAddressee.secrecy().asString() );
104  }
105  if ( mLeftAddressee.url()!= mRightAddressee.url() )
106  conflictField( TDEABC::Addressee::urlLabel(), mLeftAddressee.url().prettyURL(),
107  mRightAddressee.url().prettyURL() );
108 
109  if ( mLeftAddressee.logo() != mRightAddressee.logo() ) {
110  }
111 
112  if ( mLeftAddressee.photo() != mRightAddressee.photo() ) {
113  }
114 
115  diffList( "emails", mLeftAddressee.emails(), mRightAddressee.emails() );
116 
117  diffList( "Phone Numbers", mLeftAddressee.phoneNumbers(), mRightAddressee.phoneNumbers() );
118  diffList( "Addresses", mLeftAddressee.addresses(), mRightAddressee.addresses() );
119 
120  end();
121 }
122 
123 TQString AddresseeDiffAlgo::toString( const TDEABC::PhoneNumber &number )
124 {
125  return number.number();
126 }
127 
128 TQString AddresseeDiffAlgo::toString( const TDEABC::Address &addr )
129 {
130  return addr.formattedAddress();
131 }
132 
133 template <class L>
134 void AddresseeDiffAlgo::diffList( const TQString &id,
135  const TQValueList<L> &left, const TQValueList<L> &right )
136 {
137  for ( uint i = 0; i < left.count(); ++i ) {
138  if ( right.find( left[ i ] ) == right.end() )
139  additionalLeftField( id, toString( left[ i ] ) );
140  }
141 
142  for ( uint i = 0; i < right.count(); ++i ) {
143  if ( left.find( right[ i ] ) == left.end() )
144  additionalRightField( id, toString( right[ i ] ) );
145  }
146 }
TDEPIM classes for drag and drop of mails.