-rw-r--r-- | kabc/addressbook.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 3641c0c..2785131 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -172,768 +172,776 @@ AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const Address | |||
172 | return *this; | 172 | return *this; |
173 | } | 173 | } |
174 | 174 | ||
175 | AddressBook::ConstIterator::~ConstIterator() | 175 | AddressBook::ConstIterator::~ConstIterator() |
176 | { | 176 | { |
177 | delete d; | 177 | delete d; |
178 | } | 178 | } |
179 | 179 | ||
180 | const Addressee &AddressBook::ConstIterator::operator*() const | 180 | const Addressee &AddressBook::ConstIterator::operator*() const |
181 | { | 181 | { |
182 | return *(d->mIt); | 182 | return *(d->mIt); |
183 | } | 183 | } |
184 | 184 | ||
185 | const Addressee* AddressBook::ConstIterator::operator->() const | 185 | const Addressee* AddressBook::ConstIterator::operator->() const |
186 | { | 186 | { |
187 | return &(*(d->mIt)); | 187 | return &(*(d->mIt)); |
188 | } | 188 | } |
189 | 189 | ||
190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
191 | { | 191 | { |
192 | (d->mIt)++; | 192 | (d->mIt)++; |
193 | return *this; | 193 | return *this; |
194 | } | 194 | } |
195 | 195 | ||
196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
197 | { | 197 | { |
198 | (d->mIt)++; | 198 | (d->mIt)++; |
199 | return *this; | 199 | return *this; |
200 | } | 200 | } |
201 | 201 | ||
202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
203 | { | 203 | { |
204 | (d->mIt)--; | 204 | (d->mIt)--; |
205 | return *this; | 205 | return *this; |
206 | } | 206 | } |
207 | 207 | ||
208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
209 | { | 209 | { |
210 | (d->mIt)--; | 210 | (d->mIt)--; |
211 | return *this; | 211 | return *this; |
212 | } | 212 | } |
213 | 213 | ||
214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
215 | { | 215 | { |
216 | return ( d->mIt == it.d->mIt ); | 216 | return ( d->mIt == it.d->mIt ); |
217 | } | 217 | } |
218 | 218 | ||
219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
220 | { | 220 | { |
221 | return ( d->mIt != it.d->mIt ); | 221 | return ( d->mIt != it.d->mIt ); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | AddressBook::AddressBook() | 225 | AddressBook::AddressBook() |
226 | { | 226 | { |
227 | init(0, "contact"); | 227 | init(0, "contact"); |
228 | } | 228 | } |
229 | 229 | ||
230 | AddressBook::AddressBook( const QString &config ) | 230 | AddressBook::AddressBook( const QString &config ) |
231 | { | 231 | { |
232 | init(config, "contact"); | 232 | init(config, "contact"); |
233 | } | 233 | } |
234 | 234 | ||
235 | AddressBook::AddressBook( const QString &config, const QString &family ) | 235 | AddressBook::AddressBook( const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | init(config, family); | 237 | init(config, family); |
238 | 238 | ||
239 | } | 239 | } |
240 | 240 | ||
241 | // the default family is "contact" | 241 | // the default family is "contact" |
242 | void AddressBook::init(const QString &config, const QString &family ) | 242 | void AddressBook::init(const QString &config, const QString &family ) |
243 | { | 243 | { |
244 | blockLSEchange = false; | 244 | blockLSEchange = false; |
245 | d = new AddressBookData; | 245 | d = new AddressBookData; |
246 | QString fami = family; | 246 | QString fami = family; |
247 | if (config != 0) { | 247 | if (config != 0) { |
248 | if ( family == "syncContact" ) { | 248 | if ( family == "syncContact" ) { |
249 | qDebug("creating sync config "); | 249 | qDebug("creating sync config "); |
250 | fami = "contact"; | 250 | fami = "contact"; |
251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
252 | con->setGroup( "General" ); | 252 | con->setGroup( "General" ); |
253 | con->writeEntry( "ResourceKeys", QString("sync") ); | 253 | con->writeEntry( "ResourceKeys", QString("sync") ); |
254 | con->writeEntry( "Standard", QString("sync") ); | 254 | con->writeEntry( "Standard", QString("sync") ); |
255 | con->setGroup( "Resource_sync" ); | 255 | con->setGroup( "Resource_sync" ); |
256 | con->writeEntry( "FileName", config ); | 256 | con->writeEntry( "FileName", config ); |
257 | con->writeEntry( "FileFormat", QString("vcard") ); | 257 | con->writeEntry( "FileFormat", QString("vcard") ); |
258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
259 | con->writeEntry( "ResourceName", QString("sync_res") ); | 259 | con->writeEntry( "ResourceName", QString("sync_res") ); |
260 | if ( config.right(4) == ".xml" ) | 260 | if ( config.right(4) == ".xml" ) |
261 | con->writeEntry( "ResourceType", QString("qtopia") ); | 261 | con->writeEntry( "ResourceType", QString("qtopia") ); |
262 | else if ( config == "sharp" ) { | 262 | else if ( config == "sharp" ) { |
263 | con->writeEntry( "ResourceType", QString("sharp") ); | 263 | con->writeEntry( "ResourceType", QString("sharp") ); |
264 | } else { | 264 | } else { |
265 | con->writeEntry( "ResourceType", QString("file") ); | 265 | con->writeEntry( "ResourceType", QString("file") ); |
266 | } | 266 | } |
267 | //con->sync(); | 267 | //con->sync(); |
268 | d->mConfig = con; | 268 | d->mConfig = con; |
269 | } | 269 | } |
270 | else | 270 | else |
271 | d->mConfig = new KConfig( locateLocal("config", config) ); | 271 | d->mConfig = new KConfig( locateLocal("config", config) ); |
272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
273 | } | 273 | } |
274 | else { | 274 | else { |
275 | d->mConfig = 0; | 275 | d->mConfig = 0; |
276 | // qDebug("AddressBook::init 1 config=0"); | 276 | // qDebug("AddressBook::init 1 config=0"); |
277 | } | 277 | } |
278 | 278 | ||
279 | //US d->mErrorHandler = 0; | 279 | //US d->mErrorHandler = 0; |
280 | d->mManager = new KRES::Manager<Resource>( fami ); | 280 | d->mManager = new KRES::Manager<Resource>( fami ); |
281 | d->mManager->readConfig( d->mConfig ); | 281 | d->mManager->readConfig( d->mConfig ); |
282 | if ( family == "syncContact" ) { | 282 | if ( family == "syncContact" ) { |
283 | KRES::Manager<Resource> *manager = d->mManager; | 283 | KRES::Manager<Resource> *manager = d->mManager; |
284 | KRES::Manager<Resource>::ActiveIterator it; | 284 | KRES::Manager<Resource>::ActiveIterator it; |
285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
286 | (*it)->setAddressBook( this ); | 286 | (*it)->setAddressBook( this ); |
287 | if ( !(*it)->open() ) | 287 | if ( !(*it)->open() ) |
288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
289 | } | 289 | } |
290 | Resource *res = standardResource(); | 290 | Resource *res = standardResource(); |
291 | if ( !res ) { | 291 | if ( !res ) { |
292 | qDebug("ERROR: no standard resource"); | 292 | qDebug("ERROR: no standard resource"); |
293 | res = manager->createResource( "file" ); | 293 | res = manager->createResource( "file" ); |
294 | if ( res ) | 294 | if ( res ) |
295 | { | 295 | { |
296 | addResource( res ); | 296 | addResource( res ); |
297 | } | 297 | } |
298 | else | 298 | else |
299 | qDebug(" No resource available!!!"); | 299 | qDebug(" No resource available!!!"); |
300 | } | 300 | } |
301 | setStandardResource( res ); | 301 | setStandardResource( res ); |
302 | manager->writeConfig(); | 302 | manager->writeConfig(); |
303 | } | 303 | } |
304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
305 | "X-Department", "KADDRESSBOOK" ); | 305 | "X-Department", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
307 | "X-Profession", "KADDRESSBOOK" ); | 307 | "X-Profession", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
309 | "X-AssistantsName", "KADDRESSBOOK" ); | 309 | "X-AssistantsName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
311 | "X-ManagersName", "KADDRESSBOOK" ); | 311 | "X-ManagersName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
313 | "X-SpousesName", "KADDRESSBOOK" ); | 313 | "X-SpousesName", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
315 | "X-Office", "KADDRESSBOOK" ); | 315 | "X-Office", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
317 | "X-IMAddress", "KADDRESSBOOK" ); | 317 | "X-IMAddress", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
319 | "X-Anniversary", "KADDRESSBOOK" ); | 319 | "X-Anniversary", "KADDRESSBOOK" ); |
320 | 320 | ||
321 | //US added this field to become compatible with Opie/qtopia addressbook | 321 | //US added this field to become compatible with Opie/qtopia addressbook |
322 | // values can be "female" or "male" or "". An empty field represents undefined. | 322 | // values can be "female" or "male" or "". An empty field represents undefined. |
323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
324 | "X-Gender", "KADDRESSBOOK" ); | 324 | "X-Gender", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
326 | "X-Children", "KADDRESSBOOK" ); | 326 | "X-Children", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
330 | "X-ExternalID", "KADDRESSBOOK" ); | 330 | "X-ExternalID", "KADDRESSBOOK" ); |
331 | } | 331 | } |
332 | 332 | ||
333 | AddressBook::~AddressBook() | 333 | AddressBook::~AddressBook() |
334 | { | 334 | { |
335 | delete d->mConfig; d->mConfig = 0; | 335 | delete d->mConfig; d->mConfig = 0; |
336 | delete d->mManager; d->mManager = 0; | 336 | delete d->mManager; d->mManager = 0; |
337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
338 | delete d; d = 0; | 338 | delete d; d = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | bool AddressBook::load() | 341 | bool AddressBook::load() |
342 | { | 342 | { |
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } else { | 351 | } else { |
352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); | 352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); |
353 | } | 353 | } |
354 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | blockLSEchange = true; | 364 | blockLSEchange = true; |
365 | return ok; | 365 | return ok; |
366 | } | 366 | } |
367 | 367 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 369 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 371 | ||
372 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
375 | } | 375 | } |
376 | 376 | ||
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | // exports all Addressees, which are syncable | 379 | // exports all Addressees, which are syncable |
380 | void AddressBook::export2File( QString fileName ) | 380 | void AddressBook::export2File( QString fileName ) |
381 | { | 381 | { |
382 | 382 | ||
383 | QFile outFile( fileName ); | 383 | QFile outFile( fileName ); |
384 | if ( !outFile.open( IO_WriteOnly ) ) { | 384 | if ( !outFile.open( IO_WriteOnly ) ) { |
385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
386 | KMessageBox::error( 0, text.arg( fileName ) ); | 386 | KMessageBox::error( 0, text.arg( fileName ) ); |
387 | return ; | 387 | return ; |
388 | } | 388 | } |
389 | QTextStream t( &outFile ); | 389 | QTextStream t( &outFile ); |
390 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 390 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
391 | Iterator it; | 391 | Iterator it; |
392 | KABC::VCardConverter::Version version; | 392 | KABC::VCardConverter::Version version; |
393 | version = KABC::VCardConverter::v3_0; | 393 | version = KABC::VCardConverter::v3_0; |
394 | for ( it = begin(); it != end(); ++it ) { | 394 | for ( it = begin(); it != end(); ++it ) { |
395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { | 395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { |
396 | if ( !(*it).IDStr().isEmpty() ) { | 396 | if ( !(*it).IDStr().isEmpty() ) { |
397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
398 | } | 398 | } |
399 | KABC::VCardConverter converter; | 399 | KABC::VCardConverter converter; |
400 | QString vcard; | 400 | QString vcard; |
401 | //Resource *resource() const; | 401 | //Resource *resource() const; |
402 | converter.addresseeToVCard( *it, vcard, version ); | 402 | converter.addresseeToVCard( *it, vcard, version ); |
403 | t << vcard << "\r\n"; | 403 | t << vcard << "\r\n"; |
404 | } | 404 | } |
405 | } | 405 | } |
406 | t << "\r\n\r\n"; | 406 | t << "\r\n\r\n"; |
407 | outFile.close(); | 407 | outFile.close(); |
408 | } | 408 | } |
409 | // if QStringList uids is empty, all are exported | 409 | // if QStringList uids is empty, all are exported |
410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) |
411 | { | 411 | { |
412 | KABC::VCardConverter converter; | 412 | KABC::VCardConverter converter; |
413 | QString datastream; | 413 | QString datastream; |
414 | Iterator it; | 414 | Iterator it; |
415 | bool all = uids.isEmpty(); | 415 | bool all = uids.isEmpty(); |
416 | for ( it = begin(); it != end(); ++it ) { | 416 | for ( it = begin(); it != end(); ++it ) { |
417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
418 | if ( ! all ) { | 418 | if ( ! all ) { |
419 | if ( ! ( uids.contains((*it).uid() ) )) | 419 | if ( ! ( uids.contains((*it).uid() ) )) |
420 | continue; | 420 | continue; |
421 | } | 421 | } |
422 | KABC::Addressee a = ( *it ); | 422 | KABC::Addressee a = ( *it ); |
423 | if ( a.isEmpty() ) | 423 | if ( a.isEmpty() ) |
424 | continue; | 424 | continue; |
425 | if ( all && a.resource() && !a.resource()->includeInSync() ) | 425 | if ( all && a.resource() && !a.resource()->includeInSync() ) |
426 | continue; | 426 | continue; |
427 | a.simplifyEmails(); | 427 | a.simplifyEmails(); |
428 | a.simplifyPhoneNumbers(); | 428 | a.simplifyPhoneNumbers(); |
429 | a.simplifyPhoneNumberTypes(); | 429 | a.simplifyPhoneNumberTypes(); |
430 | a.simplifyAddresses(); | 430 | a.simplifyAddresses(); |
431 | 431 | ||
432 | QString vcard; | 432 | QString vcard; |
433 | QString vcardnew; | 433 | QString vcardnew; |
434 | converter.addresseeToVCard( a, vcard ); | 434 | converter.addresseeToVCard( a, vcard ); |
435 | int start = 0; | 435 | int start = 0; |
436 | int next; | 436 | int next; |
437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
438 | int semi = vcard.find(";", next); | 438 | int semi = vcard.find(";", next); |
439 | int dopp = vcard.find(":", next); | 439 | int dopp = vcard.find(":", next); |
440 | int sep; | 440 | int sep; |
441 | if ( semi < dopp && semi >= 0 ) | 441 | if ( semi < dopp && semi >= 0 ) |
442 | sep = semi ; | 442 | sep = semi ; |
443 | else | 443 | else |
444 | sep = dopp; | 444 | sep = dopp; |
445 | vcardnew +=vcard.mid( start, next - start); | 445 | vcardnew +=vcard.mid( start, next - start); |
446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); | 446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); |
447 | start = sep; | 447 | start = sep; |
448 | } | 448 | } |
449 | vcardnew += vcard.mid( start,vcard.length() ); | 449 | vcardnew += vcard.mid( start,vcard.length() ); |
450 | vcard = ""; | 450 | vcard = ""; |
451 | start = 0; | 451 | start = 0; |
452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | 452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { |
453 | int sep = vcardnew.find(":", next); | 453 | int sep = vcardnew.find(":", next); |
454 | vcard +=vcardnew.mid( start, next - start+3); | 454 | vcard +=vcardnew.mid( start, next - start+3); |
455 | start = sep; | 455 | start = sep; |
456 | } | 456 | } |
457 | vcard += vcardnew.mid( start,vcardnew.length() ); | 457 | vcard += vcardnew.mid( start,vcardnew.length() ); |
458 | vcard.replace ( QRegExp(";;;") , "" ); | 458 | vcard.replace ( QRegExp(";;;") , "" ); |
459 | vcard.replace ( QRegExp(";;") , "" ); | 459 | vcard.replace ( QRegExp(";;") , "" ); |
460 | datastream += vcard; | 460 | datastream += vcard; |
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | QFile outFile(fileName); | 464 | QFile outFile(fileName); |
465 | if ( outFile.open(IO_WriteOnly) ) { | 465 | if ( outFile.open(IO_WriteOnly) ) { |
466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
467 | QTextStream t( &outFile ); // use a text stream | 467 | QTextStream t( &outFile ); // use a text stream |
468 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 468 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
469 | t <<datastream; | 469 | t <<datastream; |
470 | t << "\r\n\r\n"; | 470 | t << "\r\n\r\n"; |
471 | outFile.close(); | 471 | outFile.close(); |
472 | 472 | ||
473 | } else { | 473 | } else { |
474 | qDebug("Error open temp file "); | 474 | qDebug("Error open temp file "); |
475 | return false; | 475 | return false; |
476 | } | 476 | } |
477 | return true; | 477 | return true; |
478 | 478 | ||
479 | } | 479 | } |
480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
481 | { | 481 | { |
482 | 482 | ||
483 | if ( removeOld ) | 483 | if ( removeOld ) |
484 | setUntagged( true ); | 484 | setUntagged( true ); |
485 | KABC::Addressee::List list; | 485 | KABC::Addressee::List list; |
486 | QFile file( fileName ); | 486 | QFile file( fileName ); |
487 | file.open( IO_ReadOnly ); | 487 | file.open( IO_ReadOnly ); |
488 | QByteArray rawData = file.readAll(); | 488 | QByteArray rawData = file.readAll(); |
489 | file.close(); | 489 | file.close(); |
490 | QString data; | 490 | QString data; |
491 | if ( replaceLabel ) { | 491 | if ( replaceLabel ) { |
492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
493 | data.replace ( QRegExp("LABEL") , "ADR" ); | 493 | data.replace ( QRegExp("LABEL") , "ADR" ); |
494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
495 | } else | 495 | } else |
496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
497 | KABC::VCardTool tool; | 497 | KABC::VCardTool tool; |
498 | list = tool.parseVCards( data ); | 498 | list = tool.parseVCards( data ); |
499 | KABC::Addressee::List::Iterator it; | 499 | KABC::Addressee::List::Iterator it; |
500 | for ( it = list.begin(); it != list.end(); ++it ) { | 500 | for ( it = list.begin(); it != list.end(); ++it ) { |
501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
502 | if ( !id.isEmpty() ) | 502 | if ( !id.isEmpty() ) |
503 | (*it).setIDStr(id ); | 503 | (*it).setIDStr(id ); |
504 | (*it).setResource( 0 ); | 504 | (*it).setResource( 0 ); |
505 | if ( replaceLabel ) | 505 | if ( replaceLabel ) |
506 | (*it).removeVoice(); | 506 | (*it).removeVoice(); |
507 | if ( removeOld ) | 507 | if ( removeOld ) |
508 | (*it).setTagged( true ); | 508 | (*it).setTagged( true ); |
509 | insertAddressee( (*it), false, true ); | 509 | insertAddressee( (*it), false, true ); |
510 | } | 510 | } |
511 | if ( removeOld ) | 511 | if ( removeOld ) |
512 | removeUntagged(); | 512 | removeUntagged(); |
513 | return list.count(); | 513 | return list.count(); |
514 | } | 514 | } |
515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
516 | { | 516 | { |
517 | Iterator ait; | 517 | Iterator ait; |
518 | for ( ait = begin(); ait != end(); ++ait ) { | 518 | for ( ait = begin(); ait != end(); ++ait ) { |
519 | if ( setNonSyncTagged ) { | 519 | if ( setNonSyncTagged ) { |
520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { |
521 | (*ait).setTagged( true ); | 521 | (*ait).setTagged( true ); |
522 | } else | 522 | } else |
523 | (*ait).setTagged( false ); | 523 | (*ait).setTagged( false ); |
524 | } else | 524 | } else |
525 | (*ait).setTagged( false ); | 525 | (*ait).setTagged( false ); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | void AddressBook::removeUntagged() | 528 | void AddressBook::removeUntagged() |
529 | { | 529 | { |
530 | Iterator ait; | 530 | Iterator ait; |
531 | bool todelete = false; | 531 | bool todelete = false; |
532 | Iterator todel; | 532 | Iterator todel; |
533 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
534 | if ( todelete ) | 534 | if ( todelete ) |
535 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
536 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
537 | todelete = true; | 537 | todelete = true; |
538 | todel = ait; | 538 | todel = ait; |
539 | } else | 539 | } else |
540 | todelete = false; | 540 | todelete = false; |
541 | } | 541 | } |
542 | if ( todelete ) | 542 | if ( todelete ) |
543 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
544 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
545 | } | 545 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
547 | { | 547 | { |
548 | Iterator ait; | 548 | Iterator ait; |
549 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
550 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
551 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
552 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
553 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
554 | } | 554 | } |
555 | } | 555 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | ||
557 | { | ||
558 | Iterator ait; | ||
559 | for ( ait = begin(); ait != end(); ++ait ) { | ||
560 | (*ait).removeID( syncProfile ); | ||
561 | } | ||
562 | |||
563 | } | ||
556 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 564 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
557 | { | 565 | { |
558 | Iterator ait; | 566 | Iterator ait; |
559 | for ( ait = begin(); ait != end(); ++ait ) { | 567 | for ( ait = begin(); ait != end(); ++ait ) { |
560 | QString id = (*ait).IDStr(); | 568 | QString id = (*ait).IDStr(); |
561 | (*ait).setIDStr( ":"); | 569 | (*ait).setIDStr( ":"); |
562 | (*ait).setExternalUID( id ); | 570 | (*ait).setExternalUID( id ); |
563 | (*ait).setOriginalExternalUID( id ); | 571 | (*ait).setOriginalExternalUID( id ); |
564 | if ( isPreSync ) | 572 | if ( isPreSync ) |
565 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 573 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
566 | else { | 574 | else { |
567 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 575 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
568 | (*ait).setID( currentSyncDevice,id ); | 576 | (*ait).setID( currentSyncDevice,id ); |
569 | 577 | ||
570 | } | 578 | } |
571 | } | 579 | } |
572 | } | 580 | } |
573 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 581 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
574 | { | 582 | { |
575 | 583 | ||
576 | setUntagged(); | 584 | setUntagged(); |
577 | KABC::Addressee::List list; | 585 | KABC::Addressee::List list; |
578 | QFile file( fileName ); | 586 | QFile file( fileName ); |
579 | file.open( IO_ReadOnly ); | 587 | file.open( IO_ReadOnly ); |
580 | QByteArray rawData = file.readAll(); | 588 | QByteArray rawData = file.readAll(); |
581 | file.close(); | 589 | file.close(); |
582 | QString data; | 590 | QString data; |
583 | 591 | ||
584 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 592 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
585 | KABC::VCardTool tool; | 593 | KABC::VCardTool tool; |
586 | list = tool.parseVCards( data ); | 594 | list = tool.parseVCards( data ); |
587 | KABC::Addressee::List::Iterator it; | 595 | KABC::Addressee::List::Iterator it; |
588 | for ( it = list.begin(); it != list.end(); ++it ) { | 596 | for ( it = list.begin(); it != list.end(); ++it ) { |
589 | Iterator ait; | 597 | Iterator ait; |
590 | for ( ait = begin(); ait != end(); ++ait ) { | 598 | for ( ait = begin(); ait != end(); ++ait ) { |
591 | if ( !(*ait).tagged() ) { | 599 | if ( !(*ait).tagged() ) { |
592 | if ( (*ait).containsAdr(*it)) { | 600 | if ( (*ait).containsAdr(*it)) { |
593 | (*ait).setTagged(true); | 601 | (*ait).setTagged(true); |
594 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 602 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
595 | (*it).setIDStr( ":"); | 603 | (*it).setIDStr( ":"); |
596 | (*it).setID( currentSyncDevice,id ); | 604 | (*it).setID( currentSyncDevice,id ); |
597 | (*it).setExternalUID( id ); | 605 | (*it).setExternalUID( id ); |
598 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 606 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
599 | (*it).setUid( ( (*ait).uid() )); | 607 | (*it).setUid( ( (*ait).uid() )); |
600 | break; | 608 | break; |
601 | } | 609 | } |
602 | } | 610 | } |
603 | 611 | ||
604 | } | 612 | } |
605 | if ( ait == end() ) | 613 | if ( ait == end() ) |
606 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 614 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
607 | } | 615 | } |
608 | clear(); | 616 | clear(); |
609 | for ( it = list.begin(); it != list.end(); ++it ) { | 617 | for ( it = list.begin(); it != list.end(); ++it ) { |
610 | insertAddressee( (*it) ); | 618 | insertAddressee( (*it) ); |
611 | } | 619 | } |
612 | } | 620 | } |
613 | 621 | ||
614 | bool AddressBook::saveABphone( QString fileName ) | 622 | bool AddressBook::saveABphone( QString fileName ) |
615 | { | 623 | { |
616 | //smplifyAddressees(); | 624 | //smplifyAddressees(); |
617 | qDebug("saveABphone:: saving AB... "); | 625 | qDebug("saveABphone:: saving AB... "); |
618 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 626 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
619 | return false; | 627 | return false; |
620 | qDebug("saveABphone:: writing to phone... "); | 628 | qDebug("saveABphone:: writing to phone... "); |
621 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 629 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
622 | return false; | 630 | return false; |
623 | } | 631 | } |
624 | qDebug("saveABphone:: re-reading from phone... "); | 632 | qDebug("saveABphone:: re-reading from phone... "); |
625 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 633 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
626 | return false; | 634 | return false; |
627 | } | 635 | } |
628 | return true; | 636 | return true; |
629 | } | 637 | } |
630 | bool AddressBook::saveAB() | 638 | bool AddressBook::saveAB() |
631 | { | 639 | { |
632 | bool ok = true; | 640 | bool ok = true; |
633 | 641 | ||
634 | deleteRemovedAddressees(); | 642 | deleteRemovedAddressees(); |
635 | Iterator ait; | 643 | Iterator ait; |
636 | for ( ait = begin(); ait != end(); ++ait ) { | 644 | for ( ait = begin(); ait != end(); ++ait ) { |
637 | if ( !(*ait).IDStr().isEmpty() ) { | 645 | if ( !(*ait).IDStr().isEmpty() ) { |
638 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 646 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
639 | } | 647 | } |
640 | } | 648 | } |
641 | KRES::Manager<Resource>::ActiveIterator it; | 649 | KRES::Manager<Resource>::ActiveIterator it; |
642 | KRES::Manager<Resource> *manager = d->mManager; | 650 | KRES::Manager<Resource> *manager = d->mManager; |
643 | qDebug("SaveAB::saving..." ); | 651 | qDebug("SaveAB::saving..." ); |
644 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 652 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
645 | qDebug("SaveAB::checking resource..." ); | 653 | qDebug("SaveAB::checking resource..." ); |
646 | if ( (*it)->readOnly() ) | 654 | if ( (*it)->readOnly() ) |
647 | qDebug("resource is readonly." ); | 655 | qDebug("resource is readonly." ); |
648 | if ( (*it)->isOpen() ) | 656 | if ( (*it)->isOpen() ) |
649 | qDebug("resource is open" ); | 657 | qDebug("resource is open" ); |
650 | 658 | ||
651 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 659 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
652 | Ticket *ticket = requestSaveTicket( *it ); | 660 | Ticket *ticket = requestSaveTicket( *it ); |
653 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 661 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
654 | if ( !ticket ) { | 662 | if ( !ticket ) { |
655 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 663 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
656 | .arg( (*it)->resourceName() ) ); | 664 | .arg( (*it)->resourceName() ) ); |
657 | return false; | 665 | return false; |
658 | } | 666 | } |
659 | 667 | ||
660 | //if ( !save( ticket ) ) | 668 | //if ( !save( ticket ) ) |
661 | if ( ticket->resource() ) { | 669 | if ( ticket->resource() ) { |
662 | QString name = ticket->resource()->resourceName(); | 670 | QString name = ticket->resource()->resourceName(); |
663 | if ( ! ticket->resource()->save( ticket ) ) | 671 | if ( ! ticket->resource()->save( ticket ) ) |
664 | ok = false; | 672 | ok = false; |
665 | else | 673 | else |
666 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 674 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
667 | 675 | ||
668 | } else | 676 | } else |
669 | ok = false; | 677 | ok = false; |
670 | 678 | ||
671 | } | 679 | } |
672 | } | 680 | } |
673 | return ok; | 681 | return ok; |
674 | } | 682 | } |
675 | 683 | ||
676 | AddressBook::Iterator AddressBook::begin() | 684 | AddressBook::Iterator AddressBook::begin() |
677 | { | 685 | { |
678 | Iterator it = Iterator(); | 686 | Iterator it = Iterator(); |
679 | it.d->mIt = d->mAddressees.begin(); | 687 | it.d->mIt = d->mAddressees.begin(); |
680 | return it; | 688 | return it; |
681 | } | 689 | } |
682 | 690 | ||
683 | AddressBook::ConstIterator AddressBook::begin() const | 691 | AddressBook::ConstIterator AddressBook::begin() const |
684 | { | 692 | { |
685 | ConstIterator it = ConstIterator(); | 693 | ConstIterator it = ConstIterator(); |
686 | it.d->mIt = d->mAddressees.begin(); | 694 | it.d->mIt = d->mAddressees.begin(); |
687 | return it; | 695 | return it; |
688 | } | 696 | } |
689 | 697 | ||
690 | AddressBook::Iterator AddressBook::end() | 698 | AddressBook::Iterator AddressBook::end() |
691 | { | 699 | { |
692 | Iterator it = Iterator(); | 700 | Iterator it = Iterator(); |
693 | it.d->mIt = d->mAddressees.end(); | 701 | it.d->mIt = d->mAddressees.end(); |
694 | return it; | 702 | return it; |
695 | } | 703 | } |
696 | 704 | ||
697 | AddressBook::ConstIterator AddressBook::end() const | 705 | AddressBook::ConstIterator AddressBook::end() const |
698 | { | 706 | { |
699 | ConstIterator it = ConstIterator(); | 707 | ConstIterator it = ConstIterator(); |
700 | it.d->mIt = d->mAddressees.end(); | 708 | it.d->mIt = d->mAddressees.end(); |
701 | return it; | 709 | return it; |
702 | } | 710 | } |
703 | 711 | ||
704 | void AddressBook::clear() | 712 | void AddressBook::clear() |
705 | { | 713 | { |
706 | d->mAddressees.clear(); | 714 | d->mAddressees.clear(); |
707 | } | 715 | } |
708 | 716 | ||
709 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 717 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
710 | { | 718 | { |
711 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 719 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
712 | 720 | ||
713 | if ( !resource ) | 721 | if ( !resource ) |
714 | { | 722 | { |
715 | qDebug("AddressBook::requestSaveTicket no resource" ); | 723 | qDebug("AddressBook::requestSaveTicket no resource" ); |
716 | resource = standardResource(); | 724 | resource = standardResource(); |
717 | } | 725 | } |
718 | 726 | ||
719 | KRES::Manager<Resource>::ActiveIterator it; | 727 | KRES::Manager<Resource>::ActiveIterator it; |
720 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 728 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
721 | if ( (*it) == resource ) { | 729 | if ( (*it) == resource ) { |
722 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 730 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
723 | return 0; | 731 | return 0; |
724 | else | 732 | else |
725 | return (*it)->requestSaveTicket(); | 733 | return (*it)->requestSaveTicket(); |
726 | } | 734 | } |
727 | } | 735 | } |
728 | 736 | ||
729 | return 0; | 737 | return 0; |
730 | } | 738 | } |
731 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 739 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
732 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 740 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
733 | { | 741 | { |
734 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 742 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
735 | //qDebug("block insert "); | 743 | //qDebug("block insert "); |
736 | return; | 744 | return; |
737 | } | 745 | } |
738 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 746 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
739 | bool found = false; | 747 | bool found = false; |
740 | Addressee::List::Iterator it; | 748 | Addressee::List::Iterator it; |
741 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 749 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
742 | if ( a.uid() == (*it).uid() ) { | 750 | if ( a.uid() == (*it).uid() ) { |
743 | 751 | ||
744 | bool changed = false; | 752 | bool changed = false; |
745 | Addressee addr = a; | 753 | Addressee addr = a; |
746 | if ( addr != (*it) ) | 754 | if ( addr != (*it) ) |
747 | changed = true; | 755 | changed = true; |
748 | 756 | ||
749 | if ( takeResource ) { | 757 | if ( takeResource ) { |
750 | Resource * res = (*it).resource(); | 758 | Resource * res = (*it).resource(); |
751 | (*it) = a; | 759 | (*it) = a; |
752 | (*it).setResource( res ); | 760 | (*it).setResource( res ); |
753 | } else { | 761 | } else { |
754 | (*it) = a; | 762 | (*it) = a; |
755 | if ( (*it).resource() == 0 ) | 763 | if ( (*it).resource() == 0 ) |
756 | (*it).setResource( standardResource() ); | 764 | (*it).setResource( standardResource() ); |
757 | } | 765 | } |
758 | if ( changed ) { | 766 | if ( changed ) { |
759 | if ( setRev ) { | 767 | if ( setRev ) { |
760 | 768 | ||
761 | // get rid of micro seconds | 769 | // get rid of micro seconds |
762 | QDateTime dt = QDateTime::currentDateTime(); | 770 | QDateTime dt = QDateTime::currentDateTime(); |
763 | QTime t = dt.time(); | 771 | QTime t = dt.time(); |
764 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 772 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
765 | (*it).setRevision( dt ); | 773 | (*it).setRevision( dt ); |
766 | } | 774 | } |
767 | (*it).setChanged( true ); | 775 | (*it).setChanged( true ); |
768 | } | 776 | } |
769 | 777 | ||
770 | found = true; | 778 | found = true; |
771 | } else { | 779 | } else { |
772 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 780 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
773 | QString name = (*it).uid().mid( 19 ); | 781 | QString name = (*it).uid().mid( 19 ); |
774 | Addressee b = a; | 782 | Addressee b = a; |
775 | QString id = b.getID( name ); | 783 | QString id = b.getID( name ); |
776 | if ( ! id.isEmpty() ) { | 784 | if ( ! id.isEmpty() ) { |
777 | QString des = (*it).note(); | 785 | QString des = (*it).note(); |
778 | int startN; | 786 | int startN; |
779 | if( (startN = des.find( id ) ) >= 0 ) { | 787 | if( (startN = des.find( id ) ) >= 0 ) { |
780 | int endN = des.find( ",", startN+1 ); | 788 | int endN = des.find( ",", startN+1 ); |
781 | des = des.left( startN ) + des.mid( endN+1 ); | 789 | des = des.left( startN ) + des.mid( endN+1 ); |
782 | (*it).setNote( des ); | 790 | (*it).setNote( des ); |
783 | } | 791 | } |
784 | } | 792 | } |
785 | } | 793 | } |
786 | } | 794 | } |
787 | } | 795 | } |
788 | if ( found ) | 796 | if ( found ) |
789 | return; | 797 | return; |
790 | d->mAddressees.append( a ); | 798 | d->mAddressees.append( a ); |
791 | Addressee& addr = d->mAddressees.last(); | 799 | Addressee& addr = d->mAddressees.last(); |
792 | if ( addr.resource() == 0 ) | 800 | if ( addr.resource() == 0 ) |
793 | addr.setResource( standardResource() ); | 801 | addr.setResource( standardResource() ); |
794 | 802 | ||
795 | addr.setChanged( true ); | 803 | addr.setChanged( true ); |
796 | } | 804 | } |
797 | 805 | ||
798 | void AddressBook::removeAddressee( const Addressee &a ) | 806 | void AddressBook::removeAddressee( const Addressee &a ) |
799 | { | 807 | { |
800 | Iterator it; | 808 | Iterator it; |
801 | Iterator it2; | 809 | Iterator it2; |
802 | bool found = false; | 810 | bool found = false; |
803 | for ( it = begin(); it != end(); ++it ) { | 811 | for ( it = begin(); it != end(); ++it ) { |
804 | if ( a.uid() == (*it).uid() ) { | 812 | if ( a.uid() == (*it).uid() ) { |
805 | found = true; | 813 | found = true; |
806 | it2 = it; | 814 | it2 = it; |
807 | } else { | 815 | } else { |
808 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 816 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
809 | QString name = (*it).uid().mid( 19 ); | 817 | QString name = (*it).uid().mid( 19 ); |
810 | Addressee b = a; | 818 | Addressee b = a; |
811 | QString id = b.getID( name ); | 819 | QString id = b.getID( name ); |
812 | if ( ! id.isEmpty() ) { | 820 | if ( ! id.isEmpty() ) { |
813 | QString des = (*it).note(); | 821 | QString des = (*it).note(); |
814 | if( des.find( id ) < 0 ) { | 822 | if( des.find( id ) < 0 ) { |
815 | des += id + ","; | 823 | des += id + ","; |
816 | (*it).setNote( des ); | 824 | (*it).setNote( des ); |
817 | } | 825 | } |
818 | } | 826 | } |
819 | } | 827 | } |
820 | 828 | ||
821 | } | 829 | } |
822 | } | 830 | } |
823 | 831 | ||
824 | if ( found ) | 832 | if ( found ) |
825 | removeAddressee( it2 ); | 833 | removeAddressee( it2 ); |
826 | 834 | ||
827 | } | 835 | } |
828 | 836 | ||
829 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 837 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
830 | { | 838 | { |
831 | Iterator it = begin(); | 839 | Iterator it = begin(); |
832 | Iterator it2 ; | 840 | Iterator it2 ; |
833 | QDateTime dt ( QDate( 2004,1,1) ); | 841 | QDateTime dt ( QDate( 2004,1,1) ); |
834 | while ( it != end() ) { | 842 | while ( it != end() ) { |
835 | (*it).setRevision( dt ); | 843 | (*it).setRevision( dt ); |
836 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 844 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
837 | (*it).setIDStr(""); | 845 | (*it).setIDStr(""); |
838 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 846 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
839 | it2 = it; | 847 | it2 = it; |
840 | //qDebug("removing %s ",(*it).uid().latin1() ); | 848 | //qDebug("removing %s ",(*it).uid().latin1() ); |
841 | ++it; | 849 | ++it; |
842 | removeAddressee( it2 ); | 850 | removeAddressee( it2 ); |
843 | } else { | 851 | } else { |
844 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 852 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
845 | ++it; | 853 | ++it; |
846 | } | 854 | } |
847 | } | 855 | } |
848 | deleteRemovedAddressees(); | 856 | deleteRemovedAddressees(); |
849 | } | 857 | } |
850 | 858 | ||
851 | void AddressBook::removeAddressee( const Iterator &it ) | 859 | void AddressBook::removeAddressee( const Iterator &it ) |
852 | { | 860 | { |
853 | d->mRemovedAddressees.append( (*it) ); | 861 | d->mRemovedAddressees.append( (*it) ); |
854 | d->mAddressees.remove( it.d->mIt ); | 862 | d->mAddressees.remove( it.d->mIt ); |
855 | } | 863 | } |
856 | 864 | ||
857 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 865 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
858 | { | 866 | { |
859 | Iterator it; | 867 | Iterator it; |
860 | for ( it = begin(); it != end(); ++it ) { | 868 | for ( it = begin(); it != end(); ++it ) { |
861 | if ( a.uid() == (*it).uid() ) { | 869 | if ( a.uid() == (*it).uid() ) { |
862 | return it; | 870 | return it; |
863 | } | 871 | } |
864 | } | 872 | } |
865 | return end(); | 873 | return end(); |
866 | } | 874 | } |
867 | 875 | ||
868 | Addressee AddressBook::findByUid( const QString &uid ) | 876 | Addressee AddressBook::findByUid( const QString &uid ) |
869 | { | 877 | { |
870 | Iterator it; | 878 | Iterator it; |
871 | for ( it = begin(); it != end(); ++it ) { | 879 | for ( it = begin(); it != end(); ++it ) { |
872 | if ( uid == (*it).uid() ) { | 880 | if ( uid == (*it).uid() ) { |
873 | return *it; | 881 | return *it; |
874 | } | 882 | } |
875 | } | 883 | } |
876 | return Addressee(); | 884 | return Addressee(); |
877 | } | 885 | } |
878 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 886 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
879 | { | 887 | { |
880 | //qDebug("AddressBook::preExternSync "); | 888 | //qDebug("AddressBook::preExternSync "); |
881 | AddressBook::Iterator it; | 889 | AddressBook::Iterator it; |
882 | for ( it = begin(); it != end(); ++it ) { | 890 | for ( it = begin(); it != end(); ++it ) { |
883 | (*it).setID( csd, (*it).externalUID() ); | 891 | (*it).setID( csd, (*it).externalUID() ); |
884 | (*it).computeCsum( csd ); | 892 | (*it).computeCsum( csd ); |
885 | } | 893 | } |
886 | mergeAB( aBook ,csd, isSubset ); | 894 | mergeAB( aBook ,csd, isSubset ); |
887 | } | 895 | } |
888 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 896 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
889 | { | 897 | { |
890 | //qDebug("AddressBook::postExternSync "); | 898 | //qDebug("AddressBook::postExternSync "); |
891 | AddressBook::Iterator it; | 899 | AddressBook::Iterator it; |
892 | for ( it = begin(); it != end(); ++it ) { | 900 | for ( it = begin(); it != end(); ++it ) { |
893 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 901 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
894 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 902 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
895 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 903 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
896 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 904 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
897 | if ( ad.isEmpty() ) { | 905 | if ( ad.isEmpty() ) { |
898 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 906 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
899 | } else { | 907 | } else { |
900 | (*it).computeCsum( csd ); | 908 | (*it).computeCsum( csd ); |
901 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 909 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
902 | ad.setID( csd, (*it).externalUID() ); | 910 | ad.setID( csd, (*it).externalUID() ); |
903 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 911 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
904 | aBook->insertAddressee( ad ); | 912 | aBook->insertAddressee( ad ); |
905 | } | 913 | } |
906 | } | 914 | } |
907 | } | 915 | } |
908 | } | 916 | } |
909 | 917 | ||
910 | bool AddressBook::containsExternalUid( const QString& uid ) | 918 | bool AddressBook::containsExternalUid( const QString& uid ) |
911 | { | 919 | { |
912 | Iterator it; | 920 | Iterator it; |
913 | for ( it = begin(); it != end(); ++it ) { | 921 | for ( it = begin(); it != end(); ++it ) { |
914 | if ( uid == (*it).externalUID( ) ) | 922 | if ( uid == (*it).externalUID( ) ) |
915 | return true; | 923 | return true; |
916 | } | 924 | } |
917 | return false; | 925 | return false; |
918 | } | 926 | } |
919 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 927 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
920 | { | 928 | { |
921 | Iterator it; | 929 | Iterator it; |
922 | for ( it = begin(); it != end(); ++it ) { | 930 | for ( it = begin(); it != end(); ++it ) { |
923 | if ( uid == (*it).getID( profile ) ) | 931 | if ( uid == (*it).getID( profile ) ) |
924 | return (*it); | 932 | return (*it); |
925 | } | 933 | } |
926 | return Addressee(); | 934 | return Addressee(); |
927 | } | 935 | } |
928 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 936 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
929 | { | 937 | { |
930 | Iterator it; | 938 | Iterator it; |
931 | Addressee ad; | 939 | Addressee ad; |
932 | for ( it = begin(); it != end(); ++it ) { | 940 | for ( it = begin(); it != end(); ++it ) { |
933 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 941 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
934 | if ( !ad.isEmpty() ) { | 942 | if ( !ad.isEmpty() ) { |
935 | (*it).mergeContact( ad ,isSubset); | 943 | (*it).mergeContact( ad ,isSubset); |
936 | } | 944 | } |
937 | } | 945 | } |
938 | #if 0 | 946 | #if 0 |
939 | // test only | 947 | // test only |