summaryrefslogtreecommitdiffabout
path: root/kabc/addressee.cpp
Unidiff
Diffstat (limited to 'kabc/addressee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp75
1 files changed, 34 insertions, 41 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index cb10160..2aca559 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -54,605 +54,598 @@ struct Addressee::AddresseeData : public KShared
54 QString familyName; 54 QString familyName;
55 QString givenName; 55 QString givenName;
56 QString additionalName; 56 QString additionalName;
57 QString prefix; 57 QString prefix;
58 QString suffix; 58 QString suffix;
59 QString nickName; 59 QString nickName;
60 QDateTime birthday; 60 QDateTime birthday;
61 QString mailer; 61 QString mailer;
62 TimeZone timeZone; 62 TimeZone timeZone;
63 Geo geo; 63 Geo geo;
64 QString title; 64 QString title;
65 QString role; 65 QString role;
66 QString organization; 66 QString organization;
67 QString note; 67 QString note;
68 QString productId; 68 QString productId;
69 QDateTime revision; 69 QDateTime revision;
70 QString sortString; 70 QString sortString;
71 QString externalUID; 71 QString externalUID;
72 QString originalExternalUID; 72 QString originalExternalUID;
73 KURL url; 73 KURL url;
74 Secrecy secrecy; 74 Secrecy secrecy;
75 Picture logo; 75 Picture logo;
76 Picture photo; 76 Picture photo;
77 Sound sound; 77 Sound sound;
78 Agent agent; 78 Agent agent;
79 QString mExternalId; 79 QString mExternalId;
80 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
81 Address::List addresses; 81 Address::List addresses;
82 Key::List keys; 82 Key::List keys;
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1; 91 bool tagged :1;
92}; 92};
93 93
94Addressee::Addressee() 94Addressee::Addressee()
95{ 95{
96 mData = new AddresseeData; 96 mData = new AddresseeData;
97 mData->empty = true; 97 mData->empty = true;
98 mData->changed = false; 98 mData->changed = false;
99 mData->resource = 0; 99 mData->resource = 0;
100 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
101 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
103} 103}
104 104
105Addressee::~Addressee() 105Addressee::~Addressee()
106{ 106{
107} 107}
108 108
109Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
110{ 110{
111 mData = a.mData; 111 mData = a.mData;
112} 112}
113 113
114Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
115{ 115{
116 mData = a.mData; 116 mData = a.mData;
117 return (*this); 117 return (*this);
118} 118}
119 119
120Addressee Addressee::copy() 120Addressee Addressee::copy()
121{ 121{
122 Addressee a; 122 Addressee a;
123 *(a.mData) = *mData; 123 *(a.mData) = *mData;
124 return a; 124 return a;
125} 125}
126 126
127void Addressee::detach() 127void Addressee::detach()
128{ 128{
129 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
130 *this = copy(); 130 *this = copy();
131} 131}
132 132
133bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
134{ 134{
135 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
136 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
137 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
138 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
139 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
140 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
141 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
142 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
143 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
144 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
145 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
146 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
147 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
148 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
149 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
150 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
151 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
152 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
153 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
154 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
155 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
156 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
157 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
158 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
159 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
161 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
163 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
164 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
165 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
166 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
167 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
168 168
169 return true; 169 return true;
170} 170}
171 171
172bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
173{ 173{
174 return !( a == *this ); 174 return !( a == *this );
175} 175}
176 176
177bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
178{ 178{
179 return mData->empty; 179 return mData->empty;
180} 180}
181ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
182{ 182{
183 int max = attList.count(); 183 int max = attList.count();
184 ulong cSum = 0; 184 ulong cSum = 0;
185 int j,k,i; 185 int j,k,i;
186 int add; 186 int add;
187 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
188 QString s = attList[i]; 188 QString s = attList[i];
189 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
190 j = s.length(); 190 j = s.length();
191 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
192 int mul = k +1; 192 int mul = k +1;
193 add = s[k].unicode (); 193 add = s[k].unicode ();
194 if ( k < 16 ) 194 if ( k < 16 )
195 mul = mul * mul; 195 mul = mul * mul;
196 int ii = i+1; 196 int ii = i+1;
197 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
198 cSum += add; 198 cSum += add;
199 } 199 }
200 } 200 }
201 201
202 } 202 }
203 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
204 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
205 205
206 return cSum; 206 return cSum;
207 207
208} 208}
209void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
210{ 210{
211 QStringList l; 211 QStringList l;
212 if ( !mData->name.isEmpty() ) l.append(mData->name); 212 if ( !mData->name.isEmpty() ) l.append(mData->name);
213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
216 if ( !mData->additionalName ) l.append( mData->additionalName ); 216 if ( !mData->additionalName ) l.append( mData->additionalName );
217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
224 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
225 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
226 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
227 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
228 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
231 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
232 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
233 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
234 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
235 if ( mData->url.isValid() ) 235 if ( mData->url.isValid() )
236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
237 KABC::PhoneNumber::List phoneNumbers; 237 KABC::PhoneNumber::List phoneNumbers;
238 KABC::PhoneNumber::List::Iterator phoneIter; 238 KABC::PhoneNumber::List::Iterator phoneIter;
239 239
240 QStringList t; 240 QStringList t;
241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
242 ++phoneIter ) 242 ++phoneIter )
243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
244 t.sort(); 244 t.sort();
245 uint iii; 245 uint iii;
246 for ( iii = 0; iii < t.count(); ++iii) 246 for ( iii = 0; iii < t.count(); ++iii)
247 l.append( t[iii] ); 247 l.append( t[iii] );
248 t = mData->emails; 248 t = mData->emails;
249 t.sort(); 249 t.sort();
250 for ( iii = 0; iii < t.count(); ++iii) 250 for ( iii = 0; iii < t.count(); ++iii)
251 l.append( t[iii] ); 251 l.append( t[iii] );
252 t = mData->categories; 252 t = mData->categories;
253 t.sort(); 253 t.sort();
254 for ( iii = 0; iii < t.count(); ++iii) 254 for ( iii = 0; iii < t.count(); ++iii)
255 l.append( t[iii] ); 255 l.append( t[iii] );
256 t = mData->custom; 256 t = mData->custom;
257 t.sort(); 257 t.sort();
258 for ( iii = 0; iii < t.count(); ++iii) 258 for ( iii = 0; iii < t.count(); ++iii)
259 l.append( t[iii] ); 259 l.append( t[iii] );
260 KABC::Address::List::Iterator addressIter; 260 KABC::Address::List::Iterator addressIter;
261 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 261 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
262 ++addressIter ) { 262 ++addressIter ) {
263 t = (*addressIter).asList(); 263 t = (*addressIter).asList();
264 t.sort(); 264 t.sort();
265 for ( iii = 0; iii < t.count(); ++iii) 265 for ( iii = 0; iii < t.count(); ++iii)
266 l.append( t[iii] ); 266 l.append( t[iii] );
267 } 267 }
268 uint cs = getCsum4List(l); 268 uint cs = getCsum4List(l);
269 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 269 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
270 setCsum( dev, QString::number (cs )); 270 setCsum( dev, QString::number (cs ));
271} 271}
272 272
273void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 273void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
274{ 274{
275 275
276 detach(); 276 detach();
277 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 277 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
278 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 278 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
279 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 279 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
280 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 280 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
281 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 281 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
282 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 282 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
283 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 283 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
284 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 284 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
285 if ( !mData->birthday.isValid() ) 285 if ( !mData->birthday.isValid() )
286 if ( ad.mData->birthday.isValid()) 286 if ( ad.mData->birthday.isValid())
287 mData->birthday = ad.mData->birthday; 287 mData->birthday = ad.mData->birthday;
288 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 288 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
289 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 289 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
290 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 290 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
291 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 291 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
292 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 292 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
293 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 293 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
294 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 294 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
295 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 295 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
296 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 296 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
297 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 297 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
298 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 298 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
299 QStringList t; 299 QStringList t;
300 QStringList tAD; 300 QStringList tAD;
301 uint iii; 301 uint iii;
302 if ( isSubSet ) { 302 if ( isSubSet ) {
303 // ********** phone numbers 303 // ********** phone numbers
304 PhoneNumber::List phoneAD = ad.phoneNumbers(); 304 PhoneNumber::List phoneAD = ad.phoneNumbers();
305 PhoneNumber::List::Iterator phoneItAD; 305 PhoneNumber::List::Iterator phoneItAD;
306 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 306 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
307 bool found = false; 307 bool found = false;
308 PhoneNumber::List::Iterator it; 308 PhoneNumber::List::Iterator it;
309 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 309 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
310 if ( (*it) == ( *phoneItAD ) ) { 310 if ( ( *phoneItAD ).contains( (*it) ) ) {
311 found = true; 311 found = true;
312 (*it).setType( ( *phoneItAD ).type() );
312 break; 313 break;
313 } 314 }
314 } 315 }
315 if ( ! found ) 316 if ( ! found )
316 mData->phoneNumbers.append( *phoneItAD ); 317 mData->phoneNumbers.append( *phoneItAD );
317 } 318 }
318 // ************* emails; 319 // ************* emails;
319 t = mData->emails; 320 t = mData->emails;
320 tAD = ad.mData->emails; 321 tAD = ad.mData->emails;
321 for ( iii = 0; iii < tAD.count(); ++iii) 322 for ( iii = 0; iii < tAD.count(); ++iii)
322 if ( !t.contains(tAD[iii] ) ) 323 if ( !t.contains(tAD[iii] ) )
323 mData->emails.append( tAD[iii] ); 324 mData->emails.append( tAD[iii] );
324 // ************* categories; 325 // ************* categories;
325 t = mData->categories; 326 t = mData->categories;
326 tAD = ad.mData->categories; 327 tAD = ad.mData->categories;
327 for ( iii = 0; iii < tAD.count(); ++iii) 328 for ( iii = 0; iii < tAD.count(); ++iii)
328 if ( !t.contains(tAD[iii] ) ) 329 if ( !t.contains(tAD[iii] ) )
329 mData->categories.append( tAD[iii] ); 330 mData->categories.append( tAD[iii] );
330 331
331 332
332 } 333 }
333 334
334 QStringList::ConstIterator it; 335 QStringList::ConstIterator it;
335 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { 336 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
336 QString qualifiedName = (*it).left( (*it).find( ":" )); 337 QString qualifiedName = (*it).left( (*it).find( ":" ));
337 bool found = false; 338 bool found = false;
338 QStringList::ConstIterator itL; 339 QStringList::ConstIterator itL;
339 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 340 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
340 if ( (*itL).startsWith( qualifiedName ) ) { 341 if ( (*itL).startsWith( qualifiedName ) ) {
341 found = true; 342 found = true;
342 break; 343 break;
343 } 344 }
344 } 345 }
345 if ( ! found ) { 346 if ( ! found ) {
346 mData->custom.append( *it ); 347 mData->custom.append( *it );
347 } 348 }
348 } 349 }
349 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; 350 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
350 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; 351 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
351 if ( !mData->sound.isIntern() ) { 352 if ( !mData->sound.isIntern() ) {
352 if ( mData->sound.url().isEmpty() ) { 353 if ( mData->sound.url().isEmpty() ) {
353 mData->sound = ad.mData->sound; 354 mData->sound = ad.mData->sound;
354 } 355 }
355 } 356 }
356 if ( !mData->agent.isIntern() ) { 357 if ( !mData->agent.isIntern() ) {
357 if ( mData->agent.url().isEmpty() ) { 358 if ( mData->agent.url().isEmpty() ) {
358 mData->agent = ad.mData->agent; 359 mData->agent = ad.mData->agent;
359 } 360 }
360 } 361 }
361 362 {
362#if 0 363 Key::List::Iterator itA;
363 364 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
364 if ( mData->url.isValid() ) 365 bool found = false;
365 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 366 Key::List::Iterator it;
366 KABC::PhoneNumber::List phoneNumbers; 367 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
367 KABC::PhoneNumber::List::Iterator phoneIter; 368 if ( (*it) == (*itA)) {
368 369 found = true;
369 QStringList t; 370 break;
370 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 371
371 ++phoneIter ) 372 }
372 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 373 }
373 t.sort(); 374 if ( ! found ) {
374 uint iii; 375 mData->keys.append( *itA );
375 for ( iii = 0; iii < t.count(); ++iii) 376 }
376 l.append( t[iii] ); 377 }
377 t = mData->emails;
378 t.sort();
379 for ( iii = 0; iii < t.count(); ++iii)
380 l.append( t[iii] );
381 t = mData->categories;
382 t.sort();
383 for ( iii = 0; iii < t.count(); ++iii)
384 l.append( t[iii] );
385 t = mData->custom;
386 t.sort();
387 for ( iii = 0; iii < t.count(); ++iii)
388 l.append( t[iii] );
389 KABC::Address::List::Iterator addressIter;
390 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
391 ++addressIter ) {
392 t = (*addressIter).asList();
393 t.sort();
394 for ( iii = 0; iii < t.count(); ++iii)
395 l.append( t[iii] );
396 } 378 }
379 KABC::Address::List::Iterator addressIterA;
380 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
381 bool found = false;
382 KABC::Address::List::Iterator addressIter;
383 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
384 ++addressIter ) {
385 if ( (*addressIter) == (*addressIterA)) {
386 found = true;
387 (*addressIter).setType( (*addressIterA).type() );
388 break;
389 }
397 390
398#endif 391 }
399 392 if ( ! found ) {
400 // pending: 393 mData->addresses.append( *addressIterA );
401 // merging addresses 394 }
402 // merging keys 395 }
403 //qDebug("merge contact %s ", ad.uid().latin1()); 396 //qDebug("merge contact %s ", ad.uid().latin1());
404 setUid( ad.uid() ); 397 setUid( ad.uid() );
405 setRevision( ad.revision() ); 398 setRevision( ad.revision() );
406} 399}
407 400
408bool Addressee::removeVoice() 401bool Addressee::removeVoice()
409{ 402{
410 PhoneNumber::List phoneN = phoneNumbers(); 403 PhoneNumber::List phoneN = phoneNumbers();
411 PhoneNumber::List::Iterator phoneIt; 404 PhoneNumber::List::Iterator phoneIt;
412 bool found = false; 405 bool found = false;
413 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 406 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
414 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 407 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
415 if ((*phoneIt).type() - PhoneNumber::Voice ) { 408 if ((*phoneIt).type() - PhoneNumber::Voice ) {
416 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 409 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
417 insertPhoneNumber( (*phoneIt) ); 410 insertPhoneNumber( (*phoneIt) );
418 found = true; 411 found = true;
419 } 412 }
420 } 413 }
421 414
422 } 415 }
423 return found; 416 return found;
424} 417}
425 418
426bool Addressee::containsAdr(const Addressee& ad ) 419bool Addressee::containsAdr(const Addressee& ad )
427{ 420{
428 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; 421 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
429 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; 422 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
430 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; 423 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
431 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; 424 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
432 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; 425 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
433 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; 426 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
434 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; 427 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
435 428
436 // compare phone numbers 429 // compare phone numbers
437 PhoneNumber::List phoneN = ad.phoneNumbers(); 430 PhoneNumber::List phoneN = ad.phoneNumbers();
438 PhoneNumber::List::Iterator phoneIt; 431 PhoneNumber::List::Iterator phoneIt;
439 bool found = false; 432 bool found = false;
440 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 433 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
441 bool found = false; 434 bool found = false;
442 PhoneNumber::List phoneL = ad.phoneNumbers(); 435 PhoneNumber::List phoneL = ad.phoneNumbers();
443 PhoneNumber::List::Iterator phoneItL; 436 PhoneNumber::List::Iterator phoneItL;
444 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 437 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
445 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 438 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
446 found = true; 439 found = true;
447 break; 440 break;
448 } 441 }
449 } 442 }
450 if ( ! found ) 443 if ( ! found )
451 return false; 444 return false;
452 } 445 }
453 return true; 446 return true;
454 447
455} 448}
456void Addressee::simplifyAddresses() 449void Addressee::simplifyAddresses()
457{ 450{
458 int max = 2; 451 int max = 2;
459 if ( mData->url.isValid() ) 452 if ( mData->url.isValid() )
460 max = 1; 453 max = 1;
461 if ( mData->addresses.count() <= max ) return ; 454 if ( mData->addresses.count() <= max ) return ;
462 int count = 0; 455 int count = 0;
463 Address::List list; 456 Address::List list;
464 Address::List::Iterator it; 457 Address::List::Iterator it;
465 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 458 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
466 if ( count >= max ) 459 if ( count >= max )
467 list.append( *it ); 460 list.append( *it );
468 ++count; 461 ++count;
469 } 462 }
470 for( it = list.begin(); it != list.end(); ++it ) { 463 for( it = list.begin(); it != list.end(); ++it ) {
471 removeAddress( (*it) ); 464 removeAddress( (*it) );
472 } 465 }
473} 466}
474 467
475// removes all emails but the first 468// removes all emails but the first
476// needed by phone sync 469// needed by phone sync
477void Addressee::simplifyEmails() 470void Addressee::simplifyEmails()
478{ 471{
479 if ( mData->emails.count() == 0 ) return ; 472 if ( mData->emails.count() == 0 ) return ;
480 QString email = mData->emails.first(); 473 QString email = mData->emails.first();
481 detach(); 474 detach();
482 mData->emails.clear(); 475 mData->emails.clear();
483 mData->emails.append( email ); 476 mData->emails.append( email );
484} 477}
485 478
486void Addressee::simplifyPhoneNumbers() 479void Addressee::simplifyPhoneNumbers()
487{ 480{
488 KABC::PhoneNumber::List removeNumbers; 481 KABC::PhoneNumber::List removeNumbers;
489 KABC::PhoneNumber::List::Iterator phoneIter; 482 KABC::PhoneNumber::List::Iterator phoneIter;
490 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 483 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
491 ++phoneIter ) { 484 ++phoneIter ) {
492 if ( ! ( *phoneIter ).simplifyNumber() ) 485 if ( ! ( *phoneIter ).simplifyNumber() )
493 removeNumbers.append( ( *phoneIter ) ); 486 removeNumbers.append( ( *phoneIter ) );
494 } 487 }
495 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 488 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
496 ++phoneIter ) { 489 ++phoneIter ) {
497 removePhoneNumber(( *phoneIter )); 490 removePhoneNumber(( *phoneIter ));
498 } 491 }
499} 492}
500void Addressee::simplifyPhoneNumberTypes() 493void Addressee::simplifyPhoneNumberTypes()
501{ 494{
502 KABC::PhoneNumber::List::Iterator phoneIter; 495 KABC::PhoneNumber::List::Iterator phoneIter;
503 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 496 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
504 ++phoneIter ) 497 ++phoneIter )
505 ( *phoneIter ).simplifyType(); 498 ( *phoneIter ).simplifyType();
506} 499}
507void Addressee::removeID(const QString &prof) 500void Addressee::removeID(const QString &prof)
508{ 501{
509 detach(); 502 detach();
510 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 503 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
511 504
512} 505}
513void Addressee::setID( const QString & prof , const QString & id ) 506void Addressee::setID( const QString & prof , const QString & id )
514{ 507{
515 detach(); 508 detach();
516 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 509 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
517 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 510 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
518} 511}
519void Addressee::setTempSyncStat( int id ) 512void Addressee::setTempSyncStat( int id )
520{ 513{
521 if ( mData->mTempSyncStat == id ) return; 514 if ( mData->mTempSyncStat == id ) return;
522 detach(); 515 detach();
523 mData->mTempSyncStat = id; 516 mData->mTempSyncStat = id;
524} 517}
525int Addressee::tempSyncStat() const 518int Addressee::tempSyncStat() const
526{ 519{
527 return mData->mTempSyncStat; 520 return mData->mTempSyncStat;
528} 521}
529 522
530QString Addressee::getID( const QString & prof) 523QString Addressee::getID( const QString & prof)
531{ 524{
532 return KIdManager::getId ( mData->mExternalId, prof ); 525 return KIdManager::getId ( mData->mExternalId, prof );
533} 526}
534 527
535void Addressee::setCsum( const QString & prof , const QString & id ) 528void Addressee::setCsum( const QString & prof , const QString & id )
536{ 529{
537 detach(); 530 detach();
538 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 531 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
539 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 532 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
540 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 533 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
541} 534}
542 535
543QString Addressee::getCsum( const QString & prof) 536QString Addressee::getCsum( const QString & prof)
544{ 537{
545 return KIdManager::getCsum ( mData->mExternalId, prof ); 538 return KIdManager::getCsum ( mData->mExternalId, prof );
546} 539}
547 540
548void Addressee::setIDStr( const QString & s ) 541void Addressee::setIDStr( const QString & s )
549{ 542{
550 detach(); 543 detach();
551 mData->mExternalId = s; 544 mData->mExternalId = s;
552} 545}
553 546
554QString Addressee::IDStr() const 547QString Addressee::IDStr() const
555{ 548{
556 return mData->mExternalId; 549 return mData->mExternalId;
557} 550}
558 551
559void Addressee::setExternalUID( const QString &id ) 552void Addressee::setExternalUID( const QString &id )
560{ 553{
561 if ( id == mData->externalUID ) return; 554 if ( id == mData->externalUID ) return;
562 detach(); 555 detach();
563 mData->empty = false; 556 mData->empty = false;
564 mData->externalUID = id; 557 mData->externalUID = id;
565} 558}
566 559
567QString Addressee::externalUID() const 560QString Addressee::externalUID() const
568{ 561{
569 return mData->externalUID; 562 return mData->externalUID;
570} 563}
571void Addressee::setOriginalExternalUID( const QString &id ) 564void Addressee::setOriginalExternalUID( const QString &id )
572{ 565{
573 if ( id == mData->originalExternalUID ) return; 566 if ( id == mData->originalExternalUID ) return;
574 detach(); 567 detach();
575 mData->empty = false; 568 mData->empty = false;
576 //qDebug("*******Set orig uid %s ", id.latin1()); 569 //qDebug("*******Set orig uid %s ", id.latin1());
577 mData->originalExternalUID = id; 570 mData->originalExternalUID = id;
578} 571}
579 572
580QString Addressee::originalExternalUID() const 573QString Addressee::originalExternalUID() const
581{ 574{
582 return mData->originalExternalUID; 575 return mData->originalExternalUID;
583} 576}
584 577
585void Addressee::setUid( const QString &id ) 578void Addressee::setUid( const QString &id )
586{ 579{
587 if ( id == mData->uid ) return; 580 if ( id == mData->uid ) return;
588 detach(); 581 detach();
589 //qDebug("****setuid %s ", id.latin1()); 582 //qDebug("****setuid %s ", id.latin1());
590 mData->empty = false; 583 mData->empty = false;
591 mData->uid = id; 584 mData->uid = id;
592} 585}
593 586
594QString Addressee::uid() const 587QString Addressee::uid() const
595{ 588{
596 if ( mData->uid.isEmpty() ) 589 if ( mData->uid.isEmpty() )
597 mData->uid = KApplication::randomString( 10 ); 590 mData->uid = KApplication::randomString( 10 );
598 591
599 return mData->uid; 592 return mData->uid;
600} 593}
601 594
602QString Addressee::uidLabel() 595QString Addressee::uidLabel()
603{ 596{
604 return i18n("Unique Identifier"); 597 return i18n("Unique Identifier");
605} 598}
606 599
607void Addressee::setName( const QString &name ) 600void Addressee::setName( const QString &name )
608{ 601{
609 if ( name == mData->name ) return; 602 if ( name == mData->name ) return;
610 detach(); 603 detach();
611 mData->empty = false; 604 mData->empty = false;
612 mData->name = name; 605 mData->name = name;
613} 606}
614 607
615QString Addressee::name() const 608QString Addressee::name() const
616{ 609{
617 return mData->name; 610 return mData->name;
618} 611}
619 612
620QString Addressee::nameLabel() 613QString Addressee::nameLabel()
621{ 614{
622 return i18n("Name"); 615 return i18n("Name");
623} 616}
624 617
625 618
626void Addressee::setFormattedName( const QString &formattedName ) 619void Addressee::setFormattedName( const QString &formattedName )
627{ 620{
628 if ( formattedName == mData->formattedName ) return; 621 if ( formattedName == mData->formattedName ) return;
629 detach(); 622 detach();
630 mData->empty = false; 623 mData->empty = false;
631 mData->formattedName = formattedName; 624 mData->formattedName = formattedName;
632} 625}
633 626
634QString Addressee::formattedName() const 627QString Addressee::formattedName() const
635{ 628{
636 return mData->formattedName; 629 return mData->formattedName;
637} 630}
638 631
639QString Addressee::formattedNameLabel() 632QString Addressee::formattedNameLabel()
640{ 633{
641 return i18n("Formatted Name"); 634 return i18n("Formatted Name");
642} 635}
643 636
644 637
645void Addressee::setFamilyName( const QString &familyName ) 638void Addressee::setFamilyName( const QString &familyName )
646{ 639{
647 if ( familyName == mData->familyName ) return; 640 if ( familyName == mData->familyName ) return;
648 detach(); 641 detach();
649 mData->empty = false; 642 mData->empty = false;
650 mData->familyName = familyName; 643 mData->familyName = familyName;
651} 644}
652 645
653QString Addressee::familyName() const 646QString Addressee::familyName() const
654{ 647{
655 return mData->familyName; 648 return mData->familyName;
656} 649}
657 650
658QString Addressee::familyNameLabel() 651QString Addressee::familyNameLabel()