author | zautrix <zautrix> | 2004-10-15 14:26:07 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-15 14:26:07 (UTC) |
commit | 4f276d80bd977401d656851515474cc00c661e5b (patch) (side-by-side diff) | |
tree | 0d3a747bef0431ef791b69876f5bda554f9ca83f /libkcal | |
parent | c2fb960297c4b08980921c818a4d347057732390 (diff) | |
download | kdepimpi-4f276d80bd977401d656851515474cc00c661e5b.zip kdepimpi-4f276d80bd977401d656851515474cc00c661e5b.tar.gz kdepimpi-4f276d80bd977401d656851515474cc00c661e5b.tar.bz2 |
many phone and sync fixes
-rw-r--r-- | libkcal/event.cpp | 46 | ||||
-rw-r--r-- | libkcal/event.h | 2 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 104 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 2 | ||||
-rw-r--r-- | libkcal/todo.cpp | 58 | ||||
-rw-r--r-- | libkcal/todo.h | 1 | ||||
-rw-r--r-- | libkcal/vcalformat.cpp | 141 |
7 files changed, 227 insertions, 127 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp index dfa265b..7256f05 100644 --- a/libkcal/event.cpp +++ b/libkcal/event.cpp @@ -57,4 +57,50 @@ bool KCal::operator==( const Event& e1, const Event& e2 ) +bool Event::contains ( Event* from ) +{ + + if ( !from->summary().isEmpty() ) + if ( !summary().startsWith( from->summary() )) + return false; + if ( from->dtStart().isValid() ) + if (dtStart() != from->dtStart() ) + return false; + if ( from->dtEnd().isValid() ) + if ( dtEnd() != from->dtEnd() ) + return false; + if ( !from->location().isEmpty() ) + if ( !location().startsWith( from->location() ) ) + return false; + if ( !from->description().isEmpty() ) + if ( !description().startsWith( from->description() )) + return false; + if ( from->alarms().count() ) { + Alarm *a = from->alarms().first(); + if ( a->enabled() ){ + if ( !alarms().count() ) + return false; + Alarm *b = alarms().first(); + if( ! b->enabled() ) + return false; + if ( ! (a->offset() == b->offset() )) + return false; + } + } + QStringList cat = categories(); + QStringList catFrom = from->categories(); + QString nCat; + int iii; + for ( iii = 0; iii < catFrom.count();++iii ) { + nCat = catFrom[iii]; + if ( !nCat.isEmpty() ) + if ( !cat.contains( nCat )) { + return false; + } + } + if ( from->doesRecur() ) + if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) + return false; + return true; +} void Event::setDtEnd(const QDateTime &dtEnd) diff --git a/libkcal/event.h b/libkcal/event.h index 2a8bd95..3bc8adc 100644 --- a/libkcal/event.h +++ b/libkcal/event.h @@ -72,4 +72,6 @@ class Event : public Incidence void setDuration(int seconds); + bool contains ( Event*); + private: bool accept(Visitor &v) { return v.visit(this); } diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 281434e..101db57 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -313,5 +313,14 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) if ( cat.contains( "MeetingDEF" )) { ev->setCategories( QStringList() ); + } else + if ( cat.contains( "Birthday" )) { + ev->setFloats( true ); + QDate da = ev->dtStart().date(); + ev->setDtStart( QDateTime( da) ); + ev->setDtEnd( QDateTime( da.addDays(1)) ); + } + uint cSum; + cSum = PhoneFormat::getCsumEvent( ev ); int id = ev->pilotId(); Event *event; @@ -325,6 +334,4 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) else event = ev; - uint cSum; - cSum = PhoneFormat::getCsumEvent( event ); event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); @@ -343,4 +350,6 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) } int id = ev->pilotId(); + uint cSum; + cSum = PhoneFormat::getCsumTodo( ev ); Todo *event; event = existingCal->todo( mProfileName ,QString::number( id ) ); @@ -355,6 +364,4 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) else event = ev; - uint cSum; - cSum = PhoneFormat::getCsumTodo( event ); event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); @@ -383,9 +390,5 @@ void PhoneFormat::copyEvent( Event* to, Event* from ) Alarm *b = to->newAlarm( ); b->setEnabled( a->enabled() ); - if ( a->hasStartOffset() ) { - b->setStartOffset( a->startOffset() ); - } - if ( a->hasTime() ) - b->setTime( a->time() ); + b->setStartOffset(Duration( a->offset() ) ); } @@ -402,6 +405,8 @@ void PhoneFormat::copyEvent( Event* to, Event* from ) } to->setCategories( cat ); - Recurrence * r = new Recurrence( *from->recurrence(),to); - to->setRecurrence( r ) ; + if ( from->doesRecur() ) { + Recurrence * r = new Recurrence( *from->recurrence(),to); + to->setRecurrence( r ) ; + } @@ -409,8 +414,12 @@ void PhoneFormat::copyEvent( Event* to, Event* from ) void PhoneFormat::copyTodo( Todo* to, Todo* from ) { - if ( from->dtStart().isValid() ) + if ( from->hasStartDate() ) { + to->setHasStartDate( true ); to->setDtStart( from->dtStart() ); - if ( from->dtDue().isValid() ) + } + if ( from->hasDueDate() ){ + to->setHasDueDate( true ); to->setDtDue( from->dtDue() ); + } if ( !from->location().isEmpty() ) to->setLocation( from->location() ); @@ -425,8 +434,5 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from ) Alarm *b = to->newAlarm( ); b->setEnabled( a->enabled() ); - if ( a->hasStartOffset() ) - b->setStartOffset( a->startOffset() ); - if ( a->hasTime() ) - b->setTime( a->time() ); + b->setStartOffset(Duration( a->offset() ) ); } @@ -462,14 +468,8 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from ) #include <qcstring.h> -void PhoneFormat::afterSave( Incidence* inc) +void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum) { - 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->setID( mProfileName, id ); + inc->setCsum( mProfileName, csum); inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); @@ -479,7 +479,7 @@ bool PhoneFormat::writeToPhone( Calendar * calendar) { #ifdef _WIN32_ - QString fileName = locateLocal("tmp", "tempfile.vcs"); + QString fileName = locateLocal("tmp", "phonefile.vcs"); #else - QString fileName = "/tmp/kdepimtemp.vcs"; + QString fileName = "/tmp/phonefile.vcs"; #endif @@ -495,16 +495,5 @@ bool PhoneFormat::writeToPhone( Calendar * calendar) bool PhoneFormat::save( Calendar *calendar) { - 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(); - QString message; + // 1 remove events which should be deleted @@ -535,5 +524,16 @@ bool PhoneFormat::save( Calendar *calendar) if ( !writeToPhone( calendar ) ) return false; - + 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 ); + QString message; + status.show(); + status.raise(); + qApp->processEvents(); // 5 reread data message = i18n(" Rereading all data ... "); @@ -560,17 +560,9 @@ bool PhoneFormat::save( Calendar *calendar) status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); - uint csum; - csum = PhoneFormat::getCsumEvent( ev ); - QString cSum = QString::number( csum ); - //ev->setCsum( mProfileName, cSum ); - //qDebug("Event cSum %s ", cSum.latin1()); ev1 = er1.first(); while ( ev1 ) { - if ( ev1->getCsum( mProfileName ) == cSum ) { + if ( ev->contains( ev1 ) ) { + afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName)); er1.remove( ev1 ); - afterSave( ev ); - ev->setID(mProfileName, ev1->getID(mProfileName) ); - //qDebug("Event found on phone for %s ", ev->summary().latin1()); - break; } @@ -595,15 +587,9 @@ bool PhoneFormat::save( Calendar *calendar) status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); - uint csum; - csum = PhoneFormat::getCsumTodo( to ); - QString cSum = QString::number( csum ); - //to->setCsum( mProfileName, cSum ); - //qDebug("Todo cSum %s ", cSum.latin1()); Todo* to1 = tl1.first(); while ( to1 ) { - if ( to1->getCsum( mProfileName ) == cSum ) { + if ( to->contains( to1 ) ) { + afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName)); tl1.remove( to1 ); - afterSave( to ); - to->setID(mProfileName, to1->getID(mProfileName) ); break; } diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 001fd81..d11f68b 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h @@ -55,5 +55,5 @@ class PhoneFormat : public QObject { //int initDevice(GSM_StateMachine *s); QString mProfileName; - void afterSave( Incidence* ); + void afterSave( Incidence* ,const QString&,const QString&); }; diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 0c1e3e4..3d2de61 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -57,5 +57,63 @@ Incidence *Todo::clone() } +bool Todo::contains ( Todo* from ) +{ + if ( !from->summary().isEmpty() ) + if ( !summary().startsWith( from->summary() )) + return false; + if ( from->hasStartDate() ) { + if ( !hasStartDate() ) + return false; + if ( from->dtStart() != dtStart()) + return false; + } + if ( from->hasDueDate() ){ + if ( !hasDueDate() ) + return false; + if ( from->dtDue() != dtDue()) + return false; + } + if ( !from->location().isEmpty() ) + if ( !location().startsWith( from->location() ) ) + return false; + if ( !from->description().isEmpty() ) + if ( !description().startsWith( from->description() )) + return false; + if ( from->alarms().count() ) { + Alarm *a = from->alarms().first(); + if ( a->enabled() ){ + if ( !alarms().count() ) + return false; + Alarm *b = alarms().first(); + if( ! b->enabled() ) + return false; + if ( ! (a->offset() == b->offset() )) + return false; + } + } + + QStringList cat = categories(); + QStringList catFrom = from->categories(); + QString nCat; + int iii; + for ( iii = 0; iii < catFrom.count();++iii ) { + nCat = catFrom[iii]; + if ( !nCat.isEmpty() ) + if ( !cat.contains( nCat )) { + return false; + } + } + if ( from->isCompleted() ) { + if ( !isCompleted() ) + return false; + } + if( priority() != from->priority() ) + return false; + + + return true; + +} bool KCal::operator==( const Todo& t1, const Todo& t2 ) { diff --git a/libkcal/todo.h b/libkcal/todo.h index 9aa92f8..0f22c59 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h @@ -100,4 +100,5 @@ class Todo : public Incidence /** Return true, if todo has a date associated with completion */ bool hasCompletedDate() const; + bool contains ( Todo*); private: diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp index a6ae1bc..df93209 100644 --- a/libkcal/vcalformat.cpp +++ b/libkcal/vcalformat.cpp @@ -63,5 +63,6 @@ bool VCalFormat::load(Calendar *calendar, const QString &fileName) mCalendar = calendar; clearException(); - useLocalTime = mCalendar->isLocalTime(); + if ( ! useLocalTime ) + useLocalTime = mCalendar->isLocalTime(); VObject *vcal = 0; @@ -91,5 +92,6 @@ bool VCalFormat::save(Calendar *calendar, const QString &fileName) { mCalendar = calendar; - useLocalTime = mCalendar->isLocalTime(); + if ( ! useLocalTime ) + useLocalTime = mCalendar->isLocalTime(); QString tmpStr; @@ -1173,70 +1175,74 @@ Event* VCalFormat::VEventToEvent(VObject *vevent) /*********************** YEARLY-BY-MONTH *******************************/ else if (tmpStr.left(2) == "YM") { - int index = tmpStr.find(' '); - int last = tmpStr.findRev(' ') + 1; - int rFreq = tmpStr.mid(2, (index-1)).toInt(); - index += 1; - short tmpMonth; - if( index == last ) { - // e.g. YM1 #0 - tmpMonth = anEvent->dtStart().date().month(); - anEvent->recurrence()->addYearlyNum(tmpMonth); - } - else { - // e.g. YM1 3 #0 - while (index < last) { - int index2 = tmpStr.find(' ', index); - tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); - index = index2+1; - anEvent->recurrence()->addYearlyNum(tmpMonth); - } // while != # - } - index = last; if (tmpStr.mid(index,1) == "#") index++; - if (tmpStr.find('T', index) != -1) { - QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); - anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); - } else { - int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); - if (rDuration == 0) - anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); - else - anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); - } + // we have to set this such that recurrence accepts addYearlyNum(tmpDay); + anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, 1, -1); + int index = tmpStr.find(' '); + int last = tmpStr.findRev(' ') + 1; + int rFreq = tmpStr.mid(2, (index-1)).toInt(); + index += 1; + short tmpMonth; + if( index == last ) { + // e.g. YM1 #0 + tmpMonth = anEvent->dtStart().date().month(); + anEvent->recurrence()->addYearlyNum(tmpMonth); + } + else { + // e.g. YM1 3 #0 + while (index < last) { + int index2 = tmpStr.find(' ', index); + tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); + index = index2+1; + anEvent->recurrence()->addYearlyNum(tmpMonth); + } // while != # + } + index = last; if (tmpStr.mid(index,1) == "#") index++; + if (tmpStr.find('T', index) != -1) { + QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); + anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); + } else { + int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); + if (rDuration == 0) + anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); + else + anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); + } } /*********************** YEARLY-BY-DAY *********************************/ else if (tmpStr.left(2) == "YD") { - int index = tmpStr.find(' '); - int last = tmpStr.findRev(' ') + 1; - int rFreq = tmpStr.mid(2, (index-1)).toInt(); - index += 1; - short tmpDay; - if( index == last ) { - // e.g. YD1 #0 - tmpDay = anEvent->dtStart().date().dayOfYear(); - anEvent->recurrence()->addYearlyNum(tmpDay); - } - else { - // e.g. YD1 123 #0 - while (index < last) { - int index2 = tmpStr.find(' ', index); - tmpDay = tmpStr.mid(index, (index2-index)).toShort(); - index = index2+1; - anEvent->recurrence()->addYearlyNum(tmpDay); - } // while != # - } - index = last; if (tmpStr.mid(index,1) == "#") index++; - if (tmpStr.find('T', index) != -1) { - QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); - anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); - } else { - int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); - if (rDuration == 0) - anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); - else - anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); - } + // we have to set this such that recurrence accepts addYearlyNum(tmpDay); + anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, 1, -1); + int index = tmpStr.find(' '); + int last = tmpStr.findRev(' ') + 1; + int rFreq = tmpStr.mid(2, (index-1)).toInt(); + index += 1; + short tmpDay; + if( index == last ) { + // e.g. YD1 #0 + tmpDay = anEvent->dtStart().date().dayOfYear(); + anEvent->recurrence()->addYearlyNum(tmpDay); + } + else { + // e.g. YD1 123 #0 + while (index < last) { + int index2 = tmpStr.find(' ', index); + tmpDay = tmpStr.mid(index, (index2-index)).toShort(); + index = index2+1; + anEvent->recurrence()->addYearlyNum(tmpDay); + } // while != # + } + index = last; if (tmpStr.mid(index,1) == "#") index++; + if (tmpStr.find('T', index) != -1) { + QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); + anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); + } else { + int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); + if (rDuration == 0) + anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); + else + anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); + } } else { - kdDebug(5800) << "we don't understand this type of recurrence!" << endl; + kdDebug(5800) << "we don't understand this type of recurrence!" << endl; } // if } // repeats @@ -1537,10 +1543,11 @@ void VCalFormat::populate(VObject *vcal) // set the time zone if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { - char *s = fakeCString(vObjectUStringZValue(curVO)); - mCalendar->setTimeZone(s); - deleteStr(s); + if ( vObjectUStringZValue(curVO) != 0 ) { + char *s = fakeCString(vObjectUStringZValue(curVO)); + mCalendar->setTimeZone(s); + deleteStr(s); + } } - // Store all events with a relatedTo property in a list for post-processing mEventsRelate.clear(); |