summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koprefs.cpp118
-rw-r--r--libkcal/phoneformat.cpp44
-rw-r--r--libkcal/vcalformat.cpp19
-rw-r--r--libkcal/vcalformat.h5
4 files changed, 115 insertions, 71 deletions
diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp
index 0db8e6d..dd978bf 100644
--- a/korganizer/koprefs.cpp
+++ b/korganizer/koprefs.cpp
@@ -297,264 +297,266 @@ KOPrefs::KOPrefs() :
297 297
298 addItemBool("CompactDialogs",&mCompactDialogs,false); 298 addItemBool("CompactDialogs",&mCompactDialogs,false);
299 addItemBool("VerticalScreen",&mVerticalScreen,true); 299 addItemBool("VerticalScreen",&mVerticalScreen,true);
300 300
301 KPrefs::setCurrentGroup("KOrganizer Plugins"); 301 KPrefs::setCurrentGroup("KOrganizer Plugins");
302 302
303 addItemStringList("SelectedPlugins",&mSelectedPlugins,"holidays"); 303 addItemStringList("SelectedPlugins",&mSelectedPlugins,"holidays");
304 304
305 KPrefs::setCurrentGroup("Group Scheduling"); 305 KPrefs::setCurrentGroup("Group Scheduling");
306 306
307 addItemInt("IMIPScheduler",&mIMIPScheduler,IMIPKMail); 307 addItemInt("IMIPScheduler",&mIMIPScheduler,IMIPKMail);
308 addItemInt("IMIPSend",&mIMIPSend,IMIPdirectsend); 308 addItemInt("IMIPSend",&mIMIPSend,IMIPdirectsend);
309 addItemStringList("AdditionalMails",&mAdditionalMails,""); 309 addItemStringList("AdditionalMails",&mAdditionalMails,"");
310 addItemInt("IMIP auto refresh",&mIMIPAutoRefresh,neverAuto); 310 addItemInt("IMIP auto refresh",&mIMIPAutoRefresh,neverAuto);
311 addItemInt("IMIP auto insert request",&mIMIPAutoInsertRequest,neverAuto); 311 addItemInt("IMIP auto insert request",&mIMIPAutoInsertRequest,neverAuto);
312 addItemInt("IMIP auto insert reply",&mIMIPAutoInsertReply,neverAuto); 312 addItemInt("IMIP auto insert reply",&mIMIPAutoInsertReply,neverAuto);
313 addItemInt("IMIP auto FreeBusy",&mIMIPAutoFreeBusy,neverAuto); 313 addItemInt("IMIP auto FreeBusy",&mIMIPAutoFreeBusy,neverAuto);
314 addItemInt("IMIP auto save FreeBusy",&mIMIPAutoFreeBusyReply,neverAuto); 314 addItemInt("IMIP auto save FreeBusy",&mIMIPAutoFreeBusyReply,neverAuto);
315 315
316 KPrefs::setCurrentGroup( "Editors" ); 316 KPrefs::setCurrentGroup( "Editors" );
317 317
318 addItemStringList( "EventTemplates", &mEventTemplates ); 318 addItemStringList( "EventTemplates", &mEventTemplates );
319 addItemStringList( "TodoTemplates", &mTodoTemplates ); 319 addItemStringList( "TodoTemplates", &mTodoTemplates );
320 320
321 addItemInt("DestinationPolicy",&mDestination,standardDestination); 321 addItemInt("DestinationPolicy",&mDestination,standardDestination);
322 322
323 323
324 324
325} 325}
326 326
327 327
328KOPrefs::~KOPrefs() 328KOPrefs::~KOPrefs()
329{ 329{
330 if (mInstance == this) 330 if (mInstance == this)
331 mInstance = insd.setObject(0); 331 mInstance = insd.setObject(0);
332 setLocaleDict( 0 ); 332 setLocaleDict( 0 );
333 if ( mLocaleDict ) 333 if ( mLocaleDict )
334 delete mLocaleDict; 334 delete mLocaleDict;
335 //qDebug("KOPrefs::~KOPrefs() "); 335 //qDebug("KOPrefs::~KOPrefs() ");
336} 336}
337 337
338 338
339KOPrefs *KOPrefs::instance() 339KOPrefs *KOPrefs::instance()
340{ 340{
341 if (!mInstance) { 341 if (!mInstance) {
342 mInstance = insd.setObject(new KOPrefs()); 342 mInstance = insd.setObject(new KOPrefs());
343 mInstance->readConfig(); 343 mInstance->readConfig();
344 } 344 }
345 345
346 return mInstance; 346 return mInstance;
347} 347}
348 348
349void KOPrefs::usrSetDefaults() 349void KOPrefs::usrSetDefaults()
350{ 350{
351 351
352} 352}
353 353
354void KOPrefs::fillMailDefaults() 354void KOPrefs::fillMailDefaults()
355{ 355{
356 if (mName.isEmpty()) mName = i18n("Anonymous"); 356 if (mName.isEmpty()) mName = i18n("Anonymous");
357 if (mEmail.isEmpty()) mEmail = i18n("nobody@nowhere"); 357 if (mEmail.isEmpty()) mEmail = i18n("nobody@nowhere");
358} 358}
359 359
360void KOPrefs::setTimeZoneIdDefault() 360void KOPrefs::setTimeZoneIdDefault()
361{ 361{
362 mTimeZoneId = i18n("+01:00 Europe/Oslo(CET)"); 362 mTimeZoneId = i18n("+01:00 Europe/Oslo(CET)");
363} 363}
364 364
365void KOPrefs::setCategoryDefaults() 365void KOPrefs::setCategoryDefaults()
366{ 366{
367 mCustomCategories.clear(); 367 mCustomCategories.clear();
368 mCustomCategories = getDefaultList(); 368 mCustomCategories = getDefaultList();
369 369
370 QStringList::Iterator it; 370 QStringList::Iterator it;
371 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { 371 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) {
372 setCategoryColor(*it,mDefaultCategoryColor); 372 setCategoryColor(*it,mDefaultCategoryColor);
373 } 373 }
374} 374}
375 375
376QStringList KOPrefs::getDefaultList() 376QStringList KOPrefs::getDefaultList()
377{ 377{
378 QStringList retval ; 378 QStringList retval ;
379 retval << i18n("Anniversary") << i18n("Appointment") << i18n("Birthday") << i18n("Business") << i18n("Business Travel") << i18n("Cinema") << i18n("Customer") 379 retval << i18n("Anniversary") << i18n("Appointment") << i18n("Birthday") << i18n("Business") << i18n("Business Travel") << i18n("Cinema") << i18n("Customer")
380 << i18n("Break")<< i18n("Breakfast")<< i18n("Competition")<< i18n("Dinner") 380 << i18n("Break")<< i18n("Breakfast")<< i18n("Competition")<< i18n("Dinner")
381 << i18n("Education")<< i18n("Family") << i18n("Favorites") << i18n("Festival")<< i18n("Fishing")<< i18n("Flight") << i18n("Gifts") 381 << i18n("Education")<< i18n("Family") << i18n("Favorites") << i18n("Festival")<< i18n("Fishing")<< i18n("Flight") << i18n("Gifts")
382 << i18n("Holiday") << i18n("Holiday Cards")<< i18n("Hot Contacts") << i18n("Hiking") << i18n("Hunting") << i18n("Key Customer") << i18n("Kids") 382 << i18n("Holiday") << i18n("Holiday Cards")<< i18n("Hot Contacts") << i18n("Hiking") << i18n("Hunting") << i18n("Key Customer") << i18n("Kids")
383 << i18n("Lunch") << i18n("Meeting") << i18n("Miscellaneous") << i18n("Partner")<< i18n("Party") << i18n("Personal") << i18n("Personal Travel") 383 << i18n("Lunch") << i18n("Meeting") << i18n("Miscellaneous") << i18n("Partner")<< i18n("Party") << i18n("Personal") << i18n("Personal Travel")
384 << i18n("PHB") << i18n("Phone Calls") << i18n("Projects") << i18n("Recurring") << i18n("School") << i18n("Shopping") 384 << i18n("PHB") << i18n("Phone Calls") << i18n("Projects") << i18n("Recurring") << i18n("School") << i18n("Shopping")
385 << i18n("Speach") << i18n("Special Occasion") << i18n("Sports") << i18n("Talk") << i18n("Travel") << i18n("TV")<< i18n("University") 385 << i18n("Speach") << i18n("Special Occasion") << i18n("Sports") << i18n("Talk") << i18n("Travel") << i18n("TV")<< i18n("University")
386 << i18n("Vacation") << i18n("VIP") << i18n("SyncEvent") ; 386 << i18n("Vacation") << i18n("VIP") << i18n("SyncEvent") ;
387 retval.sort(); 387 retval.sort();
388 return retval; 388 return retval;
389} 389}
390 390
391void KOPrefs::usrReadConfig() 391void KOPrefs::usrReadConfig()
392{ 392{
393 mLocaleDict = 0; 393 mLocaleDict = 0;
394 // pending LR fix translation 394 // pending LR fix translation
395 // qDebug("KOPrefs::usrReadConfig() fix translation "); 395 // qDebug("KOPrefs::usrReadConfig() fix translation ");
396 if ( mPreferredLanguage == 1 ) { 396 if ( mPreferredLanguage > 0 && mPreferredLanguage < 4 ) {
397 mLocaleDict = new QDict<QString>; 397 if ( mPreferredLanguage == 1 ) {
398 int i = 0;
399 QString fw ( germanwords[i] [0]);
400 while ( !fw.isEmpty() ) {
401 mLocaleDict->insert( fw, new QString (germanwords[i] [1] ));
402 ++i;
403 fw = germanwords[i] [0];
404 }
405
406 setLocaleDict( mLocaleDict );
407 } else {
408 QString fileName ;
409 if ( mPreferredLanguage == 3 )
410 fileName = MainWindow::resourcePath()+"usertranslation.txt";
411 else if ( mPreferredLanguage == 2 )
412 fileName = MainWindow::resourcePath()+"frenchtranslation.txt";
413 else return;
414 QFile file( fileName );
415 if (file.open( IO_ReadOnly ) ) {
416 QTextStream ts( &file );
417 ts.setCodec( QTextCodec::codecForLocale() );
418 QString text = ts.read();
419 file.close();
420 text.replace( QRegExp("\\\\n"), "\n" );
421 QString line;
422 QString we;
423 QString wt;
424 int br = 0;
425 int nbr;
426 nbr = text.find ( "},", br );
427 line = text.mid( br, nbr - br );
428 br = nbr+1;
429 int se, ee, st, et;
430 mLocaleDict = new QDict<QString>; 398 mLocaleDict = new QDict<QString>;
431 QString end = "{ \"\",\"\" }"; 399 int i = 0;
432 while ( (line != end) && (br > 1) ) { 400 QString fw ( germanwords[i] [0]);
433 //qDebug("%d *%s* ", br, line.latin1()); 401 while ( !fw.isEmpty() ) {
434 se = line.find("\"")+1; 402 mLocaleDict->insert( fw, new QString (germanwords[i] [1] ));
435 et = line.findRev("\"",-1); 403 ++i;
436 ee = line.find("\",\""); 404 fw = germanwords[i] [0];
437 st = ee+3;
438 we = line.mid( se, ee-se );
439 wt = line.mid( st, et-st );
440 //qDebug("*%s* *%s* ", we.latin1(), wt.latin1());
441 mLocaleDict->insert( we, new QString (wt) );
442 nbr = text.find ( "}", br );
443 line = text.mid( br, nbr - br );
444 br = nbr+1;
445 } 405 }
446 //qDebug("end *%s* ", end.latin1()); 406
447
448 setLocaleDict( mLocaleDict ); 407 setLocaleDict( mLocaleDict );
449 } else { 408 } else {
450 qDebug("KO: Cannot find translation file %s",fileName.latin1() ); 409 QString fileName ;
451 } 410 if ( mPreferredLanguage == 3 )
411 fileName = MainWindow::resourcePath()+"usertranslation.txt";
412 else if ( mPreferredLanguage == 2 )
413 fileName = MainWindow::resourcePath()+"frenchtranslation.txt";
414 QFile file( fileName );
415 if (file.open( IO_ReadOnly ) ) {
416 QTextStream ts( &file );
417 ts.setEncoding( QTextStream::Latin1 );
418 //ts.setCodec( QTextCodec::latin1 );
419 QString text = ts.read();
420 file.close();
421 text.replace( QRegExp("\\\\n"), "\n" );
422 QString line;
423 QString we;
424 QString wt;
425 int br = 0;
426 int nbr;
427 nbr = text.find ( "},", br );
428 line = text.mid( br, nbr - br );
429 br = nbr+1;
430 int se, ee, st, et;
431 mLocaleDict = new QDict<QString>;
432 QString end = "{ \"\",\"\" }";
433 while ( (line != end) && (br > 1) ) {
434 //qDebug("%d *%s* ", br, line.latin1());
435 se = line.find("\"")+1;
436 et = line.findRev("\"",-1);
437 ee = line.find("\",\"");
438 st = ee+3;
439 we = line.mid( se, ee-se );
440 wt = line.mid( st, et-st );
441 //qDebug("*%s* *%s* ", we.latin1(), wt.latin1());
442 mLocaleDict->insert( we, new QString (wt) );
443 nbr = text.find ( "}", br );
444 line = text.mid( br, nbr - br );
445 br = nbr+1;
446 }
447 //qDebug("end *%s* ", end.latin1());
448
449 setLocaleDict( mLocaleDict );
450 } else {
451 qDebug("KO: Cannot find translation file %s",fileName.latin1() );
452 }
452 453
453} 454 }
455 }
454 config()->setGroup("General"); 456 config()->setGroup("General");
455 457
456 mCustomCategories = config()->readListEntry("Custom Categories"); 458 mCustomCategories = config()->readListEntry("Custom Categories");
457 if ( KOPrefs::instance()->mLanguageChanged ) { 459 if ( KOPrefs::instance()->mLanguageChanged ) {
458 mLocationDefaults.clear(); 460 mLocationDefaults.clear();
459 mEventSummaryUser.clear(); 461 mEventSummaryUser.clear();
460 mTodoSummaryUser.clear(); 462 mTodoSummaryUser.clear();
461 } 463 }
462 if (mLocationDefaults.isEmpty()) { 464 if (mLocationDefaults.isEmpty()) {
463 mLocationDefaults << i18n("Home") << i18n("Office") << i18n("Libary") << i18n("School") << i18n("Doctor") << i18n("Beach") 465 mLocationDefaults << i18n("Home") << i18n("Office") << i18n("Library") << i18n("School") << i18n("Doctor") << i18n("Beach")
464 << i18n("University") << i18n("Restaurant") << i18n("Bar") << i18n("Conference room") << i18n("Cinema") << i18n("Lake") << i18n("Kindergarden") 466 << i18n("University") << i18n("Restaurant") << i18n("Bar") << i18n("Conference room") << i18n("Cinema") << i18n("Lake") << i18n("Kindergarten")
465 << i18n("Germany") << i18n("Sweden") << i18n("Forest") << i18n("Desert") << i18n("Kitchen") ; 467 << i18n("Germany") << i18n("Sweden") << i18n("Forest") << i18n("Desert") << i18n("Kitchen") ;
466 // << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") 468 // << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("")
467 mLocationDefaults.sort(); 469 mLocationDefaults.sort();
468 } 470 }
469 471
470 if (mEventSummaryUser.isEmpty()) { 472 if (mEventSummaryUser.isEmpty()) {
471 mEventSummaryUser = getDefaultList() ; 473 mEventSummaryUser = getDefaultList() ;
472 } 474 }
473 if (mTodoSummaryUser.isEmpty()) { 475 if (mTodoSummaryUser.isEmpty()) {
474 mTodoSummaryUser = getDefaultList() ; 476 mTodoSummaryUser = getDefaultList() ;
475 } 477 }
476 478
477 if (mCustomCategories.isEmpty()) setCategoryDefaults(); 479 if (mCustomCategories.isEmpty()) setCategoryDefaults();
478 480
479 config()->setGroup("Personal Settings"); 481 config()->setGroup("Personal Settings");
480 mName = config()->readEntry("user_name",""); 482 mName = config()->readEntry("user_name","");
481 mEmail = config()->readEntry("user_email",""); 483 mEmail = config()->readEntry("user_email","");
482 fillMailDefaults(); 484 fillMailDefaults();
483 485
484 config()->setGroup("Category Colors"); 486 config()->setGroup("Category Colors");
485 QStringList::Iterator it; 487 QStringList::Iterator it;
486 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { 488 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) {
487 setCategoryColor(*it,config()->readColorEntry(*it,&mDefaultCategoryColor)); 489 setCategoryColor(*it,config()->readColorEntry(*it,&mDefaultCategoryColor));
488 490
489 } 491 }
490 492
491 if (mTimeZoneId.isEmpty()) { 493 if (mTimeZoneId.isEmpty()) {
492 setTimeZoneIdDefault(); 494 setTimeZoneIdDefault();
493 } 495 }
494 KPimPrefs::usrReadConfig(); 496 KPimPrefs::usrReadConfig();
495} 497}
496 498
497 499
498void KOPrefs::usrWriteConfig() 500void KOPrefs::usrWriteConfig()
499{ 501{
500 config()->setGroup("General"); 502 config()->setGroup("General");
501 config()->writeEntry("Custom Categories",mCustomCategories); 503 config()->writeEntry("Custom Categories",mCustomCategories);
502 504
503 config()->setGroup("Personal Settings"); 505 config()->setGroup("Personal Settings");
504 config()->writeEntry("user_name",mName); 506 config()->writeEntry("user_name",mName);
505 config()->writeEntry("user_email",mEmail); 507 config()->writeEntry("user_email",mEmail);
506 508
507 config()->setGroup("Category Colors"); 509 config()->setGroup("Category Colors");
508 QDictIterator<QColor> it(mCategoryColors); 510 QDictIterator<QColor> it(mCategoryColors);
509 while (it.current()) { 511 while (it.current()) {
510 config()->writeEntry(it.currentKey(),*(it.current())); 512 config()->writeEntry(it.currentKey(),*(it.current()));
511 ++it; 513 ++it;
512 } 514 }
513 515
514 516
515 KPimPrefs::usrWriteConfig(); 517 KPimPrefs::usrWriteConfig();
516} 518}
517 519
518void KOPrefs::setCategoryColor(QString cat,const QColor & color) 520void KOPrefs::setCategoryColor(QString cat,const QColor & color)
519{ 521{
520 mCategoryColors.replace(cat,new QColor(color)); 522 mCategoryColors.replace(cat,new QColor(color));
521} 523}
522 524
523QColor *KOPrefs::categoryColor(QString cat) 525QColor *KOPrefs::categoryColor(QString cat)
524{ 526{
525 QColor *color = 0; 527 QColor *color = 0;
526 528
527 if (!cat.isEmpty()) color = mCategoryColors[cat]; 529 if (!cat.isEmpty()) color = mCategoryColors[cat];
528 530
529 if (color) return color; 531 if (color) return color;
530 else return &mDefaultCategoryColor; 532 else return &mDefaultCategoryColor;
531} 533}
532 534
533void KOPrefs::setFullName(const QString &name) 535void KOPrefs::setFullName(const QString &name)
534{ 536{
535 mName = name; 537 mName = name;
536} 538}
537 539
538void KOPrefs::setEmail(const QString &email) 540void KOPrefs::setEmail(const QString &email)
539{ 541{
540 //qDebug(" KOPrefs::setEmai*********** %s",email.latin1() ); 542 //qDebug(" KOPrefs::setEmai*********** %s",email.latin1() );
541 mEmail = email; 543 mEmail = email;
542} 544}
543 545
544QString KOPrefs::fullName() 546QString KOPrefs::fullName()
545{ 547{
546 if (mEmailControlCenter) { 548 if (mEmailControlCenter) {
547 KEMailSettings settings; 549 KEMailSettings settings;
548 return settings.getSetting(KEMailSettings::RealName); 550 return settings.getSetting(KEMailSettings::RealName);
549 } else { 551 } else {
550 return mName; 552 return mName;
551 } 553 }
552} 554}
553 555
554QString KOPrefs::email() 556QString KOPrefs::email()
555{ 557{
556 if (mEmailControlCenter) { 558 if (mEmailControlCenter) {
557 KEMailSettings settings; 559 KEMailSettings settings;
558 return settings.getSetting(KEMailSettings::EmailAddress); 560 return settings.getSetting(KEMailSettings::EmailAddress);
559 } else { 561 } else {
560 return mEmail; 562 return mEmail;
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 6276498..1769b37 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -353,279 +353,284 @@ public:
353 startDate = datefromGSM ( &repeat_startdate ); 353 startDate = datefromGSM ( &repeat_startdate );
354 event->setDtStart(QDateTime ( startDate, event->dtStart().time())); 354 event->setDtStart(QDateTime ( startDate, event->dtStart().time()));
355 } else { 355 } else {
356 startDate = event->dtStart().date(); 356 startDate = event->dtStart().date();
357 } 357 }
358 int freq = repeat_frequency; 358 int freq = repeat_frequency;
359 bool hasEndDate = false; 359 bool hasEndDate = false;
360 if ( repeat_stopdate.Day > 0 ) { 360 if ( repeat_stopdate.Day > 0 ) {
361 endDate = datefromGSM ( &repeat_stopdate ); 361 endDate = datefromGSM ( &repeat_stopdate );
362 hasEndDate = true; 362 hasEndDate = true;
363 } 363 }
364 364
365 uint weekDaysNum = repeat_dayofweek ; 365 uint weekDaysNum = repeat_dayofweek ;
366 // 1 == monday, 7 == sunday 366 // 1 == monday, 7 == sunday
367 QBitArray weekDays( 7 ); 367 QBitArray weekDays( 7 );
368 int i; 368 int i;
369 int bb = 1; 369 int bb = 1;
370 for( i = 1; i <= 7; ++i ) { 370 for( i = 1; i <= 7; ++i ) {
371 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 371 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
372 bb = 2 << (i-1); 372 bb = 2 << (i-1);
373 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 373 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
374 } 374 }
375 // qDebug("next "); 375 // qDebug("next ");
376 int pos = 0; 376 int pos = 0;
377 Recurrence *r = event->recurrence(); 377 Recurrence *r = event->recurrence();
378 /* 378 /*
379 0 daily; 379 0 daily;
380 1 weekly;x 380 1 weekly;x
381 2 monthpos;x 381 2 monthpos;x
382 3 monthlyday; 382 3 monthlyday;
383 4 rYearlyMont 383 4 rYearlyMont
384 bool repeating = false; 384 bool repeating = false;
385 int repeat_dayofweek = -1; 385 int repeat_dayofweek = -1;
386 int repeat_day = -1; 386 int repeat_day = -1;
387 int repeat_weekofmonth = -1; 387 int repeat_weekofmonth = -1;
388 int repeat_month = -1; 388 int repeat_month = -1;
389 int repeat_frequency = -1; 389 int repeat_frequency = -1;
390 */ 390 */
391 int dayOfWeek = startDate.dayOfWeek(); 391 int dayOfWeek = startDate.dayOfWeek();
392 if ( repeat_weekofmonth >= 0 ) { 392 if ( repeat_weekofmonth >= 0 ) {
393 rtype = 2; // ************************ 2 MonthlyPos 393 rtype = 2; // ************************ 2 MonthlyPos
394 pos = repeat_weekofmonth; 394 pos = repeat_weekofmonth;
395 if ( repeat_dayofweek >= 0 ) 395 if ( repeat_dayofweek >= 0 )
396 dayOfWeek = repeat_dayofweek; 396 dayOfWeek = repeat_dayofweek;
397 if (repeat_month > 0) { 397 if (repeat_month > 0) {
398 if ( repeat_month != event->dtStart().date().month() ) { 398 if ( repeat_month != event->dtStart().date().month() ) {
399 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); 399 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() );
400 event->setDtStart(QDateTime ( date , event->dtStart().time()) ); 400 event->setDtStart(QDateTime ( date , event->dtStart().time()) );
401 } 401 }
402 if ( freq == 1 ) 402 if ( freq == 1 )
403 freq = 12; 403 freq = 12;
404 } 404 }
405 } else if ( repeat_dayofweek >= 0 ) { 405 } else if ( repeat_dayofweek >= 0 ) {
406 rtype = 1;// ************************ 1 Weekly 406 rtype = 1;// ************************ 1 Weekly
407 } else if ( repeat_day >= 0 ) { 407 } else if ( repeat_day >= 0 ) {
408 if ( repeat_month > 0) { 408 if ( repeat_month > 0) {
409 rtype = 4; 409 rtype = 4;
410 } else { 410 } else {
411 rtype = 3; 411 rtype = 3;
412 } 412 }
413 } else { 413 } else {
414 rtype = 0 ; 414 rtype = 0 ;
415 } 415 }
416 416
417 if ( rtype == 0 ) { 417 if ( rtype == 0 ) {
418 if ( hasEndDate ) r->setDaily( freq, endDate ); 418 if ( hasEndDate ) r->setDaily( freq, endDate );
419 else r->setDaily( freq, -1 ); 419 else r->setDaily( freq, -1 );
420 } else if ( rtype == 1 ) { 420 } else if ( rtype == 1 ) {
421 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 421 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
422 else r->setWeekly( freq, weekDays, -1 ); 422 else r->setWeekly( freq, weekDays, -1 );
423 } else if ( rtype == 3 ) { 423 } else if ( rtype == 3 ) {
424 if ( hasEndDate ) 424 if ( hasEndDate )
425 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 425 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
426 else 426 else
427 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 427 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
428 r->addMonthlyDay( startDate.day() ); 428 r->addMonthlyDay( startDate.day() );
429 } else if ( rtype == 2 ) { 429 } else if ( rtype == 2 ) {
430 if ( hasEndDate ) 430 if ( hasEndDate )
431 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 431 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
432 else 432 else
433 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 433 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
434 QBitArray days( 7 ); 434 QBitArray days( 7 );
435 days.fill( false ); 435 days.fill( false );
436 days.setBit( dayOfWeek - 1 ); 436 days.setBit( dayOfWeek - 1 );
437 r->addMonthlyPos( pos, days ); 437 r->addMonthlyPos( pos, days );
438 } else if ( rtype == 4 ) { 438 } else if ( rtype == 4 ) {
439 if ( hasEndDate ) 439 if ( hasEndDate )
440 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 440 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
441 else 441 else
442 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 442 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
443 r->addYearlyNum( startDate.month() ); 443 r->addYearlyNum( startDate.month() );
444 } 444 }
445 } else { 445 } else {
446 event->recurrence()->unsetRecurs(); 446 event->recurrence()->unsetRecurs();
447 } 447 }
448 448
449 QStringList categoryList; 449 QStringList cat = event->categories();
450 categoryList << getCategory( Note ); 450 QString nCat = getCategory( Note );
451 event->setCategories( categoryList ); 451
452 // strange 0 semms to mean: alarm enabled 452 if ( !nCat.isEmpty() )
453 if ( !cat.contains( nCat )) {
454 cat << nCat;
455 event->setCategories( cat );
456 }
457
453 if ( alarm ) { 458 if ( alarm ) {
454 Alarm *alarm; 459 Alarm *alarm;
455 if ( event->alarms().count() > 0 ) 460 if ( event->alarms().count() > 0 )
456 alarm = event->alarms().first(); 461 alarm = event->alarms().first();
457 else { 462 else {
458 alarm = new Alarm( event ); 463 alarm = new Alarm( event );
459 event->addAlarm( alarm ); 464 event->addAlarm( alarm );
460 } 465 }
461 alarm->setType( Alarm::Audio ); 466 alarm->setType( Alarm::Audio );
462 alarm->setEnabled( true ); 467 alarm->setEnabled( true );
463 int alarmOffset = alarmDt.secsTo( event->dtStart() ); 468 int alarmOffset = alarmDt.secsTo( event->dtStart() );
464 alarm->setStartOffset( -alarmOffset ); 469 alarm->setStartOffset( -alarmOffset );
465 } else { 470 } else {
466 Alarm *alarm; 471 Alarm *alarm;
467 if ( event->alarms().count() > 0 ) { 472 if ( event->alarms().count() > 0 ) {
468 alarm = event->alarms().first(); 473 alarm = event->alarms().first();
469 alarm->setType( Alarm::Audio ); 474 alarm->setType( Alarm::Audio );
470 alarm->setStartOffset( -60*15 ); 475 alarm->setStartOffset( -60*15 );
471 alarm->setEnabled( false ); 476 alarm->setEnabled( false );
472 } 477 }
473 } 478 }
474 // csum ***************************************** 479 // csum *****************************************
475 480
476 uint cSum; 481 uint cSum;
477 cSum = PhoneFormat::getCsumEvent( event ); 482 cSum = PhoneFormat::getCsumEvent( event );
478 event->setCsum( mProfileName, QString::number( cSum )); 483 event->setCsum( mProfileName, QString::number( cSum ));
479 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 484 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
480 mCalendar->addEvent( event); 485 mCalendar->addEvent( event);
481 486
482 return true; 487 return true;
483 } 488 }
484 489
485 490
486 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = false ) { 491 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = false ) {
487 QDateTime dt; 492 QDateTime dt;
488 int y,m,t,h,min,sec; 493 int y,m,t,h,min,sec;
489 y = dtp->Year; 494 y = dtp->Year;
490 m = dtp->Month; 495 m = dtp->Month;
491 t = dtp->Day; 496 t = dtp->Day;
492 h = dtp->Hour; 497 h = dtp->Hour;
493 min = dtp->Minute; 498 min = dtp->Minute;
494 sec = dtp->Second; 499 sec = dtp->Second;
495 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 500 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
496 // dtp->Timezone: offset in hours 501 // dtp->Timezone: offset in hours
497 int offset = KGlobal::locale()->localTimeOffset( dt ); 502 int offset = KGlobal::locale()->localTimeOffset( dt );
498 if ( useTz ) 503 if ( useTz )
499 dt = dt.addSecs ( offset*60); 504 dt = dt.addSecs ( offset*60);
500 return dt; 505 return dt;
501 506
502 } 507 }
503 508
504 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 509 static QString dtToString( const QDateTime& dti, bool useTZ = false )
505 { 510 {
506 QString datestr; 511 QString datestr;
507 QString timestr; 512 QString timestr;
508 int offset = KGlobal::locale()->localTimeOffset( dti ); 513 int offset = KGlobal::locale()->localTimeOffset( dti );
509 QDateTime dt; 514 QDateTime dt;
510 if (useTZ) 515 if (useTZ)
511 dt = dti.addSecs ( -(offset*60)); 516 dt = dti.addSecs ( -(offset*60));
512 else 517 else
513 dt = dti; 518 dt = dti;
514 if(dt.date().isValid()){ 519 if(dt.date().isValid()){
515 const QDate& date = dt.date(); 520 const QDate& date = dt.date();
516 datestr.sprintf("%04d%02d%02d", 521 datestr.sprintf("%04d%02d%02d",
517 date.year(), date.month(), date.day()); 522 date.year(), date.month(), date.day());
518 } 523 }
519 if(dt.time().isValid()){ 524 if(dt.time().isValid()){
520 const QTime& time = dt.time(); 525 const QTime& time = dt.time();
521 timestr.sprintf("T%02d%02d%02d", 526 timestr.sprintf("T%02d%02d%02d",
522 time.hour(), time.minute(), time.second()); 527 time.hour(), time.minute(), time.second());
523 } 528 }
524 return datestr + timestr; 529 return datestr + timestr;
525 } 530 }
526 QDate datefromGSM ( GSM_DateTime*dtp ) { 531 QDate datefromGSM ( GSM_DateTime*dtp ) {
527 return QDate ( dtp->Year, dtp->Month, dtp->Day ); 532 return QDate ( dtp->Year, dtp->Month, dtp->Day );
528 } 533 }
529 QString getCategory( GSM_CalendarEntry*Note) 534 QString getCategory( GSM_CalendarEntry*Note)
530 { 535 {
531 QString CATEGORY; 536 QString CATEGORY;
532 switch (Note->Type) { 537 switch (Note->Type) {
533 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; 538 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break;
534 case GSM_CAL_CALL : CATEGORY = QString("Call"); break; 539 case GSM_CAL_CALL : CATEGORY = QString("Call"); break;
535 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; 540 //case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break;
536 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; 541 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break;
537 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; 542 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break;
538 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; 543 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break;
539 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; 544 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break;
540 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; 545 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break;
541 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; 546 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break;
542 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; 547 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break;
543 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; 548 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break;
544 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; 549 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break;
545 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; 550 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break;
546 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; 551 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break;
547 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; 552 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break;
548 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; 553 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break;
549 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; 554 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break;
550 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; 555 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break;
551 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; 556 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break;
552 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; 557 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break;
553 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; 558 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break;
554 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; 559 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break;
555 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; 560 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break;
556 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; 561 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break;
557 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; 562 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break;
558 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; 563 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break;
559 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; 564 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break;
560 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; 565 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break;
561 default : CATEGORY = QString(""); 566 default : CATEGORY = QString("");
562 } 567 }
563 568
564 return CATEGORY; 569 return CATEGORY;
565 } 570 }
566 571
567protected: 572protected:
568private: 573private:
569 Calendar *mCalendar; 574 Calendar *mCalendar;
570 QString mProfileName ; 575 QString mProfileName ;
571}; 576};
572 577
573 578
574PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 579PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
575{ 580{
576 mProfileName = profileName; 581 mProfileName = profileName;
577 mDevice = device; 582 mDevice = device;
578 mConnection = connection; 583 mConnection = connection;
579 mModel = model; 584 mModel = model;
580} 585}
581 586
582PhoneFormat::~PhoneFormat() 587PhoneFormat::~PhoneFormat()
583{ 588{
584} 589}
585int PhoneFormat::initDevice(GSM_StateMachine *s) 590int PhoneFormat::initDevice(GSM_StateMachine *s)
586{ 591{
587 GSM_ReadConfig(NULL, &s->Config[0], 0); 592 GSM_ReadConfig(NULL, &s->Config[0], 0);
588 s->ConfigNum = 1; 593 s->ConfigNum = 1;
589 GSM_Config *cfg = &s->Config[0]; 594 GSM_Config *cfg = &s->Config[0];
590 if ( ! mConnection.isEmpty() ) { 595 if ( ! mConnection.isEmpty() ) {
591 cfg->Connection = strdup(mConnection.latin1()); 596 cfg->Connection = strdup(mConnection.latin1());
592 cfg->DefaultConnection = false; 597 cfg->DefaultConnection = false;
593 qDebug("Connection set %s ", cfg->Connection ); 598 qDebug("Connection set %s ", cfg->Connection );
594 599
595 } 600 }
596 if ( ! mDevice.isEmpty() ) { 601 if ( ! mDevice.isEmpty() ) {
597 cfg->Device = strdup(mDevice.latin1()); 602 cfg->Device = strdup(mDevice.latin1());
598 cfg->DefaultDevice = false; 603 cfg->DefaultDevice = false;
599 qDebug("Device set %s ", cfg->Device); 604 qDebug("Device set %s ", cfg->Device);
600 605
601 } 606 }
602 if ( ! mModel.isEmpty() ) { 607 if ( ! mModel.isEmpty() ) {
603 strcpy(cfg->Model,mModel.latin1() ); 608 strcpy(cfg->Model,mModel.latin1() );
604 cfg->DefaultModel = false; 609 cfg->DefaultModel = false;
605 qDebug("Model set %s ",cfg->Model ); 610 qDebug("Model set %s ",cfg->Model );
606 } 611 }
607 int error=GSM_InitConnection(s,3); 612 int error=GSM_InitConnection(s,3);
608 return error; 613 return error;
609} 614}
610ulong PhoneFormat::getCsumTodo( Todo* todo ) 615ulong PhoneFormat::getCsumTodo( Todo* todo )
611{ 616{
612 QStringList attList; 617 QStringList attList;
613 if ( todo->hasDueDate() ) 618 if ( todo->hasDueDate() )
614 attList << PhoneParser::dtToString ( todo->dtDue() ); 619 attList << PhoneParser::dtToString ( todo->dtDue() );
615 attList << todo->summary(); 620 attList << todo->summary();
616 QString completedString = "no"; 621 QString completedString = "no";
617 if ( todo->isCompleted() ) 622 if ( todo->isCompleted() )
618 completedString = "yes"; 623 completedString = "yes";
619 attList << completedString; 624 attList << completedString;
620 attList << QString::number( todo->priority() ); 625 attList << QString::number( todo->priority() );
621 QString alarmString = "na"; 626 QString alarmString = "na";
622 Alarm *alarm; 627 Alarm *alarm;
623 if ( todo->alarms().count() > 0 ) { 628 if ( todo->alarms().count() > 0 ) {
624 alarm = todo->alarms().first(); 629 alarm = todo->alarms().first();
625 if ( alarm->enabled() ) { 630 if ( alarm->enabled() ) {
626 alarmString = QString::number(alarm->startOffset().asSeconds() ); 631 alarmString = QString::number(alarm->startOffset().asSeconds() );
627 } 632 }
628 } 633 }
629 attList << alarmString; 634 attList << alarmString;
630 attList << todo->categoriesStr(); 635 attList << todo->categoriesStr();
631 attList << todo->secrecyStr(); 636 attList << todo->secrecyStr();
@@ -977,199 +982,226 @@ bool PhoneFormat::save( Calendar *calendar)
977 qApp->processEvents(); 982 qApp->processEvents();
978 qDebug("todo5 %d ", procCount); 983 qDebug("todo5 %d ", procCount);
979 // todo2GSM( calendar, to, &ToDoEntry ); 984 // todo2GSM( calendar, to, &ToDoEntry );
980 QString loc = to->getID(mProfileName); 985 QString loc = to->getID(mProfileName);
981 if ( !loc.isEmpty() ){ 986 if ( !loc.isEmpty() ){
982 ToDoEntry.Location = loc.toInt(); 987 ToDoEntry.Location = loc.toInt();
983 } else { 988 } else {
984 qDebug("error2: loc is empty "); 989 qDebug("error2: loc is empty ");
985 } 990 }
986 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 991 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
987 error=Phone->DeleteToDo(&s,&ToDoEntry); 992 error=Phone->DeleteToDo(&s,&ToDoEntry);
988 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 993 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
989 qDebug("delete planB %d ", error); 994 qDebug("delete planB %d ", error);
990 } 995 }
991 } 996 }
992 else if ( to->getID(mProfileName).isEmpty() ) { // add new 997 else if ( to->getID(mProfileName).isEmpty() ) { // add new
993 ; 998 ;
994 } 999 }
995 else { // change existing 1000 else { // change existing
996 error=Phone->DeleteToDo(&s,&ToDoEntry); 1001 error=Phone->DeleteToDo(&s,&ToDoEntry);
997 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1002 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
998 qDebug("set planB %d ", error); 1003 qDebug("set planB %d ", error);
999 } 1004 }
1000 to->removeID( mProfileName ); 1005 to->removeID( mProfileName );
1001 } 1006 }
1002 } 1007 }
1003 to = tl.next(); 1008 to = tl.next();
1004 } 1009 }
1005 //algo 2 add event 1010 //algo 2 add event
1006 ev = er.first(); 1011 ev = er.first();
1007 QString filec; 1012 QString filec;
1008 message = i18n(" Preparing event # "); 1013 message = i18n(" Preparing event # ");
1009 procCount = 0; 1014 procCount = 0;
1010 while ( ev ) { 1015 while ( ev ) {
1011 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 1016 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1012 if ( ev->getID(mProfileName).isEmpty() ) { 1017 if ( ev->getID(mProfileName).isEmpty() ) {
1013 status.setText ( message + QString::number ( ++procCount ) ); 1018 status.setText ( message + QString::number ( ++procCount ) );
1014 qApp->processEvents(); 1019 qApp->processEvents();
1015 filec += vfconverter.eventToString( ev, calendar )+ "\n"; 1020 filec += vfconverter.eventToString( ev, calendar )+ "\n";
1016 afterSave ( ev ); 1021 afterSave ( ev );
1017 1022
1018 } 1023 }
1019 } 1024 }
1020 ev = er.next(); 1025 ev = er.next();
1021 } 1026 }
1022 //algo 2 add todo 1027 //algo 2 add todo
1023 to = tl.first(); 1028 to = tl.first();
1024 procCount = 0; 1029 procCount = 0;
1025 message = i18n(" Preparing todo # "); 1030 message = i18n(" Preparing todo # ");
1026 while ( to ) { 1031 while ( to ) {
1027 qDebug("todo2 %d ", procCount); 1032 qDebug("todo2 %d ", procCount);
1028 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 1033 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1029 qDebug("todo4 %d ", procCount); 1034 qDebug("todo4 %d ", procCount);
1030 if ( to->getID(mProfileName).isEmpty() ) { 1035 if ( to->getID(mProfileName).isEmpty() ) {
1031 status.setText ( message + QString::number ( ++procCount ) ); 1036 status.setText ( message + QString::number ( ++procCount ) );
1032 qApp->processEvents(); 1037 qApp->processEvents();
1033 filec += vfconverter.todoToString( to, calendar )+ "\n"; 1038 filec += vfconverter.todoToString( to, calendar )+ "\n";
1034 afterSave ( to ); 1039 afterSave ( to );
1035 } 1040 }
1036 } 1041 }
1037 to = tl.next(); 1042 to = tl.next();
1038 } 1043 }
1039 if ( filec.isEmpty() ) { 1044 if ( filec.isEmpty() ) {
1040 qDebug("Nothing to write back.Finished. "); 1045 qDebug("Nothing to write back.Finished. ");
1041 error=GSM_TerminateConnection(&s); 1046 error=GSM_TerminateConnection(&s);
1042 return true; 1047 return true;
1043 } 1048 }
1044 //algo 3 saving file 1049 //algo 3 saving file
1045 message = i18n(" Saving temp file ... "); 1050 message = i18n(" Saving temp file ... ");
1046 status.setText ( message ); 1051 status.setText ( message );
1047 qApp->processEvents(); 1052 qApp->processEvents();
1048 QFile file( fileName ); 1053 QFile file( fileName );
1049 if (!file.open( IO_WriteOnly ) ) { 1054 if (!file.open( IO_WriteOnly ) ) {
1050 qDebug("error open file "); 1055 qDebug("error open file ");
1051 error=GSM_TerminateConnection(&s); 1056 error=GSM_TerminateConnection(&s);
1052 return false; 1057 return false;
1053 } 1058 }
1054 QTextStream ts( &file ); 1059 QTextStream ts( &file );
1055 ts.setCodec( QTextCodec::codecForName("utf8") ); 1060 ts.setCodec( QTextCodec::codecForName("utf8") );
1056 ts << filec ; 1061 ts << filec ;
1057 file.close(); 1062 file.close();
1058 1063
1059 1064
1060 message = i18n(" Parsing temp file ... "); 1065 message = i18n(" Parsing temp file ... ");
1061 status.setText ( message ); 1066 status.setText ( message );
1062 qApp->processEvents(); 1067 qApp->processEvents();
1063 GSM_Backup Backup; 1068 GSM_Backup Backup;
1064 error=GSM_ReadBackupFile( (char*) fileName.latin1() ,&Backup); 1069 error=GSM_ReadBackupFile( (char*) fileName.latin1() ,&Backup);
1065 qDebug("Read file result %d ",error ); 1070 qDebug("Read file result %d ",error );
1066 //algo 4 writing event 1071 //algo 4 writing event
1067 int max, i; 1072 int max, i;
1068 procCount = 0; 1073 procCount = 0;
1069 message = i18n(" Writing event # "); 1074 message = i18n(" Writing event # ");
1070 if (Backup.Calendar[0] != NULL) { 1075 if (Backup.Calendar[0] != NULL) {
1071 max = 0; 1076 max = 0;
1072 while (Backup.Calendar[max]!=NULL) max++; 1077 while (Backup.Calendar[max]!=NULL) max++;
1078
1079 GSM_DateTime*dtp;
1080
1073 for (i=0;i<max;i++) { 1081 for (i=0;i<max;i++) {
1074 status.setText ( message + QString::number ( ++procCount ) ); 1082 status.setText ( message + QString::number ( ++procCount ) );
1075 qApp->processEvents(); 1083 qApp->processEvents();
1076 Note = *Backup.Calendar[i]; 1084 Note = *Backup.Calendar[i];
1085
1086#if 0
1087 int j;
1088 for (j=0;j<Note.EntriesNum;j++) {
1089 //qDebug(" for ev");
1090 switch (Note.Entries[j].EntryType) {
1091 case CAL_START_DATETIME:
1092 //Note->Entries[i].Date.Hour = 5;
1093 dtp = &Note.Entries[j].Date;
1094 qDebug("start event %d %d %d - %d %d %d", dtp->Year, dtp->Month, dtp->Day, dtp->Hour, dtp->Minute, dtp->Second );
1095 break;
1096 case CAL_END_DATETIME:
1097 dtp = &Note.Entries[j].Date;
1098 qDebug("end event %d %d %d - %d %d %d", dtp->Year, dtp->Month, dtp->Day, dtp->Hour, dtp->Minute, dtp->Second );
1099 break;
1100 }
1101 }
1102 int type = Note.Type;
1103 qDebug(" event type %d - %d %d - %d %d %d",type, GSM_CAL_CALL , GSM_CAL_MEETING ,GSM_CAL_BIRTHDAY, GSM_CAL_MEMO ,GSM_CAL_ALARM );
1104#endif
1105
1106 Note.Type = GSM_CAL_MEETING;
1107 // pending: fix in gammu GSM_ReadBackupFile the type settings
1108 int loc = Note.Location;
1077 Note.Location = 0; 1109 Note.Location = 0;
1078 error=Phone->AddCalendar(&s,&Note); 1110 error=Phone->AddCalendar(&s,&Note);
1079 qDebug("add event %d %d", error, Note.Location ); 1111 qDebug("add event %d %d %d", error, Note.Location, loc );
1080 } 1112 }
1081 } 1113 }
1082 //algo 4 writing todo 1114 //algo 4 writing todo
1083 procCount = 0; 1115 procCount = 0;
1084 message = i18n(" Writing todo # "); 1116 message = i18n(" Writing todo # ");
1085 if (Backup.ToDo[0] != NULL) { 1117 if (Backup.ToDo[0] != NULL) {
1086 max = 0; 1118 max = 0;
1087 while (Backup.ToDo[max]!=NULL) max++; 1119 while (Backup.ToDo[max]!=NULL) max++;
1088 for (i=0;i<max;i++) { 1120 for (i=0;i<max;i++) {
1089 status.setText ( message + QString::number ( ++procCount ) ); 1121 status.setText ( message + QString::number ( ++procCount ) );
1090 qApp->processEvents(); 1122 qApp->processEvents();
1091 ToDoEntry = *Backup.ToDo[i]; 1123 ToDoEntry = *Backup.ToDo[i];
1092 error = Phone->AddToDo(&s,&ToDoEntry); 1124 error = Phone->AddToDo(&s,&ToDoEntry);
1093 qDebug("add todo %d ", error); 1125 qDebug("add todo %d ", error);
1094 } 1126 }
1095 } 1127 }
1096 //algo 5 reread 1128 //algo 5 reread
1097 message = i18n(" Rereading all data ... "); 1129 message = i18n(" Rereading all data ... ");
1098 status.setText ( message ); 1130 status.setText ( message );
1099 qApp->processEvents(); 1131 qApp->processEvents();
1100 error=GSM_TerminateConnection(&s); 1132 error=GSM_TerminateConnection(&s);
1101 CalendarLocal* calendarTemp = new CalendarLocal(); 1133 CalendarLocal* calendarTemp = new CalendarLocal();
1102 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 1134 calendarTemp->setTimeZoneId( calendar->timeZoneId());
1103 if ( ! load( calendarTemp,calendar) ){ 1135 if ( ! load( calendarTemp,calendar) ){
1104 qDebug("error reloading calendar "); 1136 qDebug("error reloading calendar ");
1105 delete calendarTemp; 1137 delete calendarTemp;
1106 return false; 1138 return false;
1107 } 1139 }
1108 1140
1109 1141
1110 //algo 6 compare event 1142 //algo 6 compare event
1111 ev = er.first(); 1143 ev = er.first();
1112 message = i18n(" Comparing event # "); 1144 message = i18n(" Comparing event # ");
1113 QPtrList<Event> er1 = calendarTemp->rawEvents(); 1145 QPtrList<Event> er1 = calendarTemp->rawEvents();
1114 Event* ev1; 1146 Event* ev1;
1115 procCount = 0; 1147 procCount = 0;
1116 while ( ev ) { 1148 while ( ev ) {
1117 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { 1149 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) {
1118 qDebug("event new ID "); 1150 qDebug("event new ID ");
1119 status.setText ( message + QString::number ( ++procCount ) ); 1151 status.setText ( message + QString::number ( ++procCount ) );
1120 qApp->processEvents(); 1152 qApp->processEvents();
1121 QString cSum = ev->getCsum(mProfileName); 1153 QString cSum = ev->getCsum(mProfileName);
1122 ev1 = er1.first(); 1154 ev1 = er1.first();
1123 while ( ev1 ) { 1155 while ( ev1 ) {
1124 if ( ev1->getCsum( mProfileName ) == cSum ) { 1156 if ( ev1->getCsum( mProfileName ) == cSum ) {
1125 er1.remove( ev1 ); 1157 er1.remove( ev1 );
1126 ev->setID(mProfileName, ev1->getID(mProfileName) ); 1158 ev->setID(mProfileName, ev1->getID(mProfileName) );
1127 break; 1159 break;
1128 } 1160 }
1129 ev1 = er1.next(); 1161 ev1 = er1.next();
1130 } 1162 }
1131 if ( ! ev1 ) { 1163 if ( ! ev1 ) {
1132 ev->removeID(mProfileName); 1164 ev->removeID(mProfileName);
1133 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 1165 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
1134 qDebug("Probably writing back of events not supported "); 1166 qDebug("Probably writing back of events not supported ");
1135 } 1167 }
1136 1168
1137 } 1169 }
1138 ev = er.next(); 1170 ev = er.next();
1139 } 1171 }
1140 //algo 6 compare todo 1172 //algo 6 compare todo
1141 to = tl.first(); 1173 to = tl.first();
1142 procCount = 0; 1174 procCount = 0;
1143 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 1175 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
1144 Todo* to1 ; 1176 Todo* to1 ;
1145 message = i18n(" Comparing todo # "); 1177 message = i18n(" Comparing todo # ");
1146 while ( to ) { 1178 while ( to ) {
1147 qDebug("todo2 %d ", procCount); 1179 qDebug("todo2 %d ", procCount);
1148 if ( to->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { 1180 if ( to->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) {
1149 status.setText ( message + QString::number ( ++procCount ) ); 1181 status.setText ( message + QString::number ( ++procCount ) );
1150 qApp->processEvents(); 1182 qApp->processEvents();
1151 QString cSum = to->getCsum(mProfileName); 1183 QString cSum = to->getCsum(mProfileName);
1152 Todo* to1 = tl1.first(); 1184 Todo* to1 = tl1.first();
1153 while ( to1 ) { 1185 while ( to1 ) {
1154 if ( to1->getCsum( mProfileName ) == cSum ) { 1186 if ( to1->getCsum( mProfileName ) == cSum ) {
1155 tl1.remove( to1 ); 1187 tl1.remove( to1 );
1156 to->setID(mProfileName, to1->getID(mProfileName) ); 1188 to->setID(mProfileName, to1->getID(mProfileName) );
1157 break; 1189 break;
1158 } 1190 }
1159 to1 = tl1.next(); 1191 to1 = tl1.next();
1160 } 1192 }
1161 if ( ! to1 ) { 1193 if ( ! to1 ) {
1162 to->removeID(mProfileName); 1194 to->removeID(mProfileName);
1163 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); 1195 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
1164 qDebug("Probably writing back of todos not supported "); 1196 qDebug("Probably writing back of todos not supported ");
1165 } 1197 }
1166 } 1198 }
1167 to = tl.next(); 1199 to = tl.next();
1168 } 1200 }
1169 delete calendarTemp; 1201 delete calendarTemp;
1170 return true; 1202 return true;
1171 // ******************************************************************* 1203 // *******************************************************************
1172 // ******************************************************************* 1204 // *******************************************************************
1173 // ******************************************************************* 1205 // *******************************************************************
1174#if 0 1206#if 0
1175 while ( ev && ! planB) { 1207 while ( ev && ! planB) {
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 9307f12..0ebd7d1 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -1,282 +1,292 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brwon 3 Copyright (c) 1998 Preston Brwon
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#include <qapplication.h> 22#include <qapplication.h>
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#include <qregexp.h> 26#include <qregexp.h>
27#include <qclipboard.h> 27#include <qclipboard.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qfile.h> 29#include <qfile.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h>
32#include <kmessagebox.h> 33#include <kmessagebox.h>
33#include <kiconloader.h> 34#include <kiconloader.h>
34#include <klocale.h> 35#include <klocale.h>
35 36
36#include "vcc.h" 37#include "vcc.h"
37#include "vobject.h" 38#include "vobject.h"
38 39
39#include "vcaldrag.h" 40#include "vcaldrag.h"
40#include "calendar.h" 41#include "calendar.h"
41 42
42#include "vcalformat.h" 43#include "vcalformat.h"
43 44
44using namespace KCal; 45using namespace KCal;
45 46
46VCalFormat::VCalFormat() 47VCalFormat::VCalFormat()
47{ 48{
48 mCalendar = 0; 49 mCalendar = 0;
50 useLocalTime = false;
49} 51}
50 52
51VCalFormat::~VCalFormat() 53VCalFormat::~VCalFormat()
52{ 54{
53} 55}
54 56
55bool VCalFormat::load(Calendar *calendar, const QString &fileName) 57bool VCalFormat::load(Calendar *calendar, const QString &fileName)
56{ 58{
57 mCalendar = calendar; 59 mCalendar = calendar;
58 60
59 clearException(); 61 clearException();
60 62
61 kdDebug(5800) << "VCalFormat::load() " << fileName << endl; 63 kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
62 64
63 VObject *vcal = 0; 65 VObject *vcal = 0;
64 66
65 // this is not necessarily only 1 vcal. Could be many vcals, or include 67 // this is not necessarily only 1 vcal. Could be many vcals, or include
66 // a vcard... 68 // a vcard...
67 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 69 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
68 70
69 if (!vcal) { 71 if (!vcal) {
70 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 72 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
71 return FALSE; 73 return FALSE;
72 } 74 }
73 75
74 // any other top-level calendar stuff should be added/initialized here 76 // any other top-level calendar stuff should be added/initialized here
75 77
76 // put all vobjects into their proper places 78 // put all vobjects into their proper places
77 populate(vcal); 79 populate(vcal);
78 80
79 // clean up from vcal API stuff 81 // clean up from vcal API stuff
80 cleanVObjects(vcal); 82 cleanVObjects(vcal);
81 cleanStrTbl(); 83 cleanStrTbl();
82 84
83 return true; 85 return true;
84} 86}
85 87
86 88
87bool VCalFormat::save(Calendar *calendar, const QString &fileName) 89bool VCalFormat::save(Calendar *calendar, const QString &fileName)
88{ 90{
89 mCalendar = calendar; 91 mCalendar = calendar;
90 92
91 QString tmpStr; 93 QString tmpStr;
92 VObject *vcal, *vo; 94 VObject *vcal, *vo;
93 95
94 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; 96 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl;
95 97
96 vcal = newVObject(VCCalProp); 98 vcal = newVObject(VCCalProp);
97 99
98 // addPropValue(vcal,VCLocationProp, "0.0"); 100 // addPropValue(vcal,VCLocationProp, "0.0");
99 addPropValue(vcal,VCProdIdProp, productId()); 101 addPropValue(vcal,VCProdIdProp, productId());
100 tmpStr = mCalendar->getTimeZoneStr(); 102 tmpStr = mCalendar->getTimeZoneStr();
101 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); 103 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
102 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); 104 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit());
103 addPropValue(vcal,VCVersionProp, _VCAL_VERSION); 105 addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
104 106
105 // TODO STUFF 107 // TODO STUFF
106 QPtrList<Todo> todoList = mCalendar->rawTodos(); 108 QPtrList<Todo> todoList = mCalendar->rawTodos();
107 QPtrListIterator<Todo> qlt(todoList); 109 QPtrListIterator<Todo> qlt(todoList);
108 for (; qlt.current(); ++qlt) { 110 for (; qlt.current(); ++qlt) {
109 vo = eventToVTodo(qlt.current()); 111 vo = eventToVTodo(qlt.current());
110 addVObjectProp(vcal, vo); 112 addVObjectProp(vcal, vo);
111 } 113 }
112 114
113 // EVENT STUFF 115 // EVENT STUFF
114 QPtrList<Event> events = mCalendar->rawEvents(); 116 QPtrList<Event> events = mCalendar->rawEvents();
115 Event *ev; 117 Event *ev;
116 for(ev=events.first();ev;ev=events.next()) { 118 for(ev=events.first();ev;ev=events.next()) {
117 vo = eventToVEvent(ev); 119 vo = eventToVEvent(ev);
118 addVObjectProp(vcal, vo); 120 addVObjectProp(vcal, vo);
119 } 121 }
120 122
121 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); 123 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal);
122 cleanVObjects(vcal); 124 cleanVObjects(vcal);
123 cleanStrTbl(); 125 cleanStrTbl();
124 126
125 if (QFile::exists(fileName)) { 127 if (QFile::exists(fileName)) {
126 kdDebug(5800) << "No error" << endl; 128 kdDebug(5800) << "No error" << endl;
127 return true; 129 return true;
128 } else { 130 } else {
129 kdDebug(5800) << "Error" << endl; 131 kdDebug(5800) << "Error" << endl;
130 return false; // error 132 return false; // error
131 } 133 }
132} 134}
133 135
134bool VCalFormat::fromString( Calendar *calendar, const QString &text ) 136bool VCalFormat::fromString( Calendar *calendar, const QString &text )
135{ 137{
136 // TODO: Factor out VCalFormat::fromString() 138 // TODO: Factor out VCalFormat::fromString()
137 139
138 QCString data = text.utf8(); 140 QCString data = text.utf8();
139 141
140 if ( !data.size() ) return false; 142 if ( !data.size() ) return false;
141 143
142 VObject *vcal = Parse_MIME( data.data(), data.size()); 144 VObject *vcal = Parse_MIME( data.data(), data.size());
143 if ( !vcal ) return false; 145 if ( !vcal ) return false;
144 146
145 VObjectIterator i; 147 VObjectIterator i;
146 VObject *curvo; 148 VObject *curvo;
147 initPropIterator( &i, vcal ); 149 initPropIterator( &i, vcal );
148 150
149 // we only take the first object. TODO: parse all incidences. 151 // we only take the first object. TODO: parse all incidences.
150 do { 152 do {
151 curvo = nextVObject( &i ); 153 curvo = nextVObject( &i );
152 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 154 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
153 strcmp( vObjectName( curvo ), VCTodoProp ) ); 155 strcmp( vObjectName( curvo ), VCTodoProp ) );
154 156
155 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 157 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
156 Event *event = VEventToEvent( curvo ); 158 Event *event = VEventToEvent( curvo );
157 calendar->addEvent( event ); 159 calendar->addEvent( event );
158 } else { 160 } else {
159 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 161 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl;
160 deleteVObject( vcal ); 162 deleteVObject( vcal );
161 return false; 163 return false;
162 } 164 }
163 165
164 deleteVObject( vcal ); 166 deleteVObject( vcal );
165 167
166 return true; 168 return true;
167} 169}
168 170
169QString VCalFormat::eventToString( Event * event, Calendar *calendar) 171QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal)
170{ 172{
173
171 if ( !event ) return QString::null; 174 if ( !event ) return QString::null;
175 bool useL = useLocalTime;
176 useLocalTime = useLocal;
172 mCalendar = calendar; 177 mCalendar = calendar;
173 VObject *vevent = eventToVEvent( event ); 178 VObject *vevent = eventToVEvent( event );
174 char *buf = writeMemVObject( 0, 0, vevent ); 179 char *buf = writeMemVObject( 0, 0, vevent );
175 QString result( buf ); 180 QString result( buf );
176 cleanVObject( vevent ); 181 cleanVObject( vevent );
182 useLocalTime = useL;
177 return result; 183 return result;
178} 184}
179QString VCalFormat::todoToString( Todo * todo, Calendar *calendar ) 185QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal )
180{ 186{
187
181 if ( !todo ) return QString::null; 188 if ( !todo ) return QString::null;
189 bool useL = useLocalTime;
190 useLocalTime = useLocal;
182 mCalendar = calendar; 191 mCalendar = calendar;
183 VObject *vevent = eventToVTodo( todo ); 192 VObject *vevent = eventToVTodo( todo );
184 char *buf = writeMemVObject( 0, 0, vevent ); 193 char *buf = writeMemVObject( 0, 0, vevent );
185 QString result( buf ); 194 QString result( buf );
186 cleanVObject( vevent ); 195 cleanVObject( vevent );
196 useLocalTime = useL;
187 return result; 197 return result;
188} 198}
189 199
190QString VCalFormat::toString( Calendar *calendar ) 200QString VCalFormat::toString( Calendar *calendar )
191{ 201{
192 // TODO: Factor out VCalFormat::asString() 202 // TODO: Factor out VCalFormat::asString()
193 203
194 VObject *vcal = newVObject(VCCalProp); 204 VObject *vcal = newVObject(VCCalProp);
195 205
196 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 206 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
197 QString tmpStr = mCalendar->getTimeZoneStr(); 207 QString tmpStr = mCalendar->getTimeZoneStr();
198 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 208 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
199 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 209 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
200 210
201 // TODO: Use all data. 211 // TODO: Use all data.
202 QPtrList<Event> events = calendar->events(); 212 QPtrList<Event> events = calendar->events();
203 Event *event = events.first(); 213 Event *event = events.first();
204 if ( !event ) return QString::null; 214 if ( !event ) return QString::null;
205 215
206 VObject *vevent = eventToVEvent( event ); 216 VObject *vevent = eventToVEvent( event );
207 217
208 addVObjectProp( vcal, vevent ); 218 addVObjectProp( vcal, vevent );
209 219
210 char *buf = writeMemVObject( 0, 0, vcal ); 220 char *buf = writeMemVObject( 0, 0, vcal );
211 221
212 QString result( buf ); 222 QString result( buf );
213 223
214 cleanVObject( vcal ); 224 cleanVObject( vcal );
215 225
216 return result; 226 return result;
217} 227}
218 228
219VObject *VCalFormat::eventToVTodo(const Todo *anEvent) 229VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
220{ 230{
221 VObject *vtodo; 231 VObject *vtodo;
222 QString tmpStr; 232 QString tmpStr;
223 QStringList tmpStrList; 233 QStringList tmpStrList;
224 234
225 vtodo = newVObject(VCTodoProp); 235 vtodo = newVObject(VCTodoProp);
226 236
227 // due date 237 // due date
228 if (anEvent->hasDueDate()) { 238 if (anEvent->hasDueDate()) {
229 tmpStr = qDateTimeToISO(anEvent->dtDue(), 239 tmpStr = qDateTimeToISO(anEvent->dtDue(),
230 !anEvent->doesFloat()); 240 !anEvent->doesFloat());
231 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); 241 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit());
232 } 242 }
233 243
234 // start date 244 // start date
235 if (anEvent->hasStartDate()) { 245 if (anEvent->hasStartDate()) {
236 tmpStr = qDateTimeToISO(anEvent->dtStart(), 246 tmpStr = qDateTimeToISO(anEvent->dtStart(),
237 !anEvent->doesFloat()); 247 !anEvent->doesFloat());
238 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); 248 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit());
239 } 249 }
240 250
241 // creation date 251 // creation date
242 tmpStr = qDateTimeToISO(anEvent->created()); 252 tmpStr = qDateTimeToISO(anEvent->created());
243 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); 253 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit());
244 254
245 // unique id 255 // unique id
246 addPropValue(vtodo, VCUniqueStringProp, 256 addPropValue(vtodo, VCUniqueStringProp,
247 anEvent->uid().local8Bit()); 257 anEvent->uid().local8Bit());
248 258
249 // revision 259 // revision
250 tmpStr.sprintf("%i", anEvent->revision()); 260 tmpStr.sprintf("%i", anEvent->revision());
251 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); 261 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit());
252 262
253 // last modification date 263 // last modification date
254 tmpStr = qDateTimeToISO(anEvent->lastModified()); 264 tmpStr = qDateTimeToISO(anEvent->lastModified());
255 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); 265 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
256 266
257 // organizer stuff 267 // organizer stuff
258 tmpStr = "MAILTO:" + anEvent->organizer(); 268 tmpStr = "MAILTO:" + anEvent->organizer();
259 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); 269 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
260 270
261 // attendees 271 // attendees
262 if (anEvent->attendeeCount() != 0) { 272 if (anEvent->attendeeCount() != 0) {
263 QPtrList<Attendee> al = anEvent->attendees(); 273 QPtrList<Attendee> al = anEvent->attendees();
264 QPtrListIterator<Attendee> ai(al); 274 QPtrListIterator<Attendee> ai(al);
265 Attendee *curAttendee; 275 Attendee *curAttendee;
266 276
267 for (; ai.current(); ++ai) { 277 for (; ai.current(); ++ai) {
268 curAttendee = ai.current(); 278 curAttendee = ai.current();
269 if (!curAttendee->email().isEmpty() && 279 if (!curAttendee->email().isEmpty() &&
270 !curAttendee->name().isEmpty()) 280 !curAttendee->name().isEmpty())
271 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 281 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
272 curAttendee->email() + ">"; 282 curAttendee->email() + ">";
273 else if (curAttendee->name().isEmpty()) 283 else if (curAttendee->name().isEmpty())
274 tmpStr = "MAILTO: " + curAttendee->email(); 284 tmpStr = "MAILTO: " + curAttendee->email();
275 else if (curAttendee->email().isEmpty()) 285 else if (curAttendee->email().isEmpty())
276 tmpStr = "MAILTO: " + curAttendee->name(); 286 tmpStr = "MAILTO: " + curAttendee->name();
277 else if (curAttendee->name().isEmpty() && 287 else if (curAttendee->name().isEmpty() &&
278 curAttendee->email().isEmpty()) 288 curAttendee->email().isEmpty())
279 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 289 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
280 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); 290 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
281 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); 291 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
282 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 292 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
@@ -1341,195 +1351,194 @@ Event* VCalFormat::VEventToEvent(VObject *vevent)
1341 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 1351 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
1342 deleteStr(s); 1352 deleteStr(s);
1343 tmpStrList.clear(); 1353 tmpStrList.clear();
1344 index1 = 0; 1354 index1 = 0;
1345 index2 = 0; 1355 index2 = 0;
1346 QString resource; 1356 QString resource;
1347 while ((index2 = resources.find(';', index1)) != -1) { 1357 while ((index2 = resources.find(';', index1)) != -1) {
1348 resource = resources.mid(index1, (index2 - index1)); 1358 resource = resources.mid(index1, (index2 - index1));
1349 tmpStrList.append(resource); 1359 tmpStrList.append(resource);
1350 index1 = index2; 1360 index1 = index2;
1351 } 1361 }
1352 anEvent->setResources(tmpStrList); 1362 anEvent->setResources(tmpStrList);
1353 } 1363 }
1354 1364
1355 /* alarm stuff */ 1365 /* alarm stuff */
1356 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { 1366 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) {
1357 Alarm* alarm = anEvent->newAlarm(); 1367 Alarm* alarm = anEvent->newAlarm();
1358 VObject *a; 1368 VObject *a;
1359 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 1369 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
1360 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 1370 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
1361 deleteStr(s); 1371 deleteStr(s);
1362 } 1372 }
1363 alarm->setEnabled(true); 1373 alarm->setEnabled(true);
1364 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { 1374 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) {
1365 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 1375 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
1366 s = fakeCString(vObjectUStringZValue(a)); 1376 s = fakeCString(vObjectUStringZValue(a));
1367 alarm->setProcedureAlarm(QFile::decodeName(s)); 1377 alarm->setProcedureAlarm(QFile::decodeName(s));
1368 deleteStr(s); 1378 deleteStr(s);
1369 } 1379 }
1370 } 1380 }
1371 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { 1381 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) {
1372 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 1382 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
1373 s = fakeCString(vObjectUStringZValue(a)); 1383 s = fakeCString(vObjectUStringZValue(a));
1374 alarm->setAudioAlarm(QFile::decodeName(s)); 1384 alarm->setAudioAlarm(QFile::decodeName(s));
1375 deleteStr(s); 1385 deleteStr(s);
1376 } 1386 }
1377 } 1387 }
1378 } 1388 }
1379 1389
1380 // priority 1390 // priority
1381 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { 1391 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) {
1382 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1392 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1383 deleteStr(s); 1393 deleteStr(s);
1384 } 1394 }
1385 1395
1386 // transparency 1396 // transparency
1387 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { 1397 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) {
1388 int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); 1398 int i = atoi(s = fakeCString(vObjectUStringZValue(vo)));
1389 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); 1399 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque );
1390 deleteStr(s); 1400 deleteStr(s);
1391 } 1401 }
1392 1402
1393 // related event 1403 // related event
1394 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { 1404 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) {
1395 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 1405 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
1396 deleteStr(s); 1406 deleteStr(s);
1397 mEventsRelate.append(anEvent); 1407 mEventsRelate.append(anEvent);
1398 } 1408 }
1399 1409
1400 /* PILOT SYNC STUFF */ 1410 /* PILOT SYNC STUFF */
1401 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { 1411 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) {
1402 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1412 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1403 deleteStr(s); 1413 deleteStr(s);
1404 } 1414 }
1405 else 1415 else
1406 anEvent->setPilotId(0); 1416 anEvent->setPilotId(0);
1407 1417
1408 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { 1418 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) {
1409 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1419 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1410 deleteStr(s); 1420 deleteStr(s);
1411 } 1421 }
1412 else 1422 else
1413 anEvent->setSyncStatus(Event::SYNCMOD); 1423 anEvent->setSyncStatus(Event::SYNCMOD);
1414 1424
1415 return anEvent; 1425 return anEvent;
1416} 1426}
1417 1427
1418 1428
1419QString VCalFormat::qDateToISO(const QDate &qd) 1429QString VCalFormat::qDateToISO(const QDate &qd)
1420{ 1430{
1421 QString tmpStr; 1431 QString tmpStr;
1422 1432
1423 ASSERT(qd.isValid()); 1433 ASSERT(qd.isValid());
1424 1434
1425 tmpStr.sprintf("%.2d%.2d%.2d", 1435 tmpStr.sprintf("%.2d%.2d%.2d",
1426 qd.year(), qd.month(), qd.day()); 1436 qd.year(), qd.month(), qd.day());
1427 return tmpStr; 1437 return tmpStr;
1428 1438
1429} 1439}
1430 1440
1431QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) 1441QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu)
1432{ 1442{
1433 QString tmpStr; 1443 QString tmpStr;
1434 1444
1435 ASSERT(qdt.date().isValid()); 1445 ASSERT(qdt.date().isValid());
1436 ASSERT(qdt.time().isValid()); 1446 ASSERT(qdt.time().isValid());
1437 if (zulu) { 1447 if (zulu && !useLocalTime ) {
1438 QDateTime tmpDT(qdt); 1448 QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60);
1439 tmpDT = tmpDT.addSecs(60*(-mCalendar->getTimeZone())); // correct to GMT.
1440 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", 1449 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ",
1441 tmpDT.date().year(), tmpDT.date().month(), 1450 tmpDT.date().year(), tmpDT.date().month(),
1442 tmpDT.date().day(), tmpDT.time().hour(), 1451 tmpDT.date().day(), tmpDT.time().hour(),
1443 tmpDT.time().minute(), tmpDT.time().second()); 1452 tmpDT.time().minute(), tmpDT.time().second());
1444 } else { 1453 } else {
1445 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", 1454 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d",
1446 qdt.date().year(), qdt.date().month(), 1455 qdt.date().year(), qdt.date().month(),
1447 qdt.date().day(), qdt.time().hour(), 1456 qdt.date().day(), qdt.time().hour(),
1448 qdt.time().minute(), qdt.time().second()); 1457 qdt.time().minute(), qdt.time().second());
1449 } 1458 }
1450 return tmpStr; 1459 return tmpStr;
1451} 1460}
1452 1461
1453QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) 1462QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr)
1454{ 1463{
1455 QDate tmpDate; 1464 QDate tmpDate;
1456 QTime tmpTime; 1465 QTime tmpTime;
1457 QString tmpStr; 1466 QString tmpStr;
1458 int year, month, day, hour, minute, second; 1467 int year, month, day, hour, minute, second;
1459 1468
1460 tmpStr = dtStr; 1469 tmpStr = dtStr;
1461 year = tmpStr.left(4).toInt(); 1470 year = tmpStr.left(4).toInt();
1462 month = tmpStr.mid(4,2).toInt(); 1471 month = tmpStr.mid(4,2).toInt();
1463 day = tmpStr.mid(6,2).toInt(); 1472 day = tmpStr.mid(6,2).toInt();
1464 hour = tmpStr.mid(9,2).toInt(); 1473 hour = tmpStr.mid(9,2).toInt();
1465 minute = tmpStr.mid(11,2).toInt(); 1474 minute = tmpStr.mid(11,2).toInt();
1466 second = tmpStr.mid(13,2).toInt(); 1475 second = tmpStr.mid(13,2).toInt();
1467 tmpDate.setYMD(year, month, day); 1476 tmpDate.setYMD(year, month, day);
1468 tmpTime.setHMS(hour, minute, second); 1477 tmpTime.setHMS(hour, minute, second);
1469 1478
1470 ASSERT(tmpDate.isValid()); 1479 ASSERT(tmpDate.isValid());
1471 ASSERT(tmpTime.isValid()); 1480 ASSERT(tmpTime.isValid());
1472 QDateTime tmpDT(tmpDate, tmpTime); 1481 QDateTime tmpDT(tmpDate, tmpTime);
1473 // correct for GMT if string is in Zulu format 1482 // correct for GMT if string is in Zulu format
1474 if (dtStr.at(dtStr.length()-1) == 'Z') 1483 if (dtStr.at(dtStr.length()-1) == 'Z')
1475 tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone()); 1484 tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone());
1476 return tmpDT; 1485 return tmpDT;
1477} 1486}
1478 1487
1479QDate VCalFormat::ISOToQDate(const QString &dateStr) 1488QDate VCalFormat::ISOToQDate(const QString &dateStr)
1480{ 1489{
1481 int year, month, day; 1490 int year, month, day;
1482 1491
1483 year = dateStr.left(4).toInt(); 1492 year = dateStr.left(4).toInt();
1484 month = dateStr.mid(4,2).toInt(); 1493 month = dateStr.mid(4,2).toInt();
1485 day = dateStr.mid(6,2).toInt(); 1494 day = dateStr.mid(6,2).toInt();
1486 1495
1487 return(QDate(year, month, day)); 1496 return(QDate(year, month, day));
1488} 1497}
1489 1498
1490// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1499// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1491// and break it down from it's tree-like format into the dictionary format 1500// and break it down from it's tree-like format into the dictionary format
1492// that is used internally in the VCalFormat. 1501// that is used internally in the VCalFormat.
1493void VCalFormat::populate(VObject *vcal) 1502void VCalFormat::populate(VObject *vcal)
1494{ 1503{
1495 // this function will populate the caldict dictionary and other event 1504 // this function will populate the caldict dictionary and other event
1496 // lists. It turns vevents into Events and then inserts them. 1505 // lists. It turns vevents into Events and then inserts them.
1497 1506
1498 VObjectIterator i; 1507 VObjectIterator i;
1499 VObject *curVO, *curVOProp; 1508 VObject *curVO, *curVOProp;
1500 Event *anEvent; 1509 Event *anEvent;
1501 1510
1502 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1511 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1503 char *methodType = 0; 1512 char *methodType = 0;
1504 methodType = fakeCString(vObjectUStringZValue(curVO)); 1513 methodType = fakeCString(vObjectUStringZValue(curVO));
1505 kdDebug() << "This calendar is an iTIP transaction of type '" 1514 kdDebug() << "This calendar is an iTIP transaction of type '"
1506 << methodType << "'" << endl; 1515 << methodType << "'" << endl;
1507 delete methodType; 1516 delete methodType;
1508 } 1517 }
1509 1518
1510 // warn the user that we might have trouble reading non-known calendar. 1519 // warn the user that we might have trouble reading non-known calendar.
1511 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { 1520 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) {
1512 char *s = fakeCString(vObjectUStringZValue(curVO)); 1521 char *s = fakeCString(vObjectUStringZValue(curVO));
1513 if (strcmp(productId().local8Bit(), s) != 0) 1522 if (strcmp(productId().local8Bit(), s) != 0)
1514 kdDebug() << "This vCalendar file was not created by KOrganizer " 1523 kdDebug() << "This vCalendar file was not created by KOrganizer "
1515 "or any other product we support. Loading anyway..." << endl; 1524 "or any other product we support. Loading anyway..." << endl;
1516 mLoadedProductId = s; 1525 mLoadedProductId = s;
1517 deleteStr(s); 1526 deleteStr(s);
1518 } 1527 }
1519 1528
1520 // warn the user we might have trouble reading this unknown version. 1529 // warn the user we might have trouble reading this unknown version.
1521 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1530 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1522 char *s = fakeCString(vObjectUStringZValue(curVO)); 1531 char *s = fakeCString(vObjectUStringZValue(curVO));
1523 if (strcmp(_VCAL_VERSION, s) != 0) 1532 if (strcmp(_VCAL_VERSION, s) != 0)
1524 kdDebug() << "This vCalendar file has version " << s 1533 kdDebug() << "This vCalendar file has version " << s
1525 << "We only support " << _VCAL_VERSION << endl; 1534 << "We only support " << _VCAL_VERSION << endl;
1526 deleteStr(s); 1535 deleteStr(s);
1527 } 1536 }
1528 1537
1529 // set the time zone 1538 // set the time zone
1530 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1539 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1531 char *s = fakeCString(vObjectUStringZValue(curVO)); 1540 char *s = fakeCString(vObjectUStringZValue(curVO));
1532 mCalendar->setTimeZone(s); 1541 mCalendar->setTimeZone(s);
1533 deleteStr(s); 1542 deleteStr(s);
1534 } 1543 }
1535 1544
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h
index 7b9ca26..848be78 100644
--- a/libkcal/vcalformat.h
+++ b/libkcal/vcalformat.h
@@ -1,110 +1,111 @@
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 _VCALFORMAT_H 22#ifndef _VCALFORMAT_H
23#define _VCALFORMAT_H 23#define _VCALFORMAT_H
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#define _VCAL_VERSION "1.0" 27#define _VCAL_VERSION "1.0"
28 28
29class VObject; 29class VObject;
30 30
31namespace KCal { 31namespace KCal {
32 32
33/** 33/**
34 This class implements the vCalendar format. It provides methods for 34 This class implements the vCalendar format. It provides methods for
35 loading/saving/converting vCalendar format data into the internal KOrganizer 35 loading/saving/converting vCalendar format data into the internal KOrganizer
36 representation as Calendar and Events. 36 representation as Calendar and Events.
37 37
38 @short vCalendar format implementation 38 @short vCalendar format implementation
39*/ 39*/
40class VCalFormat : public CalFormat { 40class VCalFormat : public CalFormat {
41 public: 41 public:
42 VCalFormat(); 42 VCalFormat();
43 virtual ~VCalFormat(); 43 virtual ~VCalFormat();
44 44
45 /** loads a calendar on disk in vCalendar format into the current calendar. 45 /** loads a calendar on disk in vCalendar format into the current calendar.
46 * any information already present is lost. Returns TRUE if successful, 46 * any information already present is lost. Returns TRUE if successful,
47 * else returns FALSE. 47 * else returns FALSE.
48 * @param fileName the name of the calendar on disk. 48 * @param fileName the name of the calendar on disk.
49 */ 49 */
50 bool load(Calendar *,const QString &fileName); 50 bool load(Calendar *,const QString &fileName);
51 /** writes out the calendar to disk in vCalendar format. Returns true if 51 /** writes out the calendar to disk in vCalendar format. Returns true if
52 * successful and false on error. 52 * successful and false on error.
53 * @param fileName the name of the file 53 * @param fileName the name of the file
54 */ 54 */
55 bool save(Calendar *,const QString &fileName); 55 bool save(Calendar *,const QString &fileName);
56 56
57 /** 57 /**
58 Parse string and populate calendar with that information. 58 Parse string and populate calendar with that information.
59 */ 59 */
60 bool fromString( Calendar *, const QString & ); 60 bool fromString( Calendar *, const QString & );
61 /** 61 /**
62 Return calendar information as string. 62 Return calendar information as string.
63 */ 63 */
64 QString toString( Calendar * ); 64 QString toString( Calendar * );
65 QString eventToString( Event *, Calendar *calendar ); 65 QString eventToString( Event *, Calendar *calendar, bool useLocalTime = true );
66 QString todoToString( Todo * ,Calendar *calendar ); 66 QString todoToString( Todo * ,Calendar *calendar, bool useLocalTime = true );
67 67
68 protected: 68 protected:
69 /** translates a VObject of the TODO type into a Event */ 69 /** translates a VObject of the TODO type into a Event */
70 Todo *VTodoToEvent(VObject *vtodo); 70 Todo *VTodoToEvent(VObject *vtodo);
71 /** translates a VObject into a Event and returns a pointer to it. */ 71 /** translates a VObject into a Event and returns a pointer to it. */
72 Event *VEventToEvent(VObject *vevent); 72 Event *VEventToEvent(VObject *vevent);
73 /** translate a Event into a VTodo-type VObject and return pointer */ 73 /** translate a Event into a VTodo-type VObject and return pointer */
74 VObject *eventToVTodo(const Todo *anEvent); 74 VObject *eventToVTodo(const Todo *anEvent);
75 /** translate a Event into a VObject and returns a pointer to it. */ 75 /** translate a Event into a VObject and returns a pointer to it. */
76 VObject* eventToVEvent(const Event *anEvent); 76 VObject* eventToVEvent(const Event *anEvent);
77 77
78 /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ 78 /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */
79 QString qDateToISO(const QDate &); 79 QString qDateToISO(const QDate &);
80 /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ 80 /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */
81 QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); 81 QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE);
82 /** takes a string in the format YYYYMMDDTHHMMSS and returns a 82 /** takes a string in the format YYYYMMDDTHHMMSS and returns a
83 * valid QDateTime. */ 83 * valid QDateTime. */
84 QDateTime ISOToQDateTime(const QString & dtStr); 84 QDateTime ISOToQDateTime(const QString & dtStr);
85 /** takes a string in the format YYYYMMDD and returns a 85 /** takes a string in the format YYYYMMDD and returns a
86 * valid QDate. */ 86 * valid QDate. */
87 QDate ISOToQDate(const QString & dtStr); 87 QDate ISOToQDate(const QString & dtStr);
88 /** takes a vCalendar tree of VObjects, and puts all of them that have 88 /** takes a vCalendar tree of VObjects, and puts all of them that have
89 * the "event" property into the dictionary, todos in the todo-list, etc. */ 89 * the "event" property into the dictionary, todos in the todo-list, etc. */
90 void populate(VObject *vcal); 90 void populate(VObject *vcal);
91 91
92 /** takes a number 0 - 6 and returns the two letter string of that day, 92 /** takes a number 0 - 6 and returns the two letter string of that day,
93 * i.e. MO, TU, WE, etc. */ 93 * i.e. MO, TU, WE, etc. */
94 const char *dayFromNum(int day); 94 const char *dayFromNum(int day);
95 /** the reverse of the above function. */ 95 /** the reverse of the above function. */
96 int numFromDay(const QString &day); 96 int numFromDay(const QString &day);
97 97
98 Attendee::PartStat readStatus(const char *s) const; 98 Attendee::PartStat readStatus(const char *s) const;
99 QCString writeStatus(Attendee::PartStat status) const; 99 QCString writeStatus(Attendee::PartStat status) const;
100 100
101 private: 101 private:
102 Calendar *mCalendar; 102 Calendar *mCalendar;
103 bool useLocalTime;
103 104
104 QPtrList<Event> mEventsRelate; // events with relations 105 QPtrList<Event> mEventsRelate; // events with relations
105 QPtrList<Todo> mTodosRelate; // todos with relations 106 QPtrList<Todo> mTodosRelate; // todos with relations
106}; 107};
107 108
108} 109}
109 110
110#endif 111#endif