00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00048 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
00049 FRI = 0x10, SAT = 0x20, SUN = 0x40 };
00050
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;
00061 char 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
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 ¬es() const;
00098
00099 void setType( Type t );
00100 Type type() const;
00101
00102 void setAllDay(bool);
00103 bool isAllDay() const;
00104
00105 void setStart( const QDateTime &d );
00106 void setStart( time_t time );
00107 QDateTime start( bool actual = FALSE) const;
00108 time_t startTime() const { return startUTC; }
00109 void setEnd( const QDateTime &e );
00110 void setEnd( time_t time );
00111 QDateTime end( bool actual = FALSE ) const;
00112 time_t endTime() const { return endUTC; }
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 );
00118 bool hasAlarm() const;
00119 int alarmDelay() const;
00120 int alarmTime() const;
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
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
00146
00147 bool match( const QRegExp &r ) const;
00148
00149
00150
00151
00152 static int week( const QDate& date );
00153
00154
00155 static int occurrence( const QDate& date );
00156
00157 static char day( int dayOfWeek ) { return 1 << ( dayOfWeek - 1 ); }
00158
00159
00160 static int dayOfWeek( char day );
00161
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
00180 int mRid;
00181 int mRinfo;
00182
00183 EventPrivate *d;
00184
00185 };
00186
00187
00188
00189
00190
00191 class EffectiveEventPrivate;
00192 class QPC_EXPORT EffectiveEvent
00193 {
00194 public:
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
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
00228 const QString &description() const;
00229 const QString &location() const;
00230 const QString ¬es() 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