summaryrefslogtreecommitdiffabout
path: root/kabc/addressee.cpp
Unidiff
Diffstat (limited to 'kabc/addressee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index e8e440c..9994e29 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -10,769 +10,769 @@
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 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 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36#include <kidmanager.h> 36#include <kidmanager.h>
37//US 37//US
38#include <kstandarddirs.h> 38#include <kstandarddirs.h>
39#include <libkcal/syncdefines.h> 39#include <libkcal/syncdefines.h>
40 40
41//US #include "resource.h" 41//US #include "resource.h"
42#include "addressee.h" 42#include "addressee.h"
43 43
44using namespace KABC; 44using namespace KABC;
45 45
46static bool matchBinaryPattern( int value, int pattern ); 46static bool matchBinaryPattern( int value, int pattern );
47static bool matchBinaryPatternA( int value, int pattern ); 47static bool matchBinaryPatternA( int value, int pattern );
48static bool matchBinaryPatternP( int value, int pattern ); 48static bool matchBinaryPatternP( int value, int pattern );
49 49
50struct Addressee::AddresseeData : public KShared 50struct Addressee::AddresseeData : public KShared
51{ 51{
52 QString uid; 52 QString uid;
53 QString name; 53 QString name;
54 QString formattedName; 54 QString formattedName;
55 QString familyName; 55 QString familyName;
56 QString givenName; 56 QString givenName;
57 QString additionalName; 57 QString additionalName;
58 QString prefix; 58 QString prefix;
59 QString suffix; 59 QString suffix;
60 QString nickName; 60 QString nickName;
61 QDateTime birthday; 61 QDateTime birthday;
62 QString mailer; 62 QString mailer;
63 TimeZone timeZone; 63 TimeZone timeZone;
64 Geo geo; 64 Geo geo;
65 QString title; 65 QString title;
66 QString role; 66 QString role;
67 QString organization; 67 QString organization;
68 QString note; 68 QString note;
69 QString productId; 69 QString productId;
70 QDateTime revision; 70 QDateTime revision;
71 QString sortString; 71 QString sortString;
72 QString externalUID; 72 QString externalUID;
73 QString originalExternalUID; 73 QString originalExternalUID;
74 KURL url; 74 KURL url;
75 Secrecy secrecy; 75 Secrecy secrecy;
76 Picture logo; 76 Picture logo;
77 Picture photo; 77 Picture photo;
78 Sound sound; 78 Sound sound;
79 Agent agent; 79 Agent agent;
80 QString mExternalId; 80 QString mExternalId;
81 PhoneNumber::List phoneNumbers; 81 PhoneNumber::List phoneNumbers;
82 Address::List addresses; 82 Address::List addresses;
83 Key::List keys; 83 Key::List keys;
84 QStringList emails; 84 QStringList emails;
85 QStringList categories; 85 QStringList categories;
86 QStringList custom; 86 QStringList custom;
87 int mTempSyncStat; 87 int mTempSyncStat;
88 Resource *resource; 88 Resource *resource;
89 89
90 bool empty :1; 90 bool empty :1;
91 bool changed :1; 91 bool changed :1;
92 bool tagged :1; 92 bool tagged :1;
93}; 93};
94 94
95Addressee::Addressee() 95Addressee::Addressee()
96{ 96{
97 mData = new AddresseeData; 97 mData = new AddresseeData;
98 mData->empty = true; 98 mData->empty = true;
99 mData->changed = false; 99 mData->changed = false;
100 mData->resource = 0; 100 mData->resource = 0;
101 mData->mExternalId = ":"; 101 mData->mExternalId = ":";
102 mData->revision = QDateTime ( QDate( 2003,1,1)); 102 mData->revision = QDateTime ( QDate( 2003,1,1));
103 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 103 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
104} 104}
105 105
106Addressee::~Addressee() 106Addressee::~Addressee()
107{ 107{
108} 108}
109 109
110Addressee::Addressee( const Addressee &a ) 110Addressee::Addressee( const Addressee &a )
111{ 111{
112 mData = a.mData; 112 mData = a.mData;
113} 113}
114 114
115Addressee &Addressee::operator=( const Addressee &a ) 115Addressee &Addressee::operator=( const Addressee &a )
116{ 116{
117 mData = a.mData; 117 mData = a.mData;
118 return (*this); 118 return (*this);
119} 119}
120 120
121Addressee Addressee::copy() 121Addressee Addressee::copy()
122{ 122{
123 Addressee a; 123 Addressee a;
124 *(a.mData) = *mData; 124 *(a.mData) = *mData;
125 return a; 125 return a;
126} 126}
127 127
128void Addressee::detach() 128void Addressee::detach()
129{ 129{
130 if ( mData.count() == 1 ) return; 130 if ( mData.count() == 1 ) return;
131 *this = copy(); 131 *this = copy();
132} 132}
133 133
134bool Addressee::operator==( const Addressee &a ) const 134bool Addressee::operator==( const Addressee &a ) const
135{ 135{
136 if ( uid() != a.uid() ) return false; 136 if ( uid() != a.uid() ) return false;
137 if ( mData->name != a.mData->name ) return false; 137 if ( mData->name != a.mData->name ) return false;
138 if ( mData->formattedName != a.mData->formattedName ) return false; 138 if ( mData->formattedName != a.mData->formattedName ) return false;
139 if ( mData->familyName != a.mData->familyName ) return false; 139 if ( mData->familyName != a.mData->familyName ) return false;
140 if ( mData->givenName != a.mData->givenName ) return false; 140 if ( mData->givenName != a.mData->givenName ) return false;
141 if ( mData->additionalName != a.mData->additionalName ) return false; 141 if ( mData->additionalName != a.mData->additionalName ) return false;
142 if ( mData->prefix != a.mData->prefix ) return false; 142 if ( mData->prefix != a.mData->prefix ) return false;
143 if ( mData->suffix != a.mData->suffix ) return false; 143 if ( mData->suffix != a.mData->suffix ) return false;
144 if ( mData->nickName != a.mData->nickName ) return false; 144 if ( mData->nickName != a.mData->nickName ) return false;
145 if ( mData->birthday != a.mData->birthday ) return false; 145 if ( mData->birthday != a.mData->birthday ) return false;
146 if ( mData->mailer != a.mData->mailer ) return false; 146 if ( mData->mailer != a.mData->mailer ) return false;
147 if ( mData->timeZone != a.mData->timeZone ) return false; 147 if ( mData->timeZone != a.mData->timeZone ) return false;
148 if ( mData->geo != a.mData->geo ) return false; 148 if ( mData->geo != a.mData->geo ) return false;
149 if ( mData->title != a.mData->title ) return false; 149 if ( mData->title != a.mData->title ) return false;
150 if ( mData->role != a.mData->role ) return false; 150 if ( mData->role != a.mData->role ) return false;
151 if ( mData->organization != a.mData->organization ) return false; 151 if ( mData->organization != a.mData->organization ) return false;
152 if ( mData->note != a.mData->note ) return false; 152 if ( mData->note != a.mData->note ) return false;
153 if ( mData->productId != a.mData->productId ) return false; 153 if ( mData->productId != a.mData->productId ) return false;
154 //if ( mData->revision != a.mData->revision ) return false; 154 //if ( mData->revision != a.mData->revision ) return false;
155 if ( mData->sortString != a.mData->sortString ) return false; 155 if ( mData->sortString != a.mData->sortString ) return false;
156 if ( mData->secrecy != a.mData->secrecy ) return false; 156 if ( mData->secrecy != a.mData->secrecy ) return false;
157 if ( mData->logo != a.mData->logo ) return false; 157 if ( mData->logo != a.mData->logo ) return false;
158 if ( mData->photo != a.mData->photo ) return false; 158 if ( mData->photo != a.mData->photo ) return false;
159 if ( mData->sound != a.mData->sound ) return false; 159 if ( mData->sound != a.mData->sound ) return false;
160 if ( mData->agent != a.mData->agent ) return false; 160 if ( mData->agent != a.mData->agent ) return false;
161 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 161 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
162 ( mData->url != a.mData->url ) ) return false; 162 ( mData->url != a.mData->url ) ) return false;
163 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 163 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
164 if ( mData->addresses != a.mData->addresses ) return false; 164 if ( mData->addresses != a.mData->addresses ) return false;
165 if ( mData->keys != a.mData->keys ) return false; 165 if ( mData->keys != a.mData->keys ) return false;
166 if ( mData->emails != a.mData->emails ) return false; 166 if ( mData->emails != a.mData->emails ) return false;
167 if ( mData->categories != a.mData->categories ) return false; 167 if ( mData->categories != a.mData->categories ) return false;
168 if ( mData->custom != a.mData->custom ) return false; 168 if ( mData->custom != a.mData->custom ) return false;
169 169
170 return true; 170 return true;
171} 171}
172 172
173bool Addressee::operator!=( const Addressee &a ) const 173bool Addressee::operator!=( const Addressee &a ) const
174{ 174{
175 return !( a == *this ); 175 return !( a == *this );
176} 176}
177 177
178bool Addressee::isEmpty() const 178bool Addressee::isEmpty() const
179{ 179{
180 return mData->empty; 180 return mData->empty;
181} 181}
182ulong Addressee::getCsum4List( const QStringList & attList) 182ulong Addressee::getCsum4List( const QStringList & attList)
183{ 183{
184 int max = attList.count(); 184 int max = attList.count();
185 ulong cSum = 0; 185 ulong cSum = 0;
186 int j,k,i; 186 int j,k,i;
187 int add; 187 int add;
188 for ( i = 0; i < max ; ++i ) { 188 for ( i = 0; i < max ; ++i ) {
189 QString s = attList[i]; 189 QString s = attList[i];
190 if ( ! s.isEmpty() ){ 190 if ( ! s.isEmpty() ){
191 j = s.length(); 191 j = s.length();
192 for ( k = 0; k < j; ++k ) { 192 for ( k = 0; k < j; ++k ) {
193 int mul = k +1; 193 int mul = k +1;
194 add = s[k].unicode (); 194 add = s[k].unicode ();
195 if ( k < 16 ) 195 if ( k < 16 )
196 mul = mul * mul; 196 mul = mul * mul;
197 int ii = i+1; 197 int ii = i+1;
198 add = add * mul *ii*ii*ii; 198 add = add * mul *ii*ii*ii;
199 cSum += add; 199 cSum += add;
200 //qDebug("csum: %d %d %d", i,k,cSum); 200 //qDebug("csum: %d %d %d", i,k,cSum);
201 } 201 }
202 } 202 }
203 203
204 } 204 }
205 //QString dump = attList.join(","); 205 //QString dump = attList.join(",");
206 //qDebug("csum: %d %s", cSum,dump.latin1()); 206 //qDebug("csum: %d %s", cSum,dump.latin1());
207 207
208 return cSum; 208 return cSum;
209 209
210} 210}
211void Addressee::computeCsum(const QString &dev) 211void Addressee::computeCsum(const QString &dev)
212{ 212{
213 QStringList l; 213 QStringList l;
214 //if ( !mData->name.isEmpty() ) l.append(mData->name); 214 //if ( !mData->name.isEmpty() ) l.append(mData->name);
215 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 215 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
216 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 216 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
217 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 217 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
218 if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName ); 218 if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName );
219 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 219 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
220 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 220 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
221 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 221 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
222 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 222 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
223 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 223 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
224 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 224 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
225 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 225 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
226 if ( !mData->title .isEmpty() ) l.append( mData->title ); 226 if ( !mData->title .isEmpty() ) l.append( mData->title );
227 if ( !mData->role.isEmpty() ) l.append( mData->role ); 227 if ( !mData->role.isEmpty() ) l.append( mData->role );
228 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 228 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
229 if ( !mData->note.isEmpty() ) l.append( mData->note ); 229 if ( !mData->note.isEmpty() ) l.append( mData->note );
230 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 230 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
231 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 231 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
232 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 232 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
233 if ( !mData->logo.undefined() ) { 233 if ( !mData->logo.undefined() ) {
234 if ( !mData->logo.isIntern() ) 234 if ( !mData->logo.isIntern() )
235 l.append( mData->logo.url() ); 235 l.append( mData->logo.url() );
236 else 236 else
237 l.append( QString::number(mData->logo.data().width()* mData->logo.data().height())); 237 l.append( QString::number(mData->logo.data().width()* mData->logo.data().height()));
238 } else { 238 } else {
239 l.append( "nologo"); 239 l.append( "nologo");
240 } 240 }
241 if ( !mData->photo.undefined() ) { 241 if ( !mData->photo.undefined() ) {
242 if ( !mData->photo.isIntern() ) 242 if ( !mData->photo.isIntern() )
243 l.append( mData->photo.url() ); 243 l.append( mData->photo.url() );
244 else 244 else
245 l.append( QString::number(mData->photo.data().width()* mData->photo.data().height())); 245 l.append( QString::number(mData->photo.data().width()* mData->photo.data().height()));
246 } else { 246 } else {
247 l.append( "nophoto"); 247 l.append( "nophoto");
248 } 248 }
249#if 0 249#if 0
250 if ( !mData->sound.undefined() ) { 250 if ( !mData->sound.undefined() ) {
251 if ( !mData->sound.isIntern() ) 251 if ( !mData->sound.isIntern() )
252 l.append( mData->sound.url() ); 252 l.append( mData->sound.url() );
253 else 253 else
254 l.append( QString(mData->sound.data().with()* mData->sound.data().height())); 254 l.append( QString(mData->sound.data().with()* mData->sound.data().height()));
255 } else { 255 } else {
256 l.append( "nosound"); 256 l.append( "nosound");
257 } 257 }
258#endif 258#endif
259 //if ( !mData->agent.isEmpty() ) l.append( ); 259 //if ( !mData->agent.isEmpty() ) l.append( );
260 if ( mData->url.isValid() ) 260 if ( mData->url.isValid() )
261 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 261 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
262 KABC::PhoneNumber::List phoneNumbers; 262 KABC::PhoneNumber::List phoneNumbers;
263 KABC::PhoneNumber::List::Iterator phoneIter; 263 KABC::PhoneNumber::List::Iterator phoneIter;
264 264
265 QStringList t; 265 QStringList t;
266 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 266 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
267 ++phoneIter ) 267 ++phoneIter )
268 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 268 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
269 t.sort(); 269 t.sort();
270 uint iii; 270 uint iii;
271 for ( iii = 0; iii < t.count(); ++iii) 271 for ( iii = 0; iii < t.count(); ++iii)
272 l.append( t[iii] ); 272 l.append( t[iii] );
273 t = mData->emails; 273 t = mData->emails;
274 t.sort(); 274 t.sort();
275 for ( iii = 0; iii < t.count(); ++iii) 275 for ( iii = 0; iii < t.count(); ++iii)
276 l.append( t[iii] ); 276 l.append( t[iii] );
277 t = mData->categories; 277 t = mData->categories;
278 t.sort(); 278 t.sort();
279 for ( iii = 0; iii < t.count(); ++iii) 279 for ( iii = 0; iii < t.count(); ++iii)
280 l.append( t[iii] ); 280 l.append( t[iii] );
281 t = mData->custom; 281 t = mData->custom;
282 t.sort(); 282 t.sort();
283 for ( iii = 0; iii < t.count(); ++iii) 283 for ( iii = 0; iii < t.count(); ++iii)
284 if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { 284 if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) {
285 int find = t[iii].find (':')+1; 285 int find = t[iii].find (':')+1;
286 //qDebug("lennnn %d %d ", find, t[iii].length()); 286 //qDebug("lennnn %d %d ", find, t[iii].length());
287 if ( find < t[iii].length()) 287 if ( find < t[iii].length())
288 l.append( t[iii] ); 288 l.append( t[iii] );
289 289
290 } 290 }
291 KABC::Address::List::Iterator addressIter; 291 KABC::Address::List::Iterator addressIter;
292 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 292 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
293 ++addressIter ) { 293 ++addressIter ) {
294 t = (*addressIter).asList(); 294 t = (*addressIter).asList();
295 t.sort(); 295 t.sort();
296 for ( iii = 0; iii < t.count(); ++iii) 296 for ( iii = 0; iii < t.count(); ++iii)
297 l.append( t[iii] ); 297 l.append( t[iii] );
298 } 298 }
299 uint cs = getCsum4List(l); 299 uint cs = getCsum4List(l);
300 300
301#if 0 301#if 0
302 for ( iii = 0; iii < l.count(); ++iii) 302 for ( iii = 0; iii < l.count(); ++iii)
303 qDebug("%d***%s***",iii,l[iii].latin1()); 303 qDebug("%d***%s***",iii,l[iii].latin1());
304 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 304 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
305#endif 305#endif
306 306
307 307
308 setCsum( dev, QString::number (cs )); 308 setCsum( dev, QString::number (cs ));
309} 309}
310bool Addressee::matchAddress( QRegExp* re ) const 310bool Addressee::matchAddress( QRegExp* re ) const
311{ 311{
312 KABC::Address::List::Iterator addressIter; 312 KABC::Address::List::Iterator addressIter;
313 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 313 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
314 ++addressIter ) { 314 ++addressIter ) {
315 if ( (*addressIter).matchAddress( re ) ) 315 if ( (*addressIter).matchAddress( re ) )
316 return true; 316 return true;
317 } 317 }
318 return false; 318 return false;
319} 319}
320bool Addressee::matchPhoneNumber( QRegExp* re ) const 320bool Addressee::matchPhoneNumber( QRegExp* re ) const
321{ 321{
322 KABC::PhoneNumber::List::Iterator phoneIter; 322 KABC::PhoneNumber::List::Iterator phoneIter;
323 323
324 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) { 324 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) {
325#if QT_VERSION >= 0x030000 325#if QT_VERSION >= 0x030000
326 if (re->search( (*phoneIter).number() ) == 0) 326 if (re->search( (*phoneIter).number() ) == 0)
327#else 327#else
328 if (re->match( (*phoneIter).number() ) == 0) 328 if (re->match( (*phoneIter).number() ) == 0)
329#endif 329#endif
330 return true; 330 return true;
331 331
332 } 332 }
333 return false; 333 return false;
334 334
335} 335}
336void Addressee::mergeOLContact( const Addressee& ad ) 336void Addressee::mergeOLContact( const Addressee& ad )
337{ 337{
338 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 338 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
339 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 339 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
340 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 340 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
341 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 341 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
342 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; 342 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
343 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; 343 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
344 if ( !mData->sound.isIntern() ) { 344 if ( !mData->sound.isIntern() ) {
345 if ( mData->sound.url().isEmpty() ) { 345 if ( mData->sound.url().isEmpty() ) {
346 mData->sound = ad.mData->sound; 346 mData->sound = ad.mData->sound;
347 } 347 }
348 } 348 }
349 if ( !mData->agent.isIntern() ) { 349 if ( !mData->agent.isIntern() ) {
350 if ( mData->agent.url().isEmpty() ) { 350 if ( mData->agent.url().isEmpty() ) {
351 mData->agent = ad.mData->agent; 351 mData->agent = ad.mData->agent;
352 } 352 }
353 } 353 }
354 { 354 {
355 Key::List::Iterator itA; 355 Key::List::Iterator itA;
356 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { 356 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
357 bool found = false; 357 bool found = false;
358 Key::List::Iterator it; 358 Key::List::Iterator it;
359 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 359 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
360 if ( (*it) == (*itA)) { 360 if ( (*it) == (*itA)) {
361 found = true; 361 found = true;
362 break; 362 break;
363 363
364 } 364 }
365 } 365 }
366 if ( ! found ) { 366 if ( ! found ) {
367 mData->keys.append( *itA ); 367 mData->keys.append( *itA );
368 } 368 }
369 } 369 }
370 } 370 }
371 371
372 KABC::Address addthis = otherAddress(); 372 KABC::Address addthis = otherAddress();
373 KABC::Address addother = ad.otherAddress(); 373 KABC::Address addother = ad.otherAddress();
374 if ( !addthis.isEmpty() && !addother.isEmpty() ) 374 if ( !addthis.isEmpty() && !addother.isEmpty() )
375 addthis.setType( addother.type() ); 375 addthis.setType( addother.type() );
376 //qDebug("merge contact %s ", ad.uid().latin1()); 376 //qDebug("merge contact %s ", ad.uid().latin1());
377 setUid( ad.uid() ); 377 setUid( ad.uid() );
378 setRevision( ad.revision() ); 378 setRevision( ad.revision() );
379 379
380 380
381} 381}
382 382
383void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 383void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
384{ 384{
385 // merge all standard non-outlook fields. 385 // merge all standard non-outlook fields.
386 //if isSubSet (e.g. mobile phone sync) merge all fields 386 //if isSubSet (e.g. mobile phone sync) merge all fields
387 387
388 detach(); 388 detach();
389 if ( isSubSet ) { 389 if ( isSubSet ) {
390 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 390 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
391 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 391 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
392 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 392 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
393 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 393 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
394 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 394 if ( mData->additionalName.isEmpty() ) mData->additionalName = ad.mData->additionalName;
395 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 395 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
396 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 396 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
397 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 397 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
398 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 398 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
399 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 399 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
400 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 400 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
401 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 401 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
402 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 402 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
403 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 403 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
404 if ( !mData->birthday.isValid() ) 404 if ( !mData->birthday.isValid() )
405 if ( ad.mData->birthday.isValid()) 405 if ( ad.mData->birthday.isValid())
406 mData->birthday = ad.mData->birthday; 406 mData->birthday = ad.mData->birthday;
407 407
408 } 408 }
409 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 409 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
410 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 410 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
411 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 411 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
412 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 412 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
413 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 413 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
414 QStringList t; 414 QStringList t;
415 QStringList tAD; 415 QStringList tAD;
416 uint iii; 416 uint iii;
417 417
418 // ********** phone numbers 418 // ********** phone numbers
419 if ( isSubSet ) { 419 if ( isSubSet ) {
420 PhoneNumber::List phoneAD = ad.phoneNumbers(); 420 PhoneNumber::List phoneAD = ad.phoneNumbers();
421 PhoneNumber::List::Iterator phoneItAD; 421 PhoneNumber::List::Iterator phoneItAD;
422 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 422 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
423 bool found = false; 423 bool found = false;
424 PhoneNumber::List::Iterator it; 424 PhoneNumber::List::Iterator it;
425 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 425 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
426 if ( ( *phoneItAD ).contains( (*it) ) ) { 426 if ( ( *phoneItAD ).contains( (*it) ) ) {
427 found = true; 427 found = true;
428 (*it).setType( ( *phoneItAD ).type() ); 428 (*it).setType( ( *phoneItAD ).type() );
429 (*it).setNumber( ( *phoneItAD ).number() ); 429 (*it).setNumber( ( *phoneItAD ).number() );
430 break; 430 break;
431 } 431 }
432 } 432 }
433 // if ( isSubSet && ! found ) 433 // if ( isSubSet && ! found )
434 if ( ! found ) // LR try this one... 434 if ( ! found ) // LR try this one...
435 mData->phoneNumbers.append( *phoneItAD ); 435 mData->phoneNumbers.append( *phoneItAD );
436 } 436 }
437 } else { 437 } else {
438 PhoneNumber::List phoneAD = ad.phoneNumbers(); 438 PhoneNumber::List phoneAD = ad.phoneNumbers();
439 PhoneNumber::List::Iterator phoneItAD; 439 PhoneNumber::List::Iterator phoneItAD;
440 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 440 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
441 bool found = false; 441 bool found = false;
442 PhoneNumber::List::Iterator it; 442 PhoneNumber::List::Iterator it;
443 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 443 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
444 if ( ( *phoneItAD ).contains( (*it) ) ) { 444 if ( ( *phoneItAD ).contains( (*it) ) ) {
445 found = true; 445 found = true;
446 (*it).setType( ( *phoneItAD ).type() ); 446 (*it).setType( ( *phoneItAD ).type() );
447 (*it).setNumber( ( *phoneItAD ).number() ); 447 (*it).setNumber( ( *phoneItAD ).number() );
448 break; 448 break;
449 } 449 }
450 } 450 }
451 if ( ! found ) { // append numbers which do not have work or home type 451 if ( ! found ) { // append numbers which do not have work or home type
452 if ( ! ( ( *phoneItAD ).type() & (PhoneNumber::Work | PhoneNumber::Home) ) ) 452 if ( ! ( ( *phoneItAD ).type() & (PhoneNumber::Work | PhoneNumber::Home) ) )
453 mData->phoneNumbers.append( *phoneItAD ); 453 mData->phoneNumbers.append( *phoneItAD );
454 } 454 }
455 } 455 }
456 } 456 }
457 if ( isSubSet ) { 457 if ( isSubSet ) {
458 // ************* emails; 458 // ************* emails;
459 t = mData->emails; 459 t = mData->emails;
460 tAD = ad.mData->emails; 460 tAD = ad.mData->emails;
461 for ( iii = 0; iii < tAD.count(); ++iii) 461 for ( iii = 0; iii < tAD.count(); ++iii)
462 if ( !t.contains(tAD[iii] ) ) 462 if ( !t.contains(tAD[iii] ) )
463 mData->emails.append( tAD[iii] ); 463 mData->emails.append( tAD[iii] );
464 } 464 }
465 465
466 // ************* categories; 466 // ************* categories;
467 if ( isSubSet ) { 467 if ( isSubSet ) {
468 t = mData->categories; 468 t = mData->categories;
469 tAD = ad.mData->categories; 469 tAD = ad.mData->categories;
470 for ( iii = 0; iii < tAD.count(); ++iii) 470 for ( iii = 0; iii < tAD.count(); ++iii)
471 if ( !t.contains(tAD[iii] ) ) 471 if ( !t.contains(tAD[iii] ) )
472 mData->categories.append( tAD[iii] ); 472 mData->categories.append( tAD[iii] );
473 } 473 }
474 QStringList::ConstIterator it; 474 QStringList::ConstIterator it;
475 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { 475 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
476 QString qualifiedName = (*it).left( (*it).find( ":" )); 476 QString qualifiedName = (*it).left( (*it).find( ":" ));
477 bool found = false; 477 bool found = false;
478 QStringList::ConstIterator itL; 478 QStringList::ConstIterator itL;
479 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 479 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
480 if ( (*itL).startsWith( qualifiedName ) ) { 480 if ( (*itL).startsWith( qualifiedName ) ) {
481 found = true; 481 found = true;
482 break; 482 break;
483 } 483 }
484 } 484 }
485 if ( ! found ) { 485 if ( ! found ) {
486 mData->custom.append( *it ); 486 mData->custom.append( *it );
487 } 487 }
488 } 488 }
489 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; 489 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
490 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; 490 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
491 if ( !mData->sound.isIntern() ) { 491 if ( !mData->sound.isIntern() ) {
492 if ( mData->sound.url().isEmpty() ) { 492 if ( mData->sound.url().isEmpty() ) {
493 mData->sound = ad.mData->sound; 493 mData->sound = ad.mData->sound;
494 } 494 }
495 } 495 }
496 if ( !mData->agent.isIntern() ) { 496 if ( !mData->agent.isIntern() ) {
497 if ( mData->agent.url().isEmpty() ) { 497 if ( mData->agent.url().isEmpty() ) {
498 mData->agent = ad.mData->agent; 498 mData->agent = ad.mData->agent;
499 } 499 }
500 } 500 }
501 { 501 {
502 Key::List::Iterator itA; 502 Key::List::Iterator itA;
503 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { 503 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
504 bool found = false; 504 bool found = false;
505 Key::List::Iterator it; 505 Key::List::Iterator it;
506 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 506 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
507 if ( (*it) == (*itA)) { 507 if ( (*it) == (*itA)) {
508 found = true; 508 found = true;
509 break; 509 break;
510 510
511 } 511 }
512 } 512 }
513 if ( ! found ) { 513 if ( ! found ) {
514 mData->keys.append( *itA ); 514 mData->keys.append( *itA );
515 } 515 }
516 } 516 }
517 } 517 }
518 if ( isSubSet ) { 518 if ( isSubSet ) {
519 KABC::Address::List::Iterator addressIterA; 519 KABC::Address::List::Iterator addressIterA;
520 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { 520 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
521 bool found = false; 521 bool found = false;
522 KABC::Address::List::Iterator addressIter; 522 KABC::Address::List::Iterator addressIter;
523 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 523 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
524 ++addressIter ) { 524 ++addressIter ) {
525 if ( (*addressIter) == (*addressIterA)) { 525 if ( (*addressIter) == (*addressIterA)) {
526 found = true; 526 found = true;
527 (*addressIter).setType( (*addressIterA).type() ); 527 (*addressIter).setType( (*addressIterA).type() );
528 break; 528 break;
529 } 529 }
530 530
531 } 531 }
532 if ( isSubSet && ! found ) { 532 if ( isSubSet && ! found ) {
533 mData->addresses.append( *addressIterA ); 533 mData->addresses.append( *addressIterA );
534 } 534 }
535 } 535 }
536 } 536 }
537 //qDebug("merge contact %s ", ad.uid().latin1()); 537 //qDebug("merge contact %s ", ad.uid().latin1());
538 setUid( ad.uid() ); 538 setUid( ad.uid() );
539 setRevision( ad.revision() ); 539 setRevision( ad.revision() );
540} 540}
541 541
542bool Addressee::removeVoice() 542bool Addressee::removeVoice()
543{ 543{
544 PhoneNumber::List phoneN = phoneNumbers(); 544 PhoneNumber::List phoneN = phoneNumbers();
545 PhoneNumber::List::Iterator phoneIt; 545 PhoneNumber::List::Iterator phoneIt;
546 bool found = false; 546 bool found = false;
547 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 547 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
548 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 548 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
549 if ((*phoneIt).type() - PhoneNumber::Voice ) { 549 if ((*phoneIt).type() - PhoneNumber::Voice ) {
550 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 550 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
551 insertPhoneNumber( (*phoneIt) ); 551 insertPhoneNumber( (*phoneIt) );
552 found = true; 552 found = true;
553 } 553 }
554 } 554 }
555 555
556 } 556 }
557 return found; 557 return found;
558} 558}
559 559
560bool Addressee::containsAdr(const Addressee& ad ) 560bool Addressee::containsAdr(const Addressee& ad )
561{ 561{
562 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; 562 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
563 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; 563 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
564 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; 564 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
565 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; 565 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
566 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; 566 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
567 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; 567 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
568 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; 568 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
569 569
570 // compare phone numbers 570 // compare phone numbers
571 PhoneNumber::List phoneN = ad.phoneNumbers(); 571 PhoneNumber::List phoneN = ad.phoneNumbers();
572 PhoneNumber::List::Iterator phoneIt; 572 PhoneNumber::List::Iterator phoneIt;
573 bool found = false; 573 bool found = false;
574 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 574 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
575 bool found = false; 575 bool found = false;
576 PhoneNumber::List phoneL = ad.phoneNumbers(); 576 PhoneNumber::List phoneL = ad.phoneNumbers();
577 PhoneNumber::List::Iterator phoneItL; 577 PhoneNumber::List::Iterator phoneItL;
578 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 578 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
579 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 579 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
580 found = true; 580 found = true;
581 break; 581 break;
582 } 582 }
583 } 583 }
584 if ( ! found ) 584 if ( ! found )
585 return false; 585 return false;
586 } 586 }
587 return true; 587 return true;
588 588
589} 589}
590void Addressee::simplifyAddresses() 590void Addressee::simplifyAddresses()
591{ 591{
592 592
593 593
594 Address::List list; 594 Address::List list;
595 Address::List::Iterator it; 595 Address::List::Iterator it;
596 Address::List::Iterator it2; 596 Address::List::Iterator it2;
597 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 597 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
598 it2 = it; 598 it2 = it;
599 ++it2; 599 ++it2;
600 for( ; it2 != mData->addresses.end(); ++it2 ) { 600 for( ; it2 != mData->addresses.end(); ++it2 ) {
601 if ( (*it) == (*it2) ) { 601 if ( (*it) == (*it2) ) {
602 list.append( *it ); 602 list.append( *it );
603 break; 603 break;
604 } 604 }
605 } 605 }
606 } 606 }
607 for( it = list.begin(); it != list.end(); ++it ) { 607 for( it = list.begin(); it != list.end(); ++it ) {
608 removeAddress( (*it) ); 608 removeAddress( (*it) );
609 } 609 }
610 610
611 list.clear(); 611 list.clear();
612 int max = 2; 612 int max = 2;
613 if ( mData->url.isValid() ) 613 if ( mData->url.isValid() )
614 max = 1; 614 max = 1;
615 if ( mData->addresses.count() <= max ) return ; 615 if ( mData->addresses.count() <= max ) return ;
616 int count = 0; 616 int count = 0;
617 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 617 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
618 if ( count >= max ) 618 if ( count >= max )
619 list.append( *it ); 619 list.append( *it );
620 ++count; 620 ++count;
621 } 621 }
622 for( it = list.begin(); it != list.end(); ++it ) { 622 for( it = list.begin(); it != list.end(); ++it ) {
623 removeAddress( (*it) ); 623 removeAddress( (*it) );
624 } 624 }
625} 625}
626 626
627// removes all emails but the first 627// removes all emails but the first
628// needed by phone sync 628// needed by phone sync
629void Addressee::simplifyEmails() 629void Addressee::simplifyEmails()
630{ 630{
631 if ( mData->emails.count() == 0 ) return ; 631 if ( mData->emails.count() == 0 ) return ;
632 QString email = mData->emails.first(); 632 QString email = mData->emails.first();
633 detach(); 633 detach();
634 mData->emails.clear(); 634 mData->emails.clear();
635 mData->emails.append( email ); 635 mData->emails.append( email );
636} 636}
637void Addressee::makePhoneNumbersOLcompatible() 637void Addressee::makePhoneNumbersOLcompatible()
638{ 638{
639 KABC::PhoneNumber::List::Iterator phoneIter; 639 KABC::PhoneNumber::List::Iterator phoneIter;
640 KABC::PhoneNumber::List::Iterator phoneIter2; 640 KABC::PhoneNumber::List::Iterator phoneIter2;
641 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 641 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
642 ++phoneIter ) { 642 ++phoneIter ) {
643 ( *phoneIter ).makeCompat(); 643 ( *phoneIter ).makeCompat();
644 } 644 }
645 int hasHome = hasPhoneNumberType( PhoneNumber::Home | PhoneNumber::Pref ); 645 int hasHome = hasPhoneNumberType( PhoneNumber::Home | PhoneNumber::Pref );
646 int hasHome2 = hasPhoneNumberType( PhoneNumber::Home ); 646 int hasHome2 = hasPhoneNumberType( PhoneNumber::Home );
647 int hasWork = hasPhoneNumberType( PhoneNumber::Work | PhoneNumber::Pref ); 647 int hasWork = hasPhoneNumberType( PhoneNumber::Work | PhoneNumber::Pref );
648 int hasWork2 = hasPhoneNumberType( PhoneNumber::Work ); 648 int hasWork2 = hasPhoneNumberType( PhoneNumber::Work );
649 int hasCell = hasPhoneNumberType( PhoneNumber::Cell ); 649 int hasCell = hasPhoneNumberType( PhoneNumber::Cell );
650 int hasCell2 = hasPhoneNumberType( PhoneNumber::Car ); 650 int hasCell2 = hasPhoneNumberType( PhoneNumber::Car );
651 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 651 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
652 ++phoneIter ) { 652 ++phoneIter ) {
653 if ( (*phoneIter).type() == PhoneNumber::Home && ! hasHome ) { 653 if ( (*phoneIter).type() == PhoneNumber::Home && ! hasHome ) {
654 (*phoneIter).setType( PhoneNumber::Home | PhoneNumber::Pref ); 654 (*phoneIter).setType( PhoneNumber::Home | PhoneNumber::Pref );
655 ++hasHome; 655 ++hasHome;
656 if ( hasHome2 ) --hasHome2; 656 if ( hasHome2 ) --hasHome2;
657 } else if ( ( (*phoneIter).type() == PhoneNumber::Home | PhoneNumber::Pref) && hasHome>1 && !hasHome2 ) { 657 } else if ( ( (*phoneIter).type() == PhoneNumber::Home | PhoneNumber::Pref) && hasHome>1 && !hasHome2 ) {
658 (*phoneIter).setType( PhoneNumber::Home ); 658 (*phoneIter).setType( PhoneNumber::Home );
659 --hasHome; 659 --hasHome;
660 ++hasHome2; 660 ++hasHome2;
661 } else if ( (*phoneIter).type() == PhoneNumber::Work && ! hasWork ) { 661 } else if ( (*phoneIter).type() == PhoneNumber::Work && ! hasWork ) {
662 (*phoneIter).setType( PhoneNumber::Work | PhoneNumber::Pref ); 662 (*phoneIter).setType( PhoneNumber::Work | PhoneNumber::Pref );
663 ++hasWork; 663 ++hasWork;
664 if ( hasWork2 ) --hasWork2; 664 if ( hasWork2 ) --hasWork2;
665 } else if ( ( (*phoneIter).type() == PhoneNumber::Work | PhoneNumber::Pref) && hasWork > 1 && ! hasWork2 ) { 665 } else if ( ( (*phoneIter).type() == PhoneNumber::Work | PhoneNumber::Pref) && hasWork > 1 && ! hasWork2 ) {
666 (*phoneIter).setType( PhoneNumber::Work ); 666 (*phoneIter).setType( PhoneNumber::Work );
667 --hasWork; 667 --hasWork;
668 ++hasWork2; 668 ++hasWork2;
669 } else if ( (*phoneIter).type() == PhoneNumber::Cell && hasCell > 1 && !hasCell2) { 669 } else if ( (*phoneIter).type() == PhoneNumber::Cell && hasCell > 1 && !hasCell2) {
670 (*phoneIter).setType( PhoneNumber::Car ); 670 (*phoneIter).setType( PhoneNumber::Car );
671 ++hasCell2; 671 ++hasCell2;
672 --hasCell; 672 --hasCell;
673 } else if ( (*phoneIter).type() == PhoneNumber::Car && hasCell2 > 1 && !hasCell) { 673 } else if ( (*phoneIter).type() == PhoneNumber::Car && hasCell2 > 1 && !hasCell) {
674 (*phoneIter).setType( PhoneNumber::Cell ); 674 (*phoneIter).setType( PhoneNumber::Cell );
675 ++hasCell; 675 ++hasCell;
676 --hasCell2; 676 --hasCell2;
677 } else{ 677 } else{
678 phoneIter2 = phoneIter; 678 phoneIter2 = phoneIter;
679 ++phoneIter2; 679 ++phoneIter2;
680 for ( ; phoneIter2 != mData->phoneNumbers.end(); 680 for ( ; phoneIter2 != mData->phoneNumbers.end();
681 ++phoneIter2 ) { 681 ++phoneIter2 ) {
682 if ( (*phoneIter2).type() == (*phoneIter).type() ) { 682 if ( (*phoneIter2).type() == (*phoneIter).type() ) {
683 (*phoneIter2).setType( PhoneNumber::Voice ); 683 (*phoneIter2).setType( PhoneNumber::Voice );
684 684
685 } 685 }
686 } 686 }
687 } 687 }
688 } 688 }
689} 689}
690void Addressee::simplifyPhoneNumbers() 690void Addressee::simplifyPhoneNumbers()
691{ 691{
692 int max = 4; 692 int max = 4;
693 int inList = mData->phoneNumbers.count(); 693 int inList = mData->phoneNumbers.count();
694 KABC::PhoneNumber::List removeNumbers; 694 KABC::PhoneNumber::List removeNumbers;
695 KABC::PhoneNumber::List::Iterator phoneIter; 695 KABC::PhoneNumber::List::Iterator phoneIter;
696 if ( inList > max ) { 696 if ( inList > max ) {
697 // delete non-preferred numbers 697 // delete non-preferred numbers
698 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 698 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
699 ++phoneIter ) { 699 ++phoneIter ) {
700 if ( inList > max ) { 700 if ( inList > max ) {
701 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { 701 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
702 removeNumbers.append( ( *phoneIter ) ); 702 removeNumbers.append( ( *phoneIter ) );
703 --inList; 703 --inList;
704 } 704 }
705 } else 705 } else
706 break; 706 break;
707 } 707 }
708 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 708 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
709 ++phoneIter ) { 709 ++phoneIter ) {
710 removePhoneNumber(( *phoneIter )); 710 removePhoneNumber(( *phoneIter ));
711 } 711 }
712 // delete preferred numbers 712 // delete preferred numbers
713 if ( inList > max ) { 713 if ( inList > max ) {
714 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 714 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
715 ++phoneIter ) { 715 ++phoneIter ) {
716 if ( inList > max ) { 716 if ( inList > max ) {
717 removeNumbers.append( ( *phoneIter ) ); 717 removeNumbers.append( ( *phoneIter ) );
718 --inList; 718 --inList;
719 } else 719 } else
720 break; 720 break;
721 } 721 }
722 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 722 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
723 ++phoneIter ) { 723 ++phoneIter ) {
724 removePhoneNumber(( *phoneIter )); 724 removePhoneNumber(( *phoneIter ));
725 } 725 }
726 } 726 }
727 } 727 }
728 // remove non-numeric characters 728 // remove non-numeric characters
729 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 729 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
730 ++phoneIter ) { 730 ++phoneIter ) {
731 if ( ! ( *phoneIter ).simplifyNumber() ) 731 if ( ! ( *phoneIter ).simplifyNumber() )
732 removeNumbers.append( ( *phoneIter ) ); 732 removeNumbers.append( ( *phoneIter ) );
733 } 733 }
734 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 734 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
735 ++phoneIter ) { 735 ++phoneIter ) {
736 removePhoneNumber(( *phoneIter )); 736 removePhoneNumber(( *phoneIter ));
737 } 737 }
738} 738}
739void Addressee::simplifyPhoneNumberTypes() 739void Addressee::simplifyPhoneNumberTypes()
740{ 740{
741 KABC::PhoneNumber::List::Iterator phoneIter; 741 KABC::PhoneNumber::List::Iterator phoneIter;
742 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 742 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
743 ++phoneIter ) 743 ++phoneIter )
744 ( *phoneIter ).simplifyType(); 744 ( *phoneIter ).simplifyType();
745} 745}
746void Addressee::removeID(const QString &prof) 746void Addressee::removeID(const QString &prof)
747{ 747{
748 detach(); 748 detach();
749 if ( prof.isEmpty() ) 749 if ( prof.isEmpty() )
750 mData->mExternalId = ":"; 750 mData->mExternalId = ":";
751 else 751 else
752 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 752 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
753 753
754} 754}
755void Addressee::setID( const QString & prof , const QString & id ) 755void Addressee::setID( const QString & prof , const QString & id )
756{ 756{
757 detach(); 757 detach();
758 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 758 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
759 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 759 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
760} 760}
761void Addressee::setTempSyncStat( int id ) 761void Addressee::setTempSyncStat( int id )
762{ 762{
763 if ( mData->mTempSyncStat == id ) return; 763 if ( mData->mTempSyncStat == id ) return;
764 detach(); 764 detach();
765 mData->mTempSyncStat = id; 765 mData->mTempSyncStat = id;
766} 766}
767int Addressee::tempSyncStat() const 767int Addressee::tempSyncStat() const
768{ 768{
769 return mData->mTempSyncStat; 769 return mData->mTempSyncStat;
770} 770}
771 771
772const QString Addressee::getID( const QString & prof) const 772const QString Addressee::getID( const QString & prof) const
773{ 773{
774 return KIdManager::getId ( mData->mExternalId, prof ); 774 return KIdManager::getId ( mData->mExternalId, prof );
775} 775}
776 776
777void Addressee::setCsum( const QString & prof , const QString & id ) 777void Addressee::setCsum( const QString & prof , const QString & id )
778{ 778{