summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/event.cpp115
-rw-r--r--libkcal/event.h2
-rw-r--r--libkcal/incidencebase.cpp8
-rw-r--r--libkcal/incidencebase.h4
4 files changed, 128 insertions, 1 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 7cd81fa..235ae55 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -150,48 +150,163 @@ bool Event::hasEndDate() const
150 150
151bool Event::isMultiDay() const 151bool Event::isMultiDay() const
152{ 152{
153 bool multi = !(dtStart().date() == dtEnd().date()); 153 bool multi = !(dtStart().date() == dtEnd().date());
154 return multi; 154 return multi;
155} 155}
156 156
157void Event::setTransparency(Event::Transparency transparency) 157void Event::setTransparency(Event::Transparency transparency)
158{ 158{
159 if (mReadOnly) return; 159 if (mReadOnly) return;
160 mTransparency = transparency; 160 mTransparency = transparency;
161 updated(); 161 updated();
162} 162}
163 163
164Event::Transparency Event::transparency() const 164Event::Transparency Event::transparency() const
165{ 165{
166 return mTransparency; 166 return mTransparency;
167} 167}
168 168
169void Event::setDuration(int seconds) 169void Event::setDuration(int seconds)
170{ 170{
171 setHasEndDate(false); 171 setHasEndDate(false);
172 Incidence::setDuration(seconds); 172 Incidence::setDuration(seconds);
173} 173}
174bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, bool inFutureOnly )
175{
176 if ( testEvent == this )
177 return false;
178 if ( ! doesRecur() && !testEvent->doesRecur() ) {
179 QDateTime te;
180 if ( testEvent->doesFloat() )
181 te = testEvent->mDtEnd.addDays( 1 );
182 else
183 te = testEvent->mDtEnd;
184 QDateTime e;
185 if ( doesFloat() )
186 e = mDtEnd.addDays( 1 );
187 else
188 e = mDtEnd;
189 if ( mDtStart < te && testEvent->mDtStart < e ) {
190 if ( mDtStart < testEvent->mDtStart )
191 *overlapDT = testEvent->mDtStart;
192 else
193 *overlapDT = mDtStart;
194 if ( inFutureOnly )
195 return (*overlapDT >= QDateTime::currentDateTime() );
196 return true;
197 }
198 return false;
199 }
200 Event *nonRecur = 0;
201 Event *recurEvent = 0;
202 if ( ! doesRecur() ) {
203 nonRecur = this;
204 recurEvent = testEvent;
205 }
206 else if ( !testEvent->doesRecur() ) {
207 nonRecur = testEvent;
208 recurEvent = this;
209 }
210 if ( nonRecur ) {
211 QDateTime enr;
212 if ( nonRecur->doesFloat() )
213 enr = nonRecur->mDtEnd.addDays( 1 );
214 else
215 enr = nonRecur->mDtEnd;
216 if ( enr < recurEvent->mDtStart )
217 return false;
218 if ( inFutureOnly && enr < QDateTime::currentDateTime() )
219 return false;
220 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd );
221 if ( recurEvent->doesFloat() )
222 recDuration += 86400;
223 bool ok = true;
224 QDateTime recStart = recurEvent->mDtStart.addSecs( -300);;
225 while ( ok ) {
226 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok );
227 if ( ok ) {
228 if ( recStart > enr )
229 return false;
230 QDateTime recEnd = recStart.addSecs( recDuration );
231 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) {
232 if ( nonRecur->mDtStart < recStart )
233 *overlapDT = recStart;
234 else
235 *overlapDT = nonRecur->mDtStart;
236 if ( inFutureOnly ) {
237 if ( *overlapDT >= QDateTime::currentDateTime() )
238 return true;
239 } else
240 return true;
241 }
242 }
243 }
244 return false;
245 }
246
247 QDateTime incidenceStart = mDtStart;
248 int duration = mDtStart.secsTo( mDtEnd );
249 if ( doesFloat() )
250 duration += 86400;
251 QDateTime testincidenceStart = testEvent->mDtStart;
252 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd );
253 if ( testEvent->doesFloat() )
254 testduration += 86400;
255 bool computeThis = false;
256 if ( incidenceStart < testincidenceStart )
257 computeThis = true;
258 bool ok = true;
259 if ( computeThis )
260 incidenceStart = incidenceStart.addSecs( -300 );
261 else
262 testincidenceStart = testincidenceStart.addSecs( -300 );
263 int count = 0;
264 while ( ok ) {
265 ++count;
266 if ( count > 1000 ) break;
267 if ( computeThis )
268 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok );
269 else
270 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok );
271 if ( ok ) {
272 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) {
273 if ( incidenceStart < testincidenceStart )
274 *overlapDT = testincidenceStart;
275 else
276 *overlapDT = incidenceStart;
277 if ( inFutureOnly ) {
278 if ( *overlapDT >= QDateTime::currentDateTime() )
279 return true;
280 } else
281 return true;
282 }
283 computeThis = ( incidenceStart < testincidenceStart );
284 }
285
286 }
287 return false;
288}
174QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 289QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
175{ 290{
176 *ok = false; 291 *ok = false;
177 if ( !alarmEnabled() ) 292 if ( !alarmEnabled() )
178 return QDateTime (); 293 return QDateTime ();
179 bool yes; 294 bool yes;
180 QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); 295 QDateTime incidenceStart = getNextOccurence( start_dt, &yes );
181 if ( ! yes || cancelled() ) { 296 if ( ! yes || cancelled() ) {
182 *ok = false; 297 *ok = false;
183 return QDateTime (); 298 return QDateTime ();
184 } 299 }
185 300
186 bool enabled = false; 301 bool enabled = false;
187 Alarm* alarm; 302 Alarm* alarm;
188 int off = 0; 303 int off = 0;
189 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 304 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
190 // if ( QDateTime::currentDateTime() > incidenceStart ){ 305 // if ( QDateTime::currentDateTime() > incidenceStart ){
191// *ok = false; 306// *ok = false;
192// return incidenceStart; 307// return incidenceStart;
193// } 308// }
194 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 309 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
195 if (alarm->enabled()) { 310 if (alarm->enabled()) {
196 if ( alarm->hasTime () ) { 311 if ( alarm->hasTime () ) {
197 if ( alarm->time() < alarmStart ) { 312 if ( alarm->time() < alarmStart ) {
diff --git a/libkcal/event.h b/libkcal/event.h
index 287d403..80c11c4 100644
--- a/libkcal/event.h
+++ b/libkcal/event.h
@@ -53,39 +53,41 @@ class Event : public Incidence
53 users locale settings */ 53 users locale settings */
54 QString dtEndTimeStr() const; 54 QString dtEndTimeStr() const;
55 /** returns an event's end date as a string formatted according to the 55 /** returns an event's end date as a string formatted according to the
56 users locale settings */ 56 users locale settings */
57 QString dtEndDateStr(bool shortfmt=true) const; 57 QString dtEndDateStr(bool shortfmt=true) const;
58 /** returns an event's end date and time as a string formatted according 58 /** returns an event's end date and time as a string formatted according
59 to the users locale settings */ 59 to the users locale settings */
60 QString dtEndStr(bool shortfmt=true) const; 60 QString dtEndStr(bool shortfmt=true) const;
61 void setHasEndDate(bool); 61 void setHasEndDate(bool);
62 /** Return whether the event has an end date/time. */ 62 /** Return whether the event has an end date/time. */
63 bool hasEndDate() const; 63 bool hasEndDate() const;
64 64
65 /** Return true if the event spans multiple days, otherwise return false. */ 65 /** Return true if the event spans multiple days, otherwise return false. */
66 bool isMultiDay() const; 66 bool isMultiDay() const;
67 67
68 /** set the event's time transparency level. */ 68 /** set the event's time transparency level. */
69 void setTransparency(Transparency transparency); 69 void setTransparency(Transparency transparency);
70 /** get the event's time transparency level. */ 70 /** get the event's time transparency level. */
71 Transparency transparency() const; 71 Transparency transparency() const;
72 72
73 void setDuration(int seconds); 73 void setDuration(int seconds);
74 74
75 bool contains ( Event*); 75 bool contains ( Event*);
76 76
77 bool isOverlapping ( Event*, QDateTime*, bool inFutureOnly );
78
77 private: 79 private:
78 bool accept(Visitor &v) { return v.visit(this); } 80 bool accept(Visitor &v) { return v.visit(this); }
79 81
80 QDateTime mDtEnd; 82 QDateTime mDtEnd;
81 bool mHasEndDate; 83 bool mHasEndDate;
82 Transparency mTransparency; 84 Transparency mTransparency;
83}; 85};
84 86
85bool operator==( const Event&, const Event& ); 87bool operator==( const Event&, const Event& );
86 88
87 89
88} 90}
89 91
90 92
91#endif 93#endif
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 96039df..dcead02 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -118,48 +118,56 @@ bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
118 if ( i1.duration() != i2.duration() ) 118 if ( i1.duration() != i2.duration() )
119 return false; 119 return false;
120 } 120 }
121 } else { 121 } else {
122 return false; 122 return false;
123 } 123 }
124 124
125 return ( i1.organizer() == i2.organizer() && 125 return ( i1.organizer() == i2.organizer() &&
126 // i1.uid() == i2.uid() && 126 // i1.uid() == i2.uid() &&
127 // Don't compare lastModified, otherwise the operator is not 127 // Don't compare lastModified, otherwise the operator is not
128 // of much use. We are not comparing for identity, after all. 128 // of much use. We are not comparing for identity, after all.
129 i1.doesFloat() == i2.doesFloat() && 129 i1.doesFloat() == i2.doesFloat() &&
130 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 130 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
131 // no need to compare mObserver 131 // no need to compare mObserver
132} 132}
133 133
134 134
135QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 135QDateTime IncidenceBase::getEvenTime( QDateTime dt )
136{ 136{
137 QTime t = dt.time(); 137 QTime t = dt.time();
138 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 138 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
139 return dt; 139 return dt;
140} 140}
141 141
142bool IncidenceBase::isTagged() const
143{
144 return mIsTagged;
145}
146void IncidenceBase::setTagged( bool b)
147{
148 mIsTagged = b;
149}
142void IncidenceBase::setCalID( int id ) 150void IncidenceBase::setCalID( int id )
143{ 151{
144 if ( mCalID > 0 ) 152 if ( mCalID > 0 )
145 updated(); 153 updated();
146 mCalID = id; 154 mCalID = id;
147} 155}
148int IncidenceBase::calID() const 156int IncidenceBase::calID() const
149{ 157{
150 return mCalID; 158 return mCalID;
151} 159}
152void IncidenceBase::setCalEnabled( bool b ) 160void IncidenceBase::setCalEnabled( bool b )
153{ 161{
154 mCalEnabled = b; 162 mCalEnabled = b;
155} 163}
156bool IncidenceBase::calEnabled() const 164bool IncidenceBase::calEnabled() const
157{ 165{
158 return mCalEnabled; 166 return mCalEnabled;
159} 167}
160 168
161void IncidenceBase::setAlarmEnabled( bool b ) 169void IncidenceBase::setAlarmEnabled( bool b )
162{ 170{
163 mAlarmEnabled = b; 171 mAlarmEnabled = b;
164} 172}
165bool IncidenceBase::alarmEnabled() const 173bool IncidenceBase::alarmEnabled() const
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index dc6024a..bccf287 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -126,50 +126,52 @@ class IncidenceBase : public CustomProperties
126 /** Set Pilot Id. */ 126 /** Set Pilot Id. */
127 void setPilotId(int id); 127 void setPilotId(int id);
128 /** Return Pilot Id. */ 128 /** Return Pilot Id. */
129 int pilotId() const; 129 int pilotId() const;
130 130
131 void setTempSyncStat(int id); 131 void setTempSyncStat(int id);
132 int tempSyncStat() const; 132 int tempSyncStat() const;
133 void setIDStr( const QString & ); 133 void setIDStr( const QString & );
134 QString IDStr() const; 134 QString IDStr() const;
135 void setID( const QString &, const QString & ); 135 void setID( const QString &, const QString & );
136 QString getID( const QString & ); 136 QString getID( const QString & );
137 void setCsum( const QString &, const QString & ); 137 void setCsum( const QString &, const QString & );
138 QString getCsum( const QString & ); 138 QString getCsum( const QString & );
139 void removeID(const QString &); 139 void removeID(const QString &);
140 140
141 void registerObserver( Observer * ); 141 void registerObserver( Observer * );
142 void unRegisterObserver( Observer * ); 142 void unRegisterObserver( Observer * );
143 void updated(); 143 void updated();
144 void setCalID( int id ); 144 void setCalID( int id );
145 int calID() const; 145 int calID() const;
146 void setCalEnabled( bool ); 146 void setCalEnabled( bool );
147 bool calEnabled() const; 147 bool calEnabled() const;
148 void setAlarmEnabled( bool ); 148 void setAlarmEnabled( bool );
149 bool alarmEnabled() const; 149 bool alarmEnabled() const;
150 150 bool isTagged() const;
151 void setTagged( bool );
151 protected: 152 protected:
153 bool mIsTagged;
152 QDateTime mDtStart; 154 QDateTime mDtStart;
153 bool mReadOnly; 155 bool mReadOnly;
154 QDateTime getEvenTime( QDateTime ); 156 QDateTime getEvenTime( QDateTime );
155 157
156 private: 158 private:
157 // base components 159 // base components
158 QString mOrganizer; 160 QString mOrganizer;
159 QString mUid; 161 QString mUid;
160 int mCalID; 162 int mCalID;
161 bool mCalEnabled; 163 bool mCalEnabled;
162 bool mAlarmEnabled; 164 bool mAlarmEnabled;
163 QDateTime mLastModified; 165 QDateTime mLastModified;
164 QPtrList<Attendee> mAttendees; 166 QPtrList<Attendee> mAttendees;
165 167
166 bool mFloats; 168 bool mFloats;
167 169
168 int mDuration; 170 int mDuration;
169 bool mHasDuration; 171 bool mHasDuration;
170 QString mExternalId; 172 QString mExternalId;
171 int mTempSyncStat; 173 int mTempSyncStat;
172 174
173 // PILOT SYNCHRONIZATION STUFF 175 // PILOT SYNCHRONIZATION STUFF
174 int mPilotId; // unique id for pilot sync 176 int mPilotId; // unique id for pilot sync
175 int mSyncStatus; // status (for sync) 177 int mSyncStatus; // status (for sync)