-rw-r--r-- | libkcal/phoneformat.cpp | 336 |
1 files changed, 284 insertions, 52 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 6bbc0a3..6276498 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -390,193 +390,193 @@ public: */ int dayOfWeek = startDate.dayOfWeek(); if ( repeat_weekofmonth >= 0 ) { rtype = 2; // ************************ 2 MonthlyPos pos = repeat_weekofmonth; if ( repeat_dayofweek >= 0 ) dayOfWeek = repeat_dayofweek; if (repeat_month > 0) { if ( repeat_month != event->dtStart().date().month() ) { QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); event->setDtStart(QDateTime ( date , event->dtStart().time()) ); } if ( freq == 1 ) freq = 12; } } else if ( repeat_dayofweek >= 0 ) { rtype = 1;// ************************ 1 Weekly } else if ( repeat_day >= 0 ) { if ( repeat_month > 0) { rtype = 4; } else { rtype = 3; } } else { rtype = 0 ; } if ( rtype == 0 ) { if ( hasEndDate ) r->setDaily( freq, endDate ); else r->setDaily( freq, -1 ); } else if ( rtype == 1 ) { if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); else r->setWeekly( freq, weekDays, -1 ); } else if ( rtype == 3 ) { if ( hasEndDate ) r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); else r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); r->addMonthlyDay( startDate.day() ); } else if ( rtype == 2 ) { if ( hasEndDate ) r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); else r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); QBitArray days( 7 ); days.fill( false ); days.setBit( dayOfWeek - 1 ); r->addMonthlyPos( pos, days ); } else if ( rtype == 4 ) { if ( hasEndDate ) r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); else r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); r->addYearlyNum( startDate.month() ); } } else { event->recurrence()->unsetRecurs(); } QStringList categoryList; categoryList << getCategory( Note ); event->setCategories( categoryList ); // strange 0 semms to mean: alarm enabled if ( alarm ) { Alarm *alarm; if ( event->alarms().count() > 0 ) alarm = event->alarms().first(); else { alarm = new Alarm( event ); event->addAlarm( alarm ); } alarm->setType( Alarm::Audio ); alarm->setEnabled( true ); int alarmOffset = alarmDt.secsTo( event->dtStart() ); alarm->setStartOffset( -alarmOffset ); } else { Alarm *alarm; if ( event->alarms().count() > 0 ) { alarm = event->alarms().first(); alarm->setType( Alarm::Audio ); alarm->setStartOffset( -60*15 ); alarm->setEnabled( false ); } } // csum ***************************************** uint cSum; cSum = PhoneFormat::getCsumEvent( event ); 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; dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); // dtp->Timezone: offset in hours int offset = KGlobal::locale()->localTimeOffset( dt ); if ( useTz ) dt = dt.addSecs ( offset*60); return dt; } static QString dtToString( const QDateTime& dti, bool useTZ = false ) { QString datestr; QString timestr; int offset = KGlobal::locale()->localTimeOffset( dti ); QDateTime dt; if (useTZ) dt = dti.addSecs ( -(offset*60)); else dt = dti; if(dt.date().isValid()){ const QDate& date = dt.date(); datestr.sprintf("%04d%02d%02d", date.year(), date.month(), date.day()); } if(dt.time().isValid()){ const QTime& time = dt.time(); timestr.sprintf("T%02d%02d%02d", time.hour(), time.minute(), time.second()); } return datestr + timestr; } QDate datefromGSM ( GSM_DateTime* dtp ) { return QDate ( dtp->Year, dtp->Month, dtp->Day ); } QString getCategory( GSM_CalendarEntry* Note) { QString CATEGORY; switch (Note->Type) { case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; case GSM_CAL_CALL : CATEGORY = QString("Call"); break; case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; default : CATEGORY = QString(""); } return CATEGORY; } protected: private: Calendar *mCalendar; QString mProfileName ; }; PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) { mProfileName = profileName; mDevice = device; mConnection = connection; mModel = model; } PhoneFormat::~PhoneFormat() @@ -689,583 +689,815 @@ ulong PhoneFormat::getCsumEvent( Event* event ) QPtrList<Recurrence::rMonthPos> rmp; rmp = rec->monthPositions(); if ( rmp.first()->negative ) count = 5 - rmp.first()->rPos - 1; else count = rmp.first()->rPos - 1; list.append( QString::number( count ) ); } list.append( "0" ); break; case Recurrence::rMonthlyDay:// 3 list.append( "3" ); list.append( QString::number( rec->frequency()) );//12 list.append( "0" ); list.append( "0" ); writeEndDate = true; break; case Recurrence::rYearlyMonth://4 list.append( "4" ); list.append( QString::number( rec->frequency()) );//12 list.append( "0" ); list.append( "0" ); writeEndDate = true; break; default: list.append( "255" ); list.append( QString() ); list.append( "0" ); list.append( QString() ); list.append( "0" ); list.append( "20991231T000000" ); break; } if ( writeEndDate ) { if ( rec->endDate().isValid() ) { // 15 + 16 list.append( "1" ); list.append( PhoneParser::dtToString( rec->endDate()) ); } else { list.append( "0" ); list.append( "20991231T000000" ); } } attList << list.join(""); attList << event->categoriesStr(); attList << event->secrecyStr(); return PhoneFormat::getCsum(attList ); } ulong PhoneFormat::getCsum( const QStringList & attList) { int max = attList.count() -1; ulong cSum = 0; int j,k,i; int add; for ( i = 1; i < max ; ++i ) { QString s = attList[i]; if ( ! s.isEmpty() ){ j = s.length(); for ( k = 0; k < j; ++k ) { int mul = k +1; add = s[k].unicode (); if ( k < 16 ) mul = mul * mul; add = add * mul *i*i*i; cSum += add; } } } return cSum; } //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); #include <stdlib.h> #define DEBUGMODE false bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) { GSM_StateMachine s; qDebug(" load "); 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; 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; bool gshutdown = false; PhoneParser handler( calendar, mProfileName ); int ccc = 0; QString message = i18n(" Reading event # "); int procCount = 0; qDebug("Debug: only 10 calender items are downloaded "); while (!gshutdown && ccc++ < 10) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); qDebug("readEvent %d ", ccc); error=Phone->GetNextCalendar(&s,¬e,start); if (error == ERR_EMPTY) break; start = false; handler.readEvent( existingCal, ¬e ); qDebug("Org loc %d ",note.Location); //note.Location = 0; error=Phone->SetCalendar(&s,¬e); qDebug("new loc %d ",note.Location); } start = true; GSM_ToDoEntry ToDo; ccc = 0; message = i18n(" Reading todo # "); procCount = 0; while (!gshutdown && ccc++ < 10) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); error = Phone->GetNextToDo(&s, &ToDo, start); if (error == ERR_EMPTY) break; start = false; qDebug("ReadTodo %d ", ccc); handler.readTodo( existingCal, &ToDo, &s); } error=GSM_TerminateConnection(&s); return true; } #include <qcstring.h> void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note ) { QString eText = vfconverter.eventToString( ev, cal ); int pos = 0; GSM_ToDoEntry dummy; qDebug( "Convert event"); QByteArray ba; QDataStream s ( ba, IO_WriteOnly ); s << eText.utf8(); GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); qDebug( "Convert event done"); Note->Location = 0; QString loc = ev->getID(mProfileName); if ( !loc.isEmpty() ){ Note->Location = loc.toInt(); } } void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo ) { qDebug( "Convert todo1"); QString tText = vfconverter.todoToString( todo, cal ); int pos = 0; GSM_CalendarEntry dummy; QByteArray ba; QDataStream s ( ba, IO_WriteOnly ); s << tText.utf8(); GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); qDebug( "Convert todo done "); gsmTodo->Location = 0; QString loc = todo->getID(mProfileName); 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; int h = status.sizeHint().height()+20 ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); status.setCaption(i18n("Writing to phone...") ); status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); status.show(); status.raise(); qApp->processEvents(); 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; 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 )); event2GSM( calendar, ev, &Note ); ++loc; Note.Location = loc; error = Phone->AddCalendar(&s, &Note); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { planB = true; qDebug(" e add planB %d ", error); break; } ev->setID( mProfileName, QString::number( Note.Location ) ); qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN); afterSave( ev ); } else { afterSave( ev ); // setting temp sync stat for changed items } } ev = er.next(); } if ( planB ) { qDebug("delete all calendar..."); status.setText ( i18n("Deleting all calendar...")); qApp->processEvents(); error=Phone->DeleteAllCalendar(&s); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { message = i18n(" Deleting event # "); procCount = 0; while (1) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); qDebug("deleting event ... %d", procCount); error = Phone->GetNextCalendar(&s,&Note,true); if (error != ERR_NONE) break; error = Phone->DeleteCalendar(&s,&Note); } qDebug("deleting calendar ... finished"); } else { status.setText ( i18n("All calendar deleted!")); qDebug("all cal deleted"); } bool planC = false; ev = er.first(); procCount = 0; message = i18n(" Writing event # "); while ( ev && ! planC) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); event2GSM( calendar, ev, &Note ); Note.Location = procCount; error=Phone->AddCalendar(&s,&Note); if (error != ERR_NONE ) { // we have currently no planC :-( // planC = true; //qDebug("add planC %d ", error); //break; // we remove the ID such that this todo is not deleted after next sync ev->removeID(mProfileName); ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error); } else { qDebug("cal adding loc %d planB stat %d ", Note.Location ,error); ev->setID(mProfileName, QString::number( Note.Location )); afterSave( ev ); } ev = er.next(); } if ( planC ) { qDebug("writing cal went wrong..."); // we have currently no planC :-( } } GSM_ToDoEntry ToDoEntry; QPtrList<Todo> tl = calendar->rawTodos(); Todo* to = tl.first(); message = i18n(" Processing todo # "); procCount = 0; planB = false; while ( to && ! planB ) { 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 ); if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete error=Phone->DeleteToDo(&s,&ToDoEntry); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { planB = true; qDebug("delete planB %d ", error); } } else if ( to->getID(mProfileName).isEmpty() ) { // add new ; } else { // change existing error=Phone->SetToDo(&s,&ToDoEntry); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { planB = true; qDebug("set planB %d ", error); } qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error ); } } to = tl.next(); } // pending get empty slots to = tl.first(); while ( to && ! planB ) { 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(); //int newID ;//= pending //to->setID(mProfileName, QString::number( newID )); todo2GSM( calendar,to, &ToDoEntry ); ToDoEntry.Location = 0; error=Phone->AddToDo(&s,&ToDoEntry); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { planB = true; qDebug("new planB %d ", error); } to->setID(mProfileName, QString::number( ToDoEntry.Location )); afterSave( to ); qDebug("New Todo. Location %d %d",ToDoEntry.Location, error ); } else { afterSave( to ); } } to = tl.next(); } if ( planB ) { qDebug("delete all ..."); error=Phone->DeleteAllToDo(&s); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { while (1) { qDebug("deleting todo ..."); error = Phone->GetNextToDo(&s,&ToDoEntry,true); if (error != ERR_NONE) break; error = Phone->DeleteToDo(&s,&ToDoEntry); } qDebug("deleting todo ... finished"); } else { qDebug("all todo deleted"); } bool planC = false; to = tl.first(); while ( to && ! planC ) { todo2GSM( calendar,to, &ToDoEntry ); ToDoEntry.Location = 0; error=Phone->AddToDo(&s,&ToDoEntry); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { // we have currently no planC :-( // planC = true; //qDebug("add planC %d ", error); //break; // we remove the ID such that this todo is not deleted after next sync to->removeID(mProfileName); to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); } else { qDebug("adding %d planB %d ", ToDoEntry.Location ,error); to->setID(mProfileName, QString::number( ToDoEntry.Location )); afterSave( to ); } 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) dt = dti.addSecs ( -(offset*60)); else dt = dti; if(dt.date().isValid()){ const QDate& date = dt.date(); datestr.sprintf("%04d%02d%02d", date.year(), date.month(), date.day()); } if(dt.time().isValid()){ const QTime& time = dt.time(); timestr.sprintf("T%02d%02d%02d", time.hour(), time.minute(), time.second()); } return datestr + timestr; } QString PhoneFormat::getEventString( Event* event ) { #if 0 QStringList list; list.append( QString::number(event->zaurusId() ) ); list.append( event->categories().join(",") ); if ( !event->summary().isEmpty() ) list.append( event->summary() ); else list.append("" ); if ( !event->location().isEmpty() ) list.append( event->location() ); else list.append("" ); if ( !event->description().isEmpty() ) list.append( event->description() ); else list.append( "" ); if ( event->doesFloat () ) { list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 list.append( "1" ); } else { list.append( dtToString( event->dtStart()) ); list.append( dtToString( event->dtEnd()) ); //6 list.append( "0" ); } bool noAlarm = true; if ( event->alarms().count() > 0 ) { Alarm * al = event->alarms().first(); if ( al->enabled() ) { noAlarm = false; list.append( "0" ); // yes, 0 == alarm list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); if ( al->type() == Alarm::Audio ) list.append( "1" ); // type audio else list.append( "0" ); // type silent } } if ( noAlarm ) { list.append( "1" ); // yes, 1 == no alarm list.append( "0" ); // no alarm offset list.append( "1" ); // type } // next is: 11 // next is: 11-16 are recurrence Recurrence* rec = event->recurrence(); bool writeEndDate = false; switch ( rec->doesRecur() ) { case Recurrence::rDaily: // 0 list.append( "0" ); list.append( QString::number( rec->frequency() ));//12 list.append( "0" ); list.append( "0" ); writeEndDate = true; break; case Recurrence::rWeekly:// 1 list.append( "1" ); list.append( QString::number( rec->frequency()) );//12 list.append( "0" ); { int days = 0; QBitArray weekDays = rec->days(); int i; for( i = 1; i <= 7; ++i ) { if ( weekDays[i-1] ) { days += 1 << (i-1); } |