author | zautrix <zautrix> | 2004-08-20 04:28:28 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-20 04:28:28 (UTC) |
commit | 93decd4185adc7197008e8397cf753a5ab674d99 (patch) (side-by-side diff) | |
tree | 0d701d0a687c22cfe2894121f8540d60a5fbe7a9 /libkcal | |
parent | f7a401f03c18ef96eb40dc5540b31cd10880e845 (diff) | |
download | kdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.zip kdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.tar.gz kdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.tar.bz2 |
Bugfixes for syncing
-rw-r--r-- | libkcal/phoneformat.cpp | 336 | ||||
-rw-r--r-- | libkcal/sharpformat.cpp | 2 | ||||
-rw-r--r-- | libkcal/vcalformat.cpp | 71 |
3 files changed, 323 insertions, 86 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 6bbc0a3..6276498 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -478,17 +478,17 @@ public: event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); mCalendar->addEvent( event); return true; } - QDateTime fromGSM ( GSM_DateTime* dtp, bool useTz = true ) { + QDateTime fromGSM ( GSM_DateTime* dtp, bool useTz = false ) { QDateTime dt; int y,m,t,h,min,sec; y = dtp->Year; m = dtp->Month; t = dtp->Day; h = dtp->Hour; min = dtp->Minute; sec = dtp->Second; @@ -777,59 +777,17 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) int h = status.sizeHint().height()+20 ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); status.setCaption(i18n("Reading phone...") ); status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); status.show(); status.raise(); qApp->processEvents(); -#if 0 - static char *cp; - static INI_Section *cfg = NULL; - cfg=GSM_FindGammuRC(); - int i; - for (i = 0; i <= MAX_CONFIG_NUM; i++) { - if (cfg!=NULL) { - cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); - if (cp) di.coding = cp; - - s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); - if (s.Config[i].Localize) { - s.msg=INI_ReadFile(s.Config[i].Localize, true); - } else { -#if !defined(WIN32) && defined(LOCALE_PATH) - locale = setlocale(LC_MESSAGES, NULL); - if (locale != NULL) { - snprintf(locale_file, 200, "%s/gammu_%c%c.txt", - LOCALE_PATH, - tolower(locale[0]), - tolower(locale[1])); - s.msg = INI_ReadFile(locale_file, true); - } -#endif - } - } - - /* Wanted user specific configuration? */ - - if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; - - s.ConfigNum++; - - /* We want to use only one file descriptor for global and state machine debug output */ - s.Config[i].UseGlobalDebugFile = true; - - - /* We wanted to read just user specified configuration. */ - {break;} - } - -#endif int error=initDevice(&s); qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); if ( error != ERR_NONE ) return false; GSM_Phone_Functions *Phone; GSM_CalendarEntry note; bool start = true; Phone=s.Phone.Functions; @@ -908,27 +866,28 @@ void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo ) if ( !loc.isEmpty() ){ gsmTodo->Location = loc.toInt(); } } void PhoneFormat::afterSave( Incidence* inc) { uint csum; + inc->removeID( mProfileName ); if ( inc->type() == "Event") csum = PhoneFormat::getCsumEvent( (Event*) inc ); else csum = PhoneFormat::getCsumTodo( (Todo*) inc ); inc->setCsum( mProfileName, QString::number( csum )); inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); } bool PhoneFormat::save( Calendar *calendar) { - return true; + GSM_StateMachine s; qDebug(" save "); s.opened = false; s.msg = NULL; s.ConfigNum = 0; QLabel status ( i18n(" Opening device ..."), 0 ); int w = status.sizeHint().width()+20 ; if ( w < 200 ) w = 230; @@ -947,53 +906,325 @@ bool PhoneFormat::save( Calendar *calendar) return false; GSM_Phone_Functions *Phone; GSM_CalendarEntry Note; bool start = true; Phone=s.Phone.Functions; bool gshutdown = false; QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); - QString message = i18n(" Processing event # "); + QString message = i18n(" Deleting event # "); int procCount = 0; - bool planB = true;// false; + int diffProc = 0; + bool setPossible = true; +#ifdef _WIN32_ + QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; +#else + QString fileName = "/tmp/kdepimtemp.vcs"; +#endif + //algo 1 delete event + while ( ev ) { + if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one + + status.setText ( message + QString::number ( ++procCount ) ); + qApp->processEvents(); + qDebug("del event1 %d ", procCount); + //event2GSM( calendar, ev, &Note ); + if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete + + QString loc = ev->getID(mProfileName); + if ( !loc.isEmpty() ){ + Note.Location = loc.toInt(); + } else { + qDebug("error: loc is empty "); + } + error = Phone->DeleteCalendar(&s, &Note); + if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { + qDebug(" e error delete1 planB %d ", error); + break; + } + } + else if ( ev->getID(mProfileName).isEmpty() ) { // add new + // we have to do this later after deleting + + } + else { // change existing + + QString loc = ev->getID(mProfileName); + if ( !loc.isEmpty() ){ + Note.Location = loc.toInt(); + } else { + qDebug("error3: loc is empty "); + } + error = Phone->DeleteCalendar(&s, &Note); + if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { + qDebug(" e error delete2 planB %d ", error); + break; + } + ev->removeID( mProfileName ); + } + } + ev = er.next(); + } + //algo 1 delete todo + GSM_ToDoEntry ToDoEntry; + QPtrList<Todo> tl = calendar->rawTodos(); + Todo* to = tl.first(); + message = i18n(" Deleting todo # "); + procCount = 0; + while ( to ) { + if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + qDebug("todo3 %d ", procCount); + status.setText ( message + QString::number ( ++procCount ) ); + qApp->processEvents(); + qDebug("todo5 %d ", procCount); + // todo2GSM( calendar, to, &ToDoEntry ); + QString loc = to->getID(mProfileName); + if ( !loc.isEmpty() ){ + ToDoEntry.Location = loc.toInt(); + } else { + qDebug("error2: loc is empty "); + } + if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete + error=Phone->DeleteToDo(&s,&ToDoEntry); + if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { + qDebug("delete planB %d ", error); + } + } + else if ( to->getID(mProfileName).isEmpty() ) { // add new + ; + } + else { // change existing + error=Phone->DeleteToDo(&s,&ToDoEntry); + if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { + qDebug("set planB %d ", error); + } + to->removeID( mProfileName ); + } + } + to = tl.next(); + } + //algo 2 add event + ev = er.first(); + QString filec; + message = i18n(" Preparing event # "); + procCount = 0; + while ( ev ) { + if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { + if ( ev->getID(mProfileName).isEmpty() ) { + status.setText ( message + QString::number ( ++procCount ) ); + qApp->processEvents(); + filec += vfconverter.eventToString( ev, calendar )+ "\n"; + afterSave ( ev ); + + } + } + ev = er.next(); + } + //algo 2 add todo + to = tl.first(); + procCount = 0; + message = i18n(" Preparing todo # "); + while ( to ) { + qDebug("todo2 %d ", procCount); + if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { + qDebug("todo4 %d ", procCount); + if ( to->getID(mProfileName).isEmpty() ) { + status.setText ( message + QString::number ( ++procCount ) ); + qApp->processEvents(); + filec += vfconverter.todoToString( to, calendar )+ "\n"; + afterSave ( to ); + } + } + to = tl.next(); + } + if ( filec.isEmpty() ) { + qDebug("Nothing to write back.Finished. "); + error=GSM_TerminateConnection(&s); + return true; + } + //algo 3 saving file + message = i18n(" Saving temp file ... "); + status.setText ( message ); + qApp->processEvents(); + QFile file( fileName ); + if (!file.open( IO_WriteOnly ) ) { + qDebug("error open file "); + error=GSM_TerminateConnection(&s); + return false; + } + QTextStream ts( &file ); + ts.setCodec( QTextCodec::codecForName("utf8") ); + ts << filec ; + file.close(); + + + message = i18n(" Parsing temp file ... "); + status.setText ( message ); + qApp->processEvents(); + GSM_Backup Backup; + error=GSM_ReadBackupFile( (char*) fileName.latin1() ,&Backup); + qDebug("Read file result %d ",error ); + //algo 4 writing event + int max, i; + procCount = 0; + message = i18n(" Writing event # "); + if (Backup.Calendar[0] != NULL) { + max = 0; + while (Backup.Calendar[max]!=NULL) max++; + for (i=0;i<max;i++) { + status.setText ( message + QString::number ( ++procCount ) ); + qApp->processEvents(); + Note = *Backup.Calendar[i]; + Note.Location = 0; + error=Phone->AddCalendar(&s,&Note); + qDebug("add event %d %d", error, Note.Location ); + } + } + //algo 4 writing todo + procCount = 0; + message = i18n(" Writing todo # "); + if (Backup.ToDo[0] != NULL) { + max = 0; + while (Backup.ToDo[max]!=NULL) max++; + for (i=0;i<max;i++) { + status.setText ( message + QString::number ( ++procCount ) ); + qApp->processEvents(); + ToDoEntry = *Backup.ToDo[i]; + error = Phone->AddToDo(&s,&ToDoEntry); + qDebug("add todo %d ", error); + } + } + //algo 5 reread + message = i18n(" Rereading all data ... "); + status.setText ( message ); + qApp->processEvents(); + error=GSM_TerminateConnection(&s); + CalendarLocal* calendarTemp = new CalendarLocal(); + calendarTemp->setTimeZoneId( calendar->timeZoneId()); + if ( ! load( calendarTemp,calendar) ){ + qDebug("error reloading calendar "); + delete calendarTemp; + return false; + } + + + //algo 6 compare event + ev = er.first(); + message = i18n(" Comparing event # "); + QPtrList<Event> er1 = calendarTemp->rawEvents(); + Event* ev1; + procCount = 0; + while ( ev ) { + if ( ev->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { + qDebug("event new ID "); + status.setText ( message + QString::number ( ++procCount ) ); + qApp->processEvents(); + QString cSum = ev->getCsum(mProfileName); + ev1 = er1.first(); + while ( ev1 ) { + if ( ev1->getCsum( mProfileName ) == cSum ) { + er1.remove( ev1 ); + ev->setID(mProfileName, ev1->getID(mProfileName) ); + break; + } + ev1 = er1.next(); + } + if ( ! ev1 ) { + ev->removeID(mProfileName); + qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); + qDebug("Probably writing back of events not supported "); + } + + } + ev = er.next(); + } + //algo 6 compare todo + to = tl.first(); + procCount = 0; + QPtrList<Todo> tl1 = calendarTemp->rawTodos(); + Todo* to1 ; + message = i18n(" Comparing todo # "); + while ( to ) { + qDebug("todo2 %d ", procCount); + if ( to->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { + status.setText ( message + QString::number ( ++procCount ) ); + qApp->processEvents(); + QString cSum = to->getCsum(mProfileName); + Todo* to1 = tl1.first(); + while ( to1 ) { + if ( to1->getCsum( mProfileName ) == cSum ) { + tl1.remove( to1 ); + to->setID(mProfileName, to1->getID(mProfileName) ); + break; + } + to1 = tl1.next(); + } + if ( ! to1 ) { + to->removeID(mProfileName); + qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); + qDebug("Probably writing back of todos not supported "); + } + } + to = tl.next(); + } + delete calendarTemp; + return true; + // ******************************************************************* + // ******************************************************************* + // ******************************************************************* +#if 0 while ( ev && ! planB) { if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); qDebug("event1 %d ", procCount); event2GSM( calendar, ev, &Note ); if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete error = Phone->DeleteCalendar(&s, &Note); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { planB = true; - qDebug(" e delete planB %d ", error); + qDebug(" e delete1 planB %d ", error); break; } } else if ( ev->getID(mProfileName).isEmpty() ) { // add new // we have to do this later after deleting } else { // change existing - error = Phone->SetCalendar(&s, &Note); - if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { - planB = true; - qDebug(" e change planB %d ", error); - break; + if ( setPossible ) { + error = Phone->SetCalendar(&s, &Note); + if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { + setPossible = false; + ++diffProc; + qDebug("Set cal not supported %d ", error); + break; + } + } + if ( ! setPossible) { + ++diffProc; + error = Phone->DeleteCalendar(&s, &Note); + if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { + planB = true; + qDebug(" e delete2 planB %d ", error); + break; + } + ev->removeID( mProfileName ); } qDebug("Change Calendar. Location %d status: %d",Note.Location, error ); } } ev = er.next(); } ev = er.first(); // pending get empty slots int loc = 0; + procCount -= diffProc; while ( ev && ! planB) { if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { qDebug("event2 %d ", procCount); if ( ev->getID(mProfileName).isEmpty() ) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); //int newID ;//= pending //ev->setID(mProfileName, QString::number( newID )); @@ -1168,16 +1399,17 @@ bool PhoneFormat::save( Calendar *calendar) } to = tl.next(); } if ( planC ) { // we have currently no planC :-( } } return true; +#endif } QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) { QString datestr; QString timestr; int offset = KGlobal::locale()->localTimeOffset( dti ); QDateTime dt; if (useTZ) diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index defdb09..820d068 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp @@ -502,17 +502,17 @@ bool SharpFormat::save( Calendar *calendar) bool debug = DEBUGMODE; QString codec = "utf8"; QString answer; QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; QString command; QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); - QString fileName = "/tmp/kopitempout"; + QString fileName = "/tmp/kdepimtempfile"; int i = 0; QString changeString = ePrefix; QString deleteString = ePrefix; bool deleteEnt = false; bool changeEnt = false; QString message = i18n("Processing event # "); int procCount = 0; while ( ev ) { diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp index 076cd3f..9307f12 100644 --- a/libkcal/vcalformat.cpp +++ b/libkcal/vcalformat.cpp @@ -342,32 +342,34 @@ VObject *VCalFormat::eventToVTodo(const Todo *anEvent) } // alarm stuff kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; QPtrList<Alarm> alarms = anEvent->alarms(); Alarm* alarm; for (alarm = alarms.first(); alarm; alarm = alarms.next()) { if (alarm->enabled()) { - VObject *a = addProp(vtodo, VCDAlarmProp); - tmpStr = qDateTimeToISO(alarm->time()); - addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); - addPropValue(a, VCRepeatCountProp, "1"); - addPropValue(a, VCDisplayStringProp, "beep!"); - if (alarm->type() == Alarm::Audio) { - a = addProp(vtodo, VCAAlarmProp); - addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); - addPropValue(a, VCRepeatCountProp, "1"); - addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); - } - else if (alarm->type() == Alarm::Procedure) { - a = addProp(vtodo, VCPAlarmProp); - addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); - addPropValue(a, VCRepeatCountProp, "1"); - addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); + VObject *a; + tmpStr = qDateTimeToISO(alarm->time()); + if (alarm->type() == Alarm::Audio) { + a = addProp(vtodo, VCAAlarmProp); + addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); + addPropValue(a, VCRepeatCountProp, "1"); + addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); + } + else if (alarm->type() == Alarm::Procedure) { + a = addProp(vtodo, VCPAlarmProp); + addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); + addPropValue(a, VCRepeatCountProp, "1"); + addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); + } else { + a = addProp(vtodo, VCDAlarmProp); + addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); + addPropValue(a, VCRepeatCountProp, "1"); + addPropValue(a, VCDisplayStringProp, "beep!"); } } } if (anEvent->pilotId()) { // pilot sync stuff tmpStr.sprintf("%i",anEvent->pilotId()); addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); @@ -620,33 +622,36 @@ VObject* VCalFormat::eventToVEvent(const Event *anEvent) tmpStr = tmpStrList.join(";"); if (!tmpStr.isEmpty()) addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); // alarm stuff QPtrList<Alarm> alarms = anEvent->alarms(); Alarm* alarm; for (alarm = alarms.first(); alarm; alarm = alarms.next()) { - if (alarm->enabled()) { - VObject *a = addProp(vevent, VCDAlarmProp); - tmpStr = qDateTimeToISO(alarm->time()); - addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); - addPropValue(a, VCRepeatCountProp, "1"); - addPropValue(a, VCDisplayStringProp, "beep!"); - if (alarm->type() == Alarm::Audio) { - a = addProp(vevent, VCAAlarmProp); - addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); - addPropValue(a, VCRepeatCountProp, "1"); - addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); - } - if (alarm->type() == Alarm::Procedure) { - a = addProp(vevent, VCPAlarmProp); - addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); - addPropValue(a, VCRepeatCountProp, "1"); - addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); + if (alarm->enabled()) { + VObject *a ; + tmpStr = qDateTimeToISO(alarm->time()); + if (alarm->type() == Alarm::Audio) { + a = addProp(vevent, VCAAlarmProp); + addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); + addPropValue(a, VCRepeatCountProp, "1"); + addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); + } + if (alarm->type() == Alarm::Procedure) { + a = addProp(vevent, VCPAlarmProp); + addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); + addPropValue(a, VCRepeatCountProp, "1"); + addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); + } else { + a = addProp(vevent, VCDAlarmProp); + addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); + addPropValue(a, VCRepeatCountProp, "1"); + addPropValue(a, VCDisplayStringProp, "beep!"); + } } } // priority tmpStr.sprintf("%i",anEvent->priority()); addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); |