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
@@ -1,223 +1,338 @@
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#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "event.h" 25#include "event.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Event::Event() : 29Event::Event() :
30 mHasEndDate( false ), mTransparency( Opaque ) 30 mHasEndDate( false ), mTransparency( Opaque )
31{ 31{
32} 32}
33 33
34Event::Event(const Event &e) : Incidence(e) 34Event::Event(const Event &e) : Incidence(e)
35{ 35{
36 mDtEnd = e.mDtEnd; 36 mDtEnd = e.mDtEnd;
37 mHasEndDate = e.mHasEndDate; 37 mHasEndDate = e.mHasEndDate;
38 mTransparency = e.mTransparency; 38 mTransparency = e.mTransparency;
39} 39}
40 40
41Event::~Event() 41Event::~Event()
42{ 42{
43} 43}
44 44
45Incidence *Event::clone() 45Incidence *Event::clone()
46{ 46{
47 return new Event(*this); 47 return new Event(*this);
48} 48}
49 49
50bool KCal::operator==( const Event& e1, const Event& e2 ) 50bool KCal::operator==( const Event& e1, const Event& e2 )
51{ 51{
52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && 52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) &&
53 e1.dtEnd() == e2.dtEnd() && 53 e1.dtEnd() == e2.dtEnd() &&
54 e1.hasEndDate() == e2.hasEndDate() && 54 e1.hasEndDate() == e2.hasEndDate() &&
55 e1.transparency() == e2.transparency(); 55 e1.transparency() == e2.transparency();
56} 56}
57 57
58 58
59bool Event::contains ( Event* from ) 59bool Event::contains ( Event* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->dtStart().isValid() ) 65 if ( from->dtStart().isValid() )
66 if (dtStart() != from->dtStart() ) 66 if (dtStart() != from->dtStart() )
67 return false; 67 return false;
68 if ( from->dtEnd().isValid() ) 68 if ( from->dtEnd().isValid() )
69 if ( dtEnd() != from->dtEnd() ) 69 if ( dtEnd() != from->dtEnd() )
70 return false; 70 return false;
71 if ( !from->location().isEmpty() ) 71 if ( !from->location().isEmpty() )
72 if ( !location().startsWith( from->location() ) ) 72 if ( !location().startsWith( from->location() ) )
73 return false; 73 return false;
74 if ( !from->description().isEmpty() ) 74 if ( !from->description().isEmpty() )
75 if ( !description().startsWith( from->description() )) 75 if ( !description().startsWith( from->description() ))
76 return false; 76 return false;
77 if ( from->alarms().count() ) { 77 if ( from->alarms().count() ) {
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::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 ) {
198 alarmStart = alarm->time(); 313 alarmStart = alarm->time();
199 enabled = true; 314 enabled = true;
200 off = alarmStart.secsTo( incidenceStart ); 315 off = alarmStart.secsTo( incidenceStart );
201 } 316 }
202 317
203 } else { 318 } else {
204 int secs = alarm->startOffset().asSeconds(); 319 int secs = alarm->startOffset().asSeconds();
205 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 320 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
206 alarmStart = incidenceStart.addSecs( secs ); 321 alarmStart = incidenceStart.addSecs( secs );
207 enabled = true; 322 enabled = true;
208 off = -secs; 323 off = -secs;
209 } 324 }
210 } 325 }
211 } 326 }
212 } 327 }
213 if ( enabled ) { 328 if ( enabled ) {
214 if ( alarmStart > start_dt ) { 329 if ( alarmStart > start_dt ) {
215 *ok = true; 330 *ok = true;
216 * offset = off; 331 * offset = off;
217 return alarmStart; 332 return alarmStart;
218 } 333 }
219 } 334 }
220 *ok = false; 335 *ok = false;
221 return QDateTime (); 336 return QDateTime ();
222 337
223} 338}
diff --git a/libkcal/event.h b/libkcal/event.h
index 287d403..80c11c4 100644
--- a/libkcal/event.h
+++ b/libkcal/event.h
@@ -1,91 +1,93 @@
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 41
42 QCString type() const { return "Event"; } 42 QCString type() const { return "Event"; }
43 IncTypeID typeID() const { return eventID; } 43 IncTypeID typeID() const { return eventID; }
44 44
45 Incidence *clone(); 45 Incidence *clone();
46 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; 46 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const;
47 47
48 /** for setting an event's ending date/time with a QDateTime. */ 48 /** for setting an event's ending date/time with a QDateTime. */
49 void setDtEnd(const QDateTime &dtEnd); 49 void setDtEnd(const QDateTime &dtEnd);
50 /** Return the event's ending date/time as a QDateTime. */ 50 /** Return the event's ending date/time as a QDateTime. */
51 virtual QDateTime dtEnd() const; 51 virtual QDateTime dtEnd() const;
52 /** returns an event's end time as a string formatted according to the 52 /** returns an event's end time as a string formatted according to the
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
@@ -1,464 +1,472 @@
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#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 setUid(CalFormat::createUniqueId()); 37 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 38 mOrganizer = "";
39 mFloats = false; 39 mFloats = false;
40 mDuration = 0; 40 mDuration = 0;
41 mHasDuration = false; 41 mHasDuration = false;
42 mPilotId = 0; 42 mPilotId = 0;
43 mExternalId = ":"; 43 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 45 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
47 mCalEnabled = true; 47 mCalEnabled = true;
48 mAlarmEnabled = true; 48 mAlarmEnabled = true;
49 mCalID = 0; 49 mCalID = 0;
50} 50}
51 51
52IncidenceBase::IncidenceBase(const IncidenceBase &i) : 52IncidenceBase::IncidenceBase(const IncidenceBase &i) :
53 CustomProperties( i ) 53 CustomProperties( i )
54{ 54{
55 55
56 mReadOnly = i.mReadOnly; 56 mReadOnly = i.mReadOnly;
57 mDtStart = i.mDtStart; 57 mDtStart = i.mDtStart;
58 mDuration = i.mDuration; 58 mDuration = i.mDuration;
59 mHasDuration = i.mHasDuration; 59 mHasDuration = i.mHasDuration;
60 mOrganizer = i.mOrganizer; 60 mOrganizer = i.mOrganizer;
61 mUid = i.mUid; 61 mUid = i.mUid;
62 mCalEnabled = i.mCalEnabled; 62 mCalEnabled = i.mCalEnabled;
63 mAlarmEnabled = i.mAlarmEnabled; 63 mAlarmEnabled = i.mAlarmEnabled;
64 mCalID = i.mCalID; 64 mCalID = i.mCalID;
65 QPtrList<Attendee> attendees = i.attendees(); 65 QPtrList<Attendee> attendees = i.attendees();
66 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 66 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
67 mAttendees.append( new Attendee( *a ) ); 67 mAttendees.append( new Attendee( *a ) );
68 } 68 }
69 mFloats = i.mFloats; 69 mFloats = i.mFloats;
70 mLastModified = i.mLastModified; 70 mLastModified = i.mLastModified;
71 mPilotId = i.mPilotId; 71 mPilotId = i.mPilotId;
72 mTempSyncStat = i.mTempSyncStat; 72 mTempSyncStat = i.mTempSyncStat;
73 mSyncStatus = i.mSyncStatus; 73 mSyncStatus = i.mSyncStatus;
74 mExternalId = i.mExternalId; 74 mExternalId = i.mExternalId;
75 // The copied object is a new one, so it isn't observed by the observer 75 // The copied object is a new one, so it isn't observed by the observer
76 // of the original object. 76 // of the original object.
77 mObservers.clear(); 77 mObservers.clear();
78 78
79 mAttendees.setAutoDelete( true ); 79 mAttendees.setAutoDelete( true );
80} 80}
81 81
82IncidenceBase::~IncidenceBase() 82IncidenceBase::~IncidenceBase()
83{ 83{
84} 84}
85 85
86 86
87bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 87bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
88{ 88{
89 // do not compare mSyncStatus and mExternalId 89 // do not compare mSyncStatus and mExternalId
90 if( i1.attendees().count() != i2.attendees().count() ) { 90 if( i1.attendees().count() != i2.attendees().count() ) {
91 return false; // no need to check further 91 return false; // no need to check further
92 } 92 }
93 if ( i1.attendees().count() > 0 ) { 93 if ( i1.attendees().count() > 0 ) {
94 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 94 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
95 while ( a1 ) { 95 while ( a1 ) {
96 if ( !( (*a1) == (*a2)) ) 96 if ( !( (*a1) == (*a2)) )
97 { 97 {
98 //qDebug("Attendee not equal "); 98 //qDebug("Attendee not equal ");
99 return false; 99 return false;
100 } 100 }
101 a1 = i1.attendees().next(); 101 a1 = i1.attendees().next();
102 a2 = i2.attendees().next(); 102 a2 = i2.attendees().next();
103 } 103 }
104 } 104 }
105 //if ( i1.dtStart() != i2.dtStart() ) 105 //if ( i1.dtStart() != i2.dtStart() )
106 // return false; 106 // return false;
107#if 0 107#if 0
108 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 108 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
109 qDebug("1 %d ",i1.duration() == i2.duration() ); 109 qDebug("1 %d ",i1.duration() == i2.duration() );
110 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 110 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
111 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 111 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
112 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 112 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
113 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 113 qDebug("6 %d ",i1.organizer() == i2.organizer() );
114 114
115#endif 115#endif
116 if ( i1.hasDuration() == i2.hasDuration() ) { 116 if ( i1.hasDuration() == i2.hasDuration() ) {
117 if ( i1.hasDuration() ) { 117 if ( i1.hasDuration() ) {
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
166{ 174{
167 return mAlarmEnabled; 175 return mAlarmEnabled;
168} 176}
169 177
170 178
171void IncidenceBase::setUid(const QString &uid) 179void IncidenceBase::setUid(const QString &uid)
172{ 180{
173 mUid = uid; 181 mUid = uid;
174 updated(); 182 updated();
175} 183}
176 184
177QString IncidenceBase::uid() const 185QString IncidenceBase::uid() const
178{ 186{
179 return mUid; 187 return mUid;
180} 188}
181 189
182void IncidenceBase::setLastModified(const QDateTime &lm) 190void IncidenceBase::setLastModified(const QDateTime &lm)
183{ 191{
184 // DON'T! updated() because we call this from 192 // DON'T! updated() because we call this from
185 // Calendar::updateEvent(). 193 // Calendar::updateEvent().
186 mLastModified = getEvenTime(lm); 194 mLastModified = getEvenTime(lm);
187 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 195 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
188} 196}
189 197
190QDateTime IncidenceBase::lastModified() const 198QDateTime IncidenceBase::lastModified() const
191{ 199{
192 return mLastModified; 200 return mLastModified;
193} 201}
194 202
195void IncidenceBase::setOrganizer(const QString &o) 203void IncidenceBase::setOrganizer(const QString &o)
196{ 204{
197 // we don't check for readonly here, because it is 205 // we don't check for readonly here, because it is
198 // possible that by setting the organizer we are changing 206 // possible that by setting the organizer we are changing
199 // the event's readonly status... 207 // the event's readonly status...
200 mOrganizer = o; 208 mOrganizer = o;
201 if (mOrganizer.left(7).upper() == "MAILTO:") 209 if (mOrganizer.left(7).upper() == "MAILTO:")
202 mOrganizer = mOrganizer.remove(0,7); 210 mOrganizer = mOrganizer.remove(0,7);
203 211
204 updated(); 212 updated();
205} 213}
206 214
207QString IncidenceBase::organizer() const 215QString IncidenceBase::organizer() const
208{ 216{
209 return mOrganizer; 217 return mOrganizer;
210} 218}
211 219
212void IncidenceBase::setReadOnly( bool readOnly ) 220void IncidenceBase::setReadOnly( bool readOnly )
213{ 221{
214 mReadOnly = readOnly; 222 mReadOnly = readOnly;
215} 223}
216 224
217void IncidenceBase::setDtStart(const QDateTime &dtStart) 225void IncidenceBase::setDtStart(const QDateTime &dtStart)
218{ 226{
219// if (mReadOnly) return; 227// if (mReadOnly) return;
220 mDtStart = getEvenTime(dtStart); 228 mDtStart = getEvenTime(dtStart);
221 updated(); 229 updated();
222} 230}
223 231
224 232
225QDateTime IncidenceBase::dtStart() const 233QDateTime IncidenceBase::dtStart() const
226{ 234{
227 return mDtStart; 235 return mDtStart;
228} 236}
229 237
230QString IncidenceBase::dtStartTimeStr() const 238QString IncidenceBase::dtStartTimeStr() const
231{ 239{
232 return KGlobal::locale()->formatTime(dtStart().time()); 240 return KGlobal::locale()->formatTime(dtStart().time());
233} 241}
234 242
235QString IncidenceBase::dtStartDateStr(bool shortfmt) const 243QString IncidenceBase::dtStartDateStr(bool shortfmt) const
236{ 244{
237 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 245 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
238} 246}
239 247
240QString IncidenceBase::dtStartStr(bool shortfmt) const 248QString IncidenceBase::dtStartStr(bool shortfmt) const
241{ 249{
242 if ( doesFloat() ) 250 if ( doesFloat() )
243 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 251 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
244 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 252 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
245} 253}
246 254
247 255
248bool IncidenceBase::doesFloat() const 256bool IncidenceBase::doesFloat() const
249{ 257{
250 return mFloats; 258 return mFloats;
251} 259}
252 260
253void IncidenceBase::setFloats(bool f) 261void IncidenceBase::setFloats(bool f)
254{ 262{
255 if (mReadOnly) return; 263 if (mReadOnly) return;
256 mFloats = f; 264 mFloats = f;
257 updated(); 265 updated();
258} 266}
259 267
260 268
261bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 269bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
262{ 270{
263 if (mReadOnly) return false; 271 if (mReadOnly) return false;
264 if (a->name().left(7).upper() == "MAILTO:") 272 if (a->name().left(7).upper() == "MAILTO:")
265 a->setName(a->name().remove(0,7)); 273 a->setName(a->name().remove(0,7));
266 274
267 QPtrListIterator<Attendee> qli(mAttendees); 275 QPtrListIterator<Attendee> qli(mAttendees);
268 276
269 qli.toFirst(); 277 qli.toFirst();
270 while (qli) { 278 while (qli) {
271 if (*qli.current() == *a) 279 if (*qli.current() == *a)
272 return false; 280 return false;
273 ++qli; 281 ++qli;
274 } 282 }
275 mAttendees.append(a); 283 mAttendees.append(a);
276 if (doupdate) updated(); 284 if (doupdate) updated();
277 return true; 285 return true;
278} 286}
279 287
280#if 0 288#if 0
281void IncidenceBase::removeAttendee(Attendee *a) 289void IncidenceBase::removeAttendee(Attendee *a)
282{ 290{
283 if (mReadOnly) return; 291 if (mReadOnly) return;
284 mAttendees.removeRef(a); 292 mAttendees.removeRef(a);
285 updated(); 293 updated();
286} 294}
287 295
288void IncidenceBase::removeAttendee(const char *n) 296void IncidenceBase::removeAttendee(const char *n)
289{ 297{
290 Attendee *a; 298 Attendee *a;
291 299
292 if (mReadOnly) return; 300 if (mReadOnly) return;
293 for (a = mAttendees.first(); a; a = mAttendees.next()) 301 for (a = mAttendees.first(); a; a = mAttendees.next())
294 if (a->getName() == n) { 302 if (a->getName() == n) {
295 mAttendees.remove(); 303 mAttendees.remove();
296 break; 304 break;
297 } 305 }
298} 306}
299#endif 307#endif
300 308
301void IncidenceBase::clearAttendees() 309void IncidenceBase::clearAttendees()
302{ 310{
303 if (mReadOnly) return; 311 if (mReadOnly) return;
304 mAttendees.clear(); 312 mAttendees.clear();
305} 313}
306 314
307#if 0 315#if 0
308Attendee *IncidenceBase::getAttendee(const char *n) const 316Attendee *IncidenceBase::getAttendee(const char *n) const
309{ 317{
310 QPtrListIterator<Attendee> qli(mAttendees); 318 QPtrListIterator<Attendee> qli(mAttendees);
311 319
312 qli.toFirst(); 320 qli.toFirst();
313 while (qli) { 321 while (qli) {
314 if (qli.current()->getName() == n) 322 if (qli.current()->getName() == n)
315 return qli.current(); 323 return qli.current();
316 ++qli; 324 ++qli;
317 } 325 }
318 return 0L; 326 return 0L;
319} 327}
320#endif 328#endif
321 329
322Attendee *IncidenceBase::attendeeByMail(const QString &email) 330Attendee *IncidenceBase::attendeeByMail(const QString &email)
323{ 331{
324 QPtrListIterator<Attendee> qli(mAttendees); 332 QPtrListIterator<Attendee> qli(mAttendees);
325 333
326 qli.toFirst(); 334 qli.toFirst();
327 while (qli) { 335 while (qli) {
328 if (qli.current()->email().lower() == email.lower()) 336 if (qli.current()->email().lower() == email.lower())
329 return qli.current(); 337 return qli.current();
330 ++qli; 338 ++qli;
331 } 339 }
332 return 0L; 340 return 0L;
333} 341}
334 342
335Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 343Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
336{ 344{
337 QPtrListIterator<Attendee> qli(mAttendees); 345 QPtrListIterator<Attendee> qli(mAttendees);
338 346
339 QStringList mails = emails; 347 QStringList mails = emails;
340 if (!email.isEmpty()) { 348 if (!email.isEmpty()) {
341 mails.append(email); 349 mails.append(email);
342 } 350 }
343 qli.toFirst(); 351 qli.toFirst();
344 while (qli) { 352 while (qli) {
345 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 353 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
346 if (qli.current()->email().lower() == (*it).lower()) 354 if (qli.current()->email().lower() == (*it).lower())
347 return qli.current(); 355 return qli.current();
348 } 356 }
349 357
350 ++qli; 358 ++qli;
351 } 359 }
352 return 0L; 360 return 0L;
353} 361}
354 362
355void IncidenceBase::setDuration(int seconds) 363void IncidenceBase::setDuration(int seconds)
356{ 364{
357 mDuration = seconds; 365 mDuration = seconds;
358 setHasDuration(true); 366 setHasDuration(true);
359} 367}
360 368
361int IncidenceBase::duration() const 369int IncidenceBase::duration() const
362{ 370{
363 return mDuration; 371 return mDuration;
364} 372}
365 373
366void IncidenceBase::setHasDuration(bool b) 374void IncidenceBase::setHasDuration(bool b)
367{ 375{
368 mHasDuration = b; 376 mHasDuration = b;
369} 377}
370 378
371bool IncidenceBase::hasDuration() const 379bool IncidenceBase::hasDuration() const
372{ 380{
373 return mHasDuration; 381 return mHasDuration;
374} 382}
375 383
376void IncidenceBase::setSyncStatus(int stat) 384void IncidenceBase::setSyncStatus(int stat)
377{ 385{
378 if (mReadOnly) return; 386 if (mReadOnly) return;
379 mSyncStatus = stat; 387 mSyncStatus = stat;
380} 388}
381 389
382int IncidenceBase::syncStatus() const 390int IncidenceBase::syncStatus() const
383{ 391{
384 return mSyncStatus; 392 return mSyncStatus;
385} 393}
386 394
387void IncidenceBase::setPilotId( int id ) 395void IncidenceBase::setPilotId( int id )
388{ 396{
389 if (mReadOnly) return; 397 if (mReadOnly) return;
390 mPilotId = id; 398 mPilotId = id;
391} 399}
392 400
393int IncidenceBase::pilotId() const 401int IncidenceBase::pilotId() const
394{ 402{
395 return mPilotId; 403 return mPilotId;
396} 404}
397 405
398int IncidenceBase::tempSyncStat() const 406int IncidenceBase::tempSyncStat() const
399{ 407{
400 return mTempSyncStat; 408 return mTempSyncStat;
401} 409}
402void IncidenceBase::setTempSyncStat( int id ) 410void IncidenceBase::setTempSyncStat( int id )
403{ 411{
404 if (mReadOnly) return; 412 if (mReadOnly) return;
405 mTempSyncStat = id; 413 mTempSyncStat = id;
406} 414}
407 415
408void IncidenceBase::removeID(const QString &prof) 416void IncidenceBase::removeID(const QString &prof)
409{ 417{
410 if ( prof.isEmpty() ) 418 if ( prof.isEmpty() )
411 mExternalId = ":"; 419 mExternalId = ":";
412 else 420 else
413 mExternalId = KIdManager::removeId ( mExternalId, prof); 421 mExternalId = KIdManager::removeId ( mExternalId, prof);
414 422
415} 423}
416void IncidenceBase::setID( const QString & prof , const QString & id ) 424void IncidenceBase::setID( const QString & prof , const QString & id )
417{ 425{
418 mExternalId = KIdManager::setId ( mExternalId, prof, id ); 426 mExternalId = KIdManager::setId ( mExternalId, prof, id );
419} 427}
420QString IncidenceBase::getID( const QString & prof) 428QString IncidenceBase::getID( const QString & prof)
421{ 429{
422 return KIdManager::getId ( mExternalId, prof ); 430 return KIdManager::getId ( mExternalId, prof );
423} 431}
424 432
425// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: 433// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
426// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 434// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
427void IncidenceBase::setCsum( const QString & prof , const QString & id ) 435void IncidenceBase::setCsum( const QString & prof , const QString & id )
428{ 436{
429 mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); 437 mExternalId = KIdManager::setCsum ( mExternalId, prof, id );
430} 438}
431QString IncidenceBase::getCsum( const QString & prof) 439QString IncidenceBase::getCsum( const QString & prof)
432{ 440{
433 return KIdManager::getCsum ( mExternalId, prof ); 441 return KIdManager::getCsum ( mExternalId, prof );
434} 442}
435 443
436void IncidenceBase::setIDStr( const QString & s ) 444void IncidenceBase::setIDStr( const QString & s )
437{ 445{
438 if (mReadOnly) return; 446 if (mReadOnly) return;
439 mExternalId = s; 447 mExternalId = s;
440} 448}
441 449
442QString IncidenceBase::IDStr() const 450QString IncidenceBase::IDStr() const
443{ 451{
444 return mExternalId ; 452 return mExternalId ;
445} 453}
446void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 454void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
447{ 455{
448 if( !mObservers.contains(observer) ) mObservers.append( observer ); 456 if( !mObservers.contains(observer) ) mObservers.append( observer );
449} 457}
450 458
451void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 459void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
452{ 460{
453 mObservers.remove( observer ); 461 mObservers.remove( observer );
454} 462}
455 463
456void IncidenceBase::updated() 464void IncidenceBase::updated()
457{ 465{
458 QPtrListIterator<Observer> it(mObservers); 466 QPtrListIterator<Observer> it(mObservers);
459 while( it.current() ) { 467 while( it.current() ) {
460 Observer *o = it.current(); 468 Observer *o = it.current();
461 ++it; 469 ++it;
462 o->incidenceUpdated( this ); 470 o->incidenceUpdated( this );
463 } 471 }
464} 472}
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index dc6024a..bccf287 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -1,183 +1,185 @@
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#ifndef KCAL_INCIDENCEBASE_H 20#ifndef KCAL_INCIDENCEBASE_H
21#define KCAL_INCIDENCEBASE_H 21#define KCAL_INCIDENCEBASE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "attendee.h" 32#include "attendee.h"
33 33
34namespace KCal { 34namespace KCal {
35 35
36typedef QValueList<QDate> DateList; 36typedef QValueList<QDate> DateList;
37 enum IncTypeID { eventID,todoID,journalID,freebusyID }; 37 enum IncTypeID { eventID,todoID,journalID,freebusyID };
38 38
39/** 39/**
40 This class provides the base class common to all calendar components. 40 This class provides the base class common to all calendar components.
41*/ 41*/
42class IncidenceBase : public CustomProperties 42class IncidenceBase : public CustomProperties
43{ 43{
44 public: 44 public:
45 class Observer { 45 class Observer {
46 public: 46 public:
47 virtual void incidenceUpdated( IncidenceBase * ) = 0; 47 virtual void incidenceUpdated( IncidenceBase * ) = 0;
48 }; 48 };
49 49
50 IncidenceBase(); 50 IncidenceBase();
51 IncidenceBase(const IncidenceBase &); 51 IncidenceBase(const IncidenceBase &);
52 virtual ~IncidenceBase(); 52 virtual ~IncidenceBase();
53 53
54 virtual QCString type() const = 0; 54 virtual QCString type() const = 0;
55 virtual IncTypeID typeID() const = 0; 55 virtual IncTypeID typeID() const = 0;
56 56
57 /** Set the unique id for the event */ 57 /** Set the unique id for the event */
58 void setUid(const QString &); 58 void setUid(const QString &);
59 /** Return the unique id for the event */ 59 /** Return the unique id for the event */
60 QString uid() const; 60 QString uid() const;
61 61
62 /** Sets the time the incidence was last modified. */ 62 /** Sets the time the incidence was last modified. */
63 void setLastModified(const QDateTime &lm); 63 void setLastModified(const QDateTime &lm);
64 /** Return the time the incidence was last modified. */ 64 /** Return the time the incidence was last modified. */
65 QDateTime lastModified() const; 65 QDateTime lastModified() const;
66 66
67 /** sets the organizer for the event */ 67 /** sets the organizer for the event */
68 void setOrganizer(const QString &o); 68 void setOrganizer(const QString &o);
69 QString organizer() const; 69 QString organizer() const;
70 70
71 /** Set readonly status. */ 71 /** Set readonly status. */
72 virtual void setReadOnly( bool ); 72 virtual void setReadOnly( bool );
73 /** Return if the object is read-only. */ 73 /** Return if the object is read-only. */
74 bool isReadOnly() const { return mReadOnly; } 74 bool isReadOnly() const { return mReadOnly; }
75 75
76 /** for setting the event's starting date/time with a QDateTime. */ 76 /** for setting the event's starting date/time with a QDateTime. */
77 virtual void setDtStart(const QDateTime &dtStart); 77 virtual void setDtStart(const QDateTime &dtStart);
78 /** returns an event's starting date/time as a QDateTime. */ 78 /** returns an event's starting date/time as a QDateTime. */
79 virtual QDateTime dtStart() const; 79 virtual QDateTime dtStart() const;
80 /** returns an event's starting time as a string formatted according to the 80 /** returns an event's starting time as a string formatted according to the
81 users locale settings */ 81 users locale settings */
82 QString dtStartTimeStr() const; 82 QString dtStartTimeStr() const;
83 /** returns an event's starting date as a string formatted according to the 83 /** returns an event's starting date as a string formatted according to the
84 users locale settings */ 84 users locale settings */
85 QString dtStartDateStr(bool shortfmt=true) const; 85 QString dtStartDateStr(bool shortfmt=true) const;
86 /** returns an event's starting date and time as a string formatted according 86 /** returns an event's starting date and time as a string formatted according
87 to the users locale settings */ 87 to the users locale settings */
88 QString dtStartStr(bool shortfmt=true) const; 88 QString dtStartStr(bool shortfmt=true) const;
89 89
90 virtual void setDuration(int seconds); 90 virtual void setDuration(int seconds);
91 int duration() const; 91 int duration() const;
92 void setHasDuration(bool); 92 void setHasDuration(bool);
93 bool hasDuration() const; 93 bool hasDuration() const;
94 94
95 /** Return true or false depending on whether the incidence "floats," 95 /** Return true or false depending on whether the incidence "floats,"
96 * i.e. has a date but no time attached to it. */ 96 * i.e. has a date but no time attached to it. */
97 bool doesFloat() const; 97 bool doesFloat() const;
98 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ 98 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
99 void setFloats(bool f); 99 void setFloats(bool f);
100 100
101 /** 101 /**
102 Add Attendee to this incidence. IncidenceBase takes ownership of the 102 Add Attendee to this incidence. IncidenceBase takes ownership of the
103 Attendee object. 103 Attendee object.
104 */ 104 */
105 bool addAttendee(Attendee *a, bool doupdate=true ); 105 bool addAttendee(Attendee *a, bool doupdate=true );
106// void removeAttendee(Attendee *a); 106// void removeAttendee(Attendee *a);
107// void removeAttendee(const char *n); 107// void removeAttendee(const char *n);
108 /** Remove all Attendees. */ 108 /** Remove all Attendees. */
109 void clearAttendees(); 109 void clearAttendees();
110 /** Return list of attendees. */ 110 /** Return list of attendees. */
111 QPtrList<Attendee> attendees() const { return mAttendees; }; 111 QPtrList<Attendee> attendees() const { return mAttendees; };
112 /** Return number of attendees. */ 112 /** Return number of attendees. */
113 int attendeeCount() const { return mAttendees.count(); }; 113 int attendeeCount() const { return mAttendees.count(); };
114 /** Return the Attendee with this email */ 114 /** Return the Attendee with this email */
115 Attendee* attendeeByMail(const QString &); 115 Attendee* attendeeByMail(const QString &);
116 /** Return first Attendee with one of this emails */ 116 /** Return first Attendee with one of this emails */
117 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); 117 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
118 118
119 /** pilot syncronization states */ 119 /** pilot syncronization states */
120 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; 120 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
121 /** Set synchronisation satus. */ 121 /** Set synchronisation satus. */
122 void setSyncStatus(int stat); 122 void setSyncStatus(int stat);
123 /** Return synchronisation status. */ 123 /** Return synchronisation status. */
124 int syncStatus() const; 124 int syncStatus() const;
125 125
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)
176 178
177 QPtrList<Observer> mObservers; 179 QPtrList<Observer> mObservers;
178}; 180};
179 181
180bool operator==( const IncidenceBase&, const IncidenceBase& ); 182bool operator==( const IncidenceBase&, const IncidenceBase& );
181} 183}
182 184
183#endif 185#endif