summaryrefslogtreecommitdiffabout
path: root/libkcal/phoneformat.cpp
Unidiff
Diffstat (limited to 'libkcal/phoneformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 900fc04..794e4b4 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -13,33 +13,34 @@
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 <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <q3ptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <q3textstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qdir.h> 32#include <qdir.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <QDesktopWidget>
34 35
35#include <kdebug.h> 36#include <kdebug.h>
36#include <klocale.h> 37#include <klocale.h>
37#include <kglobal.h> 38#include <kglobal.h>
38#include <kmessagebox.h> 39#include <kmessagebox.h>
39#include <phoneaccess.h> 40#include <phoneaccess.h>
40 41
41#include "calendar.h" 42#include "calendar.h"
42#include "alarm.h" 43#include "alarm.h"
43#include "recurrence.h" 44#include "recurrence.h"
44#include "calendarlocal.h" 45#include "calendarlocal.h"
45 46
@@ -192,25 +193,25 @@ ulong PhoneFormat::getCsumEvent( Event* event )
192 } 193 }
193 //pending weekdays 194 //pending weekdays
194 writeEndDate = true; 195 writeEndDate = true;
195 196
196 break; 197 break;
197 case Recurrence::rMonthlyPos:// 2 198 case Recurrence::rMonthlyPos:// 2
198 list.append( "2" ); 199 list.append( "2" );
199 list.append( QString::number( rec->frequency()) );//12 200 list.append( QString::number( rec->frequency()) );//12
200 201
201 writeEndDate = true; 202 writeEndDate = true;
202 { 203 {
203 int count = 1; 204 int count = 1;
204 QPtrList<Recurrence::rMonthPos> rmp; 205 Q3PtrList<Recurrence::rMonthPos> rmp;
205 rmp = rec->monthPositions(); 206 rmp = rec->monthPositions();
206 if ( rmp.first()->negative ) 207 if ( rmp.first()->negative )
207 count = 5 - rmp.first()->rPos - 1; 208 count = 5 - rmp.first()->rPos - 1;
208 else 209 else
209 count = rmp.first()->rPos - 1; 210 count = rmp.first()->rPos - 1;
210 list.append( QString::number( count ) ); 211 list.append( QString::number( count ) );
211 212
212 } 213 }
213 214
214 list.append( "0" ); 215 list.append( "0" );
215 break; 216 break;
216 case Recurrence::rMonthlyDay:// 3 217 case Recurrence::rMonthlyDay:// 3
@@ -232,25 +233,25 @@ ulong PhoneFormat::getCsumEvent( Event* event )
232 list.append( "255" ); 233 list.append( "255" );
233 list.append( QString() ); 234 list.append( QString() );
234 list.append( "0" ); 235 list.append( "0" );
235 list.append( QString() ); 236 list.append( QString() );
236 list.append( "0" ); 237 list.append( "0" );
237 list.append( "20991231T000000" ); 238 list.append( "20991231T000000" );
238 break; 239 break;
239 } 240 }
240 if ( writeEndDate ) { 241 if ( writeEndDate ) {
241 242
242 if ( rec->endDate().isValid() ) { // 15 + 16 243 if ( rec->endDate().isValid() ) { // 15 + 16
243 list.append( "1" ); 244 list.append( "1" );
244 list.append( PhoneParser::dtToString( rec->endDate()) ); 245 list.append( PhoneParser::dtToString( (QDateTime)rec->endDate()) );
245 } else { 246 } else {
246 list.append( "0" ); 247 list.append( "0" );
247 list.append( "20991231T000000" ); 248 list.append( "20991231T000000" );
248 } 249 }
249 250
250 } 251 }
251 attList << list.join(""); 252 attList << list.join("");
252 attList << event->categoriesStr(); 253 attList << event->categoriesStr();
253 //qDebug("csum cat %s", event->categoriesStr().latin1()); 254 //qDebug("csum cat %s", event->categoriesStr().latin1());
254 255
255 attList << event->secrecyStr(); 256 attList << event->secrecyStr();
256 return PhoneFormat::getCsum(attList ); 257 return PhoneFormat::getCsum(attList );
@@ -296,25 +297,25 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
296 fileName = "/tmp/phonefile.vcs"; 297 fileName = "/tmp/phonefile.vcs";
297#endif 298#endif
298 QString command; 299 QString command;
299 if ( ! PhoneAccess::readFromPhone( fileName )) { 300 if ( ! PhoneAccess::readFromPhone( fileName )) {
300 return false; 301 return false;
301 } 302 }
302 VCalFormat vfload; 303 VCalFormat vfload;
303 vfload.setLocalTime ( true ); 304 vfload.setLocalTime ( true );
304 qDebug("loading file ..."); 305 qDebug("loading file ...");
305 306
306 if ( ! vfload.load( calendar, fileName ) ) 307 if ( ! vfload.load( calendar, fileName ) )
307 return false; 308 return false;
308 QPtrList<Event> er = calendar->rawEvents(); 309 Q3PtrList<Event> er = calendar->rawEvents();
309 Event* ev = er.first(); 310 Event* ev = er.first();
310 qDebug("reading events... "); 311 qDebug("reading events... ");
311 while ( ev ) { 312 while ( ev ) {
312 QStringList cat = ev->categories(); 313 QStringList cat = ev->categories();
313 if ( cat.contains( "MeetingDEF" )) { 314 if ( cat.contains( "MeetingDEF" )) {
314 ev->setCategories( QStringList() ); 315 ev->setCategories( QStringList() );
315 } else 316 } else
316 if ( cat.contains( "Birthday" )) { 317 if ( cat.contains( "Birthday" )) {
317 ev->setFloats( true ); 318 ev->setFloats( true );
318 QDate da = ev->dtStart().date(); 319 QDate da = ev->dtStart().date();
319 ev->setDtStart( QDateTime( da) ); 320 ev->setDtStart( QDateTime( da) );
320 ev->setDtEnd( QDateTime( da.addDays(1)) ); 321 ev->setDtEnd( QDateTime( da.addDays(1)) );
@@ -331,25 +332,25 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
331 calendar->deleteEvent( ev ); 332 calendar->deleteEvent( ev );
332 calendar->addEvent( event); 333 calendar->addEvent( event);
333 } 334 }
334 else 335 else
335 event = ev; 336 event = ev;
336 event->setCsum( mProfileName, QString::number( cSum )); 337 event->setCsum( mProfileName, QString::number( cSum ));
337 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 338 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
338 event->setID( mProfileName,QString::number( id ) ); 339 event->setID( mProfileName,QString::number( id ) );
339 ev = er.next(); 340 ev = er.next();
340 } 341 }
341 { 342 {
342 qDebug("reading todos... "); 343 qDebug("reading todos... ");
343 QPtrList<Todo> tr = calendar->rawTodos(); 344 Q3PtrList<Todo> tr = calendar->rawTodos();
344 Todo* ev = tr.first(); 345 Todo* ev = tr.first();
345 while ( ev ) { 346 while ( ev ) {
346 347
347 QStringList cat = ev->categories(); 348 QStringList cat = ev->categories();
348 if ( cat.contains( "MeetingDEF" )) { 349 if ( cat.contains( "MeetingDEF" )) {
349 ev->setCategories( QStringList() ); 350 ev->setCategories( QStringList() );
350 } 351 }
351 int id = ev->pilotId(); 352 int id = ev->pilotId();
352 uint cSum; 353 uint cSum;
353 cSum = PhoneFormat::getCsumTodo( ev ); 354 cSum = PhoneFormat::getCsumTodo( ev );
354 Todo *event; 355 Todo *event;
355 event = existingCal->todo( mProfileName ,QString::number( id ) ); 356 event = existingCal->todo( mProfileName ,QString::number( id ) );
@@ -456,25 +457,25 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from )
456 // set percentcomplete only, if to->isCompleted() 457 // set percentcomplete only, if to->isCompleted()
457 if ( to->isCompleted() ) 458 if ( to->isCompleted() )
458 to->setPercentComplete(from->percentComplete()); 459 to->setPercentComplete(from->percentComplete());
459 } 460 }
460 if( to->priority() == 2 && from->priority() == 1 ) 461 if( to->priority() == 2 && from->priority() == 1 )
461 ; //skip 462 ; //skip
462 else if (to->priority() == 4 && from->priority() == 5 ) 463 else if (to->priority() == 4 && from->priority() == 5 )
463 ; 464 ;
464 else 465 else
465 to->setPriority(from->priority()); 466 to->setPriority(from->priority());
466 467
467} 468}
468#include <qcstring.h> 469#include <q3cstring.h>
469 470
470void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum) 471void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum)
471{ 472{
472 inc->setID( mProfileName, id ); 473 inc->setID( mProfileName, id );
473 inc->setCsum( mProfileName, csum); 474 inc->setCsum( mProfileName, csum);
474 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 475 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
475 476
476} 477}
477 478
478bool PhoneFormat::writeToPhone( Calendar * calendar) 479bool PhoneFormat::writeToPhone( Calendar * calendar)
479{ 480{
480#ifdef DESKTOP_VERSION 481#ifdef DESKTOP_VERSION
@@ -488,36 +489,36 @@ bool PhoneFormat::writeToPhone( Calendar * calendar)
488 QString id = calendar->timeZoneId(); 489 QString id = calendar->timeZoneId();
489 calendar->setLocalTime(); 490 calendar->setLocalTime();
490 if ( ! vfsave.save( calendar, fileName ) ) 491 if ( ! vfsave.save( calendar, fileName ) )
491 return false; 492 return false;
492 calendar->setTimeZoneId( id ); 493 calendar->setTimeZoneId( id );
493 return PhoneAccess::writeToPhone( fileName ); 494 return PhoneAccess::writeToPhone( fileName );
494} 495}
495bool PhoneFormat::save( Calendar *calendar) 496bool PhoneFormat::save( Calendar *calendar)
496{ 497{
497 498
498 499
499 // 1 remove events which should be deleted 500 // 1 remove events which should be deleted
500 QPtrList<Event> er = calendar->rawEvents(); 501 Q3PtrList<Event> er = calendar->rawEvents();
501 Event* ev = er.first(); 502 Event* ev = er.first();
502 while ( ev ) { 503 while ( ev ) {
503 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 504 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
504 calendar->deleteEvent( ev ); 505 calendar->deleteEvent( ev );
505 } else { 506 } else {
506 507
507 } 508 }
508 ev = er.next(); 509 ev = er.next();
509 } 510 }
510 // 2 remove todos which should be deleted 511 // 2 remove todos which should be deleted
511 QPtrList<Todo> tl = calendar->rawTodos(); 512 Q3PtrList<Todo> tl = calendar->rawTodos();
512 Todo* to = tl.first(); 513 Todo* to = tl.first();
513 while ( to ) { 514 while ( to ) {
514 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 515 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
515 calendar->deleteTodo( to ); 516 calendar->deleteTodo( to );
516 } else { 517 } else {
517 if ( to->isCompleted()) { 518 if ( to->isCompleted()) {
518 calendar->deleteTodo( to ); 519 calendar->deleteTodo( to );
519 } 520 }
520 } 521 }
521 to = tl.next(); 522 to = tl.next();
522 } 523 }
523 // 3 save file 524 // 3 save file
@@ -543,25 +544,25 @@ bool PhoneFormat::save( Calendar *calendar)
543 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 544 calendarTemp->setTimeZoneId( calendar->timeZoneId());
544 if ( ! load( calendarTemp,calendar) ){ 545 if ( ! load( calendarTemp,calendar) ){
545 qDebug("error reloading calendar "); 546 qDebug("error reloading calendar ");
546 delete calendarTemp; 547 delete calendarTemp;
547 return false; 548 return false;
548 } 549 }
549 // 6 compare data 550 // 6 compare data
550 551
551//algo 6 compare event 552//algo 6 compare event
552 er = calendar->rawEvents(); 553 er = calendar->rawEvents();
553 ev = er.first(); 554 ev = er.first();
554 message = i18n(" Comparing event # "); 555 message = i18n(" Comparing event # ");
555 QPtrList<Event> er1 = calendarTemp->rawEvents(); 556 Q3PtrList<Event> er1 = calendarTemp->rawEvents();
556 Event* ev1; 557 Event* ev1;
557 int procCount = 0; 558 int procCount = 0;
558 while ( ev ) { 559 while ( ev ) {
559 //qDebug("event new ID %s",ev->summary().latin1()); 560 //qDebug("event new ID %s",ev->summary().latin1());
560 status.setText ( message + QString::number ( ++procCount ) ); 561 status.setText ( message + QString::number ( ++procCount ) );
561 qApp->processEvents(); 562 qApp->processEvents();
562 ev1 = er1.first(); 563 ev1 = er1.first();
563 while ( ev1 ) { 564 while ( ev1 ) {
564 if ( ev->contains( ev1 ) ) { 565 if ( ev->contains( ev1 ) ) {
565 afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName)); 566 afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName));
566 er1.remove( ev1 ); 567 er1.remove( ev1 );
567 break; 568 break;
@@ -571,25 +572,25 @@ bool PhoneFormat::save( Calendar *calendar)
571 if ( ! ev1 ) { 572 if ( ! ev1 ) {
572 // ev->removeID(mProfileName); 573 // ev->removeID(mProfileName);
573 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 574 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
574 } 575 }
575 576
576 577
577 ev = er.next(); 578 ev = er.next();
578 } 579 }
579 //algo 6 compare todo 580 //algo 6 compare todo
580 tl = calendar->rawTodos(); 581 tl = calendar->rawTodos();
581 to = tl.first(); 582 to = tl.first();
582 procCount = 0; 583 procCount = 0;
583 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 584 Q3PtrList<Todo> tl1 = calendarTemp->rawTodos();
584 Todo* to1 ; 585 Todo* to1 ;
585 message = i18n(" Comparing todo # "); 586 message = i18n(" Comparing todo # ");
586 while ( to ) { 587 while ( to ) {
587 status.setText ( message + QString::number ( ++procCount ) ); 588 status.setText ( message + QString::number ( ++procCount ) );
588 qApp->processEvents(); 589 qApp->processEvents();
589 Todo* to1 = tl1.first(); 590 Todo* to1 = tl1.first();
590 while ( to1 ) { 591 while ( to1 ) {
591 if ( to->contains( to1 ) ) { 592 if ( to->contains( to1 ) ) {
592 afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName)); 593 afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName));
593 tl1.remove( to1 ); 594 tl1.remove( to1 );
594 break; 595 break;
595 } 596 }