-rw-r--r-- | library/backend/event.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/library/backend/event.cpp b/library/backend/event.cpp index 2d02a34..eb238a4 100644 --- a/library/backend/event.cpp +++ b/library/backend/event.cpp @@ -923,390 +923,390 @@ const QDate &EffectiveEvent::date() const { return mDate; } /*! \internal */ int EffectiveEvent::length() const { return (mEnd.hour() * 60 - mStart.hour() * 60) + QABS(mStart.minute() - mEnd.minute() ); } /*! \internal */ void EffectiveEvent::setDate( const QDate &dt ) { mDate = dt; } /*! \internal */ void EffectiveEvent::setStart( const QTime &start ) { mStart = start; } /*! \internal */ void EffectiveEvent::setEnd( const QTime &end ) { mEnd = end; } /*! \internal */ void EffectiveEvent::setEvent( Event e ) { mEvent = e; } /*! \internal */ bool EffectiveEvent::operator<( const EffectiveEvent &e ) const { if ( mDate < e.date() ) return TRUE; if ( mDate == e.date() ) return ( mStart < e.start() ); else return FALSE; } /*! \internal */ bool EffectiveEvent::operator<=( const EffectiveEvent &e ) const { return (mDate <= e.date() ); } /*! \internal */ bool EffectiveEvent::operator==( const EffectiveEvent &e ) const { return ( mDate == e.date() && mStart == e.start() && mEnd == e.end() && mEvent == e.event() ); } /*! \internal */ bool EffectiveEvent::operator!=( const EffectiveEvent &e ) const { return !(*this == e); } /*! \internal */ bool EffectiveEvent::operator>( const EffectiveEvent &e ) const { return !(*this <= e ); } /*! \internal */ bool EffectiveEvent::operator>=(const EffectiveEvent &e) const { return !(*this < e); } /*! \internal */ void EffectiveEvent::setEffectiveDates( const QDate &from, const QDate &to ) { if ( !from.isValid() ) { delete d; d = 0; return; } if ( !d ) d = new EffectiveEventPrivate; d->startDate = from; d->endDate = to; } /*! \internal */ QDate EffectiveEvent::startDate() const { if ( d ) return d->startDate; else if ( mEvent.hasRepeat() ) return mDate; // single day, since multi-day should have a d pointer else return mEvent.start().date(); } /*! \internal */ QDate EffectiveEvent::endDate() const { if ( d ) return d->endDate; else if ( mEvent.hasRepeat() ) return mDate; // single day, since multi-day should have a d pointer else return mEvent.end().date(); } /*! \internal */ int EffectiveEvent::size() const { return ( mEnd.hour() - mStart.hour() ) * 3600 + (mEnd.minute() - mStart.minute() * 60 + mEnd.second() - mStart.second() ); } // vcal conversion code static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) { VObject *ret = 0; if ( o && !value.isEmpty() ) ret = addPropValue( o, prop, value.latin1() ); return ret; } static inline VObject *safeAddProp( VObject *o, const char *prop) { VObject *ret = 0; if ( o ) ret = addProp( o, prop ); return ret; } /* * Until we support vCal/iCal right * we will make DTSTART and other things * be floating in the sense of * RFC 2445 */ namespace { /* * Convert QDateTime to iso8601 but take * local time and do not use the Z at the end * */ QCString toISOLocal( const QDateTime& dt ) { QCString str; /* * year month day T Hour Minute Second * 4 2 2 2 2 2 digits */ str.sprintf("%04d%02d%02dT%02d%02d%02d", dt.date().year(), dt.date().month(), - dt.date().year(), + dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); - + qWarning("Str ist %s", str.data() ); return str; } }; static VObject *createVObject( const Event &e ) { VObject *vcal = newVObject( VCCalProp ); safeAddPropValue( vcal, VCVersionProp, "1.0" ); VObject *event = safeAddProp( vcal, VCEventProp ); safeAddPropValue( event, VCDTstartProp, toISOLocal( e.start() ) ); safeAddPropValue( event, VCDTendProp, toISOLocal( e.end() ) ); safeAddPropValue( event, "X-Qtopia-NOTES", e.description() ); safeAddPropValue( event, VCDescriptionProp, e.description() ); safeAddPropValue( event, VCLocationProp, e.location() ); if ( e.hasAlarm() ) { VObject *alarm = safeAddProp( event, VCAAlarmProp ); QDateTime dt = e.start(); dt = dt.addSecs( -e.alarmTime()*60 ); safeAddPropValue( alarm, VCRunTimeProp, toISOLocal( dt ) ); safeAddPropValue( alarm, VCAudioContentProp, (e.alarmSound() == Event::Silent ? "silent" : "alarm" ) ); } safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone() ); if ( e.type() == Event::AllDay ) safeAddPropValue( event, "X-Qtopia-AllDay", e.timeZone() ); // ### repeat missing // ### categories missing return vcal; } static Event parseVObject( VObject *obj ) { Event e; bool haveAlarm = FALSE; bool haveStart = FALSE; bool haveEnd = FALSE; QDateTime alarmTime; Event::SoundTypeChoice soundType = Event::Silent; VObjectIterator it; initPropIterator( &it, obj ); while( moreIteration( &it ) ) { VObject *o = nextVObject( &it ); QCString name = vObjectName( o ); QCString value = vObjectStringZValue( o ); if ( name == VCDTstartProp ) { e.setStart( TimeConversion::fromISO8601( value ) ); haveStart = TRUE; } else if ( name == VCDTendProp ) { e.setEnd( TimeConversion::fromISO8601( value ) ); haveEnd = TRUE; } else if ( name == "X-Qtopia-NOTES" ) { e.setNotes( value ); } else if ( name == VCDescriptionProp ) { e.setDescription( value ); } else if ( name == VCLocationProp ) { e.setLocation( value ); } else if ( name == VCAudioContentProp ) { haveAlarm = TRUE; VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectName( o ); QCString value = vObjectStringZValue( o ); if ( name == VCRunTimeProp ) alarmTime = TimeConversion::fromISO8601( value ); else if ( name == VCAudioContentProp ) { if ( value == "silent" ) soundType = Event::Silent; else soundType = Event::Loud; } } } else if ( name == "X-Qtopia-TIMEZONE") { e.setTimeZone( value ); } else if ( name == "X-Qtopia-AllDay" ) { e.setType( Event::AllDay ); } #if 0 else { printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectName( o ); QString value = vObjectStringZValue( o ); printf(" subprop: %s = %s\n", name.data(), value.latin1() ); } } #endif } if ( !haveStart && !haveEnd ) e.setStart( QDateTime::currentDateTime() ); if ( !haveEnd ) { e.setType( Event::AllDay ); e.setEnd( e.start() ); } if ( haveAlarm ) { int minutes = alarmTime.secsTo( e.start() ) / 60; e.setAlarm( TRUE, minutes, soundType ); } return e; } /*! Writes the list of \a events as a set of VCards to the file \a filename. */ void Event::writeVCalendar( const QString &filename, const QValueList<Event> &events) { QFileDirect f( filename.utf8().data() ); if ( !f.open( IO_WriteOnly ) ) { qWarning("Unable to open vcard write"); return; } QValueList<Event>::ConstIterator it; for( it = events.begin(); it != events.end(); ++it ) { VObject *obj = createVObject( *it ); writeVObject( f.directHandle() , obj ); cleanVObject( obj ); } cleanStrTbl(); } /*! Writes \a event as a VCard to the file \a filename. */ void Event::writeVCalendar( const QString &filename, const Event &event) { QFileDirect f( filename.utf8().data() ); if ( !f.open( IO_WriteOnly ) ) { qWarning("Unable to open vcard write"); return; } VObject *obj = createVObject( event ); writeVObject( f.directHandle() , obj ); cleanVObject( obj ); cleanStrTbl(); } /*! Returns the set of events read as VCards from the file \a filename. */ QValueList<Event> Event::readVCalendar( const QString &filename ) { VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); QValueList<Event> events; while ( obj ) { QCString name = vObjectName( obj ); |