summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-07-10 20:11:56 (UTC)
committer zautrix <zautrix>2005-07-10 20:11:56 (UTC)
commitf06311e58cb5887fd673eb1c2c48acf7cd987ad9 (patch) (unidiff)
tree301c74302cdddaa3716d79117023228005ebd265 /libkcal
parentcb784d21ad22ab72a4e3231974f67816185675fd (diff)
downloadkdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.zip
kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.tar.gz
kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.tar.bz2
smarter faster conflict search
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
@@ -126,96 +126,116 @@ QDateTime Event::dtEnd() const
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
diff --git a/libkcal/event.h b/libkcal/event.h
index e6055a5..2da9770 100644
--- a/libkcal/event.h
+++ b/libkcal/event.h
@@ -1,88 +1,89 @@
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