Qtopia library API Documentation

event.cpp

00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "event.h"
00022 #include "qfiledirect_p.h"
00023 #include <qtopia/timeconversion.h>
00024 #include <qtopia/stringutil.h>
00025 #include <qtopia/private/recordfields.h>
00026 #include <qbuffer.h>
00027 #include <time.h>
00028 #include "vobject_p.h"
00029 
00030 #include <stdio.h>
00031 
00032 using namespace Qtopia;
00033 
00034 static void write( QString& buf, const Event::RepeatPattern &r )
00035 {
00036     buf += " rtype=\"";
00037     switch ( r.type ) {
00038     case Event::Daily:
00039         buf += "Daily";
00040         break;
00041     case Event::Weekly:
00042         buf += "Weekly";
00043         break;
00044     case Event::MonthlyDay:
00045         buf += "MonthlyDay";
00046         break;
00047     case Event::MonthlyDate:
00048         buf += "MonthlyDate";
00049         break;
00050     case Event::Yearly:
00051         buf += "Yearly";
00052         break;
00053     default:
00054         buf += "NoRepeat";
00055         break;
00056     }
00057     buf += "\"";
00058     if ( r.days > 0 )
00059     buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\"";
00060     if ( r.position != 0 )
00061     buf += " rposition=\"" + QString::number( r.position ) + "\"";
00062 
00063     buf += " rfreq=\"" + QString::number( r.frequency ) + "\"";
00064     buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\"";
00065      if ( r.hasEndDate )
00066     buf += " enddt=\""
00067            + QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) )
00068            + "\"";
00069     buf += " created=\"" + QString::number( r.createTime ) + "\"";
00070 }
00071 
00072 Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia );
00073 
00323 Event::Event() : Record()
00324 {
00325     startUTC = endUTC = time( 0 );
00326     typ = Normal;
00327     hAlarm = FALSE;
00328     hRepeat = FALSE;
00329     aMinutes = 0;
00330     aSound = Silent;
00331     pattern.type = NoRepeat;
00332     pattern.frequency = -1;
00333 }
00334 
00338 Event::Event( const QMap<int, QString> &map )
00339 {
00340     setDescription( map[DatebookDescription] );
00341     setLocation( map[Location] );
00342     setCategories( idsFromString( map[DatebookCategory] ) );
00343     setTimeZone( map[TimeZone] );
00344     setNotes( map[Note] );
00345     setStart( TimeConversion::fromUTC( map[StartDateTime].toUInt() ) );
00346     setEnd( TimeConversion::fromUTC( map[EndDateTime].toUInt() ) );
00347     setType( (Event::Type) map[DatebookType].toInt() );
00348     setAlarm( ( map[HasAlarm] == "1" ? TRUE : FALSE ), map[AlarmTime].toInt(), (Event::SoundTypeChoice)map[SoundType].toInt() );
00349     Event::RepeatPattern p;
00350     p.type = (Event::RepeatType) map[ RepeatPatternType ].toInt();
00351     p.frequency = map[ RepeatPatternFrequency ].toInt();
00352     p.position = map[ RepeatPatternPosition ].toInt();
00353     p.days = map[ RepeatPatternDays ].toInt();
00354     p.hasEndDate = map[ RepeatPatternHasEndDate ].toInt();
00355     p.endDateUTC = map[ RepeatPatternEndDate ].toUInt();
00356     setRepeat( p );
00357 
00358     setUid( map[ DatebookUid ].toInt() );
00359 }
00360 
00364 Event::~Event()
00365 {
00366 }
00367 
00371 int Event::week( const QDate& date )
00372 {
00373     // Calculates the week this date is in within that
00374     // month. Equals the "row" is is in in the month view
00375     int week = 1;
00376     QDate tmp( date.year(), date.month(), 1 );
00377 
00378     if ( date.dayOfWeek() < tmp.dayOfWeek() )
00379     ++week;
00380 
00381     week += ( date.day() - 1 ) / 7;
00382     return week;
00383 }
00384 
00388 int Event::occurrence( const QDate& date )
00389 {
00390     // calculates the number of occurrances of this day of the
00391     // week till the given date (e.g 3rd Wednesday of the month)
00392     return ( date.day() - 1 ) / 7 + 1;
00393 }
00394 
00398 int Event::dayOfWeek( char day )
00399 {
00400     int dayOfWeek = 1;
00401     char i = Event::MON;
00402     while ( !( i & day ) && i <= Event::SUN ) {
00403     i <<= 1;
00404     ++dayOfWeek;
00405     }
00406     return dayOfWeek;
00407 }
00408 
00412 int Event::monthDiff( const QDate& first, const QDate& second )
00413 {
00414     return ( second.year() - first.year() ) * 12 +
00415     second.month() - first.month();
00416 }
00417 
00421 QMap<int, QString> Event::toMap() const
00422 {
00423     QMap<int, QString> m;
00424 
00425     if ( !description().isEmpty() )
00426     m.insert( DatebookDescription, description() );
00427     if ( !location().isEmpty() )
00428     m.insert ( Location, location() );
00429     if ( categories().count() )
00430     m.insert ( DatebookCategory, idsToString( categories() ) );
00431     if ( !timeZone().isEmpty() )
00432     m.insert ( TimeZone, timeZone() );
00433     if ( !notes().isEmpty() )
00434     m.insert ( Note, notes() );
00435 
00436     m.insert ( StartDateTime, QString::number( TimeConversion::toUTC( start() ) ) );
00437     m.insert ( EndDateTime, QString::number( TimeConversion::toUTC( end() ) ) );
00438     m.insert ( DatebookType, QString::number( (int)type() ) );
00439     m.insert ( HasAlarm, ( hasAlarm() ? "1" : "0" ) );
00440     m.insert ( SoundType, QString::number( (int)alarmSound() ) );
00441     m.insert ( AlarmTime, QString::number( alarmTime() ) );
00442     m.insert ( RepeatPatternType, QString::number( static_cast<int>( repeatPattern().type ) ) );
00443     m.insert ( RepeatPatternFrequency, QString::number( repeatPattern().frequency ) );
00444     m.insert ( RepeatPatternPosition, QString::number( repeatPattern().position ) );
00445     m.insert ( RepeatPatternDays, QString::number( repeatPattern().days ) );
00446     m.insert ( RepeatPatternHasEndDate, QString::number( static_cast<int>( repeatPattern().hasEndDate ) ) );
00447     m.insert ( RepeatPatternEndDate, QString::number( repeatPattern().endDateUTC ) );
00448 
00449     m.insert( DatebookUid, QString::number( uid()) );
00450 
00451     return m;
00452 }
00453 
00457 void Event::setRepeat( const RepeatPattern &p )
00458 {
00459     setRepeat( p.type != NoRepeat, p );
00460 }
00461 
00465 void Event::setDescription( const QString &s )
00466 {
00467     descript = s;
00468 }
00469 
00473 void Event::setLocation( const QString &s )
00474 {
00475     locat = s;
00476 }
00477 
00478 // void Event::setCategory( const QString &s )
00479 // {
00480 //     categ = s;
00481 // }
00482 
00486 void Event::setType( Type t )
00487 {
00488     typ = t;
00489 }
00490 
00495 void Event::setStart( const QDateTime &d )
00496 {
00497     startUTC = TimeConversion::toUTC( d );
00498 }
00499 
00503 void Event::setStart( time_t time )
00504 {
00505     startUTC = time;
00506 }
00507 
00512 void Event::setEnd( const QDateTime &d )
00513 {
00514     endUTC = TimeConversion::toUTC( d );
00515 }
00516 
00520 void Event::setEnd( time_t time )
00521 {
00522     endUTC = time;
00523 }
00524 
00528 void Event::setTimeZone( const QString &z )
00529 {
00530     tz = z;
00531 }
00532 
00536 void Event::setAlarm( bool b, int minutes, SoundTypeChoice s )
00537 {
00538     hAlarm = b;
00539     aMinutes = minutes;
00540     aSound = s;
00541 }
00542 
00546 void Event::setRepeat( bool b, const RepeatPattern &p )
00547 {
00548     hRepeat = b;
00549     pattern = p;
00550 }
00551 
00555 void Event::setNotes( const QString &n )
00556 {
00557     note = n;
00558 }
00559 
00563 const QString &Event::description() const
00564 {
00565     return descript;
00566 }
00567 
00571 const QString &Event::location() const
00572 {
00573     return locat;
00574 }
00575 
00576 // QString Event::category() const
00577 // {
00578 //     return categ;
00579 // }
00580 
00584 Event::Type Event::type() const
00585 {
00586     return typ;
00587 }
00588 /*
00589 QDateTime Event::start() const {
00590     return start( TRUE );
00591 }
00592 */
00596 QDateTime Event::start( bool actual ) const
00597 {
00598     QDateTime dt = TimeConversion::fromUTC( startUTC );
00599 
00600     if ( actual && typ == AllDay ) {
00601     QTime t = dt.time();
00602     t.setHMS( 0, 0, 0 );
00603     dt.setTime( t );
00604     }
00605     return dt;
00606 }
00607 /*
00608 QDateTime Event::end() const {
00609     return end( TRUE );
00610 }
00611 */
00615 QDateTime Event::end( bool actual ) const
00616 {
00617     QDateTime dt = TimeConversion::fromUTC( endUTC );
00618     if ( actual && typ == AllDay ) {
00619     dt.setTime( QTime(23,59,59) );
00620     }
00621     return dt;
00622 }
00623 
00627 const QString &Event::timeZone() const
00628 {
00629     return tz;
00630 }
00631 
00635 bool Event::hasAlarm() const
00636 {
00637     return hAlarm;
00638 }
00639 
00643 int Event::alarmTime() const
00644 {
00645     return aMinutes;
00646 }
00647 
00651 Event::SoundTypeChoice Event::alarmSound() const
00652 {
00653     return aSound;
00654 }
00655 
00659 bool Event::hasRepeat() const
00660 {
00661     return doRepeat();
00662 }
00663 
00667 const Event::RepeatPattern &Event::repeatPattern() const
00668 {
00669     return pattern;
00670 }
00671 
00675 Event::RepeatPattern &Event::repeatPattern()
00676 {
00677     return pattern;
00678 }
00679 
00683 const QString &Event::notes() const
00684 {
00685     return note;
00686 }
00687 
00691 bool Event::operator==( const Event &e ) const
00692 {
00693     if ( uid() && e.uid() == uid() )
00694     return TRUE;
00695     return ( e.descript == descript &&
00696          e.locat == locat &&
00697          e.categ == categ &&
00698          e.typ == typ &&
00699          e.startUTC == startUTC &&
00700          e.endUTC == endUTC &&
00701          e.tz == tz &&
00702          e.hAlarm == hAlarm &&
00703          e.aMinutes == aMinutes &&
00704          e.aSound == aSound &&
00705          e.hRepeat == hRepeat &&
00706          e.pattern == pattern &&
00707          e.note == note );
00708 }
00709 
00714 void Event::save( QString& buf )
00715 {
00716     buf += " description=\"" + Qtopia::escapeString(descript) + "\"";
00717     if ( !locat.isEmpty() )
00718     buf += " location=\"" + Qtopia::escapeString(locat) + "\"";
00719     // save the categoies differently....
00720     QString strCats = idsToString( categories() );
00721     buf += " categories=\"" + Qtopia::escapeString(strCats) + "\"";
00722     buf += " uid=\"" + QString::number( uid() ) + "\"";
00723     if ( (Type)typ != Normal )
00724     buf += " type=\"AllDay\"";
00725     if ( hAlarm ) {
00726     buf += " alarm=\"" + QString::number( aMinutes ) + "\" sound=\"";
00727     if ( aSound == Event::Loud )
00728         buf += "loud";
00729     else
00730         buf += "silent";
00731     buf += "\"";
00732     }
00733     if ( hRepeat )
00734     write( buf, pattern );
00735 
00736     buf += " start=\""
00737        + QString::number( startUTC )
00738        + "\"";
00739 
00740     buf += " end=\""
00741        + QString::number( endUTC )
00742        + "\"";
00743 
00744     if ( !note.isEmpty() )
00745     buf += " note=\"" + Qtopia::escapeString( note ) + "\"";
00746     buf += customToXml();
00747 }
00748 
00752 bool Event::RepeatPattern::operator==( const Event::RepeatPattern &right ) const
00753 {
00754     // *sigh*
00755     return ( type == right.type
00756          && frequency == right.frequency
00757          && position == right.position
00758          && days == right.days
00759          && hasEndDate == right.hasEndDate
00760          && endDateUTC == right.endDateUTC
00761          && createTime == right.createTime );
00762 }
00763 
00787 class EffectiveEventPrivate
00788 {
00789 public:
00790     //currently the existence of the d pointer means multi-day repeating,
00791     //msut be changed if we use the d pointer for anything else.
00792     QDate startDate;
00793     QDate endDate;
00794 };
00795 
00799 EffectiveEvent::EffectiveEvent()
00800 {
00801     mDate = QDate::currentDate();
00802     mStart = mEnd = QTime::currentTime();
00803     d = 0;
00804 }
00805 
00809 EffectiveEvent::EffectiveEvent( const Event &e, const QDate &date, Position pos )
00810 {
00811     mEvent = e;
00812     mDate = date;
00813     if ( pos & Start )
00814     mStart = e.start( TRUE ).time();
00815     else
00816     mStart = QTime( 0, 0, 0 );
00817 
00818     if ( pos & End )
00819     mEnd = e.end( TRUE ).time();
00820     else
00821     mEnd = QTime( 23, 59, 59 );
00822     d = 0;
00823 }
00824 
00828 EffectiveEvent::~EffectiveEvent()
00829 {
00830     delete d;
00831 }
00832 
00836 EffectiveEvent::EffectiveEvent( const EffectiveEvent &e )
00837 {
00838     d = 0;
00839     *this = e;
00840 }
00841 
00842 EffectiveEvent& EffectiveEvent::operator=( const EffectiveEvent & e )
00843 {
00844     if ( &e == this )
00845     return *this;
00846     delete d;
00847     if ( e.d ) {
00848     d = new EffectiveEventPrivate;
00849     d->startDate = e.d->startDate;
00850     d->endDate = e.d->endDate;
00851     } else {
00852     d = 0;
00853     }
00854     mEvent = e.mEvent;
00855     mDate = e.mDate;
00856     mStart = e.mStart;
00857     mEnd = e.mEnd;
00858 
00859     return *this;
00860 
00861 }
00862 
00863 // QString EffectiveEvent::category() const
00864 // {
00865 //     return mEvent.category();
00866 // }
00867 
00871 const QString &EffectiveEvent::description( ) const
00872 {
00873     return mEvent.description();
00874 }
00875 
00879 const QString &EffectiveEvent::location( ) const
00880 {
00881     return mEvent.location();
00882 }
00883 
00887 const QString &EffectiveEvent::notes() const
00888 {
00889     return mEvent.notes();
00890 }
00891 
00895 const Event &EffectiveEvent::event() const
00896 {
00897     return mEvent;
00898 }
00899 
00903 const QTime &EffectiveEvent::end() const
00904 {
00905     return mEnd;
00906 }
00907 
00911 const QTime &EffectiveEvent::start() const
00912 {
00913     return mStart;
00914 }
00915 
00919 const QDate &EffectiveEvent::date() const
00920 {
00921     return mDate;
00922 }
00923 
00927 int EffectiveEvent::length() const
00928 {
00929     return (mEnd.hour() * 60 - mStart.hour() * 60)
00930        + QABS(mStart.minute() - mEnd.minute() );
00931 }
00932 
00936 void EffectiveEvent::setDate( const QDate &dt )
00937 {
00938     mDate = dt;
00939 }
00940 
00944 void EffectiveEvent::setStart( const QTime &start )
00945 {
00946     mStart = start;
00947 }
00948 
00952 void EffectiveEvent::setEnd( const QTime &end )
00953 {
00954     mEnd = end;
00955 }
00956 
00960 void EffectiveEvent::setEvent( Event e )
00961 {
00962     mEvent = e;
00963 }
00964 
00968 bool EffectiveEvent::operator<( const EffectiveEvent &e ) const
00969 {
00970     if ( mDate < e.date() )
00971     return TRUE;
00972     if ( mDate == e.date() )
00973     return ( mStart < e.start() );
00974     else
00975     return FALSE;
00976 }
00977 
00981 bool EffectiveEvent::operator<=( const EffectiveEvent &e ) const
00982 {
00983     return (mDate <= e.date() );
00984 }
00985 
00989 bool EffectiveEvent::operator==( const EffectiveEvent &e ) const
00990 {
00991     return ( mDate == e.date()
00992          && mStart == e.start()
00993          && mEnd == e.end()
00994          && mEvent == e.event() );
00995 }
00996 
01000 bool EffectiveEvent::operator!=( const EffectiveEvent &e ) const
01001 {
01002     return !(*this == e);
01003 }
01004 
01008 bool EffectiveEvent::operator>( const EffectiveEvent &e ) const
01009 {
01010     return !(*this <= e );
01011 }
01012 
01016 bool EffectiveEvent::operator>=(const EffectiveEvent &e) const
01017 {
01018     return !(*this < e);
01019 }
01020 
01024 void EffectiveEvent::setEffectiveDates( const QDate &from, const QDate &to )
01025 {
01026     if ( !from.isValid() ) {
01027     delete d;
01028     d = 0;
01029     return;
01030     }
01031     if ( !d )
01032     d = new EffectiveEventPrivate;
01033     d->startDate = from;
01034     d->endDate = to;
01035 }
01036 
01040 QDate EffectiveEvent::startDate() const
01041 {
01042     if ( d )
01043     return d->startDate;
01044     else if ( mEvent.hasRepeat() )
01045     return mDate; // single day, since multi-day should have a d pointer
01046     else
01047     return mEvent.start().date();
01048 }
01049 
01053 QDate EffectiveEvent::endDate() const
01054 {
01055     if ( d )
01056     return d->endDate;
01057     else if ( mEvent.hasRepeat() )
01058     return mDate; // single day, since multi-day should have a d pointer
01059     else
01060     return mEvent.end().date();
01061 }
01062 
01066 int EffectiveEvent::size() const
01067 {
01068     return ( mEnd.hour() - mStart.hour() ) * 3600
01069          + (mEnd.minute() - mStart.minute() * 60
01070          + mEnd.second() - mStart.second() );
01071 }
01072 
01073 
01074 // vcal conversion code
01075 static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
01076 {
01077     VObject *ret = 0;
01078     if ( o && !value.isEmpty() )
01079     ret = addPropValue( o, prop, value.latin1() );
01080     return ret;
01081 }
01082 
01083 static inline VObject *safeAddProp( VObject *o, const char *prop)
01084 {
01085     VObject *ret = 0;
01086     if ( o )
01087     ret = addProp( o, prop );
01088     return ret;
01089 }
01090 
01091 /*
01092  * Until we support vCal/iCal right
01093  * we will make DTSTART and other things
01094  * be floating in the sense of
01095  * RFC 2445
01096  */
01097 namespace {
01098 /*
01099  * Convert QDateTime to iso8601 but take
01100  * local time and do not use the Z at the end
01101  *
01102  */
01103     QCString toISOLocal( const QDateTime& dt ) {
01104         QCString str;
01105         /*
01106          * year month day T Hour Minute Second
01107          *  4    2     2     2    2       2    digits
01108          */
01109         str.sprintf("%04d%02d%02dT%02d%02d%02d",
01110                     dt.date().year(),
01111                     dt.date().month(),
01112                     dt.date().day(),
01113                     dt.time().hour(),
01114                     dt.time().minute(),
01115                     dt.time().second() );
01116 
01117         qWarning("Str ist %s", str.data() );
01118 
01119         return str;
01120     }
01121 
01122 
01123 };
01124 
01125 static VObject *createVObject( const Event &e )
01126 {
01127     VObject *vcal = newVObject( VCCalProp );
01128     safeAddPropValue( vcal, VCVersionProp, "1.0" );
01129     VObject *event = safeAddProp( vcal, VCEventProp );
01130 
01131     safeAddPropValue( event, VCDTstartProp, toISOLocal( e.start() ) );
01132     safeAddPropValue( event, VCDTendProp, toISOLocal( e.end() ) );
01133     safeAddPropValue( event, "X-Qtopia-NOTES", e.description() );
01134     safeAddPropValue( event, VCDescriptionProp, e.description() );
01135     safeAddPropValue( event, VCLocationProp, e.location() );
01136 
01137     if ( e.hasAlarm() ) {
01138     VObject *alarm = safeAddProp( event, VCAAlarmProp );
01139     QDateTime dt = e.start();
01140     dt = dt.addSecs( -e.alarmTime()*60 );
01141     safeAddPropValue( alarm, VCRunTimeProp, toISOLocal( dt ) );
01142     safeAddPropValue( alarm, VCAudioContentProp,
01143               (e.alarmSound() == Event::Silent ? "silent" : "alarm" ) );
01144     }
01145 
01146     safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone() );
01147 
01148     if ( e.type() == Event::AllDay )
01149     safeAddPropValue( event, "X-Qtopia-AllDay", e.timeZone() );
01150 
01151     // ### repeat missing
01152 
01153     // ### categories missing
01154 
01155     return vcal;
01156 }
01157 
01158 
01159 static Event parseVObject( VObject *obj )
01160 {
01161     Event e;
01162 
01163     bool haveAlarm = FALSE;
01164     bool haveStart = FALSE;
01165     bool haveEnd = FALSE;
01166     QDateTime alarmTime;
01167     Event::SoundTypeChoice soundType = Event::Silent;
01168 
01169     VObjectIterator it;
01170     initPropIterator( &it, obj );
01171     while( moreIteration( &it ) ) {
01172     VObject *o = nextVObject( &it );
01173     QCString name = vObjectName( o );
01174     QCString value = vObjectStringZValue( o );
01175     if ( name == VCDTstartProp ) {
01176         e.setStart( TimeConversion::fromISO8601( value ) );
01177         haveStart = TRUE;
01178     }
01179     else if ( name == VCDTendProp ) {
01180         e.setEnd( TimeConversion::fromISO8601( value ) );
01181         haveEnd = TRUE;
01182     }
01183     else if ( name == "X-Qtopia-NOTES" ) {
01184         e.setNotes( value );
01185     }
01186     else if ( name == VCDescriptionProp ) {
01187         e.setDescription( value );
01188     }
01189     else if ( name == VCLocationProp ) {
01190         e.setLocation( value );
01191     }
01192     else if ( name == VCAudioContentProp ) {
01193         haveAlarm = TRUE;
01194         VObjectIterator nit;
01195         initPropIterator( &nit, o );
01196         while( moreIteration( &nit ) ) {
01197         VObject *o = nextVObject( &nit );
01198         QCString name = vObjectName( o );
01199         QCString value = vObjectStringZValue( o );
01200         if ( name == VCRunTimeProp )
01201             alarmTime = TimeConversion::fromISO8601( value );
01202         else if ( name == VCAudioContentProp ) {
01203             if ( value == "silent" )
01204             soundType = Event::Silent;
01205             else
01206             soundType = Event::Loud;
01207         }
01208         }
01209     }
01210     else if ( name == "X-Qtopia-TIMEZONE") {
01211         e.setTimeZone( value );
01212     }
01213     else if ( name == "X-Qtopia-AllDay" ) {
01214         e.setType( Event::AllDay );
01215     }
01216 #if 0
01217     else {
01218         printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
01219         VObjectIterator nit;
01220         initPropIterator( &nit, o );
01221         while( moreIteration( &nit ) ) {
01222         VObject *o = nextVObject( &nit );
01223         QCString name = vObjectName( o );
01224         QString value = vObjectStringZValue( o );
01225         printf(" subprop: %s = %s\n", name.data(), value.latin1() );
01226         }
01227     }
01228 #endif
01229     }
01230 
01231     if ( !haveStart && !haveEnd )
01232     e.setStart( QDateTime::currentDateTime() );
01233 
01234     if ( !haveEnd ) {
01235     e.setType( Event::AllDay );
01236     e.setEnd( e.start() );
01237     }
01238 
01239     if ( haveAlarm ) {
01240     int minutes = alarmTime.secsTo( e.start() ) / 60;
01241     e.setAlarm( TRUE, minutes, soundType );
01242     }
01243     return e;
01244 }
01245 
01246 
01250 void Event::writeVCalendar( const QString &filename, const QValueList<Event> &events)
01251 {
01252 
01253     QFileDirect f( filename.utf8().data() );
01254 
01255     if ( !f.open( IO_WriteOnly ) ) {
01256 
01257         qWarning("Unable to open vcard write");
01258 
01259         return;
01260 
01261     }
01262 
01263 
01264     QValueList<Event>::ConstIterator it;
01265     for( it = events.begin(); it != events.end(); ++it ) {
01266     VObject *obj = createVObject( *it );
01267     writeVObject( f.directHandle() , obj );
01268     cleanVObject( obj );
01269     }
01270 
01271 
01272     cleanStrTbl();
01273 }
01274 
01278 void Event::writeVCalendar( const QString &filename, const Event &event)
01279 {
01280 
01281     QFileDirect f( filename.utf8().data() );
01282 
01283     if ( !f.open( IO_WriteOnly ) ) {
01284 
01285         qWarning("Unable to open vcard write");
01286 
01287         return;
01288 
01289     }
01290 
01291 
01292     VObject *obj = createVObject( event );
01293     writeVObject( f.directHandle() , obj );
01294     cleanVObject( obj );
01295 
01296     cleanStrTbl();
01297 }
01298 
01302 QValueList<Event> Event::readVCalendar( const QString &filename )
01303 {
01304     VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
01305 
01306     QValueList<Event> events;
01307 
01308     while ( obj ) {
01309     QCString name = vObjectName( obj );
01310     if ( name == VCCalProp ) {
01311         VObjectIterator nit;
01312         initPropIterator( &nit, obj );
01313         while( moreIteration( &nit ) ) {
01314         VObject *o = nextVObject( &nit );
01315         QCString name = vObjectName( o );
01316         if ( name == VCEventProp )
01317             events.append( parseVObject( o ) );
01318         }
01319     } else if ( name == VCEventProp ) {
01320         // shouldn't happen, but just to be sure
01321         events.append( parseVObject( obj ) );
01322     }
01323     VObject *t = obj;
01324     obj = nextVObjectInList(obj);
01325     cleanVObject( t );
01326     }
01327 
01328     return events;
01329 }
01330 
01331 bool Event::match( const QRegExp &r ) const
01332 {
01333     bool returnMe;
01334     returnMe = false;
01335 
01336     if ( descript.find( r ) > -1 )
01337     returnMe = true;
01338     else if ( locat.find( r ) > -1 )
01339     returnMe = true;
01340     else if ( TimeConversion::fromUTC( startUTC ).toString().find( r ) > -1 )
01341     returnMe = true;
01342     else if ( TimeConversion::fromUTC( endUTC ).toString().find( r )  > -1 )
01343     returnMe = true;
01344     else if ( tz.find( r ) > -1 )
01345     returnMe = true;
01346     else if ( note.find( r ) > -1 )
01347     returnMe = true;
01348     else if ( doRepeat() ) {
01349     if ( pattern.hasEndDate )
01350         if ( TimeConversion::fromUTC( pattern.endDateUTC ).toString().find(r) > -1 )
01351         returnMe = true;
01352     }
01353     return returnMe;
01354 }
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:04 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001