Qtopia library API Documentation

event.h

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 #ifndef __EVENT_H__
00022 #define __EVENT_H__
00023 
00024 #include <qdatetime.h>
00025 #include <qvaluelist.h>
00026 #include <qcolor.h>
00027 
00028 #ifdef PALMTOPCENTER
00029 #include <qpc/qsorter.h>
00030 #endif
00031 #include <qtopia/private/palmtoprecord.h>
00032 
00033 #include <qpe/timeconversion.h>
00034 
00035 static const QColor colorNormal      = QColor(255, 0  , 0  );
00036 static const QColor colorRepeat      = QColor(0  , 0  , 255);
00037 static const QColor colorNormalLight = QColor(255, 220, 220);
00038 static const QColor colorRepeatLight = QColor(200, 200, 255);
00039 
00040 class EventPrivate;
00041 class QPC_EXPORT Event : public Qtopia::Record
00042 {
00043 public:
00044     enum RepeatType { NoRepeat = -1, Daily, Weekly, MonthlyDay,
00045                       MonthlyDate, Yearly };
00046 
00047     // Don't use this.
00048     enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
00049                 FRI = 0x10, SAT = 0x20, SUN = 0x40 };
00050     // Don't use this.
00051     struct QPC_EXPORT RepeatPattern
00052     {
00053     RepeatPattern() {
00054         type = NoRepeat; frequency = -1; days = 0;  position = 0; createTime = -1;
00055         hasEndDate = FALSE; endDateUTC = 0; }
00056     bool operator ==( const RepeatPattern &right ) const;
00057 
00058     RepeatType type;
00059     int frequency;
00060     int position;   // the posistion in the month (e.g. the first sunday, etc) positive, count from the front negative count from the end...
00061     char days;  // a mask for days OR in your days!
00062     bool hasEndDate;
00063     QDate endDate() const { return TimeConversion::fromUTC( endDateUTC ).date(); }
00064     void setEndDate( const QDate &dt ) { endDateUTC = TimeConversion::toUTC( dt ); }
00065     time_t endDateUTC;
00066     time_t createTime;
00067     };
00068 
00069     Event();
00070     Event( const QMap<int, QString > & map );
00071     virtual ~Event();
00072 
00073     QMap<int, QString> toMap() const;
00074 
00075     static void writeVCalendar( const QString &filename, const QValueList<Event> &events);
00076     static void writeVCalendar( const QString &filename, const Event &event);
00077     static QValueList<Event> readVCalendar( const QString &filename );
00078 
00079     enum Type { Normal, AllDay };
00080     enum SoundTypeChoice { Silent, Loud };
00081 
00082     // Don't use these, there are essentially meaningless.
00083     bool operator<( const Event &e1) const { return start() < e1.start(); };
00084     bool operator<=( const Event &e1 ) const { return start() <= e1.start(); };
00085     bool operator!=( const Event &e1 ) const { return !( *this == e1 ); };
00086     bool operator>( const Event &e1 ) const { return start() > e1.start(); };
00087     bool operator>=(const Event &e1 ) const { return start() >= e1.start(); };
00088     bool operator==( const Event &e ) const;
00089 
00090     void setDescription( const QString &s );
00091     const QString &description() const;
00092 
00093     void setLocation( const QString &s );
00094     const QString &location() const;
00095 
00096     void setNotes( const QString &n );
00097     const QString &notes() const;
00098 
00099     void setType( Type t ); // Don't use me.
00100     Type type() const; // Don't use me.
00101 
00102     void setAllDay(bool);
00103     bool isAllDay() const;
00104 
00105     void setStart( const QDateTime &d );
00106     void setStart( time_t time ); // don't use me.
00107     QDateTime start( bool actual = FALSE) const; // don't use me.
00108     time_t startTime() const { return startUTC; } // don't use me.
00109     void setEnd( const QDateTime &e );
00110     void setEnd( time_t time ); // don't use me
00111     QDateTime end( bool actual = FALSE ) const; // don't use me.
00112     time_t endTime() const { return endUTC; } // don't use me.
00113     void setTimeZone( const QString & );
00114     const QString &timeZone() const;
00115     void setAlarm( int minutes, SoundTypeChoice );
00116     void clearAlarm();
00117     void setAlarm( bool b, int minutes, SoundTypeChoice ); // Don't use me.
00118     bool hasAlarm() const;
00119     int alarmDelay() const;
00120     int alarmTime() const; // Don't use me.
00121     SoundTypeChoice alarmSound() const;
00122 
00123     RepeatType repeatType() const;
00124     int frequency() const;
00125     int weekOffset() const;
00126     QDate repeatTill() const;
00127     bool repeatForever() const;
00128     bool repeatOnWeekDay(int day) const;
00129 
00130     void setRepeatType(RepeatType);
00131     void setFrequency(int);
00132     void setRepeatTill(const QDate &);
00133     void setRepeatForever(bool);
00134     void setRepeatOnWeekDay(int day, bool enable);
00135 
00136     // Don't use any of these.
00137     void setRepeat( bool b, const RepeatPattern &p );
00138     void setRepeat( const RepeatPattern &p );
00139     bool hasRepeat() const;
00140     const RepeatPattern &repeatPattern() const;
00141     RepeatPattern &repeatPattern();
00142     bool doRepeat() const { return pattern.type != NoRepeat; }
00143 
00144     void save( QString& buf );
00145     //void load( Node *n );
00146 
00147     bool match( const QRegExp &r ) const;
00148 
00149     // Don't use these either.  Functionality will be moved elsewhere.
00150 
00151     // helper function to calculate the week of the given date
00152     static int week( const QDate& date );
00153     // calculates the number of occurrences of the week day of
00154     // the given date from the start of the month
00155     static int occurrence( const QDate& date );
00156     // returns a proper days-char for a given dayOfWeek()
00157     static char day( int dayOfWeek ) { return 1 << ( dayOfWeek - 1 ); }
00158     // returns the dayOfWeek for the *first* day it finds (ignores
00159     // any further days!). Returns 1 (Monday) if there isn't any day found
00160     static int dayOfWeek( char day );
00161     // returns the difference of months from first to second.
00162     static int monthDiff( const QDate& first, const QDate& second );
00163 
00164 private:
00165     Qtopia::UidGen &uidGen() { return sUidGen; }
00166     static Qtopia::UidGen sUidGen;
00167 
00168     QString descript, locat, categ;
00169     Type typ : 4;
00170     bool startTimeDirty : 1;
00171     bool endTimeDirty : 1;
00172     time_t startUTC, endUTC;
00173     QString tz;
00174     bool hAlarm, hRepeat;
00175     int aMinutes;
00176     SoundTypeChoice aSound;
00177     RepeatPattern pattern;
00178     QString note;
00179     // ADDITION
00180     int mRid;   // Recode ID
00181     int mRinfo; // Recode Info
00182     //
00183     EventPrivate *d;
00184 
00185 };
00186 
00187 // Since an event spans multiple day, it is better to have this
00188 // class to represent a day instead of creating many
00189 // dummy events...
00190 
00191 class EffectiveEventPrivate;
00192 class QPC_EXPORT EffectiveEvent
00193 {
00194 public:
00195     // If we calculate the effective event of a multi-day event
00196     // we have to figure out whether we are at the first day,
00197     // at the end, or anywhere else ("middle"). This is important
00198     // for the start/end times (00:00/23:59)
00199     // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
00200     //         day event
00201     // Start: start time -> 23:59
00202     // End: 00:00 -> end time
00203     // Start | End == StartEnd: for single-day events (default)
00204     //                          here we draw start time -> end time
00205     enum Position { MidWay = 0, Start = 1, End = 2, StartEnd = 3 };
00206 
00207     EffectiveEvent();
00208     EffectiveEvent( const Event &event, const QDate &startDate, Position pos = StartEnd );
00209     EffectiveEvent( const EffectiveEvent & );
00210     EffectiveEvent& operator=( const EffectiveEvent & );
00211     ~EffectiveEvent();
00212 
00213 
00214     bool operator<( const EffectiveEvent &e ) const;
00215     bool operator<=( const EffectiveEvent &e ) const;
00216     bool operator==( const EffectiveEvent &e ) const;
00217     bool operator!=( const EffectiveEvent &e ) const;
00218     bool operator>( const EffectiveEvent &e ) const;
00219     bool operator>= ( const EffectiveEvent &e ) const;
00220 
00221     void setStart( const QTime &start );
00222     void setEnd( const QTime &end );
00223     void setEvent( Event e );
00224     void setDate( const QDate &date );
00225     void setEffectiveDates( const QDate &from, const QDate &to );
00226 
00227     //    QString category() const;
00228     const QString &description() const;
00229     const QString &location() const;
00230     const QString &notes() const;
00231     const Event &event() const;
00232     const QTime &start() const;
00233     const QTime &end() const;
00234     const QDate &date() const;
00235     int length() const;
00236     int size() const;
00237 
00238     QDate startDate() const;
00239     QDate endDate() const;
00240 
00241 private:
00242     class EffectiveEventPrivate *d;
00243     Event mEvent;
00244     QDate mDate;
00245     QTime mStart,
00246       mEnd;
00247 
00248 };
00249 
00250 inline void Event::setAlarm( int minutes, SoundTypeChoice s )
00251 {
00252     setAlarm(TRUE, minutes, s);
00253 }
00254 
00255 inline void Event::clearAlarm()
00256 {
00257     setAlarm(FALSE, 0, Silent);
00258 }
00259 
00260 inline int Event::alarmDelay() const
00261 {
00262     return alarmTime();
00263 }
00264 
00265 inline void Event::setAllDay(bool enable)
00266 {
00267     if (enable)
00268     setType(AllDay);
00269     else
00270     setType(Normal);
00271 };
00272 
00273 inline bool Event::isAllDay() const
00274 {
00275     return type() == AllDay;
00276 }
00277 
00278 inline Event::RepeatType Event::repeatType() const
00279 {
00280     return repeatPattern().type;
00281 }
00282 
00283 inline int Event::frequency() const
00284 {
00285     return repeatPattern().frequency;
00286 }
00287 
00288 inline int Event::weekOffset() const
00289 {
00290     if (start().date().day() == 1)
00291     return 1;
00292     return (start().date().day() - 1) / 7 + 1;
00293 }
00294 
00295 inline QDate Event::repeatTill() const
00296 {
00297     return repeatPattern().endDate();
00298 }
00299 
00300 inline bool Event::repeatForever() const
00301 {
00302     return !repeatPattern().hasEndDate;
00303 }
00304 
00305 inline void Event::setRepeatType(RepeatType t)
00306 {
00307     pattern.type = t;
00308 }
00309 
00310 inline void Event::setFrequency(int f)
00311 {
00312     pattern.frequency = f;
00313 }
00314 
00315 inline void Event::setRepeatTill(const QDate &d)
00316 {
00317     pattern.setEndDate(d);
00318     pattern.hasEndDate = TRUE;
00319 }
00320 
00321 inline void Event::setRepeatForever(bool b)
00322 {
00323     if (!b == pattern.hasEndDate)
00324     return;
00325     if (!b && !pattern.hasEndDate)
00326     pattern.setEndDate(end().date());
00327     pattern.hasEndDate = !b;
00328 }
00329 
00330 inline bool Event::repeatOnWeekDay(int day) const
00331 {
00332     if (pattern.type != Weekly)
00333     return FALSE;
00334     return ( (1 << (day - 1)) & pattern.days ) != 0;
00335 }
00336 
00337 inline void Event::setRepeatOnWeekDay(int day, bool enable)
00338 {
00339     if ( repeatOnWeekDay( day ) != enable )
00340     pattern.days ^= 1 << (day - 1);
00341 }
00342 #ifdef PALMTOPCENTER
00343 class QPC_EXPORT EffectiveEventSizeSorter : public QSorter<EffectiveEvent>
00344 {
00345 public:
00346     int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const
00347     {
00348     return a.size() - b.size();
00349     }
00350 };
00351 
00352 class QPC_EXPORT EffectiveEventTimeSorter : public QSorter<EffectiveEvent>
00353 {
00354 public:
00355     int compare( const EffectiveEvent& a, const EffectiveEvent& b ) const
00356     {
00357     return a.start().secsTo( b.start() );
00358     }
00359 };
00360 #endif
00361 
00362 #endif
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