-rw-r--r-- | libkcal/incidence.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 4643a3a..201f593 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,295 +1,324 @@ | |||
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 "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = 0;//new Recurrence(this); | 36 | mRecurrence = 0;//new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 42 | mHasRecurrenceID = false; |
43 | mHoliday = false; | 43 | mHoliday = false; |
44 | mBirthday = false; | 44 | mBirthday = false; |
45 | mAnniversary = false; | 45 | mAnniversary = false; |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
50 | { | 50 | { |
51 | // TODO: reenable attributes currently commented out. | 51 | // TODO: reenable attributes currently commented out. |
52 | mRevision = i.mRevision; | 52 | mRevision = i.mRevision; |
53 | mCreated = i.mCreated; | 53 | mCreated = i.mCreated; |
54 | mDescription = i.mDescription; | 54 | mDescription = i.mDescription; |
55 | mSummary = i.mSummary; | 55 | mSummary = i.mSummary; |
56 | mCategories = i.mCategories; | 56 | mCategories = i.mCategories; |
57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
58 | mRelatedTo = 0; | 58 | mRelatedTo = 0; |
59 | mRelatedToUid = i.mRelatedToUid; | 59 | mRelatedToUid = i.mRelatedToUid; |
60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
61 | mExDates = i.mExDates; | 61 | mExDates = i.mExDates; |
62 | mAttachments = i.mAttachments; | 62 | mAttachments = i.mAttachments; |
63 | mResources = i.mResources; | 63 | mResources = i.mResources; |
64 | mSecrecy = i.mSecrecy; | 64 | mSecrecy = i.mSecrecy; |
65 | mPriority = i.mPriority; | 65 | mPriority = i.mPriority; |
66 | mLocation = i.mLocation; | 66 | mLocation = i.mLocation; |
67 | mCancelled = i.mCancelled; | 67 | mCancelled = i.mCancelled; |
68 | mHasStartDate = i.mHasStartDate; | 68 | mHasStartDate = i.mHasStartDate; |
69 | QPtrListIterator<Alarm> it( i.mAlarms ); | 69 | QPtrListIterator<Alarm> it( i.mAlarms ); |
70 | const Alarm *a; | 70 | const Alarm *a; |
71 | while( (a = it.current()) ) { | 71 | while( (a = it.current()) ) { |
72 | Alarm *b = new Alarm( *a ); | 72 | Alarm *b = new Alarm( *a ); |
73 | b->setParent( this ); | 73 | b->setParent( this ); |
74 | mAlarms.append( b ); | 74 | mAlarms.append( b ); |
75 | 75 | ||
76 | ++it; | 76 | ++it; |
77 | } | 77 | } |
78 | mAlarms.setAutoDelete(true); | 78 | mAlarms.setAutoDelete(true); |
79 | mHasRecurrenceID = i.mHasRecurrenceID; | 79 | mHasRecurrenceID = i.mHasRecurrenceID; |
80 | mRecurrenceID = i.mRecurrenceID; | 80 | mRecurrenceID = i.mRecurrenceID; |
81 | if ( i.mRecurrence ) | 81 | if ( i.mRecurrence ) |
82 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 82 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
83 | else | 83 | else |
84 | mRecurrence = 0; | 84 | mRecurrence = 0; |
85 | mHoliday = i.mHoliday ; | 85 | mHoliday = i.mHoliday ; |
86 | mBirthday = i.mBirthday; | 86 | mBirthday = i.mBirthday; |
87 | mAnniversary = i.mAnniversary; | 87 | mAnniversary = i.mAnniversary; |
88 | } | 88 | } |
89 | 89 | ||
90 | Incidence::~Incidence() | 90 | Incidence::~Incidence() |
91 | { | 91 | { |
92 | 92 | ||
93 | Incidence *ev; | 93 | Incidence *ev; |
94 | QPtrList<Incidence> Relations = relations(); | 94 | QPtrList<Incidence> Relations = relations(); |
95 | for (ev=Relations.first();ev;ev=Relations.next()) { | 95 | for (ev=Relations.first();ev;ev=Relations.next()) { |
96 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 96 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
97 | } | 97 | } |
98 | if (relatedTo()) relatedTo()->removeRelation(this); | 98 | if (relatedTo()) relatedTo()->removeRelation(this); |
99 | if ( mRecurrence ) | 99 | if ( mRecurrence ) |
100 | delete mRecurrence; | 100 | delete mRecurrence; |
101 | 101 | ||
102 | } | 102 | } |
103 | QString Incidence::durationText() | ||
104 | { | ||
105 | return "---"; | ||
106 | } | ||
107 | QString Incidence::durationText4Time( int offset ) | ||
108 | { | ||
109 | int min = offset/60; | ||
110 | int hours = min /60; | ||
111 | min = min % 60; | ||
112 | int days = hours /24; | ||
113 | hours = hours % 24; | ||
114 | |||
115 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { | ||
116 | if ( days == 1 ) | ||
117 | return "1" + i18n(" day"); | ||
118 | else | ||
119 | return QString::number( days )+ i18n(" days"); | ||
103 | 120 | ||
121 | } | ||
122 | QString message = QString::number ( hours ) +":"; | ||
123 | if ( min < 10 ) message += "0"; | ||
124 | message += QString::number ( min ); | ||
125 | if ( days > 0 ) { | ||
126 | if ( days == 1 ) | ||
127 | message = "1" + i18n(" day") + " "+message; | ||
128 | else | ||
129 | message = QString::number( days )+ i18n(" days") + " "+message; | ||
130 | } | ||
131 | return message; | ||
132 | } | ||
104 | bool Incidence::isHoliday() const | 133 | bool Incidence::isHoliday() const |
105 | { | 134 | { |
106 | return mHoliday; | 135 | return mHoliday; |
107 | } | 136 | } |
108 | bool Incidence::isBirthday() const | 137 | bool Incidence::isBirthday() const |
109 | { | 138 | { |
110 | 139 | ||
111 | return mBirthday ; | 140 | return mBirthday ; |
112 | } | 141 | } |
113 | bool Incidence::isAnniversary() const | 142 | bool Incidence::isAnniversary() const |
114 | { | 143 | { |
115 | return mAnniversary ; | 144 | return mAnniversary ; |
116 | 145 | ||
117 | } | 146 | } |
118 | 147 | ||
119 | bool Incidence::hasRecurrenceID() const | 148 | bool Incidence::hasRecurrenceID() const |
120 | { | 149 | { |
121 | return mHasRecurrenceID; | 150 | return mHasRecurrenceID; |
122 | } | 151 | } |
123 | 152 | ||
124 | void Incidence::setHasRecurrenceID( bool b ) | 153 | void Incidence::setHasRecurrenceID( bool b ) |
125 | { | 154 | { |
126 | mHasRecurrenceID = b; | 155 | mHasRecurrenceID = b; |
127 | } | 156 | } |
128 | 157 | ||
129 | void Incidence::setRecurrenceID(QDateTime d) | 158 | void Incidence::setRecurrenceID(QDateTime d) |
130 | { | 159 | { |
131 | mRecurrenceID = d; | 160 | mRecurrenceID = d; |
132 | mHasRecurrenceID = true; | 161 | mHasRecurrenceID = true; |
133 | updated(); | 162 | updated(); |
134 | } | 163 | } |
135 | QDateTime Incidence::recurrenceID () const | 164 | QDateTime Incidence::recurrenceID () const |
136 | { | 165 | { |
137 | return mRecurrenceID; | 166 | return mRecurrenceID; |
138 | } | 167 | } |
139 | 168 | ||
140 | bool Incidence::cancelled() const | 169 | bool Incidence::cancelled() const |
141 | { | 170 | { |
142 | return mCancelled; | 171 | return mCancelled; |
143 | } | 172 | } |
144 | void Incidence::setCancelled( bool b ) | 173 | void Incidence::setCancelled( bool b ) |
145 | { | 174 | { |
146 | mCancelled = b; | 175 | mCancelled = b; |
147 | updated(); | 176 | updated(); |
148 | } | 177 | } |
149 | bool Incidence::hasStartDate() const | 178 | bool Incidence::hasStartDate() const |
150 | { | 179 | { |
151 | return mHasStartDate; | 180 | return mHasStartDate; |
152 | } | 181 | } |
153 | 182 | ||
154 | void Incidence::setHasStartDate(bool f) | 183 | void Incidence::setHasStartDate(bool f) |
155 | { | 184 | { |
156 | if (mReadOnly) return; | 185 | if (mReadOnly) return; |
157 | mHasStartDate = f; | 186 | mHasStartDate = f; |
158 | updated(); | 187 | updated(); |
159 | } | 188 | } |
160 | 189 | ||
161 | // A string comparison that considers that null and empty are the same | 190 | // A string comparison that considers that null and empty are the same |
162 | static bool stringCompare( const QString& s1, const QString& s2 ) | 191 | static bool stringCompare( const QString& s1, const QString& s2 ) |
163 | { | 192 | { |
164 | if ( s1.isEmpty() && s2.isEmpty() ) | 193 | if ( s1.isEmpty() && s2.isEmpty() ) |
165 | return true; | 194 | return true; |
166 | return s1 == s2; | 195 | return s1 == s2; |
167 | } | 196 | } |
168 | 197 | ||
169 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 198 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
170 | { | 199 | { |
171 | 200 | ||
172 | if( i1.alarms().count() != i2.alarms().count() ) { | 201 | if( i1.alarms().count() != i2.alarms().count() ) { |
173 | return false; // no need to check further | 202 | return false; // no need to check further |
174 | } | 203 | } |
175 | if ( i1.alarms().count() > 0 ) { | 204 | if ( i1.alarms().count() > 0 ) { |
176 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 205 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
177 | { | 206 | { |
178 | qDebug("alarm not equal "); | 207 | qDebug("alarm not equal "); |
179 | return false; | 208 | return false; |
180 | } | 209 | } |
181 | } | 210 | } |
182 | #if 0 | 211 | #if 0 |
183 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 212 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
184 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 213 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
185 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 214 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
186 | if( *a1.current() == *a2.current() ) { | 215 | if( *a1.current() == *a2.current() ) { |
187 | continue; | 216 | continue; |
188 | } | 217 | } |
189 | else { | 218 | else { |
190 | return false; | 219 | return false; |
191 | } | 220 | } |
192 | } | 221 | } |
193 | #endif | 222 | #endif |
194 | 223 | ||
195 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 224 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
196 | if ( i1.hasRecurrenceID() ) { | 225 | if ( i1.hasRecurrenceID() ) { |
197 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 226 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
198 | return false; | 227 | return false; |
199 | } | 228 | } |
200 | 229 | ||
201 | } else { | 230 | } else { |
202 | return false; | 231 | return false; |
203 | } | 232 | } |
204 | 233 | ||
205 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 234 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
206 | return false; | 235 | return false; |
207 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 236 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
208 | if ( i1.hasStartDate() ) { | 237 | if ( i1.hasStartDate() ) { |
209 | if ( i1.dtStart() != i2.dtStart() ) | 238 | if ( i1.dtStart() != i2.dtStart() ) |
210 | return false; | 239 | return false; |
211 | } | 240 | } |
212 | } else { | 241 | } else { |
213 | return false; | 242 | return false; |
214 | } | 243 | } |
215 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { | 244 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { |
216 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { | 245 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { |
217 | //qDebug("recurrence is NOT equal "); | 246 | //qDebug("recurrence is NOT equal "); |
218 | return false; | 247 | return false; |
219 | } | 248 | } |
220 | } else { | 249 | } else { |
221 | // one ( or both ) recurrence is 0 | 250 | // one ( or both ) recurrence is 0 |
222 | if ( i1.mRecurrence == 0 ) { | 251 | if ( i1.mRecurrence == 0 ) { |
223 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) | 252 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) |
224 | return false; | 253 | return false; |
225 | } else { | 254 | } else { |
226 | // i1.mRecurrence != 0 | 255 | // i1.mRecurrence != 0 |
227 | // i2.mRecurrence == 0 | 256 | // i2.mRecurrence == 0 |
228 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) | 257 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) |
229 | return false; | 258 | return false; |
230 | } | 259 | } |
231 | } | 260 | } |
232 | 261 | ||
233 | return | 262 | return |
234 | // i1.created() == i2.created() && | 263 | // i1.created() == i2.created() && |
235 | stringCompare( i1.description(), i2.description() ) && | 264 | stringCompare( i1.description(), i2.description() ) && |
236 | stringCompare( i1.summary(), i2.summary() ) && | 265 | stringCompare( i1.summary(), i2.summary() ) && |
237 | i1.categories() == i2.categories() && | 266 | i1.categories() == i2.categories() && |
238 | // no need to compare mRelatedTo | 267 | // no need to compare mRelatedTo |
239 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 268 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
240 | // i1.relations() == i2.relations() && | 269 | // i1.relations() == i2.relations() && |
241 | i1.exDates() == i2.exDates() && | 270 | i1.exDates() == i2.exDates() && |
242 | i1.attachments() == i2.attachments() && | 271 | i1.attachments() == i2.attachments() && |
243 | i1.resources() == i2.resources() && | 272 | i1.resources() == i2.resources() && |
244 | i1.secrecy() == i2.secrecy() && | 273 | i1.secrecy() == i2.secrecy() && |
245 | i1.priority() == i2.priority() && | 274 | i1.priority() == i2.priority() && |
246 | i1.cancelled() == i2.cancelled() && | 275 | i1.cancelled() == i2.cancelled() && |
247 | stringCompare( i1.location(), i2.location() ); | 276 | stringCompare( i1.location(), i2.location() ); |
248 | } | 277 | } |
249 | 278 | ||
250 | Incidence* Incidence::recreateCloneException( QDate d ) | 279 | Incidence* Incidence::recreateCloneException( QDate d ) |
251 | { | 280 | { |
252 | Incidence* newInc = clone(); | 281 | Incidence* newInc = clone(); |
253 | newInc->recreate(); | 282 | newInc->recreate(); |
254 | if ( doesRecur() ) { | 283 | if ( doesRecur() ) { |
255 | addExDate( d ); | 284 | addExDate( d ); |
256 | newInc->recurrence()->unsetRecurs(); | 285 | newInc->recurrence()->unsetRecurs(); |
257 | if ( typeID() == eventID ) { | 286 | if ( typeID() == eventID ) { |
258 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 287 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
259 | QTime tim = dtStart().time(); | 288 | QTime tim = dtStart().time(); |
260 | newInc->setDtStart( QDateTime(d, tim) ); | 289 | newInc->setDtStart( QDateTime(d, tim) ); |
261 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 290 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
262 | } else { | 291 | } else { |
263 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 292 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
264 | QTime tim = ((Todo*)this)->dtDue().time(); | 293 | QTime tim = ((Todo*)this)->dtDue().time(); |
265 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 294 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
266 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 295 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
267 | ((Todo*)this)->setRecurDates(); | 296 | ((Todo*)this)->setRecurDates(); |
268 | } | 297 | } |
269 | newInc->setExDates( DateList () ); | 298 | newInc->setExDates( DateList () ); |
270 | } | 299 | } |
271 | return newInc; | 300 | return newInc; |
272 | } | 301 | } |
273 | 302 | ||
274 | void Incidence::recreate() | 303 | void Incidence::recreate() |
275 | { | 304 | { |
276 | setCreated(QDateTime::currentDateTime()); | 305 | setCreated(QDateTime::currentDateTime()); |
277 | 306 | ||
278 | setUid(CalFormat::createUniqueId()); | 307 | setUid(CalFormat::createUniqueId()); |
279 | 308 | ||
280 | setRevision(0); | 309 | setRevision(0); |
281 | setIDStr( ":" ); | 310 | setIDStr( ":" ); |
282 | setLastModified(QDateTime::currentDateTime()); | 311 | setLastModified(QDateTime::currentDateTime()); |
283 | } | 312 | } |
284 | void Incidence::cloneRelations( Incidence * newInc ) | 313 | void Incidence::cloneRelations( Incidence * newInc ) |
285 | { | 314 | { |
286 | // newInc is already a clone of this incidence | 315 | // newInc is already a clone of this incidence |
287 | Incidence * inc; | 316 | Incidence * inc; |
288 | Incidence * cloneInc; | 317 | Incidence * cloneInc; |
289 | QPtrList<Incidence> Relations = relations(); | 318 | QPtrList<Incidence> Relations = relations(); |
290 | for (inc=Relations.first();inc;inc=Relations.next()) { | 319 | for (inc=Relations.first();inc;inc=Relations.next()) { |
291 | cloneInc = inc->clone(); | 320 | cloneInc = inc->clone(); |
292 | cloneInc->recreate(); | 321 | cloneInc->recreate(); |
293 | cloneInc->setRelatedTo( newInc ); | 322 | cloneInc->setRelatedTo( newInc ); |
294 | inc->cloneRelations( cloneInc ); | 323 | inc->cloneRelations( cloneInc ); |
295 | } | 324 | } |