summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/event.cpp20
-rw-r--r--libkcal/event.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 5285559..ad66639 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -78,192 +78,212 @@ bool Event::contains ( Event* from )
78 Alarm *a = from->alarms().first(); 78 Alarm *a = from->alarms().first();
79 if ( a->enabled() ){ 79 if ( a->enabled() ){
80 if ( !alarms().count() ) 80 if ( !alarms().count() )
81 return false; 81 return false;
82 Alarm *b = alarms().first(); 82 Alarm *b = alarms().first();
83 if( ! b->enabled() ) 83 if( ! b->enabled() )
84 return false; 84 return false;
85 if ( ! (a->offset() == b->offset() )) 85 if ( ! (a->offset() == b->offset() ))
86 return false; 86 return false;
87 } 87 }
88 } 88 }
89 QStringList cat = categories(); 89 QStringList cat = categories();
90 QStringList catFrom = from->categories(); 90 QStringList catFrom = from->categories();
91 QString nCat; 91 QString nCat;
92 unsigned int iii; 92 unsigned int iii;
93 for ( iii = 0; iii < catFrom.count();++iii ) { 93 for ( iii = 0; iii < catFrom.count();++iii ) {
94 nCat = catFrom[iii]; 94 nCat = catFrom[iii];
95 if ( !nCat.isEmpty() ) 95 if ( !nCat.isEmpty() )
96 if ( !cat.contains( nCat )) { 96 if ( !cat.contains( nCat )) {
97 return false; 97 return false;
98 } 98 }
99 } 99 }
100 if ( from->doesRecur() ) 100 if ( from->doesRecur() )
101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) 101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) )
102 return false; 102 return false;
103 return true; 103 return true;
104} 104}
105 105
106void Event::setDtEnd(const QDateTime &dtEnd) 106void Event::setDtEnd(const QDateTime &dtEnd)
107{ 107{
108 if (mReadOnly) return; 108 if (mReadOnly) return;
109 109
110 mDtEnd = getEvenTime( dtEnd ); 110 mDtEnd = getEvenTime( dtEnd );
111 111
112 setHasEndDate(true); 112 setHasEndDate(true);
113 setHasDuration(false); 113 setHasDuration(false);
114 114
115 updated(); 115 updated();
116} 116}
117 117
118QDateTime Event::dtEnd() const 118QDateTime Event::dtEnd() const
119{ 119{
120 if (hasEndDate()) return mDtEnd; 120 if (hasEndDate()) return mDtEnd;
121 if (hasDuration()) return dtStart().addSecs(duration()); 121 if (hasDuration()) return dtStart().addSecs(duration());
122 122
123 return dtStart(); 123 return dtStart();
124} 124}
125 125
126QString Event::dtEndTimeStr() const 126QString Event::dtEndTimeStr() const
127{ 127{
128 return KGlobal::locale()->formatTime(mDtEnd.time()); 128 return KGlobal::locale()->formatTime(mDtEnd.time());
129} 129}
130 130
131QString Event::dtEndDateStr(bool shortfmt) const 131QString Event::dtEndDateStr(bool shortfmt) const
132{ 132{
133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); 133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt);
134} 134}
135 135
136QString Event::dtEndStr(bool shortfmt) const 136QString Event::dtEndStr(bool shortfmt) const
137{ 137{
138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); 138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt);
139} 139}
140 140
141void Event::setHasEndDate(bool b) 141void Event::setHasEndDate(bool b)
142{ 142{
143 mHasEndDate = b; 143 mHasEndDate = b;
144} 144}
145 145
146bool Event::hasEndDate() const 146bool Event::hasEndDate() const
147{ 147{
148 return mHasEndDate; 148 return mHasEndDate;
149} 149}
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::matchTime(QDateTime*startDT, QDateTime* endDT)
175{
176 if ( ! doesRecur() ) {
177 if ( doesFloat() ) {
178 if ( mDtEnd.addDays( 1 ) < *startDT)
179 return false;
180 if ( endDT && mDtStart > * endDT)
181 return false;
182 } else {
183 if ( mDtEnd < *startDT )
184 return false;
185 if ( endDT && mDtStart > * endDT)
186 return false;
187 }
188 } else {
189 if ( endDT && mDtStart > * endDT)
190 return false;
191 }
192 return true;
193}
174bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) 194bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT )
175{ 195{
176 if ( testEvent == this ) 196 if ( testEvent == this )
177 return false; 197 return false;
178 if ( ! doesRecur() && !testEvent->doesRecur() ) { 198 if ( ! doesRecur() && !testEvent->doesRecur() ) {
179 QDateTime te; 199 QDateTime te;
180 if ( testEvent->doesFloat() ) 200 if ( testEvent->doesFloat() )
181 te = testEvent->mDtEnd.addDays( 1 ); 201 te = testEvent->mDtEnd.addDays( 1 );
182 else 202 else
183 te = testEvent->mDtEnd; 203 te = testEvent->mDtEnd;
184 QDateTime e; 204 QDateTime e;
185 if ( doesFloat() ) 205 if ( doesFloat() )
186 e = mDtEnd.addDays( 1 ); 206 e = mDtEnd.addDays( 1 );
187 else 207 else
188 e = mDtEnd; 208 e = mDtEnd;
189 if ( mDtStart < te && testEvent->mDtStart < e ) { 209 if ( mDtStart < te && testEvent->mDtStart < e ) {
190 if ( mDtStart < testEvent->mDtStart ) 210 if ( mDtStart < testEvent->mDtStart )
191 *overlapDT = testEvent->mDtStart; 211 *overlapDT = testEvent->mDtStart;
192 else 212 else
193 *overlapDT = mDtStart; 213 *overlapDT = mDtStart;
194 if ( startDT ) 214 if ( startDT )
195 return (*overlapDT >= *startDT ); 215 return (*overlapDT >= *startDT );
196 return true; 216 return true;
197 } 217 }
198 return false; 218 return false;
199 } 219 }
200 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 220 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
201 if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) { 221 if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) {
202 // no need to test. times mismatch 222 // no need to test. times mismatch
203 //fprintf(stderr,"timi "); 223 //fprintf(stderr,"timi ");
204 return false; 224 return false;
205 } 225 }
206 } 226 }
207 Event *nonRecur = 0; 227 Event *nonRecur = 0;
208 Event *recurEvent = 0; 228 Event *recurEvent = 0;
209 if ( ! doesRecur() ) { 229 if ( ! doesRecur() ) {
210 nonRecur = this; 230 nonRecur = this;
211 recurEvent = testEvent; 231 recurEvent = testEvent;
212 } 232 }
213 else if ( !testEvent->doesRecur() ) { 233 else if ( !testEvent->doesRecur() ) {
214 nonRecur = testEvent; 234 nonRecur = testEvent;
215 recurEvent = this; 235 recurEvent = this;
216 } 236 }
217 if ( nonRecur ) { 237 if ( nonRecur ) {
218 QDateTime enr; 238 QDateTime enr;
219 if ( nonRecur->doesFloat() ) 239 if ( nonRecur->doesFloat() )
220 enr = nonRecur->mDtEnd.addDays( 1 ); 240 enr = nonRecur->mDtEnd.addDays( 1 );
221 else 241 else
222 enr = nonRecur->mDtEnd; 242 enr = nonRecur->mDtEnd;
223 if ( enr < recurEvent->mDtStart ) 243 if ( enr < recurEvent->mDtStart )
224 return false; 244 return false;
225 if ( startDT && enr < *startDT ) 245 if ( startDT && enr < *startDT )
226 return false; 246 return false;
227 247
228 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); 248 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd );
229 if ( recurEvent->doesFloat() ) 249 if ( recurEvent->doesFloat() )
230 recDuration += 86400; 250 recDuration += 86400;
231 bool ok = false; 251 bool ok = false;
232 QDateTime recStart; 252 QDateTime recStart;
233 if ( startDT ) { 253 if ( startDT ) {
234 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 254 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
235 } 255 }
236 if ( recStart.isValid() ) { 256 if ( recStart.isValid() ) {
237 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); 257 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1());
238 recStart = recStart.addSecs( -300); 258 recStart = recStart.addSecs( -300);
239 } 259 }
240 else 260 else
241 recStart = recurEvent->mDtStart.addSecs( -300); 261 recStart = recurEvent->mDtStart.addSecs( -300);
242 ok = true; 262 ok = true;
243 263
244 while ( ok ) { 264 while ( ok ) {
245 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); 265 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok );
246 if ( ok ) { 266 if ( ok ) {
247 if ( recStart > enr ) 267 if ( recStart > enr )
248 return false; 268 return false;
249 QDateTime recEnd = recStart.addSecs( recDuration ); 269 QDateTime recEnd = recStart.addSecs( recDuration );
250 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { 270 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) {
251 if ( nonRecur->mDtStart < recStart ) 271 if ( nonRecur->mDtStart < recStart )
252 *overlapDT = recStart; 272 *overlapDT = recStart;
253 else 273 else
254 *overlapDT = nonRecur->mDtStart; 274 *overlapDT = nonRecur->mDtStart;
255 if ( startDT ) { 275 if ( startDT ) {
256 if ( *overlapDT >= *startDT ) 276 if ( *overlapDT >= *startDT )
257 return true; 277 return true;
258 } else 278 } else
259 return true; 279 return true;
260 } 280 }
261 } 281 }
262 } 282 }
263 return false; 283 return false;
264 } 284 }
265 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 285 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
266 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { 286 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) {
267 bool found = false; 287 bool found = false;
268 uint i; 288 uint i;
269 for ( i=0; i< recurrence()->days().size();++i ) { 289 for ( i=0; i< recurrence()->days().size();++i ) {
diff --git a/libkcal/event.h b/libkcal/event.h
index e6055a5..2da9770 100644
--- a/libkcal/event.h
+++ b/libkcal/event.h
@@ -1,93 +1,94 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#ifndef EVENT_H 21#ifndef EVENT_H
22#define EVENT_H 22#define EVENT_H
23// 23//
24// Event component, representing a VEVENT object 24// Event component, representing a VEVENT object
25// 25//
26 26
27#include "incidence.h" 27#include "incidence.h"
28namespace KCal { 28namespace KCal {
29 29
30/** 30/**
31 This class provides an Event in the sense of RFC2445. 31 This class provides an Event in the sense of RFC2445.
32*/ 32*/
33class Event : public Incidence 33class Event : public Incidence
34{ 34{
35 public: 35 public:
36 enum Transparency { Opaque, Transparent }; 36 enum Transparency { Opaque, Transparent };
37 typedef ListBase<Event> List; 37 typedef ListBase<Event> List;
38 Event(); 38 Event();
39 Event(const Event &); 39 Event(const Event &);
40 ~Event(); 40 ~Event();
41 bool matchTime(QDateTime*startDT, QDateTime* endDT);
41 42
42 QCString type() const { return "Event"; } 43 QCString type() const { return "Event"; }
43 IncTypeID typeID() const { return eventID; } 44 IncTypeID typeID() const { return eventID; }
44 45
45 Incidence *clone(); 46 Incidence *clone();
46 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; 47 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const;
47 48
48 /** for setting an event's ending date/time with a QDateTime. */ 49 /** for setting an event's ending date/time with a QDateTime. */
49 void setDtEnd(const QDateTime &dtEnd); 50 void setDtEnd(const QDateTime &dtEnd);
50 /** Return the event's ending date/time as a QDateTime. */ 51 /** Return the event's ending date/time as a QDateTime. */
51 virtual QDateTime dtEnd() const; 52 virtual QDateTime dtEnd() const;
52 /** returns an event's end time as a string formatted according to the 53 /** returns an event's end time as a string formatted according to the
53 users locale settings */ 54 users locale settings */
54 QString dtEndTimeStr() const; 55 QString dtEndTimeStr() const;
55 /** returns an event's end date as a string formatted according to the 56 /** returns an event's end date as a string formatted according to the
56 users locale settings */ 57 users locale settings */
57 QString dtEndDateStr(bool shortfmt=true) const; 58 QString dtEndDateStr(bool shortfmt=true) const;
58 /** returns an event's end date and time as a string formatted according 59 /** returns an event's end date and time as a string formatted according
59 to the users locale settings */ 60 to the users locale settings */
60 QString dtEndStr(bool shortfmt=true) const; 61 QString dtEndStr(bool shortfmt=true) const;
61 void setHasEndDate(bool); 62 void setHasEndDate(bool);
62 /** Return whether the event has an end date/time. */ 63 /** Return whether the event has an end date/time. */
63 bool hasEndDate() const; 64 bool hasEndDate() const;
64 65
65 /** Return true if the event spans multiple days, otherwise return false. */ 66 /** Return true if the event spans multiple days, otherwise return false. */
66 bool isMultiDay() const; 67 bool isMultiDay() const;
67 68
68 /** set the event's time transparency level. */ 69 /** set the event's time transparency level. */
69 void setTransparency(Transparency transparency); 70 void setTransparency(Transparency transparency);
70 /** get the event's time transparency level. */ 71 /** get the event's time transparency level. */
71 Transparency transparency() const; 72 Transparency transparency() const;
72 73
73 void setDuration(int seconds); 74 void setDuration(int seconds);
74 75
75 bool contains ( Event*); 76 bool contains ( Event*);
76 77
77 bool isOverlapping ( Event*, QDateTime*, QDateTime* ); 78 bool isOverlapping ( Event*, QDateTime*, QDateTime* );
78 79
79 private: 80 private:
80 bool accept(Visitor &v) { return v.visit(this); } 81 bool accept(Visitor &v) { return v.visit(this); }
81 82
82 QDateTime mDtEnd; 83 QDateTime mDtEnd;
83 bool mHasEndDate; 84 bool mHasEndDate;
84 Transparency mTransparency; 85 Transparency mTransparency;
85}; 86};
86 87
87bool operator==( const Event&, const Event& ); 88bool operator==( const Event&, const Event& );
88 89
89 90
90} 91}
91 92
92 93
93#endif 94#endif