summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp8
-rw-r--r--kabc/addressbook.h1
-rw-r--r--kabc/addressee.cpp5
-rw-r--r--kaddressbook/kabcore.cpp4
-rw-r--r--korganizer/calendarview.cpp1
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/calendarlocal.cpp23
-rw-r--r--libkcal/calendarlocal.h1
-rw-r--r--libkcal/incidencebase.cpp5
-rw-r--r--libkdepim/ksyncmanager.cpp42
-rw-r--r--libkdepim/ksyncmanager.h1
11 files changed, 85 insertions, 7 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
175AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
176{ 176{
177 delete d; 177 delete d;
178} 178}
179 179
180const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
181{ 181{
182 return *(d->mIt); 182 return *(d->mIt);
183} 183}
184 184
185const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
186{ 186{
187 return &(*(d->mIt)); 187 return &(*(d->mIt));
188} 188}
189 189
190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
191{ 191{
192 (d->mIt)++; 192 (d->mIt)++;
193 return *this; 193 return *this;
194} 194}
195 195
196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
197{ 197{
198 (d->mIt)++; 198 (d->mIt)++;
199 return *this; 199 return *this;
200} 200}
201 201
202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
203{ 203{
204 (d->mIt)--; 204 (d->mIt)--;
205 return *this; 205 return *this;
206} 206}
207 207
208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
209{ 209{
210 (d->mIt)--; 210 (d->mIt)--;
211 return *this; 211 return *this;
212} 212}
213 213
214bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool 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
219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool 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
225AddressBook::AddressBook() 225AddressBook::AddressBook()
226{ 226{
227 init(0, "contact"); 227 init(0, "contact");
228} 228}
229 229
230AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
231{ 231{
232 init(config, "contact"); 232 init(config, "contact");
233} 233}
234 234
235AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::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"
242void AddressBook::init(const QString &config, const QString &family ) 242void 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
333AddressBook::~AddressBook() 333AddressBook::~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
341bool AddressBook::load() 341bool 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
368bool AddressBook::save( Ticket *ticket ) 368bool 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
380void AddressBook::export2File( QString fileName ) 380void 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
410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 410bool 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}
480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 480int 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}
515void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 515void 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}
528void AddressBook::removeUntagged() 528void 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}
546void AddressBook::smplifyAddressees() 546void 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}
556void AddressBook::removeSyncInfo( QString syncProfile)
557{
558 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) {
560 (*ait).removeID( syncProfile );
561 }
562
563}
556void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 564void 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}
573void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 581void 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
614bool AddressBook::saveABphone( QString fileName ) 622bool 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}
630bool AddressBook::saveAB() 638bool 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
676AddressBook::Iterator AddressBook::begin() 684AddressBook::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
683AddressBook::ConstIterator AddressBook::begin() const 691AddressBook::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
690AddressBook::Iterator AddressBook::end() 698AddressBook::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
697AddressBook::ConstIterator AddressBook::end() const 705AddressBook::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
704void AddressBook::clear() 712void AddressBook::clear()
705{ 713{
706 d->mAddressees.clear(); 714 d->mAddressees.clear();
707} 715}
708 716
709Ticket *AddressBook::requestSaveTicket( Resource *resource ) 717Ticket *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);
732void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 740void 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
798void AddressBook::removeAddressee( const Addressee &a ) 806void 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
829void AddressBook::removeSyncAddressees( bool removeDeleted ) 837void 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
851void AddressBook::removeAddressee( const Iterator &it ) 859void 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
857AddressBook::Iterator AddressBook::find( const Addressee &a ) 865AddressBook::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
868Addressee AddressBook::findByUid( const QString &uid ) 876Addressee 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}
878void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 886void 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}
888void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 896void 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
910bool AddressBook::containsExternalUid( const QString& uid ) 918bool 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}
919Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 927Addressee 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}
928void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 936void 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
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 5edca06..f124dc9 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,348 +1,349 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_ADDRESSBOOK_H 28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H 29#define KABC_ADDRESSBOOK_H
30 30
31#include <qobject.h> 31#include <qobject.h>
32 32
33#include <kresources/manager.h> 33#include <kresources/manager.h>
34#include <qptrlist.h> 34#include <qptrlist.h>
35 35
36#include "addressee.h" 36#include "addressee.h"
37#include "field.h" 37#include "field.h"
38 38
39namespace KABC { 39namespace KABC {
40 40
41class ErrorHandler; 41class ErrorHandler;
42class Resource; 42class Resource;
43class Ticket; 43class Ticket;
44 44
45/** 45/**
46 @short Address Book 46 @short Address Book
47 47
48 This class provides access to a collection of address book entries. 48 This class provides access to a collection of address book entries.
49*/ 49*/
50class AddressBook : public QObject 50class AddressBook : public QObject
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 friend QDataStream &operator<<( QDataStream &, const AddressBook & ); 54 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
55 friend QDataStream &operator>>( QDataStream &, AddressBook & ); 55 friend QDataStream &operator>>( QDataStream &, AddressBook & );
56 friend class StdAddressBook; 56 friend class StdAddressBook;
57 57
58 public: 58 public:
59 /** 59 /**
60 @short Address Book Iterator 60 @short Address Book Iterator
61 61
62 This class provides an iterator for address book entries. 62 This class provides an iterator for address book entries.
63 */ 63 */
64 class Iterator 64 class Iterator
65 { 65 {
66 public: 66 public:
67 Iterator(); 67 Iterator();
68 Iterator( const Iterator & ); 68 Iterator( const Iterator & );
69 ~Iterator(); 69 ~Iterator();
70 70
71 Iterator &operator=( const Iterator & ); 71 Iterator &operator=( const Iterator & );
72 const Addressee &operator*() const; 72 const Addressee &operator*() const;
73 Addressee &operator*(); 73 Addressee &operator*();
74 Addressee* operator->(); 74 Addressee* operator->();
75 Iterator &operator++(); 75 Iterator &operator++();
76 Iterator &operator++(int); 76 Iterator &operator++(int);
77 Iterator &operator--(); 77 Iterator &operator--();
78 Iterator &operator--(int); 78 Iterator &operator--(int);
79 bool operator==( const Iterator &it ); 79 bool operator==( const Iterator &it );
80 bool operator!=( const Iterator &it ); 80 bool operator!=( const Iterator &it );
81 81
82 struct IteratorData; 82 struct IteratorData;
83 IteratorData *d; 83 IteratorData *d;
84 }; 84 };
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 bool saveABphone( QString fileName ); 145 bool saveABphone( QString fileName );
146 void smplifyAddressees(); 146 void smplifyAddressees();
147 void removeSyncInfo( QString syncProfile);
147 void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); 148 void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
148 void export2File( QString fileName ); 149 void export2File( QString fileName );
149 bool export2PhoneFormat( QStringList uids ,QString fileName ); 150 bool export2PhoneFormat( QStringList uids ,QString fileName );
150 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); 151 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
151 void setUntagged( bool setNonSyncTagged = false ); 152 void setUntagged( bool setNonSyncTagged = false );
152 void removeUntagged(); 153 void removeUntagged();
153 void findNewExtIds( QString fileName, QString currentSyncDevice ); 154 void findNewExtIds( QString fileName, QString currentSyncDevice );
154 /** 155 /**
155 Returns a iterator for first entry of address book. 156 Returns a iterator for first entry of address book.
156 */ 157 */
157 Iterator begin(); 158 Iterator begin();
158 159
159 /** 160 /**
160 Returns a const iterator for first entry of address book. 161 Returns a const iterator for first entry of address book.
161 */ 162 */
162 ConstIterator begin() const; 163 ConstIterator begin() const;
163 164
164 /** 165 /**
165 Returns a iterator for first entry of address book. 166 Returns a iterator for first entry of address book.
166 */ 167 */
167 Iterator end(); 168 Iterator end();
168 169
169 /** 170 /**
170 Returns a const iterator for first entry of address book. 171 Returns a const iterator for first entry of address book.
171 */ 172 */
172 ConstIterator end() const; 173 ConstIterator end() const;
173 174
174 /** 175 /**
175 Removes all entries from address book. 176 Removes all entries from address book.
176 */ 177 */
177 void clear(); 178 void clear();
178 179
179 /** 180 /**
180 Insert an Addressee object into address book. If an object with the same 181 Insert an Addressee object into address book. If an object with the same
181 unique id already exists in the address book it it replaced by the new 182 unique id already exists in the address book it it replaced by the new
182 one. If not the new object is appended to the address book. 183 one. If not the new object is appended to the address book.
183 */ 184 */
184 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 185 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
185 186
186 /** 187 /**
187 Removes entry from the address book. 188 Removes entry from the address book.
188 */ 189 */
189 void removeAddressee( const Addressee & ); 190 void removeAddressee( const Addressee & );
190 191
191 /** 192 /**
192 This is like @ref removeAddressee() just above, with the difference that 193 This is like @ref removeAddressee() just above, with the difference that
193 the first element is a iterator, returned by @ref begin(). 194 the first element is a iterator, returned by @ref begin().
194 */ 195 */
195 void removeAddressee( const Iterator & ); 196 void removeAddressee( const Iterator & );
196 197
197 /** 198 /**
198 Find the specified entry in address book. Returns end(), if the entry 199 Find the specified entry in address book. Returns end(), if the entry
199 couldn't be found. 200 couldn't be found.
200 */ 201 */
201 Iterator find( const Addressee & ); 202 Iterator find( const Addressee & );
202 203
203 /** 204 /**
204 Find the entry specified by an unique id. Returns an empty Addressee 205 Find the entry specified by an unique id. Returns an empty Addressee
205 object, if the address book does not contain an entry with this id. 206 object, if the address book does not contain an entry with this id.
206 */ 207 */
207 Addressee findByUid( const QString & ); 208 Addressee findByUid( const QString & );
208 209
209 210
210 /** 211 /**
211 Returns a list of all addressees in the address book. This list can 212 Returns a list of all addressees in the address book. This list can
212 be sorted with @ref KABC::AddresseeList for example. 213 be sorted with @ref KABC::AddresseeList for example.
213 */ 214 */
214 Addressee::List allAddressees(); 215 Addressee::List allAddressees();
215 216
216 /** 217 /**
217 Find all entries with the specified name in the address book. Returns 218 Find all entries with the specified name in the address book. Returns
218 an empty list, if no entries could be found. 219 an empty list, if no entries could be found.
219 */ 220 */
220 Addressee::List findByName( const QString & ); 221 Addressee::List findByName( const QString & );
221 222
222 /** 223 /**
223 Find all entries with the specified email address in the address book. 224 Find all entries with the specified email address in the address book.
224 Returns an empty list, if no entries could be found. 225 Returns an empty list, if no entries could be found.
225 */ 226 */
226 Addressee::List findByEmail( const QString & ); 227 Addressee::List findByEmail( const QString & );
227 228
228 /** 229 /**
229 Find all entries wich have the specified category in the address book. 230 Find all entries wich have the specified category in the address book.
230 Returns an empty list, if no entries could be found. 231 Returns an empty list, if no entries could be found.
231 */ 232 */
232 Addressee::List findByCategory( const QString & ); 233 Addressee::List findByCategory( const QString & );
233 234
234 /** 235 /**
235 Return a string identifying this addressbook. 236 Return a string identifying this addressbook.
236 */ 237 */
237 virtual QString identifier(); 238 virtual QString identifier();
238 239
239 /** 240 /**
240 Used for debug output. 241 Used for debug output.
241 */ 242 */
242 void dump() const; 243 void dump() const;
243 244
244 void emitAddressBookLocked() { emit addressBookLocked( this ); } 245 void emitAddressBookLocked() { emit addressBookLocked( this ); }
245 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
246 void emitAddressBookChanged() { emit addressBookChanged( this ); } 247 void emitAddressBookChanged() { emit addressBookChanged( this ); }
247 248
248 /** 249 /**
249 Return list of all Fields known to the address book which are associated 250 Return list of all Fields known to the address book which are associated
250 with the given field category. 251 with the given field category.
251 */ 252 */
252 Field::List fields( int category = Field::All ); 253 Field::List fields( int category = Field::All );
253 254
254 /** 255 /**
255 Add custom field to address book. 256 Add custom field to address book.
256 257
257 @param label User visible label of the field. 258 @param label User visible label of the field.
258 @param category Ored list of field categories. 259 @param category Ored list of field categories.
259 @param key Identifier used as key for reading and writing the field. 260 @param key Identifier used as key for reading and writing the field.
260 @param app String used as application key for reading and writing 261 @param app String used as application key for reading and writing
261 the field. 262 the field.
262 */ 263 */
263 bool addCustomField( const QString &label, int category = Field::All, 264 bool addCustomField( const QString &label, int category = Field::All,
264 const QString &key = QString::null, 265 const QString &key = QString::null,
265 const QString &app = QString::null ); 266 const QString &app = QString::null );
266 267
267 268
268 /** 269 /**
269 Add address book resource. 270 Add address book resource.
270 */ 271 */
271 bool addResource( Resource * ); 272 bool addResource( Resource * );
272 273
273 /** 274 /**
274 Remove address book resource. 275 Remove address book resource.
275 */ 276 */
276 bool removeResource( Resource * ); 277 bool removeResource( Resource * );
277 278
278 /** 279 /**
279 Return pointer list of all resources. 280 Return pointer list of all resources.
280 */ 281 */
281 QPtrList<Resource> resources(); 282 QPtrList<Resource> resources();
282 283
283 /** 284 /**
284 Set the @p ErrorHandler, that is used by @ref error() to 285 Set the @p ErrorHandler, that is used by @ref error() to
285 provide gui-independend error messages. 286 provide gui-independend error messages.
286 */ 287 */
287 void setErrorHandler( ErrorHandler * ); 288 void setErrorHandler( ErrorHandler * );
288 289
289 /** 290 /**
290 Shows gui independend error messages. 291 Shows gui independend error messages.
291 */ 292 */
292 void error( const QString& ); 293 void error( const QString& );
293 294
294 /** 295 /**
295 Query all resources to clean up their lock files 296 Query all resources to clean up their lock files
296 */ 297 */
297 void cleanUp(); 298 void cleanUp();
298 299
299 // sync stuff 300 // sync stuff
300 //Addressee::List getExternLastSyncAddressees(); 301 //Addressee::List getExternLastSyncAddressees();
301 void resetTempSyncStat(); 302 void resetTempSyncStat();
302 QStringList uidList(); 303 QStringList uidList();
303 void removeSyncAddressees( bool removeDeleted = false ); 304 void removeSyncAddressees( bool removeDeleted = false );
304 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); 305 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset );
305 Addressee findByExternUid( const QString& uid , const QString& profile ); 306 Addressee findByExternUid( const QString& uid , const QString& profile );
306 bool containsExternalUid( const QString& uid ); 307 bool containsExternalUid( const QString& uid );
307 308
308 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); 309 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset );
309 void postExternSync( AddressBook* aBook, const QString& csd ); 310 void postExternSync( AddressBook* aBook, const QString& csd );
310 signals: 311 signals:
311 /** 312 /**
312 Emitted, when the address book has changed on disk. 313 Emitted, when the address book has changed on disk.
313 */ 314 */
314 void addressBookChanged( AddressBook * ); 315 void addressBookChanged( AddressBook * );
315 316
316 /** 317 /**
317 Emitted, when the address book has been locked for writing. 318 Emitted, when the address book has been locked for writing.
318 */ 319 */
319 void addressBookLocked( AddressBook * ); 320 void addressBookLocked( AddressBook * );
320 321
321 /** 322 /**
322 Emitted, when the address book has been unlocked. 323 Emitted, when the address book has been unlocked.
323 */ 324 */
324 void addressBookUnlocked( AddressBook * ); 325 void addressBookUnlocked( AddressBook * );
325 326
326 protected: 327 protected:
327 void deleteRemovedAddressees(); 328 void deleteRemovedAddressees();
328 void setStandardResource( Resource * ); 329 void setStandardResource( Resource * );
329 Resource *standardResource(); 330 Resource *standardResource();
330 KRES::Manager<Resource> *resourceManager(); 331 KRES::Manager<Resource> *resourceManager();
331 332
332 void init(const QString &config, const QString &family); 333 void init(const QString &config, const QString &family);
333 334
334 private: 335 private:
335//US QPtrList<Resource> mDummy; // Remove in KDE 4 336//US QPtrList<Resource> mDummy; // Remove in KDE 4
336 337
337 338
338 struct AddressBookData; 339 struct AddressBookData;
339 AddressBookData *d; 340 AddressBookData *d;
340 bool blockLSEchange; 341 bool blockLSEchange;
341}; 342};
342 343
343QDataStream &operator<<( QDataStream &, const AddressBook & ); 344QDataStream &operator<<( QDataStream &, const AddressBook & );
344QDataStream &operator>>( QDataStream &, AddressBook & ); 345QDataStream &operator>>( QDataStream &, AddressBook & );
345 346
346} 347}
347 348
348#endif 349#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 40877ef..a660a9d 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -172,769 +172,772 @@ bool Addressee::operator==( const Addressee &a ) const
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 302
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 ( ( *phoneItAD ).contains( (*it) ) ) { 310 if ( ( *phoneItAD ).contains( (*it) ) ) {
311 found = true; 311 found = true;
312 (*it).setType( ( *phoneItAD ).type() ); 312 (*it).setType( ( *phoneItAD ).type() );
313 (*it).setNumber( ( *phoneItAD ).number() ); 313 (*it).setNumber( ( *phoneItAD ).number() );
314 break; 314 break;
315 } 315 }
316 } 316 }
317 if ( isSubSet && ! found ) 317 if ( isSubSet && ! found )
318 mData->phoneNumbers.append( *phoneItAD ); 318 mData->phoneNumbers.append( *phoneItAD );
319 } 319 }
320 if ( isSubSet ) { 320 if ( isSubSet ) {
321 // ************* emails; 321 // ************* emails;
322 t = mData->emails; 322 t = mData->emails;
323 tAD = ad.mData->emails; 323 tAD = ad.mData->emails;
324 for ( iii = 0; iii < tAD.count(); ++iii) 324 for ( iii = 0; iii < tAD.count(); ++iii)
325 if ( !t.contains(tAD[iii] ) ) 325 if ( !t.contains(tAD[iii] ) )
326 mData->emails.append( tAD[iii] ); 326 mData->emails.append( tAD[iii] );
327 } 327 }
328 328
329 // ************* categories; 329 // ************* categories;
330 t = mData->categories; 330 t = mData->categories;
331 tAD = ad.mData->categories; 331 tAD = ad.mData->categories;
332 for ( iii = 0; iii < tAD.count(); ++iii) 332 for ( iii = 0; iii < tAD.count(); ++iii)
333 if ( !t.contains(tAD[iii] ) ) 333 if ( !t.contains(tAD[iii] ) )
334 mData->categories.append( tAD[iii] ); 334 mData->categories.append( tAD[iii] );
335 QStringList::ConstIterator it; 335 QStringList::ConstIterator it;
336 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 ) {
337 QString qualifiedName = (*it).left( (*it).find( ":" )); 337 QString qualifiedName = (*it).left( (*it).find( ":" ));
338 bool found = false; 338 bool found = false;
339 QStringList::ConstIterator itL; 339 QStringList::ConstIterator itL;
340 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 340 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
341 if ( (*itL).startsWith( qualifiedName ) ) { 341 if ( (*itL).startsWith( qualifiedName ) ) {
342 found = true; 342 found = true;
343 break; 343 break;
344 } 344 }
345 } 345 }
346 if ( ! found ) { 346 if ( ! found ) {
347 mData->custom.append( *it ); 347 mData->custom.append( *it );
348 } 348 }
349 } 349 }
350 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;
351 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;
352 if ( !mData->sound.isIntern() ) { 352 if ( !mData->sound.isIntern() ) {
353 if ( mData->sound.url().isEmpty() ) { 353 if ( mData->sound.url().isEmpty() ) {
354 mData->sound = ad.mData->sound; 354 mData->sound = ad.mData->sound;
355 } 355 }
356 } 356 }
357 if ( !mData->agent.isIntern() ) { 357 if ( !mData->agent.isIntern() ) {
358 if ( mData->agent.url().isEmpty() ) { 358 if ( mData->agent.url().isEmpty() ) {
359 mData->agent = ad.mData->agent; 359 mData->agent = ad.mData->agent;
360 } 360 }
361 } 361 }
362 { 362 {
363 Key::List::Iterator itA; 363 Key::List::Iterator itA;
364 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { 364 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
365 bool found = false; 365 bool found = false;
366 Key::List::Iterator it; 366 Key::List::Iterator it;
367 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 367 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
368 if ( (*it) == (*itA)) { 368 if ( (*it) == (*itA)) {
369 found = true; 369 found = true;
370 break; 370 break;
371 371
372 } 372 }
373 } 373 }
374 if ( ! found ) { 374 if ( ! found ) {
375 mData->keys.append( *itA ); 375 mData->keys.append( *itA );
376 } 376 }
377 } 377 }
378 } 378 }
379 KABC::Address::List::Iterator addressIterA; 379 KABC::Address::List::Iterator addressIterA;
380 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { 380 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
381 bool found = false; 381 bool found = false;
382 KABC::Address::List::Iterator addressIter; 382 KABC::Address::List::Iterator addressIter;
383 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 383 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
384 ++addressIter ) { 384 ++addressIter ) {
385 if ( (*addressIter) == (*addressIterA)) { 385 if ( (*addressIter) == (*addressIterA)) {
386 found = true; 386 found = true;
387 (*addressIter).setType( (*addressIterA).type() ); 387 (*addressIter).setType( (*addressIterA).type() );
388 break; 388 break;
389 } 389 }
390 390
391 } 391 }
392 if ( isSubSet && ! found ) { 392 if ( isSubSet && ! found ) {
393 mData->addresses.append( *addressIterA ); 393 mData->addresses.append( *addressIterA );
394 } 394 }
395 } 395 }
396 //qDebug("merge contact %s ", ad.uid().latin1()); 396 //qDebug("merge contact %s ", ad.uid().latin1());
397 setUid( ad.uid() ); 397 setUid( ad.uid() );
398 setRevision( ad.revision() ); 398 setRevision( ad.revision() );
399} 399}
400 400
401bool Addressee::removeVoice() 401bool Addressee::removeVoice()
402{ 402{
403 PhoneNumber::List phoneN = phoneNumbers(); 403 PhoneNumber::List phoneN = phoneNumbers();
404 PhoneNumber::List::Iterator phoneIt; 404 PhoneNumber::List::Iterator phoneIt;
405 bool found = false; 405 bool found = false;
406 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 406 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
407 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 407 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
408 if ((*phoneIt).type() - PhoneNumber::Voice ) { 408 if ((*phoneIt).type() - PhoneNumber::Voice ) {
409 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 409 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
410 insertPhoneNumber( (*phoneIt) ); 410 insertPhoneNumber( (*phoneIt) );
411 found = true; 411 found = true;
412 } 412 }
413 } 413 }
414 414
415 } 415 }
416 return found; 416 return found;
417} 417}
418 418
419bool Addressee::containsAdr(const Addressee& ad ) 419bool Addressee::containsAdr(const Addressee& ad )
420{ 420{
421 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;
422 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;
423 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 ;
424 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 ;
425 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 ;
426 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 ;
427 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 ;
428 428
429 // compare phone numbers 429 // compare phone numbers
430 PhoneNumber::List phoneN = ad.phoneNumbers(); 430 PhoneNumber::List phoneN = ad.phoneNumbers();
431 PhoneNumber::List::Iterator phoneIt; 431 PhoneNumber::List::Iterator phoneIt;
432 bool found = false; 432 bool found = false;
433 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 433 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
434 bool found = false; 434 bool found = false;
435 PhoneNumber::List phoneL = ad.phoneNumbers(); 435 PhoneNumber::List phoneL = ad.phoneNumbers();
436 PhoneNumber::List::Iterator phoneItL; 436 PhoneNumber::List::Iterator phoneItL;
437 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 437 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
438 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 438 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
439 found = true; 439 found = true;
440 break; 440 break;
441 } 441 }
442 } 442 }
443 if ( ! found ) 443 if ( ! found )
444 return false; 444 return false;
445 } 445 }
446 return true; 446 return true;
447 447
448} 448}
449void Addressee::simplifyAddresses() 449void Addressee::simplifyAddresses()
450{ 450{
451 451
452 452
453 Address::List list; 453 Address::List list;
454 Address::List::Iterator it; 454 Address::List::Iterator it;
455 Address::List::Iterator it2; 455 Address::List::Iterator it2;
456 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 456 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
457 it2 = it; 457 it2 = it;
458 ++it2; 458 ++it2;
459 for( ; it2 != mData->addresses.end(); ++it2 ) { 459 for( ; it2 != mData->addresses.end(); ++it2 ) {
460 if ( (*it) == (*it2) ) { 460 if ( (*it) == (*it2) ) {
461 list.append( *it ); 461 list.append( *it );
462 break; 462 break;
463 } 463 }
464 } 464 }
465 } 465 }
466 for( it = list.begin(); it != list.end(); ++it ) { 466 for( it = list.begin(); it != list.end(); ++it ) {
467 removeAddress( (*it) ); 467 removeAddress( (*it) );
468 } 468 }
469 469
470 list.clear(); 470 list.clear();
471 int max = 2; 471 int max = 2;
472 if ( mData->url.isValid() ) 472 if ( mData->url.isValid() )
473 max = 1; 473 max = 1;
474 if ( mData->addresses.count() <= max ) return ; 474 if ( mData->addresses.count() <= max ) return ;
475 int count = 0; 475 int count = 0;
476 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 476 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
477 if ( count >= max ) 477 if ( count >= max )
478 list.append( *it ); 478 list.append( *it );
479 ++count; 479 ++count;
480 } 480 }
481 for( it = list.begin(); it != list.end(); ++it ) { 481 for( it = list.begin(); it != list.end(); ++it ) {
482 removeAddress( (*it) ); 482 removeAddress( (*it) );
483 } 483 }
484} 484}
485 485
486// removes all emails but the first 486// removes all emails but the first
487// needed by phone sync 487// needed by phone sync
488void Addressee::simplifyEmails() 488void Addressee::simplifyEmails()
489{ 489{
490 if ( mData->emails.count() == 0 ) return ; 490 if ( mData->emails.count() == 0 ) return ;
491 QString email = mData->emails.first(); 491 QString email = mData->emails.first();
492 detach(); 492 detach();
493 mData->emails.clear(); 493 mData->emails.clear();
494 mData->emails.append( email ); 494 mData->emails.append( email );
495} 495}
496 496
497void Addressee::simplifyPhoneNumbers() 497void Addressee::simplifyPhoneNumbers()
498{ 498{
499 int max = 4; 499 int max = 4;
500 int inList = mData->phoneNumbers.count(); 500 int inList = mData->phoneNumbers.count();
501 KABC::PhoneNumber::List removeNumbers; 501 KABC::PhoneNumber::List removeNumbers;
502 KABC::PhoneNumber::List::Iterator phoneIter; 502 KABC::PhoneNumber::List::Iterator phoneIter;
503 if ( inList > max ) { 503 if ( inList > max ) {
504 // delete non-preferred numbers 504 // delete non-preferred numbers
505 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 505 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
506 ++phoneIter ) { 506 ++phoneIter ) {
507 if ( inList > max ) { 507 if ( inList > max ) {
508 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { 508 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
509 removeNumbers.append( ( *phoneIter ) ); 509 removeNumbers.append( ( *phoneIter ) );
510 --inList; 510 --inList;
511 } 511 }
512 } else 512 } else
513 break; 513 break;
514 } 514 }
515 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 515 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
516 ++phoneIter ) { 516 ++phoneIter ) {
517 removePhoneNumber(( *phoneIter )); 517 removePhoneNumber(( *phoneIter ));
518 } 518 }
519 // delete preferred numbers 519 // delete preferred numbers
520 if ( inList > max ) { 520 if ( inList > max ) {
521 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 521 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
522 ++phoneIter ) { 522 ++phoneIter ) {
523 if ( inList > max ) { 523 if ( inList > max ) {
524 removeNumbers.append( ( *phoneIter ) ); 524 removeNumbers.append( ( *phoneIter ) );
525 --inList; 525 --inList;
526 } else 526 } else
527 break; 527 break;
528 } 528 }
529 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 529 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
530 ++phoneIter ) { 530 ++phoneIter ) {
531 removePhoneNumber(( *phoneIter )); 531 removePhoneNumber(( *phoneIter ));
532 } 532 }
533 } 533 }
534 } 534 }
535 // remove non-numeric characters 535 // remove non-numeric characters
536 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 536 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
537 ++phoneIter ) { 537 ++phoneIter ) {
538 if ( ! ( *phoneIter ).simplifyNumber() ) 538 if ( ! ( *phoneIter ).simplifyNumber() )
539 removeNumbers.append( ( *phoneIter ) ); 539 removeNumbers.append( ( *phoneIter ) );
540 } 540 }
541 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 541 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
542 ++phoneIter ) { 542 ++phoneIter ) {
543 removePhoneNumber(( *phoneIter )); 543 removePhoneNumber(( *phoneIter ));
544 } 544 }
545} 545}
546void Addressee::simplifyPhoneNumberTypes() 546void Addressee::simplifyPhoneNumberTypes()
547{ 547{
548 KABC::PhoneNumber::List::Iterator phoneIter; 548 KABC::PhoneNumber::List::Iterator phoneIter;
549 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 549 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
550 ++phoneIter ) 550 ++phoneIter )
551 ( *phoneIter ).simplifyType(); 551 ( *phoneIter ).simplifyType();
552} 552}
553void Addressee::removeID(const QString &prof) 553void Addressee::removeID(const QString &prof)
554{ 554{
555 detach(); 555 detach();
556 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 556 if ( prof.isEmpty() )
557 mData->mExternalId = ":";
558 else
559 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
557 560
558} 561}
559void Addressee::setID( const QString & prof , const QString & id ) 562void Addressee::setID( const QString & prof , const QString & id )
560{ 563{
561 detach(); 564 detach();
562 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 565 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
563 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 566 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
564} 567}
565void Addressee::setTempSyncStat( int id ) 568void Addressee::setTempSyncStat( int id )
566{ 569{
567 if ( mData->mTempSyncStat == id ) return; 570 if ( mData->mTempSyncStat == id ) return;
568 detach(); 571 detach();
569 mData->mTempSyncStat = id; 572 mData->mTempSyncStat = id;
570} 573}
571int Addressee::tempSyncStat() const 574int Addressee::tempSyncStat() const
572{ 575{
573 return mData->mTempSyncStat; 576 return mData->mTempSyncStat;
574} 577}
575 578
576QString Addressee::getID( const QString & prof) 579QString Addressee::getID( const QString & prof)
577{ 580{
578 return KIdManager::getId ( mData->mExternalId, prof ); 581 return KIdManager::getId ( mData->mExternalId, prof );
579} 582}
580 583
581void Addressee::setCsum( const QString & prof , const QString & id ) 584void Addressee::setCsum( const QString & prof , const QString & id )
582{ 585{
583 detach(); 586 detach();
584 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 587 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
585 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 588 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
586 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 589 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
587} 590}
588 591
589QString Addressee::getCsum( const QString & prof) 592QString Addressee::getCsum( const QString & prof)
590{ 593{
591 return KIdManager::getCsum ( mData->mExternalId, prof ); 594 return KIdManager::getCsum ( mData->mExternalId, prof );
592} 595}
593 596
594void Addressee::setIDStr( const QString & s ) 597void Addressee::setIDStr( const QString & s )
595{ 598{
596 detach(); 599 detach();
597 mData->mExternalId = s; 600 mData->mExternalId = s;
598} 601}
599 602
600QString Addressee::IDStr() const 603QString Addressee::IDStr() const
601{ 604{
602 return mData->mExternalId; 605 return mData->mExternalId;
603} 606}
604 607
605void Addressee::setExternalUID( const QString &id ) 608void Addressee::setExternalUID( const QString &id )
606{ 609{
607 if ( id == mData->externalUID ) return; 610 if ( id == mData->externalUID ) return;
608 detach(); 611 detach();
609 mData->empty = false; 612 mData->empty = false;
610 mData->externalUID = id; 613 mData->externalUID = id;
611} 614}
612 615
613QString Addressee::externalUID() const 616QString Addressee::externalUID() const
614{ 617{
615 return mData->externalUID; 618 return mData->externalUID;
616} 619}
617void Addressee::setOriginalExternalUID( const QString &id ) 620void Addressee::setOriginalExternalUID( const QString &id )
618{ 621{
619 if ( id == mData->originalExternalUID ) return; 622 if ( id == mData->originalExternalUID ) return;
620 detach(); 623 detach();
621 mData->empty = false; 624 mData->empty = false;
622 //qDebug("*******Set orig uid %s ", id.latin1()); 625 //qDebug("*******Set orig uid %s ", id.latin1());
623 mData->originalExternalUID = id; 626 mData->originalExternalUID = id;
624} 627}
625 628
626QString Addressee::originalExternalUID() const 629QString Addressee::originalExternalUID() const
627{ 630{
628 return mData->originalExternalUID; 631 return mData->originalExternalUID;
629} 632}
630 633
631void Addressee::setUid( const QString &id ) 634void Addressee::setUid( const QString &id )
632{ 635{
633 if ( id == mData->uid ) return; 636 if ( id == mData->uid ) return;
634 detach(); 637 detach();
635 //qDebug("****setuid %s ", id.latin1()); 638 //qDebug("****setuid %s ", id.latin1());
636 mData->empty = false; 639 mData->empty = false;
637 mData->uid = id; 640 mData->uid = id;
638} 641}
639 642
640QString Addressee::uid() const 643QString Addressee::uid() const
641{ 644{
642 if ( mData->uid.isEmpty() ) 645 if ( mData->uid.isEmpty() )
643 mData->uid = KApplication::randomString( 10 ); 646 mData->uid = KApplication::randomString( 10 );
644 647
645 return mData->uid; 648 return mData->uid;
646} 649}
647 650
648QString Addressee::uidLabel() 651QString Addressee::uidLabel()
649{ 652{
650 return i18n("Unique Identifier"); 653 return i18n("Unique Identifier");
651} 654}
652 655
653void Addressee::setName( const QString &name ) 656void Addressee::setName( const QString &name )
654{ 657{
655 if ( name == mData->name ) return; 658 if ( name == mData->name ) return;
656 detach(); 659 detach();
657 mData->empty = false; 660 mData->empty = false;
658 mData->name = name; 661 mData->name = name;
659} 662}
660 663
661QString Addressee::name() const 664QString Addressee::name() const
662{ 665{
663 return mData->name; 666 return mData->name;
664} 667}
665 668
666QString Addressee::nameLabel() 669QString Addressee::nameLabel()
667{ 670{
668 return i18n("Name"); 671 return i18n("Name");
669} 672}
670 673
671 674
672void Addressee::setFormattedName( const QString &formattedName ) 675void Addressee::setFormattedName( const QString &formattedName )
673{ 676{
674 if ( formattedName == mData->formattedName ) return; 677 if ( formattedName == mData->formattedName ) return;
675 detach(); 678 detach();
676 mData->empty = false; 679 mData->empty = false;
677 mData->formattedName = formattedName; 680 mData->formattedName = formattedName;
678} 681}
679 682
680QString Addressee::formattedName() const 683QString Addressee::formattedName() const
681{ 684{
682 return mData->formattedName; 685 return mData->formattedName;
683} 686}
684 687
685QString Addressee::formattedNameLabel() 688QString Addressee::formattedNameLabel()
686{ 689{
687 return i18n("Formatted Name"); 690 return i18n("Formatted Name");
688} 691}
689 692
690 693
691void Addressee::setFamilyName( const QString &familyName ) 694void Addressee::setFamilyName( const QString &familyName )
692{ 695{
693 if ( familyName == mData->familyName ) return; 696 if ( familyName == mData->familyName ) return;
694 detach(); 697 detach();
695 mData->empty = false; 698 mData->empty = false;
696 mData->familyName = familyName; 699 mData->familyName = familyName;
697} 700}
698 701
699QString Addressee::familyName() const 702QString Addressee::familyName() const
700{ 703{
701 return mData->familyName; 704 return mData->familyName;
702} 705}
703 706
704QString Addressee::familyNameLabel() 707QString Addressee::familyNameLabel()
705{ 708{
706 return i18n("Family Name"); 709 return i18n("Family Name");
707} 710}
708 711
709 712
710void Addressee::setGivenName( const QString &givenName ) 713void Addressee::setGivenName( const QString &givenName )
711{ 714{
712 if ( givenName == mData->givenName ) return; 715 if ( givenName == mData->givenName ) return;
713 detach(); 716 detach();
714 mData->empty = false; 717 mData->empty = false;
715 mData->givenName = givenName; 718 mData->givenName = givenName;
716} 719}
717 720
718QString Addressee::givenName() const 721QString Addressee::givenName() const
719{ 722{
720 return mData->givenName; 723 return mData->givenName;
721} 724}
722 725
723QString Addressee::givenNameLabel() 726QString Addressee::givenNameLabel()
724{ 727{
725 return i18n("Given Name"); 728 return i18n("Given Name");
726} 729}
727 730
728 731
729void Addressee::setAdditionalName( const QString &additionalName ) 732void Addressee::setAdditionalName( const QString &additionalName )
730{ 733{
731 if ( additionalName == mData->additionalName ) return; 734 if ( additionalName == mData->additionalName ) return;
732 detach(); 735 detach();
733 mData->empty = false; 736 mData->empty = false;
734 mData->additionalName = additionalName; 737 mData->additionalName = additionalName;
735} 738}
736 739
737QString Addressee::additionalName() const 740QString Addressee::additionalName() const
738{ 741{
739 return mData->additionalName; 742 return mData->additionalName;
740} 743}
741 744
742QString Addressee::additionalNameLabel() 745QString Addressee::additionalNameLabel()
743{ 746{
744 return i18n("Additional Names"); 747 return i18n("Additional Names");
745} 748}
746 749
747 750
748void Addressee::setPrefix( const QString &prefix ) 751void Addressee::setPrefix( const QString &prefix )
749{ 752{
750 if ( prefix == mData->prefix ) return; 753 if ( prefix == mData->prefix ) return;
751 detach(); 754 detach();
752 mData->empty = false; 755 mData->empty = false;
753 mData->prefix = prefix; 756 mData->prefix = prefix;
754} 757}
755 758
756QString Addressee::prefix() const 759QString Addressee::prefix() const
757{ 760{
758 return mData->prefix; 761 return mData->prefix;
759} 762}
760 763
761QString Addressee::prefixLabel() 764QString Addressee::prefixLabel()
762{ 765{
763 return i18n("Honorific Prefixes"); 766 return i18n("Honorific Prefixes");
764} 767}
765 768
766 769
767void Addressee::setSuffix( const QString &suffix ) 770void Addressee::setSuffix( const QString &suffix )
768{ 771{
769 if ( suffix == mData->suffix ) return; 772 if ( suffix == mData->suffix ) return;
770 detach(); 773 detach();
771 mData->empty = false; 774 mData->empty = false;
772 mData->suffix = suffix; 775 mData->suffix = suffix;
773} 776}
774 777
775QString Addressee::suffix() const 778QString Addressee::suffix() const
776{ 779{
777 return mData->suffix; 780 return mData->suffix;
778} 781}
779 782
780QString Addressee::suffixLabel() 783QString Addressee::suffixLabel()
781{ 784{
782 return i18n("Honorific Suffixes"); 785 return i18n("Honorific Suffixes");
783} 786}
784 787
785 788
786void Addressee::setNickName( const QString &nickName ) 789void Addressee::setNickName( const QString &nickName )
787{ 790{
788 if ( nickName == mData->nickName ) return; 791 if ( nickName == mData->nickName ) return;
789 detach(); 792 detach();
790 mData->empty = false; 793 mData->empty = false;
791 mData->nickName = nickName; 794 mData->nickName = nickName;
792} 795}
793 796
794QString Addressee::nickName() const 797QString Addressee::nickName() const
795{ 798{
796 return mData->nickName; 799 return mData->nickName;
797} 800}
798 801
799QString Addressee::nickNameLabel() 802QString Addressee::nickNameLabel()
800{ 803{
801 return i18n("Nick Name"); 804 return i18n("Nick Name");
802} 805}
803 806
804 807
805void Addressee::setBirthday( const QDateTime &birthday ) 808void Addressee::setBirthday( const QDateTime &birthday )
806{ 809{
807 if ( birthday == mData->birthday ) return; 810 if ( birthday == mData->birthday ) return;
808 detach(); 811 detach();
809 mData->empty = false; 812 mData->empty = false;
810 mData->birthday = birthday; 813 mData->birthday = birthday;
811} 814}
812 815
813QDateTime Addressee::birthday() const 816QDateTime Addressee::birthday() const
814{ 817{
815 return mData->birthday; 818 return mData->birthday;
816} 819}
817 820
818QString Addressee::birthdayLabel() 821QString Addressee::birthdayLabel()
819{ 822{
820 return i18n("Birthday"); 823 return i18n("Birthday");
821} 824}
822 825
823 826
824QString Addressee::homeAddressStreetLabel() 827QString Addressee::homeAddressStreetLabel()
825{ 828{
826 return i18n("Home Address Street"); 829 return i18n("Home Address Street");
827} 830}
828 831
829 832
830QString Addressee::homeAddressLocalityLabel() 833QString Addressee::homeAddressLocalityLabel()
831{ 834{
832 return i18n("Home Address Locality"); 835 return i18n("Home Address Locality");
833} 836}
834 837
835 838
836QString Addressee::homeAddressRegionLabel() 839QString Addressee::homeAddressRegionLabel()
837{ 840{
838 return i18n("Home Address Region"); 841 return i18n("Home Address Region");
839} 842}
840 843
841 844
842QString Addressee::homeAddressPostalCodeLabel() 845QString Addressee::homeAddressPostalCodeLabel()
843{ 846{
844 return i18n("Home Address Postal Code"); 847 return i18n("Home Address Postal Code");
845} 848}
846 849
847 850
848QString Addressee::homeAddressCountryLabel() 851QString Addressee::homeAddressCountryLabel()
849{ 852{
850 return i18n("Home Address Country"); 853 return i18n("Home Address Country");
851} 854}
852 855
853 856
854QString Addressee::homeAddressLabelLabel() 857QString Addressee::homeAddressLabelLabel()
855{ 858{
856 return i18n("Home Address Label"); 859 return i18n("Home Address Label");
857} 860}
858 861
859 862
860QString Addressee::businessAddressStreetLabel() 863QString Addressee::businessAddressStreetLabel()
861{ 864{
862 return i18n("Business Address Street"); 865 return i18n("Business Address Street");
863} 866}
864 867
865 868
866QString Addressee::businessAddressLocalityLabel() 869QString Addressee::businessAddressLocalityLabel()
867{ 870{
868 return i18n("Business Address Locality"); 871 return i18n("Business Address Locality");
869} 872}
870 873
871 874
872QString Addressee::businessAddressRegionLabel() 875QString Addressee::businessAddressRegionLabel()
873{ 876{
874 return i18n("Business Address Region"); 877 return i18n("Business Address Region");
875} 878}
876 879
877 880
878QString Addressee::businessAddressPostalCodeLabel() 881QString Addressee::businessAddressPostalCodeLabel()
879{ 882{
880 return i18n("Business Address Postal Code"); 883 return i18n("Business Address Postal Code");
881} 884}
882 885
883 886
884QString Addressee::businessAddressCountryLabel() 887QString Addressee::businessAddressCountryLabel()
885{ 888{
886 return i18n("Business Address Country"); 889 return i18n("Business Address Country");
887} 890}
888 891
889 892
890QString Addressee::businessAddressLabelLabel() 893QString Addressee::businessAddressLabelLabel()
891{ 894{
892 return i18n("Business Address Label"); 895 return i18n("Business Address Label");
893} 896}
894 897
895 898
896QString Addressee::homePhoneLabel() 899QString Addressee::homePhoneLabel()
897{ 900{
898 return i18n("Home Phone"); 901 return i18n("Home Phone");
899} 902}
900 903
901 904
902QString Addressee::businessPhoneLabel() 905QString Addressee::businessPhoneLabel()
903{ 906{
904 return i18n("Business Phone"); 907 return i18n("Business Phone");
905} 908}
906 909
907 910
908QString Addressee::mobilePhoneLabel() 911QString Addressee::mobilePhoneLabel()
909{ 912{
910 return i18n("Mobile Phone"); 913 return i18n("Mobile Phone");
911} 914}
912 915
913 916
914QString Addressee::homeFaxLabel() 917QString Addressee::homeFaxLabel()
915{ 918{
916 return i18n("Home Fax"); 919 return i18n("Home Fax");
917} 920}
918 921
919 922
920QString Addressee::businessFaxLabel() 923QString Addressee::businessFaxLabel()
921{ 924{
922 return i18n("Business Fax"); 925 return i18n("Business Fax");
923} 926}
924 927
925 928
926QString Addressee::carPhoneLabel() 929QString Addressee::carPhoneLabel()
927{ 930{
928 return i18n("Car Phone"); 931 return i18n("Car Phone");
929} 932}
930 933
931 934
932QString Addressee::isdnLabel() 935QString Addressee::isdnLabel()
933{ 936{
934 return i18n("ISDN"); 937 return i18n("ISDN");
935} 938}
936 939
937 940
938QString Addressee::pagerLabel() 941QString Addressee::pagerLabel()
939{ 942{
940 return i18n("Pager"); 943 return i18n("Pager");
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index efae874..e56e46a 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2431,486 +2431,486 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
2431 2431
2432 if ( full && mode < SYNC_PREF_NEWEST ) 2432 if ( full && mode < SYNC_PREF_NEWEST )
2433 mode = SYNC_PREF_ASK; 2433 mode = SYNC_PREF_ASK;
2434 2434
2435 switch( mode ) { 2435 switch( mode ) {
2436 case SYNC_PREF_LOCAL: 2436 case SYNC_PREF_LOCAL:
2437 if ( lastSync > remoteMod ) 2437 if ( lastSync > remoteMod )
2438 return 1; 2438 return 1;
2439 if ( lastSync > localMod ) 2439 if ( lastSync > localMod )
2440 return 2; 2440 return 2;
2441 return 1; 2441 return 1;
2442 break; 2442 break;
2443 case SYNC_PREF_REMOTE: 2443 case SYNC_PREF_REMOTE:
2444 if ( lastSync > remoteMod ) 2444 if ( lastSync > remoteMod )
2445 return 1; 2445 return 1;
2446 if ( lastSync > localMod ) 2446 if ( lastSync > localMod )
2447 return 2; 2447 return 2;
2448 return 2; 2448 return 2;
2449 break; 2449 break;
2450 case SYNC_PREF_NEWEST: 2450 case SYNC_PREF_NEWEST:
2451 if ( localMod > remoteMod ) 2451 if ( localMod > remoteMod )
2452 return 1; 2452 return 1;
2453 else 2453 else
2454 return 2; 2454 return 2;
2455 break; 2455 break;
2456 case SYNC_PREF_ASK: 2456 case SYNC_PREF_ASK:
2457 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2457 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2458 if ( lastSync > remoteMod ) 2458 if ( lastSync > remoteMod )
2459 return 1; 2459 return 1;
2460 if ( lastSync > localMod ) 2460 if ( lastSync > localMod )
2461 return 2; 2461 return 2;
2462 localIsNew = localMod >= remoteMod; 2462 localIsNew = localMod >= remoteMod;
2463 //qDebug("conflict! ************************************** "); 2463 //qDebug("conflict! ************************************** ");
2464 { 2464 {
2465 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2465 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2466 result = acd.executeD(localIsNew); 2466 result = acd.executeD(localIsNew);
2467 return result; 2467 return result;
2468 } 2468 }
2469 break; 2469 break;
2470 case SYNC_PREF_FORCE_LOCAL: 2470 case SYNC_PREF_FORCE_LOCAL:
2471 return 1; 2471 return 1;
2472 break; 2472 break;
2473 case SYNC_PREF_FORCE_REMOTE: 2473 case SYNC_PREF_FORCE_REMOTE:
2474 return 2; 2474 return 2;
2475 break; 2475 break;
2476 2476
2477 default: 2477 default:
2478 // SYNC_PREF_TAKE_BOTH not implemented 2478 // SYNC_PREF_TAKE_BOTH not implemented
2479 break; 2479 break;
2480 } 2480 }
2481 return 0; 2481 return 0;
2482} 2482}
2483 2483
2484 2484
2485bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2485bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2486{ 2486{
2487 bool syncOK = true; 2487 bool syncOK = true;
2488 int addedAddressee = 0; 2488 int addedAddressee = 0;
2489 int addedAddresseeR = 0; 2489 int addedAddresseeR = 0;
2490 int deletedAddresseeR = 0; 2490 int deletedAddresseeR = 0;
2491 int deletedAddresseeL = 0; 2491 int deletedAddresseeL = 0;
2492 int changedLocal = 0; 2492 int changedLocal = 0;
2493 int changedRemote = 0; 2493 int changedRemote = 0;
2494 2494
2495 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2495 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2496 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2496 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2497 2497
2498 //QPtrList<Addressee> el = local->rawAddressees(); 2498 //QPtrList<Addressee> el = local->rawAddressees();
2499 Addressee addresseeR; 2499 Addressee addresseeR;
2500 QString uid; 2500 QString uid;
2501 int take; 2501 int take;
2502 Addressee addresseeL; 2502 Addressee addresseeL;
2503 Addressee addresseeRSync; 2503 Addressee addresseeRSync;
2504 Addressee addresseeLSync; 2504 Addressee addresseeLSync;
2505 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2505 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2506 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2506 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2507 bool fullDateRange = false; 2507 bool fullDateRange = false;
2508 local->resetTempSyncStat(); 2508 local->resetTempSyncStat();
2509 mLastAddressbookSync = QDateTime::currentDateTime(); 2509 mLastAddressbookSync = QDateTime::currentDateTime();
2510 QDateTime modifiedCalendar = mLastAddressbookSync;; 2510 QDateTime modifiedCalendar = mLastAddressbookSync;;
2511 addresseeLSync = getLastSyncAddressee(); 2511 addresseeLSync = getLastSyncAddressee();
2512 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2512 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2513 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2513 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2514 if ( !addresseeR.isEmpty() ) { 2514 if ( !addresseeR.isEmpty() ) {
2515 addresseeRSync = addresseeR; 2515 addresseeRSync = addresseeR;
2516 remote->removeAddressee(addresseeR ); 2516 remote->removeAddressee(addresseeR );
2517 2517
2518 } else { 2518 } else {
2519 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2519 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2520 addresseeRSync = addresseeLSync ; 2520 addresseeRSync = addresseeLSync ;
2521 } else { 2521 } else {
2522 qDebug("FULLDATE 1"); 2522 qDebug("FULLDATE 1");
2523 fullDateRange = true; 2523 fullDateRange = true;
2524 Addressee newAdd; 2524 Addressee newAdd;
2525 addresseeRSync = newAdd; 2525 addresseeRSync = newAdd;
2526 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2526 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2527 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2527 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2528 addresseeRSync.setRevision( mLastAddressbookSync ); 2528 addresseeRSync.setRevision( mLastAddressbookSync );
2529 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2529 addresseeRSync.setCategories( i18n("SyncAddressee") );
2530 } 2530 }
2531 } 2531 }
2532 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2532 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2533 qDebug("FULLDATE 2"); 2533 qDebug("FULLDATE 2");
2534 fullDateRange = true; 2534 fullDateRange = true;
2535 } 2535 }
2536 if ( ! fullDateRange ) { 2536 if ( ! fullDateRange ) {
2537 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2537 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2538 2538
2539 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2539 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2540 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2540 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2541 fullDateRange = true; 2541 fullDateRange = true;
2542 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2542 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2543 } 2543 }
2544 } 2544 }
2545 // fullDateRange = true; // debug only! 2545 // fullDateRange = true; // debug only!
2546 if ( fullDateRange ) 2546 if ( fullDateRange )
2547 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2547 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2548 else 2548 else
2549 mLastAddressbookSync = addresseeLSync.revision(); 2549 mLastAddressbookSync = addresseeLSync.revision();
2550 // for resyncing if own file has changed 2550 // for resyncing if own file has changed
2551 // PENDING fixme later when implemented 2551 // PENDING fixme later when implemented
2552#if 0 2552#if 0
2553 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2553 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2554 mLastAddressbookSync = loadedFileVersion; 2554 mLastAddressbookSync = loadedFileVersion;
2555 qDebug("setting mLastAddressbookSync "); 2555 qDebug("setting mLastAddressbookSync ");
2556 } 2556 }
2557#endif 2557#endif
2558 2558
2559 //qDebug("*************************** "); 2559 //qDebug("*************************** ");
2560 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2560 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2561 QStringList er = remote->uidList(); 2561 QStringList er = remote->uidList();
2562 Addressee inR ;//= er.first(); 2562 Addressee inR ;//= er.first();
2563 Addressee inL; 2563 Addressee inL;
2564 2564
2565 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2565 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2566 2566
2567 int modulo = (er.count()/10)+1; 2567 int modulo = (er.count()/10)+1;
2568 int incCounter = 0; 2568 int incCounter = 0;
2569 while ( incCounter < er.count()) { 2569 while ( incCounter < er.count()) {
2570 if (syncManager->isProgressBarCanceled()) 2570 if (syncManager->isProgressBarCanceled())
2571 return false; 2571 return false;
2572 if ( incCounter % modulo == 0 ) 2572 if ( incCounter % modulo == 0 )
2573 syncManager->showProgressBar(incCounter); 2573 syncManager->showProgressBar(incCounter);
2574 2574
2575 uid = er[ incCounter ]; 2575 uid = er[ incCounter ];
2576 bool skipIncidence = false; 2576 bool skipIncidence = false;
2577 if ( uid.left(19) == QString("last-syncAddressee-") ) 2577 if ( uid.left(19) == QString("last-syncAddressee-") )
2578 skipIncidence = true; 2578 skipIncidence = true;
2579 QString idS,OidS; 2579 QString idS,OidS;
2580 qApp->processEvents(); 2580 qApp->processEvents();
2581 if ( !skipIncidence ) { 2581 if ( !skipIncidence ) {
2582 inL = local->findByUid( uid ); 2582 inL = local->findByUid( uid );
2583 inR = remote->findByUid( uid ); 2583 inR = remote->findByUid( uid );
2584 //inL.setResource( 0 ); 2584 //inL.setResource( 0 );
2585 //inR.setResource( 0 ); 2585 //inR.setResource( 0 );
2586 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2586 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2587 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2587 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2588 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2588 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2589 //qDebug("take %d %s ", take, inL.summary().latin1()); 2589 //qDebug("take %d %s ", take, inL.summary().latin1());
2590 if ( take == 3 ) 2590 if ( take == 3 )
2591 return false; 2591 return false;
2592 if ( take == 1 ) {// take local 2592 if ( take == 1 ) {// take local
2593 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2593 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2594 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2594 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2595 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2595 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2596 local->insertAddressee( inL, false ); 2596 local->insertAddressee( inL, false );
2597 idS = inR.externalUID(); 2597 idS = inR.externalUID();
2598 OidS = inR.originalExternalUID(); 2598 OidS = inR.originalExternalUID();
2599 } 2599 }
2600 else 2600 else
2601 idS = inR.IDStr(); 2601 idS = inR.IDStr();
2602 remote->removeAddressee( inR ); 2602 remote->removeAddressee( inR );
2603 inR = inL; 2603 inR = inL;
2604 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2604 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2605 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2605 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2606 inR.setOriginalExternalUID( OidS ); 2606 inR.setOriginalExternalUID( OidS );
2607 inR.setExternalUID( idS ); 2607 inR.setExternalUID( idS );
2608 } else { 2608 } else {
2609 inR.setIDStr( idS ); 2609 inR.setIDStr( idS );
2610 } 2610 }
2611 inR.setResource( 0 ); 2611 inR.setResource( 0 );
2612 remote->insertAddressee( inR , false); 2612 remote->insertAddressee( inR , false);
2613 ++changedRemote; 2613 ++changedRemote;
2614 } else { // take == 2 take remote 2614 } else { // take == 2 take remote
2615 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2615 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2616 if ( inR.revision().date().year() < 2004 ) 2616 if ( inR.revision().date().year() < 2004 )
2617 inR.setRevision( modifiedCalendar ); 2617 inR.setRevision( modifiedCalendar );
2618 } 2618 }
2619 idS = inL.IDStr(); 2619 idS = inL.IDStr();
2620 local->removeAddressee( inL ); 2620 local->removeAddressee( inL );
2621 inL = inR; 2621 inL = inR;
2622 inL.setIDStr( idS ); 2622 inL.setIDStr( idS );
2623 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2623 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2624 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2624 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2625 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2625 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2626 } 2626 }
2627 inL.setResource( 0 ); 2627 inL.setResource( 0 );
2628 local->insertAddressee( inL , false ); 2628 local->insertAddressee( inL , false );
2629 ++changedLocal; 2629 ++changedLocal;
2630 } 2630 }
2631 } 2631 }
2632 } 2632 }
2633 } else { // no conflict 2633 } else { // no conflict
2634 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2634 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2635 QString des = addresseeLSync.note(); 2635 QString des = addresseeLSync.note();
2636 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2636 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2637 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2637 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2638 remote->insertAddressee( inR, false ); 2638 remote->insertAddressee( inR, false );
2639 ++deletedAddresseeR; 2639 ++deletedAddresseeR;
2640 } else { 2640 } else {
2641 inR.setRevision( modifiedCalendar ); 2641 inR.setRevision( modifiedCalendar );
2642 remote->insertAddressee( inR, false ); 2642 remote->insertAddressee( inR, false );
2643 inL = inR; 2643 inL = inR;
2644 inL.setResource( 0 ); 2644 inL.setResource( 0 );
2645 local->insertAddressee( inL , false); 2645 local->insertAddressee( inL , false);
2646 ++addedAddressee; 2646 ++addedAddressee;
2647 } 2647 }
2648 } else { 2648 } else {
2649 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2649 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2650 inR.setRevision( modifiedCalendar ); 2650 inR.setRevision( modifiedCalendar );
2651 remote->insertAddressee( inR, false ); 2651 remote->insertAddressee( inR, false );
2652 inR.setResource( 0 ); 2652 inR.setResource( 0 );
2653 local->insertAddressee( inR, false ); 2653 local->insertAddressee( inR, false );
2654 ++addedAddressee; 2654 ++addedAddressee;
2655 } else { 2655 } else {
2656 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2656 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2657 remote->removeAddressee( inR ); 2657 remote->removeAddressee( inR );
2658 ++deletedAddresseeR; 2658 ++deletedAddresseeR;
2659 } 2659 }
2660 } 2660 }
2661 } 2661 }
2662 } 2662 }
2663 ++incCounter; 2663 ++incCounter;
2664 } 2664 }
2665 er.clear(); 2665 er.clear();
2666 QStringList el = local->uidList(); 2666 QStringList el = local->uidList();
2667 modulo = (el.count()/10)+1; 2667 modulo = (el.count()/10)+1;
2668 2668
2669 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2669 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2670 incCounter = 0; 2670 incCounter = 0;
2671 while ( incCounter < el.count()) { 2671 while ( incCounter < el.count()) {
2672 qApp->processEvents(); 2672 qApp->processEvents();
2673 if (syncManager->isProgressBarCanceled()) 2673 if (syncManager->isProgressBarCanceled())
2674 return false; 2674 return false;
2675 if ( incCounter % modulo == 0 ) 2675 if ( incCounter % modulo == 0 )
2676 syncManager->showProgressBar(incCounter); 2676 syncManager->showProgressBar(incCounter);
2677 uid = el[ incCounter ]; 2677 uid = el[ incCounter ];
2678 bool skipIncidence = false; 2678 bool skipIncidence = false;
2679 if ( uid.left(19) == QString("last-syncAddressee-") ) 2679 if ( uid.left(19) == QString("last-syncAddressee-") )
2680 skipIncidence = true; 2680 skipIncidence = true;
2681 if ( !skipIncidence ) { 2681 if ( !skipIncidence ) {
2682 inL = local->findByUid( uid ); 2682 inL = local->findByUid( uid );
2683 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2683 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2684 inR = remote->findByUid( uid ); 2684 inR = remote->findByUid( uid );
2685 if ( inR.isEmpty() ) { 2685 if ( inR.isEmpty() ) {
2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2687 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2687 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2688 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2688 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2689 local->removeAddressee( inL ); 2689 local->removeAddressee( inL );
2690 ++deletedAddresseeL; 2690 ++deletedAddresseeL;
2691 } else { 2691 } else {
2692 if ( ! syncManager->mWriteBackExistingOnly ) { 2692 if ( ! syncManager->mWriteBackExistingOnly ) {
2693 inL.removeID(mCurrentSyncDevice ); 2693 inL.removeID(mCurrentSyncDevice );
2694 ++addedAddresseeR; 2694 ++addedAddresseeR;
2695 inL.setRevision( modifiedCalendar ); 2695 inL.setRevision( modifiedCalendar );
2696 local->insertAddressee( inL, false ); 2696 local->insertAddressee( inL, false );
2697 inR = inL; 2697 inR = inL;
2698 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2698 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2699 inR.setResource( 0 ); 2699 inR.setResource( 0 );
2700 remote->insertAddressee( inR, false ); 2700 remote->insertAddressee( inR, false );
2701 } 2701 }
2702 } 2702 }
2703 } else { 2703 } else {
2704 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2704 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2705 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2705 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2706 local->removeAddressee( inL ); 2706 local->removeAddressee( inL );
2707 ++deletedAddresseeL; 2707 ++deletedAddresseeL;
2708 } else { 2708 } else {
2709 if ( ! syncManager->mWriteBackExistingOnly ) { 2709 if ( ! syncManager->mWriteBackExistingOnly ) {
2710 ++addedAddresseeR; 2710 ++addedAddresseeR;
2711 inL.setRevision( modifiedCalendar ); 2711 inL.setRevision( modifiedCalendar );
2712 local->insertAddressee( inL, false ); 2712 local->insertAddressee( inL, false );
2713 inR = inL; 2713 inR = inL;
2714 inR.setResource( 0 ); 2714 inR.setResource( 0 );
2715 remote->insertAddressee( inR, false ); 2715 remote->insertAddressee( inR, false );
2716 } 2716 }
2717 } 2717 }
2718 } 2718 }
2719 } 2719 }
2720 } 2720 }
2721 } 2721 }
2722 ++incCounter; 2722 ++incCounter;
2723 } 2723 }
2724 el.clear(); 2724 el.clear();
2725 syncManager->hideProgressBar(); 2725 syncManager->hideProgressBar();
2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2727 // get rid of micro seconds 2727 // get rid of micro seconds
2728 QTime t = mLastAddressbookSync.time(); 2728 QTime t = mLastAddressbookSync.time();
2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2730 addresseeLSync.setRevision( mLastAddressbookSync ); 2730 addresseeLSync.setRevision( mLastAddressbookSync );
2731 addresseeRSync.setRevision( mLastAddressbookSync ); 2731 addresseeRSync.setRevision( mLastAddressbookSync );
2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2738 addresseeRSync.setNote( "" ) ; 2738 addresseeRSync.setNote( "" ) ;
2739 addresseeLSync.setNote( "" ); 2739 addresseeLSync.setNote( "" );
2740 2740
2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2742 remote->insertAddressee( addresseeRSync, false ); 2742 remote->insertAddressee( addresseeRSync, false );
2743 local->insertAddressee( addresseeLSync, false ); 2743 local->insertAddressee( addresseeLSync, false );
2744 QString mes; 2744 QString mes;
2745 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2745 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2746 if ( syncManager->mShowSyncSummary ) { 2746 if ( syncManager->mShowSyncSummary ) {
2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2748 } 2748 }
2749 qDebug( mes ); 2749 qDebug( mes );
2750 return syncOK; 2750 return syncOK;
2751} 2751}
2752 2752
2753 2753
2754//this is a overwritten callbackmethods from the syncinterface 2754//this is a overwritten callbackmethods from the syncinterface
2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2756{ 2756{
2757 2757
2758 //pending prepare addresseeview for output 2758 //pending prepare addresseeview for output
2759 //pending detect, if remote file has REV field. if not switch to external sync 2759 //pending detect, if remote file has REV field. if not switch to external sync
2760 mGlobalSyncMode = SYNC_MODE_NORMAL; 2760 mGlobalSyncMode = SYNC_MODE_NORMAL;
2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2762 2762
2763 AddressBook abLocal(filename,"syncContact"); 2763 AddressBook abLocal(filename,"syncContact");
2764 bool syncOK = false; 2764 bool syncOK = false;
2765 if ( abLocal.load() ) { 2765 if ( abLocal.load() ) {
2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2767 bool external = false; 2767 bool external = false;
2768 bool isXML = false; 2768 bool isXML = false;
2769 if ( filename.right(4) == ".xml") { 2769 if ( filename.right(4) == ".xml") {
2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2771 isXML = true; 2771 isXML = true;
2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2773 } else { 2773 } else {
2774 external = !manager->mIsKapiFile; 2774 external = !manager->mIsKapiFile;
2775 if ( external ) { 2775 if ( external ) {
2776 qDebug("Setting vcf mode to external "); 2776 qDebug("Setting vcf mode to external ");
2777 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2777 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2778 AddressBook::Iterator it; 2778 AddressBook::Iterator it;
2779 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2779 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2780 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2780 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2781 (*it).computeCsum( mCurrentSyncDevice ); 2781 (*it).computeCsum( mCurrentSyncDevice );
2782 } 2782 }
2783 } 2783 }
2784 } 2784 }
2785 //AddressBook::Iterator it; 2785 //AddressBook::Iterator it;
2786 //QStringList vcards; 2786 //QStringList vcards;
2787 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2787 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2788 // qDebug("Name %s ", (*it).familyName().latin1()); 2788 // qDebug("Name %s ", (*it).familyName().latin1());
2789 //} 2789 //}
2790 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2790 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2791 if ( syncOK ) { 2791 if ( syncOK ) {
2792 if ( syncManager->mWriteBackFile ) 2792 if ( syncManager->mWriteBackFile )
2793 { 2793 {
2794 if ( external ) 2794 if ( external )
2795 abLocal.removeSyncAddressees( !isXML); 2795 abLocal.removeSyncAddressees( !isXML);
2796 qDebug("Saving remote AB "); 2796 qDebug("Saving remote AB ");
2797 if ( ! abLocal.saveAB()) 2797 if ( ! abLocal.saveAB())
2798 qDebug("Error writing back AB to file "); 2798 qDebug("Error writing back AB to file ");
2799 if ( isXML ) { 2799 if ( isXML ) {
2800 // afterwrite processing 2800 // afterwrite processing
2801 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2801 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2802 } 2802 }
2803 } 2803 }
2804 } 2804 }
2805 setModified(); 2805 setModified();
2806 2806
2807 } 2807 }
2808 if ( syncOK ) 2808 if ( syncOK )
2809 mViewManager->refreshView(); 2809 mViewManager->refreshView();
2810 return syncOK; 2810 return syncOK;
2811 2811
2812} 2812}
2813void KABCore::removeSyncInfo( QString syncProfile) 2813void KABCore::removeSyncInfo( QString syncProfile)
2814{ 2814{
2815 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); 2815 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1());
2816 2816 mAddressBook->removeSyncInfo( syncProfile );
2817} 2817}
2818 2818
2819 2819
2820//this is a overwritten callbackmethods from the syncinterface 2820//this is a overwritten callbackmethods from the syncinterface
2821bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2821bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2822{ 2822{
2823 if ( resource == "phone" ) 2823 if ( resource == "phone" )
2824 return syncPhone(); 2824 return syncPhone();
2825 disableBR( true ); 2825 disableBR( true );
2826 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2826 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2827 2827
2828 AddressBook abLocal( resource,"syncContact"); 2828 AddressBook abLocal( resource,"syncContact");
2829 bool syncOK = false; 2829 bool syncOK = false;
2830 if ( abLocal.load() ) { 2830 if ( abLocal.load() ) {
2831 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2831 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2832 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2832 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2833 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2833 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2834 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2834 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2835 if ( syncOK ) { 2835 if ( syncOK ) {
2836 if ( syncManager->mWriteBackFile ) { 2836 if ( syncManager->mWriteBackFile ) {
2837 abLocal.removeSyncAddressees( false ); 2837 abLocal.removeSyncAddressees( false );
2838 abLocal.saveAB(); 2838 abLocal.saveAB();
2839 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2839 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2840 } 2840 }
2841 } 2841 }
2842 setModified(); 2842 setModified();
2843 } 2843 }
2844 if ( syncOK ) 2844 if ( syncOK )
2845 mViewManager->refreshView(); 2845 mViewManager->refreshView();
2846 disableBR( false ); 2846 disableBR( false );
2847 return syncOK; 2847 return syncOK;
2848 2848
2849} 2849}
2850void KABCore::message( QString m ) 2850void KABCore::message( QString m )
2851{ 2851{
2852 topLevelWidget()->setCaption( m ); 2852 topLevelWidget()->setCaption( m );
2853 mMessageTimer->start( 15000, true ); 2853 mMessageTimer->start( 15000, true );
2854} 2854}
2855bool KABCore::syncPhone() 2855bool KABCore::syncPhone()
2856{ 2856{
2857 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2857 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2858 QString fileName = getPhoneFile(); 2858 QString fileName = getPhoneFile();
2859 if ( !PhoneAccess::readFromPhone( fileName) ) { 2859 if ( !PhoneAccess::readFromPhone( fileName) ) {
2860 message(i18n("Phone access failed!")); 2860 message(i18n("Phone access failed!"));
2861 return false; 2861 return false;
2862 } 2862 }
2863 AddressBook abLocal( fileName,"syncContact"); 2863 AddressBook abLocal( fileName,"syncContact");
2864 bool syncOK = false; 2864 bool syncOK = false;
2865 { 2865 {
2866 abLocal.importFromFile( fileName ); 2866 abLocal.importFromFile( fileName );
2867 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2867 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2868 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2868 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2869 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2869 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2870 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2870 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2871 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2871 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2872 if ( syncOK ) { 2872 if ( syncOK ) {
2873 if ( syncManager->mWriteBackFile ) { 2873 if ( syncManager->mWriteBackFile ) {
2874 abLocal.removeSyncAddressees( true ); 2874 abLocal.removeSyncAddressees( true );
2875 abLocal.saveABphone( fileName ); 2875 abLocal.saveABphone( fileName );
2876 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 2876 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2877 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2877 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2878 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2878 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2879 } 2879 }
2880 } 2880 }
2881 setModified(); 2881 setModified();
2882 } 2882 }
2883 if ( syncOK ) 2883 if ( syncOK )
2884 mViewManager->refreshView(); 2884 mViewManager->refreshView();
2885 return syncOK; 2885 return syncOK;
2886} 2886}
2887void KABCore::getFile( bool success ) 2887void KABCore::getFile( bool success )
2888{ 2888{
2889 if ( ! success ) { 2889 if ( ! success ) {
2890 message( i18n("Error receiving file. Nothing changed!") ); 2890 message( i18n("Error receiving file. Nothing changed!") );
2891 return; 2891 return;
2892 } 2892 }
2893 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 2893 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
2894 if ( count ) 2894 if ( count )
2895 setModified( true ); 2895 setModified( true );
2896 message( i18n("Pi-Sync successful!") ); 2896 message( i18n("Pi-Sync successful!") );
2897 mViewManager->refreshView(); 2897 mViewManager->refreshView();
2898} 2898}
2899void KABCore::syncFileRequest() 2899void KABCore::syncFileRequest()
2900{ 2900{
2901 mAddressBook->export2File( sentSyncFile() ); 2901 mAddressBook->export2File( sentSyncFile() );
2902} 2902}
2903QString KABCore::sentSyncFile() 2903QString KABCore::sentSyncFile()
2904{ 2904{
2905#ifdef DESKTOP_VERSION 2905#ifdef DESKTOP_VERSION
2906 return locateLocal( "tmp", "copysyncab.vcf" ); 2906 return locateLocal( "tmp", "copysyncab.vcf" );
2907#else 2907#else
2908 return QString( "/tmp/copysyncab.vcf" ); 2908 return QString( "/tmp/copysyncab.vcf" );
2909#endif 2909#endif
2910} 2910}
2911 2911
2912void KABCore::setCaptionBack() 2912void KABCore::setCaptionBack()
2913{ 2913{
2914 mMessageTimer->stop(); 2914 mMessageTimer->stop();
2915 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2915 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2916} 2916}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index af01625..a08f243 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -3387,386 +3387,387 @@ void CalendarView::showDates(const DateList &selectedDates)
3387 if (selectedDates.first() < selectedDates.last() ) 3387 if (selectedDates.first() < selectedDates.last() )
3388 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3388 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3389 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3389 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3390 3390
3391} 3391}
3392 3392
3393QPtrList<CalFilter> CalendarView::filters() 3393QPtrList<CalFilter> CalendarView::filters()
3394{ 3394{
3395 return mFilters; 3395 return mFilters;
3396 3396
3397} 3397}
3398void CalendarView::editFilters() 3398void CalendarView::editFilters()
3399{ 3399{
3400 // kdDebug() << "CalendarView::editFilters()" << endl; 3400 // kdDebug() << "CalendarView::editFilters()" << endl;
3401 3401
3402 CalFilter *filter = mFilters.first(); 3402 CalFilter *filter = mFilters.first();
3403 while(filter) { 3403 while(filter) {
3404 kdDebug() << " Filter: " << filter->name() << endl; 3404 kdDebug() << " Filter: " << filter->name() << endl;
3405 filter = mFilters.next(); 3405 filter = mFilters.next();
3406 } 3406 }
3407 3407
3408 mDialogManager->showFilterEditDialog(&mFilters); 3408 mDialogManager->showFilterEditDialog(&mFilters);
3409} 3409}
3410void CalendarView::toggleFilter() 3410void CalendarView::toggleFilter()
3411{ 3411{
3412 showFilter(! mFilterView->isVisible()); 3412 showFilter(! mFilterView->isVisible());
3413} 3413}
3414 3414
3415KOFilterView *CalendarView::filterView() 3415KOFilterView *CalendarView::filterView()
3416{ 3416{
3417 return mFilterView; 3417 return mFilterView;
3418} 3418}
3419void CalendarView::selectFilter( int fil ) 3419void CalendarView::selectFilter( int fil )
3420{ 3420{
3421 mFilterView->setSelectedFilter( fil ); 3421 mFilterView->setSelectedFilter( fil );
3422} 3422}
3423void CalendarView::showFilter(bool visible) 3423void CalendarView::showFilter(bool visible)
3424{ 3424{
3425 if (visible) mFilterView->show(); 3425 if (visible) mFilterView->show();
3426 else mFilterView->hide(); 3426 else mFilterView->hide();
3427} 3427}
3428void CalendarView::toggleFilerEnabled( ) 3428void CalendarView::toggleFilerEnabled( )
3429{ 3429{
3430 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3430 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3431 if ( !mFilterView->filtersEnabled() ) 3431 if ( !mFilterView->filtersEnabled() )
3432 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3432 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3433 3433
3434} 3434}
3435void CalendarView::updateFilter() 3435void CalendarView::updateFilter()
3436{ 3436{
3437 CalFilter *filter = mFilterView->selectedFilter(); 3437 CalFilter *filter = mFilterView->selectedFilter();
3438 if (filter) { 3438 if (filter) {
3439 if (mFilterView->filtersEnabled()) { 3439 if (mFilterView->filtersEnabled()) {
3440 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3440 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3441 filter->setEnabled(true); 3441 filter->setEnabled(true);
3442 } 3442 }
3443 else filter->setEnabled(false); 3443 else filter->setEnabled(false);
3444 mCalendar->setFilter(filter); 3444 mCalendar->setFilter(filter);
3445 updateView(); 3445 updateView();
3446 } 3446 }
3447} 3447}
3448 3448
3449void CalendarView::filterEdited() 3449void CalendarView::filterEdited()
3450{ 3450{
3451 mFilterView->updateFilters(); 3451 mFilterView->updateFilters();
3452 updateFilter(); 3452 updateFilter();
3453 writeSettings(); 3453 writeSettings();
3454} 3454}
3455 3455
3456 3456
3457void CalendarView::takeOverEvent() 3457void CalendarView::takeOverEvent()
3458{ 3458{
3459 Incidence *incidence = currentSelection(); 3459 Incidence *incidence = currentSelection();
3460 3460
3461 if (!incidence) return; 3461 if (!incidence) return;
3462 3462
3463 incidence->setOrganizer(KOPrefs::instance()->email()); 3463 incidence->setOrganizer(KOPrefs::instance()->email());
3464 incidence->recreate(); 3464 incidence->recreate();
3465 incidence->setReadOnly(false); 3465 incidence->setReadOnly(false);
3466 3466
3467 updateView(); 3467 updateView();
3468} 3468}
3469 3469
3470void CalendarView::takeOverCalendar() 3470void CalendarView::takeOverCalendar()
3471{ 3471{
3472 // TODO: Create Calendar::allIncidences() function and use it here 3472 // TODO: Create Calendar::allIncidences() function and use it here
3473 3473
3474 QPtrList<Event> events = mCalendar->events(); 3474 QPtrList<Event> events = mCalendar->events();
3475 for(uint i=0; i<events.count(); ++i) { 3475 for(uint i=0; i<events.count(); ++i) {
3476 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3476 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3477 events.at(i)->recreate(); 3477 events.at(i)->recreate();
3478 events.at(i)->setReadOnly(false); 3478 events.at(i)->setReadOnly(false);
3479 } 3479 }
3480 3480
3481 QPtrList<Todo> todos = mCalendar->todos(); 3481 QPtrList<Todo> todos = mCalendar->todos();
3482 for(uint i=0; i<todos.count(); ++i) { 3482 for(uint i=0; i<todos.count(); ++i) {
3483 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3483 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3484 todos.at(i)->recreate(); 3484 todos.at(i)->recreate();
3485 todos.at(i)->setReadOnly(false); 3485 todos.at(i)->setReadOnly(false);
3486 } 3486 }
3487 3487
3488 QPtrList<Journal> journals = mCalendar->journals(); 3488 QPtrList<Journal> journals = mCalendar->journals();
3489 for(uint i=0; i<journals.count(); ++i) { 3489 for(uint i=0; i<journals.count(); ++i) {
3490 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3490 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3491 journals.at(i)->recreate(); 3491 journals.at(i)->recreate();
3492 journals.at(i)->setReadOnly(false); 3492 journals.at(i)->setReadOnly(false);
3493 } 3493 }
3494 3494
3495 updateView(); 3495 updateView();
3496} 3496}
3497 3497
3498void CalendarView::showIntro() 3498void CalendarView::showIntro()
3499{ 3499{
3500 kdDebug() << "To be implemented." << endl; 3500 kdDebug() << "To be implemented." << endl;
3501} 3501}
3502 3502
3503QWidgetStack *CalendarView::viewStack() 3503QWidgetStack *CalendarView::viewStack()
3504{ 3504{
3505 return mRightFrame; 3505 return mRightFrame;
3506} 3506}
3507 3507
3508QWidget *CalendarView::leftFrame() 3508QWidget *CalendarView::leftFrame()
3509{ 3509{
3510 return mLeftFrame; 3510 return mLeftFrame;
3511} 3511}
3512 3512
3513DateNavigator *CalendarView::dateNavigator() 3513DateNavigator *CalendarView::dateNavigator()
3514{ 3514{
3515 return mNavigator; 3515 return mNavigator;
3516} 3516}
3517 3517
3518KDateNavigator* CalendarView::dateNavigatorWidget() 3518KDateNavigator* CalendarView::dateNavigatorWidget()
3519{ 3519{
3520 return mDateNavigator; 3520 return mDateNavigator;
3521} 3521}
3522void CalendarView::toggleDateNavigatorWidget() 3522void CalendarView::toggleDateNavigatorWidget()
3523{ 3523{
3524 if (mDateNavigator->isVisible()) 3524 if (mDateNavigator->isVisible())
3525 mDateNavigator->hide(); 3525 mDateNavigator->hide();
3526 else 3526 else
3527 mDateNavigator->show(); 3527 mDateNavigator->show();
3528} 3528}
3529void CalendarView::addView(KOrg::BaseView *view) 3529void CalendarView::addView(KOrg::BaseView *view)
3530{ 3530{
3531 mViewManager->addView(view); 3531 mViewManager->addView(view);
3532} 3532}
3533 3533
3534void CalendarView::showView(KOrg::BaseView *view) 3534void CalendarView::showView(KOrg::BaseView *view)
3535{ 3535{
3536 mViewManager->showView(view, mLeftFrame->isVisible()); 3536 mViewManager->showView(view, mLeftFrame->isVisible());
3537} 3537}
3538 3538
3539Incidence *CalendarView::currentSelection() 3539Incidence *CalendarView::currentSelection()
3540{ 3540{
3541 return mViewManager->currentSelection(); 3541 return mViewManager->currentSelection();
3542} 3542}
3543void CalendarView::toggleAllDaySize() 3543void CalendarView::toggleAllDaySize()
3544{ 3544{
3545 /* 3545 /*
3546 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3546 if ( KOPrefs::instance()->mAllDaySize > 47 )
3547 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3547 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3548 else 3548 else
3549 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3549 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3550 */ 3550 */
3551 viewManager()->agendaView()->toggleAllDay(); 3551 viewManager()->agendaView()->toggleAllDay();
3552} 3552}
3553void CalendarView::toggleExpand() 3553void CalendarView::toggleExpand()
3554{ 3554{
3555 // if ( mLeftFrame->isHidden() ) { 3555 // if ( mLeftFrame->isHidden() ) {
3556 // mLeftFrame->show(); 3556 // mLeftFrame->show();
3557 // emit calendarViewExpanded( false ); 3557 // emit calendarViewExpanded( false );
3558 // } else { 3558 // } else {
3559 // mLeftFrame->hide(); 3559 // mLeftFrame->hide();
3560 // emit calendarViewExpanded( true ); 3560 // emit calendarViewExpanded( true );
3561 // } 3561 // }
3562 3562
3563 globalFlagBlockAgenda = 1; 3563 globalFlagBlockAgenda = 1;
3564 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3564 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3565 globalFlagBlockAgenda = 5; 3565 globalFlagBlockAgenda = 5;
3566 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3566 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3567 //mViewManager->showView( 0, true ); 3567 //mViewManager->showView( 0, true );
3568} 3568}
3569 3569
3570void CalendarView::calendarModified( bool modified, Calendar * ) 3570void CalendarView::calendarModified( bool modified, Calendar * )
3571{ 3571{
3572 setModified( modified ); 3572 setModified( modified );
3573} 3573}
3574 3574
3575Todo *CalendarView::selectedTodo() 3575Todo *CalendarView::selectedTodo()
3576{ 3576{
3577 Incidence *incidence = currentSelection(); 3577 Incidence *incidence = currentSelection();
3578 if ( incidence && incidence->type() == "Todo" ) { 3578 if ( incidence && incidence->type() == "Todo" ) {
3579 return static_cast<Todo *>( incidence ); 3579 return static_cast<Todo *>( incidence );
3580 } 3580 }
3581 3581
3582 incidence = mTodoList->selectedIncidences().first(); 3582 incidence = mTodoList->selectedIncidences().first();
3583 if ( incidence && incidence->type() == "Todo" ) { 3583 if ( incidence && incidence->type() == "Todo" ) {
3584 return static_cast<Todo *>( incidence ); 3584 return static_cast<Todo *>( incidence );
3585 } 3585 }
3586 3586
3587 return 0; 3587 return 0;
3588} 3588}
3589 3589
3590void CalendarView::dialogClosing(Incidence *in) 3590void CalendarView::dialogClosing(Incidence *in)
3591{ 3591{
3592 // mDialogList.remove(in); 3592 // mDialogList.remove(in);
3593} 3593}
3594 3594
3595void CalendarView::showIncidence() 3595void CalendarView::showIncidence()
3596{ 3596{
3597 Incidence *incidence = currentSelection(); 3597 Incidence *incidence = currentSelection();
3598 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3598 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3599 if ( incidence ) { 3599 if ( incidence ) {
3600 ShowIncidenceVisitor v; 3600 ShowIncidenceVisitor v;
3601 v.act( incidence, this ); 3601 v.act( incidence, this );
3602 } 3602 }
3603} 3603}
3604void CalendarView::editIncidenceDescription() 3604void CalendarView::editIncidenceDescription()
3605{ 3605{
3606 mFlagEditDescription = true; 3606 mFlagEditDescription = true;
3607 editIncidence(); 3607 editIncidence();
3608 mFlagEditDescription = false; 3608 mFlagEditDescription = false;
3609} 3609}
3610void CalendarView::editIncidence() 3610void CalendarView::editIncidence()
3611{ 3611{
3612 // qDebug("editIncidence() "); 3612 // qDebug("editIncidence() ");
3613 Incidence *incidence = currentSelection(); 3613 Incidence *incidence = currentSelection();
3614 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3614 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3615 if ( incidence ) { 3615 if ( incidence ) {
3616 EditIncidenceVisitor v; 3616 EditIncidenceVisitor v;
3617 v.act( incidence, this ); 3617 v.act( incidence, this );
3618 } 3618 }
3619} 3619}
3620 3620
3621void CalendarView::deleteIncidence() 3621void CalendarView::deleteIncidence()
3622{ 3622{
3623 Incidence *incidence = currentSelection(); 3623 Incidence *incidence = currentSelection();
3624 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3624 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3625 if ( incidence ) { 3625 if ( incidence ) {
3626 deleteIncidence(incidence); 3626 deleteIncidence(incidence);
3627 } 3627 }
3628} 3628}
3629 3629
3630void CalendarView::showIncidence(Incidence *incidence) 3630void CalendarView::showIncidence(Incidence *incidence)
3631{ 3631{
3632 if ( incidence ) { 3632 if ( incidence ) {
3633 ShowIncidenceVisitor v; 3633 ShowIncidenceVisitor v;
3634 v.act( incidence, this ); 3634 v.act( incidence, this );
3635 } 3635 }
3636} 3636}
3637 3637
3638void CalendarView::editIncidence(Incidence *incidence) 3638void CalendarView::editIncidence(Incidence *incidence)
3639{ 3639{
3640 if ( incidence ) { 3640 if ( incidence ) {
3641 3641
3642 EditIncidenceVisitor v; 3642 EditIncidenceVisitor v;
3643 v.act( incidence, this ); 3643 v.act( incidence, this );
3644 3644
3645 } 3645 }
3646} 3646}
3647 3647
3648void CalendarView::deleteIncidence(Incidence *incidence) 3648void CalendarView::deleteIncidence(Incidence *incidence)
3649{ 3649{
3650 //qDebug(" CalendarView::deleteIncidence "); 3650 //qDebug(" CalendarView::deleteIncidence ");
3651 if ( incidence ) { 3651 if ( incidence ) {
3652 DeleteIncidenceVisitor v; 3652 DeleteIncidenceVisitor v;
3653 v.act( incidence, this ); 3653 v.act( incidence, this );
3654 } 3654 }
3655} 3655}
3656 3656
3657 3657
3658void CalendarView::lookForOutgoingMessages() 3658void CalendarView::lookForOutgoingMessages()
3659{ 3659{
3660 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3660 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3661 ogd->loadMessages(); 3661 ogd->loadMessages();
3662} 3662}
3663 3663
3664void CalendarView::lookForIncomingMessages() 3664void CalendarView::lookForIncomingMessages()
3665{ 3665{
3666 IncomingDialog *icd = mDialogManager->incomingDialog(); 3666 IncomingDialog *icd = mDialogManager->incomingDialog();
3667 icd->retrieve(); 3667 icd->retrieve();
3668} 3668}
3669 3669
3670bool CalendarView::removeCompletedSubTodos( Todo* t ) 3670bool CalendarView::removeCompletedSubTodos( Todo* t )
3671{ 3671{
3672 bool deleteTodo = true; 3672 bool deleteTodo = true;
3673 QPtrList<Incidence> subTodos; 3673 QPtrList<Incidence> subTodos;
3674 Incidence *aTodo; 3674 Incidence *aTodo;
3675 subTodos = t->relations(); 3675 subTodos = t->relations();
3676 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3676 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3677 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3677 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3678 deleteTodo = false; 3678 deleteTodo = false;
3679 } 3679 }
3680 if ( deleteTodo ) { 3680 if ( deleteTodo ) {
3681 if ( t->isCompleted() ) { 3681 if ( t->isCompleted() ) {
3682 checkExternalId( t ); 3682 checkExternalId( t );
3683 mCalendar->deleteTodo( t ); 3683 mCalendar->deleteTodo( t );
3684 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3684 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3685 } 3685 }
3686 else 3686 else
3687 deleteTodo = false; 3687 deleteTodo = false;
3688 } 3688 }
3689 return deleteTodo; 3689 return deleteTodo;
3690 3690
3691} 3691}
3692void CalendarView::purgeCompleted() 3692void CalendarView::purgeCompleted()
3693{ 3693{
3694 int result = KMessageBox::warningContinueCancel(this, 3694 int result = KMessageBox::warningContinueCancel(this,
3695 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3695 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3696 3696
3697 if (result == KMessageBox::Continue) { 3697 if (result == KMessageBox::Continue) {
3698 3698
3699 QPtrList<Todo> todoCal; 3699 QPtrList<Todo> todoCal;
3700 QPtrList<Todo> rootTodos; 3700 QPtrList<Todo> rootTodos;
3701 //QPtrList<Incidence> rel; 3701 //QPtrList<Incidence> rel;
3702 Todo *aTodo;//, *rTodo; 3702 Todo *aTodo;//, *rTodo;
3703 Incidence *rIncidence; 3703 Incidence *rIncidence;
3704 bool childDelete = false; 3704 bool childDelete = false;
3705 bool deletedOne = true; 3705 bool deletedOne = true;
3706 todoCal = calendar()->todos(); 3706 todoCal = calendar()->todos();
3707 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3707 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3708 if ( !aTodo->relatedTo() ) 3708 if ( !aTodo->relatedTo() )
3709 rootTodos.append( aTodo ); 3709 rootTodos.append( aTodo );
3710 } 3710 }
3711 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3711 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3712 removeCompletedSubTodos( aTodo ); 3712 removeCompletedSubTodos( aTodo );
3713 } 3713 }
3714 3714
3715 updateView(); 3715 updateView();
3716 } 3716 }
3717} 3717}
3718 3718
3719void CalendarView::slotCalendarChanged() 3719void CalendarView::slotCalendarChanged()
3720{ 3720{
3721 ; 3721 ;
3722} 3722}
3723 3723
3724NavigatorBar *CalendarView::navigatorBar() 3724NavigatorBar *CalendarView::navigatorBar()
3725{ 3725{
3726 return mNavigatorBar; 3726 return mNavigatorBar;
3727} 3727}
3728 3728
3729 3729
3730 3730
3731void CalendarView::keyPressEvent ( QKeyEvent *e) 3731void CalendarView::keyPressEvent ( QKeyEvent *e)
3732{ 3732{
3733 //qDebug(" alendarView::keyPressEvent "); 3733 //qDebug(" alendarView::keyPressEvent ");
3734 e->ignore(); 3734 e->ignore();
3735} 3735}
3736 3736
3737 3737
3738bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 3738bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3739{ 3739{
3740 // mSyncManager = manager; 3740 // mSyncManager = manager;
3741 mSyncKDE = false; 3741 mSyncKDE = false;
3742 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 3742 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
3743 qDebug("SyncKDE request detected!"); 3743 qDebug("SyncKDE request detected!");
3744 mSyncKDE = true; 3744 mSyncKDE = true;
3745 } 3745 }
3746 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3746 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3747 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3747 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3748 return syncCalendar( filename, mode ); 3748 return syncCalendar( filename, mode );
3749} 3749}
3750bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 3750bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3751{ 3751{
3752 mSyncKDE = false; 3752 mSyncKDE = false;
3753 //mSyncManager = manager; 3753 //mSyncManager = manager;
3754 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3754 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3755 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3755 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3756 if ( resource == "sharp" ) 3756 if ( resource == "sharp" )
3757 syncExternal( 0 ); 3757 syncExternal( 0 );
3758 if ( resource == "phone" ) 3758 if ( resource == "phone" )
3759 syncExternal( 1 ); 3759 syncExternal( 1 );
3760 // pending setmodified 3760 // pending setmodified
3761 return true; 3761 return true;
3762} 3762}
3763void CalendarView::setSyncManager(KSyncManager* manager) 3763void CalendarView::setSyncManager(KSyncManager* manager)
3764{ 3764{
3765 mSyncManager = manager; 3765 mSyncManager = manager;
3766} 3766}
3767 3767
3768void CalendarView::removeSyncInfo( QString syncProfile) 3768void CalendarView::removeSyncInfo( QString syncProfile)
3769{ 3769{
3770 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); 3770 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1());
3771 mCalendar->removeSyncInfo( syncProfile );
3771 3772
3772} 3773}
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index b801186..b7d6a1f 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,352 +1,353 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
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#ifndef CALENDAR_H 22#ifndef CALENDAR_H
23#define CALENDAR_H 23#define CALENDAR_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qptrlist.h> 28#include <qptrlist.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "event.h" 32#include "event.h"
33#include "todo.h" 33#include "todo.h"
34#include "journal.h" 34#include "journal.h"
35#include "calfilter.h" 35#include "calfilter.h"
36 36
37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ 37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
38 38
39class KConfig; 39class KConfig;
40 40
41namespace KCal { 41namespace KCal {
42 42
43 43
44/** 44/**
45 This is the main "calendar" object class for KOrganizer. It holds 45 This is the main "calendar" object class for KOrganizer. It holds
46 information like all appointments/events, user information, etc. etc. 46 information like all appointments/events, user information, etc. etc.
47 one calendar is associated with each CalendarView (@see calendarview.h). 47 one calendar is associated with each CalendarView (@see calendarview.h).
48 This is an abstract base class defining the interface to a calendar. It is 48 This is an abstract base class defining the interface to a calendar. It is
49 implemented by subclasses like @see CalendarLocal, which use different 49 implemented by subclasses like @see CalendarLocal, which use different
50 methods to store and access the data. 50 methods to store and access the data.
51 51
52 Ownership of events etc. is handled by the following policy: As soon as an 52 Ownership of events etc. is handled by the following policy: As soon as an
53 event (or any other subclass of IncidenceBase) object is added to the 53 event (or any other subclass of IncidenceBase) object is added to the
54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes 54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes
55 care of deleting it. All Events returned by the query functions are returned 55 care of deleting it. All Events returned by the query functions are returned
56 as pointers, that means all changes to the returned events are immediately 56 as pointers, that means all changes to the returned events are immediately
57 visible in the Calendar. You shouldn't delete any Event object you get from 57 visible in the Calendar. You shouldn't delete any Event object you get from
58 Calendar. 58 Calendar.
59*/ 59*/
60class Calendar : public QObject, public CustomProperties, 60class Calendar : public QObject, public CustomProperties,
61 public IncidenceBase::Observer 61 public IncidenceBase::Observer
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 Calendar(); 65 Calendar();
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 void deleteIncidence(Incidence *in); 68 void deleteIncidence(Incidence *in);
69 void resetTempSyncStat(); 69 void resetTempSyncStat();
70 void resetPilotStat(int id); 70 void resetPilotStat(int id);
71 /** 71 /**
72 Clears out the current calendar, freeing all used memory etc. 72 Clears out the current calendar, freeing all used memory etc.
73 */ 73 */
74 virtual void close() = 0; 74 virtual void close() = 0;
75 75
76 /** 76 /**
77 Sync changes in memory to persistant storage. 77 Sync changes in memory to persistant storage.
78 */ 78 */
79 virtual void save() = 0; 79 virtual void save() = 0;
80 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 80 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
81 virtual void removeSyncInfo( QString syncProfile) = 0;
81 virtual bool isSaving() { return false; } 82 virtual bool isSaving() { return false; }
82 83
83 /** 84 /**
84 Return the owner of the calendar's full name. 85 Return the owner of the calendar's full name.
85 */ 86 */
86 const QString &getOwner() const; 87 const QString &getOwner() const;
87 /** 88 /**
88 Set the owner of the calendar. Should be owner's full name. 89 Set the owner of the calendar. Should be owner's full name.
89 */ 90 */
90 void setOwner( const QString &os ); 91 void setOwner( const QString &os );
91 /** 92 /**
92 Return the email address of the calendar owner. 93 Return the email address of the calendar owner.
93 */ 94 */
94 const QString &getEmail(); 95 const QString &getEmail();
95 /** 96 /**
96 Set the email address of the calendar owner. 97 Set the email address of the calendar owner.
97 */ 98 */
98 void setEmail( const QString & ); 99 void setEmail( const QString & );
99 100
100 /** 101 /**
101 Set time zone from a timezone string (e.g. -2:00) 102 Set time zone from a timezone string (e.g. -2:00)
102 */ 103 */
103 void setTimeZone( const QString &tz ); 104 void setTimeZone( const QString &tz );
104 /** 105 /**
105 Set time zone from a minutes value (e.g. -60) 106 Set time zone from a minutes value (e.g. -60)
106 */ 107 */
107 void setTimeZone( int tz ); 108 void setTimeZone( int tz );
108 /** 109 /**
109 Return time zone as offest in minutes. 110 Return time zone as offest in minutes.
110 */ 111 */
111 int getTimeZone() const; 112 int getTimeZone() const;
112 /** 113 /**
113 Compute an ISO 8601 format string from the time zone. 114 Compute an ISO 8601 format string from the time zone.
114 */ 115 */
115 QString getTimeZoneStr() const; 116 QString getTimeZoneStr() const;
116 /** 117 /**
117 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 118 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
118 values). 119 values).
119 */ 120 */
120 void setTimeZoneId( const QString & ); 121 void setTimeZoneId( const QString & );
121 /** 122 /**
122 Return time zone id. 123 Return time zone id.
123 */ 124 */
124 QString timeZoneId() const; 125 QString timeZoneId() const;
125 /** 126 /**
126 Use local time, not UTC or a time zone. 127 Use local time, not UTC or a time zone.
127 */ 128 */
128 void setLocalTime(); 129 void setLocalTime();
129 /** 130 /**
130 Return whether local time is being used. 131 Return whether local time is being used.
131 */ 132 */
132 bool isLocalTime() const; 133 bool isLocalTime() const;
133 134
134 /** 135 /**
135 Add an incidence to calendar. 136 Add an incidence to calendar.
136 137
137 @return true on success, false on error. 138 @return true on success, false on error.
138 */ 139 */
139 virtual bool addIncidence( Incidence * ); 140 virtual bool addIncidence( Incidence * );
140 /** 141 /**
141 Return filtered list of all incidences of this calendar. 142 Return filtered list of all incidences of this calendar.
142 */ 143 */
143 virtual QPtrList<Incidence> incidences(); 144 virtual QPtrList<Incidence> incidences();
144 145
145 /** 146 /**
146 Return unfiltered list of all incidences of this calendar. 147 Return unfiltered list of all incidences of this calendar.
147 */ 148 */
148 virtual QPtrList<Incidence> rawIncidences(); 149 virtual QPtrList<Incidence> rawIncidences();
149 150
150 /** 151 /**
151 Adds a Event to this calendar object. 152 Adds a Event to this calendar object.
152 @param anEvent a pointer to the event to add 153 @param anEvent a pointer to the event to add
153 154
154 @return true on success, false on error. 155 @return true on success, false on error.
155 */ 156 */
156 virtual bool addEventNoDup( Event *event ) = 0; 157 virtual bool addEventNoDup( Event *event ) = 0;
157 virtual bool addAnniversaryNoDup( Event *event ) = 0; 158 virtual bool addAnniversaryNoDup( Event *event ) = 0;
158 virtual bool addEvent( Event *anEvent ) = 0; 159 virtual bool addEvent( Event *anEvent ) = 0;
159 /** 160 /**
160 Delete event from calendar. 161 Delete event from calendar.
161 */ 162 */
162 virtual void deleteEvent( Event * ) = 0; 163 virtual void deleteEvent( Event * ) = 0;
163 /** 164 /**
164 Retrieves an event on the basis of the unique string ID. 165 Retrieves an event on the basis of the unique string ID.
165 */ 166 */
166 virtual Event *event( const QString &UniqueStr ) = 0; 167 virtual Event *event( const QString &UniqueStr ) = 0;
167 virtual Event *event( QString, QString ) = 0; 168 virtual Event *event( QString, QString ) = 0;
168 /** 169 /**
169 Builds and then returns a list of all events that match for the 170 Builds and then returns a list of all events that match for the
170 date specified. useful for dayView, etc. etc. 171 date specified. useful for dayView, etc. etc.
171 The calendar filter is applied. 172 The calendar filter is applied.
172 */ 173 */
173 QPtrList<Event> events( const QDate &date, bool sorted = false); 174 QPtrList<Event> events( const QDate &date, bool sorted = false);
174 /** 175 /**
175 Get events, which occur on the given date. 176 Get events, which occur on the given date.
176 The calendar filter is applied. 177 The calendar filter is applied.
177 */ 178 */
178 QPtrList<Event> events( const QDateTime &qdt ); 179 QPtrList<Event> events( const QDateTime &qdt );
179 /** 180 /**
180 Get events in a range of dates. If inclusive is set to true, only events 181 Get events in a range of dates. If inclusive is set to true, only events
181 are returned, which are completely included in the range. 182 are returned, which are completely included in the range.
182 The calendar filter is applied. 183 The calendar filter is applied.
183 */ 184 */
184 QPtrList<Event> events( const QDate &start, const QDate &end, 185 QPtrList<Event> events( const QDate &start, const QDate &end,
185 bool inclusive = false); 186 bool inclusive = false);
186 /** 187 /**
187 Return filtered list of all events in calendar. 188 Return filtered list of all events in calendar.
188 */ 189 */
189 virtual QPtrList<Event> events(); 190 virtual QPtrList<Event> events();
190 /** 191 /**
191 Return unfiltered list of all events in calendar. 192 Return unfiltered list of all events in calendar.
192 */ 193 */
193 virtual QPtrList<Event> rawEvents() = 0; 194 virtual QPtrList<Event> rawEvents() = 0;
194 195
195 /** 196 /**
196 Add a todo to the todolist. 197 Add a todo to the todolist.
197 198
198 @return true on success, false on error. 199 @return true on success, false on error.
199 */ 200 */
200 virtual bool addTodo( Todo *todo ) = 0; 201 virtual bool addTodo( Todo *todo ) = 0;
201 virtual bool addTodoNoDup( Todo *todo ) = 0; 202 virtual bool addTodoNoDup( Todo *todo ) = 0;
202 /** 203 /**
203 Remove a todo from the todolist. 204 Remove a todo from the todolist.
204 */ 205 */
205 virtual void deleteTodo( Todo * ) = 0; 206 virtual void deleteTodo( Todo * ) = 0;
206 virtual void deleteJournal( Journal * ) = 0; 207 virtual void deleteJournal( Journal * ) = 0;
207 /** 208 /**
208 Return filterd list of todos. 209 Return filterd list of todos.
209 */ 210 */
210 virtual QPtrList<Todo> todos(); 211 virtual QPtrList<Todo> todos();
211 /** 212 /**
212 Searches todolist for an event with this unique string identifier, 213 Searches todolist for an event with this unique string identifier,
213 returns a pointer or null. 214 returns a pointer or null.
214 */ 215 */
215 virtual Todo *todo( const QString &uid ) = 0; 216 virtual Todo *todo( const QString &uid ) = 0;
216 virtual Todo *todo( QString, QString ) = 0; 217 virtual Todo *todo( QString, QString ) = 0;
217 /** 218 /**
218 Returns list of todos due on the specified date. 219 Returns list of todos due on the specified date.
219 */ 220 */
220 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 221 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
221 /** 222 /**
222 Return unfiltered list of todos. 223 Return unfiltered list of todos.
223 */ 224 */
224 virtual QPtrList<Todo> rawTodos() = 0; 225 virtual QPtrList<Todo> rawTodos() = 0;
225 226
226 /** 227 /**
227 Add a Journal entry to calendar. 228 Add a Journal entry to calendar.
228 229
229 @return true on success, false on error. 230 @return true on success, false on error.
230 */ 231 */
231 virtual bool addJournal( Journal * ) = 0; 232 virtual bool addJournal( Journal * ) = 0;
232 /** 233 /**
233 Return Journal for given date. 234 Return Journal for given date.
234 */ 235 */
235 virtual Journal *journal( const QDate & ) = 0; 236 virtual Journal *journal( const QDate & ) = 0;
236 /** 237 /**
237 Return Journal with given UID. 238 Return Journal with given UID.
238 */ 239 */
239 virtual Journal *journal( const QString &UID ) = 0; 240 virtual Journal *journal( const QString &UID ) = 0;
240 /** 241 /**
241 Return list of all Journal entries. 242 Return list of all Journal entries.
242 */ 243 */
243 virtual QPtrList<Journal> journals() = 0; 244 virtual QPtrList<Journal> journals() = 0;
244 245
245 /** 246 /**
246 Searches all incidence types for an incidence with this unique 247 Searches all incidence types for an incidence with this unique
247 string identifier, returns a pointer or null. 248 string identifier, returns a pointer or null.
248 */ 249 */
249 Incidence* incidence( const QString&UID ); 250 Incidence* incidence( const QString&UID );
250 251
251 /** 252 /**
252 Setup relations for an incidence. 253 Setup relations for an incidence.
253 */ 254 */
254 virtual void setupRelations( Incidence * ); 255 virtual void setupRelations( Incidence * );
255 /** 256 /**
256 Remove all relations to an incidence 257 Remove all relations to an incidence
257 */ 258 */
258 virtual void removeRelations( Incidence * ); 259 virtual void removeRelations( Incidence * );
259 260
260 /** 261 /**
261 Set calendar filter, which filters events for the events() functions. 262 Set calendar filter, which filters events for the events() functions.
262 The Filter object is owned by the caller. 263 The Filter object is owned by the caller.
263 */ 264 */
264 void setFilter( CalFilter * ); 265 void setFilter( CalFilter * );
265 /** 266 /**
266 Return calendar filter. 267 Return calendar filter.
267 */ 268 */
268 CalFilter *filter(); 269 CalFilter *filter();
269 virtual QDateTime nextAlarm( int daysTo ) = 0; 270 virtual QDateTime nextAlarm( int daysTo ) = 0;
270 virtual QString nextSummary( ) const = 0; 271 virtual QString nextSummary( ) const = 0;
271 virtual void reInitAlarmSettings() = 0; 272 virtual void reInitAlarmSettings() = 0;
272 virtual QDateTime nextAlarmEventDateTime() const = 0; 273 virtual QDateTime nextAlarmEventDateTime() const = 0;
273 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 274 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
274 /** 275 /**
275 Return all alarms, which ocur in the given time interval. 276 Return all alarms, which ocur in the given time interval.
276 */ 277 */
277 virtual Alarm::List alarms( const QDateTime &from, 278 virtual Alarm::List alarms( const QDateTime &from,
278 const QDateTime &to ) = 0; 279 const QDateTime &to ) = 0;
279 280
280 class Observer { 281 class Observer {
281 public: 282 public:
282 virtual void calendarModified( bool, Calendar * ) = 0; 283 virtual void calendarModified( bool, Calendar * ) = 0;
283 }; 284 };
284 285
285 void registerObserver( Observer * ); 286 void registerObserver( Observer * );
286 287
287 void setModified( bool ); 288 void setModified( bool );
288 289
289 /** 290 /**
290 Set product id returned by loadedProductId(). This function is only 291 Set product id returned by loadedProductId(). This function is only
291 useful for the calendar loading code. 292 useful for the calendar loading code.
292 */ 293 */
293 void setLoadedProductId( const QString & ); 294 void setLoadedProductId( const QString & );
294 /** 295 /**
295 Return product id taken from file that has been loaded. Returns 296 Return product id taken from file that has been loaded. Returns
296 QString::null, if no calendar has been loaded. 297 QString::null, if no calendar has been loaded.
297 */ 298 */
298 QString loadedProductId(); 299 QString loadedProductId();
299 300
300 signals: 301 signals:
301 void calendarChanged(); 302 void calendarChanged();
302 void calendarSaved(); 303 void calendarSaved();
303 void calendarLoaded(); 304 void calendarLoaded();
304 void addAlarm(const QDateTime &qdt, const QString &noti ); 305 void addAlarm(const QDateTime &qdt, const QString &noti );
305 void removeAlarm(const QDateTime &qdt, const QString &noti ); 306 void removeAlarm(const QDateTime &qdt, const QString &noti );
306 307
307 protected: 308 protected:
308 /** 309 /**
309 Get unfiltered events, which occur on the given date. 310 Get unfiltered events, which occur on the given date.
310 */ 311 */
311 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 312 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
312 /** 313 /**
313 Get unfiltered events, which occur on the given date. 314 Get unfiltered events, which occur on the given date.
314 */ 315 */
315 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 316 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
316 bool sorted = false ) = 0; 317 bool sorted = false ) = 0;
317 /** 318 /**
318 Get events in a range of dates. If inclusive is set to true, only events 319 Get events in a range of dates. If inclusive is set to true, only events
319 are returned, which are completely included in the range. 320 are returned, which are completely included in the range.
320 */ 321 */
321 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 322 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
322 bool inclusive = false ) = 0; 323 bool inclusive = false ) = 0;
323 Incidence *mNextAlarmIncidence; 324 Incidence *mNextAlarmIncidence;
324 325
325private: 326private:
326 void init(); 327 void init();
327 328
328 QString mOwner; // who the calendar belongs to 329 QString mOwner; // who the calendar belongs to
329 QString mOwnerEmail; // email address of the owner 330 QString mOwnerEmail; // email address of the owner
330 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 331 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
331 bool mLocalTime; // use local time, not UTC or a time zone 332 bool mLocalTime; // use local time, not UTC or a time zone
332 333
333 CalFilter *mFilter; 334 CalFilter *mFilter;
334 CalFilter *mDefaultFilter; 335 CalFilter *mDefaultFilter;
335 336
336 QString mTimeZoneId; 337 QString mTimeZoneId;
337 338
338 Observer *mObserver; 339 Observer *mObserver;
339 bool mNewObserver; 340 bool mNewObserver;
340 341
341 bool mModified; 342 bool mModified;
342 343
343 QString mLoadedProductId; 344 QString mLoadedProductId;
344 345
345 // This list is used to put together related todos 346 // This list is used to put together related todos
346 QDict<Incidence> mOrphans; 347 QDict<Incidence> mOrphans;
347 QDict<Incidence> mOrphanUids; 348 QDict<Incidence> mOrphanUids;
348}; 349};
349 350
350} 351}
351 352
352#endif 353#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 21b4aaf..3f46d53 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,608 +1,629 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 close(); 68 close();
69} 69}
70 70
71bool CalendarLocal::load( const QString &fileName ) 71bool CalendarLocal::load( const QString &fileName )
72{ 72{
73 FileStorage storage( this, fileName ); 73 FileStorage storage( this, fileName );
74 return storage.load(); 74 return storage.load();
75} 75}
76 76
77bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 77bool CalendarLocal::save( const QString &fileName, CalFormat *format )
78{ 78{
79 FileStorage storage( this, fileName, format ); 79 FileStorage storage( this, fileName, format );
80 return storage.save(); 80 return storage.save();
81} 81}
82 82
83void CalendarLocal::close() 83void CalendarLocal::close()
84{ 84{
85 mEventList.setAutoDelete( true ); 85 mEventList.setAutoDelete( true );
86 mTodoList.setAutoDelete( true ); 86 mTodoList.setAutoDelete( true );
87 mJournalList.setAutoDelete( false ); 87 mJournalList.setAutoDelete( false );
88 88
89 mEventList.clear(); 89 mEventList.clear();
90 mTodoList.clear(); 90 mTodoList.clear();
91 mJournalList.clear(); 91 mJournalList.clear();
92 92
93 mEventList.setAutoDelete( false ); 93 mEventList.setAutoDelete( false );
94 mTodoList.setAutoDelete( false ); 94 mTodoList.setAutoDelete( false );
95 mJournalList.setAutoDelete( false ); 95 mJournalList.setAutoDelete( false );
96 96
97 setModified( false ); 97 setModified( false );
98} 98}
99 99
100bool CalendarLocal::addAnniversaryNoDup( Event *event ) 100bool CalendarLocal::addAnniversaryNoDup( Event *event )
101{ 101{
102 QString cat; 102 QString cat;
103 bool isBirthday = true; 103 bool isBirthday = true;
104 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 104 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
105 isBirthday = false; 105 isBirthday = false;
106 cat = i18n( "Anniversary" ); 106 cat = i18n( "Anniversary" );
107 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 107 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
108 isBirthday = true; 108 isBirthday = true;
109 cat = i18n( "Birthday" ); 109 cat = i18n( "Birthday" );
110 } else { 110 } else {
111 qDebug("addAnniversaryNoDup called without fitting category! "); 111 qDebug("addAnniversaryNoDup called without fitting category! ");
112 return false; 112 return false;
113 } 113 }
114 Event * eve; 114 Event * eve;
115 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 115 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
116 if ( !(eve->categories().contains( cat ) )) 116 if ( !(eve->categories().contains( cat ) ))
117 continue; 117 continue;
118 // now we have an event with fitting category 118 // now we have an event with fitting category
119 if ( eve->dtStart().date() != event->dtStart().date() ) 119 if ( eve->dtStart().date() != event->dtStart().date() )
120 continue; 120 continue;
121 // now we have an event with fitting category+date 121 // now we have an event with fitting category+date
122 if ( eve->summary() != event->summary() ) 122 if ( eve->summary() != event->summary() )
123 continue; 123 continue;
124 // now we have an event with fitting category+date+summary 124 // now we have an event with fitting category+date+summary
125 return false; 125 return false;
126 } 126 }
127 return addEvent( event ); 127 return addEvent( event );
128 128
129} 129}
130bool CalendarLocal::addEventNoDup( Event *event ) 130bool CalendarLocal::addEventNoDup( Event *event )
131{ 131{
132 Event * eve; 132 Event * eve;
133 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 133 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
134 if ( *eve == *event ) { 134 if ( *eve == *event ) {
135 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 135 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
136 return false; 136 return false;
137 } 137 }
138 } 138 }
139 return addEvent( event ); 139 return addEvent( event );
140} 140}
141 141
142bool CalendarLocal::addEvent( Event *event ) 142bool CalendarLocal::addEvent( Event *event )
143{ 143{
144 insertEvent( event ); 144 insertEvent( event );
145 145
146 event->registerObserver( this ); 146 event->registerObserver( this );
147 147
148 setModified( true ); 148 setModified( true );
149 149
150 return true; 150 return true;
151} 151}
152 152
153void CalendarLocal::deleteEvent( Event *event ) 153void CalendarLocal::deleteEvent( Event *event )
154{ 154{
155 155
156 156
157 if ( mEventList.removeRef( event ) ) { 157 if ( mEventList.removeRef( event ) ) {
158 setModified( true ); 158 setModified( true );
159 } 159 }
160} 160}
161 161
162 162
163Event *CalendarLocal::event( const QString &uid ) 163Event *CalendarLocal::event( const QString &uid )
164{ 164{
165 165
166 Event *event; 166 Event *event;
167 167
168 for ( event = mEventList.first(); event; event = mEventList.next() ) { 168 for ( event = mEventList.first(); event; event = mEventList.next() ) {
169 if ( event->uid() == uid ) { 169 if ( event->uid() == uid ) {
170 return event; 170 return event;
171 } 171 }
172 } 172 }
173 173
174 return 0; 174 return 0;
175} 175}
176bool CalendarLocal::addTodoNoDup( Todo *todo ) 176bool CalendarLocal::addTodoNoDup( Todo *todo )
177{ 177{
178 Todo * eve; 178 Todo * eve;
179 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 179 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
180 if ( *eve == *todo ) { 180 if ( *eve == *todo ) {
181 //qDebug("duplicate todo found! not inserted! "); 181 //qDebug("duplicate todo found! not inserted! ");
182 return false; 182 return false;
183 } 183 }
184 } 184 }
185 return addTodo( todo ); 185 return addTodo( todo );
186} 186}
187bool CalendarLocal::addTodo( Todo *todo ) 187bool CalendarLocal::addTodo( Todo *todo )
188{ 188{
189 mTodoList.append( todo ); 189 mTodoList.append( todo );
190 190
191 todo->registerObserver( this ); 191 todo->registerObserver( this );
192 192
193 // Set up subtask relations 193 // Set up subtask relations
194 setupRelations( todo ); 194 setupRelations( todo );
195 195
196 setModified( true ); 196 setModified( true );
197 197
198 return true; 198 return true;
199} 199}
200 200
201void CalendarLocal::deleteTodo( Todo *todo ) 201void CalendarLocal::deleteTodo( Todo *todo )
202{ 202{
203 // Handle orphaned children 203 // Handle orphaned children
204 removeRelations( todo ); 204 removeRelations( todo );
205 205
206 if ( mTodoList.removeRef( todo ) ) { 206 if ( mTodoList.removeRef( todo ) ) {
207 setModified( true ); 207 setModified( true );
208 } 208 }
209} 209}
210 210
211QPtrList<Todo> CalendarLocal::rawTodos() 211QPtrList<Todo> CalendarLocal::rawTodos()
212{ 212{
213 return mTodoList; 213 return mTodoList;
214} 214}
215Todo *CalendarLocal::todo( QString syncProf, QString id ) 215Todo *CalendarLocal::todo( QString syncProf, QString id )
216{ 216{
217 Todo *todo; 217 Todo *todo;
218 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 218 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
219 if ( todo->getID( syncProf ) == id ) return todo; 219 if ( todo->getID( syncProf ) == id ) return todo;
220 } 220 }
221 221
222 return 0; 222 return 0;
223} 223}
224 224void CalendarLocal::removeSyncInfo( QString syncProfile)
225{
226 QPtrList<Incidence> all = rawIncidences() ;
227 Incidence *inc;
228 for ( inc = all.first(); inc; inc = all.next() ) {
229 inc->removeID( syncProfile );
230 }
231 if ( syncProfile.isEmpty() ) {
232 QPtrList<Event> el;
233 Event *todo;
234 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
235 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
236 el.append( todo );
237 }
238 for ( todo = el.first(); todo; todo = el.next() ) {
239 deleteIncidence ( todo );
240 }
241 } else {
242 Event *lse = event( "last-syncEvent-"+ syncProfile);
243 deleteIncidence ( lse );
244 }
245}
225QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 246QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
226{ 247{
227 QPtrList<Event> el; 248 QPtrList<Event> el;
228 Event *todo; 249 Event *todo;
229 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 250 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
230 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 251 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
231 if ( todo->summary().left(3) == "E: " ) 252 if ( todo->summary().left(3) == "E: " )
232 el.append( todo ); 253 el.append( todo );
233 } 254 }
234 255
235 return el; 256 return el;
236 257
237} 258}
238Event *CalendarLocal::event( QString syncProf, QString id ) 259Event *CalendarLocal::event( QString syncProf, QString id )
239{ 260{
240 Event *todo; 261 Event *todo;
241 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 262 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
242 if ( todo->getID( syncProf ) == id ) return todo; 263 if ( todo->getID( syncProf ) == id ) return todo;
243 } 264 }
244 265
245 return 0; 266 return 0;
246} 267}
247Todo *CalendarLocal::todo( const QString &uid ) 268Todo *CalendarLocal::todo( const QString &uid )
248{ 269{
249 Todo *todo; 270 Todo *todo;
250 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 271 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
251 if ( todo->uid() == uid ) return todo; 272 if ( todo->uid() == uid ) return todo;
252 } 273 }
253 274
254 return 0; 275 return 0;
255} 276}
256QString CalendarLocal::nextSummary() const 277QString CalendarLocal::nextSummary() const
257{ 278{
258 return mNextSummary; 279 return mNextSummary;
259} 280}
260QDateTime CalendarLocal::nextAlarmEventDateTime() const 281QDateTime CalendarLocal::nextAlarmEventDateTime() const
261{ 282{
262 return mNextAlarmEventDateTime; 283 return mNextAlarmEventDateTime;
263} 284}
264void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 285void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
265{ 286{
266 //mNextAlarmIncidence 287 //mNextAlarmIncidence
267 //mNextAlarmDateTime 288 //mNextAlarmDateTime
268 //return mNextSummary; 289 //return mNextSummary;
269 //return mNextAlarmEventDateTime; 290 //return mNextAlarmEventDateTime;
270 bool newNextAlarm = false; 291 bool newNextAlarm = false;
271 bool computeNextAlarm = false; 292 bool computeNextAlarm = false;
272 bool ok; 293 bool ok;
273 int offset; 294 int offset;
274 QDateTime nextA; 295 QDateTime nextA;
275 // QString nextSum; 296 // QString nextSum;
276 //QDateTime nextEvent; 297 //QDateTime nextEvent;
277 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 298 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
278 computeNextAlarm = true; 299 computeNextAlarm = true;
279 } else { 300 } else {
280 if ( ! deleted ) { 301 if ( ! deleted ) {
281 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; 302 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ;
282 if ( ok ) { 303 if ( ok ) {
283 if ( nextA < mNextAlarmDateTime ) { 304 if ( nextA < mNextAlarmDateTime ) {
284 deRegisterAlarm(); 305 deRegisterAlarm();
285 mNextAlarmDateTime = nextA; 306 mNextAlarmDateTime = nextA;
286 mNextSummary = incidence->summary(); 307 mNextSummary = incidence->summary();
287 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 308 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
288 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 309 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
289 newNextAlarm = true; 310 newNextAlarm = true;
290 mNextAlarmIncidence = incidence; 311 mNextAlarmIncidence = incidence;
291 } else { 312 } else {
292 if ( incidence == mNextAlarmIncidence ) { 313 if ( incidence == mNextAlarmIncidence ) {
293 computeNextAlarm = true; 314 computeNextAlarm = true;
294 } 315 }
295 } 316 }
296 } else { 317 } else {
297 if ( mNextAlarmIncidence == incidence ) { 318 if ( mNextAlarmIncidence == incidence ) {
298 computeNextAlarm = true; 319 computeNextAlarm = true;
299 } 320 }
300 } 321 }
301 } else { // deleted 322 } else { // deleted
302 if ( incidence == mNextAlarmIncidence ) { 323 if ( incidence == mNextAlarmIncidence ) {
303 computeNextAlarm = true; 324 computeNextAlarm = true;
304 } 325 }
305 } 326 }
306 } 327 }
307 if ( computeNextAlarm ) { 328 if ( computeNextAlarm ) {
308 deRegisterAlarm(); 329 deRegisterAlarm();
309 nextA = nextAlarm( 1000 ); 330 nextA = nextAlarm( 1000 );
310 if (! mNextAlarmIncidence ) { 331 if (! mNextAlarmIncidence ) {
311 return; 332 return;
312 } 333 }
313 newNextAlarm = true; 334 newNextAlarm = true;
314 } 335 }
315 if ( newNextAlarm ) 336 if ( newNextAlarm )
316 registerAlarm(); 337 registerAlarm();
317} 338}
318QString CalendarLocal:: getAlarmNotification() 339QString CalendarLocal:: getAlarmNotification()
319{ 340{
320 QString ret; 341 QString ret;
321 // this should not happen 342 // this should not happen
322 if (! mNextAlarmIncidence ) 343 if (! mNextAlarmIncidence )
323 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 344 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
324 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 345 Alarm* alarm = mNextAlarmIncidence->alarms().first();
325 if ( alarm->type() == Alarm::Procedure ) { 346 if ( alarm->type() == Alarm::Procedure ) {
326 ret = "proc_alarm" + alarm->programFile()+"+++"; 347 ret = "proc_alarm" + alarm->programFile()+"+++";
327 } else { 348 } else {
328 ret = "audio_alarm" +alarm->audioFile() +"+++"; 349 ret = "audio_alarm" +alarm->audioFile() +"+++";
329 } 350 }
330 ret += "cal_alarm"+ mNextSummary.left( 25 ); 351 ret += "cal_alarm"+ mNextSummary.left( 25 );
331 if ( mNextSummary.length() > 25 ) 352 if ( mNextSummary.length() > 25 )
332 ret += "\n" + mNextSummary.mid(25, 25 ); 353 ret += "\n" + mNextSummary.mid(25, 25 );
333 ret+= "\n"+mNextAlarmEventDateTimeString; 354 ret+= "\n"+mNextAlarmEventDateTimeString;
334 return ret; 355 return ret;
335} 356}
336void CalendarLocal::registerAlarm() 357void CalendarLocal::registerAlarm()
337{ 358{
338 mLastAlarmNotificationString = getAlarmNotification(); 359 mLastAlarmNotificationString = getAlarmNotification();
339 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 360 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
340 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 361 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
341// #ifndef DESKTOP_VERSION 362// #ifndef DESKTOP_VERSION
342// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 363// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
343// #endif 364// #endif
344} 365}
345void CalendarLocal::deRegisterAlarm() 366void CalendarLocal::deRegisterAlarm()
346{ 367{
347 if ( mLastAlarmNotificationString.isNull() ) 368 if ( mLastAlarmNotificationString.isNull() )
348 return; 369 return;
349 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 370 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
350 371
351 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 372 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
352// #ifndef DESKTOP_VERSION 373// #ifndef DESKTOP_VERSION
353// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 374// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
354// #endif 375// #endif
355} 376}
356 377
357QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 378QPtrList<Todo> CalendarLocal::todos( const QDate &date )
358{ 379{
359 QPtrList<Todo> todos; 380 QPtrList<Todo> todos;
360 381
361 Todo *todo; 382 Todo *todo;
362 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 383 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
363 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 384 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
364 todos.append( todo ); 385 todos.append( todo );
365 } 386 }
366 } 387 }
367 388
368 filter()->apply( &todos ); 389 filter()->apply( &todos );
369 return todos; 390 return todos;
370} 391}
371void CalendarLocal::reInitAlarmSettings() 392void CalendarLocal::reInitAlarmSettings()
372{ 393{
373 if ( !mNextAlarmIncidence ) { 394 if ( !mNextAlarmIncidence ) {
374 nextAlarm( 1000 ); 395 nextAlarm( 1000 );
375 } 396 }
376 deRegisterAlarm(); 397 deRegisterAlarm();
377 mNextAlarmIncidence = 0; 398 mNextAlarmIncidence = 0;
378 checkAlarmForIncidence( 0, false ); 399 checkAlarmForIncidence( 0, false );
379 400
380} 401}
381 402
382 403
383 404
384QDateTime CalendarLocal::nextAlarm( int daysTo ) 405QDateTime CalendarLocal::nextAlarm( int daysTo )
385{ 406{
386 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 407 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
387 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 408 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
388 QDateTime next; 409 QDateTime next;
389 Event *e; 410 Event *e;
390 bool ok; 411 bool ok;
391 bool found = false; 412 bool found = false;
392 int offset; 413 int offset;
393 mNextAlarmIncidence = 0; 414 mNextAlarmIncidence = 0;
394 for( e = mEventList.first(); e; e = mEventList.next() ) { 415 for( e = mEventList.first(); e; e = mEventList.next() ) {
395 next = e->getNextAlarmDateTime(& ok, &offset ) ; 416 next = e->getNextAlarmDateTime(& ok, &offset ) ;
396 if ( ok ) { 417 if ( ok ) {
397 if ( next < nextA ) { 418 if ( next < nextA ) {
398 nextA = next; 419 nextA = next;
399 found = true; 420 found = true;
400 mNextSummary = e->summary(); 421 mNextSummary = e->summary();
401 mNextAlarmEventDateTime = next.addSecs(offset ) ; 422 mNextAlarmEventDateTime = next.addSecs(offset ) ;
402 mNextAlarmIncidence = (Incidence *) e; 423 mNextAlarmIncidence = (Incidence *) e;
403 } 424 }
404 } 425 }
405 } 426 }
406 Todo *t; 427 Todo *t;
407 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 428 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
408 next = t->getNextAlarmDateTime(& ok, &offset ) ; 429 next = t->getNextAlarmDateTime(& ok, &offset ) ;
409 if ( ok ) { 430 if ( ok ) {
410 if ( next < nextA ) { 431 if ( next < nextA ) {
411 nextA = next; 432 nextA = next;
412 found = true; 433 found = true;
413 mNextSummary = t->summary(); 434 mNextSummary = t->summary();
414 mNextAlarmEventDateTime = next.addSecs(offset ); 435 mNextAlarmEventDateTime = next.addSecs(offset );
415 mNextAlarmIncidence = (Incidence *) t; 436 mNextAlarmIncidence = (Incidence *) t;
416 } 437 }
417 } 438 }
418 } 439 }
419 if ( mNextAlarmIncidence ) { 440 if ( mNextAlarmIncidence ) {
420 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 441 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
421 mNextAlarmDateTime = nextA; 442 mNextAlarmDateTime = nextA;
422 } 443 }
423 return nextA; 444 return nextA;
424} 445}
425Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 446Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
426{ 447{
427 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 448 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
428} 449}
429 450
430Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 451Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
431{ 452{
432 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " 453 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - "
433 << to.toString() << ")\n"; 454 << to.toString() << ")\n";
434 455
435 Alarm::List alarms; 456 Alarm::List alarms;
436 457
437 Event *e; 458 Event *e;
438 459
439 for( e = mEventList.first(); e; e = mEventList.next() ) { 460 for( e = mEventList.first(); e; e = mEventList.next() ) {
440 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 461 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
441 else appendAlarms( alarms, e, from, to ); 462 else appendAlarms( alarms, e, from, to );
442 } 463 }
443 464
444 Todo *t; 465 Todo *t;
445 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 466 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
446 appendAlarms( alarms, t, from, to ); 467 appendAlarms( alarms, t, from, to );
447 } 468 }
448 469
449 return alarms; 470 return alarms;
450} 471}
451 472
452void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 473void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
453 const QDateTime &from, const QDateTime &to ) 474 const QDateTime &from, const QDateTime &to )
454{ 475{
455 QPtrList<Alarm> alarmList = incidence->alarms(); 476 QPtrList<Alarm> alarmList = incidence->alarms();
456 Alarm *alarm; 477 Alarm *alarm;
457 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 478 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
458// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 479// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
459// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 480// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
460 if ( alarm->enabled() ) { 481 if ( alarm->enabled() ) {
461 if ( alarm->time() >= from && alarm->time() <= to ) { 482 if ( alarm->time() >= from && alarm->time() <= to ) {
462 kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() 483 kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary()
463 << "': " << alarm->time().toString() << endl; 484 << "': " << alarm->time().toString() << endl;
464 alarms.append( alarm ); 485 alarms.append( alarm );
465 } 486 }
466 } 487 }
467 } 488 }
468} 489}
469 490
470void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 491void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
471 Incidence *incidence, 492 Incidence *incidence,
472 const QDateTime &from, 493 const QDateTime &from,
473 const QDateTime &to ) 494 const QDateTime &to )
474{ 495{
475 496
476 QPtrList<Alarm> alarmList = incidence->alarms(); 497 QPtrList<Alarm> alarmList = incidence->alarms();
477 Alarm *alarm; 498 Alarm *alarm;
478 QDateTime qdt; 499 QDateTime qdt;
479 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 500 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
480 if (incidence->recursOn(from.date())) { 501 if (incidence->recursOn(from.date())) {
481 qdt.setTime(alarm->time().time()); 502 qdt.setTime(alarm->time().time());
482 qdt.setDate(from.date()); 503 qdt.setDate(from.date());
483 } 504 }
484 else qdt = alarm->time(); 505 else qdt = alarm->time();
485 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 506 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
486 if ( alarm->enabled() ) { 507 if ( alarm->enabled() ) {
487 if ( qdt >= from && qdt <= to ) { 508 if ( qdt >= from && qdt <= to ) {
488 alarms.append( alarm ); 509 alarms.append( alarm );
489 } 510 }
490 } 511 }
491 } 512 }
492} 513}
493 514
494 515
495/****************************** PROTECTED METHODS ****************************/ 516/****************************** PROTECTED METHODS ****************************/
496 517
497// after changes are made to an event, this should be called. 518// after changes are made to an event, this should be called.
498void CalendarLocal::update( IncidenceBase *incidence ) 519void CalendarLocal::update( IncidenceBase *incidence )
499{ 520{
500 incidence->setSyncStatus( Event::SYNCMOD ); 521 incidence->setSyncStatus( Event::SYNCMOD );
501 incidence->setLastModified( QDateTime::currentDateTime() ); 522 incidence->setLastModified( QDateTime::currentDateTime() );
502 // we should probably update the revision number here, 523 // we should probably update the revision number here,
503 // or internally in the Event itself when certain things change. 524 // or internally in the Event itself when certain things change.
504 // need to verify with ical documentation. 525 // need to verify with ical documentation.
505 526
506 setModified( true ); 527 setModified( true );
507} 528}
508 529
509void CalendarLocal::insertEvent( Event *event ) 530void CalendarLocal::insertEvent( Event *event )
510{ 531{
511 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 532 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
512} 533}
513 534
514 535
515QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 536QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
516{ 537{
517 QPtrList<Event> eventList; 538 QPtrList<Event> eventList;
518 539
519 Event *event; 540 Event *event;
520 for( event = mEventList.first(); event; event = mEventList.next() ) { 541 for( event = mEventList.first(); event; event = mEventList.next() ) {
521 if ( event->doesRecur() ) { 542 if ( event->doesRecur() ) {
522 if ( event->isMultiDay() ) { 543 if ( event->isMultiDay() ) {
523 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 544 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
524 int i; 545 int i;
525 for ( i = 0; i <= extraDays; i++ ) { 546 for ( i = 0; i <= extraDays; i++ ) {
526 if ( event->recursOn( qd.addDays( -i ) ) ) { 547 if ( event->recursOn( qd.addDays( -i ) ) ) {
527 eventList.append( event ); 548 eventList.append( event );
528 break; 549 break;
529 } 550 }
530 } 551 }
531 } else { 552 } else {
532 if ( event->recursOn( qd ) ) 553 if ( event->recursOn( qd ) )
533 eventList.append( event ); 554 eventList.append( event );
534 } 555 }
535 } else { 556 } else {
536 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 557 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
537 eventList.append( event ); 558 eventList.append( event );
538 } 559 }
539 } 560 }
540 } 561 }
541 562
542 if ( !sorted ) { 563 if ( !sorted ) {
543 return eventList; 564 return eventList;
544 } 565 }
545 566
546 // kdDebug(5800) << "Sorting events for date\n" << endl; 567 // kdDebug(5800) << "Sorting events for date\n" << endl;
547 // now, we have to sort it based on dtStart.time() 568 // now, we have to sort it based on dtStart.time()
548 QPtrList<Event> eventListSorted; 569 QPtrList<Event> eventListSorted;
549 Event *sortEvent; 570 Event *sortEvent;
550 for ( event = eventList.first(); event; event = eventList.next() ) { 571 for ( event = eventList.first(); event; event = eventList.next() ) {
551 sortEvent = eventListSorted.first(); 572 sortEvent = eventListSorted.first();
552 int i = 0; 573 int i = 0;
553 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 574 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
554 { 575 {
555 i++; 576 i++;
556 sortEvent = eventListSorted.next(); 577 sortEvent = eventListSorted.next();
557 } 578 }
558 eventListSorted.insert( i, event ); 579 eventListSorted.insert( i, event );
559 } 580 }
560 return eventListSorted; 581 return eventListSorted;
561} 582}
562 583
563 584
564QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 585QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
565 bool inclusive ) 586 bool inclusive )
566{ 587{
567 Event *event = 0; 588 Event *event = 0;
568 589
569 QPtrList<Event> eventList; 590 QPtrList<Event> eventList;
570 591
571 // Get non-recurring events 592 // Get non-recurring events
572 for( event = mEventList.first(); event; event = mEventList.next() ) { 593 for( event = mEventList.first(); event; event = mEventList.next() ) {
573 if ( event->doesRecur() ) { 594 if ( event->doesRecur() ) {
574 QDate rStart = event->dtStart().date(); 595 QDate rStart = event->dtStart().date();
575 bool found = false; 596 bool found = false;
576 if ( inclusive ) { 597 if ( inclusive ) {
577 if ( rStart >= start && rStart <= end ) { 598 if ( rStart >= start && rStart <= end ) {
578 // Start date of event is in range. Now check for end date. 599 // Start date of event is in range. Now check for end date.
579 // if duration is negative, event recurs forever, so do not include it. 600 // if duration is negative, event recurs forever, so do not include it.
580 if ( event->recurrence()->duration() == 0 ) { // End date set 601 if ( event->recurrence()->duration() == 0 ) { // End date set
581 QDate rEnd = event->recurrence()->endDate(); 602 QDate rEnd = event->recurrence()->endDate();
582 if ( rEnd >= start && rEnd <= end ) { // End date within range 603 if ( rEnd >= start && rEnd <= end ) { // End date within range
583 found = true; 604 found = true;
584 } 605 }
585 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 606 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
586 // TODO: Calculate end date from duration. Should be done in Event 607 // TODO: Calculate end date from duration. Should be done in Event
587 // For now exclude all events with a duration. 608 // For now exclude all events with a duration.
588 } 609 }
589 } 610 }
590 } else { 611 } else {
591 bool founOne; 612 bool founOne;
592 QDate next = event->getNextOccurence( start, &founOne ).date(); 613 QDate next = event->getNextOccurence( start, &founOne ).date();
593 if ( founOne ) { 614 if ( founOne ) {
594 if ( next <= end ) { 615 if ( next <= end ) {
595 found = true; 616 found = true;
596 } 617 }
597 } 618 }
598 619
599 /* 620 /*
600 // crap !!! 621 // crap !!!
601 if ( rStart <= end ) { // Start date not after range 622 if ( rStart <= end ) { // Start date not after range
602 if ( rStart >= start ) { // Start date within range 623 if ( rStart >= start ) { // Start date within range
603 found = true; 624 found = true;
604 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 625 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
605 found = true; 626 found = true;
606 } else if ( event->recurrence()->duration() == 0 ) { // End date set 627 } else if ( event->recurrence()->duration() == 0 ) { // End date set
607 QDate rEnd = event->recurrence()->endDate(); 628 QDate rEnd = event->recurrence()->endDate();
608 if ( rEnd >= start && rEnd <= end ) { // End date within range 629 if ( rEnd >= start && rEnd <= end ) { // End date within range
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 5b6c64c..98ec710 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,217 +1,218 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22#ifndef KCAL_CALENDARLOCAL_H 22#ifndef KCAL_CALENDARLOCAL_H
23#define KCAL_CALENDARLOCAL_H 23#define KCAL_CALENDARLOCAL_H
24 24
25#include "calendar.h" 25#include "calendar.h"
26 26
27namespace KCal { 27namespace KCal {
28 28
29class CalFormat; 29class CalFormat;
30 30
31/** 31/**
32 This class provides a calendar stored as a local file. 32 This class provides a calendar stored as a local file.
33*/ 33*/
34class CalendarLocal : public Calendar 34class CalendarLocal : public Calendar
35{ 35{
36 public: 36 public:
37 /** 37 /**
38 Constructs a new calendar, with variables initialized to sane values. 38 Constructs a new calendar, with variables initialized to sane values.
39 */ 39 */
40 CalendarLocal(); 40 CalendarLocal();
41 /** 41 /**
42 Constructs a new calendar, with variables initialized to sane values. 42 Constructs a new calendar, with variables initialized to sane values.
43 */ 43 */
44 CalendarLocal( const QString &timeZoneId ); 44 CalendarLocal( const QString &timeZoneId );
45 ~CalendarLocal(); 45 ~CalendarLocal();
46 46
47 /** 47 /**
48 Loads a calendar on disk in vCalendar or iCalendar format into the current 48 Loads a calendar on disk in vCalendar or iCalendar format into the current
49 calendar. Any information already present is lost. 49 calendar. Any information already present is lost.
50 @return true, if successfull, false on error. 50 @return true, if successfull, false on error.
51 @param fileName the name of the calendar on disk. 51 @param fileName the name of the calendar on disk.
52 */ 52 */
53 bool load( const QString &fileName ); 53 bool load( const QString &fileName );
54 /** 54 /**
55 Writes out the calendar to disk in the specified \a format. 55 Writes out the calendar to disk in the specified \a format.
56 CalendarLocal takes ownership of the CalFormat object. 56 CalendarLocal takes ownership of the CalFormat object.
57 @return true, if successfull, false on error. 57 @return true, if successfull, false on error.
58 @param fileName the name of the file 58 @param fileName the name of the file
59 */ 59 */
60 bool save( const QString &fileName, CalFormat *format = 0 ); 60 bool save( const QString &fileName, CalFormat *format = 0 );
61 61
62 /** 62 /**
63 Clears out the current calendar, freeing all used memory etc. etc. 63 Clears out the current calendar, freeing all used memory etc. etc.
64 */ 64 */
65 void close(); 65 void close();
66 66
67 void save() {} 67 void save() {}
68 68
69 /** 69 /**
70 Add Event to calendar. 70 Add Event to calendar.
71 */ 71 */
72 void removeSyncInfo( QString syncProfile);
72 bool addAnniversaryNoDup( Event *event ); 73 bool addAnniversaryNoDup( Event *event );
73 bool addEventNoDup( Event *event ); 74 bool addEventNoDup( Event *event );
74 bool addEvent( Event *event ); 75 bool addEvent( Event *event );
75 /** 76 /**
76 Deletes an event from this calendar. 77 Deletes an event from this calendar.
77 */ 78 */
78 void deleteEvent( Event *event ); 79 void deleteEvent( Event *event );
79 80
80 /** 81 /**
81 Retrieves an event on the basis of the unique string ID. 82 Retrieves an event on the basis of the unique string ID.
82 */ 83 */
83 Event *event( const QString &uid ); 84 Event *event( const QString &uid );
84 /** 85 /**
85 Return unfiltered list of all events in calendar. 86 Return unfiltered list of all events in calendar.
86 */ 87 */
87 QPtrList<Event> rawEvents(); 88 QPtrList<Event> rawEvents();
88 QPtrList<Event> getExternLastSyncEvents(); 89 QPtrList<Event> getExternLastSyncEvents();
89 /** 90 /**
90 Add a todo to the todolist. 91 Add a todo to the todolist.
91 */ 92 */
92 bool addTodo( Todo *todo ); 93 bool addTodo( Todo *todo );
93 bool addTodoNoDup( Todo *todo ); 94 bool addTodoNoDup( Todo *todo );
94 /** 95 /**
95 Remove a todo from the todolist. 96 Remove a todo from the todolist.
96 */ 97 */
97 void deleteTodo( Todo * ); 98 void deleteTodo( Todo * );
98 /** 99 /**
99 Searches todolist for an event with this unique string identifier, 100 Searches todolist for an event with this unique string identifier,
100 returns a pointer or null. 101 returns a pointer or null.
101 */ 102 */
102 Todo *todo( const QString &uid ); 103 Todo *todo( const QString &uid );
103 /** 104 /**
104 Return list of all todos. 105 Return list of all todos.
105 */ 106 */
106 QPtrList<Todo> rawTodos(); 107 QPtrList<Todo> rawTodos();
107 /** 108 /**
108 Returns list of todos due on the specified date. 109 Returns list of todos due on the specified date.
109 */ 110 */
110 QPtrList<Todo> todos( const QDate &date ); 111 QPtrList<Todo> todos( const QDate &date );
111 /** 112 /**
112 Return list of all todos. 113 Return list of all todos.
113 114
114 Workaround because compiler does not recognize function of base class. 115 Workaround because compiler does not recognize function of base class.
115 */ 116 */
116 QPtrList<Todo> todos() { return Calendar::todos(); } 117 QPtrList<Todo> todos() { return Calendar::todos(); }
117 118
118 /** 119 /**
119 Add a Journal entry to calendar. 120 Add a Journal entry to calendar.
120 */ 121 */
121 bool addJournal( Journal * ); 122 bool addJournal( Journal * );
122 /** 123 /**
123 Remove a Journal from the calendar. 124 Remove a Journal from the calendar.
124 */ 125 */
125 void deleteJournal( Journal * ); 126 void deleteJournal( Journal * );
126 /** 127 /**
127 Return Journal for given date. 128 Return Journal for given date.
128 */ 129 */
129 Journal *journal( const QDate & ); 130 Journal *journal( const QDate & );
130 /** 131 /**
131 Return Journal with given UID. 132 Return Journal with given UID.
132 */ 133 */
133 Journal *journal( const QString &uid ); 134 Journal *journal( const QString &uid );
134 /** 135 /**
135 Return list of all Journals stored in calendar. 136 Return list of all Journals stored in calendar.
136 */ 137 */
137 QPtrList<Journal> journals(); 138 QPtrList<Journal> journals();
138 139
139 /** 140 /**
140 Return all alarms, which ocur in the given time interval. 141 Return all alarms, which ocur in the given time interval.
141 */ 142 */
142 Alarm::List alarms( const QDateTime &from, const QDateTime &to ); 143 Alarm::List alarms( const QDateTime &from, const QDateTime &to );
143 144
144 /** 145 /**
145 Return all alarms, which ocur before given date. 146 Return all alarms, which ocur before given date.
146 */ 147 */
147 Alarm::List alarmsTo( const QDateTime &to ); 148 Alarm::List alarmsTo( const QDateTime &to );
148 149
149 QDateTime nextAlarm( int daysTo ) ; 150 QDateTime nextAlarm( int daysTo ) ;
150 QDateTime nextAlarmEventDateTime() const; 151 QDateTime nextAlarmEventDateTime() const;
151 void checkAlarmForIncidence( Incidence *, bool deleted ) ; 152 void checkAlarmForIncidence( Incidence *, bool deleted ) ;
152 void registerAlarm(); 153 void registerAlarm();
153 void deRegisterAlarm(); 154 void deRegisterAlarm();
154 QString getAlarmNotification(); 155 QString getAlarmNotification();
155 QString nextSummary() const ; 156 QString nextSummary() const ;
156 /** 157 /**
157 This method should be called whenever a Event is modified directly 158 This method should be called whenever a Event is modified directly
158 via it's pointer. It makes sure that the calendar is internally 159 via it's pointer. It makes sure that the calendar is internally
159 consistent. 160 consistent.
160 */ 161 */
161 void update( IncidenceBase *incidence ); 162 void update( IncidenceBase *incidence );
162 163
163 /** 164 /**
164 Builds and then returns a list of all events that match for the 165 Builds and then returns a list of all events that match for the
165 date specified. useful for dayView, etc. etc. 166 date specified. useful for dayView, etc. etc.
166 */ 167 */
167 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); 168 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false );
168 /** 169 /**
169 Get unfiltered events for date \a qdt. 170 Get unfiltered events for date \a qdt.
170 */ 171 */
171 QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); 172 QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
172 /** 173 /**
173 Get unfiltered events in a range of dates. If inclusive is set to true, 174 Get unfiltered events in a range of dates. If inclusive is set to true,
174 only events are returned, which are completely included in the range. 175 only events are returned, which are completely included in the range.
175 */ 176 */
176 QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 177 QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
177 bool inclusive = false ); 178 bool inclusive = false );
178 Todo *todo( QString, QString ); 179 Todo *todo( QString, QString );
179 Event *event( QString, QString ); 180 Event *event( QString, QString );
180 181
181 182
182 183
183 protected: 184 protected:
184 185
185 // Event* mNextAlarmEvent; 186 // Event* mNextAlarmEvent;
186 QString mNextSummary; 187 QString mNextSummary;
187 QString mNextAlarmEventDateTimeString; 188 QString mNextAlarmEventDateTimeString;
188 QString mLastAlarmNotificationString; 189 QString mLastAlarmNotificationString;
189 QDateTime mNextAlarmEventDateTime; 190 QDateTime mNextAlarmEventDateTime;
190 QDateTime mNextAlarmDateTime; 191 QDateTime mNextAlarmDateTime;
191 void reInitAlarmSettings(); 192 void reInitAlarmSettings();
192 193
193 /** Notification function of IncidenceBase::Observer. */ 194 /** Notification function of IncidenceBase::Observer. */
194 void incidenceUpdated( IncidenceBase *i ) { update( i ); } 195 void incidenceUpdated( IncidenceBase *i ) { update( i ); }
195 196
196 /** inserts an event into its "proper place" in the calendar. */ 197 /** inserts an event into its "proper place" in the calendar. */
197 void insertEvent( Event *event ); 198 void insertEvent( Event *event );
198 199
199 /** Append alarms of incidence in interval to list of alarms. */ 200 /** Append alarms of incidence in interval to list of alarms. */
200 void appendAlarms( Alarm::List &alarms, Incidence *incidence, 201 void appendAlarms( Alarm::List &alarms, Incidence *incidence,
201 const QDateTime &from, const QDateTime &to ); 202 const QDateTime &from, const QDateTime &to );
202 203
203 /** Append alarms of recurring events in interval to list of alarms. */ 204 /** Append alarms of recurring events in interval to list of alarms. */
204 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, 205 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
205 const QDateTime &from, const QDateTime &to ); 206 const QDateTime &from, const QDateTime &to );
206 207
207 private: 208 private:
208 void init(); 209 void init();
209 210
210 QPtrList<Event> mEventList; 211 QPtrList<Event> mEventList;
211 QPtrList<Todo> mTodoList; 212 QPtrList<Todo> mTodoList;
212 QPtrList<Journal> mJournalList; 213 QPtrList<Journal> mJournalList;
213}; 214};
214 215
215} 216}
216 217
217#endif 218#endif
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index b36dc1a..9aa517c 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,407 +1,410 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 setUid(CalFormat::createUniqueId()); 37 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 38 mOrganizer = "";
39 mFloats = false; 39 mFloats = false;
40 mDuration = 0; 40 mDuration = 0;
41 mHasDuration = false; 41 mHasDuration = false;
42 mPilotId = 0; 42 mPilotId = 0;
43 mExternalId = ":"; 43 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 45 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
47} 47}
48 48
49IncidenceBase::IncidenceBase(const IncidenceBase &i) : 49IncidenceBase::IncidenceBase(const IncidenceBase &i) :
50 CustomProperties( i ) 50 CustomProperties( i )
51{ 51{
52 mReadOnly = i.mReadOnly; 52 mReadOnly = i.mReadOnly;
53 mDtStart = i.mDtStart; 53 mDtStart = i.mDtStart;
54 mDuration = i.mDuration; 54 mDuration = i.mDuration;
55 mHasDuration = i.mHasDuration; 55 mHasDuration = i.mHasDuration;
56 mOrganizer = i.mOrganizer; 56 mOrganizer = i.mOrganizer;
57 mUid = i.mUid; 57 mUid = i.mUid;
58 QPtrList<Attendee> attendees = i.attendees(); 58 QPtrList<Attendee> attendees = i.attendees();
59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
60 mAttendees.append( new Attendee( *a ) ); 60 mAttendees.append( new Attendee( *a ) );
61 } 61 }
62 mFloats = i.mFloats; 62 mFloats = i.mFloats;
63 mLastModified = i.mLastModified; 63 mLastModified = i.mLastModified;
64 mPilotId = i.mPilotId; 64 mPilotId = i.mPilotId;
65 mTempSyncStat = i.mTempSyncStat; 65 mTempSyncStat = i.mTempSyncStat;
66 mSyncStatus = i.mSyncStatus; 66 mSyncStatus = i.mSyncStatus;
67 mExternalId = i.mExternalId; 67 mExternalId = i.mExternalId;
68 // The copied object is a new one, so it isn't observed by the observer 68 // The copied object is a new one, so it isn't observed by the observer
69 // of the original object. 69 // of the original object.
70 mObservers.clear(); 70 mObservers.clear();
71 71
72 mAttendees.setAutoDelete( true ); 72 mAttendees.setAutoDelete( true );
73} 73}
74 74
75IncidenceBase::~IncidenceBase() 75IncidenceBase::~IncidenceBase()
76{ 76{
77} 77}
78 78
79 79
80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
81{ 81{
82 // do not compare mSyncStatus and mExternalId 82 // do not compare mSyncStatus and mExternalId
83 if( i1.attendees().count() != i2.attendees().count() ) { 83 if( i1.attendees().count() != i2.attendees().count() ) {
84 return false; // no need to check further 84 return false; // no need to check further
85 } 85 }
86 if ( i1.attendees().count() > 0 ) { 86 if ( i1.attendees().count() > 0 ) {
87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
88 while ( a1 ) { 88 while ( a1 ) {
89 if ( !( (*a1) == (*a2)) ) 89 if ( !( (*a1) == (*a2)) )
90 { 90 {
91 //qDebug("Attendee not equal "); 91 //qDebug("Attendee not equal ");
92 return false; 92 return false;
93 } 93 }
94 a1 = i1.attendees().next(); 94 a1 = i1.attendees().next();
95 a2 = i2.attendees().next(); 95 a2 = i2.attendees().next();
96 } 96 }
97 } 97 }
98 //if ( i1.dtStart() != i2.dtStart() ) 98 //if ( i1.dtStart() != i2.dtStart() )
99 // return false; 99 // return false;
100#if 0 100#if 0
101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
102 qDebug("1 %d ",i1.duration() == i2.duration() ); 102 qDebug("1 %d ",i1.duration() == i2.duration() );
103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
106 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 106 qDebug("6 %d ",i1.organizer() == i2.organizer() );
107 107
108#endif 108#endif
109 return ( i1.organizer() == i2.organizer() && 109 return ( i1.organizer() == i2.organizer() &&
110 // i1.uid() == i2.uid() && 110 // i1.uid() == i2.uid() &&
111 // Don't compare lastModified, otherwise the operator is not 111 // Don't compare lastModified, otherwise the operator is not
112 // of much use. We are not comparing for identity, after all. 112 // of much use. We are not comparing for identity, after all.
113 i1.doesFloat() == i2.doesFloat() && 113 i1.doesFloat() == i2.doesFloat() &&
114 i1.duration() == i2.duration() && 114 i1.duration() == i2.duration() &&
115 i1.hasDuration() == i2.hasDuration() && 115 i1.hasDuration() == i2.hasDuration() &&
116 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 116 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
117 // no need to compare mObserver 117 // no need to compare mObserver
118} 118}
119 119
120 120
121QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 121QDateTime IncidenceBase::getEvenTime( QDateTime dt )
122{ 122{
123 QTime t = dt.time(); 123 QTime t = dt.time();
124 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 124 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
125 return dt; 125 return dt;
126} 126}
127 127
128 128
129void IncidenceBase::setUid(const QString &uid) 129void IncidenceBase::setUid(const QString &uid)
130{ 130{
131 mUid = uid; 131 mUid = uid;
132 updated(); 132 updated();
133} 133}
134 134
135QString IncidenceBase::uid() const 135QString IncidenceBase::uid() const
136{ 136{
137 return mUid; 137 return mUid;
138} 138}
139 139
140void IncidenceBase::setLastModified(const QDateTime &lm) 140void IncidenceBase::setLastModified(const QDateTime &lm)
141{ 141{
142 // DON'T! updated() because we call this from 142 // DON'T! updated() because we call this from
143 // Calendar::updateEvent(). 143 // Calendar::updateEvent().
144 mLastModified = getEvenTime(lm); 144 mLastModified = getEvenTime(lm);
145 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 145 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
146} 146}
147 147
148QDateTime IncidenceBase::lastModified() const 148QDateTime IncidenceBase::lastModified() const
149{ 149{
150 return mLastModified; 150 return mLastModified;
151} 151}
152 152
153void IncidenceBase::setOrganizer(const QString &o) 153void IncidenceBase::setOrganizer(const QString &o)
154{ 154{
155 // we don't check for readonly here, because it is 155 // we don't check for readonly here, because it is
156 // possible that by setting the organizer we are changing 156 // possible that by setting the organizer we are changing
157 // the event's readonly status... 157 // the event's readonly status...
158 mOrganizer = o; 158 mOrganizer = o;
159 if (mOrganizer.left(7).upper() == "MAILTO:") 159 if (mOrganizer.left(7).upper() == "MAILTO:")
160 mOrganizer = mOrganizer.remove(0,7); 160 mOrganizer = mOrganizer.remove(0,7);
161 161
162 updated(); 162 updated();
163} 163}
164 164
165QString IncidenceBase::organizer() const 165QString IncidenceBase::organizer() const
166{ 166{
167 return mOrganizer; 167 return mOrganizer;
168} 168}
169 169
170void IncidenceBase::setReadOnly( bool readOnly ) 170void IncidenceBase::setReadOnly( bool readOnly )
171{ 171{
172 mReadOnly = readOnly; 172 mReadOnly = readOnly;
173} 173}
174 174
175void IncidenceBase::setDtStart(const QDateTime &dtStart) 175void IncidenceBase::setDtStart(const QDateTime &dtStart)
176{ 176{
177// if (mReadOnly) return; 177// if (mReadOnly) return;
178 mDtStart = getEvenTime(dtStart); 178 mDtStart = getEvenTime(dtStart);
179 updated(); 179 updated();
180} 180}
181 181
182QDateTime IncidenceBase::dtStart() const 182QDateTime IncidenceBase::dtStart() const
183{ 183{
184 return mDtStart; 184 return mDtStart;
185} 185}
186 186
187QString IncidenceBase::dtStartTimeStr() const 187QString IncidenceBase::dtStartTimeStr() const
188{ 188{
189 return KGlobal::locale()->formatTime(dtStart().time()); 189 return KGlobal::locale()->formatTime(dtStart().time());
190} 190}
191 191
192QString IncidenceBase::dtStartDateStr(bool shortfmt) const 192QString IncidenceBase::dtStartDateStr(bool shortfmt) const
193{ 193{
194 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 194 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
195} 195}
196 196
197QString IncidenceBase::dtStartStr(bool shortfmt) const 197QString IncidenceBase::dtStartStr(bool shortfmt) const
198{ 198{
199 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 199 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
200} 200}
201 201
202 202
203bool IncidenceBase::doesFloat() const 203bool IncidenceBase::doesFloat() const
204{ 204{
205 return mFloats; 205 return mFloats;
206} 206}
207 207
208void IncidenceBase::setFloats(bool f) 208void IncidenceBase::setFloats(bool f)
209{ 209{
210 if (mReadOnly) return; 210 if (mReadOnly) return;
211 mFloats = f; 211 mFloats = f;
212 updated(); 212 updated();
213} 213}
214 214
215 215
216void IncidenceBase::addAttendee(Attendee *a, bool doupdate) 216void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
217{ 217{
218 if (mReadOnly) return; 218 if (mReadOnly) return;
219 if (a->name().left(7).upper() == "MAILTO:") 219 if (a->name().left(7).upper() == "MAILTO:")
220 a->setName(a->name().remove(0,7)); 220 a->setName(a->name().remove(0,7));
221 221
222 mAttendees.append(a); 222 mAttendees.append(a);
223 if (doupdate) updated(); 223 if (doupdate) updated();
224} 224}
225 225
226#if 0 226#if 0
227void IncidenceBase::removeAttendee(Attendee *a) 227void IncidenceBase::removeAttendee(Attendee *a)
228{ 228{
229 if (mReadOnly) return; 229 if (mReadOnly) return;
230 mAttendees.removeRef(a); 230 mAttendees.removeRef(a);
231 updated(); 231 updated();
232} 232}
233 233
234void IncidenceBase::removeAttendee(const char *n) 234void IncidenceBase::removeAttendee(const char *n)
235{ 235{
236 Attendee *a; 236 Attendee *a;
237 237
238 if (mReadOnly) return; 238 if (mReadOnly) return;
239 for (a = mAttendees.first(); a; a = mAttendees.next()) 239 for (a = mAttendees.first(); a; a = mAttendees.next())
240 if (a->getName() == n) { 240 if (a->getName() == n) {
241 mAttendees.remove(); 241 mAttendees.remove();
242 break; 242 break;
243 } 243 }
244} 244}
245#endif 245#endif
246 246
247void IncidenceBase::clearAttendees() 247void IncidenceBase::clearAttendees()
248{ 248{
249 if (mReadOnly) return; 249 if (mReadOnly) return;
250 mAttendees.clear(); 250 mAttendees.clear();
251} 251}
252 252
253#if 0 253#if 0
254Attendee *IncidenceBase::getAttendee(const char *n) const 254Attendee *IncidenceBase::getAttendee(const char *n) const
255{ 255{
256 QPtrListIterator<Attendee> qli(mAttendees); 256 QPtrListIterator<Attendee> qli(mAttendees);
257 257
258 qli.toFirst(); 258 qli.toFirst();
259 while (qli) { 259 while (qli) {
260 if (qli.current()->getName() == n) 260 if (qli.current()->getName() == n)
261 return qli.current(); 261 return qli.current();
262 ++qli; 262 ++qli;
263 } 263 }
264 return 0L; 264 return 0L;
265} 265}
266#endif 266#endif
267 267
268Attendee *IncidenceBase::attendeeByMail(const QString &email) 268Attendee *IncidenceBase::attendeeByMail(const QString &email)
269{ 269{
270 QPtrListIterator<Attendee> qli(mAttendees); 270 QPtrListIterator<Attendee> qli(mAttendees);
271 271
272 qli.toFirst(); 272 qli.toFirst();
273 while (qli) { 273 while (qli) {
274 if (qli.current()->email().lower() == email.lower()) 274 if (qli.current()->email().lower() == email.lower())
275 return qli.current(); 275 return qli.current();
276 ++qli; 276 ++qli;
277 } 277 }
278 return 0L; 278 return 0L;
279} 279}
280 280
281Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 281Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
282{ 282{
283 QPtrListIterator<Attendee> qli(mAttendees); 283 QPtrListIterator<Attendee> qli(mAttendees);
284 284
285 QStringList mails = emails; 285 QStringList mails = emails;
286 if (!email.isEmpty()) { 286 if (!email.isEmpty()) {
287 mails.append(email); 287 mails.append(email);
288 } 288 }
289 qli.toFirst(); 289 qli.toFirst();
290 while (qli) { 290 while (qli) {
291 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 291 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
292 if (qli.current()->email().lower() == (*it).lower()) 292 if (qli.current()->email().lower() == (*it).lower())
293 return qli.current(); 293 return qli.current();
294 } 294 }
295 295
296 ++qli; 296 ++qli;
297 } 297 }
298 return 0L; 298 return 0L;
299} 299}
300 300
301void IncidenceBase::setDuration(int seconds) 301void IncidenceBase::setDuration(int seconds)
302{ 302{
303 mDuration = seconds; 303 mDuration = seconds;
304 setHasDuration(true); 304 setHasDuration(true);
305} 305}
306 306
307int IncidenceBase::duration() const 307int IncidenceBase::duration() const
308{ 308{
309 return mDuration; 309 return mDuration;
310} 310}
311 311
312void IncidenceBase::setHasDuration(bool b) 312void IncidenceBase::setHasDuration(bool b)
313{ 313{
314 mHasDuration = b; 314 mHasDuration = b;
315} 315}
316 316
317bool IncidenceBase::hasDuration() const 317bool IncidenceBase::hasDuration() const
318{ 318{
319 return mHasDuration; 319 return mHasDuration;
320} 320}
321 321
322void IncidenceBase::setSyncStatus(int stat) 322void IncidenceBase::setSyncStatus(int stat)
323{ 323{
324 if (mReadOnly) return; 324 if (mReadOnly) return;
325 mSyncStatus = stat; 325 mSyncStatus = stat;
326} 326}
327 327
328int IncidenceBase::syncStatus() const 328int IncidenceBase::syncStatus() const
329{ 329{
330 return mSyncStatus; 330 return mSyncStatus;
331} 331}
332 332
333void IncidenceBase::setPilotId( int id ) 333void IncidenceBase::setPilotId( int id )
334{ 334{
335 if (mReadOnly) return; 335 if (mReadOnly) return;
336 mPilotId = id; 336 mPilotId = id;
337} 337}
338 338
339int IncidenceBase::pilotId() const 339int IncidenceBase::pilotId() const
340{ 340{
341 return mPilotId; 341 return mPilotId;
342} 342}
343 343
344int IncidenceBase::tempSyncStat() const 344int IncidenceBase::tempSyncStat() const
345{ 345{
346 return mTempSyncStat; 346 return mTempSyncStat;
347} 347}
348void IncidenceBase::setTempSyncStat( int id ) 348void IncidenceBase::setTempSyncStat( int id )
349{ 349{
350 if (mReadOnly) return; 350 if (mReadOnly) return;
351 mTempSyncStat = id; 351 mTempSyncStat = id;
352} 352}
353 353
354void IncidenceBase::removeID(const QString &prof) 354void IncidenceBase::removeID(const QString &prof)
355{ 355{
356 mExternalId = KIdManager::removeId ( mExternalId, prof); 356 if ( prof.isEmpty() )
357 mExternalId = ":";
358 else
359 mExternalId = KIdManager::removeId ( mExternalId, prof);
357 360
358} 361}
359void IncidenceBase::setID( const QString & prof , const QString & id ) 362void IncidenceBase::setID( const QString & prof , const QString & id )
360{ 363{
361 mExternalId = KIdManager::setId ( mExternalId, prof, id ); 364 mExternalId = KIdManager::setId ( mExternalId, prof, id );
362} 365}
363QString IncidenceBase::getID( const QString & prof) 366QString IncidenceBase::getID( const QString & prof)
364{ 367{
365 return KIdManager::getId ( mExternalId, prof ); 368 return KIdManager::getId ( mExternalId, prof );
366} 369}
367 370
368// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: 371// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
369// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 372// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
370void IncidenceBase::setCsum( const QString & prof , const QString & id ) 373void IncidenceBase::setCsum( const QString & prof , const QString & id )
371{ 374{
372 mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); 375 mExternalId = KIdManager::setCsum ( mExternalId, prof, id );
373} 376}
374QString IncidenceBase::getCsum( const QString & prof) 377QString IncidenceBase::getCsum( const QString & prof)
375{ 378{
376 return KIdManager::getCsum ( mExternalId, prof ); 379 return KIdManager::getCsum ( mExternalId, prof );
377} 380}
378 381
379void IncidenceBase::setIDStr( const QString & s ) 382void IncidenceBase::setIDStr( const QString & s )
380{ 383{
381 if (mReadOnly) return; 384 if (mReadOnly) return;
382 mExternalId = s; 385 mExternalId = s;
383} 386}
384 387
385QString IncidenceBase::IDStr() const 388QString IncidenceBase::IDStr() const
386{ 389{
387 return mExternalId ; 390 return mExternalId ;
388} 391}
389void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 392void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
390{ 393{
391 if( !mObservers.contains(observer) ) mObservers.append( observer ); 394 if( !mObservers.contains(observer) ) mObservers.append( observer );
392} 395}
393 396
394void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 397void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
395{ 398{
396 mObservers.remove( observer ); 399 mObservers.remove( observer );
397} 400}
398 401
399void IncidenceBase::updated() 402void IncidenceBase::updated()
400{ 403{
401 QPtrListIterator<Observer> it(mObservers); 404 QPtrListIterator<Observer> it(mObservers);
402 while( it.current() ) { 405 while( it.current() ) {
403 Observer *o = it.current(); 406 Observer *o = it.current();
404 ++it; 407 ++it;
405 o->incidenceUpdated( this ); 408 o->incidenceUpdated( this );
406 } 409 }
407} 410}
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 4390a06..feb184b 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,1223 +1,1261 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <qbuttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52 52
53#include <klocale.h> 53#include <klocale.h>
54#include <kglobal.h> 54#include <kglobal.h>
55#include <kconfig.h> 55#include <kconfig.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57 57
58KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 58KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
59 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 59 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
60{ 60{
61 mServerSocket = 0; 61 mServerSocket = 0;
62 bar = new QProgressBar ( 1, 0 ); 62 bar = new QProgressBar ( 1, 0 );
63 bar->setCaption (""); 63 bar->setCaption ("");
64 64
65 int w = 300; 65 int w = 300;
66 if ( QApplication::desktop()->width() < 320 ) 66 if ( QApplication::desktop()->width() < 320 )
67 w = 220; 67 w = 220;
68 int h = bar->sizeHint().height() ; 68 int h = bar->sizeHint().height() ;
69 int dw = QApplication::desktop()->width(); 69 int dw = QApplication::desktop()->width();
70 int dh = QApplication::desktop()->height(); 70 int dh = QApplication::desktop()->height();
71 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 71 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
72 if ( mPrefs->mPassiveSyncAutoStart ) 72 if ( mPrefs->mPassiveSyncAutoStart )
73 enableQuick( false ); 73 enableQuick( false );
74 74
75} 75}
76 76
77KSyncManager::~KSyncManager() 77KSyncManager::~KSyncManager()
78{ 78{
79 delete bar; 79 delete bar;
80} 80}
81 81
82 82
83void KSyncManager::fillSyncMenu() 83void KSyncManager::fillSyncMenu()
84{ 84{
85 if ( mSyncMenu->count() ) 85 if ( mSyncMenu->count() )
86 mSyncMenu->clear(); 86 mSyncMenu->clear();
87 87
88 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 88 mSyncMenu->insertItem( i18n("Configure..."), 0 );
89 mSyncMenu->insertSeparator(); 89 mSyncMenu->insertSeparator();
90 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
91 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
92 clearMenu->insertItem( i18n("For all profiles"), 1 );
93 clearMenu->insertSeparator();
94 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
95 mSyncMenu->insertSeparator();
90 if ( mServerSocket == 0 ) { 96 if ( mServerSocket == 0 ) {
91 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 97 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
92 } else { 98 } else {
93 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 99 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
94 } 100 }
95 mSyncMenu->insertSeparator(); 101 mSyncMenu->insertSeparator();
96 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 102 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
97 mSyncMenu->insertSeparator(); 103 mSyncMenu->insertSeparator();
98
99 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 104 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
100 config.setGroup("General"); 105 config.setGroup("General");
101 QStringList prof = config.readListEntry("SyncProfileNames"); 106 QStringList prof = config.readListEntry("SyncProfileNames");
102 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 107 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
103 if ( prof.count() < 2 ) { 108 if ( prof.count() < 2 ) {
104 prof.clear(); 109 prof.clear();
105 QString externalName; 110 QString externalName;
106#ifdef DESKTOP_VERSION 111#ifdef DESKTOP_VERSION
107#ifdef _WIN32_ 112#ifdef _WIN32_
108 externalName = "OutLook(not_implemented)"; 113 externalName = "OutLook(not_implemented)";
109#else 114#else
110 externalName = "KDE_Desktop"; 115 externalName = "KDE_Desktop";
111#endif 116#endif
112#else 117#else
113 externalName = "Sharp_DTM"; 118 externalName = "Sharp_DTM";
114#endif 119#endif
115 prof << externalName; 120 prof << externalName;
116 prof << i18n("Local_file"); 121 prof << i18n("Local_file");
117 prof << i18n("Last_file"); 122 prof << i18n("Last_file");
118 KSyncProfile* temp = new KSyncProfile (); 123 KSyncProfile* temp = new KSyncProfile ();
119 temp->setName( prof[0] ); 124 temp->setName( prof[0] );
120 temp->writeConfig(&config); 125 temp->writeConfig(&config);
121 temp->setName( prof[1] ); 126 temp->setName( prof[1] );
122 temp->writeConfig(&config); 127 temp->writeConfig(&config);
123 temp->setName( prof[2] ); 128 temp->setName( prof[2] );
124 temp->writeConfig(&config); 129 temp->writeConfig(&config);
125 config.setGroup("General"); 130 config.setGroup("General");
126 config.writeEntry("SyncProfileNames",prof); 131 config.writeEntry("SyncProfileNames",prof);
127 config.writeEntry("ExternSyncProfiles",externalName); 132 config.writeEntry("ExternSyncProfiles",externalName);
128 config.sync(); 133 config.sync();
129 delete temp; 134 delete temp;
130 } 135 }
131 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 136 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
132 mSyncProfileNames = prof; 137 mSyncProfileNames = prof;
133 unsigned int i; 138 unsigned int i;
134 for ( i = 0; i < prof.count(); ++i ) { 139 for ( i = 0; i < prof.count(); ++i ) {
135 mSyncMenu->insertItem( prof[i], 1000+i ); 140 mSyncMenu->insertItem( prof[i], 1000+i );
141 clearMenu->insertItem( prof[i], 1000+i );
136 if ( i == 2 ) 142 if ( i == 2 )
137 mSyncMenu->insertSeparator(); 143 mSyncMenu->insertSeparator();
138 } 144 }
139 QDir app_dir; 145 QDir app_dir;
140 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 146 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
141 if ( mTargetApp == PWMPI) { 147 if ( mTargetApp == PWMPI) {
142 mSyncMenu->removeItem( 1000 ); 148 mSyncMenu->removeItem( 1000 );
149 clearMenu->removeItem( 1000 );
143 } 150 }
144#ifndef DESKTOP_VERSION 151#ifndef DESKTOP_VERSION
145 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 152 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
146 mSyncMenu->removeItem( 1000 ); 153 mSyncMenu->removeItem( 1000 );
154 clearMenu->removeItem( 1000 );
147 } 155 }
148#endif 156#endif
149 mSyncMenu->removeItem( 1002 ); 157 mSyncMenu->removeItem( 1002 );
158 clearMenu->removeItem( 1002 );
150} 159}
160void KSyncManager::slotClearMenu( int action )
161{
162 QString syncDevice;
163 if ( action > 999 ) {
164 syncDevice = mSyncProfileNames[action - 1000] ;
165 }
151 166
167
168
169 int result = 0;
170 QString sd;
171 if ( syncDevice.isEmpty() )
172 sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
173 else
174 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
175
176 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
177 0, 1 );
178 if ( result )
179 return;
180 mImplementation->removeSyncInfo( syncDevice );
181}
152void KSyncManager::slotSyncMenu( int action ) 182void KSyncManager::slotSyncMenu( int action )
153{ 183{
154 qDebug("syncaction %d ", action); 184 qDebug("syncaction %d ", action);
185 if ( action == 5000 )
186 return;
155 if ( action == 0 ) { 187 if ( action == 0 ) {
156 188
157 // seems to be a Qt2 event handling bug 189 // seems to be a Qt2 event handling bug
158 // syncmenu.clear causes a segfault at first time 190 // syncmenu.clear causes a segfault at first time
159 // when we call it after the main event loop, it is ok 191 // when we call it after the main event loop, it is ok
160 // same behaviour when calling OM/Pi via QCOP for the first time 192 // same behaviour when calling OM/Pi via QCOP for the first time
161 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 193 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
162 //confSync(); 194 //confSync();
163 195
164 return; 196 return;
165 } 197 }
166 if ( action == 1 ) { 198 if ( action == 1 ) {
167 multiSync( true ); 199 multiSync( true );
168 return; 200 return;
169 } 201 }
170 if ( action == 2 ) { 202 if ( action == 2 ) {
171 enableQuick(); 203 enableQuick();
172 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 204 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
173 return; 205 return;
174 } 206 }
175 if ( action == 3 ) { 207 if ( action == 3 ) {
176 delete mServerSocket; 208 delete mServerSocket;
177 mServerSocket = 0; 209 mServerSocket = 0;
178 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 210 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
179 return; 211 return;
180 } 212 }
181 213
182 if (blockSave()) 214 if (blockSave())
183 return; 215 return;
184 216
185 setBlockSave(true); 217 setBlockSave(true);
186 bool silent = false; 218 bool silent = false;
187 if ( action == 999 ) { 219 if ( action == 999 ) {
188 //special mode for silent syncing 220 //special mode for silent syncing
189 action = 1000; 221 action = 1000;
190 silent = true; 222 silent = true;
191 } 223 }
192 224
193 mCurrentSyncProfile = action - 1000 ; 225 mCurrentSyncProfile = action - 1000 ;
194 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 226 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
195 mCurrentSyncName = mLocalMachineName ; 227 mCurrentSyncName = mLocalMachineName ;
196 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 228 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
197 KSyncProfile* temp = new KSyncProfile (); 229 KSyncProfile* temp = new KSyncProfile ();
198 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 230 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
199 temp->readConfig(&config); 231 temp->readConfig(&config);
200 if (silent) { 232 if (silent) {
201 mAskForPreferences = false; 233 mAskForPreferences = false;
202 mShowSyncSummary = false; 234 mShowSyncSummary = false;
203 mWriteBackFile = true; 235 mWriteBackFile = true;
204 mSyncAlgoPrefs = 2;// take newest 236 mSyncAlgoPrefs = 2;// take newest
205 } 237 }
206 else { 238 else {
207 mAskForPreferences = temp->getAskForPreferences(); 239 mAskForPreferences = temp->getAskForPreferences();
208 mShowSyncSummary = temp->getShowSummaryAfterSync(); 240 mShowSyncSummary = temp->getShowSummaryAfterSync();
209 mWriteBackFile = temp->getWriteBackFile(); 241 mWriteBackFile = temp->getWriteBackFile();
210 mSyncAlgoPrefs = temp->getSyncPrefs(); 242 mSyncAlgoPrefs = temp->getSyncPrefs();
211 } 243 }
212 mWriteBackExistingOnly = temp->getWriteBackExisting(); 244 mWriteBackExistingOnly = temp->getWriteBackExisting();
213 mIsKapiFile = temp->getIsKapiFile(); 245 mIsKapiFile = temp->getIsKapiFile();
214 mWriteBackInFuture = 0; 246 mWriteBackInFuture = 0;
215 if ( temp->getWriteBackFuture() ) 247 if ( temp->getWriteBackFuture() )
216 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 248 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
217 249
218 if ( action == 1000 ) { 250 if ( action == 1000 ) {
219#ifdef DESKTOP_VERSION 251#ifdef DESKTOP_VERSION
220 syncKDE(); 252 syncKDE();
221#else 253#else
222 syncSharp(); 254 syncSharp();
223#endif 255#endif
224 256
225 } else if ( action == 1001 ) { 257 } else if ( action == 1001 ) {
226 syncLocalFile(); 258 syncLocalFile();
227 259
228 } else if ( action == 1002 ) { 260 } else if ( action == 1002 ) {
229 mWriteBackFile = false; 261 mWriteBackFile = false;
230 mAskForPreferences = false; 262 mAskForPreferences = false;
231 mShowSyncSummary = false; 263 mShowSyncSummary = false;
232 mSyncAlgoPrefs = 3; 264 mSyncAlgoPrefs = 3;
233 quickSyncLocalFile(); 265 quickSyncLocalFile();
234 266
235 } else if ( action >= 1003 ) { 267 } else if ( action >= 1003 ) {
236 if ( temp->getIsLocalFileSync() ) { 268 if ( temp->getIsLocalFileSync() ) {
237 switch(mTargetApp) 269 switch(mTargetApp)
238 { 270 {
239 case (KAPI): 271 case (KAPI):
240 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 272 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
241 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 273 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
242 break; 274 break;
243 case (KOPI): 275 case (KOPI):
244 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 276 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
245 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 277 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
246 break; 278 break;
247 case (PWMPI): 279 case (PWMPI):
248 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 280 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
249 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 281 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
250 break; 282 break;
251 default: 283 default:
252 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 284 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
253 break; 285 break;
254 286
255 } 287 }
256 } else { 288 } else {
257 if ( temp->getIsPhoneSync() ) { 289 if ( temp->getIsPhoneSync() ) {
258 mPhoneDevice = temp->getPhoneDevice( ) ; 290 mPhoneDevice = temp->getPhoneDevice( ) ;
259 mPhoneConnection = temp->getPhoneConnection( ); 291 mPhoneConnection = temp->getPhoneConnection( );
260 mPhoneModel = temp->getPhoneModel( ); 292 mPhoneModel = temp->getPhoneModel( );
261 syncPhone(); 293 syncPhone();
262 } else if ( temp->getIsPiSync() ) { 294 } else if ( temp->getIsPiSync() ) {
263 if ( mTargetApp == KAPI ) { 295 if ( mTargetApp == KAPI ) {
264 mPassWordPiSync = temp->getRemotePwAB(); 296 mPassWordPiSync = temp->getRemotePwAB();
265 mActiveSyncPort = temp->getRemotePortAB(); 297 mActiveSyncPort = temp->getRemotePortAB();
266 mActiveSyncIP = temp->getRemoteIPAB(); 298 mActiveSyncIP = temp->getRemoteIPAB();
267 } else if ( mTargetApp == KOPI ) { 299 } else if ( mTargetApp == KOPI ) {
268 mPassWordPiSync = temp->getRemotePw(); 300 mPassWordPiSync = temp->getRemotePw();
269 mActiveSyncPort = temp->getRemotePort(); 301 mActiveSyncPort = temp->getRemotePort();
270 mActiveSyncIP = temp->getRemoteIP(); 302 mActiveSyncIP = temp->getRemoteIP();
271 } else { 303 } else {
272 mPassWordPiSync = temp->getRemotePwPWM(); 304 mPassWordPiSync = temp->getRemotePwPWM();
273 mActiveSyncPort = temp->getRemotePortPWM(); 305 mActiveSyncPort = temp->getRemotePortPWM();
274 mActiveSyncIP = temp->getRemoteIPPWM(); 306 mActiveSyncIP = temp->getRemoteIPPWM();
275 } 307 }
276 syncPi(); 308 syncPi();
277 while ( !mPisyncFinished ) { 309 while ( !mPisyncFinished ) {
278 //qDebug("waiting "); 310 //qDebug("waiting ");
279 qApp->processEvents(); 311 qApp->processEvents();
280 } 312 }
281 } else 313 } else
282 syncRemote( temp ); 314 syncRemote( temp );
283 315
284 } 316 }
285 } 317 }
286 delete temp; 318 delete temp;
287 setBlockSave(false); 319 setBlockSave(false);
288} 320}
289 321
290void KSyncManager::enableQuick( bool ask ) 322void KSyncManager::enableQuick( bool ask )
291{ 323{
292 bool autoStart; 324 bool autoStart;
293 bool changed = false; 325 bool changed = false;
294 if ( ask ) { 326 if ( ask ) {
295 QDialog dia ( 0, "input-dialog", true ); 327 QDialog dia ( 0, "input-dialog", true );
296 QLineEdit lab ( &dia ); 328 QLineEdit lab ( &dia );
297 QVBoxLayout lay( &dia ); 329 QVBoxLayout lay( &dia );
298 lab.setText( mPrefs->mPassiveSyncPort ); 330 lab.setText( mPrefs->mPassiveSyncPort );
299 lay.setMargin(7); 331 lay.setMargin(7);
300 lay.setSpacing(7); 332 lay.setSpacing(7);
301 int po = 9197+mTargetApp; 333 int po = 9197+mTargetApp;
302 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 334 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
303 lay.addWidget( &label); 335 lay.addWidget( &label);
304 lay.addWidget( &lab); 336 lay.addWidget( &lab);
305 337
306 QLineEdit lepw ( &dia ); 338 QLineEdit lepw ( &dia );
307 lepw.setText( mPrefs->mPassiveSyncPw ); 339 lepw.setText( mPrefs->mPassiveSyncPw );
308 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 340 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
309 lay.addWidget( &label2); 341 lay.addWidget( &label2);
310 lay.addWidget( &lepw); 342 lay.addWidget( &lepw);
311 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 343 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
312 lay.addWidget( &autostart); 344 lay.addWidget( &autostart);
313 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 345 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
314#ifdef DESKTOP_VERSION 346#ifdef DESKTOP_VERSION
315#ifdef _WIN32_ 347#ifdef _WIN32_
316 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 348 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
317#else 349#else
318 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 350 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
319#endif 351#endif
320 lay.addWidget( &syncdesktop); 352 lay.addWidget( &syncdesktop);
321#else 353#else
322 mPrefs->mPassiveSyncWithDesktop = false; 354 mPrefs->mPassiveSyncWithDesktop = false;
323 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 355 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
324 syncdesktop.hide(); 356 syncdesktop.hide();
325#endif 357#endif
326 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 358 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
327 359
328 dia.setFixedSize( 230,120 ); 360 dia.setFixedSize( 230,120 );
329 dia.setCaption( i18n("Enter port for Pi-Sync") ); 361 dia.setCaption( i18n("Enter port for Pi-Sync") );
330 QPushButton pb ( "OK", &dia); 362 QPushButton pb ( "OK", &dia);
331 lay.addWidget( &pb ); 363 lay.addWidget( &pb );
332 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 364 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
333 dia.show(); 365 dia.show();
334 if ( ! dia.exec() ) 366 if ( ! dia.exec() )
335 return; 367 return;
336 dia.hide(); 368 dia.hide();
337 qApp->processEvents(); 369 qApp->processEvents();
338 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 370 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
339 changed = true; 371 changed = true;
340 mPrefs->mPassiveSyncPw = lepw.text(); 372 mPrefs->mPassiveSyncPw = lepw.text();
341 } 373 }
342 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 374 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
343 mPrefs->mPassiveSyncPort = lab.text(); 375 mPrefs->mPassiveSyncPort = lab.text();
344 changed = true; 376 changed = true;
345 } 377 }
346 autoStart = autostart.isChecked(); 378 autoStart = autostart.isChecked();
347 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 379 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
348 changed = true; 380 changed = true;
349 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 381 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
350 } 382 }
351 } 383 }
352 else 384 else
353 autoStart = mPrefs->mPassiveSyncAutoStart; 385 autoStart = mPrefs->mPassiveSyncAutoStart;
354 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 386 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
355 changed = true; 387 changed = true;
356 bool ok; 388 bool ok;
357 mPrefs->mPassiveSyncAutoStart = false; 389 mPrefs->mPassiveSyncAutoStart = false;
358 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 390 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
359 if ( ! ok ) { 391 if ( ! ok ) {
360 KMessageBox::information( 0, i18n("No valid port")); 392 KMessageBox::information( 0, i18n("No valid port"));
361 return; 393 return;
362 } 394 }
363 //qDebug("port %d ", port); 395 //qDebug("port %d ", port);
364 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 396 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
365 mServerSocket->setFileName( defaultFileName() ); 397 mServerSocket->setFileName( defaultFileName() );
366 //qDebug("connected "); 398 //qDebug("connected ");
367 if ( !mServerSocket->ok() ) { 399 if ( !mServerSocket->ok() ) {
368 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 400 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
369 delete mServerSocket; 401 delete mServerSocket;
370 mServerSocket = 0; 402 mServerSocket = 0;
371 return; 403 return;
372 } 404 }
373 mPrefs->mPassiveSyncAutoStart = autoStart; 405 mPrefs->mPassiveSyncAutoStart = autoStart;
374 if ( changed ) { 406 if ( changed ) {
375 mPrefs->writeConfig(); 407 mPrefs->writeConfig();
376 } 408 }
377 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 409 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
378 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 410 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
379} 411}
380 412
381void KSyncManager::syncLocalFile() 413void KSyncManager::syncLocalFile()
382{ 414{
383 415
384 QString fn =mPrefs->mLastSyncedLocalFile; 416 QString fn =mPrefs->mLastSyncedLocalFile;
385 QString ext; 417 QString ext;
386 418
387 switch(mTargetApp) 419 switch(mTargetApp)
388 { 420 {
389 case (KAPI): 421 case (KAPI):
390 ext = "(*.vcf)"; 422 ext = "(*.vcf)";
391 break; 423 break;
392 case (KOPI): 424 case (KOPI):
393 ext = "(*.ics/*.vcs)"; 425 ext = "(*.ics/*.vcs)";
394 break; 426 break;
395 case (PWMPI): 427 case (PWMPI):
396 ext = "(*.pwm)"; 428 ext = "(*.pwm)";
397 break; 429 break;
398 default: 430 default:
399 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 431 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
400 break; 432 break;
401 433
402 } 434 }
403 435
404 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 436 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
405 if ( fn == "" ) 437 if ( fn == "" )
406 return; 438 return;
407 if ( syncWithFile( fn, false ) ) { 439 if ( syncWithFile( fn, false ) ) {
408 qDebug("syncLocalFile() successful "); 440 qDebug("syncLocalFile() successful ");
409 } 441 }
410 442
411} 443}
412 444
413bool KSyncManager::syncWithFile( QString fn , bool quick ) 445bool KSyncManager::syncWithFile( QString fn , bool quick )
414{ 446{
415 bool ret = false; 447 bool ret = false;
416 QFileInfo info; 448 QFileInfo info;
417 info.setFile( fn ); 449 info.setFile( fn );
418 QString mess; 450 QString mess;
419 bool loadbup = true; 451 bool loadbup = true;
420 if ( !info. exists() ) { 452 if ( !info. exists() ) {
421 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 453 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
422 int result = QMessageBox::warning( mParent, i18n("Warning!"), 454 int result = QMessageBox::warning( mParent, i18n("Warning!"),
423 mess ); 455 mess );
424 return ret; 456 return ret;
425 } 457 }
426 int result = 0; 458 int result = 0;
427 if ( !quick ) { 459 if ( !quick ) {
428 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 460 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
429 result = QMessageBox::warning( mParent, i18n("Warning!"), 461 result = QMessageBox::warning( mParent, i18n("Warning!"),
430 mess, 462 mess,
431 i18n("Sync"), i18n("Cancel"), 0, 463 i18n("Sync"), i18n("Cancel"), 0,
432 0, 1 ); 464 0, 1 );
433 if ( result ) 465 if ( result )
434 return false; 466 return false;
435 } 467 }
436 if ( mAskForPreferences ) 468 if ( mAskForPreferences )
437 if ( !edit_sync_options()) { 469 if ( !edit_sync_options()) {
438 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 470 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
439 return false; 471 return false;
440 } 472 }
441 if ( result == 0 ) { 473 if ( result == 0 ) {
442 //qDebug("Now sycing ... "); 474 //qDebug("Now sycing ... ");
443 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 475 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
444 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 476 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
445 else 477 else
446 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 478 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
447 if ( ! quick ) 479 if ( ! quick )
448 mPrefs->mLastSyncedLocalFile = fn; 480 mPrefs->mLastSyncedLocalFile = fn;
449 } 481 }
450 return ret; 482 return ret;
451} 483}
452 484
453void KSyncManager::quickSyncLocalFile() 485void KSyncManager::quickSyncLocalFile()
454{ 486{
455 487
456 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 488 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
457 qDebug("quick syncLocalFile() successful "); 489 qDebug("quick syncLocalFile() successful ");
458 490
459 } 491 }
460} 492}
461 493
462void KSyncManager::multiSync( bool askforPrefs ) 494void KSyncManager::multiSync( bool askforPrefs )
463{ 495{
464 if (blockSave()) 496 if (blockSave())
465 return; 497 return;
466 setBlockSave(true); 498 setBlockSave(true);
467 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 499 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
468 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 500 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
469 question, 501 question,
470 i18n("Yes"), i18n("No"), 502 i18n("Yes"), i18n("No"),
471 0, 0 ) != 0 ) { 503 0, 0 ) != 0 ) {
472 setBlockSave(false); 504 setBlockSave(false);
473 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 505 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
474 return; 506 return;
475 } 507 }
476 mCurrentSyncDevice = i18n("Multiple profiles") ; 508 mCurrentSyncDevice = i18n("Multiple profiles") ;
477 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 509 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
478 if ( askforPrefs ) { 510 if ( askforPrefs ) {
479 if ( !edit_sync_options()) { 511 if ( !edit_sync_options()) {
480 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 512 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
481 return; 513 return;
482 } 514 }
483 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 515 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
484 } 516 }
485 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 517 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
486 qApp->processEvents(); 518 qApp->processEvents();
487 int num = ringSync() ; 519 int num = ringSync() ;
488 if ( num > 1 ) 520 if ( num > 1 )
489 ringSync(); 521 ringSync();
490 setBlockSave(false); 522 setBlockSave(false);
491 if ( num ) 523 if ( num )
492 emit save(); 524 emit save();
493 if ( num ) 525 if ( num )
494 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 526 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
495 else 527 else
496 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 528 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
497 return; 529 return;
498} 530}
499 531
500int KSyncManager::ringSync() 532int KSyncManager::ringSync()
501{ 533{
502 int syncedProfiles = 0; 534 int syncedProfiles = 0;
503 unsigned int i; 535 unsigned int i;
504 QTime timer; 536 QTime timer;
505 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 537 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
506 QStringList syncProfileNames = mSyncProfileNames; 538 QStringList syncProfileNames = mSyncProfileNames;
507 KSyncProfile* temp = new KSyncProfile (); 539 KSyncProfile* temp = new KSyncProfile ();
508 mAskForPreferences = false; 540 mAskForPreferences = false;
509 for ( i = 0; i < syncProfileNames.count(); ++i ) { 541 for ( i = 0; i < syncProfileNames.count(); ++i ) {
510 mCurrentSyncProfile = i; 542 mCurrentSyncProfile = i;
511 temp->setName(syncProfileNames[mCurrentSyncProfile]); 543 temp->setName(syncProfileNames[mCurrentSyncProfile]);
512 temp->readConfig(&config); 544 temp->readConfig(&config);
513 545
514 bool includeInRingSync; 546 bool includeInRingSync;
515 switch(mTargetApp) 547 switch(mTargetApp)
516 { 548 {
517 case (KAPI): 549 case (KAPI):
518 includeInRingSync = temp->getIncludeInRingSyncAB(); 550 includeInRingSync = temp->getIncludeInRingSyncAB();
519 break; 551 break;
520 case (KOPI): 552 case (KOPI):
521 includeInRingSync = temp->getIncludeInRingSync(); 553 includeInRingSync = temp->getIncludeInRingSync();
522 break; 554 break;
523 case (PWMPI): 555 case (PWMPI):
524 includeInRingSync = temp->getIncludeInRingSyncPWM(); 556 includeInRingSync = temp->getIncludeInRingSyncPWM();
525 break; 557 break;
526 default: 558 default:
527 qDebug("KSyncManager::ringSync: invalid apptype selected"); 559 qDebug("KSyncManager::ringSync: invalid apptype selected");
528 break; 560 break;
529 561
530 } 562 }
531 563
532 564
533 if ( includeInRingSync && ( i < 1 || i > 2 )) { 565 if ( includeInRingSync && ( i < 1 || i > 2 )) {
534 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 566 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
535 ++syncedProfiles; 567 ++syncedProfiles;
536 // mAskForPreferences = temp->getAskForPreferences(); 568 // mAskForPreferences = temp->getAskForPreferences();
537 mWriteBackFile = temp->getWriteBackFile(); 569 mWriteBackFile = temp->getWriteBackFile();
538 mWriteBackExistingOnly = temp->getWriteBackExisting(); 570 mWriteBackExistingOnly = temp->getWriteBackExisting();
539 mWriteBackInFuture = 0; 571 mWriteBackInFuture = 0;
540 if ( temp->getWriteBackFuture() ) 572 if ( temp->getWriteBackFuture() )
541 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 573 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
542 mShowSyncSummary = false; 574 mShowSyncSummary = false;
543 mCurrentSyncDevice = syncProfileNames[i] ; 575 mCurrentSyncDevice = syncProfileNames[i] ;
544 mCurrentSyncName = mLocalMachineName; 576 mCurrentSyncName = mLocalMachineName;
545 if ( i == 0 ) { 577 if ( i == 0 ) {
546#ifdef DESKTOP_VERSION 578#ifdef DESKTOP_VERSION
547 syncKDE(); 579 syncKDE();
548#else 580#else
549 syncSharp(); 581 syncSharp();
550#endif 582#endif
551 } else { 583 } else {
552 if ( temp->getIsLocalFileSync() ) { 584 if ( temp->getIsLocalFileSync() ) {
553 switch(mTargetApp) 585 switch(mTargetApp)
554 { 586 {
555 case (KAPI): 587 case (KAPI):
556 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 588 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
557 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 589 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
558 break; 590 break;
559 case (KOPI): 591 case (KOPI):
560 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 592 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
561 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 593 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
562 break; 594 break;
563 case (PWMPI): 595 case (PWMPI):
564 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 596 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
565 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 597 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
566 break; 598 break;
567 default: 599 default:
568 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 600 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
569 break; 601 break;
570 } 602 }
571 } else { 603 } else {
572 if ( temp->getIsPhoneSync() ) { 604 if ( temp->getIsPhoneSync() ) {
573 mPhoneDevice = temp->getPhoneDevice( ) ; 605 mPhoneDevice = temp->getPhoneDevice( ) ;
574 mPhoneConnection = temp->getPhoneConnection( ); 606 mPhoneConnection = temp->getPhoneConnection( );
575 mPhoneModel = temp->getPhoneModel( ); 607 mPhoneModel = temp->getPhoneModel( );
576 syncPhone(); 608 syncPhone();
577 } else if ( temp->getIsPiSync() ) { 609 } else if ( temp->getIsPiSync() ) {
578 if ( mTargetApp == KAPI ) { 610 if ( mTargetApp == KAPI ) {
579 mPassWordPiSync = temp->getRemotePwAB(); 611 mPassWordPiSync = temp->getRemotePwAB();
580 mActiveSyncPort = temp->getRemotePortAB(); 612 mActiveSyncPort = temp->getRemotePortAB();
581 mActiveSyncIP = temp->getRemoteIPAB(); 613 mActiveSyncIP = temp->getRemoteIPAB();
582 } else if ( mTargetApp == KOPI ) { 614 } else if ( mTargetApp == KOPI ) {
583 mPassWordPiSync = temp->getRemotePw(); 615 mPassWordPiSync = temp->getRemotePw();
584 mActiveSyncPort = temp->getRemotePort(); 616 mActiveSyncPort = temp->getRemotePort();
585 mActiveSyncIP = temp->getRemoteIP(); 617 mActiveSyncIP = temp->getRemoteIP();
586 } else { 618 } else {
587 mPassWordPiSync = temp->getRemotePwPWM(); 619 mPassWordPiSync = temp->getRemotePwPWM();
588 mActiveSyncPort = temp->getRemotePortPWM(); 620 mActiveSyncPort = temp->getRemotePortPWM();
589 mActiveSyncIP = temp->getRemoteIPPWM(); 621 mActiveSyncIP = temp->getRemoteIPPWM();
590 } 622 }
591 syncPi(); 623 syncPi();
592 while ( !mPisyncFinished ) { 624 while ( !mPisyncFinished ) {
593 //qDebug("waiting "); 625 //qDebug("waiting ");
594 qApp->processEvents(); 626 qApp->processEvents();
595 } 627 }
596 timer.start(); 628 timer.start();
597 while ( timer.elapsed () < 2000 ) { 629 while ( timer.elapsed () < 2000 ) {
598 qApp->processEvents(); 630 qApp->processEvents();
599 } 631 }
600 } else 632 } else
601 syncRemote( temp, false ); 633 syncRemote( temp, false );
602 634
603 } 635 }
604 } 636 }
605 timer.start(); 637 timer.start();
606 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 638 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
607 while ( timer.elapsed () < 2000 ) { 639 while ( timer.elapsed () < 2000 ) {
608 qApp->processEvents(); 640 qApp->processEvents();
609#ifndef _WIN32_ 641#ifndef _WIN32_
610 sleep (1); 642 sleep (1);
611#endif 643#endif
612 } 644 }
613 645
614 } 646 }
615 647
616 } 648 }
617 delete temp; 649 delete temp;
618 return syncedProfiles; 650 return syncedProfiles;
619} 651}
620 652
621void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 653void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
622{ 654{
623 QString question; 655 QString question;
624 if ( ask ) { 656 if ( ask ) {
625 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 657 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
626 if ( QMessageBox::information( mParent, i18n("Sync"), 658 if ( QMessageBox::information( mParent, i18n("Sync"),
627 question, 659 question,
628 i18n("Yes"), i18n("No"), 660 i18n("Yes"), i18n("No"),
629 0, 0 ) != 0 ) 661 0, 0 ) != 0 )
630 return; 662 return;
631 } 663 }
632 664
633 QString preCommand; 665 QString preCommand;
634 QString localTempFile; 666 QString localTempFile;
635 QString postCommand; 667 QString postCommand;
636 668
637 switch(mTargetApp) 669 switch(mTargetApp)
638 { 670 {
639 case (KAPI): 671 case (KAPI):
640 preCommand = prof->getPreSyncCommandAB(); 672 preCommand = prof->getPreSyncCommandAB();
641 postCommand = prof->getPostSyncCommandAB(); 673 postCommand = prof->getPostSyncCommandAB();
642 localTempFile = prof->getLocalTempFileAB(); 674 localTempFile = prof->getLocalTempFileAB();
643 break; 675 break;
644 case (KOPI): 676 case (KOPI):
645 preCommand = prof->getPreSyncCommand(); 677 preCommand = prof->getPreSyncCommand();
646 postCommand = prof->getPostSyncCommand(); 678 postCommand = prof->getPostSyncCommand();
647 localTempFile = prof->getLocalTempFile(); 679 localTempFile = prof->getLocalTempFile();
648 break; 680 break;
649 case (PWMPI): 681 case (PWMPI):
650 preCommand = prof->getPreSyncCommandPWM(); 682 preCommand = prof->getPreSyncCommandPWM();
651 postCommand = prof->getPostSyncCommandPWM(); 683 postCommand = prof->getPostSyncCommandPWM();
652 localTempFile = prof->getLocalTempFilePWM(); 684 localTempFile = prof->getLocalTempFilePWM();
653 break; 685 break;
654 default: 686 default:
655 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 687 qDebug("KSyncManager::syncRemote: invalid apptype selected");
656 break; 688 break;
657 } 689 }
658 690
659 691
660 int fi; 692 int fi;
661 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 693 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
662 QString pwd = getPassword(); 694 QString pwd = getPassword();
663 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 695 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
664 696
665 } 697 }
666 int maxlen = 30; 698 int maxlen = 30;
667 if ( QApplication::desktop()->width() > 320 ) 699 if ( QApplication::desktop()->width() > 320 )
668 maxlen += 25; 700 maxlen += 25;
669 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 701 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
670 int fileSize = 0; 702 int fileSize = 0;
671 int result = system ( preCommand ); 703 int result = system ( preCommand );
672 // 0 : okay 704 // 0 : okay
673 // 256: no such file or dir 705 // 256: no such file or dir
674 // 706 //
675 qDebug("Sync: Remote copy result(0 = okay): %d ",result ); 707 qDebug("Sync: Remote copy result(0 = okay): %d ",result );
676 if ( result != 0 ) { 708 if ( result != 0 ) {
677 unsigned int len = maxlen; 709 unsigned int len = maxlen;
678 while ( len < preCommand.length() ) { 710 while ( len < preCommand.length() ) {
679 preCommand.insert( len , "\n" ); 711 preCommand.insert( len , "\n" );
680 len += maxlen +2; 712 len += maxlen +2;
681 } 713 }
682 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; 714 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ;
683 QMessageBox::information( mParent, i18n("Sync - ERROR"), 715 QMessageBox::information( mParent, i18n("Sync - ERROR"),
684 question, 716 question,
685 i18n("Okay!")) ; 717 i18n("Okay!")) ;
686 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 718 mParent->topLevelWidget()->setCaption ("KDE-Pim");
687 return; 719 return;
688 } 720 }
689 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 721 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
690 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 722 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
691 723
692 if ( syncWithFile( localTempFile, true ) ) { 724 if ( syncWithFile( localTempFile, true ) ) {
693 725
694 if ( mWriteBackFile ) { 726 if ( mWriteBackFile ) {
695 int fi; 727 int fi;
696 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 728 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
697 QString pwd = getPassword(); 729 QString pwd = getPassword();
698 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 730 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
699 731
700 } 732 }
701 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 733 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
702 result = system ( postCommand ); 734 result = system ( postCommand );
703 qDebug("Sync:Writing back file result: %d ", result); 735 qDebug("Sync:Writing back file result: %d ", result);
704 if ( result != 0 ) { 736 if ( result != 0 ) {
705 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 737 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
706 return; 738 return;
707 } else { 739 } else {
708 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 740 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
709 } 741 }
710 } 742 }
711 } 743 }
712 return; 744 return;
713} 745}
714bool KSyncManager::edit_pisync_options() 746bool KSyncManager::edit_pisync_options()
715{ 747{
716 QDialog dia( mParent, "dia", true ); 748 QDialog dia( mParent, "dia", true );
717 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 749 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
718 QVBoxLayout lay ( &dia ); 750 QVBoxLayout lay ( &dia );
719 lay.setSpacing( 5 ); 751 lay.setSpacing( 5 );
720 lay.setMargin( 3 ); 752 lay.setMargin( 3 );
721 QLabel lab1 ( i18n("Password for remote access:"), &dia); 753 QLabel lab1 ( i18n("Password for remote access:"), &dia);
722 lay.addWidget( &lab1 ); 754 lay.addWidget( &lab1 );
723 QLineEdit le1 (&dia ); 755 QLineEdit le1 (&dia );
724 lay.addWidget( &le1 ); 756 lay.addWidget( &le1 );
725 QLabel lab2 ( i18n("Remote IP address:"), &dia); 757 QLabel lab2 ( i18n("Remote IP address:"), &dia);
726 lay.addWidget( &lab2 ); 758 lay.addWidget( &lab2 );
727 QLineEdit le2 (&dia ); 759 QLineEdit le2 (&dia );
728 lay.addWidget( &le2 ); 760 lay.addWidget( &le2 );
729 QLabel lab3 ( i18n("Remote port number:"), &dia); 761 QLabel lab3 ( i18n("Remote port number:"), &dia);
730 lay.addWidget( &lab3 ); 762 lay.addWidget( &lab3 );
731 QLineEdit le3 (&dia ); 763 QLineEdit le3 (&dia );
732 lay.addWidget( &le3 ); 764 lay.addWidget( &le3 );
733 QPushButton pb ( "OK", &dia); 765 QPushButton pb ( "OK", &dia);
734 lay.addWidget( &pb ); 766 lay.addWidget( &pb );
735 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 767 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
736 le1.setText( mPassWordPiSync ); 768 le1.setText( mPassWordPiSync );
737 le2.setText( mActiveSyncIP ); 769 le2.setText( mActiveSyncIP );
738 le3.setText( mActiveSyncPort ); 770 le3.setText( mActiveSyncPort );
739 if ( dia.exec() ) { 771 if ( dia.exec() ) {
740 mPassWordPiSync = le1.text(); 772 mPassWordPiSync = le1.text();
741 mActiveSyncPort = le3.text(); 773 mActiveSyncPort = le3.text();
742 mActiveSyncIP = le2.text(); 774 mActiveSyncIP = le2.text();
743 return true; 775 return true;
744 } 776 }
745 return false; 777 return false;
746} 778}
747bool KSyncManager::edit_sync_options() 779bool KSyncManager::edit_sync_options()
748{ 780{
749 781
750 QDialog dia( mParent, "dia", true ); 782 QDialog dia( mParent, "dia", true );
751 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 783 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
752 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 784 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
753 QVBoxLayout lay ( &dia ); 785 QVBoxLayout lay ( &dia );
754 lay.setSpacing( 2 ); 786 lay.setSpacing( 2 );
755 lay.setMargin( 3 ); 787 lay.setMargin( 3 );
756 lay.addWidget(&gr); 788 lay.addWidget(&gr);
757 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 789 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
758 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 790 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
759 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 791 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
760 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 792 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
761 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 793 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
762 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 794 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
763 //QRadioButton both( i18n("Take both on conflict"), &gr ); 795 //QRadioButton both( i18n("Take both on conflict"), &gr );
764 QPushButton pb ( "OK", &dia); 796 QPushButton pb ( "OK", &dia);
765 lay.addWidget( &pb ); 797 lay.addWidget( &pb );
766 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 798 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
767 switch ( mSyncAlgoPrefs ) { 799 switch ( mSyncAlgoPrefs ) {
768 case 0: 800 case 0:
769 loc.setChecked( true); 801 loc.setChecked( true);
770 break; 802 break;
771 case 1: 803 case 1:
772 rem.setChecked( true ); 804 rem.setChecked( true );
773 break; 805 break;
774 case 2: 806 case 2:
775 newest.setChecked( true); 807 newest.setChecked( true);
776 break; 808 break;
777 case 3: 809 case 3:
778 ask.setChecked( true); 810 ask.setChecked( true);
779 break; 811 break;
780 case 4: 812 case 4:
781 f_loc.setChecked( true); 813 f_loc.setChecked( true);
782 break; 814 break;
783 case 5: 815 case 5:
784 f_rem.setChecked( true); 816 f_rem.setChecked( true);
785 break; 817 break;
786 case 6: 818 case 6:
787 // both.setChecked( true); 819 // both.setChecked( true);
788 break; 820 break;
789 default: 821 default:
790 break; 822 break;
791 } 823 }
792 if ( dia.exec() ) { 824 if ( dia.exec() ) {
793 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 825 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
794 return true; 826 return true;
795 } 827 }
796 return false; 828 return false;
797} 829}
798 830
799QString KSyncManager::getPassword( ) 831QString KSyncManager::getPassword( )
800{ 832{
801 QString retfile = ""; 833 QString retfile = "";
802 QDialog dia ( mParent, "input-dialog", true ); 834 QDialog dia ( mParent, "input-dialog", true );
803 QLineEdit lab ( &dia ); 835 QLineEdit lab ( &dia );
804 lab.setEchoMode( QLineEdit::Password ); 836 lab.setEchoMode( QLineEdit::Password );
805 QVBoxLayout lay( &dia ); 837 QVBoxLayout lay( &dia );
806 lay.setMargin(7); 838 lay.setMargin(7);
807 lay.setSpacing(7); 839 lay.setSpacing(7);
808 lay.addWidget( &lab); 840 lay.addWidget( &lab);
809 dia.setFixedSize( 230,50 ); 841 dia.setFixedSize( 230,50 );
810 dia.setCaption( i18n("Enter password") ); 842 dia.setCaption( i18n("Enter password") );
811 QPushButton pb ( "OK", &dia); 843 QPushButton pb ( "OK", &dia);
812 lay.addWidget( &pb ); 844 lay.addWidget( &pb );
813 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 845 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
814 dia.show(); 846 dia.show();
815 int res = dia.exec(); 847 int res = dia.exec();
816 if ( res ) 848 if ( res )
817 retfile = lab.text(); 849 retfile = lab.text();
818 dia.hide(); 850 dia.hide();
819 qApp->processEvents(); 851 qApp->processEvents();
820 return retfile; 852 return retfile;
821 853
822} 854}
823 855
824 856
825void KSyncManager::confSync() 857void KSyncManager::confSync()
826{ 858{
827 static KSyncPrefsDialog* sp = 0; 859 static KSyncPrefsDialog* sp = 0;
828 if ( ! sp ) { 860 if ( ! sp ) {
829 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 861 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
830 } 862 }
831 sp->usrReadConfig(); 863 sp->usrReadConfig();
832#ifndef DESKTOP_VERSION 864#ifndef DESKTOP_VERSION
833 sp->showMaximized(); 865 sp->showMaximized();
834#else 866#else
835 sp->show(); 867 sp->show();
836#endif 868#endif
837 sp->exec(); 869 sp->exec();
870 QStringList oldSyncProfileNames = mSyncProfileNames;
838 mSyncProfileNames = sp->getSyncProfileNames(); 871 mSyncProfileNames = sp->getSyncProfileNames();
839 mLocalMachineName = sp->getLocalMachineName (); 872 mLocalMachineName = sp->getLocalMachineName ();
873 int ii;
874 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
875 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
876 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
877 }
840 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 878 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
841} 879}
842void KSyncManager::syncKDE() 880void KSyncManager::syncKDE()
843{ 881{
844 emit save(); 882 emit save();
845 switch(mTargetApp) 883 switch(mTargetApp)
846 { 884 {
847 case (KAPI): 885 case (KAPI):
848 886
849 break; 887 break;
850 case (KOPI): 888 case (KOPI):
851 { 889 {
852#ifdef DESKTOP_VERSION 890#ifdef DESKTOP_VERSION
853 QString command = qApp->applicationDirPath () + "/kdecaldump"; 891 QString command = qApp->applicationDirPath () + "/kdecaldump";
854#else 892#else
855 QString command = "kdecaldump"; 893 QString command = "kdecaldump";
856#endif 894#endif
857 if ( ! QFile::exists ( command ) ) 895 if ( ! QFile::exists ( command ) )
858 command = "kdecaldump"; 896 command = "kdecaldump";
859 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 897 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
860 system ( command.latin1()); 898 system ( command.latin1());
861 if ( syncWithFile( fileName,true ) ) { 899 if ( syncWithFile( fileName,true ) ) {
862 if ( mWriteBackFile ) { 900 if ( mWriteBackFile ) {
863 command += " --read"; 901 command += " --read";
864 system ( command.latin1()); 902 system ( command.latin1());
865 } 903 }
866 } 904 }
867 905
868 } 906 }
869 break; 907 break;
870 case (PWMPI): 908 case (PWMPI):
871 909
872 break; 910 break;
873 default: 911 default:
874 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 912 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
875 break; 913 break;
876 914
877 } 915 }
878} 916}
879 917
880void KSyncManager::syncSharp() 918void KSyncManager::syncSharp()
881{ 919{
882 920
883 if ( ! syncExternalApplication("sharp") ) 921 if ( ! syncExternalApplication("sharp") )
884 qDebug("ERROR sync sharp "); 922 qDebug("ERROR sync sharp ");
885} 923}
886 924
887bool KSyncManager::syncExternalApplication(QString resource) 925bool KSyncManager::syncExternalApplication(QString resource)
888{ 926{
889 927
890 emit save(); 928 emit save();
891 929
892 if ( mAskForPreferences ) 930 if ( mAskForPreferences )
893 if ( !edit_sync_options()) { 931 if ( !edit_sync_options()) {
894 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 932 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
895 return false; 933 return false;
896 } 934 }
897 935
898 qDebug("Sync extern %s", resource.latin1()); 936 qDebug("Sync extern %s", resource.latin1());
899 937
900 bool syncOK = mImplementation->syncExternal(this, resource); 938 bool syncOK = mImplementation->syncExternal(this, resource);
901 939
902 return syncOK; 940 return syncOK;
903 941
904} 942}
905 943
906void KSyncManager::syncPhone() 944void KSyncManager::syncPhone()
907{ 945{
908 946
909 syncExternalApplication("phone"); 947 syncExternalApplication("phone");
910 948
911} 949}
912 950
913void KSyncManager::showProgressBar(int percentage, QString caption, int total) 951void KSyncManager::showProgressBar(int percentage, QString caption, int total)
914{ 952{
915 if (!bar->isVisible()) 953 if (!bar->isVisible())
916 { 954 {
917 bar->setCaption (caption); 955 bar->setCaption (caption);
918 bar->setTotalSteps ( total ) ; 956 bar->setTotalSteps ( total ) ;
919 957
920 bar->show(); 958 bar->show();
921 } 959 }
922 960
923 bar->setProgress( percentage ); 961 bar->setProgress( percentage );
924} 962}
925 963
926void KSyncManager::hideProgressBar() 964void KSyncManager::hideProgressBar()
927{ 965{
928 bar->hide(); 966 bar->hide();
929} 967}
930 968
931bool KSyncManager::isProgressBarCanceled() 969bool KSyncManager::isProgressBarCanceled()
932{ 970{
933 return !bar->isVisible(); 971 return !bar->isVisible();
934} 972}
935 973
936QString KSyncManager::syncFileName() 974QString KSyncManager::syncFileName()
937{ 975{
938 976
939 QString fn = "tempfile"; 977 QString fn = "tempfile";
940 switch(mTargetApp) 978 switch(mTargetApp)
941 { 979 {
942 case (KAPI): 980 case (KAPI):
943 fn = "tempsyncab.vcf"; 981 fn = "tempsyncab.vcf";
944 break; 982 break;
945 case (KOPI): 983 case (KOPI):
946 fn = "tempsynccal.ics"; 984 fn = "tempsynccal.ics";
947 break; 985 break;
948 case (PWMPI): 986 case (PWMPI):
949 fn = "tempsyncpw.pwm"; 987 fn = "tempsyncpw.pwm";
950 break; 988 break;
951 default: 989 default:
952 break; 990 break;
953 } 991 }
954#ifdef _WIN32_ 992#ifdef _WIN32_
955 return locateLocal( "tmp", fn ); 993 return locateLocal( "tmp", fn );
956#else 994#else
957 return (QString( "/tmp/" )+ fn ); 995 return (QString( "/tmp/" )+ fn );
958#endif 996#endif
959} 997}
960 998
961void KSyncManager::syncPi() 999void KSyncManager::syncPi()
962{ 1000{
963 mPisyncFinished = false; 1001 mPisyncFinished = false;
964 qApp->processEvents(); 1002 qApp->processEvents();
965 if ( mAskForPreferences ) 1003 if ( mAskForPreferences )
966 if ( !edit_pisync_options()) { 1004 if ( !edit_pisync_options()) {
967 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1005 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
968 return; 1006 return;
969 } 1007 }
970 bool ok; 1008 bool ok;
971 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1009 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
972 if ( ! ok ) { 1010 if ( ! ok ) {
973 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1011 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
974 return; 1012 return;
975 } 1013 }
976 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 1014 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
977 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1015 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
978 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 1016 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
979 commandSocket->readFile( syncFileName() ); 1017 commandSocket->readFile( syncFileName() );
980} 1018}
981 1019
982void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1020void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
983{ 1021{
984 //enum { success, errorW, errorR, quiet }; 1022 //enum { success, errorW, errorR, quiet };
985 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1023 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
986 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1024 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
987 delete s; 1025 delete s;
988 if ( state == KCommandSocket::errorR ) { 1026 if ( state == KCommandSocket::errorR ) {
989 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1027 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
990 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1028 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
991 commandSocket->sendStop(); 1029 commandSocket->sendStop();
992 } 1030 }
993 mPisyncFinished = true; 1031 mPisyncFinished = true;
994 return; 1032 return;
995 1033
996 } else if ( state == KCommandSocket::errorW ) { 1034 } else if ( state == KCommandSocket::errorW ) {
997 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1035 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
998 mPisyncFinished = true; 1036 mPisyncFinished = true;
999 1037
1000 } else if ( state == KCommandSocket::successR ) { 1038 } else if ( state == KCommandSocket::successR ) {
1001 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1039 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1002 1040
1003 } else if ( state == KCommandSocket::successW ) { 1041 } else if ( state == KCommandSocket::successW ) {
1004 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1042 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1005 mPisyncFinished = true; 1043 mPisyncFinished = true;
1006 } 1044 }
1007 1045
1008 delete s; 1046 delete s;
1009} 1047}
1010 1048
1011void KSyncManager::readFileFromSocket() 1049void KSyncManager::readFileFromSocket()
1012{ 1050{
1013 QString fileName = syncFileName(); 1051 QString fileName = syncFileName();
1014 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1052 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1015 if ( ! syncWithFile( fileName , true ) ) { 1053 if ( ! syncWithFile( fileName , true ) ) {
1016 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1054 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1017 mPisyncFinished = true; 1055 mPisyncFinished = true;
1018 return; 1056 return;
1019 } 1057 }
1020 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1058 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1021 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1059 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1022 if ( mWriteBackFile ) 1060 if ( mWriteBackFile )
1023 commandSocket->writeFile( fileName ); 1061 commandSocket->writeFile( fileName );
1024 else { 1062 else {
1025 commandSocket->sendStop(); 1063 commandSocket->sendStop();
1026 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1064 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1027 mPisyncFinished = true; 1065 mPisyncFinished = true;
1028 } 1066 }
1029} 1067}
1030 1068
1031KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1069KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1032{ 1070{
1033 mPassWord = pw; 1071 mPassWord = pw;
1034 mSocket = 0; 1072 mSocket = 0;
1035 mSyncActionDialog = 0; 1073 mSyncActionDialog = 0;
1036 blockRC = false; 1074 blockRC = false;
1037}; 1075};
1038 1076
1039void KServerSocket::newConnection ( int socket ) 1077void KServerSocket::newConnection ( int socket )
1040{ 1078{
1041 // qDebug("KServerSocket:New connection %d ", socket); 1079 // qDebug("KServerSocket:New connection %d ", socket);
1042 if ( mSocket ) { 1080 if ( mSocket ) {
1043 qDebug("KServerSocket::newConnection Socket deleted! "); 1081 qDebug("KServerSocket::newConnection Socket deleted! ");
1044 delete mSocket; 1082 delete mSocket;
1045 mSocket = 0; 1083 mSocket = 0;
1046 } 1084 }
1047 mSocket = new QSocket( this ); 1085 mSocket = new QSocket( this );
1048 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1086 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1049 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1087 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1050 mSocket->setSocket( socket ); 1088 mSocket->setSocket( socket );
1051} 1089}
1052 1090
1053void KServerSocket::discardClient() 1091void KServerSocket::discardClient()
1054{ 1092{
1055 //qDebug(" KServerSocket::discardClient()"); 1093 //qDebug(" KServerSocket::discardClient()");
1056 if ( mSocket ) { 1094 if ( mSocket ) {
1057 delete mSocket; 1095 delete mSocket;
1058 mSocket = 0; 1096 mSocket = 0;
1059 } 1097 }
1060 //emit endConnect(); 1098 //emit endConnect();
1061} 1099}
1062void KServerSocket::readClient() 1100void KServerSocket::readClient()
1063{ 1101{
1064 if ( blockRC ) 1102 if ( blockRC )
1065 return; 1103 return;
1066 if ( mSocket == 0 ) { 1104 if ( mSocket == 0 ) {
1067 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 1105 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
1068 return; 1106 return;
1069 } 1107 }
1070 //qDebug("KServerSocket::readClient()"); 1108 //qDebug("KServerSocket::readClient()");
1071 if ( mSocket->canReadLine() ) { 1109 if ( mSocket->canReadLine() ) {
1072 QString line = mSocket->readLine(); 1110 QString line = mSocket->readLine();
1073 //qDebug("KServerSocket readline: %s ", line.latin1()); 1111 //qDebug("KServerSocket readline: %s ", line.latin1());
1074 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1112 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1075 if ( tokens[0] == "GET" ) { 1113 if ( tokens[0] == "GET" ) {
1076 if ( tokens[1] == mPassWord ) 1114 if ( tokens[1] == mPassWord )
1077 //emit sendFile( mSocket ); 1115 //emit sendFile( mSocket );
1078 send_file(); 1116 send_file();
1079 else { 1117 else {
1080 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1118 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1081 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1119 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1082 } 1120 }
1083 } 1121 }
1084 if ( tokens[0] == "PUT" ) { 1122 if ( tokens[0] == "PUT" ) {
1085 if ( tokens[1] == mPassWord ) { 1123 if ( tokens[1] == mPassWord ) {
1086 //emit getFile( mSocket ); 1124 //emit getFile( mSocket );
1087 blockRC = true; 1125 blockRC = true;
1088 get_file(); 1126 get_file();
1089 } 1127 }
1090 else { 1128 else {
1091 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1129 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1092 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1130 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1093 } 1131 }
1094 } 1132 }
1095 if ( tokens[0] == "STOP" ) { 1133 if ( tokens[0] == "STOP" ) {
1096 //emit endConnect(); 1134 //emit endConnect();
1097 end_connect(); 1135 end_connect();
1098 } 1136 }
1099 } 1137 }
1100} 1138}
1101void KServerSocket::end_connect() 1139void KServerSocket::end_connect()
1102{ 1140{
1103 delete mSyncActionDialog; 1141 delete mSyncActionDialog;
1104 mSyncActionDialog = 0; 1142 mSyncActionDialog = 0;
1105} 1143}
1106void KServerSocket::send_file() 1144void KServerSocket::send_file()
1107{ 1145{
1108 //qDebug("MainWindow::sendFile(QSocket* s) "); 1146 //qDebug("MainWindow::sendFile(QSocket* s) ");
1109 if ( mSyncActionDialog ) 1147 if ( mSyncActionDialog )
1110 delete mSyncActionDialog; 1148 delete mSyncActionDialog;
1111 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1149 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1112 mSyncActionDialog->setCaption(i18n("Received sync request")); 1150 mSyncActionDialog->setCaption(i18n("Received sync request"));
1113 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1151 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1114 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1152 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1115 lay->addWidget( label); 1153 lay->addWidget( label);
1116 lay->setMargin(7); 1154 lay->setMargin(7);
1117 lay->setSpacing(7); 1155 lay->setSpacing(7);
1118 mSyncActionDialog->setFixedSize( 230, 120); 1156 mSyncActionDialog->setFixedSize( 230, 120);
1119 mSyncActionDialog->show(); 1157 mSyncActionDialog->show();
1120 mSyncActionDialog->raise(); 1158 mSyncActionDialog->raise();
1121 emit request_file(); 1159 emit request_file();
1122 qApp->processEvents(); 1160 qApp->processEvents();
1123 QString fileName = mFileName; 1161 QString fileName = mFileName;
1124 QFile file( fileName ); 1162 QFile file( fileName );
1125 if (!file.open( IO_ReadOnly ) ) { 1163 if (!file.open( IO_ReadOnly ) ) {
1126 delete mSyncActionDialog; 1164 delete mSyncActionDialog;
1127 mSyncActionDialog = 0; 1165 mSyncActionDialog = 0;
1128 qDebug("KSS::error open file "); 1166 qDebug("KSS::error open file ");
1129 mSocket->close(); 1167 mSocket->close();
1130 if ( mSocket->state() == QSocket::Idle ) 1168 if ( mSocket->state() == QSocket::Idle )
1131 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1169 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1132 return ; 1170 return ;
1133 1171
1134 } 1172 }
1135 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1173 mSyncActionDialog->setCaption( i18n("Sending file...") );
1136 QTextStream ts( &file ); 1174 QTextStream ts( &file );
1137 ts.setEncoding( QTextStream::Latin1 ); 1175 ts.setEncoding( QTextStream::Latin1 );
1138 1176
1139 QTextStream os( mSocket ); 1177 QTextStream os( mSocket );
1140 os.setEncoding( QTextStream::Latin1 ); 1178 os.setEncoding( QTextStream::Latin1 );
1141 while ( ! ts.atEnd() ) { 1179 while ( ! ts.atEnd() ) {
1142 os << ts.readLine() << "\r\n"; 1180 os << ts.readLine() << "\r\n";
1143 } 1181 }
1144 //os << ts.read(); 1182 //os << ts.read();
1145 file.close(); 1183 file.close();
1146 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1184 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1147 mSocket->close(); 1185 mSocket->close();
1148 if ( mSocket->state() == QSocket::Idle ) 1186 if ( mSocket->state() == QSocket::Idle )
1149 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1187 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1150} 1188}
1151void KServerSocket::get_file() 1189void KServerSocket::get_file()
1152{ 1190{
1153 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1191 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1154 1192
1155 piTime.start(); 1193 piTime.start();
1156 piFileString = ""; 1194 piFileString = "";
1157 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1195 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1158} 1196}
1159 1197
1160 1198
1161void KServerSocket::readBackFileFromSocket() 1199void KServerSocket::readBackFileFromSocket()
1162{ 1200{
1163 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1201 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1164 while ( mSocket->canReadLine () ) { 1202 while ( mSocket->canReadLine () ) {
1165 piTime.restart(); 1203 piTime.restart();
1166 QString line = mSocket->readLine (); 1204 QString line = mSocket->readLine ();
1167 piFileString += line; 1205 piFileString += line;
1168 //qDebug("readline: %s ", line.latin1()); 1206 //qDebug("readline: %s ", line.latin1());
1169 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1207 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1170 1208
1171 } 1209 }
1172 if ( piTime.elapsed () < 3000 ) { 1210 if ( piTime.elapsed () < 3000 ) {
1173 // wait for more 1211 // wait for more
1174 //qDebug("waitformore "); 1212 //qDebug("waitformore ");
1175 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1213 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1176 return; 1214 return;
1177 } 1215 }
1178 QString fileName = mFileName; 1216 QString fileName = mFileName;
1179 QFile file ( fileName ); 1217 QFile file ( fileName );
1180 if (!file.open( IO_WriteOnly ) ) { 1218 if (!file.open( IO_WriteOnly ) ) {
1181 delete mSyncActionDialog; 1219 delete mSyncActionDialog;
1182 mSyncActionDialog = 0; 1220 mSyncActionDialog = 0;
1183 qDebug("KSS:Error open read back file "); 1221 qDebug("KSS:Error open read back file ");
1184 piFileString = ""; 1222 piFileString = "";
1185 emit file_received( false ); 1223 emit file_received( false );
1186 blockRC = false; 1224 blockRC = false;
1187 return ; 1225 return ;
1188 1226
1189 } 1227 }
1190 1228
1191 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1229 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1192 QTextStream ts ( &file ); 1230 QTextStream ts ( &file );
1193 ts.setEncoding( QTextStream::Latin1 ); 1231 ts.setEncoding( QTextStream::Latin1 );
1194 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1232 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1195 ts << piFileString; 1233 ts << piFileString;
1196 mSocket->close(); 1234 mSocket->close();
1197 if ( mSocket->state() == QSocket::Idle ) 1235 if ( mSocket->state() == QSocket::Idle )
1198 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1236 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1199 file.close(); 1237 file.close();
1200 piFileString = ""; 1238 piFileString = "";
1201 emit file_received( true ); 1239 emit file_received( true );
1202 delete mSyncActionDialog; 1240 delete mSyncActionDialog;
1203 mSyncActionDialog = 0; 1241 mSyncActionDialog = 0;
1204 blockRC = false; 1242 blockRC = false;
1205 1243
1206} 1244}
1207 1245
1208KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1246KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1209{ 1247{
1210 mPassWord = password; 1248 mPassWord = password;
1211 mSocket = 0; 1249 mSocket = 0;
1212 mPort = port; 1250 mPort = port;
1213 mHost = host; 1251 mHost = host;
1214 1252
1215 mRetVal = quiet; 1253 mRetVal = quiet;
1216 mTimerSocket = new QTimer ( this ); 1254 mTimerSocket = new QTimer ( this );
1217 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1255 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1218} 1256}
1219void KCommandSocket::readFile( QString fn ) 1257void KCommandSocket::readFile( QString fn )
1220{ 1258{
1221 if ( !mSocket ) { 1259 if ( !mSocket ) {
1222 mSocket = new QSocket( this ); 1260 mSocket = new QSocket( this );
1223 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1261 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index af4f1ab..aa32e28 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -1,212 +1,213 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 19
20 $Id$ 20 $Id$
21*/ 21*/
22#ifndef _KSYNCMANAGER_H 22#ifndef _KSYNCMANAGER_H
23#define _KSYNCMANAGER_H 23#define _KSYNCMANAGER_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qsocket.h> 27#include <qsocket.h>
28#include <qdatetime.h> 28#include <qdatetime.h>
29#include <qserversocket.h> 29#include <qserversocket.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qregexp.h> 31#include <qregexp.h>
32 32
33class QPopupMenu; 33class QPopupMenu;
34class KSyncProfile; 34class KSyncProfile;
35class KPimPrefs; 35class KPimPrefs;
36class QWidget; 36class QWidget;
37class KSyncManager; 37class KSyncManager;
38class KSyncInterface; 38class KSyncInterface;
39class QProgressBar; 39class QProgressBar;
40 40
41 41
42class KServerSocket : public QServerSocket 42class KServerSocket : public QServerSocket
43{ 43{
44 Q_OBJECT 44 Q_OBJECT
45 45
46 public: 46 public:
47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
48 48
49 void newConnection ( int socket ) ; 49 void newConnection ( int socket ) ;
50 void setFileName( QString fn ) {mFileName = fn;}; 50 void setFileName( QString fn ) {mFileName = fn;};
51 signals: 51 signals:
52 void file_received( bool ); 52 void file_received( bool );
53 void request_file(); 53 void request_file();
54 void saveFile(); 54 void saveFile();
55 void endConnect(); 55 void endConnect();
56 private slots: 56 private slots:
57 void discardClient(); 57 void discardClient();
58 void readClient(); 58 void readClient();
59 void readBackFileFromSocket(); 59 void readBackFileFromSocket();
60 private : 60 private :
61 bool blockRC; 61 bool blockRC;
62 void send_file(); 62 void send_file();
63 void get_file(); 63 void get_file();
64 void end_connect(); 64 void end_connect();
65 QDialog* mSyncActionDialog; 65 QDialog* mSyncActionDialog;
66 QSocket* mSocket; 66 QSocket* mSocket;
67 QString mPassWord; 67 QString mPassWord;
68 QString mFileName; 68 QString mFileName;
69 QTime piTime; 69 QTime piTime;
70 QString piFileString; 70 QString piFileString;
71}; 71};
72 72
73class KCommandSocket : public QObject 73class KCommandSocket : public QObject
74{ 74{
75 Q_OBJECT 75 Q_OBJECT
76 public: 76 public:
77 enum state { successR, errorR, successW, errorW, errorTO, quiet }; 77 enum state { successR, errorR, successW, errorW, errorTO, quiet };
78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
79 void readFile( QString ); 79 void readFile( QString );
80 void writeFile( QString ); 80 void writeFile( QString );
81 void sendStop(); 81 void sendStop();
82 82
83 signals: 83 signals:
84 void commandFinished( KCommandSocket*, int ); 84 void commandFinished( KCommandSocket*, int );
85 private slots: 85 private slots:
86 void startReadFileFromSocket(); 86 void startReadFileFromSocket();
87 void readFileFromSocket(); 87 void readFileFromSocket();
88 void deleteSocket(); 88 void deleteSocket();
89 void writeFileToSocket(); 89 void writeFileToSocket();
90 private : 90 private :
91 QSocket* mSocket; 91 QSocket* mSocket;
92 QString mPassWord; 92 QString mPassWord;
93 Q_UINT16 mPort; 93 Q_UINT16 mPort;
94 QString mHost; 94 QString mHost;
95 QString mFileName; 95 QString mFileName;
96 QTimer* mTimerSocket; 96 QTimer* mTimerSocket;
97 int mRetVal; 97 int mRetVal;
98 QTime mTime; 98 QTime mTime;
99 QString mFileString; 99 QString mFileString;
100 bool mFirst; 100 bool mFirst;
101}; 101};
102 102
103 103
104class KSyncManager : public QObject 104class KSyncManager : public QObject
105{ 105{
106 Q_OBJECT 106 Q_OBJECT
107 107
108 public: 108 public:
109 enum TargetApp { 109 enum TargetApp {
110 KOPI = 0, 110 KOPI = 0,
111 KAPI = 1, 111 KAPI = 1,
112 PWMPI = 2 }; 112 PWMPI = 2 };
113 113
114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
115 ~KSyncManager() ; 115 ~KSyncManager() ;
116 116
117 void multiSync( bool askforPrefs ); 117 void multiSync( bool askforPrefs );
118 bool blockSave() { return mBlockSaveFlag; } 118 bool blockSave() { return mBlockSaveFlag; }
119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
120 void setDefaultFileName( QString s) { mDefFileName = s ;} 120 void setDefaultFileName( QString s) { mDefFileName = s ;}
121 QString defaultFileName() { return mDefFileName ;} 121 QString defaultFileName() { return mDefFileName ;}
122 QString syncFileName(); 122 QString syncFileName();
123 void enableQuick( bool ask = true); 123 void enableQuick( bool ask = true);
124 124
125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
126 QString getCurrentSyncName() { return mCurrentSyncName; } 126 QString getCurrentSyncName() { return mCurrentSyncName; }
127 127
128 void showProgressBar(int percentage, QString caption = QString::null, int total=100); 128 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
129 void hideProgressBar(); 129 void hideProgressBar();
130 bool isProgressBarCanceled(); 130 bool isProgressBarCanceled();
131 131
132 // sync stuff 132 // sync stuff
133 QString mLocalMachineName; 133 QString mLocalMachineName;
134 QStringList mExternSyncProfiles; 134 QStringList mExternSyncProfiles;
135 QStringList mSyncProfileNames; 135 QStringList mSyncProfileNames;
136 bool mAskForPreferences; 136 bool mAskForPreferences;
137 bool mShowSyncSummary; 137 bool mShowSyncSummary;
138 bool mIsKapiFile; 138 bool mIsKapiFile;
139 bool mWriteBackExistingOnly; 139 bool mWriteBackExistingOnly;
140 int mSyncAlgoPrefs; 140 int mSyncAlgoPrefs;
141 bool mWriteBackFile; 141 bool mWriteBackFile;
142 int mWriteBackInFuture; 142 int mWriteBackInFuture;
143 QString mPhoneDevice; 143 QString mPhoneDevice;
144 QString mPhoneConnection; 144 QString mPhoneConnection;
145 QString mPhoneModel; 145 QString mPhoneModel;
146 QString mPassWordPiSync; 146 QString mPassWordPiSync;
147 QString mActiveSyncPort; 147 QString mActiveSyncPort;
148 QString mActiveSyncIP ; 148 QString mActiveSyncIP ;
149 149
150 signals: 150 signals:
151 void save(); 151 void save();
152 void request_file(); 152 void request_file();
153 void getFile( bool ); 153 void getFile( bool );
154 154
155 public slots: 155 public slots:
156 void slotSyncMenu( int ); 156 void slotSyncMenu( int );
157 void slotClearMenu( int action );
157 void deleteCommandSocket(KCommandSocket*s, int state); 158 void deleteCommandSocket(KCommandSocket*s, int state);
158 void readFileFromSocket(); 159 void readFileFromSocket();
159 void fillSyncMenu(); 160 void fillSyncMenu();
160 161
161 private: 162 private:
162 void syncPi(); 163 void syncPi();
163 KServerSocket * mServerSocket; 164 KServerSocket * mServerSocket;
164 KPimPrefs* mPrefs; 165 KPimPrefs* mPrefs;
165 QString mDefFileName; 166 QString mDefFileName;
166 QString mCurrentSyncDevice; 167 QString mCurrentSyncDevice;
167 QString mCurrentSyncName; 168 QString mCurrentSyncName;
168 void quickSyncLocalFile(); 169 void quickSyncLocalFile();
169 bool syncWithFile( QString fn , bool quick ); 170 bool syncWithFile( QString fn , bool quick );
170 void syncLocalFile(); 171 void syncLocalFile();
171 void syncPhone(); 172 void syncPhone();
172 void syncSharp(); 173 void syncSharp();
173 void syncKDE(); 174 void syncKDE();
174 bool syncExternalApplication(QString); 175 bool syncExternalApplication(QString);
175 int mCurrentSyncProfile ; 176 int mCurrentSyncProfile ;
176 void syncRemote( KSyncProfile* prof, bool ask = true); 177 void syncRemote( KSyncProfile* prof, bool ask = true);
177 bool edit_sync_options(); 178 bool edit_sync_options();
178 bool edit_pisync_options(); 179 bool edit_pisync_options();
179 int ringSync(); 180 int ringSync();
180 QString getPassword( ); 181 QString getPassword( );
181 bool mPisyncFinished; 182 bool mPisyncFinished;
182 bool mBlockSaveFlag; 183 bool mBlockSaveFlag;
183 QWidget* mParent; 184 QWidget* mParent;
184 KSyncInterface* mImplementation; 185 KSyncInterface* mImplementation;
185 TargetApp mTargetApp; 186 TargetApp mTargetApp;
186 QPopupMenu* mSyncMenu; 187 QPopupMenu* mSyncMenu;
187 QProgressBar* bar; 188 QProgressBar* bar;
188 189
189private slots: 190private slots:
190 void confSync(); 191 void confSync();
191 192
192 193
193}; 194};
194 195
195 196
196class KSyncInterface 197class KSyncInterface
197{ 198{
198 public : 199 public :
199 virtual void removeSyncInfo( QString syncProfile) = 0; 200 virtual void removeSyncInfo( QString syncProfile) = 0;
200 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 201 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
201 virtual bool syncExternal(KSyncManager* manager, QString resource) 202 virtual bool syncExternal(KSyncManager* manager, QString resource)
202 { 203 {
203 // empty implementation, because some syncable applications do not 204 // empty implementation, because some syncable applications do not
204 // have an external(sharpdtm) syncmode, like pwmanager. 205 // have an external(sharpdtm) syncmode, like pwmanager.
205 return false; 206 return false;
206 } 207 }
207 208
208 209
209}; 210};
210 211
211 212
212#endif 213#endif