summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-09-12 13:11:10 (UTC)
committer zautrix <zautrix>2004-09-12 13:11:10 (UTC)
commitb2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26 (patch) (unidiff)
treea25dbba0cac09b7a7892405b11eb08c7d02e6b6b /libkcal
parent3c954091cb8d90c185403c68a8bbbb2a961f67fe (diff)
downloadkdepimpi-b2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26.zip
kdepimpi-b2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26.tar.gz
kdepimpi-b2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26.tar.bz2
many phonesync fixes
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp53
1 files changed, 45 insertions, 8 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 2ad1b5a..6df639f 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -22,32 +22,33 @@
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 <qptrlist.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 <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38#include <kmessagebox.h>
38 39
39#include "calendar.h" 40#include "calendar.h"
40#include "alarm.h" 41#include "alarm.h"
41#include "recurrence.h" 42#include "recurrence.h"
42#include "calendarlocal.h" 43#include "calendarlocal.h"
43 44
44#include "phoneformat.h" 45#include "phoneformat.h"
45#include "syncdefines.h" 46#include "syncdefines.h"
46 47
47using namespace KCal; 48using namespace KCal;
48class PhoneParser : public QObject 49class PhoneParser : public QObject
49{ 50{
50public: 51public:
51 PhoneParser( ) { 52 PhoneParser( ) {
52 ; 53 ;
53 } 54 }
@@ -233,101 +234,117 @@ ulong PhoneFormat::getCsumEvent( Event* event )
233 list.append( "20991231T000000" ); 234 list.append( "20991231T000000" );
234 break; 235 break;
235 } 236 }
236 if ( writeEndDate ) { 237 if ( writeEndDate ) {
237 238
238 if ( rec->endDate().isValid() ) { // 15 + 16 239 if ( rec->endDate().isValid() ) { // 15 + 16
239 list.append( "1" ); 240 list.append( "1" );
240 list.append( PhoneParser::dtToString( rec->endDate()) ); 241 list.append( PhoneParser::dtToString( rec->endDate()) );
241 } else { 242 } else {
242 list.append( "0" ); 243 list.append( "0" );
243 list.append( "20991231T000000" ); 244 list.append( "20991231T000000" );
244 } 245 }
245 246
246 } 247 }
247 attList << list.join(""); 248 attList << list.join("");
248 attList << event->categoriesStr(); 249 attList << event->categoriesStr();
250 //qDebug("csum cat %s", event->categoriesStr().latin1());
251
249 attList << event->secrecyStr(); 252 attList << event->secrecyStr();
250 return PhoneFormat::getCsum(attList ); 253 return PhoneFormat::getCsum(attList );
251} 254}
252ulong PhoneFormat::getCsum( const QStringList & attList) 255ulong PhoneFormat::getCsum( const QStringList & attList)
253{ 256{
254 int max = attList.count() -1; 257 int max = attList.count() -1;
255 ulong cSum = 0; 258 ulong cSum = 0;
256 int j,k,i; 259 int j,k,i;
257 int add; 260 int add;
258 for ( i = 1; i < max ; ++i ) { 261 for ( i = 1; i < max ; ++i ) {
259 QString s = attList[i]; 262 QString s = attList[i];
260 if ( ! s.isEmpty() ){ 263 if ( ! s.isEmpty() ){
261 j = s.length(); 264 j = s.length();
262 for ( k = 0; k < j; ++k ) { 265 for ( k = 0; k < j; ++k ) {
263 int mul = k +1; 266 int mul = k +1;
264 add = s[k].unicode (); 267 add = s[k].unicode ();
265 if ( k < 16 ) 268 if ( k < 16 )
266 mul = mul * mul; 269 mul = mul * mul;
267 add = add * mul *i*i*i; 270 add = add * mul *i*i*i;
268 cSum += add; 271 cSum += add;
269 } 272 }
270 } 273 }
271 } 274 }
275 //QString dump = attList.join(",");
276 //qDebug("csum: %s", dump.latin1());
277
272 return cSum; 278 return cSum;
273 279
274} 280}
275//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 281//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
276#include <stdlib.h> 282#include <stdlib.h>
277#define DEBUGMODE false 283#define DEBUGMODE false
278bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 284bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
279{ 285{
280 286
281 QString fileName; 287 QString fileName;
282#ifdef _WIN32_ 288#ifdef _WIN32_
283 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 289 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
284#else 290#else
285 fileName = "/tmp/kdepimtemp.vcs"; 291 fileName = "/tmp/kdepimtemp.vcs";
286#endif 292#endif
287 QString command ="./kammu --backup " + fileName + " -yes -C" + 293 QString command ="./kammu --backup " + fileName + " -yes -C" +
288 mConnection +" -D" + mDevice +" -M" + mModel; 294 mConnection +" -D" + mDevice +" -M" + mModel;
289 int ret = system ( command.latin1() ); 295 int ret = system ( command.latin1() );
290 if ( ret != 0 ) 296 if ( ret != 0 ) {
297 qDebug("Error::command returned %d", ret);
291 return false; 298 return false;
299 }
300 qDebug("Command returned %d", ret);
292 VCalFormat vfload; 301 VCalFormat vfload;
293 vfload.setLocalTime ( true ); 302 vfload.setLocalTime ( true );
303 qDebug("loading file ...");
304
294 if ( ! vfload.load( calendar, fileName ) ) 305 if ( ! vfload.load( calendar, fileName ) )
295 return false; 306 return false;
296 QPtrList<Event> er = calendar->rawEvents(); 307 QPtrList<Event> er = calendar->rawEvents();
297 Event* ev = er.first(); 308 Event* ev = er.first();
309 qDebug("reading events... ");
298 while ( ev ) { 310 while ( ev ) {
311 QStringList cat = ev->categories();
312 if ( cat.contains( "MeetingDEF" )) {
313 ev->setCategories( QStringList() );
314 }
299 int id = ev->pilotId(); 315 int id = ev->pilotId();
300 Event *event; 316 Event *event;
301 event = existingCal->event( mProfileName ,QString::number( id ) ); 317 event = existingCal->event( mProfileName ,QString::number( id ) );
302 if ( event ) { 318 if ( event ) {
303 event = (Event*)event->clone(); 319 event = (Event*)event->clone();
304 copyEvent( event, ev ); 320 copyEvent( event, ev );
305 calendar->deleteEvent( ev ); 321 calendar->deleteEvent( ev );
306 calendar->addEvent( event); 322 calendar->addEvent( event);
307 } 323 }
308 else 324 else
309 event = ev; 325 event = ev;
310 uint cSum; 326 uint cSum;
311 cSum = PhoneFormat::getCsumEvent( event ); 327 cSum = PhoneFormat::getCsumEvent( event );
312 event->setCsum( mProfileName, QString::number( cSum )); 328 event->setCsum( mProfileName, QString::number( cSum ));
313 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 329 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
314 event->setID( mProfileName,QString::number( id ) ); 330 event->setID( mProfileName,QString::number( id ) );
315 ev = er.next(); 331 ev = er.next();
316 } 332 }
317 { 333 {
334 qDebug("reading todos... ");
318 QPtrList<Todo> tr = calendar->rawTodos(); 335 QPtrList<Todo> tr = calendar->rawTodos();
319 Todo* ev = tr.first(); 336 Todo* ev = tr.first();
320 while ( ev ) { 337 while ( ev ) {
321 338
322 QStringList cat = ev->categories(); 339 QStringList cat = ev->categories();
323 if ( cat.contains( "MeetingDEF" )) { 340 if ( cat.contains( "MeetingDEF" )) {
324 ev->setCategories( QStringList() ); 341 ev->setCategories( QStringList() );
325 } 342 }
326 int id = ev->pilotId(); 343 int id = ev->pilotId();
327 Todo *event; 344 Todo *event;
328 event = existingCal->todo( mProfileName ,QString::number( id ) ); 345 event = existingCal->todo( mProfileName ,QString::number( id ) );
329 if ( event ) { 346 if ( event ) {
330 event = (Todo*)event->clone(); 347 event = (Todo*)event->clone();
331 copyTodo( event, ev ); 348 copyTodo( event, ev );
332 calendar->deleteTodo( ev ); 349 calendar->deleteTodo( ev );
333 calendar->addTodo( event); 350 calendar->addTodo( event);
@@ -469,98 +486,118 @@ bool PhoneFormat::save( Calendar *calendar)
469 while ( ev ) { 486 while ( ev ) {
470 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 487 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
471 calendar->deleteEvent( ev ); 488 calendar->deleteEvent( ev );
472 } else { 489 } else {
473 490
474 } 491 }
475 ev = er.next(); 492 ev = er.next();
476 } 493 }
477 // 2 remove todos which should be deleted 494 // 2 remove todos which should be deleted
478 QPtrList<Todo> tl = calendar->rawTodos(); 495 QPtrList<Todo> tl = calendar->rawTodos();
479 Todo* to = tl.first(); 496 Todo* to = tl.first();
480 while ( to ) { 497 while ( to ) {
481 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 498 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
482 calendar->deleteTodo( to ); 499 calendar->deleteTodo( to );
483 } 500 }
484 to = tl.next(); 501 to = tl.next();
485 } 502 }
486 // 3 save file 503 // 3 save file
487 VCalFormat vfsave; 504 VCalFormat vfsave;
488 vfsave.setLocalTime ( true ); 505 vfsave.setLocalTime ( true );
489 if ( ! vfsave.save( calendar, fileName ) ) 506 if ( ! vfsave.save( calendar, fileName ) )
490 return false; 507 return false;
491 // 4 call kammu 508 // 4 call kammu
492 QString command ="./kammu --restore " + fileName + " -C" + 509 QString command ="./kammu --restore " + fileName + " -C" +
493 mConnection +" -D" + mDevice +" -M" + mModel;; 510 mConnection +" -D" + mDevice +" -M" + mModel;
494 int ret = system ( command.latin1() ); 511 int ret;
495 if ( ret != 0 ) 512 while ( (ret = system ( command.latin1())) != 0 ) {
513 qDebug("Error S::command returned %d. asking users", ret);
514 int retval = KMessageBox::warningContinueCancel(0,
515 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel"));
516 if ( retval != KMessageBox::Continue )
517 return false;
518 }
519 if ( ret != 0 ) {
520 qDebug("Error S::command returned %d", ret);
496 return false; 521 return false;
522 }
497 // 5 reread data 523 // 5 reread data
498 message = i18n(" Rereading all data ... "); 524 message = i18n(" Rereading all data ... ");
499 status.setText ( message ); 525 status.setText ( message );
500 qApp->processEvents(); 526 qApp->processEvents();
501 CalendarLocal* calendarTemp = new CalendarLocal(); 527 CalendarLocal* calendarTemp = new CalendarLocal();
502 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 528 calendarTemp->setTimeZoneId( calendar->timeZoneId());
503 if ( ! load( calendarTemp,calendar) ){ 529 if ( ! load( calendarTemp,calendar) ){
504 qDebug("error reloading calendar "); 530 qDebug("error reloading calendar ");
505 delete calendarTemp; 531 delete calendarTemp;
506 return false; 532 return false;
507 } 533 }
508 // 6 compare data 534 // 6 compare data
509 535
510//algo 6 compare event 536//algo 6 compare event
511 er = calendar->rawEvents(); 537 er = calendar->rawEvents();
512 ev = er.first(); 538 ev = er.first();
513 message = i18n(" Comparing event # "); 539 message = i18n(" Comparing event # ");
514 QPtrList<Event> er1 = calendarTemp->rawEvents(); 540 QPtrList<Event> er1 = calendarTemp->rawEvents();
515 Event* ev1; 541 Event* ev1;
516 int procCount = 0; 542 int procCount = 0;
517 while ( ev ) { 543 while ( ev ) {
518 qDebug("event new ID "); 544 //qDebug("event new ID %s",ev->summary().latin1());
519 status.setText ( message + QString::number ( ++procCount ) ); 545 status.setText ( message + QString::number ( ++procCount ) );
520 qApp->processEvents(); 546 qApp->processEvents();
521 QString cSum = ev->getCsum(mProfileName); 547 uint csum;
548 csum = PhoneFormat::getCsumEvent( ev );
549 QString cSum = QString::number( csum );
550 ev->setCsum( mProfileName, cSum );
551 //qDebug("Event cSum %s ", cSum.latin1());
522 ev1 = er1.first(); 552 ev1 = er1.first();
523 while ( ev1 ) { 553 while ( ev1 ) {
524 if ( ev1->getCsum( mProfileName ) == cSum ) { 554 if ( ev1->getCsum( mProfileName ) == cSum ) {
525 er1.remove( ev1 ); 555 er1.remove( ev1 );
526 afterSave( ev ); 556 afterSave( ev );
527 ev->setID(mProfileName, ev1->getID(mProfileName) ); 557 ev->setID(mProfileName, ev1->getID(mProfileName) );
558 //qDebug("Event found on phone for %s ", ev->summary().latin1());
559
528 break; 560 break;
529 } 561 }
530 ev1 = er1.next(); 562 ev1 = er1.next();
531 } 563 }
532 if ( ! ev1 ) { 564 if ( ! ev1 ) {
533 ev->removeID(mProfileName); 565 ev->removeID(mProfileName);
534 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 566 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
535 } 567 }
536 568
537 569
538 ev = er.next(); 570 ev = er.next();
539 } 571 }
540 //algo 6 compare todo 572 //algo 6 compare todo
573 tl = calendar->rawTodos();
541 to = tl.first(); 574 to = tl.first();
542 procCount = 0; 575 procCount = 0;
543 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 576 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
544 Todo* to1 ; 577 Todo* to1 ;
545 message = i18n(" Comparing todo # "); 578 message = i18n(" Comparing todo # ");
546 while ( to ) { 579 while ( to ) {
547 qDebug("todo2 %d ", procCount); 580 qDebug("todo2 %d ", procCount);
548 status.setText ( message + QString::number ( ++procCount ) ); 581 status.setText ( message + QString::number ( ++procCount ) );
549 qApp->processEvents(); 582 qApp->processEvents();
550 QString cSum = to->getCsum(mProfileName); 583 uint csum;
584 csum = PhoneFormat::getCsumTodo( to );
585 QString cSum = QString::number( csum );
586 to->setCsum( mProfileName, cSum );
587 qDebug("Todo cSum %s ", cSum.latin1());
551 Todo* to1 = tl1.first(); 588 Todo* to1 = tl1.first();
552 while ( to1 ) { 589 while ( to1 ) {
553 if ( to1->getCsum( mProfileName ) == cSum ) { 590 if ( to1->getCsum( mProfileName ) == cSum ) {
554 tl1.remove( to1 ); 591 tl1.remove( to1 );
555 afterSave( to ); 592 afterSave( to );
556 to->setID(mProfileName, to1->getID(mProfileName) ); 593 to->setID(mProfileName, to1->getID(mProfileName) );
557 break; 594 break;
558 } 595 }
559 to1 = tl1.next(); 596 to1 = tl1.next();
560 } 597 }
561 if ( ! to1 ) { 598 if ( ! to1 ) {
562 to->removeID(mProfileName); 599 to->removeID(mProfileName);
563 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); 600 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
564 } 601 }
565 602
566 to = tl.next(); 603 to = tl.next();