author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /libkcal | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
50 files changed, 521 insertions, 449 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp index 3157214..3c4a81c 100644 --- a/libkcal/alarm.cpp +++ b/libkcal/alarm.cpp | |||
@@ -1,483 +1,485 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <kdebug.h> | 22 | #include <kdebug.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | 24 | ||
25 | #include "incidence.h" | 25 | #include "incidence.h" |
26 | #include "todo.h" | 26 | #include "todo.h" |
27 | 27 | ||
28 | #include "alarm.h" | 28 | #include "alarm.h" |
29 | //Added by qt3to4: | ||
30 | #include <Q3ValueList> | ||
29 | 31 | ||
30 | using namespace KCal; | 32 | using namespace KCal; |
31 | #include <qwidget.h> | 33 | #include <qwidget.h> |
32 | Alarm::Alarm(Incidence *parent) | 34 | Alarm::Alarm(Incidence *parent) |
33 | : mParent(parent), | 35 | : mParent(parent), |
34 | mType(Audio), | 36 | mType(Audio), |
35 | mDescription(""), // to make operator==() not fail | 37 | mDescription(""), // to make operator==() not fail |
36 | mFile(""), // to make operator==() not fail | 38 | mFile(""), // to make operator==() not fail |
37 | mMailSubject(""), // to make operator==() not fail | 39 | mMailSubject(""), // to make operator==() not fail |
38 | mAlarmSnoozeTime(5), | 40 | mAlarmSnoozeTime(5), |
39 | mAlarmRepeatCount(0), | 41 | mAlarmRepeatCount(0), |
40 | mEndOffset(false), | 42 | mEndOffset(false), |
41 | mHasTime(false), | 43 | mHasTime(false), |
42 | mAlarmEnabled(false) | 44 | mAlarmEnabled(false) |
43 | { | 45 | { |
44 | 46 | ||
45 | } | 47 | } |
46 | 48 | ||
47 | Alarm::~Alarm() | 49 | Alarm::~Alarm() |
48 | { | 50 | { |
49 | } | 51 | } |
50 | 52 | ||
51 | bool Alarm::operator==( const Alarm& rhs ) const | 53 | bool Alarm::operator==( const Alarm& rhs ) const |
52 | { | 54 | { |
53 | 55 | ||
54 | if ( mType != rhs.mType || | 56 | if ( mType != rhs.mType || |
55 | mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || | 57 | mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || |
56 | mAlarmRepeatCount != rhs.mAlarmRepeatCount || | 58 | mAlarmRepeatCount != rhs.mAlarmRepeatCount || |
57 | mAlarmEnabled != rhs.mAlarmEnabled || | 59 | mAlarmEnabled != rhs.mAlarmEnabled || |
58 | mHasTime != rhs.mHasTime) | 60 | mHasTime != rhs.mHasTime) |
59 | return false; | 61 | return false; |
60 | 62 | ||
61 | #if 0 | 63 | #if 0 |
62 | if ( mType != rhs.mType ) { | 64 | if ( mType != rhs.mType ) { |
63 | 65 | ||
64 | qDebug("aaa1 "); | 66 | qDebug("aaa1 "); |
65 | return false; | 67 | return false; |
66 | } | 68 | } |
67 | 69 | ||
68 | if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) { | 70 | if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) { |
69 | 71 | ||
70 | qDebug("aaa2 "); | 72 | qDebug("aaa2 "); |
71 | return false; | 73 | return false; |
72 | } | 74 | } |
73 | 75 | ||
74 | 76 | ||
75 | if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) { | 77 | if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) { |
76 | 78 | ||
77 | qDebug("aaa3 "); | 79 | qDebug("aaa3 "); |
78 | return false; | 80 | return false; |
79 | } | 81 | } |
80 | 82 | ||
81 | if ( mAlarmEnabled != rhs.mAlarmEnabled ) { | 83 | if ( mAlarmEnabled != rhs.mAlarmEnabled ) { |
82 | 84 | ||
83 | qDebug("aaa4 "); | 85 | qDebug("aaa4 "); |
84 | return false; | 86 | return false; |
85 | } | 87 | } |
86 | 88 | ||
87 | if ( mHasTime != rhs.mHasTime ) { | 89 | if ( mHasTime != rhs.mHasTime ) { |
88 | 90 | ||
89 | qDebug("aaa5 "); | 91 | qDebug("aaa5 "); |
90 | return false; | 92 | return false; |
91 | } | 93 | } |
92 | #endif | 94 | #endif |
93 | 95 | ||
94 | 96 | ||
95 | if (mHasTime) { | 97 | if (mHasTime) { |
96 | if (mAlarmTime != rhs.mAlarmTime) | 98 | if (mAlarmTime != rhs.mAlarmTime) |
97 | return false; | 99 | return false; |
98 | } else { | 100 | } else { |
99 | if (mOffset != rhs.mOffset || | 101 | if (mOffset != rhs.mOffset || |
100 | mEndOffset != rhs.mEndOffset) | 102 | mEndOffset != rhs.mEndOffset) |
101 | return false; | 103 | return false; |
102 | } | 104 | } |
103 | switch (mType) { | 105 | switch (mType) { |
104 | case Display: | 106 | case Display: |
105 | return mDescription == rhs.mDescription; | 107 | return mDescription == rhs.mDescription; |
106 | 108 | ||
107 | case Email: | 109 | case Email: |
108 | return mDescription == rhs.mDescription && | 110 | return mDescription == rhs.mDescription && |
109 | mMailAttachFiles == rhs.mMailAttachFiles && | 111 | mMailAttachFiles == rhs.mMailAttachFiles && |
110 | mMailAddresses == rhs.mMailAddresses && | 112 | mMailAddresses == rhs.mMailAddresses && |
111 | mMailSubject == rhs.mMailSubject; | 113 | mMailSubject == rhs.mMailSubject; |
112 | 114 | ||
113 | case Procedure: | 115 | case Procedure: |
114 | return mFile == rhs.mFile && | 116 | return mFile == rhs.mFile && |
115 | mDescription == rhs.mDescription; | 117 | mDescription == rhs.mDescription; |
116 | 118 | ||
117 | case Audio: | 119 | case Audio: |
118 | return mFile == rhs.mFile; | 120 | return mFile == rhs.mFile; |
119 | 121 | ||
120 | case Invalid: | 122 | case Invalid: |
121 | break; | 123 | break; |
122 | } | 124 | } |
123 | return false; | 125 | return false; |
124 | } | 126 | } |
125 | 127 | ||
126 | void Alarm::setType(Alarm::Type type) | 128 | void Alarm::setType(Alarm::Type type) |
127 | { | 129 | { |
128 | if (type == mType) | 130 | if (type == mType) |
129 | return; | 131 | return; |
130 | 132 | ||
131 | switch (type) { | 133 | switch (type) { |
132 | case Display: | 134 | case Display: |
133 | mDescription = ""; | 135 | mDescription = ""; |
134 | break; | 136 | break; |
135 | case Procedure: | 137 | case Procedure: |
136 | mFile = mDescription = ""; | 138 | mFile = mDescription = ""; |
137 | break; | 139 | break; |
138 | case Audio: | 140 | case Audio: |
139 | mFile = ""; | 141 | mFile = ""; |
140 | break; | 142 | break; |
141 | case Email: | 143 | case Email: |
142 | mMailSubject = mDescription = ""; | 144 | mMailSubject = mDescription = ""; |
143 | mMailAddresses.clear(); | 145 | mMailAddresses.clear(); |
144 | mMailAttachFiles.clear(); | 146 | mMailAttachFiles.clear(); |
145 | break; | 147 | break; |
146 | case Invalid: | 148 | case Invalid: |
147 | break; | 149 | break; |
148 | default: | 150 | default: |
149 | return; | 151 | return; |
150 | } | 152 | } |
151 | mType = type; | 153 | mType = type; |
152 | mParent->updated(); | 154 | mParent->updated(); |
153 | } | 155 | } |
154 | 156 | ||
155 | Alarm::Type Alarm::type() const | 157 | Alarm::Type Alarm::type() const |
156 | { | 158 | { |
157 | return mType; | 159 | return mType; |
158 | } | 160 | } |
159 | 161 | ||
160 | void Alarm::setAudioAlarm(const QString &audioFile) | 162 | void Alarm::setAudioAlarm(const QString &audioFile) |
161 | { | 163 | { |
162 | mType = Audio; | 164 | mType = Audio; |
163 | mFile = audioFile; | 165 | mFile = audioFile; |
164 | mParent->updated(); | 166 | mParent->updated(); |
165 | } | 167 | } |
166 | 168 | ||
167 | void Alarm::setAudioFile(const QString &audioFile) | 169 | void Alarm::setAudioFile(const QString &audioFile) |
168 | { | 170 | { |
169 | if (mType == Audio) { | 171 | if (mType == Audio) { |
170 | mFile = audioFile; | 172 | mFile = audioFile; |
171 | mParent->updated(); | 173 | mParent->updated(); |
172 | } | 174 | } |
173 | } | 175 | } |
174 | 176 | ||
175 | QString Alarm::audioFile() const | 177 | QString Alarm::audioFile() const |
176 | { | 178 | { |
177 | return (mType == Audio) ? mFile : QString::null; | 179 | return (mType == Audio) ? mFile : QString::null; |
178 | } | 180 | } |
179 | 181 | ||
180 | void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) | 182 | void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) |
181 | { | 183 | { |
182 | mType = Procedure; | 184 | mType = Procedure; |
183 | mFile = programFile; | 185 | mFile = programFile; |
184 | mDescription = arguments; | 186 | mDescription = arguments; |
185 | mParent->updated(); | 187 | mParent->updated(); |
186 | } | 188 | } |
187 | 189 | ||
188 | void Alarm::setProgramFile(const QString &programFile) | 190 | void Alarm::setProgramFile(const QString &programFile) |
189 | { | 191 | { |
190 | if (mType == Procedure) { | 192 | if (mType == Procedure) { |
191 | mFile = programFile; | 193 | mFile = programFile; |
192 | mParent->updated(); | 194 | mParent->updated(); |
193 | } | 195 | } |
194 | } | 196 | } |
195 | 197 | ||
196 | QString Alarm::programFile() const | 198 | QString Alarm::programFile() const |
197 | { | 199 | { |
198 | return (mType == Procedure) ? mFile : QString::null; | 200 | return (mType == Procedure) ? mFile : QString::null; |
199 | } | 201 | } |
200 | 202 | ||
201 | void Alarm::setProgramArguments(const QString &arguments) | 203 | void Alarm::setProgramArguments(const QString &arguments) |
202 | { | 204 | { |
203 | if (mType == Procedure) { | 205 | if (mType == Procedure) { |
204 | mDescription = arguments; | 206 | mDescription = arguments; |
205 | mParent->updated(); | 207 | mParent->updated(); |
206 | } | 208 | } |
207 | } | 209 | } |
208 | 210 | ||
209 | QString Alarm::programArguments() const | 211 | QString Alarm::programArguments() const |
210 | { | 212 | { |
211 | return (mType == Procedure) ? mDescription : QString::null; | 213 | return (mType == Procedure) ? mDescription : QString::null; |
212 | } | 214 | } |
213 | 215 | ||
214 | void Alarm::setEmailAlarm(const QString &subject, const QString &text, | 216 | void Alarm::setEmailAlarm(const QString &subject, const QString &text, |
215 | const QValueList<Person> &addressees, const QStringList &attachments) | 217 | const Q3ValueList<Person> &addressees, const QStringList &attachments) |
216 | { | 218 | { |
217 | mType = Email; | 219 | mType = Email; |
218 | mMailSubject = subject; | 220 | mMailSubject = subject; |
219 | mDescription = text; | 221 | mDescription = text; |
220 | mMailAddresses = addressees; | 222 | mMailAddresses = addressees; |
221 | mMailAttachFiles = attachments; | 223 | mMailAttachFiles = attachments; |
222 | mParent->updated(); | 224 | mParent->updated(); |
223 | } | 225 | } |
224 | 226 | ||
225 | void Alarm::setMailAddress(const Person &mailAddress) | 227 | void Alarm::setMailAddress(const Person &mailAddress) |
226 | { | 228 | { |
227 | if (mType == Email) { | 229 | if (mType == Email) { |
228 | mMailAddresses.clear(); | 230 | mMailAddresses.clear(); |
229 | mMailAddresses += mailAddress; | 231 | mMailAddresses += mailAddress; |
230 | mParent->updated(); | 232 | mParent->updated(); |
231 | } | 233 | } |
232 | } | 234 | } |
233 | 235 | ||
234 | void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) | 236 | void Alarm::setMailAddresses(const Q3ValueList<Person> &mailAddresses) |
235 | { | 237 | { |
236 | if (mType == Email) { | 238 | if (mType == Email) { |
237 | mMailAddresses = mailAddresses; | 239 | mMailAddresses = mailAddresses; |
238 | mParent->updated(); | 240 | mParent->updated(); |
239 | } | 241 | } |
240 | } | 242 | } |
241 | 243 | ||
242 | void Alarm::addMailAddress(const Person &mailAddress) | 244 | void Alarm::addMailAddress(const Person &mailAddress) |
243 | { | 245 | { |
244 | if (mType == Email) { | 246 | if (mType == Email) { |
245 | mMailAddresses += mailAddress; | 247 | mMailAddresses += mailAddress; |
246 | mParent->updated(); | 248 | mParent->updated(); |
247 | } | 249 | } |
248 | } | 250 | } |
249 | 251 | ||
250 | QValueList<Person> Alarm::mailAddresses() const | 252 | Q3ValueList<Person> Alarm::mailAddresses() const |
251 | { | 253 | { |
252 | return (mType == Email) ? mMailAddresses : QValueList<Person>(); | 254 | return (mType == Email) ? mMailAddresses : Q3ValueList<Person>(); |
253 | } | 255 | } |
254 | 256 | ||
255 | void Alarm::setMailSubject(const QString &mailAlarmSubject) | 257 | void Alarm::setMailSubject(const QString &mailAlarmSubject) |
256 | { | 258 | { |
257 | if (mType == Email) { | 259 | if (mType == Email) { |
258 | mMailSubject = mailAlarmSubject; | 260 | mMailSubject = mailAlarmSubject; |
259 | mParent->updated(); | 261 | mParent->updated(); |
260 | } | 262 | } |
261 | } | 263 | } |
262 | 264 | ||
263 | QString Alarm::mailSubject() const | 265 | QString Alarm::mailSubject() const |
264 | { | 266 | { |
265 | return (mType == Email) ? mMailSubject : QString::null; | 267 | return (mType == Email) ? mMailSubject : QString::null; |
266 | } | 268 | } |
267 | 269 | ||
268 | void Alarm::setMailAttachment(const QString &mailAttachFile) | 270 | void Alarm::setMailAttachment(const QString &mailAttachFile) |
269 | { | 271 | { |
270 | if (mType == Email) { | 272 | if (mType == Email) { |
271 | mMailAttachFiles.clear(); | 273 | mMailAttachFiles.clear(); |
272 | mMailAttachFiles += mailAttachFile; | 274 | mMailAttachFiles += mailAttachFile; |
273 | mParent->updated(); | 275 | mParent->updated(); |
274 | } | 276 | } |
275 | } | 277 | } |
276 | 278 | ||
277 | void Alarm::setMailAttachments(const QStringList &mailAttachFiles) | 279 | void Alarm::setMailAttachments(const QStringList &mailAttachFiles) |
278 | { | 280 | { |
279 | if (mType == Email) { | 281 | if (mType == Email) { |
280 | mMailAttachFiles = mailAttachFiles; | 282 | mMailAttachFiles = mailAttachFiles; |
281 | mParent->updated(); | 283 | mParent->updated(); |
282 | } | 284 | } |
283 | } | 285 | } |
284 | 286 | ||
285 | void Alarm::addMailAttachment(const QString &mailAttachFile) | 287 | void Alarm::addMailAttachment(const QString &mailAttachFile) |
286 | { | 288 | { |
287 | if (mType == Email) { | 289 | if (mType == Email) { |
288 | mMailAttachFiles += mailAttachFile; | 290 | mMailAttachFiles += mailAttachFile; |
289 | mParent->updated(); | 291 | mParent->updated(); |
290 | } | 292 | } |
291 | } | 293 | } |
292 | 294 | ||
293 | QStringList Alarm::mailAttachments() const | 295 | QStringList Alarm::mailAttachments() const |
294 | { | 296 | { |
295 | return (mType == Email) ? mMailAttachFiles : QStringList(); | 297 | return (mType == Email) ? mMailAttachFiles : QStringList(); |
296 | } | 298 | } |
297 | 299 | ||
298 | void Alarm::setMailText(const QString &text) | 300 | void Alarm::setMailText(const QString &text) |
299 | { | 301 | { |
300 | if (mType == Email) { | 302 | if (mType == Email) { |
301 | mDescription = text; | 303 | mDescription = text; |
302 | mParent->updated(); | 304 | mParent->updated(); |
303 | } | 305 | } |
304 | } | 306 | } |
305 | 307 | ||
306 | QString Alarm::mailText() const | 308 | QString Alarm::mailText() const |
307 | { | 309 | { |
308 | return (mType == Email) ? mDescription : QString::null; | 310 | return (mType == Email) ? mDescription : QString::null; |
309 | } | 311 | } |
310 | 312 | ||
311 | void Alarm::setDisplayAlarm(const QString &text) | 313 | void Alarm::setDisplayAlarm(const QString &text) |
312 | { | 314 | { |
313 | mType = Display; | 315 | mType = Display; |
314 | mDescription = text; | 316 | mDescription = text; |
315 | mParent->updated(); | 317 | mParent->updated(); |
316 | } | 318 | } |
317 | 319 | ||
318 | void Alarm::setText(const QString &text) | 320 | void Alarm::setText(const QString &text) |
319 | { | 321 | { |
320 | if (mType == Display) { | 322 | if (mType == Display) { |
321 | mDescription = text; | 323 | mDescription = text; |
322 | mParent->updated(); | 324 | mParent->updated(); |
323 | } | 325 | } |
324 | } | 326 | } |
325 | 327 | ||
326 | QString Alarm::text() const | 328 | QString Alarm::text() const |
327 | { | 329 | { |
328 | return (mType == Display) ? mDescription : QString::null; | 330 | return (mType == Display) ? mDescription : QString::null; |
329 | } | 331 | } |
330 | 332 | ||
331 | void Alarm::setTime(const QDateTime &alarmTime) | 333 | void Alarm::setTime(const QDateTime &alarmTime) |
332 | { | 334 | { |
333 | mAlarmTime = alarmTime; | 335 | mAlarmTime = alarmTime; |
334 | mHasTime = true; | 336 | mHasTime = true; |
335 | 337 | ||
336 | mParent->updated(); | 338 | mParent->updated(); |
337 | } | 339 | } |
338 | int Alarm::offset() | 340 | int Alarm::offset() |
339 | { | 341 | { |
340 | if ( hasTime() ) { | 342 | if ( hasTime() ) { |
341 | if (mParent->typeID() == todoID ) { | 343 | if (mParent->typeID() == todoID ) { |
342 | Todo *t = static_cast<Todo*>(mParent); | 344 | Todo *t = static_cast<Todo*>(mParent); |
343 | return t->dtDue().secsTo( mAlarmTime ) ; | 345 | return t->dtDue().secsTo( mAlarmTime ) ; |
344 | } else | 346 | } else |
345 | return mParent->dtStart().secsTo( mAlarmTime ) ; | 347 | return mParent->dtStart().secsTo( mAlarmTime ) ; |
346 | } | 348 | } |
347 | else | 349 | else |
348 | { | 350 | { |
349 | return mOffset.asSeconds(); | 351 | return mOffset.asSeconds(); |
350 | } | 352 | } |
351 | 353 | ||
352 | } | 354 | } |
353 | QString Alarm::offsetText() | 355 | QString Alarm::offsetText() |
354 | { | 356 | { |
355 | int min = -offset()/60; | 357 | int min = -offset()/60; |
356 | int hours = min /60; | 358 | int hours = min /60; |
357 | min = min % 60; | 359 | min = min % 60; |
358 | int days = hours /24; | 360 | int days = hours /24; |
359 | hours = hours % 24; | 361 | hours = hours % 24; |
360 | QString message; | 362 | QString message; |
361 | //qDebug("%d %d %d ", days, hours, min ); | 363 | //qDebug("%d %d %d ", days, hours, min ); |
362 | if ( days > 0 ) | 364 | if ( days > 0 ) |
363 | message += i18n("%1d").arg( days ); | 365 | message += i18n("%1d").arg( days ); |
364 | if ( hours > 0 ) { | 366 | if ( hours > 0 ) { |
365 | if ( !message.isEmpty() ) message += "/"; | 367 | if ( !message.isEmpty() ) message += "/"; |
366 | message += i18n("%1h").arg( hours ); | 368 | message += i18n("%1h").arg( hours ); |
367 | } | 369 | } |
368 | if ( min > 0 ) { | 370 | if ( min > 0 ) { |
369 | if ( !message.isEmpty() ) message += "/"; | 371 | if ( !message.isEmpty() ) message += "/"; |
370 | message += i18n("%1min").arg( min ); | 372 | message += i18n("%1min").arg( min ); |
371 | } | 373 | } |
372 | if ( message.isEmpty() ) | 374 | if ( message.isEmpty() ) |
373 | message = i18n("%1min").arg( 0 ); | 375 | message = i18n("%1min").arg( 0 ); |
374 | if ( !mParent->alarmEnabled() ) | 376 | if ( !mParent->alarmEnabled() ) |
375 | return "!"+message + i18n("(disabled)"); | 377 | return "!"+message + i18n("(disabled)"); |
376 | return message; | 378 | return message; |
377 | } | 379 | } |
378 | 380 | ||
379 | 381 | ||
380 | QDateTime Alarm::time() const | 382 | QDateTime Alarm::time() const |
381 | { | 383 | { |
382 | if ( hasTime() ) | 384 | if ( hasTime() ) |
383 | return mAlarmTime; | 385 | return mAlarmTime; |
384 | else | 386 | else |
385 | { | 387 | { |
386 | if (mParent->typeID() == todoID ) { | 388 | if (mParent->typeID() == todoID ) { |
387 | Todo *t = static_cast<Todo*>(mParent); | 389 | Todo *t = static_cast<Todo*>(mParent); |
388 | return mOffset.end( t->dtDue() ); | 390 | return mOffset.end( t->dtDue() ); |
389 | } else if (mEndOffset) { | 391 | } else if (mEndOffset) { |
390 | return mOffset.end( mParent->dtEnd() ); | 392 | return mOffset.end( mParent->dtEnd() ); |
391 | } else { | 393 | } else { |
392 | return mOffset.end( mParent->dtStart() ); | 394 | return mOffset.end( mParent->dtStart() ); |
393 | } | 395 | } |
394 | } | 396 | } |
395 | } | 397 | } |
396 | 398 | ||
397 | bool Alarm::hasTime() const | 399 | bool Alarm::hasTime() const |
398 | { | 400 | { |
399 | return mHasTime; | 401 | return mHasTime; |
400 | } | 402 | } |
401 | 403 | ||
402 | void Alarm::setSnoozeTime(int alarmSnoozeTime) | 404 | void Alarm::setSnoozeTime(int alarmSnoozeTime) |
403 | { | 405 | { |
404 | mAlarmSnoozeTime = alarmSnoozeTime; | 406 | mAlarmSnoozeTime = alarmSnoozeTime; |
405 | mParent->updated(); | 407 | mParent->updated(); |
406 | } | 408 | } |
407 | 409 | ||
408 | int Alarm::snoozeTime() const | 410 | int Alarm::snoozeTime() const |
409 | { | 411 | { |
410 | return mAlarmSnoozeTime; | 412 | return mAlarmSnoozeTime; |
411 | } | 413 | } |
412 | 414 | ||
413 | void Alarm::setRepeatCount(int alarmRepeatCount) | 415 | void Alarm::setRepeatCount(int alarmRepeatCount) |
414 | { | 416 | { |
415 | kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; | 417 | kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; |
416 | 418 | ||
417 | mAlarmRepeatCount = alarmRepeatCount; | 419 | mAlarmRepeatCount = alarmRepeatCount; |
418 | mParent->updated(); | 420 | mParent->updated(); |
419 | } | 421 | } |
420 | 422 | ||
421 | int Alarm::repeatCount() const | 423 | int Alarm::repeatCount() const |
422 | { | 424 | { |
423 | kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; | 425 | kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; |
424 | return mAlarmRepeatCount; | 426 | return mAlarmRepeatCount; |
425 | } | 427 | } |
426 | 428 | ||
427 | void Alarm::toggleAlarm() | 429 | void Alarm::toggleAlarm() |
428 | { | 430 | { |
429 | mAlarmEnabled = !mAlarmEnabled; | 431 | mAlarmEnabled = !mAlarmEnabled; |
430 | mParent->updated(); | 432 | mParent->updated(); |
431 | } | 433 | } |
432 | 434 | ||
433 | void Alarm::setEnabled(bool enable) | 435 | void Alarm::setEnabled(bool enable) |
434 | { | 436 | { |
435 | mAlarmEnabled = enable; | 437 | mAlarmEnabled = enable; |
436 | mParent->updated(); | 438 | mParent->updated(); |
437 | } | 439 | } |
438 | 440 | ||
439 | bool Alarm::enabled() const | 441 | bool Alarm::enabled() const |
440 | { | 442 | { |
441 | return mAlarmEnabled; | 443 | return mAlarmEnabled; |
442 | } | 444 | } |
443 | 445 | ||
444 | void Alarm::setStartOffset( const Duration &offset ) | 446 | void Alarm::setStartOffset( const Duration &offset ) |
445 | { | 447 | { |
446 | mOffset = offset; | 448 | mOffset = offset; |
447 | mEndOffset = false; | 449 | mEndOffset = false; |
448 | mHasTime = false; | 450 | mHasTime = false; |
449 | mParent->updated(); | 451 | mParent->updated(); |
450 | } | 452 | } |
451 | 453 | ||
452 | Duration Alarm::startOffset() const | 454 | Duration Alarm::startOffset() const |
453 | { | 455 | { |
454 | return (mHasTime || mEndOffset) ? 0 : mOffset; | 456 | return (mHasTime || mEndOffset) ? 0 : mOffset; |
455 | } | 457 | } |
456 | 458 | ||
457 | bool Alarm::hasStartOffset() const | 459 | bool Alarm::hasStartOffset() const |
458 | { | 460 | { |
459 | return !mHasTime && !mEndOffset; | 461 | return !mHasTime && !mEndOffset; |
460 | } | 462 | } |
461 | 463 | ||
462 | bool Alarm::hasEndOffset() const | 464 | bool Alarm::hasEndOffset() const |
463 | { | 465 | { |
464 | return !mHasTime && mEndOffset; | 466 | return !mHasTime && mEndOffset; |
465 | } | 467 | } |
466 | 468 | ||
467 | void Alarm::setEndOffset( const Duration &offset ) | 469 | void Alarm::setEndOffset( const Duration &offset ) |
468 | { | 470 | { |
469 | mOffset = offset; | 471 | mOffset = offset; |
470 | mEndOffset = true; | 472 | mEndOffset = true; |
471 | mHasTime = false; | 473 | mHasTime = false; |
472 | mParent->updated(); | 474 | mParent->updated(); |
473 | } | 475 | } |
474 | 476 | ||
475 | Duration Alarm::endOffset() const | 477 | Duration Alarm::endOffset() const |
476 | { | 478 | { |
477 | return (mHasTime || !mEndOffset) ? 0 : mOffset; | 479 | return (mHasTime || !mEndOffset) ? 0 : mOffset; |
478 | } | 480 | } |
479 | 481 | ||
480 | void Alarm::setParent( Incidence *parent ) | 482 | void Alarm::setParent( Incidence *parent ) |
481 | { | 483 | { |
482 | mParent = parent; | 484 | mParent = parent; |
483 | } | 485 | } |
diff --git a/libkcal/alarm.h b/libkcal/alarm.h index ac6ea0d..b24f0f7 100644 --- a/libkcal/alarm.h +++ b/libkcal/alarm.h | |||
@@ -1,246 +1,246 @@ | |||
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 KCAL_ALARM_H | 21 | #ifndef KCAL_ALARM_H |
22 | #define KCAL_ALARM_H | 22 | #define KCAL_ALARM_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qvaluelist.h> | 25 | #include <q3valuelist.h> |
26 | 26 | ||
27 | #include "customproperties.h" | 27 | #include "customproperties.h" |
28 | #include "duration.h" | 28 | #include "duration.h" |
29 | #include "person.h" | 29 | #include "person.h" |
30 | 30 | ||
31 | namespace KCal { | 31 | namespace KCal { |
32 | 32 | ||
33 | class Incidence; | 33 | class Incidence; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | This class represents an alarm notification. | 36 | This class represents an alarm notification. |
37 | */ | 37 | */ |
38 | class Alarm : public CustomProperties | 38 | class Alarm : public CustomProperties |
39 | { | 39 | { |
40 | public: | 40 | public: |
41 | enum Type { Invalid, Display, Procedure, Email, Audio }; | 41 | enum Type { Invalid, Display, Procedure, Email, Audio }; |
42 | typedef QValueList<Alarm *> List; | 42 | typedef Q3ValueList<Alarm *> List; |
43 | 43 | ||
44 | /** Construct a new alarm with variables initialized to "sane" values. */ | 44 | /** Construct a new alarm with variables initialized to "sane" values. */ |
45 | explicit Alarm(Incidence *parent); | 45 | explicit Alarm(Incidence *parent); |
46 | /** Destruct Alarm object. */ | 46 | /** Destruct Alarm object. */ |
47 | ~Alarm(); | 47 | ~Alarm(); |
48 | 48 | ||
49 | /** Compare this alarm with another one. */ | 49 | /** Compare this alarm with another one. */ |
50 | bool operator==(const Alarm &) const; | 50 | bool operator==(const Alarm &) const; |
51 | bool operator!=(const Alarm &a) const { return !operator==(a); } | 51 | bool operator!=(const Alarm &a) const { return !operator==(a); } |
52 | 52 | ||
53 | /** Set the type of the alarm. | 53 | /** Set the type of the alarm. |
54 | If the specified type is different from the current type of the alarm, | 54 | If the specified type is different from the current type of the alarm, |
55 | the alarm's type-specific properties are initialised to null. | 55 | the alarm's type-specific properties are initialised to null. |
56 | @param type type of alarm. | 56 | @param type type of alarm. |
57 | */ | 57 | */ |
58 | void setType(Type type); | 58 | void setType(Type type); |
59 | /** Return the type of the alarm */ | 59 | /** Return the type of the alarm */ |
60 | Type type() const; | 60 | Type type() const; |
61 | int offset(); | 61 | int offset(); |
62 | QString offsetText(); | 62 | QString offsetText(); |
63 | /** Set the alarm to be a display alarm. | 63 | /** Set the alarm to be a display alarm. |
64 | @param text text to display when the alarm is triggered. | 64 | @param text text to display when the alarm is triggered. |
65 | */ | 65 | */ |
66 | void setDisplayAlarm(const QString &text); | 66 | void setDisplayAlarm(const QString &text); |
67 | /** Set the text to be displayed when the alarm is triggered. | 67 | /** Set the text to be displayed when the alarm is triggered. |
68 | Ignored if the alarm is not a display alarm. | 68 | Ignored if the alarm is not a display alarm. |
69 | */ | 69 | */ |
70 | void setText(const QString &text); | 70 | void setText(const QString &text); |
71 | /** Return the text string that displays when the alarm is triggered. */ | 71 | /** Return the text string that displays when the alarm is triggered. */ |
72 | QString text() const; | 72 | QString text() const; |
73 | 73 | ||
74 | /** Set the alarm to be an audio alarm. | 74 | /** Set the alarm to be an audio alarm. |
75 | @param audioFile optional file to play when the alarm is triggered. | 75 | @param audioFile optional file to play when the alarm is triggered. |
76 | */ | 76 | */ |
77 | void setAudioAlarm(const QString &audioFile = QString::null); | 77 | void setAudioAlarm(const QString &audioFile = QString::null); |
78 | /** Set the file to play when the audio alarm is triggered. | 78 | /** Set the file to play when the audio alarm is triggered. |
79 | Ignored if the alarm is not an audio alarm. | 79 | Ignored if the alarm is not an audio alarm. |
80 | */ | 80 | */ |
81 | void setAudioFile(const QString &audioFile); | 81 | void setAudioFile(const QString &audioFile); |
82 | /** Return the name of the audio file for the alarm. | 82 | /** Return the name of the audio file for the alarm. |
83 | @return The audio file for the alarm, or QString::null if not an audio alarm. | 83 | @return The audio file for the alarm, or QString::null if not an audio alarm. |
84 | */ | 84 | */ |
85 | QString audioFile() const; | 85 | QString audioFile() const; |
86 | 86 | ||
87 | /** Set the alarm to be a procedure alarm. | 87 | /** Set the alarm to be a procedure alarm. |
88 | @param programFile program to execute when the alarm is triggered. | 88 | @param programFile program to execute when the alarm is triggered. |
89 | @param arguments arguments to supply to programFile. | 89 | @param arguments arguments to supply to programFile. |
90 | */ | 90 | */ |
91 | void setProcedureAlarm(const QString &programFile, const QString &arguments = QString::null); | 91 | void setProcedureAlarm(const QString &programFile, const QString &arguments = QString::null); |
92 | /** Set the program file to execute when the alarm is triggered. | 92 | /** Set the program file to execute when the alarm is triggered. |
93 | Ignored if the alarm is not a procedure alarm. | 93 | Ignored if the alarm is not a procedure alarm. |
94 | */ | 94 | */ |
95 | void setProgramFile(const QString &programFile); | 95 | void setProgramFile(const QString &programFile); |
96 | /** Return the name of the program file to execute when the alarm is triggered. | 96 | /** Return the name of the program file to execute when the alarm is triggered. |
97 | @return the program file name, or QString::null if not a procedure alarm. | 97 | @return the program file name, or QString::null if not a procedure alarm. |
98 | */ | 98 | */ |
99 | QString programFile() const; | 99 | QString programFile() const; |
100 | /** Set the arguments to the program to execute when the alarm is triggered. | 100 | /** Set the arguments to the program to execute when the alarm is triggered. |
101 | Ignored if the alarm is not a procedure alarm. | 101 | Ignored if the alarm is not a procedure alarm. |
102 | */ | 102 | */ |
103 | void setProgramArguments(const QString &arguments); | 103 | void setProgramArguments(const QString &arguments); |
104 | /** Return the arguments to the program to run when the alarm is triggered. | 104 | /** Return the arguments to the program to run when the alarm is triggered. |
105 | @return the program arguments, or QString::null if not a procedure alarm. | 105 | @return the program arguments, or QString::null if not a procedure alarm. |
106 | */ | 106 | */ |
107 | QString programArguments() const; | 107 | QString programArguments() const; |
108 | 108 | ||
109 | /** Set the alarm to be an email alarm. | 109 | /** Set the alarm to be an email alarm. |
110 | @param subject subject line of email. | 110 | @param subject subject line of email. |
111 | @param text body of email. | 111 | @param text body of email. |
112 | @param addressees email addresses of recipient(s). | 112 | @param addressees email addresses of recipient(s). |
113 | @param attachments optional names of files to attach to the email. | 113 | @param attachments optional names of files to attach to the email. |
114 | */ | 114 | */ |
115 | void setEmailAlarm(const QString &subject, const QString &text, const QValueList<Person> &addressees, | 115 | void setEmailAlarm(const QString &subject, const QString &text, const Q3ValueList<Person> &addressees, |
116 | const QStringList &attachments = QStringList()); | 116 | const QStringList &attachments = QStringList()); |
117 | 117 | ||
118 | /** Send mail to this address when the alarm is triggered. | 118 | /** Send mail to this address when the alarm is triggered. |
119 | Ignored if the alarm is not an email alarm. | 119 | Ignored if the alarm is not an email alarm. |
120 | */ | 120 | */ |
121 | void setMailAddress(const Person &mailAlarmAddress); | 121 | void setMailAddress(const Person &mailAlarmAddress); |
122 | /** Send mail to these addresses when the alarm is triggered. | 122 | /** Send mail to these addresses when the alarm is triggered. |
123 | Ignored if the alarm is not an email alarm. | 123 | Ignored if the alarm is not an email alarm. |
124 | */ | 124 | */ |
125 | void setMailAddresses(const QValueList<Person> &mailAlarmAddresses); | 125 | void setMailAddresses(const Q3ValueList<Person> &mailAlarmAddresses); |
126 | /** Add this address to the list of addresses to send mail to when the alarm is triggered. | 126 | /** Add this address to the list of addresses to send mail to when the alarm is triggered. |
127 | Ignored if the alarm is not an email alarm. | 127 | Ignored if the alarm is not an email alarm. |
128 | */ | 128 | */ |
129 | void addMailAddress(const Person &mailAlarmAddress); | 129 | void addMailAddress(const Person &mailAlarmAddress); |
130 | /** return the addresses to send mail to when an alarm goes off */ | 130 | /** return the addresses to send mail to when an alarm goes off */ |
131 | QValueList<Person> mailAddresses() const; | 131 | Q3ValueList<Person> mailAddresses() const; |
132 | 132 | ||
133 | /** Set the subject line of the mail. | 133 | /** Set the subject line of the mail. |
134 | Ignored if the alarm is not an email alarm. | 134 | Ignored if the alarm is not an email alarm. |
135 | */ | 135 | */ |
136 | void setMailSubject(const QString &mailAlarmSubject); | 136 | void setMailSubject(const QString &mailAlarmSubject); |
137 | /** return the subject line of the mail */ | 137 | /** return the subject line of the mail */ |
138 | QString mailSubject() const; | 138 | QString mailSubject() const; |
139 | 139 | ||
140 | /** Attach this filename to the email. | 140 | /** Attach this filename to the email. |
141 | Ignored if the alarm is not an email alarm. | 141 | Ignored if the alarm is not an email alarm. |
142 | */ | 142 | */ |
143 | void setMailAttachment(const QString &mailAttachFile); | 143 | void setMailAttachment(const QString &mailAttachFile); |
144 | /** Attach these filenames to the email. | 144 | /** Attach these filenames to the email. |
145 | Ignored if the alarm is not an email alarm. | 145 | Ignored if the alarm is not an email alarm. |
146 | */ | 146 | */ |
147 | void setMailAttachments(const QStringList &mailAttachFiles); | 147 | void setMailAttachments(const QStringList &mailAttachFiles); |
148 | /** Add this filename to the list of files to attach to the email. | 148 | /** Add this filename to the list of files to attach to the email. |
149 | Ignored if the alarm is not an email alarm. | 149 | Ignored if the alarm is not an email alarm. |
150 | */ | 150 | */ |
151 | void addMailAttachment(const QString &mailAttachFile); | 151 | void addMailAttachment(const QString &mailAttachFile); |
152 | /** return the filenames to attach to the email */ | 152 | /** return the filenames to attach to the email */ |
153 | QStringList mailAttachments() const; | 153 | QStringList mailAttachments() const; |
154 | 154 | ||
155 | /** Set the email body text. | 155 | /** Set the email body text. |
156 | Ignored if the alarm is not an email alarm. | 156 | Ignored if the alarm is not an email alarm. |
157 | */ | 157 | */ |
158 | void setMailText(const QString &text); | 158 | void setMailText(const QString &text); |
159 | /** Return the email body text. | 159 | /** Return the email body text. |
160 | @return the body text, or QString::null if not an email alarm. | 160 | @return the body text, or QString::null if not an email alarm. |
161 | */ | 161 | */ |
162 | QString mailText() const; | 162 | QString mailText() const; |
163 | 163 | ||
164 | /** set the time to trigger an alarm */ | 164 | /** set the time to trigger an alarm */ |
165 | void setTime(const QDateTime &alarmTime); | 165 | void setTime(const QDateTime &alarmTime); |
166 | /** return the date/time when an alarm goes off */ | 166 | /** return the date/time when an alarm goes off */ |
167 | QDateTime time() const; | 167 | QDateTime time() const; |
168 | /** Return true, if the alarm has an explicit date/time. */ | 168 | /** Return true, if the alarm has an explicit date/time. */ |
169 | bool hasTime() const; | 169 | bool hasTime() const; |
170 | 170 | ||
171 | /** Set offset of alarm in time relative to the start of the event. */ | 171 | /** Set offset of alarm in time relative to the start of the event. */ |
172 | void setStartOffset(const Duration &); | 172 | void setStartOffset(const Duration &); |
173 | /** Return offset of alarm in time relative to the start of the event. | 173 | /** Return offset of alarm in time relative to the start of the event. |
174 | * If the alarm's time is not defined in terms of an offset relative | 174 | * If the alarm's time is not defined in terms of an offset relative |
175 | * to the start of the event, returns zero. | 175 | * to the start of the event, returns zero. |
176 | */ | 176 | */ |
177 | Duration startOffset() const; | 177 | Duration startOffset() const; |
178 | /** Return whether the alarm is defined in terms of an offset relative | 178 | /** Return whether the alarm is defined in terms of an offset relative |
179 | * to the start of the event. | 179 | * to the start of the event. |
180 | */ | 180 | */ |
181 | bool hasStartOffset() const; | 181 | bool hasStartOffset() const; |
182 | 182 | ||
183 | /** Set offset of alarm in time relative to the end of the event. */ | 183 | /** Set offset of alarm in time relative to the end of the event. */ |
184 | void setEndOffset(const Duration &); | 184 | void setEndOffset(const Duration &); |
185 | /** Return offset of alarm in time relative to the end of the event. | 185 | /** Return offset of alarm in time relative to the end of the event. |
186 | * If the alarm's time is not defined in terms of an offset relative | 186 | * If the alarm's time is not defined in terms of an offset relative |
187 | * to the end of the event, returns zero. | 187 | * to the end of the event, returns zero. |
188 | */ | 188 | */ |
189 | Duration endOffset() const; | 189 | Duration endOffset() const; |
190 | /** Return whether the alarm is defined in terms of an offset relative | 190 | /** Return whether the alarm is defined in terms of an offset relative |
191 | * to the end of the event. | 191 | * to the end of the event. |
192 | */ | 192 | */ |
193 | bool hasEndOffset() const; | 193 | bool hasEndOffset() const; |
194 | 194 | ||
195 | /** Set the interval between snoozes for the alarm. | 195 | /** Set the interval between snoozes for the alarm. |
196 | @param snoozeTime the time in minutes between snoozes. | 196 | @param snoozeTime the time in minutes between snoozes. |
197 | */ | 197 | */ |
198 | void setSnoozeTime(int alarmSnoozeTime); | 198 | void setSnoozeTime(int alarmSnoozeTime); |
199 | /** Get how long the alarm snooze interval is. | 199 | /** Get how long the alarm snooze interval is. |
200 | @return the number of minutes between snoozes. | 200 | @return the number of minutes between snoozes. |
201 | */ | 201 | */ |
202 | int snoozeTime() const; | 202 | int snoozeTime() const; |
203 | 203 | ||
204 | /** set how many times an alarm is to repeat itself (w/snoozes) */ | 204 | /** set how many times an alarm is to repeat itself (w/snoozes) */ |
205 | void setRepeatCount(int alarmRepeatCount); | 205 | void setRepeatCount(int alarmRepeatCount); |
206 | /** get how many times an alarm repeats */ | 206 | /** get how many times an alarm repeats */ |
207 | int repeatCount() const; | 207 | int repeatCount() const; |
208 | 208 | ||
209 | /** toggles the value of alarm to be either on or off. | 209 | /** toggles the value of alarm to be either on or off. |
210 | set's the alarm time to be x minutes before dtStart time. */ | 210 | set's the alarm time to be x minutes before dtStart time. */ |
211 | void toggleAlarm(); | 211 | void toggleAlarm(); |
212 | 212 | ||
213 | /** set the alarm enabled status */ | 213 | /** set the alarm enabled status */ |
214 | void setEnabled(bool enable); | 214 | void setEnabled(bool enable); |
215 | /** get the alarm enabled status */ | 215 | /** get the alarm enabled status */ |
216 | bool enabled() const; | 216 | bool enabled() const; |
217 | 217 | ||
218 | /** Set the alarm's parent incidence */ | 218 | /** Set the alarm's parent incidence */ |
219 | void setParent( Incidence * ); | 219 | void setParent( Incidence * ); |
220 | /** get the alarm's parent incidence */ | 220 | /** get the alarm's parent incidence */ |
221 | Incidence *parent() const { return mParent; } | 221 | Incidence *parent() const { return mParent; } |
222 | 222 | ||
223 | private: | 223 | private: |
224 | Incidence *mParent; // the incidence which this alarm belongs to | 224 | Incidence *mParent; // the incidence which this alarm belongs to |
225 | Type mType; // type of alarm | 225 | Type mType; // type of alarm |
226 | QString mDescription; // text to display/email body/procedure arguments | 226 | QString mDescription; // text to display/email body/procedure arguments |
227 | QString mFile; // procedure program to run/optional audio file to play | 227 | QString mFile; // procedure program to run/optional audio file to play |
228 | QStringList mMailAttachFiles; // filenames to attach to email | 228 | QStringList mMailAttachFiles; // filenames to attach to email |
229 | QValueList<Person> mMailAddresses; // who to mail for reminder | 229 | Q3ValueList<Person> mMailAddresses; // who to mail for reminder |
230 | QString mMailSubject; // subject of email | 230 | QString mMailSubject; // subject of email |
231 | 231 | ||
232 | int mAlarmSnoozeTime; // number of minutes after alarm to | 232 | int mAlarmSnoozeTime; // number of minutes after alarm to |
233 | // snooze before ringing again | 233 | // snooze before ringing again |
234 | int mAlarmRepeatCount; // number of times for alarm to repeat | 234 | int mAlarmRepeatCount; // number of times for alarm to repeat |
235 | // after the initial time | 235 | // after the initial time |
236 | 236 | ||
237 | QDateTime mAlarmTime; // time at which to trigger the alarm | 237 | QDateTime mAlarmTime; // time at which to trigger the alarm |
238 | Duration mOffset; // time relative to incidence DTSTART to trigger the alarm | 238 | Duration mOffset; // time relative to incidence DTSTART to trigger the alarm |
239 | bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART | 239 | bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART |
240 | bool mHasTime; // use mAlarmTime, not mOffset | 240 | bool mHasTime; // use mAlarmTime, not mOffset |
241 | bool mAlarmEnabled; | 241 | bool mAlarmEnabled; |
242 | }; | 242 | }; |
243 | 243 | ||
244 | } | 244 | } |
245 | 245 | ||
246 | #endif | 246 | #endif |
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 9b38d3f..bf095cf 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,526 +1,528 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
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 <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <time.h> | 22 | #include <time.h> |
23 | 23 | ||
24 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <kglobal.h> | 25 | #include <kglobal.h> |
26 | #include <klocale.h> | 26 | #include <klocale.h> |
27 | 27 | ||
28 | #include "exceptions.h" | 28 | #include "exceptions.h" |
29 | #include "calfilter.h" | 29 | #include "calfilter.h" |
30 | 30 | ||
31 | #include "calendar.h" | 31 | #include "calendar.h" |
32 | #include "syncdefines.h" | 32 | #include "syncdefines.h" |
33 | //Added by qt3to4: | ||
34 | #include <Q3PtrList> | ||
33 | 35 | ||
34 | using namespace KCal; | 36 | using namespace KCal; |
35 | 37 | ||
36 | Calendar::Calendar() | 38 | Calendar::Calendar() |
37 | { | 39 | { |
38 | 40 | ||
39 | init(); | 41 | init(); |
40 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 42 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
41 | } | 43 | } |
42 | 44 | ||
43 | Calendar::Calendar( const QString &timeZoneId ) | 45 | Calendar::Calendar( const QString &timeZoneId ) |
44 | { | 46 | { |
45 | 47 | ||
46 | init(); | 48 | init(); |
47 | setTimeZoneId(timeZoneId); | 49 | setTimeZoneId(timeZoneId); |
48 | } | 50 | } |
49 | 51 | ||
50 | void Calendar::init() | 52 | void Calendar::init() |
51 | { | 53 | { |
52 | mObserver = 0; | 54 | mObserver = 0; |
53 | mNewObserver = false; | 55 | mNewObserver = false; |
54 | mUndoIncidence = 0; | 56 | mUndoIncidence = 0; |
55 | mDeleteIncidencesOnClose = true; | 57 | mDeleteIncidencesOnClose = true; |
56 | mModified = false; | 58 | mModified = false; |
57 | mDefaultCalendar = 1; | 59 | mDefaultCalendar = 1; |
58 | // Setup default filter, which does nothing | 60 | // Setup default filter, which does nothing |
59 | mDefaultFilter = new CalFilter; | 61 | mDefaultFilter = new CalFilter; |
60 | mFilter = mDefaultFilter; | 62 | mFilter = mDefaultFilter; |
61 | mFilter->setEnabled(false); | 63 | mFilter->setEnabled(false); |
62 | 64 | ||
63 | // initialize random numbers. This is a hack, and not | 65 | // initialize random numbers. This is a hack, and not |
64 | // even that good of one at that. | 66 | // even that good of one at that. |
65 | // srandom(time(0)); | 67 | // srandom(time(0)); |
66 | 68 | ||
67 | // user information... | 69 | // user information... |
68 | setOwner(i18n("Unknown Name")); | 70 | setOwner(i18n("Unknown Name")); |
69 | setEmail(i18n("unknown@nowhere")); | 71 | setEmail(i18n("unknown@nowhere")); |
70 | 72 | ||
71 | #if 0 | 73 | #if 0 |
72 | tmpStr = KOPrefs::instance()->mTimeZone; | 74 | tmpStr = KOPrefs::instance()->mTimeZone; |
73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 75 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 76 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
75 | extern long int timezone; | 77 | extern long int timezone; |
76 | struct tm *now; | 78 | struct tm *now; |
77 | time_t curtime; | 79 | time_t curtime; |
78 | curtime = time(0); | 80 | curtime = time(0); |
79 | now = localtime(&curtime); | 81 | now = localtime(&curtime); |
80 | int hourOff = - ((timezone / 60) / 60); | 82 | int hourOff = - ((timezone / 60) / 60); |
81 | if (now->tm_isdst) | 83 | if (now->tm_isdst) |
82 | hourOff += 1; | 84 | hourOff += 1; |
83 | QString tzStr; | 85 | QString tzStr; |
84 | tzStr.sprintf("%.2d%.2d", | 86 | tzStr.sprintf("%.2d%.2d", |
85 | hourOff, | 87 | hourOff, |
86 | abs((timezone / 60) % 60)); | 88 | abs((timezone / 60) % 60)); |
87 | 89 | ||
88 | // if no time zone was in the config file, write what we just discovered. | 90 | // if no time zone was in the config file, write what we just discovered. |
89 | if (tmpStr.isEmpty()) { | 91 | if (tmpStr.isEmpty()) { |
90 | // KOPrefs::instance()->mTimeZone = tzStr; | 92 | // KOPrefs::instance()->mTimeZone = tzStr; |
91 | } else { | 93 | } else { |
92 | tzStr = tmpStr; | 94 | tzStr = tmpStr; |
93 | } | 95 | } |
94 | 96 | ||
95 | // if daylight savings has changed since last load time, we need | 97 | // if daylight savings has changed since last load time, we need |
96 | // to rewrite these settings to the config file. | 98 | // to rewrite these settings to the config file. |
97 | if ((now->tm_isdst && !dstSetting) || | 99 | if ((now->tm_isdst && !dstSetting) || |
98 | (!now->tm_isdst && dstSetting)) { | 100 | (!now->tm_isdst && dstSetting)) { |
99 | KOPrefs::instance()->mTimeZone = tzStr; | 101 | KOPrefs::instance()->mTimeZone = tzStr; |
100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 102 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
101 | } | 103 | } |
102 | 104 | ||
103 | setTimeZone(tzStr); | 105 | setTimeZone(tzStr); |
104 | #endif | 106 | #endif |
105 | 107 | ||
106 | // KOPrefs::instance()->writeConfig(); | 108 | // KOPrefs::instance()->writeConfig(); |
107 | } | 109 | } |
108 | 110 | ||
109 | Calendar::~Calendar() | 111 | Calendar::~Calendar() |
110 | { | 112 | { |
111 | delete mDefaultFilter; | 113 | delete mDefaultFilter; |
112 | clearUndo( 0 ); | 114 | clearUndo( 0 ); |
113 | } | 115 | } |
114 | void Calendar::clearUndo( Incidence * newUndo ) | 116 | void Calendar::clearUndo( Incidence * newUndo ) |
115 | { | 117 | { |
116 | 118 | ||
117 | if ( mUndoIncidence ) { | 119 | if ( mUndoIncidence ) { |
118 | if ( mUndoIncidence->typeID() == eventID ) | 120 | if ( mUndoIncidence->typeID() == eventID ) |
119 | delete ((Event*) mUndoIncidence) ; | 121 | delete ((Event*) mUndoIncidence) ; |
120 | else if ( mUndoIncidence->typeID() == todoID ) | 122 | else if ( mUndoIncidence->typeID() == todoID ) |
121 | delete ( (Todo*) mUndoIncidence ); | 123 | delete ( (Todo*) mUndoIncidence ); |
122 | else if ( mUndoIncidence->typeID() == journalID ) | 124 | else if ( mUndoIncidence->typeID() == journalID ) |
123 | delete ( (Journal*) mUndoIncidence ); | 125 | delete ( (Journal*) mUndoIncidence ); |
124 | else | 126 | else |
125 | delete mUndoIncidence; | 127 | delete mUndoIncidence; |
126 | } | 128 | } |
127 | mUndoIncidence = newUndo; | 129 | mUndoIncidence = newUndo; |
128 | if ( mUndoIncidence ) { | 130 | if ( mUndoIncidence ) { |
129 | mUndoIncidence->clearRelations(); | 131 | mUndoIncidence->clearRelations(); |
130 | } | 132 | } |
131 | 133 | ||
132 | } | 134 | } |
133 | 135 | ||
134 | void Calendar::setDontDeleteIncidencesOnClose () | 136 | void Calendar::setDontDeleteIncidencesOnClose () |
135 | { | 137 | { |
136 | mDeleteIncidencesOnClose = false; | 138 | mDeleteIncidencesOnClose = false; |
137 | } | 139 | } |
138 | void Calendar::setDefaultCalendar( int d ) | 140 | void Calendar::setDefaultCalendar( int d ) |
139 | { | 141 | { |
140 | mDefaultCalendar = d; | 142 | mDefaultCalendar = d; |
141 | } | 143 | } |
142 | int Calendar::defaultCalendar() | 144 | int Calendar::defaultCalendar() |
143 | { | 145 | { |
144 | return mDefaultCalendar; | 146 | return mDefaultCalendar; |
145 | } | 147 | } |
146 | const QString &Calendar::getOwner() const | 148 | const QString &Calendar::getOwner() const |
147 | { | 149 | { |
148 | return mOwner; | 150 | return mOwner; |
149 | } | 151 | } |
150 | 152 | ||
151 | bool Calendar::undoDeleteIncidence() | 153 | bool Calendar::undoDeleteIncidence() |
152 | { | 154 | { |
153 | if (!mUndoIncidence) | 155 | if (!mUndoIncidence) |
154 | return false; | 156 | return false; |
155 | addIncidence(mUndoIncidence); | 157 | addIncidence(mUndoIncidence); |
156 | mUndoIncidence = 0; | 158 | mUndoIncidence = 0; |
157 | return true; | 159 | return true; |
158 | } | 160 | } |
159 | void Calendar::setOwner(const QString &os) | 161 | void Calendar::setOwner(const QString &os) |
160 | { | 162 | { |
161 | int i; | 163 | int i; |
162 | mOwner = os; | 164 | mOwner = os; |
163 | i = mOwner.find(','); | 165 | i = mOwner.find(','); |
164 | if (i != -1) | 166 | if (i != -1) |
165 | mOwner = mOwner.left(i); | 167 | mOwner = mOwner.left(i); |
166 | 168 | ||
167 | setModified( true ); | 169 | setModified( true ); |
168 | } | 170 | } |
169 | 171 | ||
170 | void Calendar::setTimeZone(const QString & tz) | 172 | void Calendar::setTimeZone(const QString & tz) |
171 | { | 173 | { |
172 | bool neg = FALSE; | 174 | bool neg = FALSE; |
173 | int hours, minutes; | 175 | int hours, minutes; |
174 | QString tmpStr(tz); | 176 | QString tmpStr(tz); |
175 | 177 | ||
176 | if (tmpStr.left(1) == "-") | 178 | if (tmpStr.left(1) == "-") |
177 | neg = TRUE; | 179 | neg = TRUE; |
178 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 180 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
179 | tmpStr.remove(0, 1); | 181 | tmpStr.remove(0, 1); |
180 | hours = tmpStr.left(2).toInt(); | 182 | hours = tmpStr.left(2).toInt(); |
181 | if (tmpStr.length() > 2) | 183 | if (tmpStr.length() > 2) |
182 | minutes = tmpStr.right(2).toInt(); | 184 | minutes = tmpStr.right(2).toInt(); |
183 | else | 185 | else |
184 | minutes = 0; | 186 | minutes = 0; |
185 | mTimeZone = (60*hours+minutes); | 187 | mTimeZone = (60*hours+minutes); |
186 | if (neg) | 188 | if (neg) |
187 | mTimeZone = -mTimeZone; | 189 | mTimeZone = -mTimeZone; |
188 | mLocalTime = false; | 190 | mLocalTime = false; |
189 | 191 | ||
190 | setModified( true ); | 192 | setModified( true ); |
191 | } | 193 | } |
192 | 194 | ||
193 | QString Calendar::getTimeZoneStr() const | 195 | QString Calendar::getTimeZoneStr() const |
194 | { | 196 | { |
195 | if (mLocalTime) | 197 | if (mLocalTime) |
196 | return ""; | 198 | return ""; |
197 | QString tmpStr; | 199 | QString tmpStr; |
198 | int hours = abs(mTimeZone / 60); | 200 | int hours = abs(mTimeZone / 60); |
199 | int minutes = abs(mTimeZone % 60); | 201 | int minutes = abs(mTimeZone % 60); |
200 | bool neg = mTimeZone < 0; | 202 | bool neg = mTimeZone < 0; |
201 | 203 | ||
202 | tmpStr.sprintf("%c%.2d%.2d", | 204 | tmpStr.sprintf("%c%.2d%.2d", |
203 | (neg ? '-' : '+'), | 205 | (neg ? '-' : '+'), |
204 | hours, minutes); | 206 | hours, minutes); |
205 | return tmpStr; | 207 | return tmpStr; |
206 | } | 208 | } |
207 | 209 | ||
208 | void Calendar::setTimeZone(int tz) | 210 | void Calendar::setTimeZone(int tz) |
209 | { | 211 | { |
210 | mTimeZone = tz; | 212 | mTimeZone = tz; |
211 | mLocalTime = false; | 213 | mLocalTime = false; |
212 | 214 | ||
213 | setModified( true ); | 215 | setModified( true ); |
214 | } | 216 | } |
215 | 217 | ||
216 | int Calendar::getTimeZone() const | 218 | int Calendar::getTimeZone() const |
217 | { | 219 | { |
218 | return mTimeZone; | 220 | return mTimeZone; |
219 | } | 221 | } |
220 | 222 | ||
221 | void Calendar::setTimeZoneId(const QString &id) | 223 | void Calendar::setTimeZoneId(const QString &id) |
222 | { | 224 | { |
223 | mTimeZoneId = id; | 225 | mTimeZoneId = id; |
224 | mLocalTime = false; | 226 | mLocalTime = false; |
225 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 227 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
226 | if ( mTimeZone > 1000) | 228 | if ( mTimeZone > 1000) |
227 | setLocalTime(); | 229 | setLocalTime(); |
228 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 230 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
229 | setModified( true ); | 231 | setModified( true ); |
230 | } | 232 | } |
231 | 233 | ||
232 | QString Calendar::timeZoneId() const | 234 | QString Calendar::timeZoneId() const |
233 | { | 235 | { |
234 | return mTimeZoneId; | 236 | return mTimeZoneId; |
235 | } | 237 | } |
236 | 238 | ||
237 | void Calendar::setLocalTime() | 239 | void Calendar::setLocalTime() |
238 | { | 240 | { |
239 | //qDebug("Calendar::setLocalTime() "); | 241 | //qDebug("Calendar::setLocalTime() "); |
240 | mLocalTime = true; | 242 | mLocalTime = true; |
241 | mTimeZone = 0; | 243 | mTimeZone = 0; |
242 | mTimeZoneId = ""; | 244 | mTimeZoneId = ""; |
243 | 245 | ||
244 | setModified( true ); | 246 | setModified( true ); |
245 | } | 247 | } |
246 | 248 | ||
247 | bool Calendar::isLocalTime() const | 249 | bool Calendar::isLocalTime() const |
248 | { | 250 | { |
249 | return mLocalTime; | 251 | return mLocalTime; |
250 | } | 252 | } |
251 | 253 | ||
252 | const QString &Calendar::getEmail() | 254 | const QString &Calendar::getEmail() |
253 | { | 255 | { |
254 | return mOwnerEmail; | 256 | return mOwnerEmail; |
255 | } | 257 | } |
256 | 258 | ||
257 | void Calendar::setEmail(const QString &e) | 259 | void Calendar::setEmail(const QString &e) |
258 | { | 260 | { |
259 | mOwnerEmail = e; | 261 | mOwnerEmail = e; |
260 | 262 | ||
261 | setModified( true ); | 263 | setModified( true ); |
262 | } | 264 | } |
263 | 265 | ||
264 | void Calendar::setFilter(CalFilter *filter) | 266 | void Calendar::setFilter(CalFilter *filter) |
265 | { | 267 | { |
266 | mFilter = filter; | 268 | mFilter = filter; |
267 | } | 269 | } |
268 | 270 | ||
269 | CalFilter *Calendar::filter() | 271 | CalFilter *Calendar::filter() |
270 | { | 272 | { |
271 | return mFilter; | 273 | return mFilter; |
272 | } | 274 | } |
273 | 275 | ||
274 | QPtrList<Incidence> Calendar::incidences() | 276 | Q3PtrList<Incidence> Calendar::incidences() |
275 | { | 277 | { |
276 | QPtrList<Incidence> incidences; | 278 | Q3PtrList<Incidence> incidences; |
277 | 279 | ||
278 | Incidence *i; | 280 | Incidence *i; |
279 | 281 | ||
280 | QPtrList<Event> e = events(); | 282 | Q3PtrList<Event> e = events(); |
281 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 283 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
282 | 284 | ||
283 | QPtrList<Todo> t = todos(); | 285 | Q3PtrList<Todo> t = todos(); |
284 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 286 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
285 | 287 | ||
286 | QPtrList<Journal> j = journals(); | 288 | Q3PtrList<Journal> j = journals(); |
287 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 289 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
288 | 290 | ||
289 | return incidences; | 291 | return incidences; |
290 | } | 292 | } |
291 | 293 | ||
292 | void Calendar::resetPilotStat(int id ) | 294 | void Calendar::resetPilotStat(int id ) |
293 | { | 295 | { |
294 | QPtrList<Incidence> incidences; | 296 | Q3PtrList<Incidence> incidences; |
295 | 297 | ||
296 | Incidence *i; | 298 | Incidence *i; |
297 | 299 | ||
298 | QPtrList<Event> e = rawEvents(); | 300 | Q3PtrList<Event> e = rawEvents(); |
299 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 301 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
300 | 302 | ||
301 | QPtrList<Todo> t = rawTodos(); | 303 | Q3PtrList<Todo> t = rawTodos(); |
302 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 304 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
303 | 305 | ||
304 | QPtrList<Journal> j = journals(); | 306 | Q3PtrList<Journal> j = journals(); |
305 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 307 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
306 | } | 308 | } |
307 | void Calendar::resetTempSyncStat() | 309 | void Calendar::resetTempSyncStat() |
308 | { | 310 | { |
309 | QPtrList<Incidence> incidences; | 311 | Q3PtrList<Incidence> incidences; |
310 | 312 | ||
311 | Incidence *i; | 313 | Incidence *i; |
312 | 314 | ||
313 | QPtrList<Event> e = rawEvents(); | 315 | Q3PtrList<Event> e = rawEvents(); |
314 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 316 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
315 | 317 | ||
316 | QPtrList<Todo> t = rawTodos(); | 318 | Q3PtrList<Todo> t = rawTodos(); |
317 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 319 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
318 | 320 | ||
319 | QPtrList<Journal> j = journals(); | 321 | Q3PtrList<Journal> j = journals(); |
320 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 322 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
321 | } | 323 | } |
322 | QPtrList<Incidence> Calendar::rawIncidences() | 324 | Q3PtrList<Incidence> Calendar::rawIncidences() |
323 | { | 325 | { |
324 | QPtrList<Incidence> incidences; | 326 | Q3PtrList<Incidence> incidences; |
325 | 327 | ||
326 | Incidence *i; | 328 | Incidence *i; |
327 | 329 | ||
328 | QPtrList<Event> e = rawEvents(); | 330 | Q3PtrList<Event> e = rawEvents(); |
329 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 331 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
330 | 332 | ||
331 | QPtrList<Todo> t = rawTodos(); | 333 | Q3PtrList<Todo> t = rawTodos(); |
332 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 334 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
333 | 335 | ||
334 | QPtrList<Journal> j = journals(); | 336 | Q3PtrList<Journal> j = journals(); |
335 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 337 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
336 | 338 | ||
337 | return incidences; | 339 | return incidences; |
338 | } | 340 | } |
339 | 341 | ||
340 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 342 | Q3PtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
341 | { | 343 | { |
342 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 344 | Q3PtrList<Event> el = rawEventsForDate(date,sorted); |
343 | mFilter->apply(&el); | 345 | mFilter->apply(&el); |
344 | return el; | 346 | return el; |
345 | } | 347 | } |
346 | 348 | ||
347 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 349 | Q3PtrList<Event> Calendar::events( const QDateTime &qdt ) |
348 | { | 350 | { |
349 | QPtrList<Event> el = rawEventsForDate(qdt); | 351 | Q3PtrList<Event> el = rawEventsForDate(qdt); |
350 | mFilter->apply(&el); | 352 | mFilter->apply(&el); |
351 | return el; | 353 | return el; |
352 | } | 354 | } |
353 | 355 | ||
354 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 356 | Q3PtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
355 | bool inclusive) | 357 | bool inclusive) |
356 | { | 358 | { |
357 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 359 | Q3PtrList<Event> el = rawEvents(start,end,inclusive); |
358 | mFilter->apply(&el); | 360 | mFilter->apply(&el); |
359 | return el; | 361 | return el; |
360 | } | 362 | } |
361 | 363 | ||
362 | QPtrList<Event> Calendar::events() | 364 | Q3PtrList<Event> Calendar::events() |
363 | { | 365 | { |
364 | QPtrList<Event> el = rawEvents(); | 366 | Q3PtrList<Event> el = rawEvents(); |
365 | mFilter->apply(&el); | 367 | mFilter->apply(&el); |
366 | return el; | 368 | return el; |
367 | } | 369 | } |
368 | void Calendar::addIncidenceBranch(Incidence *i) | 370 | void Calendar::addIncidenceBranch(Incidence *i) |
369 | { | 371 | { |
370 | addIncidence( i ); | 372 | addIncidence( i ); |
371 | Incidence * inc; | 373 | Incidence * inc; |
372 | QPtrList<Incidence> Relations = i->relations(); | 374 | Q3PtrList<Incidence> Relations = i->relations(); |
373 | for (inc=Relations.first();inc;inc=Relations.next()) { | 375 | for (inc=Relations.first();inc;inc=Relations.next()) { |
374 | addIncidenceBranch( inc ); | 376 | addIncidenceBranch( inc ); |
375 | } | 377 | } |
376 | } | 378 | } |
377 | 379 | ||
378 | bool Calendar::addIncidence(Incidence *i) | 380 | bool Calendar::addIncidence(Incidence *i) |
379 | { | 381 | { |
380 | Incidence::AddVisitor<Calendar> v(this); | 382 | Incidence::AddVisitor<Calendar> v(this); |
381 | if ( i->calID() == 0 ) | 383 | if ( i->calID() == 0 ) |
382 | i->setCalID_block( mDefaultCalendar ); | 384 | i->setCalID_block( mDefaultCalendar ); |
383 | i->setCalEnabled( true ); | 385 | i->setCalEnabled( true ); |
384 | return i->accept(v); | 386 | return i->accept(v); |
385 | } | 387 | } |
386 | void Calendar::deleteIncidence(Incidence *in) | 388 | void Calendar::deleteIncidence(Incidence *in) |
387 | { | 389 | { |
388 | if ( in->typeID() == eventID ) | 390 | if ( in->typeID() == eventID ) |
389 | deleteEvent( (Event*) in ); | 391 | deleteEvent( (Event*) in ); |
390 | else if ( in->typeID() == todoID ) | 392 | else if ( in->typeID() == todoID ) |
391 | deleteTodo( (Todo*) in); | 393 | deleteTodo( (Todo*) in); |
392 | else if ( in->typeID() == journalID ) | 394 | else if ( in->typeID() == journalID ) |
393 | deleteJournal( (Journal*) in ); | 395 | deleteJournal( (Journal*) in ); |
394 | } | 396 | } |
395 | 397 | ||
396 | Incidence* Calendar::incidence( const QString& uid ) | 398 | Incidence* Calendar::incidence( const QString& uid ) |
397 | { | 399 | { |
398 | Incidence* i; | 400 | Incidence* i; |
399 | 401 | ||
400 | if( (i = todo( uid )) != 0 ) | 402 | if( (i = todo( uid )) != 0 ) |
401 | return i; | 403 | return i; |
402 | if( (i = event( uid )) != 0 ) | 404 | if( (i = event( uid )) != 0 ) |
403 | return i; | 405 | return i; |
404 | if( (i = journal( uid )) != 0 ) | 406 | if( (i = journal( uid )) != 0 ) |
405 | return i; | 407 | return i; |
406 | 408 | ||
407 | return 0; | 409 | return 0; |
408 | } | 410 | } |
409 | 411 | ||
410 | QPtrList<Todo> Calendar::todos() | 412 | Q3PtrList<Todo> Calendar::todos() |
411 | { | 413 | { |
412 | QPtrList<Todo> tl = rawTodos(); | 414 | Q3PtrList<Todo> tl = rawTodos(); |
413 | mFilter->apply( &tl ); | 415 | mFilter->apply( &tl ); |
414 | return tl; | 416 | return tl; |
415 | } | 417 | } |
416 | 418 | ||
417 | // When this is called, the todo have already been added to the calendar. | 419 | // When this is called, the todo have already been added to the calendar. |
418 | // This method is only about linking related todos | 420 | // This method is only about linking related todos |
419 | void Calendar::setupRelations( Incidence *incidence ) | 421 | void Calendar::setupRelations( Incidence *incidence ) |
420 | { | 422 | { |
421 | QString uid = incidence->uid(); | 423 | QString uid = incidence->uid(); |
422 | qDebug("Calendar::setupRelations %s", incidence->summary().latin1()); | 424 | qDebug("Calendar::setupRelations %s", incidence->summary().latin1()); |
423 | // First, go over the list of orphans and see if this is their parent | 425 | // First, go over the list of orphans and see if this is their parent |
424 | while( Incidence* i = mOrphans[ uid ] ) { | 426 | while( Incidence* i = mOrphans[ uid ] ) { |
425 | mOrphans.remove( uid ); | 427 | mOrphans.remove( uid ); |
426 | i->setRelatedTo( incidence ); | 428 | i->setRelatedTo( incidence ); |
427 | qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1()); | 429 | qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1()); |
428 | incidence->addRelation( i ); | 430 | incidence->addRelation( i ); |
429 | mOrphanUids.remove( i->uid() ); | 431 | mOrphanUids.remove( i->uid() ); |
430 | } | 432 | } |
431 | 433 | ||
432 | // Now see about this incidences parent | 434 | // Now see about this incidences parent |
433 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 435 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
434 | // This incidence has a uid it is related to, but is not registered to it yet | 436 | // This incidence has a uid it is related to, but is not registered to it yet |
435 | // Try to find it | 437 | // Try to find it |
436 | qDebug("Test parent for %s", incidence->summary().latin1()); | 438 | qDebug("Test parent for %s", incidence->summary().latin1()); |
437 | Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true ); | 439 | Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true ); |
438 | if( parent ) { | 440 | if( parent ) { |
439 | // Found it | 441 | // Found it |
440 | qDebug("parent found for for %s", incidence->summary().latin1()); | 442 | qDebug("parent found for for %s", incidence->summary().latin1()); |
441 | incidence->setRelatedTo( parent ); | 443 | incidence->setRelatedTo( parent ); |
442 | parent->addRelation( incidence ); | 444 | parent->addRelation( incidence ); |
443 | } else { | 445 | } else { |
444 | qDebug("NO parent found for for %s", incidence->summary().latin1()); | 446 | qDebug("NO parent found for for %s", incidence->summary().latin1()); |
445 | // Not found, put this in the mOrphans list | 447 | // Not found, put this in the mOrphans list |
446 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 448 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
447 | mOrphanUids.insert( incidence->uid(), incidence ); | 449 | mOrphanUids.insert( incidence->uid(), incidence ); |
448 | } | 450 | } |
449 | } | 451 | } |
450 | } | 452 | } |
451 | 453 | ||
452 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 454 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
453 | void Calendar::removeRelations( Incidence *incidence ) | 455 | void Calendar::removeRelations( Incidence *incidence ) |
454 | { | 456 | { |
455 | // qDebug("Calendar::removeRelations "); | 457 | // qDebug("Calendar::removeRelations "); |
456 | QString uid = incidence->uid(); | 458 | QString uid = incidence->uid(); |
457 | 459 | ||
458 | QPtrList<Incidence> relations = incidence->relations(); | 460 | Q3PtrList<Incidence> relations = incidence->relations(); |
459 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 461 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
460 | if( !mOrphanUids.find( i->uid() ) ) { | 462 | if( !mOrphanUids.find( i->uid() ) ) { |
461 | mOrphans.insert( uid, i ); | 463 | mOrphans.insert( uid, i ); |
462 | mOrphanUids.insert( i->uid(), i ); | 464 | mOrphanUids.insert( i->uid(), i ); |
463 | i->setRelatedTo( 0 ); | 465 | i->setRelatedTo( 0 ); |
464 | i->setRelatedToUid( uid ); | 466 | i->setRelatedToUid( uid ); |
465 | } | 467 | } |
466 | 468 | ||
467 | // If this incidence is related to something else, tell that about it | 469 | // If this incidence is related to something else, tell that about it |
468 | if( incidence->relatedTo() ) | 470 | if( incidence->relatedTo() ) |
469 | incidence->relatedTo()->removeRelation( incidence ); | 471 | incidence->relatedTo()->removeRelation( incidence ); |
470 | 472 | ||
471 | // Remove this one from the orphans list | 473 | // Remove this one from the orphans list |
472 | if( mOrphanUids.remove( uid ) ) { | 474 | if( mOrphanUids.remove( uid ) ) { |
473 | QString r2uid = incidence->relatedToUid(); | 475 | QString r2uid = incidence->relatedToUid(); |
474 | QPtrList<Incidence> tempList; | 476 | Q3PtrList<Incidence> tempList; |
475 | while( Incidence* i = mOrphans[ r2uid ] ) { | 477 | while( Incidence* i = mOrphans[ r2uid ] ) { |
476 | mOrphans.remove( r2uid ); | 478 | mOrphans.remove( r2uid ); |
477 | if ( i != incidence ) tempList.append( i ); | 479 | if ( i != incidence ) tempList.append( i ); |
478 | } | 480 | } |
479 | Incidence* inc = tempList.first(); | 481 | Incidence* inc = tempList.first(); |
480 | while ( inc ) { | 482 | while ( inc ) { |
481 | mOrphans.insert( r2uid, inc ); | 483 | mOrphans.insert( r2uid, inc ); |
482 | inc = tempList.next(); | 484 | inc = tempList.next(); |
483 | } | 485 | } |
484 | } | 486 | } |
485 | // LR: and another big bad bug found | 487 | // LR: and another big bad bug found |
486 | #if 0 | 488 | #if 0 |
487 | // This incidence is located in the orphans list - it should be removed | 489 | // This incidence is located in the orphans list - it should be removed |
488 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 490 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
489 | // Removing wasn't that easy | 491 | // Removing wasn't that easy |
490 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 492 | for( Q3DictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
491 | if( it.current()->uid() == uid ) { | 493 | if( it.current()->uid() == uid ) { |
492 | mOrphans.remove( it.currentKey() ); | 494 | mOrphans.remove( it.currentKey() ); |
493 | break; | 495 | break; |
494 | } | 496 | } |
495 | } | 497 | } |
496 | } | 498 | } |
497 | #endif | 499 | #endif |
498 | } | 500 | } |
499 | 501 | ||
500 | void Calendar::registerObserver( Observer *observer ) | 502 | void Calendar::registerObserver( Observer *observer ) |
501 | { | 503 | { |
502 | mObserver = observer; | 504 | mObserver = observer; |
503 | mNewObserver = true; | 505 | mNewObserver = true; |
504 | } | 506 | } |
505 | 507 | ||
506 | void Calendar::setModified( bool modified ) | 508 | void Calendar::setModified( bool modified ) |
507 | { | 509 | { |
508 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 510 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
509 | if ( modified != mModified || mNewObserver ) { | 511 | if ( modified != mModified || mNewObserver ) { |
510 | mNewObserver = false; | 512 | mNewObserver = false; |
511 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 513 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
512 | mModified = modified; | 514 | mModified = modified; |
513 | } | 515 | } |
514 | } | 516 | } |
515 | 517 | ||
516 | void Calendar::setLoadedProductId( const QString &id ) | 518 | void Calendar::setLoadedProductId( const QString &id ) |
517 | { | 519 | { |
518 | mLoadedProductId = id; | 520 | mLoadedProductId = id; |
519 | } | 521 | } |
520 | 522 | ||
521 | QString Calendar::loadedProductId() | 523 | QString Calendar::loadedProductId() |
522 | { | 524 | { |
523 | return mLoadedProductId; | 525 | return mLoadedProductId; |
524 | } | 526 | } |
525 | 527 | ||
526 | //#include "calendar.moc" | 528 | //#include "calendar.moc" |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index fbc40ad..5845f44 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,385 +1,385 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <q3ptrlist.h> |
29 | #include <qdict.h> | 29 | #include <q3dict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | Incidence * undoIncidence() { return mUndoIncidence; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | 77 | virtual void addCalendar( Calendar* ) = 0; |
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | 78 | virtual bool addCalendarFile( QString name, int id ) = 0; |
79 | virtual bool mergeCalendarFile( QString name ) = 0; | 79 | virtual bool mergeCalendarFile( QString name ) = 0; |
80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ,int * isDup = 0 ) = 0; | 80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ,int * isDup = 0 ) = 0; |
81 | virtual Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0) = 0; | 81 | virtual Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0) = 0; |
82 | virtual void setSyncEventsReadOnly() = 0; | 82 | virtual void setSyncEventsReadOnly() = 0; |
83 | virtual void setSyncEventsEnabled() = 0; | 83 | virtual void setSyncEventsEnabled() = 0; |
84 | virtual void stopAllTodos() = 0; | 84 | virtual void stopAllTodos() = 0; |
85 | virtual void clearUndo( Incidence * newUndo ); | 85 | virtual void clearUndo( Incidence * newUndo ); |
86 | 86 | ||
87 | /** | 87 | /** |
88 | Sync changes in memory to persistant storage. | 88 | Sync changes in memory to persistant storage. |
89 | */ | 89 | */ |
90 | virtual void save() = 0; | 90 | virtual void save() = 0; |
91 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 91 | virtual Q3PtrList<Event> getExternLastSyncEvents() = 0; |
92 | virtual void removeSyncInfo( QString syncProfile) = 0; | 92 | virtual void removeSyncInfo( QString syncProfile) = 0; |
93 | virtual bool isSaving() { return false; } | 93 | virtual bool isSaving() { return false; } |
94 | 94 | ||
95 | /** | 95 | /** |
96 | Return the owner of the calendar's full name. | 96 | Return the owner of the calendar's full name. |
97 | */ | 97 | */ |
98 | const QString &getOwner() const; | 98 | const QString &getOwner() const; |
99 | /** | 99 | /** |
100 | Set the owner of the calendar. Should be owner's full name. | 100 | Set the owner of the calendar. Should be owner's full name. |
101 | */ | 101 | */ |
102 | void setOwner( const QString &os ); | 102 | void setOwner( const QString &os ); |
103 | /** | 103 | /** |
104 | Return the email address of the calendar owner. | 104 | Return the email address of the calendar owner. |
105 | */ | 105 | */ |
106 | const QString &getEmail(); | 106 | const QString &getEmail(); |
107 | /** | 107 | /** |
108 | Set the email address of the calendar owner. | 108 | Set the email address of the calendar owner. |
109 | */ | 109 | */ |
110 | void setEmail( const QString & ); | 110 | void setEmail( const QString & ); |
111 | 111 | ||
112 | /** | 112 | /** |
113 | Set time zone from a timezone string (e.g. -2:00) | 113 | Set time zone from a timezone string (e.g. -2:00) |
114 | */ | 114 | */ |
115 | void setTimeZone( const QString &tz ); | 115 | void setTimeZone( const QString &tz ); |
116 | /** | 116 | /** |
117 | Set time zone from a minutes value (e.g. -60) | 117 | Set time zone from a minutes value (e.g. -60) |
118 | */ | 118 | */ |
119 | void setTimeZone( int tz ); | 119 | void setTimeZone( int tz ); |
120 | /** | 120 | /** |
121 | Return time zone as offest in minutes. | 121 | Return time zone as offest in minutes. |
122 | */ | 122 | */ |
123 | int getTimeZone() const; | 123 | int getTimeZone() const; |
124 | /** | 124 | /** |
125 | Compute an ISO 8601 format string from the time zone. | 125 | Compute an ISO 8601 format string from the time zone. |
126 | */ | 126 | */ |
127 | QString getTimeZoneStr() const; | 127 | QString getTimeZoneStr() const; |
128 | /** | 128 | /** |
129 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 129 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
130 | values). | 130 | values). |
131 | */ | 131 | */ |
132 | void setTimeZoneId( const QString & ); | 132 | void setTimeZoneId( const QString & ); |
133 | /** | 133 | /** |
134 | Return time zone id. | 134 | Return time zone id. |
135 | */ | 135 | */ |
136 | QString timeZoneId() const; | 136 | QString timeZoneId() const; |
137 | /** | 137 | /** |
138 | Use local time, not UTC or a time zone. | 138 | Use local time, not UTC or a time zone. |
139 | */ | 139 | */ |
140 | void setLocalTime(); | 140 | void setLocalTime(); |
141 | /** | 141 | /** |
142 | Return whether local time is being used. | 142 | Return whether local time is being used. |
143 | */ | 143 | */ |
144 | bool isLocalTime() const; | 144 | bool isLocalTime() const; |
145 | 145 | ||
146 | /** | 146 | /** |
147 | Add an incidence to calendar. | 147 | Add an incidence to calendar. |
148 | 148 | ||
149 | @return true on success, false on error. | 149 | @return true on success, false on error. |
150 | */ | 150 | */ |
151 | virtual bool addIncidence( Incidence * ); | 151 | virtual bool addIncidence( Incidence * ); |
152 | 152 | ||
153 | // Adds an incidence and all relatedto incidences to the cal | 153 | // Adds an incidence and all relatedto incidences to the cal |
154 | void addIncidenceBranch( Incidence * ); | 154 | void addIncidenceBranch( Incidence * ); |
155 | /** | 155 | /** |
156 | Return filtered list of all incidences of this calendar. | 156 | Return filtered list of all incidences of this calendar. |
157 | */ | 157 | */ |
158 | virtual QPtrList<Incidence> incidences(); | 158 | virtual Q3PtrList<Incidence> incidences(); |
159 | 159 | ||
160 | /** | 160 | /** |
161 | Return unfiltered list of all incidences of this calendar. | 161 | Return unfiltered list of all incidences of this calendar. |
162 | */ | 162 | */ |
163 | virtual QPtrList<Incidence> rawIncidences(); | 163 | virtual Q3PtrList<Incidence> rawIncidences(); |
164 | 164 | ||
165 | /** | 165 | /** |
166 | Adds a Event to this calendar object. | 166 | Adds a Event to this calendar object. |
167 | @param anEvent a pointer to the event to add | 167 | @param anEvent a pointer to the event to add |
168 | 168 | ||
169 | @return true on success, false on error. | 169 | @return true on success, false on error. |
170 | */ | 170 | */ |
171 | virtual bool addEventNoDup( Event *event ) = 0; | 171 | virtual bool addEventNoDup( Event *event ) = 0; |
172 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 172 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
173 | virtual bool addEvent( Event *anEvent ) = 0; | 173 | virtual bool addEvent( Event *anEvent ) = 0; |
174 | /** | 174 | /** |
175 | Delete event from calendar. | 175 | Delete event from calendar. |
176 | */ | 176 | */ |
177 | virtual void deleteEvent( Event * ) = 0; | 177 | virtual void deleteEvent( Event * ) = 0; |
178 | /** | 178 | /** |
179 | Retrieves an event on the basis of the unique string ID. | 179 | Retrieves an event on the basis of the unique string ID. |
180 | */ | 180 | */ |
181 | virtual Event *event( const QString &UniqueStr ) = 0; | 181 | virtual Event *event( const QString &UniqueStr ) = 0; |
182 | virtual Event *event( QString, QString ) = 0; | 182 | virtual Event *event( QString, QString ) = 0; |
183 | /** | 183 | /** |
184 | Builds and then returns a list of all events that match for the | 184 | Builds and then returns a list of all events that match for the |
185 | date specified. useful for dayView, etc. etc. | 185 | date specified. useful for dayView, etc. etc. |
186 | The calendar filter is applied. | 186 | The calendar filter is applied. |
187 | */ | 187 | */ |
188 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 188 | Q3PtrList<Event> events( const QDate &date, bool sorted = false); |
189 | /** | 189 | /** |
190 | Get events, which occur on the given date. | 190 | Get events, which occur on the given date. |
191 | The calendar filter is applied. | 191 | The calendar filter is applied. |
192 | */ | 192 | */ |
193 | QPtrList<Event> events( const QDateTime &qdt ); | 193 | Q3PtrList<Event> events( const QDateTime &qdt ); |
194 | /** | 194 | /** |
195 | Get events in a range of dates. If inclusive is set to true, only events | 195 | Get events in a range of dates. If inclusive is set to true, only events |
196 | are returned, which are completely included in the range. | 196 | are returned, which are completely included in the range. |
197 | The calendar filter is applied. | 197 | The calendar filter is applied. |
198 | */ | 198 | */ |
199 | QPtrList<Event> events( const QDate &start, const QDate &end, | 199 | Q3PtrList<Event> events( const QDate &start, const QDate &end, |
200 | bool inclusive = false); | 200 | bool inclusive = false); |
201 | /** | 201 | /** |
202 | Return filtered list of all events in calendar. | 202 | Return filtered list of all events in calendar. |
203 | */ | 203 | */ |
204 | virtual QPtrList<Event> events(); | 204 | virtual Q3PtrList<Event> events(); |
205 | /** | 205 | /** |
206 | Return unfiltered list of all events in calendar. | 206 | Return unfiltered list of all events in calendar. |
207 | */ | 207 | */ |
208 | virtual QPtrList<Event> rawEvents() = 0; | 208 | virtual Q3PtrList<Event> rawEvents() = 0; |
209 | 209 | ||
210 | /** | 210 | /** |
211 | Add a todo to the todolist. | 211 | Add a todo to the todolist. |
212 | 212 | ||
213 | @return true on success, false on error. | 213 | @return true on success, false on error. |
214 | */ | 214 | */ |
215 | virtual bool addTodo( Todo *todo ) = 0; | 215 | virtual bool addTodo( Todo *todo ) = 0; |
216 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 216 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
217 | /** | 217 | /** |
218 | Remove a todo from the todolist. | 218 | Remove a todo from the todolist. |
219 | */ | 219 | */ |
220 | virtual void deleteTodo( Todo * ) = 0; | 220 | virtual void deleteTodo( Todo * ) = 0; |
221 | virtual void deleteJournal( Journal * ) = 0; | 221 | virtual void deleteJournal( Journal * ) = 0; |
222 | /** | 222 | /** |
223 | Return filterd list of todos. | 223 | Return filterd list of todos. |
224 | */ | 224 | */ |
225 | virtual QPtrList<Todo> todos(); | 225 | virtual Q3PtrList<Todo> todos(); |
226 | /** | 226 | /** |
227 | Searches todolist for an event with this unique string identifier, | 227 | Searches todolist for an event with this unique string identifier, |
228 | returns a pointer or null. | 228 | returns a pointer or null. |
229 | */ | 229 | */ |
230 | virtual Todo *todo( const QString &uid ) = 0; | 230 | virtual Todo *todo( const QString &uid ) = 0; |
231 | virtual Todo *todo( QString, QString ) = 0; | 231 | virtual Todo *todo( QString, QString ) = 0; |
232 | /** | 232 | /** |
233 | Returns list of todos due on the specified date. | 233 | Returns list of todos due on the specified date. |
234 | */ | 234 | */ |
235 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 235 | virtual Q3PtrList<Todo> todos( const QDate &date ) = 0; |
236 | /** | 236 | /** |
237 | Return unfiltered list of todos. | 237 | Return unfiltered list of todos. |
238 | */ | 238 | */ |
239 | virtual QPtrList<Todo> rawTodos() = 0; | 239 | virtual Q3PtrList<Todo> rawTodos() = 0; |
240 | 240 | ||
241 | /** | 241 | /** |
242 | Add a Journal entry to calendar. | 242 | Add a Journal entry to calendar. |
243 | 243 | ||
244 | @return true on success, false on error. | 244 | @return true on success, false on error. |
245 | */ | 245 | */ |
246 | virtual bool addJournal( Journal * ) = 0; | 246 | virtual bool addJournal( Journal * ) = 0; |
247 | /** | 247 | /** |
248 | Return Journal for given date. | 248 | Return Journal for given date. |
249 | */ | 249 | */ |
250 | virtual Journal *journal( const QDate & ) = 0; | 250 | virtual Journal *journal( const QDate & ) = 0; |
251 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; | 251 | virtual Q3PtrList<Journal> journals4Date( const QDate & ) = 0; |
252 | /** | 252 | /** |
253 | Return Journal with given UID. | 253 | Return Journal with given UID. |
254 | */ | 254 | */ |
255 | virtual Journal *journal( const QString &UID ) = 0; | 255 | virtual Journal *journal( const QString &UID ) = 0; |
256 | /** | 256 | /** |
257 | Return list of all Journal entries. | 257 | Return list of all Journal entries. |
258 | */ | 258 | */ |
259 | virtual QPtrList<Journal> journals() = 0; | 259 | virtual Q3PtrList<Journal> journals() = 0; |
260 | 260 | ||
261 | /** | 261 | /** |
262 | Searches all incidence types for an incidence with this unique | 262 | Searches all incidence types for an incidence with this unique |
263 | string identifier, returns a pointer or null. | 263 | string identifier, returns a pointer or null. |
264 | */ | 264 | */ |
265 | Incidence* incidence( const QString&UID ); | 265 | Incidence* incidence( const QString&UID ); |
266 | 266 | ||
267 | /** | 267 | /** |
268 | Setup relations for an incidence. | 268 | Setup relations for an incidence. |
269 | */ | 269 | */ |
270 | virtual void setupRelations( Incidence * ); | 270 | virtual void setupRelations( Incidence * ); |
271 | /** | 271 | /** |
272 | Remove all relations to an incidence | 272 | Remove all relations to an incidence |
273 | */ | 273 | */ |
274 | virtual void removeRelations( Incidence * ); | 274 | virtual void removeRelations( Incidence * ); |
275 | 275 | ||
276 | /** | 276 | /** |
277 | Set calendar filter, which filters events for the events() functions. | 277 | Set calendar filter, which filters events for the events() functions. |
278 | The Filter object is owned by the caller. | 278 | The Filter object is owned by the caller. |
279 | */ | 279 | */ |
280 | void setFilter( CalFilter * ); | 280 | void setFilter( CalFilter * ); |
281 | /** | 281 | /** |
282 | Return calendar filter. | 282 | Return calendar filter. |
283 | */ | 283 | */ |
284 | CalFilter *filter(); | 284 | CalFilter *filter(); |
285 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 285 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
286 | virtual QString nextSummary( ) const = 0; | 286 | virtual QString nextSummary( ) const = 0; |
287 | virtual void reInitAlarmSettings() = 0; | 287 | virtual void reInitAlarmSettings() = 0; |
288 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 288 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
289 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 289 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
290 | /** | 290 | /** |
291 | Return all alarms, which ocur in the given time interval. | 291 | Return all alarms, which ocur in the given time interval. |
292 | */ | 292 | */ |
293 | virtual Alarm::List alarms( const QDateTime &from, | 293 | virtual Alarm::List alarms( const QDateTime &from, |
294 | const QDateTime &to ) = 0; | 294 | const QDateTime &to ) = 0; |
295 | 295 | ||
296 | class Observer { | 296 | class Observer { |
297 | public: | 297 | public: |
298 | virtual void calendarModified( bool, Calendar * ) = 0; | 298 | virtual void calendarModified( bool, Calendar * ) = 0; |
299 | }; | 299 | }; |
300 | 300 | ||
301 | void registerObserver( Observer * ); | 301 | void registerObserver( Observer * ); |
302 | 302 | ||
303 | void setModified( bool ); | 303 | void setModified( bool ); |
304 | 304 | ||
305 | /** | 305 | /** |
306 | Set product id returned by loadedProductId(). This function is only | 306 | Set product id returned by loadedProductId(). This function is only |
307 | useful for the calendar loading code. | 307 | useful for the calendar loading code. |
308 | */ | 308 | */ |
309 | void setLoadedProductId( const QString & ); | 309 | void setLoadedProductId( const QString & ); |
310 | /** | 310 | /** |
311 | Return product id taken from file that has been loaded. Returns | 311 | Return product id taken from file that has been loaded. Returns |
312 | QString::null, if no calendar has been loaded. | 312 | QString::null, if no calendar has been loaded. |
313 | */ | 313 | */ |
314 | QString loadedProductId(); | 314 | QString loadedProductId(); |
315 | int defaultCalendar(); | 315 | int defaultCalendar(); |
316 | void setDontDeleteIncidencesOnClose (); | 316 | void setDontDeleteIncidencesOnClose (); |
317 | public slots: | 317 | public slots: |
318 | void setDefaultCalendar( int ); | 318 | void setDefaultCalendar( int ); |
319 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 319 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
320 | virtual void setAllCalendarEnabled( bool enable ) = 0; | 320 | virtual void setAllCalendarEnabled( bool enable ) = 0; |
321 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 321 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
322 | virtual void setReadOnly( int id, bool enable ) = 0; | 322 | virtual void setReadOnly( int id, bool enable ) = 0; |
323 | virtual void setDefaultCalendarEnabledOnly() = 0; | 323 | virtual void setDefaultCalendarEnabledOnly() = 0; |
324 | virtual void setCalendarRemove( int id ) = 0; | 324 | virtual void setCalendarRemove( int id ) = 0; |
325 | virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0; | 325 | virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0; |
326 | 326 | ||
327 | signals: | 327 | signals: |
328 | void calendarChanged(); | 328 | void calendarChanged(); |
329 | void calendarSaved(); | 329 | void calendarSaved(); |
330 | void calendarLoaded(); | 330 | void calendarLoaded(); |
331 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 331 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
332 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 332 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
333 | 333 | ||
334 | protected: | 334 | protected: |
335 | /** | 335 | /** |
336 | Get unfiltered events, which occur on the given date. | 336 | Get unfiltered events, which occur on the given date. |
337 | */ | 337 | */ |
338 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 338 | virtual Q3PtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
339 | /** | 339 | /** |
340 | Get unfiltered events, which occur on the given date. | 340 | Get unfiltered events, which occur on the given date. |
341 | */ | 341 | */ |
342 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 342 | virtual Q3PtrList<Event> rawEventsForDate( const QDate &date, |
343 | bool sorted = false ) = 0; | 343 | bool sorted = false ) = 0; |
344 | /** | 344 | /** |
345 | Get events in a range of dates. If inclusive is set to true, only events | 345 | Get events in a range of dates. If inclusive is set to true, only events |
346 | are returned, which are completely included in the range. | 346 | are returned, which are completely included in the range. |
347 | */ | 347 | */ |
348 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 348 | virtual Q3PtrList<Event> rawEvents( const QDate &start, const QDate &end, |
349 | bool inclusive = false ) = 0; | 349 | bool inclusive = false ) = 0; |
350 | 350 | ||
351 | Incidence *mNextAlarmIncidence; | 351 | Incidence *mNextAlarmIncidence; |
352 | Incidence *mUndoIncidence; | 352 | Incidence *mUndoIncidence; |
353 | int mDefaultCalendar; | 353 | int mDefaultCalendar; |
354 | bool mDeleteIncidencesOnClose; | 354 | bool mDeleteIncidencesOnClose; |
355 | 355 | ||
356 | private: | 356 | private: |
357 | void init(); | 357 | void init(); |
358 | 358 | ||
359 | QString mOwner; // who the calendar belongs to | 359 | QString mOwner; // who the calendar belongs to |
360 | QString mOwnerEmail; // email address of the owner | 360 | QString mOwnerEmail; // email address of the owner |
361 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 361 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
362 | bool mLocalTime; // use local time, not UTC or a time zone | 362 | bool mLocalTime; // use local time, not UTC or a time zone |
363 | 363 | ||
364 | 364 | ||
365 | CalFilter *mFilter; | 365 | CalFilter *mFilter; |
366 | CalFilter *mDefaultFilter; | 366 | CalFilter *mDefaultFilter; |
367 | 367 | ||
368 | 368 | ||
369 | QString mTimeZoneId; | 369 | QString mTimeZoneId; |
370 | 370 | ||
371 | Observer *mObserver; | 371 | Observer *mObserver; |
372 | bool mNewObserver; | 372 | bool mNewObserver; |
373 | 373 | ||
374 | bool mModified; | 374 | bool mModified; |
375 | 375 | ||
376 | QString mLoadedProductId; | 376 | QString mLoadedProductId; |
377 | 377 | ||
378 | // This list is used to put together related todos | 378 | // This list is used to put together related todos |
379 | QDict<Incidence> mOrphans; | 379 | Q3Dict<Incidence> mOrphans; |
380 | QDict<Incidence> mOrphanUids; | 380 | Q3Dict<Incidence> mOrphanUids; |
381 | }; | 381 | }; |
382 | 382 | ||
383 | } | 383 | } |
384 | 384 | ||
385 | #endif | 385 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index ce3cd09..cb52b7c 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,1149 +1,1149 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <q3ptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | registerObserver( 0 ); | 68 | registerObserver( 0 ); |
69 | if ( mDeleteIncidencesOnClose ) | 69 | if ( mDeleteIncidencesOnClose ) |
70 | close(); | 70 | close(); |
71 | } | 71 | } |
72 | bool CalendarLocal::mergeCalendarFile( QString name ) | 72 | bool CalendarLocal::mergeCalendarFile( QString name ) |
73 | { | 73 | { |
74 | CalendarLocal calendar( timeZoneId() ); | 74 | CalendarLocal calendar( timeZoneId() ); |
75 | calendar.setDefaultCalendar( 1 ); | 75 | calendar.setDefaultCalendar( 1 ); |
76 | if ( calendar.load( name ) ) { | 76 | if ( calendar.load( name ) ) { |
77 | mergeCalendar( &calendar ); | 77 | mergeCalendar( &calendar ); |
78 | return true; | 78 | return true; |
79 | } | 79 | } |
80 | return false; | 80 | return false; |
81 | } | 81 | } |
82 | 82 | ||
83 | Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup ) | 83 | Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup ) |
84 | { | 84 | { |
85 | 85 | ||
86 | int calID = 0; | 86 | int calID = 0; |
87 | if ( isDup && *isDup > 0 ) | 87 | if ( isDup && *isDup > 0 ) |
88 | calID = *isDup; | 88 | calID = *isDup; |
89 | Todo *todo;; | 89 | Todo *todo;; |
90 | Todo *retVal = 0; | 90 | Todo *retVal = 0; |
91 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 91 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
92 | if ( todo->uid() == uid ) { | 92 | if ( todo->uid() == uid ) { |
93 | if( calID ) { | 93 | if( calID ) { |
94 | if ( todo->calID() != calID ) | 94 | if ( todo->calID() != calID ) |
95 | continue; | 95 | continue; |
96 | } | 96 | } |
97 | else { | 97 | else { |
98 | if ( enabledOnly ) { | 98 | if ( enabledOnly ) { |
99 | if ( !todo->calEnabled() ) { | 99 | if ( !todo->calEnabled() ) { |
100 | if ( isDup ) | 100 | if ( isDup ) |
101 | *isDup = todo->calID(); | 101 | *isDup = todo->calID(); |
102 | continue; | 102 | continue; |
103 | } | 103 | } |
104 | } | 104 | } |
105 | } | 105 | } |
106 | if ( doNotCheckDuplicates ) return todo; | 106 | if ( doNotCheckDuplicates ) return todo; |
107 | if ( retVal ) { | 107 | if ( retVal ) { |
108 | if ( retVal->calID() > todo->calID() ) { | 108 | if ( retVal->calID() > todo->calID() ) { |
109 | if ( isDup ) | 109 | if ( isDup ) |
110 | *isDup = retVal->calID(); | 110 | *isDup = retVal->calID(); |
111 | retVal = todo; | 111 | retVal = todo; |
112 | } | 112 | } |
113 | } else { | 113 | } else { |
114 | retVal = todo; | 114 | retVal = todo; |
115 | } | 115 | } |
116 | } | 116 | } |
117 | } | 117 | } |
118 | return retVal; | 118 | return retVal; |
119 | } | 119 | } |
120 | //if ( isDup) and * isDup == 0: store duplicate found cal id in isDup | 120 | //if ( isDup) and * isDup == 0: store duplicate found cal id in isDup |
121 | //if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly | 121 | //if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly |
122 | 122 | ||
123 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup ) | 123 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup ) |
124 | { | 124 | { |
125 | int calID = 0; | 125 | int calID = 0; |
126 | if ( isDup && *isDup > 0 ) | 126 | if ( isDup && *isDup > 0 ) |
127 | calID = *isDup; | 127 | calID = *isDup; |
128 | Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup ); | 128 | Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup ); |
129 | if ( retVal ) return retVal; | 129 | if ( retVal ) return retVal; |
130 | Event *event; | 130 | Event *event; |
131 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 131 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
132 | if ( event->uid() == uid ) { | 132 | if ( event->uid() == uid ) { |
133 | if( calID ) { | 133 | if( calID ) { |
134 | if ( event->calID() != calID ) | 134 | if ( event->calID() != calID ) |
135 | continue; | 135 | continue; |
136 | } | 136 | } |
137 | else { | 137 | else { |
138 | if ( enabledOnly ) { | 138 | if ( enabledOnly ) { |
139 | if ( !event->calEnabled() ) { | 139 | if ( !event->calEnabled() ) { |
140 | if ( isDup ) | 140 | if ( isDup ) |
141 | *isDup =event->calID() ; | 141 | *isDup =event->calID() ; |
142 | continue; | 142 | continue; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | } | 145 | } |
146 | if ( doNotCheckDuplicates ) return event; | 146 | if ( doNotCheckDuplicates ) return event; |
147 | if ( retVal ) { | 147 | if ( retVal ) { |
148 | if ( retVal->calID() > event->calID() ) { | 148 | if ( retVal->calID() > event->calID() ) { |
149 | if ( isDup ) | 149 | if ( isDup ) |
150 | *isDup = retVal->calID(); | 150 | *isDup = retVal->calID(); |
151 | retVal = event; | 151 | retVal = event; |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | retVal = event; | 154 | retVal = event; |
155 | } | 155 | } |
156 | } | 156 | } |
157 | } | 157 | } |
158 | if ( retVal ) return retVal; | 158 | if ( retVal ) return retVal; |
159 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 159 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
160 | if ( it->uid() == uid ) { | 160 | if ( it->uid() == uid ) { |
161 | if( calID ) { | 161 | if( calID ) { |
162 | if ( event->calID() != calID ) | 162 | if ( event->calID() != calID ) |
163 | continue; | 163 | continue; |
164 | } | 164 | } |
165 | else { | 165 | else { |
166 | if ( enabledOnly ) { | 166 | if ( enabledOnly ) { |
167 | if ( !it->calEnabled() ) { | 167 | if ( !it->calEnabled() ) { |
168 | if ( isDup ) | 168 | if ( isDup ) |
169 | *isDup = it->calID(); | 169 | *isDup = it->calID(); |
170 | continue; | 170 | continue; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | } | 173 | } |
174 | if ( doNotCheckDuplicates ) return it; | 174 | if ( doNotCheckDuplicates ) return it; |
175 | if ( retVal ) { | 175 | if ( retVal ) { |
176 | if ( retVal->calID() > it->calID() ) { | 176 | if ( retVal->calID() > it->calID() ) { |
177 | if ( isDup ) | 177 | if ( isDup ) |
178 | *isDup = retVal->calID(); | 178 | *isDup = retVal->calID(); |
179 | retVal = it; | 179 | retVal = it; |
180 | } | 180 | } |
181 | } else { | 181 | } else { |
182 | retVal = it; | 182 | retVal = it; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return retVal; | 185 | return retVal; |
186 | } | 186 | } |
187 | 187 | ||
188 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 188 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
189 | { | 189 | { |
190 | // 1 look for raw inc in local | 190 | // 1 look for raw inc in local |
191 | // if inc not in remote, delete in local | 191 | // if inc not in remote, delete in local |
192 | // 2 look for raw inc in remote | 192 | // 2 look for raw inc in remote |
193 | // if inc in local, replace it | 193 | // if inc in local, replace it |
194 | // if not in local, add it to default calendar | 194 | // if not in local, add it to default calendar |
195 | QPtrList<Incidence> localInc = rawIncidences(); | 195 | Q3PtrList<Incidence> localInc = rawIncidences(); |
196 | Incidence* inL = localInc.first(); | 196 | Incidence* inL = localInc.first(); |
197 | while ( inL ) { | 197 | while ( inL ) { |
198 | if ( ! inL->isReadOnly () ) | 198 | if ( ! inL->isReadOnly () ) |
199 | if ( !remote->incidenceForUid( inL->uid(), true )) | 199 | if ( !remote->incidenceForUid( inL->uid(), true )) |
200 | deleteIncidence( inL ); | 200 | deleteIncidence( inL ); |
201 | inL = localInc.next(); | 201 | inL = localInc.next(); |
202 | } | 202 | } |
203 | QPtrList<Incidence> er = remote->rawIncidences(); | 203 | Q3PtrList<Incidence> er = remote->rawIncidences(); |
204 | Incidence* inR = er.first(); | 204 | Incidence* inR = er.first(); |
205 | while ( inR ) { | 205 | while ( inR ) { |
206 | inL = incidenceForUid( inR->uid(),false ); | 206 | inL = incidenceForUid( inR->uid(),false ); |
207 | if ( inL ) { | 207 | if ( inL ) { |
208 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 208 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
209 | int calID = inL->calID(); | 209 | int calID = inL->calID(); |
210 | deleteIncidence( inL ); | 210 | deleteIncidence( inL ); |
211 | inL = inR->clone(); | 211 | inL = inR->clone(); |
212 | inL->setCalID_block( calID ); | 212 | inL->setCalID_block( calID ); |
213 | addIncidence( inL ); | 213 | addIncidence( inL ); |
214 | } | 214 | } |
215 | } else { | 215 | } else { |
216 | inL = inR->clone(); | 216 | inL = inR->clone(); |
217 | inL->setCalID_block( 0 );// add to default cal | 217 | inL->setCalID_block( 0 );// add to default cal |
218 | addIncidence( inL ); | 218 | addIncidence( inL ); |
219 | } | 219 | } |
220 | inR = er.next(); | 220 | inR = er.next(); |
221 | } | 221 | } |
222 | return true; | 222 | return true; |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 226 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
227 | { | 227 | { |
228 | CalendarLocal calendar( timeZoneId() ); | 228 | CalendarLocal calendar( timeZoneId() ); |
229 | calendar.setDefaultCalendar( id ); | 229 | calendar.setDefaultCalendar( id ); |
230 | if ( calendar.load( name ) ) { | 230 | if ( calendar.load( name ) ) { |
231 | addCalendar( &calendar ); | 231 | addCalendar( &calendar ); |
232 | return true; | 232 | return true; |
233 | } | 233 | } |
234 | return false; | 234 | return false; |
235 | } | 235 | } |
236 | void CalendarLocal::setSyncEventsEnabled() | 236 | void CalendarLocal::setSyncEventsEnabled() |
237 | { | 237 | { |
238 | Event * ev; | 238 | Event * ev; |
239 | ev = mEventList.first(); | 239 | ev = mEventList.first(); |
240 | while ( ev ) { | 240 | while ( ev ) { |
241 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 241 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
242 | ev->setCalEnabled( true ); | 242 | ev->setCalEnabled( true ); |
243 | ev = mEventList.next(); | 243 | ev = mEventList.next(); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | void CalendarLocal::setSyncEventsReadOnly() | 246 | void CalendarLocal::setSyncEventsReadOnly() |
247 | { | 247 | { |
248 | Event * ev; | 248 | Event * ev; |
249 | ev = mEventList.first(); | 249 | ev = mEventList.first(); |
250 | while ( ev ) { | 250 | while ( ev ) { |
251 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { | 251 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { |
252 | ev->setReadOnly( true ); | 252 | ev->setReadOnly( true ); |
253 | } | 253 | } |
254 | ev = mEventList.next(); | 254 | ev = mEventList.next(); |
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | void CalendarLocal::addCalendar( Calendar* cal ) | 258 | void CalendarLocal::addCalendar( Calendar* cal ) |
259 | { | 259 | { |
260 | cal->setDontDeleteIncidencesOnClose(); | 260 | cal->setDontDeleteIncidencesOnClose(); |
261 | setSyncEventsEnabled(); | 261 | setSyncEventsEnabled(); |
262 | QPtrList<Incidence> incList; | 262 | Q3PtrList<Incidence> incList; |
263 | { | 263 | { |
264 | QPtrList<Event> EventList = cal->rawEvents(); | 264 | Q3PtrList<Event> EventList = cal->rawEvents(); |
265 | Event * ev = EventList.first(); | 265 | Event * ev = EventList.first(); |
266 | while ( ev ) { | 266 | while ( ev ) { |
267 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { | 267 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { |
268 | ev->setCalID_block( 1 ); | 268 | ev->setCalID_block( 1 ); |
269 | } | 269 | } |
270 | Event * se = event( ev->uid() ); | 270 | Event * se = event( ev->uid() ); |
271 | if ( se ) | 271 | if ( se ) |
272 | incList.append( se ); | 272 | incList.append( se ); |
273 | ev->unRegisterObserver( cal ); | 273 | ev->unRegisterObserver( cal ); |
274 | ev->registerObserver( this ); | 274 | ev->registerObserver( this ); |
275 | mEventList.append( ev ); | 275 | mEventList.append( ev ); |
276 | ev = EventList.next(); | 276 | ev = EventList.next(); |
277 | } | 277 | } |
278 | 278 | ||
279 | } | 279 | } |
280 | { | 280 | { |
281 | 281 | ||
282 | QPtrList<Todo> TodoList = cal->rawTodos(); | 282 | Q3PtrList<Todo> TodoList = cal->rawTodos(); |
283 | Todo * ev = TodoList.first(); | 283 | Todo * ev = TodoList.first(); |
284 | while ( ev ) { | 284 | while ( ev ) { |
285 | ev->resetRelatedTo(); | 285 | ev->resetRelatedTo(); |
286 | Todo * se = todo( ev->uid() ); | 286 | Todo * se = todo( ev->uid() ); |
287 | if ( se ) | 287 | if ( se ) |
288 | deleteTodo( se ); | 288 | deleteTodo( se ); |
289 | ev = TodoList.next(); | 289 | ev = TodoList.next(); |
290 | } | 290 | } |
291 | //TodoList = cal->rawTodos(); | 291 | //TodoList = cal->rawTodos(); |
292 | ev = TodoList.first(); | 292 | ev = TodoList.first(); |
293 | while ( ev ) { | 293 | while ( ev ) { |
294 | ev->unRegisterObserver( cal ); | 294 | ev->unRegisterObserver( cal ); |
295 | ev->registerObserver( this ); | 295 | ev->registerObserver( this ); |
296 | mTodoList.append( ev ); | 296 | mTodoList.append( ev ); |
297 | setupRelations( ev ); | 297 | setupRelations( ev ); |
298 | ev = TodoList.next(); | 298 | ev = TodoList.next(); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | { | 301 | { |
302 | QPtrList<Journal> JournalList = cal->journals(); | 302 | Q3PtrList<Journal> JournalList = cal->journals(); |
303 | Journal * ev = JournalList.first(); | 303 | Journal * ev = JournalList.first(); |
304 | while ( ev ) { | 304 | while ( ev ) { |
305 | Journal * se = journal( ev->uid() ); | 305 | Journal * se = journal( ev->uid() ); |
306 | if ( se ) | 306 | if ( se ) |
307 | incList.append( se ); | 307 | incList.append( se ); |
308 | ev->unRegisterObserver( cal ); | 308 | ev->unRegisterObserver( cal ); |
309 | ev->registerObserver( this ); | 309 | ev->registerObserver( this ); |
310 | mJournalList.append( ev ); | 310 | mJournalList.append( ev ); |
311 | ev = JournalList.next(); | 311 | ev = JournalList.next(); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | { | 314 | { |
315 | for (Incidence * inc = incList.first(); inc; inc = incList.next() ) { | 315 | for (Incidence * inc = incList.first(); inc; inc = incList.next() ) { |
316 | deleteIncidence ( inc ); | 316 | deleteIncidence ( inc ); |
317 | } | 317 | } |
318 | } | 318 | } |
319 | setModified( true ); | 319 | setModified( true ); |
320 | } | 320 | } |
321 | bool CalendarLocal::load( const QString &fileName ) | 321 | bool CalendarLocal::load( const QString &fileName ) |
322 | { | 322 | { |
323 | FileStorage storage( this, fileName ); | 323 | FileStorage storage( this, fileName ); |
324 | return storage.load(); | 324 | return storage.load(); |
325 | } | 325 | } |
326 | 326 | ||
327 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 327 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
328 | { | 328 | { |
329 | FileStorage storage( this, fileName, format ); | 329 | FileStorage storage( this, fileName, format ); |
330 | return storage.save(); | 330 | return storage.save(); |
331 | } | 331 | } |
332 | 332 | ||
333 | void CalendarLocal::stopAllTodos() | 333 | void CalendarLocal::stopAllTodos() |
334 | { | 334 | { |
335 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 335 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
336 | it->setRunning( false ); | 336 | it->setRunning( false ); |
337 | 337 | ||
338 | } | 338 | } |
339 | void CalendarLocal::close() | 339 | void CalendarLocal::close() |
340 | { | 340 | { |
341 | 341 | ||
342 | Todo * i; | 342 | Todo * i; |
343 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 343 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
344 | 344 | ||
345 | mEventList.setAutoDelete( true ); | 345 | mEventList.setAutoDelete( true ); |
346 | mTodoList.setAutoDelete( true ); | 346 | mTodoList.setAutoDelete( true ); |
347 | mJournalList.setAutoDelete( true ); | 347 | mJournalList.setAutoDelete( true ); |
348 | 348 | ||
349 | mEventList.clear(); | 349 | mEventList.clear(); |
350 | mTodoList.clear(); | 350 | mTodoList.clear(); |
351 | mJournalList.clear(); | 351 | mJournalList.clear(); |
352 | 352 | ||
353 | mEventList.setAutoDelete( false ); | 353 | mEventList.setAutoDelete( false ); |
354 | mTodoList.setAutoDelete( false ); | 354 | mTodoList.setAutoDelete( false ); |
355 | mJournalList.setAutoDelete( false ); | 355 | mJournalList.setAutoDelete( false ); |
356 | 356 | ||
357 | setModified( false ); | 357 | setModified( false ); |
358 | } | 358 | } |
359 | 359 | ||
360 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 360 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
361 | { | 361 | { |
362 | QString cat; | 362 | QString cat; |
363 | bool isBirthday = true; | 363 | bool isBirthday = true; |
364 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 364 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
365 | isBirthday = false; | 365 | isBirthday = false; |
366 | cat = i18n( "Anniversary" ); | 366 | cat = i18n( "Anniversary" ); |
367 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 367 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
368 | isBirthday = true; | 368 | isBirthday = true; |
369 | cat = i18n( "Birthday" ); | 369 | cat = i18n( "Birthday" ); |
370 | } else { | 370 | } else { |
371 | qDebug("addAnniversaryNoDup called without fitting category! "); | 371 | qDebug("addAnniversaryNoDup called without fitting category! "); |
372 | return false; | 372 | return false; |
373 | } | 373 | } |
374 | Event * eve; | 374 | Event * eve; |
375 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 375 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
376 | if ( !(eve->categories().contains( cat ) )) | 376 | if ( !(eve->categories().contains( cat ) )) |
377 | continue; | 377 | continue; |
378 | // now we have an event with fitting category | 378 | // now we have an event with fitting category |
379 | if ( eve->dtStart().date() != event->dtStart().date() ) | 379 | if ( eve->dtStart().date() != event->dtStart().date() ) |
380 | continue; | 380 | continue; |
381 | // now we have an event with fitting category+date | 381 | // now we have an event with fitting category+date |
382 | if ( eve->summary() != event->summary() ) | 382 | if ( eve->summary() != event->summary() ) |
383 | continue; | 383 | continue; |
384 | // now we have an event with fitting category+date+summary | 384 | // now we have an event with fitting category+date+summary |
385 | return false; | 385 | return false; |
386 | } | 386 | } |
387 | return addEvent( event ); | 387 | return addEvent( event ); |
388 | 388 | ||
389 | } | 389 | } |
390 | bool CalendarLocal::addEventNoDup( Event *event ) | 390 | bool CalendarLocal::addEventNoDup( Event *event ) |
391 | { | 391 | { |
392 | Event * eve; | 392 | Event * eve; |
393 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 393 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
394 | if ( *eve == *event ) { | 394 | if ( *eve == *event ) { |
395 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 395 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
396 | return false; | 396 | return false; |
397 | } | 397 | } |
398 | } | 398 | } |
399 | return addEvent( event ); | 399 | return addEvent( event ); |
400 | } | 400 | } |
401 | 401 | ||
402 | bool CalendarLocal::addEvent( Event *event ) | 402 | bool CalendarLocal::addEvent( Event *event ) |
403 | { | 403 | { |
404 | insertEvent( event ); | 404 | insertEvent( event ); |
405 | 405 | ||
406 | event->registerObserver( this ); | 406 | event->registerObserver( this ); |
407 | 407 | ||
408 | setModified( true ); | 408 | setModified( true ); |
409 | if ( event->calID() == 0 ) | 409 | if ( event->calID() == 0 ) |
410 | event->setCalID_block( mDefaultCalendar ); | 410 | event->setCalID_block( mDefaultCalendar ); |
411 | event->setCalEnabled( true ); | 411 | event->setCalEnabled( true ); |
412 | 412 | ||
413 | return true; | 413 | return true; |
414 | } | 414 | } |
415 | 415 | ||
416 | void CalendarLocal::deleteEvent( Event *event ) | 416 | void CalendarLocal::deleteEvent( Event *event ) |
417 | { | 417 | { |
418 | clearUndo(event); | 418 | clearUndo(event); |
419 | if ( mEventList.removeRef( event ) ) { | 419 | if ( mEventList.removeRef( event ) ) { |
420 | setModified( true ); | 420 | setModified( true ); |
421 | } | 421 | } |
422 | } | 422 | } |
423 | 423 | ||
424 | 424 | ||
425 | Event *CalendarLocal::event( const QString &uid ) | 425 | Event *CalendarLocal::event( const QString &uid ) |
426 | { | 426 | { |
427 | Event *event; | 427 | Event *event; |
428 | Event *retVal = 0; | 428 | Event *retVal = 0; |
429 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 429 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
430 | if ( event->calEnabled() && event->uid() == uid ) { | 430 | if ( event->calEnabled() && event->uid() == uid ) { |
431 | if ( retVal ) { | 431 | if ( retVal ) { |
432 | if ( retVal->calID() > event->calID() ) { | 432 | if ( retVal->calID() > event->calID() ) { |
433 | retVal = event; | 433 | retVal = event; |
434 | } | 434 | } |
435 | } else { | 435 | } else { |
436 | retVal = event; | 436 | retVal = event; |
437 | } | 437 | } |
438 | } | 438 | } |
439 | } | 439 | } |
440 | return retVal; | 440 | return retVal; |
441 | } | 441 | } |
442 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 442 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
443 | { | 443 | { |
444 | Todo * eve; | 444 | Todo * eve; |
445 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 445 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
446 | if ( *eve == *todo ) { | 446 | if ( *eve == *todo ) { |
447 | //qDebug("duplicate todo found! not inserted! "); | 447 | //qDebug("duplicate todo found! not inserted! "); |
448 | return false; | 448 | return false; |
449 | } | 449 | } |
450 | } | 450 | } |
451 | return addTodo( todo ); | 451 | return addTodo( todo ); |
452 | } | 452 | } |
453 | bool CalendarLocal::addTodo( Todo *todo ) | 453 | bool CalendarLocal::addTodo( Todo *todo ) |
454 | { | 454 | { |
455 | mTodoList.append( todo ); | 455 | mTodoList.append( todo ); |
456 | 456 | ||
457 | todo->registerObserver( this ); | 457 | todo->registerObserver( this ); |
458 | 458 | ||
459 | // Set up subtask relations | 459 | // Set up subtask relations |
460 | setupRelations( todo ); | 460 | setupRelations( todo ); |
461 | 461 | ||
462 | setModified( true ); | 462 | setModified( true ); |
463 | if ( todo->calID() == 0 ) | 463 | if ( todo->calID() == 0 ) |
464 | todo->setCalID_block( mDefaultCalendar ); | 464 | todo->setCalID_block( mDefaultCalendar ); |
465 | todo->setCalEnabled( true ); | 465 | todo->setCalEnabled( true ); |
466 | return true; | 466 | return true; |
467 | } | 467 | } |
468 | 468 | ||
469 | void CalendarLocal::deleteTodo( Todo *todo ) | 469 | void CalendarLocal::deleteTodo( Todo *todo ) |
470 | { | 470 | { |
471 | QString uid = todo->uid(); | 471 | QString uid = todo->uid(); |
472 | // Handle orphaned children | 472 | // Handle orphaned children |
473 | removeRelations( todo ); | 473 | removeRelations( todo ); |
474 | clearUndo(todo); | 474 | clearUndo(todo); |
475 | 475 | ||
476 | if ( mTodoList.removeRef( todo ) ) { | 476 | if ( mTodoList.removeRef( todo ) ) { |
477 | setModified( true ); | 477 | setModified( true ); |
478 | } | 478 | } |
479 | Todo* dup = todoForUid( uid ); | 479 | Todo* dup = todoForUid( uid ); |
480 | if ( dup ) | 480 | if ( dup ) |
481 | setupRelations( dup ); | 481 | setupRelations( dup ); |
482 | } | 482 | } |
483 | 483 | ||
484 | QPtrList<Todo> CalendarLocal::rawTodos() | 484 | Q3PtrList<Todo> CalendarLocal::rawTodos() |
485 | { | 485 | { |
486 | QPtrList<Todo> el; | 486 | Q3PtrList<Todo> el; |
487 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 487 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
488 | if ( it->calEnabled() ) el.append( it ); | 488 | if ( it->calEnabled() ) el.append( it ); |
489 | return el; | 489 | return el; |
490 | } | 490 | } |
491 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 491 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
492 | { | 492 | { |
493 | Todo *todo; | 493 | Todo *todo; |
494 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 494 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
495 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 495 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
496 | } | 496 | } |
497 | 497 | ||
498 | return 0; | 498 | return 0; |
499 | } | 499 | } |
500 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 500 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
501 | { | 501 | { |
502 | QPtrList<Incidence> all = rawIncidences() ; | 502 | Q3PtrList<Incidence> all = rawIncidences() ; |
503 | Incidence *inc; | 503 | Incidence *inc; |
504 | for ( inc = all.first(); inc; inc = all.next() ) { | 504 | for ( inc = all.first(); inc; inc = all.next() ) { |
505 | inc->removeID( syncProfile ); | 505 | inc->removeID( syncProfile ); |
506 | } | 506 | } |
507 | if ( syncProfile.isEmpty() ) { | 507 | if ( syncProfile.isEmpty() ) { |
508 | QPtrList<Event> el; | 508 | Q3PtrList<Event> el; |
509 | Event *todo; | 509 | Event *todo; |
510 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 510 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
511 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 511 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
512 | el.append( todo ); | 512 | el.append( todo ); |
513 | } | 513 | } |
514 | for ( todo = el.first(); todo; todo = el.next() ) { | 514 | for ( todo = el.first(); todo; todo = el.next() ) { |
515 | deleteIncidence ( todo ); | 515 | deleteIncidence ( todo ); |
516 | } | 516 | } |
517 | } else { | 517 | } else { |
518 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 518 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
519 | if ( lse ) | 519 | if ( lse ) |
520 | deleteIncidence ( lse ); | 520 | deleteIncidence ( lse ); |
521 | } | 521 | } |
522 | } | 522 | } |
523 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 523 | Q3PtrList<Event> CalendarLocal::getExternLastSyncEvents() |
524 | { | 524 | { |
525 | QPtrList<Event> el; | 525 | Q3PtrList<Event> el; |
526 | Event *todo; | 526 | Event *todo; |
527 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 527 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
528 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 528 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
529 | if ( todo->summary().left(3) == "E: " ) | 529 | if ( todo->summary().left(3) == "E: " ) |
530 | el.append( todo ); | 530 | el.append( todo ); |
531 | } | 531 | } |
532 | 532 | ||
533 | return el; | 533 | return el; |
534 | 534 | ||
535 | } | 535 | } |
536 | Event *CalendarLocal::event( QString syncProf, QString id ) | 536 | Event *CalendarLocal::event( QString syncProf, QString id ) |
537 | { | 537 | { |
538 | Event *todo; | 538 | Event *todo; |
539 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 539 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
540 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 540 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
541 | } | 541 | } |
542 | 542 | ||
543 | return 0; | 543 | return 0; |
544 | } | 544 | } |
545 | Todo *CalendarLocal::todo( const QString &uid ) | 545 | Todo *CalendarLocal::todo( const QString &uid ) |
546 | { | 546 | { |
547 | Todo *todo; | 547 | Todo *todo; |
548 | Todo *retVal = 0; | 548 | Todo *retVal = 0; |
549 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 549 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
550 | if ( todo->calEnabled() && todo->uid() == uid ) { | 550 | if ( todo->calEnabled() && todo->uid() == uid ) { |
551 | if ( retVal ) { | 551 | if ( retVal ) { |
552 | if ( retVal->calID() > todo->calID() ) { | 552 | if ( retVal->calID() > todo->calID() ) { |
553 | retVal = todo; | 553 | retVal = todo; |
554 | } | 554 | } |
555 | } else { | 555 | } else { |
556 | retVal = todo; | 556 | retVal = todo; |
557 | } | 557 | } |
558 | } | 558 | } |
559 | } | 559 | } |
560 | return retVal; | 560 | return retVal; |
561 | } | 561 | } |
562 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) | 562 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) |
563 | { | 563 | { |
564 | events = 0; | 564 | events = 0; |
565 | todos = 0; | 565 | todos = 0; |
566 | journals = 0; | 566 | journals = 0; |
567 | { | 567 | { |
568 | Todo *todo; | 568 | Todo *todo; |
569 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 569 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
570 | if ( todo->calID() == calId ) | 570 | if ( todo->calID() == calId ) |
571 | ++todos; | 571 | ++todos; |
572 | } | 572 | } |
573 | } | 573 | } |
574 | { | 574 | { |
575 | Event *todo; | 575 | Event *todo; |
576 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 576 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
577 | if ( todo->calID() == calId ) | 577 | if ( todo->calID() == calId ) |
578 | ++events; | 578 | ++events; |
579 | 579 | ||
580 | } | 580 | } |
581 | } | 581 | } |
582 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 582 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
583 | if ( it->calID() == calId ) ++journals; | 583 | if ( it->calID() == calId ) ++journals; |
584 | 584 | ||
585 | } | 585 | } |
586 | QString CalendarLocal::nextSummary() const | 586 | QString CalendarLocal::nextSummary() const |
587 | { | 587 | { |
588 | return mNextSummary; | 588 | return mNextSummary; |
589 | } | 589 | } |
590 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 590 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
591 | { | 591 | { |
592 | return mNextAlarmEventDateTime; | 592 | return mNextAlarmEventDateTime; |
593 | } | 593 | } |
594 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 594 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
595 | { | 595 | { |
596 | //mNextAlarmIncidence | 596 | //mNextAlarmIncidence |
597 | //mNextAlarmDateTime | 597 | //mNextAlarmDateTime |
598 | //return mNextSummary; | 598 | //return mNextSummary; |
599 | //return mNextAlarmEventDateTime; | 599 | //return mNextAlarmEventDateTime; |
600 | bool newNextAlarm = false; | 600 | bool newNextAlarm = false; |
601 | bool computeNextAlarm = false; | 601 | bool computeNextAlarm = false; |
602 | bool ok; | 602 | bool ok; |
603 | int offset; | 603 | int offset; |
604 | QDateTime nextA; | 604 | QDateTime nextA; |
605 | // QString nextSum; | 605 | // QString nextSum; |
606 | //QDateTime nextEvent; | 606 | //QDateTime nextEvent; |
607 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 607 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
608 | computeNextAlarm = true; | 608 | computeNextAlarm = true; |
609 | } else { | 609 | } else { |
610 | if ( ! deleted ) { | 610 | if ( ! deleted ) { |
611 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 611 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
612 | if ( ok ) { | 612 | if ( ok ) { |
613 | if ( nextA < mNextAlarmDateTime ) { | 613 | if ( nextA < mNextAlarmDateTime ) { |
614 | deRegisterAlarm(); | 614 | deRegisterAlarm(); |
615 | mNextAlarmDateTime = nextA; | 615 | mNextAlarmDateTime = nextA; |
616 | mNextSummary = incidence->summary(); | 616 | mNextSummary = incidence->summary(); |
617 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 617 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
618 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 618 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
619 | newNextAlarm = true; | 619 | newNextAlarm = true; |
620 | mNextAlarmIncidence = incidence; | 620 | mNextAlarmIncidence = incidence; |
621 | } else { | 621 | } else { |
622 | if ( incidence == mNextAlarmIncidence ) { | 622 | if ( incidence == mNextAlarmIncidence ) { |
623 | computeNextAlarm = true; | 623 | computeNextAlarm = true; |
624 | } | 624 | } |
625 | } | 625 | } |
626 | } else { | 626 | } else { |
627 | if ( mNextAlarmIncidence == incidence ) { | 627 | if ( mNextAlarmIncidence == incidence ) { |
628 | computeNextAlarm = true; | 628 | computeNextAlarm = true; |
629 | } | 629 | } |
630 | } | 630 | } |
631 | } else { // deleted | 631 | } else { // deleted |
632 | if ( incidence == mNextAlarmIncidence ) { | 632 | if ( incidence == mNextAlarmIncidence ) { |
633 | computeNextAlarm = true; | 633 | computeNextAlarm = true; |
634 | } | 634 | } |
635 | } | 635 | } |
636 | } | 636 | } |
637 | if ( computeNextAlarm ) { | 637 | if ( computeNextAlarm ) { |
638 | deRegisterAlarm(); | 638 | deRegisterAlarm(); |
639 | nextA = nextAlarm( 1000 ); | 639 | nextA = nextAlarm( 1000 ); |
640 | if (! mNextAlarmIncidence ) { | 640 | if (! mNextAlarmIncidence ) { |
641 | return; | 641 | return; |
642 | } | 642 | } |
643 | newNextAlarm = true; | 643 | newNextAlarm = true; |
644 | } | 644 | } |
645 | if ( newNextAlarm ) | 645 | if ( newNextAlarm ) |
646 | registerAlarm(); | 646 | registerAlarm(); |
647 | } | 647 | } |
648 | QString CalendarLocal:: getAlarmNotification() | 648 | QString CalendarLocal:: getAlarmNotification() |
649 | { | 649 | { |
650 | QString ret; | 650 | QString ret; |
651 | // this should not happen | 651 | // this should not happen |
652 | if (! mNextAlarmIncidence ) | 652 | if (! mNextAlarmIncidence ) |
653 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 653 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
654 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 654 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
655 | if ( alarm->type() == Alarm::Procedure ) { | 655 | if ( alarm->type() == Alarm::Procedure ) { |
656 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 656 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
657 | } else { | 657 | } else { |
658 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 658 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
659 | } | 659 | } |
660 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 660 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
661 | if ( mNextSummary.length() > 25 ) | 661 | if ( mNextSummary.length() > 25 ) |
662 | ret += "\n" + mNextSummary.mid(25, 25 ); | 662 | ret += "\n" + mNextSummary.mid(25, 25 ); |
663 | ret+= "\n"+mNextAlarmEventDateTimeString; | 663 | ret+= "\n"+mNextAlarmEventDateTimeString; |
664 | return ret; | 664 | return ret; |
665 | } | 665 | } |
666 | void CalendarLocal::registerAlarm() | 666 | void CalendarLocal::registerAlarm() |
667 | { | 667 | { |
668 | mLastAlarmNotificationString = getAlarmNotification(); | 668 | mLastAlarmNotificationString = getAlarmNotification(); |
669 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 669 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
670 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 670 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
671 | // #ifndef DESKTOP_VERSION | 671 | // #ifndef DESKTOP_VERSION |
672 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 672 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
673 | // #endif | 673 | // #endif |
674 | } | 674 | } |
675 | void CalendarLocal::deRegisterAlarm() | 675 | void CalendarLocal::deRegisterAlarm() |
676 | { | 676 | { |
677 | if ( mLastAlarmNotificationString.isNull() ) | 677 | if ( mLastAlarmNotificationString.isNull() ) |
678 | return; | 678 | return; |
679 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 679 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
680 | 680 | ||
681 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 681 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
682 | mNextAlarmEventDateTime = QDateTime(); | 682 | mNextAlarmEventDateTime = QDateTime(); |
683 | // #ifndef DESKTOP_VERSION | 683 | // #ifndef DESKTOP_VERSION |
684 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 684 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
685 | // #endif | 685 | // #endif |
686 | } | 686 | } |
687 | 687 | ||
688 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 688 | Q3PtrList<Todo> CalendarLocal::todos( const QDate &date ) |
689 | { | 689 | { |
690 | QPtrList<Todo> todos; | 690 | Q3PtrList<Todo> todos; |
691 | 691 | ||
692 | Todo *todo; | 692 | Todo *todo; |
693 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 693 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
694 | if ( !todo->calEnabled() ) continue; | 694 | if ( !todo->calEnabled() ) continue; |
695 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 695 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
696 | todos.append( todo ); | 696 | todos.append( todo ); |
697 | } | 697 | } |
698 | } | 698 | } |
699 | 699 | ||
700 | filter()->apply( &todos ); | 700 | filter()->apply( &todos ); |
701 | return todos; | 701 | return todos; |
702 | } | 702 | } |
703 | void CalendarLocal::reInitAlarmSettings() | 703 | void CalendarLocal::reInitAlarmSettings() |
704 | { | 704 | { |
705 | if ( !mNextAlarmIncidence ) { | 705 | if ( !mNextAlarmIncidence ) { |
706 | nextAlarm( 1000 ); | 706 | nextAlarm( 1000 ); |
707 | } | 707 | } |
708 | deRegisterAlarm(); | 708 | deRegisterAlarm(); |
709 | mNextAlarmIncidence = 0; | 709 | mNextAlarmIncidence = 0; |
710 | checkAlarmForIncidence( 0, false ); | 710 | checkAlarmForIncidence( 0, false ); |
711 | 711 | ||
712 | } | 712 | } |
713 | 713 | ||
714 | 714 | ||
715 | 715 | ||
716 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 716 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
717 | { | 717 | { |
718 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 718 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
719 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 719 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
720 | QDateTime next; | 720 | QDateTime next; |
721 | Event *e; | 721 | Event *e; |
722 | bool ok; | 722 | bool ok; |
723 | bool found = false; | 723 | bool found = false; |
724 | int offset; | 724 | int offset; |
725 | mNextAlarmIncidence = 0; | 725 | mNextAlarmIncidence = 0; |
726 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 726 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
727 | if ( !e->calEnabled() ) continue; | 727 | if ( !e->calEnabled() ) continue; |
728 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 728 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
729 | if ( ok ) { | 729 | if ( ok ) { |
730 | if ( next < nextA ) { | 730 | if ( next < nextA ) { |
731 | nextA = next; | 731 | nextA = next; |
732 | found = true; | 732 | found = true; |
733 | mNextSummary = e->summary(); | 733 | mNextSummary = e->summary(); |
734 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 734 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
735 | mNextAlarmIncidence = (Incidence *) e; | 735 | mNextAlarmIncidence = (Incidence *) e; |
736 | } | 736 | } |
737 | } | 737 | } |
738 | } | 738 | } |
739 | Todo *t; | 739 | Todo *t; |
740 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 740 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
741 | if ( !t->calEnabled() ) continue; | 741 | if ( !t->calEnabled() ) continue; |
742 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 742 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
743 | if ( ok ) { | 743 | if ( ok ) { |
744 | if ( next < nextA ) { | 744 | if ( next < nextA ) { |
745 | nextA = next; | 745 | nextA = next; |
746 | found = true; | 746 | found = true; |
747 | mNextSummary = t->summary(); | 747 | mNextSummary = t->summary(); |
748 | mNextAlarmEventDateTime = next.addSecs(offset ); | 748 | mNextAlarmEventDateTime = next.addSecs(offset ); |
749 | mNextAlarmIncidence = (Incidence *) t; | 749 | mNextAlarmIncidence = (Incidence *) t; |
750 | } | 750 | } |
751 | } | 751 | } |
752 | } | 752 | } |
753 | if ( mNextAlarmIncidence ) { | 753 | if ( mNextAlarmIncidence ) { |
754 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 754 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
755 | mNextAlarmDateTime = nextA; | 755 | mNextAlarmDateTime = nextA; |
756 | } | 756 | } |
757 | return nextA; | 757 | return nextA; |
758 | } | 758 | } |
759 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 759 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
760 | { | 760 | { |
761 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 761 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
762 | } | 762 | } |
763 | 763 | ||
764 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 764 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
765 | { | 765 | { |
766 | 766 | ||
767 | Alarm::List alarms; | 767 | Alarm::List alarms; |
768 | 768 | ||
769 | Event *e; | 769 | Event *e; |
770 | 770 | ||
771 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 771 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
772 | if ( !e->calEnabled() ) continue; | 772 | if ( !e->calEnabled() ) continue; |
773 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 773 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
774 | else appendAlarms( alarms, e, from, to ); | 774 | else appendAlarms( alarms, e, from, to ); |
775 | } | 775 | } |
776 | 776 | ||
777 | Todo *t; | 777 | Todo *t; |
778 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 778 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
779 | if ( !t->calEnabled() ) continue; | 779 | if ( !t->calEnabled() ) continue; |
780 | appendAlarms( alarms, t, from, to ); | 780 | appendAlarms( alarms, t, from, to ); |
781 | } | 781 | } |
782 | 782 | ||
783 | return alarms; | 783 | return alarms; |
784 | } | 784 | } |
785 | 785 | ||
786 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 786 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
787 | const QDateTime &from, const QDateTime &to ) | 787 | const QDateTime &from, const QDateTime &to ) |
788 | { | 788 | { |
789 | QPtrList<Alarm> alarmList = incidence->alarms(); | 789 | Q3PtrList<Alarm> alarmList = incidence->alarms(); |
790 | Alarm *alarm; | 790 | Alarm *alarm; |
791 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 791 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
792 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 792 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
793 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 793 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
794 | if ( alarm->enabled() ) { | 794 | if ( alarm->enabled() ) { |
795 | if ( alarm->time() >= from && alarm->time() <= to ) { | 795 | if ( alarm->time() >= from && alarm->time() <= to ) { |
796 | alarms.append( alarm ); | 796 | alarms.append( alarm ); |
797 | } | 797 | } |
798 | } | 798 | } |
799 | } | 799 | } |
800 | } | 800 | } |
801 | 801 | ||
802 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 802 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
803 | Incidence *incidence, | 803 | Incidence *incidence, |
804 | const QDateTime &from, | 804 | const QDateTime &from, |
805 | const QDateTime &to ) | 805 | const QDateTime &to ) |
806 | { | 806 | { |
807 | 807 | ||
808 | QPtrList<Alarm> alarmList = incidence->alarms(); | 808 | Q3PtrList<Alarm> alarmList = incidence->alarms(); |
809 | Alarm *alarm; | 809 | Alarm *alarm; |
810 | QDateTime qdt; | 810 | QDateTime qdt; |
811 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 811 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
812 | if (incidence->recursOn(from.date())) { | 812 | if (incidence->recursOn(from.date())) { |
813 | qdt.setTime(alarm->time().time()); | 813 | qdt.setTime(alarm->time().time()); |
814 | qdt.setDate(from.date()); | 814 | qdt.setDate(from.date()); |
815 | } | 815 | } |
816 | else qdt = alarm->time(); | 816 | else qdt = alarm->time(); |
817 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 817 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
818 | if ( alarm->enabled() ) { | 818 | if ( alarm->enabled() ) { |
819 | if ( qdt >= from && qdt <= to ) { | 819 | if ( qdt >= from && qdt <= to ) { |
820 | alarms.append( alarm ); | 820 | alarms.append( alarm ); |
821 | } | 821 | } |
822 | } | 822 | } |
823 | } | 823 | } |
824 | } | 824 | } |
825 | 825 | ||
826 | 826 | ||
827 | /****************************** PROTECTED METHODS ****************************/ | 827 | /****************************** PROTECTED METHODS ****************************/ |
828 | 828 | ||
829 | // after changes are made to an event, this should be called. | 829 | // after changes are made to an event, this should be called. |
830 | void CalendarLocal::update( IncidenceBase *incidence ) | 830 | void CalendarLocal::update( IncidenceBase *incidence ) |
831 | { | 831 | { |
832 | incidence->setSyncStatus( Event::SYNCMOD ); | 832 | incidence->setSyncStatus( Event::SYNCMOD ); |
833 | incidence->setLastModified( QDateTime::currentDateTime() ); | 833 | incidence->setLastModified( QDateTime::currentDateTime() ); |
834 | // we should probably update the revision number here, | 834 | // we should probably update the revision number here, |
835 | // or internally in the Event itself when certain things change. | 835 | // or internally in the Event itself when certain things change. |
836 | // need to verify with ical documentation. | 836 | // need to verify with ical documentation. |
837 | 837 | ||
838 | setModified( true ); | 838 | setModified( true ); |
839 | } | 839 | } |
840 | 840 | ||
841 | void CalendarLocal::insertEvent( Event *event ) | 841 | void CalendarLocal::insertEvent( Event *event ) |
842 | { | 842 | { |
843 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 843 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
844 | } | 844 | } |
845 | 845 | ||
846 | 846 | ||
847 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 847 | Q3PtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
848 | { | 848 | { |
849 | QPtrList<Event> eventList; | 849 | Q3PtrList<Event> eventList; |
850 | 850 | ||
851 | Event *event; | 851 | Event *event; |
852 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 852 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
853 | if ( !event->calEnabled() ) continue; | 853 | if ( !event->calEnabled() ) continue; |
854 | if ( event->doesRecur() ) { | 854 | if ( event->doesRecur() ) { |
855 | if ( event->isMultiDay() ) { | 855 | if ( event->isMultiDay() ) { |
856 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 856 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
857 | int i; | 857 | int i; |
858 | for ( i = 0; i <= extraDays; i++ ) { | 858 | for ( i = 0; i <= extraDays; i++ ) { |
859 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 859 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
860 | eventList.append( event ); | 860 | eventList.append( event ); |
861 | break; | 861 | break; |
862 | } | 862 | } |
863 | } | 863 | } |
864 | } else { | 864 | } else { |
865 | if ( event->recursOn( qd ) ) | 865 | if ( event->recursOn( qd ) ) |
866 | eventList.append( event ); | 866 | eventList.append( event ); |
867 | } | 867 | } |
868 | } else { | 868 | } else { |
869 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 869 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
870 | eventList.append( event ); | 870 | eventList.append( event ); |
871 | } | 871 | } |
872 | } | 872 | } |
873 | } | 873 | } |
874 | 874 | ||
875 | if ( !sorted ) { | 875 | if ( !sorted ) { |
876 | return eventList; | 876 | return eventList; |
877 | } | 877 | } |
878 | 878 | ||
879 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 879 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
880 | // now, we have to sort it based on dtStart.time() | 880 | // now, we have to sort it based on dtStart.time() |
881 | QPtrList<Event> eventListSorted; | 881 | Q3PtrList<Event> eventListSorted; |
882 | Event *sortEvent; | 882 | Event *sortEvent; |
883 | for ( event = eventList.first(); event; event = eventList.next() ) { | 883 | for ( event = eventList.first(); event; event = eventList.next() ) { |
884 | sortEvent = eventListSorted.first(); | 884 | sortEvent = eventListSorted.first(); |
885 | int i = 0; | 885 | int i = 0; |
886 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 886 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
887 | { | 887 | { |
888 | i++; | 888 | i++; |
889 | sortEvent = eventListSorted.next(); | 889 | sortEvent = eventListSorted.next(); |
890 | } | 890 | } |
891 | eventListSorted.insert( i, event ); | 891 | eventListSorted.insert( i, event ); |
892 | } | 892 | } |
893 | return eventListSorted; | 893 | return eventListSorted; |
894 | } | 894 | } |
895 | 895 | ||
896 | 896 | ||
897 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 897 | Q3PtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
898 | bool inclusive ) | 898 | bool inclusive ) |
899 | { | 899 | { |
900 | Event *event = 0; | 900 | Event *event = 0; |
901 | 901 | ||
902 | QPtrList<Event> eventList; | 902 | Q3PtrList<Event> eventList; |
903 | 903 | ||
904 | // Get non-recurring events | 904 | // Get non-recurring events |
905 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 905 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
906 | if ( !event->calEnabled() ) continue; | 906 | if ( !event->calEnabled() ) continue; |
907 | if ( event->doesRecur() ) { | 907 | if ( event->doesRecur() ) { |
908 | QDate rStart = event->dtStart().date(); | 908 | QDate rStart = event->dtStart().date(); |
909 | bool found = false; | 909 | bool found = false; |
910 | if ( inclusive ) { | 910 | if ( inclusive ) { |
911 | if ( rStart >= start && rStart <= end ) { | 911 | if ( rStart >= start && rStart <= end ) { |
912 | // Start date of event is in range. Now check for end date. | 912 | // Start date of event is in range. Now check for end date. |
913 | // if duration is negative, event recurs forever, so do not include it. | 913 | // if duration is negative, event recurs forever, so do not include it. |
914 | if ( event->recurrence()->duration() == 0 ) { // End date set | 914 | if ( event->recurrence()->duration() == 0 ) { // End date set |
915 | QDate rEnd = event->recurrence()->endDate(); | 915 | QDate rEnd = event->recurrence()->endDate(); |
916 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 916 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
917 | found = true; | 917 | found = true; |
918 | } | 918 | } |
919 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 919 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
920 | // TODO: Calculate end date from duration. Should be done in Event | 920 | // TODO: Calculate end date from duration. Should be done in Event |
921 | // For now exclude all events with a duration. | 921 | // For now exclude all events with a duration. |
922 | } | 922 | } |
923 | } | 923 | } |
924 | } else { | 924 | } else { |
925 | bool founOne; | 925 | bool founOne; |
926 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 926 | QDate next = event->getNextOccurence( (QDateTime)start, &founOne ).date(); |
927 | if ( founOne ) { | 927 | if ( founOne ) { |
928 | if ( next <= end ) { | 928 | if ( next <= end ) { |
929 | found = true; | 929 | found = true; |
930 | } | 930 | } |
931 | } | 931 | } |
932 | 932 | ||
933 | /* | 933 | /* |
934 | // crap !!! | 934 | // crap !!! |
935 | if ( rStart <= end ) { // Start date not after range | 935 | if ( rStart <= end ) { // Start date not after range |
936 | if ( rStart >= start ) { // Start date within range | 936 | if ( rStart >= start ) { // Start date within range |
937 | found = true; | 937 | found = true; |
938 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 938 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
939 | found = true; | 939 | found = true; |
940 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 940 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
941 | QDate rEnd = event->recurrence()->endDate(); | 941 | QDate rEnd = event->recurrence()->endDate(); |
942 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 942 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
943 | found = true; | 943 | found = true; |
944 | } | 944 | } |
945 | } else { // Duration set | 945 | } else { // Duration set |
946 | // TODO: Calculate end date from duration. Should be done in Event | 946 | // TODO: Calculate end date from duration. Should be done in Event |
947 | // For now include all events with a duration. | 947 | // For now include all events with a duration. |
948 | found = true; | 948 | found = true; |
949 | } | 949 | } |
950 | } | 950 | } |
951 | */ | 951 | */ |
952 | 952 | ||
953 | } | 953 | } |
954 | 954 | ||
955 | if ( found ) eventList.append( event ); | 955 | if ( found ) eventList.append( event ); |
956 | } else { | 956 | } else { |
957 | QDate s = event->dtStart().date(); | 957 | QDate s = event->dtStart().date(); |
958 | QDate e = event->dtEnd().date(); | 958 | QDate e = event->dtEnd().date(); |
959 | 959 | ||
960 | if ( inclusive ) { | 960 | if ( inclusive ) { |
961 | if ( s >= start && e <= end ) { | 961 | if ( s >= start && e <= end ) { |
962 | eventList.append( event ); | 962 | eventList.append( event ); |
963 | } | 963 | } |
964 | } else { | 964 | } else { |
965 | if ( ( e >= start && s <= end ) ) { | 965 | if ( ( e >= start && s <= end ) ) { |
966 | eventList.append( event ); | 966 | eventList.append( event ); |
967 | } | 967 | } |
968 | } | 968 | } |
969 | } | 969 | } |
970 | } | 970 | } |
971 | 971 | ||
972 | return eventList; | 972 | return eventList; |
973 | } | 973 | } |
974 | 974 | ||
975 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 975 | Q3PtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
976 | { | 976 | { |
977 | return rawEventsForDate( qdt.date() ); | 977 | return rawEventsForDate( qdt.date() ); |
978 | } | 978 | } |
979 | 979 | ||
980 | QPtrList<Event> CalendarLocal::rawEvents() | 980 | Q3PtrList<Event> CalendarLocal::rawEvents() |
981 | { | 981 | { |
982 | QPtrList<Event> el; | 982 | Q3PtrList<Event> el; |
983 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 983 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
984 | if ( it->calEnabled() ) el.append( it ); | 984 | if ( it->calEnabled() ) el.append( it ); |
985 | return el; | 985 | return el; |
986 | } | 986 | } |
987 | 987 | ||
988 | bool CalendarLocal::addJournal(Journal *journal) | 988 | bool CalendarLocal::addJournal(Journal *journal) |
989 | { | 989 | { |
990 | mJournalList.append(journal); | 990 | mJournalList.append(journal); |
991 | 991 | ||
992 | journal->registerObserver( this ); | 992 | journal->registerObserver( this ); |
993 | 993 | ||
994 | setModified( true ); | 994 | setModified( true ); |
995 | if ( journal->calID() == 0 ) | 995 | if ( journal->calID() == 0 ) |
996 | journal->setCalID_block( mDefaultCalendar ); | 996 | journal->setCalID_block( mDefaultCalendar ); |
997 | journal->setCalEnabled( true ); | 997 | journal->setCalEnabled( true ); |
998 | return true; | 998 | return true; |
999 | } | 999 | } |
1000 | 1000 | ||
1001 | void CalendarLocal::deleteJournal( Journal *journal ) | 1001 | void CalendarLocal::deleteJournal( Journal *journal ) |
1002 | { | 1002 | { |
1003 | clearUndo(journal); | 1003 | clearUndo(journal); |
1004 | if ( mJournalList.removeRef(journal) ) { | 1004 | if ( mJournalList.removeRef(journal) ) { |
1005 | setModified( true ); | 1005 | setModified( true ); |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) | 1009 | Q3PtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) |
1010 | { | 1010 | { |
1011 | QPtrList<Journal> el; | 1011 | Q3PtrList<Journal> el; |
1012 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1012 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1013 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); | 1013 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); |
1014 | return el; | 1014 | return el; |
1015 | } | 1015 | } |
1016 | Journal *CalendarLocal::journal( const QDate &date ) | 1016 | Journal *CalendarLocal::journal( const QDate &date ) |
1017 | { | 1017 | { |
1018 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 1018 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
1019 | 1019 | ||
1020 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1020 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1021 | if ( it->calEnabled() && it->dtStart().date() == date ) | 1021 | if ( it->calEnabled() && it->dtStart().date() == date ) |
1022 | return it; | 1022 | return it; |
1023 | 1023 | ||
1024 | return 0; | 1024 | return 0; |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | Journal *CalendarLocal::journal( const QString &uid ) | 1027 | Journal *CalendarLocal::journal( const QString &uid ) |
1028 | { | 1028 | { |
1029 | Journal * retVal = 0; | 1029 | Journal * retVal = 0; |
1030 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1030 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1031 | if ( it->calEnabled() && it->uid() == uid ) { | 1031 | if ( it->calEnabled() && it->uid() == uid ) { |
1032 | if ( retVal ) { | 1032 | if ( retVal ) { |
1033 | if ( retVal->calID() > it->calID() ) { | 1033 | if ( retVal->calID() > it->calID() ) { |
1034 | retVal = it; | 1034 | retVal = it; |
1035 | } | 1035 | } |
1036 | } else { | 1036 | } else { |
1037 | retVal = it; | 1037 | retVal = it; |
1038 | } | 1038 | } |
1039 | } | 1039 | } |
1040 | return retVal; | 1040 | return retVal; |
1041 | } | 1041 | } |
1042 | 1042 | ||
1043 | QPtrList<Journal> CalendarLocal::journals() | 1043 | Q3PtrList<Journal> CalendarLocal::journals() |
1044 | { | 1044 | { |
1045 | QPtrList<Journal> el; | 1045 | Q3PtrList<Journal> el; |
1046 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1046 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1047 | if ( it->calEnabled() ) el.append( it ); | 1047 | if ( it->calEnabled() ) el.append( it ); |
1048 | return el; | 1048 | return el; |
1049 | } | 1049 | } |
1050 | void CalendarLocal::setCalendarRemove( int id ) | 1050 | void CalendarLocal::setCalendarRemove( int id ) |
1051 | { | 1051 | { |
1052 | 1052 | ||
1053 | { | 1053 | { |
1054 | QPtrList<Event> EventList = mEventList; | 1054 | Q3PtrList<Event> EventList = mEventList; |
1055 | Event * ev = EventList.first(); | 1055 | Event * ev = EventList.first(); |
1056 | while ( ev ) { | 1056 | while ( ev ) { |
1057 | if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) | 1057 | if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) |
1058 | deleteEvent( ev ); | 1058 | deleteEvent( ev ); |
1059 | ev = EventList.next(); | 1059 | ev = EventList.next(); |
1060 | } | 1060 | } |
1061 | } | 1061 | } |
1062 | { | 1062 | { |
1063 | 1063 | ||
1064 | QPtrList<Todo> TodoList = mTodoList; | 1064 | Q3PtrList<Todo> TodoList = mTodoList; |
1065 | Todo * ev = TodoList.first(); | 1065 | Todo * ev = TodoList.first(); |
1066 | while ( ev ) { | 1066 | while ( ev ) { |
1067 | if ( ev->calID() == id ) | 1067 | if ( ev->calID() == id ) |
1068 | deleteTodo( ev ); | 1068 | deleteTodo( ev ); |
1069 | ev = TodoList.next(); | 1069 | ev = TodoList.next(); |
1070 | } | 1070 | } |
1071 | } | 1071 | } |
1072 | { | 1072 | { |
1073 | QPtrList<Journal> JournalList = mJournalList; | 1073 | Q3PtrList<Journal> JournalList = mJournalList; |
1074 | Journal * ev = JournalList.first(); | 1074 | Journal * ev = JournalList.first(); |
1075 | while ( ev ) { | 1075 | while ( ev ) { |
1076 | if ( ev->calID() == id ) | 1076 | if ( ev->calID() == id ) |
1077 | deleteJournal( ev ); | 1077 | deleteJournal( ev ); |
1078 | ev = JournalList.next(); | 1078 | ev = JournalList.next(); |
1079 | } | 1079 | } |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | clearUndo(0); | 1082 | clearUndo(0); |
1083 | 1083 | ||
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | void CalendarLocal::setAllCalendarEnabled( bool enable ) | 1086 | void CalendarLocal::setAllCalendarEnabled( bool enable ) |
1087 | { | 1087 | { |
1088 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1088 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1089 | it->setCalEnabled( enable ); | 1089 | it->setCalEnabled( enable ); |
1090 | 1090 | ||
1091 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1091 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1092 | it->setCalEnabled( enable ); | 1092 | it->setCalEnabled( enable ); |
1093 | 1093 | ||
1094 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1094 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1095 | it->setCalEnabled( enable ); | 1095 | it->setCalEnabled( enable ); |
1096 | 1096 | ||
1097 | 1097 | ||
1098 | } | 1098 | } |
1099 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 1099 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
1100 | { | 1100 | { |
1101 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1101 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1102 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1102 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1103 | 1103 | ||
1104 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1104 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1105 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1105 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1106 | 1106 | ||
1107 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1107 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1108 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1108 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1109 | 1109 | ||
1110 | } | 1110 | } |
1111 | 1111 | ||
1112 | void CalendarLocal::setReadOnly( int id, bool enable ) | 1112 | void CalendarLocal::setReadOnly( int id, bool enable ) |
1113 | { | 1113 | { |
1114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1115 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1115 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1116 | 1116 | ||
1117 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1117 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1118 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1118 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1119 | 1119 | ||
1120 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1120 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1121 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1121 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1122 | 1122 | ||
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 1125 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
1126 | { | 1126 | { |
1127 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1127 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1128 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1128 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1129 | 1129 | ||
1130 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1130 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1131 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1131 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1132 | 1132 | ||
1133 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1133 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1134 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1134 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1135 | reInitAlarmSettings(); | 1135 | reInitAlarmSettings(); |
1136 | 1136 | ||
1137 | } | 1137 | } |
1138 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 1138 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
1139 | { | 1139 | { |
1140 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1140 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1141 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 1141 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
1142 | 1142 | ||
1143 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1143 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1144 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1144 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1145 | 1145 | ||
1146 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1146 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1147 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1147 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1148 | 1148 | ||
1149 | } | 1149 | } |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 1ceabce..1df65c7 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,234 +1,236 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | //Added by qt3to4: | ||
27 | #include <Q3PtrList> | ||
26 | 28 | ||
27 | namespace KCal { | 29 | namespace KCal { |
28 | 30 | ||
29 | class CalFormat; | 31 | class CalFormat; |
30 | 32 | ||
31 | /** | 33 | /** |
32 | This class provides a calendar stored as a local file. | 34 | This class provides a calendar stored as a local file. |
33 | */ | 35 | */ |
34 | class CalendarLocal : public Calendar | 36 | class CalendarLocal : public Calendar |
35 | { | 37 | { |
36 | public: | 38 | public: |
37 | /** | 39 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 40 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 41 | */ |
40 | CalendarLocal(); | 42 | CalendarLocal(); |
41 | /** | 43 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 44 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 45 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 46 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 47 | ~CalendarLocal(); |
46 | void addCalendar( Calendar* ); | 48 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 49 | bool addCalendarFile( QString name, int id ); |
48 | bool mergeCalendarFile( QString name ); | 50 | bool mergeCalendarFile( QString name ); |
49 | bool mergeCalendar( Calendar* cal ); | 51 | bool mergeCalendar( Calendar* cal ); |
50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false,int * isDup = 0 ); | 52 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false,int * isDup = 0 ); |
51 | Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0 ); | 53 | Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0 ); |
52 | void setSyncEventsReadOnly(); | 54 | void setSyncEventsReadOnly(); |
53 | void setSyncEventsEnabled(); | 55 | void setSyncEventsEnabled(); |
54 | void stopAllTodos(); | 56 | void stopAllTodos(); |
55 | /** | 57 | /** |
56 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 58 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
57 | calendar. Any information already present is lost. | 59 | calendar. Any information already present is lost. |
58 | @return true, if successfull, false on error. | 60 | @return true, if successfull, false on error. |
59 | @param fileName the name of the calendar on disk. | 61 | @param fileName the name of the calendar on disk. |
60 | */ | 62 | */ |
61 | bool load( const QString &fileName ); | 63 | bool load( const QString &fileName ); |
62 | /** | 64 | /** |
63 | Writes out the calendar to disk in the specified \a format. | 65 | Writes out the calendar to disk in the specified \a format. |
64 | CalendarLocal takes ownership of the CalFormat object. | 66 | CalendarLocal takes ownership of the CalFormat object. |
65 | @return true, if successfull, false on error. | 67 | @return true, if successfull, false on error. |
66 | @param fileName the name of the file | 68 | @param fileName the name of the file |
67 | */ | 69 | */ |
68 | bool save( const QString &fileName, CalFormat *format = 0 ); | 70 | bool save( const QString &fileName, CalFormat *format = 0 ); |
69 | 71 | ||
70 | /** | 72 | /** |
71 | Clears out the current calendar, freeing all used memory etc. etc. | 73 | Clears out the current calendar, freeing all used memory etc. etc. |
72 | */ | 74 | */ |
73 | void close(); | 75 | void close(); |
74 | 76 | ||
75 | void save() {} | 77 | void save() {} |
76 | 78 | ||
77 | /** | 79 | /** |
78 | Add Event to calendar. | 80 | Add Event to calendar. |
79 | */ | 81 | */ |
80 | void removeSyncInfo( QString syncProfile); | 82 | void removeSyncInfo( QString syncProfile); |
81 | bool addAnniversaryNoDup( Event *event ); | 83 | bool addAnniversaryNoDup( Event *event ); |
82 | bool addEventNoDup( Event *event ); | 84 | bool addEventNoDup( Event *event ); |
83 | bool addEvent( Event *event ); | 85 | bool addEvent( Event *event ); |
84 | /** | 86 | /** |
85 | Deletes an event from this calendar. | 87 | Deletes an event from this calendar. |
86 | */ | 88 | */ |
87 | void deleteEvent( Event *event ); | 89 | void deleteEvent( Event *event ); |
88 | 90 | ||
89 | /** | 91 | /** |
90 | Retrieves an event on the basis of the unique string ID. | 92 | Retrieves an event on the basis of the unique string ID. |
91 | */ | 93 | */ |
92 | Event *event( const QString &uid ); | 94 | Event *event( const QString &uid ); |
93 | /** | 95 | /** |
94 | Return unfiltered list of all events in calendar. | 96 | Return unfiltered list of all events in calendar. |
95 | */ | 97 | */ |
96 | QPtrList<Event> rawEvents(); | 98 | Q3PtrList<Event> rawEvents(); |
97 | QPtrList<Event> getExternLastSyncEvents(); | 99 | Q3PtrList<Event> getExternLastSyncEvents(); |
98 | /** | 100 | /** |
99 | Add a todo to the todolist. | 101 | Add a todo to the todolist. |
100 | */ | 102 | */ |
101 | bool addTodo( Todo *todo ); | 103 | bool addTodo( Todo *todo ); |
102 | bool addTodoNoDup( Todo *todo ); | 104 | bool addTodoNoDup( Todo *todo ); |
103 | /** | 105 | /** |
104 | Remove a todo from the todolist. | 106 | Remove a todo from the todolist. |
105 | */ | 107 | */ |
106 | void deleteTodo( Todo * ); | 108 | void deleteTodo( Todo * ); |
107 | /** | 109 | /** |
108 | Searches todolist for an event with this unique string identifier, | 110 | Searches todolist for an event with this unique string identifier, |
109 | returns a pointer or null. | 111 | returns a pointer or null. |
110 | */ | 112 | */ |
111 | Todo *todo( const QString &uid ); | 113 | Todo *todo( const QString &uid ); |
112 | /** | 114 | /** |
113 | Return list of all todos. | 115 | Return list of all todos. |
114 | */ | 116 | */ |
115 | QPtrList<Todo> rawTodos(); | 117 | Q3PtrList<Todo> rawTodos(); |
116 | /** | 118 | /** |
117 | Returns list of todos due on the specified date. | 119 | Returns list of todos due on the specified date. |
118 | */ | 120 | */ |
119 | QPtrList<Todo> todos( const QDate &date ); | 121 | Q3PtrList<Todo> todos( const QDate &date ); |
120 | /** | 122 | /** |
121 | Return list of all todos. | 123 | Return list of all todos. |
122 | 124 | ||
123 | Workaround because compiler does not recognize function of base class. | 125 | Workaround because compiler does not recognize function of base class. |
124 | */ | 126 | */ |
125 | QPtrList<Todo> todos() { return Calendar::todos(); } | 127 | Q3PtrList<Todo> todos() { return Calendar::todos(); } |
126 | 128 | ||
127 | /** | 129 | /** |
128 | Add a Journal entry to calendar. | 130 | Add a Journal entry to calendar. |
129 | */ | 131 | */ |
130 | bool addJournal( Journal * ); | 132 | bool addJournal( Journal * ); |
131 | /** | 133 | /** |
132 | Remove a Journal from the calendar. | 134 | Remove a Journal from the calendar. |
133 | */ | 135 | */ |
134 | void deleteJournal( Journal * ); | 136 | void deleteJournal( Journal * ); |
135 | /** | 137 | /** |
136 | Return Journal for given date. | 138 | Return Journal for given date. |
137 | */ | 139 | */ |
138 | Journal *journal( const QDate & ); | 140 | Journal *journal( const QDate & ); |
139 | QPtrList<Journal> journals4Date( const QDate & ); | 141 | Q3PtrList<Journal> journals4Date( const QDate & ); |
140 | /** | 142 | /** |
141 | Return Journal with given UID. | 143 | Return Journal with given UID. |
142 | */ | 144 | */ |
143 | Journal *journal( const QString &uid ); | 145 | Journal *journal( const QString &uid ); |
144 | /** | 146 | /** |
145 | Return list of all Journals stored in calendar. | 147 | Return list of all Journals stored in calendar. |
146 | */ | 148 | */ |
147 | QPtrList<Journal> journals(); | 149 | Q3PtrList<Journal> journals(); |
148 | 150 | ||
149 | /** | 151 | /** |
150 | Return all alarms, which ocur in the given time interval. | 152 | Return all alarms, which ocur in the given time interval. |
151 | */ | 153 | */ |
152 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 154 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
153 | 155 | ||
154 | /** | 156 | /** |
155 | Return all alarms, which ocur before given date. | 157 | Return all alarms, which ocur before given date. |
156 | */ | 158 | */ |
157 | Alarm::List alarmsTo( const QDateTime &to ); | 159 | Alarm::List alarmsTo( const QDateTime &to ); |
158 | 160 | ||
159 | QDateTime nextAlarm( int daysTo ) ; | 161 | QDateTime nextAlarm( int daysTo ) ; |
160 | QDateTime nextAlarmEventDateTime() const; | 162 | QDateTime nextAlarmEventDateTime() const; |
161 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 163 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
162 | void registerAlarm(); | 164 | void registerAlarm(); |
163 | void deRegisterAlarm(); | 165 | void deRegisterAlarm(); |
164 | QString getAlarmNotification(); | 166 | QString getAlarmNotification(); |
165 | QString nextSummary() const ; | 167 | QString nextSummary() const ; |
166 | /** | 168 | /** |
167 | This method should be called whenever a Event is modified directly | 169 | This method should be called whenever a Event is modified directly |
168 | via it's pointer. It makes sure that the calendar is internally | 170 | via it's pointer. It makes sure that the calendar is internally |
169 | consistent. | 171 | consistent. |
170 | */ | 172 | */ |
171 | void update( IncidenceBase *incidence ); | 173 | void update( IncidenceBase *incidence ); |
172 | 174 | ||
173 | /** | 175 | /** |
174 | Builds and then returns a list of all events that match for the | 176 | Builds and then returns a list of all events that match for the |
175 | date specified. useful for dayView, etc. etc. | 177 | date specified. useful for dayView, etc. etc. |
176 | */ | 178 | */ |
177 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 179 | Q3PtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
178 | /** | 180 | /** |
179 | Get unfiltered events for date \a qdt. | 181 | Get unfiltered events for date \a qdt. |
180 | */ | 182 | */ |
181 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 183 | Q3PtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
182 | /** | 184 | /** |
183 | Get unfiltered events in a range of dates. If inclusive is set to true, | 185 | Get unfiltered events in a range of dates. If inclusive is set to true, |
184 | only events are returned, which are completely included in the range. | 186 | only events are returned, which are completely included in the range. |
185 | */ | 187 | */ |
186 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 188 | Q3PtrList<Event> rawEvents( const QDate &start, const QDate &end, |
187 | bool inclusive = false ); | 189 | bool inclusive = false ); |
188 | Todo *todo( QString, QString ); | 190 | Todo *todo( QString, QString ); |
189 | Event *event( QString, QString ); | 191 | Event *event( QString, QString ); |
190 | void getIncidenceCount( int calId, int& events, int & todos, int & journals); | 192 | void getIncidenceCount( int calId, int& events, int & todos, int & journals); |
191 | 193 | ||
192 | public slots: | 194 | public slots: |
193 | void setCalendarEnabled( int id, bool enable ); | 195 | void setCalendarEnabled( int id, bool enable ); |
194 | void setAlarmEnabled( int id, bool enable ); | 196 | void setAlarmEnabled( int id, bool enable ); |
195 | void setReadOnly( int id, bool enable ); | 197 | void setReadOnly( int id, bool enable ); |
196 | void setDefaultCalendarEnabledOnly(); | 198 | void setDefaultCalendarEnabledOnly(); |
197 | void setCalendarRemove( int id ); | 199 | void setCalendarRemove( int id ); |
198 | void setAllCalendarEnabled( bool enable ); | 200 | void setAllCalendarEnabled( bool enable ); |
199 | 201 | ||
200 | protected: | 202 | protected: |
201 | 203 | ||
202 | // Event* mNextAlarmEvent; | 204 | // Event* mNextAlarmEvent; |
203 | QString mNextSummary; | 205 | QString mNextSummary; |
204 | QString mNextAlarmEventDateTimeString; | 206 | QString mNextAlarmEventDateTimeString; |
205 | QString mLastAlarmNotificationString; | 207 | QString mLastAlarmNotificationString; |
206 | QDateTime mNextAlarmEventDateTime; | 208 | QDateTime mNextAlarmEventDateTime; |
207 | QDateTime mNextAlarmDateTime; | 209 | QDateTime mNextAlarmDateTime; |
208 | void reInitAlarmSettings(); | 210 | void reInitAlarmSettings(); |
209 | 211 | ||
210 | /** Notification function of IncidenceBase::Observer. */ | 212 | /** Notification function of IncidenceBase::Observer. */ |
211 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 213 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
212 | 214 | ||
213 | /** inserts an event into its "proper place" in the calendar. */ | 215 | /** inserts an event into its "proper place" in the calendar. */ |
214 | void insertEvent( Event *event ); | 216 | void insertEvent( Event *event ); |
215 | 217 | ||
216 | /** Append alarms of incidence in interval to list of alarms. */ | 218 | /** Append alarms of incidence in interval to list of alarms. */ |
217 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 219 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
218 | const QDateTime &from, const QDateTime &to ); | 220 | const QDateTime &from, const QDateTime &to ); |
219 | 221 | ||
220 | /** Append alarms of recurring events in interval to list of alarms. */ | 222 | /** Append alarms of recurring events in interval to list of alarms. */ |
221 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 223 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
222 | const QDateTime &from, const QDateTime &to ); | 224 | const QDateTime &from, const QDateTime &to ); |
223 | 225 | ||
224 | private: | 226 | private: |
225 | void init(); | 227 | void init(); |
226 | 228 | ||
227 | QPtrList<Event> mEventList; | 229 | Q3PtrList<Event> mEventList; |
228 | QPtrList<Todo> mTodoList; | 230 | Q3PtrList<Todo> mTodoList; |
229 | QPtrList<Journal> mJournalList; | 231 | Q3PtrList<Journal> mJournalList; |
230 | }; | 232 | }; |
231 | 233 | ||
232 | } | 234 | } |
233 | 235 | ||
234 | #endif | 236 | #endif |
diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp index 72f70c2..fa1dbd5 100644 --- a/libkcal/calfilter.cpp +++ b/libkcal/calfilter.cpp | |||
@@ -1,221 +1,223 @@ | |||
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 <kdebug.h> | 21 | #include <kdebug.h> |
22 | 22 | ||
23 | #include "calfilter.h" | 23 | #include "calfilter.h" |
24 | //Added by qt3to4: | ||
25 | #include <Q3PtrList> | ||
24 | 26 | ||
25 | using namespace KCal; | 27 | using namespace KCal; |
26 | 28 | ||
27 | CalFilter::CalFilter() | 29 | CalFilter::CalFilter() |
28 | { | 30 | { |
29 | mEnabled = true; | 31 | mEnabled = true; |
30 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 32 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
31 | } | 33 | } |
32 | 34 | ||
33 | CalFilter::CalFilter(const QString &name) | 35 | CalFilter::CalFilter(const QString &name) |
34 | { | 36 | { |
35 | mName = name; | 37 | mName = name; |
36 | mEnabled = true; | 38 | mEnabled = true; |
37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 39 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
38 | } | 40 | } |
39 | 41 | ||
40 | CalFilter::~CalFilter() | 42 | CalFilter::~CalFilter() |
41 | { | 43 | { |
42 | } | 44 | } |
43 | 45 | ||
44 | void CalFilter::apply(QPtrList<Event> *eventlist) | 46 | void CalFilter::apply(Q3PtrList<Event> *eventlist) |
45 | { | 47 | { |
46 | if (!mEnabled) return; | 48 | if (!mEnabled) return; |
47 | 49 | ||
48 | // kdDebug(5800) << "CalFilter::apply()" << endl; | 50 | // kdDebug(5800) << "CalFilter::apply()" << endl; |
49 | 51 | ||
50 | Event *event = eventlist->first(); | 52 | Event *event = eventlist->first(); |
51 | while(event) { | 53 | while(event) { |
52 | if (!filterEvent(event)) { | 54 | if (!filterEvent(event)) { |
53 | eventlist->remove(); | 55 | eventlist->remove(); |
54 | event = eventlist->current(); | 56 | event = eventlist->current(); |
55 | } else { | 57 | } else { |
56 | event = eventlist->next(); | 58 | event = eventlist->next(); |
57 | } | 59 | } |
58 | } | 60 | } |
59 | 61 | ||
60 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | 62 | // kdDebug(5800) << "CalFilter::apply() done" << endl; |
61 | } | 63 | } |
62 | 64 | ||
63 | // TODO: avoid duplicating apply() code | 65 | // TODO: avoid duplicating apply() code |
64 | void CalFilter::apply(QPtrList<Todo> *eventlist) | 66 | void CalFilter::apply(Q3PtrList<Todo> *eventlist) |
65 | { | 67 | { |
66 | if (!mEnabled) return; | 68 | if (!mEnabled) return; |
67 | Todo *event = eventlist->first(); | 69 | Todo *event = eventlist->first(); |
68 | while(event) { | 70 | while(event) { |
69 | if (!filterTodo(event)) { | 71 | if (!filterTodo(event)) { |
70 | eventlist->remove(); | 72 | eventlist->remove(); |
71 | event = eventlist->current(); | 73 | event = eventlist->current(); |
72 | } else { | 74 | } else { |
73 | event = eventlist->next(); | 75 | event = eventlist->next(); |
74 | } | 76 | } |
75 | } | 77 | } |
76 | 78 | ||
77 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | 79 | // kdDebug(5800) << "CalFilter::apply() done" << endl; |
78 | } | 80 | } |
79 | bool CalFilter::filterCalendarItem(Incidence *in) | 81 | bool CalFilter::filterCalendarItem(Incidence *in) |
80 | { | 82 | { |
81 | if ( !in->calEnabled() ) | 83 | if ( !in->calEnabled() ) |
82 | return false; | 84 | return false; |
83 | if ( in->typeID() == eventID ) | 85 | if ( in->typeID() == eventID ) |
84 | return filterEvent( (Event*) in ); | 86 | return filterEvent( (Event*) in ); |
85 | else if ( in->typeID() == todoID ) | 87 | else if ( in->typeID() == todoID ) |
86 | return filterTodo( (Todo*) in); | 88 | return filterTodo( (Todo*) in); |
87 | else if ( in->typeID () == journalID ) | 89 | else if ( in->typeID () == journalID ) |
88 | return filterJournal( (Journal*) in ); | 90 | return filterJournal( (Journal*) in ); |
89 | return false; | 91 | return false; |
90 | } | 92 | } |
91 | bool CalFilter::filterEvent(Event *event) | 93 | bool CalFilter::filterEvent(Event *event) |
92 | { | 94 | { |
93 | 95 | ||
94 | if ( !event->calEnabled() ) | 96 | if ( !event->calEnabled() ) |
95 | return false; | 97 | return false; |
96 | if (mCriteria & HideEvents) | 98 | if (mCriteria & HideEvents) |
97 | return false; | 99 | return false; |
98 | if (mCriteria & HideRecurring) { | 100 | if (mCriteria & HideRecurring) { |
99 | if (event->recurrence()->doesRecur()) return false; | 101 | if (event->recurrence()->doesRecur()) return false; |
100 | } | 102 | } |
101 | 103 | ||
102 | return filterIncidence(event); | 104 | return filterIncidence(event); |
103 | } | 105 | } |
104 | bool CalFilter::filterJournal(Journal *j) | 106 | bool CalFilter::filterJournal(Journal *j) |
105 | { | 107 | { |
106 | if ( !j->calEnabled() ) | 108 | if ( !j->calEnabled() ) |
107 | return false; | 109 | return false; |
108 | if (mCriteria & HideJournals) | 110 | if (mCriteria & HideJournals) |
109 | return false; | 111 | return false; |
110 | return true; | 112 | return true; |
111 | } | 113 | } |
112 | bool CalFilter::filterTodo(Todo *todo) | 114 | bool CalFilter::filterTodo(Todo *todo) |
113 | { | 115 | { |
114 | if ( !todo->calEnabled() ) | 116 | if ( !todo->calEnabled() ) |
115 | return false; | 117 | return false; |
116 | if (mCriteria & HideTodos) | 118 | if (mCriteria & HideTodos) |
117 | return false; | 119 | return false; |
118 | if (mCriteria & HideCompleted) { | 120 | if (mCriteria & HideCompleted) { |
119 | if (todo->isCompleted()) return false; | 121 | if (todo->isCompleted()) return false; |
120 | } | 122 | } |
121 | 123 | ||
122 | return filterIncidence(todo); | 124 | return filterIncidence(todo); |
123 | } | 125 | } |
124 | bool CalFilter::showCategories() | 126 | bool CalFilter::showCategories() |
125 | { | 127 | { |
126 | return mCriteria & ShowCategories; | 128 | return mCriteria & ShowCategories; |
127 | } | 129 | } |
128 | int CalFilter::getSecrecy() | 130 | int CalFilter::getSecrecy() |
129 | { | 131 | { |
130 | if ( (mCriteria & ShowPublic )) | 132 | if ( (mCriteria & ShowPublic )) |
131 | return Incidence::SecrecyPublic; | 133 | return Incidence::SecrecyPublic; |
132 | if ( (mCriteria & ShowPrivate )) | 134 | if ( (mCriteria & ShowPrivate )) |
133 | return Incidence::SecrecyPrivate; | 135 | return Incidence::SecrecyPrivate; |
134 | if ( (mCriteria & ShowConfidential )) | 136 | if ( (mCriteria & ShowConfidential )) |
135 | return Incidence::SecrecyConfidential; | 137 | return Incidence::SecrecyConfidential; |
136 | return Incidence::SecrecyPublic; | 138 | return Incidence::SecrecyPublic; |
137 | } | 139 | } |
138 | bool CalFilter::filterIncidence(Incidence *incidence) | 140 | bool CalFilter::filterIncidence(Incidence *incidence) |
139 | { | 141 | { |
140 | if ( mCriteria > 7 ) { | 142 | if ( mCriteria > 7 ) { |
141 | switch (incidence->secrecy()) { | 143 | switch (incidence->secrecy()) { |
142 | case Incidence::SecrecyPublic: | 144 | case Incidence::SecrecyPublic: |
143 | if (! (mCriteria & ShowPublic )) | 145 | if (! (mCriteria & ShowPublic )) |
144 | return false; | 146 | return false; |
145 | break; | 147 | break; |
146 | case Incidence::SecrecyPrivate: | 148 | case Incidence::SecrecyPrivate: |
147 | if (! (mCriteria & ShowPrivate )) | 149 | if (! (mCriteria & ShowPrivate )) |
148 | return false; | 150 | return false; |
149 | break; | 151 | break; |
150 | case Incidence::SecrecyConfidential: | 152 | case Incidence::SecrecyConfidential: |
151 | if (! (mCriteria & ShowConfidential )) | 153 | if (! (mCriteria & ShowConfidential )) |
152 | return false; | 154 | return false; |
153 | break; | 155 | break; |
154 | default: | 156 | default: |
155 | return false; | 157 | return false; |
156 | break; | 158 | break; |
157 | } | 159 | } |
158 | } | 160 | } |
159 | 161 | ||
160 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | 162 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; |
161 | 163 | ||
162 | if (mCriteria & ShowCategories) { | 164 | if (mCriteria & ShowCategories) { |
163 | for (QStringList::Iterator it = mCategoryList.begin(); | 165 | for (QStringList::Iterator it = mCategoryList.begin(); |
164 | it != mCategoryList.end(); ++it ) { | 166 | it != mCategoryList.end(); ++it ) { |
165 | //QStringList incidenceCategories = incidence->categories(); | 167 | //QStringList incidenceCategories = incidence->categories(); |
166 | for (QStringList::Iterator it2 = incidence->categoriesP()->begin(); | 168 | for (QStringList::Iterator it2 = incidence->categoriesP()->begin(); |
167 | it2 != incidence->categoriesP()->end(); ++it2 ) { | 169 | it2 != incidence->categoriesP()->end(); ++it2 ) { |
168 | if ((*it) == (*it2)) { | 170 | if ((*it) == (*it2)) { |
169 | return true; | 171 | return true; |
170 | } | 172 | } |
171 | } | 173 | } |
172 | } | 174 | } |
173 | return false; | 175 | return false; |
174 | } else { | 176 | } else { |
175 | for (QStringList::Iterator it = mCategoryList.begin(); | 177 | for (QStringList::Iterator it = mCategoryList.begin(); |
176 | it != mCategoryList.end(); ++it ) { | 178 | it != mCategoryList.end(); ++it ) { |
177 | //QStringList incidenceCategories = incidence->categories(); | 179 | //QStringList incidenceCategories = incidence->categories(); |
178 | for (QStringList::Iterator it2 = incidence->categoriesP()->begin(); | 180 | for (QStringList::Iterator it2 = incidence->categoriesP()->begin(); |
179 | it2 != incidence->categoriesP()->end(); ++it2 ) { | 181 | it2 != incidence->categoriesP()->end(); ++it2 ) { |
180 | if ((*it) == (*it2)) { | 182 | if ((*it) == (*it2)) { |
181 | return false; | 183 | return false; |
182 | } | 184 | } |
183 | } | 185 | } |
184 | } | 186 | } |
185 | return true; | 187 | return true; |
186 | } | 188 | } |
187 | 189 | ||
188 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; | 190 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; |
189 | 191 | ||
190 | return true; | 192 | return true; |
191 | } | 193 | } |
192 | 194 | ||
193 | void CalFilter::setEnabled(bool enabled) | 195 | void CalFilter::setEnabled(bool enabled) |
194 | { | 196 | { |
195 | mEnabled = enabled; | 197 | mEnabled = enabled; |
196 | } | 198 | } |
197 | 199 | ||
198 | bool CalFilter::isEnabled() | 200 | bool CalFilter::isEnabled() |
199 | { | 201 | { |
200 | return mEnabled; | 202 | return mEnabled; |
201 | } | 203 | } |
202 | 204 | ||
203 | void CalFilter::setCriteria(int criteria) | 205 | void CalFilter::setCriteria(int criteria) |
204 | { | 206 | { |
205 | mCriteria = criteria; | 207 | mCriteria = criteria; |
206 | } | 208 | } |
207 | 209 | ||
208 | int CalFilter::criteria() | 210 | int CalFilter::criteria() |
209 | { | 211 | { |
210 | return mCriteria; | 212 | return mCriteria; |
211 | } | 213 | } |
212 | 214 | ||
213 | void CalFilter::setCategoryList(const QStringList &categoryList) | 215 | void CalFilter::setCategoryList(const QStringList &categoryList) |
214 | { | 216 | { |
215 | mCategoryList = categoryList; | 217 | mCategoryList = categoryList; |
216 | } | 218 | } |
217 | 219 | ||
218 | QStringList CalFilter::categoryList() | 220 | QStringList CalFilter::categoryList() |
219 | { | 221 | { |
220 | return mCategoryList; | 222 | return mCategoryList; |
221 | } | 223 | } |
diff --git a/libkcal/calfilter.h b/libkcal/calfilter.h index e349770..821149f 100644 --- a/libkcal/calfilter.h +++ b/libkcal/calfilter.h | |||
@@ -1,130 +1,130 @@ | |||
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 _CALFILTER_H | 21 | #ifndef _CALFILTER_H |
22 | #define _CALFILTER_H | 22 | #define _CALFILTER_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <q3ptrlist.h> |
26 | 26 | ||
27 | #include "event.h" | 27 | #include "event.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | #include "journal.h" | 29 | #include "journal.h" |
30 | 30 | ||
31 | namespace KCal { | 31 | namespace KCal { |
32 | 32 | ||
33 | /** | 33 | /** |
34 | Filter for calendar objects. | 34 | Filter for calendar objects. |
35 | */ | 35 | */ |
36 | class CalFilter { | 36 | class CalFilter { |
37 | public: | 37 | public: |
38 | /** Construct filter. */ | 38 | /** Construct filter. */ |
39 | CalFilter(); | 39 | CalFilter(); |
40 | /** Construct filter with name */ | 40 | /** Construct filter with name */ |
41 | CalFilter(const QString &name); | 41 | CalFilter(const QString &name); |
42 | /** Destruct filter. */ | 42 | /** Destruct filter. */ |
43 | ~CalFilter(); | 43 | ~CalFilter(); |
44 | 44 | ||
45 | /** | 45 | /** |
46 | Set name of filter. | 46 | Set name of filter. |
47 | */ | 47 | */ |
48 | void setName(const QString &name) { mName = name; } | 48 | void setName(const QString &name) { mName = name; } |
49 | /** | 49 | /** |
50 | Return name of filter. | 50 | Return name of filter. |
51 | */ | 51 | */ |
52 | QString name() const { return mName; } | 52 | QString name() const { return mName; } |
53 | 53 | ||
54 | /** | 54 | /** |
55 | Apply filter to eventlist, all events not matching filter criterias are | 55 | Apply filter to eventlist, all events not matching filter criterias are |
56 | removed from the list. | 56 | removed from the list. |
57 | */ | 57 | */ |
58 | void apply(QPtrList<Event> *eventlist); | 58 | void apply(Q3PtrList<Event> *eventlist); |
59 | 59 | ||
60 | /** | 60 | /** |
61 | Apply filter to todolist, all todos not matching filter criterias are | 61 | Apply filter to todolist, all todos not matching filter criterias are |
62 | removed from the list. | 62 | removed from the list. |
63 | */ | 63 | */ |
64 | void apply(QPtrList<Todo> *todolist); | 64 | void apply(Q3PtrList<Todo> *todolist); |
65 | bool CalFilter::filterCalendarItem(Incidence *in); | 65 | bool filterCalendarItem(Incidence *in); |
66 | bool CalFilter::filterJournal(Journal *in); | 66 | bool filterJournal(Journal *in); |
67 | /** | 67 | /** |
68 | Apply filter criteria on the specified event. Return true, if event passes | 68 | Apply filter criteria on the specified event. Return true, if event passes |
69 | criteria, otherwise return false. | 69 | criteria, otherwise return false. |
70 | */ | 70 | */ |
71 | bool filterEvent(Event *); | 71 | bool filterEvent(Event *); |
72 | 72 | ||
73 | /** | 73 | /** |
74 | Apply filter criteria on the specified todo. Return true, if event passes | 74 | Apply filter criteria on the specified todo. Return true, if event passes |
75 | criteria, otherwise return false. | 75 | criteria, otherwise return false. |
76 | */ | 76 | */ |
77 | bool filterTodo(Todo *); | 77 | bool filterTodo(Todo *); |
78 | 78 | ||
79 | /** | 79 | /** |
80 | Apply filter criteria on the specified incidence. Return true, if event passes | 80 | Apply filter criteria on the specified incidence. Return true, if event passes |
81 | criteria, otherwise return false. | 81 | criteria, otherwise return false. |
82 | */ | 82 | */ |
83 | bool filterIncidence(Incidence *); | 83 | bool filterIncidence(Incidence *); |
84 | 84 | ||
85 | /** | 85 | /** |
86 | Enable or disable filter. | 86 | Enable or disable filter. |
87 | */ | 87 | */ |
88 | void setEnabled(bool); | 88 | void setEnabled(bool); |
89 | /** | 89 | /** |
90 | Return wheter the filter is enabled or not. | 90 | Return wheter the filter is enabled or not. |
91 | */ | 91 | */ |
92 | bool isEnabled(); | 92 | bool isEnabled(); |
93 | bool showCategories(); | 93 | bool showCategories(); |
94 | int getSecrecy(); | 94 | int getSecrecy(); |
95 | /** | 95 | /** |
96 | Set list of categories, which is used for showing/hiding categories of | 96 | Set list of categories, which is used for showing/hiding categories of |
97 | events. | 97 | events. |
98 | See related functions. | 98 | See related functions. |
99 | */ | 99 | */ |
100 | void setCategoryList(const QStringList &); | 100 | void setCategoryList(const QStringList &); |
101 | /** | 101 | /** |
102 | Return category list, used for showing/hiding categories of events. | 102 | Return category list, used for showing/hiding categories of events. |
103 | See related functions. | 103 | See related functions. |
104 | */ | 104 | */ |
105 | QStringList categoryList(); | 105 | QStringList categoryList(); |
106 | 106 | ||
107 | enum { HideRecurring = 1, HideCompleted = 2, ShowCategories = 4 ,ShowPublic = 8, ShowPrivate = 16, ShowConfidential = 32, HideEvents = 64, HideTodos = 128, HideJournals = 256 }; | 107 | enum { HideRecurring = 1, HideCompleted = 2, ShowCategories = 4 ,ShowPublic = 8, ShowPrivate = 16, ShowConfidential = 32, HideEvents = 64, HideTodos = 128, HideJournals = 256 }; |
108 | 108 | ||
109 | /** | 109 | /** |
110 | Set criteria, which have to be fulfilled by events passing the filter. | 110 | Set criteria, which have to be fulfilled by events passing the filter. |
111 | */ | 111 | */ |
112 | void setCriteria(int); | 112 | void setCriteria(int); |
113 | /** | 113 | /** |
114 | Get inclusive filter criteria. | 114 | Get inclusive filter criteria. |
115 | */ | 115 | */ |
116 | int criteria(); | 116 | int criteria(); |
117 | 117 | ||
118 | private: | 118 | private: |
119 | QString mName; | 119 | QString mName; |
120 | 120 | ||
121 | int mCriteria; | 121 | int mCriteria; |
122 | 122 | ||
123 | bool mEnabled; | 123 | bool mEnabled; |
124 | 124 | ||
125 | QStringList mCategoryList; | 125 | QStringList mCategoryList; |
126 | }; | 126 | }; |
127 | 127 | ||
128 | } | 128 | } |
129 | 129 | ||
130 | #endif /* _CALFILTER_H */ | 130 | #endif /* _CALFILTER_H */ |
diff --git a/libkcal/customproperties.cpp b/libkcal/customproperties.cpp index adc1710..16f4a28 100644 --- a/libkcal/customproperties.cpp +++ b/libkcal/customproperties.cpp | |||
@@ -1,114 +1,116 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> | 3 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> |
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 "customproperties.h" | 21 | #include "customproperties.h" |
22 | //Added by qt3to4: | ||
23 | #include <Q3CString> | ||
22 | 24 | ||
23 | using namespace KCal; | 25 | using namespace KCal; |
24 | 26 | ||
25 | CustomProperties::CustomProperties() | 27 | CustomProperties::CustomProperties() |
26 | { | 28 | { |
27 | } | 29 | } |
28 | 30 | ||
29 | CustomProperties::CustomProperties(const CustomProperties &cp) | 31 | CustomProperties::CustomProperties(const CustomProperties &cp) |
30 | : mProperties(cp.mProperties) | 32 | : mProperties(cp.mProperties) |
31 | { | 33 | { |
32 | } | 34 | } |
33 | 35 | ||
34 | CustomProperties::~CustomProperties() | 36 | CustomProperties::~CustomProperties() |
35 | { | 37 | { |
36 | } | 38 | } |
37 | 39 | ||
38 | void CustomProperties::setCustomProperty(const QCString &app, const QCString &key, | 40 | void CustomProperties::setCustomProperty(const Q3CString &app, const Q3CString &key, |
39 | const QString &value) | 41 | const QString &value) |
40 | { | 42 | { |
41 | if (value.isNull() || key.isEmpty() || app.isEmpty()) | 43 | if (value.isNull() || key.isEmpty() || app.isEmpty()) |
42 | return; | 44 | return; |
43 | QCString property = "X-KDE-" + app + "-" + key; | 45 | Q3CString property = "X-KDE-" + app + "-" + key; |
44 | if (!checkName(property)) | 46 | if (!checkName(property)) |
45 | return; | 47 | return; |
46 | mProperties[property] = value; | 48 | mProperties[property] = value; |
47 | } | 49 | } |
48 | 50 | ||
49 | void CustomProperties::removeCustomProperty(const QCString &app, const QCString &key) | 51 | void CustomProperties::removeCustomProperty(const Q3CString &app, const Q3CString &key) |
50 | { | 52 | { |
51 | removeNonKDECustomProperty(QCString("X-KDE-" + app + "-" + key)); | 53 | removeNonKDECustomProperty(Q3CString("X-KDE-" + app + "-" + key)); |
52 | } | 54 | } |
53 | 55 | ||
54 | QString CustomProperties::customProperty(const QCString &app, const QCString &key) const | 56 | QString CustomProperties::customProperty(const Q3CString &app, const Q3CString &key) const |
55 | { | 57 | { |
56 | return nonKDECustomProperty(QCString("X-KDE-" + app + "-" + key)); | 58 | return nonKDECustomProperty(Q3CString("X-KDE-" + app + "-" + key)); |
57 | } | 59 | } |
58 | 60 | ||
59 | void CustomProperties::setNonKDECustomProperty(const QCString &name, const QString &value) | 61 | void CustomProperties::setNonKDECustomProperty(const Q3CString &name, const QString &value) |
60 | { | 62 | { |
61 | if (value.isNull() || !checkName(name)) | 63 | if (value.isNull() || !checkName(name)) |
62 | return; | 64 | return; |
63 | mProperties[name] = value; | 65 | mProperties[name] = value; |
64 | } | 66 | } |
65 | 67 | ||
66 | void CustomProperties::removeNonKDECustomProperty(const QCString &name) | 68 | void CustomProperties::removeNonKDECustomProperty(const Q3CString &name) |
67 | { | 69 | { |
68 | QMap<QCString, QString>::Iterator it = mProperties.find(name); | 70 | QMap<Q3CString, QString>::Iterator it = mProperties.find(name); |
69 | if (it != mProperties.end()) | 71 | if (it != mProperties.end()) |
70 | mProperties.remove(it); | 72 | mProperties.remove(it); |
71 | } | 73 | } |
72 | 74 | ||
73 | QString CustomProperties::nonKDECustomProperty(const QCString &name) const | 75 | QString CustomProperties::nonKDECustomProperty(const Q3CString &name) const |
74 | { | 76 | { |
75 | QMap<QCString, QString>::ConstIterator it = mProperties.find(name); | 77 | QMap<Q3CString, QString>::ConstIterator it = mProperties.find(name); |
76 | if (it == mProperties.end()) | 78 | if (it == mProperties.end()) |
77 | return QString::null; | 79 | return QString::null; |
78 | return it.data(); | 80 | return it.data(); |
79 | } | 81 | } |
80 | 82 | ||
81 | void CustomProperties::setCustomProperties(const QMap<QCString, QString> &properties) | 83 | void CustomProperties::setCustomProperties(const QMap<Q3CString, QString> &properties) |
82 | { | 84 | { |
83 | for (QMap<QCString, QString>::ConstIterator it = properties.begin(); it != properties.end(); ++it) { | 85 | for (QMap<Q3CString, QString>::ConstIterator it = properties.begin(); it != properties.end(); ++it) { |
84 | // Validate the property name and convert any null string to empty string | 86 | // Validate the property name and convert any null string to empty string |
85 | if (checkName(it.key())) { | 87 | if (checkName(it.key())) { |
86 | mProperties[it.key()] = it.data().isNull() ? QString("") : it.data(); | 88 | mProperties[it.key()] = it.data().isNull() ? QString("") : it.data(); |
87 | } | 89 | } |
88 | } | 90 | } |
89 | } | 91 | } |
90 | 92 | ||
91 | QMap<QCString, QString> CustomProperties::customProperties() const | 93 | QMap<Q3CString, QString> CustomProperties::customProperties() const |
92 | { | 94 | { |
93 | return mProperties; | 95 | return mProperties; |
94 | } | 96 | } |
95 | 97 | ||
96 | bool CustomProperties::checkName(const QCString &name) | 98 | bool CustomProperties::checkName(const Q3CString &name) |
97 | { | 99 | { |
98 | // Check that the property name starts with 'X-' and contains | 100 | // Check that the property name starts with 'X-' and contains |
99 | // only the permitted characters | 101 | // only the permitted characters |
100 | const char* n = name; | 102 | const char* n = name; |
101 | int len = name.length(); | 103 | int len = name.length(); |
102 | if (len < 2 || n[0] != 'X' || n[1] != '-') | 104 | if (len < 2 || n[0] != 'X' || n[1] != '-') |
103 | return false; | 105 | return false; |
104 | for (int i = 2; i < len; ++i) { | 106 | for (int i = 2; i < len; ++i) { |
105 | char ch = n[i]; | 107 | char ch = n[i]; |
106 | if (ch >= 'A' && ch <= 'Z' | 108 | if (ch >= 'A' && ch <= 'Z' |
107 | || ch >= 'a' && ch <= 'z' | 109 | || ch >= 'a' && ch <= 'z' |
108 | || ch >= '0' && ch <= '9' | 110 | || ch >= '0' && ch <= '9' |
109 | || ch == '-') | 111 | || ch == '-') |
110 | continue; | 112 | continue; |
111 | return false; // invalid character found | 113 | return false; // invalid character found |
112 | } | 114 | } |
113 | return true; | 115 | return true; |
114 | } | 116 | } |
diff --git a/libkcal/customproperties.h b/libkcal/customproperties.h index 0cbfdcd..75eb3ad 100644 --- a/libkcal/customproperties.h +++ b/libkcal/customproperties.h | |||
@@ -1,97 +1,99 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> | 3 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> |
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 KCAL_CUSTOM_PROPERTIES_H | 21 | #ifndef KCAL_CUSTOM_PROPERTIES_H |
22 | #define KCAL_CUSTOM_PROPERTIES_H | 22 | #define KCAL_CUSTOM_PROPERTIES_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qmap.h> | 25 | #include <qmap.h> |
26 | //Added by qt3to4: | ||
27 | #include <Q3CString> | ||
26 | 28 | ||
27 | namespace KCal { | 29 | namespace KCal { |
28 | 30 | ||
29 | /** | 31 | /** |
30 | This class represents custom calendar properties. | 32 | This class represents custom calendar properties. |
31 | It is used as a base class for classes which represent calendar components. | 33 | It is used as a base class for classes which represent calendar components. |
32 | A custom property name written by libkcal has the form X-KDE-APP-KEY where | 34 | A custom property name written by libkcal has the form X-KDE-APP-KEY where |
33 | APP represents the application name, and KEY distinguishes individual | 35 | APP represents the application name, and KEY distinguishes individual |
34 | properties for the application. | 36 | properties for the application. |
35 | In keeping with RFC2445, property names must be composed only of the | 37 | In keeping with RFC2445, property names must be composed only of the |
36 | characters A-Z, a-z, 0-9 and '-'. | 38 | characters A-Z, a-z, 0-9 and '-'. |
37 | */ | 39 | */ |
38 | class CustomProperties | 40 | class CustomProperties |
39 | { | 41 | { |
40 | public: | 42 | public: |
41 | /** Construct a new empty custom properties instance */ | 43 | /** Construct a new empty custom properties instance */ |
42 | CustomProperties(); | 44 | CustomProperties(); |
43 | CustomProperties(const CustomProperties &); | 45 | CustomProperties(const CustomProperties &); |
44 | ~CustomProperties(); | 46 | ~CustomProperties(); |
45 | 47 | ||
46 | /** Create or modify a custom calendar property. | 48 | /** Create or modify a custom calendar property. |
47 | @param app Application name as it appears in the custom property name. | 49 | @param app Application name as it appears in the custom property name. |
48 | @param key Property identifier specific to the application. | 50 | @param key Property identifier specific to the application. |
49 | @param value The property's value. A call with a value of QString::null | 51 | @param value The property's value. A call with a value of QString::null |
50 | will be ignored. | 52 | will be ignored. |
51 | */ | 53 | */ |
52 | void setCustomProperty(const QCString &app, const QCString &key, | 54 | void setCustomProperty(const Q3CString &app, const Q3CString &key, |
53 | const QString &value); | 55 | const QString &value); |
54 | /** Delete a custom calendar property. | 56 | /** Delete a custom calendar property. |
55 | @param app Application name as it appears in the custom property name. | 57 | @param app Application name as it appears in the custom property name. |
56 | @param key Property identifier specific to the application. | 58 | @param key Property identifier specific to the application. |
57 | */ | 59 | */ |
58 | void removeCustomProperty(const QCString &app, const QCString &key); | 60 | void removeCustomProperty(const Q3CString &app, const Q3CString &key); |
59 | /** Return the value of a custom calendar property. | 61 | /** Return the value of a custom calendar property. |
60 | @param app Application name as it appears in the custom property name. | 62 | @param app Application name as it appears in the custom property name. |
61 | @param key Property identifier specific to the application. | 63 | @param key Property identifier specific to the application. |
62 | @return Property value, or QString::null if (and only if) the property does not exist. | 64 | @return Property value, or QString::null if (and only if) the property does not exist. |
63 | */ | 65 | */ |
64 | QString customProperty(const QCString &app, const QCString &key) const; | 66 | QString customProperty(const Q3CString &app, const Q3CString &key) const; |
65 | 67 | ||
66 | /** Create or modify a non-KDE or non-standard custom calendar property. | 68 | /** Create or modify a non-KDE or non-standard custom calendar property. |
67 | @param name Full property name | 69 | @param name Full property name |
68 | @param value The property's value. A call with a value of QString::null | 70 | @param value The property's value. A call with a value of QString::null |
69 | will be ignored. | 71 | will be ignored. |
70 | */ | 72 | */ |
71 | void setNonKDECustomProperty(const QCString &name, const QString &value); | 73 | void setNonKDECustomProperty(const Q3CString &name, const QString &value); |
72 | /** Delete a non-KDE or non-standard custom calendar property. | 74 | /** Delete a non-KDE or non-standard custom calendar property. |
73 | @param name Full property name | 75 | @param name Full property name |
74 | */ | 76 | */ |
75 | void removeNonKDECustomProperty(const QCString &name); | 77 | void removeNonKDECustomProperty(const Q3CString &name); |
76 | /** Return the value of a non-KDE or non-standard custom calendar property. | 78 | /** Return the value of a non-KDE or non-standard custom calendar property. |
77 | @param name Full property name | 79 | @param name Full property name |
78 | @return Property value, or QString::null if (and only if) the property does not exist. | 80 | @return Property value, or QString::null if (and only if) the property does not exist. |
79 | */ | 81 | */ |
80 | QString nonKDECustomProperty(const QCString& name) const; | 82 | QString nonKDECustomProperty(const Q3CString& name) const; |
81 | 83 | ||
82 | /** Initialise the alarm's custom calendar properties to the specified | 84 | /** Initialise the alarm's custom calendar properties to the specified |
83 | key/value pairs. | 85 | key/value pairs. |
84 | */ | 86 | */ |
85 | void setCustomProperties(const QMap<QCString, QString> &properties); | 87 | void setCustomProperties(const QMap<Q3CString, QString> &properties); |
86 | /** Return all custom calendar property key/value pairs. */ | 88 | /** Return all custom calendar property key/value pairs. */ |
87 | QMap<QCString, QString> customProperties() const; | 89 | QMap<Q3CString, QString> customProperties() const; |
88 | 90 | ||
89 | private: | 91 | private: |
90 | static bool checkName(const QCString& name); | 92 | static bool checkName(const Q3CString& name); |
91 | 93 | ||
92 | QMap<QCString, QString> mProperties; // custom calendar properties | 94 | QMap<Q3CString, QString> mProperties; // custom calendar properties |
93 | }; | 95 | }; |
94 | 96 | ||
95 | } | 97 | } |
96 | 98 | ||
97 | #endif | 99 | #endif |
diff --git a/libkcal/dndfactory.cpp b/libkcal/dndfactory.cpp index cdcfae4..ca7e212 100644 --- a/libkcal/dndfactory.cpp +++ b/libkcal/dndfactory.cpp | |||
@@ -1,186 +1,189 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brwon | 3 | Copyright (c) 1998 Preston Brwon |
4 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> |
5 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> | 5 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qapplication.h> | 23 | #include <qapplication.h> |
24 | #include <qclipboard.h> | 24 | #include <qclipboard.h> |
25 | //Added by qt3to4: | ||
26 | #include <QDropEvent> | ||
27 | #include <Q3PtrList> | ||
25 | 28 | ||
26 | #include <kiconloader.h> | 29 | #include <kiconloader.h> |
27 | #include <kdebug.h> | 30 | #include <kdebug.h> |
28 | #include <kmessagebox.h> | 31 | #include <kmessagebox.h> |
29 | #include <klocale.h> | 32 | #include <klocale.h> |
30 | 33 | ||
31 | #include "vcaldrag.h" | 34 | #include "vcaldrag.h" |
32 | #include "icaldrag.h" | 35 | #include "icaldrag.h" |
33 | #include "calendar.h" | 36 | #include "calendar.h" |
34 | #include "vcalformat.h" | 37 | #include "vcalformat.h" |
35 | #include "icalformat.h" | 38 | #include "icalformat.h" |
36 | #include "calendarlocal.h" | 39 | #include "calendarlocal.h" |
37 | 40 | ||
38 | #include "dndfactory.h" | 41 | #include "dndfactory.h" |
39 | 42 | ||
40 | using namespace KCal; | 43 | using namespace KCal; |
41 | 44 | ||
42 | DndFactory::DndFactory( Calendar *cal ) : | 45 | DndFactory::DndFactory( Calendar *cal ) : |
43 | mCalendar( cal ) | 46 | mCalendar( cal ) |
44 | { | 47 | { |
45 | } | 48 | } |
46 | 49 | ||
47 | ICalDrag *DndFactory::createDrag( Incidence *incidence, QWidget *owner ) | 50 | ICalDrag *DndFactory::createDrag( Incidence *incidence, QWidget *owner ) |
48 | { | 51 | { |
49 | CalendarLocal cal( mCalendar->timeZoneId() ); | 52 | CalendarLocal cal( mCalendar->timeZoneId() ); |
50 | Incidence *i = incidence->clone(); | 53 | Incidence *i = incidence->clone(); |
51 | cal.addIncidence( i ); | 54 | cal.addIncidence( i ); |
52 | 55 | ||
53 | ICalDrag *icd = new ICalDrag( &cal, owner ); | 56 | ICalDrag *icd = new ICalDrag( &cal, owner ); |
54 | if ( i->type() == "Event" ) | 57 | if ( i->type() == "Event" ) |
55 | icd->setPixmap( BarIcon( "appointment" ) ); | 58 | icd->setPixmap( BarIcon( "appointment" ) ); |
56 | else if ( i->type() == "Todo" ) | 59 | else if ( i->type() == "Todo" ) |
57 | icd->setPixmap( BarIcon( "todo" ) ); | 60 | icd->setPixmap( BarIcon( "todo" ) ); |
58 | 61 | ||
59 | return icd; | 62 | return icd; |
60 | } | 63 | } |
61 | 64 | ||
62 | Event *DndFactory::createDrop(QDropEvent *de) | 65 | Event *DndFactory::createDrop(QDropEvent *de) |
63 | { | 66 | { |
64 | kdDebug(5800) << "DndFactory::createDrop()" << endl; | 67 | kdDebug(5800) << "DndFactory::createDrop()" << endl; |
65 | 68 | ||
66 | CalendarLocal cal( mCalendar->timeZoneId() ); | 69 | CalendarLocal cal( mCalendar->timeZoneId() ); |
67 | 70 | ||
68 | if ( ICalDrag::decode( de, &cal ) || VCalDrag::decode( de, &cal ) ) { | 71 | if ( ICalDrag::decode( de, &cal ) || VCalDrag::decode( de, &cal ) ) { |
69 | de->accept(); | 72 | de->accept(); |
70 | 73 | ||
71 | QPtrList<Event> events = cal.events(); | 74 | Q3PtrList<Event> events = cal.events(); |
72 | if ( !events.isEmpty() ) { | 75 | if ( !events.isEmpty() ) { |
73 | Event *event = new Event( *events.first() ); | 76 | Event *event = new Event( *events.first() ); |
74 | return event; | 77 | return event; |
75 | } | 78 | } |
76 | } | 79 | } |
77 | 80 | ||
78 | return 0; | 81 | return 0; |
79 | } | 82 | } |
80 | 83 | ||
81 | Todo *DndFactory::createDropTodo(QDropEvent *de) | 84 | Todo *DndFactory::createDropTodo(QDropEvent *de) |
82 | { | 85 | { |
83 | kdDebug(5800) << "VCalFormat::createDropTodo()" << endl; | 86 | kdDebug(5800) << "VCalFormat::createDropTodo()" << endl; |
84 | 87 | ||
85 | CalendarLocal cal( mCalendar->timeZoneId() ); | 88 | CalendarLocal cal( mCalendar->timeZoneId() ); |
86 | 89 | ||
87 | if ( ICalDrag::decode( de, &cal ) || VCalDrag::decode( de, &cal ) ) { | 90 | if ( ICalDrag::decode( de, &cal ) || VCalDrag::decode( de, &cal ) ) { |
88 | de->accept(); | 91 | de->accept(); |
89 | 92 | ||
90 | QPtrList<Todo> todos = cal.todos(); | 93 | Q3PtrList<Todo> todos = cal.todos(); |
91 | if ( !todos.isEmpty() ) { | 94 | if ( !todos.isEmpty() ) { |
92 | Todo *todo = new Todo( *todos.first() ); | 95 | Todo *todo = new Todo( *todos.first() ); |
93 | return todo; | 96 | return todo; |
94 | } | 97 | } |
95 | } | 98 | } |
96 | 99 | ||
97 | return 0; | 100 | return 0; |
98 | } | 101 | } |
99 | 102 | ||
100 | 103 | ||
101 | void DndFactory::cutIncidence( Incidence *selectedInc ) | 104 | void DndFactory::cutIncidence( Incidence *selectedInc ) |
102 | { | 105 | { |
103 | if ( copyIncidence( selectedInc ) ) { | 106 | if ( copyIncidence( selectedInc ) ) { |
104 | mCalendar->deleteIncidence( selectedInc ); | 107 | mCalendar->deleteIncidence( selectedInc ); |
105 | } | 108 | } |
106 | } | 109 | } |
107 | 110 | ||
108 | bool DndFactory::copyIncidence( Incidence *selectedInc ) | 111 | bool DndFactory::copyIncidence( Incidence *selectedInc ) |
109 | { | 112 | { |
110 | if ( !selectedInc ) | 113 | if ( !selectedInc ) |
111 | return false; | 114 | return false; |
112 | QClipboard *cb = QApplication::clipboard(); | 115 | QClipboard *cb = QApplication::clipboard(); |
113 | 116 | ||
114 | CalendarLocal cal( mCalendar->timeZoneId() ); | 117 | CalendarLocal cal( mCalendar->timeZoneId() ); |
115 | Incidence *inc = selectedInc->clone(); | 118 | Incidence *inc = selectedInc->clone(); |
116 | cal.addIncidence( inc ); | 119 | cal.addIncidence( inc ); |
117 | cb->setData( new ICalDrag( &cal ) ); | 120 | cb->setData( new ICalDrag( &cal ) ); |
118 | 121 | ||
119 | return true; | 122 | return true; |
120 | } | 123 | } |
121 | 124 | ||
122 | Incidence *DndFactory::pasteIncidence(const QDate &newDate, const QTime *newTime) | 125 | Incidence *DndFactory::pasteIncidence(const QDate &newDate, const QTime *newTime) |
123 | { | 126 | { |
124 | // kdDebug(5800) << "DnDFactory::pasteEvent()" << endl; | 127 | // kdDebug(5800) << "DnDFactory::pasteEvent()" << endl; |
125 | 128 | ||
126 | CalendarLocal cal( mCalendar->timeZoneId() ); | 129 | CalendarLocal cal( mCalendar->timeZoneId() ); |
127 | 130 | ||
128 | QClipboard *cb = QApplication::clipboard(); | 131 | QClipboard *cb = QApplication::clipboard(); |
129 | 132 | ||
130 | if ( !ICalDrag::decode( cb->data(), &cal ) && | 133 | if ( !ICalDrag::decode( cb->data(), &cal ) && |
131 | !VCalDrag::decode( cb->data(), &cal ) ) { | 134 | !VCalDrag::decode( cb->data(), &cal ) ) { |
132 | kdDebug(5800) << "Can't parse clipboard" << endl; | 135 | kdDebug(5800) << "Can't parse clipboard" << endl; |
133 | return 0; | 136 | return 0; |
134 | } | 137 | } |
135 | 138 | ||
136 | QPtrList<Incidence> incList = cal.incidences(); | 139 | Q3PtrList<Incidence> incList = cal.incidences(); |
137 | Incidence *inc = incList.first(); | 140 | Incidence *inc = incList.first(); |
138 | 141 | ||
139 | if ( !incList.isEmpty() && inc ) { | 142 | if ( !incList.isEmpty() && inc ) { |
140 | inc = inc->clone(); | 143 | inc = inc->clone(); |
141 | 144 | ||
142 | inc->recreate(); | 145 | inc->recreate(); |
143 | 146 | ||
144 | if ( inc->type() == "Event" ) { | 147 | if ( inc->type() == "Event" ) { |
145 | 148 | ||
146 | Event *anEvent = static_cast<Event*>( inc ); | 149 | Event *anEvent = static_cast<Event*>( inc ); |
147 | // Calculate length of event | 150 | // Calculate length of event |
148 | int daysOffset = anEvent->dtStart().date().daysTo( | 151 | int daysOffset = anEvent->dtStart().date().daysTo( |
149 | anEvent->dtEnd().date() ); | 152 | anEvent->dtEnd().date() ); |
150 | // new end date if event starts at the same time on the new day | 153 | // new end date if event starts at the same time on the new day |
151 | QDateTime endDate( newDate.addDays(daysOffset), anEvent->dtEnd().time() ); | 154 | QDateTime endDate( newDate.addDays(daysOffset), anEvent->dtEnd().time() ); |
152 | 155 | ||
153 | if ( newTime ) { | 156 | if ( newTime ) { |
154 | // additional offset for new time of day | 157 | // additional offset for new time of day |
155 | int addSecsOffset( anEvent->dtStart().time().secsTo( *newTime )); | 158 | int addSecsOffset( anEvent->dtStart().time().secsTo( *newTime )); |
156 | endDate=endDate.addSecs( addSecsOffset ); | 159 | endDate=endDate.addSecs( addSecsOffset ); |
157 | anEvent->setDtStart( QDateTime( newDate, *newTime ) ); | 160 | anEvent->setDtStart( QDateTime( newDate, *newTime ) ); |
158 | } else { | 161 | } else { |
159 | anEvent->setDtStart( QDateTime( newDate, anEvent->dtStart().time() ) ); | 162 | anEvent->setDtStart( QDateTime( newDate, anEvent->dtStart().time() ) ); |
160 | } | 163 | } |
161 | anEvent->setDtEnd( endDate ); | 164 | anEvent->setDtEnd( endDate ); |
162 | 165 | ||
163 | } else if ( inc->type() == "Todo" ) { | 166 | } else if ( inc->type() == "Todo" ) { |
164 | Todo *anTodo = static_cast<Todo*>( inc ); | 167 | Todo *anTodo = static_cast<Todo*>( inc ); |
165 | if ( newTime ) { | 168 | if ( newTime ) { |
166 | anTodo->setDtDue( QDateTime( newDate, *newTime ) ); | 169 | anTodo->setDtDue( QDateTime( newDate, *newTime ) ); |
167 | } else { | 170 | } else { |
168 | anTodo->setDtDue( QDateTime( newDate, anTodo->dtDue().time() ) ); | 171 | anTodo->setDtDue( QDateTime( newDate, anTodo->dtDue().time() ) ); |
169 | } | 172 | } |
170 | } else if ( inc->type() == "Journal" ) { | 173 | } else if ( inc->type() == "Journal" ) { |
171 | Journal *anJournal = static_cast<Journal*>( inc ); | 174 | Journal *anJournal = static_cast<Journal*>( inc ); |
172 | if ( newTime ) { | 175 | if ( newTime ) { |
173 | anJournal->setDtStart( QDateTime( newDate, *newTime ) ); | 176 | anJournal->setDtStart( QDateTime( newDate, *newTime ) ); |
174 | } else { | 177 | } else { |
175 | anJournal->setDtStart( QDateTime( newDate ) ); | 178 | anJournal->setDtStart( QDateTime( newDate ) ); |
176 | } | 179 | } |
177 | } else { | 180 | } else { |
178 | kdDebug(5850) << "Trying to paste unknown incidence of type " << inc->type() << endl; | 181 | kdDebug(5850) << "Trying to paste unknown incidence of type " << inc->type() << endl; |
179 | } | 182 | } |
180 | 183 | ||
181 | return inc; | 184 | return inc; |
182 | 185 | ||
183 | } | 186 | } |
184 | 187 | ||
185 | return 0; | 188 | return 0; |
186 | } | 189 | } |
diff --git a/libkcal/dndfactory.h b/libkcal/dndfactory.h index 2df5259..a873c37 100644 --- a/libkcal/dndfactory.h +++ b/libkcal/dndfactory.h | |||
@@ -1,83 +1,85 @@ | |||
1 | //Added by qt3to4: | ||
2 | #include <QDropEvent> | ||
1 | /* | 3 | /* |
2 | This file is part of libkcal. | 4 | This file is part of libkcal. |
3 | 5 | ||
4 | Copyright (c) 1998 Preston Brown | 6 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> | 7 | Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> | 8 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> |
7 | 9 | ||
8 | This library is free software; you can redistribute it and/or | 10 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public | 11 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either | 12 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. | 13 | version 2 of the License, or (at your option) any later version. |
12 | 14 | ||
13 | This library is distributed in the hope that it will be useful, | 15 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. | 18 | Library General Public License for more details. |
17 | 19 | ||
18 | You should have received a copy of the GNU Library General Public License | 20 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to | 21 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 22 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. | 23 | Boston, MA 02111-1307, USA. |
22 | */ | 24 | */ |
23 | 25 | ||
24 | #ifdef DESKTOP_VERSION | 26 | #ifdef DESKTOP_VERSION |
25 | 27 | ||
26 | #ifndef KCAL_DNDFACTORY_H | 28 | #ifndef KCAL_DNDFACTORY_H |
27 | #define KCAL_DNDFACTORY_H | 29 | #define KCAL_DNDFACTORY_H |
28 | 30 | ||
29 | //#include "libkcal_export.h" | 31 | //#include "libkcal_export.h" |
30 | 32 | ||
31 | namespace KCal { | 33 | namespace KCal { |
32 | 34 | ||
33 | class ICalDrag; | 35 | class ICalDrag; |
34 | class Event; | 36 | class Event; |
35 | class Todo; | 37 | class Todo; |
36 | class Calendar; | 38 | class Calendar; |
37 | #define LIBKCAL_EXPORT | 39 | #define LIBKCAL_EXPORT |
38 | 40 | ||
39 | /** | 41 | /** |
40 | This class implements functions to create Drag and Drop objects used for | 42 | This class implements functions to create Drag and Drop objects used for |
41 | Drag-and-Drop and Copy-and-Paste. | 43 | Drag-and-Drop and Copy-and-Paste. |
42 | 44 | ||
43 | @short vCalendar/iCalendar Drag-and-Drop object factory. | 45 | @short vCalendar/iCalendar Drag-and-Drop object factory. |
44 | */ | 46 | */ |
45 | class LIBKCAL_EXPORT DndFactory | 47 | class LIBKCAL_EXPORT DndFactory |
46 | { | 48 | { |
47 | public: | 49 | public: |
48 | DndFactory( Calendar * ); | 50 | DndFactory( Calendar * ); |
49 | 51 | ||
50 | /** | 52 | /** |
51 | Create a drag object. | 53 | Create a drag object. |
52 | */ | 54 | */ |
53 | ICalDrag *createDrag( Incidence *incidence, QWidget *owner ); | 55 | ICalDrag *createDrag( Incidence *incidence, QWidget *owner ); |
54 | 56 | ||
55 | /** Create Todo object from drop event */ | 57 | /** Create Todo object from drop event */ |
56 | Todo *createDropTodo(QDropEvent *de); | 58 | Todo *createDropTodo(QDropEvent *de); |
57 | /** Create Event object from drop event */ | 59 | /** Create Event object from drop event */ |
58 | Event *createDrop(QDropEvent *de); | 60 | Event *createDrop(QDropEvent *de); |
59 | 61 | ||
60 | /** cut incidence to clipboard */ | 62 | /** cut incidence to clipboard */ |
61 | void cutIncidence( Incidence * ); | 63 | void cutIncidence( Incidence * ); |
62 | /** copy the incidence to clipboard */ | 64 | /** copy the incidence to clipboard */ |
63 | bool copyIncidence( Incidence * ); | 65 | bool copyIncidence( Incidence * ); |
64 | /** pastes the event or todo and returns a pointer to the new incidence pasted. */ | 66 | /** pastes the event or todo and returns a pointer to the new incidence pasted. */ |
65 | Incidence *pasteIncidence( const QDate &, const QTime *newTime = 0 ); | 67 | Incidence *pasteIncidence( const QDate &, const QTime *newTime = 0 ); |
66 | 68 | ||
67 | private: | 69 | private: |
68 | Calendar *mCalendar; | 70 | Calendar *mCalendar; |
69 | 71 | ||
70 | class Private; | 72 | class Private; |
71 | Private *d; | 73 | Private *d; |
72 | }; | 74 | }; |
73 | 75 | ||
74 | } | 76 | } |
75 | 77 | ||
76 | #endif | 78 | #endif |
77 | 79 | ||
78 | #else // dummy implementation for embedded | 80 | #else // dummy implementation for embedded |
79 | #include "dndfactory_dummy.h" | 81 | #include "dndfactory_dummy.h" |
80 | #define cutIncidence cutEvent | 82 | #define cutIncidence cutEvent |
81 | #define pasteIncidence pasteEvent | 83 | #define pasteIncidence pasteEvent |
82 | #define copyIncidence copyEvent | 84 | #define copyIncidence copyEvent |
83 | #endif | 85 | #endif |
diff --git a/libkcal/dndfactory_dummy.h b/libkcal/dndfactory_dummy.h index 44cc114..3ab6adf 100644 --- a/libkcal/dndfactory_dummy.h +++ b/libkcal/dndfactory_dummy.h | |||
@@ -1,65 +1,67 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | // $Id$ | 22 | // $Id$ |
23 | 23 | ||
24 | #ifndef KCAL_DNDFACTORY_H | 24 | #ifndef KCAL_DNDFACTORY_H |
25 | #define KCAL_DNDFACTORY_H | 25 | #define KCAL_DNDFACTORY_H |
26 | 26 | ||
27 | #include "vcalformat.h" | 27 | #include "vcalformat.h" |
28 | //Added by qt3to4: | ||
29 | #include <QDropEvent> | ||
28 | 30 | ||
29 | class QDropEvent; | 31 | class QDropEvent; |
30 | 32 | ||
31 | namespace KCal { | 33 | namespace KCal { |
32 | 34 | ||
33 | /** | 35 | /** |
34 | This class implements functions to create Drag and Drop objects used for | 36 | This class implements functions to create Drag and Drop objects used for |
35 | Drag-and-Drop and Copy-and-Paste. | 37 | Drag-and-Drop and Copy-and-Paste. |
36 | 38 | ||
37 | @short vCalendar Drag-and-Drop object factory. | 39 | @short vCalendar Drag-and-Drop object factory. |
38 | */ | 40 | */ |
39 | class DndFactory { | 41 | class DndFactory { |
40 | public: | 42 | public: |
41 | DndFactory( Calendar * ) {} | 43 | DndFactory( Calendar * ) {} |
42 | 44 | ||
43 | /** create an object to be used with the Xdnd Drag And Drop protocol. */ | 45 | /** create an object to be used with the Xdnd Drag And Drop protocol. */ |
44 | ICalDrag *createDrag(Event *, QWidget *) { return 0; } | 46 | ICalDrag *createDrag(Event *, QWidget *) { return 0; } |
45 | /** create an object to be used with the Xdnd Drag And Drop protocol. */ | 47 | /** create an object to be used with the Xdnd Drag And Drop protocol. */ |
46 | ICalDrag *createDragTodo(Todo *, QWidget *) { return 0; } | 48 | ICalDrag *createDragTodo(Todo *, QWidget *) { return 0; } |
47 | /** Create Todo object from drop event */ | 49 | /** Create Todo object from drop event */ |
48 | Todo *createDropTodo(QDropEvent *) { return 0; } | 50 | Todo *createDropTodo(QDropEvent *) { return 0; } |
49 | /** Create Event object from drop event */ | 51 | /** Create Event object from drop event */ |
50 | Event *createDrop(QDropEvent *) { return 0; } | 52 | Event *createDrop(QDropEvent *) { return 0; } |
51 | 53 | ||
52 | /** cut event to clipboard */ | 54 | /** cut event to clipboard */ |
53 | void cutEvent(Event *) {} | 55 | void cutEvent(Event *) {} |
54 | /** cut, copy, and paste operations follow. */ | 56 | /** cut, copy, and paste operations follow. */ |
55 | bool copyEvent(Event *) { return false; } | 57 | bool copyEvent(Event *) { return false; } |
56 | /** pastes the event and returns a pointer to the new event pasted. */ | 58 | /** pastes the event and returns a pointer to the new event pasted. */ |
57 | Event *pasteEvent(const QDate &, const QTime *newTime = 0) { | 59 | Event *pasteEvent(const QDate &, const QTime *newTime = 0) { |
58 | Q_UNUSED( newTime ); | 60 | Q_UNUSED( newTime ); |
59 | return 0; | 61 | return 0; |
60 | } | 62 | } |
61 | }; | 63 | }; |
62 | 64 | ||
63 | } | 65 | } |
64 | 66 | ||
65 | #endif | 67 | #endif |
diff --git a/libkcal/dummyscheduler.cpp b/libkcal/dummyscheduler.cpp index ae40e6d..73eb3d0 100644 --- a/libkcal/dummyscheduler.cpp +++ b/libkcal/dummyscheduler.cpp | |||
@@ -1,119 +1,121 @@ | |||
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 | // | 21 | // |
22 | // DummyScheduler - iMIP implementation of iTIP methods | 22 | // DummyScheduler - iMIP implementation of iTIP methods |
23 | // | 23 | // |
24 | 24 | ||
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qtextstream.h> | 26 | #include <q3textstream.h> |
27 | //Added by qt3to4: | ||
28 | #include <Q3PtrList> | ||
27 | 29 | ||
28 | #include <kdebug.h> | 30 | #include <kdebug.h> |
29 | 31 | ||
30 | #include "event.h" | 32 | #include "event.h" |
31 | #include "icalformat.h" | 33 | #include "icalformat.h" |
32 | 34 | ||
33 | #include "dummyscheduler.h" | 35 | #include "dummyscheduler.h" |
34 | 36 | ||
35 | using namespace KCal; | 37 | using namespace KCal; |
36 | 38 | ||
37 | DummyScheduler::DummyScheduler(Calendar *calendar) | 39 | DummyScheduler::DummyScheduler(Calendar *calendar) |
38 | : Scheduler(calendar) | 40 | : Scheduler(calendar) |
39 | { | 41 | { |
40 | } | 42 | } |
41 | 43 | ||
42 | DummyScheduler::~DummyScheduler() | 44 | DummyScheduler::~DummyScheduler() |
43 | { | 45 | { |
44 | } | 46 | } |
45 | 47 | ||
46 | bool DummyScheduler::publish (IncidenceBase *incidence,const QString &recipients) | 48 | bool DummyScheduler::publish (IncidenceBase *incidence,const QString &recipients) |
47 | { | 49 | { |
48 | QString messageText = mFormat->createScheduleMessage(incidence, | 50 | QString messageText = mFormat->createScheduleMessage(incidence, |
49 | Scheduler::Publish); | 51 | Scheduler::Publish); |
50 | 52 | ||
51 | return saveMessage(messageText); | 53 | return saveMessage(messageText); |
52 | } | 54 | } |
53 | 55 | ||
54 | bool DummyScheduler::performTransaction(IncidenceBase *incidence,Method method,const QString &recipients) | 56 | bool DummyScheduler::performTransaction(IncidenceBase *incidence,Method method,const QString &recipients) |
55 | { | 57 | { |
56 | QString messageText = mFormat->createScheduleMessage(incidence,method); | 58 | QString messageText = mFormat->createScheduleMessage(incidence,method); |
57 | 59 | ||
58 | return saveMessage(messageText); | 60 | return saveMessage(messageText); |
59 | } | 61 | } |
60 | 62 | ||
61 | bool DummyScheduler::performTransaction(IncidenceBase *incidence,Method method) | 63 | bool DummyScheduler::performTransaction(IncidenceBase *incidence,Method method) |
62 | { | 64 | { |
63 | QString messageText = mFormat->createScheduleMessage(incidence,method); | 65 | QString messageText = mFormat->createScheduleMessage(incidence,method); |
64 | 66 | ||
65 | return saveMessage(messageText); | 67 | return saveMessage(messageText); |
66 | } | 68 | } |
67 | 69 | ||
68 | bool DummyScheduler::saveMessage(const QString &message) | 70 | bool DummyScheduler::saveMessage(const QString &message) |
69 | { | 71 | { |
70 | QFile f("dummyscheduler.store"); | 72 | QFile f("dummyscheduler.store"); |
71 | if (f.open(IO_WriteOnly | IO_Append)) { | 73 | if (f.open(QIODevice::WriteOnly | QIODevice::Append)) { |
72 | QTextStream t(&f); | 74 | Q3TextStream t(&f); |
73 | t << message << endl; | 75 | t << message << endl; |
74 | f.close(); | 76 | f.close(); |
75 | return true; | 77 | return true; |
76 | } else { | 78 | } else { |
77 | return false; | 79 | return false; |
78 | } | 80 | } |
79 | } | 81 | } |
80 | 82 | ||
81 | QPtrList<ScheduleMessage> DummyScheduler::retrieveTransactions() | 83 | Q3PtrList<ScheduleMessage> DummyScheduler::retrieveTransactions() |
82 | { | 84 | { |
83 | QPtrList<ScheduleMessage> messageList; | 85 | Q3PtrList<ScheduleMessage> messageList; |
84 | 86 | ||
85 | QFile f("dummyscheduler.store"); | 87 | QFile f("dummyscheduler.store"); |
86 | if (!f.open(IO_ReadOnly)) { | 88 | if (!f.open(QIODevice::ReadOnly)) { |
87 | kdDebug(5800) << "DummyScheduler::retrieveTransactions(): Can't open file" | 89 | kdDebug(5800) << "DummyScheduler::retrieveTransactions(): Can't open file" |
88 | << endl; | 90 | << endl; |
89 | } else { | 91 | } else { |
90 | QTextStream t(&f); | 92 | Q3TextStream t(&f); |
91 | QString messageString; | 93 | QString messageString; |
92 | QString messageLine = t.readLine(); | 94 | QString messageLine = t.readLine(); |
93 | while (!messageLine.isNull()) { | 95 | while (!messageLine.isNull()) { |
94 | // kdDebug(5800) << "++++++++" << messageLine << endl; | 96 | // kdDebug(5800) << "++++++++" << messageLine << endl; |
95 | messageString += messageLine + "\n"; | 97 | messageString += messageLine + "\n"; |
96 | if (messageLine.find("END:VCALENDAR") >= 0) { | 98 | if (messageLine.find("END:VCALENDAR") >= 0) { |
97 | kdDebug(5800) << "---------------" << messageString << endl; | 99 | kdDebug(5800) << "---------------" << messageString << endl; |
98 | ScheduleMessage *message = mFormat->parseScheduleMessage(mCalendar, | 100 | ScheduleMessage *message = mFormat->parseScheduleMessage(mCalendar, |
99 | messageString); | 101 | messageString); |
100 | kdDebug(5800) << "--Parsed" << endl; | 102 | kdDebug(5800) << "--Parsed" << endl; |
101 | if (message) { | 103 | if (message) { |
102 | messageList.append(message); | 104 | messageList.append(message); |
103 | } else { | 105 | } else { |
104 | QString errorMessage; | 106 | QString errorMessage; |
105 | if (mFormat->exception()) { | 107 | if (mFormat->exception()) { |
106 | errorMessage = mFormat->exception()->message(); | 108 | errorMessage = mFormat->exception()->message(); |
107 | } | 109 | } |
108 | kdDebug(5800) << "DummyScheduler::retrieveTransactions() Error parsing " | 110 | kdDebug(5800) << "DummyScheduler::retrieveTransactions() Error parsing " |
109 | "message: " << errorMessage << endl; | 111 | "message: " << errorMessage << endl; |
110 | } | 112 | } |
111 | messageString=""; | 113 | messageString=""; |
112 | } | 114 | } |
113 | messageLine = t.readLine(); | 115 | messageLine = t.readLine(); |
114 | } | 116 | } |
115 | f.close(); | 117 | f.close(); |
116 | } | 118 | } |
117 | 119 | ||
118 | return messageList; | 120 | return messageList; |
119 | } | 121 | } |
diff --git a/libkcal/dummyscheduler.h b/libkcal/dummyscheduler.h index df42153..f86d583 100644 --- a/libkcal/dummyscheduler.h +++ b/libkcal/dummyscheduler.h | |||
@@ -1,51 +1,53 @@ | |||
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 DUMMYSCHEDULER_H | 20 | #ifndef DUMMYSCHEDULER_H |
21 | #define DUMMYSCHEDULER_H | 21 | #define DUMMYSCHEDULER_H |
22 | // | 22 | // |
23 | // Dummy implementation of iTIP methods | 23 | // Dummy implementation of iTIP methods |
24 | // | 24 | // |
25 | 25 | ||
26 | #include "scheduler.h" | 26 | #include "scheduler.h" |
27 | //Added by qt3to4: | ||
28 | #include <Q3PtrList> | ||
27 | 29 | ||
28 | namespace KCal { | 30 | namespace KCal { |
29 | 31 | ||
30 | /** | 32 | /** |
31 | This class implements the iTIP interface as a primitive local version for | 33 | This class implements the iTIP interface as a primitive local version for |
32 | testing. It uses a file dummyscheduler.store as inbox/outbox. | 34 | testing. It uses a file dummyscheduler.store as inbox/outbox. |
33 | */ | 35 | */ |
34 | class DummyScheduler : public Scheduler { | 36 | class DummyScheduler : public Scheduler { |
35 | public: | 37 | public: |
36 | DummyScheduler(Calendar *); | 38 | DummyScheduler(Calendar *); |
37 | virtual ~DummyScheduler(); | 39 | virtual ~DummyScheduler(); |
38 | 40 | ||
39 | bool publish (IncidenceBase *incidence,const QString &recipients); | 41 | bool publish (IncidenceBase *incidence,const QString &recipients); |
40 | bool performTransaction(IncidenceBase *incidence,Method method); | 42 | bool performTransaction(IncidenceBase *incidence,Method method); |
41 | bool performTransaction(IncidenceBase *incidence,Method method,const QString &recipients); | 43 | bool performTransaction(IncidenceBase *incidence,Method method,const QString &recipients); |
42 | QPtrList<ScheduleMessage> retrieveTransactions(); | 44 | Q3PtrList<ScheduleMessage> retrieveTransactions(); |
43 | 45 | ||
44 | protected: | 46 | protected: |
45 | bool saveMessage(const QString &); | 47 | bool saveMessage(const QString &); |
46 | }; | 48 | }; |
47 | 49 | ||
48 | } | 50 | } |
49 | 51 | ||
50 | #endif // DUMMYSCHEDULER_H | 52 | #endif // DUMMYSCHEDULER_H |
51 | 53 | ||
diff --git a/libkcal/event.cpp b/libkcal/event.cpp index fdf5657..060df81 100644 --- a/libkcal/event.cpp +++ b/libkcal/event.cpp | |||
@@ -1,424 +1,424 @@ | |||
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 | ||
27 | using namespace KCal; | 27 | using namespace KCal; |
28 | 28 | ||
29 | Event::Event() : | 29 | Event::Event() : |
30 | mHasEndDate( false ), mTransparency( Opaque ) | 30 | mHasEndDate( false ), mTransparency( Opaque ) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | Event::Event(const Event &e) : Incidence(e) | 34 | Event::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 | ||
41 | Event::~Event() | 41 | Event::~Event() |
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | Incidence *Event::clone() | 45 | Incidence *Event::clone() |
46 | { | 46 | { |
47 | return new Event(*this); | 47 | return new Event(*this); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool KCal::operator==( const Event& e1, const Event& e2 ) | 50 | bool 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 | ||
59 | bool Event::contains ( Event* from ) | 59 | bool 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 | ||
106 | void Event::setDtEnd(const QDateTime &dtEnd) | 106 | void 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 | ||
118 | QDateTime Event::dtEnd() const | 118 | QDateTime 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 | ||
126 | QString Event::dtEndTimeStr() const | 126 | QString Event::dtEndTimeStr() const |
127 | { | 127 | { |
128 | return KGlobal::locale()->formatTime(mDtEnd.time()); | 128 | return KGlobal::locale()->formatTime(mDtEnd.time()); |
129 | } | 129 | } |
130 | 130 | ||
131 | QString Event::dtEndDateStr(bool shortfmt) const | 131 | QString 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 | ||
136 | QString Event::dtEndStr(bool shortfmt) const | 136 | QString 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 | ||
141 | void Event::setHasEndDate(bool b) | 141 | void Event::setHasEndDate(bool b) |
142 | { | 142 | { |
143 | mHasEndDate = b; | 143 | mHasEndDate = b; |
144 | } | 144 | } |
145 | 145 | ||
146 | bool Event::hasEndDate() const | 146 | bool Event::hasEndDate() const |
147 | { | 147 | { |
148 | return mHasEndDate; | 148 | return mHasEndDate; |
149 | } | 149 | } |
150 | 150 | ||
151 | bool Event::isMultiDay() const | 151 | bool 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 | ||
157 | void Event::setTransparency(Event::Transparency transparency) | 157 | void 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 | ||
164 | Event::Transparency Event::transparency() const | 164 | Event::Transparency Event::transparency() const |
165 | { | 165 | { |
166 | return mTransparency; | 166 | return mTransparency; |
167 | } | 167 | } |
168 | 168 | ||
169 | void Event::setDuration(int seconds) | 169 | void Event::setDuration(int seconds) |
170 | { | 170 | { |
171 | setHasEndDate(false); | 171 | setHasEndDate(false); |
172 | Incidence::setDuration(seconds); | 172 | Incidence::setDuration(seconds); |
173 | } | 173 | } |
174 | bool Event::matchTime(QDateTime*startDT, QDateTime* endDT) | 174 | bool Event::matchTime(QDateTime*startDT, QDateTime* endDT) |
175 | { | 175 | { |
176 | if ( cancelled() ) return false; | 176 | if ( cancelled() ) return false; |
177 | if ( ! doesRecur() ) { | 177 | if ( ! doesRecur() ) { |
178 | if ( doesFloat() ) { | 178 | if ( doesFloat() ) { |
179 | if ( mDtEnd.addDays( 1 ) < *startDT) | 179 | if ( mDtEnd.addDays( 1 ) < *startDT) |
180 | return false; | 180 | return false; |
181 | if ( endDT && mDtStart > * endDT) | 181 | if ( endDT && mDtStart > * endDT) |
182 | return false; | 182 | return false; |
183 | } else { | 183 | } else { |
184 | if ( mDtEnd < *startDT ) | 184 | if ( mDtEnd < *startDT ) |
185 | return false; | 185 | return false; |
186 | if ( endDT && mDtStart > * endDT) | 186 | if ( endDT && mDtStart > * endDT) |
187 | return false; | 187 | return false; |
188 | } | 188 | } |
189 | } else { | 189 | } else { |
190 | if ( endDT && mDtStart > * endDT) | 190 | if ( endDT && mDtStart > * endDT) |
191 | return false; | 191 | return false; |
192 | } | 192 | } |
193 | return true; | 193 | return true; |
194 | } | 194 | } |
195 | bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) | 195 | bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) |
196 | { | 196 | { |
197 | if ( testEvent == this ) | 197 | if ( testEvent == this ) |
198 | return false; | 198 | return false; |
199 | if ( ! doesRecur() && !testEvent->doesRecur() ) { | 199 | if ( ! doesRecur() && !testEvent->doesRecur() ) { |
200 | QDateTime te; | 200 | QDateTime te; |
201 | if ( testEvent->doesFloat() ) | 201 | if ( testEvent->doesFloat() ) |
202 | te = testEvent->mDtEnd.addDays( 1 ); | 202 | te = testEvent->mDtEnd.addDays( 1 ); |
203 | else | 203 | else |
204 | te = testEvent->mDtEnd; | 204 | te = testEvent->mDtEnd; |
205 | QDateTime e; | 205 | QDateTime e; |
206 | if ( doesFloat() ) | 206 | if ( doesFloat() ) |
207 | e = mDtEnd.addDays( 1 ); | 207 | e = mDtEnd.addDays( 1 ); |
208 | else | 208 | else |
209 | e = mDtEnd; | 209 | e = mDtEnd; |
210 | if ( mDtStart < te && testEvent->mDtStart < e ) { | 210 | if ( mDtStart < te && testEvent->mDtStart < e ) { |
211 | if ( mDtStart < testEvent->mDtStart ) | 211 | if ( mDtStart < testEvent->mDtStart ) |
212 | *overlapDT = testEvent->mDtStart; | 212 | *overlapDT = testEvent->mDtStart; |
213 | else | 213 | else |
214 | *overlapDT = mDtStart; | 214 | *overlapDT = mDtStart; |
215 | if ( startDT ) | 215 | if ( startDT ) |
216 | return (*overlapDT >= *startDT ); | 216 | return (*overlapDT >= *startDT ); |
217 | return true; | 217 | return true; |
218 | } | 218 | } |
219 | return false; | 219 | return false; |
220 | } | 220 | } |
221 | if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { | 221 | if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { |
222 | if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) { | 222 | if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) { |
223 | // no need to test. times mismatch | 223 | // no need to test. times mismatch |
224 | //fprintf(stderr,"timi "); | 224 | //fprintf(stderr,"timi "); |
225 | return false; | 225 | return false; |
226 | } | 226 | } |
227 | } | 227 | } |
228 | Event *nonRecur = 0; | 228 | Event *nonRecur = 0; |
229 | Event *recurEvent = 0; | 229 | Event *recurEvent = 0; |
230 | if ( ! doesRecur() ) { | 230 | if ( ! doesRecur() ) { |
231 | nonRecur = this; | 231 | nonRecur = this; |
232 | recurEvent = testEvent; | 232 | recurEvent = testEvent; |
233 | } | 233 | } |
234 | else if ( !testEvent->doesRecur() ) { | 234 | else if ( !testEvent->doesRecur() ) { |
235 | nonRecur = testEvent; | 235 | nonRecur = testEvent; |
236 | recurEvent = this; | 236 | recurEvent = this; |
237 | } | 237 | } |
238 | if ( nonRecur ) { | 238 | if ( nonRecur ) { |
239 | QDateTime enr; | 239 | QDateTime enr; |
240 | if ( nonRecur->doesFloat() ) | 240 | if ( nonRecur->doesFloat() ) |
241 | enr = nonRecur->mDtEnd.addDays( 1 ); | 241 | enr = nonRecur->mDtEnd.addDays( 1 ); |
242 | else | 242 | else |
243 | enr = nonRecur->mDtEnd; | 243 | enr = nonRecur->mDtEnd; |
244 | if ( enr < recurEvent->mDtStart ) | 244 | if ( enr < recurEvent->mDtStart ) |
245 | return false; | 245 | return false; |
246 | if ( startDT && enr < *startDT ) | 246 | if ( startDT && enr < *startDT ) |
247 | return false; | 247 | return false; |
248 | 248 | ||
249 | int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); | 249 | int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); |
250 | if ( recurEvent->doesFloat() ) | 250 | if ( recurEvent->doesFloat() ) |
251 | recDuration += 86400; | 251 | recDuration += 86400; |
252 | bool ok = false; | 252 | bool ok = false; |
253 | QDateTime recStart; | 253 | QDateTime recStart; |
254 | if ( startDT ) { | 254 | if ( startDT ) { |
255 | recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); | 255 | recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); |
256 | } | 256 | } |
257 | if ( recStart.isValid() ) { | 257 | if ( recStart.isValid() ) { |
258 | //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); | 258 | //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); |
259 | recStart = recStart.addSecs( -300); | 259 | recStart = recStart.addSecs( -300); |
260 | } | 260 | } |
261 | else | 261 | else |
262 | recStart = recurEvent->mDtStart.addSecs( -300); | 262 | recStart = recurEvent->mDtStart.addSecs( -300); |
263 | ok = true; | 263 | ok = true; |
264 | 264 | ||
265 | while ( ok ) { | 265 | while ( ok ) { |
266 | recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); | 266 | recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); |
267 | if ( ok ) { | 267 | if ( ok ) { |
268 | if ( recStart > enr ) | 268 | if ( recStart > enr ) |
269 | return false; | 269 | return false; |
270 | QDateTime recEnd = recStart.addSecs( recDuration ); | 270 | QDateTime recEnd = recStart.addSecs( recDuration ); |
271 | if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { | 271 | if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { |
272 | if ( nonRecur->mDtStart < recStart ) | 272 | if ( nonRecur->mDtStart < recStart ) |
273 | *overlapDT = recStart; | 273 | *overlapDT = recStart; |
274 | else | 274 | else |
275 | *overlapDT = nonRecur->mDtStart; | 275 | *overlapDT = nonRecur->mDtStart; |
276 | if ( startDT ) { | 276 | if ( startDT ) { |
277 | if ( *overlapDT >= *startDT ) | 277 | if ( *overlapDT >= *startDT ) |
278 | return true; | 278 | return true; |
279 | } else | 279 | } else |
280 | return true; | 280 | return true; |
281 | } | 281 | } |
282 | } | 282 | } |
283 | } | 283 | } |
284 | return false; | 284 | return false; |
285 | } | 285 | } |
286 | if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { | 286 | if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { |
287 | if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { | 287 | if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { |
288 | bool found = false; | 288 | bool found = false; |
289 | uint i; | 289 | uint i; |
290 | for ( i=0; i< recurrence()->days().size();++i ) { | 290 | for ( i=0; i< recurrence()->days().size();++i ) { |
291 | found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) ); | 291 | found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) ); |
292 | } | 292 | } |
293 | if ( ! found ) { | 293 | if ( ! found ) { |
294 | //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1()); | 294 | //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1()); |
295 | return false; | 295 | return false; |
296 | } | 296 | } |
297 | 297 | ||
298 | } | 298 | } |
299 | } | 299 | } |
300 | bool ok = true; | 300 | bool ok = true; |
301 | QDateTime incidenceStart;// = mDtStart; | 301 | QDateTime incidenceStart;// = mDtStart; |
302 | QDateTime testincidenceStart;// = testEvent->mDtStart; | 302 | QDateTime testincidenceStart;// = testEvent->mDtStart; |
303 | if ( startDT ) { | 303 | if ( startDT ) { |
304 | incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); | 304 | incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); |
305 | testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); | 305 | testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); |
306 | } | 306 | } |
307 | if ( !testincidenceStart.isValid() ) | 307 | if ( !testincidenceStart.isValid() ) |
308 | testincidenceStart = testEvent->mDtStart; | 308 | testincidenceStart = testEvent->mDtStart; |
309 | if ( !incidenceStart.isValid() ) | 309 | if ( !incidenceStart.isValid() ) |
310 | incidenceStart = mDtStart; | 310 | incidenceStart = mDtStart; |
311 | int duration = mDtStart.secsTo( mDtEnd ); | 311 | int duration = mDtStart.secsTo( mDtEnd ); |
312 | if ( doesFloat() ) | 312 | if ( doesFloat() ) |
313 | duration += 86400; | 313 | duration += 86400; |
314 | int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); | 314 | int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); |
315 | if ( testEvent->doesFloat() ) | 315 | if ( testEvent->doesFloat() ) |
316 | testduration += 86400; | 316 | testduration += 86400; |
317 | bool computeThis = false; | 317 | bool computeThis = false; |
318 | if ( incidenceStart < testincidenceStart ) | 318 | if ( incidenceStart < testincidenceStart ) |
319 | computeThis = true; | 319 | computeThis = true; |
320 | if ( computeThis ) | 320 | if ( computeThis ) |
321 | incidenceStart = incidenceStart.addSecs( -300 ); | 321 | incidenceStart = incidenceStart.addSecs( -300 ); |
322 | else | 322 | else |
323 | testincidenceStart = testincidenceStart.addSecs( -300 ); | 323 | testincidenceStart = testincidenceStart.addSecs( -300 ); |
324 | int count = 0; | 324 | int count = 0; |
325 | ok = true; | 325 | ok = true; |
326 | int countbreak = 2000; | 326 | int countbreak = 2000; |
327 | QDateTime stopSearch; | 327 | QDateTime stopSearch; |
328 | bool testStop = false; | 328 | bool testStop = false; |
329 | if ( startDT ) { | 329 | if ( startDT ) { |
330 | stopSearch = startDT->addDays( 365*3 ); | 330 | stopSearch = startDT->addDays( 365*3 ); |
331 | testStop = true; | 331 | testStop = true; |
332 | } | 332 | } |
333 | while ( ok ) { | 333 | while ( ok ) { |
334 | ++count; | 334 | ++count; |
335 | if ( count > countbreak ) break; | 335 | if ( count > countbreak ) break; |
336 | if ( computeThis ) { | 336 | if ( computeThis ) { |
337 | if ( testStop ) | 337 | if ( testStop ) |
338 | if ( testincidenceStart > stopSearch ) | 338 | if ( testincidenceStart > stopSearch ) |
339 | break; | 339 | break; |
340 | incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); | 340 | incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); |
341 | } | 341 | } |
342 | else { | 342 | else { |
343 | if ( testStop ) | 343 | if ( testStop ) |
344 | if ( incidenceStart > stopSearch ) | 344 | if ( incidenceStart > stopSearch ) |
345 | break; | 345 | break; |
346 | testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); | 346 | testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); |
347 | } | 347 | } |
348 | if ( ok ) { | 348 | if ( ok ) { |
349 | if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { | 349 | if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { |
350 | if ( incidenceStart < testincidenceStart ) | 350 | if ( incidenceStart < testincidenceStart ) |
351 | *overlapDT = testincidenceStart; | 351 | *overlapDT = testincidenceStart; |
352 | else | 352 | else |
353 | *overlapDT = incidenceStart; | 353 | *overlapDT = incidenceStart; |
354 | if ( startDT ) { | 354 | if ( startDT ) { |
355 | if ( *overlapDT >= *startDT ) | 355 | if ( *overlapDT >= *startDT ) |
356 | return true; | 356 | return true; |
357 | } else | 357 | } else |
358 | return true; | 358 | return true; |
359 | } | 359 | } |
360 | computeThis = ( incidenceStart < testincidenceStart ); | 360 | computeThis = ( incidenceStart < testincidenceStart ); |
361 | } | 361 | } |
362 | 362 | ||
363 | } | 363 | } |
364 | //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() ); | 364 | //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() ); |
365 | return false; | 365 | return false; |
366 | } | 366 | } |
367 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const | 367 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const |
368 | { | 368 | { |
369 | *ok = false; | 369 | *ok = false; |
370 | if ( !alarmEnabled() ) | 370 | if ( !alarmEnabled() ) |
371 | return QDateTime (); | 371 | return QDateTime (); |
372 | bool yes; | 372 | bool yes; |
373 | QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); | 373 | QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); |
374 | if ( ! yes || cancelled() ) { | 374 | if ( ! yes || cancelled() ) { |
375 | *ok = false; | 375 | *ok = false; |
376 | return QDateTime (); | 376 | return QDateTime (); |
377 | } | 377 | } |
378 | 378 | ||
379 | bool enabled = false; | 379 | bool enabled = false; |
380 | Alarm* alarm; | 380 | Alarm* alarm; |
381 | int off = 0; | 381 | int off = 0; |
382 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 382 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
383 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 383 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
384 | // *ok = false; | 384 | // *ok = false; |
385 | // return incidenceStart; | 385 | // return incidenceStart; |
386 | // } | 386 | // } |
387 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 387 | for (Q3PtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
388 | if (alarm->enabled()) { | 388 | if (alarm->enabled()) { |
389 | if ( alarm->hasTime () ) { | 389 | if ( alarm->hasTime () ) { |
390 | if ( alarm->time() < alarmStart ) { | 390 | if ( alarm->time() < alarmStart ) { |
391 | alarmStart = alarm->time(); | 391 | alarmStart = alarm->time(); |
392 | enabled = true; | 392 | enabled = true; |
393 | off = alarmStart.secsTo( incidenceStart ); | 393 | off = alarmStart.secsTo( incidenceStart ); |
394 | } | 394 | } |
395 | 395 | ||
396 | } else { | 396 | } else { |
397 | int secs = alarm->startOffset().asSeconds(); | 397 | int secs = alarm->startOffset().asSeconds(); |
398 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 398 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
399 | alarmStart = incidenceStart.addSecs( secs ); | 399 | alarmStart = incidenceStart.addSecs( secs ); |
400 | enabled = true; | 400 | enabled = true; |
401 | off = -secs; | 401 | off = -secs; |
402 | } | 402 | } |
403 | } | 403 | } |
404 | } | 404 | } |
405 | } | 405 | } |
406 | if ( enabled ) { | 406 | if ( enabled ) { |
407 | if ( alarmStart > start_dt ) { | 407 | if ( alarmStart > start_dt ) { |
408 | *ok = true; | 408 | *ok = true; |
409 | * offset = off; | 409 | * offset = off; |
410 | return alarmStart; | 410 | return alarmStart; |
411 | } | 411 | } |
412 | } | 412 | } |
413 | *ok = false; | 413 | *ok = false; |
414 | return QDateTime (); | 414 | return QDateTime (); |
415 | 415 | ||
416 | } | 416 | } |
417 | 417 | ||
418 | QString Event::durationText() | 418 | QString Event::durationText() |
419 | { | 419 | { |
420 | int sec = mDtStart.secsTo( mDtEnd ); | 420 | int sec = mDtStart.secsTo( mDtEnd ); |
421 | if ( doesFloat() ) | 421 | if ( doesFloat() ) |
422 | sec += 86400; | 422 | sec += 86400; |
423 | return durationText4Time( sec ); | 423 | return durationText4Time( sec ); |
424 | } | 424 | } |
diff --git a/libkcal/event.h b/libkcal/event.h index 6a58618..da44f81 100644 --- a/libkcal/event.h +++ b/libkcal/event.h | |||
@@ -1,95 +1,97 @@ | |||
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" |
28 | //Added by qt3to4: | ||
29 | #include <Q3CString> | ||
28 | namespace KCal { | 30 | namespace KCal { |
29 | 31 | ||
30 | /** | 32 | /** |
31 | This class provides an Event in the sense of RFC2445. | 33 | This class provides an Event in the sense of RFC2445. |
32 | */ | 34 | */ |
33 | class Event : public Incidence | 35 | class Event : public Incidence |
34 | { | 36 | { |
35 | public: | 37 | public: |
36 | enum Transparency { Opaque, Transparent }; | 38 | enum Transparency { Opaque, Transparent }; |
37 | typedef ListBase<Event> List; | 39 | typedef ListBase<Event> List; |
38 | Event(); | 40 | Event(); |
39 | Event(const Event &); | 41 | Event(const Event &); |
40 | ~Event(); | 42 | ~Event(); |
41 | bool matchTime(QDateTime*startDT, QDateTime* endDT); | 43 | bool matchTime(QDateTime*startDT, QDateTime* endDT); |
42 | 44 | ||
43 | QCString type() const { return "Event"; } | 45 | Q3CString type() const { return "Event"; } |
44 | IncTypeID typeID() const { return eventID; } | 46 | IncTypeID typeID() const { return eventID; } |
45 | 47 | ||
46 | Incidence *clone(); | 48 | Incidence *clone(); |
47 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; | 49 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; |
48 | 50 | ||
49 | /** for setting an event's ending date/time with a QDateTime. */ | 51 | /** for setting an event's ending date/time with a QDateTime. */ |
50 | void setDtEnd(const QDateTime &dtEnd); | 52 | void setDtEnd(const QDateTime &dtEnd); |
51 | /** Return the event's ending date/time as a QDateTime. */ | 53 | /** Return the event's ending date/time as a QDateTime. */ |
52 | virtual QDateTime dtEnd() const; | 54 | virtual QDateTime dtEnd() const; |
53 | /** returns an event's end time as a string formatted according to the | 55 | /** returns an event's end time as a string formatted according to the |
54 | users locale settings */ | 56 | users locale settings */ |
55 | QString dtEndTimeStr() const; | 57 | QString dtEndTimeStr() const; |
56 | /** returns an event's end date as a string formatted according to the | 58 | /** returns an event's end date as a string formatted according to the |
57 | users locale settings */ | 59 | users locale settings */ |
58 | QString dtEndDateStr(bool shortfmt=true) const; | 60 | QString dtEndDateStr(bool shortfmt=true) const; |
59 | /** returns an event's end date and time as a string formatted according | 61 | /** returns an event's end date and time as a string formatted according |
60 | to the users locale settings */ | 62 | to the users locale settings */ |
61 | QString dtEndStr(bool shortfmt=true) const; | 63 | QString dtEndStr(bool shortfmt=true) const; |
62 | void setHasEndDate(bool); | 64 | void setHasEndDate(bool); |
63 | /** Return whether the event has an end date/time. */ | 65 | /** Return whether the event has an end date/time. */ |
64 | bool hasEndDate() const; | 66 | bool hasEndDate() const; |
65 | 67 | ||
66 | /** Return true if the event spans multiple days, otherwise return false. */ | 68 | /** Return true if the event spans multiple days, otherwise return false. */ |
67 | bool isMultiDay() const; | 69 | bool isMultiDay() const; |
68 | 70 | ||
69 | /** set the event's time transparency level. */ | 71 | /** set the event's time transparency level. */ |
70 | void setTransparency(Transparency transparency); | 72 | void setTransparency(Transparency transparency); |
71 | /** get the event's time transparency level. */ | 73 | /** get the event's time transparency level. */ |
72 | Transparency transparency() const; | 74 | Transparency transparency() const; |
73 | 75 | ||
74 | void setDuration(int seconds); | 76 | void setDuration(int seconds); |
75 | 77 | ||
76 | bool contains ( Event*); | 78 | bool contains ( Event*); |
77 | 79 | ||
78 | bool isOverlapping ( Event*, QDateTime*, QDateTime* ); | 80 | bool isOverlapping ( Event*, QDateTime*, QDateTime* ); |
79 | QString durationText(); | 81 | QString durationText(); |
80 | 82 | ||
81 | private: | 83 | private: |
82 | bool accept(Visitor &v) { return v.visit(this); } | 84 | bool accept(Visitor &v) { return v.visit(this); } |
83 | 85 | ||
84 | QDateTime mDtEnd; | 86 | QDateTime mDtEnd; |
85 | bool mHasEndDate; | 87 | bool mHasEndDate; |
86 | Transparency mTransparency; | 88 | Transparency mTransparency; |
87 | }; | 89 | }; |
88 | 90 | ||
89 | bool operator==( const Event&, const Event& ); | 91 | bool operator==( const Event&, const Event& ); |
90 | 92 | ||
91 | 93 | ||
92 | } | 94 | } |
93 | 95 | ||
94 | 96 | ||
95 | #endif | 97 | #endif |
diff --git a/libkcal/filestorage.cpp b/libkcal/filestorage.cpp index a139124..3d1309f 100644 --- a/libkcal/filestorage.cpp +++ b/libkcal/filestorage.cpp | |||
@@ -1,140 +1,140 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2002 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 <stdlib.h> | 21 | #include <stdlib.h> |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <q3ptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | 28 | ||
29 | #include "calendar.h" | 29 | #include "calendar.h" |
30 | #include "vcaldrag.h" | 30 | #include "vcaldrag.h" |
31 | #include "vcalformat.h" | 31 | #include "vcalformat.h" |
32 | #include "icalformat.h" | 32 | #include "icalformat.h" |
33 | 33 | ||
34 | #include "filestorage.h" | 34 | #include "filestorage.h" |
35 | 35 | ||
36 | using namespace KCal; | 36 | using namespace KCal; |
37 | 37 | ||
38 | FileStorage::FileStorage( Calendar *cal, const QString &fileName, | 38 | FileStorage::FileStorage( Calendar *cal, const QString &fileName, |
39 | CalFormat *format ) | 39 | CalFormat *format ) |
40 | : CalStorage( cal ), | 40 | : CalStorage( cal ), |
41 | mFileName( fileName ), | 41 | mFileName( fileName ), |
42 | mSaveFormat( format ) | 42 | mSaveFormat( format ) |
43 | { | 43 | { |
44 | } | 44 | } |
45 | 45 | ||
46 | FileStorage::~FileStorage() | 46 | FileStorage::~FileStorage() |
47 | { | 47 | { |
48 | delete mSaveFormat; | 48 | delete mSaveFormat; |
49 | } | 49 | } |
50 | 50 | ||
51 | void FileStorage::setFileName( const QString &fileName ) | 51 | void FileStorage::setFileName( const QString &fileName ) |
52 | { | 52 | { |
53 | mFileName = fileName; | 53 | mFileName = fileName; |
54 | } | 54 | } |
55 | 55 | ||
56 | QString FileStorage::fileName()const | 56 | QString FileStorage::fileName()const |
57 | { | 57 | { |
58 | return mFileName; | 58 | return mFileName; |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | void FileStorage::setSaveFormat( CalFormat *format ) | 62 | void FileStorage::setSaveFormat( CalFormat *format ) |
63 | { | 63 | { |
64 | delete mSaveFormat; | 64 | delete mSaveFormat; |
65 | mSaveFormat = format; | 65 | mSaveFormat = format; |
66 | } | 66 | } |
67 | 67 | ||
68 | CalFormat *FileStorage::saveFormat()const | 68 | CalFormat *FileStorage::saveFormat()const |
69 | { | 69 | { |
70 | return mSaveFormat; | 70 | return mSaveFormat; |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | bool FileStorage::open() | 74 | bool FileStorage::open() |
75 | { | 75 | { |
76 | return true; | 76 | return true; |
77 | } | 77 | } |
78 | 78 | ||
79 | bool FileStorage::load( ) | 79 | bool FileStorage::load( ) |
80 | { | 80 | { |
81 | kdDebug(5800) << "FileStorage::load(): '" << mFileName << "'" << endl; | 81 | kdDebug(5800) << "FileStorage::load(): '" << mFileName << "'" << endl; |
82 | 82 | ||
83 | // do we want to silently accept this, or make some noise? Dunno... | 83 | // do we want to silently accept this, or make some noise? Dunno... |
84 | // it is a semantical thing vs. a practical thing. | 84 | // it is a semantical thing vs. a practical thing. |
85 | if (mFileName.isEmpty()) return false; | 85 | if (mFileName.isEmpty()) return false; |
86 | 86 | ||
87 | // Always try to load with iCalendar. It will detect, if it is actually a | 87 | // Always try to load with iCalendar. It will detect, if it is actually a |
88 | // vCalendar file. | 88 | // vCalendar file. |
89 | ICalFormat iCal; | 89 | ICalFormat iCal; |
90 | 90 | ||
91 | bool success = iCal.load( calendar(), mFileName); | 91 | bool success = iCal.load( calendar(), mFileName); |
92 | 92 | ||
93 | if ( !success ) { | 93 | if ( !success ) { |
94 | if ( iCal.exception() ) { | 94 | if ( iCal.exception() ) { |
95 | // kdDebug(5800) << "---Error: " << mFormat->exception()->errorCode() << endl; | 95 | // kdDebug(5800) << "---Error: " << mFormat->exception()->errorCode() << endl; |
96 | if ( iCal.exception()->errorCode() == ErrorFormat::CalVersion1 ) { | 96 | if ( iCal.exception()->errorCode() == ErrorFormat::CalVersion1 ) { |
97 | // Expected non vCalendar file, but detected vCalendar | 97 | // Expected non vCalendar file, but detected vCalendar |
98 | kdDebug(5800) << "FileStorage::load() Fallback to VCalFormat" << endl; | 98 | kdDebug(5800) << "FileStorage::load() Fallback to VCalFormat" << endl; |
99 | VCalFormat vCal; | 99 | VCalFormat vCal; |
100 | success = vCal.load( calendar(), mFileName ); | 100 | success = vCal.load( calendar(), mFileName ); |
101 | calendar()->setLoadedProductId( vCal.productId() ); | 101 | calendar()->setLoadedProductId( vCal.productId() ); |
102 | } else { | 102 | } else { |
103 | return false; | 103 | return false; |
104 | } | 104 | } |
105 | } else { | 105 | } else { |
106 | kdDebug(5800) << "Warning! There should be set an exception." << endl; | 106 | kdDebug(5800) << "Warning! There should be set an exception." << endl; |
107 | return false; | 107 | return false; |
108 | } | 108 | } |
109 | } else { | 109 | } else { |
110 | // kdDebug(5800) << "---Success" << endl; | 110 | // kdDebug(5800) << "---Success" << endl; |
111 | calendar()->setLoadedProductId( iCal.loadedProductId() ); | 111 | calendar()->setLoadedProductId( iCal.loadedProductId() ); |
112 | } | 112 | } |
113 | 113 | ||
114 | calendar()->setModified( false ); | 114 | calendar()->setModified( false ); |
115 | 115 | ||
116 | return true; | 116 | return true; |
117 | } | 117 | } |
118 | 118 | ||
119 | bool FileStorage::save() | 119 | bool FileStorage::save() |
120 | { | 120 | { |
121 | if ( mFileName.isEmpty() ) return false; | 121 | if ( mFileName.isEmpty() ) return false; |
122 | 122 | ||
123 | bool success; | 123 | bool success; |
124 | 124 | ||
125 | if ( mSaveFormat ) { | 125 | if ( mSaveFormat ) { |
126 | success = mSaveFormat->save( calendar(), mFileName); | 126 | success = mSaveFormat->save( calendar(), mFileName); |
127 | } else { | 127 | } else { |
128 | ICalFormat iCal; | 128 | ICalFormat iCal; |
129 | success = iCal.save( calendar(), mFileName); | 129 | success = iCal.save( calendar(), mFileName); |
130 | } | 130 | } |
131 | 131 | ||
132 | if ( success ) calendar()->setModified( false ); | 132 | if ( success ) calendar()->setModified( false ); |
133 | 133 | ||
134 | return success; | 134 | return success; |
135 | } | 135 | } |
136 | 136 | ||
137 | bool FileStorage::close() | 137 | bool FileStorage::close() |
138 | { | 138 | { |
139 | return true; | 139 | return true; |
140 | } | 140 | } |
diff --git a/libkcal/freebusy.cpp b/libkcal/freebusy.cpp index ba15d6d..e4e9ec9 100644 --- a/libkcal/freebusy.cpp +++ b/libkcal/freebusy.cpp | |||
@@ -1,184 +1,187 @@ | |||
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 <kdebug.h> | 21 | #include <kdebug.h> |
22 | 22 | ||
23 | #include "freebusy.h" | 23 | #include "freebusy.h" |
24 | //Added by qt3to4: | ||
25 | #include <Q3ValueList> | ||
26 | #include <Q3PtrList> | ||
24 | 27 | ||
25 | using namespace KCal; | 28 | using namespace KCal; |
26 | 29 | ||
27 | FreeBusy::FreeBusy() | 30 | FreeBusy::FreeBusy() |
28 | { | 31 | { |
29 | } | 32 | } |
30 | 33 | ||
31 | FreeBusy::FreeBusy(const QDateTime &start, const QDateTime &end) | 34 | FreeBusy::FreeBusy(const QDateTime &start, const QDateTime &end) |
32 | { | 35 | { |
33 | setDtStart(start); | 36 | setDtStart(start); |
34 | setDtEnd(end); | 37 | setDtEnd(end); |
35 | } | 38 | } |
36 | 39 | ||
37 | FreeBusy::FreeBusy( Calendar *calendar, const QDateTime &start, const QDateTime &end ) | 40 | FreeBusy::FreeBusy( Calendar *calendar, const QDateTime &start, const QDateTime &end ) |
38 | { | 41 | { |
39 | kdDebug() << "FreeBusy::FreeBusy" << endl; | 42 | kdDebug() << "FreeBusy::FreeBusy" << endl; |
40 | mCalendar = calendar; | 43 | mCalendar = calendar; |
41 | 44 | ||
42 | setDtStart(start); | 45 | setDtStart(start); |
43 | setDtEnd(end); | 46 | setDtEnd(end); |
44 | 47 | ||
45 | //Gets all the events in the calendar | 48 | //Gets all the events in the calendar |
46 | QPtrList<Event> eventList = mCalendar->events(); | 49 | Q3PtrList<Event> eventList = mCalendar->events(); |
47 | Event *event; | 50 | Event *event; |
48 | 51 | ||
49 | int extraDays, i, x, duration; | 52 | int extraDays, i, x, duration; |
50 | duration = start.daysTo(end); | 53 | duration = start.daysTo(end); |
51 | QDate day; | 54 | QDate day; |
52 | QDateTime tmpStart; | 55 | QDateTime tmpStart; |
53 | QDateTime tmpEnd; | 56 | QDateTime tmpEnd; |
54 | //Loops through every event in the calendar | 57 | //Loops through every event in the calendar |
55 | for( event = eventList.first(); event; event = eventList.next() ) { | 58 | for( event = eventList.first(); event; event = eventList.next() ) { |
56 | //This whole for loop is for recurring events, it loops through | 59 | //This whole for loop is for recurring events, it loops through |
57 | //each of the days of the freebusy request | 60 | //each of the days of the freebusy request |
58 | 61 | ||
59 | //First check if this is transparent. If it is, it shouldn't be in the | 62 | //First check if this is transparent. If it is, it shouldn't be in the |
60 | //freebusy list | 63 | //freebusy list |
61 | if ( event->transparency() == Event::Transparent ) | 64 | if ( event->transparency() == Event::Transparent ) |
62 | // Transparent | 65 | // Transparent |
63 | continue; | 66 | continue; |
64 | 67 | ||
65 | for(i=0; i<=duration; i++) { | 68 | for(i=0; i<=duration; i++) { |
66 | day=(start.addDays(i).date()); | 69 | day=(start.addDays(i).date()); |
67 | tmpStart.setDate(day); | 70 | tmpStart.setDate(day); |
68 | tmpEnd.setDate(day); | 71 | tmpEnd.setDate(day); |
69 | 72 | ||
70 | if( (*(event->recurrence())).doesRecur() ) { | 73 | if( (*(event->recurrence())).doesRecur() ) { |
71 | if ( event->isMultiDay() ) { | 74 | if ( event->isMultiDay() ) { |
72 | extraDays = event->dtStart().date().daysTo(event->dtEnd().date()); | 75 | extraDays = event->dtStart().date().daysTo(event->dtEnd().date()); |
73 | for (x=0; x<=extraDays; x++) { | 76 | for (x=0; x<=extraDays; x++) { |
74 | if ( event->recursOn(day.addDays(-x))) { | 77 | if ( event->recursOn(day.addDays(-x))) { |
75 | tmpStart.setDate(day.addDays(-x)); | 78 | tmpStart.setDate(day.addDays(-x)); |
76 | tmpStart.setTime(event->dtStart().time()); | 79 | tmpStart.setTime(event->dtStart().time()); |
77 | tmpEnd=tmpStart.addSecs( (event->duration()) ); | 80 | tmpEnd=tmpStart.addSecs( (event->duration()) ); |
78 | 81 | ||
79 | addLocalPeriod( tmpStart, tmpEnd ); | 82 | addLocalPeriod( tmpStart, tmpEnd ); |
80 | break; | 83 | break; |
81 | } | 84 | } |
82 | } | 85 | } |
83 | } else { | 86 | } else { |
84 | if (event->recursOn(day)) { | 87 | if (event->recursOn(day)) { |
85 | tmpStart.setTime(event->dtStart().time()); | 88 | tmpStart.setTime(event->dtStart().time()); |
86 | tmpEnd.setTime(event->dtEnd().time()); | 89 | tmpEnd.setTime(event->dtEnd().time()); |
87 | 90 | ||
88 | addLocalPeriod (tmpStart, tmpEnd); | 91 | addLocalPeriod (tmpStart, tmpEnd); |
89 | } | 92 | } |
90 | } | 93 | } |
91 | } | 94 | } |
92 | 95 | ||
93 | } | 96 | } |
94 | //Non-reocurring events | 97 | //Non-reocurring events |
95 | addLocalPeriod(event->dtStart(), event->dtEnd()); | 98 | addLocalPeriod(event->dtStart(), event->dtEnd()); |
96 | } | 99 | } |
97 | 100 | ||
98 | sortList(); | 101 | sortList(); |
99 | } | 102 | } |
100 | 103 | ||
101 | FreeBusy::~FreeBusy() | 104 | FreeBusy::~FreeBusy() |
102 | { | 105 | { |
103 | } | 106 | } |
104 | 107 | ||
105 | bool FreeBusy::setDtEnd( const QDateTime &end ) | 108 | bool FreeBusy::setDtEnd( const QDateTime &end ) |
106 | { | 109 | { |
107 | mDtEnd = end; | 110 | mDtEnd = end; |
108 | return true; | 111 | return true; |
109 | } | 112 | } |
110 | 113 | ||
111 | QDateTime FreeBusy::dtEnd() const | 114 | QDateTime FreeBusy::dtEnd() const |
112 | { | 115 | { |
113 | return mDtEnd; | 116 | return mDtEnd; |
114 | } | 117 | } |
115 | 118 | ||
116 | QValueList<Period> FreeBusy::busyPeriods() const | 119 | Q3ValueList<Period> FreeBusy::busyPeriods() const |
117 | { | 120 | { |
118 | return mBusyPeriods; | 121 | return mBusyPeriods; |
119 | } | 122 | } |
120 | 123 | ||
121 | bool FreeBusy::addLocalPeriod(const QDateTime &eventStart, const QDateTime &eventEnd ) { | 124 | bool FreeBusy::addLocalPeriod(const QDateTime &eventStart, const QDateTime &eventEnd ) { |
122 | QDateTime tmpStart; | 125 | QDateTime tmpStart; |
123 | QDateTime tmpEnd; | 126 | QDateTime tmpEnd; |
124 | 127 | ||
125 | //Check to see if the start *or* end of the event is | 128 | //Check to see if the start *or* end of the event is |
126 | //between the start and end of the freebusy dates. | 129 | //between the start and end of the freebusy dates. |
127 | if (!((((this->dtStart()).secsTo(eventStart)>=0)&&(eventStart.secsTo(this->dtEnd())>=0)) | 130 | if (!((((this->dtStart()).secsTo(eventStart)>=0)&&(eventStart.secsTo(this->dtEnd())>=0)) |
128 | ||(((this->dtStart()).secsTo(eventEnd) >= 0)&&(eventEnd.secsTo(this->dtEnd()) >= 0)))) | 131 | ||(((this->dtStart()).secsTo(eventEnd) >= 0)&&(eventEnd.secsTo(this->dtEnd()) >= 0)))) |
129 | return false; | 132 | return false; |
130 | 133 | ||
131 | if ( eventStart.secsTo(this->dtStart())>=0) { | 134 | if ( eventStart.secsTo(this->dtStart())>=0) { |
132 | tmpStart = this->dtStart(); | 135 | tmpStart = this->dtStart(); |
133 | } else { | 136 | } else { |
134 | tmpStart = eventStart; | 137 | tmpStart = eventStart; |
135 | } | 138 | } |
136 | 139 | ||
137 | if ( eventEnd.secsTo(this->dtEnd())<=0 ) { | 140 | if ( eventEnd.secsTo(this->dtEnd())<=0 ) { |
138 | tmpEnd = this->dtEnd(); | 141 | tmpEnd = this->dtEnd(); |
139 | } else { | 142 | } else { |
140 | tmpEnd = eventEnd; | 143 | tmpEnd = eventEnd; |
141 | } | 144 | } |
142 | 145 | ||
143 | Period p(tmpStart, tmpEnd); | 146 | Period p(tmpStart, tmpEnd); |
144 | mBusyPeriods.append( p ); | 147 | mBusyPeriods.append( p ); |
145 | 148 | ||
146 | return true; | 149 | return true; |
147 | } | 150 | } |
148 | 151 | ||
149 | FreeBusy::FreeBusy(QValueList<Period> busyPeriods) | 152 | FreeBusy::FreeBusy(Q3ValueList<Period> busyPeriods) |
150 | { | 153 | { |
151 | mBusyPeriods = busyPeriods; | 154 | mBusyPeriods = busyPeriods; |
152 | } | 155 | } |
153 | 156 | ||
154 | void FreeBusy::sortList() | 157 | void FreeBusy::sortList() |
155 | { | 158 | { |
156 | typedef QValueList<Period> PeriodList; | 159 | typedef Q3ValueList<Period> PeriodList; |
157 | 160 | ||
158 | PeriodList::Iterator tmpPeriod, earlyPeriod; | 161 | PeriodList::Iterator tmpPeriod, earlyPeriod; |
159 | PeriodList sortedList; | 162 | PeriodList sortedList; |
160 | QDateTime earlyTime; | 163 | QDateTime earlyTime; |
161 | 164 | ||
162 | while( mBusyPeriods.count() > 0 ) { | 165 | while( mBusyPeriods.count() > 0 ) { |
163 | earlyTime=(*mBusyPeriods.begin()).start(); | 166 | earlyTime=(*mBusyPeriods.begin()).start(); |
164 | for (tmpPeriod=mBusyPeriods.begin(); tmpPeriod!=mBusyPeriods.end(); tmpPeriod++) { | 167 | for (tmpPeriod=mBusyPeriods.begin(); tmpPeriod!=mBusyPeriods.end(); tmpPeriod++) { |
165 | if (earlyTime.secsTo((*tmpPeriod).start()) <= 0) { | 168 | if (earlyTime.secsTo((*tmpPeriod).start()) <= 0) { |
166 | earlyTime=(*tmpPeriod).start(); | 169 | earlyTime=(*tmpPeriod).start(); |
167 | earlyPeriod=tmpPeriod; | 170 | earlyPeriod=tmpPeriod; |
168 | } | 171 | } |
169 | } | 172 | } |
170 | //Move tmpPeriod to sortedList | 173 | //Move tmpPeriod to sortedList |
171 | Period tmpPeriod( (*earlyPeriod).start(), (*earlyPeriod).end() ); | 174 | Period tmpPeriod( (*earlyPeriod).start(), (*earlyPeriod).end() ); |
172 | sortedList.append( tmpPeriod ); | 175 | sortedList.append( tmpPeriod ); |
173 | mBusyPeriods.remove( earlyPeriod ); | 176 | mBusyPeriods.remove( earlyPeriod ); |
174 | } | 177 | } |
175 | mBusyPeriods=sortedList; | 178 | mBusyPeriods=sortedList; |
176 | } | 179 | } |
177 | 180 | ||
178 | void FreeBusy::addPeriod(const QDateTime &start, const QDateTime &end) | 181 | void FreeBusy::addPeriod(const QDateTime &start, const QDateTime &end) |
179 | { | 182 | { |
180 | Period p(start, end); | 183 | Period p(start, end); |
181 | mBusyPeriods.append( p ); | 184 | mBusyPeriods.append( p ); |
182 | 185 | ||
183 | sortList(); | 186 | sortList(); |
184 | } | 187 | } |
diff --git a/libkcal/freebusy.h b/libkcal/freebusy.h index d741c72..bd14cb7 100644 --- a/libkcal/freebusy.h +++ b/libkcal/freebusy.h | |||
@@ -1,73 +1,75 @@ | |||
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_FREEBUSY_H | 20 | #ifndef KCAL_FREEBUSY_H |
21 | #define KCAL_FREEBUSY_H | 21 | #define KCAL_FREEBUSY_H |
22 | // | 22 | // |
23 | // FreeBusy - information about free/busy times | 23 | // FreeBusy - information about free/busy times |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qvaluelist.h> | 27 | #include <q3valuelist.h> |
28 | #include <qptrlist.h> | 28 | #include <q3ptrlist.h> |
29 | //Added by qt3to4: | ||
30 | #include <Q3CString> | ||
29 | 31 | ||
30 | #include "period.h" | 32 | #include "period.h" |
31 | #include "calendar.h" | 33 | #include "calendar.h" |
32 | 34 | ||
33 | #include "incidencebase.h" | 35 | #include "incidencebase.h" |
34 | 36 | ||
35 | namespace KCal { | 37 | namespace KCal { |
36 | 38 | ||
37 | /** | 39 | /** |
38 | This class provides information about free/busy time of a calendar user. | 40 | This class provides information about free/busy time of a calendar user. |
39 | */ | 41 | */ |
40 | class FreeBusy : public IncidenceBase | 42 | class FreeBusy : public IncidenceBase |
41 | { | 43 | { |
42 | public: | 44 | public: |
43 | FreeBusy(); | 45 | FreeBusy(); |
44 | FreeBusy(const QDateTime &start, const QDateTime &end); | 46 | FreeBusy(const QDateTime &start, const QDateTime &end); |
45 | FreeBusy(Calendar *calendar, const QDateTime &start, const QDateTime &end); | 47 | FreeBusy(Calendar *calendar, const QDateTime &start, const QDateTime &end); |
46 | FreeBusy(QValueList<Period> busyPeriods); | 48 | FreeBusy(Q3ValueList<Period> busyPeriods); |
47 | 49 | ||
48 | ~FreeBusy(); | 50 | ~FreeBusy(); |
49 | 51 | ||
50 | QCString type() const { return "FreeBusy"; } | 52 | Q3CString type() const { return "FreeBusy"; } |
51 | IncTypeID typeID() const { return freebusyID; } | 53 | IncTypeID typeID() const { return freebusyID; } |
52 | 54 | ||
53 | virtual QDateTime dtEnd() const; | 55 | virtual QDateTime dtEnd() const; |
54 | bool setDtEnd( const QDateTime &end ); | 56 | bool setDtEnd( const QDateTime &end ); |
55 | 57 | ||
56 | QValueList<Period> busyPeriods() const; | 58 | Q3ValueList<Period> busyPeriods() const; |
57 | 59 | ||
58 | void addPeriod(const QDateTime &start, const QDateTime &end); | 60 | void addPeriod(const QDateTime &start, const QDateTime &end); |
59 | void sortList(); | 61 | void sortList(); |
60 | 62 | ||
61 | private: | 63 | private: |
62 | 64 | ||
63 | //This is used for creating a freebusy object for the current user | 65 | //This is used for creating a freebusy object for the current user |
64 | bool addLocalPeriod(const QDateTime &start, const QDateTime &end); | 66 | bool addLocalPeriod(const QDateTime &start, const QDateTime &end); |
65 | 67 | ||
66 | QDateTime mDtEnd; | 68 | QDateTime mDtEnd; |
67 | QValueList<Period> mBusyPeriods; | 69 | Q3ValueList<Period> mBusyPeriods; |
68 | Calendar *mCalendar; | 70 | Calendar *mCalendar; |
69 | }; | 71 | }; |
70 | 72 | ||
71 | } | 73 | } |
72 | 74 | ||
73 | #endif | 75 | #endif |
diff --git a/libkcal/icaldrag.cpp b/libkcal/icaldrag.cpp index 446a115..7f5a796 100644 --- a/libkcal/icaldrag.cpp +++ b/libkcal/icaldrag.cpp | |||
@@ -1,58 +1,58 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include "icaldrag.h" | 22 | #include "icaldrag.h" |
23 | 23 | ||
24 | #include "icalformat.h" | 24 | #include "icalformat.h" |
25 | 25 | ||
26 | #include <kdebug.h> | 26 | #include <kdebug.h> |
27 | 27 | ||
28 | using namespace KCal; | 28 | using namespace KCal; |
29 | 29 | ||
30 | ICalDrag::ICalDrag( Calendar *cal, QWidget *parent, const char *name ) | 30 | ICalDrag::ICalDrag( Calendar *cal, QWidget *parent, const char *name ) |
31 | : QStoredDrag( "text/calendar", parent, name ) | 31 | : Q3StoredDrag( "text/calendar", parent, name ) |
32 | { | 32 | { |
33 | ICalFormat icf; | 33 | ICalFormat icf; |
34 | QString scal = icf.toString( cal ); | 34 | QString scal = icf.toString( cal ); |
35 | 35 | ||
36 | setEncodedData( scal.utf8() ); | 36 | setEncodedData( scal.utf8() ); |
37 | } | 37 | } |
38 | 38 | ||
39 | bool ICalDrag::canDecode( QMimeSource *me ) | 39 | bool ICalDrag::canDecode( QMimeSource *me ) |
40 | { | 40 | { |
41 | return me->provides( "text/calendar" ); | 41 | return me->provides( "text/calendar" ); |
42 | } | 42 | } |
43 | 43 | ||
44 | bool ICalDrag::decode( QMimeSource *de, Calendar *cal ) | 44 | bool ICalDrag::decode( QMimeSource *de, Calendar *cal ) |
45 | { | 45 | { |
46 | bool success = false; | 46 | bool success = false; |
47 | 47 | ||
48 | QByteArray payload = de->encodedData( "text/calendar" ); | 48 | QByteArray payload = de->encodedData( "text/calendar" ); |
49 | if ( payload.size() ) { | 49 | if ( payload.size() ) { |
50 | QString txt = QString::fromUtf8( payload.data() ); | 50 | QString txt = QString::fromUtf8( payload.data() ); |
51 | 51 | ||
52 | ICalFormat icf; | 52 | ICalFormat icf; |
53 | success = icf.fromString( cal, txt ); | 53 | success = icf.fromString( cal, txt ); |
54 | } | 54 | } |
55 | 55 | ||
56 | return success; | 56 | return success; |
57 | } | 57 | } |
58 | 58 | ||
diff --git a/libkcal/icaldrag.h b/libkcal/icaldrag.h index fdf32b7..c1f73f4 100644 --- a/libkcal/icaldrag.h +++ b/libkcal/icaldrag.h | |||
@@ -1,46 +1,46 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef ICALDRAG_H | 22 | #ifndef ICALDRAG_H |
23 | #define ICALDRAG_H | 23 | #define ICALDRAG_H |
24 | 24 | ||
25 | #include <qdragobject.h> | 25 | #include <q3dragobject.h> |
26 | #include "calendar.h" | 26 | #include "calendar.h" |
27 | 27 | ||
28 | namespace KCal { | 28 | namespace KCal { |
29 | 29 | ||
30 | /** iCalendar drag&drop class. */ | 30 | /** iCalendar drag&drop class. */ |
31 | class ICalDrag : public QStoredDrag | 31 | class ICalDrag : public Q3StoredDrag |
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | /** Create a drag&drop object for iCalendar component \a ical. */ | 34 | /** Create a drag&drop object for iCalendar component \a ical. */ |
35 | ICalDrag( Calendar *cal, QWidget *parent = 0, const char *name = 0 ); | 35 | ICalDrag( Calendar *cal, QWidget *parent = 0, const char *name = 0 ); |
36 | ~ICalDrag() {}; | 36 | ~ICalDrag() {}; |
37 | 37 | ||
38 | /** Return, if drag&drop object can be decode to iCalendar. */ | 38 | /** Return, if drag&drop object can be decode to iCalendar. */ |
39 | static bool canDecode( QMimeSource * ); | 39 | static bool canDecode( QMimeSource * ); |
40 | /** Decode drag&drop object to iCalendar component \a cal. */ | 40 | /** Decode drag&drop object to iCalendar component \a cal. */ |
41 | static bool decode( QMimeSource *e, Calendar *cal ); | 41 | static bool decode( QMimeSource *e, Calendar *cal ); |
42 | }; | 42 | }; |
43 | 43 | ||
44 | } | 44 | } |
45 | 45 | ||
46 | #endif | 46 | #endif |
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp index 6f3a799..3829bc1 100644 --- a/libkcal/icalformat.cpp +++ b/libkcal/icalformat.cpp | |||
@@ -1,469 +1,469 @@ | |||
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 <qdatetime.h> | 21 | #include <qdatetime.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qptrlist.h> | 23 | #include <q3ptrlist.h> |
24 | #include <qregexp.h> | 24 | #include <qregexp.h> |
25 | #include <qclipboard.h> | 25 | #include <qclipboard.h> |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qtextstream.h> | 27 | #include <q3textstream.h> |
28 | #include <qtextcodec.h> | 28 | #include <qtextcodec.h> |
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <kglobal.h> | 32 | #include <kglobal.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | extern "C" { | 35 | extern "C" { |
36 | #include <ical.h> | 36 | #include <ical.h> |
37 | #include <icalss.h> | 37 | #include <icalss.h> |
38 | #include <icalparser.h> | 38 | #include <icalparser.h> |
39 | #include <icalrestriction.h> | 39 | #include <icalrestriction.h> |
40 | } | 40 | } |
41 | 41 | ||
42 | #include "calendar.h" | 42 | #include "calendar.h" |
43 | #include "calendarlocal.h" | 43 | #include "calendarlocal.h" |
44 | #include "journal.h" | 44 | #include "journal.h" |
45 | 45 | ||
46 | #include "icalformat.h" | 46 | #include "icalformat.h" |
47 | #include "icalformatimpl.h" | 47 | #include "icalformatimpl.h" |
48 | 48 | ||
49 | #define _ICAL_VERSION "2.0" | 49 | #define _ICAL_VERSION "2.0" |
50 | 50 | ||
51 | using namespace KCal; | 51 | using namespace KCal; |
52 | 52 | ||
53 | ICalFormat::ICalFormat( bool pe ) | 53 | ICalFormat::ICalFormat( bool pe ) |
54 | { | 54 | { |
55 | mProcessEvents = pe; | 55 | mProcessEvents = pe; |
56 | mImpl = new ICalFormatImpl( this ); | 56 | mImpl = new ICalFormatImpl( this ); |
57 | tzOffsetMin = 0; | 57 | tzOffsetMin = 0; |
58 | //qDebug("new ICalFormat() "); | 58 | //qDebug("new ICalFormat() "); |
59 | } | 59 | } |
60 | 60 | ||
61 | ICalFormat::~ICalFormat() | 61 | ICalFormat::~ICalFormat() |
62 | { | 62 | { |
63 | delete mImpl; | 63 | delete mImpl; |
64 | //qDebug("delete ICalFormat "); | 64 | //qDebug("delete ICalFormat "); |
65 | } | 65 | } |
66 | 66 | ||
67 | bool ICalFormat::load( Calendar *calendar, const QString &fileName) | 67 | bool ICalFormat::load( Calendar *calendar, const QString &fileName) |
68 | { | 68 | { |
69 | 69 | ||
70 | clearException(); | 70 | clearException(); |
71 | 71 | ||
72 | QFile file( fileName ); | 72 | QFile file( fileName ); |
73 | if (!file.open( IO_ReadOnly ) ) { | 73 | if (!file.open( QIODevice::ReadOnly ) ) { |
74 | setException(new ErrorFormat(ErrorFormat::LoadError)); | 74 | setException(new ErrorFormat(ErrorFormat::LoadError)); |
75 | return false; | 75 | return false; |
76 | } | 76 | } |
77 | QTextStream ts( &file ); | 77 | Q3TextStream ts( &file ); |
78 | QString text; | 78 | QString text; |
79 | 79 | ||
80 | ts.setEncoding( QTextStream::Latin1 ); | 80 | ts.setEncoding( Q3TextStream::Latin1 ); |
81 | text = ts.read(); | 81 | text = ts.read(); |
82 | file.close(); | 82 | file.close(); |
83 | 83 | ||
84 | return fromString( calendar, text ); | 84 | return fromString( calendar, text ); |
85 | } | 85 | } |
86 | 86 | ||
87 | //#include <qdatetime.h> | 87 | //#include <qdatetime.h> |
88 | bool ICalFormat::save( Calendar *calendar, const QString &fileName ) | 88 | bool ICalFormat::save( Calendar *calendar, const QString &fileName ) |
89 | { | 89 | { |
90 | //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; | 90 | //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; |
91 | //qDebug("ICalFormat::save "); | 91 | //qDebug("ICalFormat::save "); |
92 | clearException(); | 92 | clearException(); |
93 | QString text = toString( calendar ); | 93 | QString text = toString( calendar ); |
94 | //return false; | 94 | //return false; |
95 | // qDebug("to string takes ms: %d ",is.elapsed() ); | 95 | // qDebug("to string takes ms: %d ",is.elapsed() ); |
96 | if ( text.isNull() ) return false; | 96 | if ( text.isNull() ) return false; |
97 | 97 | ||
98 | // TODO: write backup file | 98 | // TODO: write backup file |
99 | //is.restart(); | 99 | //is.restart(); |
100 | QFile file( fileName ); | 100 | QFile file( fileName ); |
101 | if (!file.open( IO_WriteOnly ) ) { | 101 | if (!file.open( QIODevice::WriteOnly ) ) { |
102 | setException(new ErrorFormat(ErrorFormat::SaveError, | 102 | setException(new ErrorFormat(ErrorFormat::SaveError, |
103 | i18n("Could not open file '%1'").arg(fileName))); | 103 | i18n("Could not open file '%1'").arg(fileName))); |
104 | return false; | 104 | return false; |
105 | } | 105 | } |
106 | QTextStream ts( &file ); | 106 | Q3TextStream ts( &file ); |
107 | 107 | ||
108 | ts.setEncoding( QTextStream::Latin1 ); | 108 | ts.setEncoding( Q3TextStream::Latin1 ); |
109 | ts << text; | 109 | ts << text; |
110 | file.close(); | 110 | file.close(); |
111 | //qDebug("saving file takes ms: %d ", is.elapsed() ); | 111 | //qDebug("saving file takes ms: %d ", is.elapsed() ); |
112 | return true; | 112 | return true; |
113 | } | 113 | } |
114 | 114 | ||
115 | bool ICalFormat::fromString( Calendar *cal, const QString &text ) | 115 | bool ICalFormat::fromString( Calendar *cal, const QString &text ) |
116 | { | 116 | { |
117 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 117 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
118 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); | 118 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); |
119 | // Get first VCALENDAR component. | 119 | // Get first VCALENDAR component. |
120 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components | 120 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components |
121 | icalcomponent *calendar; | 121 | icalcomponent *calendar; |
122 | 122 | ||
123 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); | 123 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); |
124 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); | 124 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); |
125 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); | 125 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); |
126 | if (!calendar) { | 126 | if (!calendar) { |
127 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); | 127 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | 130 | ||
131 | bool success = true; | 131 | bool success = true; |
132 | 132 | ||
133 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { | 133 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { |
134 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); | 134 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); |
135 | success = false; | 135 | success = false; |
136 | } else { | 136 | } else { |
137 | // put all objects into their proper places | 137 | // put all objects into their proper places |
138 | if ( !mImpl->populate( cal, calendar ) ) { | 138 | if ( !mImpl->populate( cal, calendar ) ) { |
139 | if ( !exception() ) { | 139 | if ( !exception() ) { |
140 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); | 140 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); |
141 | } | 141 | } |
142 | success = false; | 142 | success = false; |
143 | } else | 143 | } else |
144 | mLoadedProductId = mImpl->loadedProductId(); | 144 | mLoadedProductId = mImpl->loadedProductId(); |
145 | } | 145 | } |
146 | 146 | ||
147 | icalcomponent_free( calendar ); | 147 | icalcomponent_free( calendar ); |
148 | icalmemory_free_ring(); | 148 | icalmemory_free_ring(); |
149 | 149 | ||
150 | return success; | 150 | return success; |
151 | } | 151 | } |
152 | 152 | ||
153 | Incidence *ICalFormat::fromString( const QString &text ) | 153 | Incidence *ICalFormat::fromString( const QString &text ) |
154 | { | 154 | { |
155 | CalendarLocal cal( mTimeZoneId ); | 155 | CalendarLocal cal( mTimeZoneId ); |
156 | fromString(&cal, text); | 156 | fromString(&cal, text); |
157 | 157 | ||
158 | Incidence *ical = 0; | 158 | Incidence *ical = 0; |
159 | QPtrList<Event> elist = cal.events(); | 159 | Q3PtrList<Event> elist = cal.events(); |
160 | if ( elist.count() > 0 ) { | 160 | if ( elist.count() > 0 ) { |
161 | ical = elist.first(); | 161 | ical = elist.first(); |
162 | } else { | 162 | } else { |
163 | QPtrList<Todo> tlist = cal.todos(); | 163 | Q3PtrList<Todo> tlist = cal.todos(); |
164 | if ( tlist.count() > 0 ) { | 164 | if ( tlist.count() > 0 ) { |
165 | ical = tlist.first(); | 165 | ical = tlist.first(); |
166 | } else { | 166 | } else { |
167 | QPtrList<Journal> jlist = cal.journals(); | 167 | Q3PtrList<Journal> jlist = cal.journals(); |
168 | if ( jlist.count() > 0 ) { | 168 | if ( jlist.count() > 0 ) { |
169 | ical = jlist.first(); | 169 | ical = jlist.first(); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | } | 172 | } |
173 | return ical; | 173 | return ical; |
174 | } | 174 | } |
175 | #include <qapp.h> | 175 | #include <qapplication.h> |
176 | 176 | ||
177 | QString ICalFormat::toString( Calendar *cal ) | 177 | QString ICalFormat::toString( Calendar *cal ) |
178 | { | 178 | { |
179 | 179 | ||
180 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 180 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
181 | 181 | ||
182 | icalcomponent *calendar = mImpl->createCalendarComponent(cal); | 182 | icalcomponent *calendar = mImpl->createCalendarComponent(cal); |
183 | 183 | ||
184 | icalcomponent *component; | 184 | icalcomponent *component; |
185 | 185 | ||
186 | // todos | 186 | // todos |
187 | QPtrList<Todo> todoList = cal->rawTodos(); | 187 | Q3PtrList<Todo> todoList = cal->rawTodos(); |
188 | QPtrListIterator<Todo> qlt(todoList); | 188 | Q3PtrListIterator<Todo> qlt(todoList); |
189 | for (; qlt.current(); ++qlt) { | 189 | for (; qlt.current(); ++qlt) { |
190 | component = mImpl->writeTodo(qlt.current()); | 190 | component = mImpl->writeTodo(qlt.current()); |
191 | icalcomponent_add_component(calendar,component); | 191 | icalcomponent_add_component(calendar,component); |
192 | //qDebug(" todos "); | 192 | //qDebug(" todos "); |
193 | if ( mProcessEvents ) { | 193 | if ( mProcessEvents ) { |
194 | //qDebug("mProcessEvents "); | 194 | //qDebug("mProcessEvents "); |
195 | qApp->processEvents(); | 195 | qApp->processEvents(); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | // events | 198 | // events |
199 | QPtrList<Event> events = cal->rawEvents(); | 199 | Q3PtrList<Event> events = cal->rawEvents(); |
200 | Event *ev; | 200 | Event *ev; |
201 | for(ev=events.first();ev;ev=events.next()) { | 201 | for(ev=events.first();ev;ev=events.next()) { |
202 | component = mImpl->writeEvent(ev); | 202 | component = mImpl->writeEvent(ev); |
203 | icalcomponent_add_component(calendar,component); | 203 | icalcomponent_add_component(calendar,component); |
204 | //qDebug("events "); | 204 | //qDebug("events "); |
205 | if ( mProcessEvents ) | 205 | if ( mProcessEvents ) |
206 | qApp->processEvents(); | 206 | qApp->processEvents(); |
207 | } | 207 | } |
208 | 208 | ||
209 | // journals | 209 | // journals |
210 | QPtrList<Journal> journals = cal->journals(); | 210 | Q3PtrList<Journal> journals = cal->journals(); |
211 | Journal *j; | 211 | Journal *j; |
212 | for(j=journals.first();j;j=journals.next()) { | 212 | for(j=journals.first();j;j=journals.next()) { |
213 | component = mImpl->writeJournal(j); | 213 | component = mImpl->writeJournal(j); |
214 | icalcomponent_add_component(calendar,component); | 214 | icalcomponent_add_component(calendar,component); |
215 | //qDebug("journals "); | 215 | //qDebug("journals "); |
216 | if ( mProcessEvents ) | 216 | if ( mProcessEvents ) |
217 | qApp->processEvents(); | 217 | qApp->processEvents(); |
218 | } | 218 | } |
219 | const char *text; | 219 | const char *text; |
220 | QString ret =""; | 220 | QString ret =""; |
221 | text = icalcomponent_as_ical_string( calendar ); | 221 | text = icalcomponent_as_ical_string( calendar ); |
222 | if ( mProcessEvents ) | 222 | if ( mProcessEvents ) |
223 | qApp->processEvents(); | 223 | qApp->processEvents(); |
224 | 224 | ||
225 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; | 225 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; |
226 | 226 | ||
227 | 227 | ||
228 | if ( text ) { | 228 | if ( text ) { |
229 | ret = QString ( text ); | 229 | ret = QString ( text ); |
230 | } | 230 | } |
231 | icalcomponent_free( calendar ); | 231 | icalcomponent_free( calendar ); |
232 | 232 | ||
233 | if (!text) { | 233 | if (!text) { |
234 | setException(new ErrorFormat(ErrorFormat::SaveError, | 234 | setException(new ErrorFormat(ErrorFormat::SaveError, |
235 | i18n("libical error"))); | 235 | i18n("libical error"))); |
236 | icalmemory_free_ring(); | 236 | icalmemory_free_ring(); |
237 | return QString::null; | 237 | return QString::null; |
238 | } | 238 | } |
239 | icalmemory_free_ring(); | 239 | icalmemory_free_ring(); |
240 | return ret; | 240 | return ret; |
241 | } | 241 | } |
242 | 242 | ||
243 | QString ICalFormat::toICalString( Incidence *incidence ) | 243 | QString ICalFormat::toICalString( Incidence *incidence ) |
244 | { | 244 | { |
245 | CalendarLocal cal( mTimeZoneId ); | 245 | CalendarLocal cal( mTimeZoneId ); |
246 | cal.addIncidence( incidence->clone() ); | 246 | cal.addIncidence( incidence->clone() ); |
247 | return toString( &cal ); | 247 | return toString( &cal ); |
248 | } | 248 | } |
249 | 249 | ||
250 | QString ICalFormat::toString( Incidence *incidence ) | 250 | QString ICalFormat::toString( Incidence *incidence ) |
251 | { | 251 | { |
252 | icalcomponent *component; | 252 | icalcomponent *component; |
253 | 253 | ||
254 | component = mImpl->writeIncidence( incidence ); | 254 | component = mImpl->writeIncidence( incidence ); |
255 | 255 | ||
256 | const char *text = icalcomponent_as_ical_string( component ); | 256 | const char *text = icalcomponent_as_ical_string( component ); |
257 | 257 | ||
258 | icalcomponent_free( component ); | 258 | icalcomponent_free( component ); |
259 | 259 | ||
260 | return QString::fromLocal8Bit( text ); | 260 | return QString::fromLocal8Bit( text ); |
261 | } | 261 | } |
262 | 262 | ||
263 | QString ICalFormat::toString( Recurrence *recurrence ) | 263 | QString ICalFormat::toString( Recurrence *recurrence ) |
264 | { | 264 | { |
265 | icalproperty *property; | 265 | icalproperty *property; |
266 | property = mImpl->writeRecurrenceRule( recurrence ); | 266 | property = mImpl->writeRecurrenceRule( recurrence ); |
267 | const char *text = icalproperty_as_ical_string( property ); | 267 | const char *text = icalproperty_as_ical_string( property ); |
268 | icalproperty_free( property ); | 268 | icalproperty_free( property ); |
269 | return QString::fromLocal8Bit( text ); | 269 | return QString::fromLocal8Bit( text ); |
270 | } | 270 | } |
271 | /* | 271 | /* |
272 | bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) | 272 | bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) |
273 | { | 273 | { |
274 | bool success = true; | 274 | bool success = true; |
275 | icalerror_clear_errno(); | 275 | icalerror_clear_errno(); |
276 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); | 276 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); |
277 | if ( icalerrno != ICAL_NO_ERROR ) { | 277 | if ( icalerrno != ICAL_NO_ERROR ) { |
278 | kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; | 278 | kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; |
279 | success = false; | 279 | success = false; |
280 | } | 280 | } |
281 | 281 | ||
282 | if ( success ) { | 282 | if ( success ) { |
283 | mImpl->readRecurrence( recur, recurrence ); | 283 | mImpl->readRecurrence( recur, recurrence ); |
284 | } | 284 | } |
285 | 285 | ||
286 | return success; | 286 | return success; |
287 | } | 287 | } |
288 | */ | 288 | */ |
289 | 289 | ||
290 | QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, | 290 | QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, |
291 | Scheduler::Method method) | 291 | Scheduler::Method method) |
292 | { | 292 | { |
293 | icalcomponent *message = mImpl->createScheduleComponent(incidence,method); | 293 | icalcomponent *message = mImpl->createScheduleComponent(incidence,method); |
294 | 294 | ||
295 | QString messageText = icalcomponent_as_ical_string(message); | 295 | QString messageText = icalcomponent_as_ical_string(message); |
296 | 296 | ||
297 | 297 | ||
298 | 298 | ||
299 | return messageText; | 299 | return messageText; |
300 | } | 300 | } |
301 | 301 | ||
302 | ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, | 302 | ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, |
303 | const QString &messageText ) | 303 | const QString &messageText ) |
304 | { | 304 | { |
305 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 305 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
306 | clearException(); | 306 | clearException(); |
307 | 307 | ||
308 | if (messageText.isEmpty()) return 0; | 308 | if (messageText.isEmpty()) return 0; |
309 | 309 | ||
310 | icalcomponent *message; | 310 | icalcomponent *message; |
311 | message = icalparser_parse_string(messageText.local8Bit()); | 311 | message = icalparser_parse_string(messageText.local8Bit()); |
312 | 312 | ||
313 | if (!message) return 0; | 313 | if (!message) return 0; |
314 | 314 | ||
315 | icalproperty *m = icalcomponent_get_first_property(message, | 315 | icalproperty *m = icalcomponent_get_first_property(message, |
316 | ICAL_METHOD_PROPERTY); | 316 | ICAL_METHOD_PROPERTY); |
317 | 317 | ||
318 | if (!m) return 0; | 318 | if (!m) return 0; |
319 | 319 | ||
320 | icalcomponent *c; | 320 | icalcomponent *c; |
321 | 321 | ||
322 | IncidenceBase *incidence = 0; | 322 | IncidenceBase *incidence = 0; |
323 | c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); | 323 | c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); |
324 | if (c) { | 324 | if (c) { |
325 | incidence = mImpl->readEvent(c); | 325 | incidence = mImpl->readEvent(c); |
326 | } | 326 | } |
327 | 327 | ||
328 | if (!incidence) { | 328 | if (!incidence) { |
329 | c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); | 329 | c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); |
330 | if (c) { | 330 | if (c) { |
331 | incidence = mImpl->readTodo(c); | 331 | incidence = mImpl->readTodo(c); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | if (!incidence) { | 335 | if (!incidence) { |
336 | c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); | 336 | c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); |
337 | if (c) { | 337 | if (c) { |
338 | incidence = mImpl->readFreeBusy(c); | 338 | incidence = mImpl->readFreeBusy(c); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | if (!incidence) { | 342 | if (!incidence) { |
343 | kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; | 343 | kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; |
344 | return 0; | 344 | return 0; |
345 | } | 345 | } |
346 | 346 | ||
347 | kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; | 347 | kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; |
348 | 348 | ||
349 | icalproperty_method icalmethod = icalproperty_get_method(m); | 349 | icalproperty_method icalmethod = icalproperty_get_method(m); |
350 | Scheduler::Method method; | 350 | Scheduler::Method method; |
351 | 351 | ||
352 | switch (icalmethod) { | 352 | switch (icalmethod) { |
353 | case ICAL_METHOD_PUBLISH: | 353 | case ICAL_METHOD_PUBLISH: |
354 | method = Scheduler::Publish; | 354 | method = Scheduler::Publish; |
355 | break; | 355 | break; |
356 | case ICAL_METHOD_REQUEST: | 356 | case ICAL_METHOD_REQUEST: |
357 | method = Scheduler::Request; | 357 | method = Scheduler::Request; |
358 | break; | 358 | break; |
359 | case ICAL_METHOD_REFRESH: | 359 | case ICAL_METHOD_REFRESH: |
360 | method = Scheduler::Refresh; | 360 | method = Scheduler::Refresh; |
361 | break; | 361 | break; |
362 | case ICAL_METHOD_CANCEL: | 362 | case ICAL_METHOD_CANCEL: |
363 | method = Scheduler::Cancel; | 363 | method = Scheduler::Cancel; |
364 | break; | 364 | break; |
365 | case ICAL_METHOD_ADD: | 365 | case ICAL_METHOD_ADD: |
366 | method = Scheduler::Add; | 366 | method = Scheduler::Add; |
367 | break; | 367 | break; |
368 | case ICAL_METHOD_REPLY: | 368 | case ICAL_METHOD_REPLY: |
369 | method = Scheduler::Reply; | 369 | method = Scheduler::Reply; |
370 | break; | 370 | break; |
371 | case ICAL_METHOD_COUNTER: | 371 | case ICAL_METHOD_COUNTER: |
372 | method = Scheduler::Counter; | 372 | method = Scheduler::Counter; |
373 | break; | 373 | break; |
374 | case ICAL_METHOD_DECLINECOUNTER: | 374 | case ICAL_METHOD_DECLINECOUNTER: |
375 | method = Scheduler::Declinecounter; | 375 | method = Scheduler::Declinecounter; |
376 | break; | 376 | break; |
377 | default: | 377 | default: |
378 | method = Scheduler::NoMethod; | 378 | method = Scheduler::NoMethod; |
379 | kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; | 379 | kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; |
380 | break; | 380 | break; |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | if (!icalrestriction_check(message)) { | 384 | if (!icalrestriction_check(message)) { |
385 | setException(new ErrorFormat(ErrorFormat::Restriction, | 385 | setException(new ErrorFormat(ErrorFormat::Restriction, |
386 | Scheduler::translatedMethodName(method) + ": " + | 386 | Scheduler::translatedMethodName(method) + ": " + |
387 | mImpl->extractErrorProperty(c))); | 387 | mImpl->extractErrorProperty(c))); |
388 | return 0; | 388 | return 0; |
389 | } | 389 | } |
390 | 390 | ||
391 | icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); | 391 | icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); |
392 | 392 | ||
393 | Incidence *existingIncidence = cal->event(incidence->uid()); | 393 | Incidence *existingIncidence = cal->event(incidence->uid()); |
394 | if (existingIncidence) { | 394 | if (existingIncidence) { |
395 | // TODO: check, if cast is required, or if it can be done by virtual funcs. | 395 | // TODO: check, if cast is required, or if it can be done by virtual funcs. |
396 | if (existingIncidence->typeID() == todoID ) { | 396 | if (existingIncidence->typeID() == todoID ) { |
397 | Todo *todo = static_cast<Todo *>(existingIncidence); | 397 | Todo *todo = static_cast<Todo *>(existingIncidence); |
398 | icalcomponent_add_component(calendarComponent, | 398 | icalcomponent_add_component(calendarComponent, |
399 | mImpl->writeTodo(todo)); | 399 | mImpl->writeTodo(todo)); |
400 | } | 400 | } |
401 | if (existingIncidence->typeID() == eventID ) { | 401 | if (existingIncidence->typeID() == eventID ) { |
402 | Event *event = static_cast<Event *>(existingIncidence); | 402 | Event *event = static_cast<Event *>(existingIncidence); |
403 | icalcomponent_add_component(calendarComponent, | 403 | icalcomponent_add_component(calendarComponent, |
404 | mImpl->writeEvent(event)); | 404 | mImpl->writeEvent(event)); |
405 | } | 405 | } |
406 | } else { | 406 | } else { |
407 | calendarComponent = 0; | 407 | calendarComponent = 0; |
408 | } | 408 | } |
409 | qDebug("icalclassify commented out "); | 409 | qDebug("icalclassify commented out "); |
410 | ScheduleMessage::Status status; | 410 | ScheduleMessage::Status status; |
411 | #if 0 | 411 | #if 0 |
412 | 412 | ||
413 | icalclass result = icalclassify(message,calendarComponent,(char *)""); | 413 | icalclass result = icalclassify(message,calendarComponent,(char *)""); |
414 | 414 | ||
415 | 415 | ||
416 | 416 | ||
417 | switch (result) { | 417 | switch (result) { |
418 | case ICAL_PUBLISH_NEW_CLASS: | 418 | case ICAL_PUBLISH_NEW_CLASS: |
419 | status = ScheduleMessage::PublishNew; | 419 | status = ScheduleMessage::PublishNew; |
420 | break; | 420 | break; |
421 | case ICAL_OBSOLETE_CLASS: | 421 | case ICAL_OBSOLETE_CLASS: |
422 | status = ScheduleMessage::Obsolete; | 422 | status = ScheduleMessage::Obsolete; |
423 | break; | 423 | break; |
424 | case ICAL_REQUEST_NEW_CLASS: | 424 | case ICAL_REQUEST_NEW_CLASS: |
425 | status = ScheduleMessage::RequestNew; | 425 | status = ScheduleMessage::RequestNew; |
426 | break; | 426 | break; |
427 | case ICAL_REQUEST_UPDATE_CLASS: | 427 | case ICAL_REQUEST_UPDATE_CLASS: |
428 | status = ScheduleMessage::RequestUpdate; | 428 | status = ScheduleMessage::RequestUpdate; |
429 | break; | 429 | break; |
430 | case ICAL_UNKNOWN_CLASS: | 430 | case ICAL_UNKNOWN_CLASS: |
431 | default: | 431 | default: |
432 | status = ScheduleMessage::Unknown; | 432 | status = ScheduleMessage::Unknown; |
433 | break; | 433 | break; |
434 | } | 434 | } |
435 | #endif | 435 | #endif |
436 | status = ScheduleMessage::RequestUpdate; | 436 | status = ScheduleMessage::RequestUpdate; |
437 | return new ScheduleMessage(incidence,method,status); | 437 | return new ScheduleMessage(incidence,method,status); |
438 | } | 438 | } |
439 | 439 | ||
440 | void ICalFormat::setTimeZone( const QString &id, bool utc ) | 440 | void ICalFormat::setTimeZone( const QString &id, bool utc ) |
441 | { | 441 | { |
442 | 442 | ||
443 | 443 | ||
444 | mTimeZoneId = id; | 444 | mTimeZoneId = id; |
445 | mUtc = utc; | 445 | mUtc = utc; |
446 | 446 | ||
447 | tzOffsetMin = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 447 | tzOffsetMin = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
448 | 448 | ||
449 | //qDebug("ICalFormat::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), tzOffsetMin); | 449 | //qDebug("ICalFormat::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), tzOffsetMin); |
450 | } | 450 | } |
451 | 451 | ||
452 | QString ICalFormat::timeZoneId() const | 452 | QString ICalFormat::timeZoneId() const |
453 | { | 453 | { |
454 | return mTimeZoneId; | 454 | return mTimeZoneId; |
455 | } | 455 | } |
456 | 456 | ||
457 | bool ICalFormat::utc() const | 457 | bool ICalFormat::utc() const |
458 | { | 458 | { |
459 | return mUtc; | 459 | return mUtc; |
460 | } | 460 | } |
461 | int ICalFormat::timeOffset() | 461 | int ICalFormat::timeOffset() |
462 | { | 462 | { |
463 | return tzOffsetMin; | 463 | return tzOffsetMin; |
464 | } | 464 | } |
465 | const char *ICalFormat::tzString() | 465 | const char *ICalFormat::tzString() |
466 | { | 466 | { |
467 | const char* ret = (const char* ) mTzString; | 467 | const char* ret = (const char* ) mTzString; |
468 | return ret; | 468 | return ret; |
469 | } | 469 | } |
diff --git a/libkcal/icalformat.h b/libkcal/icalformat.h index a770dbb..a454b35 100644 --- a/libkcal/icalformat.h +++ b/libkcal/icalformat.h | |||
@@ -1,116 +1,118 @@ | |||
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 ICALFORMAT_H | 20 | #ifndef ICALFORMAT_H |
21 | #define ICALFORMAT_H | 21 | #define ICALFORMAT_H |
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | //Added by qt3to4: | ||
25 | #include <Q3CString> | ||
24 | 26 | ||
25 | #include "scheduler.h" | 27 | #include "scheduler.h" |
26 | 28 | ||
27 | #include "calformat.h" | 29 | #include "calformat.h" |
28 | 30 | ||
29 | namespace KCal { | 31 | namespace KCal { |
30 | 32 | ||
31 | class ICalFormatImpl; | 33 | class ICalFormatImpl; |
32 | 34 | ||
33 | /** | 35 | /** |
34 | This class implements the iCalendar format. It provides methods for | 36 | This class implements the iCalendar format. It provides methods for |
35 | loading/saving/converting iCalendar format data into the internal KOrganizer | 37 | loading/saving/converting iCalendar format data into the internal KOrganizer |
36 | representation as Calendar and Events. | 38 | representation as Calendar and Events. |
37 | 39 | ||
38 | @short iCalendar format implementation | 40 | @short iCalendar format implementation |
39 | */ | 41 | */ |
40 | class ICalFormat : public CalFormat { | 42 | class ICalFormat : public CalFormat { |
41 | public: | 43 | public: |
42 | /** Create new iCalendar format. */ | 44 | /** Create new iCalendar format. */ |
43 | ICalFormat( bool pe = true); | 45 | ICalFormat( bool pe = true); |
44 | virtual ~ICalFormat(); | 46 | virtual ~ICalFormat(); |
45 | 47 | ||
46 | /** | 48 | /** |
47 | Loads a calendar on disk in iCalendar format into calendar. | 49 | Loads a calendar on disk in iCalendar format into calendar. |
48 | Returns true if successful, else returns false. Provides more error | 50 | Returns true if successful, else returns false. Provides more error |
49 | information by exception(). | 51 | information by exception(). |
50 | @param calendar Calendar object to be filled. | 52 | @param calendar Calendar object to be filled. |
51 | @param fileName The name of the calendar file on disk. | 53 | @param fileName The name of the calendar file on disk. |
52 | */ | 54 | */ |
53 | bool load( Calendar *, const QString &fileName ); | 55 | bool load( Calendar *, const QString &fileName ); |
54 | /** | 56 | /** |
55 | Writes out the calendar to disk in iCalendar format. Returns true if | 57 | Writes out the calendar to disk in iCalendar format. Returns true if |
56 | successful and false on error. | 58 | successful and false on error. |
57 | 59 | ||
58 | @param calendar The Calendar object to be written. | 60 | @param calendar The Calendar object to be written. |
59 | @param fileName The name of the calendar file on disk. | 61 | @param fileName The name of the calendar file on disk. |
60 | */ | 62 | */ |
61 | bool save( Calendar *, const QString &fileName ); | 63 | bool save( Calendar *, const QString &fileName ); |
62 | 64 | ||
63 | /** | 65 | /** |
64 | Parse string and populate calendar with that information. | 66 | Parse string and populate calendar with that information. |
65 | */ | 67 | */ |
66 | bool fromString( Calendar *, const QString & ); | 68 | bool fromString( Calendar *, const QString & ); |
67 | /** | 69 | /** |
68 | Parse string and return first ical component. | 70 | Parse string and return first ical component. |
69 | */ | 71 | */ |
70 | Incidence *fromString( const QString & ); | 72 | Incidence *fromString( const QString & ); |
71 | /** | 73 | /** |
72 | Return calendar information as string. | 74 | Return calendar information as string. |
73 | */ | 75 | */ |
74 | QString toString( Calendar * ); | 76 | QString toString( Calendar * ); |
75 | /** | 77 | /** |
76 | Return incidence as full iCalendar formatted text. | 78 | Return incidence as full iCalendar formatted text. |
77 | */ | 79 | */ |
78 | QString toICalString( Incidence * ); | 80 | QString toICalString( Incidence * ); |
79 | /** | 81 | /** |
80 | Return incidence as iCalendar formatted text. | 82 | Return incidence as iCalendar formatted text. |
81 | */ | 83 | */ |
82 | QString toString( Incidence * ); | 84 | QString toString( Incidence * ); |
83 | /** | 85 | /** |
84 | Return recurrence as iCalendar formatted text. | 86 | Return recurrence as iCalendar formatted text. |
85 | */ | 87 | */ |
86 | QString toString( Recurrence * ); | 88 | QString toString( Recurrence * ); |
87 | /** | 89 | /** |
88 | Parse string and fill recurrence object with | 90 | Parse string and fill recurrence object with |
89 | that information | 91 | that information |
90 | */ | 92 | */ |
91 | //bool fromString ( Recurrence *, const QString& ); | 93 | //bool fromString ( Recurrence *, const QString& ); |
92 | 94 | ||
93 | /** Create a scheduling message for event \a e using method \m */ | 95 | /** Create a scheduling message for event \a e using method \m */ |
94 | QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m); | 96 | QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m); |
95 | /** Parse scheduling message provided as string \s */ | 97 | /** Parse scheduling message provided as string \s */ |
96 | ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s); | 98 | ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s); |
97 | 99 | ||
98 | /** Set id of used time zone and whether this time zone is UTC or not. */ | 100 | /** Set id of used time zone and whether this time zone is UTC or not. */ |
99 | void setTimeZone( const QString &id, bool utc ); | 101 | void setTimeZone( const QString &id, bool utc ); |
100 | QString timeZoneId() const; | 102 | QString timeZoneId() const; |
101 | int timeOffset(); | 103 | int timeOffset(); |
102 | const char * tzString(); | 104 | const char * tzString(); |
103 | bool utc() const; | 105 | bool utc() const; |
104 | 106 | ||
105 | private: | 107 | private: |
106 | bool mProcessEvents; | 108 | bool mProcessEvents; |
107 | ICalFormatImpl *mImpl; | 109 | ICalFormatImpl *mImpl; |
108 | QString mTimeZoneId; | 110 | QString mTimeZoneId; |
109 | QCString mTzString; | 111 | Q3CString mTzString; |
110 | int tzOffsetMin; | 112 | int tzOffsetMin; |
111 | bool mUtc; | 113 | bool mUtc; |
112 | }; | 114 | }; |
113 | 115 | ||
114 | } | 116 | } |
115 | 117 | ||
116 | #endif | 118 | #endif |
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp index 65eabc8..ea144ee 100644 --- a/libkcal/icalformatimpl.cpp +++ b/libkcal/icalformatimpl.cpp | |||
@@ -1,1854 +1,1857 @@ | |||
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 <qdatetime.h> | 21 | #include <qdatetime.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qptrlist.h> | 23 | #include <q3ptrlist.h> |
24 | #include <qfile.h> | 24 | #include <qfile.h> |
25 | //Added by qt3to4: | ||
26 | #include <Q3ValueList> | ||
27 | #include <Q3CString> | ||
25 | 28 | ||
26 | #include <kdebug.h> | 29 | #include <kdebug.h> |
27 | #include <klocale.h> | 30 | #include <klocale.h> |
28 | #include <kglobal.h> | 31 | #include <kglobal.h> |
29 | 32 | ||
30 | extern "C" { | 33 | extern "C" { |
31 | #include <ical.h> | 34 | #include <ical.h> |
32 | #include <icalss.h> | 35 | #include <icalss.h> |
33 | #include <icalparser.h> | 36 | #include <icalparser.h> |
34 | #include <icalrestriction.h> | 37 | #include <icalrestriction.h> |
35 | } | 38 | } |
36 | 39 | ||
37 | #include "calendar.h" | 40 | #include "calendar.h" |
38 | #include "journal.h" | 41 | #include "journal.h" |
39 | #include "icalformat.h" | 42 | #include "icalformat.h" |
40 | #include "icalformatimpl.h" | 43 | #include "icalformatimpl.h" |
41 | #include "compat.h" | 44 | #include "compat.h" |
42 | 45 | ||
43 | #define _ICAL_VERSION "2.0" | 46 | #define _ICAL_VERSION "2.0" |
44 | 47 | ||
45 | using namespace KCal; | 48 | using namespace KCal; |
46 | 49 | ||
47 | const int gSecondsPerMinute = 60; | 50 | const int gSecondsPerMinute = 60; |
48 | const int gSecondsPerHour = gSecondsPerMinute * 60; | 51 | const int gSecondsPerHour = gSecondsPerMinute * 60; |
49 | const int gSecondsPerDay = gSecondsPerHour * 24; | 52 | const int gSecondsPerDay = gSecondsPerHour * 24; |
50 | const int gSecondsPerWeek = gSecondsPerDay * 7; | 53 | const int gSecondsPerWeek = gSecondsPerDay * 7; |
51 | 54 | ||
52 | ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : | 55 | ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : |
53 | mParent( parent ), mCalendarVersion( 0 ) | 56 | mParent( parent ), mCalendarVersion( 0 ) |
54 | { | 57 | { |
55 | mCompat = new Compat; | 58 | mCompat = new Compat; |
56 | } | 59 | } |
57 | 60 | ||
58 | ICalFormatImpl::~ICalFormatImpl() | 61 | ICalFormatImpl::~ICalFormatImpl() |
59 | { | 62 | { |
60 | delete mCompat; | 63 | delete mCompat; |
61 | } | 64 | } |
62 | 65 | ||
63 | class ToStringVisitor : public Incidence::Visitor | 66 | class ToStringVisitor : public Incidence::Visitor |
64 | { | 67 | { |
65 | public: | 68 | public: |
66 | ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} | 69 | ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} |
67 | 70 | ||
68 | bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } | 71 | bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } |
69 | bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } | 72 | bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } |
70 | bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } | 73 | bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } |
71 | 74 | ||
72 | icalcomponent *component() { return mComponent; } | 75 | icalcomponent *component() { return mComponent; } |
73 | 76 | ||
74 | private: | 77 | private: |
75 | ICalFormatImpl *mImpl; | 78 | ICalFormatImpl *mImpl; |
76 | icalcomponent *mComponent; | 79 | icalcomponent *mComponent; |
77 | }; | 80 | }; |
78 | 81 | ||
79 | icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) | 82 | icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) |
80 | { | 83 | { |
81 | ToStringVisitor v( this ); | 84 | ToStringVisitor v( this ); |
82 | incidence->accept(v); | 85 | incidence->accept(v); |
83 | return v.component(); | 86 | return v.component(); |
84 | } | 87 | } |
85 | 88 | ||
86 | icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) | 89 | icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) |
87 | { | 90 | { |
88 | QString tmpStr; | 91 | QString tmpStr; |
89 | QStringList tmpStrList; | 92 | QStringList tmpStrList; |
90 | 93 | ||
91 | icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); | 94 | icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); |
92 | 95 | ||
93 | writeIncidence(vtodo,todo); | 96 | writeIncidence(vtodo,todo); |
94 | 97 | ||
95 | // due date | 98 | // due date |
96 | if (todo->hasDueDate()) { | 99 | if (todo->hasDueDate()) { |
97 | icaltimetype due; | 100 | icaltimetype due; |
98 | if (todo->doesFloat()) { | 101 | if (todo->doesFloat()) { |
99 | due = writeICalDate(todo->dtDue().date()); | 102 | due = writeICalDate(todo->dtDue().date()); |
100 | } else { | 103 | } else { |
101 | due = writeICalDateTime(todo->dtDue()); | 104 | due = writeICalDateTime(todo->dtDue()); |
102 | } | 105 | } |
103 | icalcomponent_add_property(vtodo,icalproperty_new_due(due)); | 106 | icalcomponent_add_property(vtodo,icalproperty_new_due(due)); |
104 | } | 107 | } |
105 | 108 | ||
106 | // start time | 109 | // start time |
107 | if (todo->hasStartDate()) { | 110 | if (todo->hasStartDate()) { |
108 | icaltimetype start; | 111 | icaltimetype start; |
109 | if (todo->doesFloat()) { | 112 | if (todo->doesFloat()) { |
110 | // kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; | 113 | // kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; |
111 | start = writeICalDate(todo->dtStart().date()); | 114 | start = writeICalDate(todo->dtStart().date()); |
112 | } else { | 115 | } else { |
113 | // kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; | 116 | // kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; |
114 | start = writeICalDateTime(todo->dtStart()); | 117 | start = writeICalDateTime(todo->dtStart()); |
115 | } | 118 | } |
116 | icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); | 119 | icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); |
117 | } | 120 | } |
118 | 121 | ||
119 | // completion date | 122 | // completion date |
120 | if (todo->isCompleted()) { | 123 | if (todo->isCompleted()) { |
121 | if (!todo->hasCompletedDate()) { | 124 | if (!todo->hasCompletedDate()) { |
122 | // If todo was created by KOrganizer <2.2 it has no correct completion | 125 | // If todo was created by KOrganizer <2.2 it has no correct completion |
123 | // date. Set it to now. | 126 | // date. Set it to now. |
124 | todo->setCompleted(QDateTime::currentDateTime()); | 127 | todo->setCompleted(QDateTime::currentDateTime()); |
125 | } | 128 | } |
126 | icaltimetype completed = writeICalDateTime(todo->completed()); | 129 | icaltimetype completed = writeICalDateTime(todo->completed()); |
127 | icalcomponent_add_property(vtodo,icalproperty_new_completed(completed)); | 130 | icalcomponent_add_property(vtodo,icalproperty_new_completed(completed)); |
128 | } | 131 | } |
129 | 132 | ||
130 | icalcomponent_add_property(vtodo, | 133 | icalcomponent_add_property(vtodo, |
131 | icalproperty_new_percentcomplete(todo->percentComplete())); | 134 | icalproperty_new_percentcomplete(todo->percentComplete())); |
132 | 135 | ||
133 | return vtodo; | 136 | return vtodo; |
134 | } | 137 | } |
135 | 138 | ||
136 | icalcomponent *ICalFormatImpl::writeEvent(Event *event) | 139 | icalcomponent *ICalFormatImpl::writeEvent(Event *event) |
137 | { | 140 | { |
138 | kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() | 141 | kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() |
139 | << ")" << endl; | 142 | << ")" << endl; |
140 | 143 | ||
141 | QString tmpStr; | 144 | QString tmpStr; |
142 | QStringList tmpStrList; | 145 | QStringList tmpStrList; |
143 | 146 | ||
144 | icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); | 147 | icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); |
145 | 148 | ||
146 | writeIncidence(vevent,event); | 149 | writeIncidence(vevent,event); |
147 | 150 | ||
148 | // start time | 151 | // start time |
149 | icaltimetype start; | 152 | icaltimetype start; |
150 | if (event->doesFloat()) { | 153 | if (event->doesFloat()) { |
151 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; | 154 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; |
152 | start = writeICalDate(event->dtStart().date()); | 155 | start = writeICalDate(event->dtStart().date()); |
153 | } else { | 156 | } else { |
154 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; | 157 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; |
155 | start = writeICalDateTime(event->dtStart()); | 158 | start = writeICalDateTime(event->dtStart()); |
156 | } | 159 | } |
157 | icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); | 160 | icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); |
158 | 161 | ||
159 | if (event->hasEndDate()) { | 162 | if (event->hasEndDate()) { |
160 | // end time | 163 | // end time |
161 | icaltimetype end; | 164 | icaltimetype end; |
162 | if (event->doesFloat()) { | 165 | if (event->doesFloat()) { |
163 | // kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; | 166 | // kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; |
164 | // +1 day because end date is non-inclusive. | 167 | // +1 day because end date is non-inclusive. |
165 | end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); | 168 | end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); |
166 | } else { | 169 | } else { |
167 | // kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; | 170 | // kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; |
168 | end = writeICalDateTime(event->dtEnd()); | 171 | end = writeICalDateTime(event->dtEnd()); |
169 | } | 172 | } |
170 | icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); | 173 | icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); |
171 | } | 174 | } |
172 | 175 | ||
173 | // TODO: attachments, resources | 176 | // TODO: attachments, resources |
174 | #if 0 | 177 | #if 0 |
175 | // attachments | 178 | // attachments |
176 | tmpStrList = anEvent->attachments(); | 179 | tmpStrList = anEvent->attachments(); |
177 | for ( QStringList::Iterator it = tmpStrList.begin(); | 180 | for ( QStringList::Iterator it = tmpStrList.begin(); |
178 | it != tmpStrList.end(); | 181 | it != tmpStrList.end(); |
179 | ++it ) | 182 | ++it ) |
180 | addPropValue(vevent, VCAttachProp, (*it).utf8()); | 183 | addPropValue(vevent, VCAttachProp, (*it).utf8()); |
181 | 184 | ||
182 | // resources | 185 | // resources |
183 | tmpStrList = anEvent->resources(); | 186 | tmpStrList = anEvent->resources(); |
184 | tmpStr = tmpStrList.join(";"); | 187 | tmpStr = tmpStrList.join(";"); |
185 | if (!tmpStr.isEmpty()) | 188 | if (!tmpStr.isEmpty()) |
186 | addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); | 189 | addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); |
187 | 190 | ||
188 | #endif | 191 | #endif |
189 | 192 | ||
190 | // Transparency | 193 | // Transparency |
191 | switch( event->transparency() ) { | 194 | switch( event->transparency() ) { |
192 | case Event::Transparent: | 195 | case Event::Transparent: |
193 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); | 196 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); |
194 | break; | 197 | break; |
195 | case Event::Opaque: | 198 | case Event::Opaque: |
196 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); | 199 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); |
197 | break; | 200 | break; |
198 | } | 201 | } |
199 | 202 | ||
200 | return vevent; | 203 | return vevent; |
201 | } | 204 | } |
202 | 205 | ||
203 | icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, | 206 | icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, |
204 | Scheduler::Method method) | 207 | Scheduler::Method method) |
205 | { | 208 | { |
206 | 209 | ||
207 | 210 | ||
208 | icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); | 211 | icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); |
209 | 212 | ||
210 | writeIncidenceBase(vfreebusy,freebusy); | 213 | writeIncidenceBase(vfreebusy,freebusy); |
211 | 214 | ||
212 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( | 215 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( |
213 | writeICalDateTime(freebusy->dtStart()))); | 216 | writeICalDateTime(freebusy->dtStart()))); |
214 | 217 | ||
215 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( | 218 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( |
216 | writeICalDateTime(freebusy->dtEnd()))); | 219 | writeICalDateTime(freebusy->dtEnd()))); |
217 | 220 | ||
218 | if (method == Scheduler::Request) { | 221 | if (method == Scheduler::Request) { |
219 | icalcomponent_add_property(vfreebusy,icalproperty_new_uid( | 222 | icalcomponent_add_property(vfreebusy,icalproperty_new_uid( |
220 | freebusy->uid().utf8())); | 223 | freebusy->uid().utf8())); |
221 | } | 224 | } |
222 | 225 | ||
223 | //Loops through all the periods in the freebusy object | 226 | //Loops through all the periods in the freebusy object |
224 | QValueList<Period> list = freebusy->busyPeriods(); | 227 | Q3ValueList<Period> list = freebusy->busyPeriods(); |
225 | QValueList<Period>::Iterator it; | 228 | Q3ValueList<Period>::Iterator it; |
226 | icalperiodtype period; | 229 | icalperiodtype period; |
227 | for (it = list.begin(); it!= list.end(); ++it) { | 230 | for (it = list.begin(); it!= list.end(); ++it) { |
228 | period.start = writeICalDateTime((*it).start()); | 231 | period.start = writeICalDateTime((*it).start()); |
229 | period.end = writeICalDateTime((*it).end()); | 232 | period.end = writeICalDateTime((*it).end()); |
230 | icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); | 233 | icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); |
231 | } | 234 | } |
232 | 235 | ||
233 | return vfreebusy; | 236 | return vfreebusy; |
234 | } | 237 | } |
235 | 238 | ||
236 | icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) | 239 | icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) |
237 | { | 240 | { |
238 | icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); | 241 | icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); |
239 | 242 | ||
240 | writeIncidence(vjournal,journal); | 243 | writeIncidence(vjournal,journal); |
241 | 244 | ||
242 | // start time | 245 | // start time |
243 | if (journal->dtStart().isValid()) { | 246 | if (journal->dtStart().isValid()) { |
244 | icaltimetype start; | 247 | icaltimetype start; |
245 | if (journal->doesFloat()) { | 248 | if (journal->doesFloat()) { |
246 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; | 249 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; |
247 | start = writeICalDate(journal->dtStart().date()); | 250 | start = writeICalDate(journal->dtStart().date()); |
248 | } else { | 251 | } else { |
249 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; | 252 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; |
250 | start = writeICalDateTime(journal->dtStart()); | 253 | start = writeICalDateTime(journal->dtStart()); |
251 | } | 254 | } |
252 | icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); | 255 | icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); |
253 | } | 256 | } |
254 | 257 | ||
255 | return vjournal; | 258 | return vjournal; |
256 | } | 259 | } |
257 | 260 | ||
258 | void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) | 261 | void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) |
259 | { | 262 | { |
260 | // pilot sync stuff | 263 | // pilot sync stuff |
261 | // TODO: move this application-specific code to kpilot | 264 | // TODO: move this application-specific code to kpilot |
262 | if (incidence->pilotId()) { | 265 | if (incidence->pilotId()) { |
263 | incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); | 266 | incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); |
264 | incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); | 267 | incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); |
265 | } | 268 | } |
266 | if ( !incidence->IDStr().isEmpty()) { | 269 | if ( !incidence->IDStr().isEmpty()) { |
267 | incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); | 270 | incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); |
268 | } | 271 | } |
269 | 272 | ||
270 | 273 | ||
271 | writeIncidenceBase(parent,incidence); | 274 | writeIncidenceBase(parent,incidence); |
272 | if (incidence->cancelled()) { | 275 | if (incidence->cancelled()) { |
273 | icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); | 276 | icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); |
274 | } | 277 | } |
275 | 278 | ||
276 | // creation date | 279 | // creation date |
277 | icalcomponent_add_property(parent,icalproperty_new_created( | 280 | icalcomponent_add_property(parent,icalproperty_new_created( |
278 | writeICalDateTime(incidence->created()))); | 281 | writeICalDateTime(incidence->created()))); |
279 | 282 | ||
280 | // unique id | 283 | // unique id |
281 | icalcomponent_add_property(parent,icalproperty_new_uid( | 284 | icalcomponent_add_property(parent,icalproperty_new_uid( |
282 | incidence->uid().utf8())); | 285 | incidence->uid().utf8())); |
283 | 286 | ||
284 | // revision | 287 | // revision |
285 | icalcomponent_add_property(parent,icalproperty_new_sequence( | 288 | icalcomponent_add_property(parent,icalproperty_new_sequence( |
286 | incidence->revision())); | 289 | incidence->revision())); |
287 | 290 | ||
288 | // last modification date | 291 | // last modification date |
289 | icalcomponent_add_property(parent,icalproperty_new_lastmodified( | 292 | icalcomponent_add_property(parent,icalproperty_new_lastmodified( |
290 | writeICalDateTime(incidence->lastModified()))); | 293 | writeICalDateTime(incidence->lastModified()))); |
291 | 294 | ||
292 | // description | 295 | // description |
293 | if (!incidence->description().isEmpty()) { | 296 | if (!incidence->description().isEmpty()) { |
294 | icalcomponent_add_property(parent,icalproperty_new_description( | 297 | icalcomponent_add_property(parent,icalproperty_new_description( |
295 | incidence->description().utf8())); | 298 | incidence->description().utf8())); |
296 | } | 299 | } |
297 | 300 | ||
298 | // summary | 301 | // summary |
299 | if (!incidence->summary().isEmpty()) { | 302 | if (!incidence->summary().isEmpty()) { |
300 | icalcomponent_add_property(parent,icalproperty_new_summary( | 303 | icalcomponent_add_property(parent,icalproperty_new_summary( |
301 | incidence->summary().utf8())); | 304 | incidence->summary().utf8())); |
302 | } | 305 | } |
303 | 306 | ||
304 | // location | 307 | // location |
305 | if (!incidence->location().isEmpty()) { | 308 | if (!incidence->location().isEmpty()) { |
306 | icalcomponent_add_property(parent,icalproperty_new_location( | 309 | icalcomponent_add_property(parent,icalproperty_new_location( |
307 | incidence->location().utf8())); | 310 | incidence->location().utf8())); |
308 | } | 311 | } |
309 | 312 | ||
310 | // TODO: | 313 | // TODO: |
311 | // status | 314 | // status |
312 | // addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); | 315 | // addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); |
313 | 316 | ||
314 | // secrecy | 317 | // secrecy |
315 | enum icalproperty_class classInt; | 318 | enum icalproperty_class classInt; |
316 | switch (incidence->secrecy()) { | 319 | switch (incidence->secrecy()) { |
317 | case Incidence::SecrecyPublic: | 320 | case Incidence::SecrecyPublic: |
318 | classInt = ICAL_CLASS_PUBLIC; | 321 | classInt = ICAL_CLASS_PUBLIC; |
319 | break; | 322 | break; |
320 | case Incidence::SecrecyConfidential: | 323 | case Incidence::SecrecyConfidential: |
321 | classInt = ICAL_CLASS_CONFIDENTIAL; | 324 | classInt = ICAL_CLASS_CONFIDENTIAL; |
322 | break; | 325 | break; |
323 | case Incidence::SecrecyPrivate: | 326 | case Incidence::SecrecyPrivate: |
324 | classInt =ICAL_CLASS_PRIVATE ; | 327 | classInt =ICAL_CLASS_PRIVATE ; |
325 | default: | 328 | default: |
326 | classInt =ICAL_CLASS_PRIVATE ; | 329 | classInt =ICAL_CLASS_PRIVATE ; |
327 | break; | 330 | break; |
328 | } | 331 | } |
329 | icalcomponent_add_property(parent,icalproperty_new_class(classInt)); | 332 | icalcomponent_add_property(parent,icalproperty_new_class(classInt)); |
330 | 333 | ||
331 | // priority | 334 | // priority |
332 | icalcomponent_add_property(parent,icalproperty_new_priority( | 335 | icalcomponent_add_property(parent,icalproperty_new_priority( |
333 | incidence->priority())); | 336 | incidence->priority())); |
334 | 337 | ||
335 | // categories | 338 | // categories |
336 | QStringList categories = incidence->categories(); | 339 | QStringList categories = incidence->categories(); |
337 | QStringList::Iterator it; | 340 | QStringList::Iterator it; |
338 | for(it = categories.begin(); it != categories.end(); ++it ) { | 341 | for(it = categories.begin(); it != categories.end(); ++it ) { |
339 | icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); | 342 | icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); |
340 | } | 343 | } |
341 | // TODO: Ensure correct concatenation of categories properties. | 344 | // TODO: Ensure correct concatenation of categories properties. |
342 | 345 | ||
343 | /* | 346 | /* |
344 | // categories | 347 | // categories |
345 | tmpStrList = incidence->getCategories(); | 348 | tmpStrList = incidence->getCategories(); |
346 | tmpStr = ""; | 349 | tmpStr = ""; |
347 | QString catStr; | 350 | QString catStr; |
348 | for ( QStringList::Iterator it = tmpStrList.begin(); | 351 | for ( QStringList::Iterator it = tmpStrList.begin(); |
349 | it != tmpStrList.end(); | 352 | it != tmpStrList.end(); |
350 | ++it ) { | 353 | ++it ) { |
351 | catStr = *it; | 354 | catStr = *it; |
352 | if (catStr[0] == ' ') | 355 | if (catStr[0] == ' ') |
353 | tmpStr += catStr.mid(1); | 356 | tmpStr += catStr.mid(1); |
354 | else | 357 | else |
355 | tmpStr += catStr; | 358 | tmpStr += catStr; |
356 | // this must be a ';' character as the vCalendar specification requires! | 359 | // this must be a ';' character as the vCalendar specification requires! |
357 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 360 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
358 | // read in. | 361 | // read in. |
359 | tmpStr += ";"; | 362 | tmpStr += ";"; |
360 | } | 363 | } |
361 | if (!tmpStr.isEmpty()) { | 364 | if (!tmpStr.isEmpty()) { |
362 | tmpStr.truncate(tmpStr.length()-1); | 365 | tmpStr.truncate(tmpStr.length()-1); |
363 | icalcomponent_add_property(parent,icalproperty_new_categories( | 366 | icalcomponent_add_property(parent,icalproperty_new_categories( |
364 | writeText(incidence->getCategories().join(";")))); | 367 | writeText(incidence->getCategories().join(";")))); |
365 | } | 368 | } |
366 | */ | 369 | */ |
367 | 370 | ||
368 | // related event | 371 | // related event |
369 | if (!incidence->relatedToUid().isEmpty()) { | 372 | if (!incidence->relatedToUid().isEmpty()) { |
370 | icalcomponent_add_property(parent,icalproperty_new_relatedto( | 373 | icalcomponent_add_property(parent,icalproperty_new_relatedto( |
371 | incidence->relatedToUid().utf8())); | 374 | incidence->relatedToUid().utf8())); |
372 | } | 375 | } |
373 | 376 | ||
374 | // recurrence rule stuff | 377 | // recurrence rule stuff |
375 | if (incidence->doesRecur()) { | 378 | if (incidence->doesRecur()) { |
376 | icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence())); | 379 | icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence())); |
377 | // recurrence excpetion dates | 380 | // recurrence excpetion dates |
378 | DateList dateList = incidence->exDates(); | 381 | DateList dateList = incidence->exDates(); |
379 | DateList::ConstIterator exIt; | 382 | DateList::ConstIterator exIt; |
380 | for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { | 383 | for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { |
381 | icalcomponent_add_property(parent,icalproperty_new_exdate( | 384 | icalcomponent_add_property(parent,icalproperty_new_exdate( |
382 | writeICalDate(*exIt))); | 385 | writeICalDate(*exIt))); |
383 | } | 386 | } |
384 | } | 387 | } |
385 | 388 | ||
386 | // attachments | 389 | // attachments |
387 | QPtrList<Attachment> attachments = incidence->attachments(); | 390 | Q3PtrList<Attachment> attachments = incidence->attachments(); |
388 | for (Attachment *at = attachments.first(); at; at = attachments.next()) | 391 | for (Attachment *at = attachments.first(); at; at = attachments.next()) |
389 | icalcomponent_add_property(parent,writeAttachment(at)); | 392 | icalcomponent_add_property(parent,writeAttachment(at)); |
390 | 393 | ||
391 | // alarms | 394 | // alarms |
392 | QPtrList<Alarm> alarms = incidence->alarms(); | 395 | Q3PtrList<Alarm> alarms = incidence->alarms(); |
393 | Alarm* alarm; | 396 | Alarm* alarm; |
394 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 397 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
395 | if (alarm->enabled()) { | 398 | if (alarm->enabled()) { |
396 | kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; | 399 | kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; |
397 | icalcomponent_add_component(parent,writeAlarm(alarm)); | 400 | icalcomponent_add_component(parent,writeAlarm(alarm)); |
398 | } | 401 | } |
399 | } | 402 | } |
400 | if( incidence->hasRecurrenceID() ) { | 403 | if( incidence->hasRecurrenceID() ) { |
401 | icalcomponent_add_property(parent, | 404 | icalcomponent_add_property(parent, |
402 | icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); | 405 | icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); |
403 | } | 406 | } |
404 | // duration | 407 | // duration |
405 | 408 | ||
406 | // turned off as it always is set to PTS0 (and must not occur together with DTEND | 409 | // turned off as it always is set to PTS0 (and must not occur together with DTEND |
407 | 410 | ||
408 | if (incidence->hasDuration()) { | 411 | if (incidence->hasDuration()) { |
409 | icaldurationtype duration; | 412 | icaldurationtype duration; |
410 | duration = writeICalDuration(incidence->duration()); | 413 | duration = writeICalDuration(incidence->duration()); |
411 | icalcomponent_add_property(parent,icalproperty_new_duration(duration)); | 414 | icalcomponent_add_property(parent,icalproperty_new_duration(duration)); |
412 | } | 415 | } |
413 | } | 416 | } |
414 | 417 | ||
415 | void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) | 418 | void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) |
416 | { | 419 | { |
417 | icalcomponent_add_property(parent,icalproperty_new_dtstamp( | 420 | icalcomponent_add_property(parent,icalproperty_new_dtstamp( |
418 | writeICalDateTime(QDateTime::currentDateTime()))); | 421 | writeICalDateTime(QDateTime::currentDateTime()))); |
419 | 422 | ||
420 | // organizer stuff | 423 | // organizer stuff |
421 | icalcomponent_add_property(parent,icalproperty_new_organizer( | 424 | icalcomponent_add_property(parent,icalproperty_new_organizer( |
422 | ("MAILTO:" + incidenceBase->organizer()).utf8())); | 425 | ("MAILTO:" + incidenceBase->organizer()).utf8())); |
423 | 426 | ||
424 | // attendees | 427 | // attendees |
425 | if (incidenceBase->attendeeCount() != 0) { | 428 | if (incidenceBase->attendeeCount() != 0) { |
426 | QPtrList<Attendee> al = incidenceBase->attendees(); | 429 | Q3PtrList<Attendee> al = incidenceBase->attendees(); |
427 | QPtrListIterator<Attendee> ai(al); | 430 | Q3PtrListIterator<Attendee> ai(al); |
428 | for (; ai.current(); ++ai) { | 431 | for (; ai.current(); ++ai) { |
429 | icalcomponent_add_property(parent,writeAttendee(ai.current())); | 432 | icalcomponent_add_property(parent,writeAttendee(ai.current())); |
430 | } | 433 | } |
431 | } | 434 | } |
432 | 435 | ||
433 | // custom properties | 436 | // custom properties |
434 | writeCustomProperties(parent, incidenceBase); | 437 | writeCustomProperties(parent, incidenceBase); |
435 | } | 438 | } |
436 | 439 | ||
437 | void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) | 440 | void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) |
438 | { | 441 | { |
439 | QMap<QCString, QString> custom = properties->customProperties(); | 442 | QMap<Q3CString, QString> custom = properties->customProperties(); |
440 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { | 443 | for (QMap<Q3CString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { |
441 | icalproperty *p = icalproperty_new_x(c.data().utf8()); | 444 | icalproperty *p = icalproperty_new_x(c.data().utf8()); |
442 | icalproperty_set_x_name(p,c.key()); | 445 | icalproperty_set_x_name(p,c.key()); |
443 | icalcomponent_add_property(parent,p); | 446 | icalcomponent_add_property(parent,p); |
444 | } | 447 | } |
445 | } | 448 | } |
446 | 449 | ||
447 | icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) | 450 | icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) |
448 | { | 451 | { |
449 | icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); | 452 | icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); |
450 | 453 | ||
451 | if (!attendee->name().isEmpty()) { | 454 | if (!attendee->name().isEmpty()) { |
452 | icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); | 455 | icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); |
453 | } | 456 | } |
454 | 457 | ||
455 | 458 | ||
456 | icalproperty_add_parameter(p,icalparameter_new_rsvp( | 459 | icalproperty_add_parameter(p,icalparameter_new_rsvp( |
457 | attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); | 460 | attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); |
458 | 461 | ||
459 | icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; | 462 | icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; |
460 | switch (attendee->status()) { | 463 | switch (attendee->status()) { |
461 | default: | 464 | default: |
462 | case Attendee::NeedsAction: | 465 | case Attendee::NeedsAction: |
463 | status = ICAL_PARTSTAT_NEEDSACTION; | 466 | status = ICAL_PARTSTAT_NEEDSACTION; |
464 | break; | 467 | break; |
465 | case Attendee::Accepted: | 468 | case Attendee::Accepted: |
466 | status = ICAL_PARTSTAT_ACCEPTED; | 469 | status = ICAL_PARTSTAT_ACCEPTED; |
467 | break; | 470 | break; |
468 | case Attendee::Declined: | 471 | case Attendee::Declined: |
469 | status = ICAL_PARTSTAT_DECLINED; | 472 | status = ICAL_PARTSTAT_DECLINED; |
470 | break; | 473 | break; |
471 | case Attendee::Tentative: | 474 | case Attendee::Tentative: |
472 | status = ICAL_PARTSTAT_TENTATIVE; | 475 | status = ICAL_PARTSTAT_TENTATIVE; |
473 | break; | 476 | break; |
474 | case Attendee::Delegated: | 477 | case Attendee::Delegated: |
475 | status = ICAL_PARTSTAT_DELEGATED; | 478 | status = ICAL_PARTSTAT_DELEGATED; |
476 | break; | 479 | break; |
477 | case Attendee::Completed: | 480 | case Attendee::Completed: |
478 | status = ICAL_PARTSTAT_COMPLETED; | 481 | status = ICAL_PARTSTAT_COMPLETED; |
479 | break; | 482 | break; |
480 | case Attendee::InProcess: | 483 | case Attendee::InProcess: |
481 | status = ICAL_PARTSTAT_INPROCESS; | 484 | status = ICAL_PARTSTAT_INPROCESS; |
482 | break; | 485 | break; |
483 | } | 486 | } |
484 | icalproperty_add_parameter(p,icalparameter_new_partstat(status)); | 487 | icalproperty_add_parameter(p,icalparameter_new_partstat(status)); |
485 | 488 | ||
486 | icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; | 489 | icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; |
487 | switch (attendee->role()) { | 490 | switch (attendee->role()) { |
488 | case Attendee::Chair: | 491 | case Attendee::Chair: |
489 | role = ICAL_ROLE_CHAIR; | 492 | role = ICAL_ROLE_CHAIR; |
490 | break; | 493 | break; |
491 | default: | 494 | default: |
492 | case Attendee::ReqParticipant: | 495 | case Attendee::ReqParticipant: |
493 | role = ICAL_ROLE_REQPARTICIPANT; | 496 | role = ICAL_ROLE_REQPARTICIPANT; |
494 | break; | 497 | break; |
495 | case Attendee::OptParticipant: | 498 | case Attendee::OptParticipant: |
496 | role = ICAL_ROLE_OPTPARTICIPANT; | 499 | role = ICAL_ROLE_OPTPARTICIPANT; |
497 | break; | 500 | break; |
498 | case Attendee::NonParticipant: | 501 | case Attendee::NonParticipant: |
499 | role = ICAL_ROLE_NONPARTICIPANT; | 502 | role = ICAL_ROLE_NONPARTICIPANT; |
500 | break; | 503 | break; |
501 | } | 504 | } |
502 | icalproperty_add_parameter(p,icalparameter_new_role(role)); | 505 | icalproperty_add_parameter(p,icalparameter_new_role(role)); |
503 | 506 | ||
504 | if (!attendee->uid().isEmpty()) { | 507 | if (!attendee->uid().isEmpty()) { |
505 | icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); | 508 | icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); |
506 | icalparameter_set_xname(icalparameter_uid,"X-UID"); | 509 | icalparameter_set_xname(icalparameter_uid,"X-UID"); |
507 | icalproperty_add_parameter(p,icalparameter_uid); | 510 | icalproperty_add_parameter(p,icalparameter_uid); |
508 | } | 511 | } |
509 | 512 | ||
510 | return p; | 513 | return p; |
511 | } | 514 | } |
512 | 515 | ||
513 | icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) | 516 | icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) |
514 | { | 517 | { |
515 | #if 0 | 518 | #if 0 |
516 | icalattachtype* attach = icalattachtype_new(); | 519 | icalattachtype* attach = icalattachtype_new(); |
517 | if (att->isUri()) | 520 | if (att->isUri()) |
518 | icalattachtype_set_url(attach, att->uri().utf8().data()); | 521 | icalattachtype_set_url(attach, att->uri().utf8().data()); |
519 | else | 522 | else |
520 | icalattachtype_set_base64(attach, att->data(), 0); | 523 | icalattachtype_set_base64(attach, att->data(), 0); |
521 | #endif | 524 | #endif |
522 | icalattach *attach; | 525 | icalattach *attach; |
523 | if (att->isUri()) | 526 | if (att->isUri()) |
524 | attach = icalattach_new_from_url( att->uri().utf8().data()); | 527 | attach = icalattach_new_from_url( att->uri().utf8().data()); |
525 | else | 528 | else |
526 | attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); | 529 | attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); |
527 | icalproperty *p = icalproperty_new_attach(attach); | 530 | icalproperty *p = icalproperty_new_attach(attach); |
528 | if (!att->mimeType().isEmpty()) | 531 | if (!att->mimeType().isEmpty()) |
529 | icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); | 532 | icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); |
530 | 533 | ||
531 | if (att->isBinary()) { | 534 | if (att->isBinary()) { |
532 | icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); | 535 | icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); |
533 | icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); | 536 | icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); |
534 | } | 537 | } |
535 | return p; | 538 | return p; |
536 | } | 539 | } |
537 | 540 | ||
538 | icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) | 541 | icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) |
539 | { | 542 | { |
540 | // kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; | 543 | // kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; |
541 | 544 | ||
542 | icalrecurrencetype r; | 545 | icalrecurrencetype r; |
543 | 546 | ||
544 | icalrecurrencetype_clear(&r); | 547 | icalrecurrencetype_clear(&r); |
545 | 548 | ||
546 | int index = 0; | 549 | int index = 0; |
547 | int index2 = 0; | 550 | int index2 = 0; |
548 | 551 | ||
549 | QPtrList<Recurrence::rMonthPos> tmpPositions; | 552 | Q3PtrList<Recurrence::rMonthPos> tmpPositions; |
550 | QPtrList<int> tmpDays; | 553 | Q3PtrList<int> tmpDays; |
551 | int *tmpDay; | 554 | int *tmpDay; |
552 | Recurrence::rMonthPos *tmpPos; | 555 | Recurrence::rMonthPos *tmpPos; |
553 | bool datetime = false; | 556 | bool datetime = false; |
554 | int day; | 557 | int day; |
555 | int i; | 558 | int i; |
556 | 559 | ||
557 | switch(recur->doesRecur()) { | 560 | switch(recur->doesRecur()) { |
558 | case Recurrence::rMinutely: | 561 | case Recurrence::rMinutely: |
559 | r.freq = ICAL_MINUTELY_RECURRENCE; | 562 | r.freq = ICAL_MINUTELY_RECURRENCE; |
560 | datetime = true; | 563 | datetime = true; |
561 | break; | 564 | break; |
562 | case Recurrence::rHourly: | 565 | case Recurrence::rHourly: |
563 | r.freq = ICAL_HOURLY_RECURRENCE; | 566 | r.freq = ICAL_HOURLY_RECURRENCE; |
564 | datetime = true; | 567 | datetime = true; |
565 | break; | 568 | break; |
566 | case Recurrence::rDaily: | 569 | case Recurrence::rDaily: |
567 | r.freq = ICAL_DAILY_RECURRENCE; | 570 | r.freq = ICAL_DAILY_RECURRENCE; |
568 | break; | 571 | break; |
569 | case Recurrence::rWeekly: | 572 | case Recurrence::rWeekly: |
570 | r.freq = ICAL_WEEKLY_RECURRENCE; | 573 | r.freq = ICAL_WEEKLY_RECURRENCE; |
571 | r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); | 574 | r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); |
572 | for (i = 0; i < 7; i++) { | 575 | for (i = 0; i < 7; i++) { |
573 | if (recur->days().testBit(i)) { | 576 | if (recur->days().testBit(i)) { |
574 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 577 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
575 | r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); | 578 | r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); |
576 | } | 579 | } |
577 | } | 580 | } |
578 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 581 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
579 | break; | 582 | break; |
580 | case Recurrence::rMonthlyPos: | 583 | case Recurrence::rMonthlyPos: |
581 | r.freq = ICAL_MONTHLY_RECURRENCE; | 584 | r.freq = ICAL_MONTHLY_RECURRENCE; |
582 | 585 | ||
583 | tmpPositions = recur->monthPositions(); | 586 | tmpPositions = recur->monthPositions(); |
584 | for (tmpPos = tmpPositions.first(); | 587 | for (tmpPos = tmpPositions.first(); |
585 | tmpPos; | 588 | tmpPos; |
586 | tmpPos = tmpPositions.next()) { | 589 | tmpPos = tmpPositions.next()) { |
587 | for (i = 0; i < 7; i++) { | 590 | for (i = 0; i < 7; i++) { |
588 | if (tmpPos->rDays.testBit(i)) { | 591 | if (tmpPos->rDays.testBit(i)) { |
589 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 592 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
590 | day += tmpPos->rPos*8; | 593 | day += tmpPos->rPos*8; |
591 | if (tmpPos->negative) day = -day; | 594 | if (tmpPos->negative) day = -day; |
592 | r.by_day[index++] = day; | 595 | r.by_day[index++] = day; |
593 | } | 596 | } |
594 | } | 597 | } |
595 | } | 598 | } |
596 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 599 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
597 | break; | 600 | break; |
598 | case Recurrence::rMonthlyDay: | 601 | case Recurrence::rMonthlyDay: |
599 | r.freq = ICAL_MONTHLY_RECURRENCE; | 602 | r.freq = ICAL_MONTHLY_RECURRENCE; |
600 | 603 | ||
601 | tmpDays = recur->monthDays(); | 604 | tmpDays = recur->monthDays(); |
602 | for (tmpDay = tmpDays.first(); | 605 | for (tmpDay = tmpDays.first(); |
603 | tmpDay; | 606 | tmpDay; |
604 | tmpDay = tmpDays.next()) { | 607 | tmpDay = tmpDays.next()) { |
605 | r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); | 608 | r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); |
606 | } | 609 | } |
607 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 610 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
608 | break; | 611 | break; |
609 | case Recurrence::rYearlyMonth: | 612 | case Recurrence::rYearlyMonth: |
610 | case Recurrence::rYearlyPos: | 613 | case Recurrence::rYearlyPos: |
611 | r.freq = ICAL_YEARLY_RECURRENCE; | 614 | r.freq = ICAL_YEARLY_RECURRENCE; |
612 | 615 | ||
613 | tmpDays = recur->yearNums(); | 616 | tmpDays = recur->yearNums(); |
614 | for (tmpDay = tmpDays.first(); | 617 | for (tmpDay = tmpDays.first(); |
615 | tmpDay; | 618 | tmpDay; |
616 | tmpDay = tmpDays.next()) { | 619 | tmpDay = tmpDays.next()) { |
617 | r.by_month[index++] = *tmpDay; | 620 | r.by_month[index++] = *tmpDay; |
618 | } | 621 | } |
619 | // r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; | 622 | // r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; |
620 | if (recur->doesRecur() == Recurrence::rYearlyPos) { | 623 | if (recur->doesRecur() == Recurrence::rYearlyPos) { |
621 | tmpPositions = recur->monthPositions(); | 624 | tmpPositions = recur->monthPositions(); |
622 | for (tmpPos = tmpPositions.first(); | 625 | for (tmpPos = tmpPositions.first(); |
623 | tmpPos; | 626 | tmpPos; |
624 | tmpPos = tmpPositions.next()) { | 627 | tmpPos = tmpPositions.next()) { |
625 | for (i = 0; i < 7; i++) { | 628 | for (i = 0; i < 7; i++) { |
626 | if (tmpPos->rDays.testBit(i)) { | 629 | if (tmpPos->rDays.testBit(i)) { |
627 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 630 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
628 | day += tmpPos->rPos*8; | 631 | day += tmpPos->rPos*8; |
629 | if (tmpPos->negative) day = -day; | 632 | if (tmpPos->negative) day = -day; |
630 | r.by_day[index2++] = day; | 633 | r.by_day[index2++] = day; |
631 | } | 634 | } |
632 | } | 635 | } |
633 | } | 636 | } |
634 | // r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; | 637 | // r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; |
635 | } | 638 | } |
636 | break; | 639 | break; |
637 | case Recurrence::rYearlyDay: | 640 | case Recurrence::rYearlyDay: |
638 | r.freq = ICAL_YEARLY_RECURRENCE; | 641 | r.freq = ICAL_YEARLY_RECURRENCE; |
639 | 642 | ||
640 | tmpDays = recur->yearNums(); | 643 | tmpDays = recur->yearNums(); |
641 | for (tmpDay = tmpDays.first(); | 644 | for (tmpDay = tmpDays.first(); |
642 | tmpDay; | 645 | tmpDay; |
643 | tmpDay = tmpDays.next()) { | 646 | tmpDay = tmpDays.next()) { |
644 | r.by_year_day[index++] = *tmpDay; | 647 | r.by_year_day[index++] = *tmpDay; |
645 | } | 648 | } |
646 | // r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 649 | // r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
647 | break; | 650 | break; |
648 | default: | 651 | default: |
649 | r.freq = ICAL_NO_RECURRENCE; | 652 | r.freq = ICAL_NO_RECURRENCE; |
650 | kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; | 653 | kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; |
651 | break; | 654 | break; |
652 | } | 655 | } |
653 | 656 | ||
654 | r.interval = recur->frequency(); | 657 | r.interval = recur->frequency(); |
655 | 658 | ||
656 | if (recur->duration() > 0) { | 659 | if (recur->duration() > 0) { |
657 | r.count = recur->duration(); | 660 | r.count = recur->duration(); |
658 | } else if (recur->duration() == -1) { | 661 | } else if (recur->duration() == -1) { |
659 | r.count = 0; | 662 | r.count = 0; |
660 | } else { | 663 | } else { |
661 | if (datetime) | 664 | if (datetime) |
662 | r.until = writeICalDateTime(recur->endDateTime()); | 665 | r.until = writeICalDateTime(recur->endDateTime()); |
663 | else | 666 | else |
664 | r.until = writeICalDate(recur->endDate()); | 667 | r.until = writeICalDate(recur->endDate()); |
665 | } | 668 | } |
666 | 669 | ||
667 | // Debug output | 670 | // Debug output |
668 | #if 0 | 671 | #if 0 |
669 | const char *str = icalrecurrencetype_as_string(&r); | 672 | const char *str = icalrecurrencetype_as_string(&r); |
670 | if (str) { | 673 | if (str) { |
671 | kdDebug(5800) << " String: " << str << endl; | 674 | kdDebug(5800) << " String: " << str << endl; |
672 | } else { | 675 | } else { |
673 | kdDebug(5800) << " No String" << endl; | 676 | kdDebug(5800) << " No String" << endl; |
674 | } | 677 | } |
675 | #endif | 678 | #endif |
676 | 679 | ||
677 | return icalproperty_new_rrule(r); | 680 | return icalproperty_new_rrule(r); |
678 | } | 681 | } |
679 | 682 | ||
680 | icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) | 683 | icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) |
681 | { | 684 | { |
682 | icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); | 685 | icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); |
683 | 686 | ||
684 | icalproperty_action action; | 687 | icalproperty_action action; |
685 | icalattach *attach = 0; | 688 | icalattach *attach = 0; |
686 | 689 | ||
687 | switch (alarm->type()) { | 690 | switch (alarm->type()) { |
688 | case Alarm::Procedure: | 691 | case Alarm::Procedure: |
689 | action = ICAL_ACTION_PROCEDURE; | 692 | action = ICAL_ACTION_PROCEDURE; |
690 | attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); | 693 | attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); |
691 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 694 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
692 | if (!alarm->programArguments().isEmpty()) { | 695 | if (!alarm->programArguments().isEmpty()) { |
693 | icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); | 696 | icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); |
694 | } | 697 | } |
695 | icalattach_unref( attach ); | 698 | icalattach_unref( attach ); |
696 | break; | 699 | break; |
697 | case Alarm::Audio: | 700 | case Alarm::Audio: |
698 | action = ICAL_ACTION_AUDIO; | 701 | action = ICAL_ACTION_AUDIO; |
699 | if (!alarm->audioFile().isEmpty()) { | 702 | if (!alarm->audioFile().isEmpty()) { |
700 | attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); | 703 | attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); |
701 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 704 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
702 | icalattach_unref( attach ); | 705 | icalattach_unref( attach ); |
703 | } | 706 | } |
704 | break; | 707 | break; |
705 | case Alarm::Email: { | 708 | case Alarm::Email: { |
706 | action = ICAL_ACTION_EMAIL; | 709 | action = ICAL_ACTION_EMAIL; |
707 | QValueList<Person> addresses = alarm->mailAddresses(); | 710 | Q3ValueList<Person> addresses = alarm->mailAddresses(); |
708 | for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { | 711 | for (Q3ValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { |
709 | icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); | 712 | icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); |
710 | if (!(*ad).name().isEmpty()) { | 713 | if (!(*ad).name().isEmpty()) { |
711 | icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); | 714 | icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); |
712 | } | 715 | } |
713 | icalcomponent_add_property(a,p); | 716 | icalcomponent_add_property(a,p); |
714 | } | 717 | } |
715 | icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); | 718 | icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); |
716 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); | 719 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); |
717 | QStringList attachments = alarm->mailAttachments(); | 720 | QStringList attachments = alarm->mailAttachments(); |
718 | if (attachments.count() > 0) { | 721 | if (attachments.count() > 0) { |
719 | for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { | 722 | for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { |
720 | attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); | 723 | attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); |
721 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 724 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
722 | icalattach_unref( attach ); | 725 | icalattach_unref( attach ); |
723 | } | 726 | } |
724 | } | 727 | } |
725 | break; | 728 | break; |
726 | } | 729 | } |
727 | case Alarm::Display: | 730 | case Alarm::Display: |
728 | action = ICAL_ACTION_DISPLAY; | 731 | action = ICAL_ACTION_DISPLAY; |
729 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); | 732 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); |
730 | break; | 733 | break; |
731 | case Alarm::Invalid: | 734 | case Alarm::Invalid: |
732 | default: | 735 | default: |
733 | kdDebug(5800) << "Unknown type of alarm" << endl; | 736 | kdDebug(5800) << "Unknown type of alarm" << endl; |
734 | action = ICAL_ACTION_NONE; | 737 | action = ICAL_ACTION_NONE; |
735 | break; | 738 | break; |
736 | } | 739 | } |
737 | icalcomponent_add_property(a,icalproperty_new_action(action)); | 740 | icalcomponent_add_property(a,icalproperty_new_action(action)); |
738 | 741 | ||
739 | // Trigger time | 742 | // Trigger time |
740 | icaltriggertype trigger; | 743 | icaltriggertype trigger; |
741 | if ( alarm->hasTime() ) { | 744 | if ( alarm->hasTime() ) { |
742 | trigger.time = writeICalDateTime(alarm->time()); | 745 | trigger.time = writeICalDateTime(alarm->time()); |
743 | trigger.duration = icaldurationtype_null_duration(); | 746 | trigger.duration = icaldurationtype_null_duration(); |
744 | } else { | 747 | } else { |
745 | trigger.time = icaltime_null_time(); | 748 | trigger.time = icaltime_null_time(); |
746 | Duration offset; | 749 | Duration offset; |
747 | if ( alarm->hasStartOffset() ) | 750 | if ( alarm->hasStartOffset() ) |
748 | offset = alarm->startOffset(); | 751 | offset = alarm->startOffset(); |
749 | else | 752 | else |
750 | offset = alarm->endOffset(); | 753 | offset = alarm->endOffset(); |
751 | trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); | 754 | trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); |
752 | } | 755 | } |
753 | icalproperty *p = icalproperty_new_trigger(trigger); | 756 | icalproperty *p = icalproperty_new_trigger(trigger); |
754 | if ( alarm->hasEndOffset() ) | 757 | if ( alarm->hasEndOffset() ) |
755 | icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); | 758 | icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); |
756 | icalcomponent_add_property(a,p); | 759 | icalcomponent_add_property(a,p); |
757 | 760 | ||
758 | // Repeat count and duration | 761 | // Repeat count and duration |
759 | if (alarm->repeatCount()) { | 762 | if (alarm->repeatCount()) { |
760 | icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); | 763 | icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); |
761 | icalcomponent_add_property(a,icalproperty_new_duration( | 764 | icalcomponent_add_property(a,icalproperty_new_duration( |
762 | icaldurationtype_from_int(alarm->snoozeTime()*60))); | 765 | icaldurationtype_from_int(alarm->snoozeTime()*60))); |
763 | } | 766 | } |
764 | 767 | ||
765 | // Custom properties | 768 | // Custom properties |
766 | QMap<QCString, QString> custom = alarm->customProperties(); | 769 | QMap<Q3CString, QString> custom = alarm->customProperties(); |
767 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { | 770 | for (QMap<Q3CString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { |
768 | icalproperty *p = icalproperty_new_x(c.data().utf8()); | 771 | icalproperty *p = icalproperty_new_x(c.data().utf8()); |
769 | icalproperty_set_x_name(p,c.key()); | 772 | icalproperty_set_x_name(p,c.key()); |
770 | icalcomponent_add_property(a,p); | 773 | icalcomponent_add_property(a,p); |
771 | } | 774 | } |
772 | 775 | ||
773 | return a; | 776 | return a; |
774 | } | 777 | } |
775 | 778 | ||
776 | Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) | 779 | Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) |
777 | { | 780 | { |
778 | Todo *todo = new Todo; | 781 | Todo *todo = new Todo; |
779 | 782 | ||
780 | readIncidence(vtodo,todo); | 783 | readIncidence(vtodo,todo); |
781 | 784 | ||
782 | icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); | 785 | icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); |
783 | 786 | ||
784 | // int intvalue; | 787 | // int intvalue; |
785 | icaltimetype icaltime; | 788 | icaltimetype icaltime; |
786 | 789 | ||
787 | QStringList categories; | 790 | QStringList categories; |
788 | 791 | ||
789 | while (p) { | 792 | while (p) { |
790 | icalproperty_kind kind = icalproperty_isa(p); | 793 | icalproperty_kind kind = icalproperty_isa(p); |
791 | switch (kind) { | 794 | switch (kind) { |
792 | 795 | ||
793 | case ICAL_DUE_PROPERTY: // due date | 796 | case ICAL_DUE_PROPERTY: // due date |
794 | icaltime = icalproperty_get_due(p); | 797 | icaltime = icalproperty_get_due(p); |
795 | if (icaltime.is_date) { | 798 | if (icaltime.is_date) { |
796 | todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); | 799 | todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); |
797 | todo->setFloats(true); | 800 | todo->setFloats(true); |
798 | 801 | ||
799 | } else { | 802 | } else { |
800 | todo->setDtDue(readICalDateTime(icaltime)); | 803 | todo->setDtDue(readICalDateTime(icaltime)); |
801 | todo->setFloats(false); | 804 | todo->setFloats(false); |
802 | } | 805 | } |
803 | todo->setHasDueDate(true); | 806 | todo->setHasDueDate(true); |
804 | break; | 807 | break; |
805 | 808 | ||
806 | case ICAL_COMPLETED_PROPERTY: // completion date | 809 | case ICAL_COMPLETED_PROPERTY: // completion date |
807 | icaltime = icalproperty_get_completed(p); | 810 | icaltime = icalproperty_get_completed(p); |
808 | todo->setCompleted(readICalDateTime(icaltime)); | 811 | todo->setCompleted(readICalDateTime(icaltime)); |
809 | break; | 812 | break; |
810 | 813 | ||
811 | case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed | 814 | case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed |
812 | todo->setPercentComplete(icalproperty_get_percentcomplete(p)); | 815 | todo->setPercentComplete(icalproperty_get_percentcomplete(p)); |
813 | break; | 816 | break; |
814 | 817 | ||
815 | case ICAL_RELATEDTO_PROPERTY: // related todo (parent) | 818 | case ICAL_RELATEDTO_PROPERTY: // related todo (parent) |
816 | todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); | 819 | todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); |
817 | mTodosRelate.append(todo); | 820 | mTodosRelate.append(todo); |
818 | break; | 821 | break; |
819 | 822 | ||
820 | case ICAL_DTSTART_PROPERTY: | 823 | case ICAL_DTSTART_PROPERTY: |
821 | // Flag that todo has start date. Value is read in by readIncidence(). | 824 | // Flag that todo has start date. Value is read in by readIncidence(). |
822 | todo->setHasStartDate(true); | 825 | todo->setHasStartDate(true); |
823 | break; | 826 | break; |
824 | 827 | ||
825 | default: | 828 | default: |
826 | // kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind | 829 | // kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind |
827 | // << endl; | 830 | // << endl; |
828 | break; | 831 | break; |
829 | } | 832 | } |
830 | 833 | ||
831 | p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); | 834 | p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); |
832 | } | 835 | } |
833 | 836 | ||
834 | return todo; | 837 | return todo; |
835 | } | 838 | } |
836 | 839 | ||
837 | Event *ICalFormatImpl::readEvent(icalcomponent *vevent) | 840 | Event *ICalFormatImpl::readEvent(icalcomponent *vevent) |
838 | { | 841 | { |
839 | Event *event = new Event; | 842 | Event *event = new Event; |
840 | event->setFloats(false); | 843 | event->setFloats(false); |
841 | 844 | ||
842 | readIncidence(vevent,event); | 845 | readIncidence(vevent,event); |
843 | 846 | ||
844 | icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); | 847 | icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); |
845 | 848 | ||
846 | // int intvalue; | 849 | // int intvalue; |
847 | icaltimetype icaltime; | 850 | icaltimetype icaltime; |
848 | 851 | ||
849 | QStringList categories; | 852 | QStringList categories; |
850 | QString transparency; | 853 | QString transparency; |
851 | 854 | ||
852 | while (p) { | 855 | while (p) { |
853 | icalproperty_kind kind = icalproperty_isa(p); | 856 | icalproperty_kind kind = icalproperty_isa(p); |
854 | switch (kind) { | 857 | switch (kind) { |
855 | 858 | ||
856 | case ICAL_DTEND_PROPERTY: // start date and time | 859 | case ICAL_DTEND_PROPERTY: // start date and time |
857 | icaltime = icalproperty_get_dtend(p); | 860 | icaltime = icalproperty_get_dtend(p); |
858 | if (icaltime.is_date) { | 861 | if (icaltime.is_date) { |
859 | event->setFloats( true ); | 862 | event->setFloats( true ); |
860 | // End date is non-inclusive | 863 | // End date is non-inclusive |
861 | QDate endDate = readICalDate( icaltime ).addDays( -1 ); | 864 | QDate endDate = readICalDate( icaltime ).addDays( -1 ); |
862 | mCompat->fixFloatingEnd( endDate ); | 865 | mCompat->fixFloatingEnd( endDate ); |
863 | if ( endDate < event->dtStart().date() ) { | 866 | if ( endDate < event->dtStart().date() ) { |
864 | endDate = event->dtStart().date(); | 867 | endDate = event->dtStart().date(); |
865 | } | 868 | } |
866 | event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); | 869 | event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); |
867 | } else { | 870 | } else { |
868 | event->setDtEnd(readICalDateTime(icaltime)); | 871 | event->setDtEnd(readICalDateTime(icaltime)); |
869 | } | 872 | } |
870 | break; | 873 | break; |
871 | 874 | ||
872 | // TODO: | 875 | // TODO: |
873 | // at this point, there should be at least a start or end time. | 876 | // at this point, there should be at least a start or end time. |
874 | // fix up for events that take up no time but have a time associated | 877 | // fix up for events that take up no time but have a time associated |
875 | #if 0 | 878 | #if 0 |
876 | if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) | 879 | if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) |
877 | anEvent->setDtStart(anEvent->dtEnd()); | 880 | anEvent->setDtStart(anEvent->dtEnd()); |
878 | if (!(vo = isAPropertyOf(vevent, VCDTendProp))) | 881 | if (!(vo = isAPropertyOf(vevent, VCDTendProp))) |
879 | anEvent->setDtEnd(anEvent->dtStart()); | 882 | anEvent->setDtEnd(anEvent->dtStart()); |
880 | #endif | 883 | #endif |
881 | 884 | ||
882 | // TODO: exdates | 885 | // TODO: exdates |
883 | #if 0 | 886 | #if 0 |
884 | // recurrence exceptions | 887 | // recurrence exceptions |
885 | if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { | 888 | if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { |
886 | anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); | 889 | anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); |
887 | deleteStr(s); | 890 | deleteStr(s); |
888 | } | 891 | } |
889 | #endif | 892 | #endif |
890 | 893 | ||
891 | #if 0 | 894 | #if 0 |
892 | // secrecy | 895 | // secrecy |
893 | if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { | 896 | if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { |
894 | anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); | 897 | anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); |
895 | deleteStr(s); | 898 | deleteStr(s); |
896 | } | 899 | } |
897 | else | 900 | else |
898 | anEvent->setSecrecy("PUBLIC"); | 901 | anEvent->setSecrecy("PUBLIC"); |
899 | 902 | ||
900 | // attachments | 903 | // attachments |
901 | tmpStrList.clear(); | 904 | tmpStrList.clear(); |
902 | initPropIterator(&voi, vevent); | 905 | initPropIterator(&voi, vevent); |
903 | while (moreIteration(&voi)) { | 906 | while (moreIteration(&voi)) { |
904 | vo = nextVObject(&voi); | 907 | vo = nextVObject(&voi); |
905 | if (strcmp(vObjectName(vo), VCAttachProp) == 0) { | 908 | if (strcmp(vObjectName(vo), VCAttachProp) == 0) { |
906 | tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); | 909 | tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); |
907 | deleteStr(s); | 910 | deleteStr(s); |
908 | } | 911 | } |
909 | } | 912 | } |
910 | anEvent->setAttachments(tmpStrList); | 913 | anEvent->setAttachments(tmpStrList); |
911 | 914 | ||
912 | // resources | 915 | // resources |
913 | if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { | 916 | if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { |
914 | QString resources = (s = fakeCString(vObjectUStringZValue(vo))); | 917 | QString resources = (s = fakeCString(vObjectUStringZValue(vo))); |
915 | deleteStr(s); | 918 | deleteStr(s); |
916 | tmpStrList.clear(); | 919 | tmpStrList.clear(); |
917 | index1 = 0; | 920 | index1 = 0; |
918 | index2 = 0; | 921 | index2 = 0; |
919 | QString resource; | 922 | QString resource; |
920 | while ((index2 = resources.find(';', index1)) != -1) { | 923 | while ((index2 = resources.find(';', index1)) != -1) { |
921 | resource = resources.mid(index1, (index2 - index1)); | 924 | resource = resources.mid(index1, (index2 - index1)); |
922 | tmpStrList.append(resource); | 925 | tmpStrList.append(resource); |
923 | index1 = index2; | 926 | index1 = index2; |
924 | } | 927 | } |
925 | anEvent->setResources(tmpStrList); | 928 | anEvent->setResources(tmpStrList); |
926 | } | 929 | } |
927 | #endif | 930 | #endif |
928 | 931 | ||
929 | case ICAL_RELATEDTO_PROPERTY: // releated event (parent) | 932 | case ICAL_RELATEDTO_PROPERTY: // releated event (parent) |
930 | event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); | 933 | event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); |
931 | mEventsRelate.append(event); | 934 | mEventsRelate.append(event); |
932 | break; | 935 | break; |
933 | 936 | ||
934 | case ICAL_TRANSP_PROPERTY: // Transparency | 937 | case ICAL_TRANSP_PROPERTY: // Transparency |
935 | if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT ) | 938 | if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT ) |
936 | event->setTransparency( Event::Transparent ); | 939 | event->setTransparency( Event::Transparent ); |
937 | else | 940 | else |
938 | event->setTransparency( Event::Opaque ); | 941 | event->setTransparency( Event::Opaque ); |
939 | break; | 942 | break; |
940 | 943 | ||
941 | default: | 944 | default: |
942 | // kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind | 945 | // kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind |
943 | // << endl; | 946 | // << endl; |
944 | break; | 947 | break; |
945 | } | 948 | } |
946 | 949 | ||
947 | p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); | 950 | p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); |
948 | } | 951 | } |
949 | 952 | ||
950 | QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); | 953 | QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); |
951 | if (!msade.isNull()) { | 954 | if (!msade.isNull()) { |
952 | bool floats = (msade == QString::fromLatin1("TRUE")); | 955 | bool floats = (msade == QString::fromLatin1("TRUE")); |
953 | kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; | 956 | kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; |
954 | event->setFloats(floats); | 957 | event->setFloats(floats); |
955 | if (floats) { | 958 | if (floats) { |
956 | QDateTime endDate = event->dtEnd(); | 959 | QDateTime endDate = event->dtEnd(); |
957 | event->setDtEnd(endDate.addDays(-1)); | 960 | event->setDtEnd(endDate.addDays(-1)); |
958 | } | 961 | } |
959 | } | 962 | } |
960 | 963 | ||
961 | // some stupid vCal exporters ignore the standard and use Description | 964 | // some stupid vCal exporters ignore the standard and use Description |
962 | // instead of Summary for the default field. Correct for this. | 965 | // instead of Summary for the default field. Correct for this. |
963 | if (event->summary().isEmpty() && | 966 | if (event->summary().isEmpty() && |
964 | !(event->description().isEmpty())) { | 967 | !(event->description().isEmpty())) { |
965 | QString tmpStr = event->description().simplifyWhiteSpace(); | 968 | QString tmpStr = event->description().simplifyWhiteSpace(); |
966 | event->setDescription(""); | 969 | event->setDescription(""); |
967 | event->setSummary(tmpStr); | 970 | event->setSummary(tmpStr); |
968 | } | 971 | } |
969 | 972 | ||
970 | return event; | 973 | return event; |
971 | } | 974 | } |
972 | 975 | ||
973 | FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) | 976 | FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) |
974 | { | 977 | { |
975 | FreeBusy *freebusy = new FreeBusy; | 978 | FreeBusy *freebusy = new FreeBusy; |
976 | 979 | ||
977 | readIncidenceBase(vfreebusy,freebusy); | 980 | readIncidenceBase(vfreebusy,freebusy); |
978 | 981 | ||
979 | icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); | 982 | icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); |
980 | 983 | ||
981 | icaltimetype icaltime; | 984 | icaltimetype icaltime; |
982 | icalperiodtype icalperiod; | 985 | icalperiodtype icalperiod; |
983 | QDateTime period_start, period_end; | 986 | QDateTime period_start, period_end; |
984 | 987 | ||
985 | while (p) { | 988 | while (p) { |
986 | icalproperty_kind kind = icalproperty_isa(p); | 989 | icalproperty_kind kind = icalproperty_isa(p); |
987 | switch (kind) { | 990 | switch (kind) { |
988 | 991 | ||
989 | case ICAL_DTSTART_PROPERTY: // start date and time | 992 | case ICAL_DTSTART_PROPERTY: // start date and time |
990 | icaltime = icalproperty_get_dtstart(p); | 993 | icaltime = icalproperty_get_dtstart(p); |
991 | freebusy->setDtStart(readICalDateTime(icaltime)); | 994 | freebusy->setDtStart(readICalDateTime(icaltime)); |
992 | break; | 995 | break; |
993 | 996 | ||
994 | case ICAL_DTEND_PROPERTY: // start End Date and Time | 997 | case ICAL_DTEND_PROPERTY: // start End Date and Time |
995 | icaltime = icalproperty_get_dtend(p); | 998 | icaltime = icalproperty_get_dtend(p); |
996 | freebusy->setDtEnd(readICalDateTime(icaltime)); | 999 | freebusy->setDtEnd(readICalDateTime(icaltime)); |
997 | break; | 1000 | break; |
998 | 1001 | ||
999 | case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times | 1002 | case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times |
1000 | icalperiod = icalproperty_get_freebusy(p); | 1003 | icalperiod = icalproperty_get_freebusy(p); |
1001 | period_start = readICalDateTime(icalperiod.start); | 1004 | period_start = readICalDateTime(icalperiod.start); |
1002 | period_end = readICalDateTime(icalperiod.end); | 1005 | period_end = readICalDateTime(icalperiod.end); |
1003 | freebusy->addPeriod(period_start, period_end); | 1006 | freebusy->addPeriod(period_start, period_end); |
1004 | break; | 1007 | break; |
1005 | 1008 | ||
1006 | default: | 1009 | default: |
1007 | kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind | 1010 | kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind |
1008 | << endl; | 1011 | << endl; |
1009 | break; | 1012 | break; |
1010 | } | 1013 | } |
1011 | p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); | 1014 | p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); |
1012 | } | 1015 | } |
1013 | 1016 | ||
1014 | return freebusy; | 1017 | return freebusy; |
1015 | } | 1018 | } |
1016 | 1019 | ||
1017 | Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) | 1020 | Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) |
1018 | { | 1021 | { |
1019 | Journal *journal = new Journal; | 1022 | Journal *journal = new Journal; |
1020 | 1023 | ||
1021 | readIncidence(vjournal,journal); | 1024 | readIncidence(vjournal,journal); |
1022 | 1025 | ||
1023 | if ( !journal->dtStart().isValid() && journal->created().isValid() ) { | 1026 | if ( !journal->dtStart().isValid() && journal->created().isValid() ) { |
1024 | journal->setDtStart( journal->created() ); | 1027 | journal->setDtStart( journal->created() ); |
1025 | } | 1028 | } |
1026 | return journal; | 1029 | return journal; |
1027 | } | 1030 | } |
1028 | 1031 | ||
1029 | Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) | 1032 | Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) |
1030 | { | 1033 | { |
1031 | icalparameter *p = 0; | 1034 | icalparameter *p = 0; |
1032 | 1035 | ||
1033 | QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); | 1036 | QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); |
1034 | 1037 | ||
1035 | QString name; | 1038 | QString name; |
1036 | QString uid = QString::null; | 1039 | QString uid = QString::null; |
1037 | p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); | 1040 | p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); |
1038 | if (p) { | 1041 | if (p) { |
1039 | name = QString::fromUtf8(icalparameter_get_cn(p)); | 1042 | name = QString::fromUtf8(icalparameter_get_cn(p)); |
1040 | } else { | 1043 | } else { |
1041 | } | 1044 | } |
1042 | 1045 | ||
1043 | bool rsvp=false; | 1046 | bool rsvp=false; |
1044 | p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); | 1047 | p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); |
1045 | if (p) { | 1048 | if (p) { |
1046 | icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); | 1049 | icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); |
1047 | if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; | 1050 | if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; |
1048 | } | 1051 | } |
1049 | 1052 | ||
1050 | Attendee::PartStat status = Attendee::NeedsAction; | 1053 | Attendee::PartStat status = Attendee::NeedsAction; |
1051 | p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); | 1054 | p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); |
1052 | if (p) { | 1055 | if (p) { |
1053 | icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); | 1056 | icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); |
1054 | switch(partStatParameter) { | 1057 | switch(partStatParameter) { |
1055 | default: | 1058 | default: |
1056 | case ICAL_PARTSTAT_NEEDSACTION: | 1059 | case ICAL_PARTSTAT_NEEDSACTION: |
1057 | status = Attendee::NeedsAction; | 1060 | status = Attendee::NeedsAction; |
1058 | break; | 1061 | break; |
1059 | case ICAL_PARTSTAT_ACCEPTED: | 1062 | case ICAL_PARTSTAT_ACCEPTED: |
1060 | status = Attendee::Accepted; | 1063 | status = Attendee::Accepted; |
1061 | break; | 1064 | break; |
1062 | case ICAL_PARTSTAT_DECLINED: | 1065 | case ICAL_PARTSTAT_DECLINED: |
1063 | status = Attendee::Declined; | 1066 | status = Attendee::Declined; |
1064 | break; | 1067 | break; |
1065 | case ICAL_PARTSTAT_TENTATIVE: | 1068 | case ICAL_PARTSTAT_TENTATIVE: |
1066 | status = Attendee::Tentative; | 1069 | status = Attendee::Tentative; |
1067 | break; | 1070 | break; |
1068 | case ICAL_PARTSTAT_DELEGATED: | 1071 | case ICAL_PARTSTAT_DELEGATED: |
1069 | status = Attendee::Delegated; | 1072 | status = Attendee::Delegated; |
1070 | break; | 1073 | break; |
1071 | case ICAL_PARTSTAT_COMPLETED: | 1074 | case ICAL_PARTSTAT_COMPLETED: |
1072 | status = Attendee::Completed; | 1075 | status = Attendee::Completed; |
1073 | break; | 1076 | break; |
1074 | case ICAL_PARTSTAT_INPROCESS: | 1077 | case ICAL_PARTSTAT_INPROCESS: |
1075 | status = Attendee::InProcess; | 1078 | status = Attendee::InProcess; |
1076 | break; | 1079 | break; |
1077 | } | 1080 | } |
1078 | } | 1081 | } |
1079 | 1082 | ||
1080 | Attendee::Role role = Attendee::ReqParticipant; | 1083 | Attendee::Role role = Attendee::ReqParticipant; |
1081 | p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); | 1084 | p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); |
1082 | if (p) { | 1085 | if (p) { |
1083 | icalparameter_role roleParameter = icalparameter_get_role(p); | 1086 | icalparameter_role roleParameter = icalparameter_get_role(p); |
1084 | switch(roleParameter) { | 1087 | switch(roleParameter) { |
1085 | case ICAL_ROLE_CHAIR: | 1088 | case ICAL_ROLE_CHAIR: |
1086 | role = Attendee::Chair; | 1089 | role = Attendee::Chair; |
1087 | break; | 1090 | break; |
1088 | default: | 1091 | default: |
1089 | case ICAL_ROLE_REQPARTICIPANT: | 1092 | case ICAL_ROLE_REQPARTICIPANT: |
1090 | role = Attendee::ReqParticipant; | 1093 | role = Attendee::ReqParticipant; |
1091 | break; | 1094 | break; |
1092 | case ICAL_ROLE_OPTPARTICIPANT: | 1095 | case ICAL_ROLE_OPTPARTICIPANT: |
1093 | role = Attendee::OptParticipant; | 1096 | role = Attendee::OptParticipant; |
1094 | break; | 1097 | break; |
1095 | case ICAL_ROLE_NONPARTICIPANT: | 1098 | case ICAL_ROLE_NONPARTICIPANT: |
1096 | role = Attendee::NonParticipant; | 1099 | role = Attendee::NonParticipant; |
1097 | break; | 1100 | break; |
1098 | } | 1101 | } |
1099 | } | 1102 | } |
1100 | 1103 | ||
1101 | p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); | 1104 | p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); |
1102 | uid = icalparameter_get_xvalue(p); | 1105 | uid = icalparameter_get_xvalue(p); |
1103 | // This should be added, but there seems to be a libical bug here. | 1106 | // This should be added, but there seems to be a libical bug here. |
1104 | /*while (p) { | 1107 | /*while (p) { |
1105 | // if (icalparameter_get_xname(p) == "X-UID") { | 1108 | // if (icalparameter_get_xname(p) == "X-UID") { |
1106 | uid = icalparameter_get_xvalue(p); | 1109 | uid = icalparameter_get_xvalue(p); |
1107 | p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); | 1110 | p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); |
1108 | } */ | 1111 | } */ |
1109 | 1112 | ||
1110 | return new Attendee( name, email, rsvp, status, role, uid ); | 1113 | return new Attendee( name, email, rsvp, status, role, uid ); |
1111 | } | 1114 | } |
1112 | 1115 | ||
1113 | Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) | 1116 | Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) |
1114 | { | 1117 | { |
1115 | icalattach *a = icalproperty_get_attach(attach); | 1118 | icalattach *a = icalproperty_get_attach(attach); |
1116 | icalparameter_value v = ICAL_VALUE_NONE; | 1119 | icalparameter_value v = ICAL_VALUE_NONE; |
1117 | icalparameter_encoding e = ICAL_ENCODING_NONE; | 1120 | icalparameter_encoding e = ICAL_ENCODING_NONE; |
1118 | 1121 | ||
1119 | Attachment *attachment = 0; | 1122 | Attachment *attachment = 0; |
1120 | /* | 1123 | /* |
1121 | icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); | 1124 | icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); |
1122 | if (vp) | 1125 | if (vp) |
1123 | v = icalparameter_get_value(vp); | 1126 | v = icalparameter_get_value(vp); |
1124 | 1127 | ||
1125 | icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); | 1128 | icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); |
1126 | if (ep) | 1129 | if (ep) |
1127 | e = icalparameter_get_encoding(ep); | 1130 | e = icalparameter_get_encoding(ep); |
1128 | */ | 1131 | */ |
1129 | int isurl = icalattach_get_is_url (a); | 1132 | int isurl = icalattach_get_is_url (a); |
1130 | if (isurl == 0) | 1133 | if (isurl == 0) |
1131 | attachment = new Attachment((const char*)icalattach_get_data(a)); | 1134 | attachment = new Attachment((const char*)icalattach_get_data(a)); |
1132 | else { | 1135 | else { |
1133 | attachment = new Attachment(QString(icalattach_get_url(a))); | 1136 | attachment = new Attachment(QString(icalattach_get_url(a))); |
1134 | } | 1137 | } |
1135 | 1138 | ||
1136 | icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); | 1139 | icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); |
1137 | if (p) | 1140 | if (p) |
1138 | attachment->setMimeType(QString(icalparameter_get_fmttype(p))); | 1141 | attachment->setMimeType(QString(icalparameter_get_fmttype(p))); |
1139 | 1142 | ||
1140 | return attachment; | 1143 | return attachment; |
1141 | } | 1144 | } |
1142 | #include <qtextcodec.h> | 1145 | #include <qtextcodec.h> |
1143 | void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) | 1146 | void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) |
1144 | { | 1147 | { |
1145 | readIncidenceBase(parent,incidence); | 1148 | readIncidenceBase(parent,incidence); |
1146 | 1149 | ||
1147 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); | 1150 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); |
1148 | bool readrec = false; | 1151 | bool readrec = false; |
1149 | const char *text; | 1152 | const char *text; |
1150 | int intvalue; | 1153 | int intvalue; |
1151 | icaltimetype icaltime; | 1154 | icaltimetype icaltime; |
1152 | icaldurationtype icalduration; | 1155 | icaldurationtype icalduration; |
1153 | struct icalrecurrencetype rectype; | 1156 | struct icalrecurrencetype rectype; |
1154 | QStringList categories; | 1157 | QStringList categories; |
1155 | 1158 | ||
1156 | while (p) { | 1159 | while (p) { |
1157 | icalproperty_kind kind = icalproperty_isa(p); | 1160 | icalproperty_kind kind = icalproperty_isa(p); |
1158 | switch (kind) { | 1161 | switch (kind) { |
1159 | 1162 | ||
1160 | case ICAL_CREATED_PROPERTY: | 1163 | case ICAL_CREATED_PROPERTY: |
1161 | icaltime = icalproperty_get_created(p); | 1164 | icaltime = icalproperty_get_created(p); |
1162 | incidence->setCreated(readICalDateTime(icaltime)); | 1165 | incidence->setCreated(readICalDateTime(icaltime)); |
1163 | break; | 1166 | break; |
1164 | 1167 | ||
1165 | case ICAL_SEQUENCE_PROPERTY: // sequence | 1168 | case ICAL_SEQUENCE_PROPERTY: // sequence |
1166 | intvalue = icalproperty_get_sequence(p); | 1169 | intvalue = icalproperty_get_sequence(p); |
1167 | incidence->setRevision(intvalue); | 1170 | incidence->setRevision(intvalue); |
1168 | break; | 1171 | break; |
1169 | 1172 | ||
1170 | case ICAL_LASTMODIFIED_PROPERTY: // last modification date | 1173 | case ICAL_LASTMODIFIED_PROPERTY: // last modification date |
1171 | icaltime = icalproperty_get_lastmodified(p); | 1174 | icaltime = icalproperty_get_lastmodified(p); |
1172 | incidence->setLastModified(readICalDateTime(icaltime)); | 1175 | incidence->setLastModified(readICalDateTime(icaltime)); |
1173 | break; | 1176 | break; |
1174 | 1177 | ||
1175 | case ICAL_DTSTART_PROPERTY: // start date and time | 1178 | case ICAL_DTSTART_PROPERTY: // start date and time |
1176 | icaltime = icalproperty_get_dtstart(p); | 1179 | icaltime = icalproperty_get_dtstart(p); |
1177 | if (icaltime.is_date) { | 1180 | if (icaltime.is_date) { |
1178 | incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); | 1181 | incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); |
1179 | incidence->setFloats(true); | 1182 | incidence->setFloats(true); |
1180 | } else { | 1183 | } else { |
1181 | incidence->setDtStart(readICalDateTime(icaltime)); | 1184 | incidence->setDtStart(readICalDateTime(icaltime)); |
1182 | } | 1185 | } |
1183 | break; | 1186 | break; |
1184 | 1187 | ||
1185 | case ICAL_DURATION_PROPERTY: // start date and time | 1188 | case ICAL_DURATION_PROPERTY: // start date and time |
1186 | icalduration = icalproperty_get_duration(p); | 1189 | icalduration = icalproperty_get_duration(p); |
1187 | incidence->setDuration(readICalDuration(icalduration)); | 1190 | incidence->setDuration(readICalDuration(icalduration)); |
1188 | break; | 1191 | break; |
1189 | 1192 | ||
1190 | case ICAL_DESCRIPTION_PROPERTY: // description | 1193 | case ICAL_DESCRIPTION_PROPERTY: // description |
1191 | text = icalproperty_get_description(p); | 1194 | text = icalproperty_get_description(p); |
1192 | incidence->setDescription(QString::fromUtf8(text)); | 1195 | incidence->setDescription(QString::fromUtf8(text)); |
1193 | break; | 1196 | break; |
1194 | 1197 | ||
1195 | case ICAL_SUMMARY_PROPERTY: // summary | 1198 | case ICAL_SUMMARY_PROPERTY: // summary |
1196 | { | 1199 | { |
1197 | text = icalproperty_get_summary(p); | 1200 | text = icalproperty_get_summary(p); |
1198 | incidence->setSummary(QString::fromUtf8(text)); | 1201 | incidence->setSummary(QString::fromUtf8(text)); |
1199 | } | 1202 | } |
1200 | break; | 1203 | break; |
1201 | case ICAL_STATUS_PROPERTY: // summary | 1204 | case ICAL_STATUS_PROPERTY: // summary |
1202 | { | 1205 | { |
1203 | if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) | 1206 | if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) |
1204 | incidence->setCancelled( true ); | 1207 | incidence->setCancelled( true ); |
1205 | } | 1208 | } |
1206 | break; | 1209 | break; |
1207 | 1210 | ||
1208 | case ICAL_LOCATION_PROPERTY: // location | 1211 | case ICAL_LOCATION_PROPERTY: // location |
1209 | text = icalproperty_get_location(p); | 1212 | text = icalproperty_get_location(p); |
1210 | incidence->setLocation(QString::fromUtf8(text)); | 1213 | incidence->setLocation(QString::fromUtf8(text)); |
1211 | break; | 1214 | break; |
1212 | 1215 | ||
1213 | case ICAL_RECURRENCEID_PROPERTY: | 1216 | case ICAL_RECURRENCEID_PROPERTY: |
1214 | icaltime = icalproperty_get_recurrenceid(p); | 1217 | icaltime = icalproperty_get_recurrenceid(p); |
1215 | incidence->setRecurrenceID( readICalDateTime(icaltime) ); | 1218 | incidence->setRecurrenceID( readICalDateTime(icaltime) ); |
1216 | //qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() ); | 1219 | //qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() ); |
1217 | break; | 1220 | break; |
1218 | #if 0 | 1221 | #if 0 |
1219 | // status | 1222 | // status |
1220 | if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { | 1223 | if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { |
1221 | incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); | 1224 | incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); |
1222 | deleteStr(s); | 1225 | deleteStr(s); |
1223 | } | 1226 | } |
1224 | else | 1227 | else |
1225 | incidence->setStatus("NEEDS ACTION"); | 1228 | incidence->setStatus("NEEDS ACTION"); |
1226 | #endif | 1229 | #endif |
1227 | 1230 | ||
1228 | case ICAL_PRIORITY_PROPERTY: // priority | 1231 | case ICAL_PRIORITY_PROPERTY: // priority |
1229 | intvalue = icalproperty_get_priority(p); | 1232 | intvalue = icalproperty_get_priority(p); |
1230 | incidence->setPriority(intvalue); | 1233 | incidence->setPriority(intvalue); |
1231 | break; | 1234 | break; |
1232 | 1235 | ||
1233 | case ICAL_CATEGORIES_PROPERTY: // categories | 1236 | case ICAL_CATEGORIES_PROPERTY: // categories |
1234 | text = icalproperty_get_categories(p); | 1237 | text = icalproperty_get_categories(p); |
1235 | categories.append(QString::fromUtf8(text)); | 1238 | categories.append(QString::fromUtf8(text)); |
1236 | break; | 1239 | break; |
1237 | //******************************************* | 1240 | //******************************************* |
1238 | case ICAL_RRULE_PROPERTY: | 1241 | case ICAL_RRULE_PROPERTY: |
1239 | // we do need (maybe )start datetime of incidence for recurrence | 1242 | // we do need (maybe )start datetime of incidence for recurrence |
1240 | // such that we can read recurrence only after we read incidence completely | 1243 | // such that we can read recurrence only after we read incidence completely |
1241 | readrec = true; | 1244 | readrec = true; |
1242 | rectype = icalproperty_get_rrule(p); | 1245 | rectype = icalproperty_get_rrule(p); |
1243 | break; | 1246 | break; |
1244 | 1247 | ||
1245 | case ICAL_EXDATE_PROPERTY: | 1248 | case ICAL_EXDATE_PROPERTY: |
1246 | icaltime = icalproperty_get_exdate(p); | 1249 | icaltime = icalproperty_get_exdate(p); |
1247 | incidence->addExDate(readICalDate(icaltime)); | 1250 | incidence->addExDate(readICalDate(icaltime)); |
1248 | break; | 1251 | break; |
1249 | 1252 | ||
1250 | case ICAL_CLASS_PROPERTY: { | 1253 | case ICAL_CLASS_PROPERTY: { |
1251 | int inttext = icalproperty_get_class(p); | 1254 | int inttext = icalproperty_get_class(p); |
1252 | if (inttext == ICAL_CLASS_PUBLIC ) { | 1255 | if (inttext == ICAL_CLASS_PUBLIC ) { |
1253 | incidence->setSecrecy(Incidence::SecrecyPublic); | 1256 | incidence->setSecrecy(Incidence::SecrecyPublic); |
1254 | } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { | 1257 | } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { |
1255 | incidence->setSecrecy(Incidence::SecrecyConfidential); | 1258 | incidence->setSecrecy(Incidence::SecrecyConfidential); |
1256 | } else { | 1259 | } else { |
1257 | incidence->setSecrecy(Incidence::SecrecyPrivate); | 1260 | incidence->setSecrecy(Incidence::SecrecyPrivate); |
1258 | } | 1261 | } |
1259 | } | 1262 | } |
1260 | break; | 1263 | break; |
1261 | 1264 | ||
1262 | case ICAL_ATTACH_PROPERTY: // attachments | 1265 | case ICAL_ATTACH_PROPERTY: // attachments |
1263 | incidence->addAttachment(readAttachment(p)); | 1266 | incidence->addAttachment(readAttachment(p)); |
1264 | break; | 1267 | break; |
1265 | 1268 | ||
1266 | default: | 1269 | default: |
1267 | // kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind | 1270 | // kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind |
1268 | // << endl; | 1271 | // << endl; |
1269 | break; | 1272 | break; |
1270 | } | 1273 | } |
1271 | 1274 | ||
1272 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); | 1275 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); |
1273 | } | 1276 | } |
1274 | if ( readrec ) { | 1277 | if ( readrec ) { |
1275 | readRecurrenceRule(rectype,incidence); | 1278 | readRecurrenceRule(rectype,incidence); |
1276 | } | 1279 | } |
1277 | // kpilot stuff | 1280 | // kpilot stuff |
1278 | // TODO: move this application-specific code to kpilot | 1281 | // TODO: move this application-specific code to kpilot |
1279 | QString kp = incidence->nonKDECustomProperty("X-PILOTID"); | 1282 | QString kp = incidence->nonKDECustomProperty("X-PILOTID"); |
1280 | if (!kp.isNull()) { | 1283 | if (!kp.isNull()) { |
1281 | incidence->setPilotId(kp.toInt()); | 1284 | incidence->setPilotId(kp.toInt()); |
1282 | } | 1285 | } |
1283 | kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); | 1286 | kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); |
1284 | if (!kp.isNull()) { | 1287 | if (!kp.isNull()) { |
1285 | incidence->setSyncStatus(kp.toInt()); | 1288 | incidence->setSyncStatus(kp.toInt()); |
1286 | } | 1289 | } |
1287 | 1290 | ||
1288 | 1291 | ||
1289 | kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); | 1292 | kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); |
1290 | if (!kp.isNull()) { | 1293 | if (!kp.isNull()) { |
1291 | incidence->setIDStr(kp); | 1294 | incidence->setIDStr(kp); |
1292 | } | 1295 | } |
1293 | 1296 | ||
1294 | // Cancel backwards compatibility mode for subsequent changes by the application | 1297 | // Cancel backwards compatibility mode for subsequent changes by the application |
1295 | if ( readrec ) | 1298 | if ( readrec ) |
1296 | incidence->recurrence()->setCompatVersion(); | 1299 | incidence->recurrence()->setCompatVersion(); |
1297 | 1300 | ||
1298 | // add categories | 1301 | // add categories |
1299 | incidence->setCategories(categories); | 1302 | incidence->setCategories(categories); |
1300 | 1303 | ||
1301 | // iterate through all alarms | 1304 | // iterate through all alarms |
1302 | for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); | 1305 | for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); |
1303 | alarm; | 1306 | alarm; |
1304 | alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { | 1307 | alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { |
1305 | readAlarm(alarm,incidence); | 1308 | readAlarm(alarm,incidence); |
1306 | } | 1309 | } |
1307 | } | 1310 | } |
1308 | 1311 | ||
1309 | void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) | 1312 | void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) |
1310 | { | 1313 | { |
1311 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); | 1314 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); |
1312 | 1315 | ||
1313 | while (p) { | 1316 | while (p) { |
1314 | icalproperty_kind kind = icalproperty_isa(p); | 1317 | icalproperty_kind kind = icalproperty_isa(p); |
1315 | switch (kind) { | 1318 | switch (kind) { |
1316 | 1319 | ||
1317 | case ICAL_UID_PROPERTY: // unique id | 1320 | case ICAL_UID_PROPERTY: // unique id |
1318 | incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); | 1321 | incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); |
1319 | break; | 1322 | break; |
1320 | 1323 | ||
1321 | case ICAL_ORGANIZER_PROPERTY: // organizer | 1324 | case ICAL_ORGANIZER_PROPERTY: // organizer |
1322 | incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); | 1325 | incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); |
1323 | break; | 1326 | break; |
1324 | 1327 | ||
1325 | case ICAL_ATTENDEE_PROPERTY: // attendee | 1328 | case ICAL_ATTENDEE_PROPERTY: // attendee |
1326 | incidenceBase->addAttendee(readAttendee(p)); | 1329 | incidenceBase->addAttendee(readAttendee(p)); |
1327 | break; | 1330 | break; |
1328 | 1331 | ||
1329 | default: | 1332 | default: |
1330 | break; | 1333 | break; |
1331 | } | 1334 | } |
1332 | 1335 | ||
1333 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); | 1336 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); |
1334 | } | 1337 | } |
1335 | 1338 | ||
1336 | // custom properties | 1339 | // custom properties |
1337 | readCustomProperties(parent, incidenceBase); | 1340 | readCustomProperties(parent, incidenceBase); |
1338 | } | 1341 | } |
1339 | 1342 | ||
1340 | void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) | 1343 | void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) |
1341 | { | 1344 | { |
1342 | QMap<QCString, QString> customProperties; | 1345 | QMap<Q3CString, QString> customProperties; |
1343 | 1346 | ||
1344 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); | 1347 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); |
1345 | 1348 | ||
1346 | while (p) { | 1349 | while (p) { |
1347 | QString value = QString::fromUtf8(icalproperty_get_x(p)); | 1350 | QString value = QString::fromUtf8(icalproperty_get_x(p)); |
1348 | customProperties[icalproperty_get_x_name(p)] = value; | 1351 | customProperties[icalproperty_get_x_name(p)] = value; |
1349 | //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); | 1352 | //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); |
1350 | 1353 | ||
1351 | p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); | 1354 | p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); |
1352 | } | 1355 | } |
1353 | 1356 | ||
1354 | properties->setCustomProperties(customProperties); | 1357 | properties->setCustomProperties(customProperties); |
1355 | } | 1358 | } |
1356 | 1359 | ||
1357 | void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) | 1360 | void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) |
1358 | { | 1361 | { |
1359 | // kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; | 1362 | // kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; |
1360 | 1363 | ||
1361 | Recurrence *recur = incidence->recurrence(); | 1364 | Recurrence *recur = incidence->recurrence(); |
1362 | recur->setCompatVersion(mCalendarVersion); | 1365 | recur->setCompatVersion(mCalendarVersion); |
1363 | recur->unsetRecurs(); | 1366 | recur->unsetRecurs(); |
1364 | 1367 | ||
1365 | struct icalrecurrencetype r = rrule; | 1368 | struct icalrecurrencetype r = rrule; |
1366 | 1369 | ||
1367 | dumpIcalRecurrence(r); | 1370 | dumpIcalRecurrence(r); |
1368 | readRecurrence( r, recur, incidence); | 1371 | readRecurrence( r, recur, incidence); |
1369 | } | 1372 | } |
1370 | 1373 | ||
1371 | void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) | 1374 | void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) |
1372 | { | 1375 | { |
1373 | int wkst; | 1376 | int wkst; |
1374 | int index = 0; | 1377 | int index = 0; |
1375 | short day = 0; | 1378 | short day = 0; |
1376 | QBitArray qba(7); | 1379 | QBitArray qba(7); |
1377 | int frequ = r.freq; | 1380 | int frequ = r.freq; |
1378 | int interv = r.interval; | 1381 | int interv = r.interval; |
1379 | // preprocessing for odd recurrence definitions | 1382 | // preprocessing for odd recurrence definitions |
1380 | 1383 | ||
1381 | if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { | 1384 | if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { |
1382 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1385 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1383 | interv = 12; | 1386 | interv = 12; |
1384 | } | 1387 | } |
1385 | } | 1388 | } |
1386 | if ( r.freq == ICAL_YEARLY_RECURRENCE ) { | 1389 | if ( r.freq == ICAL_YEARLY_RECURRENCE ) { |
1387 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { | 1390 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { |
1388 | frequ = ICAL_MONTHLY_RECURRENCE; | 1391 | frequ = ICAL_MONTHLY_RECURRENCE; |
1389 | interv = 12* r.interval; | 1392 | interv = 12* r.interval; |
1390 | } | 1393 | } |
1391 | } | 1394 | } |
1392 | 1395 | ||
1393 | switch (frequ) { | 1396 | switch (frequ) { |
1394 | case ICAL_MINUTELY_RECURRENCE: | 1397 | case ICAL_MINUTELY_RECURRENCE: |
1395 | if (!icaltime_is_null_time(r.until)) { | 1398 | if (!icaltime_is_null_time(r.until)) { |
1396 | recur->setMinutely(interv,readICalDateTime(r.until)); | 1399 | recur->setMinutely(interv,readICalDateTime(r.until)); |
1397 | } else { | 1400 | } else { |
1398 | if (r.count == 0) | 1401 | if (r.count == 0) |
1399 | recur->setMinutely(interv,-1); | 1402 | recur->setMinutely(interv,-1); |
1400 | else | 1403 | else |
1401 | recur->setMinutely(interv,r.count); | 1404 | recur->setMinutely(interv,r.count); |
1402 | } | 1405 | } |
1403 | break; | 1406 | break; |
1404 | case ICAL_HOURLY_RECURRENCE: | 1407 | case ICAL_HOURLY_RECURRENCE: |
1405 | if (!icaltime_is_null_time(r.until)) { | 1408 | if (!icaltime_is_null_time(r.until)) { |
1406 | recur->setHourly(interv,readICalDateTime(r.until)); | 1409 | recur->setHourly(interv,readICalDateTime(r.until)); |
1407 | } else { | 1410 | } else { |
1408 | if (r.count == 0) | 1411 | if (r.count == 0) |
1409 | recur->setHourly(interv,-1); | 1412 | recur->setHourly(interv,-1); |
1410 | else | 1413 | else |
1411 | recur->setHourly(interv,r.count); | 1414 | recur->setHourly(interv,r.count); |
1412 | } | 1415 | } |
1413 | break; | 1416 | break; |
1414 | case ICAL_DAILY_RECURRENCE: | 1417 | case ICAL_DAILY_RECURRENCE: |
1415 | if (!icaltime_is_null_time(r.until)) { | 1418 | if (!icaltime_is_null_time(r.until)) { |
1416 | recur->setDaily(interv,readICalDate(r.until)); | 1419 | recur->setDaily(interv,readICalDate(r.until)); |
1417 | } else { | 1420 | } else { |
1418 | if (r.count == 0) | 1421 | if (r.count == 0) |
1419 | recur->setDaily(interv,-1); | 1422 | recur->setDaily(interv,-1); |
1420 | else | 1423 | else |
1421 | recur->setDaily(interv,r.count); | 1424 | recur->setDaily(interv,r.count); |
1422 | } | 1425 | } |
1423 | break; | 1426 | break; |
1424 | case ICAL_WEEKLY_RECURRENCE: | 1427 | case ICAL_WEEKLY_RECURRENCE: |
1425 | // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; | 1428 | // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; |
1426 | wkst = (r.week_start + 5)%7 + 1; | 1429 | wkst = (r.week_start + 5)%7 + 1; |
1427 | if (!icaltime_is_null_time(r.until)) { | 1430 | if (!icaltime_is_null_time(r.until)) { |
1428 | recur->setWeekly(interv,qba,readICalDate(r.until),wkst); | 1431 | recur->setWeekly(interv,qba,readICalDate(r.until),wkst); |
1429 | } else { | 1432 | } else { |
1430 | if (r.count == 0) | 1433 | if (r.count == 0) |
1431 | recur->setWeekly(interv,qba,-1,wkst); | 1434 | recur->setWeekly(interv,qba,-1,wkst); |
1432 | else | 1435 | else |
1433 | recur->setWeekly(interv,qba,r.count,wkst); | 1436 | recur->setWeekly(interv,qba,r.count,wkst); |
1434 | } | 1437 | } |
1435 | if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { | 1438 | if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { |
1436 | int wday = incidence->dtStart().date().dayOfWeek ()-1; | 1439 | int wday = incidence->dtStart().date().dayOfWeek ()-1; |
1437 | //qDebug("weekly error found "); | 1440 | //qDebug("weekly error found "); |
1438 | qba.setBit(wday); | 1441 | qba.setBit(wday); |
1439 | } else { | 1442 | } else { |
1440 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1443 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1441 | // kdDebug(5800) << " " << day << endl; | 1444 | // kdDebug(5800) << " " << day << endl; |
1442 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1445 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1443 | } | 1446 | } |
1444 | } | 1447 | } |
1445 | break; | 1448 | break; |
1446 | case ICAL_MONTHLY_RECURRENCE: | 1449 | case ICAL_MONTHLY_RECURRENCE: |
1447 | 1450 | ||
1448 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1451 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1449 | if (!icaltime_is_null_time(r.until)) { | 1452 | if (!icaltime_is_null_time(r.until)) { |
1450 | recur->setMonthly(Recurrence::rMonthlyPos,interv, | 1453 | recur->setMonthly(Recurrence::rMonthlyPos,interv, |
1451 | readICalDate(r.until)); | 1454 | readICalDate(r.until)); |
1452 | } else { | 1455 | } else { |
1453 | if (r.count == 0) | 1456 | if (r.count == 0) |
1454 | recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); | 1457 | recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); |
1455 | else | 1458 | else |
1456 | recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); | 1459 | recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); |
1457 | } | 1460 | } |
1458 | bool useSetPos = false; | 1461 | bool useSetPos = false; |
1459 | short pos = 0; | 1462 | short pos = 0; |
1460 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1463 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1461 | // kdDebug(5800) << "----a " << index << ": " << day << endl; | 1464 | // kdDebug(5800) << "----a " << index << ": " << day << endl; |
1462 | pos = icalrecurrencetype_day_position(day); | 1465 | pos = icalrecurrencetype_day_position(day); |
1463 | if (pos) { | 1466 | if (pos) { |
1464 | day = icalrecurrencetype_day_day_of_week(day); | 1467 | day = icalrecurrencetype_day_day_of_week(day); |
1465 | QBitArray ba(7); // don't wipe qba | 1468 | QBitArray ba(7); // don't wipe qba |
1466 | ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1469 | ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1467 | recur->addMonthlyPos(pos,ba); | 1470 | recur->addMonthlyPos(pos,ba); |
1468 | } else { | 1471 | } else { |
1469 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1472 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1470 | useSetPos = true; | 1473 | useSetPos = true; |
1471 | } | 1474 | } |
1472 | } | 1475 | } |
1473 | if (useSetPos) { | 1476 | if (useSetPos) { |
1474 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1477 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1475 | recur->addMonthlyPos(r.by_set_pos[0],qba); | 1478 | recur->addMonthlyPos(r.by_set_pos[0],qba); |
1476 | } | 1479 | } |
1477 | } | 1480 | } |
1478 | } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1481 | } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1479 | if (!icaltime_is_null_time(r.until)) { | 1482 | if (!icaltime_is_null_time(r.until)) { |
1480 | recur->setMonthly(Recurrence::rMonthlyDay,interv, | 1483 | recur->setMonthly(Recurrence::rMonthlyDay,interv, |
1481 | readICalDate(r.until)); | 1484 | readICalDate(r.until)); |
1482 | } else { | 1485 | } else { |
1483 | if (r.count == 0) | 1486 | if (r.count == 0) |
1484 | recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); | 1487 | recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); |
1485 | else | 1488 | else |
1486 | recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); | 1489 | recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); |
1487 | } | 1490 | } |
1488 | while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1491 | while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1489 | // kdDebug(5800) << "----b " << day << endl; | 1492 | // kdDebug(5800) << "----b " << day << endl; |
1490 | recur->addMonthlyDay(day); | 1493 | recur->addMonthlyDay(day); |
1491 | } | 1494 | } |
1492 | } | 1495 | } |
1493 | break; | 1496 | break; |
1494 | case ICAL_YEARLY_RECURRENCE: | 1497 | case ICAL_YEARLY_RECURRENCE: |
1495 | if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1498 | if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1496 | //qDebug(" YEARLY DAY OF YEAR"); | 1499 | //qDebug(" YEARLY DAY OF YEAR"); |
1497 | if (!icaltime_is_null_time(r.until)) { | 1500 | if (!icaltime_is_null_time(r.until)) { |
1498 | recur->setYearly(Recurrence::rYearlyDay,interv, | 1501 | recur->setYearly(Recurrence::rYearlyDay,interv, |
1499 | readICalDate(r.until)); | 1502 | readICalDate(r.until)); |
1500 | } else { | 1503 | } else { |
1501 | if (r.count == 0) | 1504 | if (r.count == 0) |
1502 | recur->setYearly(Recurrence::rYearlyDay,interv,-1); | 1505 | recur->setYearly(Recurrence::rYearlyDay,interv,-1); |
1503 | else | 1506 | else |
1504 | recur->setYearly(Recurrence::rYearlyDay,interv,r.count); | 1507 | recur->setYearly(Recurrence::rYearlyDay,interv,r.count); |
1505 | } | 1508 | } |
1506 | while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1509 | while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1507 | recur->addYearlyNum(day); | 1510 | recur->addYearlyNum(day); |
1508 | } | 1511 | } |
1509 | } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { | 1512 | } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { |
1510 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1513 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1511 | qDebug("YEARLY POS NOT SUPPORTED BY GUI"); | 1514 | qDebug("YEARLY POS NOT SUPPORTED BY GUI"); |
1512 | if (!icaltime_is_null_time(r.until)) { | 1515 | if (!icaltime_is_null_time(r.until)) { |
1513 | recur->setYearly(Recurrence::rYearlyPos,interv, | 1516 | recur->setYearly(Recurrence::rYearlyPos,interv, |
1514 | readICalDate(r.until)); | 1517 | readICalDate(r.until)); |
1515 | } else { | 1518 | } else { |
1516 | if (r.count == 0) | 1519 | if (r.count == 0) |
1517 | recur->setYearly(Recurrence::rYearlyPos,interv,-1); | 1520 | recur->setYearly(Recurrence::rYearlyPos,interv,-1); |
1518 | else | 1521 | else |
1519 | recur->setYearly(Recurrence::rYearlyPos,interv,r.count); | 1522 | recur->setYearly(Recurrence::rYearlyPos,interv,r.count); |
1520 | } | 1523 | } |
1521 | bool useSetPos = false; | 1524 | bool useSetPos = false; |
1522 | short pos = 0; | 1525 | short pos = 0; |
1523 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1526 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1524 | // kdDebug(5800) << "----a " << index << ": " << day << endl; | 1527 | // kdDebug(5800) << "----a " << index << ": " << day << endl; |
1525 | pos = icalrecurrencetype_day_position(day); | 1528 | pos = icalrecurrencetype_day_position(day); |
1526 | if (pos) { | 1529 | if (pos) { |
1527 | day = icalrecurrencetype_day_day_of_week(day); | 1530 | day = icalrecurrencetype_day_day_of_week(day); |
1528 | QBitArray ba(7); // don't wipe qba | 1531 | QBitArray ba(7); // don't wipe qba |
1529 | ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1532 | ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1530 | recur->addYearlyMonthPos(pos,ba); | 1533 | recur->addYearlyMonthPos(pos,ba); |
1531 | } else { | 1534 | } else { |
1532 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1535 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1533 | useSetPos = true; | 1536 | useSetPos = true; |
1534 | } | 1537 | } |
1535 | } | 1538 | } |
1536 | if (useSetPos) { | 1539 | if (useSetPos) { |
1537 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1540 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1538 | recur->addYearlyMonthPos(r.by_set_pos[0],qba); | 1541 | recur->addYearlyMonthPos(r.by_set_pos[0],qba); |
1539 | } | 1542 | } |
1540 | } | 1543 | } |
1541 | } else { | 1544 | } else { |
1542 | //qDebug("YEARLY MONTH "); | 1545 | //qDebug("YEARLY MONTH "); |
1543 | if (!icaltime_is_null_time(r.until)) { | 1546 | if (!icaltime_is_null_time(r.until)) { |
1544 | recur->setYearly(Recurrence::rYearlyMonth,interv, | 1547 | recur->setYearly(Recurrence::rYearlyMonth,interv, |
1545 | readICalDate(r.until)); | 1548 | readICalDate(r.until)); |
1546 | } else { | 1549 | } else { |
1547 | if (r.count == 0) | 1550 | if (r.count == 0) |
1548 | recur->setYearly(Recurrence::rYearlyMonth,interv,-1); | 1551 | recur->setYearly(Recurrence::rYearlyMonth,interv,-1); |
1549 | else | 1552 | else |
1550 | recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); | 1553 | recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); |
1551 | } | 1554 | } |
1552 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { | 1555 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { |
1553 | index = 0; | 1556 | index = 0; |
1554 | while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1557 | while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1555 | recur->addYearlyNum(day); | 1558 | recur->addYearlyNum(day); |
1556 | } | 1559 | } |
1557 | } else { | 1560 | } else { |
1558 | recur->addYearlyNum(incidence->dtStart().date().month()); | 1561 | recur->addYearlyNum(incidence->dtStart().date().month()); |
1559 | } | 1562 | } |
1560 | } | 1563 | } |
1561 | 1564 | ||
1562 | } | 1565 | } |
1563 | break; | 1566 | break; |
1564 | default: | 1567 | default: |
1565 | ; | 1568 | ; |
1566 | break; | 1569 | break; |
1567 | } | 1570 | } |
1568 | } | 1571 | } |
1569 | 1572 | ||
1570 | void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) | 1573 | void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) |
1571 | { | 1574 | { |
1572 | //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; | 1575 | //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; |
1573 | 1576 | ||
1574 | Alarm* ialarm = incidence->newAlarm(); | 1577 | Alarm* ialarm = incidence->newAlarm(); |
1575 | ialarm->setRepeatCount(0); | 1578 | ialarm->setRepeatCount(0); |
1576 | ialarm->setEnabled(true); | 1579 | ialarm->setEnabled(true); |
1577 | 1580 | ||
1578 | // Determine the alarm's action type | 1581 | // Determine the alarm's action type |
1579 | icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); | 1582 | icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); |
1580 | if ( !p ) { | 1583 | if ( !p ) { |
1581 | return; | 1584 | return; |
1582 | } | 1585 | } |
1583 | 1586 | ||
1584 | icalproperty_action action = icalproperty_get_action(p); | 1587 | icalproperty_action action = icalproperty_get_action(p); |
1585 | Alarm::Type type = Alarm::Display; | 1588 | Alarm::Type type = Alarm::Display; |
1586 | switch ( action ) { | 1589 | switch ( action ) { |
1587 | case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; | 1590 | case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; |
1588 | case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; | 1591 | case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; |
1589 | case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; | 1592 | case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; |
1590 | case ICAL_ACTION_EMAIL: type = Alarm::Email; break; | 1593 | case ICAL_ACTION_EMAIL: type = Alarm::Email; break; |
1591 | default: | 1594 | default: |
1592 | ; | 1595 | ; |
1593 | return; | 1596 | return; |
1594 | } | 1597 | } |
1595 | ialarm->setType(type); | 1598 | ialarm->setType(type); |
1596 | 1599 | ||
1597 | p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); | 1600 | p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); |
1598 | while (p) { | 1601 | while (p) { |
1599 | icalproperty_kind kind = icalproperty_isa(p); | 1602 | icalproperty_kind kind = icalproperty_isa(p); |
1600 | 1603 | ||
1601 | switch (kind) { | 1604 | switch (kind) { |
1602 | case ICAL_TRIGGER_PROPERTY: { | 1605 | case ICAL_TRIGGER_PROPERTY: { |
1603 | icaltriggertype trigger = icalproperty_get_trigger(p); | 1606 | icaltriggertype trigger = icalproperty_get_trigger(p); |
1604 | if (icaltime_is_null_time(trigger.time)) { | 1607 | if (icaltime_is_null_time(trigger.time)) { |
1605 | if (icaldurationtype_is_null_duration(trigger.duration)) { | 1608 | if (icaldurationtype_is_null_duration(trigger.duration)) { |
1606 | kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; | 1609 | kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; |
1607 | } else { | 1610 | } else { |
1608 | Duration duration = icaldurationtype_as_int( trigger.duration ); | 1611 | Duration duration = icaldurationtype_as_int( trigger.duration ); |
1609 | icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); | 1612 | icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); |
1610 | if (param && icalparameter_get_related(param) == ICAL_RELATED_END) | 1613 | if (param && icalparameter_get_related(param) == ICAL_RELATED_END) |
1611 | ialarm->setEndOffset(duration); | 1614 | ialarm->setEndOffset(duration); |
1612 | else | 1615 | else |
1613 | ialarm->setStartOffset(duration); | 1616 | ialarm->setStartOffset(duration); |
1614 | } | 1617 | } |
1615 | } else { | 1618 | } else { |
1616 | ialarm->setTime(readICalDateTime(trigger.time)); | 1619 | ialarm->setTime(readICalDateTime(trigger.time)); |
1617 | } | 1620 | } |
1618 | break; | 1621 | break; |
1619 | } | 1622 | } |
1620 | case ICAL_DURATION_PROPERTY: { | 1623 | case ICAL_DURATION_PROPERTY: { |
1621 | icaldurationtype duration = icalproperty_get_duration(p); | 1624 | icaldurationtype duration = icalproperty_get_duration(p); |
1622 | ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); | 1625 | ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); |
1623 | break; | 1626 | break; |
1624 | } | 1627 | } |
1625 | case ICAL_REPEAT_PROPERTY: | 1628 | case ICAL_REPEAT_PROPERTY: |
1626 | ialarm->setRepeatCount(icalproperty_get_repeat(p)); | 1629 | ialarm->setRepeatCount(icalproperty_get_repeat(p)); |
1627 | break; | 1630 | break; |
1628 | 1631 | ||
1629 | // Only in DISPLAY and EMAIL and PROCEDURE alarms | 1632 | // Only in DISPLAY and EMAIL and PROCEDURE alarms |
1630 | case ICAL_DESCRIPTION_PROPERTY: { | 1633 | case ICAL_DESCRIPTION_PROPERTY: { |
1631 | QString description = QString::fromUtf8(icalproperty_get_description(p)); | 1634 | QString description = QString::fromUtf8(icalproperty_get_description(p)); |
1632 | switch ( action ) { | 1635 | switch ( action ) { |
1633 | case ICAL_ACTION_DISPLAY: | 1636 | case ICAL_ACTION_DISPLAY: |
1634 | ialarm->setText( description ); | 1637 | ialarm->setText( description ); |
1635 | break; | 1638 | break; |
1636 | case ICAL_ACTION_PROCEDURE: | 1639 | case ICAL_ACTION_PROCEDURE: |
1637 | ialarm->setProgramArguments( description ); | 1640 | ialarm->setProgramArguments( description ); |
1638 | break; | 1641 | break; |
1639 | case ICAL_ACTION_EMAIL: | 1642 | case ICAL_ACTION_EMAIL: |
1640 | ialarm->setMailText( description ); | 1643 | ialarm->setMailText( description ); |
1641 | break; | 1644 | break; |
1642 | default: | 1645 | default: |
1643 | break; | 1646 | break; |
1644 | } | 1647 | } |
1645 | break; | 1648 | break; |
1646 | } | 1649 | } |
1647 | // Only in EMAIL alarm | 1650 | // Only in EMAIL alarm |
1648 | case ICAL_SUMMARY_PROPERTY: | 1651 | case ICAL_SUMMARY_PROPERTY: |
1649 | ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); | 1652 | ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); |
1650 | break; | 1653 | break; |
1651 | 1654 | ||
1652 | // Only in EMAIL alarm | 1655 | // Only in EMAIL alarm |
1653 | case ICAL_ATTENDEE_PROPERTY: { | 1656 | case ICAL_ATTENDEE_PROPERTY: { |
1654 | QString email = QString::fromUtf8(icalproperty_get_attendee(p)); | 1657 | QString email = QString::fromUtf8(icalproperty_get_attendee(p)); |
1655 | QString name; | 1658 | QString name; |
1656 | icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); | 1659 | icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); |
1657 | if (param) { | 1660 | if (param) { |
1658 | name = QString::fromUtf8(icalparameter_get_cn(param)); | 1661 | name = QString::fromUtf8(icalparameter_get_cn(param)); |
1659 | } | 1662 | } |
1660 | ialarm->addMailAddress(Person(name, email)); | 1663 | ialarm->addMailAddress(Person(name, email)); |
1661 | break; | 1664 | break; |
1662 | } | 1665 | } |
1663 | // Only in AUDIO and EMAIL and PROCEDURE alarms | 1666 | // Only in AUDIO and EMAIL and PROCEDURE alarms |
1664 | case ICAL_ATTACH_PROPERTY: { | 1667 | case ICAL_ATTACH_PROPERTY: { |
1665 | icalattach *attach = icalproperty_get_attach(p); | 1668 | icalattach *attach = icalproperty_get_attach(p); |
1666 | QString url = QFile::decodeName(icalattach_get_url(attach)); | 1669 | QString url = QFile::decodeName(icalattach_get_url(attach)); |
1667 | switch ( action ) { | 1670 | switch ( action ) { |
1668 | case ICAL_ACTION_AUDIO: | 1671 | case ICAL_ACTION_AUDIO: |
1669 | ialarm->setAudioFile( url ); | 1672 | ialarm->setAudioFile( url ); |
1670 | break; | 1673 | break; |
1671 | case ICAL_ACTION_PROCEDURE: | 1674 | case ICAL_ACTION_PROCEDURE: |
1672 | ialarm->setProgramFile( url ); | 1675 | ialarm->setProgramFile( url ); |
1673 | break; | 1676 | break; |
1674 | case ICAL_ACTION_EMAIL: | 1677 | case ICAL_ACTION_EMAIL: |
1675 | ialarm->addMailAttachment( url ); | 1678 | ialarm->addMailAttachment( url ); |
1676 | break; | 1679 | break; |
1677 | default: | 1680 | default: |
1678 | break; | 1681 | break; |
1679 | } | 1682 | } |
1680 | break; | 1683 | break; |
1681 | } | 1684 | } |
1682 | default: | 1685 | default: |
1683 | break; | 1686 | break; |
1684 | } | 1687 | } |
1685 | 1688 | ||
1686 | p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); | 1689 | p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); |
1687 | } | 1690 | } |
1688 | 1691 | ||
1689 | // custom properties | 1692 | // custom properties |
1690 | readCustomProperties(alarm, ialarm); | 1693 | readCustomProperties(alarm, ialarm); |
1691 | 1694 | ||
1692 | // TODO: check for consistency of alarm properties | 1695 | // TODO: check for consistency of alarm properties |
1693 | } | 1696 | } |
1694 | 1697 | ||
1695 | icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) | 1698 | icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) |
1696 | { | 1699 | { |
1697 | icaltimetype t; | 1700 | icaltimetype t; |
1698 | 1701 | ||
1699 | t.year = date.year(); | 1702 | t.year = date.year(); |
1700 | t.month = date.month(); | 1703 | t.month = date.month(); |
1701 | t.day = date.day(); | 1704 | t.day = date.day(); |
1702 | 1705 | ||
1703 | t.hour = 0; | 1706 | t.hour = 0; |
1704 | t.minute = 0; | 1707 | t.minute = 0; |
1705 | t.second = 0; | 1708 | t.second = 0; |
1706 | 1709 | ||
1707 | t.is_date = 1; | 1710 | t.is_date = 1; |
1708 | 1711 | ||
1709 | t.is_utc = 0; | 1712 | t.is_utc = 0; |
1710 | 1713 | ||
1711 | t.zone = 0; | 1714 | t.zone = 0; |
1712 | 1715 | ||
1713 | return t; | 1716 | return t; |
1714 | } | 1717 | } |
1715 | 1718 | ||
1716 | icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) | 1719 | icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) |
1717 | { | 1720 | { |
1718 | icaltimetype t; | 1721 | icaltimetype t; |
1719 | t.is_date = 0; | 1722 | t.is_date = 0; |
1720 | t.zone = 0; | 1723 | t.zone = 0; |
1721 | QDateTime datetime; | 1724 | QDateTime datetime; |
1722 | if ( mParent->utc() ) { | 1725 | if ( mParent->utc() ) { |
1723 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 1726 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
1724 | datetime = dt.addSecs ( -offset*60); | 1727 | datetime = dt.addSecs ( -offset*60); |
1725 | t.is_utc = 1; | 1728 | t.is_utc = 1; |
1726 | } | 1729 | } |
1727 | else { | 1730 | else { |
1728 | datetime = dt; | 1731 | datetime = dt; |
1729 | t.is_utc = 0; | 1732 | t.is_utc = 0; |
1730 | 1733 | ||
1731 | } | 1734 | } |
1732 | t.year = datetime.date().year(); | 1735 | t.year = datetime.date().year(); |
1733 | t.month = datetime.date().month(); | 1736 | t.month = datetime.date().month(); |
1734 | t.day = datetime.date().day(); | 1737 | t.day = datetime.date().day(); |
1735 | 1738 | ||
1736 | t.hour = datetime.time().hour(); | 1739 | t.hour = datetime.time().hour(); |
1737 | t.minute = datetime.time().minute(); | 1740 | t.minute = datetime.time().minute(); |
1738 | t.second = datetime.time().second(); | 1741 | t.second = datetime.time().second(); |
1739 | 1742 | ||
1740 | //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); | 1743 | //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); |
1741 | 1744 | ||
1742 | // if ( mParent->utc() ) { | 1745 | // if ( mParent->utc() ) { |
1743 | // datetime = KGlobal::locale()->localTime( dt ); | 1746 | // datetime = KGlobal::locale()->localTime( dt ); |
1744 | // qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); | 1747 | // qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); |
1745 | // if (mParent->timeZoneId().isEmpty()) | 1748 | // if (mParent->timeZoneId().isEmpty()) |
1746 | // t = icaltime_as_utc(t, 0); | 1749 | // t = icaltime_as_utc(t, 0); |
1747 | // else | 1750 | // else |
1748 | // t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); | 1751 | // t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); |
1749 | // } | 1752 | // } |
1750 | 1753 | ||
1751 | return t; | 1754 | return t; |
1752 | } | 1755 | } |
1753 | 1756 | ||
1754 | QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) | 1757 | QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) |
1755 | { | 1758 | { |
1756 | QDateTime dt (QDate(t.year,t.month,t.day), | 1759 | QDateTime dt (QDate(t.year,t.month,t.day), |
1757 | QTime(t.hour,t.minute,t.second) ); | 1760 | QTime(t.hour,t.minute,t.second) ); |
1758 | 1761 | ||
1759 | if (t.is_utc) { | 1762 | if (t.is_utc) { |
1760 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 1763 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
1761 | dt = dt.addSecs ( offset*60); | 1764 | dt = dt.addSecs ( offset*60); |
1762 | } | 1765 | } |
1763 | 1766 | ||
1764 | return dt; | 1767 | return dt; |
1765 | } | 1768 | } |
1766 | 1769 | ||
1767 | QDate ICalFormatImpl::readICalDate(icaltimetype t) | 1770 | QDate ICalFormatImpl::readICalDate(icaltimetype t) |
1768 | { | 1771 | { |
1769 | return QDate(t.year,t.month,t.day); | 1772 | return QDate(t.year,t.month,t.day); |
1770 | } | 1773 | } |
1771 | 1774 | ||
1772 | icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) | 1775 | icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) |
1773 | { | 1776 | { |
1774 | icaldurationtype d; | 1777 | icaldurationtype d; |
1775 | 1778 | ||
1776 | d.is_neg = (seconds<0)?1:0; | 1779 | d.is_neg = (seconds<0)?1:0; |
1777 | if (seconds<0) seconds = -seconds; | 1780 | if (seconds<0) seconds = -seconds; |
1778 | 1781 | ||
1779 | d.weeks = seconds / gSecondsPerWeek; | 1782 | d.weeks = seconds / gSecondsPerWeek; |
1780 | seconds %= gSecondsPerWeek; | 1783 | seconds %= gSecondsPerWeek; |
1781 | d.days = seconds / gSecondsPerDay; | 1784 | d.days = seconds / gSecondsPerDay; |
1782 | seconds %= gSecondsPerDay; | 1785 | seconds %= gSecondsPerDay; |
1783 | d.hours = seconds / gSecondsPerHour; | 1786 | d.hours = seconds / gSecondsPerHour; |
1784 | seconds %= gSecondsPerHour; | 1787 | seconds %= gSecondsPerHour; |
1785 | d.minutes = seconds / gSecondsPerMinute; | 1788 | d.minutes = seconds / gSecondsPerMinute; |
1786 | seconds %= gSecondsPerMinute; | 1789 | seconds %= gSecondsPerMinute; |
1787 | d.seconds = seconds; | 1790 | d.seconds = seconds; |
1788 | return d; | 1791 | return d; |
1789 | } | 1792 | } |
1790 | 1793 | ||
1791 | int ICalFormatImpl::readICalDuration(icaldurationtype d) | 1794 | int ICalFormatImpl::readICalDuration(icaldurationtype d) |
1792 | { | 1795 | { |
1793 | int result = 0; | 1796 | int result = 0; |
1794 | 1797 | ||
1795 | result += d.weeks * gSecondsPerWeek; | 1798 | result += d.weeks * gSecondsPerWeek; |
1796 | result += d.days * gSecondsPerDay; | 1799 | result += d.days * gSecondsPerDay; |
1797 | result += d.hours * gSecondsPerHour; | 1800 | result += d.hours * gSecondsPerHour; |
1798 | result += d.minutes * gSecondsPerMinute; | 1801 | result += d.minutes * gSecondsPerMinute; |
1799 | result += d.seconds; | 1802 | result += d.seconds; |
1800 | 1803 | ||
1801 | if (d.is_neg) result *= -1; | 1804 | if (d.is_neg) result *= -1; |
1802 | 1805 | ||
1803 | return result; | 1806 | return result; |
1804 | } | 1807 | } |
1805 | 1808 | ||
1806 | icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) | 1809 | icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) |
1807 | { | 1810 | { |
1808 | icalcomponent *calendar; | 1811 | icalcomponent *calendar; |
1809 | 1812 | ||
1810 | // Root component | 1813 | // Root component |
1811 | calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); | 1814 | calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); |
1812 | 1815 | ||
1813 | icalproperty *p; | 1816 | icalproperty *p; |
1814 | 1817 | ||
1815 | // Product Identifier | 1818 | // Product Identifier |
1816 | p = icalproperty_new_prodid(CalFormat::productId().utf8()); | 1819 | p = icalproperty_new_prodid(CalFormat::productId().utf8()); |
1817 | icalcomponent_add_property(calendar,p); | 1820 | icalcomponent_add_property(calendar,p); |
1818 | 1821 | ||
1819 | // TODO: Add time zone | 1822 | // TODO: Add time zone |
1820 | 1823 | ||
1821 | // iCalendar version (2.0) | 1824 | // iCalendar version (2.0) |
1822 | p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); | 1825 | p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); |
1823 | icalcomponent_add_property(calendar,p); | 1826 | icalcomponent_add_property(calendar,p); |
1824 | 1827 | ||
1825 | // Custom properties | 1828 | // Custom properties |
1826 | if( cal != 0 ) | 1829 | if( cal != 0 ) |
1827 | writeCustomProperties(calendar, cal); | 1830 | writeCustomProperties(calendar, cal); |
1828 | 1831 | ||
1829 | return calendar; | 1832 | return calendar; |
1830 | } | 1833 | } |
1831 | 1834 | ||
1832 | 1835 | ||
1833 | 1836 | ||
1834 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. | 1837 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. |
1835 | // and break it down from its tree-like format into the dictionary format | 1838 | // and break it down from its tree-like format into the dictionary format |
1836 | // that is used internally in the ICalFormatImpl. | 1839 | // that is used internally in the ICalFormatImpl. |
1837 | bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) | 1840 | bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) |
1838 | { | 1841 | { |
1839 | // this function will populate the caldict dictionary and other event | 1842 | // this function will populate the caldict dictionary and other event |
1840 | // lists. It turns vevents into Events and then inserts them. | 1843 | // lists. It turns vevents into Events and then inserts them. |
1841 | 1844 | ||
1842 | if (!calendar) return false; | 1845 | if (!calendar) return false; |
1843 | 1846 | ||
1844 | // TODO: check for METHOD | 1847 | // TODO: check for METHOD |
1845 | #if 0 | 1848 | #if 0 |
1846 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { | 1849 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { |
1847 | char *methodType = 0; | 1850 | char *methodType = 0; |
1848 | methodType = fakeCString(vObjectUStringZValue(curVO)); | 1851 | methodType = fakeCString(vObjectUStringZValue(curVO)); |
1849 | if (mEnableDialogs) | 1852 | if (mEnableDialogs) |
1850 | KMessageBox::information(mTopWidget, | 1853 | KMessageBox::information(mTopWidget, |
1851 | i18n("This calendar is an iTIP transaction of type \"%1\".") | 1854 | i18n("This calendar is an iTIP transaction of type \"%1\".") |
1852 | .arg(methodType), | 1855 | .arg(methodType), |
1853 | i18n("%1: iTIP Transaction").arg(CalFormat::application())); | 1856 | i18n("%1: iTIP Transaction").arg(CalFormat::application())); |
1854 | delete methodType; | 1857 | delete methodType; |
diff --git a/libkcal/icalformatimpl.h b/libkcal/icalformatimpl.h index 203c302..3a35b4c 100644 --- a/libkcal/icalformatimpl.h +++ b/libkcal/icalformatimpl.h | |||
@@ -1,109 +1,111 @@ | |||
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 ICALFORMATIMPL_H | 20 | #ifndef ICALFORMATIMPL_H |
21 | #define ICALFORMATIMPL_H | 21 | #define ICALFORMATIMPL_H |
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | //Added by qt3to4: | ||
25 | #include <Q3PtrList> | ||
24 | 26 | ||
25 | #include "scheduler.h" | 27 | #include "scheduler.h" |
26 | #include "freebusy.h" | 28 | #include "freebusy.h" |
27 | 29 | ||
28 | extern "C" { | 30 | extern "C" { |
29 | #include <ical.h> | 31 | #include <ical.h> |
30 | #include <icalss.h> | 32 | #include <icalss.h> |
31 | } | 33 | } |
32 | 34 | ||
33 | namespace KCal { | 35 | namespace KCal { |
34 | 36 | ||
35 | class Compat; | 37 | class Compat; |
36 | 38 | ||
37 | /** | 39 | /** |
38 | This class provides the libical dependent functions for ICalFormat. | 40 | This class provides the libical dependent functions for ICalFormat. |
39 | */ | 41 | */ |
40 | class ICalFormatImpl { | 42 | class ICalFormatImpl { |
41 | public: | 43 | public: |
42 | /** Create new iCal format for calendar object */ | 44 | /** Create new iCal format for calendar object */ |
43 | ICalFormatImpl( ICalFormat *parent ); | 45 | ICalFormatImpl( ICalFormat *parent ); |
44 | virtual ~ICalFormatImpl(); | 46 | virtual ~ICalFormatImpl(); |
45 | 47 | ||
46 | bool populate( Calendar *, icalcomponent *fs); | 48 | bool populate( Calendar *, icalcomponent *fs); |
47 | 49 | ||
48 | icalcomponent *writeIncidence(Incidence *incidence); | 50 | icalcomponent *writeIncidence(Incidence *incidence); |
49 | icalcomponent *writeTodo(Todo *todo); | 51 | icalcomponent *writeTodo(Todo *todo); |
50 | icalcomponent *writeEvent(Event *event); | 52 | icalcomponent *writeEvent(Event *event); |
51 | icalcomponent *writeFreeBusy(FreeBusy *freebusy, | 53 | icalcomponent *writeFreeBusy(FreeBusy *freebusy, |
52 | Scheduler::Method method); | 54 | Scheduler::Method method); |
53 | icalcomponent *writeJournal(Journal *journal); | 55 | icalcomponent *writeJournal(Journal *journal); |
54 | void writeIncidence(icalcomponent *parent,Incidence *incidence); | 56 | void writeIncidence(icalcomponent *parent,Incidence *incidence); |
55 | icalproperty *writeAttendee(Attendee *attendee); | 57 | icalproperty *writeAttendee(Attendee *attendee); |
56 | icalproperty *writeAttachment(Attachment *attach); | 58 | icalproperty *writeAttachment(Attachment *attach); |
57 | icalproperty *writeRecurrenceRule(Recurrence *); | 59 | icalproperty *writeRecurrenceRule(Recurrence *); |
58 | icalcomponent *writeAlarm(Alarm *alarm); | 60 | icalcomponent *writeAlarm(Alarm *alarm); |
59 | 61 | ||
60 | QString extractErrorProperty(icalcomponent *); | 62 | QString extractErrorProperty(icalcomponent *); |
61 | Todo *readTodo(icalcomponent *vtodo); | 63 | Todo *readTodo(icalcomponent *vtodo); |
62 | Event *readEvent(icalcomponent *vevent); | 64 | Event *readEvent(icalcomponent *vevent); |
63 | FreeBusy *readFreeBusy(icalcomponent *vfreebusy); | 65 | FreeBusy *readFreeBusy(icalcomponent *vfreebusy); |
64 | Journal *readJournal(icalcomponent *vjournal); | 66 | Journal *readJournal(icalcomponent *vjournal); |
65 | Attendee *readAttendee(icalproperty *attendee); | 67 | Attendee *readAttendee(icalproperty *attendee); |
66 | Attachment *readAttachment(icalproperty *attach); | 68 | Attachment *readAttachment(icalproperty *attach); |
67 | void readIncidence(icalcomponent *parent,Incidence *incidence); | 69 | void readIncidence(icalcomponent *parent,Incidence *incidence); |
68 | void readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *event); | 70 | void readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *event); |
69 | void readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur,Incidence *event ); | 71 | void readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur,Incidence *event ); |
70 | void readAlarm(icalcomponent *alarm,Incidence *incidence); | 72 | void readAlarm(icalcomponent *alarm,Incidence *incidence); |
71 | /** Return the PRODID string loaded from calendar file */ | 73 | /** Return the PRODID string loaded from calendar file */ |
72 | const QString &loadedProductId() { return mLoadedProductId; } | 74 | const QString &loadedProductId() { return mLoadedProductId; } |
73 | 75 | ||
74 | icaltimetype writeICalDate(const QDate &); | 76 | icaltimetype writeICalDate(const QDate &); |
75 | QDate readICalDate(icaltimetype); | 77 | QDate readICalDate(icaltimetype); |
76 | icaltimetype writeICalDateTime(const QDateTime &); | 78 | icaltimetype writeICalDateTime(const QDateTime &); |
77 | QDateTime readICalDateTime(icaltimetype); | 79 | QDateTime readICalDateTime(icaltimetype); |
78 | icaldurationtype writeICalDuration(int seconds); | 80 | icaldurationtype writeICalDuration(int seconds); |
79 | int readICalDuration(icaldurationtype); | 81 | int readICalDuration(icaldurationtype); |
80 | icalcomponent *createCalendarComponent(Calendar * = 0); | 82 | icalcomponent *createCalendarComponent(Calendar * = 0); |
81 | icalcomponent *createScheduleComponent(IncidenceBase *,Scheduler::Method); | 83 | icalcomponent *createScheduleComponent(IncidenceBase *,Scheduler::Method); |
82 | 84 | ||
83 | private: | 85 | private: |
84 | void writeIncidenceBase(icalcomponent *parent,IncidenceBase *); | 86 | void writeIncidenceBase(icalcomponent *parent,IncidenceBase *); |
85 | void readIncidenceBase(icalcomponent *parent,IncidenceBase *); | 87 | void readIncidenceBase(icalcomponent *parent,IncidenceBase *); |
86 | void writeCustomProperties(icalcomponent *parent,CustomProperties *); | 88 | void writeCustomProperties(icalcomponent *parent,CustomProperties *); |
87 | void readCustomProperties(icalcomponent *parent,CustomProperties *); | 89 | void readCustomProperties(icalcomponent *parent,CustomProperties *); |
88 | void dumpIcalRecurrence(icalrecurrencetype); | 90 | void dumpIcalRecurrence(icalrecurrencetype); |
89 | 91 | ||
90 | ICalFormat *mParent; | 92 | ICalFormat *mParent; |
91 | Calendar *mCalendar; | 93 | Calendar *mCalendar; |
92 | 94 | ||
93 | QString mLoadedProductId; // PRODID string loaded from calendar file | 95 | QString mLoadedProductId; // PRODID string loaded from calendar file |
94 | int mCalendarVersion; // determines backward compatibility mode on read | 96 | int mCalendarVersion; // determines backward compatibility mode on read |
95 | 97 | ||
96 | QPtrList<Event> mEventsRelate; // events with relations | 98 | Q3PtrList<Event> mEventsRelate; // events with relations |
97 | QPtrList<Todo> mTodosRelate; // todos with relations | 99 | Q3PtrList<Todo> mTodosRelate; // todos with relations |
98 | 100 | ||
99 | static const int mSecondsPerWeek; | 101 | static const int mSecondsPerWeek; |
100 | static const int mSecondsPerDay; | 102 | static const int mSecondsPerDay; |
101 | static const int mSecondsPerHour; | 103 | static const int mSecondsPerHour; |
102 | static const int mSecondsPerMinute; | 104 | static const int mSecondsPerMinute; |
103 | 105 | ||
104 | Compat *mCompat; | 106 | Compat *mCompat; |
105 | }; | 107 | }; |
106 | 108 | ||
107 | } | 109 | } |
108 | 110 | ||
109 | #endif | 111 | #endif |
diff --git a/libkcal/imipscheduler.cpp b/libkcal/imipscheduler.cpp index e186f8e..e6d56a6 100644 --- a/libkcal/imipscheduler.cpp +++ b/libkcal/imipscheduler.cpp | |||
@@ -1,58 +1,60 @@ | |||
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 | // | 21 | // |
22 | // IMIPScheduler - iMIP implementation of iTIP methods | 22 | // IMIPScheduler - iMIP implementation of iTIP methods |
23 | // | 23 | // |
24 | 24 | ||
25 | #include "event.h" | 25 | #include "event.h" |
26 | #include "icalformat.h" | 26 | #include "icalformat.h" |
27 | 27 | ||
28 | #include "imipscheduler.h" | 28 | #include "imipscheduler.h" |
29 | //Added by qt3to4: | ||
30 | #include <Q3PtrList> | ||
29 | 31 | ||
30 | using namespace KCal; | 32 | using namespace KCal; |
31 | 33 | ||
32 | IMIPScheduler::IMIPScheduler(Calendar *calendar) | 34 | IMIPScheduler::IMIPScheduler(Calendar *calendar) |
33 | : Scheduler(calendar) | 35 | : Scheduler(calendar) |
34 | { | 36 | { |
35 | } | 37 | } |
36 | 38 | ||
37 | IMIPScheduler::~IMIPScheduler() | 39 | IMIPScheduler::~IMIPScheduler() |
38 | { | 40 | { |
39 | } | 41 | } |
40 | 42 | ||
41 | bool IMIPScheduler::publish (IncidenceBase *incidence,const QString &recipients) | 43 | bool IMIPScheduler::publish (IncidenceBase *incidence,const QString &recipients) |
42 | { | 44 | { |
43 | return false; | 45 | return false; |
44 | } | 46 | } |
45 | 47 | ||
46 | bool IMIPScheduler::performTransaction(IncidenceBase *incidence,Method method) | 48 | bool IMIPScheduler::performTransaction(IncidenceBase *incidence,Method method) |
47 | { | 49 | { |
48 | mFormat->createScheduleMessage(incidence,method); | 50 | mFormat->createScheduleMessage(incidence,method); |
49 | 51 | ||
50 | return false; | 52 | return false; |
51 | } | 53 | } |
52 | 54 | ||
53 | QPtrList<ScheduleMessage> IMIPScheduler::retrieveTransactions() | 55 | Q3PtrList<ScheduleMessage> IMIPScheduler::retrieveTransactions() |
54 | { | 56 | { |
55 | QPtrList<ScheduleMessage> messageList; | 57 | Q3PtrList<ScheduleMessage> messageList; |
56 | 58 | ||
57 | return messageList; | 59 | return messageList; |
58 | } | 60 | } |
diff --git a/libkcal/imipscheduler.h b/libkcal/imipscheduler.h index f142060..5a2d38e 100644 --- a/libkcal/imipscheduler.h +++ b/libkcal/imipscheduler.h | |||
@@ -1,49 +1,49 @@ | |||
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 IMIPSCHEDULER_H | 20 | #ifndef IMIPSCHEDULER_H |
21 | #define IMIPSCHEDULER_H | 21 | #define IMIPSCHEDULER_H |
22 | // | 22 | // |
23 | // iMIP implementation of iTIP methods | 23 | // iMIP implementation of iTIP methods |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qptrlist.h> | 26 | #include <q3ptrlist.h> |
27 | 27 | ||
28 | #include "scheduler.h" | 28 | #include "scheduler.h" |
29 | 29 | ||
30 | namespace KCal { | 30 | namespace KCal { |
31 | 31 | ||
32 | /* | 32 | /* |
33 | This class implements the iTIP interface using the email interface specified | 33 | This class implements the iTIP interface using the email interface specified |
34 | as iMIP. | 34 | as iMIP. |
35 | */ | 35 | */ |
36 | class IMIPScheduler : public Scheduler { | 36 | class IMIPScheduler : public Scheduler { |
37 | public: | 37 | public: |
38 | IMIPScheduler(Calendar *); | 38 | IMIPScheduler(Calendar *); |
39 | virtual ~IMIPScheduler(); | 39 | virtual ~IMIPScheduler(); |
40 | 40 | ||
41 | bool publish (IncidenceBase *incidence,const QString &recipients); | 41 | bool publish (IncidenceBase *incidence,const QString &recipients); |
42 | bool performTransaction(IncidenceBase *incidence,Method method); | 42 | bool performTransaction(IncidenceBase *incidence,Method method); |
43 | QPtrList<ScheduleMessage> retrieveTransactions(); | 43 | Q3PtrList<ScheduleMessage> retrieveTransactions(); |
44 | }; | 44 | }; |
45 | 45 | ||
46 | } | 46 | } |
47 | 47 | ||
48 | #endif // IMIPSCHEDULER_H | 48 | #endif // IMIPSCHEDULER_H |
49 | 49 | ||
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 7dd9bd2..8fcdc69 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,872 +1,874 @@ | |||
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 | //Added by qt3to4: | ||
30 | #include <Q3PtrList> | ||
29 | 31 | ||
30 | using namespace KCal; | 32 | using namespace KCal; |
31 | 33 | ||
32 | Incidence::Incidence() : | 34 | Incidence::Incidence() : |
33 | IncidenceBase(), | 35 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 36 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 37 | { |
36 | mRecurrence = 0;//new Recurrence(this); | 38 | mRecurrence = 0;//new Recurrence(this); |
37 | mCancelled = false; | 39 | mCancelled = false; |
38 | recreate(); | 40 | recreate(); |
39 | mHasStartDate = true; | 41 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 42 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 43 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 44 | mHasRecurrenceID = false; |
43 | mHoliday = false; | 45 | mHoliday = false; |
44 | mBirthday = false; | 46 | mBirthday = false; |
45 | mAnniversary = false; | 47 | mAnniversary = false; |
46 | 48 | ||
47 | } | 49 | } |
48 | 50 | ||
49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 51 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
50 | { | 52 | { |
51 | // TODO: reenable attributes currently commented out. | 53 | // TODO: reenable attributes currently commented out. |
52 | mRevision = i.mRevision; | 54 | mRevision = i.mRevision; |
53 | mCreated = i.mCreated; | 55 | mCreated = i.mCreated; |
54 | mDescription = i.mDescription; | 56 | mDescription = i.mDescription; |
55 | mSummary = i.mSummary; | 57 | mSummary = i.mSummary; |
56 | mCategories = i.mCategories; | 58 | mCategories = i.mCategories; |
57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 59 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
58 | mRelatedTo = 0; | 60 | mRelatedTo = 0; |
59 | mRelatedToUid = i.mRelatedToUid; | 61 | mRelatedToUid = i.mRelatedToUid; |
60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 62 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
61 | mExDates = i.mExDates; | 63 | mExDates = i.mExDates; |
62 | QPtrListIterator<Attachment> itat( i.mAttachments ); | 64 | Q3PtrListIterator<Attachment> itat( i.mAttachments ); |
63 | Attachment *at; | 65 | Attachment *at; |
64 | while( (at = itat.current()) ) { | 66 | while( (at = itat.current()) ) { |
65 | Attachment *a = new Attachment( *at ); | 67 | Attachment *a = new Attachment( *at ); |
66 | mAttachments.append( a ); | 68 | mAttachments.append( a ); |
67 | ++itat; | 69 | ++itat; |
68 | } | 70 | } |
69 | mAttachments.setAutoDelete( true ); | 71 | mAttachments.setAutoDelete( true ); |
70 | mResources = i.mResources; | 72 | mResources = i.mResources; |
71 | mSecrecy = i.mSecrecy; | 73 | mSecrecy = i.mSecrecy; |
72 | mPriority = i.mPriority; | 74 | mPriority = i.mPriority; |
73 | mLocation = i.mLocation; | 75 | mLocation = i.mLocation; |
74 | mCancelled = i.mCancelled; | 76 | mCancelled = i.mCancelled; |
75 | mHasStartDate = i.mHasStartDate; | 77 | mHasStartDate = i.mHasStartDate; |
76 | QPtrListIterator<Alarm> it( i.mAlarms ); | 78 | Q3PtrListIterator<Alarm> it( i.mAlarms ); |
77 | const Alarm *a; | 79 | const Alarm *a; |
78 | while( (a = it.current()) ) { | 80 | while( (a = it.current()) ) { |
79 | Alarm *b = new Alarm( *a ); | 81 | Alarm *b = new Alarm( *a ); |
80 | b->setParent( this ); | 82 | b->setParent( this ); |
81 | mAlarms.append( b ); | 83 | mAlarms.append( b ); |
82 | 84 | ||
83 | ++it; | 85 | ++it; |
84 | } | 86 | } |
85 | mAlarms.setAutoDelete(true); | 87 | mAlarms.setAutoDelete(true); |
86 | mHasRecurrenceID = i.mHasRecurrenceID; | 88 | mHasRecurrenceID = i.mHasRecurrenceID; |
87 | mRecurrenceID = i.mRecurrenceID; | 89 | mRecurrenceID = i.mRecurrenceID; |
88 | if ( i.mRecurrence ) | 90 | if ( i.mRecurrence ) |
89 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 91 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
90 | else | 92 | else |
91 | mRecurrence = 0; | 93 | mRecurrence = 0; |
92 | mHoliday = i.mHoliday ; | 94 | mHoliday = i.mHoliday ; |
93 | mBirthday = i.mBirthday; | 95 | mBirthday = i.mBirthday; |
94 | mAnniversary = i.mAnniversary; | 96 | mAnniversary = i.mAnniversary; |
95 | } | 97 | } |
96 | 98 | ||
97 | Incidence::~Incidence() | 99 | Incidence::~Incidence() |
98 | { | 100 | { |
99 | 101 | ||
100 | Incidence *ev; | 102 | Incidence *ev; |
101 | QPtrList<Incidence> Relations = relations(); | 103 | Q3PtrList<Incidence> Relations = relations(); |
102 | for (ev=Relations.first();ev;ev=Relations.next()) { | 104 | for (ev=Relations.first();ev;ev=Relations.next()) { |
103 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 105 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
104 | } | 106 | } |
105 | if (relatedTo()) relatedTo()->removeRelation(this); | 107 | if (relatedTo()) relatedTo()->removeRelation(this); |
106 | if ( mRecurrence ) | 108 | if ( mRecurrence ) |
107 | delete mRecurrence; | 109 | delete mRecurrence; |
108 | 110 | ||
109 | } | 111 | } |
110 | QString Incidence::durationText() | 112 | QString Incidence::durationText() |
111 | { | 113 | { |
112 | return "---"; | 114 | return "---"; |
113 | } | 115 | } |
114 | QString Incidence::durationText4Time( int offset ) | 116 | QString Incidence::durationText4Time( int offset ) |
115 | { | 117 | { |
116 | int min = offset/60; | 118 | int min = offset/60; |
117 | int hours = min /60; | 119 | int hours = min /60; |
118 | min = min % 60; | 120 | min = min % 60; |
119 | int days = hours /24; | 121 | int days = hours /24; |
120 | hours = hours % 24; | 122 | hours = hours % 24; |
121 | 123 | ||
122 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { | 124 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { |
123 | if ( days == 1 ) | 125 | if ( days == 1 ) |
124 | return "1" + i18n(" day"); | 126 | return "1" + i18n(" day"); |
125 | else | 127 | else |
126 | return QString::number( days )+ i18n(" days"); | 128 | return QString::number( days )+ i18n(" days"); |
127 | 129 | ||
128 | } | 130 | } |
129 | QString message = QString::number ( hours ) +":"; | 131 | QString message = QString::number ( hours ) +":"; |
130 | if ( min < 10 ) message += "0"; | 132 | if ( min < 10 ) message += "0"; |
131 | message += QString::number ( min ); | 133 | message += QString::number ( min ); |
132 | if ( days > 0 ) { | 134 | if ( days > 0 ) { |
133 | if ( days == 1 ) | 135 | if ( days == 1 ) |
134 | message = "1" + i18n(" day") + " "+message; | 136 | message = "1" + i18n(" day") + " "+message; |
135 | else | 137 | else |
136 | message = QString::number( days )+ i18n(" days") + " "+message; | 138 | message = QString::number( days )+ i18n(" days") + " "+message; |
137 | } | 139 | } |
138 | return message; | 140 | return message; |
139 | } | 141 | } |
140 | bool Incidence::isHoliday() const | 142 | bool Incidence::isHoliday() const |
141 | { | 143 | { |
142 | return mHoliday; | 144 | return mHoliday; |
143 | } | 145 | } |
144 | bool Incidence::isBirthday() const | 146 | bool Incidence::isBirthday() const |
145 | { | 147 | { |
146 | 148 | ||
147 | return mBirthday ; | 149 | return mBirthday ; |
148 | } | 150 | } |
149 | bool Incidence::isAnniversary() const | 151 | bool Incidence::isAnniversary() const |
150 | { | 152 | { |
151 | return mAnniversary ; | 153 | return mAnniversary ; |
152 | 154 | ||
153 | } | 155 | } |
154 | 156 | ||
155 | bool Incidence::hasRecurrenceID() const | 157 | bool Incidence::hasRecurrenceID() const |
156 | { | 158 | { |
157 | return mHasRecurrenceID; | 159 | return mHasRecurrenceID; |
158 | } | 160 | } |
159 | 161 | ||
160 | void Incidence::setHasRecurrenceID( bool b ) | 162 | void Incidence::setHasRecurrenceID( bool b ) |
161 | { | 163 | { |
162 | mHasRecurrenceID = b; | 164 | mHasRecurrenceID = b; |
163 | } | 165 | } |
164 | 166 | ||
165 | void Incidence::setRecurrenceID(QDateTime d) | 167 | void Incidence::setRecurrenceID(QDateTime d) |
166 | { | 168 | { |
167 | mRecurrenceID = d; | 169 | mRecurrenceID = d; |
168 | mHasRecurrenceID = true; | 170 | mHasRecurrenceID = true; |
169 | updated(); | 171 | updated(); |
170 | } | 172 | } |
171 | QDateTime Incidence::recurrenceID () const | 173 | QDateTime Incidence::recurrenceID () const |
172 | { | 174 | { |
173 | return mRecurrenceID; | 175 | return mRecurrenceID; |
174 | } | 176 | } |
175 | 177 | ||
176 | bool Incidence::cancelled() const | 178 | bool Incidence::cancelled() const |
177 | { | 179 | { |
178 | return mCancelled; | 180 | return mCancelled; |
179 | } | 181 | } |
180 | void Incidence::setCancelled( bool b ) | 182 | void Incidence::setCancelled( bool b ) |
181 | { | 183 | { |
182 | mCancelled = b; | 184 | mCancelled = b; |
183 | updated(); | 185 | updated(); |
184 | } | 186 | } |
185 | bool Incidence::hasStartDate() const | 187 | bool Incidence::hasStartDate() const |
186 | { | 188 | { |
187 | return mHasStartDate; | 189 | return mHasStartDate; |
188 | } | 190 | } |
189 | 191 | ||
190 | void Incidence::setHasStartDate(bool f) | 192 | void Incidence::setHasStartDate(bool f) |
191 | { | 193 | { |
192 | if (mReadOnly) return; | 194 | if (mReadOnly) return; |
193 | mHasStartDate = f; | 195 | mHasStartDate = f; |
194 | updated(); | 196 | updated(); |
195 | } | 197 | } |
196 | 198 | ||
197 | // A string comparison that considers that null and empty are the same | 199 | // A string comparison that considers that null and empty are the same |
198 | static bool stringCompare( const QString& s1, const QString& s2 ) | 200 | static bool stringCompare( const QString& s1, const QString& s2 ) |
199 | { | 201 | { |
200 | if ( s1.isEmpty() && s2.isEmpty() ) | 202 | if ( s1.isEmpty() && s2.isEmpty() ) |
201 | return true; | 203 | return true; |
202 | return s1 == s2; | 204 | return s1 == s2; |
203 | } | 205 | } |
204 | 206 | ||
205 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 207 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
206 | { | 208 | { |
207 | 209 | ||
208 | if( i1.alarms().count() != i2.alarms().count() ) { | 210 | if( i1.alarms().count() != i2.alarms().count() ) { |
209 | return false; // no need to check further | 211 | return false; // no need to check further |
210 | } | 212 | } |
211 | if ( i1.alarms().count() > 0 ) { | 213 | if ( i1.alarms().count() > 0 ) { |
212 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 214 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
213 | { | 215 | { |
214 | qDebug("alarm not equal "); | 216 | qDebug("alarm not equal "); |
215 | return false; | 217 | return false; |
216 | } | 218 | } |
217 | } | 219 | } |
218 | #if 0 | 220 | #if 0 |
219 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 221 | Q3PtrListIterator<Alarm> a1( i1.alarms() ); |
220 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 222 | Q3PtrListIterator<Alarm> a2( i2.alarms() ); |
221 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 223 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
222 | if( *a1.current() == *a2.current() ) { | 224 | if( *a1.current() == *a2.current() ) { |
223 | continue; | 225 | continue; |
224 | } | 226 | } |
225 | else { | 227 | else { |
226 | return false; | 228 | return false; |
227 | } | 229 | } |
228 | } | 230 | } |
229 | #endif | 231 | #endif |
230 | 232 | ||
231 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 233 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
232 | if ( i1.hasRecurrenceID() ) { | 234 | if ( i1.hasRecurrenceID() ) { |
233 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 235 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
234 | return false; | 236 | return false; |
235 | } | 237 | } |
236 | 238 | ||
237 | } else { | 239 | } else { |
238 | return false; | 240 | return false; |
239 | } | 241 | } |
240 | 242 | ||
241 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 243 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
242 | return false; | 244 | return false; |
243 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 245 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
244 | if ( i1.hasStartDate() ) { | 246 | if ( i1.hasStartDate() ) { |
245 | if ( i1.dtStart() != i2.dtStart() ) | 247 | if ( i1.dtStart() != i2.dtStart() ) |
246 | return false; | 248 | return false; |
247 | } | 249 | } |
248 | } else { | 250 | } else { |
249 | return false; | 251 | return false; |
250 | } | 252 | } |
251 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { | 253 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { |
252 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { | 254 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { |
253 | //qDebug("recurrence is NOT equal "); | 255 | //qDebug("recurrence is NOT equal "); |
254 | return false; | 256 | return false; |
255 | } | 257 | } |
256 | } else { | 258 | } else { |
257 | // one ( or both ) recurrence is 0 | 259 | // one ( or both ) recurrence is 0 |
258 | if ( i1.mRecurrence == 0 ) { | 260 | if ( i1.mRecurrence == 0 ) { |
259 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) | 261 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) |
260 | return false; | 262 | return false; |
261 | } else { | 263 | } else { |
262 | // i1.mRecurrence != 0 | 264 | // i1.mRecurrence != 0 |
263 | // i2.mRecurrence == 0 | 265 | // i2.mRecurrence == 0 |
264 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) | 266 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) |
265 | return false; | 267 | return false; |
266 | } | 268 | } |
267 | } | 269 | } |
268 | 270 | ||
269 | return | 271 | return |
270 | // i1.created() == i2.created() && | 272 | // i1.created() == i2.created() && |
271 | stringCompare( i1.description(), i2.description() ) && | 273 | stringCompare( i1.description(), i2.description() ) && |
272 | stringCompare( i1.summary(), i2.summary() ) && | 274 | stringCompare( i1.summary(), i2.summary() ) && |
273 | i1.categories() == i2.categories() && | 275 | i1.categories() == i2.categories() && |
274 | // no need to compare mRelatedTo | 276 | // no need to compare mRelatedTo |
275 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 277 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
276 | // i1.relations() == i2.relations() && | 278 | // i1.relations() == i2.relations() && |
277 | i1.exDates() == i2.exDates() && | 279 | i1.exDates() == i2.exDates() && |
278 | i1.attachments() == i2.attachments() && | 280 | i1.attachments() == i2.attachments() && |
279 | i1.resources() == i2.resources() && | 281 | i1.resources() == i2.resources() && |
280 | i1.secrecy() == i2.secrecy() && | 282 | i1.secrecy() == i2.secrecy() && |
281 | i1.priority() == i2.priority() && | 283 | i1.priority() == i2.priority() && |
282 | i1.cancelled() == i2.cancelled() && | 284 | i1.cancelled() == i2.cancelled() && |
283 | stringCompare( i1.location(), i2.location() ); | 285 | stringCompare( i1.location(), i2.location() ); |
284 | } | 286 | } |
285 | 287 | ||
286 | Incidence* Incidence::recreateCloneException( QDate d ) | 288 | Incidence* Incidence::recreateCloneException( QDate d ) |
287 | { | 289 | { |
288 | Incidence* newInc = clone(); | 290 | Incidence* newInc = clone(); |
289 | newInc->recreate(); | 291 | newInc->recreate(); |
290 | if ( doesRecur() ) { | 292 | if ( doesRecur() ) { |
291 | addExDate( d ); | 293 | addExDate( d ); |
292 | newInc->recurrence()->unsetRecurs(); | 294 | newInc->recurrence()->unsetRecurs(); |
293 | if ( typeID() == eventID ) { | 295 | if ( typeID() == eventID ) { |
294 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 296 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
295 | QTime tim = dtStart().time(); | 297 | QTime tim = dtStart().time(); |
296 | newInc->setDtStart( QDateTime(d, tim) ); | 298 | newInc->setDtStart( QDateTime(d, tim) ); |
297 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 299 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
298 | } else { | 300 | } else { |
299 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 301 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
300 | QTime tim = ((Todo*)this)->dtDue().time(); | 302 | QTime tim = ((Todo*)this)->dtDue().time(); |
301 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 303 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
302 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 304 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
303 | ((Todo*)this)->setRecurDates(); | 305 | ((Todo*)this)->setRecurDates(); |
304 | } | 306 | } |
305 | newInc->setExDates( DateList () ); | 307 | newInc->setExDates( DateList () ); |
306 | } | 308 | } |
307 | return newInc; | 309 | return newInc; |
308 | } | 310 | } |
309 | 311 | ||
310 | void Incidence::recreate() | 312 | void Incidence::recreate() |
311 | { | 313 | { |
312 | setCreated(QDateTime::currentDateTime()); | 314 | setCreated(QDateTime::currentDateTime()); |
313 | 315 | ||
314 | setUid(CalFormat::createUniqueId()); | 316 | setUid(CalFormat::createUniqueId()); |
315 | 317 | ||
316 | setRevision(0); | 318 | setRevision(0); |
317 | setIDStr( ":" ); | 319 | setIDStr( ":" ); |
318 | setLastModified(QDateTime::currentDateTime()); | 320 | setLastModified(QDateTime::currentDateTime()); |
319 | } | 321 | } |
320 | void Incidence::cloneRelations( Incidence * newInc ) | 322 | void Incidence::cloneRelations( Incidence * newInc ) |
321 | { | 323 | { |
322 | // newInc is already a clone of this incidence | 324 | // newInc is already a clone of this incidence |
323 | Incidence * inc; | 325 | Incidence * inc; |
324 | Incidence * cloneInc; | 326 | Incidence * cloneInc; |
325 | QPtrList<Incidence> Relations = relations(); | 327 | Q3PtrList<Incidence> Relations = relations(); |
326 | for (inc=Relations.first();inc;inc=Relations.next()) { | 328 | for (inc=Relations.first();inc;inc=Relations.next()) { |
327 | cloneInc = inc->clone(); | 329 | cloneInc = inc->clone(); |
328 | cloneInc->recreate(); | 330 | cloneInc->recreate(); |
329 | cloneInc->setRelatedTo( newInc ); | 331 | cloneInc->setRelatedTo( newInc ); |
330 | inc->cloneRelations( cloneInc ); | 332 | inc->cloneRelations( cloneInc ); |
331 | } | 333 | } |
332 | } | 334 | } |
333 | void Incidence::setReadOnly( bool readOnly ) | 335 | void Incidence::setReadOnly( bool readOnly ) |
334 | { | 336 | { |
335 | IncidenceBase::setReadOnly( readOnly ); | 337 | IncidenceBase::setReadOnly( readOnly ); |
336 | if ( mRecurrence ) | 338 | if ( mRecurrence ) |
337 | mRecurrence->setRecurReadOnly( readOnly); | 339 | mRecurrence->setRecurReadOnly( readOnly); |
338 | } | 340 | } |
339 | void Incidence::setLastModifiedSubInvalid() | 341 | void Incidence::setLastModifiedSubInvalid() |
340 | { | 342 | { |
341 | mLastModifiedSub = QDateTime(); | 343 | mLastModifiedSub = QDateTime(); |
342 | if ( mRelatedTo ) | 344 | if ( mRelatedTo ) |
343 | mRelatedTo->setLastModifiedSubInvalid(); | 345 | mRelatedTo->setLastModifiedSubInvalid(); |
344 | } | 346 | } |
345 | QString Incidence::lastModifiedSubSortKey() const | 347 | QString Incidence::lastModifiedSubSortKey() const |
346 | { | 348 | { |
347 | if ( mLastModifiedSubSortKey.isEmpty() ) | 349 | if ( mLastModifiedSubSortKey.isEmpty() ) |
348 | return lastModifiedSortKey(); | 350 | return lastModifiedSortKey(); |
349 | return mLastModifiedSubSortKey; | 351 | return mLastModifiedSubSortKey; |
350 | } | 352 | } |
351 | QDateTime Incidence::lastModifiedSub() | 353 | QDateTime Incidence::lastModifiedSub() |
352 | { | 354 | { |
353 | if ( !mRelations.count() ) | 355 | if ( !mRelations.count() ) |
354 | return lastModified(); | 356 | return lastModified(); |
355 | if ( mLastModifiedSub.isValid() ) | 357 | if ( mLastModifiedSub.isValid() ) |
356 | return mLastModifiedSub; | 358 | return mLastModifiedSub; |
357 | mLastModifiedSub = lastModified(); | 359 | mLastModifiedSub = lastModified(); |
358 | Incidence * inc; | 360 | Incidence * inc; |
359 | QPtrList<Incidence> Relations = relations(); | 361 | Q3PtrList<Incidence> Relations = relations(); |
360 | for (inc=Relations.first();inc;inc=Relations.next()) { | 362 | for (inc=Relations.first();inc;inc=Relations.next()) { |
361 | if ( inc->lastModifiedSub() > mLastModifiedSub ) | 363 | if ( inc->lastModifiedSub() > mLastModifiedSub ) |
362 | mLastModifiedSub = inc->lastModifiedSub(); | 364 | mLastModifiedSub = inc->lastModifiedSub(); |
363 | } | 365 | } |
364 | mLastModifiedSubSortKey.sprintf("%04d%02d%02d%02d%02d%02d", | 366 | mLastModifiedSubSortKey.sprintf("%04d%02d%02d%02d%02d%02d", |
365 | mLastModifiedSub.date().year(), | 367 | mLastModifiedSub.date().year(), |
366 | mLastModifiedSub.date().month(), | 368 | mLastModifiedSub.date().month(), |
367 | mLastModifiedSub.date().day(), | 369 | mLastModifiedSub.date().day(), |
368 | mLastModifiedSub.time().hour(), | 370 | mLastModifiedSub.time().hour(), |
369 | mLastModifiedSub.time().minute(), | 371 | mLastModifiedSub.time().minute(), |
370 | mLastModifiedSub.time().second() ); | 372 | mLastModifiedSub.time().second() ); |
371 | return mLastModifiedSub; | 373 | return mLastModifiedSub; |
372 | } | 374 | } |
373 | void Incidence::setCreated(QDateTime created) | 375 | void Incidence::setCreated(QDateTime created) |
374 | { | 376 | { |
375 | if (mReadOnly) return; | 377 | if (mReadOnly) return; |
376 | mCreated = getEvenTime(created); | 378 | mCreated = getEvenTime(created); |
377 | } | 379 | } |
378 | 380 | ||
379 | QDateTime Incidence::created() const | 381 | QDateTime Incidence::created() const |
380 | { | 382 | { |
381 | return mCreated; | 383 | return mCreated; |
382 | } | 384 | } |
383 | 385 | ||
384 | void Incidence::setRevision(int rev) | 386 | void Incidence::setRevision(int rev) |
385 | { | 387 | { |
386 | if (mReadOnly) return; | 388 | if (mReadOnly) return; |
387 | mRevision = rev; | 389 | mRevision = rev; |
388 | 390 | ||
389 | updated(); | 391 | updated(); |
390 | } | 392 | } |
391 | 393 | ||
392 | int Incidence::revision() const | 394 | int Incidence::revision() const |
393 | { | 395 | { |
394 | return mRevision; | 396 | return mRevision; |
395 | } | 397 | } |
396 | 398 | ||
397 | void Incidence::setDtStart(const QDateTime &dtStart) | 399 | void Incidence::setDtStart(const QDateTime &dtStart) |
398 | { | 400 | { |
399 | 401 | ||
400 | QDateTime dt = getEvenTime(dtStart); | 402 | QDateTime dt = getEvenTime(dtStart); |
401 | 403 | ||
402 | if ( mRecurrence ) | 404 | if ( mRecurrence ) |
403 | mRecurrence->setRecurStart( dt); | 405 | mRecurrence->setRecurStart( dt); |
404 | IncidenceBase::setDtStart( dt ); | 406 | IncidenceBase::setDtStart( dt ); |
405 | } | 407 | } |
406 | 408 | ||
407 | void Incidence::setDescription(const QString &description) | 409 | void Incidence::setDescription(const QString &description) |
408 | { | 410 | { |
409 | if (mReadOnly) return; | 411 | if (mReadOnly) return; |
410 | mDescription = description; | 412 | mDescription = description; |
411 | updated(); | 413 | updated(); |
412 | } | 414 | } |
413 | 415 | ||
414 | QString Incidence::description() const | 416 | QString Incidence::description() const |
415 | { | 417 | { |
416 | return mDescription; | 418 | return mDescription; |
417 | } | 419 | } |
418 | 420 | ||
419 | 421 | ||
420 | void Incidence::setSummary(const QString &summary) | 422 | void Incidence::setSummary(const QString &summary) |
421 | { | 423 | { |
422 | if (mReadOnly) return; | 424 | if (mReadOnly) return; |
423 | mSummary = summary; | 425 | mSummary = summary; |
424 | updated(); | 426 | updated(); |
425 | } | 427 | } |
426 | 428 | ||
427 | QString Incidence::summary() const | 429 | QString Incidence::summary() const |
428 | { | 430 | { |
429 | return mSummary; | 431 | return mSummary; |
430 | } | 432 | } |
431 | void Incidence::checkCategories() | 433 | void Incidence::checkCategories() |
432 | { | 434 | { |
433 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); | 435 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); |
434 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); | 436 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); |
435 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); | 437 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); |
436 | } | 438 | } |
437 | 439 | ||
438 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false | 440 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false |
439 | { | 441 | { |
440 | if (mReadOnly) return; | 442 | if (mReadOnly) return; |
441 | int i; | 443 | int i; |
442 | for( i = 0; i < categories.count(); ++i ) { | 444 | for( i = 0; i < categories.count(); ++i ) { |
443 | if ( !mCategories.contains (categories[i])) | 445 | if ( !mCategories.contains (categories[i])) |
444 | mCategories.append( categories[i] ); | 446 | mCategories.append( categories[i] ); |
445 | } | 447 | } |
446 | checkCategories(); | 448 | checkCategories(); |
447 | updated(); | 449 | updated(); |
448 | if ( addToRelations ) { | 450 | if ( addToRelations ) { |
449 | Incidence * inc; | 451 | Incidence * inc; |
450 | QPtrList<Incidence> Relations = relations(); | 452 | Q3PtrList<Incidence> Relations = relations(); |
451 | for (inc=Relations.first();inc;inc=Relations.next()) { | 453 | for (inc=Relations.first();inc;inc=Relations.next()) { |
452 | inc->addCategories( categories, true ); | 454 | inc->addCategories( categories, true ); |
453 | } | 455 | } |
454 | } | 456 | } |
455 | } | 457 | } |
456 | 458 | ||
457 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false | 459 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false |
458 | { | 460 | { |
459 | if (mReadOnly) return; | 461 | if (mReadOnly) return; |
460 | mCategories = categories; | 462 | mCategories = categories; |
461 | checkCategories(); | 463 | checkCategories(); |
462 | updated(); | 464 | updated(); |
463 | if ( setForRelations ) { | 465 | if ( setForRelations ) { |
464 | Incidence * inc; | 466 | Incidence * inc; |
465 | QPtrList<Incidence> Relations = relations(); | 467 | Q3PtrList<Incidence> Relations = relations(); |
466 | for (inc=Relations.first();inc;inc=Relations.next()) { | 468 | for (inc=Relations.first();inc;inc=Relations.next()) { |
467 | inc->setCategories( categories, true ); | 469 | inc->setCategories( categories, true ); |
468 | } | 470 | } |
469 | } | 471 | } |
470 | } | 472 | } |
471 | 473 | ||
472 | // TODO: remove setCategories(QString) function | 474 | // TODO: remove setCategories(QString) function |
473 | void Incidence::setCategories(const QString &catStr) | 475 | void Incidence::setCategories(const QString &catStr) |
474 | { | 476 | { |
475 | if (mReadOnly) return; | 477 | if (mReadOnly) return; |
476 | mCategories.clear(); | 478 | mCategories.clear(); |
477 | 479 | ||
478 | if (catStr.isEmpty()) return; | 480 | if (catStr.isEmpty()) return; |
479 | 481 | ||
480 | mCategories = QStringList::split(",",catStr); | 482 | mCategories = QStringList::split(",",catStr); |
481 | 483 | ||
482 | QStringList::Iterator it; | 484 | QStringList::Iterator it; |
483 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 485 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
484 | *it = (*it).stripWhiteSpace(); | 486 | *it = (*it).stripWhiteSpace(); |
485 | } | 487 | } |
486 | checkCategories(); | 488 | checkCategories(); |
487 | updated(); | 489 | updated(); |
488 | } | 490 | } |
489 | // using this makes filtering 3 times faster | 491 | // using this makes filtering 3 times faster |
490 | QStringList* Incidence::categoriesP() | 492 | QStringList* Incidence::categoriesP() |
491 | { | 493 | { |
492 | return &mCategories; | 494 | return &mCategories; |
493 | } | 495 | } |
494 | 496 | ||
495 | QStringList Incidence::categories() const | 497 | QStringList Incidence::categories() const |
496 | { | 498 | { |
497 | return mCategories; | 499 | return mCategories; |
498 | } | 500 | } |
499 | 501 | ||
500 | QString Incidence::categoriesStr() | 502 | QString Incidence::categoriesStr() |
501 | { | 503 | { |
502 | return mCategories.join(","); | 504 | return mCategories.join(","); |
503 | } | 505 | } |
504 | QString Incidence::categoriesStrWithSpace() | 506 | QString Incidence::categoriesStrWithSpace() |
505 | { | 507 | { |
506 | return mCategories.join(", "); | 508 | return mCategories.join(", "); |
507 | } | 509 | } |
508 | 510 | ||
509 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 511 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
510 | { | 512 | { |
511 | if (mReadOnly) return; | 513 | if (mReadOnly) return; |
512 | mRelatedToUid = relatedToUid; | 514 | mRelatedToUid = relatedToUid; |
513 | } | 515 | } |
514 | void Incidence::clearRelations() | 516 | void Incidence::clearRelations() |
515 | { | 517 | { |
516 | mRelatedTo = 0; | 518 | mRelatedTo = 0; |
517 | mRelations.clear(); | 519 | mRelations.clear(); |
518 | } | 520 | } |
519 | QString Incidence::relatedToUid() const | 521 | QString Incidence::relatedToUid() const |
520 | { | 522 | { |
521 | return mRelatedToUid; | 523 | return mRelatedToUid; |
522 | } | 524 | } |
523 | void Incidence::resetRelatedTo() | 525 | void Incidence::resetRelatedTo() |
524 | { | 526 | { |
525 | QString store = mRelatedToUid; | 527 | QString store = mRelatedToUid; |
526 | setRelatedTo( 0 ); | 528 | setRelatedTo( 0 ); |
527 | mRelatedToUid = store; | 529 | mRelatedToUid = store; |
528 | } | 530 | } |
529 | 531 | ||
530 | void Incidence::setRelatedTo(Incidence *relatedTo) | 532 | void Incidence::setRelatedTo(Incidence *relatedTo) |
531 | { | 533 | { |
532 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 534 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
533 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 535 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
534 | if (mReadOnly || mRelatedTo == relatedTo) return; | 536 | if (mReadOnly || mRelatedTo == relatedTo) return; |
535 | if(mRelatedTo) { | 537 | if(mRelatedTo) { |
536 | // updated(); | 538 | // updated(); |
537 | mRelatedTo->removeRelation(this); | 539 | mRelatedTo->removeRelation(this); |
538 | } | 540 | } |
539 | mRelatedTo = relatedTo; | 541 | mRelatedTo = relatedTo; |
540 | if (mRelatedTo) { | 542 | if (mRelatedTo) { |
541 | mRelatedTo->addRelation(this); | 543 | mRelatedTo->addRelation(this); |
542 | mRelatedToUid = mRelatedTo->uid(); | 544 | mRelatedToUid = mRelatedTo->uid(); |
543 | } else { | 545 | } else { |
544 | mRelatedToUid = ""; | 546 | mRelatedToUid = ""; |
545 | } | 547 | } |
546 | } | 548 | } |
547 | 549 | ||
548 | Incidence *Incidence::relatedTo() const | 550 | Incidence *Incidence::relatedTo() const |
549 | { | 551 | { |
550 | return mRelatedTo; | 552 | return mRelatedTo; |
551 | } | 553 | } |
552 | 554 | ||
553 | QPtrList<Incidence> Incidence::relations() const | 555 | Q3PtrList<Incidence> Incidence::relations() const |
554 | { | 556 | { |
555 | return mRelations; | 557 | return mRelations; |
556 | } | 558 | } |
557 | 559 | ||
558 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) | 560 | void Incidence::addRelationsToList(Q3PtrList<Incidence> *rel) |
559 | { | 561 | { |
560 | Incidence* inc; | 562 | Incidence* inc; |
561 | QPtrList<Incidence> Relations = relations(); | 563 | Q3PtrList<Incidence> Relations = relations(); |
562 | for (inc=Relations.first();inc;inc=Relations.next()) { | 564 | for (inc=Relations.first();inc;inc=Relations.next()) { |
563 | inc->addRelationsToList( rel ); | 565 | inc->addRelationsToList( rel ); |
564 | } | 566 | } |
565 | if ( rel->findRef( this ) == -1 ) | 567 | if ( rel->findRef( this ) == -1 ) |
566 | rel->append( this ); | 568 | rel->append( this ); |
567 | } | 569 | } |
568 | 570 | ||
569 | void Incidence::addRelation(Incidence *event) | 571 | void Incidence::addRelation(Incidence *event) |
570 | { | 572 | { |
571 | setLastModifiedSubInvalid(); | 573 | setLastModifiedSubInvalid(); |
572 | if( mRelations.findRef( event ) == -1 ) { | 574 | if( mRelations.findRef( event ) == -1 ) { |
573 | mRelations.append(event); | 575 | mRelations.append(event); |
574 | //updated(); | 576 | //updated(); |
575 | } | 577 | } |
576 | } | 578 | } |
577 | 579 | ||
578 | void Incidence::removeRelation(Incidence *event) | 580 | void Incidence::removeRelation(Incidence *event) |
579 | { | 581 | { |
580 | setLastModifiedSubInvalid(); | 582 | setLastModifiedSubInvalid(); |
581 | mRelations.removeRef(event); | 583 | mRelations.removeRef(event); |
582 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 584 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
583 | } | 585 | } |
584 | 586 | ||
585 | bool Incidence::recursOn(const QDate &qd) const | 587 | bool Incidence::recursOn(const QDate &qd) const |
586 | { | 588 | { |
587 | if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; | 589 | if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; |
588 | else return false; | 590 | else return false; |
589 | } | 591 | } |
590 | 592 | ||
591 | void Incidence::setExDates(const DateList &exDates) | 593 | void Incidence::setExDates(const DateList &exDates) |
592 | { | 594 | { |
593 | if (mReadOnly) return; | 595 | if (mReadOnly) return; |
594 | mExDates = exDates; | 596 | mExDates = exDates; |
595 | recurrence()->setRecurExDatesCount(mExDates.count()); | 597 | recurrence()->setRecurExDatesCount(mExDates.count()); |
596 | 598 | ||
597 | updated(); | 599 | updated(); |
598 | } | 600 | } |
599 | 601 | ||
600 | void Incidence::addExDate(const QDate &date) | 602 | void Incidence::addExDate(const QDate &date) |
601 | { | 603 | { |
602 | if (mReadOnly) return; | 604 | if (mReadOnly) return; |
603 | mExDates.append(date); | 605 | mExDates.append(date); |
604 | 606 | ||
605 | recurrence()->setRecurExDatesCount(mExDates.count()); | 607 | recurrence()->setRecurExDatesCount(mExDates.count()); |
606 | 608 | ||
607 | updated(); | 609 | updated(); |
608 | } | 610 | } |
609 | 611 | ||
610 | DateList Incidence::exDates() const | 612 | DateList Incidence::exDates() const |
611 | { | 613 | { |
612 | return mExDates; | 614 | return mExDates; |
613 | } | 615 | } |
614 | 616 | ||
615 | bool Incidence::isException(const QDate &date) const | 617 | bool Incidence::isException(const QDate &date) const |
616 | { | 618 | { |
617 | DateList::ConstIterator it; | 619 | DateList::ConstIterator it; |
618 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 620 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
619 | if ( (*it) == date ) { | 621 | if ( (*it) == date ) { |
620 | return true; | 622 | return true; |
621 | } | 623 | } |
622 | } | 624 | } |
623 | 625 | ||
624 | return false; | 626 | return false; |
625 | } | 627 | } |
626 | 628 | ||
627 | void Incidence::addAttachment(Attachment *attachment) | 629 | void Incidence::addAttachment(Attachment *attachment) |
628 | { | 630 | { |
629 | if (mReadOnly || !attachment) return; | 631 | if (mReadOnly || !attachment) return; |
630 | mAttachments.append(attachment); | 632 | mAttachments.append(attachment); |
631 | updated(); | 633 | updated(); |
632 | } | 634 | } |
633 | 635 | ||
634 | void Incidence::deleteAttachment(Attachment *attachment) | 636 | void Incidence::deleteAttachment(Attachment *attachment) |
635 | { | 637 | { |
636 | mAttachments.removeRef(attachment); | 638 | mAttachments.removeRef(attachment); |
637 | } | 639 | } |
638 | 640 | ||
639 | void Incidence::deleteAttachments(const QString& mime) | 641 | void Incidence::deleteAttachments(const QString& mime) |
640 | { | 642 | { |
641 | Attachment *at = mAttachments.first(); | 643 | Attachment *at = mAttachments.first(); |
642 | while (at) { | 644 | while (at) { |
643 | if (at->mimeType() == mime) | 645 | if (at->mimeType() == mime) |
644 | mAttachments.remove(); | 646 | mAttachments.remove(); |
645 | else | 647 | else |
646 | at = mAttachments.next(); | 648 | at = mAttachments.next(); |
647 | } | 649 | } |
648 | } | 650 | } |
649 | 651 | ||
650 | QPtrList<Attachment> Incidence::attachments() const | 652 | Q3PtrList<Attachment> Incidence::attachments() const |
651 | { | 653 | { |
652 | return mAttachments; | 654 | return mAttachments; |
653 | } | 655 | } |
654 | 656 | ||
655 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 657 | Q3PtrList<Attachment> Incidence::attachments(const QString& mime) const |
656 | { | 658 | { |
657 | QPtrList<Attachment> attachments; | 659 | Q3PtrList<Attachment> attachments; |
658 | QPtrListIterator<Attachment> it( mAttachments ); | 660 | Q3PtrListIterator<Attachment> it( mAttachments ); |
659 | Attachment *at; | 661 | Attachment *at; |
660 | while ( (at = it.current()) ) { | 662 | while ( (at = it.current()) ) { |
661 | if (at->mimeType() == mime) | 663 | if (at->mimeType() == mime) |
662 | attachments.append(at); | 664 | attachments.append(at); |
663 | ++it; | 665 | ++it; |
664 | } | 666 | } |
665 | 667 | ||
666 | return attachments; | 668 | return attachments; |
667 | } | 669 | } |
668 | 670 | ||
669 | void Incidence::setResources(const QStringList &resources) | 671 | void Incidence::setResources(const QStringList &resources) |
670 | { | 672 | { |
671 | if (mReadOnly) return; | 673 | if (mReadOnly) return; |
672 | mResources = resources; | 674 | mResources = resources; |
673 | updated(); | 675 | updated(); |
674 | } | 676 | } |
675 | 677 | ||
676 | QStringList Incidence::resources() const | 678 | QStringList Incidence::resources() const |
677 | { | 679 | { |
678 | return mResources; | 680 | return mResources; |
679 | } | 681 | } |
680 | 682 | ||
681 | 683 | ||
682 | void Incidence::setPriority(int priority) | 684 | void Incidence::setPriority(int priority) |
683 | { | 685 | { |
684 | if (mReadOnly) return; | 686 | if (mReadOnly) return; |
685 | mPriority = priority; | 687 | mPriority = priority; |
686 | updated(); | 688 | updated(); |
687 | } | 689 | } |
688 | 690 | ||
689 | int Incidence::priority() const | 691 | int Incidence::priority() const |
690 | { | 692 | { |
691 | return mPriority; | 693 | return mPriority; |
692 | } | 694 | } |
693 | 695 | ||
694 | void Incidence::setSecrecy(int sec) | 696 | void Incidence::setSecrecy(int sec) |
695 | { | 697 | { |
696 | if (mReadOnly) return; | 698 | if (mReadOnly) return; |
697 | mSecrecy = sec; | 699 | mSecrecy = sec; |
698 | updated(); | 700 | updated(); |
699 | } | 701 | } |
700 | 702 | ||
701 | int Incidence::secrecy() const | 703 | int Incidence::secrecy() const |
702 | { | 704 | { |
703 | return mSecrecy; | 705 | return mSecrecy; |
704 | } | 706 | } |
705 | 707 | ||
706 | QString Incidence::secrecyStr() const | 708 | QString Incidence::secrecyStr() const |
707 | { | 709 | { |
708 | return secrecyName(mSecrecy); | 710 | return secrecyName(mSecrecy); |
709 | } | 711 | } |
710 | 712 | ||
711 | QString Incidence::secrecyName(int secrecy) | 713 | QString Incidence::secrecyName(int secrecy) |
712 | { | 714 | { |
713 | switch (secrecy) { | 715 | switch (secrecy) { |
714 | case SecrecyPublic: | 716 | case SecrecyPublic: |
715 | return i18n("Public"); | 717 | return i18n("Public"); |
716 | break; | 718 | break; |
717 | case SecrecyPrivate: | 719 | case SecrecyPrivate: |
718 | return i18n("Private"); | 720 | return i18n("Private"); |
719 | break; | 721 | break; |
720 | case SecrecyConfidential: | 722 | case SecrecyConfidential: |
721 | return i18n("Confidential"); | 723 | return i18n("Confidential"); |
722 | break; | 724 | break; |
723 | default: | 725 | default: |
724 | return i18n("Undefined"); | 726 | return i18n("Undefined"); |
725 | break; | 727 | break; |
726 | } | 728 | } |
727 | } | 729 | } |
728 | 730 | ||
729 | QStringList Incidence::secrecyList() | 731 | QStringList Incidence::secrecyList() |
730 | { | 732 | { |
731 | QStringList list; | 733 | QStringList list; |
732 | list << secrecyName(SecrecyPublic); | 734 | list << secrecyName(SecrecyPublic); |
733 | list << secrecyName(SecrecyPrivate); | 735 | list << secrecyName(SecrecyPrivate); |
734 | list << secrecyName(SecrecyConfidential); | 736 | list << secrecyName(SecrecyConfidential); |
735 | 737 | ||
736 | return list; | 738 | return list; |
737 | } | 739 | } |
738 | 740 | ||
739 | 741 | ||
740 | QPtrList<Alarm> Incidence::alarms() const | 742 | Q3PtrList<Alarm> Incidence::alarms() const |
741 | { | 743 | { |
742 | return mAlarms; | 744 | return mAlarms; |
743 | } | 745 | } |
744 | 746 | ||
745 | Alarm* Incidence::newAlarm() | 747 | Alarm* Incidence::newAlarm() |
746 | { | 748 | { |
747 | Alarm* alarm = new Alarm(this); | 749 | Alarm* alarm = new Alarm(this); |
748 | mAlarms.append(alarm); | 750 | mAlarms.append(alarm); |
749 | // updated(); | 751 | // updated(); |
750 | return alarm; | 752 | return alarm; |
751 | } | 753 | } |
752 | 754 | ||
753 | void Incidence::addAlarm(Alarm *alarm) | 755 | void Incidence::addAlarm(Alarm *alarm) |
754 | { | 756 | { |
755 | mAlarms.append(alarm); | 757 | mAlarms.append(alarm); |
756 | updated(); | 758 | updated(); |
757 | } | 759 | } |
758 | 760 | ||
759 | void Incidence::removeAlarm(Alarm *alarm) | 761 | void Incidence::removeAlarm(Alarm *alarm) |
760 | { | 762 | { |
761 | mAlarms.removeRef(alarm); | 763 | mAlarms.removeRef(alarm); |
762 | updated(); | 764 | updated(); |
763 | } | 765 | } |
764 | 766 | ||
765 | void Incidence::clearAlarms() | 767 | void Incidence::clearAlarms() |
766 | { | 768 | { |
767 | mAlarms.clear(); | 769 | mAlarms.clear(); |
768 | updated(); | 770 | updated(); |
769 | } | 771 | } |
770 | 772 | ||
771 | bool Incidence::isAlarmEnabled() const | 773 | bool Incidence::isAlarmEnabled() const |
772 | { | 774 | { |
773 | Alarm* alarm; | 775 | Alarm* alarm; |
774 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 776 | for (Q3PtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
775 | if (alarm->enabled()) | 777 | if (alarm->enabled()) |
776 | return true; | 778 | return true; |
777 | } | 779 | } |
778 | return false; | 780 | return false; |
779 | } | 781 | } |
780 | #include <stdlib.h> | 782 | #include <stdlib.h> |
781 | Recurrence *Incidence::recurrence() | 783 | Recurrence *Incidence::recurrence() |
782 | { | 784 | { |
783 | if ( ! mRecurrence ) { | 785 | if ( ! mRecurrence ) { |
784 | mRecurrence = new Recurrence(this); | 786 | mRecurrence = new Recurrence(this); |
785 | mRecurrence->setRecurStart( dtStart() ); | 787 | mRecurrence->setRecurStart( dtStart() ); |
786 | mRecurrence->setRecurReadOnly( isReadOnly()); | 788 | mRecurrence->setRecurReadOnly( isReadOnly()); |
787 | //qDebug("creating new recurence "); | 789 | //qDebug("creating new recurence "); |
788 | //abort(); | 790 | //abort(); |
789 | } | 791 | } |
790 | return mRecurrence; | 792 | return mRecurrence; |
791 | } | 793 | } |
792 | void Incidence::setRecurrence( Recurrence * r) | 794 | void Incidence::setRecurrence( Recurrence * r) |
793 | { | 795 | { |
794 | if ( mRecurrence ) | 796 | if ( mRecurrence ) |
795 | delete mRecurrence; | 797 | delete mRecurrence; |
796 | mRecurrence = r; | 798 | mRecurrence = r; |
797 | } | 799 | } |
798 | 800 | ||
799 | void Incidence::setLocation(const QString &location) | 801 | void Incidence::setLocation(const QString &location) |
800 | { | 802 | { |
801 | if (mReadOnly) return; | 803 | if (mReadOnly) return; |
802 | mLocation = location; | 804 | mLocation = location; |
803 | updated(); | 805 | updated(); |
804 | } | 806 | } |
805 | 807 | ||
806 | QString Incidence::location() const | 808 | QString Incidence::location() const |
807 | { | 809 | { |
808 | return mLocation; | 810 | return mLocation; |
809 | } | 811 | } |
810 | QString Incidence::recurrenceText() const | 812 | QString Incidence::recurrenceText() const |
811 | { | 813 | { |
812 | if ( mRecurrence ) return mRecurrence->recurrenceText(); | 814 | if ( mRecurrence ) return mRecurrence->recurrenceText(); |
813 | return i18n("No"); | 815 | return i18n("No"); |
814 | } | 816 | } |
815 | 817 | ||
816 | ushort Incidence::doesRecur() const | 818 | ushort Incidence::doesRecur() const |
817 | { | 819 | { |
818 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 820 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
819 | else return Recurrence::rNone; | 821 | else return Recurrence::rNone; |
820 | } | 822 | } |
821 | 823 | ||
822 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 824 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
823 | { | 825 | { |
824 | QDateTime incidenceStart = dt; | 826 | QDateTime incidenceStart = dt; |
825 | *ok = false; | 827 | *ok = false; |
826 | if ( doesRecur() ) { | 828 | if ( doesRecur() ) { |
827 | bool last; | 829 | bool last; |
828 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); | 830 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); |
829 | int count = 0; | 831 | int count = 0; |
830 | if ( !last ) { | 832 | if ( !last ) { |
831 | while ( !last ) { | 833 | while ( !last ) { |
832 | ++count; | 834 | ++count; |
833 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); | 835 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); |
834 | if ( recursOn( incidenceStart.date() ) ) { | 836 | if ( recursOn( incidenceStart.date() ) ) { |
835 | last = true; // exit while llop | 837 | last = true; // exit while llop |
836 | } else { | 838 | } else { |
837 | if ( last ) { // no alarm on last recurrence | 839 | if ( last ) { // no alarm on last recurrence |
838 | return QDateTime (); | 840 | return QDateTime (); |
839 | } | 841 | } |
840 | int year = incidenceStart.date().year(); | 842 | int year = incidenceStart.date().year(); |
841 | // workaround for bug in recurrence | 843 | // workaround for bug in recurrence |
842 | if ( count == 100 || year < 1000 || year > 5000 ) { | 844 | if ( count == 100 || year < 1000 || year > 5000 ) { |
843 | return QDateTime (); | 845 | return QDateTime (); |
844 | } | 846 | } |
845 | incidenceStart = incidenceStart.addSecs( 1 ); | 847 | incidenceStart = incidenceStart.addSecs( 1 ); |
846 | } | 848 | } |
847 | } | 849 | } |
848 | } else { | 850 | } else { |
849 | return QDateTime (); | 851 | return QDateTime (); |
850 | } | 852 | } |
851 | } else { | 853 | } else { |
852 | if ( hasStartDate () ) { | 854 | if ( hasStartDate () ) { |
853 | incidenceStart = dtStart(); | 855 | incidenceStart = dtStart(); |
854 | } | 856 | } |
855 | if ( typeID() == todoID ) { | 857 | if ( typeID() == todoID ) { |
856 | if ( ((Todo*)this)->hasDueDate() ) | 858 | if ( ((Todo*)this)->hasDueDate() ) |
857 | incidenceStart = ((Todo*)this)->dtDue(); | 859 | incidenceStart = ((Todo*)this)->dtDue(); |
858 | } | 860 | } |
859 | } | 861 | } |
860 | if ( incidenceStart > dt ) | 862 | if ( incidenceStart > dt ) |
861 | *ok = true; | 863 | *ok = true; |
862 | return incidenceStart; | 864 | return incidenceStart; |
863 | } | 865 | } |
864 | QDateTime Incidence::dtStart() const | 866 | QDateTime Incidence::dtStart() const |
865 | { | 867 | { |
866 | if ( doesRecur() ) { | 868 | if ( doesRecur() ) { |
867 | if ( typeID() == todoID ) { | 869 | if ( typeID() == todoID ) { |
868 | ((Todo*)this)->checkSetCompletedFalse(); | 870 | ((Todo*)this)->checkSetCompletedFalse(); |
869 | } | 871 | } |
870 | } | 872 | } |
871 | return mDtStart; | 873 | return mDtStart; |
872 | } | 874 | } |
diff --git a/libkcal/incidence.h b/libkcal/incidence.h index f89942f..2940129 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h | |||
@@ -1,327 +1,329 @@ | |||
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 INCIDENCE_H | 20 | #ifndef INCIDENCE_H |
21 | #define INCIDENCE_H | 21 | #define INCIDENCE_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 <q3valuelist.h> |
29 | //Added by qt3to4: | ||
30 | #include <Q3PtrList> | ||
29 | 31 | ||
30 | #include "recurrence.h" | 32 | #include "recurrence.h" |
31 | #include "alarm.h" | 33 | #include "alarm.h" |
32 | #include "attachment.h" | 34 | #include "attachment.h" |
33 | #include "listbase.h" | 35 | #include "listbase.h" |
34 | #include "incidencebase.h" | 36 | #include "incidencebase.h" |
35 | 37 | ||
36 | namespace KCal { | 38 | namespace KCal { |
37 | 39 | ||
38 | class Event; | 40 | class Event; |
39 | class Todo; | 41 | class Todo; |
40 | class Journal; | 42 | class Journal; |
41 | 43 | ||
42 | /** | 44 | /** |
43 | This class provides the base class common to all calendar components. | 45 | This class provides the base class common to all calendar components. |
44 | */ | 46 | */ |
45 | class Incidence : public IncidenceBase | 47 | class Incidence : public IncidenceBase |
46 | { | 48 | { |
47 | public: | 49 | public: |
48 | /** | 50 | /** |
49 | This class provides the interface for a visitor of calendar components. It | 51 | This class provides the interface for a visitor of calendar components. It |
50 | serves as base class for concrete visitors, which implement certain actions on | 52 | serves as base class for concrete visitors, which implement certain actions on |
51 | calendar components. It allows to add functions, which operate on the concrete | 53 | calendar components. It allows to add functions, which operate on the concrete |
52 | types of calendar components, without changing the calendar component classes. | 54 | types of calendar components, without changing the calendar component classes. |
53 | */ | 55 | */ |
54 | class Visitor | 56 | class Visitor |
55 | { | 57 | { |
56 | public: | 58 | public: |
57 | /** Destruct Incidence::Visitor */ | 59 | /** Destruct Incidence::Visitor */ |
58 | virtual ~Visitor() {} | 60 | virtual ~Visitor() {} |
59 | 61 | ||
60 | /** | 62 | /** |
61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 63 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
62 | on an Event object. | 64 | on an Event object. |
63 | */ | 65 | */ |
64 | virtual bool visit(Event *) { return false; } | 66 | virtual bool visit(Event *) { return false; } |
65 | /** | 67 | /** |
66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 68 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
67 | on an Todo object. | 69 | on an Todo object. |
68 | */ | 70 | */ |
69 | virtual bool visit(Todo *) { return false; } | 71 | virtual bool visit(Todo *) { return false; } |
70 | /** | 72 | /** |
71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 73 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
72 | on an Journal object. | 74 | on an Journal object. |
73 | */ | 75 | */ |
74 | virtual bool visit(Journal *) { return false; } | 76 | virtual bool visit(Journal *) { return false; } |
75 | 77 | ||
76 | protected: | 78 | protected: |
77 | /** Constructor is protected to prevent direct creation of visitor base class. */ | 79 | /** Constructor is protected to prevent direct creation of visitor base class. */ |
78 | Visitor() {} | 80 | Visitor() {} |
79 | }; | 81 | }; |
80 | 82 | ||
81 | /** | 83 | /** |
82 | This class implements a visitor for adding an Incidence to a resource | 84 | This class implements a visitor for adding an Incidence to a resource |
83 | supporting addEvent(), addTodo() and addJournal() calls. | 85 | supporting addEvent(), addTodo() and addJournal() calls. |
84 | */ | 86 | */ |
85 | template<class T> | 87 | template<class T> |
86 | class AddVisitor : public Visitor | 88 | class AddVisitor : public Visitor |
87 | { | 89 | { |
88 | public: | 90 | public: |
89 | AddVisitor( T *r ) : mResource( r ) {} | 91 | AddVisitor( T *r ) : mResource( r ) {} |
90 | bool visit( Event *e ) { return mResource->addEvent( e ); } | 92 | bool visit( Event *e ) { return mResource->addEvent( e ); } |
91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } | 93 | bool visit( Todo *t ) { return mResource->addTodo( t ); } |
92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } | 94 | bool visit( Journal *j ) { return mResource->addJournal( j ); } |
93 | 95 | ||
94 | private: | 96 | private: |
95 | T *mResource; | 97 | T *mResource; |
96 | }; | 98 | }; |
97 | 99 | ||
98 | /** enumeration for describing an event's secrecy. */ | 100 | /** enumeration for describing an event's secrecy. */ |
99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; | 101 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; |
100 | typedef ListBase<Incidence> List; | 102 | typedef ListBase<Incidence> List; |
101 | Incidence(); | 103 | Incidence(); |
102 | Incidence(const Incidence &); | 104 | Incidence(const Incidence &); |
103 | ~Incidence(); | 105 | ~Incidence(); |
104 | 106 | ||
105 | /** | 107 | /** |
106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to | 108 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to |
107 | provide this implementation: | 109 | provide this implementation: |
108 | <pre> | 110 | <pre> |
109 | bool accept(Visitor &v) { return v.visit(this); } | 111 | bool accept(Visitor &v) { return v.visit(this); } |
110 | </pre> | 112 | </pre> |
111 | */ | 113 | */ |
112 | virtual bool accept(Visitor &) { return false; } | 114 | virtual bool accept(Visitor &) { return false; } |
113 | 115 | ||
114 | virtual Incidence *clone() = 0; | 116 | virtual Incidence *clone() = 0; |
115 | virtual void cloneRelations( Incidence * ); | 117 | virtual void cloneRelations( Incidence * ); |
116 | void addRelationsToList(QPtrList<Incidence> *rel); | 118 | void addRelationsToList(Q3PtrList<Incidence> *rel); |
117 | void clearRelations(); | 119 | void clearRelations(); |
118 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; | 120 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; |
119 | void setReadOnly( bool ); | 121 | void setReadOnly( bool ); |
120 | 122 | ||
121 | /** | 123 | /** |
122 | Recreate event. The event is made a new unique event, but already stored | 124 | Recreate event. The event is made a new unique event, but already stored |
123 | event information is preserved. Sets uniquie id, creation date, last | 125 | event information is preserved. Sets uniquie id, creation date, last |
124 | modification date and revision number. | 126 | modification date and revision number. |
125 | */ | 127 | */ |
126 | void recreate(); | 128 | void recreate(); |
127 | Incidence* recreateCloneException(QDate); | 129 | Incidence* recreateCloneException(QDate); |
128 | 130 | ||
129 | /** set creation date */ | 131 | /** set creation date */ |
130 | void setCreated(QDateTime); | 132 | void setCreated(QDateTime); |
131 | /** return time and date of creation. */ | 133 | /** return time and date of creation. */ |
132 | QDateTime created() const; | 134 | QDateTime created() const; |
133 | 135 | ||
134 | /** set the number of revisions this event has seen */ | 136 | /** set the number of revisions this event has seen */ |
135 | void setRevision(int rev); | 137 | void setRevision(int rev); |
136 | /** return the number of revisions this event has seen */ | 138 | /** return the number of revisions this event has seen */ |
137 | int revision() const; | 139 | int revision() const; |
138 | 140 | ||
139 | /** Set starting date/time. */ | 141 | /** Set starting date/time. */ |
140 | virtual void setDtStart(const QDateTime &dtStart); | 142 | virtual void setDtStart(const QDateTime &dtStart); |
141 | /** Return the incidence's ending date/time as a QDateTime. */ | 143 | /** Return the incidence's ending date/time as a QDateTime. */ |
142 | virtual QDateTime dtEnd() const { return QDateTime(); } | 144 | virtual QDateTime dtEnd() const { return QDateTime(); } |
143 | 145 | ||
144 | /** sets the event's lengthy description. */ | 146 | /** sets the event's lengthy description. */ |
145 | void setDescription(const QString &description); | 147 | void setDescription(const QString &description); |
146 | /** returns a reference to the event's description. */ | 148 | /** returns a reference to the event's description. */ |
147 | QString description() const; | 149 | QString description() const; |
148 | 150 | ||
149 | /** sets the event's short summary. */ | 151 | /** sets the event's short summary. */ |
150 | void setSummary(const QString &summary); | 152 | void setSummary(const QString &summary); |
151 | /** returns a reference to the event's summary. */ | 153 | /** returns a reference to the event's summary. */ |
152 | QString summary() const; | 154 | QString summary() const; |
153 | 155 | ||
154 | /** set event's applicable categories */ | 156 | /** set event's applicable categories */ |
155 | void setCategories(const QStringList &categories, bool setForRelations = false); | 157 | void setCategories(const QStringList &categories, bool setForRelations = false); |
156 | void addCategories(const QStringList &categories, bool addToRelations = false); | 158 | void addCategories(const QStringList &categories, bool addToRelations = false); |
157 | /** set event's categories based on a comma delimited string */ | 159 | /** set event's categories based on a comma delimited string */ |
158 | void setCategories(const QString &catStr); | 160 | void setCategories(const QString &catStr); |
159 | /** return categories in a list */ | 161 | /** return categories in a list */ |
160 | QStringList categories() const; | 162 | QStringList categories() const; |
161 | QStringList* categoriesP(); | 163 | QStringList* categoriesP(); |
162 | /** return categories as a comma separated string */ | 164 | /** return categories as a comma separated string */ |
163 | QString categoriesStr(); | 165 | QString categoriesStr(); |
164 | QString categoriesStrWithSpace(); | 166 | QString categoriesStrWithSpace(); |
165 | 167 | ||
166 | /** point at some other event to which the event relates. This function should | 168 | /** point at some other event to which the event relates. This function should |
167 | * only be used when constructing a calendar before the related Event | 169 | * only be used when constructing a calendar before the related Event |
168 | * exists. */ | 170 | * exists. */ |
169 | void setRelatedToUid(const QString &); | 171 | void setRelatedToUid(const QString &); |
170 | /** what event does this one relate to? This function should | 172 | /** what event does this one relate to? This function should |
171 | * only be used when constructing a calendar before the related Event | 173 | * only be used when constructing a calendar before the related Event |
172 | * exists. */ | 174 | * exists. */ |
173 | QString relatedToUid() const; | 175 | QString relatedToUid() const; |
174 | /** point at some other event to which the event relates */ | 176 | /** point at some other event to which the event relates */ |
175 | void setRelatedTo(Incidence *relatedTo); | 177 | void setRelatedTo(Incidence *relatedTo); |
176 | void resetRelatedTo(); | 178 | void resetRelatedTo(); |
177 | /** what event does this one relate to? */ | 179 | /** what event does this one relate to? */ |
178 | Incidence *relatedTo() const; | 180 | Incidence *relatedTo() const; |
179 | /** All events that are related to this event */ | 181 | /** All events that are related to this event */ |
180 | QPtrList<Incidence> relations() const; | 182 | Q3PtrList<Incidence> relations() const; |
181 | /** Add an event which is related to this event */ | 183 | /** Add an event which is related to this event */ |
182 | void addRelation(Incidence *); | 184 | void addRelation(Incidence *); |
183 | /** Remove event that is related to this event */ | 185 | /** Remove event that is related to this event */ |
184 | void removeRelation(Incidence *); | 186 | void removeRelation(Incidence *); |
185 | 187 | ||
186 | /** returns the list of dates which are exceptions to the recurrence rule */ | 188 | /** returns the list of dates which are exceptions to the recurrence rule */ |
187 | DateList exDates() const; | 189 | DateList exDates() const; |
188 | /** sets the list of dates which are exceptions to the recurrence rule */ | 190 | /** sets the list of dates which are exceptions to the recurrence rule */ |
189 | void setExDates(const DateList &_exDates); | 191 | void setExDates(const DateList &_exDates); |
190 | void setExDates(const char *dates); | 192 | void setExDates(const char *dates); |
191 | /** Add a date to the list of exceptions of the recurrence rule. */ | 193 | /** Add a date to the list of exceptions of the recurrence rule. */ |
192 | void addExDate(const QDate &date); | 194 | void addExDate(const QDate &date); |
193 | 195 | ||
194 | /** returns true if there is an exception for this date in the recurrence | 196 | /** returns true if there is an exception for this date in the recurrence |
195 | rule set, or false otherwise. */ | 197 | rule set, or false otherwise. */ |
196 | bool isException(const QDate &qd) const; | 198 | bool isException(const QDate &qd) const; |
197 | 199 | ||
198 | /** add attachment to this event */ | 200 | /** add attachment to this event */ |
199 | void addAttachment(Attachment *attachment); | 201 | void addAttachment(Attachment *attachment); |
200 | /** remove and delete a specific attachment */ | 202 | /** remove and delete a specific attachment */ |
201 | void deleteAttachment(Attachment *attachment); | 203 | void deleteAttachment(Attachment *attachment); |
202 | /** remove and delete all attachments with this mime type */ | 204 | /** remove and delete all attachments with this mime type */ |
203 | void deleteAttachments(const QString& mime); | 205 | void deleteAttachments(const QString& mime); |
204 | /** return list of all associated attachments */ | 206 | /** return list of all associated attachments */ |
205 | QPtrList<Attachment> attachments() const; | 207 | Q3PtrList<Attachment> attachments() const; |
206 | /** find a list of attachments with this mime type */ | 208 | /** find a list of attachments with this mime type */ |
207 | QPtrList<Attachment> attachments(const QString& mime) const; | 209 | Q3PtrList<Attachment> attachments(const QString& mime) const; |
208 | 210 | ||
209 | /** sets the event's status the value specified. See the enumeration | 211 | /** sets the event's status the value specified. See the enumeration |
210 | * above for possible values. */ | 212 | * above for possible values. */ |
211 | void setSecrecy(int); | 213 | void setSecrecy(int); |
212 | /** return the event's secrecy. */ | 214 | /** return the event's secrecy. */ |
213 | int secrecy() const; | 215 | int secrecy() const; |
214 | /** return the event's secrecy in string format. */ | 216 | /** return the event's secrecy in string format. */ |
215 | QString secrecyStr() const; | 217 | QString secrecyStr() const; |
216 | /** return list of all availbale secrecy classes */ | 218 | /** return list of all availbale secrecy classes */ |
217 | static QStringList secrecyList(); | 219 | static QStringList secrecyList(); |
218 | /** return human-readable name of secrecy class */ | 220 | /** return human-readable name of secrecy class */ |
219 | static QString secrecyName(int); | 221 | static QString secrecyName(int); |
220 | 222 | ||
221 | /** returns TRUE if the date specified is one on which the event will | 223 | /** returns TRUE if the date specified is one on which the event will |
222 | * recur. */ | 224 | * recur. */ |
223 | bool recursOn(const QDate &qd) const; | 225 | bool recursOn(const QDate &qd) const; |
224 | 226 | ||
225 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): | 227 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): |
226 | 228 | ||
227 | /** set resources used, such as Office, Car, etc. */ | 229 | /** set resources used, such as Office, Car, etc. */ |
228 | void setResources(const QStringList &resources); | 230 | void setResources(const QStringList &resources); |
229 | /** return list of current resources */ | 231 | /** return list of current resources */ |
230 | QStringList resources() const; | 232 | QStringList resources() const; |
231 | 233 | ||
232 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ | 234 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ |
233 | void setPriority(int priority); | 235 | void setPriority(int priority); |
234 | /** get the event's priority */ | 236 | /** get the event's priority */ |
235 | int priority() const; | 237 | int priority() const; |
236 | 238 | ||
237 | /** All alarms that are associated with this incidence */ | 239 | /** All alarms that are associated with this incidence */ |
238 | QPtrList<Alarm> alarms() const; | 240 | Q3PtrList<Alarm> alarms() const; |
239 | /** Create a new alarm which is associated with this incidence */ | 241 | /** Create a new alarm which is associated with this incidence */ |
240 | Alarm* newAlarm(); | 242 | Alarm* newAlarm(); |
241 | /** Add an alarm which is associated with this incidence */ | 243 | /** Add an alarm which is associated with this incidence */ |
242 | void addAlarm(Alarm*); | 244 | void addAlarm(Alarm*); |
243 | /** Remove an alarm that is associated with this incidence */ | 245 | /** Remove an alarm that is associated with this incidence */ |
244 | void removeAlarm(Alarm*); | 246 | void removeAlarm(Alarm*); |
245 | /** Remove all alarms that are associated with this incidence */ | 247 | /** Remove all alarms that are associated with this incidence */ |
246 | void clearAlarms(); | 248 | void clearAlarms(); |
247 | /** return whether any alarm associated with this incidence is enabled */ | 249 | /** return whether any alarm associated with this incidence is enabled */ |
248 | bool isAlarmEnabled() const; | 250 | bool isAlarmEnabled() const; |
249 | 251 | ||
250 | /** | 252 | /** |
251 | Return the recurrence rule associated with this incidence. If there is | 253 | Return the recurrence rule associated with this incidence. If there is |
252 | none, returns an appropriate (non-0) object. | 254 | none, returns an appropriate (non-0) object. |
253 | */ | 255 | */ |
254 | Recurrence *recurrence(); | 256 | Recurrence *recurrence(); |
255 | void setRecurrence(Recurrence * r); | 257 | void setRecurrence(Recurrence * r); |
256 | /** | 258 | /** |
257 | Forward to Recurrence::doesRecur(). | 259 | Forward to Recurrence::doesRecur(). |
258 | */ | 260 | */ |
259 | ushort doesRecur() const; | 261 | ushort doesRecur() const; |
260 | 262 | ||
261 | /** set the event's/todo's location. Do _not_ use it with journal */ | 263 | /** set the event's/todo's location. Do _not_ use it with journal */ |
262 | void setLocation(const QString &location); | 264 | void setLocation(const QString &location); |
263 | /** return the event's/todo's location. Do _not_ use it with journal */ | 265 | /** return the event's/todo's location. Do _not_ use it with journal */ |
264 | QString location() const; | 266 | QString location() const; |
265 | /** returns TRUE or FALSE depending on whether the todo has a start date */ | 267 | /** returns TRUE or FALSE depending on whether the todo has a start date */ |
266 | bool hasStartDate() const; | 268 | bool hasStartDate() const; |
267 | /** sets the event's hasStartDate value. */ | 269 | /** sets the event's hasStartDate value. */ |
268 | void setHasStartDate(bool f); | 270 | void setHasStartDate(bool f); |
269 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; | 271 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; |
270 | bool cancelled() const; | 272 | bool cancelled() const; |
271 | void setCancelled( bool b ); | 273 | void setCancelled( bool b ); |
272 | 274 | ||
273 | bool hasRecurrenceID() const; | 275 | bool hasRecurrenceID() const; |
274 | void setHasRecurrenceID( bool b ); | 276 | void setHasRecurrenceID( bool b ); |
275 | 277 | ||
276 | void setRecurrenceID(QDateTime); | 278 | void setRecurrenceID(QDateTime); |
277 | QDateTime recurrenceID () const; | 279 | QDateTime recurrenceID () const; |
278 | QDateTime dtStart() const; | 280 | QDateTime dtStart() const; |
279 | bool isHoliday() const; | 281 | bool isHoliday() const; |
280 | bool isBirthday() const; | 282 | bool isBirthday() const; |
281 | bool isAnniversary() const; | 283 | bool isAnniversary() const; |
282 | QDateTime lastModifiedSub(); | 284 | QDateTime lastModifiedSub(); |
283 | QString lastModifiedSubSortKey() const; | 285 | QString lastModifiedSubSortKey() const; |
284 | QString recurrenceText() const; | 286 | QString recurrenceText() const; |
285 | void setLastModifiedSubInvalid(); | 287 | void setLastModifiedSubInvalid(); |
286 | 288 | ||
287 | virtual QString durationText(); | 289 | virtual QString durationText(); |
288 | QString durationText4Time( int secs ); | 290 | QString durationText4Time( int secs ); |
289 | Recurrence *mRecurrence; | 291 | Recurrence *mRecurrence; |
290 | protected: | 292 | protected: |
291 | QPtrList<Alarm> mAlarms; | 293 | Q3PtrList<Alarm> mAlarms; |
292 | QPtrList<Incidence> mRelations; | 294 | Q3PtrList<Incidence> mRelations; |
293 | QDateTime mRecurrenceID; | 295 | QDateTime mRecurrenceID; |
294 | bool mHasRecurrenceID; | 296 | bool mHasRecurrenceID; |
295 | private: | 297 | private: |
296 | void checkCategories(); | 298 | void checkCategories(); |
297 | QString mLastModifiedSubSortKey; | 299 | QString mLastModifiedSubSortKey; |
298 | bool mHoliday, mBirthday, mAnniversary; | 300 | bool mHoliday, mBirthday, mAnniversary; |
299 | int mRevision; | 301 | int mRevision; |
300 | bool mCancelled; | 302 | bool mCancelled; |
301 | 303 | ||
302 | // base components of jounal, event and todo | 304 | // base components of jounal, event and todo |
303 | QDateTime mCreated; | 305 | QDateTime mCreated; |
304 | QDateTime mLastModifiedSub; | 306 | QDateTime mLastModifiedSub; |
305 | QString mDescription; | 307 | QString mDescription; |
306 | QString mSummary; | 308 | QString mSummary; |
307 | QStringList mCategories; | 309 | QStringList mCategories; |
308 | Incidence *mRelatedTo; | 310 | Incidence *mRelatedTo; |
309 | QString mRelatedToUid; | 311 | QString mRelatedToUid; |
310 | DateList mExDates; | 312 | DateList mExDates; |
311 | QPtrList<Attachment> mAttachments; | 313 | Q3PtrList<Attachment> mAttachments; |
312 | QStringList mResources; | 314 | QStringList mResources; |
313 | bool mHasStartDate; // if todo has associated start date | 315 | bool mHasStartDate; // if todo has associated start date |
314 | 316 | ||
315 | int mSecrecy; | 317 | int mSecrecy; |
316 | int mPriority; // 1 = highest, 2 = less, etc. | 318 | int mPriority; // 1 = highest, 2 = less, etc. |
317 | 319 | ||
318 | //QPtrList<Alarm> mAlarms; | 320 | //QPtrList<Alarm> mAlarms; |
319 | 321 | ||
320 | QString mLocation; | 322 | QString mLocation; |
321 | }; | 323 | }; |
322 | 324 | ||
323 | bool operator==( const Incidence&, const Incidence& ); | 325 | bool operator==( const Incidence&, const Incidence& ); |
324 | 326 | ||
325 | } | 327 | } |
326 | 328 | ||
327 | #endif | 329 | #endif |
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index 56c0560..f11ec54 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp | |||
@@ -1,500 +1,502 @@ | |||
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 | //Added by qt3to4: | ||
31 | #include <Q3PtrList> | ||
30 | 32 | ||
31 | using namespace KCal; | 33 | using namespace KCal; |
32 | 34 | ||
33 | IncidenceBase::IncidenceBase() : | 35 | IncidenceBase::IncidenceBase() : |
34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), | 36 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), |
35 | mPilotId(0), mSyncStatus(SYNCMOD) | 37 | mPilotId(0), mSyncStatus(SYNCMOD) |
36 | { | 38 | { |
37 | blockLastModified = false; | 39 | blockLastModified = false; |
38 | setUid(CalFormat::createUniqueId()); | 40 | setUid(CalFormat::createUniqueId()); |
39 | mOrganizer = ""; | 41 | mOrganizer = ""; |
40 | mFloats = false; | 42 | mFloats = false; |
41 | mDuration = 0; | 43 | mDuration = 0; |
42 | mHasDuration = false; | 44 | mHasDuration = false; |
43 | mPilotId = 0; | 45 | mPilotId = 0; |
44 | mExternalId = ":"; | 46 | mExternalId = ":"; |
45 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 47 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
46 | mSyncStatus = 0; | 48 | mSyncStatus = 0; |
47 | mAttendees.setAutoDelete( true ); | 49 | mAttendees.setAutoDelete( true ); |
48 | mCalEnabled = true; | 50 | mCalEnabled = true; |
49 | mAlarmEnabled = true; | 51 | mAlarmEnabled = true; |
50 | mCalID = 0; | 52 | mCalID = 0; |
51 | } | 53 | } |
52 | 54 | ||
53 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : | 55 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : |
54 | CustomProperties( i ) | 56 | CustomProperties( i ) |
55 | { | 57 | { |
56 | 58 | ||
57 | blockLastModified = false; | 59 | blockLastModified = false; |
58 | mReadOnly = i.mReadOnly; | 60 | mReadOnly = i.mReadOnly; |
59 | mDtStart = i.mDtStart; | 61 | mDtStart = i.mDtStart; |
60 | mDuration = i.mDuration; | 62 | mDuration = i.mDuration; |
61 | mHasDuration = i.mHasDuration; | 63 | mHasDuration = i.mHasDuration; |
62 | mOrganizer = i.mOrganizer; | 64 | mOrganizer = i.mOrganizer; |
63 | mUid = i.mUid; | 65 | mUid = i.mUid; |
64 | mCalEnabled = i.mCalEnabled; | 66 | mCalEnabled = i.mCalEnabled; |
65 | mAlarmEnabled = i.mAlarmEnabled; | 67 | mAlarmEnabled = i.mAlarmEnabled; |
66 | mCalID = i.mCalID; | 68 | mCalID = i.mCalID; |
67 | QPtrList<Attendee> attendees = i.attendees(); | 69 | Q3PtrList<Attendee> attendees = i.attendees(); |
68 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { | 70 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { |
69 | mAttendees.append( new Attendee( *a ) ); | 71 | mAttendees.append( new Attendee( *a ) ); |
70 | } | 72 | } |
71 | mFloats = i.mFloats; | 73 | mFloats = i.mFloats; |
72 | mLastModified = i.mLastModified; | 74 | mLastModified = i.mLastModified; |
73 | mPilotId = i.mPilotId; | 75 | mPilotId = i.mPilotId; |
74 | mTempSyncStat = i.mTempSyncStat; | 76 | mTempSyncStat = i.mTempSyncStat; |
75 | mSyncStatus = i.mSyncStatus; | 77 | mSyncStatus = i.mSyncStatus; |
76 | mExternalId = i.mExternalId; | 78 | mExternalId = i.mExternalId; |
77 | // The copied object is a new one, so it isn't observed by the observer | 79 | // The copied object is a new one, so it isn't observed by the observer |
78 | // of the original object. | 80 | // of the original object. |
79 | mObservers.clear(); | 81 | mObservers.clear(); |
80 | 82 | ||
81 | mAttendees.setAutoDelete( true ); | 83 | mAttendees.setAutoDelete( true ); |
82 | } | 84 | } |
83 | 85 | ||
84 | IncidenceBase::~IncidenceBase() | 86 | IncidenceBase::~IncidenceBase() |
85 | { | 87 | { |
86 | } | 88 | } |
87 | 89 | ||
88 | 90 | ||
89 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) | 91 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) |
90 | { | 92 | { |
91 | // do not compare mSyncStatus and mExternalId | 93 | // do not compare mSyncStatus and mExternalId |
92 | if( i1.attendees().count() != i2.attendees().count() ) { | 94 | if( i1.attendees().count() != i2.attendees().count() ) { |
93 | return false; // no need to check further | 95 | return false; // no need to check further |
94 | } | 96 | } |
95 | if ( i1.attendees().count() > 0 ) { | 97 | if ( i1.attendees().count() > 0 ) { |
96 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; | 98 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; |
97 | while ( a1 ) { | 99 | while ( a1 ) { |
98 | if ( !( (*a1) == (*a2)) ) | 100 | if ( !( (*a1) == (*a2)) ) |
99 | { | 101 | { |
100 | //qDebug("Attendee not equal "); | 102 | //qDebug("Attendee not equal "); |
101 | return false; | 103 | return false; |
102 | } | 104 | } |
103 | a1 = i1.attendees().next(); | 105 | a1 = i1.attendees().next(); |
104 | a2 = i2.attendees().next(); | 106 | a2 = i2.attendees().next(); |
105 | } | 107 | } |
106 | } | 108 | } |
107 | //if ( i1.dtStart() != i2.dtStart() ) | 109 | //if ( i1.dtStart() != i2.dtStart() ) |
108 | // return false; | 110 | // return false; |
109 | #if 0 | 111 | #if 0 |
110 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); | 112 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); |
111 | qDebug("1 %d ",i1.duration() == i2.duration() ); | 113 | qDebug("1 %d ",i1.duration() == i2.duration() ); |
112 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); | 114 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); |
113 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); | 115 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); |
114 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); | 116 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); |
115 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); | 117 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); |
116 | 118 | ||
117 | #endif | 119 | #endif |
118 | if ( i1.hasDuration() == i2.hasDuration() ) { | 120 | if ( i1.hasDuration() == i2.hasDuration() ) { |
119 | if ( i1.hasDuration() ) { | 121 | if ( i1.hasDuration() ) { |
120 | if ( i1.duration() != i2.duration() ) | 122 | if ( i1.duration() != i2.duration() ) |
121 | return false; | 123 | return false; |
122 | } | 124 | } |
123 | } else { | 125 | } else { |
124 | return false; | 126 | return false; |
125 | } | 127 | } |
126 | 128 | ||
127 | return ( i1.organizer() == i2.organizer() && | 129 | return ( i1.organizer() == i2.organizer() && |
128 | // i1.uid() == i2.uid() && | 130 | // i1.uid() == i2.uid() && |
129 | // Don't compare lastModified, otherwise the operator is not | 131 | // Don't compare lastModified, otherwise the operator is not |
130 | // of much use. We are not comparing for identity, after all. | 132 | // of much use. We are not comparing for identity, after all. |
131 | i1.doesFloat() == i2.doesFloat() && | 133 | i1.doesFloat() == i2.doesFloat() && |
132 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); | 134 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); |
133 | // no need to compare mObserver | 135 | // no need to compare mObserver |
134 | } | 136 | } |
135 | 137 | ||
136 | 138 | ||
137 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) | 139 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) |
138 | { | 140 | { |
139 | QTime t = dt.time(); | 141 | QTime t = dt.time(); |
140 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 142 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
141 | return dt; | 143 | return dt; |
142 | } | 144 | } |
143 | 145 | ||
144 | bool IncidenceBase::isTagged() const | 146 | bool IncidenceBase::isTagged() const |
145 | { | 147 | { |
146 | return mIsTagged; | 148 | return mIsTagged; |
147 | } | 149 | } |
148 | void IncidenceBase::setTagged( bool b) | 150 | void IncidenceBase::setTagged( bool b) |
149 | { | 151 | { |
150 | mIsTagged = b; | 152 | mIsTagged = b; |
151 | } | 153 | } |
152 | void IncidenceBase::setCalID( int id ) | 154 | void IncidenceBase::setCalID( int id ) |
153 | { | 155 | { |
154 | if ( mCalID > 0 ) { | 156 | if ( mCalID > 0 ) { |
155 | updated(); | 157 | updated(); |
156 | } | 158 | } |
157 | mCalID = id; | 159 | mCalID = id; |
158 | } | 160 | } |
159 | void IncidenceBase::setCalID_block( int id ) | 161 | void IncidenceBase::setCalID_block( int id ) |
160 | { | 162 | { |
161 | if ( mCalID > 0 ) { | 163 | if ( mCalID > 0 ) { |
162 | blockLastModified = true; | 164 | blockLastModified = true; |
163 | updated(); | 165 | updated(); |
164 | blockLastModified = false; | 166 | blockLastModified = false; |
165 | } | 167 | } |
166 | mCalID = id; | 168 | mCalID = id; |
167 | } | 169 | } |
168 | int IncidenceBase::calID() const | 170 | int IncidenceBase::calID() const |
169 | { | 171 | { |
170 | return mCalID; | 172 | return mCalID; |
171 | } | 173 | } |
172 | void IncidenceBase::setCalEnabled( bool b ) | 174 | void IncidenceBase::setCalEnabled( bool b ) |
173 | { | 175 | { |
174 | mCalEnabled = b; | 176 | mCalEnabled = b; |
175 | } | 177 | } |
176 | bool IncidenceBase::calEnabled() const | 178 | bool IncidenceBase::calEnabled() const |
177 | { | 179 | { |
178 | return mCalEnabled; | 180 | return mCalEnabled; |
179 | } | 181 | } |
180 | 182 | ||
181 | void IncidenceBase::setAlarmEnabled( bool b ) | 183 | void IncidenceBase::setAlarmEnabled( bool b ) |
182 | { | 184 | { |
183 | mAlarmEnabled = b; | 185 | mAlarmEnabled = b; |
184 | } | 186 | } |
185 | bool IncidenceBase::alarmEnabled() const | 187 | bool IncidenceBase::alarmEnabled() const |
186 | { | 188 | { |
187 | return mAlarmEnabled; | 189 | return mAlarmEnabled; |
188 | } | 190 | } |
189 | 191 | ||
190 | 192 | ||
191 | void IncidenceBase::setUid(const QString &uid) | 193 | void IncidenceBase::setUid(const QString &uid) |
192 | { | 194 | { |
193 | mUid = uid; | 195 | mUid = uid; |
194 | updated(); | 196 | updated(); |
195 | } | 197 | } |
196 | 198 | ||
197 | QString IncidenceBase::uid() const | 199 | QString IncidenceBase::uid() const |
198 | { | 200 | { |
199 | return mUid; | 201 | return mUid; |
200 | } | 202 | } |
201 | void IncidenceBase::setLastModifiedSubInvalid() | 203 | void IncidenceBase::setLastModifiedSubInvalid() |
202 | { | 204 | { |
203 | // virtual method | 205 | // virtual method |
204 | } | 206 | } |
205 | void IncidenceBase::setLastModified(const QDateTime &lm) | 207 | void IncidenceBase::setLastModified(const QDateTime &lm) |
206 | { | 208 | { |
207 | if ( blockLastModified ) return; | 209 | if ( blockLastModified ) return; |
208 | // DON'T! updated() because we call this from | 210 | // DON'T! updated() because we call this from |
209 | // Calendar::updateEvent(). | 211 | // Calendar::updateEvent(). |
210 | mLastModified = getEvenTime(lm); | 212 | mLastModified = getEvenTime(lm); |
211 | mLastModifiedKey.sprintf("%04d%02d%02d%02d%02d%02d", | 213 | mLastModifiedKey.sprintf("%04d%02d%02d%02d%02d%02d", |
212 | mLastModified.date().year(), | 214 | mLastModified.date().year(), |
213 | mLastModified.date().month(), | 215 | mLastModified.date().month(), |
214 | mLastModified.date().day(), | 216 | mLastModified.date().day(), |
215 | mLastModified.time().hour(), | 217 | mLastModified.time().hour(), |
216 | mLastModified.time().minute(), | 218 | mLastModified.time().minute(), |
217 | mLastModified.time().second() ); | 219 | mLastModified.time().second() ); |
218 | setLastModifiedSubInvalid(); | 220 | setLastModifiedSubInvalid(); |
219 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); | 221 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); |
220 | } | 222 | } |
221 | QString IncidenceBase::lastModifiedSortKey() const | 223 | QString IncidenceBase::lastModifiedSortKey() const |
222 | { | 224 | { |
223 | return mLastModifiedKey; | 225 | return mLastModifiedKey; |
224 | } | 226 | } |
225 | 227 | ||
226 | QDateTime IncidenceBase::lastModified() const | 228 | QDateTime IncidenceBase::lastModified() const |
227 | { | 229 | { |
228 | return mLastModified; | 230 | return mLastModified; |
229 | } | 231 | } |
230 | 232 | ||
231 | void IncidenceBase::setOrganizer(const QString &o) | 233 | void IncidenceBase::setOrganizer(const QString &o) |
232 | { | 234 | { |
233 | // we don't check for readonly here, because it is | 235 | // we don't check for readonly here, because it is |
234 | // possible that by setting the organizer we are changing | 236 | // possible that by setting the organizer we are changing |
235 | // the event's readonly status... | 237 | // the event's readonly status... |
236 | mOrganizer = o; | 238 | mOrganizer = o; |
237 | if (mOrganizer.left(7).upper() == "MAILTO:") | 239 | if (mOrganizer.left(7).upper() == "MAILTO:") |
238 | mOrganizer = mOrganizer.remove(0,7); | 240 | mOrganizer = mOrganizer.remove(0,7); |
239 | 241 | ||
240 | updated(); | 242 | updated(); |
241 | } | 243 | } |
242 | 244 | ||
243 | QString IncidenceBase::organizer() const | 245 | QString IncidenceBase::organizer() const |
244 | { | 246 | { |
245 | return mOrganizer; | 247 | return mOrganizer; |
246 | } | 248 | } |
247 | 249 | ||
248 | void IncidenceBase::setReadOnly( bool readOnly ) | 250 | void IncidenceBase::setReadOnly( bool readOnly ) |
249 | { | 251 | { |
250 | mReadOnly = readOnly; | 252 | mReadOnly = readOnly; |
251 | } | 253 | } |
252 | 254 | ||
253 | void IncidenceBase::setDtStart(const QDateTime &dtStart) | 255 | void IncidenceBase::setDtStart(const QDateTime &dtStart) |
254 | { | 256 | { |
255 | // if (mReadOnly) return; | 257 | // if (mReadOnly) return; |
256 | mDtStart = getEvenTime(dtStart); | 258 | mDtStart = getEvenTime(dtStart); |
257 | updated(); | 259 | updated(); |
258 | } | 260 | } |
259 | 261 | ||
260 | 262 | ||
261 | QDateTime IncidenceBase::dtStart() const | 263 | QDateTime IncidenceBase::dtStart() const |
262 | { | 264 | { |
263 | return mDtStart; | 265 | return mDtStart; |
264 | } | 266 | } |
265 | 267 | ||
266 | QString IncidenceBase::dtStartTimeStr() const | 268 | QString IncidenceBase::dtStartTimeStr() const |
267 | { | 269 | { |
268 | return KGlobal::locale()->formatTime(dtStart().time()); | 270 | return KGlobal::locale()->formatTime(dtStart().time()); |
269 | } | 271 | } |
270 | 272 | ||
271 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const | 273 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const |
272 | { | 274 | { |
273 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 275 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
274 | } | 276 | } |
275 | 277 | ||
276 | QString IncidenceBase::dtStartStr(bool shortfmt) const | 278 | QString IncidenceBase::dtStartStr(bool shortfmt) const |
277 | { | 279 | { |
278 | if ( doesFloat() ) | 280 | if ( doesFloat() ) |
279 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 281 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
280 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); | 282 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); |
281 | } | 283 | } |
282 | 284 | ||
283 | 285 | ||
284 | bool IncidenceBase::doesFloat() const | 286 | bool IncidenceBase::doesFloat() const |
285 | { | 287 | { |
286 | return mFloats; | 288 | return mFloats; |
287 | } | 289 | } |
288 | 290 | ||
289 | void IncidenceBase::setFloats(bool f) | 291 | void IncidenceBase::setFloats(bool f) |
290 | { | 292 | { |
291 | if (mReadOnly) return; | 293 | if (mReadOnly) return; |
292 | mFloats = f; | 294 | mFloats = f; |
293 | updated(); | 295 | updated(); |
294 | } | 296 | } |
295 | 297 | ||
296 | 298 | ||
297 | bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) | 299 | bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) |
298 | { | 300 | { |
299 | if (mReadOnly) return false; | 301 | if (mReadOnly) return false; |
300 | if (a->name().left(7).upper() == "MAILTO:") | 302 | if (a->name().left(7).upper() == "MAILTO:") |
301 | a->setName(a->name().remove(0,7)); | 303 | a->setName(a->name().remove(0,7)); |
302 | 304 | ||
303 | QPtrListIterator<Attendee> qli(mAttendees); | 305 | Q3PtrListIterator<Attendee> qli(mAttendees); |
304 | 306 | ||
305 | qli.toFirst(); | 307 | qli.toFirst(); |
306 | while (qli) { | 308 | while (qli) { |
307 | if (*qli.current() == *a) | 309 | if (*qli.current() == *a) |
308 | return false; | 310 | return false; |
309 | ++qli; | 311 | ++qli; |
310 | } | 312 | } |
311 | mAttendees.append(a); | 313 | mAttendees.append(a); |
312 | if (doupdate) updated(); | 314 | if (doupdate) updated(); |
313 | return true; | 315 | return true; |
314 | } | 316 | } |
315 | 317 | ||
316 | #if 0 | 318 | #if 0 |
317 | void IncidenceBase::removeAttendee(Attendee *a) | 319 | void IncidenceBase::removeAttendee(Attendee *a) |
318 | { | 320 | { |
319 | if (mReadOnly) return; | 321 | if (mReadOnly) return; |
320 | mAttendees.removeRef(a); | 322 | mAttendees.removeRef(a); |
321 | updated(); | 323 | updated(); |
322 | } | 324 | } |
323 | 325 | ||
324 | void IncidenceBase::removeAttendee(const char *n) | 326 | void IncidenceBase::removeAttendee(const char *n) |
325 | { | 327 | { |
326 | Attendee *a; | 328 | Attendee *a; |
327 | 329 | ||
328 | if (mReadOnly) return; | 330 | if (mReadOnly) return; |
329 | for (a = mAttendees.first(); a; a = mAttendees.next()) | 331 | for (a = mAttendees.first(); a; a = mAttendees.next()) |
330 | if (a->getName() == n) { | 332 | if (a->getName() == n) { |
331 | mAttendees.remove(); | 333 | mAttendees.remove(); |
332 | break; | 334 | break; |
333 | } | 335 | } |
334 | } | 336 | } |
335 | #endif | 337 | #endif |
336 | 338 | ||
337 | void IncidenceBase::clearAttendees() | 339 | void IncidenceBase::clearAttendees() |
338 | { | 340 | { |
339 | if (mReadOnly) return; | 341 | if (mReadOnly) return; |
340 | mAttendees.clear(); | 342 | mAttendees.clear(); |
341 | } | 343 | } |
342 | 344 | ||
343 | #if 0 | 345 | #if 0 |
344 | Attendee *IncidenceBase::getAttendee(const char *n) const | 346 | Attendee *IncidenceBase::getAttendee(const char *n) const |
345 | { | 347 | { |
346 | QPtrListIterator<Attendee> qli(mAttendees); | 348 | Q3PtrListIterator<Attendee> qli(mAttendees); |
347 | 349 | ||
348 | qli.toFirst(); | 350 | qli.toFirst(); |
349 | while (qli) { | 351 | while (qli) { |
350 | if (qli.current()->getName() == n) | 352 | if (qli.current()->getName() == n) |
351 | return qli.current(); | 353 | return qli.current(); |
352 | ++qli; | 354 | ++qli; |
353 | } | 355 | } |
354 | return 0L; | 356 | return 0L; |
355 | } | 357 | } |
356 | #endif | 358 | #endif |
357 | 359 | ||
358 | Attendee *IncidenceBase::attendeeByMail(const QString &email) | 360 | Attendee *IncidenceBase::attendeeByMail(const QString &email) |
359 | { | 361 | { |
360 | QPtrListIterator<Attendee> qli(mAttendees); | 362 | Q3PtrListIterator<Attendee> qli(mAttendees); |
361 | 363 | ||
362 | qli.toFirst(); | 364 | qli.toFirst(); |
363 | while (qli) { | 365 | while (qli) { |
364 | if (qli.current()->email().lower() == email.lower()) | 366 | if (qli.current()->email().lower() == email.lower()) |
365 | return qli.current(); | 367 | return qli.current(); |
366 | ++qli; | 368 | ++qli; |
367 | } | 369 | } |
368 | return 0L; | 370 | return 0L; |
369 | } | 371 | } |
370 | 372 | ||
371 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) | 373 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) |
372 | { | 374 | { |
373 | QPtrListIterator<Attendee> qli(mAttendees); | 375 | Q3PtrListIterator<Attendee> qli(mAttendees); |
374 | 376 | ||
375 | QStringList mails = emails; | 377 | QStringList mails = emails; |
376 | if (!email.isEmpty()) { | 378 | if (!email.isEmpty()) { |
377 | mails.append(email); | 379 | mails.append(email); |
378 | } | 380 | } |
379 | qli.toFirst(); | 381 | qli.toFirst(); |
380 | while (qli) { | 382 | while (qli) { |
381 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { | 383 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { |
382 | if (qli.current()->email().lower() == (*it).lower()) | 384 | if (qli.current()->email().lower() == (*it).lower()) |
383 | return qli.current(); | 385 | return qli.current(); |
384 | } | 386 | } |
385 | 387 | ||
386 | ++qli; | 388 | ++qli; |
387 | } | 389 | } |
388 | return 0L; | 390 | return 0L; |
389 | } | 391 | } |
390 | 392 | ||
391 | void IncidenceBase::setDuration(int seconds) | 393 | void IncidenceBase::setDuration(int seconds) |
392 | { | 394 | { |
393 | mDuration = seconds; | 395 | mDuration = seconds; |
394 | setHasDuration(true); | 396 | setHasDuration(true); |
395 | } | 397 | } |
396 | 398 | ||
397 | int IncidenceBase::duration() const | 399 | int IncidenceBase::duration() const |
398 | { | 400 | { |
399 | return mDuration; | 401 | return mDuration; |
400 | } | 402 | } |
401 | 403 | ||
402 | void IncidenceBase::setHasDuration(bool b) | 404 | void IncidenceBase::setHasDuration(bool b) |
403 | { | 405 | { |
404 | mHasDuration = b; | 406 | mHasDuration = b; |
405 | } | 407 | } |
406 | 408 | ||
407 | bool IncidenceBase::hasDuration() const | 409 | bool IncidenceBase::hasDuration() const |
408 | { | 410 | { |
409 | return mHasDuration; | 411 | return mHasDuration; |
410 | } | 412 | } |
411 | 413 | ||
412 | void IncidenceBase::setSyncStatus(int stat) | 414 | void IncidenceBase::setSyncStatus(int stat) |
413 | { | 415 | { |
414 | if (mReadOnly) return; | 416 | if (mReadOnly) return; |
415 | mSyncStatus = stat; | 417 | mSyncStatus = stat; |
416 | } | 418 | } |
417 | 419 | ||
418 | int IncidenceBase::syncStatus() const | 420 | int IncidenceBase::syncStatus() const |
419 | { | 421 | { |
420 | return mSyncStatus; | 422 | return mSyncStatus; |
421 | } | 423 | } |
422 | 424 | ||
423 | void IncidenceBase::setPilotId( int id ) | 425 | void IncidenceBase::setPilotId( int id ) |
424 | { | 426 | { |
425 | if (mReadOnly) return; | 427 | if (mReadOnly) return; |
426 | mPilotId = id; | 428 | mPilotId = id; |
427 | } | 429 | } |
428 | 430 | ||
429 | int IncidenceBase::pilotId() const | 431 | int IncidenceBase::pilotId() const |
430 | { | 432 | { |
431 | return mPilotId; | 433 | return mPilotId; |
432 | } | 434 | } |
433 | 435 | ||
434 | int IncidenceBase::tempSyncStat() const | 436 | int IncidenceBase::tempSyncStat() const |
435 | { | 437 | { |
436 | return mTempSyncStat; | 438 | return mTempSyncStat; |
437 | } | 439 | } |
438 | void IncidenceBase::setTempSyncStat( int id ) | 440 | void IncidenceBase::setTempSyncStat( int id ) |
439 | { | 441 | { |
440 | if (mReadOnly) return; | 442 | if (mReadOnly) return; |
441 | mTempSyncStat = id; | 443 | mTempSyncStat = id; |
442 | } | 444 | } |
443 | 445 | ||
444 | void IncidenceBase::removeID(const QString &prof) | 446 | void IncidenceBase::removeID(const QString &prof) |
445 | { | 447 | { |
446 | if ( prof.isEmpty() ) | 448 | if ( prof.isEmpty() ) |
447 | mExternalId = ":"; | 449 | mExternalId = ":"; |
448 | else | 450 | else |
449 | mExternalId = KIdManager::removeId ( mExternalId, prof); | 451 | mExternalId = KIdManager::removeId ( mExternalId, prof); |
450 | 452 | ||
451 | } | 453 | } |
452 | void IncidenceBase::setID( const QString & prof , const QString & id ) | 454 | void IncidenceBase::setID( const QString & prof , const QString & id ) |
453 | { | 455 | { |
454 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); | 456 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); |
455 | } | 457 | } |
456 | QString IncidenceBase::getID( const QString & prof) | 458 | QString IncidenceBase::getID( const QString & prof) |
457 | { | 459 | { |
458 | return KIdManager::getId ( mExternalId, prof ); | 460 | return KIdManager::getId ( mExternalId, prof ); |
459 | } | 461 | } |
460 | 462 | ||
461 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: | 463 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: |
462 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 | 464 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 |
463 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) | 465 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) |
464 | { | 466 | { |
465 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); | 467 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); |
466 | } | 468 | } |
467 | QString IncidenceBase::getCsum( const QString & prof) | 469 | QString IncidenceBase::getCsum( const QString & prof) |
468 | { | 470 | { |
469 | return KIdManager::getCsum ( mExternalId, prof ); | 471 | return KIdManager::getCsum ( mExternalId, prof ); |
470 | } | 472 | } |
471 | 473 | ||
472 | void IncidenceBase::setIDStr( const QString & s ) | 474 | void IncidenceBase::setIDStr( const QString & s ) |
473 | { | 475 | { |
474 | if (mReadOnly) return; | 476 | if (mReadOnly) return; |
475 | mExternalId = s; | 477 | mExternalId = s; |
476 | } | 478 | } |
477 | 479 | ||
478 | QString IncidenceBase::IDStr() const | 480 | QString IncidenceBase::IDStr() const |
479 | { | 481 | { |
480 | return mExternalId ; | 482 | return mExternalId ; |
481 | } | 483 | } |
482 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) | 484 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) |
483 | { | 485 | { |
484 | if( !mObservers.contains(observer) ) mObservers.append( observer ); | 486 | if( !mObservers.contains(observer) ) mObservers.append( observer ); |
485 | } | 487 | } |
486 | 488 | ||
487 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) | 489 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) |
488 | { | 490 | { |
489 | mObservers.remove( observer ); | 491 | mObservers.remove( observer ); |
490 | } | 492 | } |
491 | 493 | ||
492 | void IncidenceBase::updated() | 494 | void IncidenceBase::updated() |
493 | { | 495 | { |
494 | QPtrListIterator<Observer> it(mObservers); | 496 | Q3PtrListIterator<Observer> it(mObservers); |
495 | while( it.current() ) { | 497 | while( it.current() ) { |
496 | Observer *o = it.current(); | 498 | Observer *o = it.current(); |
497 | ++it; | 499 | ++it; |
498 | o->incidenceUpdated( this ); | 500 | o->incidenceUpdated( this ); |
499 | } | 501 | } |
500 | } | 502 | } |
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h index 3edc03b..d97f524 100644 --- a/libkcal/incidencebase.h +++ b/libkcal/incidencebase.h | |||
@@ -1,190 +1,192 @@ | |||
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 <q3valuelist.h> |
29 | #include <qptrlist.h> | 29 | #include <q3ptrlist.h> |
30 | //Added by qt3to4: | ||
31 | #include <Q3CString> | ||
30 | 32 | ||
31 | #include "customproperties.h" | 33 | #include "customproperties.h" |
32 | #include "attendee.h" | 34 | #include "attendee.h" |
33 | 35 | ||
34 | namespace KCal { | 36 | namespace KCal { |
35 | 37 | ||
36 | typedef QValueList<QDate> DateList; | 38 | typedef Q3ValueList<QDate> DateList; |
37 | enum IncTypeID { eventID,todoID,journalID,freebusyID }; | 39 | enum IncTypeID { eventID,todoID,journalID,freebusyID }; |
38 | 40 | ||
39 | /** | 41 | /** |
40 | This class provides the base class common to all calendar components. | 42 | This class provides the base class common to all calendar components. |
41 | */ | 43 | */ |
42 | class IncidenceBase : public CustomProperties | 44 | class IncidenceBase : public CustomProperties |
43 | { | 45 | { |
44 | public: | 46 | public: |
45 | class Observer { | 47 | class Observer { |
46 | public: | 48 | public: |
47 | virtual void incidenceUpdated( IncidenceBase * ) = 0; | 49 | virtual void incidenceUpdated( IncidenceBase * ) = 0; |
48 | }; | 50 | }; |
49 | 51 | ||
50 | IncidenceBase(); | 52 | IncidenceBase(); |
51 | IncidenceBase(const IncidenceBase &); | 53 | IncidenceBase(const IncidenceBase &); |
52 | virtual ~IncidenceBase(); | 54 | virtual ~IncidenceBase(); |
53 | 55 | ||
54 | virtual QCString type() const = 0; | 56 | virtual Q3CString type() const = 0; |
55 | virtual IncTypeID typeID() const = 0; | 57 | virtual IncTypeID typeID() const = 0; |
56 | 58 | ||
57 | /** Set the unique id for the event */ | 59 | /** Set the unique id for the event */ |
58 | void setUid(const QString &); | 60 | void setUid(const QString &); |
59 | /** Return the unique id for the event */ | 61 | /** Return the unique id for the event */ |
60 | QString uid() const; | 62 | QString uid() const; |
61 | 63 | ||
62 | /** Sets the time the incidence was last modified. */ | 64 | /** Sets the time the incidence was last modified. */ |
63 | void setLastModified(const QDateTime &lm); | 65 | void setLastModified(const QDateTime &lm); |
64 | /** Return the time the incidence was last modified. */ | 66 | /** Return the time the incidence was last modified. */ |
65 | QDateTime lastModified() const; | 67 | QDateTime lastModified() const; |
66 | QString lastModifiedSortKey() const; | 68 | QString lastModifiedSortKey() const; |
67 | 69 | ||
68 | /** sets the organizer for the event */ | 70 | /** sets the organizer for the event */ |
69 | void setOrganizer(const QString &o); | 71 | void setOrganizer(const QString &o); |
70 | QString organizer() const; | 72 | QString organizer() const; |
71 | 73 | ||
72 | /** Set readonly status. */ | 74 | /** Set readonly status. */ |
73 | virtual void setReadOnly( bool ); | 75 | virtual void setReadOnly( bool ); |
74 | /** Return if the object is read-only. */ | 76 | /** Return if the object is read-only. */ |
75 | bool isReadOnly() const { return mReadOnly; } | 77 | bool isReadOnly() const { return mReadOnly; } |
76 | 78 | ||
77 | /** for setting the event's starting date/time with a QDateTime. */ | 79 | /** for setting the event's starting date/time with a QDateTime. */ |
78 | virtual void setDtStart(const QDateTime &dtStart); | 80 | virtual void setDtStart(const QDateTime &dtStart); |
79 | /** returns an event's starting date/time as a QDateTime. */ | 81 | /** returns an event's starting date/time as a QDateTime. */ |
80 | virtual QDateTime dtStart() const; | 82 | virtual QDateTime dtStart() const; |
81 | /** returns an event's starting time as a string formatted according to the | 83 | /** returns an event's starting time as a string formatted according to the |
82 | users locale settings */ | 84 | users locale settings */ |
83 | QString dtStartTimeStr() const; | 85 | QString dtStartTimeStr() const; |
84 | /** returns an event's starting date as a string formatted according to the | 86 | /** returns an event's starting date as a string formatted according to the |
85 | users locale settings */ | 87 | users locale settings */ |
86 | QString dtStartDateStr(bool shortfmt=true) const; | 88 | QString dtStartDateStr(bool shortfmt=true) const; |
87 | /** returns an event's starting date and time as a string formatted according | 89 | /** returns an event's starting date and time as a string formatted according |
88 | to the users locale settings */ | 90 | to the users locale settings */ |
89 | QString dtStartStr(bool shortfmt=true) const; | 91 | QString dtStartStr(bool shortfmt=true) const; |
90 | 92 | ||
91 | virtual void setDuration(int seconds); | 93 | virtual void setDuration(int seconds); |
92 | int duration() const; | 94 | int duration() const; |
93 | void setHasDuration(bool); | 95 | void setHasDuration(bool); |
94 | bool hasDuration() const; | 96 | bool hasDuration() const; |
95 | 97 | ||
96 | /** Return true or false depending on whether the incidence "floats," | 98 | /** Return true or false depending on whether the incidence "floats," |
97 | * i.e. has a date but no time attached to it. */ | 99 | * i.e. has a date but no time attached to it. */ |
98 | bool doesFloat() const; | 100 | bool doesFloat() const; |
99 | /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ | 101 | /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ |
100 | void setFloats(bool f); | 102 | void setFloats(bool f); |
101 | 103 | ||
102 | /** | 104 | /** |
103 | Add Attendee to this incidence. IncidenceBase takes ownership of the | 105 | Add Attendee to this incidence. IncidenceBase takes ownership of the |
104 | Attendee object. | 106 | Attendee object. |
105 | */ | 107 | */ |
106 | bool addAttendee(Attendee *a, bool doupdate=true ); | 108 | bool addAttendee(Attendee *a, bool doupdate=true ); |
107 | // void removeAttendee(Attendee *a); | 109 | // void removeAttendee(Attendee *a); |
108 | // void removeAttendee(const char *n); | 110 | // void removeAttendee(const char *n); |
109 | /** Remove all Attendees. */ | 111 | /** Remove all Attendees. */ |
110 | void clearAttendees(); | 112 | void clearAttendees(); |
111 | /** Return list of attendees. */ | 113 | /** Return list of attendees. */ |
112 | QPtrList<Attendee> attendees() const { return mAttendees; }; | 114 | Q3PtrList<Attendee> attendees() const { return mAttendees; }; |
113 | /** Return number of attendees. */ | 115 | /** Return number of attendees. */ |
114 | int attendeeCount() const { return mAttendees.count(); }; | 116 | int attendeeCount() const { return mAttendees.count(); }; |
115 | /** Return the Attendee with this email */ | 117 | /** Return the Attendee with this email */ |
116 | Attendee* attendeeByMail(const QString &); | 118 | Attendee* attendeeByMail(const QString &); |
117 | /** Return first Attendee with one of this emails */ | 119 | /** Return first Attendee with one of this emails */ |
118 | Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); | 120 | Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); |
119 | 121 | ||
120 | /** pilot syncronization states */ | 122 | /** pilot syncronization states */ |
121 | enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; | 123 | enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; |
122 | /** Set synchronisation satus. */ | 124 | /** Set synchronisation satus. */ |
123 | void setSyncStatus(int stat); | 125 | void setSyncStatus(int stat); |
124 | /** Return synchronisation status. */ | 126 | /** Return synchronisation status. */ |
125 | int syncStatus() const; | 127 | int syncStatus() const; |
126 | 128 | ||
127 | /** Set Pilot Id. */ | 129 | /** Set Pilot Id. */ |
128 | void setPilotId(int id); | 130 | void setPilotId(int id); |
129 | /** Return Pilot Id. */ | 131 | /** Return Pilot Id. */ |
130 | int pilotId() const; | 132 | int pilotId() const; |
131 | 133 | ||
132 | void setTempSyncStat(int id); | 134 | void setTempSyncStat(int id); |
133 | int tempSyncStat() const; | 135 | int tempSyncStat() const; |
134 | void setIDStr( const QString & ); | 136 | void setIDStr( const QString & ); |
135 | QString IDStr() const; | 137 | QString IDStr() const; |
136 | void setID( const QString &, const QString & ); | 138 | void setID( const QString &, const QString & ); |
137 | QString getID( const QString & ); | 139 | QString getID( const QString & ); |
138 | void setCsum( const QString &, const QString & ); | 140 | void setCsum( const QString &, const QString & ); |
139 | QString getCsum( const QString & ); | 141 | QString getCsum( const QString & ); |
140 | void removeID(const QString &); | 142 | void removeID(const QString &); |
141 | 143 | ||
142 | void registerObserver( Observer * ); | 144 | void registerObserver( Observer * ); |
143 | void unRegisterObserver( Observer * ); | 145 | void unRegisterObserver( Observer * ); |
144 | void updated(); | 146 | void updated(); |
145 | void setCalID( int id ); | 147 | void setCalID( int id ); |
146 | void setCalID_block( int id ); | 148 | void setCalID_block( int id ); |
147 | int calID() const; | 149 | int calID() const; |
148 | void setCalEnabled( bool ); | 150 | void setCalEnabled( bool ); |
149 | bool calEnabled() const; | 151 | bool calEnabled() const; |
150 | void setAlarmEnabled( bool ); | 152 | void setAlarmEnabled( bool ); |
151 | bool alarmEnabled() const; | 153 | bool alarmEnabled() const; |
152 | bool isTagged() const; | 154 | bool isTagged() const; |
153 | void setTagged( bool ); | 155 | void setTagged( bool ); |
154 | virtual void setLastModifiedSubInvalid(); | 156 | virtual void setLastModifiedSubInvalid(); |
155 | protected: | 157 | protected: |
156 | bool blockLastModified; | 158 | bool blockLastModified; |
157 | bool mIsTagged; | 159 | bool mIsTagged; |
158 | QDateTime mDtStart; | 160 | QDateTime mDtStart; |
159 | bool mReadOnly; | 161 | bool mReadOnly; |
160 | QDateTime getEvenTime( QDateTime ); | 162 | QDateTime getEvenTime( QDateTime ); |
161 | 163 | ||
162 | private: | 164 | private: |
163 | // base components | 165 | // base components |
164 | QString mOrganizer; | 166 | QString mOrganizer; |
165 | QString mLastModifiedKey; | 167 | QString mLastModifiedKey; |
166 | QString mUid; | 168 | QString mUid; |
167 | int mCalID; | 169 | int mCalID; |
168 | bool mCalEnabled; | 170 | bool mCalEnabled; |
169 | bool mAlarmEnabled; | 171 | bool mAlarmEnabled; |
170 | QDateTime mLastModified; | 172 | QDateTime mLastModified; |
171 | QPtrList<Attendee> mAttendees; | 173 | Q3PtrList<Attendee> mAttendees; |
172 | 174 | ||
173 | bool mFloats; | 175 | bool mFloats; |
174 | 176 | ||
175 | int mDuration; | 177 | int mDuration; |
176 | bool mHasDuration; | 178 | bool mHasDuration; |
177 | QString mExternalId; | 179 | QString mExternalId; |
178 | int mTempSyncStat; | 180 | int mTempSyncStat; |
179 | 181 | ||
180 | // PILOT SYNCHRONIZATION STUFF | 182 | // PILOT SYNCHRONIZATION STUFF |
181 | int mPilotId; // unique id for pilot sync | 183 | int mPilotId; // unique id for pilot sync |
182 | int mSyncStatus; // status (for sync) | 184 | int mSyncStatus; // status (for sync) |
183 | 185 | ||
184 | QPtrList<Observer> mObservers; | 186 | Q3PtrList<Observer> mObservers; |
185 | }; | 187 | }; |
186 | 188 | ||
187 | bool operator==( const IncidenceBase&, const IncidenceBase& ); | 189 | bool operator==( const IncidenceBase&, const IncidenceBase& ); |
188 | } | 190 | } |
189 | 191 | ||
190 | #endif | 192 | #endif |
diff --git a/libkcal/journal.h b/libkcal/journal.h index 1cd0a22..c83356f 100644 --- a/libkcal/journal.h +++ b/libkcal/journal.h | |||
@@ -1,51 +1,53 @@ | |||
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 JOURNAL_H | 20 | #ifndef JOURNAL_H |
21 | #define JOURNAL_H | 21 | #define JOURNAL_H |
22 | // | 22 | // |
23 | // Journal component, representing a VJOURNAL object | 23 | // Journal component, representing a VJOURNAL object |
24 | // | 24 | // |
25 | 25 | ||
26 | #include "incidence.h" | 26 | #include "incidence.h" |
27 | //Added by qt3to4: | ||
28 | #include <Q3CString> | ||
27 | 29 | ||
28 | namespace KCal { | 30 | namespace KCal { |
29 | 31 | ||
30 | /** | 32 | /** |
31 | This class provides a Journal in the sense of RFC2445. | 33 | This class provides a Journal in the sense of RFC2445. |
32 | */ | 34 | */ |
33 | class Journal : public Incidence | 35 | class Journal : public Incidence |
34 | { | 36 | { |
35 | public: | 37 | public: |
36 | Journal(); | 38 | Journal(); |
37 | ~Journal(); | 39 | ~Journal(); |
38 | 40 | ||
39 | QCString type() const { return "Journal"; } | 41 | Q3CString type() const { return "Journal"; } |
40 | IncTypeID typeID() const { return journalID; } | 42 | IncTypeID typeID() const { return journalID; } |
41 | 43 | ||
42 | Incidence *clone(); | 44 | Incidence *clone(); |
43 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; | 45 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; |
44 | private: | 46 | private: |
45 | bool accept(Visitor &v) { return v.visit(this); } | 47 | bool accept(Visitor &v) { return v.visit(this); } |
46 | }; | 48 | }; |
47 | 49 | ||
48 | bool operator==( const Journal&, const Journal& ); | 50 | bool operator==( const Journal&, const Journal& ); |
49 | } | 51 | } |
50 | 52 | ||
51 | #endif | 53 | #endif |
diff --git a/libkcal/kincidenceformatter.cpp b/libkcal/kincidenceformatter.cpp index 733b897..bce68b0 100644 --- a/libkcal/kincidenceformatter.cpp +++ b/libkcal/kincidenceformatter.cpp | |||
@@ -1,443 +1,445 @@ | |||
1 | #include "kincidenceformatter.h" | 1 | #include "kincidenceformatter.h" |
2 | #include <kstaticdeleter.h> | 2 | #include <kstaticdeleter.h> |
3 | #include <kglobal.h> | 3 | #include <kglobal.h> |
4 | #include <klocale.h> | 4 | #include <klocale.h> |
5 | #ifdef DEKTOP_VERSION | 5 | #ifdef DEKTOP_VERSION |
6 | #include <kabc/stdaddressbook.h> | 6 | #include <kabc/stdaddressbook.h> |
7 | //Added by qt3to4: | ||
8 | #include <Q3PtrList> | ||
7 | #define size count | 9 | #define size count |
8 | #endif | 10 | #endif |
9 | 11 | ||
10 | KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; | 12 | KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; |
11 | static KStaticDeleter<KIncidenceFormatter> insd; | 13 | static KStaticDeleter<KIncidenceFormatter> insd; |
12 | 14 | ||
13 | QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified ) | 15 | QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified ) |
14 | { | 16 | { |
15 | // #ifndef QT_NO_INPUTDIALOG | 17 | // #ifndef QT_NO_INPUTDIALOG |
16 | // return QInputDialog::getItem( caption, label, items, current, editable ); | 18 | // return QInputDialog::getItem( caption, label, items, current, editable ); |
17 | // #else | 19 | // #else |
18 | // return QString::null; | 20 | // return QString::null; |
19 | // #endif | 21 | // #endif |
20 | mDetails = details; | 22 | mDetails = details; |
21 | mCreated = created ; | 23 | mCreated = created ; |
22 | mModified = modified; | 24 | mModified = modified; |
23 | mText = ""; | 25 | mText = ""; |
24 | if ( inc->typeID() == eventID ) | 26 | if ( inc->typeID() == eventID ) |
25 | setEvent((Event *) inc ); | 27 | setEvent((Event *) inc ); |
26 | else if ( inc->typeID() == todoID ) | 28 | else if ( inc->typeID() == todoID ) |
27 | setTodo((Todo *) inc ); | 29 | setTodo((Todo *) inc ); |
28 | return mText; | 30 | return mText; |
29 | } | 31 | } |
30 | 32 | ||
31 | KIncidenceFormatter* KIncidenceFormatter::instance() | 33 | KIncidenceFormatter* KIncidenceFormatter::instance() |
32 | { | 34 | { |
33 | if (!mInstance) { | 35 | if (!mInstance) { |
34 | mInstance = insd.setObject(new KIncidenceFormatter()); | 36 | mInstance = insd.setObject(new KIncidenceFormatter()); |
35 | } | 37 | } |
36 | return mInstance; | 38 | return mInstance; |
37 | } | 39 | } |
38 | KIncidenceFormatter::~KIncidenceFormatter() | 40 | KIncidenceFormatter::~KIncidenceFormatter() |
39 | { | 41 | { |
40 | if (mInstance == this) | 42 | if (mInstance == this) |
41 | mInstance = insd.setObject(0); | 43 | mInstance = insd.setObject(0); |
42 | //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); | 44 | //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); |
43 | } | 45 | } |
44 | KIncidenceFormatter::KIncidenceFormatter() | 46 | KIncidenceFormatter::KIncidenceFormatter() |
45 | { | 47 | { |
46 | mColorMode = 0; | 48 | mColorMode = 0; |
47 | } | 49 | } |
48 | void KIncidenceFormatter::setEvent(Event *event) | 50 | void KIncidenceFormatter::setEvent(Event *event) |
49 | { | 51 | { |
50 | int mode = 0; | 52 | int mode = 0; |
51 | mCurrentIncidence = event; | 53 | mCurrentIncidence = event; |
52 | bool shortDate = true; | 54 | bool shortDate = true; |
53 | if ( mode == 0 ) { | 55 | if ( mode == 0 ) { |
54 | addTag("h3",deTag(event->summary())); | 56 | addTag("h3",deTag(event->summary())); |
55 | formatReadOnly(event); | 57 | formatReadOnly(event); |
56 | } | 58 | } |
57 | else { | 59 | else { |
58 | if ( mColorMode == 1 ) { | 60 | if ( mColorMode == 1 ) { |
59 | mText +="<font color=\"#00A000\">"; | 61 | mText +="<font color=\"#00A000\">"; |
60 | } | 62 | } |
61 | if ( mColorMode == 2 ) { | 63 | if ( mColorMode == 2 ) { |
62 | mText +="<font color=\"#C00000\">"; | 64 | mText +="<font color=\"#C00000\">"; |
63 | } | 65 | } |
64 | // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; | 66 | // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; |
65 | if ( mode == 1 ) { | 67 | if ( mode == 1 ) { |
66 | addTag("h2",i18n( "Local: " ) +deTag(event->summary())); | 68 | addTag("h2",i18n( "Local: " ) +deTag(event->summary())); |
67 | } else { | 69 | } else { |
68 | addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); | 70 | addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); |
69 | } | 71 | } |
70 | formatReadOnly(event); | 72 | formatReadOnly(event); |
71 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); | 73 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); |
72 | if ( mColorMode ) | 74 | if ( mColorMode ) |
73 | mText += "</font>"; | 75 | mText += "</font>"; |
74 | } | 76 | } |
75 | if (event->cancelled ()) { | 77 | if (event->cancelled ()) { |
76 | mText +="<font color=\"#B00000\">"; | 78 | mText +="<font color=\"#B00000\">"; |
77 | addTag("i",i18n("This event has been cancelled!")); | 79 | addTag("i",i18n("This event has been cancelled!")); |
78 | mText.append("<br>"); | 80 | mText.append("<br>"); |
79 | mText += "</font>"; | 81 | mText += "</font>"; |
80 | } | 82 | } |
81 | if (event->doesFloat()) { | 83 | if (event->doesFloat()) { |
82 | if (event->isMultiDay()) { | 84 | if (event->isMultiDay()) { |
83 | mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") | 85 | mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") |
84 | .arg(event->dtStartDateStr(shortDate)) | 86 | .arg(event->dtStartDateStr(shortDate)) |
85 | .arg(event->dtEndDateStr(shortDate))); | 87 | .arg(event->dtEndDateStr(shortDate))); |
86 | mText.append(i18n("<p><b>Duration:</b> %1 days</p>") | 88 | mText.append(i18n("<p><b>Duration:</b> %1 days</p>") |
87 | .arg(event->dtStart().daysTo(event->dtEnd())+1)); | 89 | .arg(event->dtStart().daysTo(event->dtEnd())+1)); |
88 | } else { | 90 | } else { |
89 | mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); | 91 | mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); |
90 | } | 92 | } |
91 | } else { | 93 | } else { |
92 | if (event->isMultiDay()) { | 94 | if (event->isMultiDay()) { |
93 | mText.append(i18n("<p><b>From:</b> %1</p> ") | 95 | mText.append(i18n("<p><b>From:</b> %1</p> ") |
94 | .arg(event->dtStartStr( shortDate))); | 96 | .arg(event->dtStartStr( shortDate))); |
95 | mText.append(i18n("<p><b>To:</b> %1</p>") | 97 | mText.append(i18n("<p><b>To:</b> %1</p>") |
96 | .arg(event->dtEndStr(shortDate))); | 98 | .arg(event->dtEndStr(shortDate))); |
97 | } else { | 99 | } else { |
98 | mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") | 100 | mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") |
99 | .arg(event->dtStartTimeStr()) | 101 | .arg(event->dtStartTimeStr()) |
100 | .arg(event->dtEndTimeStr())); | 102 | .arg(event->dtEndTimeStr())); |
101 | mText.append(i18n("<p><b>On:</b> %1</p> ") | 103 | mText.append(i18n("<p><b>On:</b> %1</p> ") |
102 | .arg(event->dtStartDateStr( shortDate ))); | 104 | .arg(event->dtStartDateStr( shortDate ))); |
103 | } | 105 | } |
104 | } | 106 | } |
105 | if (!event->location().isEmpty()) { | 107 | if (!event->location().isEmpty()) { |
106 | addTag("b",i18n("Location: ")); | 108 | addTag("b",i18n("Location: ")); |
107 | mText.append(deTag(event->location())+"<br>"); | 109 | mText.append(deTag(event->location())+"<br>"); |
108 | } | 110 | } |
109 | 111 | ||
110 | if (event->doesRecur()) { | 112 | if (event->doesRecur()) { |
111 | 113 | ||
112 | QString recurText = event->recurrence()->recurrenceText(); | 114 | QString recurText = event->recurrence()->recurrenceText(); |
113 | addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); | 115 | addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); |
114 | 116 | ||
115 | bool ok; | 117 | bool ok; |
116 | QDate start = QDate::currentDate(); | 118 | QDate start = QDate::currentDate(); |
117 | QDateTime next; | 119 | QDateTime next; |
118 | next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); | 120 | next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); |
119 | if ( ok ) { | 121 | if ( ok ) { |
120 | addTag("p",i18n("<b>Next recurrence is on:</b>") ); | 122 | addTag("p",i18n("<b>Next recurrence is on:</b>") ); |
121 | addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); | 123 | addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); |
122 | 124 | ||
123 | } else { | 125 | } else { |
124 | bool last; | 126 | bool last; |
125 | QDate nextd; | 127 | QDate nextd; |
126 | nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); | 128 | nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); |
127 | if ( last ) { | 129 | if ( last ) { |
128 | addTag("p",i18n("<b>Last recurrence was on:</b>") ); | 130 | addTag("p",i18n("<b>Last recurrence was on:</b>") ); |
129 | addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); | 131 | addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); |
130 | } | 132 | } |
131 | } | 133 | } |
132 | } | 134 | } |
133 | 135 | ||
134 | 136 | ||
135 | if (event->isAlarmEnabled()) { | 137 | if (event->isAlarmEnabled()) { |
136 | Alarm *alarm =event->alarms().first() ; | 138 | Alarm *alarm =event->alarms().first() ; |
137 | QDateTime t = alarm->time(); | 139 | QDateTime t = alarm->time(); |
138 | if (event->doesRecur()) { | 140 | if (event->doesRecur()) { |
139 | bool ok = false; | 141 | bool ok = false; |
140 | int offset = 0; | 142 | int offset = 0; |
141 | QDateTime next = event->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 143 | QDateTime next = event->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
142 | if ( ok ) { | 144 | if ( ok ) { |
143 | t = next; | 145 | t = next; |
144 | } | 146 | } |
145 | } | 147 | } |
146 | QString s =i18n("( %1 before )").arg( alarm->offsetText() ); | 148 | QString s =i18n("( %1 before )").arg( alarm->offsetText() ); |
147 | addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); | 149 | addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); |
148 | //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); | 150 | //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); |
149 | //addTag("p",s); | 151 | //addTag("p",s); |
150 | } | 152 | } |
151 | 153 | ||
152 | 154 | ||
153 | 155 | ||
154 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); | 156 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); |
155 | // mText.append(event->secrecyStr()+"<br>"); | 157 | // mText.append(event->secrecyStr()+"<br>"); |
156 | formatCategories(event); | 158 | formatCategories(event); |
157 | 159 | ||
158 | formatAttendees(event); | 160 | formatAttendees(event); |
159 | 161 | ||
160 | if ( mCreated ) { | 162 | if ( mCreated ) { |
161 | #ifdef DESKTOP_VERSION | 163 | #ifdef DESKTOP_VERSION |
162 | addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); | 164 | addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); |
163 | #else | 165 | #else |
164 | addTag("p",i18n("<b>Created: ") +" </b>"); | 166 | addTag("p",i18n("<b>Created: ") +" </b>"); |
165 | addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); | 167 | addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); |
166 | #endif | 168 | #endif |
167 | 169 | ||
168 | } | 170 | } |
169 | if ( mModified ) { | 171 | if ( mModified ) { |
170 | #ifdef DESKTOP_VERSION | 172 | #ifdef DESKTOP_VERSION |
171 | addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); | 173 | addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); |
172 | #else | 174 | #else |
173 | addTag("p",i18n("<b>Last modified: ") +" </b>"); | 175 | addTag("p",i18n("<b>Last modified: ") +" </b>"); |
174 | addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); | 176 | addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); |
175 | #endif | 177 | #endif |
176 | 178 | ||
177 | } | 179 | } |
178 | if ( mDetails ) { | 180 | if ( mDetails ) { |
179 | if (!event->description().isEmpty()) { | 181 | if (!event->description().isEmpty()) { |
180 | addTag("p",i18n("<b>Details: </b>")); | 182 | addTag("p",i18n("<b>Details: </b>")); |
181 | addTag("p",deTag(event->description())); | 183 | addTag("p",deTag(event->description())); |
182 | } | 184 | } |
183 | } | 185 | } |
184 | 186 | ||
185 | } | 187 | } |
186 | 188 | ||
187 | void KIncidenceFormatter::setTodo(Todo *event ) | 189 | void KIncidenceFormatter::setTodo(Todo *event ) |
188 | { | 190 | { |
189 | int mode = 0; | 191 | int mode = 0; |
190 | mCurrentIncidence = event; | 192 | mCurrentIncidence = event; |
191 | bool shortDate = true; | 193 | bool shortDate = true; |
192 | if (mode == 0 ) { | 194 | if (mode == 0 ) { |
193 | addTag("h3",deTag(event->summary())); | 195 | addTag("h3",deTag(event->summary())); |
194 | formatReadOnly(event); | 196 | formatReadOnly(event); |
195 | } | 197 | } |
196 | else { | 198 | else { |
197 | if ( mColorMode == 1 ) { | 199 | if ( mColorMode == 1 ) { |
198 | mText +="<font color=\"#00A000\">"; | 200 | mText +="<font color=\"#00A000\">"; |
199 | } | 201 | } |
200 | if ( mColorMode == 2 ) { | 202 | if ( mColorMode == 2 ) { |
201 | mText +="<font color=\"#B00000\">"; | 203 | mText +="<font color=\"#B00000\">"; |
202 | } | 204 | } |
203 | if ( mode == 1 ) { | 205 | if ( mode == 1 ) { |
204 | addTag("h2",i18n( "Local: " ) +deTag(event->summary())); | 206 | addTag("h2",i18n( "Local: " ) +deTag(event->summary())); |
205 | } else { | 207 | } else { |
206 | addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); | 208 | addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); |
207 | } | 209 | } |
208 | formatReadOnly(event); | 210 | formatReadOnly(event); |
209 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); | 211 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); |
210 | if ( mColorMode ) | 212 | if ( mColorMode ) |
211 | mText += "</font>"; | 213 | mText += "</font>"; |
212 | } | 214 | } |
213 | if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { | 215 | if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { |
214 | mText +="<font color=\"#B00000\">"; | 216 | mText +="<font color=\"#B00000\">"; |
215 | addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) ); | 217 | addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) ); |
216 | mText += "</font>"; | 218 | mText += "</font>"; |
217 | } else { | 219 | } else { |
218 | mText.append(i18n("<p><i>%1 % completed</i></p>") | 220 | mText.append(i18n("<p><i>%1 % completed</i></p>") |
219 | .arg(event->percentComplete())); | 221 | .arg(event->percentComplete())); |
220 | } | 222 | } |
221 | if (event->cancelled ()) { | 223 | if (event->cancelled ()) { |
222 | mText +="<font color=\"#B00000\">"; | 224 | mText +="<font color=\"#B00000\">"; |
223 | addTag("i",i18n("This todo has been cancelled!")); | 225 | addTag("i",i18n("This todo has been cancelled!")); |
224 | mText.append("<br>"); | 226 | mText.append("<br>"); |
225 | mText += "</font>"; | 227 | mText += "</font>"; |
226 | } | 228 | } |
227 | 229 | ||
228 | 230 | ||
229 | if (event->doesRecur()) { | 231 | if (event->doesRecur()) { |
230 | 232 | ||
231 | QString recurText = event->recurrence()->recurrenceText(); | 233 | QString recurText = event->recurrence()->recurrenceText(); |
232 | addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>"); | 234 | addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>"); |
233 | } | 235 | } |
234 | 236 | ||
235 | if (event->hasStartDate()) { | 237 | if (event->hasStartDate()) { |
236 | mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate))); | 238 | mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate))); |
237 | } | 239 | } |
238 | 240 | ||
239 | 241 | ||
240 | if (event->hasDueDate()) { | 242 | if (event->hasDueDate()) { |
241 | mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); | 243 | mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); |
242 | } | 244 | } |
243 | 245 | ||
244 | if (!event->location().isEmpty()) { | 246 | if (!event->location().isEmpty()) { |
245 | addTag("b",i18n("Location: ")); | 247 | addTag("b",i18n("Location: ")); |
246 | mText.append(deTag(event->location())+"<br>"); | 248 | mText.append(deTag(event->location())+"<br>"); |
247 | } | 249 | } |
248 | 250 | ||
249 | mText.append(i18n("<p><b>Priority:</b> %2</p>") | 251 | mText.append(i18n("<p><b>Priority:</b> %2</p>") |
250 | .arg(QString::number(event->priority()))); | 252 | .arg(QString::number(event->priority()))); |
251 | 253 | ||
252 | if (event->isAlarmEnabled()) { | 254 | if (event->isAlarmEnabled()) { |
253 | Alarm *alarm =event->alarms().first() ; | 255 | Alarm *alarm =event->alarms().first() ; |
254 | QDateTime t = alarm->time(); | 256 | QDateTime t = alarm->time(); |
255 | if (event->doesRecur()) { | 257 | if (event->doesRecur()) { |
256 | bool ok = false; | 258 | bool ok = false; |
257 | int offset = 0; | 259 | int offset = 0; |
258 | QDateTime next = event->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 260 | QDateTime next = event->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
259 | if ( ok ) { | 261 | if ( ok ) { |
260 | t = next; | 262 | t = next; |
261 | } | 263 | } |
262 | } | 264 | } |
263 | QString s =i18n("( %1 before )").arg( alarm->offsetText() ); | 265 | QString s =i18n("( %1 before )").arg( alarm->offsetText() ); |
264 | addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); | 266 | addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); |
265 | addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); | 267 | addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); |
266 | //addTag("p",s); | 268 | //addTag("p",s); |
267 | } | 269 | } |
268 | 270 | ||
269 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); | 271 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); |
270 | formatCategories(event); | 272 | formatCategories(event); |
271 | 273 | ||
272 | formatAttendees(event); | 274 | formatAttendees(event); |
273 | if ( mCreated ) { | 275 | if ( mCreated ) { |
274 | #ifdef DESKTOP_VERSION | 276 | #ifdef DESKTOP_VERSION |
275 | addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); | 277 | addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); |
276 | #else | 278 | #else |
277 | addTag("p",i18n("<b>Created: ") +" </b>"); | 279 | addTag("p",i18n("<b>Created: ") +" </b>"); |
278 | addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); | 280 | addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); |
279 | #endif | 281 | #endif |
280 | 282 | ||
281 | } | 283 | } |
282 | if ( mModified ) { | 284 | if ( mModified ) { |
283 | #ifdef DESKTOP_VERSION | 285 | #ifdef DESKTOP_VERSION |
284 | addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); | 286 | addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); |
285 | #else | 287 | #else |
286 | addTag("p",i18n("<b>Last modified: ") +" </b>"); | 288 | addTag("p",i18n("<b>Last modified: ") +" </b>"); |
287 | addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); | 289 | addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); |
288 | #endif | 290 | #endif |
289 | 291 | ||
290 | } | 292 | } |
291 | if ( mDetails ) { | 293 | if ( mDetails ) { |
292 | if (!event->description().isEmpty()) { | 294 | if (!event->description().isEmpty()) { |
293 | addTag("p",i18n("<b>Details: </b>")); | 295 | addTag("p",i18n("<b>Details: </b>")); |
294 | addTag("p",deTag(event->description())); | 296 | addTag("p",deTag(event->description())); |
295 | } | 297 | } |
296 | } | 298 | } |
297 | } | 299 | } |
298 | 300 | ||
299 | void KIncidenceFormatter::setJournal(Journal* ) | 301 | void KIncidenceFormatter::setJournal(Journal* ) |
300 | { | 302 | { |
301 | 303 | ||
302 | } | 304 | } |
303 | 305 | ||
304 | void KIncidenceFormatter::formatCategories(Incidence *event) | 306 | void KIncidenceFormatter::formatCategories(Incidence *event) |
305 | { | 307 | { |
306 | if (!event->categoriesStr().isEmpty()) { | 308 | if (!event->categoriesStr().isEmpty()) { |
307 | addTag("p",i18n("<b>Categories: </b>")+event->categoriesStrWithSpace() ); | 309 | addTag("p",i18n("<b>Categories: </b>")+event->categoriesStrWithSpace() ); |
308 | //mText.append(event->categoriesStr()); | 310 | //mText.append(event->categoriesStr()); |
309 | } | 311 | } |
310 | } | 312 | } |
311 | void KIncidenceFormatter::addTag(const QString & tag,const QString & text) | 313 | void KIncidenceFormatter::addTag(const QString & tag,const QString & text) |
312 | { | 314 | { |
313 | int number=text.contains("\n"); | 315 | int number=text.count("\n"); |
314 | QString str = "<" + tag + ">"; | 316 | QString str = "<" + tag + ">"; |
315 | QString tmpText=text; | 317 | QString tmpText=text; |
316 | QString tmpStr=str; | 318 | QString tmpStr=str; |
317 | if(number !=-1) | 319 | if(number !=-1) |
318 | { | 320 | { |
319 | if (number > 0) { | 321 | if (number > 0) { |
320 | int pos=0; | 322 | int pos=0; |
321 | QString tmp; | 323 | QString tmp; |
322 | for(int i=0;i<=number;i++) { | 324 | for(int i=0;i<=number;i++) { |
323 | pos=tmpText.find("\n"); | 325 | pos=tmpText.find("\n"); |
324 | tmp=tmpText.left(pos); | 326 | tmp=tmpText.left(pos); |
325 | tmpText=tmpText.right(tmpText.length()-pos-1); | 327 | tmpText=tmpText.right(tmpText.length()-pos-1); |
326 | tmpStr+=tmp+"<br>"; | 328 | tmpStr+=tmp+"<br>"; |
327 | } | 329 | } |
328 | } | 330 | } |
329 | else tmpStr += tmpText; | 331 | else tmpStr += tmpText; |
330 | tmpStr+="</" + tag + ">"; | 332 | tmpStr+="</" + tag + ">"; |
331 | mText.append(tmpStr); | 333 | mText.append(tmpStr); |
332 | } | 334 | } |
333 | else | 335 | else |
334 | { | 336 | { |
335 | str += text + "</" + tag + ">"; | 337 | str += text + "</" + tag + ">"; |
336 | mText.append(str); | 338 | mText.append(str); |
337 | } | 339 | } |
338 | } | 340 | } |
339 | 341 | ||
340 | void KIncidenceFormatter::formatAttendees(Incidence *event) | 342 | void KIncidenceFormatter::formatAttendees(Incidence *event) |
341 | { | 343 | { |
342 | QPtrList<Attendee> attendees = event->attendees(); | 344 | Q3PtrList<Attendee> attendees = event->attendees(); |
343 | if (attendees.count()) { | 345 | if (attendees.count()) { |
344 | QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); | 346 | QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); |
345 | QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); | 347 | QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); |
346 | addTag("h3",i18n("Organizer")); | 348 | addTag("h3",i18n("Organizer")); |
347 | mText.append("<ul><li>"); | 349 | mText.append("<ul><li>"); |
348 | #if 0 | 350 | #if 0 |
349 | //ndef KORG_NOKABC | 351 | //ndef KORG_NOKABC |
350 | 352 | ||
351 | KABC::AddressBook *add_book = KABC::StdAddressBook::self(); | 353 | KABC::AddressBook *add_book = KABC::StdAddressBook::self(); |
352 | KABC::Addressee::List addressList; | 354 | KABC::Addressee::List addressList; |
353 | addressList = add_book->findByEmail(event->organizer()); | 355 | addressList = add_book->findByEmail(event->organizer()); |
354 | KABC::Addressee o = addressList.first(); | 356 | KABC::Addressee o = addressList.first(); |
355 | if (!o.isEmpty() && addressList.size()<2) { | 357 | if (!o.isEmpty() && addressList.size()<2) { |
356 | mText += "<a href=\"uid:" + o.uid() + "\">"; | 358 | mText += "<a href=\"uid:" + o.uid() + "\">"; |
357 | mText += o.formattedName(); | 359 | mText += o.formattedName(); |
358 | mText += "</a>\n"; | 360 | mText += "</a>\n"; |
359 | } else { | 361 | } else { |
360 | mText.append(event->organizer()); | 362 | mText.append(event->organizer()); |
361 | } | 363 | } |
362 | #else | 364 | #else |
363 | mText.append(event->organizer()); | 365 | mText.append(event->organizer()); |
364 | #endif | 366 | #endif |
365 | if (iconPath) { | 367 | if (!iconPath.isEmpty()) { |
366 | mText += " <a href=\"mailto:" + event->organizer() + "\">"; | 368 | mText += " <a href=\"mailto:" + event->organizer() + "\">"; |
367 | mText += "<IMG src=\"" + iconPath + "\">"; | 369 | mText += "<IMG src=\"" + iconPath + "\">"; |
368 | mText += "</a>\n"; | 370 | mText += "</a>\n"; |
369 | } | 371 | } |
370 | mText.append("</li></ul>"); | 372 | mText.append("</li></ul>"); |
371 | 373 | ||
372 | addTag("h3",i18n("Attendees")); | 374 | addTag("h3",i18n("Attendees")); |
373 | Attendee *a; | 375 | Attendee *a; |
374 | mText.append("<ul>"); | 376 | mText.append("<ul>"); |
375 | for(a=attendees.first();a;a=attendees.next()) { | 377 | for(a=attendees.first();a;a=attendees.next()) { |
376 | #if 0 | 378 | #if 0 |
377 | //ndef KORG_NOKABC | 379 | //ndef KORG_NOKABC |
378 | if (a->name().isEmpty()) { | 380 | if (a->name().isEmpty()) { |
379 | addressList = add_book->findByEmail(a->email()); | 381 | addressList = add_book->findByEmail(a->email()); |
380 | KABC::Addressee o = addressList.first(); | 382 | KABC::Addressee o = addressList.first(); |
381 | if (!o.isEmpty() && addressList.size()<2) { | 383 | if (!o.isEmpty() && addressList.size()<2) { |
382 | mText += "<a href=\"uid:" + o.uid() + "\">"; | 384 | mText += "<a href=\"uid:" + o.uid() + "\">"; |
383 | mText += o.formattedName(); | 385 | mText += o.formattedName(); |
384 | mText += "</a>\n"; | 386 | mText += "</a>\n"; |
385 | } else { | 387 | } else { |
386 | mText += "<li>"; | 388 | mText += "<li>"; |
387 | mText.append(a->email()); | 389 | mText.append(a->email()); |
388 | mText += "\n"; | 390 | mText += "\n"; |
389 | } | 391 | } |
390 | } else { | 392 | } else { |
391 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; | 393 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; |
392 | if (!a->name().isEmpty()) mText += a->name(); | 394 | if (!a->name().isEmpty()) mText += a->name(); |
393 | else mText += a->email(); | 395 | else mText += a->email(); |
394 | mText += "</a>\n"; | 396 | mText += "</a>\n"; |
395 | } | 397 | } |
396 | #else | 398 | #else |
397 | //qDebug("nokabc "); | 399 | //qDebug("nokabc "); |
398 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; | 400 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; |
399 | if (!a->name().isEmpty()) mText += a->name(); | 401 | if (!a->name().isEmpty()) mText += a->name(); |
400 | else mText += a->email(); | 402 | else mText += a->email(); |
401 | mText += "</a>\n"; | 403 | mText += "</a>\n"; |
402 | #endif | 404 | #endif |
403 | 405 | ||
404 | if (!a->email().isEmpty()) { | 406 | if (!a->email().isEmpty()) { |
405 | if (iconPath) { | 407 | if (!iconPath.isEmpty()) { |
406 | mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; | 408 | mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; |
407 | if ( a->RSVP() ) | 409 | if ( a->RSVP() ) |
408 | mText += "<IMG src=\"" + iconPath + "\">"; | 410 | mText += "<IMG src=\"" + iconPath + "\">"; |
409 | else | 411 | else |
410 | mText += "<IMG src=\"" + NOiconPath + "\">"; | 412 | mText += "<IMG src=\"" + NOiconPath + "\">"; |
411 | mText += "</a>\n"; | 413 | mText += "</a>\n"; |
412 | } | 414 | } |
413 | } | 415 | } |
414 | if (a->status() != Attendee::NeedsAction ) | 416 | if (a->status() != Attendee::NeedsAction ) |
415 | mText +="[" + a->statusStr() + "] "; | 417 | mText +="[" + a->statusStr() + "] "; |
416 | if (a->role() == Attendee::Chair ) | 418 | if (a->role() == Attendee::Chair ) |
417 | mText +="(" + a->roleStr().left(1) + ".)"; | 419 | mText +="(" + a->roleStr().left(1) + ".)"; |
418 | } | 420 | } |
419 | mText.append("</li></ul>"); | 421 | mText.append("</li></ul>"); |
420 | } | 422 | } |
421 | } | 423 | } |
422 | 424 | ||
423 | void KIncidenceFormatter::formatReadOnly(Incidence *event) | 425 | void KIncidenceFormatter::formatReadOnly(Incidence *event) |
424 | { | 426 | { |
425 | if (event->isReadOnly()) { | 427 | if (event->isReadOnly()) { |
426 | addTag("p","<em>(" + i18n("read-only") + ")</em>"); | 428 | addTag("p","<em>(" + i18n("read-only") + ")</em>"); |
427 | } | 429 | } |
428 | } | 430 | } |
429 | QString KIncidenceFormatter::deTag(QString text) | 431 | QString KIncidenceFormatter::deTag(QString text) |
430 | { | 432 | { |
431 | #if QT_VERSION >= 0x030000 | 433 | #if QT_VERSION >= 0x030000 |
432 | text.replace( '<' , "<" ); | 434 | text.replace( '<' , "<" ); |
433 | text.replace( '>' , ">" ); | 435 | text.replace( '>' , ">" ); |
434 | #else | 436 | #else |
435 | if ( text.find ('<') >= 0 ) { | 437 | if ( text.find ('<') >= 0 ) { |
436 | text.replace( QRegExp("<") , "<" ); | 438 | text.replace( QRegExp("<") , "<" ); |
437 | } | 439 | } |
438 | if ( text.find ('>') >= 0 ) { | 440 | if ( text.find ('>') >= 0 ) { |
439 | text.replace( QRegExp(">") , ">" ); | 441 | text.replace( QRegExp(">") , ">" ); |
440 | } | 442 | } |
441 | #endif | 443 | #endif |
442 | return text; | 444 | return text; |
443 | } | 445 | } |
diff --git a/libkcal/libkcal.pro b/libkcal/libkcal.pro index 33c63c3..1f43b10 100644 --- a/libkcal/libkcal.pro +++ b/libkcal/libkcal.pro | |||
@@ -1,108 +1,112 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | TARGET = microkcal | 3 | TARGET = xmicrokcal |
4 | 4 | ||
5 | include( ../variables.pri ) | 5 | include( ../variables.pri ) |
6 | 6 | ||
7 | INCLUDEPATH += ../libkdepim ../microkde versit ../microkde/kdecore | 7 | INCLUDEPATH += ../libkdepim ../microkde versit ../microkde/kdecore |
8 | #../qtcompat | 8 | #../qtcompat |
9 | INCLUDEPATH += ../libical/src/libical | 9 | INCLUDEPATH += ../libical/src/libical |
10 | INCLUDEPATH += ../libical/src/libicalss | 10 | INCLUDEPATH += ../libical/src/libicalss |
11 | DESTDIR = ../bin | 11 | DESTDIR = ../bin |
12 | DEFINES += DESKTOP_VERSION | 12 | DEFINES += DESKTOP_VERSION |
13 | unix: { | 13 | unix: { |
14 | LIBS += ../libical/lib/libical.a | 14 | LIBS += ../libical/lib/libical.a |
15 | LIBS += ../libical/lib/libicalss.a | 15 | LIBS += ../libical/lib/libicalss.a |
16 | OBJECTS_DIR = obj/unix | 16 | OBJECTS_DIR = obj/unix |
17 | MOC_DIR = moc/unix | 17 | MOC_DIR = moc/unix |
18 | } | 18 | } |
19 | win32: { | 19 | win32: { |
20 | DEFINES += _WIN32_ | 20 | DEFINES += _WIN32_ |
21 | 21 | ||
22 | LIBS += ../libical/lib/ical.lib | 22 | LIBS += ../libical/lib/ical.lib |
23 | LIBS += ../libical/lib/icalss.lib | 23 | LIBS += ../libical/lib/icalss.lib |
24 | OBJECTS_DIR = obj/win | 24 | OBJECTS_DIR = obj/win |
25 | MOC_DIR = moc/win | 25 | MOC_DIR = moc/win |
26 | 26 | ||
27 | } | 27 | } |
28 | 28 | ||
29 | INTERFACES = \ | 29 | INTERFACES = \ |
30 | 30 | ||
31 | HEADERS = \ | 31 | HEADERS = \ |
32 | alarm.h \ | 32 | alarm.h \ |
33 | attachment.h \ | 33 | attachment.h \ |
34 | attendee.h \ | 34 | attendee.h \ |
35 | calendar.h \ | 35 | calendar.h \ |
36 | calendarlocal.h \ | 36 | calendarlocal.h \ |
37 | calfilter.h \ | 37 | calfilter.h \ |
38 | calformat.h \ | 38 | calformat.h \ |
39 | calstorage.h \ | 39 | calstorage.h \ |
40 | compat.h \ | 40 | compat.h \ |
41 | customproperties.h \ | 41 | customproperties.h \ |
42 | dummyscheduler.h \ | 42 | dummyscheduler.h \ |
43 | kincidenceformatter.h \ | 43 | kincidenceformatter.h \ |
44 | duration.h \ | 44 | duration.h \ |
45 | event.h \ | 45 | event.h \ |
46 | exceptions.h \ | 46 | exceptions.h \ |
47 | filestorage.h \ | 47 | filestorage.h \ |
48 | freebusy.h \ | 48 | freebusy.h \ |
49 | icaldrag.h \ | 49 | icaldrag.h \ |
50 | icalformat.h \ | 50 | icalformat.h \ |
51 | icalformatimpl.h \ | 51 | icalformatimpl.h \ |
52 | imipscheduler.h \ | 52 | imipscheduler.h \ |
53 | incidence.h \ | 53 | incidence.h \ |
54 | incidencebase.h \ | 54 | incidencebase.h \ |
55 | journal.h \ | 55 | journal.h \ |
56 | period.h \ | 56 | period.h \ |
57 | person.h \ | 57 | person.h \ |
58 | qtopiaformat.h \ | 58 | qtopiaformat.h \ |
59 | recurrence.h \ | 59 | recurrence.h \ |
60 | scheduler.h \ | 60 | scheduler.h \ |
61 | todo.h \ | 61 | todo.h \ |
62 | dndfactory.h \ | 62 | dndfactory.h \ |
63 | vcaldrag.h \ | 63 | vcaldrag.h \ |
64 | vcalformat.h \ | 64 | vcalformat.h \ |
65 | versit/port.h \ | 65 | versit/port.h \ |
66 | versit/vcc.h \ | 66 | versit/vcc.h \ |
67 | versit/vobject.h \ | 67 | versit/vobject.h \ |
68 | phoneformat.h \ | 68 | phoneformat.h \ |
69 | 69 | ||
70 | 70 | ||
71 | 71 | ||
72 | SOURCES = \ | 72 | SOURCES = \ |
73 | alarm.cpp \ | 73 | alarm.cpp \ |
74 | attachment.cpp \ | 74 | attachment.cpp \ |
75 | attendee.cpp \ | 75 | attendee.cpp \ |
76 | calendar.cpp \ | 76 | calendar.cpp \ |
77 | calendarlocal.cpp \ | 77 | calendarlocal.cpp \ |
78 | calfilter.cpp \ | 78 | calfilter.cpp \ |
79 | calformat.cpp \ | 79 | calformat.cpp \ |
80 | compat.cpp \ | 80 | compat.cpp \ |
81 | customproperties.cpp \ | 81 | customproperties.cpp \ |
82 | dummyscheduler.cpp \ | 82 | dummyscheduler.cpp \ |
83 | kincidenceformatter.cpp \ | 83 | kincidenceformatter.cpp \ |
84 | duration.cpp \ | 84 | duration.cpp \ |
85 | event.cpp \ | 85 | event.cpp \ |
86 | exceptions.cpp \ | 86 | exceptions.cpp \ |
87 | filestorage.cpp \ | 87 | filestorage.cpp \ |
88 | freebusy.cpp \ | 88 | freebusy.cpp \ |
89 | icaldrag.cpp \ | 89 | icaldrag.cpp \ |
90 | icalformat.cpp \ | 90 | icalformat.cpp \ |
91 | icalformatimpl.cpp \ | 91 | icalformatimpl.cpp \ |
92 | imipscheduler.cpp \ | 92 | imipscheduler.cpp \ |
93 | incidence.cpp \ | 93 | incidence.cpp \ |
94 | incidencebase.cpp \ | 94 | incidencebase.cpp \ |
95 | journal.cpp \ | 95 | journal.cpp \ |
96 | period.cpp \ | 96 | period.cpp \ |
97 | person.cpp \ | 97 | person.cpp \ |
98 | qtopiaformat.cpp \ | 98 | qtopiaformat.cpp \ |
99 | recurrence.cpp \ | 99 | recurrence.cpp \ |
100 | scheduler.cpp \ | 100 | scheduler.cpp \ |
101 | todo.cpp \ | 101 | todo.cpp \ |
102 | dndfactory.cpp \ | 102 | dndfactory.cpp \ |
103 | vcaldrag.cpp \ | 103 | vcaldrag.cpp \ |
104 | vcalformat.cpp \ | 104 | vcalformat.cpp \ |
105 | versit/vcc.c \ | 105 | versit/vcc.c \ |
106 | versit/vobject.c \ | 106 | versit/vobject.c \ |
107 | phoneformat.cpp \ | 107 | phoneformat.cpp \ |
108 | 108 | ||
109 | #The following line was inserted by qt3to4 | ||
110 | QT += xml qt3support | ||
111 | #The following line was inserted by qt3to4 | ||
112 | QT += | ||
diff --git a/libkcal/libkcalE.pro b/libkcal/libkcalE.pro index 737be53..fe46656 100644 --- a/libkcal/libkcalE.pro +++ b/libkcal/libkcalE.pro | |||
@@ -1,93 +1,93 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | TARGET = microkcal | 3 | TARGET = xmicrokcal |
4 | 4 | ||
5 | INCLUDEPATH += ../libkdepim ../microkde ../qtcompat versit ../microkde/kdecore $(QPEDIR)/include | 5 | INCLUDEPATH += ../libkdepim ../microkde ../qtcompat versit ../microkde/kdecore $(QPEDIR)/include |
6 | INCLUDEPATH += ../libical/src/libical | 6 | INCLUDEPATH += ../libical/src/libical |
7 | INCLUDEPATH += ../libical/src/libicalss | 7 | INCLUDEPATH += ../libical/src/libicalss |
8 | OBJECTS_DIR = obj/$(PLATFORM) | 8 | OBJECTS_DIR = obj/$(PLATFORM) |
9 | MOC_DIR = moc/$(PLATFORM) | 9 | MOC_DIR = moc/$(PLATFORM) |
10 | DESTDIR = $(QPEDIR)/lib | 10 | DESTDIR = $(QPEDIR)/lib |
11 | #LIBS += ../libical/lib/$(PLATFORM)/libical.a | 11 | #LIBS += ../libical/lib/$(PLATFORM)/libical.a |
12 | #LIBS += ../libical/lib/$(PLATFORM)/libicalss.a | 12 | #LIBS += ../libical/lib/$(PLATFORM)/libicalss.a |
13 | LIBS += ../dest$(LIBICAL_PATH)/libical.a | 13 | LIBS += ../dest$(LIBICAL_PATH)/libical.a |
14 | LIBS += ../dest$(LIBICAL_PATH)/libicalss.a | 14 | LIBS += ../dest$(LIBICAL_PATH)/libicalss.a |
15 | 15 | ||
16 | INTERFACES = \ | 16 | INTERFACES = \ |
17 | 17 | ||
18 | HEADERS = \ | 18 | HEADERS = \ |
19 | alarm.h \ | 19 | alarm.h \ |
20 | attachment.h \ | 20 | attachment.h \ |
21 | attendee.h \ | 21 | attendee.h \ |
22 | calendar.h \ | 22 | calendar.h \ |
23 | calendarlocal.h \ | 23 | calendarlocal.h \ |
24 | calfilter.h \ | 24 | calfilter.h \ |
25 | calformat.h \ | 25 | calformat.h \ |
26 | calstorage.h \ | 26 | calstorage.h \ |
27 | compat.h \ | 27 | compat.h \ |
28 | customproperties.h \ | 28 | customproperties.h \ |
29 | dummyscheduler.h \ | 29 | dummyscheduler.h \ |
30 | duration.h \ | 30 | duration.h \ |
31 | event.h \ | 31 | event.h \ |
32 | exceptions.h \ | 32 | exceptions.h \ |
33 | filestorage.h \ | 33 | filestorage.h \ |
34 | freebusy.h \ | 34 | freebusy.h \ |
35 | icaldrag.h \ | 35 | icaldrag.h \ |
36 | icalformat.h \ | 36 | icalformat.h \ |
37 | icalformatimpl.h \ | 37 | icalformatimpl.h \ |
38 | imipscheduler.h \ | 38 | imipscheduler.h \ |
39 | incidence.h \ | 39 | incidence.h \ |
40 | incidencebase.h \ | 40 | incidencebase.h \ |
41 | kincidenceformatter.h \ | 41 | kincidenceformatter.h \ |
42 | journal.h \ | 42 | journal.h \ |
43 | period.h \ | 43 | period.h \ |
44 | person.h \ | 44 | person.h \ |
45 | qtopiaformat.h \ | 45 | qtopiaformat.h \ |
46 | sharpformat.h \ | 46 | sharpformat.h \ |
47 | phoneformat.h \ | 47 | phoneformat.h \ |
48 | recurrence.h \ | 48 | recurrence.h \ |
49 | scheduler.h \ | 49 | scheduler.h \ |
50 | todo.h \ | 50 | todo.h \ |
51 | vcaldrag.h \ | 51 | vcaldrag.h \ |
52 | vcalformat.h \ | 52 | vcalformat.h \ |
53 | versit/port.h \ | 53 | versit/port.h \ |
54 | versit/vcc.h \ | 54 | versit/vcc.h \ |
55 | versit/vobject.h \ | 55 | versit/vobject.h \ |
56 | 56 | ||
57 | SOURCES = \ | 57 | SOURCES = \ |
58 | alarm.cpp \ | 58 | alarm.cpp \ |
59 | attachment.cpp \ | 59 | attachment.cpp \ |
60 | attendee.cpp \ | 60 | attendee.cpp \ |
61 | calendar.cpp \ | 61 | calendar.cpp \ |
62 | calendarlocal.cpp \ | 62 | calendarlocal.cpp \ |
63 | calfilter.cpp \ | 63 | calfilter.cpp \ |
64 | calformat.cpp \ | 64 | calformat.cpp \ |
65 | compat.cpp \ | 65 | compat.cpp \ |
66 | customproperties.cpp \ | 66 | customproperties.cpp \ |
67 | dummyscheduler.cpp \ | 67 | dummyscheduler.cpp \ |
68 | duration.cpp \ | 68 | duration.cpp \ |
69 | event.cpp \ | 69 | event.cpp \ |
70 | exceptions.cpp \ | 70 | exceptions.cpp \ |
71 | filestorage.cpp \ | 71 | filestorage.cpp \ |
72 | freebusy.cpp \ | 72 | freebusy.cpp \ |
73 | icaldrag.cpp \ | 73 | icaldrag.cpp \ |
74 | icalformat.cpp \ | 74 | icalformat.cpp \ |
75 | icalformatimpl.cpp \ | 75 | icalformatimpl.cpp \ |
76 | imipscheduler.cpp \ | 76 | imipscheduler.cpp \ |
77 | incidence.cpp \ | 77 | incidence.cpp \ |
78 | incidencebase.cpp \ | 78 | incidencebase.cpp \ |
79 | kincidenceformatter.cpp \ | 79 | kincidenceformatter.cpp \ |
80 | journal.cpp \ | 80 | journal.cpp \ |
81 | period.cpp \ | 81 | period.cpp \ |
82 | person.cpp \ | 82 | person.cpp \ |
83 | qtopiaformat.cpp \ | 83 | qtopiaformat.cpp \ |
84 | sharpformat.cpp \ | 84 | sharpformat.cpp \ |
85 | phoneformat.cpp \ | 85 | phoneformat.cpp \ |
86 | recurrence.cpp \ | 86 | recurrence.cpp \ |
87 | scheduler.cpp \ | 87 | scheduler.cpp \ |
88 | todo.cpp \ | 88 | todo.cpp \ |
89 | vcaldrag.cpp \ | 89 | vcaldrag.cpp \ |
90 | vcalformat.cpp \ | 90 | vcalformat.cpp \ |
91 | versit/vcc.c \ | 91 | versit/vcc.c \ |
92 | versit/vobject.c \ | 92 | versit/vobject.c \ |
93 | 93 | ||
diff --git a/libkcal/listbase.h b/libkcal/listbase.h index 085b13d..6c942ef 100644 --- a/libkcal/listbase.h +++ b/libkcal/listbase.h | |||
@@ -1,97 +1,99 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | #ifndef KCAL_LISTBASE_H | 21 | #ifndef KCAL_LISTBASE_H |
22 | #define KCAL_LISTBASE_H | 22 | #define KCAL_LISTBASE_H |
23 | 23 | ||
24 | #include <qvaluelist.h> | 24 | #include <q3valuelist.h> |
25 | //Added by qt3to4: | ||
26 | #include <Q3PtrList> | ||
25 | 27 | ||
26 | namespace KCal { | 28 | namespace KCal { |
27 | class Event; | 29 | class Event; |
28 | class Todo; | 30 | class Todo; |
29 | /** | 31 | /** |
30 | This class provides a template for lists of pointers. It extends QValueList<T | 32 | This class provides a template for lists of pointers. It extends QValueList<T |
31 | *> by auto delete funtionality known from QPtrList. | 33 | *> by auto delete funtionality known from QPtrList. |
32 | */ | 34 | */ |
33 | template<class T> | 35 | template<class T> |
34 | class ListBase : public QValueList<T *> | 36 | class ListBase : public Q3ValueList<T *> |
35 | { | 37 | { |
36 | public: | 38 | public: |
37 | ListBase() | 39 | ListBase() |
38 | : QValueList<T *>(), mAutoDelete( false ) | 40 | : Q3ValueList<T *>(), mAutoDelete( false ) |
39 | { | 41 | { |
40 | } | 42 | } |
41 | 43 | ||
42 | ListBase( const ListBase &l ) | 44 | ListBase( const ListBase &l ) |
43 | : QValueList<T *>( l ), mAutoDelete( false ) | 45 | : Q3ValueList<T *>( l ), mAutoDelete( false ) |
44 | { | 46 | { |
45 | } | 47 | } |
46 | 48 | ||
47 | ~ListBase() | 49 | ~ListBase() |
48 | { | 50 | { |
49 | if ( mAutoDelete ) { | 51 | if ( mAutoDelete ) { |
50 | QValueListIterator<T *> it; | 52 | Q3ValueListIterator<T *> it; |
51 | for( it = QValueList<T*>::begin(); it != QValueList<T*>::end(); ++it ) { | 53 | for( it = Q3ValueList<T*>::begin(); it != Q3ValueList<T*>::end(); ++it ) { |
52 | delete *it; | 54 | delete *it; |
53 | } | 55 | } |
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
57 | ListBase &operator=( const ListBase &l ) | 59 | ListBase &operator=( const ListBase &l ) |
58 | { | 60 | { |
59 | if ( this == &l ) return *this; | 61 | if ( this == &l ) return *this; |
60 | QValueList<T *>::operator=( l ); | 62 | Q3ValueList<T *>::operator=( l ); |
61 | return *this; | 63 | return *this; |
62 | } | 64 | } |
63 | 65 | ||
64 | void setAutoDelete( bool autoDelete ) | 66 | void setAutoDelete( bool autoDelete ) |
65 | { | 67 | { |
66 | mAutoDelete = autoDelete; | 68 | mAutoDelete = autoDelete; |
67 | } | 69 | } |
68 | 70 | ||
69 | bool removeRef( T *t ) | 71 | bool removeRef( T *t ) |
70 | { | 72 | { |
71 | QValueListIterator<T *> it = find( t ); | 73 | Q3ValueListIterator<T *> it = find( t ); |
72 | if ( it == QValueList<T*>::end() ) { | 74 | if ( it == Q3ValueList<T*>::end() ) { |
73 | return false; | 75 | return false; |
74 | } else { | 76 | } else { |
75 | if ( mAutoDelete ) delete t; | 77 | if ( mAutoDelete ) delete t; |
76 | remove( it ); | 78 | remove( it ); |
77 | return true; | 79 | return true; |
78 | } | 80 | } |
79 | } | 81 | } |
80 | void fill ( QPtrList<T> list ) { | 82 | void fill ( Q3PtrList<T> list ) { |
81 | QPtrListIterator<T> it (list); | 83 | Q3PtrListIterator<T> it (list); |
82 | T *item; | 84 | T *item; |
83 | while ( (item = it.current()) != 0 ) { | 85 | while ( (item = it.current()) != 0 ) { |
84 | append( item ); | 86 | append( item ); |
85 | ++it; | 87 | ++it; |
86 | } | 88 | } |
87 | 89 | ||
88 | } | 90 | } |
89 | 91 | ||
90 | 92 | ||
91 | private: | 93 | private: |
92 | bool mAutoDelete; | 94 | bool mAutoDelete; |
93 | }; | 95 | }; |
94 | 96 | ||
95 | } | 97 | } |
96 | 98 | ||
97 | #endif | 99 | #endif |
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 900fc04..794e4b4 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -1,620 +1,621 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> | 4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <q3ptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qclipboard.h> | 28 | #include <qclipboard.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <q3textstream.h> |
31 | #include <qtextcodec.h> | 31 | #include <qtextcodec.h> |
32 | #include <qdir.h> | 32 | #include <qdir.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <QDesktopWidget> | ||
34 | 35 | ||
35 | #include <kdebug.h> | 36 | #include <kdebug.h> |
36 | #include <klocale.h> | 37 | #include <klocale.h> |
37 | #include <kglobal.h> | 38 | #include <kglobal.h> |
38 | #include <kmessagebox.h> | 39 | #include <kmessagebox.h> |
39 | #include <phoneaccess.h> | 40 | #include <phoneaccess.h> |
40 | 41 | ||
41 | #include "calendar.h" | 42 | #include "calendar.h" |
42 | #include "alarm.h" | 43 | #include "alarm.h" |
43 | #include "recurrence.h" | 44 | #include "recurrence.h" |
44 | #include "calendarlocal.h" | 45 | #include "calendarlocal.h" |
45 | 46 | ||
46 | #include "phoneformat.h" | 47 | #include "phoneformat.h" |
47 | #include "syncdefines.h" | 48 | #include "syncdefines.h" |
48 | 49 | ||
49 | using namespace KCal; | 50 | using namespace KCal; |
50 | class PhoneParser : public QObject | 51 | class PhoneParser : public QObject |
51 | { | 52 | { |
52 | public: | 53 | public: |
53 | PhoneParser( ) { | 54 | PhoneParser( ) { |
54 | ; | 55 | ; |
55 | } | 56 | } |
56 | 57 | ||
57 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) | 58 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) |
58 | { | 59 | { |
59 | QString datestr; | 60 | QString datestr; |
60 | QString timestr; | 61 | QString timestr; |
61 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 62 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
62 | QDateTime dt; | 63 | QDateTime dt; |
63 | if (useTZ) | 64 | if (useTZ) |
64 | dt = dti.addSecs ( -(offset*60)); | 65 | dt = dti.addSecs ( -(offset*60)); |
65 | else | 66 | else |
66 | dt = dti; | 67 | dt = dti; |
67 | if(dt.date().isValid()){ | 68 | if(dt.date().isValid()){ |
68 | const QDate& date = dt.date(); | 69 | const QDate& date = dt.date(); |
69 | datestr.sprintf("%04d%02d%02d", | 70 | datestr.sprintf("%04d%02d%02d", |
70 | date.year(), date.month(), date.day()); | 71 | date.year(), date.month(), date.day()); |
71 | } | 72 | } |
72 | if(dt.time().isValid()){ | 73 | if(dt.time().isValid()){ |
73 | const QTime& time = dt.time(); | 74 | const QTime& time = dt.time(); |
74 | timestr.sprintf("T%02d%02d%02d", | 75 | timestr.sprintf("T%02d%02d%02d", |
75 | time.hour(), time.minute(), time.second()); | 76 | time.hour(), time.minute(), time.second()); |
76 | } | 77 | } |
77 | return datestr + timestr; | 78 | return datestr + timestr; |
78 | } | 79 | } |
79 | 80 | ||
80 | 81 | ||
81 | }; | 82 | }; |
82 | 83 | ||
83 | 84 | ||
84 | 85 | ||
85 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 86 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
86 | { | 87 | { |
87 | mProfileName = profileName; | 88 | mProfileName = profileName; |
88 | PhoneAccess::writeConfig( device, connection, model ); | 89 | PhoneAccess::writeConfig( device, connection, model ); |
89 | } | 90 | } |
90 | 91 | ||
91 | PhoneFormat::~PhoneFormat() | 92 | PhoneFormat::~PhoneFormat() |
92 | { | 93 | { |
93 | } | 94 | } |
94 | 95 | ||
95 | #if 0 | 96 | #if 0 |
96 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 97 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
97 | { | 98 | { |
98 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 99 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
99 | s->ConfigNum = 1; | 100 | s->ConfigNum = 1; |
100 | GSM_Config *cfg = &s->Config[0]; | 101 | GSM_Config *cfg = &s->Config[0]; |
101 | if ( ! mConnection.isEmpty() ) { | 102 | if ( ! mConnection.isEmpty() ) { |
102 | cfg->Connection = strdup(mConnection.latin1()); | 103 | cfg->Connection = strdup(mConnection.latin1()); |
103 | cfg->DefaultConnection = false; | 104 | cfg->DefaultConnection = false; |
104 | qDebug("Connection set %s ", cfg->Connection ); | 105 | qDebug("Connection set %s ", cfg->Connection ); |
105 | 106 | ||
106 | } | 107 | } |
107 | if ( ! mDevice.isEmpty() ) { | 108 | if ( ! mDevice.isEmpty() ) { |
108 | cfg->Device = strdup(mDevice.latin1()); | 109 | cfg->Device = strdup(mDevice.latin1()); |
109 | cfg->DefaultDevice = false; | 110 | cfg->DefaultDevice = false; |
110 | qDebug("Device set %s ", cfg->Device); | 111 | qDebug("Device set %s ", cfg->Device); |
111 | 112 | ||
112 | } | 113 | } |
113 | if ( ! mModel.isEmpty() ) { | 114 | if ( ! mModel.isEmpty() ) { |
114 | strcpy(cfg->Model,mModel.latin1() ); | 115 | strcpy(cfg->Model,mModel.latin1() ); |
115 | cfg->DefaultModel = false; | 116 | cfg->DefaultModel = false; |
116 | qDebug("Model set %s ",cfg->Model ); | 117 | qDebug("Model set %s ",cfg->Model ); |
117 | } | 118 | } |
118 | int error=GSM_InitConnection(s,3); | 119 | int error=GSM_InitConnection(s,3); |
119 | return error; | 120 | return error; |
120 | } | 121 | } |
121 | #endif | 122 | #endif |
122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 123 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
123 | { | 124 | { |
124 | QStringList attList; | 125 | QStringList attList; |
125 | if ( todo->hasDueDate() ) | 126 | if ( todo->hasDueDate() ) |
126 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 127 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
127 | attList << todo->summary(); | 128 | attList << todo->summary(); |
128 | QString completedString = "no"; | 129 | QString completedString = "no"; |
129 | if ( todo->isCompleted() ) | 130 | if ( todo->isCompleted() ) |
130 | completedString = "yes"; | 131 | completedString = "yes"; |
131 | attList << completedString; | 132 | attList << completedString; |
132 | int prio = todo->priority(); | 133 | int prio = todo->priority(); |
133 | if( prio == 2 ) prio = 1; | 134 | if( prio == 2 ) prio = 1; |
134 | if (prio == 4 ) prio = 5 ; | 135 | if (prio == 4 ) prio = 5 ; |
135 | attList << QString::number( prio ); | 136 | attList << QString::number( prio ); |
136 | QString alarmString = "na"; | 137 | QString alarmString = "na"; |
137 | Alarm *alarm; | 138 | Alarm *alarm; |
138 | if ( todo->alarms().count() > 0 ) { | 139 | if ( todo->alarms().count() > 0 ) { |
139 | alarm = todo->alarms().first(); | 140 | alarm = todo->alarms().first(); |
140 | if ( alarm->enabled() ) { | 141 | if ( alarm->enabled() ) { |
141 | alarmString = QString::number(alarm->offset() ); | 142 | alarmString = QString::number(alarm->offset() ); |
142 | } | 143 | } |
143 | } | 144 | } |
144 | attList << alarmString; | 145 | attList << alarmString; |
145 | attList << todo->categoriesStr(); | 146 | attList << todo->categoriesStr(); |
146 | attList << todo->secrecyStr(); | 147 | attList << todo->secrecyStr(); |
147 | return PhoneFormat::getCsum(attList ); | 148 | return PhoneFormat::getCsum(attList ); |
148 | 149 | ||
149 | } | 150 | } |
150 | ulong PhoneFormat::getCsumEvent( Event* event ) | 151 | ulong PhoneFormat::getCsumEvent( Event* event ) |
151 | { | 152 | { |
152 | QStringList attList; | 153 | QStringList attList; |
153 | attList << PhoneParser::dtToString ( event->dtStart() ); | 154 | attList << PhoneParser::dtToString ( event->dtStart() ); |
154 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 155 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
155 | attList << event->summary(); | 156 | attList << event->summary(); |
156 | attList << event->location(); | 157 | attList << event->location(); |
157 | QString alarmString = "na"; | 158 | QString alarmString = "na"; |
158 | Alarm *alarm; | 159 | Alarm *alarm; |
159 | if ( event->alarms().count() > 0 ) { | 160 | if ( event->alarms().count() > 0 ) { |
160 | alarm = event->alarms().first(); | 161 | alarm = event->alarms().first(); |
161 | if ( alarm->enabled() ) { | 162 | if ( alarm->enabled() ) { |
162 | alarmString = QString::number( alarm->offset() ); | 163 | alarmString = QString::number( alarm->offset() ); |
163 | } | 164 | } |
164 | } | 165 | } |
165 | attList << alarmString; | 166 | attList << alarmString; |
166 | Recurrence* rec = event->recurrence(); | 167 | Recurrence* rec = event->recurrence(); |
167 | QStringList list; | 168 | QStringList list; |
168 | bool writeEndDate = false; | 169 | bool writeEndDate = false; |
169 | switch ( rec->doesRecur() ) | 170 | switch ( rec->doesRecur() ) |
170 | { | 171 | { |
171 | case Recurrence::rDaily: // 0 | 172 | case Recurrence::rDaily: // 0 |
172 | list.append( "0" ); | 173 | list.append( "0" ); |
173 | list.append( QString::number( rec->frequency() ));//12 | 174 | list.append( QString::number( rec->frequency() ));//12 |
174 | list.append( "0" ); | 175 | list.append( "0" ); |
175 | list.append( "0" ); | 176 | list.append( "0" ); |
176 | writeEndDate = true; | 177 | writeEndDate = true; |
177 | break; | 178 | break; |
178 | case Recurrence::rWeekly:// 1 | 179 | case Recurrence::rWeekly:// 1 |
179 | list.append( "1" ); | 180 | list.append( "1" ); |
180 | list.append( QString::number( rec->frequency()) );//12 | 181 | list.append( QString::number( rec->frequency()) );//12 |
181 | list.append( "0" ); | 182 | list.append( "0" ); |
182 | { | 183 | { |
183 | int days = 0; | 184 | int days = 0; |
184 | QBitArray weekDays = rec->days(); | 185 | QBitArray weekDays = rec->days(); |
185 | int i; | 186 | int i; |
186 | for( i = 1; i <= 7; ++i ) { | 187 | for( i = 1; i <= 7; ++i ) { |
187 | if ( weekDays[i-1] ) { | 188 | if ( weekDays[i-1] ) { |
188 | days += 1 << (i-1); | 189 | days += 1 << (i-1); |
189 | } | 190 | } |
190 | } | 191 | } |
191 | list.append( QString::number( days ) ); | 192 | list.append( QString::number( days ) ); |
192 | } | 193 | } |
193 | //pending weekdays | 194 | //pending weekdays |
194 | writeEndDate = true; | 195 | writeEndDate = true; |
195 | 196 | ||
196 | break; | 197 | break; |
197 | case Recurrence::rMonthlyPos:// 2 | 198 | case Recurrence::rMonthlyPos:// 2 |
198 | list.append( "2" ); | 199 | list.append( "2" ); |
199 | list.append( QString::number( rec->frequency()) );//12 | 200 | list.append( QString::number( rec->frequency()) );//12 |
200 | 201 | ||
201 | writeEndDate = true; | 202 | writeEndDate = true; |
202 | { | 203 | { |
203 | int count = 1; | 204 | int count = 1; |
204 | QPtrList<Recurrence::rMonthPos> rmp; | 205 | Q3PtrList<Recurrence::rMonthPos> rmp; |
205 | rmp = rec->monthPositions(); | 206 | rmp = rec->monthPositions(); |
206 | if ( rmp.first()->negative ) | 207 | if ( rmp.first()->negative ) |
207 | count = 5 - rmp.first()->rPos - 1; | 208 | count = 5 - rmp.first()->rPos - 1; |
208 | else | 209 | else |
209 | count = rmp.first()->rPos - 1; | 210 | count = rmp.first()->rPos - 1; |
210 | list.append( QString::number( count ) ); | 211 | list.append( QString::number( count ) ); |
211 | 212 | ||
212 | } | 213 | } |
213 | 214 | ||
214 | list.append( "0" ); | 215 | list.append( "0" ); |
215 | break; | 216 | break; |
216 | case Recurrence::rMonthlyDay:// 3 | 217 | case Recurrence::rMonthlyDay:// 3 |
217 | list.append( "3" ); | 218 | list.append( "3" ); |
218 | list.append( QString::number( rec->frequency()) );//12 | 219 | list.append( QString::number( rec->frequency()) );//12 |
219 | list.append( "0" ); | 220 | list.append( "0" ); |
220 | list.append( "0" ); | 221 | list.append( "0" ); |
221 | writeEndDate = true; | 222 | writeEndDate = true; |
222 | break; | 223 | break; |
223 | case Recurrence::rYearlyMonth://4 | 224 | case Recurrence::rYearlyMonth://4 |
224 | list.append( "4" ); | 225 | list.append( "4" ); |
225 | list.append( QString::number( rec->frequency()) );//12 | 226 | list.append( QString::number( rec->frequency()) );//12 |
226 | list.append( "0" ); | 227 | list.append( "0" ); |
227 | list.append( "0" ); | 228 | list.append( "0" ); |
228 | writeEndDate = true; | 229 | writeEndDate = true; |
229 | break; | 230 | break; |
230 | 231 | ||
231 | default: | 232 | default: |
232 | list.append( "255" ); | 233 | list.append( "255" ); |
233 | list.append( QString() ); | 234 | list.append( QString() ); |
234 | list.append( "0" ); | 235 | list.append( "0" ); |
235 | list.append( QString() ); | 236 | list.append( QString() ); |
236 | list.append( "0" ); | 237 | list.append( "0" ); |
237 | list.append( "20991231T000000" ); | 238 | list.append( "20991231T000000" ); |
238 | break; | 239 | break; |
239 | } | 240 | } |
240 | if ( writeEndDate ) { | 241 | if ( writeEndDate ) { |
241 | 242 | ||
242 | if ( rec->endDate().isValid() ) { // 15 + 16 | 243 | if ( rec->endDate().isValid() ) { // 15 + 16 |
243 | list.append( "1" ); | 244 | list.append( "1" ); |
244 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 245 | list.append( PhoneParser::dtToString( (QDateTime)rec->endDate()) ); |
245 | } else { | 246 | } else { |
246 | list.append( "0" ); | 247 | list.append( "0" ); |
247 | list.append( "20991231T000000" ); | 248 | list.append( "20991231T000000" ); |
248 | } | 249 | } |
249 | 250 | ||
250 | } | 251 | } |
251 | attList << list.join(""); | 252 | attList << list.join(""); |
252 | attList << event->categoriesStr(); | 253 | attList << event->categoriesStr(); |
253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 254 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
254 | 255 | ||
255 | attList << event->secrecyStr(); | 256 | attList << event->secrecyStr(); |
256 | return PhoneFormat::getCsum(attList ); | 257 | return PhoneFormat::getCsum(attList ); |
257 | } | 258 | } |
258 | ulong PhoneFormat::getCsum( const QStringList & attList) | 259 | ulong PhoneFormat::getCsum( const QStringList & attList) |
259 | { | 260 | { |
260 | int max = attList.count(); | 261 | int max = attList.count(); |
261 | ulong cSum = 0; | 262 | ulong cSum = 0; |
262 | int j,k,i; | 263 | int j,k,i; |
263 | int add; | 264 | int add; |
264 | for ( i = 0; i < max ; ++i ) { | 265 | for ( i = 0; i < max ; ++i ) { |
265 | QString s = attList[i]; | 266 | QString s = attList[i]; |
266 | if ( ! s.isEmpty() ){ | 267 | if ( ! s.isEmpty() ){ |
267 | j = s.length(); | 268 | j = s.length(); |
268 | for ( k = 0; k < j; ++k ) { | 269 | for ( k = 0; k < j; ++k ) { |
269 | int mul = k +1; | 270 | int mul = k +1; |
270 | add = s[k].unicode (); | 271 | add = s[k].unicode (); |
271 | if ( k < 16 ) | 272 | if ( k < 16 ) |
272 | mul = mul * mul; | 273 | mul = mul * mul; |
273 | int ii = i+1; | 274 | int ii = i+1; |
274 | add = add * mul *ii*ii*ii; | 275 | add = add * mul *ii*ii*ii; |
275 | cSum += add; | 276 | cSum += add; |
276 | } | 277 | } |
277 | } | 278 | } |
278 | 279 | ||
279 | } | 280 | } |
280 | //QString dump = attList.join(","); | 281 | //QString dump = attList.join(","); |
281 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 282 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
282 | 283 | ||
283 | return cSum; | 284 | return cSum; |
284 | 285 | ||
285 | } | 286 | } |
286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 287 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
287 | #include <stdlib.h> | 288 | #include <stdlib.h> |
288 | #define DEBUGMODE false | 289 | #define DEBUGMODE false |
289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 290 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
290 | { | 291 | { |
291 | 292 | ||
292 | QString fileName; | 293 | QString fileName; |
293 | #ifdef DESKTOP_VERSION | 294 | #ifdef DESKTOP_VERSION |
294 | fileName = locateLocal("tmp", "phonefile.vcs"); | 295 | fileName = locateLocal("tmp", "phonefile.vcs"); |
295 | #else | 296 | #else |
296 | fileName = "/tmp/phonefile.vcs"; | 297 | fileName = "/tmp/phonefile.vcs"; |
297 | #endif | 298 | #endif |
298 | QString command; | 299 | QString command; |
299 | if ( ! PhoneAccess::readFromPhone( fileName )) { | 300 | if ( ! PhoneAccess::readFromPhone( fileName )) { |
300 | return false; | 301 | return false; |
301 | } | 302 | } |
302 | VCalFormat vfload; | 303 | VCalFormat vfload; |
303 | vfload.setLocalTime ( true ); | 304 | vfload.setLocalTime ( true ); |
304 | qDebug("loading file ..."); | 305 | qDebug("loading file ..."); |
305 | 306 | ||
306 | if ( ! vfload.load( calendar, fileName ) ) | 307 | if ( ! vfload.load( calendar, fileName ) ) |
307 | return false; | 308 | return false; |
308 | QPtrList<Event> er = calendar->rawEvents(); | 309 | Q3PtrList<Event> er = calendar->rawEvents(); |
309 | Event* ev = er.first(); | 310 | Event* ev = er.first(); |
310 | qDebug("reading events... "); | 311 | qDebug("reading events... "); |
311 | while ( ev ) { | 312 | while ( ev ) { |
312 | QStringList cat = ev->categories(); | 313 | QStringList cat = ev->categories(); |
313 | if ( cat.contains( "MeetingDEF" )) { | 314 | if ( cat.contains( "MeetingDEF" )) { |
314 | ev->setCategories( QStringList() ); | 315 | ev->setCategories( QStringList() ); |
315 | } else | 316 | } else |
316 | if ( cat.contains( "Birthday" )) { | 317 | if ( cat.contains( "Birthday" )) { |
317 | ev->setFloats( true ); | 318 | ev->setFloats( true ); |
318 | QDate da = ev->dtStart().date(); | 319 | QDate da = ev->dtStart().date(); |
319 | ev->setDtStart( QDateTime( da) ); | 320 | ev->setDtStart( QDateTime( da) ); |
320 | ev->setDtEnd( QDateTime( da.addDays(1)) ); | 321 | ev->setDtEnd( QDateTime( da.addDays(1)) ); |
321 | 322 | ||
322 | } | 323 | } |
323 | uint cSum; | 324 | uint cSum; |
324 | cSum = PhoneFormat::getCsumEvent( ev ); | 325 | cSum = PhoneFormat::getCsumEvent( ev ); |
325 | int id = ev->pilotId(); | 326 | int id = ev->pilotId(); |
326 | Event *event; | 327 | Event *event; |
327 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 328 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
328 | if ( event ) { | 329 | if ( event ) { |
329 | event = (Event*)event->clone(); | 330 | event = (Event*)event->clone(); |
330 | copyEvent( event, ev ); | 331 | copyEvent( event, ev ); |
331 | calendar->deleteEvent( ev ); | 332 | calendar->deleteEvent( ev ); |
332 | calendar->addEvent( event); | 333 | calendar->addEvent( event); |
333 | } | 334 | } |
334 | else | 335 | else |
335 | event = ev; | 336 | event = ev; |
336 | event->setCsum( mProfileName, QString::number( cSum )); | 337 | event->setCsum( mProfileName, QString::number( cSum )); |
337 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 338 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
338 | event->setID( mProfileName,QString::number( id ) ); | 339 | event->setID( mProfileName,QString::number( id ) ); |
339 | ev = er.next(); | 340 | ev = er.next(); |
340 | } | 341 | } |
341 | { | 342 | { |
342 | qDebug("reading todos... "); | 343 | qDebug("reading todos... "); |
343 | QPtrList<Todo> tr = calendar->rawTodos(); | 344 | Q3PtrList<Todo> tr = calendar->rawTodos(); |
344 | Todo* ev = tr.first(); | 345 | Todo* ev = tr.first(); |
345 | while ( ev ) { | 346 | while ( ev ) { |
346 | 347 | ||
347 | QStringList cat = ev->categories(); | 348 | QStringList cat = ev->categories(); |
348 | if ( cat.contains( "MeetingDEF" )) { | 349 | if ( cat.contains( "MeetingDEF" )) { |
349 | ev->setCategories( QStringList() ); | 350 | ev->setCategories( QStringList() ); |
350 | } | 351 | } |
351 | int id = ev->pilotId(); | 352 | int id = ev->pilotId(); |
352 | uint cSum; | 353 | uint cSum; |
353 | cSum = PhoneFormat::getCsumTodo( ev ); | 354 | cSum = PhoneFormat::getCsumTodo( ev ); |
354 | Todo *event; | 355 | Todo *event; |
355 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 356 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
356 | if ( event ) { | 357 | if ( event ) { |
357 | //qDebug("copy todo %s ", event->summary().latin1()); | 358 | //qDebug("copy todo %s ", event->summary().latin1()); |
358 | 359 | ||
359 | event = (Todo*)event->clone(); | 360 | event = (Todo*)event->clone(); |
360 | copyTodo( event, ev ); | 361 | copyTodo( event, ev ); |
361 | calendar->deleteTodo( ev ); | 362 | calendar->deleteTodo( ev ); |
362 | calendar->addTodo( event); | 363 | calendar->addTodo( event); |
363 | } | 364 | } |
364 | else | 365 | else |
365 | event = ev; | 366 | event = ev; |
366 | event->setCsum( mProfileName, QString::number( cSum )); | 367 | event->setCsum( mProfileName, QString::number( cSum )); |
367 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 368 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
368 | event->setID( mProfileName,QString::number( id ) ); | 369 | event->setID( mProfileName,QString::number( id ) ); |
369 | ev = tr.next(); | 370 | ev = tr.next(); |
370 | } | 371 | } |
371 | } | 372 | } |
372 | return true; | 373 | return true; |
373 | } | 374 | } |
374 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 375 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
375 | { | 376 | { |
376 | if ( from->dtStart().isValid() ) | 377 | if ( from->dtStart().isValid() ) |
377 | to->setDtStart( from->dtStart() ); | 378 | to->setDtStart( from->dtStart() ); |
378 | if ( from->dtEnd().isValid() ) | 379 | if ( from->dtEnd().isValid() ) |
379 | to->setDtEnd( from->dtEnd() ); | 380 | to->setDtEnd( from->dtEnd() ); |
380 | if ( !from->location().isEmpty() ) | 381 | if ( !from->location().isEmpty() ) |
381 | to->setLocation( from->location() ); | 382 | to->setLocation( from->location() ); |
382 | if ( !from->description().isEmpty() ) | 383 | if ( !from->description().isEmpty() ) |
383 | to->setDescription( from->description() ); | 384 | to->setDescription( from->description() ); |
384 | if ( !from->summary().isEmpty() ) | 385 | if ( !from->summary().isEmpty() ) |
385 | to->setSummary( from->summary() ); | 386 | to->setSummary( from->summary() ); |
386 | 387 | ||
387 | if ( from->alarms().count() ) { | 388 | if ( from->alarms().count() ) { |
388 | to->clearAlarms(); | 389 | to->clearAlarms(); |
389 | Alarm *a = from->alarms().first(); | 390 | Alarm *a = from->alarms().first(); |
390 | Alarm *b = to->newAlarm( ); | 391 | Alarm *b = to->newAlarm( ); |
391 | b->setEnabled( a->enabled() ); | 392 | b->setEnabled( a->enabled() ); |
392 | b->setStartOffset(Duration( a->offset() ) ); | 393 | b->setStartOffset(Duration( a->offset() ) ); |
393 | 394 | ||
394 | } | 395 | } |
395 | QStringList cat = to->categories(); | 396 | QStringList cat = to->categories(); |
396 | QStringList catFrom = from->categories(); | 397 | QStringList catFrom = from->categories(); |
397 | QString nCat; | 398 | QString nCat; |
398 | int iii; | 399 | int iii; |
399 | for ( iii = 0; iii < catFrom.count();++iii ) { | 400 | for ( iii = 0; iii < catFrom.count();++iii ) { |
400 | nCat = catFrom[iii]; | 401 | nCat = catFrom[iii]; |
401 | if ( !nCat.isEmpty() ) | 402 | if ( !nCat.isEmpty() ) |
402 | if ( !cat.contains( nCat )) { | 403 | if ( !cat.contains( nCat )) { |
403 | cat << nCat; | 404 | cat << nCat; |
404 | } | 405 | } |
405 | } | 406 | } |
406 | to->setCategories( cat ); | 407 | to->setCategories( cat ); |
407 | if ( from->doesRecur() ) { | 408 | if ( from->doesRecur() ) { |
408 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 409 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
409 | to->setRecurrence( r ) ; | 410 | to->setRecurrence( r ) ; |
410 | } | 411 | } |
411 | 412 | ||
412 | 413 | ||
413 | } | 414 | } |
414 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 415 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
415 | { | 416 | { |
416 | if ( from->hasStartDate() ) { | 417 | if ( from->hasStartDate() ) { |
417 | to->setHasStartDate( true ); | 418 | to->setHasStartDate( true ); |
418 | to->setDtStart( from->dtStart() ); | 419 | to->setDtStart( from->dtStart() ); |
419 | } | 420 | } |
420 | if ( from->hasDueDate() ){ | 421 | if ( from->hasDueDate() ){ |
421 | to->setHasDueDate( true ); | 422 | to->setHasDueDate( true ); |
422 | to->setDtDue( from->dtDue() ); | 423 | to->setDtDue( from->dtDue() ); |
423 | } | 424 | } |
424 | if ( !from->location().isEmpty() ) | 425 | if ( !from->location().isEmpty() ) |
425 | to->setLocation( from->location() ); | 426 | to->setLocation( from->location() ); |
426 | if ( !from->description().isEmpty() ) | 427 | if ( !from->description().isEmpty() ) |
427 | to->setDescription( from->description() ); | 428 | to->setDescription( from->description() ); |
428 | if ( !from->summary().isEmpty() ) | 429 | if ( !from->summary().isEmpty() ) |
429 | to->setSummary( from->summary() ); | 430 | to->setSummary( from->summary() ); |
430 | 431 | ||
431 | if ( from->alarms().count() ) { | 432 | if ( from->alarms().count() ) { |
432 | to->clearAlarms(); | 433 | to->clearAlarms(); |
433 | Alarm *a = from->alarms().first(); | 434 | Alarm *a = from->alarms().first(); |
434 | Alarm *b = to->newAlarm( ); | 435 | Alarm *b = to->newAlarm( ); |
435 | b->setEnabled( a->enabled() ); | 436 | b->setEnabled( a->enabled() ); |
436 | b->setStartOffset(Duration( a->offset() ) ); | 437 | b->setStartOffset(Duration( a->offset() ) ); |
437 | } | 438 | } |
438 | 439 | ||
439 | QStringList cat = to->categories(); | 440 | QStringList cat = to->categories(); |
440 | QStringList catFrom = from->categories(); | 441 | QStringList catFrom = from->categories(); |
441 | QString nCat; | 442 | QString nCat; |
442 | int iii; | 443 | int iii; |
443 | for ( iii = 0; iii < catFrom.count();++iii ) { | 444 | for ( iii = 0; iii < catFrom.count();++iii ) { |
444 | nCat = catFrom[iii]; | 445 | nCat = catFrom[iii]; |
445 | if ( !nCat.isEmpty() ) | 446 | if ( !nCat.isEmpty() ) |
446 | if ( !cat.contains( nCat )) { | 447 | if ( !cat.contains( nCat )) { |
447 | cat << nCat; | 448 | cat << nCat; |
448 | } | 449 | } |
449 | } | 450 | } |
450 | to->setCategories( cat ); | 451 | to->setCategories( cat ); |
451 | if ( from->isCompleted() ) { | 452 | if ( from->isCompleted() ) { |
452 | to->setCompleted( true ); | 453 | to->setCompleted( true ); |
453 | if( from->completed().isValid() ) | 454 | if( from->completed().isValid() ) |
454 | to->setCompleted( from->completed() ); | 455 | to->setCompleted( from->completed() ); |
455 | } else { | 456 | } else { |
456 | // set percentcomplete only, if to->isCompleted() | 457 | // set percentcomplete only, if to->isCompleted() |
457 | if ( to->isCompleted() ) | 458 | if ( to->isCompleted() ) |
458 | to->setPercentComplete(from->percentComplete()); | 459 | to->setPercentComplete(from->percentComplete()); |
459 | } | 460 | } |
460 | if( to->priority() == 2 && from->priority() == 1 ) | 461 | if( to->priority() == 2 && from->priority() == 1 ) |
461 | ; //skip | 462 | ; //skip |
462 | else if (to->priority() == 4 && from->priority() == 5 ) | 463 | else if (to->priority() == 4 && from->priority() == 5 ) |
463 | ; | 464 | ; |
464 | else | 465 | else |
465 | to->setPriority(from->priority()); | 466 | to->setPriority(from->priority()); |
466 | 467 | ||
467 | } | 468 | } |
468 | #include <qcstring.h> | 469 | #include <q3cstring.h> |
469 | 470 | ||
470 | void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum) | 471 | void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum) |
471 | { | 472 | { |
472 | inc->setID( mProfileName, id ); | 473 | inc->setID( mProfileName, id ); |
473 | inc->setCsum( mProfileName, csum); | 474 | inc->setCsum( mProfileName, csum); |
474 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 475 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
475 | 476 | ||
476 | } | 477 | } |
477 | 478 | ||
478 | bool PhoneFormat::writeToPhone( Calendar * calendar) | 479 | bool PhoneFormat::writeToPhone( Calendar * calendar) |
479 | { | 480 | { |
480 | #ifdef DESKTOP_VERSION | 481 | #ifdef DESKTOP_VERSION |
481 | QString fileName = locateLocal("tmp", "phonefile.vcs"); | 482 | QString fileName = locateLocal("tmp", "phonefile.vcs"); |
482 | #else | 483 | #else |
483 | QString fileName = "/tmp/phonefile.vcs"; | 484 | QString fileName = "/tmp/phonefile.vcs"; |
484 | #endif | 485 | #endif |
485 | 486 | ||
486 | VCalFormat vfsave; | 487 | VCalFormat vfsave; |
487 | vfsave.setLocalTime ( true ); | 488 | vfsave.setLocalTime ( true ); |
488 | QString id = calendar->timeZoneId(); | 489 | QString id = calendar->timeZoneId(); |
489 | calendar->setLocalTime(); | 490 | calendar->setLocalTime(); |
490 | if ( ! vfsave.save( calendar, fileName ) ) | 491 | if ( ! vfsave.save( calendar, fileName ) ) |
491 | return false; | 492 | return false; |
492 | calendar->setTimeZoneId( id ); | 493 | calendar->setTimeZoneId( id ); |
493 | return PhoneAccess::writeToPhone( fileName ); | 494 | return PhoneAccess::writeToPhone( fileName ); |
494 | } | 495 | } |
495 | bool PhoneFormat::save( Calendar *calendar) | 496 | bool PhoneFormat::save( Calendar *calendar) |
496 | { | 497 | { |
497 | 498 | ||
498 | 499 | ||
499 | // 1 remove events which should be deleted | 500 | // 1 remove events which should be deleted |
500 | QPtrList<Event> er = calendar->rawEvents(); | 501 | Q3PtrList<Event> er = calendar->rawEvents(); |
501 | Event* ev = er.first(); | 502 | Event* ev = er.first(); |
502 | while ( ev ) { | 503 | while ( ev ) { |
503 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 504 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
504 | calendar->deleteEvent( ev ); | 505 | calendar->deleteEvent( ev ); |
505 | } else { | 506 | } else { |
506 | 507 | ||
507 | } | 508 | } |
508 | ev = er.next(); | 509 | ev = er.next(); |
509 | } | 510 | } |
510 | // 2 remove todos which should be deleted | 511 | // 2 remove todos which should be deleted |
511 | QPtrList<Todo> tl = calendar->rawTodos(); | 512 | Q3PtrList<Todo> tl = calendar->rawTodos(); |
512 | Todo* to = tl.first(); | 513 | Todo* to = tl.first(); |
513 | while ( to ) { | 514 | while ( to ) { |
514 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 515 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
515 | calendar->deleteTodo( to ); | 516 | calendar->deleteTodo( to ); |
516 | } else { | 517 | } else { |
517 | if ( to->isCompleted()) { | 518 | if ( to->isCompleted()) { |
518 | calendar->deleteTodo( to ); | 519 | calendar->deleteTodo( to ); |
519 | } | 520 | } |
520 | } | 521 | } |
521 | to = tl.next(); | 522 | to = tl.next(); |
522 | } | 523 | } |
523 | // 3 save file | 524 | // 3 save file |
524 | if ( !writeToPhone( calendar ) ) | 525 | if ( !writeToPhone( calendar ) ) |
525 | return false; | 526 | return false; |
526 | QLabel status ( i18n(" Opening device ..."), 0 ); | 527 | QLabel status ( i18n(" Opening device ..."), 0 ); |
527 | int w = status.sizeHint().width()+20 ; | 528 | int w = status.sizeHint().width()+20 ; |
528 | if ( w < 200 ) w = 230; | 529 | if ( w < 200 ) w = 230; |
529 | int h = status.sizeHint().height()+20 ; | 530 | int h = status.sizeHint().height()+20 ; |
530 | int dw = QApplication::desktop()->width(); | 531 | int dw = QApplication::desktop()->width(); |
531 | int dh = QApplication::desktop()->height(); | 532 | int dh = QApplication::desktop()->height(); |
532 | status.setCaption(i18n("Writing to phone...") ); | 533 | status.setCaption(i18n("Writing to phone...") ); |
533 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 534 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
534 | QString message; | 535 | QString message; |
535 | status.show(); | 536 | status.show(); |
536 | status.raise(); | 537 | status.raise(); |
537 | qApp->processEvents(); | 538 | qApp->processEvents(); |
538 | // 5 reread data | 539 | // 5 reread data |
539 | message = i18n(" Rereading all data ... "); | 540 | message = i18n(" Rereading all data ... "); |
540 | status.setText ( message ); | 541 | status.setText ( message ); |
541 | qApp->processEvents(); | 542 | qApp->processEvents(); |
542 | CalendarLocal* calendarTemp = new CalendarLocal(); | 543 | CalendarLocal* calendarTemp = new CalendarLocal(); |
543 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 544 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
544 | if ( ! load( calendarTemp,calendar) ){ | 545 | if ( ! load( calendarTemp,calendar) ){ |
545 | qDebug("error reloading calendar "); | 546 | qDebug("error reloading calendar "); |
546 | delete calendarTemp; | 547 | delete calendarTemp; |
547 | return false; | 548 | return false; |
548 | } | 549 | } |
549 | // 6 compare data | 550 | // 6 compare data |
550 | 551 | ||
551 | //algo 6 compare event | 552 | //algo 6 compare event |
552 | er = calendar->rawEvents(); | 553 | er = calendar->rawEvents(); |
553 | ev = er.first(); | 554 | ev = er.first(); |
554 | message = i18n(" Comparing event # "); | 555 | message = i18n(" Comparing event # "); |
555 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 556 | Q3PtrList<Event> er1 = calendarTemp->rawEvents(); |
556 | Event* ev1; | 557 | Event* ev1; |
557 | int procCount = 0; | 558 | int procCount = 0; |
558 | while ( ev ) { | 559 | while ( ev ) { |
559 | //qDebug("event new ID %s",ev->summary().latin1()); | 560 | //qDebug("event new ID %s",ev->summary().latin1()); |
560 | status.setText ( message + QString::number ( ++procCount ) ); | 561 | status.setText ( message + QString::number ( ++procCount ) ); |
561 | qApp->processEvents(); | 562 | qApp->processEvents(); |
562 | ev1 = er1.first(); | 563 | ev1 = er1.first(); |
563 | while ( ev1 ) { | 564 | while ( ev1 ) { |
564 | if ( ev->contains( ev1 ) ) { | 565 | if ( ev->contains( ev1 ) ) { |
565 | afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName)); | 566 | afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName)); |
566 | er1.remove( ev1 ); | 567 | er1.remove( ev1 ); |
567 | break; | 568 | break; |
568 | } | 569 | } |
569 | ev1 = er1.next(); | 570 | ev1 = er1.next(); |
570 | } | 571 | } |
571 | if ( ! ev1 ) { | 572 | if ( ! ev1 ) { |
572 | // ev->removeID(mProfileName); | 573 | // ev->removeID(mProfileName); |
573 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 574 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
574 | } | 575 | } |
575 | 576 | ||
576 | 577 | ||
577 | ev = er.next(); | 578 | ev = er.next(); |
578 | } | 579 | } |
579 | //algo 6 compare todo | 580 | //algo 6 compare todo |
580 | tl = calendar->rawTodos(); | 581 | tl = calendar->rawTodos(); |
581 | to = tl.first(); | 582 | to = tl.first(); |
582 | procCount = 0; | 583 | procCount = 0; |
583 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 584 | Q3PtrList<Todo> tl1 = calendarTemp->rawTodos(); |
584 | Todo* to1 ; | 585 | Todo* to1 ; |
585 | message = i18n(" Comparing todo # "); | 586 | message = i18n(" Comparing todo # "); |
586 | while ( to ) { | 587 | while ( to ) { |
587 | status.setText ( message + QString::number ( ++procCount ) ); | 588 | status.setText ( message + QString::number ( ++procCount ) ); |
588 | qApp->processEvents(); | 589 | qApp->processEvents(); |
589 | Todo* to1 = tl1.first(); | 590 | Todo* to1 = tl1.first(); |
590 | while ( to1 ) { | 591 | while ( to1 ) { |
591 | if ( to->contains( to1 ) ) { | 592 | if ( to->contains( to1 ) ) { |
592 | afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName)); | 593 | afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName)); |
593 | tl1.remove( to1 ); | 594 | tl1.remove( to1 ); |
594 | break; | 595 | break; |
595 | } | 596 | } |
596 | to1 = tl1.next(); | 597 | to1 = tl1.next(); |
597 | } | 598 | } |
598 | if ( ! to1 ) { | 599 | if ( ! to1 ) { |
599 | //to->removeID(mProfileName); | 600 | //to->removeID(mProfileName); |
600 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 601 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
601 | } | 602 | } |
602 | 603 | ||
603 | to = tl.next(); | 604 | to = tl.next(); |
604 | } | 605 | } |
605 | delete calendarTemp; | 606 | delete calendarTemp; |
606 | return true; | 607 | return true; |
607 | 608 | ||
608 | 609 | ||
609 | 610 | ||
610 | } | 611 | } |
611 | 612 | ||
612 | 613 | ||
613 | QString PhoneFormat::toString( Calendar * ) | 614 | QString PhoneFormat::toString( Calendar * ) |
614 | { | 615 | { |
615 | return QString::null; | 616 | return QString::null; |
616 | } | 617 | } |
617 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 618 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
618 | { | 619 | { |
619 | return false; | 620 | return false; |
620 | } | 621 | } |
diff --git a/libkcal/qtopiaformat.cpp b/libkcal/qtopiaformat.cpp index 0a4a031..2dfe1a4 100644 --- a/libkcal/qtopiaformat.cpp +++ b/libkcal/qtopiaformat.cpp | |||
@@ -1,333 +1,333 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qptrlist.h> | 24 | #include <q3ptrlist.h> |
25 | #include <qregexp.h> | 25 | #include <qregexp.h> |
26 | #include <qclipboard.h> | 26 | #include <qclipboard.h> |
27 | #include <qfile.h> | 27 | #include <qfile.h> |
28 | #include <qtextstream.h> | 28 | #include <q3textstream.h> |
29 | #include <qxml.h> | 29 | #include <qxml.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | 33 | ||
34 | #include "calendar.h" | 34 | #include "calendar.h" |
35 | #include "calendarlocal.h" | 35 | #include "calendarlocal.h" |
36 | 36 | ||
37 | #include "qtopiaformat.h" | 37 | #include "qtopiaformat.h" |
38 | 38 | ||
39 | using namespace KCal; | 39 | using namespace KCal; |
40 | 40 | ||
41 | class QtopiaParser : public QXmlDefaultHandler | 41 | class QtopiaParser : public QXmlDefaultHandler |
42 | { | 42 | { |
43 | public: | 43 | public: |
44 | QtopiaParser( Calendar *calendar ) : mCalendar( calendar ) { | 44 | QtopiaParser( Calendar *calendar ) : mCalendar( calendar ) { |
45 | oldCategories = 0; | 45 | oldCategories = 0; |
46 | } | 46 | } |
47 | 47 | ||
48 | bool startElement( const QString &, const QString &, const QString & qName, | 48 | bool startElement( const QString &, const QString &, const QString & qName, |
49 | const QXmlAttributes &attributes ) | 49 | const QXmlAttributes &attributes ) |
50 | { | 50 | { |
51 | if ( qName == "event" ) { | 51 | if ( qName == "event" ) { |
52 | Event *event = new Event; | 52 | Event *event = new Event; |
53 | QString uid = "Qtopia" + attributes.value( "uid" ); | 53 | QString uid = "Qtopia" + attributes.value( "uid" ); |
54 | // event->setUid( uid ); | 54 | // event->setUid( uid ); |
55 | 55 | ||
56 | event->setSummary( attributes.value( "description" ) ); | 56 | event->setSummary( attributes.value( "description" ) ); |
57 | event->setLocation( attributes.value( "location" ) ); | 57 | event->setLocation( attributes.value( "location" ) ); |
58 | event->setDescription( attributes.value( "note" ) ); | 58 | event->setDescription( attributes.value( "note" ) ); |
59 | event->setDtStart( toDateTime( attributes.value( "start" ) ) ); | 59 | event->setDtStart( toDateTime( attributes.value( "start" ) ) ); |
60 | event->setDtEnd( toDateTime( attributes.value( "end" ) ) ); | 60 | event->setDtEnd( toDateTime( attributes.value( "end" ) ) ); |
61 | 61 | ||
62 | if ( attributes.value( "type" ) == "AllDay" ) { | 62 | if ( attributes.value( "type" ) == "AllDay" ) { |
63 | event->setFloats( true ); | 63 | event->setFloats( true ); |
64 | } else { | 64 | } else { |
65 | event->setFloats( false ); | 65 | event->setFloats( false ); |
66 | } | 66 | } |
67 | 67 | ||
68 | QString rtype = attributes.value( "rtype" ); | 68 | QString rtype = attributes.value( "rtype" ); |
69 | if ( !rtype.isEmpty() ) { | 69 | if ( !rtype.isEmpty() ) { |
70 | QDate startDate = event->dtStart().date(); | 70 | QDate startDate = event->dtStart().date(); |
71 | 71 | ||
72 | QString freqStr = attributes.value( "rfreq" ); | 72 | QString freqStr = attributes.value( "rfreq" ); |
73 | int freq = freqStr.toInt(); | 73 | int freq = freqStr.toInt(); |
74 | 74 | ||
75 | QString hasEndDateStr = attributes.value( "rhasenddate" ); | 75 | QString hasEndDateStr = attributes.value( "rhasenddate" ); |
76 | bool hasEndDate = hasEndDateStr == "1"; | 76 | bool hasEndDate = hasEndDateStr == "1"; |
77 | 77 | ||
78 | QString endDateStr = attributes.value( "enddt" ); | 78 | QString endDateStr = attributes.value( "enddt" ); |
79 | QDate endDate = toDateTime( endDateStr ).date(); | 79 | QDate endDate = toDateTime( endDateStr ).date(); |
80 | 80 | ||
81 | QString weekDaysStr = attributes.value( "rweekdays" ); | 81 | QString weekDaysStr = attributes.value( "rweekdays" ); |
82 | int weekDaysNum = weekDaysStr.toInt(); | 82 | int weekDaysNum = weekDaysStr.toInt(); |
83 | if ( weekDaysNum == 0 ) | 83 | if ( weekDaysNum == 0 ) |
84 | weekDaysNum = (1 << (event->dtStart().date().dayOfWeek()-1)); | 84 | weekDaysNum = (1 << (event->dtStart().date().dayOfWeek()-1)); |
85 | 85 | ||
86 | QBitArray weekDays( 7 ); | 86 | QBitArray weekDays( 7 ); |
87 | weekDays.fill( false ); | 87 | weekDays.fill( false ); |
88 | int i; | 88 | int i; |
89 | for( i = 0; i < 7; ++i ) { | 89 | for( i = 0; i < 7; ++i ) { |
90 | weekDays.setBit( i , ( 1 << i ) & weekDaysNum ); | 90 | weekDays.setBit( i , ( 1 << i ) & weekDaysNum ); |
91 | qDebug("%d %d %d ",i, weekDaysNum, weekDays.at(i) ); | 91 | qDebug("%d %d %d ",i, weekDaysNum, weekDays.at(i) ); |
92 | } | 92 | } |
93 | 93 | ||
94 | QString posStr = attributes.value( "rposition" ); | 94 | QString posStr = attributes.value( "rposition" ); |
95 | int pos = posStr.toInt(); | 95 | int pos = posStr.toInt(); |
96 | 96 | ||
97 | Recurrence *r = event->recurrence(); | 97 | Recurrence *r = event->recurrence(); |
98 | 98 | ||
99 | if ( rtype == "Daily" ) { | 99 | if ( rtype == "Daily" ) { |
100 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 100 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
101 | else r->setDaily( freq, -1 ); | 101 | else r->setDaily( freq, -1 ); |
102 | } else if ( rtype == "Weekly" ) { | 102 | } else if ( rtype == "Weekly" ) { |
103 | // fix needed here | 103 | // fix needed here |
104 | // rweekdays not set in XML file | 104 | // rweekdays not set in XML file |
105 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 105 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
106 | else r->setWeekly( freq, weekDays, -1 ); | 106 | else r->setWeekly( freq, weekDays, -1 ); |
107 | } else if ( rtype == "MonthlyDate" ) { | 107 | } else if ( rtype == "MonthlyDate" ) { |
108 | if ( hasEndDate ) | 108 | if ( hasEndDate ) |
109 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 109 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
110 | else | 110 | else |
111 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 111 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
112 | r->addMonthlyDay( startDate.day() ); | 112 | r->addMonthlyDay( startDate.day() ); |
113 | } else if ( rtype == "MonthlyDay" ) { | 113 | } else if ( rtype == "MonthlyDay" ) { |
114 | if ( hasEndDate ) | 114 | if ( hasEndDate ) |
115 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 115 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
116 | else | 116 | else |
117 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 117 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
118 | QBitArray days( 7 ); | 118 | QBitArray days( 7 ); |
119 | days.fill( false ); | 119 | days.fill( false ); |
120 | days.setBit( startDate.dayOfWeek() - 1 ); | 120 | days.setBit( startDate.dayOfWeek() - 1 ); |
121 | r->addMonthlyPos( pos, days ); | 121 | r->addMonthlyPos( pos, days ); |
122 | } else if ( rtype == "Yearly" ) { | 122 | } else if ( rtype == "Yearly" ) { |
123 | if ( hasEndDate ) | 123 | if ( hasEndDate ) |
124 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 124 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
125 | else | 125 | else |
126 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 126 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
127 | r->addYearlyNum( startDate.month() ); | 127 | r->addYearlyNum( startDate.month() ); |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | QString categoryList = attributes.value( "categories" ); | 131 | QString categoryList = attributes.value( "categories" ); |
132 | event->setCategories( lookupCategories( categoryList ) ); | 132 | event->setCategories( lookupCategories( categoryList ) ); |
133 | 133 | ||
134 | QString alarmStr = attributes.value( "alarm" ); | 134 | QString alarmStr = attributes.value( "alarm" ); |
135 | if ( !alarmStr.isEmpty() ) { | 135 | if ( !alarmStr.isEmpty() ) { |
136 | Alarm *alarm = new Alarm( event ); | 136 | Alarm *alarm = new Alarm( event ); |
137 | alarm->setType( Alarm::Display ); | 137 | alarm->setType( Alarm::Display ); |
138 | alarm->setEnabled( true ); | 138 | alarm->setEnabled( true ); |
139 | int alarmOffset = alarmStr.toInt(); | 139 | int alarmOffset = alarmStr.toInt(); |
140 | alarm->setStartOffset( alarmOffset * -60 ); | 140 | alarm->setStartOffset( alarmOffset * -60 ); |
141 | event->addAlarm( alarm ); | 141 | event->addAlarm( alarm ); |
142 | } | 142 | } |
143 | // the following may not be | 143 | // the following may not be |
144 | //Event *oldEvent = mCalendar->event( uid ); | 144 | //Event *oldEvent = mCalendar->event( uid ); |
145 | //if ( oldEvent ) mCalendar->deleteEvent( oldEvent ); | 145 | //if ( oldEvent ) mCalendar->deleteEvent( oldEvent ); |
146 | 146 | ||
147 | mCalendar->addEventNoDup( event ); | 147 | mCalendar->addEventNoDup( event ); |
148 | } else if ( qName == "Task" ) { | 148 | } else if ( qName == "Task" ) { |
149 | Todo *todo = new Todo; | 149 | Todo *todo = new Todo; |
150 | 150 | ||
151 | QString uid = "Qtopia" + attributes.value( "Uid" ); | 151 | QString uid = "Qtopia" + attributes.value( "Uid" ); |
152 | //todo->setUid( uid ); | 152 | //todo->setUid( uid ); |
153 | 153 | ||
154 | QString description = attributes.value( "Description" ); | 154 | QString description = attributes.value( "Description" ); |
155 | int pos = description.find( '\n' ); | 155 | int pos = description.find( '\n' ); |
156 | if ( pos > 0 ) { | 156 | if ( pos > 0 ) { |
157 | QString summary = description.left( pos ); | 157 | QString summary = description.left( pos ); |
158 | todo->setSummary( summary ); | 158 | todo->setSummary( summary ); |
159 | todo->setDescription( description ); | 159 | todo->setDescription( description ); |
160 | } else { | 160 | } else { |
161 | todo->setSummary( description ); | 161 | todo->setSummary( description ); |
162 | } | 162 | } |
163 | 163 | ||
164 | int priority = attributes.value( "Priority" ).toInt(); | 164 | int priority = attributes.value( "Priority" ).toInt(); |
165 | if ( priority == 0 ) priority = 3; | 165 | if ( priority == 0 ) priority = 3; |
166 | todo->setPriority( priority ); | 166 | todo->setPriority( priority ); |
167 | 167 | ||
168 | QString categoryList = attributes.value( "Categories" ); | 168 | QString categoryList = attributes.value( "Categories" ); |
169 | todo->setCategories( lookupCategories( categoryList ) ); | 169 | todo->setCategories( lookupCategories( categoryList ) ); |
170 | 170 | ||
171 | QString completedStr = attributes.value( "Completed" ); | 171 | QString completedStr = attributes.value( "Completed" ); |
172 | if ( completedStr == "1" ) todo->setCompleted( true ); | 172 | if ( completedStr == "1" ) todo->setCompleted( true ); |
173 | 173 | ||
174 | QString hasDateStr = attributes.value( "HasDate" ); | 174 | QString hasDateStr = attributes.value( "HasDate" ); |
175 | if ( hasDateStr == "1" ) { | 175 | if ( hasDateStr == "1" ) { |
176 | int year = attributes.value( "DateYear" ).toInt(); | 176 | int year = attributes.value( "DateYear" ).toInt(); |
177 | int month = attributes.value( "DateMonth" ).toInt(); | 177 | int month = attributes.value( "DateMonth" ).toInt(); |
178 | int day = attributes.value( "DateDay" ).toInt(); | 178 | int day = attributes.value( "DateDay" ).toInt(); |
179 | 179 | ||
180 | todo->setDtDue( QDateTime( QDate( year, month, day ) ) ); | 180 | todo->setDtDue( QDateTime( QDate( year, month, day ) ) ); |
181 | todo->setHasDueDate( true ); | 181 | todo->setHasDueDate( true ); |
182 | } | 182 | } |
183 | 183 | ||
184 | // Todo *oldTodo = mCalendar->todo( uid ); | 184 | // Todo *oldTodo = mCalendar->todo( uid ); |
185 | //if ( oldTodo ) mCalendar->deleteTodo( oldTodo ); | 185 | //if ( oldTodo ) mCalendar->deleteTodo( oldTodo ); |
186 | 186 | ||
187 | mCalendar->addTodoNoDup( todo ); | 187 | mCalendar->addTodoNoDup( todo ); |
188 | } else if ( qName == "Category" ) { | 188 | } else if ( qName == "Category" ) { |
189 | QString id = attributes.value( "id" ); | 189 | QString id = attributes.value( "id" ); |
190 | QString name = attributes.value( "name" ); | 190 | QString name = attributes.value( "name" ); |
191 | setCategory( id, name ); | 191 | setCategory( id, name ); |
192 | } | 192 | } |
193 | 193 | ||
194 | return true; | 194 | return true; |
195 | } | 195 | } |
196 | 196 | ||
197 | bool warning ( const QXmlParseException &exception ) | 197 | bool warning ( const QXmlParseException &exception ) |
198 | { | 198 | { |
199 | printException( exception ); | 199 | printException( exception ); |
200 | return true; | 200 | return true; |
201 | } | 201 | } |
202 | 202 | ||
203 | bool error ( const QXmlParseException &exception ) | 203 | bool error ( const QXmlParseException &exception ) |
204 | { | 204 | { |
205 | printException( exception ); | 205 | printException( exception ); |
206 | return false; | 206 | return false; |
207 | } | 207 | } |
208 | 208 | ||
209 | bool fatalError ( const QXmlParseException &exception ) | 209 | bool fatalError ( const QXmlParseException &exception ) |
210 | { | 210 | { |
211 | printException( exception ); | 211 | printException( exception ); |
212 | return false; | 212 | return false; |
213 | } | 213 | } |
214 | 214 | ||
215 | QString errorString () | 215 | QString errorString () |
216 | { | 216 | { |
217 | return "QtopiaParser: Error!"; | 217 | return "QtopiaParser: Error!"; |
218 | } | 218 | } |
219 | void setCategoriesList ( QStringList * c ) | 219 | void setCategoriesList ( QStringList * c ) |
220 | { | 220 | { |
221 | oldCategories = c; | 221 | oldCategories = c; |
222 | } | 222 | } |
223 | 223 | ||
224 | protected: | 224 | protected: |
225 | void printException( const QXmlParseException &exception ) | 225 | void printException( const QXmlParseException &exception ) |
226 | { | 226 | { |
227 | kdError() << "XML Parse Error (line " << exception.lineNumber() | 227 | kdError() << "XML Parse Error (line " << exception.lineNumber() |
228 | << ", col " << exception.columnNumber() << "): " | 228 | << ", col " << exception.columnNumber() << "): " |
229 | << exception.message() << "(public ID: '" | 229 | << exception.message() << "(public ID: '" |
230 | << exception.publicId() << "' system ID: '" | 230 | << exception.publicId() << "' system ID: '" |
231 | << exception.systemId() << "')" << endl; | 231 | << exception.systemId() << "')" << endl; |
232 | } | 232 | } |
233 | 233 | ||
234 | QDateTime toDateTime( const QString &value ) | 234 | QDateTime toDateTime( const QString &value ) |
235 | { | 235 | { |
236 | QDateTime dt; | 236 | QDateTime dt; |
237 | dt.setTime_t( value.toUInt() ); | 237 | dt.setTime_t( value.toUInt() ); |
238 | 238 | ||
239 | return dt; | 239 | return dt; |
240 | } | 240 | } |
241 | 241 | ||
242 | QStringList lookupCategories( const QString &categoryList ) | 242 | QStringList lookupCategories( const QString &categoryList ) |
243 | { | 243 | { |
244 | QStringList categoryIds = QStringList::split( ";", categoryList ); | 244 | QStringList categoryIds = QStringList::split( ";", categoryList ); |
245 | QStringList categories; | 245 | QStringList categories; |
246 | QStringList::ConstIterator it; | 246 | QStringList::ConstIterator it; |
247 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { | 247 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { |
248 | QString cate = category( *it ); | 248 | QString cate = category( *it ); |
249 | if ( oldCategories ) { | 249 | if ( oldCategories ) { |
250 | if ( ! oldCategories->contains( cate ) ) | 250 | if ( ! oldCategories->contains( cate ) ) |
251 | oldCategories->append( cate ); | 251 | oldCategories->append( cate ); |
252 | } | 252 | } |
253 | categories.append(cate ); | 253 | categories.append(cate ); |
254 | } | 254 | } |
255 | return categories; | 255 | return categories; |
256 | } | 256 | } |
257 | 257 | ||
258 | private: | 258 | private: |
259 | Calendar *mCalendar; | 259 | Calendar *mCalendar; |
260 | QStringList * oldCategories; | 260 | QStringList * oldCategories; |
261 | static QString category( const QString &id ) | 261 | static QString category( const QString &id ) |
262 | { | 262 | { |
263 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); | 263 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); |
264 | if ( it == mCategoriesMap.end() ) return id; | 264 | if ( it == mCategoriesMap.end() ) return id; |
265 | else return *it; | 265 | else return *it; |
266 | } | 266 | } |
267 | 267 | ||
268 | static void setCategory( const QString &id, const QString &name ) | 268 | static void setCategory( const QString &id, const QString &name ) |
269 | { | 269 | { |
270 | mCategoriesMap.insert( id, name ); | 270 | mCategoriesMap.insert( id, name ); |
271 | } | 271 | } |
272 | 272 | ||
273 | static QMap<QString,QString> mCategoriesMap; | 273 | static QMap<QString,QString> mCategoriesMap; |
274 | }; | 274 | }; |
275 | 275 | ||
276 | QMap<QString,QString> QtopiaParser::mCategoriesMap; | 276 | QMap<QString,QString> QtopiaParser::mCategoriesMap; |
277 | 277 | ||
278 | QtopiaFormat::QtopiaFormat() | 278 | QtopiaFormat::QtopiaFormat() |
279 | { | 279 | { |
280 | mCategories = 0; | 280 | mCategories = 0; |
281 | } | 281 | } |
282 | 282 | ||
283 | QtopiaFormat::~QtopiaFormat() | 283 | QtopiaFormat::~QtopiaFormat() |
284 | { | 284 | { |
285 | } | 285 | } |
286 | #include <qdom.h> | 286 | #include <qdom.h> |
287 | bool QtopiaFormat::load( Calendar *calendar, const QString &fileName ) | 287 | bool QtopiaFormat::load( Calendar *calendar, const QString &fileName ) |
288 | { | 288 | { |
289 | clearException(); | 289 | clearException(); |
290 | // qDebug("load QtopiaFormat: %s ",fileName.latin1() ); | 290 | // qDebug("load QtopiaFormat: %s ",fileName.latin1() ); |
291 | QtopiaParser handler( calendar ); | 291 | QtopiaParser handler( calendar ); |
292 | handler.setCategoriesList( mCategories ); | 292 | handler.setCategoriesList( mCategories ); |
293 | QFile xmlFile( fileName ); | 293 | QFile xmlFile( fileName ); |
294 | QXmlInputSource source( xmlFile ); | 294 | QXmlInputSource source( xmlFile ); |
295 | QXmlSimpleReader reader; | 295 | QXmlSimpleReader reader; |
296 | reader.setContentHandler( &handler ); | 296 | reader.setContentHandler( &handler ); |
297 | return reader.parse( source ); | 297 | return reader.parse( source ); |
298 | } | 298 | } |
299 | 299 | ||
300 | bool QtopiaFormat::save( Calendar *calendar, const QString &fileName ) | 300 | bool QtopiaFormat::save( Calendar *calendar, const QString &fileName ) |
301 | { | 301 | { |
302 | 302 | ||
303 | clearException(); | 303 | clearException(); |
304 | 304 | ||
305 | QString text = toString( calendar ); | 305 | QString text = toString( calendar ); |
306 | 306 | ||
307 | if ( text.isNull() ) return false; | 307 | if ( text.isNull() ) return false; |
308 | 308 | ||
309 | // TODO: write backup file | 309 | // TODO: write backup file |
310 | 310 | ||
311 | QFile file( fileName ); | 311 | QFile file( fileName ); |
312 | if (!file.open( IO_WriteOnly ) ) { | 312 | if (!file.open( QIODevice::WriteOnly ) ) { |
313 | setException(new ErrorFormat(ErrorFormat::SaveError, | 313 | setException(new ErrorFormat(ErrorFormat::SaveError, |
314 | i18n("Could not open file '%1'").arg(fileName))); | 314 | i18n("Could not open file '%1'").arg(fileName))); |
315 | return false; | 315 | return false; |
316 | } | 316 | } |
317 | QTextStream ts( &file ); | 317 | Q3TextStream ts( &file ); |
318 | ts << text; | 318 | ts << text; |
319 | file.close(); | 319 | file.close(); |
320 | 320 | ||
321 | return true; | 321 | return true; |
322 | } | 322 | } |
323 | 323 | ||
324 | bool QtopiaFormat::fromString( Calendar *, const QString & ) | 324 | bool QtopiaFormat::fromString( Calendar *, const QString & ) |
325 | { | 325 | { |
326 | 326 | ||
327 | return false; | 327 | return false; |
328 | } | 328 | } |
329 | 329 | ||
330 | QString QtopiaFormat::toString( Calendar * ) | 330 | QString QtopiaFormat::toString( Calendar * ) |
331 | { | 331 | { |
332 | return QString::null; | 332 | return QString::null; |
333 | } | 333 | } |
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp index 6ee5499..9a4e540 100644 --- a/libkcal/recurrence.cpp +++ b/libkcal/recurrence.cpp | |||
@@ -1,3401 +1,3404 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> | 5 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <limits.h> | 23 | #include <limits.h> |
24 | 24 | ||
25 | #include <kdebug.h> | 25 | #include <kdebug.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | #include "incidence.h" | 29 | #include "incidence.h" |
30 | 30 | ||
31 | #include "recurrence.h" | 31 | #include "recurrence.h" |
32 | //Added by qt3to4: | ||
33 | #include <Q3ValueList> | ||
34 | #include <Q3PtrList> | ||
32 | 35 | ||
33 | using namespace KCal; | 36 | using namespace KCal; |
34 | 37 | ||
35 | Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; | 38 | Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; |
36 | 39 | ||
37 | 40 | ||
38 | Recurrence::Recurrence(Incidence *parent, int compatVersion) | 41 | Recurrence::Recurrence(Incidence *parent, int compatVersion) |
39 | : recurs(rNone), // by default, it's not a recurring event | 42 | : recurs(rNone), // by default, it's not a recurring event |
40 | rWeekStart(1), // default is Monday | 43 | rWeekStart(1), // default is Monday |
41 | rDays(7), | 44 | rDays(7), |
42 | mFloats(parent ? parent->doesFloat() : false), | 45 | mFloats(parent ? parent->doesFloat() : false), |
43 | mRecurReadOnly(false), | 46 | mRecurReadOnly(false), |
44 | mRecurExDatesCount(0), | 47 | mRecurExDatesCount(0), |
45 | mFeb29YearlyType(mFeb29YearlyDefaultType), | 48 | mFeb29YearlyType(mFeb29YearlyDefaultType), |
46 | mCompatVersion(compatVersion ? compatVersion : INT_MAX), | 49 | mCompatVersion(compatVersion ? compatVersion : INT_MAX), |
47 | mCompatRecurs(rNone), | 50 | mCompatRecurs(rNone), |
48 | mCompatDuration(0), | 51 | mCompatDuration(0), |
49 | mParent(parent) | 52 | mParent(parent) |
50 | { | 53 | { |
51 | rMonthDays.setAutoDelete( true ); | 54 | rMonthDays.setAutoDelete( true ); |
52 | rMonthPositions.setAutoDelete( true ); | 55 | rMonthPositions.setAutoDelete( true ); |
53 | rYearNums.setAutoDelete( true ); | 56 | rYearNums.setAutoDelete( true ); |
54 | } | 57 | } |
55 | 58 | ||
56 | Recurrence::Recurrence(const Recurrence &r, Incidence *parent) | 59 | Recurrence::Recurrence(const Recurrence &r, Incidence *parent) |
57 | : recurs(r.recurs), | 60 | : recurs(r.recurs), |
58 | rWeekStart(r.rWeekStart), | 61 | rWeekStart(r.rWeekStart), |
59 | rDays(r.rDays.copy()), | 62 | rDays(r.rDays), |
60 | rFreq(r.rFreq), | 63 | rFreq(r.rFreq), |
61 | rDuration(r.rDuration), | 64 | rDuration(r.rDuration), |
62 | rEndDateTime(r.rEndDateTime), | 65 | rEndDateTime(r.rEndDateTime), |
63 | mRecurStart(r.mRecurStart), | 66 | mRecurStart(r.mRecurStart), |
64 | mFloats(r.mFloats), | 67 | mFloats(r.mFloats), |
65 | mRecurReadOnly(r.mRecurReadOnly), | 68 | mRecurReadOnly(r.mRecurReadOnly), |
66 | mRecurExDatesCount(r.mRecurExDatesCount), | 69 | mRecurExDatesCount(r.mRecurExDatesCount), |
67 | mFeb29YearlyType(r.mFeb29YearlyType), | 70 | mFeb29YearlyType(r.mFeb29YearlyType), |
68 | mCompatVersion(r.mCompatVersion), | 71 | mCompatVersion(r.mCompatVersion), |
69 | mCompatRecurs(r.mCompatRecurs), | 72 | mCompatRecurs(r.mCompatRecurs), |
70 | mCompatDuration(r.mCompatDuration), | 73 | mCompatDuration(r.mCompatDuration), |
71 | mParent(parent) | 74 | mParent(parent) |
72 | { | 75 | { |
73 | for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { | 76 | for (Q3PtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { |
74 | rMonthPos *tmp = new rMonthPos; | 77 | rMonthPos *tmp = new rMonthPos; |
75 | tmp->rPos = mp.current()->rPos; | 78 | tmp->rPos = mp.current()->rPos; |
76 | tmp->negative = mp.current()->negative; | 79 | tmp->negative = mp.current()->negative; |
77 | tmp->rDays = mp.current()->rDays.copy(); | 80 | tmp->rDays = mp.current()->rDays; |
78 | rMonthPositions.append(tmp); | 81 | rMonthPositions.append(tmp); |
79 | } | 82 | } |
80 | for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { | 83 | for (Q3PtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { |
81 | int *tmp = new int; | 84 | int *tmp = new int; |
82 | *tmp = *md.current(); | 85 | *tmp = *md.current(); |
83 | rMonthDays.append(tmp); | 86 | rMonthDays.append(tmp); |
84 | } | 87 | } |
85 | for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { | 88 | for (Q3PtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { |
86 | int *tmp = new int; | 89 | int *tmp = new int; |
87 | *tmp = *yn.current(); | 90 | *tmp = *yn.current(); |
88 | rYearNums.append(tmp); | 91 | rYearNums.append(tmp); |
89 | } | 92 | } |
90 | rMonthDays.setAutoDelete( true ); | 93 | rMonthDays.setAutoDelete( true ); |
91 | rMonthPositions.setAutoDelete( true ); | 94 | rMonthPositions.setAutoDelete( true ); |
92 | rYearNums.setAutoDelete( true ); | 95 | rYearNums.setAutoDelete( true ); |
93 | } | 96 | } |
94 | 97 | ||
95 | Recurrence::~Recurrence() | 98 | Recurrence::~Recurrence() |
96 | { | 99 | { |
97 | } | 100 | } |
98 | 101 | ||
99 | 102 | ||
100 | bool Recurrence::operator==( const Recurrence& r2 ) const | 103 | bool Recurrence::operator==( const Recurrence& r2 ) const |
101 | { | 104 | { |
102 | 105 | ||
103 | // the following line is obvious | 106 | // the following line is obvious |
104 | if ( recurs == rNone && r2.recurs == rNone ) | 107 | if ( recurs == rNone && r2.recurs == rNone ) |
105 | return true; | 108 | return true; |
106 | // we need the above line, because two non recurring events may | 109 | // we need the above line, because two non recurring events may |
107 | // differ in the other settings, because one (or both) | 110 | // differ in the other settings, because one (or both) |
108 | // may be not initialized properly | 111 | // may be not initialized properly |
109 | 112 | ||
110 | if ( recurs != r2.recurs | 113 | if ( recurs != r2.recurs |
111 | || rFreq != r2.rFreq | 114 | || rFreq != r2.rFreq |
112 | || rDuration != r2.rDuration | 115 | || rDuration != r2.rDuration |
113 | || !rDuration && rEndDateTime != r2.rEndDateTime | 116 | || !rDuration && rEndDateTime != r2.rEndDateTime |
114 | || mRecurStart != r2.mRecurStart | 117 | || mRecurStart != r2.mRecurStart |
115 | || mFloats != r2.mFloats | 118 | || mFloats != r2.mFloats |
116 | || mRecurReadOnly != r2.mRecurReadOnly | 119 | || mRecurReadOnly != r2.mRecurReadOnly |
117 | || mRecurExDatesCount != r2.mRecurExDatesCount ) | 120 | || mRecurExDatesCount != r2.mRecurExDatesCount ) |
118 | return false; | 121 | return false; |
119 | // no need to compare mCompat* and mParent | 122 | // no need to compare mCompat* and mParent |
120 | // OK to compare the pointers | 123 | // OK to compare the pointers |
121 | switch ( recurs ) | 124 | switch ( recurs ) |
122 | { | 125 | { |
123 | case rWeekly: | 126 | case rWeekly: |
124 | return rDays == r2.rDays | 127 | return rDays == r2.rDays |
125 | && rWeekStart == r2.rWeekStart; | 128 | && rWeekStart == r2.rWeekStart; |
126 | case rMonthlyPos: { | 129 | case rMonthlyPos: { |
127 | QPtrList<rMonthPos> MonthPositions = rMonthPositions; | 130 | Q3PtrList<rMonthPos> MonthPositions = rMonthPositions; |
128 | QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; | 131 | Q3PtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; |
129 | if ( !MonthPositions.count() ) | 132 | if ( !MonthPositions.count() ) |
130 | return false; | 133 | return false; |
131 | if ( !MonthPositions2.count() ) | 134 | if ( !MonthPositions2.count() ) |
132 | return false; | 135 | return false; |
133 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; | 136 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; |
134 | } | 137 | } |
135 | case rMonthlyDay: { | 138 | case rMonthlyDay: { |
136 | QPtrList<int> MonthDays = rMonthDays ; | 139 | Q3PtrList<int> MonthDays = rMonthDays ; |
137 | QPtrList<int> MonthDays2 = r2.rMonthDays ; | 140 | Q3PtrList<int> MonthDays2 = r2.rMonthDays ; |
138 | if ( !MonthDays.count() ) | 141 | if ( !MonthDays.count() ) |
139 | return false; | 142 | return false; |
140 | if ( !MonthDays2.count() ) | 143 | if ( !MonthDays2.count() ) |
141 | return false; | 144 | return false; |
142 | return *MonthDays.first() == *MonthDays2.first() ; | 145 | return *MonthDays.first() == *MonthDays2.first() ; |
143 | } | 146 | } |
144 | case rYearlyPos: { | 147 | case rYearlyPos: { |
145 | 148 | ||
146 | QPtrList<int> YearNums = rYearNums; | 149 | Q3PtrList<int> YearNums = rYearNums; |
147 | QPtrList<int> YearNums2 = r2.rYearNums; | 150 | Q3PtrList<int> YearNums2 = r2.rYearNums; |
148 | if ( *YearNums.first() != *YearNums2.first() ) | 151 | if ( *YearNums.first() != *YearNums2.first() ) |
149 | return false; | 152 | return false; |
150 | QPtrList<rMonthPos> MonthPositions = rMonthPositions; | 153 | Q3PtrList<rMonthPos> MonthPositions = rMonthPositions; |
151 | QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; | 154 | Q3PtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; |
152 | if ( !MonthPositions.count() ) | 155 | if ( !MonthPositions.count() ) |
153 | return false; | 156 | return false; |
154 | if ( !MonthPositions2.count() ) | 157 | if ( !MonthPositions2.count() ) |
155 | return false; | 158 | return false; |
156 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; | 159 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; |
157 | 160 | ||
158 | } | 161 | } |
159 | case rYearlyMonth: { | 162 | case rYearlyMonth: { |
160 | QPtrList<int> YearNums = rYearNums; | 163 | Q3PtrList<int> YearNums = rYearNums; |
161 | QPtrList<int> YearNums2 = r2.rYearNums; | 164 | Q3PtrList<int> YearNums2 = r2.rYearNums; |
162 | return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType); | 165 | return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType); |
163 | } | 166 | } |
164 | case rYearlyDay: { | 167 | case rYearlyDay: { |
165 | QPtrList<int> YearNums = rYearNums; | 168 | Q3PtrList<int> YearNums = rYearNums; |
166 | QPtrList<int> YearNums2 = r2.rYearNums; | 169 | Q3PtrList<int> YearNums2 = r2.rYearNums; |
167 | return ( *YearNums.first() == *YearNums2.first() ); | 170 | return ( *YearNums.first() == *YearNums2.first() ); |
168 | } | 171 | } |
169 | case rNone: | 172 | case rNone: |
170 | case rMinutely: | 173 | case rMinutely: |
171 | case rHourly: | 174 | case rHourly: |
172 | case rDaily: | 175 | case rDaily: |
173 | default: | 176 | default: |
174 | return true; | 177 | return true; |
175 | } | 178 | } |
176 | } | 179 | } |
177 | /* | 180 | /* |
178 | bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) | 181 | bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) |
179 | { | 182 | { |
180 | if ( l1.count() != l2.count() ) | 183 | if ( l1.count() != l2.count() ) |
181 | return false; | 184 | return false; |
182 | int count = l1.count(); | 185 | int count = l1.count(); |
183 | int i; | 186 | int i; |
184 | for ( i = 0; i < count ; ++i ) { | 187 | for ( i = 0; i < count ; ++i ) { |
185 | // if ( l1.at(i) != l2.at(i) ) | 188 | // if ( l1.at(i) != l2.at(i) ) |
186 | return false; | 189 | return false; |
187 | qDebug("compüare "); | 190 | qDebug("compüare "); |
188 | } | 191 | } |
189 | return true; | 192 | return true; |
190 | } | 193 | } |
191 | */ | 194 | */ |
192 | QString Recurrence::recurrenceText() const | 195 | QString Recurrence::recurrenceText() const |
193 | { | 196 | { |
194 | QString recurText; | 197 | QString recurText; |
195 | if ( recurs == Recurrence::rMinutely ) | 198 | if ( recurs == Recurrence::rMinutely ) |
196 | recurText = i18n("minutely"); | 199 | recurText = i18n("minutely"); |
197 | else if ( recurs == Recurrence::rHourly ) | 200 | else if ( recurs == Recurrence::rHourly ) |
198 | recurText = i18n("hourly"); | 201 | recurText = i18n("hourly"); |
199 | else if ( recurs == Recurrence::rDaily ) | 202 | else if ( recurs == Recurrence::rDaily ) |
200 | recurText = i18n("daily"); | 203 | recurText = i18n("daily"); |
201 | else if ( recurs == Recurrence::rWeekly ) | 204 | else if ( recurs == Recurrence::rWeekly ) |
202 | recurText = i18n("weekly"); | 205 | recurText = i18n("weekly"); |
203 | else if ( recurs == Recurrence::rMonthlyPos ) | 206 | else if ( recurs == Recurrence::rMonthlyPos ) |
204 | recurText = i18n("monthly"); | 207 | recurText = i18n("monthly"); |
205 | else if ( recurs == Recurrence::rMonthlyDay ) | 208 | else if ( recurs == Recurrence::rMonthlyDay ) |
206 | recurText = i18n("monthly"); | 209 | recurText = i18n("monthly"); |
207 | else if ( recurs == Recurrence::rYearlyMonth ) | 210 | else if ( recurs == Recurrence::rYearlyMonth ) |
208 | recurText = i18n("yearly"); | 211 | recurText = i18n("yearly"); |
209 | else if ( recurs == Recurrence::rYearlyDay ) | 212 | else if ( recurs == Recurrence::rYearlyDay ) |
210 | recurText = i18n("day-yearly"); | 213 | recurText = i18n("day-yearly"); |
211 | else if ( recurs == Recurrence::rYearlyPos ) | 214 | else if ( recurs == Recurrence::rYearlyPos ) |
212 | recurText = i18n("position-yearly"); | 215 | recurText = i18n("position-yearly"); |
213 | if ( !recurText.isEmpty() ) { | 216 | if ( !recurText.isEmpty() ) { |
214 | if ( rFreq > 1 ){ | 217 | if ( rFreq > 1 ){ |
215 | recurText = i18n("(%1) ").arg(rFreq ) + recurText; | 218 | recurText = i18n("(%1) ").arg(rFreq ) + recurText; |
216 | } | 219 | } |
217 | } else | 220 | } else |
218 | recurText = i18n("No"); | 221 | recurText = i18n("No"); |
219 | return recurText; | 222 | return recurText; |
220 | } | 223 | } |
221 | 224 | ||
222 | void Recurrence::setCompatVersion(int version) | 225 | void Recurrence::setCompatVersion(int version) |
223 | { | 226 | { |
224 | mCompatVersion = version ? version : INT_MAX; | 227 | mCompatVersion = version ? version : INT_MAX; |
225 | } | 228 | } |
226 | 229 | ||
227 | ushort Recurrence::doesRecur() const | 230 | ushort Recurrence::doesRecur() const |
228 | { | 231 | { |
229 | return recurs; | 232 | return recurs; |
230 | } | 233 | } |
231 | 234 | ||
232 | bool Recurrence::recursOnPure(const QDate &qd) const | 235 | bool Recurrence::recursOnPure(const QDate &qd) const |
233 | { | 236 | { |
234 | switch(recurs) { | 237 | switch(recurs) { |
235 | case rMinutely: | 238 | case rMinutely: |
236 | return recursSecondly(qd, rFreq*60); | 239 | return recursSecondly(qd, rFreq*60); |
237 | case rHourly: | 240 | case rHourly: |
238 | return recursSecondly(qd, rFreq*3600); | 241 | return recursSecondly(qd, rFreq*3600); |
239 | case rDaily: | 242 | case rDaily: |
240 | return recursDaily(qd); | 243 | return recursDaily(qd); |
241 | case rWeekly: | 244 | case rWeekly: |
242 | return recursWeekly(qd); | 245 | return recursWeekly(qd); |
243 | case rMonthlyPos: | 246 | case rMonthlyPos: |
244 | case rMonthlyDay: | 247 | case rMonthlyDay: |
245 | return recursMonthly(qd); | 248 | return recursMonthly(qd); |
246 | case rYearlyMonth: | 249 | case rYearlyMonth: |
247 | return recursYearlyByMonth(qd); | 250 | return recursYearlyByMonth(qd); |
248 | case rYearlyDay: | 251 | case rYearlyDay: |
249 | return recursYearlyByDay(qd); | 252 | return recursYearlyByDay(qd); |
250 | case rYearlyPos: | 253 | case rYearlyPos: |
251 | return recursYearlyByPos(qd); | 254 | return recursYearlyByPos(qd); |
252 | default: | 255 | default: |
253 | return false; | 256 | return false; |
254 | case rNone: | 257 | case rNone: |
255 | return false; | 258 | return false; |
256 | } // case | 259 | } // case |
257 | return false; | 260 | return false; |
258 | } | 261 | } |
259 | 262 | ||
260 | bool Recurrence::recursAtPure(const QDateTime &dt) const | 263 | bool Recurrence::recursAtPure(const QDateTime &dt) const |
261 | { | 264 | { |
262 | switch(recurs) { | 265 | switch(recurs) { |
263 | case rMinutely: | 266 | case rMinutely: |
264 | return recursMinutelyAt(dt, rFreq); | 267 | return recursMinutelyAt(dt, rFreq); |
265 | case rHourly: | 268 | case rHourly: |
266 | return recursMinutelyAt(dt, rFreq*60); | 269 | return recursMinutelyAt(dt, rFreq*60); |
267 | default: | 270 | default: |
268 | if (dt.time() != mRecurStart.time()) | 271 | if (dt.time() != mRecurStart.time()) |
269 | return false; | 272 | return false; |
270 | switch(recurs) { | 273 | switch(recurs) { |
271 | case rDaily: | 274 | case rDaily: |
272 | return recursDaily(dt.date()); | 275 | return recursDaily(dt.date()); |
273 | case rWeekly: | 276 | case rWeekly: |
274 | return recursWeekly(dt.date()); | 277 | return recursWeekly(dt.date()); |
275 | case rMonthlyPos: | 278 | case rMonthlyPos: |
276 | case rMonthlyDay: | 279 | case rMonthlyDay: |
277 | return recursMonthly(dt.date()); | 280 | return recursMonthly(dt.date()); |
278 | case rYearlyMonth: | 281 | case rYearlyMonth: |
279 | return recursYearlyByMonth(dt.date()); | 282 | return recursYearlyByMonth(dt.date()); |
280 | case rYearlyDay: | 283 | case rYearlyDay: |
281 | return recursYearlyByDay(dt.date()); | 284 | return recursYearlyByDay(dt.date()); |
282 | case rYearlyPos: | 285 | case rYearlyPos: |
283 | return recursYearlyByPos(dt.date()); | 286 | return recursYearlyByPos(dt.date()); |
284 | default: | 287 | default: |
285 | return false; | 288 | return false; |
286 | case rNone: | 289 | case rNone: |
287 | return false; | 290 | return false; |
288 | } | 291 | } |
289 | } // case | 292 | } // case |
290 | return false; | 293 | return false; |
291 | } | 294 | } |
292 | 295 | ||
293 | QDate Recurrence::endDate() const | 296 | QDate Recurrence::endDate() const |
294 | { | 297 | { |
295 | int count = 0; | 298 | int count = 0; |
296 | QDate end; | 299 | QDate end; |
297 | if (recurs != rNone) { | 300 | if (recurs != rNone) { |
298 | if (rDuration < 0) | 301 | if (rDuration < 0) |
299 | return QDate(); // infinite recurrence | 302 | return QDate(); // infinite recurrence |
300 | if (rDuration == 0) | 303 | if (rDuration == 0) |
301 | return rEndDateTime.date(); | 304 | return rEndDateTime.date(); |
302 | 305 | ||
303 | // The end date is determined by the recurrence count | 306 | // The end date is determined by the recurrence count |
304 | QDate dStart = mRecurStart.date(); | 307 | QDate dStart = mRecurStart.date(); |
305 | switch (recurs) | 308 | switch (recurs) |
306 | { | 309 | { |
307 | case rMinutely: | 310 | case rMinutely: |
308 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date(); | 311 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date(); |
309 | case rHourly: | 312 | case rHourly: |
310 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date(); | 313 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date(); |
311 | case rDaily: | 314 | case rDaily: |
312 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); | 315 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); |
313 | 316 | ||
314 | case rWeekly: | 317 | case rWeekly: |
315 | count = weeklyCalc(END_DATE_AND_COUNT, end); | 318 | count = weeklyCalc(END_DATE_AND_COUNT, end); |
316 | break; | 319 | break; |
317 | case rMonthlyPos: | 320 | case rMonthlyPos: |
318 | case rMonthlyDay: | 321 | case rMonthlyDay: |
319 | count = monthlyCalc(END_DATE_AND_COUNT, end); | 322 | count = monthlyCalc(END_DATE_AND_COUNT, end); |
320 | break; | 323 | break; |
321 | case rYearlyMonth: | 324 | case rYearlyMonth: |
322 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); | 325 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); |
323 | break; | 326 | break; |
324 | case rYearlyDay: | 327 | case rYearlyDay: |
325 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); | 328 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); |
326 | break; | 329 | break; |
327 | case rYearlyPos: | 330 | case rYearlyPos: |
328 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); | 331 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); |
329 | break; | 332 | break; |
330 | default: | 333 | default: |
331 | // catch-all. Should never get here. | 334 | // catch-all. Should never get here. |
332 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; | 335 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; |
333 | break; | 336 | break; |
334 | } | 337 | } |
335 | } | 338 | } |
336 | if (!count) | 339 | if (!count) |
337 | return QDate(); // error - there is no recurrence | 340 | return QDate(); // error - there is no recurrence |
338 | return end; | 341 | return end; |
339 | } | 342 | } |
340 | 343 | ||
341 | QDateTime Recurrence::endDateTime() const | 344 | QDateTime Recurrence::endDateTime() const |
342 | { | 345 | { |
343 | int count = 0; | 346 | int count = 0; |
344 | QDate end; | 347 | QDate end; |
345 | if (recurs != rNone) { | 348 | if (recurs != rNone) { |
346 | if (rDuration < 0) | 349 | if (rDuration < 0) |
347 | return QDateTime(); // infinite recurrence | 350 | return QDateTime(); // infinite recurrence |
348 | if (rDuration == 0) | 351 | if (rDuration == 0) |
349 | return rEndDateTime; | 352 | return rEndDateTime; |
350 | 353 | ||
351 | // The end date is determined by the recurrence count | 354 | // The end date is determined by the recurrence count |
352 | QDate dStart = mRecurStart.date(); | 355 | QDate dStart = mRecurStart.date(); |
353 | switch (recurs) | 356 | switch (recurs) |
354 | { | 357 | { |
355 | case rMinutely: | 358 | case rMinutely: |
356 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); | 359 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); |
357 | case rHourly: | 360 | case rHourly: |
358 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); | 361 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); |
359 | case rDaily: | 362 | case rDaily: |
360 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); | 363 | return (QDateTime)dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); |
361 | 364 | ||
362 | case rWeekly: | 365 | case rWeekly: |
363 | count = weeklyCalc(END_DATE_AND_COUNT, end); | 366 | count = weeklyCalc(END_DATE_AND_COUNT, end); |
364 | break; | 367 | break; |
365 | case rMonthlyPos: | 368 | case rMonthlyPos: |
366 | case rMonthlyDay: | 369 | case rMonthlyDay: |
367 | count = monthlyCalc(END_DATE_AND_COUNT, end); | 370 | count = monthlyCalc(END_DATE_AND_COUNT, end); |
368 | break; | 371 | break; |
369 | case rYearlyMonth: | 372 | case rYearlyMonth: |
370 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); | 373 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); |
371 | break; | 374 | break; |
372 | case rYearlyDay: | 375 | case rYearlyDay: |
373 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); | 376 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); |
374 | break; | 377 | break; |
375 | case rYearlyPos: | 378 | case rYearlyPos: |
376 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); | 379 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); |
377 | break; | 380 | break; |
378 | default: | 381 | default: |
379 | // catch-all. Should never get here. | 382 | // catch-all. Should never get here. |
380 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; | 383 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; |
381 | break; | 384 | break; |
382 | } | 385 | } |
383 | } | 386 | } |
384 | if (!count) | 387 | if (!count) |
385 | return QDateTime(); // error - there is no recurrence | 388 | return QDateTime(); // error - there is no recurrence |
386 | return QDateTime(end, mRecurStart.time()); | 389 | return QDateTime(end, mRecurStart.time()); |
387 | } | 390 | } |
388 | 391 | ||
389 | int Recurrence::durationTo(const QDate &date) const | 392 | int Recurrence::durationTo(const QDate &date) const |
390 | { | 393 | { |
391 | QDate d = date; | 394 | QDate d = date; |
392 | return recurCalc(COUNT_TO_DATE, d); | 395 | return recurCalc(COUNT_TO_DATE, d); |
393 | } | 396 | } |
394 | 397 | ||
395 | int Recurrence::durationTo(const QDateTime &datetime) const | 398 | int Recurrence::durationTo(const QDateTime &datetime) const |
396 | { | 399 | { |
397 | QDateTime dt = datetime; | 400 | QDateTime dt = datetime; |
398 | return recurCalc(COUNT_TO_DATE, dt); | 401 | return recurCalc(COUNT_TO_DATE, dt); |
399 | } | 402 | } |
400 | 403 | ||
401 | void Recurrence::unsetRecurs() | 404 | void Recurrence::unsetRecurs() |
402 | { | 405 | { |
403 | if (mRecurReadOnly) return; | 406 | if (mRecurReadOnly) return; |
404 | recurs = rNone; | 407 | recurs = rNone; |
405 | rMonthPositions.clear(); | 408 | rMonthPositions.clear(); |
406 | rMonthDays.clear(); | 409 | rMonthDays.clear(); |
407 | rYearNums.clear(); | 410 | rYearNums.clear(); |
408 | } | 411 | } |
409 | 412 | ||
410 | void Recurrence::setRecurStart(const QDateTime &start) | 413 | void Recurrence::setRecurStart(const QDateTime &start) |
411 | { | 414 | { |
412 | mRecurStart = start; | 415 | mRecurStart = start; |
413 | mFloats = false; | 416 | mFloats = false; |
414 | switch (recurs) | 417 | switch (recurs) |
415 | { | 418 | { |
416 | case rMinutely: | 419 | case rMinutely: |
417 | case rHourly: | 420 | case rHourly: |
418 | break; | 421 | break; |
419 | case rDaily: | 422 | case rDaily: |
420 | case rWeekly: | 423 | case rWeekly: |
421 | case rMonthlyPos: | 424 | case rMonthlyPos: |
422 | case rMonthlyDay: | 425 | case rMonthlyDay: |
423 | case rYearlyMonth: | 426 | case rYearlyMonth: |
424 | case rYearlyDay: | 427 | case rYearlyDay: |
425 | case rYearlyPos: | 428 | case rYearlyPos: |
426 | default: | 429 | default: |
427 | rEndDateTime.setTime(start.time()); | 430 | rEndDateTime.setTime(start.time()); |
428 | break; | 431 | break; |
429 | } | 432 | } |
430 | } | 433 | } |
431 | 434 | ||
432 | void Recurrence::setRecurStart(const QDate &start) | 435 | void Recurrence::setRecurStart(const QDate &start) |
433 | { | 436 | { |
434 | mRecurStart.setDate(start); | 437 | mRecurStart.setDate(start); |
435 | mRecurStart.setTime(QTime(0,0,0)); | 438 | mRecurStart.setTime(QTime(0,0,0)); |
436 | switch (recurs) | 439 | switch (recurs) |
437 | { | 440 | { |
438 | case rMinutely: | 441 | case rMinutely: |
439 | case rHourly: | 442 | case rHourly: |
440 | break; | 443 | break; |
441 | case rDaily: | 444 | case rDaily: |
442 | case rWeekly: | 445 | case rWeekly: |
443 | case rMonthlyPos: | 446 | case rMonthlyPos: |
444 | case rMonthlyDay: | 447 | case rMonthlyDay: |
445 | case rYearlyMonth: | 448 | case rYearlyMonth: |
446 | case rYearlyDay: | 449 | case rYearlyDay: |
447 | case rYearlyPos: | 450 | case rYearlyPos: |
448 | default: | 451 | default: |
449 | mFloats = true; | 452 | mFloats = true; |
450 | break; | 453 | break; |
451 | } | 454 | } |
452 | } | 455 | } |
453 | 456 | ||
454 | void Recurrence::setFloats(bool f) | 457 | void Recurrence::setFloats(bool f) |
455 | { | 458 | { |
456 | switch (recurs) | 459 | switch (recurs) |
457 | { | 460 | { |
458 | case rDaily: | 461 | case rDaily: |
459 | case rWeekly: | 462 | case rWeekly: |
460 | case rMonthlyPos: | 463 | case rMonthlyPos: |
461 | case rMonthlyDay: | 464 | case rMonthlyDay: |
462 | case rYearlyMonth: | 465 | case rYearlyMonth: |
463 | case rYearlyDay: | 466 | case rYearlyDay: |
464 | case rYearlyPos: | 467 | case rYearlyPos: |
465 | break; | 468 | break; |
466 | case rMinutely: | 469 | case rMinutely: |
467 | case rHourly: | 470 | case rHourly: |
468 | default: | 471 | default: |
469 | return; // can't set sub-daily to floating | 472 | return; // can't set sub-daily to floating |
470 | } | 473 | } |
471 | mFloats = f; | 474 | mFloats = f; |
472 | if (f) { | 475 | if (f) { |
473 | mRecurStart.setTime(QTime(0,0,0)); | 476 | mRecurStart.setTime(QTime(0,0,0)); |
474 | rEndDateTime.setTime(QTime(0,0,0)); | 477 | rEndDateTime.setTime(QTime(0,0,0)); |
475 | } | 478 | } |
476 | } | 479 | } |
477 | 480 | ||
478 | int Recurrence::frequency() const | 481 | int Recurrence::frequency() const |
479 | { | 482 | { |
480 | return rFreq; | 483 | return rFreq; |
481 | } | 484 | } |
482 | 485 | ||
483 | int Recurrence::duration() const | 486 | int Recurrence::duration() const |
484 | { | 487 | { |
485 | return rDuration; | 488 | return rDuration; |
486 | } | 489 | } |
487 | 490 | ||
488 | void Recurrence::setDuration(int _rDuration) | 491 | void Recurrence::setDuration(int _rDuration) |
489 | { | 492 | { |
490 | if (mRecurReadOnly) return; | 493 | if (mRecurReadOnly) return; |
491 | if (_rDuration > 0) { | 494 | if (_rDuration > 0) { |
492 | rDuration = _rDuration; | 495 | rDuration = _rDuration; |
493 | // Compatibility mode is only needed when reading the calendar in ICalFormatImpl, | 496 | // Compatibility mode is only needed when reading the calendar in ICalFormatImpl, |
494 | // so explicitly setting the duration means no backwards compatibility is needed. | 497 | // so explicitly setting the duration means no backwards compatibility is needed. |
495 | mCompatDuration = 0; | 498 | mCompatDuration = 0; |
496 | } | 499 | } |
497 | } | 500 | } |
498 | 501 | ||
499 | QString Recurrence::endDateStr(bool shortfmt) const | 502 | QString Recurrence::endDateStr(bool shortfmt) const |
500 | { | 503 | { |
501 | return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt); | 504 | return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt); |
502 | } | 505 | } |
503 | 506 | ||
504 | const QBitArray &Recurrence::days() const | 507 | const QBitArray &Recurrence::days() const |
505 | { | 508 | { |
506 | return rDays; | 509 | return rDays; |
507 | } | 510 | } |
508 | 511 | ||
509 | const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const | 512 | const Q3PtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const |
510 | { | 513 | { |
511 | return rMonthPositions; | 514 | return rMonthPositions; |
512 | } | 515 | } |
513 | 516 | ||
514 | const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const | 517 | const Q3PtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const |
515 | { | 518 | { |
516 | return rMonthPositions; | 519 | return rMonthPositions; |
517 | } | 520 | } |
518 | 521 | ||
519 | const QPtrList<int> &Recurrence::monthDays() const | 522 | const Q3PtrList<int> &Recurrence::monthDays() const |
520 | { | 523 | { |
521 | return rMonthDays; | 524 | return rMonthDays; |
522 | } | 525 | } |
523 | 526 | ||
524 | void Recurrence::setMinutely(int _rFreq, int _rDuration) | 527 | void Recurrence::setMinutely(int _rFreq, int _rDuration) |
525 | { | 528 | { |
526 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 529 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
527 | return; | 530 | return; |
528 | setDailySub(rMinutely, _rFreq, _rDuration); | 531 | setDailySub(rMinutely, _rFreq, _rDuration); |
529 | } | 532 | } |
530 | 533 | ||
531 | void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime) | 534 | void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime) |
532 | { | 535 | { |
533 | if (mRecurReadOnly) return; | 536 | if (mRecurReadOnly) return; |
534 | rEndDateTime = _rEndDateTime; | 537 | rEndDateTime = _rEndDateTime; |
535 | setDailySub(rMinutely, _rFreq, 0); | 538 | setDailySub(rMinutely, _rFreq, 0); |
536 | } | 539 | } |
537 | 540 | ||
538 | void Recurrence::setHourly(int _rFreq, int _rDuration) | 541 | void Recurrence::setHourly(int _rFreq, int _rDuration) |
539 | { | 542 | { |
540 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 543 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
541 | return; | 544 | return; |
542 | setDailySub(rHourly, _rFreq, _rDuration); | 545 | setDailySub(rHourly, _rFreq, _rDuration); |
543 | } | 546 | } |
544 | 547 | ||
545 | void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime) | 548 | void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime) |
546 | { | 549 | { |
547 | if (mRecurReadOnly) return; | 550 | if (mRecurReadOnly) return; |
548 | rEndDateTime = _rEndDateTime; | 551 | rEndDateTime = _rEndDateTime; |
549 | setDailySub(rHourly, _rFreq, 0); | 552 | setDailySub(rHourly, _rFreq, 0); |
550 | } | 553 | } |
551 | 554 | ||
552 | void Recurrence::setDaily(int _rFreq, int _rDuration) | 555 | void Recurrence::setDaily(int _rFreq, int _rDuration) |
553 | { | 556 | { |
554 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 557 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
555 | return; | 558 | return; |
556 | setDailySub(rDaily, _rFreq, _rDuration); | 559 | setDailySub(rDaily, _rFreq, _rDuration); |
557 | } | 560 | } |
558 | 561 | ||
559 | void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate) | 562 | void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate) |
560 | { | 563 | { |
561 | if (mRecurReadOnly) return; | 564 | if (mRecurReadOnly) return; |
562 | rEndDateTime.setDate(_rEndDate); | 565 | rEndDateTime.setDate(_rEndDate); |
563 | rEndDateTime.setTime(mRecurStart.time()); | 566 | rEndDateTime.setTime(mRecurStart.time()); |
564 | setDailySub(rDaily, _rFreq, 0); | 567 | setDailySub(rDaily, _rFreq, 0); |
565 | } | 568 | } |
566 | 569 | ||
567 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, | 570 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, |
568 | int _rDuration, int _rWeekStart) | 571 | int _rDuration, int _rWeekStart) |
569 | { | 572 | { |
570 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 573 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
571 | return; | 574 | return; |
572 | recurs = rWeekly; | 575 | recurs = rWeekly; |
573 | 576 | ||
574 | rFreq = _rFreq; | 577 | rFreq = _rFreq; |
575 | rDays = _rDays; | 578 | rDays = _rDays; |
576 | rWeekStart = _rWeekStart; | 579 | rWeekStart = _rWeekStart; |
577 | rDuration = _rDuration; | 580 | rDuration = _rDuration; |
578 | if (mCompatVersion < 310 && _rDuration > 0) { | 581 | if (mCompatVersion < 310 && _rDuration > 0) { |
579 | // Backwards compatibility for KDE < 3.1. | 582 | // Backwards compatibility for KDE < 3.1. |
580 | // rDuration was set to the number of time periods to recur, | 583 | // rDuration was set to the number of time periods to recur, |
581 | // with week start always on a Monday. | 584 | // with week start always on a Monday. |
582 | // Convert this to the number of occurrences. | 585 | // Convert this to the number of occurrences. |
583 | mCompatDuration = _rDuration; | 586 | mCompatDuration = _rDuration; |
584 | int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek()); | 587 | int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek()); |
585 | QDate end(mRecurStart.date().addDays(weeks * rFreq)); | 588 | QDate end(mRecurStart.date().addDays(weeks * rFreq)); |
586 | rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly | 589 | rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly |
587 | rDuration = weeklyCalc(COUNT_TO_DATE, end); | 590 | rDuration = weeklyCalc(COUNT_TO_DATE, end); |
588 | } else { | 591 | } else { |
589 | mCompatDuration = 0; | 592 | mCompatDuration = 0; |
590 | } | 593 | } |
591 | rMonthPositions.clear(); | 594 | rMonthPositions.clear(); |
592 | rMonthDays.clear(); | 595 | rMonthDays.clear(); |
593 | if (mParent) mParent->updated(); | 596 | if (mParent) mParent->updated(); |
594 | } | 597 | } |
595 | 598 | ||
596 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, | 599 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, |
597 | const QDate &_rEndDate, int _rWeekStart) | 600 | const QDate &_rEndDate, int _rWeekStart) |
598 | { | 601 | { |
599 | if (mRecurReadOnly) return; | 602 | if (mRecurReadOnly) return; |
600 | recurs = rWeekly; | 603 | recurs = rWeekly; |
601 | 604 | ||
602 | rFreq = _rFreq; | 605 | rFreq = _rFreq; |
603 | rDays = _rDays; | 606 | rDays = _rDays; |
604 | rWeekStart = _rWeekStart; | 607 | rWeekStart = _rWeekStart; |
605 | rEndDateTime.setDate(_rEndDate); | 608 | rEndDateTime.setDate(_rEndDate); |
606 | rEndDateTime.setTime(mRecurStart.time()); | 609 | rEndDateTime.setTime(mRecurStart.time()); |
607 | rDuration = 0; // set to 0 because there is an end date | 610 | rDuration = 0; // set to 0 because there is an end date |
608 | mCompatDuration = 0; | 611 | mCompatDuration = 0; |
609 | rMonthPositions.clear(); | 612 | rMonthPositions.clear(); |
610 | rMonthDays.clear(); | 613 | rMonthDays.clear(); |
611 | rYearNums.clear(); | 614 | rYearNums.clear(); |
612 | if (mParent) mParent->updated(); | 615 | if (mParent) mParent->updated(); |
613 | } | 616 | } |
614 | 617 | ||
615 | void Recurrence::setMonthly(short type, int _rFreq, int _rDuration) | 618 | void Recurrence::setMonthly(short type, int _rFreq, int _rDuration) |
616 | { | 619 | { |
617 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 620 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
618 | return; | 621 | return; |
619 | recurs = type; | 622 | recurs = type; |
620 | 623 | ||
621 | rFreq = _rFreq; | 624 | rFreq = _rFreq; |
622 | rDuration = _rDuration; | 625 | rDuration = _rDuration; |
623 | if (mCompatVersion < 310) | 626 | if (mCompatVersion < 310) |
624 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 627 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
625 | rYearNums.clear(); | 628 | rYearNums.clear(); |
626 | if (mParent) mParent->updated(); | 629 | if (mParent) mParent->updated(); |
627 | } | 630 | } |
628 | 631 | ||
629 | void Recurrence::setMonthly(short type, int _rFreq, | 632 | void Recurrence::setMonthly(short type, int _rFreq, |
630 | const QDate &_rEndDate) | 633 | const QDate &_rEndDate) |
631 | { | 634 | { |
632 | if (mRecurReadOnly) return; | 635 | if (mRecurReadOnly) return; |
633 | recurs = type; | 636 | recurs = type; |
634 | 637 | ||
635 | rFreq = _rFreq; | 638 | rFreq = _rFreq; |
636 | rEndDateTime.setDate(_rEndDate); | 639 | rEndDateTime.setDate(_rEndDate); |
637 | rEndDateTime.setTime(mRecurStart.time()); | 640 | rEndDateTime.setTime(mRecurStart.time()); |
638 | rDuration = 0; // set to 0 because there is an end date | 641 | rDuration = 0; // set to 0 because there is an end date |
639 | mCompatDuration = 0; | 642 | mCompatDuration = 0; |
640 | rYearNums.clear(); | 643 | rYearNums.clear(); |
641 | if (mParent) mParent->updated(); | 644 | if (mParent) mParent->updated(); |
642 | } | 645 | } |
643 | 646 | ||
644 | void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays) | 647 | void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays) |
645 | { | 648 | { |
646 | if (recurs == rMonthlyPos) | 649 | if (recurs == rMonthlyPos) |
647 | addMonthlyPos_(_rPos, _rDays); | 650 | addMonthlyPos_(_rPos, _rDays); |
648 | } | 651 | } |
649 | 652 | ||
650 | void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays) | 653 | void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays) |
651 | { | 654 | { |
652 | if (mRecurReadOnly | 655 | if (mRecurReadOnly |
653 | || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number | 656 | || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number |
654 | return; | 657 | return; |
655 | 658 | ||
656 | for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) { | 659 | for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) { |
657 | int itPos = it->negative ? -it->rPos : it->rPos; | 660 | int itPos = it->negative ? -it->rPos : it->rPos; |
658 | if (_rPos == itPos) { | 661 | if (_rPos == itPos) { |
659 | // This week is already in the list. | 662 | // This week is already in the list. |
660 | // Combine the specified days with those in the list. | 663 | // Combine the specified days with those in the list. |
661 | it->rDays |= _rDays; | 664 | it->rDays |= _rDays; |
662 | if (mParent) mParent->updated(); | 665 | if (mParent) mParent->updated(); |
663 | return; | 666 | return; |
664 | } | 667 | } |
665 | } | 668 | } |
666 | // Add the new position to the list | 669 | // Add the new position to the list |
667 | rMonthPos *tmpPos = new rMonthPos; | 670 | rMonthPos *tmpPos = new rMonthPos; |
668 | if (_rPos > 0) { | 671 | if (_rPos > 0) { |
669 | tmpPos->rPos = _rPos; | 672 | tmpPos->rPos = _rPos; |
670 | tmpPos->negative = false; | 673 | tmpPos->negative = false; |
671 | } else { | 674 | } else { |
672 | tmpPos->rPos = -_rPos; // take abs() | 675 | tmpPos->rPos = -_rPos; // take abs() |
673 | tmpPos->negative = true; | 676 | tmpPos->negative = true; |
674 | } | 677 | } |
675 | tmpPos->rDays = _rDays; | 678 | tmpPos->rDays = _rDays; |
676 | tmpPos->rDays.detach(); | 679 | tmpPos->rDays.detach(); |
677 | rMonthPositions.append(tmpPos); | 680 | rMonthPositions.append(tmpPos); |
678 | 681 | ||
679 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 682 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
680 | // Backwards compatibility for KDE < 3.1. | 683 | // Backwards compatibility for KDE < 3.1. |
681 | // rDuration was set to the number of time periods to recur. | 684 | // rDuration was set to the number of time periods to recur. |
682 | // Convert this to the number of occurrences. | 685 | // Convert this to the number of occurrences. |
683 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; | 686 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; |
684 | int month = mRecurStart.date().month() - 1 + monthsAhead; | 687 | int month = mRecurStart.date().month() - 1 + monthsAhead; |
685 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); | 688 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); |
686 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 689 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
687 | rDuration = recurCalc(COUNT_TO_DATE, end); | 690 | rDuration = recurCalc(COUNT_TO_DATE, end); |
688 | } | 691 | } |
689 | 692 | ||
690 | if (mParent) mParent->updated(); | 693 | if (mParent) mParent->updated(); |
691 | } | 694 | } |
692 | 695 | ||
693 | void Recurrence::addMonthlyDay(short _rDay) | 696 | void Recurrence::addMonthlyDay(short _rDay) |
694 | { | 697 | { |
695 | if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth) | 698 | if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth) |
696 | || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number | 699 | || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number |
697 | return; | 700 | return; |
698 | for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { | 701 | for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { |
699 | if (_rDay == *it) | 702 | if (_rDay == *it) |
700 | return; // this day is already in the list - avoid duplication | 703 | return; // this day is already in the list - avoid duplication |
701 | } | 704 | } |
702 | int *tmpDay = new int; | 705 | int *tmpDay = new int; |
703 | *tmpDay = _rDay; | 706 | *tmpDay = _rDay; |
704 | rMonthDays.append(tmpDay); | 707 | rMonthDays.append(tmpDay); |
705 | 708 | ||
706 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 709 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
707 | // Backwards compatibility for KDE < 3.1. | 710 | // Backwards compatibility for KDE < 3.1. |
708 | // rDuration was set to the number of time periods to recur. | 711 | // rDuration was set to the number of time periods to recur. |
709 | // Convert this to the number of occurrences. | 712 | // Convert this to the number of occurrences. |
710 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; | 713 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; |
711 | int month = mRecurStart.date().month() - 1 + monthsAhead; | 714 | int month = mRecurStart.date().month() - 1 + monthsAhead; |
712 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); | 715 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); |
713 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 716 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
714 | rDuration = recurCalc(COUNT_TO_DATE, end); | 717 | rDuration = recurCalc(COUNT_TO_DATE, end); |
715 | } | 718 | } |
716 | 719 | ||
717 | if (mParent) mParent->updated(); | 720 | if (mParent) mParent->updated(); |
718 | } | 721 | } |
719 | 722 | ||
720 | void Recurrence::setYearly(int type, int _rFreq, int _rDuration) | 723 | void Recurrence::setYearly(int type, int _rFreq, int _rDuration) |
721 | { | 724 | { |
722 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 725 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
723 | return; | 726 | return; |
724 | if (mCompatVersion < 310) | 727 | if (mCompatVersion < 310) |
725 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 728 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
726 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration); | 729 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration); |
727 | } | 730 | } |
728 | 731 | ||
729 | void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate) | 732 | void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate) |
730 | { | 733 | { |
731 | if (mRecurReadOnly) return; | 734 | if (mRecurReadOnly) return; |
732 | rEndDateTime.setDate(_rEndDate); | 735 | rEndDateTime.setDate(_rEndDate); |
733 | rEndDateTime.setTime(mRecurStart.time()); | 736 | rEndDateTime.setTime(mRecurStart.time()); |
734 | mCompatDuration = 0; | 737 | mCompatDuration = 0; |
735 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0); | 738 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0); |
736 | } | 739 | } |
737 | 740 | ||
738 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration) | 741 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration) |
739 | { | 742 | { |
740 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 743 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
741 | return; | 744 | return; |
742 | if (mCompatVersion < 310) | 745 | if (mCompatVersion < 310) |
743 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 746 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
744 | setYearly_(rYearlyMonth, type, _rFreq, _rDuration); | 747 | setYearly_(rYearlyMonth, type, _rFreq, _rDuration); |
745 | } | 748 | } |
746 | 749 | ||
747 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) | 750 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) |
748 | { | 751 | { |
749 | if (mRecurReadOnly) return; | 752 | if (mRecurReadOnly) return; |
750 | rEndDateTime.setDate(_rEndDate); | 753 | rEndDateTime.setDate(_rEndDate); |
751 | rEndDateTime.setTime(mRecurStart.time()); | 754 | rEndDateTime.setTime(mRecurStart.time()); |
752 | mCompatDuration = 0; | 755 | mCompatDuration = 0; |
753 | setYearly_(rYearlyMonth, type, _rFreq, 0); | 756 | setYearly_(rYearlyMonth, type, _rFreq, 0); |
754 | } | 757 | } |
755 | 758 | ||
756 | void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) | 759 | void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) |
757 | { | 760 | { |
758 | if (recurs == rYearlyPos) | 761 | if (recurs == rYearlyPos) |
759 | addMonthlyPos_(_rPos, _rDays); | 762 | addMonthlyPos_(_rPos, _rDays); |
760 | } | 763 | } |
761 | 764 | ||
762 | const QPtrList<int> &Recurrence::yearNums() const | 765 | const Q3PtrList<int> &Recurrence::yearNums() const |
763 | { | 766 | { |
764 | return rYearNums; | 767 | return rYearNums; |
765 | } | 768 | } |
766 | void Recurrence::addYearlyMonth(short _rPos ) | 769 | void Recurrence::addYearlyMonth(short _rPos ) |
767 | { | 770 | { |
768 | if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number | 771 | if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number |
769 | return; | 772 | return; |
770 | rMonthPos *tmpPos = new rMonthPos; | 773 | rMonthPos *tmpPos = new rMonthPos; |
771 | if ( _rPos > 0) { | 774 | if ( _rPos > 0) { |
772 | tmpPos->rPos = _rPos; | 775 | tmpPos->rPos = _rPos; |
773 | tmpPos->negative = false; | 776 | tmpPos->negative = false; |
774 | } else { | 777 | } else { |
775 | tmpPos->rPos = -_rPos; // take abs() | 778 | tmpPos->rPos = -_rPos; // take abs() |
776 | tmpPos->negative = true; | 779 | tmpPos->negative = true; |
777 | } | 780 | } |
778 | rMonthPositions.append(tmpPos); | 781 | rMonthPositions.append(tmpPos); |
779 | } | 782 | } |
780 | void Recurrence::addYearlyNum(short _rNum) | 783 | void Recurrence::addYearlyNum(short _rNum) |
781 | { | 784 | { |
782 | if (mRecurReadOnly | 785 | if (mRecurReadOnly |
783 | || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) | 786 | || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) |
784 | || _rNum <= 0) // invalid day/month number | 787 | || _rNum <= 0) // invalid day/month number |
785 | return; | 788 | return; |
786 | 789 | ||
787 | if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { | 790 | if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { |
788 | // Backwards compatibility for KDE < 3.1. | 791 | // Backwards compatibility for KDE < 3.1. |
789 | // Dates were stored as day numbers, with a fiddle to take account of leap years. | 792 | // Dates were stored as day numbers, with a fiddle to take account of leap years. |
790 | // Convert the day number to a month. | 793 | // Convert the day number to a month. |
791 | if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) | 794 | if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) |
792 | return; // invalid day number | 795 | return; // invalid day number |
793 | _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); | 796 | _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); |
794 | } else | 797 | } else |
795 | if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 | 798 | if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 |
796 | || recurs == rYearlyDay && _rNum > 366) | 799 | || recurs == rYearlyDay && _rNum > 366) |
797 | return; // invalid day number | 800 | return; // invalid day number |
798 | 801 | ||
799 | uint i = 0; | 802 | uint i = 0; |
800 | for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { | 803 | for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { |
801 | if (_rNum == *it) | 804 | if (_rNum == *it) |
802 | return; // this day/month is already in the list - avoid duplication | 805 | return; // this day/month is already in the list - avoid duplication |
803 | ++i; | 806 | ++i; |
804 | } | 807 | } |
805 | 808 | ||
806 | int *tmpNum = new int; | 809 | int *tmpNum = new int; |
807 | *tmpNum = _rNum; | 810 | *tmpNum = _rNum; |
808 | rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position | 811 | rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position |
809 | 812 | ||
810 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 813 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
811 | // Backwards compatibility for KDE < 3.1. | 814 | // Backwards compatibility for KDE < 3.1. |
812 | // rDuration was set to the number of time periods to recur. | 815 | // rDuration was set to the number of time periods to recur. |
813 | // Convert this to the number of occurrences. | 816 | // Convert this to the number of occurrences. |
814 | QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31); | 817 | QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31); |
815 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 818 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
816 | rDuration = recurCalc(COUNT_TO_DATE, end); | 819 | rDuration = recurCalc(COUNT_TO_DATE, end); |
817 | } | 820 | } |
818 | 821 | ||
819 | if (mParent) mParent->updated(); | 822 | if (mParent) mParent->updated(); |
820 | } | 823 | } |
821 | 824 | ||
822 | 825 | ||
823 | QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const | 826 | QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const |
824 | { | 827 | { |
825 | if (last) | 828 | if (last) |
826 | *last = false; | 829 | *last = false; |
827 | int freq; | 830 | int freq; |
828 | switch (recurs) | 831 | switch (recurs) |
829 | { | 832 | { |
830 | case rMinutely: | 833 | case rMinutely: |
831 | freq = rFreq * 60; | 834 | freq = rFreq * 60; |
832 | break; | 835 | break; |
833 | case rHourly: | 836 | case rHourly: |
834 | freq = rFreq * 3600; | 837 | freq = rFreq * 3600; |
835 | break; | 838 | break; |
836 | case rDaily: | 839 | case rDaily: |
837 | case rWeekly: | 840 | case rWeekly: |
838 | case rMonthlyPos: | 841 | case rMonthlyPos: |
839 | case rMonthlyDay: | 842 | case rMonthlyDay: |
840 | case rYearlyMonth: | 843 | case rYearlyMonth: |
841 | case rYearlyDay: | 844 | case rYearlyDay: |
842 | case rYearlyPos: { | 845 | case rYearlyPos: { |
843 | QDate preDate = preDateTime.date(); | 846 | QDate preDate = preDateTime.date(); |
844 | if (!mFloats && mRecurStart.time() > preDateTime.time()) | 847 | if (!mFloats && mRecurStart.time() > preDateTime.time()) |
845 | preDate = preDate.addDays(-1); | 848 | preDate = preDate.addDays(-1); |
846 | return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); | 849 | return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); |
847 | } | 850 | } |
848 | default: | 851 | default: |
849 | return QDateTime(); | 852 | return QDateTime(); |
850 | } | 853 | } |
851 | 854 | ||
852 | // It's a sub-daily recurrence | 855 | // It's a sub-daily recurrence |
853 | if (preDateTime < mRecurStart) | 856 | if (preDateTime < mRecurStart) |
854 | return mRecurStart; | 857 | return mRecurStart; |
855 | int count = mRecurStart.secsTo(preDateTime) / freq + 2; | 858 | int count = mRecurStart.secsTo(preDateTime) / freq + 2; |
856 | if (rDuration > 0) { | 859 | if (rDuration > 0) { |
857 | if (count > rDuration) | 860 | if (count > rDuration) |
858 | return QDateTime(); | 861 | return QDateTime(); |
859 | if (last && count == rDuration) | 862 | if (last && count == rDuration) |
860 | *last = true; | 863 | *last = true; |
861 | } | 864 | } |
862 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 865 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
863 | if (rDuration == 0) { | 866 | if (rDuration == 0) { |
864 | if (endtime > rEndDateTime) | 867 | if (endtime > rEndDateTime) |
865 | return QDateTime(); | 868 | return QDateTime(); |
866 | if (last && endtime == rEndDateTime) | 869 | if (last && endtime == rEndDateTime) |
867 | *last = true; | 870 | *last = true; |
868 | } | 871 | } |
869 | return endtime; | 872 | return endtime; |
870 | } | 873 | } |
871 | 874 | ||
872 | QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const | 875 | QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const |
873 | { | 876 | { |
874 | if (last) | 877 | if (last) |
875 | *last = false; | 878 | *last = false; |
876 | switch (recurs) | 879 | switch (recurs) |
877 | { | 880 | { |
878 | case rMinutely: | 881 | case rMinutely: |
879 | case rHourly: | 882 | case rHourly: |
880 | return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); | 883 | return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); |
881 | case rDaily: | 884 | case rDaily: |
882 | case rWeekly: | 885 | case rWeekly: |
883 | case rMonthlyPos: | 886 | case rMonthlyPos: |
884 | case rMonthlyDay: | 887 | case rMonthlyDay: |
885 | case rYearlyMonth: | 888 | case rYearlyMonth: |
886 | case rYearlyDay: | 889 | case rYearlyDay: |
887 | case rYearlyPos: | 890 | case rYearlyPos: |
888 | qDebug("Recurrence::getNextDate: MAY BE BROKEN "); | 891 | qDebug("Recurrence::getNextDate: MAY BE BROKEN "); |
889 | return getNextDateNoTime(preDate, last); | 892 | return getNextDateNoTime(preDate, last); |
890 | default: | 893 | default: |
891 | return QDate(); | 894 | return QDate(); |
892 | } | 895 | } |
893 | } | 896 | } |
894 | 897 | ||
895 | 898 | ||
896 | QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const | 899 | QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const |
897 | { | 900 | { |
898 | if (last) | 901 | if (last) |
899 | *last = false; | 902 | *last = false; |
900 | int freq; | 903 | int freq; |
901 | switch (recurs) | 904 | switch (recurs) |
902 | { | 905 | { |
903 | case rMinutely: | 906 | case rMinutely: |
904 | freq = rFreq * 60; | 907 | freq = rFreq * 60; |
905 | break; | 908 | break; |
906 | case rHourly: | 909 | case rHourly: |
907 | freq = rFreq * 3600; | 910 | freq = rFreq * 3600; |
908 | break; | 911 | break; |
909 | case rDaily: | 912 | case rDaily: |
910 | case rWeekly: | 913 | case rWeekly: |
911 | case rMonthlyPos: | 914 | case rMonthlyPos: |
912 | case rMonthlyDay: | 915 | case rMonthlyDay: |
913 | case rYearlyMonth: | 916 | case rYearlyMonth: |
914 | case rYearlyDay: | 917 | case rYearlyDay: |
915 | case rYearlyPos: { | 918 | case rYearlyPos: { |
916 | QDate afterDate = afterDateTime.date(); | 919 | QDate afterDate = afterDateTime.date(); |
917 | if (!mFloats && mRecurStart.time() < afterDateTime.time()) | 920 | if (!mFloats && mRecurStart.time() < afterDateTime.time()) |
918 | afterDate = afterDate.addDays(1); | 921 | afterDate = afterDate.addDays(1); |
919 | return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); | 922 | return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); |
920 | } | 923 | } |
921 | default: | 924 | default: |
922 | return QDateTime(); | 925 | return QDateTime(); |
923 | } | 926 | } |
924 | 927 | ||
925 | // It's a sub-daily recurrence | 928 | // It's a sub-daily recurrence |
926 | if (afterDateTime <= mRecurStart) | 929 | if (afterDateTime <= mRecurStart) |
927 | return QDateTime(); | 930 | return QDateTime(); |
928 | int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; | 931 | int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; |
929 | if (rDuration > 0) { | 932 | if (rDuration > 0) { |
930 | if (count > rDuration) | 933 | if (count > rDuration) |
931 | count = rDuration; | 934 | count = rDuration; |
932 | if (last && count == rDuration) | 935 | if (last && count == rDuration) |
933 | *last = true; | 936 | *last = true; |
934 | } | 937 | } |
935 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 938 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
936 | if (rDuration == 0) { | 939 | if (rDuration == 0) { |
937 | if (endtime > rEndDateTime) | 940 | if (endtime > rEndDateTime) |
938 | endtime = rEndDateTime; | 941 | endtime = rEndDateTime; |
939 | if (last && endtime == rEndDateTime) | 942 | if (last && endtime == rEndDateTime) |
940 | *last = true; | 943 | *last = true; |
941 | } | 944 | } |
942 | return endtime; | 945 | return endtime; |
943 | } | 946 | } |
944 | 947 | ||
945 | QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const | 948 | QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const |
946 | { | 949 | { |
947 | if (last) | 950 | if (last) |
948 | *last = false; | 951 | *last = false; |
949 | switch (recurs) | 952 | switch (recurs) |
950 | { | 953 | { |
951 | case rMinutely: | 954 | case rMinutely: |
952 | case rHourly: | 955 | case rHourly: |
953 | return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); | 956 | return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); |
954 | case rDaily: | 957 | case rDaily: |
955 | case rWeekly: | 958 | case rWeekly: |
956 | case rMonthlyPos: | 959 | case rMonthlyPos: |
957 | case rMonthlyDay: | 960 | case rMonthlyDay: |
958 | case rYearlyMonth: | 961 | case rYearlyMonth: |
959 | case rYearlyDay: | 962 | case rYearlyDay: |
960 | case rYearlyPos: | 963 | case rYearlyPos: |
961 | return getPreviousDateNoTime(afterDate, last); | 964 | return getPreviousDateNoTime(afterDate, last); |
962 | default: | 965 | default: |
963 | return QDate(); | 966 | return QDate(); |
964 | } | 967 | } |
965 | } | 968 | } |
966 | 969 | ||
967 | 970 | ||
968 | /***************************** PROTECTED FUNCTIONS ***************************/ | 971 | /***************************** PROTECTED FUNCTIONS ***************************/ |
969 | 972 | ||
970 | bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const | 973 | bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const |
971 | { | 974 | { |
972 | if ((qd >= mRecurStart.date()) && | 975 | if ((qd >= mRecurStart.date()) && |
973 | ((rDuration > 0) && (qd <= endDate()) || | 976 | ((rDuration > 0) && (qd <= endDate()) || |
974 | ((rDuration == 0) && (qd <= rEndDateTime.date())) || | 977 | ((rDuration == 0) && (qd <= rEndDateTime.date())) || |
975 | (rDuration == -1))) { | 978 | (rDuration == -1))) { |
976 | // The date queried falls within the range of the event. | 979 | // The date queried falls within the range of the event. |
977 | if (secondFreq < 24*3600) | 980 | if (secondFreq < 24*3600) |
978 | return true; // the event recurs at least once each day | 981 | return true; // the event recurs at least once each day |
979 | int after = mRecurStart.secsTo(QDateTime(qd)) - 1; | 982 | int after = mRecurStart.secsTo(QDateTime(qd)) - 1; |
980 | if (after / secondFreq != (after + 24*3600) / secondFreq) | 983 | if (after / secondFreq != (after + 24*3600) / secondFreq) |
981 | return true; | 984 | return true; |
982 | } | 985 | } |
983 | return false; | 986 | return false; |
984 | } | 987 | } |
985 | 988 | ||
986 | bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const | 989 | bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const |
987 | { | 990 | { |
988 | if ((dt >= mRecurStart) && | 991 | if ((dt >= mRecurStart) && |
989 | ((rDuration > 0) && (dt <= endDateTime()) || | 992 | ((rDuration > 0) && (dt <= endDateTime()) || |
990 | ((rDuration == 0) && (dt <= rEndDateTime)) || | 993 | ((rDuration == 0) && (dt <= rEndDateTime)) || |
991 | (rDuration == -1))) { | 994 | (rDuration == -1))) { |
992 | // The time queried falls within the range of the event. | 995 | // The time queried falls within the range of the event. |
993 | if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) | 996 | if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) |
994 | return true; | 997 | return true; |
995 | } | 998 | } |
996 | return false; | 999 | return false; |
997 | } | 1000 | } |
998 | 1001 | ||
999 | bool Recurrence::recursDaily(const QDate &qd) const | 1002 | bool Recurrence::recursDaily(const QDate &qd) const |
1000 | { | 1003 | { |
1001 | QDate dStart = mRecurStart.date(); | 1004 | QDate dStart = mRecurStart.date(); |
1002 | if ((dStart.daysTo(qd) % rFreq) == 0) { | 1005 | if ((dStart.daysTo(qd) % rFreq) == 0) { |
1003 | // The date is a day which recurs | 1006 | // The date is a day which recurs |
1004 | if (qd >= dStart | 1007 | if (qd >= dStart |
1005 | && ((rDuration > 0 && qd <= endDate()) || | 1008 | && ((rDuration > 0 && qd <= endDate()) || |
1006 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1009 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1007 | rDuration == -1)) { | 1010 | rDuration == -1)) { |
1008 | // The date queried falls within the range of the event. | 1011 | // The date queried falls within the range of the event. |
1009 | return true; | 1012 | return true; |
1010 | } | 1013 | } |
1011 | } | 1014 | } |
1012 | return false; | 1015 | return false; |
1013 | } | 1016 | } |
1014 | 1017 | ||
1015 | bool Recurrence::recursWeekly(const QDate &qd) const | 1018 | bool Recurrence::recursWeekly(const QDate &qd) const |
1016 | { | 1019 | { |
1017 | QDate dStart = mRecurStart.date(); | 1020 | QDate dStart = mRecurStart.date(); |
1018 | if ((dStart.daysTo(qd)/7) % rFreq == 0) { | 1021 | if ((dStart.daysTo(qd)/7) % rFreq == 0) { |
1019 | // The date is in a week which recurs | 1022 | // The date is in a week which recurs |
1020 | if (qd >= dStart | 1023 | if (qd >= dStart |
1021 | && ((rDuration > 0 && qd <= endDate()) || | 1024 | && ((rDuration > 0 && qd <= endDate()) || |
1022 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1025 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1023 | rDuration == -1)) { | 1026 | rDuration == -1)) { |
1024 | // The date queried falls within the range of the event. | 1027 | // The date queried falls within the range of the event. |
1025 | // check if the bits set match today. | 1028 | // check if the bits set match today. |
1026 | int i = qd.dayOfWeek()-1; | 1029 | int i = qd.dayOfWeek()-1; |
1027 | if (rDays.testBit((uint) i)) | 1030 | if (rDays.testBit((uint) i)) |
1028 | return true; | 1031 | return true; |
1029 | } | 1032 | } |
1030 | } | 1033 | } |
1031 | return false; | 1034 | return false; |
1032 | } | 1035 | } |
1033 | 1036 | ||
1034 | bool Recurrence::recursMonthly(const QDate &qd) const | 1037 | bool Recurrence::recursMonthly(const QDate &qd) const |
1035 | { | 1038 | { |
1036 | QDate dStart = mRecurStart.date(); | 1039 | QDate dStart = mRecurStart.date(); |
1037 | int year = qd.year(); | 1040 | int year = qd.year(); |
1038 | int month = qd.month(); | 1041 | int month = qd.month(); |
1039 | int day = qd.day(); | 1042 | int day = qd.day(); |
1040 | // calculate how many months ahead this date is from the original | 1043 | // calculate how many months ahead this date is from the original |
1041 | // event's date | 1044 | // event's date |
1042 | int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month()); | 1045 | int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month()); |
1043 | if ((monthsAhead % rFreq) == 0) { | 1046 | if ((monthsAhead % rFreq) == 0) { |
1044 | // The date is in a month which recurs | 1047 | // The date is in a month which recurs |
1045 | if (qd >= dStart | 1048 | if (qd >= dStart |
1046 | && ((rDuration > 0 && qd <= endDate()) || | 1049 | && ((rDuration > 0 && qd <= endDate()) || |
1047 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1050 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1048 | rDuration == -1)) { | 1051 | rDuration == -1)) { |
1049 | // The date queried falls within the range of the event. | 1052 | // The date queried falls within the range of the event. |
1050 | QValueList<int> days; | 1053 | Q3ValueList<int> days; |
1051 | int daysInMonth = qd.daysInMonth(); | 1054 | int daysInMonth = qd.daysInMonth(); |
1052 | if (recurs == rMonthlyDay) | 1055 | if (recurs == rMonthlyDay) |
1053 | getMonthlyDayDays(days, daysInMonth); | 1056 | getMonthlyDayDays(days, daysInMonth); |
1054 | else if (recurs == rMonthlyPos) | 1057 | else if (recurs == rMonthlyPos) |
1055 | getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); | 1058 | getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); |
1056 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1059 | for (Q3ValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1057 | if (*it == day) | 1060 | if (*it == day) |
1058 | return true; | 1061 | return true; |
1059 | } | 1062 | } |
1060 | // no dates matched | 1063 | // no dates matched |
1061 | } | 1064 | } |
1062 | } | 1065 | } |
1063 | return false; | 1066 | return false; |
1064 | } | 1067 | } |
1065 | 1068 | ||
1066 | bool Recurrence::recursYearlyByMonth(const QDate &qd) const | 1069 | bool Recurrence::recursYearlyByMonth(const QDate &qd) const |
1067 | { | 1070 | { |
1068 | QDate dStart = mRecurStart.date(); | 1071 | QDate dStart = mRecurStart.date(); |
1069 | int startDay = dStart.day(); | 1072 | int startDay = dStart.day(); |
1070 | int qday = qd.day(); | 1073 | int qday = qd.day(); |
1071 | int qmonth = qd.month(); | 1074 | int qmonth = qd.month(); |
1072 | int qyear = qd.year(); | 1075 | int qyear = qd.year(); |
1073 | bool match = (qday == startDay); | 1076 | bool match = (qday == startDay); |
1074 | if (!match && startDay == 29 && dStart.month() == 2) { | 1077 | if (!match && startDay == 29 && dStart.month() == 2) { |
1075 | // It's a recurrence on February 29th | 1078 | // It's a recurrence on February 29th |
1076 | switch (mFeb29YearlyType) { | 1079 | switch (mFeb29YearlyType) { |
1077 | case rFeb28: | 1080 | case rFeb28: |
1078 | if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear)) | 1081 | if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear)) |
1079 | match = true; | 1082 | match = true; |
1080 | break; | 1083 | break; |
1081 | case rMar1: | 1084 | case rMar1: |
1082 | if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) { | 1085 | if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) { |
1083 | qmonth = 2; | 1086 | qmonth = 2; |
1084 | match = true; | 1087 | match = true; |
1085 | } | 1088 | } |
1086 | break; | 1089 | break; |
1087 | case rFeb29: | 1090 | case rFeb29: |
1088 | break; | 1091 | break; |
1089 | } | 1092 | } |
1090 | } | 1093 | } |
1091 | 1094 | ||
1092 | if (match) { | 1095 | if (match) { |
1093 | // The day of the month matches. Calculate how many years ahead | 1096 | // The day of the month matches. Calculate how many years ahead |
1094 | // this date is from the original event's date. | 1097 | // this date is from the original event's date. |
1095 | int yearsAhead = (qyear - dStart.year()); | 1098 | int yearsAhead = (qyear - dStart.year()); |
1096 | if (yearsAhead % rFreq == 0) { | 1099 | if (yearsAhead % rFreq == 0) { |
1097 | // The date is in a year which recurs | 1100 | // The date is in a year which recurs |
1098 | if (qd >= dStart | 1101 | if (qd >= dStart |
1099 | && ((rDuration > 0 && qd <= endDate()) || | 1102 | && ((rDuration > 0 && qd <= endDate()) || |
1100 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1103 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1101 | rDuration == -1)) { | 1104 | rDuration == -1)) { |
1102 | // The date queried falls within the range of the event. | 1105 | // The date queried falls within the range of the event. |
1103 | int i = qmonth; | 1106 | int i = qmonth; |
1104 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1107 | for (Q3PtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1105 | if (i == *qlin.current()) | 1108 | if (i == *qlin.current()) |
1106 | return true; | 1109 | return true; |
1107 | } | 1110 | } |
1108 | } | 1111 | } |
1109 | } | 1112 | } |
1110 | } | 1113 | } |
1111 | return false; | 1114 | return false; |
1112 | } | 1115 | } |
1113 | 1116 | ||
1114 | bool Recurrence::recursYearlyByPos(const QDate &qd) const | 1117 | bool Recurrence::recursYearlyByPos(const QDate &qd) const |
1115 | { | 1118 | { |
1116 | QDate dStart = mRecurStart.date(); | 1119 | QDate dStart = mRecurStart.date(); |
1117 | int year = qd.year(); | 1120 | int year = qd.year(); |
1118 | int month = qd.month(); | 1121 | int month = qd.month(); |
1119 | int day = qd.day(); | 1122 | int day = qd.day(); |
1120 | // calculate how many years ahead this date is from the original | 1123 | // calculate how many years ahead this date is from the original |
1121 | // event's date | 1124 | // event's date |
1122 | int yearsAhead = (year - dStart.year()); | 1125 | int yearsAhead = (year - dStart.year()); |
1123 | if (yearsAhead % rFreq == 0) { | 1126 | if (yearsAhead % rFreq == 0) { |
1124 | // The date is in a year which recurs | 1127 | // The date is in a year which recurs |
1125 | if (qd >= dStart | 1128 | if (qd >= dStart |
1126 | && ((rDuration > 0 && qd <= endDate()) || | 1129 | && ((rDuration > 0 && qd <= endDate()) || |
1127 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1130 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1128 | rDuration == -1)) { | 1131 | rDuration == -1)) { |
1129 | // The date queried falls within the range of the event. | 1132 | // The date queried falls within the range of the event. |
1130 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1133 | for (Q3PtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1131 | if (month == *qlin.current()) { | 1134 | if (month == *qlin.current()) { |
1132 | // The month recurs | 1135 | // The month recurs |
1133 | QValueList<int> days; | 1136 | Q3ValueList<int> days; |
1134 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); | 1137 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); |
1135 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1138 | for (Q3ValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1136 | if (*it == day) | 1139 | if (*it == day) |
1137 | return true; | 1140 | return true; |
1138 | } | 1141 | } |
1139 | } | 1142 | } |
1140 | } | 1143 | } |
1141 | } | 1144 | } |
1142 | } | 1145 | } |
1143 | return false; | 1146 | return false; |
1144 | } | 1147 | } |
1145 | 1148 | ||
1146 | bool Recurrence::recursYearlyByDay(const QDate &qd) const | 1149 | bool Recurrence::recursYearlyByDay(const QDate &qd) const |
1147 | { | 1150 | { |
1148 | QDate dStart = mRecurStart.date(); | 1151 | QDate dStart = mRecurStart.date(); |
1149 | // calculate how many years ahead this date is from the original | 1152 | // calculate how many years ahead this date is from the original |
1150 | // event's date | 1153 | // event's date |
1151 | int yearsAhead = (qd.year() - dStart.year()); | 1154 | int yearsAhead = (qd.year() - dStart.year()); |
1152 | if (yearsAhead % rFreq == 0) { | 1155 | if (yearsAhead % rFreq == 0) { |
1153 | // The date is in a year which recurs | 1156 | // The date is in a year which recurs |
1154 | if (qd >= dStart | 1157 | if (qd >= dStart |
1155 | && ((rDuration > 0 && qd <= endDate()) || | 1158 | && ((rDuration > 0 && qd <= endDate()) || |
1156 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1159 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1157 | rDuration == -1)) { | 1160 | rDuration == -1)) { |
1158 | // The date queried falls within the range of the event. | 1161 | // The date queried falls within the range of the event. |
1159 | int i = qd.dayOfYear(); | 1162 | int i = qd.dayOfYear(); |
1160 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1163 | for (Q3PtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1161 | if (i == *qlin.current()) | 1164 | if (i == *qlin.current()) |
1162 | return true; | 1165 | return true; |
1163 | } | 1166 | } |
1164 | } | 1167 | } |
1165 | } | 1168 | } |
1166 | return false; | 1169 | return false; |
1167 | } | 1170 | } |
1168 | 1171 | ||
1169 | /* Get the date of the next recurrence, after the specified date. | 1172 | /* Get the date of the next recurrence, after the specified date. |
1170 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the | 1173 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the |
1171 | * last recurrence, else false. | 1174 | * last recurrence, else false. |
1172 | * Reply = date of next recurrence, or invalid date if none. | 1175 | * Reply = date of next recurrence, or invalid date if none. |
1173 | */ | 1176 | */ |
1174 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const | 1177 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const |
1175 | { | 1178 | { |
1176 | 1179 | ||
1177 | if (last) | 1180 | if (last) |
1178 | *last = false; | 1181 | *last = false; |
1179 | QDate dStart = mRecurStart.date(); | 1182 | QDate dStart = mRecurStart.date(); |
1180 | if (preDate < dStart) | 1183 | if (preDate < dStart) |
1181 | return dStart; | 1184 | return dStart; |
1182 | QDate earliestDate = preDate.addDays(1); | 1185 | QDate earliestDate = preDate.addDays(1); |
1183 | QDate nextDate; | 1186 | QDate nextDate; |
1184 | 1187 | ||
1185 | switch (recurs) { | 1188 | switch (recurs) { |
1186 | case rDaily: | 1189 | case rDaily: |
1187 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); | 1190 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); |
1188 | break; | 1191 | break; |
1189 | 1192 | ||
1190 | case rWeekly: { | 1193 | case rWeekly: { |
1191 | QDate start = dStart.addDays(-((dStart.dayOfWeek() - rWeekStart + 7)%7)); // start of week for dStart | 1194 | QDate start = dStart.addDays(-((dStart.dayOfWeek() - rWeekStart + 7)%7)); // start of week for dStart |
1192 | int earliestDayOfWeek = earliestDate.dayOfWeek(); | 1195 | int earliestDayOfWeek = earliestDate.dayOfWeek(); |
1193 | int weeksAhead = start.daysTo(earliestDate) / 7; | 1196 | int weeksAhead = start.daysTo(earliestDate) / 7; |
1194 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week | 1197 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week |
1195 | weeksAhead -= notThisWeek; // latest week which recurred | 1198 | weeksAhead -= notThisWeek; // latest week which recurred |
1196 | int weekday = 0; | 1199 | int weekday = 0; |
1197 | // First check for any remaining day this week, if this week is a recurring week | 1200 | // First check for any remaining day this week, if this week is a recurring week |
1198 | if (!notThisWeek) | 1201 | if (!notThisWeek) |
1199 | weekday = getFirstDayInWeek(earliestDayOfWeek); | 1202 | weekday = getFirstDayInWeek(earliestDayOfWeek); |
1200 | // Check for a day in the next scheduled week | 1203 | // Check for a day in the next scheduled week |
1201 | if (!weekday ) | 1204 | if (!weekday ) |
1202 | weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; | 1205 | weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; |
1203 | nextDate = start.addDays(weeksAhead*7 + weekday - 1); | 1206 | nextDate = start.addDays(weeksAhead*7 + weekday - 1); |
1204 | break; | 1207 | break; |
1205 | } | 1208 | } |
1206 | case rMonthlyDay: | 1209 | case rMonthlyDay: |
1207 | case rMonthlyPos: { | 1210 | case rMonthlyPos: { |
1208 | int startYear = dStart.year(); | 1211 | int startYear = dStart.year(); |
1209 | int startMonth = dStart.month(); // 1..12 | 1212 | int startMonth = dStart.month(); // 1..12 |
1210 | int earliestYear = earliestDate.year(); | 1213 | int earliestYear = earliestDate.year(); |
1211 | int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; | 1214 | int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; |
1212 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month | 1215 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month |
1213 | monthsAhead -= notThisMonth; // latest month which recurred | 1216 | monthsAhead -= notThisMonth; // latest month which recurred |
1214 | // Check for the first later day in the current month | 1217 | // Check for the first later day in the current month |
1215 | if (!notThisMonth) | 1218 | if (!notThisMonth) |
1216 | nextDate = getFirstDateInMonth(earliestDate); | 1219 | nextDate = getFirstDateInMonth(earliestDate); |
1217 | if (!nextDate.isValid() ) { | 1220 | if (!nextDate.isValid() ) { |
1218 | // Check for a day in the next scheduled month | 1221 | // Check for a day in the next scheduled month |
1219 | int months = startMonth - 1 + monthsAhead + rFreq; | 1222 | int months = startMonth - 1 + monthsAhead + rFreq; |
1220 | nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); | 1223 | nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); |
1221 | } | 1224 | } |
1222 | break; | 1225 | break; |
1223 | } | 1226 | } |
1224 | case rYearlyMonth: | 1227 | case rYearlyMonth: |
1225 | case rYearlyPos: | 1228 | case rYearlyPos: |
1226 | case rYearlyDay: { | 1229 | case rYearlyDay: { |
1227 | int startYear = dStart.year(); | 1230 | int startYear = dStart.year(); |
1228 | int yearsAhead = earliestDate.year() - startYear; | 1231 | int yearsAhead = earliestDate.year() - startYear; |
1229 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year | 1232 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year |
1230 | yearsAhead -= notThisYear; // latest year which recurred | 1233 | yearsAhead -= notThisYear; // latest year which recurred |
1231 | // Check for the first later date in the current year | 1234 | // Check for the first later date in the current year |
1232 | if (!notThisYear) | 1235 | if (!notThisYear) |
1233 | nextDate = getFirstDateInYear(earliestDate); | 1236 | nextDate = getFirstDateInYear(earliestDate); |
1234 | // Check for a date in the next scheduled year | 1237 | // Check for a date in the next scheduled year |
1235 | if (!nextDate.isValid() && earliestDate.dayOfYear() > 1) | 1238 | if (!nextDate.isValid() && earliestDate.dayOfYear() > 1) |
1236 | nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1)); | 1239 | nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1)); |
1237 | break; | 1240 | break; |
1238 | } | 1241 | } |
1239 | case rNone: | 1242 | case rNone: |
1240 | default: | 1243 | default: |
1241 | return QDate(); | 1244 | return QDate(); |
1242 | } | 1245 | } |
1243 | 1246 | ||
1244 | if (rDuration >= 0 && nextDate.isValid()) { | 1247 | if (rDuration >= 0 && nextDate.isValid()) { |
1245 | // Check that the date found is within the range of the recurrence | 1248 | // Check that the date found is within the range of the recurrence |
1246 | QDate end = endDate(); | 1249 | QDate end = endDate(); |
1247 | if (nextDate > end) | 1250 | if (nextDate > end) |
1248 | return QDate(); | 1251 | return QDate(); |
1249 | if (last && nextDate == end) | 1252 | if (last && nextDate == end) |
1250 | *last = true; | 1253 | *last = true; |
1251 | } | 1254 | } |
1252 | return nextDate; | 1255 | return nextDate; |
1253 | } | 1256 | } |
1254 | 1257 | ||
1255 | /* Get the date of the last previous recurrence, before the specified date. | 1258 | /* Get the date of the last previous recurrence, before the specified date. |
1256 | * Reply = date of previous recurrence, or invalid date if none. | 1259 | * Reply = date of previous recurrence, or invalid date if none. |
1257 | */ | 1260 | */ |
1258 | QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const | 1261 | QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const |
1259 | { | 1262 | { |
1260 | if (last) | 1263 | if (last) |
1261 | *last = false; | 1264 | *last = false; |
1262 | QDate dStart = mRecurStart.date(); | 1265 | QDate dStart = mRecurStart.date(); |
1263 | QDate latestDate = afterDate.addDays(-1); | 1266 | QDate latestDate = afterDate.addDays(-1); |
1264 | if (latestDate < dStart) | 1267 | if (latestDate < dStart) |
1265 | return QDate(); | 1268 | return QDate(); |
1266 | QDate prevDate; | 1269 | QDate prevDate; |
1267 | 1270 | ||
1268 | switch (recurs) { | 1271 | switch (recurs) { |
1269 | case rDaily: | 1272 | case rDaily: |
1270 | prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq); | 1273 | prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq); |
1271 | break; | 1274 | break; |
1272 | 1275 | ||
1273 | case rWeekly: { | 1276 | case rWeekly: { |
1274 | QDate start = dStart.addDays(-((dStart.dayOfWeek() - rWeekStart + 7)%7)); // start of week for dStart | 1277 | QDate start = dStart.addDays(-((dStart.dayOfWeek() - rWeekStart + 7)%7)); // start of week for dStart |
1275 | int latestDayOfWeek = latestDate.dayOfWeek(); | 1278 | int latestDayOfWeek = latestDate.dayOfWeek(); |
1276 | int weeksAhead = start.daysTo(latestDate) / 7; | 1279 | int weeksAhead = start.daysTo(latestDate) / 7; |
1277 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week | 1280 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week |
1278 | weeksAhead -= notThisWeek; // latest week which recurred | 1281 | weeksAhead -= notThisWeek; // latest week which recurred |
1279 | int weekday = 0; | 1282 | int weekday = 0; |
1280 | // First check for any previous day this week, if this week is a recurring week | 1283 | // First check for any previous day this week, if this week is a recurring week |
1281 | if (!notThisWeek) | 1284 | if (!notThisWeek) |
1282 | weekday = getLastDayInWeek(latestDayOfWeek); | 1285 | weekday = getLastDayInWeek(latestDayOfWeek); |
1283 | // Check for a day in the previous scheduled week | 1286 | // Check for a day in the previous scheduled week |
1284 | if (!weekday) { | 1287 | if (!weekday) { |
1285 | if (!notThisWeek) | 1288 | if (!notThisWeek) |
1286 | weeksAhead -= rFreq; | 1289 | weeksAhead -= rFreq; |
1287 | int weekEnd = (rWeekStart + 5)%7 + 1; | 1290 | int weekEnd = (rWeekStart + 5)%7 + 1; |
1288 | weekday = getLastDayInWeek(weekEnd); | 1291 | weekday = getLastDayInWeek(weekEnd); |
1289 | } | 1292 | } |
1290 | if (weekday) | 1293 | if (weekday) |
1291 | prevDate = start.addDays(weeksAhead*7 + weekday - 1); | 1294 | prevDate = start.addDays(weeksAhead*7 + weekday - 1); |
1292 | break; | 1295 | break; |
1293 | } | 1296 | } |
1294 | case rMonthlyDay: | 1297 | case rMonthlyDay: |
1295 | case rMonthlyPos: { | 1298 | case rMonthlyPos: { |
1296 | int startYear = dStart.year(); | 1299 | int startYear = dStart.year(); |
1297 | int startMonth = dStart.month(); // 1..12 | 1300 | int startMonth = dStart.month(); // 1..12 |
1298 | int latestYear = latestDate.year(); | 1301 | int latestYear = latestDate.year(); |
1299 | int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth; | 1302 | int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth; |
1300 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month | 1303 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month |
1301 | monthsAhead -= notThisMonth; // latest month which recurred | 1304 | monthsAhead -= notThisMonth; // latest month which recurred |
1302 | // Check for the last earlier day in the current month | 1305 | // Check for the last earlier day in the current month |
1303 | if (!notThisMonth) | 1306 | if (!notThisMonth) |
1304 | prevDate = getLastDateInMonth(latestDate); | 1307 | prevDate = getLastDateInMonth(latestDate); |
1305 | if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) { | 1308 | if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) { |
1306 | // Check for a day in the previous scheduled month | 1309 | // Check for a day in the previous scheduled month |
1307 | if (!notThisMonth) | 1310 | if (!notThisMonth) |
1308 | monthsAhead -= rFreq; | 1311 | monthsAhead -= rFreq; |
1309 | int months = startMonth + monthsAhead; // get the month after the one that recurs | 1312 | int months = startMonth + monthsAhead; // get the month after the one that recurs |
1310 | prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1)); | 1313 | prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1)); |
1311 | } | 1314 | } |
1312 | break; | 1315 | break; |
1313 | } | 1316 | } |
1314 | case rYearlyMonth: | 1317 | case rYearlyMonth: |
1315 | case rYearlyPos: | 1318 | case rYearlyPos: |
1316 | case rYearlyDay: { | 1319 | case rYearlyDay: { |
1317 | int startYear = dStart.year(); | 1320 | int startYear = dStart.year(); |
1318 | int yearsAhead = latestDate.year() - startYear; | 1321 | int yearsAhead = latestDate.year() - startYear; |
1319 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year | 1322 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year |
1320 | yearsAhead -= notThisYear; // latest year which recurred | 1323 | yearsAhead -= notThisYear; // latest year which recurred |
1321 | // Check for the first later date in the current year | 1324 | // Check for the first later date in the current year |
1322 | if (!notThisYear) | 1325 | if (!notThisYear) |
1323 | prevDate = getLastDateInYear(latestDate); | 1326 | prevDate = getLastDateInYear(latestDate); |
1324 | if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) { | 1327 | if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) { |
1325 | // Check for a date in the next scheduled year | 1328 | // Check for a date in the next scheduled year |
1326 | if (!notThisYear) | 1329 | if (!notThisYear) |
1327 | yearsAhead -= rFreq; | 1330 | yearsAhead -= rFreq; |
1328 | prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31)); | 1331 | prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31)); |
1329 | } | 1332 | } |
1330 | break; | 1333 | break; |
1331 | } | 1334 | } |
1332 | case rNone: | 1335 | case rNone: |
1333 | default: | 1336 | default: |
1334 | return QDate(); | 1337 | return QDate(); |
1335 | } | 1338 | } |
1336 | 1339 | ||
1337 | if (prevDate.isValid()) { | 1340 | if (prevDate.isValid()) { |
1338 | // Check that the date found is within the range of the recurrence | 1341 | // Check that the date found is within the range of the recurrence |
1339 | if (prevDate < dStart) | 1342 | if (prevDate < dStart) |
1340 | return QDate(); | 1343 | return QDate(); |
1341 | if (rDuration >= 0) { | 1344 | if (rDuration >= 0) { |
1342 | QDate end = endDate(); | 1345 | QDate end = endDate(); |
1343 | if (prevDate >= end) { | 1346 | if (prevDate >= end) { |
1344 | if (last) | 1347 | if (last) |
1345 | *last = true; | 1348 | *last = true; |
1346 | return end; | 1349 | return end; |
1347 | } | 1350 | } |
1348 | } | 1351 | } |
1349 | } | 1352 | } |
1350 | return prevDate; | 1353 | return prevDate; |
1351 | } | 1354 | } |
1352 | 1355 | ||
1353 | void Recurrence::setDailySub(short type, int freq, int duration) | 1356 | void Recurrence::setDailySub(short type, int freq, int duration) |
1354 | { | 1357 | { |
1355 | recurs = type; | 1358 | recurs = type; |
1356 | rFreq = freq; | 1359 | rFreq = freq; |
1357 | rDuration = duration; | 1360 | rDuration = duration; |
1358 | rMonthPositions.clear(); | 1361 | rMonthPositions.clear(); |
1359 | rMonthDays.clear(); | 1362 | rMonthDays.clear(); |
1360 | rYearNums.clear(); | 1363 | rYearNums.clear(); |
1361 | if (type != rDaily) | 1364 | if (type != rDaily) |
1362 | mFloats = false; // sub-daily types can't be floating | 1365 | mFloats = false; // sub-daily types can't be floating |
1363 | 1366 | ||
1364 | if (mParent) mParent->updated(); | 1367 | if (mParent) mParent->updated(); |
1365 | } | 1368 | } |
1366 | 1369 | ||
1367 | void Recurrence::setYearly_(short type, Feb29Type feb29type, int freq, int duration) | 1370 | void Recurrence::setYearly_(short type, Feb29Type feb29type, int freq, int duration) |
1368 | { | 1371 | { |
1369 | recurs = type; | 1372 | recurs = type; |
1370 | if (mCompatVersion < 310 && type == rYearlyDay) { | 1373 | if (mCompatVersion < 310 && type == rYearlyDay) { |
1371 | mCompatRecurs = rYearlyDay; | 1374 | mCompatRecurs = rYearlyDay; |
1372 | recurs = rYearlyMonth; // convert old yearly-by-day to yearly-by-month | 1375 | recurs = rYearlyMonth; // convert old yearly-by-day to yearly-by-month |
1373 | feb29type = rMar1; // retain the same day number in the year | 1376 | feb29type = rMar1; // retain the same day number in the year |
1374 | } | 1377 | } |
1375 | 1378 | ||
1376 | mFeb29YearlyType = feb29type; | 1379 | mFeb29YearlyType = feb29type; |
1377 | rFreq = freq; | 1380 | rFreq = freq; |
1378 | rDuration = duration; | 1381 | rDuration = duration; |
1379 | if (type != rYearlyPos) | 1382 | if (type != rYearlyPos) |
1380 | rMonthPositions.clear(); | 1383 | rMonthPositions.clear(); |
1381 | rMonthDays.clear(); | 1384 | rMonthDays.clear(); |
1382 | if (mParent) mParent->updated(); | 1385 | if (mParent) mParent->updated(); |
1383 | } | 1386 | } |
1384 | 1387 | ||
1385 | int Recurrence::recurCalc(PeriodFunc func, QDateTime &endtime) const | 1388 | int Recurrence::recurCalc(PeriodFunc func, QDateTime &endtime) const |
1386 | { | 1389 | { |
1387 | QDate enddate = endtime.date(); | 1390 | QDate enddate = endtime.date(); |
1388 | switch (func) { | 1391 | switch (func) { |
1389 | case END_DATE_AND_COUNT: | 1392 | case END_DATE_AND_COUNT: |
1390 | if (rDuration < 0) { | 1393 | if (rDuration < 0) { |
1391 | endtime = QDateTime(); | 1394 | endtime = QDateTime(); |
1392 | return 0; // infinite recurrence | 1395 | return 0; // infinite recurrence |
1393 | } | 1396 | } |
1394 | if (rDuration == 0) { | 1397 | if (rDuration == 0) { |
1395 | endtime = rEndDateTime; | 1398 | endtime = rEndDateTime; |
1396 | func = COUNT_TO_DATE; | 1399 | func = COUNT_TO_DATE; |
1397 | } | 1400 | } |
1398 | break; | 1401 | break; |
1399 | case COUNT_TO_DATE: | 1402 | case COUNT_TO_DATE: |
1400 | // Count recurrences up to and including the specified date/time. | 1403 | // Count recurrences up to and including the specified date/time. |
1401 | if (endtime < mRecurStart) | 1404 | if (endtime < mRecurStart) |
1402 | return 0; | 1405 | return 0; |
1403 | if (rDuration == 0 && endtime > rEndDateTime) | 1406 | if (rDuration == 0 && endtime > rEndDateTime) |
1404 | enddate = rEndDateTime.date(); | 1407 | enddate = rEndDateTime.date(); |
1405 | else if (!mFloats && mRecurStart.time() > endtime.time()) | 1408 | else if (!mFloats && mRecurStart.time() > endtime.time()) |
1406 | enddate = enddate.addDays(-1); | 1409 | enddate = enddate.addDays(-1); |
1407 | break; | 1410 | break; |
1408 | case NEXT_AFTER_DATE: | 1411 | case NEXT_AFTER_DATE: |
1409 | // Find next recurrence AFTER endtime | 1412 | // Find next recurrence AFTER endtime |
1410 | if (endtime < mRecurStart) { | 1413 | if (endtime < mRecurStart) { |
1411 | endtime = mRecurStart; | 1414 | endtime = mRecurStart; |
1412 | return 1; | 1415 | return 1; |
1413 | } | 1416 | } |
1414 | if (rDuration == 0 && endtime >= rEndDateTime) { | 1417 | if (rDuration == 0 && endtime >= rEndDateTime) { |
1415 | endtime = QDateTime(); | 1418 | endtime = QDateTime(); |
1416 | return 0; | 1419 | return 0; |
1417 | } | 1420 | } |
1418 | if (!mFloats && mRecurStart.time() > endtime.time()) | 1421 | if (!mFloats && mRecurStart.time() > endtime.time()) |
1419 | enddate = enddate.addDays(-1); | 1422 | enddate = enddate.addDays(-1); |
1420 | break; | 1423 | break; |
1421 | default: | 1424 | default: |
1422 | endtime = QDateTime(); | 1425 | endtime = QDateTime(); |
1423 | return 0; | 1426 | return 0; |
1424 | } | 1427 | } |
1425 | 1428 | ||
1426 | int count = 0; // default = error | 1429 | int count = 0; // default = error |
1427 | bool timed = false; | 1430 | bool timed = false; |
1428 | switch (recurs) { | 1431 | switch (recurs) { |
1429 | case rMinutely: | 1432 | case rMinutely: |
1430 | timed = true; | 1433 | timed = true; |
1431 | count = secondlyCalc(func, endtime, rFreq*60); | 1434 | count = secondlyCalc(func, endtime, rFreq*60); |
1432 | break; | 1435 | break; |
1433 | case rHourly: | 1436 | case rHourly: |
1434 | timed = true; | 1437 | timed = true; |
1435 | count = secondlyCalc(func, endtime, rFreq*3600); | 1438 | count = secondlyCalc(func, endtime, rFreq*3600); |
1436 | break; | 1439 | break; |
1437 | case rDaily: | 1440 | case rDaily: |
1438 | count = dailyCalc(func, enddate); | 1441 | count = dailyCalc(func, enddate); |
1439 | break; | 1442 | break; |
1440 | case rWeekly: | 1443 | case rWeekly: |
1441 | count = weeklyCalc(func, enddate); | 1444 | count = weeklyCalc(func, enddate); |
1442 | break; | 1445 | break; |
1443 | case rMonthlyPos: | 1446 | case rMonthlyPos: |
1444 | case rMonthlyDay: | 1447 | case rMonthlyDay: |
1445 | count = monthlyCalc(func, enddate); | 1448 | count = monthlyCalc(func, enddate); |
1446 | break; | 1449 | break; |
1447 | case rYearlyMonth: | 1450 | case rYearlyMonth: |
1448 | count = yearlyMonthCalc(func, enddate); | 1451 | count = yearlyMonthCalc(func, enddate); |
1449 | break; | 1452 | break; |
1450 | case rYearlyPos: | 1453 | case rYearlyPos: |
1451 | count = yearlyPosCalc(func, enddate); | 1454 | count = yearlyPosCalc(func, enddate); |
1452 | break; | 1455 | break; |
1453 | case rYearlyDay: | 1456 | case rYearlyDay: |
1454 | count = yearlyDayCalc(func, enddate); | 1457 | count = yearlyDayCalc(func, enddate); |
1455 | break; | 1458 | break; |
1456 | default: | 1459 | default: |
1457 | break; | 1460 | break; |
1458 | } | 1461 | } |
1459 | 1462 | ||
1460 | switch (func) { | 1463 | switch (func) { |
1461 | case END_DATE_AND_COUNT: | 1464 | case END_DATE_AND_COUNT: |
1462 | case NEXT_AFTER_DATE: | 1465 | case NEXT_AFTER_DATE: |
1463 | if (count == 0) | 1466 | if (count == 0) |
1464 | endtime = QDateTime(); | 1467 | endtime = QDateTime(); |
1465 | else if (!timed) { | 1468 | else if (!timed) { |
1466 | endtime.setDate(enddate); | 1469 | endtime.setDate(enddate); |
1467 | endtime.setTime(mRecurStart.time()); | 1470 | endtime.setTime(mRecurStart.time()); |
1468 | } | 1471 | } |
1469 | break; | 1472 | break; |
1470 | case COUNT_TO_DATE: | 1473 | case COUNT_TO_DATE: |
1471 | break; | 1474 | break; |
1472 | } | 1475 | } |
1473 | return count; | 1476 | return count; |
1474 | } | 1477 | } |
1475 | 1478 | ||
1476 | int Recurrence::recurCalc(PeriodFunc func, QDate &enddate) const | 1479 | int Recurrence::recurCalc(PeriodFunc func, QDate &enddate) const |
1477 | { | 1480 | { |
1478 | QDateTime endtime(enddate, QTime(23,59,59)); | 1481 | QDateTime endtime(enddate, QTime(23,59,59)); |
1479 | switch (func) { | 1482 | switch (func) { |
1480 | case END_DATE_AND_COUNT: | 1483 | case END_DATE_AND_COUNT: |
1481 | if (rDuration < 0) { | 1484 | if (rDuration < 0) { |
1482 | enddate = QDate(); | 1485 | enddate = QDate(); |
1483 | return 0; // infinite recurrence | 1486 | return 0; // infinite recurrence |
1484 | } | 1487 | } |
1485 | if (rDuration == 0) { | 1488 | if (rDuration == 0) { |
1486 | enddate = rEndDateTime.date(); | 1489 | enddate = rEndDateTime.date(); |
1487 | func = COUNT_TO_DATE; | 1490 | func = COUNT_TO_DATE; |
1488 | } | 1491 | } |
1489 | break; | 1492 | break; |
1490 | case COUNT_TO_DATE: | 1493 | case COUNT_TO_DATE: |
1491 | // Count recurrences up to and including the specified date. | 1494 | // Count recurrences up to and including the specified date. |
1492 | if (enddate < mRecurStart.date()) | 1495 | if (enddate < mRecurStart.date()) |
1493 | return 0; | 1496 | return 0; |
1494 | if (rDuration == 0 && enddate > rEndDateTime.date()) { | 1497 | if (rDuration == 0 && enddate > rEndDateTime.date()) { |
1495 | enddate = rEndDateTime.date(); | 1498 | enddate = rEndDateTime.date(); |
1496 | endtime.setDate(enddate); | 1499 | endtime.setDate(enddate); |
1497 | } | 1500 | } |
1498 | break; | 1501 | break; |
1499 | case NEXT_AFTER_DATE: | 1502 | case NEXT_AFTER_DATE: |
1500 | if (enddate < mRecurStart.date()) { | 1503 | if (enddate < mRecurStart.date()) { |
1501 | enddate = mRecurStart.date(); | 1504 | enddate = mRecurStart.date(); |
1502 | return 1; | 1505 | return 1; |
1503 | } | 1506 | } |
1504 | if (rDuration == 0 && enddate >= rEndDateTime.date()) { | 1507 | if (rDuration == 0 && enddate >= rEndDateTime.date()) { |
1505 | enddate = QDate(); | 1508 | enddate = QDate(); |
1506 | return 0; | 1509 | return 0; |
1507 | } | 1510 | } |
1508 | break; | 1511 | break; |
1509 | default: | 1512 | default: |
1510 | enddate = QDate(); | 1513 | enddate = QDate(); |
1511 | return 0; | 1514 | return 0; |
1512 | } | 1515 | } |
1513 | 1516 | ||
1514 | int count = 0; // default = error | 1517 | int count = 0; // default = error |
1515 | bool timed = false; | 1518 | bool timed = false; |
1516 | switch (recurs) { | 1519 | switch (recurs) { |
1517 | case rMinutely: | 1520 | case rMinutely: |
1518 | timed = true; | 1521 | timed = true; |
1519 | count = secondlyCalc(func, endtime, rFreq*60); | 1522 | count = secondlyCalc(func, endtime, rFreq*60); |
1520 | break; | 1523 | break; |
1521 | case rHourly: | 1524 | case rHourly: |
1522 | timed = true; | 1525 | timed = true; |
1523 | count = secondlyCalc(func, endtime, rFreq*3600); | 1526 | count = secondlyCalc(func, endtime, rFreq*3600); |
1524 | break; | 1527 | break; |
1525 | case rDaily: | 1528 | case rDaily: |
1526 | count = dailyCalc(func, enddate); | 1529 | count = dailyCalc(func, enddate); |
1527 | break; | 1530 | break; |
1528 | case rWeekly: | 1531 | case rWeekly: |
1529 | count = weeklyCalc(func, enddate); | 1532 | count = weeklyCalc(func, enddate); |
1530 | break; | 1533 | break; |
1531 | case rMonthlyPos: | 1534 | case rMonthlyPos: |
1532 | case rMonthlyDay: | 1535 | case rMonthlyDay: |
1533 | count = monthlyCalc(func, enddate); | 1536 | count = monthlyCalc(func, enddate); |
1534 | break; | 1537 | break; |
1535 | case rYearlyMonth: | 1538 | case rYearlyMonth: |
1536 | count = yearlyMonthCalc(func, enddate); | 1539 | count = yearlyMonthCalc(func, enddate); |
1537 | break; | 1540 | break; |
1538 | case rYearlyPos: | 1541 | case rYearlyPos: |
1539 | count = yearlyPosCalc(func, enddate); | 1542 | count = yearlyPosCalc(func, enddate); |
1540 | break; | 1543 | break; |
1541 | case rYearlyDay: | 1544 | case rYearlyDay: |
1542 | count = yearlyDayCalc(func, enddate); | 1545 | count = yearlyDayCalc(func, enddate); |
1543 | break; | 1546 | break; |
1544 | default: | 1547 | default: |
1545 | break; | 1548 | break; |
1546 | } | 1549 | } |
1547 | 1550 | ||
1548 | switch (func) { | 1551 | switch (func) { |
1549 | case END_DATE_AND_COUNT: | 1552 | case END_DATE_AND_COUNT: |
1550 | case NEXT_AFTER_DATE: | 1553 | case NEXT_AFTER_DATE: |
1551 | if (count == 0) | 1554 | if (count == 0) |
1552 | endtime = QDate(); | 1555 | endtime = QDateTime(); |
1553 | else if (timed) | 1556 | else if (timed) |
1554 | enddate = endtime.date(); | 1557 | enddate = endtime.date(); |
1555 | break; | 1558 | break; |
1556 | case COUNT_TO_DATE: | 1559 | case COUNT_TO_DATE: |
1557 | break; | 1560 | break; |
1558 | } | 1561 | } |
1559 | return count; | 1562 | return count; |
1560 | } | 1563 | } |
1561 | 1564 | ||
1562 | /* Find count and, depending on 'func', the end date/time of a secondly recurrence. | 1565 | /* Find count and, depending on 'func', the end date/time of a secondly recurrence. |
1563 | * Reply = total number of occurrences up to 'endtime', or 0 if error. | 1566 | * Reply = total number of occurrences up to 'endtime', or 0 if error. |
1564 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'endtime' is updated to the | 1567 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'endtime' is updated to the |
1565 | * recurrence end date/time. | 1568 | * recurrence end date/time. |
1566 | */ | 1569 | */ |
1567 | int Recurrence::secondlyCalc(PeriodFunc func, QDateTime &endtime, int freq) const | 1570 | int Recurrence::secondlyCalc(PeriodFunc func, QDateTime &endtime, int freq) const |
1568 | { | 1571 | { |
1569 | switch (func) { | 1572 | switch (func) { |
1570 | case END_DATE_AND_COUNT: | 1573 | case END_DATE_AND_COUNT: |
1571 | endtime = mRecurStart.addSecs((rDuration + mRecurExDatesCount - 1) * freq); | 1574 | endtime = mRecurStart.addSecs((rDuration + mRecurExDatesCount - 1) * freq); |
1572 | return rDuration + mRecurExDatesCount; | 1575 | return rDuration + mRecurExDatesCount; |
1573 | case COUNT_TO_DATE: { | 1576 | case COUNT_TO_DATE: { |
1574 | int n = mRecurStart.secsTo(endtime)/freq + 1; | 1577 | int n = mRecurStart.secsTo(endtime)/freq + 1; |
1575 | if (rDuration > 0 && n > rDuration + mRecurExDatesCount) | 1578 | if (rDuration > 0 && n > rDuration + mRecurExDatesCount) |
1576 | return rDuration + mRecurExDatesCount; | 1579 | return rDuration + mRecurExDatesCount; |
1577 | return n; | 1580 | return n; |
1578 | } | 1581 | } |
1579 | case NEXT_AFTER_DATE: { | 1582 | case NEXT_AFTER_DATE: { |
1580 | int count = mRecurStart.secsTo(endtime) / freq + 2; | 1583 | int count = mRecurStart.secsTo(endtime) / freq + 2; |
1581 | if (rDuration > 0 && count > rDuration) | 1584 | if (rDuration > 0 && count > rDuration) |
1582 | return 0; | 1585 | return 0; |
1583 | endtime = mRecurStart.addSecs((count - 1)*freq); | 1586 | endtime = mRecurStart.addSecs((count - 1)*freq); |
1584 | return count; | 1587 | return count; |
1585 | } | 1588 | } |
1586 | } | 1589 | } |
1587 | return 0; | 1590 | return 0; |
1588 | } | 1591 | } |
1589 | 1592 | ||
1590 | /* Find count and, depending on 'func', the end date of a daily recurrence. | 1593 | /* Find count and, depending on 'func', the end date of a daily recurrence. |
1591 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 1594 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
1592 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 1595 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
1593 | * recurrence end date. | 1596 | * recurrence end date. |
1594 | */ | 1597 | */ |
1595 | int Recurrence::dailyCalc(PeriodFunc func, QDate &enddate) const | 1598 | int Recurrence::dailyCalc(PeriodFunc func, QDate &enddate) const |
1596 | { | 1599 | { |
1597 | QDate dStart = mRecurStart.date(); | 1600 | QDate dStart = mRecurStart.date(); |
1598 | switch (func) { | 1601 | switch (func) { |
1599 | case END_DATE_AND_COUNT: | 1602 | case END_DATE_AND_COUNT: |
1600 | enddate = dStart.addDays((rDuration + mRecurExDatesCount - 1) * rFreq); | 1603 | enddate = dStart.addDays((rDuration + mRecurExDatesCount - 1) * rFreq); |
1601 | return rDuration + mRecurExDatesCount; | 1604 | return rDuration + mRecurExDatesCount; |
1602 | case COUNT_TO_DATE: { | 1605 | case COUNT_TO_DATE: { |
1603 | int n = dStart.daysTo(enddate)/rFreq + 1; | 1606 | int n = dStart.daysTo(enddate)/rFreq + 1; |
1604 | if (rDuration > 0 && n > rDuration + mRecurExDatesCount) | 1607 | if (rDuration > 0 && n > rDuration + mRecurExDatesCount) |
1605 | return rDuration + mRecurExDatesCount; | 1608 | return rDuration + mRecurExDatesCount; |
1606 | return n; | 1609 | return n; |
1607 | } | 1610 | } |
1608 | case NEXT_AFTER_DATE: { | 1611 | case NEXT_AFTER_DATE: { |
1609 | int count = dStart.daysTo(enddate) / rFreq + 2; | 1612 | int count = dStart.daysTo(enddate) / rFreq + 2; |
1610 | if (rDuration > 0 && count > rDuration) | 1613 | if (rDuration > 0 && count > rDuration) |
1611 | return 0; | 1614 | return 0; |
1612 | enddate = dStart.addDays((count - 1)*rFreq); | 1615 | enddate = dStart.addDays((count - 1)*rFreq); |
1613 | return count; | 1616 | return count; |
1614 | } | 1617 | } |
1615 | } | 1618 | } |
1616 | return 0; | 1619 | return 0; |
1617 | } | 1620 | } |
1618 | 1621 | ||
1619 | /* Find count and, depending on 'func', the end date of a weekly recurrence. | 1622 | /* Find count and, depending on 'func', the end date of a weekly recurrence. |
1620 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 1623 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
1621 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 1624 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
1622 | * recurrence end date. | 1625 | * recurrence end date. |
1623 | */ | 1626 | */ |
1624 | int Recurrence::weeklyCalc(PeriodFunc func, QDate &enddate) const | 1627 | int Recurrence::weeklyCalc(PeriodFunc func, QDate &enddate) const |
1625 | { | 1628 | { |
1626 | int daysPerWeek = 0; | 1629 | int daysPerWeek = 0; |
1627 | for (int i = 0; i < 7; ++i) { | 1630 | for (int i = 0; i < 7; ++i) { |
1628 | if (rDays.testBit((uint)i)) | 1631 | if (rDays.testBit((uint)i)) |
1629 | ++daysPerWeek; | 1632 | ++daysPerWeek; |
1630 | } | 1633 | } |
1631 | if (!daysPerWeek) | 1634 | if (!daysPerWeek) |
1632 | return 0; // there are no days to recur on | 1635 | return 0; // there are no days to recur on |
1633 | 1636 | ||
1634 | switch (func) { | 1637 | switch (func) { |
1635 | case END_DATE_AND_COUNT: | 1638 | case END_DATE_AND_COUNT: |
1636 | return weeklyCalcEndDate(enddate, daysPerWeek); | 1639 | return weeklyCalcEndDate(enddate, daysPerWeek); |
1637 | case COUNT_TO_DATE: | 1640 | case COUNT_TO_DATE: |
1638 | return weeklyCalcToDate(enddate, daysPerWeek); | 1641 | return weeklyCalcToDate(enddate, daysPerWeek); |
1639 | case NEXT_AFTER_DATE: | 1642 | case NEXT_AFTER_DATE: |
1640 | return weeklyCalcNextAfter(enddate, daysPerWeek); | 1643 | return weeklyCalcNextAfter(enddate, daysPerWeek); |
1641 | } | 1644 | } |
1642 | return 0; | 1645 | return 0; |
1643 | } | 1646 | } |
1644 | 1647 | ||
1645 | int Recurrence::weeklyCalcEndDate(QDate &enddate, int daysPerWeek) const | 1648 | int Recurrence::weeklyCalcEndDate(QDate &enddate, int daysPerWeek) const |
1646 | { | 1649 | { |
1647 | int startDayOfWeek = mRecurStart.date().dayOfWeek(); // 1..7 | 1650 | int startDayOfWeek = mRecurStart.date().dayOfWeek(); // 1..7 |
1648 | int countGone = 0; | 1651 | int countGone = 0; |
1649 | int daysGone = 0; | 1652 | int daysGone = 0; |
1650 | uint countTogo = rDuration + mRecurExDatesCount; | 1653 | uint countTogo = rDuration + mRecurExDatesCount; |
1651 | if (startDayOfWeek != rWeekStart) { | 1654 | if (startDayOfWeek != rWeekStart) { |
1652 | // Check what remains of the start week | 1655 | // Check what remains of the start week |
1653 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { | 1656 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { |
1654 | ++daysGone; | 1657 | ++daysGone; |
1655 | if (rDays.testBit((uint)i)) { | 1658 | if (rDays.testBit((uint)i)) { |
1656 | ++countGone; | 1659 | ++countGone; |
1657 | if (--countTogo == 0) | 1660 | if (--countTogo == 0) |
1658 | break; | 1661 | break; |
1659 | } | 1662 | } |
1660 | } | 1663 | } |
1661 | daysGone += 7 * (rFreq - 1); | 1664 | daysGone += 7 * (rFreq - 1); |
1662 | } | 1665 | } |
1663 | if (countTogo) { | 1666 | if (countTogo) { |
1664 | // Skip the remaining whole weeks | 1667 | // Skip the remaining whole weeks |
1665 | // Leave at least 1 recurrence remaining, in order to get its date | 1668 | // Leave at least 1 recurrence remaining, in order to get its date |
1666 | int wholeWeeks = (countTogo - 1) / daysPerWeek; | 1669 | int wholeWeeks = (countTogo - 1) / daysPerWeek; |
1667 | daysGone += wholeWeeks * 7 * rFreq; | 1670 | daysGone += wholeWeeks * 7 * rFreq; |
1668 | countGone += wholeWeeks * daysPerWeek; | 1671 | countGone += wholeWeeks * daysPerWeek; |
1669 | countTogo -= wholeWeeks * daysPerWeek; | 1672 | countTogo -= wholeWeeks * daysPerWeek; |
1670 | // Check the last week in the recurrence | 1673 | // Check the last week in the recurrence |
1671 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { | 1674 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { |
1672 | ++daysGone; | 1675 | ++daysGone; |
1673 | if (rDays.testBit((uint)i)) { | 1676 | if (rDays.testBit((uint)i)) { |
1674 | ++countGone; | 1677 | ++countGone; |
1675 | if (--countTogo == 0) | 1678 | if (--countTogo == 0) |
1676 | break; | 1679 | break; |
1677 | } | 1680 | } |
1678 | } | 1681 | } |
1679 | } | 1682 | } |
1680 | enddate = mRecurStart.date().addDays(daysGone); | 1683 | enddate = mRecurStart.date().addDays(daysGone); |
1681 | return countGone; | 1684 | return countGone; |
1682 | } | 1685 | } |
1683 | 1686 | ||
1684 | int Recurrence::weeklyCalcToDate(const QDate &enddate, int daysPerWeek) const | 1687 | int Recurrence::weeklyCalcToDate(const QDate &enddate, int daysPerWeek) const |
1685 | { | 1688 | { |
1686 | QDate dStart = mRecurStart.date(); | 1689 | QDate dStart = mRecurStart.date(); |
1687 | int startDayOfWeek = dStart.dayOfWeek(); // 1..7 | 1690 | int startDayOfWeek = dStart.dayOfWeek(); // 1..7 |
1688 | int countGone = 0; | 1691 | int countGone = 0; |
1689 | int daysGone = 0; | 1692 | int daysGone = 0; |
1690 | int totalDays = dStart.daysTo(enddate) + 1; | 1693 | int totalDays = dStart.daysTo(enddate) + 1; |
1691 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 1694 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
1692 | 1695 | ||
1693 | if (startDayOfWeek != rWeekStart) { | 1696 | if (startDayOfWeek != rWeekStart) { |
1694 | // Check what remains of the start week | 1697 | // Check what remains of the start week |
1695 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { | 1698 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { |
1696 | if (rDays.testBit((uint)i)) { | 1699 | if (rDays.testBit((uint)i)) { |
1697 | if (++countGone >= countMax) | 1700 | if (++countGone >= countMax) |
1698 | return countMax; | 1701 | return countMax; |
1699 | } | 1702 | } |
1700 | if (++daysGone == totalDays) | 1703 | if (++daysGone == totalDays) |
1701 | return countGone; | 1704 | return countGone; |
1702 | } | 1705 | } |
1703 | daysGone += 7 * (rFreq - 1); | 1706 | daysGone += 7 * (rFreq - 1); |
1704 | if (daysGone >= totalDays) | 1707 | if (daysGone >= totalDays) |
1705 | return countGone; | 1708 | return countGone; |
1706 | } | 1709 | } |
1707 | // Skip the remaining whole weeks | 1710 | // Skip the remaining whole weeks |
1708 | int wholeWeeks = (totalDays - daysGone) / 7; | 1711 | int wholeWeeks = (totalDays - daysGone) / 7; |
1709 | countGone += (wholeWeeks / rFreq) * daysPerWeek; | 1712 | countGone += (wholeWeeks / rFreq) * daysPerWeek; |
1710 | if (countGone >= countMax) | 1713 | if (countGone >= countMax) |
1711 | return countMax; | 1714 | return countMax; |
1712 | daysGone += wholeWeeks * 7; | 1715 | daysGone += wholeWeeks * 7; |
1713 | if (daysGone >= totalDays // have we reached the end date? | 1716 | if (daysGone >= totalDays // have we reached the end date? |
1714 | || wholeWeeks % rFreq) // is end week a recurrence week? | 1717 | || wholeWeeks % rFreq) // is end week a recurrence week? |
1715 | return countGone; | 1718 | return countGone; |
1716 | 1719 | ||
1717 | // Check the last week in the recurrence | 1720 | // Check the last week in the recurrence |
1718 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { | 1721 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { |
1719 | if (rDays.testBit((uint)i)) { | 1722 | if (rDays.testBit((uint)i)) { |
1720 | if (++countGone >= countMax) | 1723 | if (++countGone >= countMax) |
1721 | return countMax; | 1724 | return countMax; |
1722 | } | 1725 | } |
1723 | if (++daysGone == totalDays) | 1726 | if (++daysGone == totalDays) |
1724 | return countGone; | 1727 | return countGone; |
1725 | } | 1728 | } |
1726 | return countGone; | 1729 | return countGone; |
1727 | } | 1730 | } |
1728 | 1731 | ||
1729 | int Recurrence::weeklyCalcNextAfter(QDate &enddate, int daysPerWeek) const | 1732 | int Recurrence::weeklyCalcNextAfter(QDate &enddate, int daysPerWeek) const |
1730 | { | 1733 | { |
1731 | QDate dStart = mRecurStart.date(); | 1734 | QDate dStart = mRecurStart.date(); |
1732 | int startDayOfWeek = dStart.dayOfWeek(); // 1..7 | 1735 | int startDayOfWeek = dStart.dayOfWeek(); // 1..7 |
1733 | int totalDays = dStart.daysTo(enddate) + 1; | 1736 | int totalDays = dStart.daysTo(enddate) + 1; |
1734 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; | 1737 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; |
1735 | int countGone = 0; | 1738 | int countGone = 0; |
1736 | int daysGone = 0; | 1739 | int daysGone = 0; |
1737 | int recurWeeks; | 1740 | int recurWeeks; |
1738 | 1741 | ||
1739 | if (startDayOfWeek != rWeekStart) { | 1742 | if (startDayOfWeek != rWeekStart) { |
1740 | // Check what remains of the start week | 1743 | // Check what remains of the start week |
1741 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { | 1744 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { |
1742 | ++daysGone; | 1745 | ++daysGone; |
1743 | if (rDays.testBit((uint)i)) { | 1746 | if (rDays.testBit((uint)i)) { |
1744 | ++countGone; | 1747 | ++countGone; |
1745 | if (daysGone > totalDays) | 1748 | if (daysGone > totalDays) |
1746 | goto ex; | 1749 | goto ex; |
1747 | if (--countTogo == 0) | 1750 | if (--countTogo == 0) |
1748 | return 0; | 1751 | return 0; |
1749 | } | 1752 | } |
1750 | } | 1753 | } |
1751 | daysGone += 7 * (rFreq - 1); | 1754 | daysGone += 7 * (rFreq - 1); |
1752 | } | 1755 | } |
1753 | 1756 | ||
1754 | // Skip the remaining whole weeks | 1757 | // Skip the remaining whole weeks |
1755 | recurWeeks = (totalDays - daysGone) / (7 * rFreq); | 1758 | recurWeeks = (totalDays - daysGone) / (7 * rFreq); |
1756 | if (recurWeeks) { | 1759 | if (recurWeeks) { |
1757 | int n = recurWeeks * daysPerWeek; | 1760 | int n = recurWeeks * daysPerWeek; |
1758 | if (static_cast<uint>(n) > countTogo) | 1761 | if (static_cast<uint>(n) > countTogo) |
1759 | return 0; // reached end of recurrence | 1762 | return 0; // reached end of recurrence |
1760 | countGone += n; | 1763 | countGone += n; |
1761 | countTogo -= n; | 1764 | countTogo -= n; |
1762 | daysGone += recurWeeks * 7 * rFreq; | 1765 | daysGone += recurWeeks * 7 * rFreq; |
1763 | } | 1766 | } |
1764 | 1767 | ||
1765 | // Check the last week or two in the recurrence | 1768 | // Check the last week or two in the recurrence |
1766 | for ( ; ; ) { | 1769 | for ( ; ; ) { |
1767 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { | 1770 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { |
1768 | ++daysGone; | 1771 | ++daysGone; |
1769 | if (rDays.testBit((uint)i)) { | 1772 | if (rDays.testBit((uint)i)) { |
1770 | ++countGone; | 1773 | ++countGone; |
1771 | if (daysGone > totalDays) | 1774 | if (daysGone > totalDays) |
1772 | goto ex; | 1775 | goto ex; |
1773 | if (--countTogo == 0) | 1776 | if (--countTogo == 0) |
1774 | return 0; | 1777 | return 0; |
1775 | } | 1778 | } |
1776 | } | 1779 | } |
1777 | daysGone += 7 * (rFreq - 1); | 1780 | daysGone += 7 * (rFreq - 1); |
1778 | } | 1781 | } |
1779 | ex: | 1782 | ex: |
1780 | enddate = dStart.addDays(daysGone); | 1783 | enddate = dStart.addDays(daysGone); |
1781 | return countGone; | 1784 | return countGone; |
1782 | } | 1785 | } |
1783 | 1786 | ||
1784 | /* Find count and, depending on 'func', the end date of a monthly recurrence. | 1787 | /* Find count and, depending on 'func', the end date of a monthly recurrence. |
1785 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 1788 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
1786 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 1789 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
1787 | * recurrence end date. | 1790 | * recurrence end date. |
1788 | */ | 1791 | */ |
1789 | struct Recurrence::MonthlyData { | 1792 | struct Recurrence::MonthlyData { |
1790 | const Recurrence *recurrence; | 1793 | const Recurrence *recurrence; |
1791 | int year; // current year | 1794 | int year; // current year |
1792 | int month; // current month 0..11 | 1795 | int month; // current month 0..11 |
1793 | int day; // current day of month 1..31 | 1796 | int day; // current day of month 1..31 |
1794 | bool varies; // true if recurring days vary between different months | 1797 | bool varies; // true if recurring days vary between different months |
1795 | private: | 1798 | private: |
1796 | QValueList<int> days28, days29, days30, days31; // recurring days in months of each length | 1799 | Q3ValueList<int> days28, days29, days30, days31; // recurring days in months of each length |
1797 | QValueList<int> *recurDays[4]; | 1800 | Q3ValueList<int> *recurDays[4]; |
1798 | public: | 1801 | public: |
1799 | MonthlyData(const Recurrence* r, const QDate &date) | 1802 | MonthlyData(const Recurrence* r, const QDate &date) |
1800 | : recurrence(r), year(date.year()), month(date.month()-1), day(date.day()) | 1803 | : recurrence(r), year(date.year()), month(date.month()-1), day(date.day()) |
1801 | { recurDays[0] = &days28; | 1804 | { recurDays[0] = &days28; |
1802 | recurDays[1] = &days29; | 1805 | recurDays[1] = &days29; |
1803 | recurDays[2] = &days30; | 1806 | recurDays[2] = &days30; |
1804 | recurDays[3] = &days31; | 1807 | recurDays[3] = &days31; |
1805 | varies = (recurrence->recurs == rMonthlyPos) | 1808 | varies = (recurrence->recurs == rMonthlyPos) |
1806 | ? true : recurrence->getMonthlyDayDays(days31, 31); | 1809 | ? true : recurrence->getMonthlyDayDays(days31, 31); |
1807 | } | 1810 | } |
1808 | const QValueList<int>* dayList() const { | 1811 | const Q3ValueList<int>* dayList() const { |
1809 | if (!varies) | 1812 | if (!varies) |
1810 | return &days31; | 1813 | return &days31; |
1811 | QDate startOfMonth(year, month + 1, 1); | 1814 | QDate startOfMonth(year, month + 1, 1); |
1812 | int daysInMonth = startOfMonth.daysInMonth(); | 1815 | int daysInMonth = startOfMonth.daysInMonth(); |
1813 | QValueList<int>* days = recurDays[daysInMonth - 28]; | 1816 | Q3ValueList<int>* days = recurDays[daysInMonth - 28]; |
1814 | if (recurrence->recurs == rMonthlyPos) | 1817 | if (recurrence->recurs == rMonthlyPos) |
1815 | recurrence->getMonthlyPosDays(*days, daysInMonth, startOfMonth.dayOfWeek()); | 1818 | recurrence->getMonthlyPosDays(*days, daysInMonth, startOfMonth.dayOfWeek()); |
1816 | else if (days->isEmpty()) | 1819 | else if (days->isEmpty()) |
1817 | recurrence->getMonthlyDayDays(*days, daysInMonth); | 1820 | recurrence->getMonthlyDayDays(*days, daysInMonth); |
1818 | return days; | 1821 | return days; |
1819 | } | 1822 | } |
1820 | int yearMonth() const { return year*12 + month; } | 1823 | int yearMonth() const { return year*12 + month; } |
1821 | void addMonths(int diff) { month += diff; year += month / 12; month %= 12; } | 1824 | void addMonths(int diff) { month += diff; year += month / 12; month %= 12; } |
1822 | QDate date() const { return QDate(year, month + 1, day); } | 1825 | QDate date() const { return QDate(year, month + 1, day); } |
1823 | }; | 1826 | }; |
1824 | 1827 | ||
1825 | int Recurrence::monthlyCalc(PeriodFunc func, QDate &enddate) const | 1828 | int Recurrence::monthlyCalc(PeriodFunc func, QDate &enddate) const |
1826 | { | 1829 | { |
1827 | if (recurs == rMonthlyPos && rMonthPositions.isEmpty() | 1830 | if (recurs == rMonthlyPos && rMonthPositions.isEmpty() |
1828 | || recurs == rMonthlyDay && rMonthDays.isEmpty()) | 1831 | || recurs == rMonthlyDay && rMonthDays.isEmpty()) |
1829 | return 0; | 1832 | return 0; |
1830 | 1833 | ||
1831 | MonthlyData data(this, mRecurStart.date()); | 1834 | MonthlyData data(this, mRecurStart.date()); |
1832 | switch (func) { | 1835 | switch (func) { |
1833 | case END_DATE_AND_COUNT: | 1836 | case END_DATE_AND_COUNT: |
1834 | return monthlyCalcEndDate(enddate, data); | 1837 | return monthlyCalcEndDate(enddate, data); |
1835 | case COUNT_TO_DATE: | 1838 | case COUNT_TO_DATE: |
1836 | return monthlyCalcToDate(enddate, data); | 1839 | return monthlyCalcToDate(enddate, data); |
1837 | case NEXT_AFTER_DATE: | 1840 | case NEXT_AFTER_DATE: |
1838 | return monthlyCalcNextAfter(enddate, data); | 1841 | return monthlyCalcNextAfter(enddate, data); |
1839 | } | 1842 | } |
1840 | return 0; | 1843 | return 0; |
1841 | } | 1844 | } |
1842 | 1845 | ||
1843 | int Recurrence::monthlyCalcEndDate(QDate &enddate, MonthlyData &data) const | 1846 | int Recurrence::monthlyCalcEndDate(QDate &enddate, MonthlyData &data) const |
1844 | { | 1847 | { |
1845 | uint countTogo = rDuration + mRecurExDatesCount; | 1848 | uint countTogo = rDuration + mRecurExDatesCount; |
1846 | int countGone = 0; | 1849 | int countGone = 0; |
1847 | QValueList<int>::ConstIterator it; | 1850 | Q3ValueList<int>::ConstIterator it; |
1848 | const QValueList<int>* days = data.dayList(); | 1851 | const Q3ValueList<int>* days = data.dayList(); |
1849 | 1852 | ||
1850 | if (data.day > 1) { | 1853 | if (data.day > 1) { |
1851 | // Check what remains of the start month | 1854 | // Check what remains of the start month |
1852 | for (it = days->begin(); it != days->end(); ++it) { | 1855 | for (it = days->begin(); it != days->end(); ++it) { |
1853 | if (*it >= data.day) { | 1856 | if (*it >= data.day) { |
1854 | ++countGone; | 1857 | ++countGone; |
1855 | if (--countTogo == 0) { | 1858 | if (--countTogo == 0) { |
1856 | data.day = *it; | 1859 | data.day = *it; |
1857 | break; | 1860 | break; |
1858 | } | 1861 | } |
1859 | } | 1862 | } |
1860 | } | 1863 | } |
1861 | if (countTogo) { | 1864 | if (countTogo) { |
1862 | data.day = 1; | 1865 | data.day = 1; |
1863 | data.addMonths(rFreq); | 1866 | data.addMonths(rFreq); |
1864 | } | 1867 | } |
1865 | } | 1868 | } |
1866 | if (countTogo) { | 1869 | if (countTogo) { |
1867 | if (data.varies) { | 1870 | if (data.varies) { |
1868 | // The number of recurrence days varies from month to month, | 1871 | // The number of recurrence days varies from month to month, |
1869 | // so we need to check month by month. | 1872 | // so we need to check month by month. |
1870 | for ( ; ; ) { | 1873 | for ( ; ; ) { |
1871 | days = data.dayList(); | 1874 | days = data.dayList(); |
1872 | uint n = days->count(); // number of recurrence days in this month | 1875 | uint n = days->count(); // number of recurrence days in this month |
1873 | if (n >= countTogo) | 1876 | if (n >= countTogo) |
1874 | break; | 1877 | break; |
1875 | countTogo -= n; | 1878 | countTogo -= n; |
1876 | countGone += n; | 1879 | countGone += n; |
1877 | data.addMonths(rFreq); | 1880 | data.addMonths(rFreq); |
1878 | } | 1881 | } |
1879 | } else { | 1882 | } else { |
1880 | // The number of recurrences is the same every month, | 1883 | // The number of recurrences is the same every month, |
1881 | // so skip the month-by-month check. | 1884 | // so skip the month-by-month check. |
1882 | // Skip the remaining whole months, but leave at least | 1885 | // Skip the remaining whole months, but leave at least |
1883 | // 1 recurrence remaining, in order to get its date. | 1886 | // 1 recurrence remaining, in order to get its date. |
1884 | int daysPerMonth = days->count(); | 1887 | int daysPerMonth = days->count(); |
1885 | int wholeMonths = (countTogo - 1) / daysPerMonth; | 1888 | int wholeMonths = (countTogo - 1) / daysPerMonth; |
1886 | data.addMonths(wholeMonths * rFreq); | 1889 | data.addMonths(wholeMonths * rFreq); |
1887 | countGone += wholeMonths * daysPerMonth; | 1890 | countGone += wholeMonths * daysPerMonth; |
1888 | countTogo -= wholeMonths * daysPerMonth; | 1891 | countTogo -= wholeMonths * daysPerMonth; |
1889 | } | 1892 | } |
1890 | if (countTogo) { | 1893 | if (countTogo) { |
1891 | // Check the last month in the recurrence | 1894 | // Check the last month in the recurrence |
1892 | for (it = days->begin(); it != days->end(); ++it) { | 1895 | for (it = days->begin(); it != days->end(); ++it) { |
1893 | ++countGone; | 1896 | ++countGone; |
1894 | if (--countTogo == 0) { | 1897 | if (--countTogo == 0) { |
1895 | data.day = *it; | 1898 | data.day = *it; |
1896 | break; | 1899 | break; |
1897 | } | 1900 | } |
1898 | } | 1901 | } |
1899 | } | 1902 | } |
1900 | } | 1903 | } |
1901 | enddate = data.date(); | 1904 | enddate = data.date(); |
1902 | return countGone; | 1905 | return countGone; |
1903 | } | 1906 | } |
1904 | 1907 | ||
1905 | int Recurrence::monthlyCalcToDate(const QDate &enddate, MonthlyData &data) const | 1908 | int Recurrence::monthlyCalcToDate(const QDate &enddate, MonthlyData &data) const |
1906 | { | 1909 | { |
1907 | int countGone = 0; | 1910 | int countGone = 0; |
1908 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 1911 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
1909 | int endYear = enddate.year(); | 1912 | int endYear = enddate.year(); |
1910 | int endMonth = enddate.month() - 1; // zero-based | 1913 | int endMonth = enddate.month() - 1; // zero-based |
1911 | int endDay = enddate.day(); | 1914 | int endDay = enddate.day(); |
1912 | int endYearMonth = endYear*12 + endMonth; | 1915 | int endYearMonth = endYear*12 + endMonth; |
1913 | QValueList<int>::ConstIterator it; | 1916 | Q3ValueList<int>::ConstIterator it; |
1914 | const QValueList<int>* days = data.dayList(); | 1917 | const Q3ValueList<int>* days = data.dayList(); |
1915 | 1918 | ||
1916 | if (data.day > 1) { | 1919 | if (data.day > 1) { |
1917 | // Check what remains of the start month | 1920 | // Check what remains of the start month |
1918 | for (it = days->begin(); it != days->end(); ++it) { | 1921 | for (it = days->begin(); it != days->end(); ++it) { |
1919 | if (*it >= data.day) { | 1922 | if (*it >= data.day) { |
1920 | if (data.yearMonth() == endYearMonth && *it > endDay) | 1923 | if (data.yearMonth() == endYearMonth && *it > endDay) |
1921 | return countGone; | 1924 | return countGone; |
1922 | if (++countGone >= countMax) | 1925 | if (++countGone >= countMax) |
1923 | return countMax; | 1926 | return countMax; |
1924 | } | 1927 | } |
1925 | } | 1928 | } |
1926 | data.day = 1; | 1929 | data.day = 1; |
1927 | data.addMonths(rFreq); | 1930 | data.addMonths(rFreq); |
1928 | } | 1931 | } |
1929 | 1932 | ||
1930 | if (data.varies) { | 1933 | if (data.varies) { |
1931 | // The number of recurrence days varies from month to month, | 1934 | // The number of recurrence days varies from month to month, |
1932 | // so we need to check month by month. | 1935 | // so we need to check month by month. |
1933 | while (data.yearMonth() < endYearMonth) { | 1936 | while (data.yearMonth() < endYearMonth) { |
1934 | countGone += data.dayList()->count(); | 1937 | countGone += data.dayList()->count(); |
1935 | if (countGone >= countMax) | 1938 | if (countGone >= countMax) |
1936 | return countMax; | 1939 | return countMax; |
1937 | data.addMonths(rFreq); | 1940 | data.addMonths(rFreq); |
1938 | } | 1941 | } |
1939 | days = data.dayList(); | 1942 | days = data.dayList(); |
1940 | } else { | 1943 | } else { |
1941 | // The number of recurrences is the same every month, | 1944 | // The number of recurrences is the same every month, |
1942 | // so skip the month-by-month check. | 1945 | // so skip the month-by-month check. |
1943 | // Skip the remaining whole months. | 1946 | // Skip the remaining whole months. |
1944 | int daysPerMonth = days->count(); | 1947 | int daysPerMonth = days->count(); |
1945 | int wholeMonths = endYearMonth - data.yearMonth(); | 1948 | int wholeMonths = endYearMonth - data.yearMonth(); |
1946 | countGone += (wholeMonths / rFreq) * daysPerMonth; | 1949 | countGone += (wholeMonths / rFreq) * daysPerMonth; |
1947 | if (countGone >= countMax) | 1950 | if (countGone >= countMax) |
1948 | return countMax; | 1951 | return countMax; |
1949 | if (wholeMonths % rFreq) | 1952 | if (wholeMonths % rFreq) |
1950 | return countGone; // end year isn't a recurrence year | 1953 | return countGone; // end year isn't a recurrence year |
1951 | data.year = endYear; | 1954 | data.year = endYear; |
1952 | data.month = endMonth; | 1955 | data.month = endMonth; |
1953 | } | 1956 | } |
1954 | 1957 | ||
1955 | // Check the last month in the recurrence | 1958 | // Check the last month in the recurrence |
1956 | for (it = days->begin(); it != days->end(); ++it) { | 1959 | for (it = days->begin(); it != days->end(); ++it) { |
1957 | if (*it > endDay) | 1960 | if (*it > endDay) |
1958 | return countGone; | 1961 | return countGone; |
1959 | if (++countGone >= countMax) | 1962 | if (++countGone >= countMax) |
1960 | return countMax; | 1963 | return countMax; |
1961 | } | 1964 | } |
1962 | return countGone; | 1965 | return countGone; |
1963 | } | 1966 | } |
1964 | 1967 | ||
1965 | int Recurrence::monthlyCalcNextAfter(QDate &enddate, MonthlyData &data) const | 1968 | int Recurrence::monthlyCalcNextAfter(QDate &enddate, MonthlyData &data) const |
1966 | { | 1969 | { |
1967 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; | 1970 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; |
1968 | int countGone = 0; | 1971 | int countGone = 0; |
1969 | int endYear = enddate.year(); | 1972 | int endYear = enddate.year(); |
1970 | int endDay = enddate.day(); | 1973 | int endDay = enddate.day(); |
1971 | int endYearMonth = endYear*12 + enddate.month() - 1; | 1974 | int endYearMonth = endYear*12 + enddate.month() - 1; |
1972 | QValueList<int>::ConstIterator it; | 1975 | Q3ValueList<int>::ConstIterator it; |
1973 | const QValueList<int>* days = data.dayList(); | 1976 | const Q3ValueList<int>* days = data.dayList(); |
1974 | 1977 | ||
1975 | if (data.day > 1) { | 1978 | if (data.day > 1) { |
1976 | // Check what remains of the start month | 1979 | // Check what remains of the start month |
1977 | for (it = days->begin(); it != days->end(); ++it) { | 1980 | for (it = days->begin(); it != days->end(); ++it) { |
1978 | if (*it >= data.day) { | 1981 | if (*it >= data.day) { |
1979 | ++countGone; | 1982 | ++countGone; |
1980 | if (data.yearMonth() == endYearMonth && *it > endDay) { | 1983 | if (data.yearMonth() == endYearMonth && *it > endDay) { |
1981 | data.day = *it; | 1984 | data.day = *it; |
1982 | goto ex; | 1985 | goto ex; |
1983 | } | 1986 | } |
1984 | if (--countTogo == 0) | 1987 | if (--countTogo == 0) |
1985 | return 0; | 1988 | return 0; |
1986 | } | 1989 | } |
1987 | } | 1990 | } |
1988 | data.day = 1; | 1991 | data.day = 1; |
1989 | data.addMonths(rFreq); | 1992 | data.addMonths(rFreq); |
1990 | } | 1993 | } |
1991 | 1994 | ||
1992 | if (data.varies) { | 1995 | if (data.varies) { |
1993 | // The number of recurrence days varies from month to month, | 1996 | // The number of recurrence days varies from month to month, |
1994 | // so we need to check month by month. | 1997 | // so we need to check month by month. |
1995 | while (data.yearMonth() <= endYearMonth) { | 1998 | while (data.yearMonth() <= endYearMonth) { |
1996 | days = data.dayList(); | 1999 | days = data.dayList(); |
1997 | uint n = days->count(); // number of recurrence days in this month | 2000 | uint n = days->count(); // number of recurrence days in this month |
1998 | if (data.yearMonth() == endYearMonth && days->last() > endDay) | 2001 | if (data.yearMonth() == endYearMonth && days->last() > endDay) |
1999 | break; | 2002 | break; |
2000 | if (n >= countTogo) | 2003 | if (n >= countTogo) |
2001 | return 0; | 2004 | return 0; |
2002 | countGone += n; | 2005 | countGone += n; |
2003 | countTogo -= n; | 2006 | countTogo -= n; |
2004 | data.addMonths(rFreq); | 2007 | data.addMonths(rFreq); |
2005 | } | 2008 | } |
2006 | days = data.dayList(); | 2009 | days = data.dayList(); |
2007 | } else { | 2010 | } else { |
2008 | // The number of recurrences is the same every month, | 2011 | // The number of recurrences is the same every month, |
2009 | // so skip the month-by-month check. | 2012 | // so skip the month-by-month check. |
2010 | // Skip the remaining whole months to at least end year/month. | 2013 | // Skip the remaining whole months to at least end year/month. |
2011 | int daysPerMonth = days->count(); | 2014 | int daysPerMonth = days->count(); |
2012 | int elapsed = endYearMonth - data.yearMonth(); | 2015 | int elapsed = endYearMonth - data.yearMonth(); |
2013 | int recurMonths = (elapsed + rFreq - 1) / rFreq; | 2016 | int recurMonths = (elapsed + rFreq - 1) / rFreq; |
2014 | if (elapsed % rFreq == 0 && days->last() <= endDay) | 2017 | if (elapsed % rFreq == 0 && days->last() <= endDay) |
2015 | ++recurMonths; // required month is after endYearMonth | 2018 | ++recurMonths; // required month is after endYearMonth |
2016 | if (recurMonths) { | 2019 | if (recurMonths) { |
2017 | int n = recurMonths * daysPerMonth; | 2020 | int n = recurMonths * daysPerMonth; |
2018 | if (static_cast<uint>(n) > countTogo) | 2021 | if (static_cast<uint>(n) > countTogo) |
2019 | return 0; // reached end of recurrence | 2022 | return 0; // reached end of recurrence |
2020 | countTogo -= n; | 2023 | countTogo -= n; |
2021 | countGone += n; | 2024 | countGone += n; |
2022 | data.addMonths(recurMonths * rFreq); | 2025 | data.addMonths(recurMonths * rFreq); |
2023 | } | 2026 | } |
2024 | } | 2027 | } |
2025 | 2028 | ||
2026 | // Check the last month in the recurrence | 2029 | // Check the last month in the recurrence |
2027 | for (it = days->begin(); it != days->end(); ++it) { | 2030 | for (it = days->begin(); it != days->end(); ++it) { |
2028 | ++countGone; | 2031 | ++countGone; |
2029 | if (data.yearMonth() > endYearMonth || *it > endDay) { | 2032 | if (data.yearMonth() > endYearMonth || *it > endDay) { |
2030 | data.day = *it; | 2033 | data.day = *it; |
2031 | break; | 2034 | break; |
2032 | } | 2035 | } |
2033 | if (--countTogo == 0) | 2036 | if (--countTogo == 0) |
2034 | return 0; | 2037 | return 0; |
2035 | } | 2038 | } |
2036 | ex: | 2039 | ex: |
2037 | enddate = data.date(); | 2040 | enddate = data.date(); |
2038 | return countGone; | 2041 | return countGone; |
2039 | } | 2042 | } |
2040 | 2043 | ||
2041 | 2044 | ||
2042 | /* Find count and, depending on 'func', the end date of an annual recurrence by date. | 2045 | /* Find count and, depending on 'func', the end date of an annual recurrence by date. |
2043 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 2046 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
2044 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 2047 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
2045 | * recurrence end date. | 2048 | * recurrence end date. |
2046 | */ | 2049 | */ |
2047 | struct Recurrence::YearlyMonthData { | 2050 | struct Recurrence::YearlyMonthData { |
2048 | const Recurrence *recurrence; | 2051 | const Recurrence *recurrence; |
2049 | int year; // current year | 2052 | int year; // current year |
2050 | int month; // current month 1..12 | 2053 | int month; // current month 1..12 |
2051 | int day; // current day of month 1..31 | 2054 | int day; // current day of month 1..31 |
2052 | bool leapyear; // true if February 29th recurs and current year is a leap year | 2055 | bool leapyear; // true if February 29th recurs and current year is a leap year |
2053 | bool feb29; // true if February 29th recurs | 2056 | bool feb29; // true if February 29th recurs |
2054 | private: | 2057 | private: |
2055 | QValueList<int> months; // recurring months in non-leap years 1..12 | 2058 | Q3ValueList<int> months; // recurring months in non-leap years 1..12 |
2056 | QValueList<int> leapMonths; // recurring months in leap years 1..12 | 2059 | Q3ValueList<int> leapMonths; // recurring months in leap years 1..12 |
2057 | public: | 2060 | public: |
2058 | YearlyMonthData(const Recurrence* r, const QDate &date) | 2061 | YearlyMonthData(const Recurrence* r, const QDate &date) |
2059 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()) | 2062 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()) |
2060 | { feb29 = recurrence->getYearlyMonthMonths(day, months, leapMonths); | 2063 | { feb29 = recurrence->getYearlyMonthMonths(day, months, leapMonths); |
2061 | leapyear = feb29 && QDate::leapYear(year); | 2064 | leapyear = feb29 && QDate::leapYear(year); |
2062 | } | 2065 | } |
2063 | const QValueList<int>* monthList() const | 2066 | const Q3ValueList<int>* monthList() const |
2064 | { return leapyear ? &leapMonths : &months; } | 2067 | { return leapyear ? &leapMonths : &months; } |
2065 | const QValueList<int>* leapMonthList() const { return &leapMonths; } | 2068 | const Q3ValueList<int>* leapMonthList() const { return &leapMonths; } |
2066 | QDate date() const { return QDate(year, month, day); } | 2069 | QDate date() const { return QDate(year, month, day); } |
2067 | }; | 2070 | }; |
2068 | 2071 | ||
2069 | int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const | 2072 | int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const |
2070 | { | 2073 | { |
2071 | if (rYearNums.isEmpty()) | 2074 | if (rYearNums.isEmpty()) |
2072 | return 0; | 2075 | return 0; |
2073 | YearlyMonthData data(this, mRecurStart.date()); | 2076 | YearlyMonthData data(this, mRecurStart.date()); |
2074 | switch (func) { | 2077 | switch (func) { |
2075 | case END_DATE_AND_COUNT: | 2078 | case END_DATE_AND_COUNT: |
2076 | return yearlyMonthCalcEndDate(enddate, data); | 2079 | return yearlyMonthCalcEndDate(enddate, data); |
2077 | case COUNT_TO_DATE: | 2080 | case COUNT_TO_DATE: |
2078 | return yearlyMonthCalcToDate(enddate, data); | 2081 | return yearlyMonthCalcToDate(enddate, data); |
2079 | case NEXT_AFTER_DATE: | 2082 | case NEXT_AFTER_DATE: |
2080 | return yearlyMonthCalcNextAfter(enddate, data); | 2083 | return yearlyMonthCalcNextAfter(enddate, data); |
2081 | } | 2084 | } |
2082 | return 0; | 2085 | return 0; |
2083 | } | 2086 | } |
2084 | 2087 | ||
2085 | // Find total count and end date of an annual recurrence by date. | 2088 | // Find total count and end date of an annual recurrence by date. |
2086 | // Reply = total number of occurrences. | 2089 | // Reply = total number of occurrences. |
2087 | int Recurrence::yearlyMonthCalcEndDate(QDate &enddate, YearlyMonthData &data) const | 2090 | int Recurrence::yearlyMonthCalcEndDate(QDate &enddate, YearlyMonthData &data) const |
2088 | { | 2091 | { |
2089 | uint countTogo = rDuration + mRecurExDatesCount; | 2092 | uint countTogo = rDuration + mRecurExDatesCount; |
2090 | int countGone = 0; | 2093 | int countGone = 0; |
2091 | QValueList<int>::ConstIterator it; | 2094 | Q3ValueList<int>::ConstIterator it; |
2092 | const QValueList<int>* mons = data.monthList(); // get recurring months for this year | 2095 | const Q3ValueList<int>* mons = data.monthList(); // get recurring months for this year |
2093 | 2096 | ||
2094 | if (data.month > 1) { | 2097 | if (data.month > 1) { |
2095 | // Check what remains of the start year | 2098 | // Check what remains of the start year |
2096 | for (it = mons->begin(); it != mons->end(); ++it) { | 2099 | for (it = mons->begin(); it != mons->end(); ++it) { |
2097 | if (*it >= data.month) { | 2100 | if (*it >= data.month) { |
2098 | ++countGone; | 2101 | ++countGone; |
2099 | if (--countTogo == 0) { | 2102 | if (--countTogo == 0) { |
2100 | data.month = *it; | 2103 | data.month = *it; |
2101 | if (data.month == 2 && data.feb29 && !data.leapyear) { | 2104 | if (data.month == 2 && data.feb29 && !data.leapyear) { |
2102 | // The recurrence should end on February 29th, but it's a non-leap year | 2105 | // The recurrence should end on February 29th, but it's a non-leap year |
2103 | switch (mFeb29YearlyType) { | 2106 | switch (mFeb29YearlyType) { |
2104 | case rFeb28: | 2107 | case rFeb28: |
2105 | data.day = 28; | 2108 | data.day = 28; |
2106 | break; | 2109 | break; |
2107 | case rMar1: | 2110 | case rMar1: |
2108 | data.month = 3; | 2111 | data.month = 3; |
2109 | data.day = 1; | 2112 | data.day = 1; |
2110 | break; | 2113 | break; |
2111 | case rFeb29: | 2114 | case rFeb29: |
2112 | break; | 2115 | break; |
2113 | } | 2116 | } |
2114 | } | 2117 | } |
2115 | break; | 2118 | break; |
2116 | } | 2119 | } |
2117 | } | 2120 | } |
2118 | } | 2121 | } |
2119 | if (countTogo) { | 2122 | if (countTogo) { |
2120 | data.month = 1; | 2123 | data.month = 1; |
2121 | data.year += rFreq; | 2124 | data.year += rFreq; |
2122 | } | 2125 | } |
2123 | } | 2126 | } |
2124 | if (countTogo) { | 2127 | if (countTogo) { |
2125 | if (data.feb29 && mFeb29YearlyType == rFeb29) { | 2128 | if (data.feb29 && mFeb29YearlyType == rFeb29) { |
2126 | // The number of recurrences is different on leap years, | 2129 | // The number of recurrences is different on leap years, |
2127 | // so check year-by-year. | 2130 | // so check year-by-year. |
2128 | for ( ; ; ) { | 2131 | for ( ; ; ) { |
2129 | mons = data.monthList(); | 2132 | mons = data.monthList(); |
2130 | uint n = mons->count(); | 2133 | uint n = mons->count(); |
2131 | if (n >= countTogo) | 2134 | if (n >= countTogo) |
2132 | break; | 2135 | break; |
2133 | countTogo -= n; | 2136 | countTogo -= n; |
2134 | countGone += n; | 2137 | countGone += n; |
2135 | data.year += rFreq; | 2138 | data.year += rFreq; |
2136 | } | 2139 | } |
2137 | } else { | 2140 | } else { |
2138 | // The number of recurrences is the same every year, | 2141 | // The number of recurrences is the same every year, |
2139 | // so skip the year-by-year check. | 2142 | // so skip the year-by-year check. |
2140 | // Skip the remaining whole years, but leave at least | 2143 | // Skip the remaining whole years, but leave at least |
2141 | // 1 recurrence remaining, in order to get its date. | 2144 | // 1 recurrence remaining, in order to get its date. |
2142 | int monthsPerYear = mons->count(); | 2145 | int monthsPerYear = mons->count(); |
2143 | int wholeYears = (countTogo - 1) / monthsPerYear; | 2146 | int wholeYears = (countTogo - 1) / monthsPerYear; |
2144 | data.year += wholeYears * rFreq; | 2147 | data.year += wholeYears * rFreq; |
2145 | countGone += wholeYears * monthsPerYear; | 2148 | countGone += wholeYears * monthsPerYear; |
2146 | countTogo -= wholeYears * monthsPerYear; | 2149 | countTogo -= wholeYears * monthsPerYear; |
2147 | } | 2150 | } |
2148 | if (countTogo) { | 2151 | if (countTogo) { |
2149 | // Check the last year in the recurrence | 2152 | // Check the last year in the recurrence |
2150 | for (it = mons->begin(); it != mons->end(); ++it) { | 2153 | for (it = mons->begin(); it != mons->end(); ++it) { |
2151 | ++countGone; | 2154 | ++countGone; |
2152 | if (--countTogo == 0) { | 2155 | if (--countTogo == 0) { |
2153 | data.month = *it; | 2156 | data.month = *it; |
2154 | if (data.month == 2 && data.feb29 && !QDate::leapYear(data.year)) { | 2157 | if (data.month == 2 && data.feb29 && !QDate::leapYear(data.year)) { |
2155 | // The recurrence should end on February 29th, but it's a non-leap year | 2158 | // The recurrence should end on February 29th, but it's a non-leap year |
2156 | switch (mFeb29YearlyType) { | 2159 | switch (mFeb29YearlyType) { |
2157 | case rFeb28: | 2160 | case rFeb28: |
2158 | data.day = 28; | 2161 | data.day = 28; |
2159 | break; | 2162 | break; |
2160 | case rMar1: | 2163 | case rMar1: |
2161 | data.month = 3; | 2164 | data.month = 3; |
2162 | data.day = 1; | 2165 | data.day = 1; |
2163 | break; | 2166 | break; |
2164 | case rFeb29: | 2167 | case rFeb29: |
2165 | break; | 2168 | break; |
2166 | } | 2169 | } |
2167 | } | 2170 | } |
2168 | break; | 2171 | break; |
2169 | } | 2172 | } |
2170 | } | 2173 | } |
2171 | } | 2174 | } |
2172 | } | 2175 | } |
2173 | enddate = data.date(); | 2176 | enddate = data.date(); |
2174 | return countGone; | 2177 | return countGone; |
2175 | } | 2178 | } |
2176 | 2179 | ||
2177 | // Find count of an annual recurrence by date. | 2180 | // Find count of an annual recurrence by date. |
2178 | // Reply = total number of occurrences up to 'enddate'. | 2181 | // Reply = total number of occurrences up to 'enddate'. |
2179 | int Recurrence::yearlyMonthCalcToDate(const QDate &enddate, YearlyMonthData &data) const | 2182 | int Recurrence::yearlyMonthCalcToDate(const QDate &enddate, YearlyMonthData &data) const |
2180 | { | 2183 | { |
2181 | int countGone = 0; | 2184 | int countGone = 0; |
2182 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 2185 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
2183 | int endYear = enddate.year(); | 2186 | int endYear = enddate.year(); |
2184 | int endMonth = enddate.month(); | 2187 | int endMonth = enddate.month(); |
2185 | int endDay = enddate.day(); | 2188 | int endDay = enddate.day(); |
2186 | if (endDay < data.day) { | 2189 | if (endDay < data.day) { |
2187 | /* The end day of the month is earlier than the recurrence day of the month. | 2190 | /* The end day of the month is earlier than the recurrence day of the month. |
2188 | * If Feb 29th recurs and: | 2191 | * If Feb 29th recurs and: |
2189 | * 1) it recurs on Feb 28th in non-leap years, don't adjust the end month | 2192 | * 1) it recurs on Feb 28th in non-leap years, don't adjust the end month |
2190 | * if enddate is Feb 28th on a non-leap year. | 2193 | * if enddate is Feb 28th on a non-leap year. |
2191 | * 2) it recurs on Mar 1st in non-leap years, allow the end month to be | 2194 | * 2) it recurs on Mar 1st in non-leap years, allow the end month to be |
2192 | * adjusted to February, to simplify calculations. | 2195 | * adjusted to February, to simplify calculations. |
2193 | */ | 2196 | */ |
2194 | if (data.feb29 && !QDate::leapYear(endYear) | 2197 | if (data.feb29 && !QDate::leapYear(endYear) |
2195 | && mFeb29YearlyType == rFeb28 && endDay == 28 && endMonth == 2) { | 2198 | && mFeb29YearlyType == rFeb28 && endDay == 28 && endMonth == 2) { |
2196 | } | 2199 | } |
2197 | else if (--endMonth == 0) { | 2200 | else if (--endMonth == 0) { |
2198 | endMonth = 12; | 2201 | endMonth = 12; |
2199 | --endYear; | 2202 | --endYear; |
2200 | } | 2203 | } |
2201 | } | 2204 | } |
2202 | QValueList<int>::ConstIterator it; | 2205 | Q3ValueList<int>::ConstIterator it; |
2203 | const QValueList<int>* mons = data.monthList(); | 2206 | const Q3ValueList<int>* mons = data.monthList(); |
2204 | 2207 | ||
2205 | if (data.month > 1) { | 2208 | if (data.month > 1) { |
2206 | // Check what remains of the start year | 2209 | // Check what remains of the start year |
2207 | for (it = mons->begin(); it != mons->end(); ++it) { | 2210 | for (it = mons->begin(); it != mons->end(); ++it) { |
2208 | if (*it >= data.month) { | 2211 | if (*it >= data.month) { |
2209 | if (data.year == endYear && *it > endMonth) | 2212 | if (data.year == endYear && *it > endMonth) |
2210 | return countGone; | 2213 | return countGone; |
2211 | if (++countGone >= countMax) | 2214 | if (++countGone >= countMax) |
2212 | return countMax; | 2215 | return countMax; |
2213 | } | 2216 | } |
2214 | } | 2217 | } |
2215 | data.month = 1; | 2218 | data.month = 1; |
2216 | data.year += rFreq; | 2219 | data.year += rFreq; |
2217 | } | 2220 | } |
2218 | if (data.feb29 && mFeb29YearlyType == rFeb29) { | 2221 | if (data.feb29 && mFeb29YearlyType == rFeb29) { |
2219 | // The number of recurrences is different on leap years, | 2222 | // The number of recurrences is different on leap years, |
2220 | // so check year-by-year. | 2223 | // so check year-by-year. |
2221 | while (data.year < endYear) { | 2224 | while (data.year < endYear) { |
2222 | countGone += data.monthList()->count(); | 2225 | countGone += data.monthList()->count(); |
2223 | if (countGone >= countMax) | 2226 | if (countGone >= countMax) |
2224 | return countMax; | 2227 | return countMax; |
2225 | data.year += rFreq; | 2228 | data.year += rFreq; |
2226 | } | 2229 | } |
2227 | mons = data.monthList(); | 2230 | mons = data.monthList(); |
2228 | } else { | 2231 | } else { |
2229 | // The number of recurrences is the same every year, | 2232 | // The number of recurrences is the same every year, |
2230 | // so skip the year-by-year check. | 2233 | // so skip the year-by-year check. |
2231 | // Skip the remaining whole years. | 2234 | // Skip the remaining whole years. |
2232 | int monthsPerYear = mons->count(); | 2235 | int monthsPerYear = mons->count(); |
2233 | int wholeYears = endYear - data.year; | 2236 | int wholeYears = endYear - data.year; |
2234 | countGone += (wholeYears / rFreq) * monthsPerYear; | 2237 | countGone += (wholeYears / rFreq) * monthsPerYear; |
2235 | if (countGone >= countMax) | 2238 | if (countGone >= countMax) |
2236 | return countMax; | 2239 | return countMax; |
2237 | if (wholeYears % rFreq) | 2240 | if (wholeYears % rFreq) |
2238 | return countGone; // end year isn't a recurrence year | 2241 | return countGone; // end year isn't a recurrence year |
2239 | data.year = endYear; | 2242 | data.year = endYear; |
2240 | } | 2243 | } |
2241 | 2244 | ||
2242 | // Check the last year in the recurrence | 2245 | // Check the last year in the recurrence |
2243 | for (it = mons->begin(); it != mons->end(); ++it) { | 2246 | for (it = mons->begin(); it != mons->end(); ++it) { |
2244 | if (*it > endMonth) | 2247 | if (*it > endMonth) |
2245 | return countGone; | 2248 | return countGone; |
2246 | if (++countGone >= countMax) | 2249 | if (++countGone >= countMax) |
2247 | return countMax; | 2250 | return countMax; |
2248 | } | 2251 | } |
2249 | return countGone; | 2252 | return countGone; |
2250 | } | 2253 | } |
2251 | 2254 | ||
2252 | // Find count and date of first recurrence after 'enddate' of an annual recurrence by date. | 2255 | // Find count and date of first recurrence after 'enddate' of an annual recurrence by date. |
2253 | // Reply = total number of occurrences up to 'enddate'. | 2256 | // Reply = total number of occurrences up to 'enddate'. |
2254 | int Recurrence::yearlyMonthCalcNextAfter(QDate &enddate, YearlyMonthData &data) const | 2257 | int Recurrence::yearlyMonthCalcNextAfter(QDate &enddate, YearlyMonthData &data) const |
2255 | { | 2258 | { |
2256 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; | 2259 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; |
2257 | int countGone = 0; | 2260 | int countGone = 0; |
2258 | int endYear = enddate.year(); | 2261 | int endYear = enddate.year(); |
2259 | int endMonth = enddate.month(); | 2262 | int endMonth = enddate.month(); |
2260 | int endDay = enddate.day(); | 2263 | int endDay = enddate.day(); |
2261 | bool mar1TooEarly = false; | 2264 | bool mar1TooEarly = false; |
2262 | bool feb28ok = false; | 2265 | bool feb28ok = false; |
2263 | if (endDay < data.day) { | 2266 | if (endDay < data.day) { |
2264 | if (data.feb29 && mFeb29YearlyType == rMar1 && endMonth == 3) | 2267 | if (data.feb29 && mFeb29YearlyType == rMar1 && endMonth == 3) |
2265 | mar1TooEarly = true; | 2268 | mar1TooEarly = true; |
2266 | if (data.feb29 && mFeb29YearlyType == rFeb28 && endMonth == 2 && endDay == 28) | 2269 | if (data.feb29 && mFeb29YearlyType == rFeb28 && endMonth == 2 && endDay == 28) |
2267 | feb28ok = true; | 2270 | feb28ok = true; |
2268 | else if (--endMonth == 0) { | 2271 | else if (--endMonth == 0) { |
2269 | endMonth = 12; | 2272 | endMonth = 12; |
2270 | --endYear; | 2273 | --endYear; |
2271 | } | 2274 | } |
2272 | } | 2275 | } |
2273 | QValueList<int>::ConstIterator it; | 2276 | Q3ValueList<int>::ConstIterator it; |
2274 | const QValueList<int>* mons = data.monthList(); | 2277 | const Q3ValueList<int>* mons = data.monthList(); |
2275 | 2278 | ||
2276 | if (data.month > 1) { | 2279 | if (data.month > 1) { |
2277 | // Check what remains of the start year | 2280 | // Check what remains of the start year |
2278 | for (it = mons->begin(); it != mons->end(); ++it) { | 2281 | for (it = mons->begin(); it != mons->end(); ++it) { |
2279 | if (*it >= data.month) { | 2282 | if (*it >= data.month) { |
2280 | ++countGone; | 2283 | ++countGone; |
2281 | if (data.year == endYear | 2284 | if (data.year == endYear |
2282 | && ( *it > endMonth && (*it > 3 || !mar1TooEarly) | 2285 | && ( *it > endMonth && (*it > 3 || !mar1TooEarly) |
2283 | || *it == 2 && feb28ok && data.leapyear)) { | 2286 | || *it == 2 && feb28ok && data.leapyear)) { |
2284 | if (*it == 2 && data.feb29 && !data.leapyear) { | 2287 | if (*it == 2 && data.feb29 && !data.leapyear) { |
2285 | // The next recurrence should be on February 29th, but it's a non-leap year | 2288 | // The next recurrence should be on February 29th, but it's a non-leap year |
2286 | switch (mFeb29YearlyType) { | 2289 | switch (mFeb29YearlyType) { |
2287 | case rFeb28: | 2290 | case rFeb28: |
2288 | data.month = 2; | 2291 | data.month = 2; |
2289 | data.day = 28; | 2292 | data.day = 28; |
2290 | break; | 2293 | break; |
2291 | case rMar1: | 2294 | case rMar1: |
2292 | data.month = 3; | 2295 | data.month = 3; |
2293 | data.day = 1; | 2296 | data.day = 1; |
2294 | break; | 2297 | break; |
2295 | case rFeb29: // impossible in this context! | 2298 | case rFeb29: // impossible in this context! |
2296 | break; | 2299 | break; |
2297 | } | 2300 | } |
2298 | } | 2301 | } |
2299 | else | 2302 | else |
2300 | data.month = *it; | 2303 | data.month = *it; |
2301 | goto ex; | 2304 | goto ex; |
2302 | } | 2305 | } |
2303 | if (--countTogo == 0) | 2306 | if (--countTogo == 0) |
2304 | return 0; | 2307 | return 0; |
2305 | } | 2308 | } |
2306 | } | 2309 | } |
2307 | data.month = 1; | 2310 | data.month = 1; |
2308 | data.year += rFreq; | 2311 | data.year += rFreq; |
2309 | } | 2312 | } |
2310 | 2313 | ||
2311 | if (data.feb29 && mFeb29YearlyType == rFeb29) { | 2314 | if (data.feb29 && mFeb29YearlyType == rFeb29) { |
2312 | // The number of recurrences is different on leap years, | 2315 | // The number of recurrences is different on leap years, |
2313 | // so check year-by-year. | 2316 | // so check year-by-year. |
2314 | while (data.year <= endYear) { | 2317 | while (data.year <= endYear) { |
2315 | mons = data.monthList(); | 2318 | mons = data.monthList(); |
2316 | if (data.year == endYear && mons->last() > endMonth) | 2319 | if (data.year == endYear && mons->last() > endMonth) |
2317 | break; | 2320 | break; |
2318 | uint n = mons->count(); | 2321 | uint n = mons->count(); |
2319 | if (n >= countTogo) | 2322 | if (n >= countTogo) |
2320 | break; | 2323 | break; |
2321 | countTogo -= n; | 2324 | countTogo -= n; |
2322 | countGone += n; | 2325 | countGone += n; |
2323 | data.year += rFreq; | 2326 | data.year += rFreq; |
2324 | } | 2327 | } |
2325 | mons = data.monthList(); | 2328 | mons = data.monthList(); |
2326 | } else { | 2329 | } else { |
2327 | // The number of recurrences is the same every year, | 2330 | // The number of recurrences is the same every year, |
2328 | // so skip the year-by-year check. | 2331 | // so skip the year-by-year check. |
2329 | // Skip the remaining whole years to at least endYear. | 2332 | // Skip the remaining whole years to at least endYear. |
2330 | int monthsPerYear = mons->count(); | 2333 | int monthsPerYear = mons->count(); |
2331 | int recurYears = (endYear - data.year + rFreq - 1) / rFreq; | 2334 | int recurYears = (endYear - data.year + rFreq - 1) / rFreq; |
2332 | if ((endYear - data.year)%rFreq == 0 | 2335 | if ((endYear - data.year)%rFreq == 0 |
2333 | && mons->last() <= endMonth) | 2336 | && mons->last() <= endMonth) |
2334 | ++recurYears; // required year is after endYear | 2337 | ++recurYears; // required year is after endYear |
2335 | if (recurYears) { | 2338 | if (recurYears) { |
2336 | int n = recurYears * monthsPerYear; | 2339 | int n = recurYears * monthsPerYear; |
2337 | if (static_cast<uint>(n) > countTogo) | 2340 | if (static_cast<uint>(n) > countTogo) |
2338 | return 0; // reached end of recurrence | 2341 | return 0; // reached end of recurrence |
2339 | countTogo -= n; | 2342 | countTogo -= n; |
2340 | countGone += n; | 2343 | countGone += n; |
2341 | data.year += recurYears * rFreq; | 2344 | data.year += recurYears * rFreq; |
2342 | } | 2345 | } |
2343 | } | 2346 | } |
2344 | 2347 | ||
2345 | // Check the last year in the recurrence | 2348 | // Check the last year in the recurrence |
2346 | for (it = mons->begin(); it != mons->end(); ++it) { | 2349 | for (it = mons->begin(); it != mons->end(); ++it) { |
2347 | ++countGone; | 2350 | ++countGone; |
2348 | if (data.year > endYear | 2351 | if (data.year > endYear |
2349 | || ( *it > endMonth && (*it > 3 || !mar1TooEarly) | 2352 | || ( *it > endMonth && (*it > 3 || !mar1TooEarly) |
2350 | || *it == 2 && feb28ok && QDate::leapYear(data.year))) { | 2353 | || *it == 2 && feb28ok && QDate::leapYear(data.year))) { |
2351 | if (*it == 2 && data.feb29 && !QDate::leapYear(data.year)) { | 2354 | if (*it == 2 && data.feb29 && !QDate::leapYear(data.year)) { |
2352 | // The next recurrence should be on February 29th, but it's a non-leap year | 2355 | // The next recurrence should be on February 29th, but it's a non-leap year |
2353 | switch (mFeb29YearlyType) { | 2356 | switch (mFeb29YearlyType) { |
2354 | case rFeb28: | 2357 | case rFeb28: |
2355 | data.month = 2; | 2358 | data.month = 2; |
2356 | data.day = 28; | 2359 | data.day = 28; |
2357 | break; | 2360 | break; |
2358 | case rMar1: | 2361 | case rMar1: |
2359 | data.month = 3; | 2362 | data.month = 3; |
2360 | data.day = 1; | 2363 | data.day = 1; |
2361 | break; | 2364 | break; |
2362 | case rFeb29: // impossible in this context! | 2365 | case rFeb29: // impossible in this context! |
2363 | break; | 2366 | break; |
2364 | } | 2367 | } |
2365 | } | 2368 | } |
2366 | else | 2369 | else |
2367 | data.month = *it; | 2370 | data.month = *it; |
2368 | break; | 2371 | break; |
2369 | } | 2372 | } |
2370 | if (--countTogo == 0) | 2373 | if (--countTogo == 0) |
2371 | return 0; | 2374 | return 0; |
2372 | } | 2375 | } |
2373 | ex: | 2376 | ex: |
2374 | enddate = data.date(); | 2377 | enddate = data.date(); |
2375 | return countGone; | 2378 | return countGone; |
2376 | } | 2379 | } |
2377 | 2380 | ||
2378 | 2381 | ||
2379 | /* Find count and, depending on 'func', the end date of an annual recurrence by date. | 2382 | /* Find count and, depending on 'func', the end date of an annual recurrence by date. |
2380 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 2383 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
2381 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 2384 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
2382 | * recurrence end date. | 2385 | * recurrence end date. |
2383 | */ | 2386 | */ |
2384 | struct Recurrence::YearlyPosData { | 2387 | struct Recurrence::YearlyPosData { |
2385 | const Recurrence *recurrence; | 2388 | const Recurrence *recurrence; |
2386 | int year; // current year | 2389 | int year; // current year |
2387 | int month; // current month 1..12 | 2390 | int month; // current month 1..12 |
2388 | int day; // current day of month 1..31 | 2391 | int day; // current day of month 1..31 |
2389 | int daysPerMonth; // number of days which recur each month, or -1 if variable | 2392 | int daysPerMonth; // number of days which recur each month, or -1 if variable |
2390 | int count; // number of days which recur each year, or -1 if variable | 2393 | int count; // number of days which recur each year, or -1 if variable |
2391 | bool varies; // true if number of days varies from year to year | 2394 | bool varies; // true if number of days varies from year to year |
2392 | private: | 2395 | private: |
2393 | mutable QValueList<int> days; | 2396 | mutable Q3ValueList<int> days; |
2394 | public: | 2397 | public: |
2395 | YearlyPosData(const Recurrence* r, const QDate &date) | 2398 | YearlyPosData(const Recurrence* r, const QDate &date) |
2396 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()), count(-1) | 2399 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()), count(-1) |
2397 | { if ((daysPerMonth = r->countMonthlyPosDays()) > 0) | 2400 | { if ((daysPerMonth = r->countMonthlyPosDays()) > 0) |
2398 | count = daysPerMonth * r->rYearNums.count(); | 2401 | count = daysPerMonth * r->rYearNums.count(); |
2399 | varies = (daysPerMonth < 0); | 2402 | varies = (daysPerMonth < 0); |
2400 | } | 2403 | } |
2401 | const QValueList<int>* dayList() const { | 2404 | const Q3ValueList<int>* dayList() const { |
2402 | QDate startOfMonth(year, month, 1); | 2405 | QDate startOfMonth(year, month, 1); |
2403 | recurrence->getMonthlyPosDays(days, startOfMonth.daysInMonth(), startOfMonth.dayOfWeek()); | 2406 | recurrence->getMonthlyPosDays(days, startOfMonth.daysInMonth(), startOfMonth.dayOfWeek()); |
2404 | return &days; | 2407 | return &days; |
2405 | } | 2408 | } |
2406 | int yearMonth() const { return year*12 + month - 1; } | 2409 | int yearMonth() const { return year*12 + month - 1; } |
2407 | void addMonths(int diff) { month += diff - 1; year += month / 12; month = month % 12 + 1; } | 2410 | void addMonths(int diff) { month += diff - 1; year += month / 12; month = month % 12 + 1; } |
2408 | QDate date() const { return QDate(year, month, day); } | 2411 | QDate date() const { return QDate(year, month, day); } |
2409 | }; | 2412 | }; |
2410 | 2413 | ||
2411 | int Recurrence::yearlyPosCalc(PeriodFunc func, QDate &enddate) const | 2414 | int Recurrence::yearlyPosCalc(PeriodFunc func, QDate &enddate) const |
2412 | { | 2415 | { |
2413 | if (rYearNums.isEmpty() || rMonthPositions.isEmpty()) | 2416 | if (rYearNums.isEmpty() || rMonthPositions.isEmpty()) |
2414 | return 0; | 2417 | return 0; |
2415 | YearlyPosData data(this, mRecurStart.date()); | 2418 | YearlyPosData data(this, mRecurStart.date()); |
2416 | switch (func) { | 2419 | switch (func) { |
2417 | case END_DATE_AND_COUNT: | 2420 | case END_DATE_AND_COUNT: |
2418 | return yearlyPosCalcEndDate(enddate, data); | 2421 | return yearlyPosCalcEndDate(enddate, data); |
2419 | case COUNT_TO_DATE: | 2422 | case COUNT_TO_DATE: |
2420 | return yearlyPosCalcToDate(enddate, data); | 2423 | return yearlyPosCalcToDate(enddate, data); |
2421 | case NEXT_AFTER_DATE: | 2424 | case NEXT_AFTER_DATE: |
2422 | return yearlyPosCalcNextAfter(enddate, data); | 2425 | return yearlyPosCalcNextAfter(enddate, data); |
2423 | } | 2426 | } |
2424 | return 0; | 2427 | return 0; |
2425 | } | 2428 | } |
2426 | 2429 | ||
2427 | int Recurrence::yearlyPosCalcEndDate(QDate &enddate, YearlyPosData &data) const | 2430 | int Recurrence::yearlyPosCalcEndDate(QDate &enddate, YearlyPosData &data) const |
2428 | { | 2431 | { |
2429 | uint countTogo = rDuration + mRecurExDatesCount; | 2432 | uint countTogo = rDuration + mRecurExDatesCount; |
2430 | int countGone = 0; | 2433 | int countGone = 0; |
2431 | QValueList<int>::ConstIterator id; | 2434 | Q3ValueList<int>::ConstIterator id; |
2432 | const QValueList<int>* days; | 2435 | const Q3ValueList<int>* days; |
2433 | 2436 | ||
2434 | if (data.month > 1 || data.day > 1) { | 2437 | if (data.month > 1 || data.day > 1) { |
2435 | // Check what remains of the start year | 2438 | // Check what remains of the start year |
2436 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2439 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2437 | if (*im.current() >= data.month) { | 2440 | if (*im.current() >= data.month) { |
2438 | // Check what remains of the start month | 2441 | // Check what remains of the start month |
2439 | if (data.day > 1 || data.varies | 2442 | if (data.day > 1 || data.varies |
2440 | || static_cast<uint>(data.daysPerMonth) >= countTogo) { | 2443 | || static_cast<uint>(data.daysPerMonth) >= countTogo) { |
2441 | data.month = *im.current(); | 2444 | data.month = *im.current(); |
2442 | days = data.dayList(); | 2445 | days = data.dayList(); |
2443 | for (id = days->begin(); id != days->end(); ++id) { | 2446 | for (id = days->begin(); id != days->end(); ++id) { |
2444 | if (*id >= data.day) { | 2447 | if (*id >= data.day) { |
2445 | ++countGone; | 2448 | ++countGone; |
2446 | if (--countTogo == 0) { | 2449 | if (--countTogo == 0) { |
2447 | data.month = *im.current(); | 2450 | data.month = *im.current(); |
2448 | data.day = *id; | 2451 | data.day = *id; |
2449 | goto ex; | 2452 | goto ex; |
2450 | } | 2453 | } |
2451 | } | 2454 | } |
2452 | } | 2455 | } |
2453 | data.day = 1; | 2456 | data.day = 1; |
2454 | } else { | 2457 | } else { |
2455 | // The number of days per month is constant, so skip | 2458 | // The number of days per month is constant, so skip |
2456 | // the whole month. | 2459 | // the whole month. |
2457 | countTogo -= data.daysPerMonth; | 2460 | countTogo -= data.daysPerMonth; |
2458 | countGone += data.daysPerMonth; | 2461 | countGone += data.daysPerMonth; |
2459 | } | 2462 | } |
2460 | } | 2463 | } |
2461 | } | 2464 | } |
2462 | data.month = 1; | 2465 | data.month = 1; |
2463 | data.year += rFreq; | 2466 | data.year += rFreq; |
2464 | } | 2467 | } |
2465 | 2468 | ||
2466 | if (data.varies) { | 2469 | if (data.varies) { |
2467 | // The number of recurrences varies from year to year. | 2470 | // The number of recurrences varies from year to year. |
2468 | for ( ; ; ) { | 2471 | for ( ; ; ) { |
2469 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2472 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2470 | data.month = *im.current(); | 2473 | data.month = *im.current(); |
2471 | days = data.dayList(); | 2474 | days = data.dayList(); |
2472 | int n = days->count(); | 2475 | int n = days->count(); |
2473 | if (static_cast<uint>(n) >= countTogo) { | 2476 | if (static_cast<uint>(n) >= countTogo) { |
2474 | // Check the last month in the recurrence | 2477 | // Check the last month in the recurrence |
2475 | for (id = days->begin(); id != days->end(); ++id) { | 2478 | for (id = days->begin(); id != days->end(); ++id) { |
2476 | ++countGone; | 2479 | ++countGone; |
2477 | if (--countTogo == 0) { | 2480 | if (--countTogo == 0) { |
2478 | data.day = *id; | 2481 | data.day = *id; |
2479 | goto ex; | 2482 | goto ex; |
2480 | } | 2483 | } |
2481 | } | 2484 | } |
2482 | } | 2485 | } |
2483 | countTogo -= n; | 2486 | countTogo -= n; |
2484 | countGone += n; | 2487 | countGone += n; |
2485 | } | 2488 | } |
2486 | data.year += rFreq; | 2489 | data.year += rFreq; |
2487 | } | 2490 | } |
2488 | } else { | 2491 | } else { |
2489 | // The number of recurrences is the same every year, | 2492 | // The number of recurrences is the same every year, |
2490 | // so skip the year-by-year check. | 2493 | // so skip the year-by-year check. |
2491 | // Skip the remaining whole years, but leave at least | 2494 | // Skip the remaining whole years, but leave at least |
2492 | // 1 recurrence remaining, in order to get its date. | 2495 | // 1 recurrence remaining, in order to get its date. |
2493 | int wholeYears = (countTogo - 1) / data.count; | 2496 | int wholeYears = (countTogo - 1) / data.count; |
2494 | data.year += wholeYears * rFreq; | 2497 | data.year += wholeYears * rFreq; |
2495 | countGone += wholeYears * data.count; | 2498 | countGone += wholeYears * data.count; |
2496 | countTogo -= wholeYears * data.count; | 2499 | countTogo -= wholeYears * data.count; |
2497 | 2500 | ||
2498 | // Check the last year in the recurrence. | 2501 | // Check the last year in the recurrence. |
2499 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2502 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2500 | if (static_cast<uint>(data.daysPerMonth) >= countTogo) { | 2503 | if (static_cast<uint>(data.daysPerMonth) >= countTogo) { |
2501 | // Check the last month in the recurrence | 2504 | // Check the last month in the recurrence |
2502 | data.month = *im.current(); | 2505 | data.month = *im.current(); |
2503 | days = data.dayList(); | 2506 | days = data.dayList(); |
2504 | for (id = days->begin(); id != days->end(); ++id) { | 2507 | for (id = days->begin(); id != days->end(); ++id) { |
2505 | ++countGone; | 2508 | ++countGone; |
2506 | if (--countTogo == 0) { | 2509 | if (--countTogo == 0) { |
2507 | data.day = *id; | 2510 | data.day = *id; |
2508 | goto ex; | 2511 | goto ex; |
2509 | } | 2512 | } |
2510 | } | 2513 | } |
2511 | } | 2514 | } |
2512 | countTogo -= data.daysPerMonth; | 2515 | countTogo -= data.daysPerMonth; |
2513 | countGone += data.daysPerMonth; | 2516 | countGone += data.daysPerMonth; |
2514 | } | 2517 | } |
2515 | data.year += rFreq; | 2518 | data.year += rFreq; |
2516 | } | 2519 | } |
2517 | ex: | 2520 | ex: |
2518 | enddate = data.date(); | 2521 | enddate = data.date(); |
2519 | return countGone; | 2522 | return countGone; |
2520 | } | 2523 | } |
2521 | 2524 | ||
2522 | int Recurrence::yearlyPosCalcToDate(const QDate &enddate, YearlyPosData &data) const | 2525 | int Recurrence::yearlyPosCalcToDate(const QDate &enddate, YearlyPosData &data) const |
2523 | { | 2526 | { |
2524 | int countGone = 0; | 2527 | int countGone = 0; |
2525 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 2528 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
2526 | int endYear = enddate.year(); | 2529 | int endYear = enddate.year(); |
2527 | int endMonth = enddate.month(); | 2530 | int endMonth = enddate.month(); |
2528 | int endDay = enddate.day(); | 2531 | int endDay = enddate.day(); |
2529 | if (endDay < data.day && --endMonth == 0) { | 2532 | if (endDay < data.day && --endMonth == 0) { |
2530 | endMonth = 12; | 2533 | endMonth = 12; |
2531 | --endYear; | 2534 | --endYear; |
2532 | } | 2535 | } |
2533 | int endYearMonth = endYear*12 + endMonth; | 2536 | int endYearMonth = endYear*12 + endMonth; |
2534 | QValueList<int>::ConstIterator id; | 2537 | Q3ValueList<int>::ConstIterator id; |
2535 | const QValueList<int>* days; | 2538 | const Q3ValueList<int>* days; |
2536 | 2539 | ||
2537 | if (data.month > 1 || data.day > 1) { | 2540 | if (data.month > 1 || data.day > 1) { |
2538 | // Check what remains of the start year | 2541 | // Check what remains of the start year |
2539 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2542 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2540 | if (*im.current() >= data.month) { | 2543 | if (*im.current() >= data.month) { |
2541 | data.month = *im.current(); | 2544 | data.month = *im.current(); |
2542 | if (data.yearMonth() > endYearMonth) | 2545 | if (data.yearMonth() > endYearMonth) |
2543 | return countGone; | 2546 | return countGone; |
2544 | // Check what remains of the start month | 2547 | // Check what remains of the start month |
2545 | bool lastMonth = (data.yearMonth() == endYearMonth); | 2548 | bool lastMonth = (data.yearMonth() == endYearMonth); |
2546 | if (lastMonth || data.day > 1 || data.varies) { | 2549 | if (lastMonth || data.day > 1 || data.varies) { |
2547 | days = data.dayList(); | 2550 | days = data.dayList(); |
2548 | if (lastMonth || data.day > 1) { | 2551 | if (lastMonth || data.day > 1) { |
2549 | for (id = days->begin(); id != days->end(); ++id) { | 2552 | for (id = days->begin(); id != days->end(); ++id) { |
2550 | if (*id >= data.day) { | 2553 | if (*id >= data.day) { |
2551 | if (lastMonth && *id > endDay) | 2554 | if (lastMonth && *id > endDay) |
2552 | return countGone; | 2555 | return countGone; |
2553 | if (++countGone >= countMax) | 2556 | if (++countGone >= countMax) |
2554 | return countMax; | 2557 | return countMax; |
2555 | } | 2558 | } |
2556 | } | 2559 | } |
2557 | } else { | 2560 | } else { |
2558 | countGone += days->count(); | 2561 | countGone += days->count(); |
2559 | if (countGone >= countMax) | 2562 | if (countGone >= countMax) |
2560 | return countMax; | 2563 | return countMax; |
2561 | } | 2564 | } |
2562 | data.day = 1; | 2565 | data.day = 1; |
2563 | } else { | 2566 | } else { |
2564 | // The number of days per month is constant, so skip | 2567 | // The number of days per month is constant, so skip |
2565 | // the whole month. | 2568 | // the whole month. |
2566 | countGone += data.daysPerMonth; | 2569 | countGone += data.daysPerMonth; |
2567 | if (countGone >= countMax) | 2570 | if (countGone >= countMax) |
2568 | return countMax; | 2571 | return countMax; |
2569 | } | 2572 | } |
2570 | } | 2573 | } |
2571 | } | 2574 | } |
2572 | data.month = 1; | 2575 | data.month = 1; |
2573 | data.year += rFreq; | 2576 | data.year += rFreq; |
2574 | } | 2577 | } |
2575 | 2578 | ||
2576 | if (data.varies) { | 2579 | if (data.varies) { |
2577 | // The number of recurrences varies from year to year. | 2580 | // The number of recurrences varies from year to year. |
2578 | for ( ; ; ) { | 2581 | for ( ; ; ) { |
2579 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2582 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2580 | data.month = *im.current(); | 2583 | data.month = *im.current(); |
2581 | days = data.dayList(); | 2584 | days = data.dayList(); |
2582 | if (data.yearMonth() >= endYearMonth) { | 2585 | if (data.yearMonth() >= endYearMonth) { |
2583 | if (data.yearMonth() > endYearMonth) | 2586 | if (data.yearMonth() > endYearMonth) |
2584 | return countGone; | 2587 | return countGone; |
2585 | // Check the last month in the recurrence | 2588 | // Check the last month in the recurrence |
2586 | for (id = days->begin(); id != days->end(); ++id) { | 2589 | for (id = days->begin(); id != days->end(); ++id) { |
2587 | if (*id > endDay) | 2590 | if (*id > endDay) |
2588 | return countGone; | 2591 | return countGone; |
2589 | if (++countGone >= countMax) | 2592 | if (++countGone >= countMax) |
2590 | return countMax; | 2593 | return countMax; |
2591 | } | 2594 | } |
2592 | } else { | 2595 | } else { |
2593 | countGone += days->count(); | 2596 | countGone += days->count(); |
2594 | if (countGone >= countMax) | 2597 | if (countGone >= countMax) |
2595 | return countMax; | 2598 | return countMax; |
2596 | } | 2599 | } |
2597 | } | 2600 | } |
2598 | data.year += rFreq; | 2601 | data.year += rFreq; |
2599 | } | 2602 | } |
2600 | } else { | 2603 | } else { |
2601 | // The number of recurrences is the same every year, | 2604 | // The number of recurrences is the same every year, |
2602 | // so skip the year-by-year check. | 2605 | // so skip the year-by-year check. |
2603 | // Skip the remaining whole years, but leave at least | 2606 | // Skip the remaining whole years, but leave at least |
2604 | // 1 recurrence remaining, in order to get its date. | 2607 | // 1 recurrence remaining, in order to get its date. |
2605 | int wholeYears = endYear - data.year; | 2608 | int wholeYears = endYear - data.year; |
2606 | countGone += (wholeYears / rFreq) * data.count; | 2609 | countGone += (wholeYears / rFreq) * data.count; |
2607 | if (countGone >= countMax) | 2610 | if (countGone >= countMax) |
2608 | return countMax; | 2611 | return countMax; |
2609 | if (wholeYears % rFreq) | 2612 | if (wholeYears % rFreq) |
2610 | return countGone; // end year isn't a recurrence year | 2613 | return countGone; // end year isn't a recurrence year |
2611 | data.year = endYear; | 2614 | data.year = endYear; |
2612 | 2615 | ||
2613 | // Check the last year in the recurrence. | 2616 | // Check the last year in the recurrence. |
2614 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2617 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2615 | data.month = *im.current(); | 2618 | data.month = *im.current(); |
2616 | if (data.month >= endMonth) { | 2619 | if (data.month >= endMonth) { |
2617 | if (data.month > endMonth) | 2620 | if (data.month > endMonth) |
2618 | return countGone; | 2621 | return countGone; |
2619 | // Check the last month in the recurrence | 2622 | // Check the last month in the recurrence |
2620 | days = data.dayList(); | 2623 | days = data.dayList(); |
2621 | for (id = days->begin(); id != days->end(); ++id) { | 2624 | for (id = days->begin(); id != days->end(); ++id) { |
2622 | if (*id > endDay) | 2625 | if (*id > endDay) |
2623 | return countGone; | 2626 | return countGone; |
2624 | if (++countGone >= countMax) | 2627 | if (++countGone >= countMax) |
2625 | return countMax; | 2628 | return countMax; |
2626 | } | 2629 | } |
2627 | } else { | 2630 | } else { |
2628 | countGone += data.daysPerMonth; | 2631 | countGone += data.daysPerMonth; |
2629 | if (countGone >= countMax) | 2632 | if (countGone >= countMax) |
2630 | return countMax; | 2633 | return countMax; |
2631 | } | 2634 | } |
2632 | } | 2635 | } |
2633 | } | 2636 | } |
2634 | return countGone; | 2637 | return countGone; |
2635 | } | 2638 | } |
2636 | 2639 | ||
2637 | int Recurrence::yearlyPosCalcNextAfter(QDate &enddate, YearlyPosData &data) const | 2640 | int Recurrence::yearlyPosCalcNextAfter(QDate &enddate, YearlyPosData &data) const |
2638 | { | 2641 | { |
2639 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; | 2642 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; |
2640 | int countGone = 0; | 2643 | int countGone = 0; |
2641 | int endYear = enddate.year(); | 2644 | int endYear = enddate.year(); |
2642 | int endMonth = enddate.month(); | 2645 | int endMonth = enddate.month(); |
2643 | int endDay = enddate.day(); | 2646 | int endDay = enddate.day(); |
2644 | if (endDay < data.day && --endMonth == 0) { | 2647 | if (endDay < data.day && --endMonth == 0) { |
2645 | endMonth = 12; | 2648 | endMonth = 12; |
2646 | --endYear; | 2649 | --endYear; |
2647 | } | 2650 | } |
2648 | int endYearMonth = endYear*12 + endMonth; | 2651 | int endYearMonth = endYear*12 + endMonth; |
2649 | QValueList<int>::ConstIterator id; | 2652 | Q3ValueList<int>::ConstIterator id; |
2650 | const QValueList<int>* days; | 2653 | const Q3ValueList<int>* days; |
2651 | 2654 | ||
2652 | if (data.varies) { | 2655 | if (data.varies) { |
2653 | // The number of recurrences varies from year to year. | 2656 | // The number of recurrences varies from year to year. |
2654 | for ( ; ; ) { | 2657 | for ( ; ; ) { |
2655 | // Check the next year | 2658 | // Check the next year |
2656 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2659 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2657 | if (*im.current() >= data.month) { | 2660 | if (*im.current() >= data.month) { |
2658 | // Check the next month | 2661 | // Check the next month |
2659 | data.month = *im.current(); | 2662 | data.month = *im.current(); |
2660 | int ended = data.yearMonth() - endYearMonth; | 2663 | int ended = data.yearMonth() - endYearMonth; |
2661 | days = data.dayList(); | 2664 | days = data.dayList(); |
2662 | if (ended >= 0 || data.day > 1) { | 2665 | if (ended >= 0 || data.day > 1) { |
2663 | // This is the start or end month, so check each day | 2666 | // This is the start or end month, so check each day |
2664 | for (id = days->begin(); id != days->end(); ++id) { | 2667 | for (id = days->begin(); id != days->end(); ++id) { |
2665 | if (*id >= data.day) { | 2668 | if (*id >= data.day) { |
2666 | ++countGone; | 2669 | ++countGone; |
2667 | if (ended > 0 || (ended == 0 && *id > endDay)) { | 2670 | if (ended > 0 || (ended == 0 && *id > endDay)) { |
2668 | data.day = *id; | 2671 | data.day = *id; |
2669 | goto ex; | 2672 | goto ex; |
2670 | } | 2673 | } |
2671 | if (--countTogo == 0) | 2674 | if (--countTogo == 0) |
2672 | return 0; | 2675 | return 0; |
2673 | } | 2676 | } |
2674 | } | 2677 | } |
2675 | } else { | 2678 | } else { |
2676 | // Skip the whole month | 2679 | // Skip the whole month |
2677 | uint n = days->count(); | 2680 | uint n = days->count(); |
2678 | if (n >= countTogo) | 2681 | if (n >= countTogo) |
2679 | return 0; | 2682 | return 0; |
2680 | countGone += n; | 2683 | countGone += n; |
2681 | } | 2684 | } |
2682 | data.day = 1; // we've checked the start month now | 2685 | data.day = 1; // we've checked the start month now |
2683 | } | 2686 | } |
2684 | } | 2687 | } |
2685 | data.month = 1; // we've checked the start year now | 2688 | data.month = 1; // we've checked the start year now |
2686 | data.year += rFreq; | 2689 | data.year += rFreq; |
2687 | } | 2690 | } |
2688 | } else { | 2691 | } else { |
2689 | // The number of recurrences is the same every year. | 2692 | // The number of recurrences is the same every year. |
2690 | if (data.month > 1 || data.day > 1) { | 2693 | if (data.month > 1 || data.day > 1) { |
2691 | // Check what remains of the start year | 2694 | // Check what remains of the start year |
2692 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2695 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2693 | if (*im.current() >= data.month) { | 2696 | if (*im.current() >= data.month) { |
2694 | // Check what remains of the start month | 2697 | // Check what remains of the start month |
2695 | data.month = *im.current(); | 2698 | data.month = *im.current(); |
2696 | int ended = data.yearMonth() - endYearMonth; | 2699 | int ended = data.yearMonth() - endYearMonth; |
2697 | if (ended >= 0 || data.day > 1) { | 2700 | if (ended >= 0 || data.day > 1) { |
2698 | // This is the start or end month, so check each day | 2701 | // This is the start or end month, so check each day |
2699 | days = data.dayList(); | 2702 | days = data.dayList(); |
2700 | for (id = days->begin(); id != days->end(); ++id) { | 2703 | for (id = days->begin(); id != days->end(); ++id) { |
2701 | if (*id >= data.day) { | 2704 | if (*id >= data.day) { |
2702 | ++countGone; | 2705 | ++countGone; |
2703 | if (ended > 0 || (ended == 0 && *id > endDay)) { | 2706 | if (ended > 0 || (ended == 0 && *id > endDay)) { |
2704 | data.day = *id; | 2707 | data.day = *id; |
2705 | goto ex; | 2708 | goto ex; |
2706 | } | 2709 | } |
2707 | if (--countTogo == 0) | 2710 | if (--countTogo == 0) |
2708 | return 0; | 2711 | return 0; |
2709 | } | 2712 | } |
2710 | } | 2713 | } |
2711 | data.day = 1; // we've checked the start month now | 2714 | data.day = 1; // we've checked the start month now |
2712 | } else { | 2715 | } else { |
2713 | // Skip the whole month. | 2716 | // Skip the whole month. |
2714 | if (static_cast<uint>(data.daysPerMonth) >= countTogo) | 2717 | if (static_cast<uint>(data.daysPerMonth) >= countTogo) |
2715 | return 0; | 2718 | return 0; |
2716 | countGone += data.daysPerMonth; | 2719 | countGone += data.daysPerMonth; |
2717 | } | 2720 | } |
2718 | } | 2721 | } |
2719 | } | 2722 | } |
2720 | data.year += rFreq; | 2723 | data.year += rFreq; |
2721 | } | 2724 | } |
2722 | // Skip the remaining whole years to at least endYear. | 2725 | // Skip the remaining whole years to at least endYear. |
2723 | int recurYears = (endYear - data.year + rFreq - 1) / rFreq; | 2726 | int recurYears = (endYear - data.year + rFreq - 1) / rFreq; |
2724 | if ((endYear - data.year)%rFreq == 0 | 2727 | if ((endYear - data.year)%rFreq == 0 |
2725 | && *rYearNums.getLast() <= endMonth) | 2728 | && *rYearNums.getLast() <= endMonth) |
2726 | ++recurYears; // required year is after endYear | 2729 | ++recurYears; // required year is after endYear |
2727 | if (recurYears) { | 2730 | if (recurYears) { |
2728 | int n = recurYears * data.count; | 2731 | int n = recurYears * data.count; |
2729 | if (static_cast<uint>(n) > countTogo) | 2732 | if (static_cast<uint>(n) > countTogo) |
2730 | return 0; // reached end of recurrence | 2733 | return 0; // reached end of recurrence |
2731 | countTogo -= n; | 2734 | countTogo -= n; |
2732 | countGone += n; | 2735 | countGone += n; |
2733 | data.year += recurYears * rFreq; | 2736 | data.year += recurYears * rFreq; |
2734 | } | 2737 | } |
2735 | 2738 | ||
2736 | // Check the last year in the recurrence | 2739 | // Check the last year in the recurrence |
2737 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2740 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2738 | data.month = *im.current(); | 2741 | data.month = *im.current(); |
2739 | int ended = data.yearMonth() - endYearMonth; | 2742 | int ended = data.yearMonth() - endYearMonth; |
2740 | if (ended >= 0) { | 2743 | if (ended >= 0) { |
2741 | // This is the end month, so check each day | 2744 | // This is the end month, so check each day |
2742 | days = data.dayList(); | 2745 | days = data.dayList(); |
2743 | for (id = days->begin(); id != days->end(); ++id) { | 2746 | for (id = days->begin(); id != days->end(); ++id) { |
2744 | ++countGone; | 2747 | ++countGone; |
2745 | if (ended > 0 || (ended == 0 && *id > endDay)) { | 2748 | if (ended > 0 || (ended == 0 && *id > endDay)) { |
2746 | data.day = *id; | 2749 | data.day = *id; |
2747 | goto ex; | 2750 | goto ex; |
2748 | } | 2751 | } |
2749 | if (--countTogo == 0) | 2752 | if (--countTogo == 0) |
2750 | return 0; | 2753 | return 0; |
2751 | } | 2754 | } |
2752 | } else { | 2755 | } else { |
2753 | // Skip the whole month. | 2756 | // Skip the whole month. |
2754 | if (static_cast<uint>(data.daysPerMonth) >= countTogo) | 2757 | if (static_cast<uint>(data.daysPerMonth) >= countTogo) |
2755 | return 0; | 2758 | return 0; |
2756 | countGone += data.daysPerMonth; | 2759 | countGone += data.daysPerMonth; |
2757 | } | 2760 | } |
2758 | } | 2761 | } |
2759 | } | 2762 | } |
2760 | ex: | 2763 | ex: |
2761 | enddate = data.date(); | 2764 | enddate = data.date(); |
2762 | return countGone; | 2765 | return countGone; |
2763 | } | 2766 | } |
2764 | 2767 | ||
2765 | 2768 | ||
2766 | /* Find count and, depending on 'func', the end date of an annual recurrence by day. | 2769 | /* Find count and, depending on 'func', the end date of an annual recurrence by day. |
2767 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 2770 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
2768 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 2771 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
2769 | * recurrence end date. | 2772 | * recurrence end date. |
2770 | */ | 2773 | */ |
2771 | struct Recurrence::YearlyDayData { | 2774 | struct Recurrence::YearlyDayData { |
2772 | int year; // current year | 2775 | int year; // current year |
2773 | int day; // current day of year 1..366 | 2776 | int day; // current day of year 1..366 |
2774 | bool varies; // true if day 366 recurs | 2777 | bool varies; // true if day 366 recurs |
2775 | private: | 2778 | private: |
2776 | int daycount; | 2779 | int daycount; |
2777 | public: | 2780 | public: |
2778 | YearlyDayData(const Recurrence* r, const QDate &date) | 2781 | YearlyDayData(const Recurrence* r, const QDate &date) |
2779 | : year(date.year()), day(date.dayOfYear()), varies(*r->rYearNums.getLast() == 366), | 2782 | : year(date.year()), day(date.dayOfYear()), varies(*r->rYearNums.getLast() == 366), |
2780 | daycount(r->rYearNums.count()) { } | 2783 | daycount(r->rYearNums.count()) { } |
2781 | bool leapYear() const { return QDate::leapYear(year); } | 2784 | bool leapYear() const { return QDate::leapYear(year); } |
2782 | int dayCount() const { return daycount - (varies && !QDate::leapYear(year) ? 1 : 0); } | 2785 | int dayCount() const { return daycount - (varies && !QDate::leapYear(year) ? 1 : 0); } |
2783 | bool isMaxDayCount() const { return !varies || QDate::leapYear(year); } | 2786 | bool isMaxDayCount() const { return !varies || QDate::leapYear(year); } |
2784 | QDate date() const { return QDate(year, 1, 1).addDays(day - 1); } | 2787 | QDate date() const { return QDate(year, 1, 1).addDays(day - 1); } |
2785 | }; | 2788 | }; |
2786 | 2789 | ||
2787 | int Recurrence::yearlyDayCalc(PeriodFunc func, QDate &enddate) const | 2790 | int Recurrence::yearlyDayCalc(PeriodFunc func, QDate &enddate) const |
2788 | { | 2791 | { |
2789 | if (rYearNums.isEmpty()) | 2792 | if (rYearNums.isEmpty()) |
2790 | return 0; | 2793 | return 0; |
2791 | YearlyDayData data(this, mRecurStart.date()); | 2794 | YearlyDayData data(this, mRecurStart.date()); |
2792 | switch (func) { | 2795 | switch (func) { |
2793 | case END_DATE_AND_COUNT: | 2796 | case END_DATE_AND_COUNT: |
2794 | return yearlyDayCalcEndDate(enddate, data); | 2797 | return yearlyDayCalcEndDate(enddate, data); |
2795 | case COUNT_TO_DATE: | 2798 | case COUNT_TO_DATE: |
2796 | return yearlyDayCalcToDate(enddate, data); | 2799 | return yearlyDayCalcToDate(enddate, data); |
2797 | case NEXT_AFTER_DATE: | 2800 | case NEXT_AFTER_DATE: |
2798 | return yearlyDayCalcNextAfter(enddate, data); | 2801 | return yearlyDayCalcNextAfter(enddate, data); |
2799 | } | 2802 | } |
2800 | return 0; | 2803 | return 0; |
2801 | } | 2804 | } |
2802 | 2805 | ||
2803 | int Recurrence::yearlyDayCalcEndDate(QDate &enddate, YearlyDayData &data) const | 2806 | int Recurrence::yearlyDayCalcEndDate(QDate &enddate, YearlyDayData &data) const |
2804 | { | 2807 | { |
2805 | uint countTogo = rDuration + mRecurExDatesCount; | 2808 | uint countTogo = rDuration + mRecurExDatesCount; |
2806 | int countGone = 0; | 2809 | int countGone = 0; |
2807 | 2810 | ||
2808 | if (data.day > 1) { | 2811 | if (data.day > 1) { |
2809 | // Check what remains of the start year | 2812 | // Check what remains of the start year |
2810 | bool leapOK = data.isMaxDayCount(); | 2813 | bool leapOK = data.isMaxDayCount(); |
2811 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2814 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2812 | int d = *it.current(); | 2815 | int d = *it.current(); |
2813 | if (d >= data.day && (leapOK || d < 366)) { | 2816 | if (d >= data.day && (leapOK || d < 366)) { |
2814 | ++countGone; | 2817 | ++countGone; |
2815 | if (--countTogo == 0) { | 2818 | if (--countTogo == 0) { |
2816 | data.day = d; | 2819 | data.day = d; |
2817 | goto ex; | 2820 | goto ex; |
2818 | } | 2821 | } |
2819 | } | 2822 | } |
2820 | } | 2823 | } |
2821 | data.day = 1; | 2824 | data.day = 1; |
2822 | data.year += rFreq; | 2825 | data.year += rFreq; |
2823 | } | 2826 | } |
2824 | 2827 | ||
2825 | if (data.varies) { | 2828 | if (data.varies) { |
2826 | // The number of recurrences is different in leap years, | 2829 | // The number of recurrences is different in leap years, |
2827 | // so check year-by-year. | 2830 | // so check year-by-year. |
2828 | for ( ; ; ) { | 2831 | for ( ; ; ) { |
2829 | uint n = data.dayCount(); | 2832 | uint n = data.dayCount(); |
2830 | if (n >= countTogo) | 2833 | if (n >= countTogo) |
2831 | break; | 2834 | break; |
2832 | countTogo -= n; | 2835 | countTogo -= n; |
2833 | countGone += n; | 2836 | countGone += n; |
2834 | data.year += rFreq; | 2837 | data.year += rFreq; |
2835 | } | 2838 | } |
2836 | } else { | 2839 | } else { |
2837 | // The number of recurrences is the same every year, | 2840 | // The number of recurrences is the same every year, |
2838 | // so skip the year-by-year check. | 2841 | // so skip the year-by-year check. |
2839 | // Skip the remaining whole years, but leave at least | 2842 | // Skip the remaining whole years, but leave at least |
2840 | // 1 recurrence remaining, in order to get its date. | 2843 | // 1 recurrence remaining, in order to get its date. |
2841 | int daysPerYear = rYearNums.count(); | 2844 | int daysPerYear = rYearNums.count(); |
2842 | int wholeYears = (countTogo - 1) / daysPerYear; | 2845 | int wholeYears = (countTogo - 1) / daysPerYear; |
2843 | data.year += wholeYears * rFreq; | 2846 | data.year += wholeYears * rFreq; |
2844 | countGone += wholeYears * daysPerYear; | 2847 | countGone += wholeYears * daysPerYear; |
2845 | countTogo -= wholeYears * daysPerYear; | 2848 | countTogo -= wholeYears * daysPerYear; |
2846 | } | 2849 | } |
2847 | if (countTogo) { | 2850 | if (countTogo) { |
2848 | // Check the last year in the recurrence | 2851 | // Check the last year in the recurrence |
2849 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2852 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2850 | ++countGone; | 2853 | ++countGone; |
2851 | if (--countTogo == 0) { | 2854 | if (--countTogo == 0) { |
2852 | data.day = *it.current(); | 2855 | data.day = *it.current(); |
2853 | break; | 2856 | break; |
2854 | } | 2857 | } |
2855 | } | 2858 | } |
2856 | } | 2859 | } |
2857 | ex: | 2860 | ex: |
2858 | enddate = data.date(); | 2861 | enddate = data.date(); |
2859 | return countGone; | 2862 | return countGone; |
2860 | } | 2863 | } |
2861 | 2864 | ||
2862 | int Recurrence::yearlyDayCalcToDate(const QDate &enddate, YearlyDayData &data) const | 2865 | int Recurrence::yearlyDayCalcToDate(const QDate &enddate, YearlyDayData &data) const |
2863 | { | 2866 | { |
2864 | int countGone = 0; | 2867 | int countGone = 0; |
2865 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 2868 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
2866 | int endYear = enddate.year(); | 2869 | int endYear = enddate.year(); |
2867 | int endDay = enddate.dayOfYear(); | 2870 | int endDay = enddate.dayOfYear(); |
2868 | 2871 | ||
2869 | if (data.day > 1) { | 2872 | if (data.day > 1) { |
2870 | // Check what remains of the start year | 2873 | // Check what remains of the start year |
2871 | bool leapOK = data.isMaxDayCount(); | 2874 | bool leapOK = data.isMaxDayCount(); |
2872 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2875 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2873 | int d = *it.current(); | 2876 | int d = *it.current(); |
2874 | if (d >= data.day && (leapOK || d < 366)) { | 2877 | if (d >= data.day && (leapOK || d < 366)) { |
2875 | if (data.year == endYear && d > endDay) | 2878 | if (data.year == endYear && d > endDay) |
2876 | return countGone; | 2879 | return countGone; |
2877 | if (++countGone >= countMax) | 2880 | if (++countGone >= countMax) |
2878 | return countMax; | 2881 | return countMax; |
2879 | } | 2882 | } |
2880 | } | 2883 | } |
2881 | data.day = 1; | 2884 | data.day = 1; |
2882 | data.year += rFreq; | 2885 | data.year += rFreq; |
2883 | } | 2886 | } |
2884 | 2887 | ||
2885 | if (data.varies) { | 2888 | if (data.varies) { |
2886 | // The number of recurrences is different in leap years, | 2889 | // The number of recurrences is different in leap years, |
2887 | // so check year-by-year. | 2890 | // so check year-by-year. |
2888 | while (data.year < endYear) { | 2891 | while (data.year < endYear) { |
2889 | uint n = data.dayCount(); | 2892 | uint n = data.dayCount(); |
2890 | countGone += n; | 2893 | countGone += n; |
2891 | if (countGone >= countMax) | 2894 | if (countGone >= countMax) |
2892 | return countMax; | 2895 | return countMax; |
2893 | data.year += rFreq; | 2896 | data.year += rFreq; |
2894 | } | 2897 | } |
2895 | if (data.year > endYear) | 2898 | if (data.year > endYear) |
2896 | return countGone; | 2899 | return countGone; |
2897 | } else { | 2900 | } else { |
2898 | // The number of recurrences is the same every year. | 2901 | // The number of recurrences is the same every year. |
2899 | // Skip the remaining whole years. | 2902 | // Skip the remaining whole years. |
2900 | int wholeYears = endYear - data.year; | 2903 | int wholeYears = endYear - data.year; |
2901 | countGone += (wholeYears / rFreq) * rYearNums.count(); | 2904 | countGone += (wholeYears / rFreq) * rYearNums.count(); |
2902 | if (countGone >= countMax) | 2905 | if (countGone >= countMax) |
2903 | return countMax; | 2906 | return countMax; |
2904 | if (wholeYears % rFreq) | 2907 | if (wholeYears % rFreq) |
2905 | return countGone; // end year isn't a recurrence year | 2908 | return countGone; // end year isn't a recurrence year |
2906 | data.year = endYear; | 2909 | data.year = endYear; |
2907 | } | 2910 | } |
2908 | 2911 | ||
2909 | if (data.year <= endYear) { | 2912 | if (data.year <= endYear) { |
2910 | // Check the last year in the recurrence | 2913 | // Check the last year in the recurrence |
2911 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2914 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2912 | if (*it.current() > endDay) | 2915 | if (*it.current() > endDay) |
2913 | return countGone; | 2916 | return countGone; |
2914 | if (++countGone >= countMax) | 2917 | if (++countGone >= countMax) |
2915 | return countMax; | 2918 | return countMax; |
2916 | } | 2919 | } |
2917 | } | 2920 | } |
2918 | return countGone; | 2921 | return countGone; |
2919 | } | 2922 | } |
2920 | 2923 | ||
2921 | int Recurrence::yearlyDayCalcNextAfter(QDate &enddate, YearlyDayData &data) const | 2924 | int Recurrence::yearlyDayCalcNextAfter(QDate &enddate, YearlyDayData &data) const |
2922 | { | 2925 | { |
2923 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; | 2926 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; |
2924 | int countGone = 0; | 2927 | int countGone = 0; |
2925 | int endYear = enddate.year(); | 2928 | int endYear = enddate.year(); |
2926 | int endDay = enddate.dayOfYear(); | 2929 | int endDay = enddate.dayOfYear(); |
2927 | 2930 | ||
2928 | if (data.day > 1) { | 2931 | if (data.day > 1) { |
2929 | // Check what remains of the start year | 2932 | // Check what remains of the start year |
2930 | bool leapOK = data.isMaxDayCount(); | 2933 | bool leapOK = data.isMaxDayCount(); |
2931 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2934 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2932 | int d = *it.current(); | 2935 | int d = *it.current(); |
2933 | if (d >= data.day && (leapOK || d < 366)) { | 2936 | if (d >= data.day && (leapOK || d < 366)) { |
2934 | ++countGone; | 2937 | ++countGone; |
2935 | if (data.year == endYear && d > endDay) { | 2938 | if (data.year == endYear && d > endDay) { |
2936 | data.day = d; | 2939 | data.day = d; |
2937 | goto ex; | 2940 | goto ex; |
2938 | } | 2941 | } |
2939 | if (--countTogo == 0) | 2942 | if (--countTogo == 0) |
2940 | return 0; | 2943 | return 0; |
2941 | } | 2944 | } |
2942 | } | 2945 | } |
2943 | data.day = 1; | 2946 | data.day = 1; |
2944 | data.year += rFreq; | 2947 | data.year += rFreq; |
2945 | } | 2948 | } |
2946 | 2949 | ||
2947 | if (data.varies) { | 2950 | if (data.varies) { |
2948 | // The number of recurrences is different in leap years, | 2951 | // The number of recurrences is different in leap years, |
2949 | // so check year-by-year. | 2952 | // so check year-by-year. |
2950 | while (data.year <= endYear) { | 2953 | while (data.year <= endYear) { |
2951 | uint n = data.dayCount(); | 2954 | uint n = data.dayCount(); |
2952 | if (data.year == endYear && *rYearNums.getLast() > endDay) | 2955 | if (data.year == endYear && *rYearNums.getLast() > endDay) |
2953 | break; | 2956 | break; |
2954 | if (n >= countTogo) | 2957 | if (n >= countTogo) |
2955 | break; | 2958 | break; |
2956 | countTogo -= n; | 2959 | countTogo -= n; |
2957 | countGone += n; | 2960 | countGone += n; |
2958 | data.year += rFreq; | 2961 | data.year += rFreq; |
2959 | } | 2962 | } |
2960 | } else { | 2963 | } else { |
2961 | // The number of recurrences is the same every year, | 2964 | // The number of recurrences is the same every year, |
2962 | // so skip the year-by-year check. | 2965 | // so skip the year-by-year check. |
2963 | // Skip the remaining whole years to at least endYear. | 2966 | // Skip the remaining whole years to at least endYear. |
2964 | int daysPerYear = rYearNums.count(); | 2967 | int daysPerYear = rYearNums.count(); |
2965 | int recurYears = (endYear - data.year + rFreq - 1) / rFreq; | 2968 | int recurYears = (endYear - data.year + rFreq - 1) / rFreq; |
2966 | if ((endYear - data.year)%rFreq == 0 | 2969 | if ((endYear - data.year)%rFreq == 0 |
2967 | && *rYearNums.getLast() <= endDay) | 2970 | && *rYearNums.getLast() <= endDay) |
2968 | ++recurYears; // required year is after endYear | 2971 | ++recurYears; // required year is after endYear |
2969 | if (recurYears) { | 2972 | if (recurYears) { |
2970 | int n = recurYears * daysPerYear; | 2973 | int n = recurYears * daysPerYear; |
2971 | if (static_cast<uint>(n) > countTogo) | 2974 | if (static_cast<uint>(n) > countTogo) |
2972 | return 0; // reached end of recurrence | 2975 | return 0; // reached end of recurrence |
2973 | countTogo -= n; | 2976 | countTogo -= n; |
2974 | countGone += n; | 2977 | countGone += n; |
2975 | data.year += recurYears * rFreq; | 2978 | data.year += recurYears * rFreq; |
2976 | } | 2979 | } |
2977 | } | 2980 | } |
2978 | 2981 | ||
2979 | // Check the last year in the recurrence | 2982 | // Check the last year in the recurrence |
2980 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2983 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2981 | ++countGone; | 2984 | ++countGone; |
2982 | int d = *it.current(); | 2985 | int d = *it.current(); |
2983 | if (data.year > endYear || d > endDay) { | 2986 | if (data.year > endYear || d > endDay) { |
2984 | data.day = d; | 2987 | data.day = d; |
2985 | break; | 2988 | break; |
2986 | } | 2989 | } |
2987 | if (--countTogo == 0) | 2990 | if (--countTogo == 0) |
2988 | return 0; | 2991 | return 0; |
2989 | } | 2992 | } |
2990 | ex: | 2993 | ex: |
2991 | enddate = data.date(); | 2994 | enddate = data.date(); |
2992 | return countGone; | 2995 | return countGone; |
2993 | } | 2996 | } |
2994 | 2997 | ||
2995 | // Get the days in this month which recur, in numerical order. | 2998 | // Get the days in this month which recur, in numerical order. |
2996 | // Parameters: daysInMonth = number of days in this month | 2999 | // Parameters: daysInMonth = number of days in this month |
2997 | // startDayOfWeek = day of week for first day of month. | 3000 | // startDayOfWeek = day of week for first day of month. |
2998 | void Recurrence::getMonthlyPosDays(QValueList<int> &list, int daysInMonth, int startDayOfWeek) const | 3001 | void Recurrence::getMonthlyPosDays(Q3ValueList<int> &list, int daysInMonth, int startDayOfWeek) const |
2999 | { | 3002 | { |
3000 | list.clear(); | 3003 | list.clear(); |
3001 | int endDayOfWeek = (startDayOfWeek + daysInMonth - 2) % 7 + 1; | 3004 | int endDayOfWeek = (startDayOfWeek + daysInMonth - 2) % 7 + 1; |
3002 | // Go through the list, compiling a bit list of actual day numbers | 3005 | // Go through the list, compiling a bit list of actual day numbers |
3003 | Q_UINT32 days = 0; | 3006 | Q_UINT32 days = 0; |
3004 | for (QPtrListIterator<rMonthPos> pos(rMonthPositions); pos.current(); ++pos) { | 3007 | for (Q3PtrListIterator<rMonthPos> pos(rMonthPositions); pos.current(); ++pos) { |
3005 | int weeknum = pos.current()->rPos - 1; // get 0-based week number | 3008 | int weeknum = pos.current()->rPos - 1; // get 0-based week number |
3006 | QBitArray &rdays = pos.current()->rDays; | 3009 | QBitArray &rdays = pos.current()->rDays; |
3007 | if (pos.current()->negative) { | 3010 | if (pos.current()->negative) { |
3008 | // nth days before the end of the month | 3011 | // nth days before the end of the month |
3009 | for (uint i = 1; i <= 7; ++i) { | 3012 | for (uint i = 1; i <= 7; ++i) { |
3010 | if (rdays.testBit(i - 1)) { | 3013 | if (rdays.testBit(i - 1)) { |
3011 | int day = daysInMonth - weeknum*7 - (endDayOfWeek - i + 7) % 7; | 3014 | int day = daysInMonth - weeknum*7 - (endDayOfWeek - i + 7) % 7; |
3012 | if (day > 0) | 3015 | if (day > 0) |
3013 | days |= 1 << (day - 1); | 3016 | days |= 1 << (day - 1); |
3014 | } | 3017 | } |
3015 | } | 3018 | } |
3016 | } else { | 3019 | } else { |
3017 | // nth days after the start of the month | 3020 | // nth days after the start of the month |
3018 | for (uint i = 1; i <= 7; ++i) { | 3021 | for (uint i = 1; i <= 7; ++i) { |
3019 | if (rdays.testBit(i - 1)) { | 3022 | if (rdays.testBit(i - 1)) { |
3020 | int day = 1 + weeknum*7 + (i - startDayOfWeek + 7) % 7; | 3023 | int day = 1 + weeknum*7 + (i - startDayOfWeek + 7) % 7; |
3021 | if (day <= daysInMonth) | 3024 | if (day <= daysInMonth) |
3022 | days |= 1 << (day - 1); | 3025 | days |= 1 << (day - 1); |
3023 | } | 3026 | } |
3024 | } | 3027 | } |
3025 | } | 3028 | } |
3026 | } | 3029 | } |
3027 | // Compile the ordered list | 3030 | // Compile the ordered list |
3028 | Q_UINT32 mask = 1; | 3031 | Q_UINT32 mask = 1; |
3029 | for (int i = 0; i < daysInMonth; mask <<= 1, ++i) { | 3032 | for (int i = 0; i < daysInMonth; mask <<= 1, ++i) { |
3030 | if (days & mask) | 3033 | if (days & mask) |
3031 | list.append(i + 1); | 3034 | list.append(i + 1); |
3032 | } | 3035 | } |
3033 | } | 3036 | } |
3034 | 3037 | ||
3035 | // Get the number of days in the month which recur. | 3038 | // Get the number of days in the month which recur. |
3036 | // Reply = -1 if the number varies from month to month. | 3039 | // Reply = -1 if the number varies from month to month. |
3037 | int Recurrence::countMonthlyPosDays() const | 3040 | int Recurrence::countMonthlyPosDays() const |
3038 | { | 3041 | { |
3039 | int count = 0; | 3042 | int count = 0; |
3040 | Q_UINT8 positive[5] = { 0, 0, 0, 0, 0 }; | 3043 | Q_UINT8 positive[5] = { 0, 0, 0, 0, 0 }; |
3041 | Q_UINT8 negative[4] = { 0, 0, 0, 0 }; | 3044 | Q_UINT8 negative[4] = { 0, 0, 0, 0 }; |
3042 | for (QPtrListIterator<rMonthPos> pos(rMonthPositions); pos.current(); ++pos) { | 3045 | for (Q3PtrListIterator<rMonthPos> pos(rMonthPositions); pos.current(); ++pos) { |
3043 | int weeknum = pos.current()->rPos; | 3046 | int weeknum = pos.current()->rPos; |
3044 | Q_UINT8* wk; | 3047 | Q_UINT8* wk; |
3045 | if (pos.current()->negative) { | 3048 | if (pos.current()->negative) { |
3046 | // nth days before the end of the month | 3049 | // nth days before the end of the month |
3047 | if (weeknum > 4) | 3050 | if (weeknum > 4) |
3048 | return -1; // days in 5th week are often missing | 3051 | return -1; // days in 5th week are often missing |
3049 | wk = &negative[4 - weeknum]; | 3052 | wk = &negative[4 - weeknum]; |
3050 | } else { | 3053 | } else { |
3051 | // nth days after the start of the month | 3054 | // nth days after the start of the month |
3052 | if (weeknum > 4) | 3055 | if (weeknum > 4) |
3053 | return -1; // days in 5th week are often missing | 3056 | return -1; // days in 5th week are often missing |
3054 | wk = &positive[weeknum - 1]; | 3057 | wk = &positive[weeknum - 1]; |
3055 | } | 3058 | } |
3056 | QBitArray &rdays = pos.current()->rDays; | 3059 | QBitArray &rdays = pos.current()->rDays; |
3057 | for (uint i = 0; i < 7; ++i) { | 3060 | for (uint i = 0; i < 7; ++i) { |
3058 | if (rdays.testBit(i)) { | 3061 | if (rdays.testBit(i)) { |
3059 | ++count; | 3062 | ++count; |
3060 | *wk |= (1 << i); | 3063 | *wk |= (1 << i); |
3061 | } | 3064 | } |
3062 | } | 3065 | } |
3063 | } | 3066 | } |
3064 | // Check for any possible days which could be duplicated by | 3067 | // Check for any possible days which could be duplicated by |
3065 | // a positive and a negative position. | 3068 | // a positive and a negative position. |
3066 | for (int i = 0; i < 4; ++i) { | 3069 | for (int i = 0; i < 4; ++i) { |
3067 | if (negative[i] & (positive[i] | positive[i+1])) | 3070 | if (negative[i] & (positive[i] | positive[i+1])) |
3068 | return -1; | 3071 | return -1; |
3069 | } | 3072 | } |
3070 | return count; | 3073 | return count; |
3071 | } | 3074 | } |
3072 | 3075 | ||
3073 | // Get the days in this month which recur, in numerical order. | 3076 | // Get the days in this month which recur, in numerical order. |
3074 | // Reply = true if day numbers varies from month to month. | 3077 | // Reply = true if day numbers varies from month to month. |
3075 | bool Recurrence::getMonthlyDayDays(QValueList<int> &list, int daysInMonth) const | 3078 | bool Recurrence::getMonthlyDayDays(Q3ValueList<int> &list, int daysInMonth) const |
3076 | { | 3079 | { |
3077 | list.clear(); | 3080 | list.clear(); |
3078 | bool variable = false; | 3081 | bool variable = false; |
3079 | Q_UINT32 days = 0; | 3082 | Q_UINT32 days = 0; |
3080 | for (QPtrListIterator<int> it(rMonthDays); it.current(); ++it) { | 3083 | for (Q3PtrListIterator<int> it(rMonthDays); it.current(); ++it) { |
3081 | int day = *it.current(); | 3084 | int day = *it.current(); |
3082 | if (day > 0) { | 3085 | if (day > 0) { |
3083 | // date in the month | 3086 | // date in the month |
3084 | if (day <= daysInMonth) | 3087 | if (day <= daysInMonth) |
3085 | days |= 1 << (day - 1); | 3088 | days |= 1 << (day - 1); |
3086 | if (day > 28 && day <= 31) | 3089 | if (day > 28 && day <= 31) |
3087 | variable = true; // this date does not appear in some months | 3090 | variable = true; // this date does not appear in some months |
3088 | } else if (day < 0) { | 3091 | } else if (day < 0) { |
3089 | // days before the end of the month | 3092 | // days before the end of the month |
3090 | variable = true; // this date varies depending on the month length | 3093 | variable = true; // this date varies depending on the month length |
3091 | day = daysInMonth + day; // zero-based day of month | 3094 | day = daysInMonth + day; // zero-based day of month |
3092 | if (day >= 0) | 3095 | if (day >= 0) |
3093 | days |= 1 << day; | 3096 | days |= 1 << day; |
3094 | } | 3097 | } |
3095 | } | 3098 | } |
3096 | // Compile the ordered list | 3099 | // Compile the ordered list |
3097 | Q_UINT32 mask = 1; | 3100 | Q_UINT32 mask = 1; |
3098 | for (int i = 0; i < daysInMonth; mask <<= 1, ++i) { | 3101 | for (int i = 0; i < daysInMonth; mask <<= 1, ++i) { |
3099 | if (days & mask) | 3102 | if (days & mask) |
3100 | list.append(i + 1); | 3103 | list.append(i + 1); |
3101 | } | 3104 | } |
3102 | return variable; | 3105 | return variable; |
3103 | } | 3106 | } |
3104 | 3107 | ||
3105 | // Get the months which recur, in numerical order, for both leap years and non-leap years. | 3108 | // Get the months which recur, in numerical order, for both leap years and non-leap years. |
3106 | // N.B. If February 29th recurs on March 1st in non-leap years, February (not March) is | 3109 | // N.B. If February 29th recurs on March 1st in non-leap years, February (not March) is |
3107 | // included in the non-leap year month list. | 3110 | // included in the non-leap year month list. |
3108 | // Reply = true if February 29th also recurs. | 3111 | // Reply = true if February 29th also recurs. |
3109 | bool Recurrence::getYearlyMonthMonths(int day, QValueList<int> &list, QValueList<int> &leaplist) const | 3112 | bool Recurrence::getYearlyMonthMonths(int day, Q3ValueList<int> &list, Q3ValueList<int> &leaplist) const |
3110 | { | 3113 | { |
3111 | list.clear(); | 3114 | list.clear(); |
3112 | leaplist.clear(); | 3115 | leaplist.clear(); |
3113 | bool feb29 = false; | 3116 | bool feb29 = false; |
3114 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 3117 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
3115 | int month = *it.current(); | 3118 | int month = *it.current(); |
3116 | if (month == 2) { | 3119 | if (month == 2) { |
3117 | if (day <= 28) { | 3120 | if (day <= 28) { |
3118 | list.append(month); // date appears in February | 3121 | list.append(month); // date appears in February |
3119 | leaplist.append(month); | 3122 | leaplist.append(month); |
3120 | } | 3123 | } |
3121 | else if (day == 29) { | 3124 | else if (day == 29) { |
3122 | // February 29th | 3125 | // February 29th |
3123 | leaplist.append(month); | 3126 | leaplist.append(month); |
3124 | switch (mFeb29YearlyType) { | 3127 | switch (mFeb29YearlyType) { |
3125 | case rFeb28: | 3128 | case rFeb28: |
3126 | case rMar1: | 3129 | case rMar1: |
3127 | list.append(2); | 3130 | list.append(2); |
3128 | break; | 3131 | break; |
3129 | case rFeb29: | 3132 | case rFeb29: |
3130 | break; | 3133 | break; |
3131 | } | 3134 | } |
3132 | feb29 = true; | 3135 | feb29 = true; |
3133 | } | 3136 | } |
3134 | } | 3137 | } |
3135 | else if (day <= 30 || QDate(2000, month, 1).daysInMonth() == 31) { | 3138 | else if (day <= 30 || QDate(2000, month, 1).daysInMonth() == 31) { |
3136 | list.append(month); // date appears in every month | 3139 | list.append(month); // date appears in every month |
3137 | leaplist.append(month); | 3140 | leaplist.append(month); |
3138 | } | 3141 | } |
3139 | } | 3142 | } |
3140 | return feb29; | 3143 | return feb29; |
3141 | } | 3144 | } |
3142 | 3145 | ||
3143 | /* From the recurrence day of the week list, get the earliest day in the | 3146 | /* From the recurrence day of the week list, get the earliest day in the |
3144 | * specified week which is >= the startDay. | 3147 | * specified week which is >= the startDay. |
3145 | * Parameters: startDay = 1..7 (Monday..Sunday) | 3148 | * Parameters: startDay = 1..7 (Monday..Sunday) |
3146 | * useWeekStart = true to end search at day before next rWeekStart | 3149 | * useWeekStart = true to end search at day before next rWeekStart |
3147 | * = false to search for a full 7 days | 3150 | * = false to search for a full 7 days |
3148 | * Reply = day of the week (1..7), or 0 if none found. | 3151 | * Reply = day of the week (1..7), or 0 if none found. |
3149 | */ | 3152 | */ |
3150 | int Recurrence::getFirstDayInWeek(int startDay, bool useWeekStart) const | 3153 | int Recurrence::getFirstDayInWeek(int startDay, bool useWeekStart) const |
3151 | { | 3154 | { |
3152 | int last = ((useWeekStart ? rWeekStart : startDay) + 5)%7; | 3155 | int last = ((useWeekStart ? rWeekStart : startDay) + 5)%7; |
3153 | for (int i = startDay - 1; ; i = (i + 1)%7) { | 3156 | for (int i = startDay - 1; ; i = (i + 1)%7) { |
3154 | if (rDays.testBit(i)) | 3157 | if (rDays.testBit(i)) |
3155 | return i + 1; | 3158 | return i + 1; |
3156 | if (i == last) | 3159 | if (i == last) |
3157 | return 0; | 3160 | return 0; |
3158 | } | 3161 | } |
3159 | } | 3162 | } |
3160 | 3163 | ||
3161 | /* From the recurrence day of the week list, get the latest day in the | 3164 | /* From the recurrence day of the week list, get the latest day in the |
3162 | * specified week which is <= the endDay. | 3165 | * specified week which is <= the endDay. |
3163 | * Parameters: endDay = 1..7 (Monday..Sunday) | 3166 | * Parameters: endDay = 1..7 (Monday..Sunday) |
3164 | * useWeekStart = true to end search at rWeekStart | 3167 | * useWeekStart = true to end search at rWeekStart |
3165 | * = false to search for a full 7 days | 3168 | * = false to search for a full 7 days |
3166 | * Reply = day of the week (1..7), or 0 if none found. | 3169 | * Reply = day of the week (1..7), or 0 if none found. |
3167 | */ | 3170 | */ |
3168 | int Recurrence::getLastDayInWeek(int endDay, bool useWeekStart) const | 3171 | int Recurrence::getLastDayInWeek(int endDay, bool useWeekStart) const |
3169 | { | 3172 | { |
3170 | int last = useWeekStart ? rWeekStart - 1 : endDay%7; | 3173 | int last = useWeekStart ? rWeekStart - 1 : endDay%7; |
3171 | for (int i = endDay - 1; ; i = (i + 6)%7) { | 3174 | for (int i = endDay - 1; ; i = (i + 6)%7) { |
3172 | if (rDays.testBit(i)) | 3175 | if (rDays.testBit(i)) |
3173 | return i + 1; | 3176 | return i + 1; |
3174 | if (i == last) | 3177 | if (i == last) |
3175 | return 0; | 3178 | return 0; |
3176 | } | 3179 | } |
3177 | } | 3180 | } |
3178 | 3181 | ||
3179 | /* From the recurrence monthly day number list or monthly day of week/week of | 3182 | /* From the recurrence monthly day number list or monthly day of week/week of |
3180 | * month list, get the earliest day in the specified month which is >= the | 3183 | * month list, get the earliest day in the specified month which is >= the |
3181 | * earliestDate. | 3184 | * earliestDate. |
3182 | */ | 3185 | */ |
3183 | QDate Recurrence::getFirstDateInMonth(const QDate &earliestDate) const | 3186 | QDate Recurrence::getFirstDateInMonth(const QDate &earliestDate) const |
3184 | { | 3187 | { |
3185 | int earliestDay = earliestDate.day(); | 3188 | int earliestDay = earliestDate.day(); |
3186 | int daysInMonth = earliestDate.daysInMonth(); | 3189 | int daysInMonth = earliestDate.daysInMonth(); |
3187 | switch (recurs) { | 3190 | switch (recurs) { |
3188 | case rMonthlyDay: { | 3191 | case rMonthlyDay: { |
3189 | int minday = daysInMonth + 1; | 3192 | int minday = daysInMonth + 1; |
3190 | for (QPtrListIterator<int> it(rMonthDays); it.current(); ++it) { | 3193 | for (Q3PtrListIterator<int> it(rMonthDays); it.current(); ++it) { |
3191 | int day = *it.current(); | 3194 | int day = *it.current(); |
3192 | if (day < 0) | 3195 | if (day < 0) |
3193 | day = daysInMonth + day + 1; | 3196 | day = daysInMonth + day + 1; |
3194 | if (day >= earliestDay && day < minday) | 3197 | if (day >= earliestDay && day < minday) |
3195 | minday = day; | 3198 | minday = day; |
3196 | } | 3199 | } |
3197 | if (minday <= daysInMonth) | 3200 | if (minday <= daysInMonth) |
3198 | return earliestDate.addDays(minday - earliestDay); | 3201 | return earliestDate.addDays(minday - earliestDay); |
3199 | break; | 3202 | break; |
3200 | } | 3203 | } |
3201 | case rMonthlyPos: | 3204 | case rMonthlyPos: |
3202 | case rYearlyPos: { | 3205 | case rYearlyPos: { |
3203 | QDate monthBegin(earliestDate.addDays(1 - earliestDay)); | 3206 | QDate monthBegin(earliestDate.addDays(1 - earliestDay)); |
3204 | QValueList<int> dayList; | 3207 | Q3ValueList<int> dayList; |
3205 | getMonthlyPosDays(dayList, daysInMonth, monthBegin.dayOfWeek()); | 3208 | getMonthlyPosDays(dayList, daysInMonth, monthBegin.dayOfWeek()); |
3206 | for (QValueList<int>::ConstIterator id = dayList.begin(); id != dayList.end(); ++id) { | 3209 | for (Q3ValueList<int>::ConstIterator id = dayList.begin(); id != dayList.end(); ++id) { |
3207 | if (*id >= earliestDay) | 3210 | if (*id >= earliestDay) |
3208 | return monthBegin.addDays(*id - 1); | 3211 | return monthBegin.addDays(*id - 1); |
3209 | } | 3212 | } |
3210 | break; | 3213 | break; |
3211 | } | 3214 | } |
3212 | } | 3215 | } |
3213 | return QDate(); | 3216 | return QDate(); |
3214 | } | 3217 | } |
3215 | 3218 | ||
3216 | /* From the recurrence monthly day number list or monthly day of week/week of | 3219 | /* From the recurrence monthly day number list or monthly day of week/week of |
3217 | * month list, get the latest day in the specified month which is <= the | 3220 | * month list, get the latest day in the specified month which is <= the |
3218 | * latestDate. | 3221 | * latestDate. |
3219 | */ | 3222 | */ |
3220 | QDate Recurrence::getLastDateInMonth(const QDate &latestDate) const | 3223 | QDate Recurrence::getLastDateInMonth(const QDate &latestDate) const |
3221 | { | 3224 | { |
3222 | int latestDay = latestDate.day(); | 3225 | int latestDay = latestDate.day(); |
3223 | int daysInMonth = latestDate.daysInMonth(); | 3226 | int daysInMonth = latestDate.daysInMonth(); |
3224 | switch (recurs) { | 3227 | switch (recurs) { |
3225 | case rMonthlyDay: { | 3228 | case rMonthlyDay: { |
3226 | int maxday = -1; | 3229 | int maxday = -1; |
3227 | for (QPtrListIterator<int> it(rMonthDays); it.current(); ++it) { | 3230 | for (Q3PtrListIterator<int> it(rMonthDays); it.current(); ++it) { |
3228 | int day = *it.current(); | 3231 | int day = *it.current(); |
3229 | if (day < 0) | 3232 | if (day < 0) |
3230 | day = daysInMonth + day + 1; | 3233 | day = daysInMonth + day + 1; |
3231 | if (day <= latestDay && day > maxday) | 3234 | if (day <= latestDay && day > maxday) |
3232 | maxday = day; | 3235 | maxday = day; |
3233 | } | 3236 | } |
3234 | if (maxday > 0) | 3237 | if (maxday > 0) |
3235 | return QDate(latestDate.year(), latestDate.month(), maxday); | 3238 | return QDate(latestDate.year(), latestDate.month(), maxday); |
3236 | break; | 3239 | break; |
3237 | } | 3240 | } |
3238 | case rMonthlyPos: | 3241 | case rMonthlyPos: |
3239 | case rYearlyPos: { | 3242 | case rYearlyPos: { |
3240 | QDate monthBegin(latestDate.addDays(1 - latestDay)); | 3243 | QDate monthBegin(latestDate.addDays(1 - latestDay)); |
3241 | QValueList<int> dayList; | 3244 | Q3ValueList<int> dayList; |
3242 | getMonthlyPosDays(dayList, daysInMonth, monthBegin.dayOfWeek()); | 3245 | getMonthlyPosDays(dayList, daysInMonth, monthBegin.dayOfWeek()); |
3243 | for (QValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { | 3246 | for (Q3ValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { |
3244 | if (*id <= latestDay) | 3247 | if (*id <= latestDay) |
3245 | return monthBegin.addDays(*id - 1); | 3248 | return monthBegin.addDays(*id - 1); |
3246 | } | 3249 | } |
3247 | break; | 3250 | break; |
3248 | } | 3251 | } |
3249 | } | 3252 | } |
3250 | return QDate(); | 3253 | return QDate(); |
3251 | } | 3254 | } |
3252 | 3255 | ||
3253 | /* From the recurrence yearly month list or yearly day list, get the earliest | 3256 | /* From the recurrence yearly month list or yearly day list, get the earliest |
3254 | * month or day in the specified year which is >= the earliestDate. | 3257 | * month or day in the specified year which is >= the earliestDate. |
3255 | * Note that rYearNums is sorted in numerical order. | 3258 | * Note that rYearNums is sorted in numerical order. |
3256 | */ | 3259 | */ |
3257 | QDate Recurrence::getFirstDateInYear(const QDate &earliestDate) const | 3260 | QDate Recurrence::getFirstDateInYear(const QDate &earliestDate) const |
3258 | { | 3261 | { |
3259 | QPtrListIterator<int> it(rYearNums); | 3262 | Q3PtrListIterator<int> it(rYearNums); |
3260 | switch (recurs) { | 3263 | switch (recurs) { |
3261 | case rYearlyMonth: { | 3264 | case rYearlyMonth: { |
3262 | int day = recurStart().date().day(); | 3265 | int day = recurStart().date().day(); |
3263 | int earliestYear = earliestDate.year(); | 3266 | int earliestYear = earliestDate.year(); |
3264 | int earliestMonth = earliestDate.month(); | 3267 | int earliestMonth = earliestDate.month(); |
3265 | int earliestDay = earliestDate.day(); | 3268 | int earliestDay = earliestDate.day(); |
3266 | if (earliestDay > day) { | 3269 | if (earliestDay > day) { |
3267 | // The earliest date is later in the month than the recurrence date, | 3270 | // The earliest date is later in the month than the recurrence date, |
3268 | // so skip to the next month before starting to check | 3271 | // so skip to the next month before starting to check |
3269 | if (++earliestMonth > 12) | 3272 | if (++earliestMonth > 12) |
3270 | return QDate(); | 3273 | return QDate(); |
3271 | } | 3274 | } |
3272 | for ( ; it.current(); ++it) { | 3275 | for ( ; it.current(); ++it) { |
3273 | int month = *it.current(); | 3276 | int month = *it.current(); |
3274 | if (month >= earliestMonth) { | 3277 | if (month >= earliestMonth) { |
3275 | if (day <= 28 || QDate::isValid(earliestYear, month, day)) | 3278 | if (day <= 28 || QDate::isValid(earliestYear, month, day)) |
3276 | return QDate(earliestYear, month, day); | 3279 | return QDate(earliestYear, month, day); |
3277 | if (day == 29 && month == 2) { | 3280 | if (day == 29 && month == 2) { |
3278 | // It's a recurrence on February 29th, in a non-leap year | 3281 | // It's a recurrence on February 29th, in a non-leap year |
3279 | switch (mFeb29YearlyType) { | 3282 | switch (mFeb29YearlyType) { |
3280 | case rMar1: | 3283 | case rMar1: |
3281 | return QDate(earliestYear, 3, 1); | 3284 | return QDate(earliestYear, 3, 1); |
3282 | case rFeb28: | 3285 | case rFeb28: |
3283 | if (earliestDay <= 28) | 3286 | if (earliestDay <= 28) |
3284 | return QDate(earliestYear, 2, 28); | 3287 | return QDate(earliestYear, 2, 28); |
3285 | break; | 3288 | break; |
3286 | case rFeb29: | 3289 | case rFeb29: |
3287 | break; | 3290 | break; |
3288 | } | 3291 | } |
3289 | } | 3292 | } |
3290 | } | 3293 | } |
3291 | } | 3294 | } |
3292 | break; | 3295 | break; |
3293 | } | 3296 | } |
3294 | case rYearlyPos: { | 3297 | case rYearlyPos: { |
3295 | QValueList<int> dayList; | 3298 | Q3ValueList<int> dayList; |
3296 | int earliestYear = earliestDate.year(); | 3299 | int earliestYear = earliestDate.year(); |
3297 | int earliestMonth = earliestDate.month(); | 3300 | int earliestMonth = earliestDate.month(); |
3298 | int earliestDay = earliestDate.day(); | 3301 | int earliestDay = earliestDate.day(); |
3299 | for ( ; it.current(); ++it) { | 3302 | for ( ; it.current(); ++it) { |
3300 | int month = *it.current(); | 3303 | int month = *it.current(); |
3301 | if (month >= earliestMonth) { | 3304 | if (month >= earliestMonth) { |
3302 | QDate monthBegin(earliestYear, month, 1); | 3305 | QDate monthBegin(earliestYear, month, 1); |
3303 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); | 3306 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); |
3304 | for (QValueList<int>::ConstIterator id = dayList.begin(); id != dayList.end(); ++id) { | 3307 | for (Q3ValueList<int>::ConstIterator id = dayList.begin(); id != dayList.end(); ++id) { |
3305 | if (*id >= earliestDay) | 3308 | if (*id >= earliestDay) |
3306 | return monthBegin.addDays(*id - 1); | 3309 | return monthBegin.addDays(*id - 1); |
3307 | } | 3310 | } |
3308 | earliestDay = 1; | 3311 | earliestDay = 1; |
3309 | } | 3312 | } |
3310 | } | 3313 | } |
3311 | break; | 3314 | break; |
3312 | } | 3315 | } |
3313 | case rYearlyDay: { | 3316 | case rYearlyDay: { |
3314 | int earliestDay = earliestDate.dayOfYear(); | 3317 | int earliestDay = earliestDate.dayOfYear(); |
3315 | for ( ; it.current(); ++it) { | 3318 | for ( ; it.current(); ++it) { |
3316 | int day = *it.current(); | 3319 | int day = *it.current(); |
3317 | if (day >= earliestDay && (day <= 365 || day <= earliestDate.daysInYear())) | 3320 | if (day >= earliestDay && (day <= 365 || day <= earliestDate.daysInYear())) |
3318 | return earliestDate.addDays(day - earliestDay); | 3321 | return earliestDate.addDays(day - earliestDay); |
3319 | } | 3322 | } |
3320 | break; | 3323 | break; |
3321 | } | 3324 | } |
3322 | } | 3325 | } |
3323 | return QDate(); | 3326 | return QDate(); |
3324 | } | 3327 | } |
3325 | 3328 | ||
3326 | /* From the recurrence yearly month list or yearly day list, get the latest | 3329 | /* From the recurrence yearly month list or yearly day list, get the latest |
3327 | * month or day in the specified year which is <= the latestDate. | 3330 | * month or day in the specified year which is <= the latestDate. |
3328 | * Note that rYearNums is sorted in numerical order. | 3331 | * Note that rYearNums is sorted in numerical order. |
3329 | */ | 3332 | */ |
3330 | QDate Recurrence::getLastDateInYear(const QDate &latestDate) const | 3333 | QDate Recurrence::getLastDateInYear(const QDate &latestDate) const |
3331 | { | 3334 | { |
3332 | QPtrListIterator<int> it(rYearNums); | 3335 | Q3PtrListIterator<int> it(rYearNums); |
3333 | switch (recurs) { | 3336 | switch (recurs) { |
3334 | case rYearlyMonth: { | 3337 | case rYearlyMonth: { |
3335 | int day = recurStart().date().day(); | 3338 | int day = recurStart().date().day(); |
3336 | int latestYear = latestDate.year(); | 3339 | int latestYear = latestDate.year(); |
3337 | int latestMonth = latestDate.month(); | 3340 | int latestMonth = latestDate.month(); |
3338 | if (latestDate.day() > day) { | 3341 | if (latestDate.day() > day) { |
3339 | // The latest date is earlier in the month than the recurrence date, | 3342 | // The latest date is earlier in the month than the recurrence date, |
3340 | // so skip to the previous month before starting to check | 3343 | // so skip to the previous month before starting to check |
3341 | if (--latestMonth <= 0) | 3344 | if (--latestMonth <= 0) |
3342 | return QDate(); | 3345 | return QDate(); |
3343 | } | 3346 | } |
3344 | for (it.toLast(); it.current(); --it) { | 3347 | for (it.toLast(); it.current(); --it) { |
3345 | int month = *it.current(); | 3348 | int month = *it.current(); |
3346 | if (month <= latestMonth) { | 3349 | if (month <= latestMonth) { |
3347 | if (day <= 28 || QDate::isValid(latestYear, month, day)) | 3350 | if (day <= 28 || QDate::isValid(latestYear, month, day)) |
3348 | return QDate(latestYear, month, day); | 3351 | return QDate(latestYear, month, day); |
3349 | if (day == 29 && month == 2) { | 3352 | if (day == 29 && month == 2) { |
3350 | // It's a recurrence on February 29th, in a non-leap year | 3353 | // It's a recurrence on February 29th, in a non-leap year |
3351 | switch (mFeb29YearlyType) { | 3354 | switch (mFeb29YearlyType) { |
3352 | case rMar1: | 3355 | case rMar1: |
3353 | if (latestMonth >= 3) | 3356 | if (latestMonth >= 3) |
3354 | return QDate(latestYear, 3, 1); | 3357 | return QDate(latestYear, 3, 1); |
3355 | break; | 3358 | break; |
3356 | case rFeb28: | 3359 | case rFeb28: |
3357 | return QDate(latestYear, 2, 28); | 3360 | return QDate(latestYear, 2, 28); |
3358 | case rFeb29: | 3361 | case rFeb29: |
3359 | break; | 3362 | break; |
3360 | } | 3363 | } |
3361 | } | 3364 | } |
3362 | } | 3365 | } |
3363 | } | 3366 | } |
3364 | break; | 3367 | break; |
3365 | } | 3368 | } |
3366 | case rYearlyPos: { | 3369 | case rYearlyPos: { |
3367 | QValueList<int> dayList; | 3370 | Q3ValueList<int> dayList; |
3368 | int latestYear = latestDate.year(); | 3371 | int latestYear = latestDate.year(); |
3369 | int latestMonth = latestDate.month(); | 3372 | int latestMonth = latestDate.month(); |
3370 | int latestDay = latestDate.day(); | 3373 | int latestDay = latestDate.day(); |
3371 | for (it.toLast(); it.current(); --it) { | 3374 | for (it.toLast(); it.current(); --it) { |
3372 | int month = *it.current(); | 3375 | int month = *it.current(); |
3373 | if (month <= latestMonth) { | 3376 | if (month <= latestMonth) { |
3374 | QDate monthBegin(latestYear, month, 1); | 3377 | QDate monthBegin(latestYear, month, 1); |
3375 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); | 3378 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); |
3376 | for (QValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { | 3379 | for (Q3ValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { |
3377 | if (*id <= latestDay) | 3380 | if (*id <= latestDay) |
3378 | return monthBegin.addDays(*id - 1); | 3381 | return monthBegin.addDays(*id - 1); |
3379 | } | 3382 | } |
3380 | latestDay = 31; | 3383 | latestDay = 31; |
3381 | } | 3384 | } |
3382 | } | 3385 | } |
3383 | break; | 3386 | break; |
3384 | } | 3387 | } |
3385 | case rYearlyDay: { | 3388 | case rYearlyDay: { |
3386 | int latestDay = latestDate.dayOfYear(); | 3389 | int latestDay = latestDate.dayOfYear(); |
3387 | for (it.toLast(); it.current(); --it) { | 3390 | for (it.toLast(); it.current(); --it) { |
3388 | int day = *it.current(); | 3391 | int day = *it.current(); |
3389 | if (day <= latestDay) | 3392 | if (day <= latestDay) |
3390 | return latestDate.addDays(day - latestDay); | 3393 | return latestDate.addDays(day - latestDay); |
3391 | } | 3394 | } |
3392 | break; | 3395 | break; |
3393 | } | 3396 | } |
3394 | } | 3397 | } |
3395 | return QDate(); | 3398 | return QDate(); |
3396 | } | 3399 | } |
3397 | 3400 | ||
3398 | void Recurrence::dump() const | 3401 | void Recurrence::dump() const |
3399 | { | 3402 | { |
3400 | ; | 3403 | ; |
3401 | } | 3404 | } |
diff --git a/libkcal/recurrence.h b/libkcal/recurrence.h index b13d14f..5b5aab1 100644 --- a/libkcal/recurrence.h +++ b/libkcal/recurrence.h | |||
@@ -1,401 +1,403 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> | 5 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_RECURRENCE_H | 22 | #ifndef KCAL_RECURRENCE_H |
23 | #define KCAL_RECURRENCE_H | 23 | #define KCAL_RECURRENCE_H |
24 | 24 | ||
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qbitarray.h> | 26 | #include <qbitarray.h> |
27 | #include <qptrlist.h> | 27 | #include <q3ptrlist.h> |
28 | //Added by qt3to4: | ||
29 | #include <Q3ValueList> | ||
28 | 30 | ||
29 | namespace KCal { | 31 | namespace KCal { |
30 | 32 | ||
31 | class Incidence; | 33 | class Incidence; |
32 | 34 | ||
33 | /** | 35 | /** |
34 | This class represents a recurrence rule for a calendar incidence. | 36 | This class represents a recurrence rule for a calendar incidence. |
35 | */ | 37 | */ |
36 | class Recurrence | 38 | class Recurrence |
37 | { | 39 | { |
38 | public: | 40 | public: |
39 | /** enumeration for describing how an event recurs, if at all. */ | 41 | /** enumeration for describing how an event recurs, if at all. */ |
40 | enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003, | 42 | enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003, |
41 | rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006, | 43 | rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006, |
42 | rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009 }; | 44 | rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009 }; |
43 | 45 | ||
44 | /** Enumeration for specifying what date yearly recurrences of February 29th occur | 46 | /** Enumeration for specifying what date yearly recurrences of February 29th occur |
45 | * in non-leap years. */ | 47 | * in non-leap years. */ |
46 | enum Feb29Type { | 48 | enum Feb29Type { |
47 | rMar1, // recur on March 1st (default) | 49 | rMar1, // recur on March 1st (default) |
48 | rFeb28, // recur on February 28th | 50 | rFeb28, // recur on February 28th |
49 | rFeb29 // only recur on February 29th, i.e. don't recur in non-leap years | 51 | rFeb29 // only recur on February 29th, i.e. don't recur in non-leap years |
50 | }; | 52 | }; |
51 | 53 | ||
52 | /** structure for Recurs rMonthlyPos */ | 54 | /** structure for Recurs rMonthlyPos */ |
53 | struct rMonthPos { | 55 | struct rMonthPos { |
54 | QBitArray rDays; | 56 | QBitArray rDays; |
55 | short rPos; | 57 | short rPos; |
56 | bool negative; | 58 | bool negative; |
57 | }; | 59 | }; |
58 | 60 | ||
59 | Recurrence(Incidence *parent, int compatVersion = 0); | 61 | Recurrence(Incidence *parent, int compatVersion = 0); |
60 | Recurrence(const Recurrence&, Incidence *parent); | 62 | Recurrence(const Recurrence&, Incidence *parent); |
61 | ~Recurrence(); | 63 | ~Recurrence(); |
62 | 64 | ||
63 | bool operator==( const Recurrence& ) const; | 65 | bool operator==( const Recurrence& ) const; |
64 | bool operator!=( const Recurrence& r ) const { return !operator==(r); } | 66 | bool operator!=( const Recurrence& r ) const { return !operator==(r); } |
65 | 67 | ||
66 | Incidence *parent() { return mParent; } | 68 | Incidence *parent() { return mParent; } |
67 | 69 | ||
68 | /** Return the start of the recurrence */ | 70 | /** Return the start of the recurrence */ |
69 | QDateTime recurStart() const { return mRecurStart; } | 71 | QDateTime recurStart() const { return mRecurStart; } |
70 | /** Returns the number of exception dates for the recurrence */ | 72 | /** Returns the number of exception dates for the recurrence */ |
71 | int recurExDatesCount() const { return mRecurExDatesCount; } | 73 | int recurExDatesCount() const { return mRecurExDatesCount; } |
72 | /** Set start of recurrence, as a date and time. */ | 74 | /** Set start of recurrence, as a date and time. */ |
73 | void setRecurStart(const QDateTime &start); | 75 | void setRecurStart(const QDateTime &start); |
74 | /** Set start of recurrence, as a date with no time. | 76 | /** Set start of recurrence, as a date with no time. |
75 | * Recurrence types which are sub-daily (e.g. rHourly) always have a time; | 77 | * Recurrence types which are sub-daily (e.g. rHourly) always have a time; |
76 | * the time is set to 00:00:00 in these cases. */ | 78 | * the time is set to 00:00:00 in these cases. */ |
77 | void setRecurStart(const QDate &start); | 79 | void setRecurStart(const QDate &start); |
78 | /** Set whether the recurrence has no time, just a date. | 80 | /** Set whether the recurrence has no time, just a date. |
79 | * Recurrence types which are sub-daily (e.g. rHourly) always have a time | 81 | * Recurrence types which are sub-daily (e.g. rHourly) always have a time |
80 | * and cannot be set to float. | 82 | * and cannot be set to float. |
81 | * N.B. This property is derived by default from the parent incidence, | 83 | * N.B. This property is derived by default from the parent incidence, |
82 | * or according to whether a time is specified in setRecurStart(). */ | 84 | * or according to whether a time is specified in setRecurStart(). */ |
83 | void setFloats(bool f); | 85 | void setFloats(bool f); |
84 | /** | 86 | /** |
85 | Returns whether the recurrence has no time, just a date. | 87 | Returns whether the recurrence has no time, just a date. |
86 | */ | 88 | */ |
87 | bool doesFloat() const { | 89 | bool doesFloat() const { |
88 | return mFloats; | 90 | return mFloats; |
89 | } | 91 | } |
90 | 92 | ||
91 | /** Set if recurrence is read-only or can be changed. */ | 93 | /** Set if recurrence is read-only or can be changed. */ |
92 | void setRecurReadOnly(bool readOnly) { mRecurReadOnly = readOnly; } | 94 | void setRecurReadOnly(bool readOnly) { mRecurReadOnly = readOnly; } |
93 | bool recurReadOnly() const | 95 | bool recurReadOnly() const |
94 | { | 96 | { |
95 | return mRecurReadOnly; | 97 | return mRecurReadOnly; |
96 | } | 98 | } |
97 | 99 | ||
98 | 100 | ||
99 | /** Set number of exception dates. */ | 101 | /** Set number of exception dates. */ |
100 | void setRecurExDatesCount(int count) { if (count >= 0) mRecurExDatesCount = count; } | 102 | void setRecurExDatesCount(int count) { if (count >= 0) mRecurExDatesCount = count; } |
101 | /** Set the calendar file version for backwards compatibility. | 103 | /** Set the calendar file version for backwards compatibility. |
102 | * @var version is the KOrganizer/libkcal version, e.g. 220 for KDE 2.2.0. | 104 | * @var version is the KOrganizer/libkcal version, e.g. 220 for KDE 2.2.0. |
103 | * Specify version = 0 to cancel compatibility mode. | 105 | * Specify version = 0 to cancel compatibility mode. |
104 | */ | 106 | */ |
105 | void setCompatVersion(int version = 0); | 107 | void setCompatVersion(int version = 0); |
106 | 108 | ||
107 | /** Returns the event's recurrence status. See the enumeration at the top | 109 | /** Returns the event's recurrence status. See the enumeration at the top |
108 | * of this file for possible values. */ | 110 | * of this file for possible values. */ |
109 | ushort doesRecur() const; | 111 | ushort doesRecur() const; |
110 | /** Returns true if the date specified is one on which the event will | 112 | /** Returns true if the date specified is one on which the event will |
111 | * recur. */ | 113 | * recur. */ |
112 | bool recursOnPure(const QDate &qd) const; | 114 | bool recursOnPure(const QDate &qd) const; |
113 | /** Returns true if the date/time specified is one at which the event will | 115 | /** Returns true if the date/time specified is one at which the event will |
114 | * recur. Times are rounded down to the nearest minute to determine the result. */ | 116 | * recur. Times are rounded down to the nearest minute to determine the result. */ |
115 | bool recursAtPure(const QDateTime &) const; | 117 | bool recursAtPure(const QDateTime &) const; |
116 | /** Turns off recurrence for the event. */ | 118 | /** Turns off recurrence for the event. */ |
117 | void unsetRecurs(); | 119 | void unsetRecurs(); |
118 | 120 | ||
119 | /** Returns the date of the next recurrence, after the specified date. | 121 | /** Returns the date of the next recurrence, after the specified date. |
120 | * @var preDate the date after which to find the recurrence. | 122 | * @var preDate the date after which to find the recurrence. |
121 | * @var last if non-null, *last is set to true if the next recurrence is the | 123 | * @var last if non-null, *last is set to true if the next recurrence is the |
122 | * last recurrence, else false. | 124 | * last recurrence, else false. |
123 | * Reply = date of next recurrence, or invalid date if none. | 125 | * Reply = date of next recurrence, or invalid date if none. |
124 | */ | 126 | */ |
125 | QDate getNextDate(const QDate& preDate, bool* last = 0) const; | 127 | QDate getNextDate(const QDate& preDate, bool* last = 0) const; |
126 | /** Returns the date and time of the next recurrence, after the specified date/time. | 128 | /** Returns the date and time of the next recurrence, after the specified date/time. |
127 | * If the recurrence has no time, the next date after the specified date is returned. | 129 | * If the recurrence has no time, the next date after the specified date is returned. |
128 | * @var preDate the date/time after which to find the recurrence. | 130 | * @var preDate the date/time after which to find the recurrence. |
129 | * @var last if non-null, *last is set to true if the next recurrence is the | 131 | * @var last if non-null, *last is set to true if the next recurrence is the |
130 | * last recurrence, else false. | 132 | * last recurrence, else false. |
131 | * Reply = date/time of next recurrence, or invalid date if none. | 133 | * Reply = date/time of next recurrence, or invalid date if none. |
132 | */ | 134 | */ |
133 | QDateTime getNextDateTime(const QDateTime& preDateTime, bool* last = 0) const; | 135 | QDateTime getNextDateTime(const QDateTime& preDateTime, bool* last = 0) const; |
134 | /** Returns the date of the last previous recurrence, before the specified date. | 136 | /** Returns the date of the last previous recurrence, before the specified date. |
135 | * @var afterDate the date before which to find the recurrence. | 137 | * @var afterDate the date before which to find the recurrence. |
136 | * @var last if non-null, *last is set to true if the previous recurrence is the | 138 | * @var last if non-null, *last is set to true if the previous recurrence is the |
137 | * last recurrence, else false. | 139 | * last recurrence, else false. |
138 | * Reply = date of previous recurrence, or invalid date if none. | 140 | * Reply = date of previous recurrence, or invalid date if none. |
139 | */ | 141 | */ |
140 | QDate getPreviousDate(const QDate& afterDate, bool* last = 0) const; | 142 | QDate getPreviousDate(const QDate& afterDate, bool* last = 0) const; |
141 | /** Returns the date and time of the last previous recurrence, before the specified date/time. | 143 | /** Returns the date and time of the last previous recurrence, before the specified date/time. |
142 | * If a time later than 00:00:00 is specified and the recurrence has no time, 00:00:00 on | 144 | * If a time later than 00:00:00 is specified and the recurrence has no time, 00:00:00 on |
143 | * the specified date is returned if that date recurs. | 145 | * the specified date is returned if that date recurs. |
144 | * @var afterDate the date/time before which to find the recurrence. | 146 | * @var afterDate the date/time before which to find the recurrence. |
145 | * @var last if non-null, *last is set to true if the previous recurrence is the | 147 | * @var last if non-null, *last is set to true if the previous recurrence is the |
146 | * last recurrence, else false. | 148 | * last recurrence, else false. |
147 | * Reply = date/time of previous recurrence, or invalid date if none. | 149 | * Reply = date/time of previous recurrence, or invalid date if none. |
148 | */ | 150 | */ |
149 | QDateTime getPreviousDateTime(const QDateTime& afterDateTime, bool* last = 0) const; | 151 | QDateTime getPreviousDateTime(const QDateTime& afterDateTime, bool* last = 0) const; |
150 | 152 | ||
151 | /** Returns frequency of recurrence, in terms of the recurrence time period type. */ | 153 | /** Returns frequency of recurrence, in terms of the recurrence time period type. */ |
152 | int frequency() const; | 154 | int frequency() const; |
153 | /** Returns the total number of recurrences, including the initial occurrence. */ | 155 | /** Returns the total number of recurrences, including the initial occurrence. */ |
154 | int duration() const; | 156 | int duration() const; |
155 | /** Sets the total number of times the event is to occur, including both the | 157 | /** Sets the total number of times the event is to occur, including both the |
156 | * first and last. */ | 158 | * first and last. */ |
157 | void setDuration(int duration); | 159 | void setDuration(int duration); |
158 | /** Returns the number of recurrences up to and including the date specified. */ | 160 | /** Returns the number of recurrences up to and including the date specified. */ |
159 | int durationTo(const QDate &) const; | 161 | int durationTo(const QDate &) const; |
160 | /** Returns the number of recurrences up to and including the date/time specified. */ | 162 | /** Returns the number of recurrences up to and including the date/time specified. */ |
161 | int durationTo(const QDateTime &) const; | 163 | int durationTo(const QDateTime &) const; |
162 | 164 | ||
163 | /** Returns the date of the last recurrence. | 165 | /** Returns the date of the last recurrence. |
164 | * An invalid date is returned if the recurrence has no end. | 166 | * An invalid date is returned if the recurrence has no end. |
165 | * Note: for some recurrence types, endDate() can involve significant calculation. | 167 | * Note: for some recurrence types, endDate() can involve significant calculation. |
166 | */ | 168 | */ |
167 | QDate endDate() const; | 169 | QDate endDate() const; |
168 | /** Returns the date and time of the last recurrence. | 170 | /** Returns the date and time of the last recurrence. |
169 | * An invalid date is returned if the recurrence has no end. | 171 | * An invalid date is returned if the recurrence has no end. |
170 | * Note: for some recurrence types, endDateTime() can involve significant calculation. | 172 | * Note: for some recurrence types, endDateTime() can involve significant calculation. |
171 | */ | 173 | */ |
172 | QDateTime endDateTime() const; | 174 | QDateTime endDateTime() const; |
173 | /** Returns a string representing the recurrence end date in the format | 175 | /** Returns a string representing the recurrence end date in the format |
174 | according to the user's locale settings. */ | 176 | according to the user's locale settings. */ |
175 | QString endDateStr(bool shortfmt=true) const; | 177 | QString endDateStr(bool shortfmt=true) const; |
176 | 178 | ||
177 | /** Sets an event to recur minutely. | 179 | /** Sets an event to recur minutely. |
178 | * @var _rFreq the frequency to recur, e.g. 2 is every other minute | 180 | * @var _rFreq the frequency to recur, e.g. 2 is every other minute |
179 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. | 181 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. |
180 | */ | 182 | */ |
181 | void setMinutely(int _rFreq, int duration); | 183 | void setMinutely(int _rFreq, int duration); |
182 | /** Sets an event to recur minutely. | 184 | /** Sets an event to recur minutely. |
183 | * @var _rFreq the frequency to recur, e.g. 2 is every other minute | 185 | * @var _rFreq the frequency to recur, e.g. 2 is every other minute |
184 | * @var endDateTime the ending date/time after which to stop recurring | 186 | * @var endDateTime the ending date/time after which to stop recurring |
185 | */ | 187 | */ |
186 | void setMinutely(int _rFreq, const QDateTime &endDateTime); | 188 | void setMinutely(int _rFreq, const QDateTime &endDateTime); |
187 | 189 | ||
188 | /** Sets an event to recur hourly. | 190 | /** Sets an event to recur hourly. |
189 | * @var _rFreq the frequency to recur, e.g. 2 is every other hour | 191 | * @var _rFreq the frequency to recur, e.g. 2 is every other hour |
190 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. | 192 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. |
191 | */ | 193 | */ |
192 | void setHourly(int _rFreq, int duration); | 194 | void setHourly(int _rFreq, int duration); |
193 | /** Sets an event to recur hourly. | 195 | /** Sets an event to recur hourly. |
194 | * @var _rFreq the frequency to recur, e.g. 2 is every other hour | 196 | * @var _rFreq the frequency to recur, e.g. 2 is every other hour |
195 | * @var endDateTime the ending date/time after which to stop recurring | 197 | * @var endDateTime the ending date/time after which to stop recurring |
196 | */ | 198 | */ |
197 | void setHourly(int _rFreq, const QDateTime &endDateTime); | 199 | void setHourly(int _rFreq, const QDateTime &endDateTime); |
198 | 200 | ||
199 | /** Sets an event to recur daily. | 201 | /** Sets an event to recur daily. |
200 | * @var _rFreq the frequency to recur, e.g. 2 is every other day | 202 | * @var _rFreq the frequency to recur, e.g. 2 is every other day |
201 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. | 203 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. |
202 | */ | 204 | */ |
203 | void setDaily(int _rFreq, int duration); | 205 | void setDaily(int _rFreq, int duration); |
204 | /** Sets an event to recur daily. | 206 | /** Sets an event to recur daily. |
205 | * @var _rFreq the frequency to recur, e.g. 2 is every other day | 207 | * @var _rFreq the frequency to recur, e.g. 2 is every other day |
206 | * @var endDate the ending date after which to stop recurring | 208 | * @var endDate the ending date after which to stop recurring |
207 | */ | 209 | */ |
208 | void setDaily(int _rFreq, const QDate &endDate); | 210 | void setDaily(int _rFreq, const QDate &endDate); |
209 | 211 | ||
210 | /** Sets an event to recur weekly. | 212 | /** Sets an event to recur weekly. |
211 | * @var _rFreq the frequency to recur, e.g. every other week etc. | 213 | * @var _rFreq the frequency to recur, e.g. every other week etc. |
212 | * @var _rDays a 7 bit array indicating which days on which to recur (bit 0 = Monday). | 214 | * @var _rDays a 7 bit array indicating which days on which to recur (bit 0 = Monday). |
213 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. | 215 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. |
214 | * @var weekStart the first day of the week (Monday=1 .. Sunday=7, default is Monday). | 216 | * @var weekStart the first day of the week (Monday=1 .. Sunday=7, default is Monday). |
215 | */ | 217 | */ |
216 | void setWeekly(int _rFreq, const QBitArray &_rDays, int duration, int weekStart = 1); | 218 | void setWeekly(int _rFreq, const QBitArray &_rDays, int duration, int weekStart = 1); |
217 | /** Sets an event to recur weekly. | 219 | /** Sets an event to recur weekly. |
218 | * @var _rFreq the frequency to recur, e.g. every other week etc. | 220 | * @var _rFreq the frequency to recur, e.g. every other week etc. |
219 | * @var _rDays a 7 bit array indicating which days on which to recur (bit 0 = Monday). | 221 | * @var _rDays a 7 bit array indicating which days on which to recur (bit 0 = Monday). |
220 | * @var endDate the date on which to stop recurring. | 222 | * @var endDate the date on which to stop recurring. |
221 | * @var weekStart the first day of the week (Monday=1 .. Sunday=7, default is Monday). | 223 | * @var weekStart the first day of the week (Monday=1 .. Sunday=7, default is Monday). |
222 | */ | 224 | */ |
223 | void setWeekly(int _rFreq, const QBitArray &_rDays, const QDate &endDate, int weekStart = 1); | 225 | void setWeekly(int _rFreq, const QBitArray &_rDays, const QDate &endDate, int weekStart = 1); |
224 | /** Returns the first day of the week. Monday=1 .. Sunday=7. */ | 226 | /** Returns the first day of the week. Monday=1 .. Sunday=7. */ |
225 | int weekStart() const { return rWeekStart; } | 227 | int weekStart() const { return rWeekStart; } |
226 | /** Returns week day mask (bit 0 = Monday). */ | 228 | /** Returns week day mask (bit 0 = Monday). */ |
227 | const QBitArray &days() const; | 229 | const QBitArray &days() const; |
228 | 230 | ||
229 | /** Sets an event to recur monthly. | 231 | /** Sets an event to recur monthly. |
230 | * @var type rMonthlyPos or rMonthlyDay | 232 | * @var type rMonthlyPos or rMonthlyDay |
231 | * @var _rFreq the frequency to recur, e.g. 3 for every third month. | 233 | * @var _rFreq the frequency to recur, e.g. 3 for every third month. |
232 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. | 234 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. |
233 | */ | 235 | */ |
234 | void setMonthly(short type, int _rFreq, int duration); | 236 | void setMonthly(short type, int _rFreq, int duration); |
235 | /** same as above, but with ending date not number of recurrences */ | 237 | /** same as above, but with ending date not number of recurrences */ |
236 | void setMonthly(short type, int _rFreq, const QDate &endDate); | 238 | void setMonthly(short type, int _rFreq, const QDate &endDate); |
237 | /** Adds a position to the recursMonthlyPos recurrence rule, if it is | 239 | /** Adds a position to the recursMonthlyPos recurrence rule, if it is |
238 | * set. | 240 | * set. |
239 | * @var _rPos the position in the month for the recurrence, with valid | 241 | * @var _rPos the position in the month for the recurrence, with valid |
240 | * values being 1-5 (5 weeks max in a month). | 242 | * values being 1-5 (5 weeks max in a month). |
241 | * @var _rDays the days for the position to recur on (bit 0 = Monday). | 243 | * @var _rDays the days for the position to recur on (bit 0 = Monday). |
242 | * Example: _rPos = 2, and bits 0 and 2 are set in _rDays: | 244 | * Example: _rPos = 2, and bits 0 and 2 are set in _rDays: |
243 | * the rule is to repeat every 2nd Monday and Wednesday in the month. | 245 | * the rule is to repeat every 2nd Monday and Wednesday in the month. |
244 | */ | 246 | */ |
245 | void addMonthlyPos(short _rPos, const QBitArray &_rDays); | 247 | void addMonthlyPos(short _rPos, const QBitArray &_rDays); |
246 | /** Adds a position the the recursMonthlyDay list. | 248 | /** Adds a position the the recursMonthlyDay list. |
247 | * @var _rDay the date in the month to recur. | 249 | * @var _rDay the date in the month to recur. |
248 | */ | 250 | */ |
249 | void addMonthlyDay(short _rDay); | 251 | void addMonthlyDay(short _rDay); |
250 | /** Returns list of day positions in months. */ | 252 | /** Returns list of day positions in months. */ |
251 | const QPtrList<rMonthPos> &monthPositions() const; | 253 | const Q3PtrList<rMonthPos> &monthPositions() const; |
252 | /** Returns list of day numbers of a month. */ | 254 | /** Returns list of day numbers of a month. */ |
253 | const QPtrList<int> &monthDays() const; | 255 | const Q3PtrList<int> &monthDays() const; |
254 | 256 | ||
255 | /** Sets an event to recur yearly. | 257 | /** Sets an event to recur yearly. |
256 | * @var type rYearlyMonth, rYearlyPos or rYearlyDay | 258 | * @var type rYearlyMonth, rYearlyPos or rYearlyDay |
257 | * @var freq the frequency to recur, e.g. 3 for every third year. | 259 | * @var freq the frequency to recur, e.g. 3 for every third year. |
258 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. | 260 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. |
259 | */ | 261 | */ |
260 | void setYearly(int type, int freq, int duration); | 262 | void setYearly(int type, int freq, int duration); |
261 | /** Sets an event to recur yearly ending at \a endDate. */ | 263 | /** Sets an event to recur yearly ending at \a endDate. */ |
262 | void setYearly(int type, int freq, const QDate &endDate); | 264 | void setYearly(int type, int freq, const QDate &endDate); |
263 | /** Sets an event to recur yearly on specified dates. | 265 | /** Sets an event to recur yearly on specified dates. |
264 | * The dates must be specified by calling addYearlyNum(). | 266 | * The dates must be specified by calling addYearlyNum(). |
265 | * @var type the way recurrences of February 29th are to be handled in non-leap years. | 267 | * @var type the way recurrences of February 29th are to be handled in non-leap years. |
266 | * @var freq the frequency to recur, e.g. 3 for every third year. | 268 | * @var freq the frequency to recur, e.g. 3 for every third year. |
267 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. | 269 | * @var duration the number of times the event is to occur, or -1 to recur indefinitely. |
268 | */ | 270 | */ |
269 | void setYearlyByDate(Feb29Type type, int freq, int duration); | 271 | void setYearlyByDate(Feb29Type type, int freq, int duration); |
270 | /** Sets an event to recur yearly ending at \a endDate. */ | 272 | /** Sets an event to recur yearly ending at \a endDate. */ |
271 | void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate); | 273 | void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate); |
272 | /** Adds position of day or month in year. | 274 | /** Adds position of day or month in year. |
273 | * N.B. for recursYearlyPos, addYearlyMonthPos() must also be called | 275 | * N.B. for recursYearlyPos, addYearlyMonthPos() must also be called |
274 | * to add positions within the month. */ | 276 | * to add positions within the month. */ |
275 | void addYearlyNum(short _rNum); | 277 | void addYearlyNum(short _rNum); |
276 | /** Adds a position to the recursYearlyPos recurrence rule, if it is set. | 278 | /** Adds a position to the recursYearlyPos recurrence rule, if it is set. |
277 | * N.B. addYearlyNum() must also be called to add recurrence months. | 279 | * N.B. addYearlyNum() must also be called to add recurrence months. |
278 | * Parameters are the same as for addMonthlyPos(). | 280 | * Parameters are the same as for addMonthlyPos(). |
279 | */ | 281 | */ |
280 | void addYearlyMonthPos(short _rPos, const QBitArray &_rDays); | 282 | void addYearlyMonthPos(short _rPos, const QBitArray &_rDays); |
281 | /** Returns positions of days or months in year. */ | 283 | /** Returns positions of days or months in year. */ |
282 | const QPtrList<int> &yearNums() const; | 284 | const Q3PtrList<int> &yearNums() const; |
283 | /** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */ | 285 | /** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */ |
284 | const QPtrList<rMonthPos> &yearMonthPositions() const; | 286 | const Q3PtrList<rMonthPos> &yearMonthPositions() const; |
285 | /** Returns how yearly recurrences of February 29th are handled. */ | 287 | /** Returns how yearly recurrences of February 29th are handled. */ |
286 | Feb29Type feb29YearlyType() const { return mFeb29YearlyType; } | 288 | Feb29Type feb29YearlyType() const { return mFeb29YearlyType; } |
287 | /** Sets the default method for handling yearly recurrences of February 29th. */ | 289 | /** Sets the default method for handling yearly recurrences of February 29th. */ |
288 | static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; } | 290 | static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; } |
289 | /** Returns the default method for handling yearly recurrences of February 29th. */ | 291 | /** Returns the default method for handling yearly recurrences of February 29th. */ |
290 | static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; } | 292 | static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; } |
291 | void addYearlyMonth(short _rPos ); // added LR | 293 | void addYearlyMonth(short _rPos ); // added LR |
292 | /** | 294 | /** |
293 | Debug output. | 295 | Debug output. |
294 | */ | 296 | */ |
295 | void dump() const; | 297 | void dump() const; |
296 | QString recurrenceText() const; | 298 | QString recurrenceText() const; |
297 | bool getYearlyMonthMonths(int day, QValueList<int>&, | 299 | bool getYearlyMonthMonths(int day, Q3ValueList<int>&, |
298 | QValueList<int> &leaplist) const; | 300 | Q3ValueList<int> &leaplist) const; |
299 | 301 | ||
300 | protected: | 302 | protected: |
301 | enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE }; | 303 | enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE }; |
302 | struct MonthlyData; friend struct MonthlyData; | 304 | struct MonthlyData; friend struct MonthlyData; |
303 | struct YearlyMonthData; friend struct YearlyMonthData; | 305 | struct YearlyMonthData; friend struct YearlyMonthData; |
304 | struct YearlyPosData; friend struct YearlyPosData; | 306 | struct YearlyPosData; friend struct YearlyPosData; |
305 | struct YearlyDayData; friend struct YearlyDayData; | 307 | struct YearlyDayData; friend struct YearlyDayData; |
306 | 308 | ||
307 | bool recursSecondly(const QDate &, int secondFreq) const; | 309 | bool recursSecondly(const QDate &, int secondFreq) const; |
308 | bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const; | 310 | bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const; |
309 | bool recursDaily(const QDate &) const; | 311 | bool recursDaily(const QDate &) const; |
310 | bool recursWeekly(const QDate &) const; | 312 | bool recursWeekly(const QDate &) const; |
311 | bool recursMonthly(const QDate &) const; | 313 | bool recursMonthly(const QDate &) const; |
312 | bool recursYearlyByMonth(const QDate &) const; | 314 | bool recursYearlyByMonth(const QDate &) const; |
313 | bool recursYearlyByPos(const QDate &) const; | 315 | bool recursYearlyByPos(const QDate &) const; |
314 | bool recursYearlyByDay(const QDate &) const; | 316 | bool recursYearlyByDay(const QDate &) const; |
315 | 317 | ||
316 | QDate getNextDateNoTime(const QDate& preDate, bool* last) const; | 318 | QDate getNextDateNoTime(const QDate& preDate, bool* last) const; |
317 | QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const; | 319 | QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const; |
318 | 320 | ||
319 | void addMonthlyPos_(short _rPos, const QBitArray &_rDays); | 321 | void addMonthlyPos_(short _rPos, const QBitArray &_rDays); |
320 | void setDailySub(short type, int freq, int duration); | 322 | void setDailySub(short type, int freq, int duration); |
321 | void setYearly_(short type, Feb29Type, int freq, int duration); | 323 | void setYearly_(short type, Feb29Type, int freq, int duration); |
322 | int recurCalc(PeriodFunc, QDate &enddate) const; | 324 | int recurCalc(PeriodFunc, QDate &enddate) const; |
323 | int recurCalc(PeriodFunc, QDateTime &endtime) const; | 325 | int recurCalc(PeriodFunc, QDateTime &endtime) const; |
324 | int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const; | 326 | int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const; |
325 | int dailyCalc(PeriodFunc, QDate &enddate) const; | 327 | int dailyCalc(PeriodFunc, QDate &enddate) const; |
326 | int weeklyCalc(PeriodFunc, QDate &enddate) const; | 328 | int weeklyCalc(PeriodFunc, QDate &enddate) const; |
327 | int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const; | 329 | int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const; |
328 | int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const; | 330 | int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const; |
329 | int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const; | 331 | int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const; |
330 | int monthlyCalc(PeriodFunc, QDate &enddate) const; | 332 | int monthlyCalc(PeriodFunc, QDate &enddate) const; |
331 | int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const; | 333 | int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const; |
332 | int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const; | 334 | int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const; |
333 | int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const; | 335 | int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const; |
334 | int yearlyMonthCalc(PeriodFunc, QDate &enddate) const; | 336 | int yearlyMonthCalc(PeriodFunc, QDate &enddate) const; |
335 | int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const; | 337 | int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const; |
336 | int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const; | 338 | int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const; |
337 | int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const; | 339 | int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const; |
338 | int yearlyPosCalc(PeriodFunc, QDate &enddate) const; | 340 | int yearlyPosCalc(PeriodFunc, QDate &enddate) const; |
339 | int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const; | 341 | int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const; |
340 | int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const; | 342 | int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const; |
341 | int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const; | 343 | int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const; |
342 | int yearlyDayCalc(PeriodFunc, QDate &enddate) const; | 344 | int yearlyDayCalc(PeriodFunc, QDate &enddate) const; |
343 | int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const; | 345 | int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const; |
344 | int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const; | 346 | int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const; |
345 | int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const; | 347 | int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const; |
346 | 348 | ||
347 | int countMonthlyPosDays() const; | 349 | int countMonthlyPosDays() const; |
348 | void getMonthlyPosDays(QValueList<int>&, int daysInMonth, | 350 | void getMonthlyPosDays(Q3ValueList<int>&, int daysInMonth, |
349 | int startDayOfWeek) const; | 351 | int startDayOfWeek) const; |
350 | bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const; | 352 | bool getMonthlyDayDays(Q3ValueList<int>&, int daysInMonth) const; |
351 | 353 | ||
352 | int getFirstDayInWeek(int startDay, bool useWeekStart = true) const; | 354 | int getFirstDayInWeek(int startDay, bool useWeekStart = true) const; |
353 | int getLastDayInWeek(int endDay, bool useWeekStart = true) const; | 355 | int getLastDayInWeek(int endDay, bool useWeekStart = true) const; |
354 | QDate getFirstDateInMonth(const QDate& earliestDate) const; | 356 | QDate getFirstDateInMonth(const QDate& earliestDate) const; |
355 | QDate getLastDateInMonth(const QDate& latestDate) const; | 357 | QDate getLastDateInMonth(const QDate& latestDate) const; |
356 | QDate getFirstDateInYear(const QDate& earliestDate) const; | 358 | QDate getFirstDateInYear(const QDate& earliestDate) const; |
357 | QDate getLastDateInYear(const QDate& latestDate) const; | 359 | QDate getLastDateInYear(const QDate& latestDate) const; |
358 | 360 | ||
359 | private: | 361 | private: |
360 | // Prohibit copying | 362 | // Prohibit copying |
361 | Recurrence(const Recurrence&); | 363 | Recurrence(const Recurrence&); |
362 | Recurrence &operator=(const Recurrence&); | 364 | Recurrence &operator=(const Recurrence&); |
363 | 365 | ||
364 | short recurs; // should be one of the enums. | 366 | short recurs; // should be one of the enums. |
365 | 367 | ||
366 | int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7 | 368 | int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7 |
367 | QBitArray rDays; // array of days during week it recurs | 369 | QBitArray rDays; // array of days during week it recurs |
368 | 370 | ||
369 | QPtrList<rMonthPos> rMonthPositions; // list of positions during a month | 371 | Q3PtrList<rMonthPos> rMonthPositions; // list of positions during a month |
370 | // on which an event recurs | 372 | // on which an event recurs |
371 | 373 | ||
372 | QPtrList<int> rMonthDays; // list of days during a month on | 374 | Q3PtrList<int> rMonthDays; // list of days during a month on |
373 | // which the event recurs | 375 | // which the event recurs |
374 | 376 | ||
375 | QPtrList<int> rYearNums; // either months/days to recur on for rYearly, | 377 | Q3PtrList<int> rYearNums; // either months/days to recur on for rYearly, |
376 | // sorted in numerical order | 378 | // sorted in numerical order |
377 | 379 | ||
378 | int rFreq; // frequency of period | 380 | int rFreq; // frequency of period |
379 | 381 | ||
380 | // one of the following must be specified | 382 | // one of the following must be specified |
381 | int rDuration; // num times to recur (inc. first occurrence), -1 = infinite | 383 | int rDuration; // num times to recur (inc. first occurrence), -1 = infinite |
382 | QDateTime rEndDateTime; // date/time at which to end recurrence | 384 | QDateTime rEndDateTime; // date/time at which to end recurrence |
383 | 385 | ||
384 | QDateTime mRecurStart; // date/time of first recurrence | 386 | QDateTime mRecurStart; // date/time of first recurrence |
385 | bool mFloats; // the recurrence has no time, just a date | 387 | bool mFloats; // the recurrence has no time, just a date |
386 | bool mRecurReadOnly; | 388 | bool mRecurReadOnly; |
387 | int mRecurExDatesCount; // number of recurrences (in addition to rDuration) which are excluded | 389 | int mRecurExDatesCount; // number of recurrences (in addition to rDuration) which are excluded |
388 | Feb29Type mFeb29YearlyType; // how to handle yearly recurrences of February 29th | 390 | Feb29Type mFeb29YearlyType; // how to handle yearly recurrences of February 29th |
389 | static Feb29Type mFeb29YearlyDefaultType; // default value for mFeb29YearlyType | 391 | static Feb29Type mFeb29YearlyDefaultType; // default value for mFeb29YearlyType |
390 | 392 | ||
391 | // Backwards compatibility for KDE < 3.1. | 393 | // Backwards compatibility for KDE < 3.1. |
392 | int mCompatVersion; // calendar file version for backwards compatibility | 394 | int mCompatVersion; // calendar file version for backwards compatibility |
393 | short mCompatRecurs; // original 'recurs' in old calendar format, or rNone | 395 | short mCompatRecurs; // original 'recurs' in old calendar format, or rNone |
394 | int mCompatDuration; // original 'rDuration' in old calendar format, or 0 | 396 | int mCompatDuration; // original 'rDuration' in old calendar format, or 0 |
395 | 397 | ||
396 | Incidence *mParent; | 398 | Incidence *mParent; |
397 | }; | 399 | }; |
398 | 400 | ||
399 | } | 401 | } |
400 | 402 | ||
401 | #endif | 403 | #endif |
diff --git a/libkcal/scheduler.cpp b/libkcal/scheduler.cpp index 253d8b7..234cfcf 100644 --- a/libkcal/scheduler.cpp +++ b/libkcal/scheduler.cpp | |||
@@ -1,355 +1,357 @@ | |||
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 <qdir.h> | 21 | #include <qdir.h> |
22 | #include <qfile.h> | 22 | #include <qfile.h> |
23 | #include <qtextstream.h> | 23 | #include <q3textstream.h> |
24 | //Added by qt3to4: | ||
25 | #include <Q3PtrList> | ||
24 | 26 | ||
25 | #include <klocale.h> | 27 | #include <klocale.h> |
26 | #include <kdebug.h> | 28 | #include <kdebug.h> |
27 | #include <kstandarddirs.h> | 29 | #include <kstandarddirs.h> |
28 | 30 | ||
29 | #include "event.h" | 31 | #include "event.h" |
30 | #include "todo.h" | 32 | #include "todo.h" |
31 | #include "freebusy.h" | 33 | #include "freebusy.h" |
32 | #include "icalformat.h" | 34 | #include "icalformat.h" |
33 | #include "calendar.h" | 35 | #include "calendar.h" |
34 | 36 | ||
35 | #include "scheduler.h" | 37 | #include "scheduler.h" |
36 | 38 | ||
37 | using namespace KCal; | 39 | using namespace KCal; |
38 | 40 | ||
39 | ScheduleMessage::ScheduleMessage(IncidenceBase *incidence,int method,ScheduleMessage::Status status) | 41 | ScheduleMessage::ScheduleMessage(IncidenceBase *incidence,int method,ScheduleMessage::Status status) |
40 | { | 42 | { |
41 | mIncidence = incidence; | 43 | mIncidence = incidence; |
42 | mMethod = method; | 44 | mMethod = method; |
43 | mStatus = status; | 45 | mStatus = status; |
44 | } | 46 | } |
45 | 47 | ||
46 | QString ScheduleMessage::statusName(ScheduleMessage::Status status) | 48 | QString ScheduleMessage::statusName(ScheduleMessage::Status status) |
47 | { | 49 | { |
48 | switch (status) { | 50 | switch (status) { |
49 | case PublishNew: | 51 | case PublishNew: |
50 | return i18n("Publish"); | 52 | return i18n("Publish"); |
51 | case Obsolete: | 53 | case Obsolete: |
52 | return i18n("Obsolete"); | 54 | return i18n("Obsolete"); |
53 | case RequestNew: | 55 | case RequestNew: |
54 | return i18n("New Request"); | 56 | return i18n("New Request"); |
55 | case RequestUpdate: | 57 | case RequestUpdate: |
56 | return i18n("Updated Request"); | 58 | return i18n("Updated Request"); |
57 | default: | 59 | default: |
58 | return i18n("Unknown Status: %1").arg(QString::number(status)); | 60 | return i18n("Unknown Status: %1").arg(QString::number(status)); |
59 | } | 61 | } |
60 | } | 62 | } |
61 | 63 | ||
62 | Scheduler::Scheduler(Calendar *calendar) | 64 | Scheduler::Scheduler(Calendar *calendar) |
63 | { | 65 | { |
64 | mCalendar = calendar; | 66 | mCalendar = calendar; |
65 | mFormat = new ICalFormat(); | 67 | mFormat = new ICalFormat(); |
66 | } | 68 | } |
67 | 69 | ||
68 | Scheduler::~Scheduler() | 70 | Scheduler::~Scheduler() |
69 | { | 71 | { |
70 | delete mFormat; | 72 | delete mFormat; |
71 | } | 73 | } |
72 | 74 | ||
73 | bool Scheduler::acceptTransaction(IncidenceBase *incidence,Method method,ScheduleMessage::Status status) | 75 | bool Scheduler::acceptTransaction(IncidenceBase *incidence,Method method,ScheduleMessage::Status status) |
74 | { | 76 | { |
75 | kdDebug() << "Scheduler::acceptTransaction " << endl; | 77 | kdDebug() << "Scheduler::acceptTransaction " << endl; |
76 | switch (method) { | 78 | switch (method) { |
77 | case Publish: | 79 | case Publish: |
78 | return acceptPublish(incidence, status, method); | 80 | return acceptPublish(incidence, status, method); |
79 | case Request: | 81 | case Request: |
80 | return acceptRequest(incidence, status); | 82 | return acceptRequest(incidence, status); |
81 | case Add: | 83 | case Add: |
82 | return acceptAdd(incidence, status); | 84 | return acceptAdd(incidence, status); |
83 | case Cancel: | 85 | case Cancel: |
84 | return acceptCancel(incidence, status); | 86 | return acceptCancel(incidence, status); |
85 | case Declinecounter: | 87 | case Declinecounter: |
86 | return acceptDeclineCounter(incidence, status); | 88 | return acceptDeclineCounter(incidence, status); |
87 | case Reply: | 89 | case Reply: |
88 | return acceptReply(incidence, status, method); | 90 | return acceptReply(incidence, status, method); |
89 | case Refresh: | 91 | case Refresh: |
90 | return acceptRefresh(incidence, status); | 92 | return acceptRefresh(incidence, status); |
91 | case Counter: | 93 | case Counter: |
92 | return acceptCounter(incidence, status); | 94 | return acceptCounter(incidence, status); |
93 | default: | 95 | default: |
94 | deleteTransaction(incidence); | 96 | deleteTransaction(incidence); |
95 | return false; | 97 | return false; |
96 | } | 98 | } |
97 | deleteTransaction(incidence); | 99 | deleteTransaction(incidence); |
98 | return false; | 100 | return false; |
99 | } | 101 | } |
100 | 102 | ||
101 | QString Scheduler::methodName(Method method) | 103 | QString Scheduler::methodName(Method method) |
102 | { | 104 | { |
103 | switch (method) { | 105 | switch (method) { |
104 | case Publish: | 106 | case Publish: |
105 | return QString::fromLatin1("Publish"); | 107 | return QString::fromLatin1("Publish"); |
106 | case Request: | 108 | case Request: |
107 | return QString::fromLatin1("Request"); | 109 | return QString::fromLatin1("Request"); |
108 | case Refresh: | 110 | case Refresh: |
109 | return QString::fromLatin1("Refresh"); | 111 | return QString::fromLatin1("Refresh"); |
110 | case Cancel: | 112 | case Cancel: |
111 | return QString::fromLatin1("Cancel"); | 113 | return QString::fromLatin1("Cancel"); |
112 | case Add: | 114 | case Add: |
113 | return QString::fromLatin1("Add"); | 115 | return QString::fromLatin1("Add"); |
114 | case Reply: | 116 | case Reply: |
115 | return QString::fromLatin1("Reply"); | 117 | return QString::fromLatin1("Reply"); |
116 | case Counter: | 118 | case Counter: |
117 | return QString::fromLatin1("Counter"); | 119 | return QString::fromLatin1("Counter"); |
118 | case Declinecounter: | 120 | case Declinecounter: |
119 | return QString::fromLatin1("Decline Counter"); | 121 | return QString::fromLatin1("Decline Counter"); |
120 | default: | 122 | default: |
121 | return QString::fromLatin1("Unknown"); | 123 | return QString::fromLatin1("Unknown"); |
122 | } | 124 | } |
123 | } | 125 | } |
124 | 126 | ||
125 | QString Scheduler::translatedMethodName(Method method) | 127 | QString Scheduler::translatedMethodName(Method method) |
126 | { | 128 | { |
127 | switch (method) { | 129 | switch (method) { |
128 | case Publish: | 130 | case Publish: |
129 | return i18n("Publish"); | 131 | return i18n("Publish"); |
130 | case Request: | 132 | case Request: |
131 | return i18n("Request"); | 133 | return i18n("Request"); |
132 | case Refresh: | 134 | case Refresh: |
133 | return i18n("Refresh"); | 135 | return i18n("Refresh"); |
134 | case Cancel: | 136 | case Cancel: |
135 | return i18n("Cancel"); | 137 | return i18n("Cancel"); |
136 | case Add: | 138 | case Add: |
137 | return i18n("Add"); | 139 | return i18n("Add"); |
138 | case Reply: | 140 | case Reply: |
139 | return i18n("Reply"); | 141 | return i18n("Reply"); |
140 | case Counter: | 142 | case Counter: |
141 | return i18n("counter proposal","Counter"); | 143 | return i18n("counter proposal","Counter"); |
142 | case Declinecounter: | 144 | case Declinecounter: |
143 | return i18n("decline counter proposal","Decline Counter"); | 145 | return i18n("decline counter proposal","Decline Counter"); |
144 | default: | 146 | default: |
145 | return i18n("Unknown"); | 147 | return i18n("Unknown"); |
146 | } | 148 | } |
147 | } | 149 | } |
148 | 150 | ||
149 | bool Scheduler::deleteTransaction(IncidenceBase *) | 151 | bool Scheduler::deleteTransaction(IncidenceBase *) |
150 | { | 152 | { |
151 | return true; | 153 | return true; |
152 | } | 154 | } |
153 | 155 | ||
154 | bool Scheduler::acceptPublish(IncidenceBase *incidence,ScheduleMessage::Status status, Method method) | 156 | bool Scheduler::acceptPublish(IncidenceBase *incidence,ScheduleMessage::Status status, Method method) |
155 | { | 157 | { |
156 | if(incidence->type()=="FreeBusy") { | 158 | if(incidence->type()=="FreeBusy") { |
157 | return acceptFreeBusy(incidence, method); | 159 | return acceptFreeBusy(incidence, method); |
158 | } | 160 | } |
159 | switch (status) { | 161 | switch (status) { |
160 | case ScheduleMessage::Unknown: | 162 | case ScheduleMessage::Unknown: |
161 | case ScheduleMessage::PublishNew: | 163 | case ScheduleMessage::PublishNew: |
162 | if (!mCalendar->event(incidence->uid())) { | 164 | if (!mCalendar->event(incidence->uid())) { |
163 | Incidence *inc = static_cast<Incidence *>(incidence); | 165 | Incidence *inc = static_cast<Incidence *>(incidence); |
164 | mCalendar->addIncidence(inc); | 166 | mCalendar->addIncidence(inc); |
165 | deleteTransaction(incidence); | 167 | deleteTransaction(incidence); |
166 | } | 168 | } |
167 | return true; | 169 | return true; |
168 | case ScheduleMessage::Obsolete: | 170 | case ScheduleMessage::Obsolete: |
169 | return true; | 171 | return true; |
170 | default: | 172 | default: |
171 | deleteTransaction(incidence); | 173 | deleteTransaction(incidence); |
172 | return false; | 174 | return false; |
173 | } | 175 | } |
174 | deleteTransaction(incidence); | 176 | deleteTransaction(incidence); |
175 | return false; | 177 | return false; |
176 | } | 178 | } |
177 | 179 | ||
178 | bool Scheduler::acceptRequest(IncidenceBase *incidence,ScheduleMessage::Status status) | 180 | bool Scheduler::acceptRequest(IncidenceBase *incidence,ScheduleMessage::Status status) |
179 | { | 181 | { |
180 | Incidence *inc = static_cast<Incidence *>(incidence); | 182 | Incidence *inc = static_cast<Incidence *>(incidence); |
181 | if (inc->type()=="FreeBusy") { | 183 | if (inc->type()=="FreeBusy") { |
182 | // reply to this request is handled in korganizer's incomingdialog | 184 | // reply to this request is handled in korganizer's incomingdialog |
183 | return true; | 185 | return true; |
184 | } else { | 186 | } else { |
185 | Event *even = mCalendar->event(incidence->uid()); | 187 | Event *even = mCalendar->event(incidence->uid()); |
186 | if (even) { | 188 | if (even) { |
187 | if ( even->revision()<=inc->revision() ) { | 189 | if ( even->revision()<=inc->revision() ) { |
188 | if ( even->revision()==inc->revision() && | 190 | if ( even->revision()==inc->revision() && |
189 | even->lastModified()>inc->lastModified()) { | 191 | even->lastModified()>inc->lastModified()) { |
190 | deleteTransaction(incidence); | 192 | deleteTransaction(incidence); |
191 | return false; | 193 | return false; |
192 | } | 194 | } |
193 | mCalendar->deleteEvent(even); | 195 | mCalendar->deleteEvent(even); |
194 | } else { | 196 | } else { |
195 | deleteTransaction(incidence); | 197 | deleteTransaction(incidence); |
196 | return false; | 198 | return false; |
197 | } | 199 | } |
198 | } else { | 200 | } else { |
199 | Todo *todo = mCalendar->todo(incidence->uid()); | 201 | Todo *todo = mCalendar->todo(incidence->uid()); |
200 | if (todo) { | 202 | if (todo) { |
201 | if ( todo->revision()<=inc->revision() ) { | 203 | if ( todo->revision()<=inc->revision() ) { |
202 | if ( todo->revision()==inc->revision() && | 204 | if ( todo->revision()==inc->revision() && |
203 | todo->lastModified()>inc->lastModified()) { | 205 | todo->lastModified()>inc->lastModified()) { |
204 | deleteTransaction(incidence); | 206 | deleteTransaction(incidence); |
205 | return false; | 207 | return false; |
206 | } | 208 | } |
207 | mCalendar->deleteTodo(todo); | 209 | mCalendar->deleteTodo(todo); |
208 | } else { | 210 | } else { |
209 | deleteTransaction(incidence); | 211 | deleteTransaction(incidence); |
210 | return false; | 212 | return false; |
211 | } | 213 | } |
212 | } | 214 | } |
213 | } | 215 | } |
214 | } | 216 | } |
215 | mCalendar->addIncidence(inc); | 217 | mCalendar->addIncidence(inc); |
216 | deleteTransaction(incidence); | 218 | deleteTransaction(incidence); |
217 | return true; | 219 | return true; |
218 | } | 220 | } |
219 | 221 | ||
220 | bool Scheduler::acceptAdd(IncidenceBase *incidence,ScheduleMessage::Status status) | 222 | bool Scheduler::acceptAdd(IncidenceBase *incidence,ScheduleMessage::Status status) |
221 | { | 223 | { |
222 | deleteTransaction(incidence); | 224 | deleteTransaction(incidence); |
223 | return false; | 225 | return false; |
224 | } | 226 | } |
225 | 227 | ||
226 | bool Scheduler::acceptCancel(IncidenceBase *incidence,ScheduleMessage::Status status) | 228 | bool Scheduler::acceptCancel(IncidenceBase *incidence,ScheduleMessage::Status status) |
227 | { | 229 | { |
228 | bool ret = false; | 230 | bool ret = false; |
229 | Event *even = mCalendar->event(incidence->uid()); | 231 | Event *even = mCalendar->event(incidence->uid()); |
230 | if (even) { | 232 | if (even) { |
231 | mCalendar->deleteEvent(even); | 233 | mCalendar->deleteEvent(even); |
232 | ret = true; | 234 | ret = true; |
233 | } else { | 235 | } else { |
234 | Todo *todo = mCalendar->todo(incidence->uid()); | 236 | Todo *todo = mCalendar->todo(incidence->uid()); |
235 | if (todo) { | 237 | if (todo) { |
236 | mCalendar->deleteTodo(todo); | 238 | mCalendar->deleteTodo(todo); |
237 | ret = true; | 239 | ret = true; |
238 | } | 240 | } |
239 | } | 241 | } |
240 | deleteTransaction(incidence); | 242 | deleteTransaction(incidence); |
241 | return ret; | 243 | return ret; |
242 | } | 244 | } |
243 | 245 | ||
244 | bool Scheduler::acceptDeclineCounter(IncidenceBase *incidence,ScheduleMessage::Status status) | 246 | bool Scheduler::acceptDeclineCounter(IncidenceBase *incidence,ScheduleMessage::Status status) |
245 | { | 247 | { |
246 | deleteTransaction(incidence); | 248 | deleteTransaction(incidence); |
247 | return false; | 249 | return false; |
248 | } | 250 | } |
249 | 251 | ||
250 | //bool Scheduler::acceptFreeBusy(Incidence *incidence,ScheduleMessage::Status status) | 252 | //bool Scheduler::acceptFreeBusy(Incidence *incidence,ScheduleMessage::Status status) |
251 | //{ | 253 | //{ |
252 | // deleteTransaction(incidence); | 254 | // deleteTransaction(incidence); |
253 | // return false; | 255 | // return false; |
254 | //} | 256 | //} |
255 | 257 | ||
256 | bool Scheduler::acceptReply(IncidenceBase *incidence,ScheduleMessage::Status status, Method method) | 258 | bool Scheduler::acceptReply(IncidenceBase *incidence,ScheduleMessage::Status status, Method method) |
257 | { | 259 | { |
258 | if(incidence->type()=="FreeBusy") { | 260 | if(incidence->type()=="FreeBusy") { |
259 | return acceptFreeBusy(incidence, method); | 261 | return acceptFreeBusy(incidence, method); |
260 | } | 262 | } |
261 | bool ret = false; | 263 | bool ret = false; |
262 | Event *ev = mCalendar->event(incidence->uid()); | 264 | Event *ev = mCalendar->event(incidence->uid()); |
263 | Todo *to = mCalendar->todo(incidence->uid()); | 265 | Todo *to = mCalendar->todo(incidence->uid()); |
264 | if (ev || to) { | 266 | if (ev || to) { |
265 | //get matching attendee in calendar | 267 | //get matching attendee in calendar |
266 | kdDebug(5800) << "Scheduler::acceptTransaction match found!" << endl; | 268 | kdDebug(5800) << "Scheduler::acceptTransaction match found!" << endl; |
267 | QPtrList<Attendee> attendeesIn = incidence->attendees(); | 269 | Q3PtrList<Attendee> attendeesIn = incidence->attendees(); |
268 | QPtrList<Attendee> attendeesEv; | 270 | Q3PtrList<Attendee> attendeesEv; |
269 | if (ev) attendeesEv = ev->attendees(); | 271 | if (ev) attendeesEv = ev->attendees(); |
270 | if (to) attendeesEv = to->attendees(); | 272 | if (to) attendeesEv = to->attendees(); |
271 | Attendee *attIn; | 273 | Attendee *attIn; |
272 | Attendee *attEv; | 274 | Attendee *attEv; |
273 | for ( attIn = attendeesIn.first(); attIn; attIn = attendeesIn.next() ) { | 275 | for ( attIn = attendeesIn.first(); attIn; attIn = attendeesIn.next() ) { |
274 | for ( attEv = attendeesEv.first(); attEv; attEv = attendeesEv.next() ) { | 276 | for ( attEv = attendeesEv.first(); attEv; attEv = attendeesEv.next() ) { |
275 | if (attIn->email()==attEv->email()) { | 277 | if (attIn->email()==attEv->email()) { |
276 | //update attendee-info | 278 | //update attendee-info |
277 | kdDebug(5800) << "Scheduler::acceptTransaction update attendee" << endl; | 279 | kdDebug(5800) << "Scheduler::acceptTransaction update attendee" << endl; |
278 | attEv->setStatus(attIn->status()); | 280 | attEv->setStatus(attIn->status()); |
279 | attEv->setRSVP(false); | 281 | attEv->setRSVP(false); |
280 | // better to not update the sequence number with replys | 282 | // better to not update the sequence number with replys |
281 | //if (ev) ev->setRevision(ev->revision()+1); | 283 | //if (ev) ev->setRevision(ev->revision()+1); |
282 | //if (to) to->setRevision(to->revision()+1); | 284 | //if (to) to->setRevision(to->revision()+1); |
283 | ret = true; | 285 | ret = true; |
284 | } | 286 | } |
285 | } | 287 | } |
286 | } | 288 | } |
287 | } | 289 | } |
288 | if (ret) deleteTransaction(incidence); | 290 | if (ret) deleteTransaction(incidence); |
289 | return ret; | 291 | return ret; |
290 | } | 292 | } |
291 | 293 | ||
292 | bool Scheduler::acceptRefresh(IncidenceBase *incidence,ScheduleMessage::Status status) | 294 | bool Scheduler::acceptRefresh(IncidenceBase *incidence,ScheduleMessage::Status status) |
293 | { | 295 | { |
294 | // handled in korganizer's IncomingDialog | 296 | // handled in korganizer's IncomingDialog |
295 | deleteTransaction(incidence); | 297 | deleteTransaction(incidence); |
296 | return false; | 298 | return false; |
297 | } | 299 | } |
298 | 300 | ||
299 | bool Scheduler::acceptCounter(IncidenceBase *incidence,ScheduleMessage::Status status) | 301 | bool Scheduler::acceptCounter(IncidenceBase *incidence,ScheduleMessage::Status status) |
300 | { | 302 | { |
301 | deleteTransaction(incidence); | 303 | deleteTransaction(incidence); |
302 | return false; | 304 | return false; |
303 | } | 305 | } |
304 | 306 | ||
305 | bool Scheduler::acceptFreeBusy(IncidenceBase *incidence, Method method) | 307 | bool Scheduler::acceptFreeBusy(IncidenceBase *incidence, Method method) |
306 | { | 308 | { |
307 | FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); | 309 | FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); |
308 | 310 | ||
309 | QString freeBusyDirName = locateLocal("appdata","freebusy"); | 311 | QString freeBusyDirName = locateLocal("appdata","freebusy"); |
310 | kdDebug() << "acceptFreeBusy:: freeBusyDirName: " << freeBusyDirName << endl; | 312 | kdDebug() << "acceptFreeBusy:: freeBusyDirName: " << freeBusyDirName << endl; |
311 | 313 | ||
312 | QString from; | 314 | QString from; |
313 | if(method == Scheduler::Publish) { | 315 | if(method == Scheduler::Publish) { |
314 | from = freebusy->organizer(); | 316 | from = freebusy->organizer(); |
315 | } | 317 | } |
316 | if((method == Scheduler::Reply) && (freebusy->attendeeCount() == 1)) { | 318 | if((method == Scheduler::Reply) && (freebusy->attendeeCount() == 1)) { |
317 | Attendee *attendee = freebusy->attendees().first(); | 319 | Attendee *attendee = freebusy->attendees().first(); |
318 | from = attendee->email(); | 320 | from = attendee->email(); |
319 | } | 321 | } |
320 | 322 | ||
321 | QDir freeBusyDir(freeBusyDirName); | 323 | QDir freeBusyDir(freeBusyDirName); |
322 | if (!freeBusyDir.exists()) { | 324 | if (!freeBusyDir.exists()) { |
323 | kdDebug() << "Directory " << freeBusyDirName << " does not exist!" << endl; | 325 | kdDebug() << "Directory " << freeBusyDirName << " does not exist!" << endl; |
324 | kdDebug() << "Creating directory: " << freeBusyDirName << endl; | 326 | kdDebug() << "Creating directory: " << freeBusyDirName << endl; |
325 | 327 | ||
326 | if(!freeBusyDir.mkdir(freeBusyDirName, TRUE)) { | 328 | if(!freeBusyDir.mkdir(freeBusyDirName, TRUE)) { |
327 | kdDebug() << "Could not create directory: " << freeBusyDirName << endl; | 329 | kdDebug() << "Could not create directory: " << freeBusyDirName << endl; |
328 | return false; | 330 | return false; |
329 | } | 331 | } |
330 | } | 332 | } |
331 | 333 | ||
332 | QString filename(freeBusyDirName); | 334 | QString filename(freeBusyDirName); |
333 | filename += "/"; | 335 | filename += "/"; |
334 | filename += from; | 336 | filename += from; |
335 | filename += ".ifb"; | 337 | filename += ".ifb"; |
336 | QFile f(filename); | 338 | QFile f(filename); |
337 | 339 | ||
338 | kdDebug() << "acceptFreeBusy: filename" << filename << endl; | 340 | kdDebug() << "acceptFreeBusy: filename" << filename << endl; |
339 | 341 | ||
340 | freebusy->clearAttendees(); | 342 | freebusy->clearAttendees(); |
341 | freebusy->setOrganizer(from); | 343 | freebusy->setOrganizer(from); |
342 | 344 | ||
343 | QString messageText = mFormat->createScheduleMessage(freebusy, Publish); | 345 | QString messageText = mFormat->createScheduleMessage(freebusy, Publish); |
344 | 346 | ||
345 | if (!f.open(IO_ReadWrite)) { | 347 | if (!f.open(QIODevice::ReadWrite)) { |
346 | kdDebug() << "acceptFreeBusy: Can't open:" << filename << " for writing" << endl; | 348 | kdDebug() << "acceptFreeBusy: Can't open:" << filename << " for writing" << endl; |
347 | return false; | 349 | return false; |
348 | } | 350 | } |
349 | QTextStream t(&f); | 351 | Q3TextStream t(&f); |
350 | t << messageText; | 352 | t << messageText; |
351 | f.close(); | 353 | f.close(); |
352 | 354 | ||
353 | deleteTransaction(incidence); | 355 | deleteTransaction(incidence); |
354 | return true; | 356 | return true; |
355 | } | 357 | } |
diff --git a/libkcal/scheduler.h b/libkcal/scheduler.h index a9f43b9..357e98e 100644 --- a/libkcal/scheduler.h +++ b/libkcal/scheduler.h | |||
@@ -1,133 +1,133 @@ | |||
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 SCHEDULER_H | 20 | #ifndef SCHEDULER_H |
21 | #define SCHEDULER_H | 21 | #define SCHEDULER_H |
22 | 22 | ||
23 | // iTIP transactions base class | 23 | // iTIP transactions base class |
24 | 24 | ||
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qptrlist.h> | 26 | #include <q3ptrlist.h> |
27 | 27 | ||
28 | namespace KCal { | 28 | namespace KCal { |
29 | 29 | ||
30 | class IncidenceBase; | 30 | class IncidenceBase; |
31 | class Event; | 31 | class Event; |
32 | class Calendar; | 32 | class Calendar; |
33 | class ICalFormat; | 33 | class ICalFormat; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | This class provides an encapsulation of a scheduling message. It associates an | 36 | This class provides an encapsulation of a scheduling message. It associates an |
37 | incidence with a method and status information. This class is used by the | 37 | incidence with a method and status information. This class is used by the |
38 | Scheduler class. | 38 | Scheduler class. |
39 | 39 | ||
40 | @short A Scheduling message | 40 | @short A Scheduling message |
41 | */ | 41 | */ |
42 | class ScheduleMessage { | 42 | class ScheduleMessage { |
43 | public: | 43 | public: |
44 | /** Message status. */ | 44 | /** Message status. */ |
45 | enum Status { PublishNew, Obsolete, RequestNew, RequestUpdate, Unknown }; | 45 | enum Status { PublishNew, Obsolete, RequestNew, RequestUpdate, Unknown }; |
46 | 46 | ||
47 | /** | 47 | /** |
48 | Create a scheduling message with method as defined in Scheduler::Method | 48 | Create a scheduling message with method as defined in Scheduler::Method |
49 | and a status. | 49 | and a status. |
50 | */ | 50 | */ |
51 | ScheduleMessage(IncidenceBase *,int method,Status status); | 51 | ScheduleMessage(IncidenceBase *,int method,Status status); |
52 | ~ScheduleMessage() {}; | 52 | ~ScheduleMessage() {}; |
53 | 53 | ||
54 | /** Return event associated with this message. */ | 54 | /** Return event associated with this message. */ |
55 | IncidenceBase *event() { return mIncidence; } | 55 | IncidenceBase *event() { return mIncidence; } |
56 | /** Return iTIP method associated with this message. */ | 56 | /** Return iTIP method associated with this message. */ |
57 | int method() { return mMethod; } | 57 | int method() { return mMethod; } |
58 | /** Return status of this message. */ | 58 | /** Return status of this message. */ |
59 | Status status() { return mStatus; } | 59 | Status status() { return mStatus; } |
60 | /** Return error message if there is any. */ | 60 | /** Return error message if there is any. */ |
61 | QString error() { return mError; } | 61 | QString error() { return mError; } |
62 | 62 | ||
63 | /** Return a human-readable name for an ical message status. */ | 63 | /** Return a human-readable name for an ical message status. */ |
64 | static QString statusName(Status status); | 64 | static QString statusName(Status status); |
65 | 65 | ||
66 | private: | 66 | private: |
67 | IncidenceBase *mIncidence; | 67 | IncidenceBase *mIncidence; |
68 | int mMethod; | 68 | int mMethod; |
69 | Status mStatus; | 69 | Status mStatus; |
70 | QString mError; | 70 | QString mError; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | This class provides an encapsulation of iTIP transactions. It is an abstract | 74 | This class provides an encapsulation of iTIP transactions. It is an abstract |
75 | base class for inheritance by implementations of the iTIP scheme like iMIP or | 75 | base class for inheritance by implementations of the iTIP scheme like iMIP or |
76 | iRIP. | 76 | iRIP. |
77 | */ | 77 | */ |
78 | class Scheduler { | 78 | class Scheduler { |
79 | public: | 79 | public: |
80 | /** iTIP methods. */ | 80 | /** iTIP methods. */ |
81 | enum Method { Publish,Request,Refresh,Cancel,Add,Reply,Counter, | 81 | enum Method { Publish,Request,Refresh,Cancel,Add,Reply,Counter, |
82 | Declinecounter,NoMethod }; | 82 | Declinecounter,NoMethod }; |
83 | 83 | ||
84 | /** Create scheduler for calendar specified as argument. */ | 84 | /** Create scheduler for calendar specified as argument. */ |
85 | Scheduler(Calendar *calendar); | 85 | Scheduler(Calendar *calendar); |
86 | virtual ~Scheduler(); | 86 | virtual ~Scheduler(); |
87 | 87 | ||
88 | /** iTIP publish action */ | 88 | /** iTIP publish action */ |
89 | virtual bool publish (IncidenceBase *incidence,const QString &recipients) = 0; | 89 | virtual bool publish (IncidenceBase *incidence,const QString &recipients) = 0; |
90 | /** Perform iTIP transaction on incidence. The method is specified as the | 90 | /** Perform iTIP transaction on incidence. The method is specified as the |
91 | method argumanet and can be any valid iTIP method. */ | 91 | method argumanet and can be any valid iTIP method. */ |
92 | virtual bool performTransaction(IncidenceBase *incidence,Method method) = 0; | 92 | virtual bool performTransaction(IncidenceBase *incidence,Method method) = 0; |
93 | /** Perform iTIP transaction on incidence to specified recipient(s). The | 93 | /** Perform iTIP transaction on incidence to specified recipient(s). The |
94 | method is specified as the method argumanet and can be any valid iTIP | 94 | method is specified as the method argumanet and can be any valid iTIP |
95 | method. */ | 95 | method. */ |
96 | virtual bool performTransaction(IncidenceBase *incidence,Method method,const QString &recipients) = 0; | 96 | virtual bool performTransaction(IncidenceBase *incidence,Method method,const QString &recipients) = 0; |
97 | /** Retrieve incoming iTIP transactions */ | 97 | /** Retrieve incoming iTIP transactions */ |
98 | virtual QPtrList<ScheduleMessage> retrieveTransactions() = 0; | 98 | virtual Q3PtrList<ScheduleMessage> retrieveTransactions() = 0; |
99 | 99 | ||
100 | /** | 100 | /** |
101 | Accept transaction. The incidence argument specifies the iCal compoennt | 101 | Accept transaction. The incidence argument specifies the iCal compoennt |
102 | on which the transaction acts. The status is the result of processing a | 102 | on which the transaction acts. The status is the result of processing a |
103 | iTIP message with the current calendar and specifies the action to be | 103 | iTIP message with the current calendar and specifies the action to be |
104 | taken for this incidence. | 104 | taken for this incidence. |
105 | */ | 105 | */ |
106 | bool acceptTransaction(IncidenceBase *,Method method,ScheduleMessage::Status status); | 106 | bool acceptTransaction(IncidenceBase *,Method method,ScheduleMessage::Status status); |
107 | 107 | ||
108 | /** Return a machine-readable name for a iTIP method. */ | 108 | /** Return a machine-readable name for a iTIP method. */ |
109 | static QString methodName(Method); | 109 | static QString methodName(Method); |
110 | /** Return a translated and human-readable name for a iTIP method. */ | 110 | /** Return a translated and human-readable name for a iTIP method. */ |
111 | static QString translatedMethodName(Method); | 111 | static QString translatedMethodName(Method); |
112 | 112 | ||
113 | virtual bool deleteTransaction(IncidenceBase *incidence); | 113 | virtual bool deleteTransaction(IncidenceBase *incidence); |
114 | 114 | ||
115 | protected: | 115 | protected: |
116 | 116 | ||
117 | bool acceptPublish(IncidenceBase *,ScheduleMessage::Status status, Method method); | 117 | bool acceptPublish(IncidenceBase *,ScheduleMessage::Status status, Method method); |
118 | bool acceptRequest(IncidenceBase *,ScheduleMessage::Status status); | 118 | bool acceptRequest(IncidenceBase *,ScheduleMessage::Status status); |
119 | bool acceptAdd(IncidenceBase *,ScheduleMessage::Status status); | 119 | bool acceptAdd(IncidenceBase *,ScheduleMessage::Status status); |
120 | bool acceptCancel(IncidenceBase *,ScheduleMessage::Status status); | 120 | bool acceptCancel(IncidenceBase *,ScheduleMessage::Status status); |
121 | bool acceptDeclineCounter(IncidenceBase *,ScheduleMessage::Status status); | 121 | bool acceptDeclineCounter(IncidenceBase *,ScheduleMessage::Status status); |
122 | bool acceptReply(IncidenceBase *,ScheduleMessage::Status status, Method method); | 122 | bool acceptReply(IncidenceBase *,ScheduleMessage::Status status, Method method); |
123 | bool acceptRefresh(IncidenceBase *,ScheduleMessage::Status status); | 123 | bool acceptRefresh(IncidenceBase *,ScheduleMessage::Status status); |
124 | bool acceptCounter(IncidenceBase *,ScheduleMessage::Status status); | 124 | bool acceptCounter(IncidenceBase *,ScheduleMessage::Status status); |
125 | bool acceptFreeBusy(IncidenceBase *,Method method); | 125 | bool acceptFreeBusy(IncidenceBase *,Method method); |
126 | 126 | ||
127 | Calendar *mCalendar; | 127 | Calendar *mCalendar; |
128 | ICalFormat *mFormat; | 128 | ICalFormat *mFormat; |
129 | }; | 129 | }; |
130 | 130 | ||
131 | } | 131 | } |
132 | 132 | ||
133 | #endif // SCHEDULER_H | 133 | #endif // SCHEDULER_H |
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index 9b757f7..b8c2aa7 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -1,1012 +1,1012 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <q3ptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qclipboard.h> | 28 | #include <qclipboard.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <q3textstream.h> |
31 | #include <qtextcodec.h> | 31 | #include <qtextcodec.h> |
32 | #include <qxml.h> | 32 | #include <qxml.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | #include <klocale.h> | 36 | #include <klocale.h> |
37 | #include <kglobal.h> | 37 | #include <kglobal.h> |
38 | 38 | ||
39 | #include "calendar.h" | 39 | #include "calendar.h" |
40 | #include "alarm.h" | 40 | #include "alarm.h" |
41 | #include "recurrence.h" | 41 | #include "recurrence.h" |
42 | #include "calendarlocal.h" | 42 | #include "calendarlocal.h" |
43 | 43 | ||
44 | #include "sharpformat.h" | 44 | #include "sharpformat.h" |
45 | #include "syncdefines.h" | 45 | #include "syncdefines.h" |
46 | 46 | ||
47 | using namespace KCal; | 47 | using namespace KCal; |
48 | 48 | ||
49 | //CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY | 49 | //CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY |
50 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 50 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
51 | 51 | ||
52 | //ARSD silentalarm = 0 | 52 | //ARSD silentalarm = 0 |
53 | // 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly | 53 | // 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly |
54 | // 12 RFRQ | 54 | // 12 RFRQ |
55 | // 13 RPOS pos = 4. monday in month | 55 | // 13 RPOS pos = 4. monday in month |
56 | // 14 RDYS days: 1 mon/ 2 tue .. 64 sun | 56 | // 14 RDYS days: 1 mon/ 2 tue .. 64 sun |
57 | // 15 REND 0 = no end/ 1 = end | 57 | // 15 REND 0 = no end/ 1 = end |
58 | // 16 REDT rec end dt | 58 | // 16 REDT rec end dt |
59 | //ALSD | 59 | //ALSD |
60 | //ALED | 60 | //ALED |
61 | //MDAY | 61 | //MDAY |
62 | 62 | ||
63 | class SharpParser : public QObject | 63 | class SharpParser : public QObject |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | SharpParser( Calendar *calendar ) : mCalendar( calendar ) { | 66 | SharpParser( Calendar *calendar ) : mCalendar( calendar ) { |
67 | } | 67 | } |
68 | 68 | ||
69 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) | 69 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) |
70 | { | 70 | { |
71 | int i = 1; | 71 | int i = 1; |
72 | bool skip = true; | 72 | bool skip = true; |
73 | int max = attList.count() -2; | 73 | int max = attList.count() -2; |
74 | while ( i < max ) { | 74 | while ( i < max ) { |
75 | if ( !attList[i].isEmpty() ) { | 75 | if ( !attList[i].isEmpty() ) { |
76 | skip = false; | 76 | skip = false; |
77 | break; | 77 | break; |
78 | } | 78 | } |
79 | ++i ; | 79 | ++i ; |
80 | } | 80 | } |
81 | if ( skip ) | 81 | if ( skip ) |
82 | return false; | 82 | return false; |
83 | ulong cSum = SharpFormat::getCsum(attList ); | 83 | ulong cSum = SharpFormat::getCsum(attList ); |
84 | 84 | ||
85 | if ( qName == "Event" ) { | 85 | if ( qName == "Event" ) { |
86 | Event *event; | 86 | Event *event; |
87 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); | 87 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); |
88 | if ( event ) | 88 | if ( event ) |
89 | event = (Event*)event->clone(); | 89 | event = (Event*)event->clone(); |
90 | else | 90 | else |
91 | event = new Event; | 91 | event = new Event; |
92 | event->setID("Sharp_DTM", attList[0] ); | 92 | event->setID("Sharp_DTM", attList[0] ); |
93 | event->setCsum( "Sharp_DTM", QString::number( cSum )); | 93 | event->setCsum( "Sharp_DTM", QString::number( cSum )); |
94 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 94 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
95 | 95 | ||
96 | event->setSummary( attList[2] ); | 96 | event->setSummary( attList[2] ); |
97 | event->setLocation( attList[3] ); | 97 | event->setLocation( attList[3] ); |
98 | event->setDescription( attList[4] ); | 98 | event->setDescription( attList[4] ); |
99 | if ( attList[7] == "1" ) { | 99 | if ( attList[7] == "1" ) { |
100 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); | 100 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); |
101 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); | 101 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); |
102 | event->setFloats( true ); | 102 | event->setFloats( true ); |
103 | } else { | 103 | } else { |
104 | event->setFloats( false ); | 104 | event->setFloats( false ); |
105 | event->setDtStart( fromString( attList[5] ) ); | 105 | event->setDtStart( fromString( attList[5] ) ); |
106 | event->setDtEnd( fromString( attList[6] )); | 106 | event->setDtEnd( fromString( attList[6] )); |
107 | } | 107 | } |
108 | 108 | ||
109 | QString rtype = attList[11]; | 109 | QString rtype = attList[11]; |
110 | if ( rtype != "255" ) { | 110 | if ( rtype != "255" ) { |
111 | // qDebug("recurs "); | 111 | // qDebug("recurs "); |
112 | QDate startDate = event->dtStart().date(); | 112 | QDate startDate = event->dtStart().date(); |
113 | 113 | ||
114 | QString freqStr = attList[12]; | 114 | QString freqStr = attList[12]; |
115 | int freq = freqStr.toInt(); | 115 | int freq = freqStr.toInt(); |
116 | 116 | ||
117 | QString hasEndDateStr = attList[15] ; | 117 | QString hasEndDateStr = attList[15] ; |
118 | bool hasEndDate = hasEndDateStr == "1"; | 118 | bool hasEndDate = hasEndDateStr == "1"; |
119 | 119 | ||
120 | QString endDateStr = attList[16]; | 120 | QString endDateStr = attList[16]; |
121 | QDate endDate = fromString( endDateStr ).date(); | 121 | QDate endDate = fromString( endDateStr ).date(); |
122 | 122 | ||
123 | QString weekDaysStr = attList[14]; | 123 | QString weekDaysStr = attList[14]; |
124 | uint weekDaysNum = weekDaysStr.toInt(); | 124 | uint weekDaysNum = weekDaysStr.toInt(); |
125 | 125 | ||
126 | QBitArray weekDays( 7 ); | 126 | QBitArray weekDays( 7 ); |
127 | int i; | 127 | int i; |
128 | int bb = 1; | 128 | int bb = 1; |
129 | for( i = 1; i <= 7; ++i ) { | 129 | for( i = 1; i <= 7; ++i ) { |
130 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | 130 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); |
131 | bb = 2 << (i-1); | 131 | bb = 2 << (i-1); |
132 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | 132 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); |
133 | } | 133 | } |
134 | // qDebug("next "); | 134 | // qDebug("next "); |
135 | QString posStr = attList[13]; | 135 | QString posStr = attList[13]; |
136 | int pos = posStr.toInt(); | 136 | int pos = posStr.toInt(); |
137 | Recurrence *r = event->recurrence(); | 137 | Recurrence *r = event->recurrence(); |
138 | 138 | ||
139 | if ( rtype == "0" ) { | 139 | if ( rtype == "0" ) { |
140 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 140 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
141 | else r->setDaily( freq, -1 ); | 141 | else r->setDaily( freq, -1 ); |
142 | } else if ( rtype == "1" ) { | 142 | } else if ( rtype == "1" ) { |
143 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 143 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
144 | else r->setWeekly( freq, weekDays, -1 ); | 144 | else r->setWeekly( freq, weekDays, -1 ); |
145 | } else if ( rtype == "3" ) { | 145 | } else if ( rtype == "3" ) { |
146 | if ( hasEndDate ) | 146 | if ( hasEndDate ) |
147 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 147 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
148 | else | 148 | else |
149 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 149 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
150 | r->addMonthlyDay( startDate.day() ); | 150 | r->addMonthlyDay( startDate.day() ); |
151 | } else if ( rtype == "2" ) { | 151 | } else if ( rtype == "2" ) { |
152 | if ( hasEndDate ) | 152 | if ( hasEndDate ) |
153 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 153 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
154 | else | 154 | else |
155 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 155 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
156 | QBitArray days( 7 ); | 156 | QBitArray days( 7 ); |
157 | days.fill( false ); | 157 | days.fill( false ); |
158 | days.setBit( startDate.dayOfWeek() - 1 ); | 158 | days.setBit( startDate.dayOfWeek() - 1 ); |
159 | r->addMonthlyPos( pos, days ); | 159 | r->addMonthlyPos( pos, days ); |
160 | } else if ( rtype == "4" ) { | 160 | } else if ( rtype == "4" ) { |
161 | if ( hasEndDate ) | 161 | if ( hasEndDate ) |
162 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 162 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
163 | else | 163 | else |
164 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 164 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
165 | r->addYearlyNum( startDate.month() ); | 165 | r->addYearlyNum( startDate.month() ); |
166 | } | 166 | } |
167 | } else { | 167 | } else { |
168 | event->recurrence()->unsetRecurs(); | 168 | event->recurrence()->unsetRecurs(); |
169 | } | 169 | } |
170 | 170 | ||
171 | QString categoryList = attList[1] ; | 171 | QString categoryList = attList[1] ; |
172 | event->setCategories( categoryList ); | 172 | event->setCategories( categoryList ); |
173 | 173 | ||
174 | // strange 0 semms to mean: alarm enabled | 174 | // strange 0 semms to mean: alarm enabled |
175 | if ( attList[8] == "0" ) { | 175 | if ( attList[8] == "0" ) { |
176 | Alarm *alarm; | 176 | Alarm *alarm; |
177 | if ( event->alarms().count() > 0 ) | 177 | if ( event->alarms().count() > 0 ) |
178 | alarm = event->alarms().first(); | 178 | alarm = event->alarms().first(); |
179 | else { | 179 | else { |
180 | alarm = new Alarm( event ); | 180 | alarm = new Alarm( event ); |
181 | event->addAlarm( alarm ); | 181 | event->addAlarm( alarm ); |
182 | alarm->setType( Alarm::Audio ); | 182 | alarm->setType( Alarm::Audio ); |
183 | } | 183 | } |
184 | //alarm->setType( Alarm::Audio ); | 184 | //alarm->setType( Alarm::Audio ); |
185 | alarm->setEnabled( true ); | 185 | alarm->setEnabled( true ); |
186 | int alarmOffset = attList[9].toInt(); | 186 | int alarmOffset = attList[9].toInt(); |
187 | alarm->setStartOffset( alarmOffset * -60 ); | 187 | alarm->setStartOffset( alarmOffset * -60 ); |
188 | } else { | 188 | } else { |
189 | Alarm *alarm; | 189 | Alarm *alarm; |
190 | if ( event->alarms().count() > 0 ) { | 190 | if ( event->alarms().count() > 0 ) { |
191 | alarm = event->alarms().first(); | 191 | alarm = event->alarms().first(); |
192 | alarm->setType( Alarm::Audio ); | 192 | alarm->setType( Alarm::Audio ); |
193 | alarm->setStartOffset( -60*15 ); | 193 | alarm->setStartOffset( -60*15 ); |
194 | alarm->setEnabled( false ); | 194 | alarm->setEnabled( false ); |
195 | } | 195 | } |
196 | } | 196 | } |
197 | 197 | ||
198 | mCalendar->addEvent( event); | 198 | mCalendar->addEvent( event); |
199 | } else if ( qName == "Todo" ) { | 199 | } else if ( qName == "Todo" ) { |
200 | Todo *todo; | 200 | Todo *todo; |
201 | 201 | ||
202 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); | 202 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); |
203 | if (todo ) | 203 | if (todo ) |
204 | todo = (Todo*)todo->clone(); | 204 | todo = (Todo*)todo->clone(); |
205 | else | 205 | else |
206 | todo = new Todo; | 206 | todo = new Todo; |
207 | 207 | ||
208 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 | 208 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 |
209 | // 0 1 2 3 4 5 6 7 8 | 209 | // 0 1 2 3 4 5 6 7 8 |
210 | //1,,,,,1,4,Loch zumachen,"" | 210 | //1,,,,,1,4,Loch zumachen,"" |
211 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " | 211 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " |
212 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes | 212 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes |
213 | 213 | ||
214 | todo->setID( "Sharp_DTM", attList[0]); | 214 | todo->setID( "Sharp_DTM", attList[0]); |
215 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); | 215 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); |
216 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 216 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
217 | 217 | ||
218 | todo->setSummary( attList[7] ); | 218 | todo->setSummary( attList[7] ); |
219 | todo->setDescription( attList[8]); | 219 | todo->setDescription( attList[8]); |
220 | 220 | ||
221 | int priority = attList[6].toInt(); | 221 | int priority = attList[6].toInt(); |
222 | if ( priority == 0 ) priority = 3; | 222 | if ( priority == 0 ) priority = 3; |
223 | todo->setPriority( priority ); | 223 | todo->setPriority( priority ); |
224 | 224 | ||
225 | QString categoryList = attList[1]; | 225 | QString categoryList = attList[1]; |
226 | todo->setCategories( categoryList ); | 226 | todo->setCategories( categoryList ); |
227 | 227 | ||
228 | 228 | ||
229 | 229 | ||
230 | QString hasDateStr = attList[3]; // due | 230 | QString hasDateStr = attList[3]; // due |
231 | if ( !hasDateStr.isEmpty() ) { | 231 | if ( !hasDateStr.isEmpty() ) { |
232 | if ( hasDateStr.right(6) == "000000" ) { | 232 | if ( hasDateStr.right(6) == "000000" ) { |
233 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); | 233 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); |
234 | todo->setFloats( true ); | 234 | todo->setFloats( true ); |
235 | } | 235 | } |
236 | else { | 236 | else { |
237 | todo->setDtDue( fromString( hasDateStr ) ); | 237 | todo->setDtDue( fromString( hasDateStr ) ); |
238 | todo->setFloats( false ); | 238 | todo->setFloats( false ); |
239 | } | 239 | } |
240 | 240 | ||
241 | todo->setHasDueDate( true ); | 241 | todo->setHasDueDate( true ); |
242 | } | 242 | } |
243 | hasDateStr = attList[2];//start | 243 | hasDateStr = attList[2];//start |
244 | if ( !hasDateStr.isEmpty() ) { | 244 | if ( !hasDateStr.isEmpty() ) { |
245 | 245 | ||
246 | todo->setDtStart( fromString( hasDateStr ) ); | 246 | todo->setDtStart( fromString( hasDateStr ) ); |
247 | todo->setHasStartDate( true); | 247 | todo->setHasStartDate( true); |
248 | } else | 248 | } else |
249 | todo->setHasStartDate( false ); | 249 | todo->setHasStartDate( false ); |
250 | hasDateStr = attList[4];//completed | 250 | hasDateStr = attList[4];//completed |
251 | if ( !hasDateStr.isEmpty() ) { | 251 | if ( !hasDateStr.isEmpty() ) { |
252 | todo->setCompleted(fromString( hasDateStr ) ); | 252 | todo->setCompleted(fromString( hasDateStr ) ); |
253 | } | 253 | } |
254 | QString completedStr = attList[5]; | 254 | QString completedStr = attList[5]; |
255 | if ( completedStr == "0" ) | 255 | if ( completedStr == "0" ) |
256 | todo->setCompleted( true ); | 256 | todo->setCompleted( true ); |
257 | else { | 257 | else { |
258 | // do not change percent complete | 258 | // do not change percent complete |
259 | if ( todo->isCompleted() ) | 259 | if ( todo->isCompleted() ) |
260 | todo->setCompleted( false ); | 260 | todo->setCompleted( false ); |
261 | } | 261 | } |
262 | mCalendar->addTodo( todo ); | 262 | mCalendar->addTodo( todo ); |
263 | 263 | ||
264 | } else if ( qName == "Category" ) { | 264 | } else if ( qName == "Category" ) { |
265 | /* | 265 | /* |
266 | QString id = attributes.value( "id" ); | 266 | QString id = attributes.value( "id" ); |
267 | QString name = attributes.value( "name" ); | 267 | QString name = attributes.value( "name" ); |
268 | setCategory( id, name ); | 268 | setCategory( id, name ); |
269 | */ | 269 | */ |
270 | } | 270 | } |
271 | //qDebug("end "); | 271 | //qDebug("end "); |
272 | return true; | 272 | return true; |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | QDateTime fromString ( QString s, bool useTz = true ) { | 276 | QDateTime fromString ( QString s, bool useTz = true ) { |
277 | QDateTime dt; | 277 | QDateTime dt; |
278 | int y,m,t,h,min,sec; | 278 | int y,m,t,h,min,sec; |
279 | y = s.mid(0,4).toInt(); | 279 | y = s.mid(0,4).toInt(); |
280 | m = s.mid(4,2).toInt(); | 280 | m = s.mid(4,2).toInt(); |
281 | t = s.mid(6,2).toInt(); | 281 | t = s.mid(6,2).toInt(); |
282 | h = s.mid(9,2).toInt(); | 282 | h = s.mid(9,2).toInt(); |
283 | min = s.mid(11,2).toInt(); | 283 | min = s.mid(11,2).toInt(); |
284 | sec = s.mid(13,2).toInt(); | 284 | sec = s.mid(13,2).toInt(); |
285 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | 285 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); |
286 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 286 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
287 | if ( useTz ) | 287 | if ( useTz ) |
288 | dt = dt.addSecs ( offset*60); | 288 | dt = dt.addSecs ( offset*60); |
289 | return dt; | 289 | return dt; |
290 | 290 | ||
291 | } | 291 | } |
292 | protected: | 292 | protected: |
293 | QDateTime toDateTime( const QString &value ) | 293 | QDateTime toDateTime( const QString &value ) |
294 | { | 294 | { |
295 | QDateTime dt; | 295 | QDateTime dt; |
296 | dt.setTime_t( value.toUInt() ); | 296 | dt.setTime_t( value.toUInt() ); |
297 | 297 | ||
298 | return dt; | 298 | return dt; |
299 | } | 299 | } |
300 | 300 | ||
301 | private: | 301 | private: |
302 | Calendar *mCalendar; | 302 | Calendar *mCalendar; |
303 | }; | 303 | }; |
304 | 304 | ||
305 | 305 | ||
306 | SharpFormat::SharpFormat() | 306 | SharpFormat::SharpFormat() |
307 | { | 307 | { |
308 | 308 | ||
309 | } | 309 | } |
310 | 310 | ||
311 | SharpFormat::~SharpFormat() | 311 | SharpFormat::~SharpFormat() |
312 | { | 312 | { |
313 | } | 313 | } |
314 | ulong SharpFormat::getCsum( const QStringList & attList) | 314 | ulong SharpFormat::getCsum( const QStringList & attList) |
315 | { | 315 | { |
316 | int max = attList.count() -1; | 316 | int max = attList.count() -1; |
317 | ulong cSum = 0; | 317 | ulong cSum = 0; |
318 | int j,k,i; | 318 | int j,k,i; |
319 | int add; | 319 | int add; |
320 | for ( i = 1; i < max ; ++i ) { | 320 | for ( i = 1; i < max ; ++i ) { |
321 | QString s = attList[i]; | 321 | QString s = attList[i]; |
322 | if ( ! s.isEmpty() ){ | 322 | if ( ! s.isEmpty() ){ |
323 | j = s.length(); | 323 | j = s.length(); |
324 | for ( k = 0; k < j; ++k ) { | 324 | for ( k = 0; k < j; ++k ) { |
325 | int mul = k +1; | 325 | int mul = k +1; |
326 | add = s[k].unicode (); | 326 | add = s[k].unicode (); |
327 | if ( k < 16 ) | 327 | if ( k < 16 ) |
328 | mul = mul * mul; | 328 | mul = mul * mul; |
329 | add = add * mul *i*i*i; | 329 | add = add * mul *i*i*i; |
330 | cSum += add; | 330 | cSum += add; |
331 | } | 331 | } |
332 | } | 332 | } |
333 | } | 333 | } |
334 | return cSum; | 334 | return cSum; |
335 | 335 | ||
336 | } | 336 | } |
337 | #include <stdlib.h> | 337 | #include <stdlib.h> |
338 | #define DEBUGMODE false | 338 | #define DEBUGMODE false |
339 | //#define DEBUGMODE true | 339 | //#define DEBUGMODE true |
340 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) | 340 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) |
341 | { | 341 | { |
342 | 342 | ||
343 | 343 | ||
344 | bool debug = DEBUGMODE; | 344 | bool debug = DEBUGMODE; |
345 | QString text; | 345 | QString text; |
346 | QString codec = "utf8"; | 346 | QString codec = "utf8"; |
347 | QLabel status ( i18n("Reading events ..."), 0 ); | 347 | QLabel status ( i18n("Reading events ..."), 0 ); |
348 | 348 | ||
349 | int w = status.sizeHint().width()+20 ; | 349 | int w = status.sizeHint().width()+20 ; |
350 | if ( w < 200 ) w = 200; | 350 | if ( w < 200 ) w = 200; |
351 | int h = status.sizeHint().height()+20 ; | 351 | int h = status.sizeHint().height()+20 ; |
352 | int dw = QApplication::desktop()->width(); | 352 | int dw = QApplication::desktop()->width(); |
353 | int dh = QApplication::desktop()->height(); | 353 | int dh = QApplication::desktop()->height(); |
354 | status.setCaption(i18n("Reading DTM Data") ); | 354 | status.setCaption(i18n("Reading DTM Data") ); |
355 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 355 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
356 | status.show(); | 356 | status.show(); |
357 | status.raise(); | 357 | status.raise(); |
358 | qApp->processEvents(); | 358 | qApp->processEvents(); |
359 | QString fileName; | 359 | QString fileName; |
360 | if ( ! debug ) { | 360 | if ( ! debug ) { |
361 | fileName = "/tmp/kopitempout"; | 361 | fileName = "/tmp/kopitempout"; |
362 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; | 362 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; |
363 | system ( command.latin1() ); | 363 | system ( command.latin1() ); |
364 | } else { | 364 | } else { |
365 | fileName = "/tmp/events.txt"; | 365 | fileName = "/tmp/events.txt"; |
366 | 366 | ||
367 | } | 367 | } |
368 | QFile file( fileName ); | 368 | QFile file( fileName ); |
369 | if (!file.open( IO_ReadOnly ) ) { | 369 | if (!file.open( QIODevice::ReadOnly ) ) { |
370 | return false; | 370 | return false; |
371 | 371 | ||
372 | } | 372 | } |
373 | QTextStream ts( &file ); | 373 | Q3TextStream ts( &file ); |
374 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 374 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
375 | text = ts.read(); | 375 | text = ts.read(); |
376 | file.close(); | 376 | file.close(); |
377 | status.setText( i18n("Processing events ...") ); | 377 | status.setText( i18n("Processing events ...") ); |
378 | status.raise(); | 378 | status.raise(); |
379 | qApp->processEvents(); | 379 | qApp->processEvents(); |
380 | fromString2Cal( calendar, existngCal, text, "Event" ); | 380 | fromString2Cal( calendar, existngCal, text, "Event" ); |
381 | status.setText( i18n("Reading todos ...") ); | 381 | status.setText( i18n("Reading todos ...") ); |
382 | qApp->processEvents(); | 382 | qApp->processEvents(); |
383 | if ( ! debug ) { | 383 | if ( ! debug ) { |
384 | fileName = "/tmp/kopitempout"; | 384 | fileName = "/tmp/kopitempout"; |
385 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; | 385 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; |
386 | system ( command.latin1() ); | 386 | system ( command.latin1() ); |
387 | } else { | 387 | } else { |
388 | fileName = "/tmp/todo.txt"; | 388 | fileName = "/tmp/todo.txt"; |
389 | } | 389 | } |
390 | file.setName( fileName ); | 390 | file.setName( fileName ); |
391 | if (!file.open( IO_ReadOnly ) ) { | 391 | if (!file.open( QIODevice::ReadOnly ) ) { |
392 | return false; | 392 | return false; |
393 | 393 | ||
394 | } | 394 | } |
395 | ts.setDevice( &file ); | 395 | ts.setDevice( &file ); |
396 | text = ts.read(); | 396 | text = ts.read(); |
397 | file.close(); | 397 | file.close(); |
398 | 398 | ||
399 | status.setText( i18n("Processing todos ...") ); | 399 | status.setText( i18n("Processing todos ...") ); |
400 | status.raise(); | 400 | status.raise(); |
401 | qApp->processEvents(); | 401 | qApp->processEvents(); |
402 | fromString2Cal( calendar, existngCal, text, "Todo" ); | 402 | fromString2Cal( calendar, existngCal, text, "Todo" ); |
403 | return true; | 403 | return true; |
404 | } | 404 | } |
405 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) | 405 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) |
406 | { | 406 | { |
407 | int retval = -1; | 407 | int retval = -1; |
408 | QStringList templist; | 408 | QStringList templist; |
409 | QString tempString; | 409 | QString tempString; |
410 | int start = 0; | 410 | int start = 0; |
411 | int len = answer.length(); | 411 | int len = answer.length(); |
412 | int end = answer.find ("\n",start)+1; | 412 | int end = answer.find ("\n",start)+1; |
413 | bool ok = true; | 413 | bool ok = true; |
414 | start = end; | 414 | start = end; |
415 | int ccc = 0; | 415 | int ccc = 0; |
416 | while ( start > 0 ) { | 416 | while ( start > 0 ) { |
417 | templist.clear(); | 417 | templist.clear(); |
418 | ok = true; | 418 | ok = true; |
419 | int loopCount = 0; | 419 | int loopCount = 0; |
420 | while ( ok ) { | 420 | while ( ok ) { |
421 | ++loopCount; | 421 | ++loopCount; |
422 | if ( loopCount > 25 ) { | 422 | if ( loopCount > 25 ) { |
423 | qDebug("KO: Error in while loop"); | 423 | qDebug("KO: Error in while loop"); |
424 | ok = false; | 424 | ok = false; |
425 | start = 0; | 425 | start = 0; |
426 | break; | 426 | break; |
427 | } | 427 | } |
428 | if ( ok ) | 428 | if ( ok ) |
429 | tempString = getPart( answer, ok, start ); | 429 | tempString = getPart( answer, ok, start ); |
430 | if ( start >= len || start == 0 ) { | 430 | if ( start >= len || start == 0 ) { |
431 | start = 0; | 431 | start = 0; |
432 | ok = false; | 432 | ok = false; |
433 | } | 433 | } |
434 | if ( tempString.right(1) =="\n" ) | 434 | if ( tempString.right(1) =="\n" ) |
435 | tempString = tempString.left( tempString.length()-1); | 435 | tempString = tempString.left( tempString.length()-1); |
436 | 436 | ||
437 | templist.append( tempString ); | 437 | templist.append( tempString ); |
438 | } | 438 | } |
439 | ++ccc; | 439 | ++ccc; |
440 | if ( ccc == 2 && loopCount < 25 ) { | 440 | if ( ccc == 2 && loopCount < 25 ) { |
441 | start = 0; | 441 | start = 0; |
442 | bool ok; | 442 | bool ok; |
443 | int newnum = templist[0].toInt( &ok ); | 443 | int newnum = templist[0].toInt( &ok ); |
444 | if ( ok && newnum > 0) { | 444 | if ( ok && newnum > 0) { |
445 | retval = newnum; | 445 | retval = newnum; |
446 | inc->setID( "Sharp_DTM",templist[0] ); | 446 | inc->setID( "Sharp_DTM",templist[0] ); |
447 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); | 447 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); |
448 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 448 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
449 | } | 449 | } |
450 | if ( ok && newnum == -1 ) { | 450 | if ( ok && newnum == -1 ) { |
451 | qDebug("Error writing back %s ", inc->summary().latin1()); | 451 | qDebug("Error writing back %s ", inc->summary().latin1()); |
452 | } | 452 | } |
453 | } | 453 | } |
454 | } | 454 | } |
455 | //qDebug("getNumFromRecord returning : %d ", retval); | 455 | //qDebug("getNumFromRecord returning : %d ", retval); |
456 | return retval; | 456 | return retval; |
457 | } | 457 | } |
458 | bool SharpFormat::save( Calendar *calendar) | 458 | bool SharpFormat::save( Calendar *calendar) |
459 | { | 459 | { |
460 | 460 | ||
461 | QLabel status ( i18n("Processing/adding events ..."), 0 ); | 461 | QLabel status ( i18n("Processing/adding events ..."), 0 ); |
462 | int w = status.sizeHint().width()+20 ; | 462 | int w = status.sizeHint().width()+20 ; |
463 | if ( w < 200 ) w = 200; | 463 | if ( w < 200 ) w = 200; |
464 | int h = status.sizeHint().height()+20 ; | 464 | int h = status.sizeHint().height()+20 ; |
465 | int dw = QApplication::desktop()->width(); | 465 | int dw = QApplication::desktop()->width(); |
466 | int dh = QApplication::desktop()->height(); | 466 | int dh = QApplication::desktop()->height(); |
467 | status.setCaption(i18n("Writing DTM Data") ); | 467 | status.setCaption(i18n("Writing DTM Data") ); |
468 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 468 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
469 | status.show(); | 469 | status.show(); |
470 | status.raise(); | 470 | status.raise(); |
471 | qApp->processEvents(); | 471 | qApp->processEvents(); |
472 | bool debug = DEBUGMODE; | 472 | bool debug = DEBUGMODE; |
473 | QString codec = "utf8"; | 473 | QString codec = "utf8"; |
474 | QString answer; | 474 | QString answer; |
475 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; | 475 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; |
476 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; | 476 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; |
477 | QString command; | 477 | QString command; |
478 | QPtrList<Event> er = calendar->rawEvents(); | 478 | Q3PtrList<Event> er = calendar->rawEvents(); |
479 | Event* ev = er.first(); | 479 | Event* ev = er.first(); |
480 | QString fileName = "/tmp/kopitempout"; | 480 | QString fileName = "/tmp/kopitempout"; |
481 | int i = 0; | 481 | int i = 0; |
482 | QString changeString = ePrefix; | 482 | QString changeString = ePrefix; |
483 | QString deleteString = ePrefix; | 483 | QString deleteString = ePrefix; |
484 | bool deleteEnt = false; | 484 | bool deleteEnt = false; |
485 | bool changeEnt = false; | 485 | bool changeEnt = false; |
486 | QString message = i18n("Processing event # "); | 486 | QString message = i18n("Processing event # "); |
487 | int procCount = 0; | 487 | int procCount = 0; |
488 | while ( ev ) { | 488 | while ( ev ) { |
489 | //qDebug("i %d ", ++i); | 489 | //qDebug("i %d ", ++i); |
490 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 490 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
491 | status.setText ( message + QString::number ( ++procCount ) ); | 491 | status.setText ( message + QString::number ( ++procCount ) ); |
492 | qApp->processEvents(); | 492 | qApp->processEvents(); |
493 | QString eString = getEventString( ev ); | 493 | QString eString = getEventString( ev ); |
494 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 494 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
495 | // deleting empty strings does not work. | 495 | // deleting empty strings does not work. |
496 | // we write first and x and then delete the record with the x | 496 | // we write first and x and then delete the record with the x |
497 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 497 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
498 | changeString += eString + "\n"; | 498 | changeString += eString + "\n"; |
499 | deleteString += eString + "\n"; | 499 | deleteString += eString + "\n"; |
500 | deleteEnt = true; | 500 | deleteEnt = true; |
501 | changeEnt = true; | 501 | changeEnt = true; |
502 | } | 502 | } |
503 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new | 503 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new |
504 | QString fileNameIn = "/tmp/kopitempin"; | 504 | QString fileNameIn = "/tmp/kopitempin"; |
505 | QFile fileIn( fileNameIn ); | 505 | QFile fileIn( fileNameIn ); |
506 | if (!fileIn.open( IO_WriteOnly ) ) { | 506 | if (!fileIn.open( QIODevice::WriteOnly ) ) { |
507 | return false; | 507 | return false; |
508 | } | 508 | } |
509 | QTextStream tsIn( &fileIn ); | 509 | Q3TextStream tsIn( &fileIn ); |
510 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 510 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
511 | tsIn << ePrefix << eString ; | 511 | tsIn << ePrefix << eString ; |
512 | fileIn.close(); | 512 | fileIn.close(); |
513 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 513 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
514 | command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; | 514 | command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; |
515 | //qDebug("command ++++++++ "); | 515 | //qDebug("command ++++++++ "); |
516 | //qDebug("%s ",command.latin1()); | 516 | //qDebug("%s ",command.latin1()); |
517 | //qDebug("command -------- "); | 517 | //qDebug("command -------- "); |
518 | system ( command.utf8() ); | 518 | system ( command.utf8() ); |
519 | QFile file( fileName ); | 519 | QFile file( fileName ); |
520 | if (!file.open( IO_ReadOnly ) ) { | 520 | if (!file.open( QIODevice::ReadOnly ) ) { |
521 | return false; | 521 | return false; |
522 | 522 | ||
523 | } | 523 | } |
524 | QTextStream ts( &file ); | 524 | Q3TextStream ts( &file ); |
525 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 525 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
526 | answer = ts.read(); | 526 | answer = ts.read(); |
527 | file.close(); | 527 | file.close(); |
528 | //qDebug("answer \n%s ", answer.latin1()); | 528 | //qDebug("answer \n%s ", answer.latin1()); |
529 | getNumFromRecord( answer, ev ) ; | 529 | getNumFromRecord( answer, ev ) ; |
530 | 530 | ||
531 | } | 531 | } |
532 | else { // change existing | 532 | else { // change existing |
533 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); | 533 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); |
534 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 534 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
535 | changeString += eString + "\n"; | 535 | changeString += eString + "\n"; |
536 | changeEnt = true; | 536 | changeEnt = true; |
537 | 537 | ||
538 | } | 538 | } |
539 | } | 539 | } |
540 | ev = er.next(); | 540 | ev = er.next(); |
541 | } | 541 | } |
542 | status.setText ( i18n("Changing events ...") ); | 542 | status.setText ( i18n("Changing events ...") ); |
543 | qApp->processEvents(); | 543 | qApp->processEvents(); |
544 | //qDebug("changing... "); | 544 | //qDebug("changing... "); |
545 | if ( changeEnt ) { | 545 | if ( changeEnt ) { |
546 | QFile file( fileName ); | 546 | QFile file( fileName ); |
547 | if (!file.open( IO_WriteOnly ) ) { | 547 | if (!file.open( QIODevice::WriteOnly ) ) { |
548 | return false; | 548 | return false; |
549 | 549 | ||
550 | } | 550 | } |
551 | QTextStream ts( &file ); | 551 | Q3TextStream ts( &file ); |
552 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 552 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
553 | ts << changeString ; | 553 | ts << changeString ; |
554 | file.close(); | 554 | file.close(); |
555 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; | 555 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; |
556 | system ( command.latin1() ); | 556 | system ( command.latin1() ); |
557 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 557 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
558 | 558 | ||
559 | } | 559 | } |
560 | status.setText ( i18n("Deleting events ...") ); | 560 | status.setText ( i18n("Deleting events ...") ); |
561 | qApp->processEvents(); | 561 | qApp->processEvents(); |
562 | //qDebug("deleting... "); | 562 | //qDebug("deleting... "); |
563 | if ( deleteEnt ) { | 563 | if ( deleteEnt ) { |
564 | QFile file( fileName ); | 564 | QFile file( fileName ); |
565 | if (!file.open( IO_WriteOnly ) ) { | 565 | if (!file.open( QIODevice::WriteOnly ) ) { |
566 | return false; | 566 | return false; |
567 | 567 | ||
568 | } | 568 | } |
569 | QTextStream ts( &file ); | 569 | Q3TextStream ts( &file ); |
570 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 570 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
571 | ts << deleteString; | 571 | ts << deleteString; |
572 | file.close(); | 572 | file.close(); |
573 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; | 573 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; |
574 | system ( command.latin1() ); | 574 | system ( command.latin1() ); |
575 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 575 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
576 | } | 576 | } |
577 | 577 | ||
578 | 578 | ||
579 | changeString = tPrefix; | 579 | changeString = tPrefix; |
580 | deleteString = tPrefix; | 580 | deleteString = tPrefix; |
581 | status.setText ( i18n("Processing todos ...") ); | 581 | status.setText ( i18n("Processing todos ...") ); |
582 | qApp->processEvents(); | 582 | qApp->processEvents(); |
583 | QPtrList<Todo> tl = calendar->rawTodos(); | 583 | Q3PtrList<Todo> tl = calendar->rawTodos(); |
584 | Todo* to = tl.first(); | 584 | Todo* to = tl.first(); |
585 | i = 0; | 585 | i = 0; |
586 | message = i18n("Processing todo # "); | 586 | message = i18n("Processing todo # "); |
587 | procCount = 0; | 587 | procCount = 0; |
588 | while ( to ) { | 588 | while ( to ) { |
589 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 589 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
590 | status.setText ( message + QString::number ( ++procCount ) ); | 590 | status.setText ( message + QString::number ( ++procCount ) ); |
591 | qApp->processEvents(); | 591 | qApp->processEvents(); |
592 | QString eString = getTodoString( to ); | 592 | QString eString = getTodoString( to ); |
593 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 593 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
594 | // deleting empty strings does not work. | 594 | // deleting empty strings does not work. |
595 | // we write first and x and then delete the record with the x | 595 | // we write first and x and then delete the record with the x |
596 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 596 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
597 | changeString += eString + "\n"; | 597 | changeString += eString + "\n"; |
598 | deleteString += eString + "\n"; | 598 | deleteString += eString + "\n"; |
599 | deleteEnt = true; | 599 | deleteEnt = true; |
600 | changeEnt = true; | 600 | changeEnt = true; |
601 | } | 601 | } |
602 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new | 602 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new |
603 | 603 | ||
604 | 604 | ||
605 | 605 | ||
606 | QString fileNameIn = "/tmp/kopitempin"; | 606 | QString fileNameIn = "/tmp/kopitempin"; |
607 | QFile fileIn( fileNameIn ); | 607 | QFile fileIn( fileNameIn ); |
608 | if (!fileIn.open( IO_WriteOnly ) ) { | 608 | if (!fileIn.open( QIODevice::WriteOnly ) ) { |
609 | return false; | 609 | return false; |
610 | } | 610 | } |
611 | QTextStream tsIn( &fileIn ); | 611 | Q3TextStream tsIn( &fileIn ); |
612 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 612 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
613 | tsIn << tPrefix << eString ; | 613 | tsIn << tPrefix << eString ; |
614 | fileIn.close(); | 614 | fileIn.close(); |
615 | command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName; | 615 | command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName; |
616 | system ( command.utf8() ); | 616 | system ( command.utf8() ); |
617 | QFile file( fileName ); | 617 | QFile file( fileName ); |
618 | if (!file.open( IO_ReadOnly ) ) { | 618 | if (!file.open( QIODevice::ReadOnly ) ) { |
619 | return false; | 619 | return false; |
620 | } | 620 | } |
621 | QTextStream ts( &file ); | 621 | Q3TextStream ts( &file ); |
622 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 622 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
623 | answer = ts.read(); | 623 | answer = ts.read(); |
624 | file.close(); | 624 | file.close(); |
625 | //qDebug("answer \n%s ", answer.latin1()); | 625 | //qDebug("answer \n%s ", answer.latin1()); |
626 | getNumFromRecord( answer, to ) ; | 626 | getNumFromRecord( answer, to ) ; |
627 | 627 | ||
628 | } | 628 | } |
629 | else { // change existing | 629 | else { // change existing |
630 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); | 630 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); |
631 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 631 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
632 | changeString += eString + "\n"; | 632 | changeString += eString + "\n"; |
633 | changeEnt = true; | 633 | changeEnt = true; |
634 | 634 | ||
635 | } | 635 | } |
636 | } | 636 | } |
637 | 637 | ||
638 | to = tl.next(); | 638 | to = tl.next(); |
639 | } | 639 | } |
640 | status.setText ( i18n("Changing todos ...") ); | 640 | status.setText ( i18n("Changing todos ...") ); |
641 | qApp->processEvents(); | 641 | qApp->processEvents(); |
642 | //qDebug("changing... "); | 642 | //qDebug("changing... "); |
643 | if ( changeEnt ) { | 643 | if ( changeEnt ) { |
644 | QFile file( fileName ); | 644 | QFile file( fileName ); |
645 | if (!file.open( IO_WriteOnly ) ) { | 645 | if (!file.open( QIODevice::WriteOnly ) ) { |
646 | return false; | 646 | return false; |
647 | 647 | ||
648 | } | 648 | } |
649 | QTextStream ts( &file ); | 649 | Q3TextStream ts( &file ); |
650 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 650 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
651 | ts << changeString ; | 651 | ts << changeString ; |
652 | file.close(); | 652 | file.close(); |
653 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; | 653 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; |
654 | system ( command.latin1() ); | 654 | system ( command.latin1() ); |
655 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 655 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
656 | 656 | ||
657 | } | 657 | } |
658 | status.setText ( i18n("Deleting todos ...") ); | 658 | status.setText ( i18n("Deleting todos ...") ); |
659 | qApp->processEvents(); | 659 | qApp->processEvents(); |
660 | //qDebug("deleting... "); | 660 | //qDebug("deleting... "); |
661 | if ( deleteEnt ) { | 661 | if ( deleteEnt ) { |
662 | QFile file( fileName ); | 662 | QFile file( fileName ); |
663 | if (!file.open( IO_WriteOnly ) ) { | 663 | if (!file.open( QIODevice::WriteOnly ) ) { |
664 | return false; | 664 | return false; |
665 | 665 | ||
666 | } | 666 | } |
667 | QTextStream ts( &file ); | 667 | Q3TextStream ts( &file ); |
668 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 668 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
669 | ts << deleteString; | 669 | ts << deleteString; |
670 | file.close(); | 670 | file.close(); |
671 | command = "db2file todo -d -c " + codec+ " < "+ fileName; | 671 | command = "db2file todo -d -c " + codec+ " < "+ fileName; |
672 | system ( command.latin1() ); | 672 | system ( command.latin1() ); |
673 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 673 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
674 | } | 674 | } |
675 | 675 | ||
676 | return true; | 676 | return true; |
677 | } | 677 | } |
678 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) | 678 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) |
679 | { | 679 | { |
680 | QString datestr; | 680 | QString datestr; |
681 | QString timestr; | 681 | QString timestr; |
682 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 682 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
683 | QDateTime dt; | 683 | QDateTime dt; |
684 | if (useTZ) | 684 | if (useTZ) |
685 | dt = dti.addSecs ( -(offset*60)); | 685 | dt = dti.addSecs ( -(offset*60)); |
686 | else | 686 | else |
687 | dt = dti; | 687 | dt = dti; |
688 | if(dt.date().isValid()){ | 688 | if(dt.date().isValid()){ |
689 | const QDate& date = dt.date(); | 689 | const QDate& date = dt.date(); |
690 | datestr.sprintf("%04d%02d%02d", | 690 | datestr.sprintf("%04d%02d%02d", |
691 | date.year(), date.month(), date.day()); | 691 | date.year(), date.month(), date.day()); |
692 | } | 692 | } |
693 | if(dt.time().isValid()){ | 693 | if(dt.time().isValid()){ |
694 | const QTime& time = dt.time(); | 694 | const QTime& time = dt.time(); |
695 | timestr.sprintf("T%02d%02d%02d", | 695 | timestr.sprintf("T%02d%02d%02d", |
696 | time.hour(), time.minute(), time.second()); | 696 | time.hour(), time.minute(), time.second()); |
697 | } | 697 | } |
698 | return datestr + timestr; | 698 | return datestr + timestr; |
699 | } | 699 | } |
700 | QString SharpFormat::getEventString( Event* event ) | 700 | QString SharpFormat::getEventString( Event* event ) |
701 | { | 701 | { |
702 | QStringList list; | 702 | QStringList list; |
703 | list.append( event->getID("Sharp_DTM") ); | 703 | list.append( event->getID("Sharp_DTM") ); |
704 | list.append( event->categories().join(",") ); | 704 | list.append( event->categories().join(",") ); |
705 | if ( !event->summary().isEmpty() ) | 705 | if ( !event->summary().isEmpty() ) |
706 | list.append( event->summary() ); | 706 | list.append( event->summary() ); |
707 | else | 707 | else |
708 | list.append("" ); | 708 | list.append("" ); |
709 | if ( !event->location().isEmpty() ) | 709 | if ( !event->location().isEmpty() ) |
710 | list.append( event->location() ); | 710 | list.append( event->location() ); |
711 | else | 711 | else |
712 | list.append("" ); | 712 | list.append("" ); |
713 | if ( !event->description().isEmpty() ) | 713 | if ( !event->description().isEmpty() ) |
714 | list.append( event->description() ); | 714 | list.append( event->description() ); |
715 | else | 715 | else |
716 | list.append( "" ); | 716 | list.append( "" ); |
717 | if ( event->doesFloat () ) { | 717 | if ( event->doesFloat () ) { |
718 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | 718 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); |
719 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | 719 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 |
720 | list.append( "1" ); | 720 | list.append( "1" ); |
721 | 721 | ||
722 | } | 722 | } |
723 | else { | 723 | else { |
724 | list.append( dtToString( event->dtStart()) ); | 724 | list.append( dtToString( event->dtStart()) ); |
725 | list.append( dtToString( event->dtEnd()) ); //6 | 725 | list.append( dtToString( event->dtEnd()) ); //6 |
726 | list.append( "0" ); | 726 | list.append( "0" ); |
727 | } | 727 | } |
728 | bool noAlarm = true; | 728 | bool noAlarm = true; |
729 | if ( event->alarms().count() > 0 ) { | 729 | if ( event->alarms().count() > 0 ) { |
730 | Alarm * al = event->alarms().first(); | 730 | Alarm * al = event->alarms().first(); |
731 | if ( al->enabled() ) { | 731 | if ( al->enabled() ) { |
732 | noAlarm = false; | 732 | noAlarm = false; |
733 | list.append( "0" ); // yes, 0 == alarm | 733 | list.append( "0" ); // yes, 0 == alarm |
734 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); | 734 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); |
735 | if ( al->type() == Alarm::Audio ) | 735 | if ( al->type() == Alarm::Audio ) |
736 | list.append( "1" ); // type audio | 736 | list.append( "1" ); // type audio |
737 | else | 737 | else |
738 | list.append( "0" ); // type silent | 738 | list.append( "0" ); // type silent |
739 | } | 739 | } |
740 | } | 740 | } |
741 | if ( noAlarm ) { | 741 | if ( noAlarm ) { |
742 | list.append( "1" ); // yes, 1 == no alarm | 742 | list.append( "1" ); // yes, 1 == no alarm |
743 | list.append( "0" ); // no alarm offset | 743 | list.append( "0" ); // no alarm offset |
744 | list.append( "1" ); // type | 744 | list.append( "1" ); // type |
745 | } | 745 | } |
746 | // next is: 11 | 746 | // next is: 11 |
747 | // next is: 11-16 are recurrence | 747 | // next is: 11-16 are recurrence |
748 | Recurrence* rec = event->recurrence(); | 748 | Recurrence* rec = event->recurrence(); |
749 | 749 | ||
750 | bool writeEndDate = false; | 750 | bool writeEndDate = false; |
751 | switch ( rec->doesRecur() ) | 751 | switch ( rec->doesRecur() ) |
752 | { | 752 | { |
753 | case Recurrence::rDaily: // 0 | 753 | case Recurrence::rDaily: // 0 |
754 | list.append( "0" ); | 754 | list.append( "0" ); |
755 | list.append( QString::number( rec->frequency() ));//12 | 755 | list.append( QString::number( rec->frequency() ));//12 |
756 | list.append( "0" ); | 756 | list.append( "0" ); |
757 | list.append( "0" ); | 757 | list.append( "0" ); |
758 | writeEndDate = true; | 758 | writeEndDate = true; |
759 | break; | 759 | break; |
760 | case Recurrence::rWeekly:// 1 | 760 | case Recurrence::rWeekly:// 1 |
761 | list.append( "1" ); | 761 | list.append( "1" ); |
762 | list.append( QString::number( rec->frequency()) );//12 | 762 | list.append( QString::number( rec->frequency()) );//12 |
763 | list.append( "0" ); | 763 | list.append( "0" ); |
764 | { | 764 | { |
765 | int days = 0; | 765 | int days = 0; |
766 | QBitArray weekDays = rec->days(); | 766 | QBitArray weekDays = rec->days(); |
767 | int i; | 767 | int i; |
768 | for( i = 1; i <= 7; ++i ) { | 768 | for( i = 1; i <= 7; ++i ) { |
769 | if ( weekDays[i-1] ) { | 769 | if ( weekDays[i-1] ) { |
770 | days += 1 << (i-1); | 770 | days += 1 << (i-1); |
771 | } | 771 | } |
772 | } | 772 | } |
773 | list.append( QString::number( days ) ); | 773 | list.append( QString::number( days ) ); |
774 | } | 774 | } |
775 | //pending weekdays | 775 | //pending weekdays |
776 | writeEndDate = true; | 776 | writeEndDate = true; |
777 | 777 | ||
778 | break; | 778 | break; |
779 | case Recurrence::rMonthlyPos:// 2 | 779 | case Recurrence::rMonthlyPos:// 2 |
780 | list.append( "2" ); | 780 | list.append( "2" ); |
781 | list.append( QString::number( rec->frequency()) );//12 | 781 | list.append( QString::number( rec->frequency()) );//12 |
782 | 782 | ||
783 | writeEndDate = true; | 783 | writeEndDate = true; |
784 | { | 784 | { |
785 | int count = 1; | 785 | int count = 1; |
786 | QPtrList<Recurrence::rMonthPos> rmp; | 786 | Q3PtrList<Recurrence::rMonthPos> rmp; |
787 | rmp = rec->monthPositions(); | 787 | rmp = rec->monthPositions(); |
788 | if ( rmp.first()->negative ) | 788 | if ( rmp.first()->negative ) |
789 | count = 5 - rmp.first()->rPos - 1; | 789 | count = 5 - rmp.first()->rPos - 1; |
790 | else | 790 | else |
791 | count = rmp.first()->rPos - 1; | 791 | count = rmp.first()->rPos - 1; |
792 | list.append( QString::number( count ) ); | 792 | list.append( QString::number( count ) ); |
793 | 793 | ||
794 | } | 794 | } |
795 | 795 | ||
796 | list.append( "0" ); | 796 | list.append( "0" ); |
797 | break; | 797 | break; |
798 | case Recurrence::rMonthlyDay:// 3 | 798 | case Recurrence::rMonthlyDay:// 3 |
799 | list.append( "3" ); | 799 | list.append( "3" ); |
800 | list.append( QString::number( rec->frequency()) );//12 | 800 | list.append( QString::number( rec->frequency()) );//12 |
801 | list.append( "0" ); | 801 | list.append( "0" ); |
802 | list.append( "0" ); | 802 | list.append( "0" ); |
803 | writeEndDate = true; | 803 | writeEndDate = true; |
804 | break; | 804 | break; |
805 | case Recurrence::rYearlyMonth://4 | 805 | case Recurrence::rYearlyMonth://4 |
806 | list.append( "4" ); | 806 | list.append( "4" ); |
807 | list.append( QString::number( rec->frequency()) );//12 | 807 | list.append( QString::number( rec->frequency()) );//12 |
808 | list.append( "0" ); | 808 | list.append( "0" ); |
809 | list.append( "0" ); | 809 | list.append( "0" ); |
810 | writeEndDate = true; | 810 | writeEndDate = true; |
811 | break; | 811 | break; |
812 | 812 | ||
813 | default: | 813 | default: |
814 | list.append( "255" ); | 814 | list.append( "255" ); |
815 | list.append( QString() ); | 815 | list.append( QString() ); |
816 | list.append( "0" ); | 816 | list.append( "0" ); |
817 | list.append( QString() ); | 817 | list.append( QString() ); |
818 | list.append( "0" ); | 818 | list.append( "0" ); |
819 | list.append( "20991231T000000" ); | 819 | list.append( "20991231T000000" ); |
820 | break; | 820 | break; |
821 | } | 821 | } |
822 | if ( writeEndDate ) { | 822 | if ( writeEndDate ) { |
823 | 823 | ||
824 | if ( rec->endDate().isValid() ) { // 15 + 16 | 824 | if ( rec->endDate().isValid() ) { // 15 + 16 |
825 | list.append( "1" ); | 825 | list.append( "1" ); |
826 | list.append( dtToString( rec->endDate(), false ) ); | 826 | list.append( dtToString( rec->endDate(), false ) ); |
827 | } else { | 827 | } else { |
828 | list.append( "0" ); | 828 | list.append( "0" ); |
829 | list.append( "20991231T000000" ); | 829 | list.append( "20991231T000000" ); |
830 | } | 830 | } |
831 | 831 | ||
832 | } | 832 | } |
833 | if ( event->doesFloat () ) { | 833 | if ( event->doesFloat () ) { |
834 | list.append( dtToString( event->dtStart(), false ).left( 8 )); | 834 | list.append( dtToString( event->dtStart(), false ).left( 8 )); |
835 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 | 835 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 |
836 | 836 | ||
837 | } | 837 | } |
838 | else { | 838 | else { |
839 | list.append( QString() ); | 839 | list.append( QString() ); |
840 | list.append( QString() ); | 840 | list.append( QString() ); |
841 | 841 | ||
842 | } | 842 | } |
843 | if (event->dtStart().date() == event->dtEnd().date() ) | 843 | if (event->dtStart().date() == event->dtEnd().date() ) |
844 | list.append( "0" ); | 844 | list.append( "0" ); |
845 | else | 845 | else |
846 | list.append( "1" ); | 846 | list.append( "1" ); |
847 | 847 | ||
848 | 848 | ||
849 | for(QStringList::Iterator it=list.begin(); | 849 | for(QStringList::Iterator it=list.begin(); |
850 | it!=list.end(); ++it){ | 850 | it!=list.end(); ++it){ |
851 | QString& s = (*it); | 851 | QString& s = (*it); |
852 | s.replace(QRegExp("\""), "\"\""); | 852 | s.replace(QRegExp("\""), "\"\""); |
853 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | 853 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ |
854 | s.prepend('\"'); | 854 | s.prepend('\"'); |
855 | s.append('\"'); | 855 | s.append('\"'); |
856 | } else if(s.isEmpty() && !s.isNull()){ | 856 | } else if(s.isEmpty() && !s.isNull()){ |
857 | s = "\"\""; | 857 | s = "\"\""; |
858 | } | 858 | } |
859 | } | 859 | } |
860 | return list.join(","); | 860 | return list.join(","); |
861 | 861 | ||
862 | 862 | ||
863 | } | 863 | } |
864 | QString SharpFormat::getTodoString( Todo* todo ) | 864 | QString SharpFormat::getTodoString( Todo* todo ) |
865 | { | 865 | { |
866 | QStringList list; | 866 | QStringList list; |
867 | list.append( todo->getID("Sharp_DTM") ); | 867 | list.append( todo->getID("Sharp_DTM") ); |
868 | list.append( todo->categories().join(",") ); | 868 | list.append( todo->categories().join(",") ); |
869 | 869 | ||
870 | if ( todo->hasStartDate() ) { | 870 | if ( todo->hasStartDate() ) { |
871 | list.append( dtToString( todo->dtStart()) ); | 871 | list.append( dtToString( todo->dtStart()) ); |
872 | } else | 872 | } else |
873 | list.append( QString() ); | 873 | list.append( QString() ); |
874 | 874 | ||
875 | if ( todo->hasDueDate() ) { | 875 | if ( todo->hasDueDate() ) { |
876 | QTime tim; | 876 | QTime tim; |
877 | if ( todo->doesFloat()) { | 877 | if ( todo->doesFloat()) { |
878 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; | 878 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; |
879 | } else { | 879 | } else { |
880 | list.append( dtToString(todo->dtDue() ) ); | 880 | list.append( dtToString(todo->dtDue() ) ); |
881 | } | 881 | } |
882 | } else | 882 | } else |
883 | list.append( QString() ); | 883 | list.append( QString() ); |
884 | 884 | ||
885 | if ( todo->isCompleted() ) { | 885 | if ( todo->isCompleted() ) { |
886 | list.append( dtToString( todo->completed()) ); | 886 | list.append( dtToString( todo->completed()) ); |
887 | list.append( "0" ); // yes 0 == completed | 887 | list.append( "0" ); // yes 0 == completed |
888 | } else { | 888 | } else { |
889 | list.append( dtToString( todo->completed()) ); | 889 | list.append( dtToString( todo->completed()) ); |
890 | list.append( "1" ); | 890 | list.append( "1" ); |
891 | } | 891 | } |
892 | list.append( QString::number( todo->priority() )); | 892 | list.append( QString::number( todo->priority() )); |
893 | if( ! todo->summary().isEmpty() ) | 893 | if( ! todo->summary().isEmpty() ) |
894 | list.append( todo->summary() ); | 894 | list.append( todo->summary() ); |
895 | else | 895 | else |
896 | list.append( "" ); | 896 | list.append( "" ); |
897 | if (! todo->description().isEmpty() ) | 897 | if (! todo->description().isEmpty() ) |
898 | list.append( todo->description() ); | 898 | list.append( todo->description() ); |
899 | else | 899 | else |
900 | list.append( "" ); | 900 | list.append( "" ); |
901 | for(QStringList::Iterator it=list.begin(); | 901 | for(QStringList::Iterator it=list.begin(); |
902 | it!=list.end(); ++it){ | 902 | it!=list.end(); ++it){ |
903 | QString& s = (*it); | 903 | QString& s = (*it); |
904 | s.replace(QRegExp("\""), "\"\""); | 904 | s.replace(QRegExp("\""), "\"\""); |
905 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | 905 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ |
906 | s.prepend('\"'); | 906 | s.prepend('\"'); |
907 | s.append('\"'); | 907 | s.append('\"'); |
908 | } else if(s.isEmpty() && !s.isNull()){ | 908 | } else if(s.isEmpty() && !s.isNull()){ |
909 | s = "\"\""; | 909 | s = "\"\""; |
910 | } | 910 | } |
911 | } | 911 | } |
912 | return list.join(","); | 912 | return list.join(","); |
913 | } | 913 | } |
914 | QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) | 914 | QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) |
915 | { | 915 | { |
916 | //qDebug("start %d ", start); | 916 | //qDebug("start %d ", start); |
917 | 917 | ||
918 | QString retval =""; | 918 | QString retval =""; |
919 | if ( text.at(start) == '"' ) { | 919 | if ( text.at(start) == '"' ) { |
920 | if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { | 920 | if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { |
921 | start = start +2; | 921 | start = start +2; |
922 | if ( text.mid( start,1) == "," ) { | 922 | if ( text.mid( start,1) == "," ) { |
923 | start += 1; | 923 | start += 1; |
924 | } | 924 | } |
925 | retval = ""; | 925 | retval = ""; |
926 | if ( text.mid( start,1) == "\n" ) { | 926 | if ( text.mid( start,1) == "\n" ) { |
927 | start += 1; | 927 | start += 1; |
928 | ok = false; | 928 | ok = false; |
929 | } | 929 | } |
930 | return retval; | 930 | return retval; |
931 | } | 931 | } |
932 | int hk = start+1; | 932 | int hk = start+1; |
933 | hk = text.find ('"',hk); | 933 | hk = text.find ('"',hk); |
934 | while ( text.at(hk+1) == '"' ) | 934 | while ( text.at(hk+1) == '"' ) |
935 | hk = text.find ('"',hk+2); | 935 | hk = text.find ('"',hk+2); |
936 | retval = text.mid( start+1, hk-start-1); | 936 | retval = text.mid( start+1, hk-start-1); |
937 | start = hk+1; | 937 | start = hk+1; |
938 | retval.replace( QRegExp("\"\""), "\""); | 938 | retval.replace( QRegExp("\"\""), "\""); |
939 | if ( text.mid( start,1) == "," ) { | 939 | if ( text.mid( start,1) == "," ) { |
940 | start += 1; | 940 | start += 1; |
941 | } | 941 | } |
942 | if ( text.mid( start,1) == "\n" ) { | 942 | if ( text.mid( start,1) == "\n" ) { |
943 | start += 1; | 943 | start += 1; |
944 | ok = false; | 944 | ok = false; |
945 | } | 945 | } |
946 | //qDebug("retval***%s*** ",retval.latin1() ); | 946 | //qDebug("retval***%s*** ",retval.latin1() ); |
947 | return retval; | 947 | return retval; |
948 | 948 | ||
949 | } else { | 949 | } else { |
950 | int nl = text.find ("\n",start); | 950 | int nl = text.find ("\n",start); |
951 | int kom = text.find (',',start); | 951 | int kom = text.find (',',start); |
952 | if ( kom < nl ) { | 952 | if ( kom < nl ) { |
953 | // qDebug("kom < nl %d ", kom); | 953 | // qDebug("kom < nl %d ", kom); |
954 | retval = text.mid(start, kom-start); | 954 | retval = text.mid(start, kom-start); |
955 | start = kom+1; | 955 | start = kom+1; |
956 | return retval; | 956 | return retval; |
957 | } else { | 957 | } else { |
958 | if ( nl == kom ) { | 958 | if ( nl == kom ) { |
959 | // qDebug(" nl == kom "); | 959 | // qDebug(" nl == kom "); |
960 | start = 0; | 960 | start = 0; |
961 | ok = false; | 961 | ok = false; |
962 | return "0"; | 962 | return "0"; |
963 | } | 963 | } |
964 | // qDebug(" nl < kom ", nl); | 964 | // qDebug(" nl < kom ", nl); |
965 | retval = text.mid( start, nl-start); | 965 | retval = text.mid( start, nl-start); |
966 | ok = false; | 966 | ok = false; |
967 | start = nl+1; | 967 | start = nl+1; |
968 | return retval; | 968 | return retval; |
969 | } | 969 | } |
970 | } | 970 | } |
971 | } | 971 | } |
972 | bool SharpFormat::fromString( Calendar *calendar, const QString & text) | 972 | bool SharpFormat::fromString( Calendar *calendar, const QString & text) |
973 | { | 973 | { |
974 | return false; | 974 | return false; |
975 | } | 975 | } |
976 | bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) | 976 | bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) |
977 | { | 977 | { |
978 | // qDebug("test %s ", text.latin1()); | 978 | // qDebug("test %s ", text.latin1()); |
979 | QStringList templist; | 979 | QStringList templist; |
980 | QString tempString; | 980 | QString tempString; |
981 | int start = 0; | 981 | int start = 0; |
982 | int len = text.length(); | 982 | int len = text.length(); |
983 | int end = text.find ("\n",start)+1; | 983 | int end = text.find ("\n",start)+1; |
984 | bool ok = true; | 984 | bool ok = true; |
985 | start = end; | 985 | start = end; |
986 | SharpParser handler( calendar ); | 986 | SharpParser handler( calendar ); |
987 | // handler.setCategoriesList( mCategories ); | 987 | // handler.setCategoriesList( mCategories ); |
988 | while ( start > 0 ) { | 988 | while ( start > 0 ) { |
989 | templist.clear(); | 989 | templist.clear(); |
990 | ok = true; | 990 | ok = true; |
991 | while ( ok ) { | 991 | while ( ok ) { |
992 | tempString = getPart( text, ok, start ); | 992 | tempString = getPart( text, ok, start ); |
993 | if ( start >= len || start == 0 ) { | 993 | if ( start >= len || start == 0 ) { |
994 | start = 0; | 994 | start = 0; |
995 | ok = false; | 995 | ok = false; |
996 | } | 996 | } |
997 | if ( tempString.right(1) =="\n" ) | 997 | if ( tempString.right(1) =="\n" ) |
998 | tempString = tempString.left( tempString.length()-1); | 998 | tempString = tempString.left( tempString.length()-1); |
999 | //if ( ok ) | 999 | //if ( ok ) |
1000 | templist.append( tempString ); | 1000 | templist.append( tempString ); |
1001 | //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); | 1001 | //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); |
1002 | } | 1002 | } |
1003 | handler.startElement( existingCalendar, templist, type ); | 1003 | handler.startElement( existingCalendar, templist, type ); |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | return false; | 1006 | return false; |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | QString SharpFormat::toString( Calendar * ) | 1009 | QString SharpFormat::toString( Calendar * ) |
1010 | { | 1010 | { |
1011 | return QString::null; | 1011 | return QString::null; |
1012 | } | 1012 | } |
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index cc1c5ae..5a0c32e 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -114,570 +114,570 @@ void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | |||
114 | if ( !mRunning) return; | 114 | if ( !mRunning) return; |
115 | if ( mRunSaveTimer ) | 115 | if ( mRunSaveTimer ) |
116 | mRunSaveTimer->stop(); | 116 | mRunSaveTimer->stop(); |
117 | mRunning = false; | 117 | mRunning = false; |
118 | mRunStart = start; | 118 | mRunStart = start; |
119 | mRunEnd = end; | 119 | mRunEnd = end; |
120 | saveRunningInfoToFile( comment ); | 120 | saveRunningInfoToFile( comment ); |
121 | } | 121 | } |
122 | void Todo::restartSaveTimer( int secs ) | 122 | void Todo::restartSaveTimer( int secs ) |
123 | { | 123 | { |
124 | mRunSaveTimer->start( secs * 1000 ); | 124 | mRunSaveTimer->start( secs * 1000 ); |
125 | mRunLastSave = QDateTime::currentDateTime(); | 125 | mRunLastSave = QDateTime::currentDateTime(); |
126 | mCurrentTimerDelay = secs; | 126 | mCurrentTimerDelay = secs; |
127 | } | 127 | } |
128 | void Todo::timerSlotSaveRunningInfoToFile() | 128 | void Todo::timerSlotSaveRunningInfoToFile() |
129 | { | 129 | { |
130 | mRunEnd = QDateTime::currentDateTime(); | 130 | mRunEnd = QDateTime::currentDateTime(); |
131 | int secsTo = mRunLastSave.secsTo( mRunEnd ); | 131 | int secsTo = mRunLastSave.secsTo( mRunEnd ); |
132 | //if( secsTo == 8 ) ++secsTo; | 132 | //if( secsTo == 8 ) ++secsTo; |
133 | qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); | 133 | qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); |
134 | if ( secsTo > mCurrentTimerDelay ) { | 134 | if ( secsTo > mCurrentTimerDelay ) { |
135 | qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 135 | qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
136 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 136 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
137 | return; | 137 | return; |
138 | } | 138 | } |
139 | int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); | 139 | int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); |
140 | if ( msecs < 0 ) { | 140 | if ( msecs < 0 ) { |
141 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 141 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
142 | return; | 142 | return; |
143 | } | 143 | } |
144 | // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); | 144 | // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); |
145 | if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { | 145 | if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { |
146 | qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); | 146 | qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); |
147 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 147 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); | 150 | restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); |
151 | saveRunningInfoToFile( QString::null ); | 151 | saveRunningInfoToFile( QString::null ); |
152 | } | 152 | } |
153 | void Todo::saveRunningInfoToFile() | 153 | void Todo::saveRunningInfoToFile() |
154 | { | 154 | { |
155 | mRunEnd = QDateTime::currentDateTime(); | 155 | mRunEnd = QDateTime::currentDateTime(); |
156 | saveRunningInfoToFile( QString::null ); | 156 | saveRunningInfoToFile( QString::null ); |
157 | } | 157 | } |
158 | void Todo::saveRunningInfoToFile( QString comment ) | 158 | void Todo::saveRunningInfoToFile( QString comment ) |
159 | { | 159 | { |
160 | #ifndef DESKTOP_VERSION | 160 | #ifndef DESKTOP_VERSION |
161 | //QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable ); | 161 | //QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable ); |
162 | #endif | 162 | #endif |
163 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 163 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
164 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { | 164 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { |
165 | qDebug("Running time < 15 seconds. Skipped. "); | 165 | qDebug("Running time < 15 seconds. Skipped. "); |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | QString dir = KGlobalSettings::timeTrackerDir(); | 168 | QString dir = KGlobalSettings::timeTrackerDir(); |
169 | //qDebug("%s ", dir.latin1()); | 169 | //qDebug("%s ", dir.latin1()); |
170 | QString file = "%1%2%3-%4%5%6-"; | 170 | QString file = "%1%2%3-%4%5%6-"; |
171 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); | 171 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); |
172 | file.replace ( QRegExp (" "), "0" ); | 172 | file.replace ( QRegExp (" "), "0" ); |
173 | file += uid(); | 173 | file += uid(); |
174 | //qDebug("File %s ",file.latin1() ); | 174 | //qDebug("File %s ",file.latin1() ); |
175 | CalendarLocal cal; | 175 | CalendarLocal cal; |
176 | cal.setLocalTime(); | 176 | cal.setLocalTime(); |
177 | Todo * to = (Todo*) clone(); | 177 | Todo * to = (Todo*) clone(); |
178 | to->setFloats( false ); | 178 | to->setFloats( false ); |
179 | to->setDtStart( mRunStart ); | 179 | to->setDtStart( mRunStart ); |
180 | to->setHasStartDate( true ); | 180 | to->setHasStartDate( true ); |
181 | to->setDtDue( mRunEnd ); | 181 | to->setDtDue( mRunEnd ); |
182 | to->setHasDueDate( true ); | 182 | to->setHasDueDate( true ); |
183 | to->setUid( file ); | 183 | to->setUid( file ); |
184 | if ( !comment.isEmpty() ) { | 184 | if ( !comment.isEmpty() ) { |
185 | QString des = to->description(); | 185 | QString des = to->description(); |
186 | if ( des.isEmpty () ) | 186 | if ( des.isEmpty () ) |
187 | to->setDescription( "TT-Note: " + comment ); | 187 | to->setDescription( "TT-Note: " + comment ); |
188 | else | 188 | else |
189 | to->setDescription( "TT-Note: " + comment +"\n" + des ); | 189 | to->setDescription( "TT-Note: " + comment +"\n" + des ); |
190 | } | 190 | } |
191 | cal.addIncidence( to ); | 191 | cal.addIncidence( to ); |
192 | ICalFormat format( false ); | 192 | ICalFormat format( false ); |
193 | file = dir +"/" +file +".ics"; | 193 | file = dir +"/" +file +".ics"; |
194 | format.save( &cal, file ); | 194 | format.save( &cal, file ); |
195 | saveParents(); | 195 | saveParents(); |
196 | if ( !mLastSavedFileName.isEmpty() ) { | 196 | if ( !mLastSavedFileName.isEmpty() ) { |
197 | if ( mLastSavedFileName != file ) { | 197 | if ( mLastSavedFileName != file ) { |
198 | QFile::remove( mLastSavedFileName ); | 198 | QFile::remove( mLastSavedFileName ); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | mLastSavedFileName = file; | 201 | mLastSavedFileName = file; |
202 | #ifndef DESKTOP_VERSION | 202 | #ifndef DESKTOP_VERSION |
203 | //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable ); | 203 | //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable ); |
204 | #endif | 204 | #endif |
205 | } | 205 | } |
206 | void Todo::saveParents() | 206 | void Todo::saveParents() |
207 | { | 207 | { |
208 | if (!relatedTo() ) | 208 | if (!relatedTo() ) |
209 | return; | 209 | return; |
210 | Incidence * inc = relatedTo(); | 210 | Incidence * inc = relatedTo(); |
211 | if ( inc->typeID() != todoID ) | 211 | if ( inc->typeID() != todoID ) |
212 | return; | 212 | return; |
213 | Todo* to = (Todo*)inc; | 213 | Todo* to = (Todo*)inc; |
214 | bool saveTodo = false; | 214 | bool saveTodo = false; |
215 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 215 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
216 | QFileInfo fi ( file ); | 216 | QFileInfo fi ( file ); |
217 | if ( fi.exists() ) { | 217 | if ( fi.exists() ) { |
218 | if ( fi.lastModified () < to->lastModified ()) | 218 | if ( fi.lastModified () < to->lastModified ()) |
219 | saveTodo = true; | 219 | saveTodo = true; |
220 | } else { | 220 | } else { |
221 | saveTodo = true; | 221 | saveTodo = true; |
222 | } | 222 | } |
223 | if ( saveTodo ) { | 223 | if ( saveTodo ) { |
224 | CalendarLocal cal; | 224 | CalendarLocal cal; |
225 | cal.setLocalTime(); | 225 | cal.setLocalTime(); |
226 | Todo * par = (Todo *) to->clone(); | 226 | Todo * par = (Todo *) to->clone(); |
227 | cal.addIncidence( par ); | 227 | cal.addIncidence( par ); |
228 | ICalFormat format( false ); | 228 | ICalFormat format( false ); |
229 | format.save( &cal, file ); | 229 | format.save( &cal, file ); |
230 | } | 230 | } |
231 | to->saveParents(); | 231 | to->saveParents(); |
232 | } | 232 | } |
233 | 233 | ||
234 | int Todo::runTime() | 234 | int Todo::runTime() |
235 | { | 235 | { |
236 | if ( !mRunning ) | 236 | if ( !mRunning ) |
237 | return 0; | 237 | return 0; |
238 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 238 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
239 | } | 239 | } |
240 | bool Todo::hasRunningSub() | 240 | bool Todo::hasRunningSub() |
241 | { | 241 | { |
242 | if ( mRunning ) | 242 | if ( mRunning ) |
243 | return true; | 243 | return true; |
244 | Incidence *aTodo; | 244 | Incidence *aTodo; |
245 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 245 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
246 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 246 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
247 | return true; | 247 | return true; |
248 | } | 248 | } |
249 | return false; | 249 | return false; |
250 | } | 250 | } |
251 | Incidence *Todo::clone() | 251 | Incidence *Todo::clone() |
252 | { | 252 | { |
253 | return new Todo(*this); | 253 | return new Todo(*this); |
254 | } | 254 | } |
255 | 255 | ||
256 | bool Todo::contains ( Todo* from ) | 256 | bool Todo::contains ( Todo* from ) |
257 | { | 257 | { |
258 | 258 | ||
259 | if ( !from->summary().isEmpty() ) | 259 | if ( !from->summary().isEmpty() ) |
260 | if ( !summary().startsWith( from->summary() )) | 260 | if ( !summary().startsWith( from->summary() )) |
261 | return false; | 261 | return false; |
262 | if ( from->hasStartDate() ) { | 262 | if ( from->hasStartDate() ) { |
263 | if ( !hasStartDate() ) | 263 | if ( !hasStartDate() ) |
264 | return false; | 264 | return false; |
265 | if ( from->dtStart() != dtStart()) | 265 | if ( from->dtStart() != dtStart()) |
266 | return false; | 266 | return false; |
267 | } | 267 | } |
268 | if ( from->hasDueDate() ){ | 268 | if ( from->hasDueDate() ){ |
269 | if ( !hasDueDate() ) | 269 | if ( !hasDueDate() ) |
270 | return false; | 270 | return false; |
271 | if ( from->dtDue() != dtDue()) | 271 | if ( from->dtDue() != dtDue()) |
272 | return false; | 272 | return false; |
273 | } | 273 | } |
274 | if ( !from->location().isEmpty() ) | 274 | if ( !from->location().isEmpty() ) |
275 | if ( !location().startsWith( from->location() ) ) | 275 | if ( !location().startsWith( from->location() ) ) |
276 | return false; | 276 | return false; |
277 | if ( !from->description().isEmpty() ) | 277 | if ( !from->description().isEmpty() ) |
278 | if ( !description().startsWith( from->description() )) | 278 | if ( !description().startsWith( from->description() )) |
279 | return false; | 279 | return false; |
280 | if ( from->alarms().count() ) { | 280 | if ( from->alarms().count() ) { |
281 | Alarm *a = from->alarms().first(); | 281 | Alarm *a = from->alarms().first(); |
282 | if ( a->enabled() ){ | 282 | if ( a->enabled() ){ |
283 | if ( !alarms().count() ) | 283 | if ( !alarms().count() ) |
284 | return false; | 284 | return false; |
285 | Alarm *b = alarms().first(); | 285 | Alarm *b = alarms().first(); |
286 | if( ! b->enabled() ) | 286 | if( ! b->enabled() ) |
287 | return false; | 287 | return false; |
288 | if ( ! (a->offset() == b->offset() )) | 288 | if ( ! (a->offset() == b->offset() )) |
289 | return false; | 289 | return false; |
290 | } | 290 | } |
291 | } | 291 | } |
292 | 292 | ||
293 | QStringList cat = categories(); | 293 | QStringList cat = categories(); |
294 | QStringList catFrom = from->categories(); | 294 | QStringList catFrom = from->categories(); |
295 | QString nCat; | 295 | QString nCat; |
296 | unsigned int iii; | 296 | unsigned int iii; |
297 | for ( iii = 0; iii < catFrom.count();++iii ) { | 297 | for ( iii = 0; iii < catFrom.count();++iii ) { |
298 | nCat = catFrom[iii]; | 298 | nCat = catFrom[iii]; |
299 | if ( !nCat.isEmpty() ) | 299 | if ( !nCat.isEmpty() ) |
300 | if ( !cat.contains( nCat )) { | 300 | if ( !cat.contains( nCat )) { |
301 | return false; | 301 | return false; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | if ( from->isCompleted() ) { | 304 | if ( from->isCompleted() ) { |
305 | if ( !isCompleted() ) | 305 | if ( !isCompleted() ) |
306 | return false; | 306 | return false; |
307 | } | 307 | } |
308 | if( priority() != from->priority() ) | 308 | if( priority() != from->priority() ) |
309 | return false; | 309 | return false; |
310 | 310 | ||
311 | 311 | ||
312 | return true; | 312 | return true; |
313 | 313 | ||
314 | } | 314 | } |
315 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 315 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
316 | { | 316 | { |
317 | 317 | ||
318 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 318 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
319 | if ( ! ret ) | 319 | if ( ! ret ) |
320 | return false; | 320 | return false; |
321 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 321 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
322 | if ( t1.hasDueDate() ) { | 322 | if ( t1.hasDueDate() ) { |
323 | if ( t1.doesFloat() == t2.doesFloat() ) { | 323 | if ( t1.doesFloat() == t2.doesFloat() ) { |
324 | if ( t1.doesFloat() ) { | 324 | if ( t1.doesFloat() ) { |
325 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 325 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
326 | return false; | 326 | return false; |
327 | } else | 327 | } else |
328 | if ( t1.dtDue() != t2.dtDue() ) | 328 | if ( t1.dtDue() != t2.dtDue() ) |
329 | return false; | 329 | return false; |
330 | } else | 330 | } else |
331 | return false;// float != | 331 | return false;// float != |
332 | } | 332 | } |
333 | 333 | ||
334 | } else | 334 | } else |
335 | return false; | 335 | return false; |
336 | if ( t1.percentComplete() != t2.percentComplete() ) | 336 | if ( t1.percentComplete() != t2.percentComplete() ) |
337 | return false; | 337 | return false; |
338 | if ( t1.isCompleted() ) { | 338 | if ( t1.isCompleted() ) { |
339 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 339 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
340 | if ( t1.hasCompletedDate() ) { | 340 | if ( t1.hasCompletedDate() ) { |
341 | if ( t1.completed() != t2.completed() ) | 341 | if ( t1.completed() != t2.completed() ) |
342 | return false; | 342 | return false; |
343 | } | 343 | } |
344 | 344 | ||
345 | } else | 345 | } else |
346 | return false; | 346 | return false; |
347 | } | 347 | } |
348 | return true; | 348 | return true; |
349 | 349 | ||
350 | } | 350 | } |
351 | 351 | ||
352 | void Todo::setDtDue(const QDateTime &dtDue) | 352 | void Todo::setDtDue(const QDateTime &dtDue) |
353 | { | 353 | { |
354 | //int diffsecs = mDtDue.secsTo(dtDue); | 354 | //int diffsecs = mDtDue.secsTo(dtDue); |
355 | 355 | ||
356 | /*if (mReadOnly) return; | 356 | /*if (mReadOnly) return; |
357 | const QPtrList<Alarm>& alarms = alarms(); | 357 | const QPtrList<Alarm>& alarms = alarms(); |
358 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 358 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
359 | if (alarm->enabled()) { | 359 | if (alarm->enabled()) { |
360 | alarm->setTime(alarm->time().addSecs(diffsecs)); | 360 | alarm->setTime(alarm->time().addSecs(diffsecs)); |
361 | } | 361 | } |
362 | }*/ | 362 | }*/ |
363 | mDtDue = getEvenTime(dtDue); | 363 | mDtDue = getEvenTime(dtDue); |
364 | 364 | ||
365 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; | 365 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; |
366 | 366 | ||
367 | /*const QPtrList<Alarm>& alarms = alarms(); | 367 | /*const QPtrList<Alarm>& alarms = alarms(); |
368 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) | 368 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) |
369 | alarm->setAlarmStart(mDtDue);*/ | 369 | alarm->setAlarmStart(mDtDue);*/ |
370 | updated(); | 370 | updated(); |
371 | } | 371 | } |
372 | 372 | ||
373 | QDateTime Todo::dtDue() const | 373 | QDateTime Todo::dtDue() const |
374 | { | 374 | { |
375 | return mDtDue; | 375 | return mDtDue; |
376 | } | 376 | } |
377 | 377 | ||
378 | QString Todo::dtDueTimeStr() const | 378 | QString Todo::dtDueTimeStr() const |
379 | { | 379 | { |
380 | return KGlobal::locale()->formatTime(mDtDue.time()); | 380 | return KGlobal::locale()->formatTime(mDtDue.time()); |
381 | } | 381 | } |
382 | 382 | ||
383 | QString Todo::dtDueDateStr(bool shortfmt) const | 383 | QString Todo::dtDueDateStr(bool shortfmt) const |
384 | { | 384 | { |
385 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 385 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
386 | } | 386 | } |
387 | 387 | ||
388 | QString Todo::dtDueStr(bool shortfmt) const | 388 | QString Todo::dtDueStr(bool shortfmt) const |
389 | { | 389 | { |
390 | if ( doesFloat() ) | 390 | if ( doesFloat() ) |
391 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 391 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
392 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); | 392 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); |
393 | } | 393 | } |
394 | // retval 0 : no found | 394 | // retval 0 : no found |
395 | // 1 : due for date found | 395 | // 1 : due for date found |
396 | // 2 : overdue for date found | 396 | // 2 : overdue for date found |
397 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | 397 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) |
398 | { | 398 | { |
399 | int retval = 0; | 399 | int retval = 0; |
400 | if ( isCompleted() ) | 400 | if ( isCompleted() ) |
401 | return 0; | 401 | return 0; |
402 | if ( hasDueDate() ) { | 402 | if ( hasDueDate() ) { |
403 | if ( dtDue().date() < date ) | 403 | if ( dtDue().date() < date ) |
404 | return 2; | 404 | return 2; |
405 | // we do not return, because we may find an overdue sub todo | 405 | // we do not return, because we may find an overdue sub todo |
406 | if ( dtDue().date() == date ) | 406 | if ( dtDue().date() == date ) |
407 | retval = 1; | 407 | retval = 1; |
408 | } | 408 | } |
409 | if ( checkSubtodos ) { | 409 | if ( checkSubtodos ) { |
410 | Incidence *aTodo; | 410 | Incidence *aTodo; |
411 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 411 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
412 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | 412 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); |
413 | if ( ret == 2 ) | 413 | if ( ret == 2 ) |
414 | return 2; | 414 | return 2; |
415 | if ( ret == 1) | 415 | if ( ret == 1) |
416 | retval = 1; | 416 | retval = 1; |
417 | } | 417 | } |
418 | } | 418 | } |
419 | return retval; | 419 | return retval; |
420 | } | 420 | } |
421 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | 421 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true |
422 | { | 422 | { |
423 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | 423 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); |
424 | } | 424 | } |
425 | bool Todo::hasDueDate() const | 425 | bool Todo::hasDueDate() const |
426 | { | 426 | { |
427 | return mHasDueDate; | 427 | return mHasDueDate; |
428 | } | 428 | } |
429 | 429 | ||
430 | void Todo::setHasDueDate(bool f) | 430 | void Todo::setHasDueDate(bool f) |
431 | { | 431 | { |
432 | if (mReadOnly) return; | 432 | if (mReadOnly) return; |
433 | mHasDueDate = f; | 433 | mHasDueDate = f; |
434 | updated(); | 434 | updated(); |
435 | } | 435 | } |
436 | 436 | ||
437 | 437 | ||
438 | #if 0 | 438 | #if 0 |
439 | void Todo::setStatus(const QString &statStr) | 439 | void Todo::setStatus(const QString &statStr) |
440 | { | 440 | { |
441 | if (mReadOnly) return; | 441 | if (mReadOnly) return; |
442 | QString ss(statStr.upper()); | 442 | QString ss(statStr.upper()); |
443 | 443 | ||
444 | if (ss == "X-ACTION") | 444 | if (ss == "X-ACTION") |
445 | mStatus = NEEDS_ACTION; | 445 | mStatus = NEEDS_ACTION; |
446 | else if (ss == "NEEDS ACTION") | 446 | else if (ss == "NEEDS ACTION") |
447 | mStatus = NEEDS_ACTION; | 447 | mStatus = NEEDS_ACTION; |
448 | else if (ss == "ACCEPTED") | 448 | else if (ss == "ACCEPTED") |
449 | mStatus = ACCEPTED; | 449 | mStatus = ACCEPTED; |
450 | else if (ss == "SENT") | 450 | else if (ss == "SENT") |
451 | mStatus = SENT; | 451 | mStatus = SENT; |
452 | else if (ss == "TENTATIVE") | 452 | else if (ss == "TENTATIVE") |
453 | mStatus = TENTATIVE; | 453 | mStatus = TENTATIVE; |
454 | else if (ss == "CONFIRMED") | 454 | else if (ss == "CONFIRMED") |
455 | mStatus = CONFIRMED; | 455 | mStatus = CONFIRMED; |
456 | else if (ss == "DECLINED") | 456 | else if (ss == "DECLINED") |
457 | mStatus = DECLINED; | 457 | mStatus = DECLINED; |
458 | else if (ss == "COMPLETED") | 458 | else if (ss == "COMPLETED") |
459 | mStatus = COMPLETED; | 459 | mStatus = COMPLETED; |
460 | else if (ss == "DELEGATED") | 460 | else if (ss == "DELEGATED") |
461 | mStatus = DELEGATED; | 461 | mStatus = DELEGATED; |
462 | 462 | ||
463 | updated(); | 463 | updated(); |
464 | } | 464 | } |
465 | 465 | ||
466 | void Todo::setStatus(int status) | 466 | void Todo::setStatus(int status) |
467 | { | 467 | { |
468 | if (mReadOnly) return; | 468 | if (mReadOnly) return; |
469 | mStatus = status; | 469 | mStatus = status; |
470 | updated(); | 470 | updated(); |
471 | } | 471 | } |
472 | 472 | ||
473 | int Todo::status() const | 473 | int Todo::status() const |
474 | { | 474 | { |
475 | return mStatus; | 475 | return mStatus; |
476 | } | 476 | } |
477 | 477 | ||
478 | QString Todo::statusStr() const | 478 | QString Todo::statusStr() const |
479 | { | 479 | { |
480 | switch(mStatus) { | 480 | switch(mStatus) { |
481 | case NEEDS_ACTION: | 481 | case NEEDS_ACTION: |
482 | return QString("NEEDS ACTION"); | 482 | return QString("NEEDS ACTION"); |
483 | break; | 483 | break; |
484 | case ACCEPTED: | 484 | case ACCEPTED: |
485 | return QString("ACCEPTED"); | 485 | return QString("ACCEPTED"); |
486 | break; | 486 | break; |
487 | case SENT: | 487 | case SENT: |
488 | return QString("SENT"); | 488 | return QString("SENT"); |
489 | break; | 489 | break; |
490 | case TENTATIVE: | 490 | case TENTATIVE: |
491 | return QString("TENTATIVE"); | 491 | return QString("TENTATIVE"); |
492 | break; | 492 | break; |
493 | case CONFIRMED: | 493 | case CONFIRMED: |
494 | return QString("CONFIRMED"); | 494 | return QString("CONFIRMED"); |
495 | break; | 495 | break; |
496 | case DECLINED: | 496 | case DECLINED: |
497 | return QString("DECLINED"); | 497 | return QString("DECLINED"); |
498 | break; | 498 | break; |
499 | case COMPLETED: | 499 | case COMPLETED: |
500 | return QString("COMPLETED"); | 500 | return QString("COMPLETED"); |
501 | break; | 501 | break; |
502 | case DELEGATED: | 502 | case DELEGATED: |
503 | return QString("DELEGATED"); | 503 | return QString("DELEGATED"); |
504 | break; | 504 | break; |
505 | } | 505 | } |
506 | return QString(""); | 506 | return QString(""); |
507 | } | 507 | } |
508 | #endif | 508 | #endif |
509 | 509 | ||
510 | bool Todo::isCompleted() const | 510 | bool Todo::isCompleted() const |
511 | { | 511 | { |
512 | if (mPercentComplete == 100) { | 512 | if (mPercentComplete == 100) { |
513 | return true; | 513 | return true; |
514 | } | 514 | } |
515 | else return false; | 515 | else return false; |
516 | } | 516 | } |
517 | 517 | ||
518 | void Todo::setCompleted(bool completed) | 518 | void Todo::setCompleted(bool completed) |
519 | { | 519 | { |
520 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { | 520 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { |
521 | if ( !setRecurDates() ) | 521 | if ( !setRecurDates() ) |
522 | completed = false; | 522 | completed = false; |
523 | } | 523 | } |
524 | if (completed) mPercentComplete = 100; | 524 | if (completed) mPercentComplete = 100; |
525 | else { | 525 | else { |
526 | mPercentComplete = 0; | 526 | mPercentComplete = 0; |
527 | mHasCompletedDate = false; | 527 | mHasCompletedDate = false; |
528 | } | 528 | } |
529 | updated(); | 529 | updated(); |
530 | } | 530 | } |
531 | 531 | ||
532 | QDateTime Todo::completed() const | 532 | QDateTime Todo::completed() const |
533 | { | 533 | { |
534 | return mCompleted; | 534 | return mCompleted; |
535 | } | 535 | } |
536 | 536 | ||
537 | QString Todo::completedStr( bool shortF ) const | 537 | QString Todo::completedStr( bool shortF ) const |
538 | { | 538 | { |
539 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 539 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
540 | } | 540 | } |
541 | 541 | ||
542 | void Todo::setCompleted(const QDateTime &completed) | 542 | void Todo::setCompleted(const QDateTime &completed) |
543 | { | 543 | { |
544 | //qDebug("Todo::setCompleted "); | 544 | //qDebug("Todo::setCompleted "); |
545 | if ( mHasCompletedDate ) { | 545 | if ( mHasCompletedDate ) { |
546 | // qDebug("has completed data - return "); | 546 | // qDebug("has completed data - return "); |
547 | return; | 547 | return; |
548 | } | 548 | } |
549 | mHasCompletedDate = true; | 549 | mHasCompletedDate = true; |
550 | mPercentComplete = 100; | 550 | mPercentComplete = 100; |
551 | mCompleted = getEvenTime(completed); | 551 | mCompleted = getEvenTime(completed); |
552 | updated(); | 552 | updated(); |
553 | } | 553 | } |
554 | 554 | ||
555 | bool Todo::hasCompletedDate() const | 555 | bool Todo::hasCompletedDate() const |
556 | { | 556 | { |
557 | return mHasCompletedDate; | 557 | return mHasCompletedDate; |
558 | } | 558 | } |
559 | 559 | ||
560 | int Todo::percentComplete() const | 560 | int Todo::percentComplete() const |
561 | { | 561 | { |
562 | return mPercentComplete; | 562 | return mPercentComplete; |
563 | } | 563 | } |
564 | bool Todo::setRecurDates() | 564 | bool Todo::setRecurDates() |
565 | { | 565 | { |
566 | if ( !mHasRecurrenceID ) | 566 | if ( !mHasRecurrenceID ) |
567 | return true; | 567 | return true; |
568 | int secs = mDtStart.secsTo( dtDue() ); | 568 | int secs = mDtStart.secsTo( dtDue() ); |
569 | bool ok; | 569 | bool ok; |
570 | qDebug("T:setRecurDates() "); | 570 | qDebug("T:setRecurDates() "); |
571 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 571 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
572 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); | 572 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); |
573 | if ( ok ) { | 573 | if ( ok ) { |
574 | mRecurrenceID = next; | 574 | mRecurrenceID = next; |
575 | mDtStart = next; | 575 | mDtStart = next; |
576 | setDtDue( next.addSecs( secs ) ); | 576 | setDtDue( next.addSecs( secs ) ); |
577 | if ( QDateTime::currentDateTime() > next) | 577 | if ( QDateTime::currentDateTime() > next) |
578 | return false; | 578 | return false; |
579 | } else { | 579 | } else { |
580 | setHasRecurrenceID( false ); | 580 | setHasRecurrenceID( false ); |
581 | recurrence()->unsetRecurs(); | 581 | recurrence()->unsetRecurs(); |
582 | } | 582 | } |
583 | return true; | 583 | return true; |
584 | } | 584 | } |
585 | void Todo::setPercentComplete(int v) | 585 | void Todo::setPercentComplete(int v) |
586 | { | 586 | { |
587 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { | 587 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { |
588 | if ( !setRecurDates() ) | 588 | if ( !setRecurDates() ) |
589 | v = 0; | 589 | v = 0; |
590 | } | 590 | } |
591 | mPercentComplete = v; | 591 | mPercentComplete = v; |
592 | if ( v != 100 ) | 592 | if ( v != 100 ) |
593 | mHasCompletedDate = false; | 593 | mHasCompletedDate = false; |
594 | updated(); | 594 | updated(); |
595 | } | 595 | } |
596 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const | 596 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const |
597 | { | 597 | { |
598 | *ok = false; | 598 | *ok = false; |
599 | if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { | 599 | if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { |
600 | return QDateTime (); | 600 | return QDateTime (); |
601 | } | 601 | } |
602 | // if the recurring todo is set to complete and requested time < start time of todo | 602 | // if the recurring todo is set to complete and requested time < start time of todo |
603 | // we want to get the alarm. | 603 | // we want to get the alarm. |
604 | bool iscompleted = isCompleted(); | 604 | bool iscompleted = isCompleted(); |
605 | if ( iscompleted && doesRecur() ) { | 605 | if ( iscompleted && doesRecur() ) { |
606 | Todo * to = (Todo*) this; | 606 | Todo * to = (Todo*) this; |
607 | to->checkSetCompletedFalse(); | 607 | to->checkSetCompletedFalse(); |
608 | iscompleted = isCompleted(); | 608 | iscompleted = isCompleted(); |
609 | if ( hasStartDate() && start_dt < dtStart() ){ | 609 | if ( hasStartDate() && start_dt < dtStart() ){ |
610 | iscompleted = false; | 610 | iscompleted = false; |
611 | } | 611 | } |
612 | } | 612 | } |
613 | if ( iscompleted ) { | 613 | if ( iscompleted ) { |
614 | return QDateTime (); | 614 | return QDateTime (); |
615 | } | 615 | } |
616 | QDateTime incidenceStart; | 616 | QDateTime incidenceStart; |
617 | incidenceStart = dtDue(); | 617 | incidenceStart = dtDue(); |
618 | bool enabled = false; | 618 | bool enabled = false; |
619 | Alarm* alarm; | 619 | Alarm* alarm; |
620 | int off = 0; | 620 | int off = 0; |
621 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 621 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
622 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 622 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
623 | // *ok = false; | 623 | // *ok = false; |
624 | // return incidenceStart; | 624 | // return incidenceStart; |
625 | // } | 625 | // } |
626 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 626 | for (Q3PtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
627 | if (alarm->enabled()) { | 627 | if (alarm->enabled()) { |
628 | if ( alarm->hasTime () ) { | 628 | if ( alarm->hasTime () ) { |
629 | if ( alarm->time() < alarmStart ) { | 629 | if ( alarm->time() < alarmStart ) { |
630 | alarmStart = alarm->time(); | 630 | alarmStart = alarm->time(); |
631 | enabled = true; | 631 | enabled = true; |
632 | off = alarmStart.secsTo( incidenceStart ); | 632 | off = alarmStart.secsTo( incidenceStart ); |
633 | } | 633 | } |
634 | 634 | ||
635 | } else { | 635 | } else { |
636 | int secs = alarm->startOffset().asSeconds(); | 636 | int secs = alarm->startOffset().asSeconds(); |
637 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 637 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
638 | alarmStart = incidenceStart.addSecs( secs ); | 638 | alarmStart = incidenceStart.addSecs( secs ); |
639 | enabled = true; | 639 | enabled = true; |
640 | off = -secs; | 640 | off = -secs; |
641 | } | 641 | } |
642 | } | 642 | } |
643 | } | 643 | } |
644 | } | 644 | } |
645 | if ( enabled ) { | 645 | if ( enabled ) { |
646 | if ( alarmStart > start_dt ) { | 646 | if ( alarmStart > start_dt ) { |
647 | *ok = true; | 647 | *ok = true; |
648 | * offset = off; | 648 | * offset = off; |
649 | return alarmStart; | 649 | return alarmStart; |
650 | } | 650 | } |
651 | } | 651 | } |
652 | *ok = false; | 652 | *ok = false; |
653 | return QDateTime (); | 653 | return QDateTime (); |
654 | 654 | ||
655 | } | 655 | } |
656 | 656 | ||
657 | void Todo::checkSetCompletedFalse() | 657 | void Todo::checkSetCompletedFalse() |
658 | { | 658 | { |
659 | if ( !mHasRecurrenceID ) { | 659 | if ( !mHasRecurrenceID ) { |
660 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); | 660 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); |
661 | return; | 661 | return; |
662 | } | 662 | } |
663 | // qDebug("Todo::checkSetCompletedFalse()"); | 663 | // qDebug("Todo::checkSetCompletedFalse()"); |
664 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 664 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
665 | if ( mPercentComplete == 100 ) { | 665 | if ( mPercentComplete == 100 ) { |
666 | QDateTime dt = QDateTime::currentDateTime(); | 666 | QDateTime dt = QDateTime::currentDateTime(); |
667 | if ( dt > mDtStart && dt > mRecurrenceID ) { | 667 | if ( dt > mDtStart && dt > mRecurrenceID ) { |
668 | qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 668 | qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
669 | setCompleted( false ); | 669 | setCompleted( false ); |
670 | qDebug("Todo::checkSetCompletedFalse "); | 670 | qDebug("Todo::checkSetCompletedFalse "); |
671 | } | 671 | } |
672 | } | 672 | } |
673 | } | 673 | } |
674 | QString Todo::durationText() | 674 | QString Todo::durationText() |
675 | { | 675 | { |
676 | if ( mHasDueDate && hasStartDate() ) { | 676 | if ( mHasDueDate && hasStartDate() ) { |
677 | int sec = dtStart().secsTo( dtDue() ); | 677 | int sec = dtStart().secsTo( dtDue() ); |
678 | if ( doesFloat() ) | 678 | if ( doesFloat() ) |
679 | sec += 86400; | 679 | sec += 86400; |
680 | return durationText4Time( sec ); | 680 | return durationText4Time( sec ); |
681 | } | 681 | } |
682 | return "---"; | 682 | return "---"; |
683 | } | 683 | } |
diff --git a/libkcal/todo.h b/libkcal/todo.h index 2131732..cea976c 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h | |||
@@ -1,162 +1,164 @@ | |||
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 TODO_H | 20 | #ifndef TODO_H |
21 | #define TODO_H | 21 | #define TODO_H |
22 | // | 22 | // |
23 | // Todo component, representing a VTODO object | 23 | // Todo component, representing a VTODO object |
24 | // | 24 | // |
25 | 25 | ||
26 | #include "incidence.h" | 26 | #include "incidence.h" |
27 | 27 | ||
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | //Added by qt3to4: | ||
30 | #include <Q3CString> | ||
29 | 31 | ||
30 | namespace KCal { | 32 | namespace KCal { |
31 | 33 | ||
32 | /** | 34 | /** |
33 | This class provides a Todo in the sense of RFC2445. | 35 | This class provides a Todo in the sense of RFC2445. |
34 | */ | 36 | */ |
35 | class Todo : public QObject,public Incidence | 37 | class Todo : public QObject,public Incidence |
36 | { | 38 | { |
37 | Q_OBJECT | 39 | Q_OBJECT |
38 | public: | 40 | public: |
39 | Todo(); | 41 | Todo(); |
40 | Todo(const Todo &); | 42 | Todo(const Todo &); |
41 | ~Todo(); | 43 | ~Todo(); |
42 | typedef ListBase<Todo> List; | 44 | typedef ListBase<Todo> List; |
43 | QCString type() const { return "Todo"; } | 45 | Q3CString type() const { return "Todo"; } |
44 | IncTypeID typeID() const { return todoID; } | 46 | IncTypeID typeID() const { return todoID; } |
45 | 47 | ||
46 | /** Return an exact copy of this todo. */ | 48 | /** Return an exact copy of this todo. */ |
47 | Incidence *clone(); | 49 | Incidence *clone(); |
48 | QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; | 50 | QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; |
49 | 51 | ||
50 | /** for setting the todo's due date/time with a QDateTime. */ | 52 | /** for setting the todo's due date/time with a QDateTime. */ |
51 | void setDtDue(const QDateTime &dtDue); | 53 | void setDtDue(const QDateTime &dtDue); |
52 | /** returns an event's Due date/time as a QDateTime. */ | 54 | /** returns an event's Due date/time as a QDateTime. */ |
53 | QDateTime dtDue() const; | 55 | QDateTime dtDue() const; |
54 | /** returns an event's due time as a string formatted according to the | 56 | /** returns an event's due time as a string formatted according to the |
55 | users locale settings */ | 57 | users locale settings */ |
56 | QString dtDueTimeStr() const; | 58 | QString dtDueTimeStr() const; |
57 | /** returns an event's due date as a string formatted according to the | 59 | /** returns an event's due date as a string formatted according to the |
58 | users locale settings */ | 60 | users locale settings */ |
59 | QString dtDueDateStr(bool shortfmt=true) const; | 61 | QString dtDueDateStr(bool shortfmt=true) const; |
60 | /** returns an event's due date and time as a string formatted according | 62 | /** returns an event's due date and time as a string formatted according |
61 | to the users locale settings */ | 63 | to the users locale settings */ |
62 | QString dtDueStr(bool shortfmt=true) const; | 64 | QString dtDueStr(bool shortfmt=true) const; |
63 | 65 | ||
64 | /** returns TRUE or FALSE depending on whether the todo has a due date */ | 66 | /** returns TRUE or FALSE depending on whether the todo has a due date */ |
65 | bool hasDueDate() const; | 67 | bool hasDueDate() const; |
66 | /** sets the event's hasDueDate value. */ | 68 | /** sets the event's hasDueDate value. */ |
67 | void setHasDueDate(bool f); | 69 | void setHasDueDate(bool f); |
68 | 70 | ||
69 | /* | 71 | /* |
70 | Looks for a subtodo (including itself ) which is not complete and is | 72 | Looks for a subtodo (including itself ) which is not complete and is |
71 | - overdue, or | 73 | - overdue, or |
72 | - due today. | 74 | - due today. |
73 | It returns 0 for nothing found, | 75 | It returns 0 for nothing found, |
74 | 1 for found a todo which is due today and no overdue found | 76 | 1 for found a todo which is due today and no overdue found |
75 | 2 for found a overdue todo | 77 | 2 for found a overdue todo |
76 | */ | 78 | */ |
77 | int hasDueSubTodo( bool checkSubtodos = true ); | 79 | int hasDueSubTodo( bool checkSubtodos = true ); |
78 | /* same as above, but a specific date can be specified*/ | 80 | /* same as above, but a specific date can be specified*/ |
79 | int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); | 81 | int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); |
80 | 82 | ||
81 | 83 | ||
82 | /** sets the event's status to the string specified. The string | 84 | /** sets the event's status to the string specified. The string |
83 | * must be a recognized value for the status field, i.e. a string | 85 | * must be a recognized value for the status field, i.e. a string |
84 | * equivalent of the possible status enumerations previously described. */ | 86 | * equivalent of the possible status enumerations previously described. */ |
85 | // void setStatus(const QString &statStr); | 87 | // void setStatus(const QString &statStr); |
86 | /** sets the event's status to the value specified. See the enumeration | 88 | /** sets the event's status to the value specified. See the enumeration |
87 | * above for possible values. */ | 89 | * above for possible values. */ |
88 | // void setStatus(int); | 90 | // void setStatus(int); |
89 | /** return the event's status. */ | 91 | /** return the event's status. */ |
90 | // int status() const; | 92 | // int status() const; |
91 | /** return the event's status in string format. */ | 93 | /** return the event's status in string format. */ |
92 | // QString statusStr() const; | 94 | // QString statusStr() const; |
93 | 95 | ||
94 | /** return, if this todo is completed */ | 96 | /** return, if this todo is completed */ |
95 | bool isCompleted() const; | 97 | bool isCompleted() const; |
96 | /** set completed state of this todo */ | 98 | /** set completed state of this todo */ |
97 | void setCompleted(bool); | 99 | void setCompleted(bool); |
98 | 100 | ||
99 | /** | 101 | /** |
100 | Return how many percent of the task are completed. Returns a value | 102 | Return how many percent of the task are completed. Returns a value |
101 | between 0 and 100. | 103 | between 0 and 100. |
102 | */ | 104 | */ |
103 | int percentComplete() const; | 105 | int percentComplete() const; |
104 | /** | 106 | /** |
105 | Set how many percent of the task are completed. Valid values are in the | 107 | Set how many percent of the task are completed. Valid values are in the |
106 | range from 0 to 100. | 108 | range from 0 to 100. |
107 | */ | 109 | */ |
108 | void setPercentComplete(int); | 110 | void setPercentComplete(int); |
109 | 111 | ||
110 | /** return date and time when todo was completed */ | 112 | /** return date and time when todo was completed */ |
111 | QDateTime completed() const; | 113 | QDateTime completed() const; |
112 | QString completedStr(bool shortF = true) const; | 114 | QString completedStr(bool shortF = true) const; |
113 | /** set date and time of completion */ | 115 | /** set date and time of completion */ |
114 | void setCompleted(const QDateTime &completed); | 116 | void setCompleted(const QDateTime &completed); |
115 | 117 | ||
116 | /** Return true, if todo has a date associated with completion */ | 118 | /** Return true, if todo has a date associated with completion */ |
117 | bool hasCompletedDate() const; | 119 | bool hasCompletedDate() const; |
118 | bool contains ( Todo*); | 120 | bool contains ( Todo*); |
119 | void checkSetCompletedFalse(); | 121 | void checkSetCompletedFalse(); |
120 | bool setRecurDates(); | 122 | bool setRecurDates(); |
121 | bool isRunning() {return mRunning;} | 123 | bool isRunning() {return mRunning;} |
122 | bool hasRunningSub(); | 124 | bool hasRunningSub(); |
123 | void setRunning( bool ); | 125 | void setRunning( bool ); |
124 | void setRunningFalse( QString ); | 126 | void setRunningFalse( QString ); |
125 | void stopRunning(); | 127 | void stopRunning(); |
126 | int runTime(); | 128 | int runTime(); |
127 | QDateTime runStart () const { return mRunStart;} | 129 | QDateTime runStart () const { return mRunStart;} |
128 | void saveRunningInfo( QString comment, QDateTime start, QDateTime end ); | 130 | void saveRunningInfo( QString comment, QDateTime start, QDateTime end ); |
129 | public slots: | 131 | public slots: |
130 | void saveRunningInfoToFile( QString st ); | 132 | void saveRunningInfoToFile( QString st ); |
131 | void saveRunningInfoToFile( ); | 133 | void saveRunningInfoToFile( ); |
132 | void saveParents(); | 134 | void saveParents(); |
133 | QString durationText(); | 135 | QString durationText(); |
134 | private slots: | 136 | private slots: |
135 | void timerSlotSaveRunningInfoToFile( ); | 137 | void timerSlotSaveRunningInfoToFile( ); |
136 | private: | 138 | private: |
137 | QString mLastSavedFileName; | 139 | QString mLastSavedFileName; |
138 | void restartSaveTimer( int secs ); | 140 | void restartSaveTimer( int secs ); |
139 | int mCurrentTimerDelay; | 141 | int mCurrentTimerDelay; |
140 | bool mRunning; | 142 | bool mRunning; |
141 | QTimer * mRunSaveTimer; | 143 | QTimer * mRunSaveTimer; |
142 | QDateTime mRunStart; | 144 | QDateTime mRunStart; |
143 | QDateTime mRunLastSave; | 145 | QDateTime mRunLastSave; |
144 | QDateTime mRunEnd; | 146 | QDateTime mRunEnd; |
145 | bool accept(Visitor &v) { return v.visit(this); } | 147 | bool accept(Visitor &v) { return v.visit(this); } |
146 | 148 | ||
147 | QDateTime mDtDue; // due date of todo | 149 | QDateTime mDtDue; // due date of todo |
148 | 150 | ||
149 | bool mHasDueDate; // if todo has associated due date | 151 | bool mHasDueDate; // if todo has associated due date |
150 | 152 | ||
151 | // int mStatus; // confirmed/delegated/tentative/etc | 153 | // int mStatus; // confirmed/delegated/tentative/etc |
152 | 154 | ||
153 | QDateTime mCompleted; | 155 | QDateTime mCompleted; |
154 | bool mHasCompletedDate; | 156 | bool mHasCompletedDate; |
155 | 157 | ||
156 | int mPercentComplete; | 158 | int mPercentComplete; |
157 | }; | 159 | }; |
158 | 160 | ||
159 | bool operator==( const Todo&, const Todo& ); | 161 | bool operator==( const Todo&, const Todo& ); |
160 | } | 162 | } |
161 | 163 | ||
162 | #endif | 164 | #endif |
diff --git a/libkcal/vcaldrag.cpp b/libkcal/vcaldrag.cpp index f01f332..324981e 100644 --- a/libkcal/vcaldrag.cpp +++ b/libkcal/vcaldrag.cpp | |||
@@ -1,54 +1,54 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include "vcaldrag.h" | 22 | #include "vcaldrag.h" |
23 | 23 | ||
24 | #include "vcalformat.h" | 24 | #include "vcalformat.h" |
25 | 25 | ||
26 | using namespace KCal; | 26 | using namespace KCal; |
27 | 27 | ||
28 | VCalDrag::VCalDrag( Calendar *cal, QWidget *parent, const char *name ) | 28 | VCalDrag::VCalDrag( Calendar *cal, QWidget *parent, const char *name ) |
29 | : QStoredDrag( "text/x-vCalendar", parent, name ) | 29 | : Q3StoredDrag( "text/x-vCalendar", parent, name ) |
30 | { | 30 | { |
31 | VCalFormat format; | 31 | VCalFormat format; |
32 | setEncodedData( format.toString( cal ).utf8() ); | 32 | setEncodedData( format.toString( cal ).utf8() ); |
33 | } | 33 | } |
34 | 34 | ||
35 | bool VCalDrag::canDecode( QMimeSource *me ) | 35 | bool VCalDrag::canDecode( QMimeSource *me ) |
36 | { | 36 | { |
37 | return me->provides( "text/x-vCalendar" ); | 37 | return me->provides( "text/x-vCalendar" ); |
38 | } | 38 | } |
39 | 39 | ||
40 | bool VCalDrag::decode( QMimeSource *de, Calendar *cal ) | 40 | bool VCalDrag::decode( QMimeSource *de, Calendar *cal ) |
41 | { | 41 | { |
42 | bool success = false; | 42 | bool success = false; |
43 | 43 | ||
44 | QByteArray payload = de->encodedData( "text/x-vCalendar" ); | 44 | QByteArray payload = de->encodedData( "text/x-vCalendar" ); |
45 | if ( payload.size() ) { | 45 | if ( payload.size() ) { |
46 | QString txt = QString::fromUtf8( payload.data() ); | 46 | QString txt = QString::fromUtf8( payload.data() ); |
47 | 47 | ||
48 | VCalFormat format; | 48 | VCalFormat format; |
49 | success = format.fromString( cal, txt ); | 49 | success = format.fromString( cal, txt ); |
50 | } | 50 | } |
51 | 51 | ||
52 | return success; | 52 | return success; |
53 | } | 53 | } |
54 | 54 | ||
diff --git a/libkcal/vcaldrag.h b/libkcal/vcaldrag.h index 3048124..68a320d 100644 --- a/libkcal/vcaldrag.h +++ b/libkcal/vcaldrag.h | |||
@@ -1,47 +1,47 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef VCALDRAG_H | 22 | #ifndef VCALDRAG_H |
23 | #define VCALDRAG_H | 23 | #define VCALDRAG_H |
24 | 24 | ||
25 | #include <qdragobject.h> | 25 | #include <q3dragobject.h> |
26 | 26 | ||
27 | 27 | ||
28 | namespace KCal { | 28 | namespace KCal { |
29 | 29 | ||
30 | class Calendar; | 30 | class Calendar; |
31 | 31 | ||
32 | /** vCalendar drag&drop class. */ | 32 | /** vCalendar drag&drop class. */ |
33 | class VCalDrag : public QStoredDrag { | 33 | class VCalDrag : public Q3StoredDrag { |
34 | public: | 34 | public: |
35 | /** Create a drag&drop object for vCalendar component \a vcal. */ | 35 | /** Create a drag&drop object for vCalendar component \a vcal. */ |
36 | VCalDrag( Calendar *vcal, QWidget *parent = 0, const char *name = 0 ); | 36 | VCalDrag( Calendar *vcal, QWidget *parent = 0, const char *name = 0 ); |
37 | ~VCalDrag() {}; | 37 | ~VCalDrag() {}; |
38 | 38 | ||
39 | /** Return, if drag&drop object can be decode to vCalendar. */ | 39 | /** Return, if drag&drop object can be decode to vCalendar. */ |
40 | static bool canDecode( QMimeSource * ); | 40 | static bool canDecode( QMimeSource * ); |
41 | /** Decode drag&drop object to vCalendar component \a vcal. */ | 41 | /** Decode drag&drop object to vCalendar component \a vcal. */ |
42 | static bool decode( QMimeSource *e, Calendar *cal ); | 42 | static bool decode( QMimeSource *e, Calendar *cal ); |
43 | }; | 43 | }; |
44 | 44 | ||
45 | } | 45 | } |
46 | 46 | ||
47 | #endif | 47 | #endif |
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp index 2e19740..9cbaf16 100644 --- a/libkcal/vcalformat.cpp +++ b/libkcal/vcalformat.cpp | |||
@@ -1,1715 +1,1717 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brwon | 3 | Copyright (c) 1998 Preston Brwon |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <qapplication.h> | 22 | #include <qapplication.h> |
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <q3ptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qclipboard.h> | 27 | #include <qclipboard.h> |
28 | #include <qdialog.h> | 28 | #include <qdialog.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | //Added by qt3to4: | ||
31 | #include <Q3CString> | ||
30 | 32 | ||
31 | #include <kdebug.h> | 33 | #include <kdebug.h> |
32 | #include <kglobal.h> | 34 | #include <kglobal.h> |
33 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
34 | #include <kiconloader.h> | 36 | #include <kiconloader.h> |
35 | #include <klocale.h> | 37 | #include <klocale.h> |
36 | 38 | ||
37 | #include "vcc.h" | 39 | #include "vcc.h" |
38 | #include "vobject.h" | 40 | #include "vobject.h" |
39 | 41 | ||
40 | #include "vcaldrag.h" | 42 | #include "vcaldrag.h" |
41 | #include "calendar.h" | 43 | #include "calendar.h" |
42 | 44 | ||
43 | #include "vcalformat.h" | 45 | #include "vcalformat.h" |
44 | 46 | ||
45 | using namespace KCal; | 47 | using namespace KCal; |
46 | 48 | ||
47 | VCalFormat::VCalFormat() | 49 | VCalFormat::VCalFormat() |
48 | { | 50 | { |
49 | mCalendar = 0; | 51 | mCalendar = 0; |
50 | useLocalTime = false; | 52 | useLocalTime = false; |
51 | } | 53 | } |
52 | 54 | ||
53 | VCalFormat::~VCalFormat() | 55 | VCalFormat::~VCalFormat() |
54 | { | 56 | { |
55 | } | 57 | } |
56 | 58 | ||
57 | void VCalFormat::setLocalTime ( bool b ) | 59 | void VCalFormat::setLocalTime ( bool b ) |
58 | { | 60 | { |
59 | useLocalTime = b; | 61 | useLocalTime = b; |
60 | } | 62 | } |
61 | bool VCalFormat::load(Calendar *calendar, const QString &fileName) | 63 | bool VCalFormat::load(Calendar *calendar, const QString &fileName) |
62 | { | 64 | { |
63 | mCalendar = calendar; | 65 | mCalendar = calendar; |
64 | clearException(); | 66 | clearException(); |
65 | if ( ! useLocalTime ) | 67 | if ( ! useLocalTime ) |
66 | useLocalTime = mCalendar->isLocalTime(); | 68 | useLocalTime = mCalendar->isLocalTime(); |
67 | VObject *vcal = 0; | 69 | VObject *vcal = 0; |
68 | 70 | ||
69 | // this is not necessarily only 1 vcal. Could be many vcals, or include | 71 | // this is not necessarily only 1 vcal. Could be many vcals, or include |
70 | // a vcard... | 72 | // a vcard... |
71 | vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); | 73 | vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); |
72 | 74 | ||
73 | if (!vcal) { | 75 | if (!vcal) { |
74 | setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 76 | setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
75 | return FALSE; | 77 | return FALSE; |
76 | } | 78 | } |
77 | 79 | ||
78 | // any other top-level calendar stuff should be added/initialized here | 80 | // any other top-level calendar stuff should be added/initialized here |
79 | 81 | ||
80 | // put all vobjects into their proper places | 82 | // put all vobjects into their proper places |
81 | populate(vcal); | 83 | populate(vcal); |
82 | 84 | ||
83 | // clean up from vcal API stuff | 85 | // clean up from vcal API stuff |
84 | cleanVObjects(vcal); | 86 | cleanVObjects(vcal); |
85 | cleanStrTbl(); | 87 | cleanStrTbl(); |
86 | 88 | ||
87 | return true; | 89 | return true; |
88 | } | 90 | } |
89 | 91 | ||
90 | 92 | ||
91 | bool VCalFormat::save(Calendar *calendar, const QString &fileName) | 93 | bool VCalFormat::save(Calendar *calendar, const QString &fileName) |
92 | { | 94 | { |
93 | mCalendar = calendar; | 95 | mCalendar = calendar; |
94 | if ( ! useLocalTime ) | 96 | if ( ! useLocalTime ) |
95 | useLocalTime = mCalendar->isLocalTime(); | 97 | useLocalTime = mCalendar->isLocalTime(); |
96 | 98 | ||
97 | QString tmpStr; | 99 | QString tmpStr; |
98 | VObject *vcal, *vo; | 100 | VObject *vcal, *vo; |
99 | 101 | ||
100 | 102 | ||
101 | vcal = newVObject(VCCalProp); | 103 | vcal = newVObject(VCCalProp); |
102 | 104 | ||
103 | // addPropValue(vcal,VCLocationProp, "0.0"); | 105 | // addPropValue(vcal,VCLocationProp, "0.0"); |
104 | addPropValue(vcal,VCProdIdProp, productId()); | 106 | addPropValue(vcal,VCProdIdProp, productId()); |
105 | tmpStr = mCalendar->getTimeZoneStr(); | 107 | tmpStr = mCalendar->getTimeZoneStr(); |
106 | //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); | 108 | //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); |
107 | addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); | 109 | addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); |
108 | addPropValue(vcal,VCVersionProp, _VCAL_VERSION); | 110 | addPropValue(vcal,VCVersionProp, _VCAL_VERSION); |
109 | 111 | ||
110 | // TODO STUFF | 112 | // TODO STUFF |
111 | QPtrList<Todo> todoList = mCalendar->rawTodos(); | 113 | Q3PtrList<Todo> todoList = mCalendar->rawTodos(); |
112 | QPtrListIterator<Todo> qlt(todoList); | 114 | Q3PtrListIterator<Todo> qlt(todoList); |
113 | for (; qlt.current(); ++qlt) { | 115 | for (; qlt.current(); ++qlt) { |
114 | vo = eventToVTodo(qlt.current()); | 116 | vo = eventToVTodo(qlt.current()); |
115 | addVObjectProp(vcal, vo); | 117 | addVObjectProp(vcal, vo); |
116 | } | 118 | } |
117 | 119 | ||
118 | // EVENT STUFF | 120 | // EVENT STUFF |
119 | QPtrList<Event> events = mCalendar->rawEvents(); | 121 | Q3PtrList<Event> events = mCalendar->rawEvents(); |
120 | Event *ev; | 122 | Event *ev; |
121 | for(ev=events.first();ev;ev=events.next()) { | 123 | for(ev=events.first();ev;ev=events.next()) { |
122 | vo = eventToVEvent(ev); | 124 | vo = eventToVEvent(ev); |
123 | addVObjectProp(vcal, vo); | 125 | addVObjectProp(vcal, vo); |
124 | } | 126 | } |
125 | 127 | ||
126 | writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); | 128 | writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); |
127 | cleanVObjects(vcal); | 129 | cleanVObjects(vcal); |
128 | cleanStrTbl(); | 130 | cleanStrTbl(); |
129 | 131 | ||
130 | if (QFile::exists(fileName)) { | 132 | if (QFile::exists(fileName)) { |
131 | return true; | 133 | return true; |
132 | } else { | 134 | } else { |
133 | return false; // error | 135 | return false; // error |
134 | } | 136 | } |
135 | } | 137 | } |
136 | 138 | ||
137 | bool VCalFormat::fromString( Calendar *calendar, const QString &text ) | 139 | bool VCalFormat::fromString( Calendar *calendar, const QString &text ) |
138 | { | 140 | { |
139 | // TODO: Factor out VCalFormat::fromString() | 141 | // TODO: Factor out VCalFormat::fromString() |
140 | 142 | ||
141 | QCString data = text.utf8(); | 143 | Q3CString data = text.utf8(); |
142 | 144 | ||
143 | if ( !data.size() ) return false; | 145 | if ( !data.size() ) return false; |
144 | 146 | ||
145 | VObject *vcal = Parse_MIME( data.data(), data.size()); | 147 | VObject *vcal = Parse_MIME( data.data(), data.size()); |
146 | if ( !vcal ) return false; | 148 | if ( !vcal ) return false; |
147 | 149 | ||
148 | VObjectIterator i; | 150 | VObjectIterator i; |
149 | VObject *curvo; | 151 | VObject *curvo; |
150 | initPropIterator( &i, vcal ); | 152 | initPropIterator( &i, vcal ); |
151 | 153 | ||
152 | // we only take the first object. TODO: parse all incidences. | 154 | // we only take the first object. TODO: parse all incidences. |
153 | do { | 155 | do { |
154 | curvo = nextVObject( &i ); | 156 | curvo = nextVObject( &i ); |
155 | } while ( strcmp( vObjectName( curvo ), VCEventProp ) && | 157 | } while ( strcmp( vObjectName( curvo ), VCEventProp ) && |
156 | strcmp( vObjectName( curvo ), VCTodoProp ) ); | 158 | strcmp( vObjectName( curvo ), VCTodoProp ) ); |
157 | 159 | ||
158 | if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { | 160 | if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { |
159 | Event *event = VEventToEvent( curvo ); | 161 | Event *event = VEventToEvent( curvo ); |
160 | calendar->addEvent( event ); | 162 | calendar->addEvent( event ); |
161 | } else { | 163 | } else { |
162 | qDebug("VCalFormat::fromString(): Unknown object type. "); | 164 | qDebug("VCalFormat::fromString(): Unknown object type. "); |
163 | deleteVObject( vcal ); | 165 | deleteVObject( vcal ); |
164 | return false; | 166 | return false; |
165 | } | 167 | } |
166 | 168 | ||
167 | deleteVObject( vcal ); | 169 | deleteVObject( vcal ); |
168 | 170 | ||
169 | return true; | 171 | return true; |
170 | } | 172 | } |
171 | 173 | ||
172 | QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal) | 174 | QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal) |
173 | { | 175 | { |
174 | 176 | ||
175 | if ( !event ) return QString::null; | 177 | if ( !event ) return QString::null; |
176 | bool useL = useLocalTime; | 178 | bool useL = useLocalTime; |
177 | useLocalTime = useLocal; | 179 | useLocalTime = useLocal; |
178 | mCalendar = calendar; | 180 | mCalendar = calendar; |
179 | VObject *vevent = eventToVEvent( event ); | 181 | VObject *vevent = eventToVEvent( event ); |
180 | char *buf = writeMemVObject( 0, 0, vevent ); | 182 | char *buf = writeMemVObject( 0, 0, vevent ); |
181 | QString result( buf ); | 183 | QString result( buf ); |
182 | cleanVObject( vevent ); | 184 | cleanVObject( vevent ); |
183 | useLocalTime = useL; | 185 | useLocalTime = useL; |
184 | return result; | 186 | return result; |
185 | } | 187 | } |
186 | QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal ) | 188 | QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal ) |
187 | { | 189 | { |
188 | 190 | ||
189 | if ( !todo ) return QString::null; | 191 | if ( !todo ) return QString::null; |
190 | bool useL = useLocalTime; | 192 | bool useL = useLocalTime; |
191 | useLocalTime = useLocal; | 193 | useLocalTime = useLocal; |
192 | mCalendar = calendar; | 194 | mCalendar = calendar; |
193 | VObject *vevent = eventToVTodo( todo ); | 195 | VObject *vevent = eventToVTodo( todo ); |
194 | char *buf = writeMemVObject( 0, 0, vevent ); | 196 | char *buf = writeMemVObject( 0, 0, vevent ); |
195 | QString result( buf ); | 197 | QString result( buf ); |
196 | cleanVObject( vevent ); | 198 | cleanVObject( vevent ); |
197 | useLocalTime = useL; | 199 | useLocalTime = useL; |
198 | return result; | 200 | return result; |
199 | } | 201 | } |
200 | 202 | ||
201 | QString VCalFormat::toString( Calendar *calendar ) | 203 | QString VCalFormat::toString( Calendar *calendar ) |
202 | { | 204 | { |
203 | // TODO: Factor out VCalFormat::asString() | 205 | // TODO: Factor out VCalFormat::asString() |
204 | 206 | ||
205 | VObject *vcal = newVObject(VCCalProp); | 207 | VObject *vcal = newVObject(VCCalProp); |
206 | 208 | ||
207 | addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); | 209 | addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); |
208 | QString tmpStr = mCalendar->getTimeZoneStr(); | 210 | QString tmpStr = mCalendar->getTimeZoneStr(); |
209 | addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); | 211 | addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); |
210 | addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); | 212 | addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); |
211 | 213 | ||
212 | // TODO: Use all data. | 214 | // TODO: Use all data. |
213 | QPtrList<Event> events = calendar->events(); | 215 | Q3PtrList<Event> events = calendar->events(); |
214 | Event *event = events.first(); | 216 | Event *event = events.first(); |
215 | if ( !event ) return QString::null; | 217 | if ( !event ) return QString::null; |
216 | 218 | ||
217 | VObject *vevent = eventToVEvent( event ); | 219 | VObject *vevent = eventToVEvent( event ); |
218 | 220 | ||
219 | addVObjectProp( vcal, vevent ); | 221 | addVObjectProp( vcal, vevent ); |
220 | 222 | ||
221 | char *buf = writeMemVObject( 0, 0, vcal ); | 223 | char *buf = writeMemVObject( 0, 0, vcal ); |
222 | 224 | ||
223 | QString result( buf ); | 225 | QString result( buf ); |
224 | 226 | ||
225 | cleanVObject( vcal ); | 227 | cleanVObject( vcal ); |
226 | 228 | ||
227 | return result; | 229 | return result; |
228 | } | 230 | } |
229 | 231 | ||
230 | VObject *VCalFormat::eventToVTodo(const Todo *anEvent) | 232 | VObject *VCalFormat::eventToVTodo(const Todo *anEvent) |
231 | { | 233 | { |
232 | VObject *vtodo; | 234 | VObject *vtodo; |
233 | QString tmpStr; | 235 | QString tmpStr; |
234 | 236 | ||
235 | 237 | ||
236 | vtodo = newVObject(VCTodoProp); | 238 | vtodo = newVObject(VCTodoProp); |
237 | 239 | ||
238 | // due date | 240 | // due date |
239 | if (anEvent->hasDueDate()) { | 241 | if (anEvent->hasDueDate()) { |
240 | tmpStr = qDateTimeToISO(anEvent->dtDue(), | 242 | tmpStr = qDateTimeToISO(anEvent->dtDue(), |
241 | !anEvent->doesFloat()); | 243 | !anEvent->doesFloat()); |
242 | addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); | 244 | addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); |
243 | } | 245 | } |
244 | 246 | ||
245 | // start date | 247 | // start date |
246 | if (anEvent->hasStartDate()) { | 248 | if (anEvent->hasStartDate()) { |
247 | tmpStr = qDateTimeToISO(anEvent->dtStart(), | 249 | tmpStr = qDateTimeToISO(anEvent->dtStart(), |
248 | !anEvent->doesFloat()); | 250 | !anEvent->doesFloat()); |
249 | addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); | 251 | addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); |
250 | } | 252 | } |
251 | 253 | ||
252 | // creation date | 254 | // creation date |
253 | tmpStr = qDateTimeToISO(anEvent->created()); | 255 | tmpStr = qDateTimeToISO(anEvent->created()); |
254 | addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); | 256 | addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); |
255 | 257 | ||
256 | // unique id | 258 | // unique id |
257 | addPropValue(vtodo, VCUniqueStringProp, | 259 | addPropValue(vtodo, VCUniqueStringProp, |
258 | anEvent->uid().local8Bit()); | 260 | anEvent->uid().local8Bit()); |
259 | 261 | ||
260 | // revision | 262 | // revision |
261 | tmpStr.sprintf("%i", anEvent->revision()); | 263 | tmpStr.sprintf("%i", anEvent->revision()); |
262 | addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); | 264 | addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); |
263 | 265 | ||
264 | // last modification date | 266 | // last modification date |
265 | tmpStr = qDateTimeToISO(anEvent->lastModified()); | 267 | tmpStr = qDateTimeToISO(anEvent->lastModified()); |
266 | addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); | 268 | addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); |
267 | 269 | ||
268 | // organizer stuff | 270 | // organizer stuff |
269 | tmpStr = "MAILTO:" + anEvent->organizer(); | 271 | tmpStr = "MAILTO:" + anEvent->organizer(); |
270 | addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); | 272 | addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); |
271 | 273 | ||
272 | // attendees | 274 | // attendees |
273 | if (anEvent->attendeeCount() != 0) { | 275 | if (anEvent->attendeeCount() != 0) { |
274 | QPtrList<Attendee> al = anEvent->attendees(); | 276 | Q3PtrList<Attendee> al = anEvent->attendees(); |
275 | QPtrListIterator<Attendee> ai(al); | 277 | Q3PtrListIterator<Attendee> ai(al); |
276 | Attendee *curAttendee; | 278 | Attendee *curAttendee; |
277 | 279 | ||
278 | for (; ai.current(); ++ai) { | 280 | for (; ai.current(); ++ai) { |
279 | curAttendee = ai.current(); | 281 | curAttendee = ai.current(); |
280 | if (!curAttendee->email().isEmpty() && | 282 | if (!curAttendee->email().isEmpty() && |
281 | !curAttendee->name().isEmpty()) | 283 | !curAttendee->name().isEmpty()) |
282 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + | 284 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + |
283 | curAttendee->email() + ">"; | 285 | curAttendee->email() + ">"; |
284 | else if (curAttendee->name().isEmpty()) | 286 | else if (curAttendee->name().isEmpty()) |
285 | tmpStr = "MAILTO: " + curAttendee->email(); | 287 | tmpStr = "MAILTO: " + curAttendee->email(); |
286 | else if (curAttendee->email().isEmpty()) | 288 | else if (curAttendee->email().isEmpty()) |
287 | tmpStr = "MAILTO: " + curAttendee->name(); | 289 | tmpStr = "MAILTO: " + curAttendee->name(); |
288 | else if (curAttendee->name().isEmpty() && | 290 | else if (curAttendee->name().isEmpty() && |
289 | curAttendee->email().isEmpty()) | 291 | curAttendee->email().isEmpty()) |
290 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; | 292 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; |
291 | VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); | 293 | VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); |
292 | addPropValue(aProp, VCRoleProp, writeRole(curAttendee->role())); | 294 | addPropValue(aProp, VCRoleProp, writeRole(curAttendee->role())); |
293 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); | 295 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); |
294 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); | 296 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); |
295 | } | 297 | } |
296 | } | 298 | } |
297 | 299 | ||
298 | // description BL: | 300 | // description BL: |
299 | if (!anEvent->description().isEmpty()) { | 301 | if (!anEvent->description().isEmpty()) { |
300 | VObject *d = addPropValue(vtodo, VCDescriptionProp, | 302 | VObject *d = addPropValue(vtodo, VCDescriptionProp, |
301 | anEvent->description().local8Bit()); | 303 | anEvent->description().local8Bit()); |
302 | if (anEvent->description().find('\n') != -1) | 304 | if (anEvent->description().find('\n') != -1) |
303 | addProp(d, VCQuotedPrintableProp); | 305 | addProp(d, VCQuotedPrintableProp); |
304 | } | 306 | } |
305 | 307 | ||
306 | // summary | 308 | // summary |
307 | if (!anEvent->summary().isEmpty()) | 309 | if (!anEvent->summary().isEmpty()) |
308 | addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); | 310 | addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); |
309 | 311 | ||
310 | if (!anEvent->location().isEmpty()) | 312 | if (!anEvent->location().isEmpty()) |
311 | addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); | 313 | addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); |
312 | 314 | ||
313 | // completed | 315 | // completed |
314 | // status | 316 | // status |
315 | // backward compatibility, KOrganizer used to interpret only these two values | 317 | // backward compatibility, KOrganizer used to interpret only these two values |
316 | addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : | 318 | addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : |
317 | "NEEDS_ACTION"); | 319 | "NEEDS_ACTION"); |
318 | // completion date | 320 | // completion date |
319 | if (anEvent->hasCompletedDate()) { | 321 | if (anEvent->hasCompletedDate()) { |
320 | tmpStr = qDateTimeToISO(anEvent->completed()); | 322 | tmpStr = qDateTimeToISO(anEvent->completed()); |
321 | addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); | 323 | addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); |
322 | } | 324 | } |
323 | 325 | ||
324 | // priority | 326 | // priority |
325 | tmpStr.sprintf("%i",anEvent->priority()); | 327 | tmpStr.sprintf("%i",anEvent->priority()); |
326 | addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); | 328 | addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); |
327 | 329 | ||
328 | // related event | 330 | // related event |
329 | if (anEvent->relatedToUid()) { | 331 | if (!anEvent->relatedToUid().isEmpty()) { |
330 | addPropValue(vtodo, VCRelatedToProp, | 332 | addPropValue(vtodo, VCRelatedToProp, |
331 | anEvent->relatedToUid().local8Bit()); | 333 | anEvent->relatedToUid().local8Bit()); |
332 | } | 334 | } |
333 | 335 | ||
334 | // categories | 336 | // categories |
335 | QStringList tmpStrList = anEvent->categories(); | 337 | QStringList tmpStrList = anEvent->categories(); |
336 | tmpStr = ""; | 338 | tmpStr = ""; |
337 | QString catStr; | 339 | QString catStr; |
338 | for ( QStringList::Iterator it = tmpStrList.begin(); | 340 | for ( QStringList::Iterator it = tmpStrList.begin(); |
339 | it != tmpStrList.end(); | 341 | it != tmpStrList.end(); |
340 | ++it ) { | 342 | ++it ) { |
341 | catStr = *it; | 343 | catStr = *it; |
342 | if (catStr[0] == ' ') | 344 | if (catStr[0] == ' ') |
343 | tmpStr += catStr.mid(1); | 345 | tmpStr += catStr.mid(1); |
344 | else | 346 | else |
345 | tmpStr += catStr; | 347 | tmpStr += catStr; |
346 | // this must be a ';' character as the vCalendar specification requires! | 348 | // this must be a ';' character as the vCalendar specification requires! |
347 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 349 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
348 | // read in. | 350 | // read in. |
349 | tmpStr += ";"; | 351 | tmpStr += ";"; |
350 | } | 352 | } |
351 | if (!tmpStr.isEmpty()) { | 353 | if (!tmpStr.isEmpty()) { |
352 | tmpStr.truncate(tmpStr.length()-1); | 354 | tmpStr.truncate(tmpStr.length()-1); |
353 | addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); | 355 | addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); |
354 | } | 356 | } |
355 | 357 | ||
356 | // alarm stuff | 358 | // alarm stuff |
357 | kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; | 359 | kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; |
358 | QPtrList<Alarm> alarms = anEvent->alarms(); | 360 | Q3PtrList<Alarm> alarms = anEvent->alarms(); |
359 | Alarm* alarm; | 361 | Alarm* alarm; |
360 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 362 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
361 | if (alarm->enabled()) { | 363 | if (alarm->enabled()) { |
362 | VObject *a; | 364 | VObject *a; |
363 | tmpStr = qDateTimeToISO(alarm->time()); | 365 | tmpStr = qDateTimeToISO(alarm->time()); |
364 | if (alarm->type() == Alarm::Audio) { | 366 | if (alarm->type() == Alarm::Audio) { |
365 | a = addProp(vtodo, VCAAlarmProp); | 367 | a = addProp(vtodo, VCAAlarmProp); |
366 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 368 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
367 | addPropValue(a, VCRepeatCountProp, "1"); | 369 | addPropValue(a, VCRepeatCountProp, "1"); |
368 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); | 370 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); |
369 | } | 371 | } |
370 | else if (alarm->type() == Alarm::Procedure) { | 372 | else if (alarm->type() == Alarm::Procedure) { |
371 | a = addProp(vtodo, VCPAlarmProp); | 373 | a = addProp(vtodo, VCPAlarmProp); |
372 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 374 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
373 | addPropValue(a, VCRepeatCountProp, "1"); | 375 | addPropValue(a, VCRepeatCountProp, "1"); |
374 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); | 376 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); |
375 | } else { | 377 | } else { |
376 | a = addProp(vtodo, VCDAlarmProp); | 378 | a = addProp(vtodo, VCDAlarmProp); |
377 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 379 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
378 | addPropValue(a, VCRepeatCountProp, "1"); | 380 | addPropValue(a, VCRepeatCountProp, "1"); |
379 | addPropValue(a, VCDisplayStringProp, "beep!"); | 381 | addPropValue(a, VCDisplayStringProp, "beep!"); |
380 | } | 382 | } |
381 | } | 383 | } |
382 | } | 384 | } |
383 | 385 | ||
384 | if (anEvent->pilotId()) { | 386 | if (anEvent->pilotId()) { |
385 | // pilot sync stuff | 387 | // pilot sync stuff |
386 | tmpStr.sprintf("%i",anEvent->pilotId()); | 388 | tmpStr.sprintf("%i",anEvent->pilotId()); |
387 | addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); | 389 | addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); |
388 | tmpStr.sprintf("%i",anEvent->syncStatus()); | 390 | tmpStr.sprintf("%i",anEvent->syncStatus()); |
389 | addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); | 391 | addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); |
390 | } | 392 | } |
391 | 393 | ||
392 | return vtodo; | 394 | return vtodo; |
393 | } | 395 | } |
394 | 396 | ||
395 | VObject* VCalFormat::eventToVEvent(Event *anEvent) | 397 | VObject* VCalFormat::eventToVEvent(Event *anEvent) |
396 | { | 398 | { |
397 | VObject *vevent; | 399 | VObject *vevent; |
398 | QString tmpStr; | 400 | QString tmpStr; |
399 | 401 | ||
400 | vevent = newVObject(VCEventProp); | 402 | vevent = newVObject(VCEventProp); |
401 | 403 | ||
402 | // start and end time | 404 | // start and end time |
403 | tmpStr = qDateTimeToISO(anEvent->dtStart(), | 405 | tmpStr = qDateTimeToISO(anEvent->dtStart(), |
404 | !anEvent->doesFloat()); | 406 | !anEvent->doesFloat()); |
405 | addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); | 407 | addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); |
406 | 408 | ||
407 | // events that have time associated but take up no time should | 409 | // events that have time associated but take up no time should |
408 | // not have both DTSTART and DTEND. | 410 | // not have both DTSTART and DTEND. |
409 | if (anEvent->dtStart() != anEvent->dtEnd()) { | 411 | if (anEvent->dtStart() != anEvent->dtEnd()) { |
410 | tmpStr = qDateTimeToISO(anEvent->dtEnd(), | 412 | tmpStr = qDateTimeToISO(anEvent->dtEnd(), |
411 | !anEvent->doesFloat()); | 413 | !anEvent->doesFloat()); |
412 | addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); | 414 | addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); |
413 | } | 415 | } |
414 | 416 | ||
415 | // creation date | 417 | // creation date |
416 | tmpStr = qDateTimeToISO(anEvent->created()); | 418 | tmpStr = qDateTimeToISO(anEvent->created()); |
417 | addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); | 419 | addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); |
418 | 420 | ||
419 | // unique id | 421 | // unique id |
420 | addPropValue(vevent, VCUniqueStringProp, | 422 | addPropValue(vevent, VCUniqueStringProp, |
421 | anEvent->uid().local8Bit()); | 423 | anEvent->uid().local8Bit()); |
422 | 424 | ||
423 | // revision | 425 | // revision |
424 | tmpStr.sprintf("%i", anEvent->revision()); | 426 | tmpStr.sprintf("%i", anEvent->revision()); |
425 | addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); | 427 | addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); |
426 | 428 | ||
427 | // last modification date | 429 | // last modification date |
428 | tmpStr = qDateTimeToISO(anEvent->lastModified()); | 430 | tmpStr = qDateTimeToISO(anEvent->lastModified()); |
429 | addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); | 431 | addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); |
430 | 432 | ||
431 | // attendee and organizer stuff | 433 | // attendee and organizer stuff |
432 | tmpStr = "MAILTO:" + anEvent->organizer(); | 434 | tmpStr = "MAILTO:" + anEvent->organizer(); |
433 | addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); | 435 | addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); |
434 | 436 | ||
435 | if (anEvent->attendeeCount() != 0) { | 437 | if (anEvent->attendeeCount() != 0) { |
436 | QPtrList<Attendee> al = anEvent->attendees(); | 438 | Q3PtrList<Attendee> al = anEvent->attendees(); |
437 | QPtrListIterator<Attendee> ai(al); | 439 | Q3PtrListIterator<Attendee> ai(al); |
438 | Attendee *curAttendee; | 440 | Attendee *curAttendee; |
439 | 441 | ||
440 | // TODO: Put this functionality into Attendee class | 442 | // TODO: Put this functionality into Attendee class |
441 | for (; ai.current(); ++ai) { | 443 | for (; ai.current(); ++ai) { |
442 | curAttendee = ai.current(); | 444 | curAttendee = ai.current(); |
443 | if (!curAttendee->email().isEmpty() && | 445 | if (!curAttendee->email().isEmpty() && |
444 | !curAttendee->name().isEmpty()) | 446 | !curAttendee->name().isEmpty()) |
445 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + | 447 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + |
446 | curAttendee->email() + ">"; | 448 | curAttendee->email() + ">"; |
447 | else if (curAttendee->name().isEmpty()) | 449 | else if (curAttendee->name().isEmpty()) |
448 | tmpStr = "MAILTO: " + curAttendee->email(); | 450 | tmpStr = "MAILTO: " + curAttendee->email(); |
449 | else if (curAttendee->email().isEmpty()) | 451 | else if (curAttendee->email().isEmpty()) |
450 | tmpStr = "MAILTO: " + curAttendee->name(); | 452 | tmpStr = "MAILTO: " + curAttendee->name(); |
451 | else if (curAttendee->name().isEmpty() && | 453 | else if (curAttendee->name().isEmpty() && |
452 | curAttendee->email().isEmpty()) | 454 | curAttendee->email().isEmpty()) |
453 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; | 455 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; |
454 | VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); | 456 | VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); |
455 | addPropValue(aProp, VCRoleProp, writeRole(curAttendee->role())); | 457 | addPropValue(aProp, VCRoleProp, writeRole(curAttendee->role())); |
456 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); | 458 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); |
457 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); | 459 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); |
458 | } | 460 | } |
459 | } | 461 | } |
460 | 462 | ||
461 | // recurrence rule stuff | 463 | // recurrence rule stuff |
462 | if (anEvent->doesRecur()) { | 464 | if (anEvent->doesRecur()) { |
463 | // some more variables | 465 | // some more variables |
464 | QPtrList<Recurrence::rMonthPos> tmpPositions; | 466 | Q3PtrList<Recurrence::rMonthPos> tmpPositions; |
465 | QPtrList<int> tmpDays; | 467 | Q3PtrList<int> tmpDays; |
466 | int *tmpDay; | 468 | int *tmpDay; |
467 | Recurrence::rMonthPos *tmpPos; | 469 | Recurrence::rMonthPos *tmpPos; |
468 | QString tmpStr2; | 470 | QString tmpStr2; |
469 | int i; | 471 | int i; |
470 | 472 | ||
471 | switch(anEvent->recurrence()->doesRecur()) { | 473 | switch(anEvent->recurrence()->doesRecur()) { |
472 | case Recurrence::rDaily: | 474 | case Recurrence::rDaily: |
473 | tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); | 475 | tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); |
474 | // if (anEvent->rDuration > 0) | 476 | // if (anEvent->rDuration > 0) |
475 | //tmpStr += "#"; | 477 | //tmpStr += "#"; |
476 | break; | 478 | break; |
477 | case Recurrence::rWeekly: | 479 | case Recurrence::rWeekly: |
478 | tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); | 480 | tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); |
479 | for (i = 0; i < 7; i++) { | 481 | for (i = 0; i < 7; i++) { |
480 | if (anEvent->recurrence()->days().testBit(i)) | 482 | if (anEvent->recurrence()->days().testBit(i)) |
481 | tmpStr += dayFromNum(i); | 483 | tmpStr += dayFromNum(i); |
482 | } | 484 | } |
483 | break; | 485 | break; |
484 | case Recurrence::rMonthlyPos: | 486 | case Recurrence::rMonthlyPos: |
485 | tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); | 487 | tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); |
486 | // write out all rMonthPos's | 488 | // write out all rMonthPos's |
487 | tmpPositions = anEvent->recurrence()->monthPositions(); | 489 | tmpPositions = anEvent->recurrence()->monthPositions(); |
488 | for (tmpPos = tmpPositions.first(); | 490 | for (tmpPos = tmpPositions.first(); |
489 | tmpPos; | 491 | tmpPos; |
490 | tmpPos = tmpPositions.next()) { | 492 | tmpPos = tmpPositions.next()) { |
491 | 493 | ||
492 | tmpStr2.sprintf("%i", tmpPos->rPos); | 494 | tmpStr2.sprintf("%i", tmpPos->rPos); |
493 | if (tmpPos->negative) | 495 | if (tmpPos->negative) |
494 | tmpStr2 += "- "; | 496 | tmpStr2 += "- "; |
495 | else | 497 | else |
496 | tmpStr2 += "+ "; | 498 | tmpStr2 += "+ "; |
497 | tmpStr += tmpStr2; | 499 | tmpStr += tmpStr2; |
498 | for (i = 0; i < 7; i++) { | 500 | for (i = 0; i < 7; i++) { |
499 | if (tmpPos->rDays.testBit(i)) | 501 | if (tmpPos->rDays.testBit(i)) |
500 | tmpStr += dayFromNum(i); | 502 | tmpStr += dayFromNum(i); |
501 | } | 503 | } |
502 | } // loop for all rMonthPos's | 504 | } // loop for all rMonthPos's |
503 | break; | 505 | break; |
504 | case Recurrence::rMonthlyDay: | 506 | case Recurrence::rMonthlyDay: |
505 | tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); | 507 | tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); |
506 | // write out all rMonthDays; | 508 | // write out all rMonthDays; |
507 | tmpDays = anEvent->recurrence()->monthDays(); | 509 | tmpDays = anEvent->recurrence()->monthDays(); |
508 | for (tmpDay = tmpDays.first(); | 510 | for (tmpDay = tmpDays.first(); |
509 | tmpDay; | 511 | tmpDay; |
510 | tmpDay = tmpDays.next()) { | 512 | tmpDay = tmpDays.next()) { |
511 | tmpStr2.sprintf("%i ", *tmpDay); | 513 | tmpStr2.sprintf("%i ", *tmpDay); |
512 | tmpStr += tmpStr2; | 514 | tmpStr += tmpStr2; |
513 | } | 515 | } |
514 | break; | 516 | break; |
515 | case Recurrence::rYearlyMonth: | 517 | case Recurrence::rYearlyMonth: |
516 | tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); | 518 | tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); |
517 | // write out all the rYearNums; | 519 | // write out all the rYearNums; |
518 | tmpDays = anEvent->recurrence()->yearNums(); | 520 | tmpDays = anEvent->recurrence()->yearNums(); |
519 | for (tmpDay = tmpDays.first(); | 521 | for (tmpDay = tmpDays.first(); |
520 | tmpDay; | 522 | tmpDay; |
521 | tmpDay = tmpDays.next()) { | 523 | tmpDay = tmpDays.next()) { |
522 | tmpStr2.sprintf("%i ", *tmpDay); | 524 | tmpStr2.sprintf("%i ", *tmpDay); |
523 | tmpStr += tmpStr2; | 525 | tmpStr += tmpStr2; |
524 | } | 526 | } |
525 | break; | 527 | break; |
526 | case Recurrence::rYearlyDay: | 528 | case Recurrence::rYearlyDay: |
527 | tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); | 529 | tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); |
528 | // write out all the rYearNums; | 530 | // write out all the rYearNums; |
529 | tmpDays = anEvent->recurrence()->yearNums(); | 531 | tmpDays = anEvent->recurrence()->yearNums(); |
530 | for (tmpDay = tmpDays.first(); | 532 | for (tmpDay = tmpDays.first(); |
531 | tmpDay; | 533 | tmpDay; |
532 | tmpDay = tmpDays.next()) { | 534 | tmpDay = tmpDays.next()) { |
533 | tmpStr2.sprintf("%i ", *tmpDay); | 535 | tmpStr2.sprintf("%i ", *tmpDay); |
534 | tmpStr += tmpStr2; | 536 | tmpStr += tmpStr2; |
535 | } | 537 | } |
536 | break; | 538 | break; |
537 | default: | 539 | default: |
538 | kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; | 540 | kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; |
539 | break; | 541 | break; |
540 | } // switch | 542 | } // switch |
541 | 543 | ||
542 | if (anEvent->recurrence()->duration() > 0) { | 544 | if (anEvent->recurrence()->duration() > 0) { |
543 | tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); | 545 | tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); |
544 | tmpStr += tmpStr2; | 546 | tmpStr += tmpStr2; |
545 | } else if (anEvent->recurrence()->duration() == -1) { | 547 | } else if (anEvent->recurrence()->duration() == -1) { |
546 | tmpStr += "#0"; // defined as repeat forever | 548 | tmpStr += "#0"; // defined as repeat forever |
547 | } else { | 549 | } else { |
548 | tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); | 550 | tmpStr += qDateTimeToISO((QDateTime)anEvent->recurrence()->endDate(), FALSE); |
549 | } | 551 | } |
550 | addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); | 552 | addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); |
551 | 553 | ||
552 | } // event repeats | 554 | } // event repeats |
553 | 555 | ||
554 | // exceptions to recurrence | 556 | // exceptions to recurrence |
555 | DateList dateList = anEvent->exDates(); | 557 | DateList dateList = anEvent->exDates(); |
556 | DateList::ConstIterator it; | 558 | DateList::ConstIterator it; |
557 | QString tmpStr2; | 559 | QString tmpStr2; |
558 | 560 | ||
559 | for (it = dateList.begin(); it != dateList.end(); ++it) { | 561 | for (it = dateList.begin(); it != dateList.end(); ++it) { |
560 | tmpStr = qDateToISO(*it) + ";"; | 562 | tmpStr = qDateToISO(*it) + ";"; |
561 | tmpStr2 += tmpStr; | 563 | tmpStr2 += tmpStr; |
562 | } | 564 | } |
563 | if (!tmpStr2.isEmpty()) { | 565 | if (!tmpStr2.isEmpty()) { |
564 | tmpStr2.truncate(tmpStr2.length()-1); | 566 | tmpStr2.truncate(tmpStr2.length()-1); |
565 | addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); | 567 | addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); |
566 | } | 568 | } |
567 | 569 | ||
568 | // description | 570 | // description |
569 | if (!anEvent->description().isEmpty()) { | 571 | if (!anEvent->description().isEmpty()) { |
570 | VObject *d = addPropValue(vevent, VCDescriptionProp, | 572 | VObject *d = addPropValue(vevent, VCDescriptionProp, |
571 | anEvent->description().local8Bit()); | 573 | anEvent->description().local8Bit()); |
572 | if (anEvent->description().find('\n') != -1) | 574 | if (anEvent->description().find('\n') != -1) |
573 | addProp(d, VCQuotedPrintableProp); | 575 | addProp(d, VCQuotedPrintableProp); |
574 | } | 576 | } |
575 | 577 | ||
576 | // summary | 578 | // summary |
577 | if (!anEvent->summary().isEmpty()) | 579 | if (!anEvent->summary().isEmpty()) |
578 | addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); | 580 | addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); |
579 | 581 | ||
580 | if (!anEvent->location().isEmpty()) | 582 | if (!anEvent->location().isEmpty()) |
581 | addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); | 583 | addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); |
582 | 584 | ||
583 | // status | 585 | // status |
584 | // TODO: define Event status | 586 | // TODO: define Event status |
585 | // addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); | 587 | // addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); |
586 | 588 | ||
587 | // secrecy | 589 | // secrecy |
588 | const char *text = 0; | 590 | const char *text = 0; |
589 | switch (anEvent->secrecy()) { | 591 | switch (anEvent->secrecy()) { |
590 | case Incidence::SecrecyPublic: | 592 | case Incidence::SecrecyPublic: |
591 | text = "PUBLIC"; | 593 | text = "PUBLIC"; |
592 | break; | 594 | break; |
593 | case Incidence::SecrecyPrivate: | 595 | case Incidence::SecrecyPrivate: |
594 | text = "PRIVATE"; | 596 | text = "PRIVATE"; |
595 | break; | 597 | break; |
596 | case Incidence::SecrecyConfidential: | 598 | case Incidence::SecrecyConfidential: |
597 | text = "CONFIDENTIAL"; | 599 | text = "CONFIDENTIAL"; |
598 | break; | 600 | break; |
599 | } | 601 | } |
600 | if (text) { | 602 | if (text) { |
601 | addPropValue(vevent, VCClassProp, text); | 603 | addPropValue(vevent, VCClassProp, text); |
602 | } | 604 | } |
603 | 605 | ||
604 | // categories | 606 | // categories |
605 | QStringList tmpStrList = anEvent->categories(); | 607 | QStringList tmpStrList = anEvent->categories(); |
606 | tmpStr = ""; | 608 | tmpStr = ""; |
607 | QString catStr; | 609 | QString catStr; |
608 | for ( QStringList::Iterator it = tmpStrList.begin(); | 610 | for ( QStringList::Iterator it = tmpStrList.begin(); |
609 | it != tmpStrList.end(); | 611 | it != tmpStrList.end(); |
610 | ++it ) { | 612 | ++it ) { |
611 | catStr = *it; | 613 | catStr = *it; |
612 | if (catStr[0] == ' ') | 614 | if (catStr[0] == ' ') |
613 | tmpStr += catStr.mid(1); | 615 | tmpStr += catStr.mid(1); |
614 | else | 616 | else |
615 | tmpStr += catStr; | 617 | tmpStr += catStr; |
616 | // this must be a ';' character as the vCalendar specification requires! | 618 | // this must be a ';' character as the vCalendar specification requires! |
617 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 619 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
618 | // read in. | 620 | // read in. |
619 | tmpStr += ";"; | 621 | tmpStr += ";"; |
620 | } | 622 | } |
621 | if (!tmpStr.isEmpty()) { | 623 | if (!tmpStr.isEmpty()) { |
622 | tmpStr.truncate(tmpStr.length()-1); | 624 | tmpStr.truncate(tmpStr.length()-1); |
623 | addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); | 625 | addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); |
624 | } | 626 | } |
625 | 627 | ||
626 | // attachments | 628 | // attachments |
627 | // TODO: handle binary attachments! | 629 | // TODO: handle binary attachments! |
628 | QPtrList<Attachment> attachments = anEvent->attachments(); | 630 | Q3PtrList<Attachment> attachments = anEvent->attachments(); |
629 | for ( Attachment *at = attachments.first(); at; at = attachments.next() ) | 631 | for ( Attachment *at = attachments.first(); at; at = attachments.next() ) |
630 | addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); | 632 | addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); |
631 | 633 | ||
632 | // resources | 634 | // resources |
633 | tmpStrList = anEvent->resources(); | 635 | tmpStrList = anEvent->resources(); |
634 | tmpStr = tmpStrList.join(";"); | 636 | tmpStr = tmpStrList.join(";"); |
635 | if (!tmpStr.isEmpty()) | 637 | if (!tmpStr.isEmpty()) |
636 | addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); | 638 | addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); |
637 | 639 | ||
638 | // alarm stuff | 640 | // alarm stuff |
639 | QPtrList<Alarm> alarms = anEvent->alarms(); | 641 | Q3PtrList<Alarm> alarms = anEvent->alarms(); |
640 | Alarm* alarm; | 642 | Alarm* alarm; |
641 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 643 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
642 | if (alarm->enabled()) { | 644 | if (alarm->enabled()) { |
643 | VObject *a ; | 645 | VObject *a ; |
644 | tmpStr = qDateTimeToISO(alarm->time()); | 646 | tmpStr = qDateTimeToISO(alarm->time()); |
645 | if (alarm->type() == Alarm::Audio) { | 647 | if (alarm->type() == Alarm::Audio) { |
646 | a = addProp(vevent, VCAAlarmProp); | 648 | a = addProp(vevent, VCAAlarmProp); |
647 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 649 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
648 | addPropValue(a, VCRepeatCountProp, "1"); | 650 | addPropValue(a, VCRepeatCountProp, "1"); |
649 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); | 651 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); |
650 | } | 652 | } |
651 | if (alarm->type() == Alarm::Procedure) { | 653 | if (alarm->type() == Alarm::Procedure) { |
652 | a = addProp(vevent, VCPAlarmProp); | 654 | a = addProp(vevent, VCPAlarmProp); |
653 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 655 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
654 | addPropValue(a, VCRepeatCountProp, "1"); | 656 | addPropValue(a, VCRepeatCountProp, "1"); |
655 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); | 657 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); |
656 | } else { | 658 | } else { |
657 | a = addProp(vevent, VCDAlarmProp); | 659 | a = addProp(vevent, VCDAlarmProp); |
658 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 660 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
659 | addPropValue(a, VCRepeatCountProp, "1"); | 661 | addPropValue(a, VCRepeatCountProp, "1"); |
660 | addPropValue(a, VCDisplayStringProp, "beep!"); | 662 | addPropValue(a, VCDisplayStringProp, "beep!"); |
661 | 663 | ||
662 | } | 664 | } |
663 | } | 665 | } |
664 | } | 666 | } |
665 | 667 | ||
666 | // priority | 668 | // priority |
667 | tmpStr.sprintf("%i",anEvent->priority()); | 669 | tmpStr.sprintf("%i",anEvent->priority()); |
668 | addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); | 670 | addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); |
669 | 671 | ||
670 | // transparency | 672 | // transparency |
671 | tmpStr.sprintf("%i",anEvent->transparency()); | 673 | tmpStr.sprintf("%i",anEvent->transparency()); |
672 | addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); | 674 | addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); |
673 | 675 | ||
674 | // related event | 676 | // related event |
675 | if (anEvent->relatedToUid()) { | 677 | if (!anEvent->relatedToUid().isEmpty()) { |
676 | addPropValue(vevent, VCRelatedToProp, | 678 | addPropValue(vevent, VCRelatedToProp, |
677 | anEvent->relatedToUid().local8Bit()); | 679 | anEvent->relatedToUid().local8Bit()); |
678 | } | 680 | } |
679 | 681 | ||
680 | if (anEvent->pilotId()) { | 682 | if (anEvent->pilotId()) { |
681 | // pilot sync stuff | 683 | // pilot sync stuff |
682 | tmpStr.sprintf("%i",anEvent->pilotId()); | 684 | tmpStr.sprintf("%i",anEvent->pilotId()); |
683 | addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); | 685 | addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); |
684 | tmpStr.sprintf("%i",anEvent->syncStatus()); | 686 | tmpStr.sprintf("%i",anEvent->syncStatus()); |
685 | addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); | 687 | addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); |
686 | } | 688 | } |
687 | 689 | ||
688 | return vevent; | 690 | return vevent; |
689 | } | 691 | } |
690 | 692 | ||
691 | Todo *VCalFormat::VTodoToEvent(VObject *vtodo) | 693 | Todo *VCalFormat::VTodoToEvent(VObject *vtodo) |
692 | { | 694 | { |
693 | VObject *vo; | 695 | VObject *vo; |
694 | VObjectIterator voi; | 696 | VObjectIterator voi; |
695 | char *s; | 697 | char *s; |
696 | 698 | ||
697 | Todo *anEvent = new Todo; | 699 | Todo *anEvent = new Todo; |
698 | 700 | ||
699 | // creation date | 701 | // creation date |
700 | if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { | 702 | if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { |
701 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 703 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
702 | deleteStr(s); | 704 | deleteStr(s); |
703 | } | 705 | } |
704 | 706 | ||
705 | // unique id | 707 | // unique id |
706 | vo = isAPropertyOf(vtodo, VCUniqueStringProp); | 708 | vo = isAPropertyOf(vtodo, VCUniqueStringProp); |
707 | // while the UID property is preferred, it is not required. We'll use the | 709 | // while the UID property is preferred, it is not required. We'll use the |
708 | // default Event UID if none is given. | 710 | // default Event UID if none is given. |
709 | if (vo) { | 711 | if (vo) { |
710 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); | 712 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); |
711 | deleteStr(s); | 713 | deleteStr(s); |
712 | } | 714 | } |
713 | 715 | ||
714 | // last modification date | 716 | // last modification date |
715 | if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { | 717 | if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { |
716 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 718 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
717 | deleteStr(s); | 719 | deleteStr(s); |
718 | } | 720 | } |
719 | else | 721 | else |
720 | anEvent->setLastModified(QDateTime(QDate::currentDate(), | 722 | anEvent->setLastModified(QDateTime(QDate::currentDate(), |
721 | QTime::currentTime())); | 723 | QTime::currentTime())); |
722 | 724 | ||
723 | // organizer | 725 | // organizer |
724 | // if our extension property for the event's ORGANIZER exists, add it. | 726 | // if our extension property for the event's ORGANIZER exists, add it. |
725 | if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { | 727 | if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { |
726 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); | 728 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); |
727 | deleteStr(s); | 729 | deleteStr(s); |
728 | } else { | 730 | } else { |
729 | anEvent->setOrganizer(mCalendar->getEmail()); | 731 | anEvent->setOrganizer(mCalendar->getEmail()); |
730 | } | 732 | } |
731 | 733 | ||
732 | // attendees. | 734 | // attendees. |
733 | initPropIterator(&voi, vtodo); | 735 | initPropIterator(&voi, vtodo); |
734 | while (moreIteration(&voi)) { | 736 | while (moreIteration(&voi)) { |
735 | vo = nextVObject(&voi); | 737 | vo = nextVObject(&voi); |
736 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { | 738 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { |
737 | Attendee *a; | 739 | Attendee *a; |
738 | VObject *vp; | 740 | VObject *vp; |
739 | s = fakeCString(vObjectUStringZValue(vo)); | 741 | s = fakeCString(vObjectUStringZValue(vo)); |
740 | QString tmpStr = QString::fromLocal8Bit(s); | 742 | QString tmpStr = QString::fromLocal8Bit(s); |
741 | deleteStr(s); | 743 | deleteStr(s); |
742 | tmpStr = tmpStr.simplifyWhiteSpace(); | 744 | tmpStr = tmpStr.simplifyWhiteSpace(); |
743 | int emailPos1, emailPos2; | 745 | int emailPos1, emailPos2; |
744 | if ((emailPos1 = tmpStr.find('<')) > 0) { | 746 | if ((emailPos1 = tmpStr.find('<')) > 0) { |
745 | // both email address and name | 747 | // both email address and name |
746 | emailPos2 = tmpStr.findRev('>'); | 748 | emailPos2 = tmpStr.findRev('>'); |
747 | a = new Attendee(tmpStr.left(emailPos1 - 1), | 749 | a = new Attendee(tmpStr.left(emailPos1 - 1), |
748 | tmpStr.mid(emailPos1 + 1, | 750 | tmpStr.mid(emailPos1 + 1, |
749 | emailPos2 - (emailPos1 + 1))); | 751 | emailPos2 - (emailPos1 + 1))); |
750 | } else if (tmpStr.find('@') > 0) { | 752 | } else if (tmpStr.find('@') > 0) { |
751 | // just an email address | 753 | // just an email address |
752 | a = new Attendee(0, tmpStr); | 754 | a = new Attendee(0, tmpStr); |
753 | } else { | 755 | } else { |
754 | // just a name | 756 | // just a name |
755 | // QString email = tmpStr.replace( QRegExp(" "), "." ); | 757 | // QString email = tmpStr.replace( QRegExp(" "), "." ); |
756 | a = new Attendee(tmpStr,0); | 758 | a = new Attendee(tmpStr,0); |
757 | } | 759 | } |
758 | // is there a Role property? | 760 | // is there a Role property? |
759 | if ((vp = isAPropertyOf(vo, VCRoleProp)) != 0) | 761 | if ((vp = isAPropertyOf(vo, VCRoleProp)) != 0) |
760 | a->setRole(readRole(vObjectStringZValue(vp))); | 762 | a->setRole(readRole(vObjectStringZValue(vp))); |
761 | // is there an RSVP property? | 763 | // is there an RSVP property? |
762 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) | 764 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) |
763 | a->setRSVP(vObjectStringZValue(vp)); | 765 | a->setRSVP(vObjectStringZValue(vp)); |
764 | // is there a status property? | 766 | // is there a status property? |
765 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) | 767 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) |
766 | a->setStatus(readStatus(vObjectStringZValue(vp))); | 768 | a->setStatus(readStatus(vObjectStringZValue(vp))); |
767 | // add the attendee | 769 | // add the attendee |
768 | anEvent->addAttendee(a); | 770 | anEvent->addAttendee(a); |
769 | } | 771 | } |
770 | } | 772 | } |
771 | 773 | ||
772 | // description for todo | 774 | // description for todo |
773 | if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { | 775 | if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { |
774 | s = fakeCString(vObjectUStringZValue(vo)); | 776 | s = fakeCString(vObjectUStringZValue(vo)); |
775 | anEvent->setDescription(QString::fromLocal8Bit(s)); | 777 | anEvent->setDescription(QString::fromLocal8Bit(s)); |
776 | deleteStr(s); | 778 | deleteStr(s); |
777 | } | 779 | } |
778 | 780 | ||
779 | // summary | 781 | // summary |
780 | if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { | 782 | if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { |
781 | s = fakeCString(vObjectUStringZValue(vo)); | 783 | s = fakeCString(vObjectUStringZValue(vo)); |
782 | anEvent->setSummary(QString::fromLocal8Bit(s)); | 784 | anEvent->setSummary(QString::fromLocal8Bit(s)); |
783 | deleteStr(s); | 785 | deleteStr(s); |
784 | } | 786 | } |
785 | if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { | 787 | if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { |
786 | s = fakeCString(vObjectUStringZValue(vo)); | 788 | s = fakeCString(vObjectUStringZValue(vo)); |
787 | anEvent->setLocation(QString::fromLocal8Bit(s)); | 789 | anEvent->setLocation(QString::fromLocal8Bit(s)); |
788 | deleteStr(s); | 790 | deleteStr(s); |
789 | } | 791 | } |
790 | 792 | ||
791 | 793 | ||
792 | // completed | 794 | // completed |
793 | // was: status | 795 | // was: status |
794 | if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { | 796 | if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { |
795 | s = fakeCString(vObjectUStringZValue(vo)); | 797 | s = fakeCString(vObjectUStringZValue(vo)); |
796 | if (strcmp(s,"COMPLETED") == 0) { | 798 | if (strcmp(s,"COMPLETED") == 0) { |
797 | anEvent->setCompleted(true); | 799 | anEvent->setCompleted(true); |
798 | } else { | 800 | } else { |
799 | anEvent->setCompleted(false); | 801 | anEvent->setCompleted(false); |
800 | } | 802 | } |
801 | deleteStr(s); | 803 | deleteStr(s); |
802 | } | 804 | } |
803 | else | 805 | else |
804 | anEvent->setCompleted(false); | 806 | anEvent->setCompleted(false); |
805 | 807 | ||
806 | // completion date | 808 | // completion date |
807 | if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { | 809 | if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { |
808 | anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 810 | anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
809 | deleteStr(s); | 811 | deleteStr(s); |
810 | } | 812 | } |
811 | 813 | ||
812 | // priority | 814 | // priority |
813 | if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { | 815 | if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { |
814 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 816 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
815 | deleteStr(s); | 817 | deleteStr(s); |
816 | } | 818 | } |
817 | 819 | ||
818 | // due date | 820 | // due date |
819 | if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { | 821 | if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { |
820 | anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 822 | anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
821 | deleteStr(s); | 823 | deleteStr(s); |
822 | anEvent->setHasDueDate(true); | 824 | anEvent->setHasDueDate(true); |
823 | } else { | 825 | } else { |
824 | anEvent->setHasDueDate(false); | 826 | anEvent->setHasDueDate(false); |
825 | } | 827 | } |
826 | 828 | ||
827 | // start time | 829 | // start time |
828 | if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { | 830 | if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { |
829 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 831 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
830 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; | 832 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; |
831 | deleteStr(s); | 833 | deleteStr(s); |
832 | anEvent->setHasStartDate(true); | 834 | anEvent->setHasStartDate(true); |
833 | } else { | 835 | } else { |
834 | anEvent->setHasStartDate(false); | 836 | anEvent->setHasStartDate(false); |
835 | } | 837 | } |
836 | 838 | ||
837 | /* alarm stuff */ | 839 | /* alarm stuff */ |
838 | //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; | 840 | //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; |
839 | if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { | 841 | if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { |
840 | Alarm* alarm = anEvent->newAlarm(); | 842 | Alarm* alarm = anEvent->newAlarm(); |
841 | VObject *a; | 843 | VObject *a; |
842 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { | 844 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { |
843 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); | 845 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); |
844 | deleteStr(s); | 846 | deleteStr(s); |
845 | } | 847 | } |
846 | alarm->setEnabled(true); | 848 | alarm->setEnabled(true); |
847 | if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { | 849 | if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { |
848 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { | 850 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { |
849 | s = fakeCString(vObjectUStringZValue(a)); | 851 | s = fakeCString(vObjectUStringZValue(a)); |
850 | alarm->setProcedureAlarm(QFile::decodeName(s)); | 852 | alarm->setProcedureAlarm(QFile::decodeName(s)); |
851 | deleteStr(s); | 853 | deleteStr(s); |
852 | } | 854 | } |
853 | } | 855 | } |
854 | if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { | 856 | if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { |
855 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { | 857 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { |
856 | s = fakeCString(vObjectUStringZValue(a)); | 858 | s = fakeCString(vObjectUStringZValue(a)); |
857 | alarm->setAudioAlarm(QFile::decodeName(s)); | 859 | alarm->setAudioAlarm(QFile::decodeName(s)); |
858 | deleteStr(s); | 860 | deleteStr(s); |
859 | } | 861 | } |
860 | } | 862 | } |
861 | } | 863 | } |
862 | 864 | ||
863 | // related todo | 865 | // related todo |
864 | if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { | 866 | if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { |
865 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); | 867 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); |
866 | deleteStr(s); | 868 | deleteStr(s); |
867 | mTodosRelate.append(anEvent); | 869 | mTodosRelate.append(anEvent); |
868 | } | 870 | } |
869 | 871 | ||
870 | // categories | 872 | // categories |
871 | if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { | 873 | if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { |
872 | s = fakeCString(vObjectUStringZValue(vo)); | 874 | s = fakeCString(vObjectUStringZValue(vo)); |
873 | QString categories = QString::fromLocal8Bit(s); | 875 | QString categories = QString::fromLocal8Bit(s); |
874 | deleteStr(s); | 876 | deleteStr(s); |
875 | QStringList tmpStrList = QStringList::split( ';', categories ); | 877 | QStringList tmpStrList = QStringList::split( ';', categories ); |
876 | anEvent->setCategories(tmpStrList); | 878 | anEvent->setCategories(tmpStrList); |
877 | } | 879 | } |
878 | 880 | ||
879 | /* PILOT SYNC STUFF */ | 881 | /* PILOT SYNC STUFF */ |
880 | if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { | 882 | if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { |
881 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 883 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
882 | deleteStr(s); | 884 | deleteStr(s); |
883 | } | 885 | } |
884 | else | 886 | else |
885 | anEvent->setPilotId(0); | 887 | anEvent->setPilotId(0); |
886 | 888 | ||
887 | if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { | 889 | if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { |
888 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 890 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
889 | deleteStr(s); | 891 | deleteStr(s); |
890 | } | 892 | } |
891 | else | 893 | else |
892 | anEvent->setSyncStatus(Event::SYNCMOD); | 894 | anEvent->setSyncStatus(Event::SYNCMOD); |
893 | 895 | ||
894 | return anEvent; | 896 | return anEvent; |
895 | } | 897 | } |
896 | 898 | ||
897 | Event* VCalFormat::VEventToEvent(VObject *vevent) | 899 | Event* VCalFormat::VEventToEvent(VObject *vevent) |
898 | { | 900 | { |
899 | VObject *vo; | 901 | VObject *vo; |
900 | VObjectIterator voi; | 902 | VObjectIterator voi; |
901 | char *s; | 903 | char *s; |
902 | 904 | ||
903 | Event *anEvent = new Event; | 905 | Event *anEvent = new Event; |
904 | 906 | ||
905 | // creation date | 907 | // creation date |
906 | if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { | 908 | if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { |
907 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 909 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
908 | deleteStr(s); | 910 | deleteStr(s); |
909 | } | 911 | } |
910 | 912 | ||
911 | // unique id | 913 | // unique id |
912 | vo = isAPropertyOf(vevent, VCUniqueStringProp); | 914 | vo = isAPropertyOf(vevent, VCUniqueStringProp); |
913 | // while the UID property is preferred, it is not required. We'll use the | 915 | // while the UID property is preferred, it is not required. We'll use the |
914 | // default Event UID if none is given. | 916 | // default Event UID if none is given. |
915 | if (vo) { | 917 | if (vo) { |
916 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); | 918 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); |
917 | deleteStr(s); | 919 | deleteStr(s); |
918 | } | 920 | } |
919 | 921 | ||
920 | // revision | 922 | // revision |
921 | // again NSCAL doesn't give us much to work with, so we improvise... | 923 | // again NSCAL doesn't give us much to work with, so we improvise... |
922 | if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { | 924 | if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { |
923 | anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 925 | anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
924 | deleteStr(s); | 926 | deleteStr(s); |
925 | } | 927 | } |
926 | else | 928 | else |
927 | anEvent->setRevision(0); | 929 | anEvent->setRevision(0); |
928 | 930 | ||
929 | // last modification date | 931 | // last modification date |
930 | if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { | 932 | if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { |
931 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 933 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
932 | deleteStr(s); | 934 | deleteStr(s); |
933 | } | 935 | } |
934 | else | 936 | else |
935 | anEvent->setLastModified(QDateTime(QDate::currentDate(), | 937 | anEvent->setLastModified(QDateTime(QDate::currentDate(), |
936 | QTime::currentTime())); | 938 | QTime::currentTime())); |
937 | 939 | ||
938 | // organizer | 940 | // organizer |
939 | // if our extension property for the event's ORGANIZER exists, add it. | 941 | // if our extension property for the event's ORGANIZER exists, add it. |
940 | if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { | 942 | if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { |
941 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); | 943 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); |
942 | deleteStr(s); | 944 | deleteStr(s); |
943 | } else { | 945 | } else { |
944 | anEvent->setOrganizer(mCalendar->getEmail()); | 946 | anEvent->setOrganizer(mCalendar->getEmail()); |
945 | } | 947 | } |
946 | 948 | ||
947 | // deal with attendees. | 949 | // deal with attendees. |
948 | initPropIterator(&voi, vevent); | 950 | initPropIterator(&voi, vevent); |
949 | while (moreIteration(&voi)) { | 951 | while (moreIteration(&voi)) { |
950 | vo = nextVObject(&voi); | 952 | vo = nextVObject(&voi); |
951 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { | 953 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { |
952 | Attendee *a; | 954 | Attendee *a; |
953 | VObject *vp; | 955 | VObject *vp; |
954 | s = fakeCString(vObjectUStringZValue(vo)); | 956 | s = fakeCString(vObjectUStringZValue(vo)); |
955 | QString tmpStr = QString::fromLocal8Bit(s); | 957 | QString tmpStr = QString::fromLocal8Bit(s); |
956 | deleteStr(s); | 958 | deleteStr(s); |
957 | tmpStr = tmpStr.simplifyWhiteSpace(); | 959 | tmpStr = tmpStr.simplifyWhiteSpace(); |
958 | int emailPos1, emailPos2; | 960 | int emailPos1, emailPos2; |
959 | if ((emailPos1 = tmpStr.find('<')) > 0) { | 961 | if ((emailPos1 = tmpStr.find('<')) > 0) { |
960 | // both email address and name | 962 | // both email address and name |
961 | emailPos2 = tmpStr.findRev('>'); | 963 | emailPos2 = tmpStr.findRev('>'); |
962 | a = new Attendee(tmpStr.left(emailPos1 - 1), | 964 | a = new Attendee(tmpStr.left(emailPos1 - 1), |
963 | tmpStr.mid(emailPos1 + 1, | 965 | tmpStr.mid(emailPos1 + 1, |
964 | emailPos2 - (emailPos1 + 1))); | 966 | emailPos2 - (emailPos1 + 1))); |
965 | } else if (tmpStr.find('@') > 0) { | 967 | } else if (tmpStr.find('@') > 0) { |
966 | // just an email address | 968 | // just an email address |
967 | a = new Attendee(0, tmpStr); | 969 | a = new Attendee(0, tmpStr); |
968 | } else { | 970 | } else { |
969 | // just a name | 971 | // just a name |
970 | //QString email = tmpStr.replace( QRegExp(" "), "." ); | 972 | //QString email = tmpStr.replace( QRegExp(" "), "." ); |
971 | a = new Attendee(tmpStr,0); | 973 | a = new Attendee(tmpStr,0); |
972 | } | 974 | } |
973 | 975 | ||
974 | 976 | ||
975 | // is there a Role property? | 977 | // is there a Role property? |
976 | if ((vp = isAPropertyOf(vo, VCRoleProp)) != 0) | 978 | if ((vp = isAPropertyOf(vo, VCRoleProp)) != 0) |
977 | a->setRole(readRole(vObjectStringZValue(vp))); | 979 | a->setRole(readRole(vObjectStringZValue(vp))); |
978 | 980 | ||
979 | // is there an RSVP property? | 981 | // is there an RSVP property? |
980 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) | 982 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) |
981 | a->setRSVP(vObjectStringZValue(vp)); | 983 | a->setRSVP(vObjectStringZValue(vp)); |
982 | // is there a status property? | 984 | // is there a status property? |
983 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) | 985 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) |
984 | a->setStatus(readStatus(vObjectStringZValue(vp))); | 986 | a->setStatus(readStatus(vObjectStringZValue(vp))); |
985 | // add the attendee | 987 | // add the attendee |
986 | anEvent->addAttendee(a); | 988 | anEvent->addAttendee(a); |
987 | } | 989 | } |
988 | } | 990 | } |
989 | 991 | ||
990 | // This isn't strictly true. An event that doesn't have a start time | 992 | // This isn't strictly true. An event that doesn't have a start time |
991 | // or an end time doesn't "float", it has an anchor in time but it doesn't | 993 | // or an end time doesn't "float", it has an anchor in time but it doesn't |
992 | // "take up" any time. | 994 | // "take up" any time. |
993 | /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) || | 995 | /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) || |
994 | (isAPropertyOf(vevent, VCDTendProp) == 0)) { | 996 | (isAPropertyOf(vevent, VCDTendProp) == 0)) { |
995 | anEvent->setFloats(TRUE); | 997 | anEvent->setFloats(TRUE); |
996 | } else { | 998 | } else { |
997 | }*/ | 999 | }*/ |
998 | 1000 | ||
999 | anEvent->setFloats(FALSE); | 1001 | anEvent->setFloats(FALSE); |
1000 | 1002 | ||
1001 | // start time | 1003 | // start time |
1002 | if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) { | 1004 | if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) { |
1003 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 1005 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
1004 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; | 1006 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; |
1005 | deleteStr(s); | 1007 | deleteStr(s); |
1006 | if (anEvent->dtStart().time().isNull()) | 1008 | if (anEvent->dtStart().time().isNull()) |
1007 | anEvent->setFloats(TRUE); | 1009 | anEvent->setFloats(TRUE); |
1008 | } | 1010 | } |
1009 | 1011 | ||
1010 | // stop time | 1012 | // stop time |
1011 | if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) { | 1013 | if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) { |
1012 | anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 1014 | anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
1013 | deleteStr(s); | 1015 | deleteStr(s); |
1014 | if (anEvent->dtEnd().time().isNull()) | 1016 | if (anEvent->dtEnd().time().isNull()) |
1015 | anEvent->setFloats(TRUE); | 1017 | anEvent->setFloats(TRUE); |
1016 | } | 1018 | } |
1017 | 1019 | ||
1018 | // at this point, there should be at least a start or end time. | 1020 | // at this point, there should be at least a start or end time. |
1019 | // fix up for events that take up no time but have a time associated | 1021 | // fix up for events that take up no time but have a time associated |
1020 | if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) | 1022 | if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) |
1021 | anEvent->setDtStart(anEvent->dtEnd()); | 1023 | anEvent->setDtStart(anEvent->dtEnd()); |
1022 | if (!(vo = isAPropertyOf(vevent, VCDTendProp))) | 1024 | if (!(vo = isAPropertyOf(vevent, VCDTendProp))) |
1023 | anEvent->setDtEnd(anEvent->dtStart()); | 1025 | anEvent->setDtEnd(anEvent->dtStart()); |
1024 | 1026 | ||
1025 | /////////////////////////////////////////////////////////////////////////// | 1027 | /////////////////////////////////////////////////////////////////////////// |
1026 | 1028 | ||
1027 | // repeat stuff | 1029 | // repeat stuff |
1028 | if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) { | 1030 | if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) { |
1029 | QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo))); | 1031 | QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo))); |
1030 | deleteStr(s); | 1032 | deleteStr(s); |
1031 | tmpStr.simplifyWhiteSpace(); | 1033 | tmpStr.simplifyWhiteSpace(); |
1032 | tmpStr = tmpStr.upper(); | 1034 | tmpStr = tmpStr.upper(); |
1033 | 1035 | ||
1034 | /********************************* DAILY ******************************/ | 1036 | /********************************* DAILY ******************************/ |
1035 | if (tmpStr.left(1) == "D") { | 1037 | if (tmpStr.left(1) == "D") { |
1036 | int index = tmpStr.find(' '); | 1038 | int index = tmpStr.find(' '); |
1037 | int rFreq = tmpStr.mid(1, (index-1)).toInt(); | 1039 | int rFreq = tmpStr.mid(1, (index-1)).toInt(); |
1038 | index = tmpStr.findRev(' ') + 1; // advance to last field | 1040 | index = tmpStr.findRev(' ') + 1; // advance to last field |
1039 | if (tmpStr.mid(index,1) == "#") index++; | 1041 | if (tmpStr.mid(index,1) == "#") index++; |
1040 | if (tmpStr.find('T', index) != -1) { | 1042 | if (tmpStr.find('T', index) != -1) { |
1041 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1043 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1042 | anEvent->recurrence()->setDaily(rFreq, rEndDate); | 1044 | anEvent->recurrence()->setDaily(rFreq, rEndDate); |
1043 | } else { | 1045 | } else { |
1044 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1046 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1045 | if (rDuration == 0) // VEvents set this to 0 forever, we use -1 | 1047 | if (rDuration == 0) // VEvents set this to 0 forever, we use -1 |
1046 | anEvent->recurrence()->setDaily(rFreq, -1); | 1048 | anEvent->recurrence()->setDaily(rFreq, -1); |
1047 | else | 1049 | else |
1048 | anEvent->recurrence()->setDaily(rFreq, rDuration); | 1050 | anEvent->recurrence()->setDaily(rFreq, rDuration); |
1049 | } | 1051 | } |
1050 | } | 1052 | } |
1051 | /********************************* WEEKLY ******************************/ | 1053 | /********************************* WEEKLY ******************************/ |
1052 | else if (tmpStr.left(1) == "W") { | 1054 | else if (tmpStr.left(1) == "W") { |
1053 | int index = tmpStr.find(' '); | 1055 | int index = tmpStr.find(' '); |
1054 | int last = tmpStr.findRev(' ') + 1; | 1056 | int last = tmpStr.findRev(' ') + 1; |
1055 | int rFreq = tmpStr.mid(1, (index-1)).toInt(); | 1057 | int rFreq = tmpStr.mid(1, (index-1)).toInt(); |
1056 | index += 1; // advance to beginning of stuff after freq | 1058 | index += 1; // advance to beginning of stuff after freq |
1057 | QBitArray qba(7); | 1059 | QBitArray qba(7); |
1058 | QString dayStr; | 1060 | QString dayStr; |
1059 | if( index == last ) { | 1061 | if( index == last ) { |
1060 | // e.g. W1 #0 | 1062 | // e.g. W1 #0 |
1061 | qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); | 1063 | qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); |
1062 | } | 1064 | } |
1063 | else { | 1065 | else { |
1064 | // e.g. W1 SU #0 | 1066 | // e.g. W1 SU #0 |
1065 | while (index < last) { | 1067 | while (index < last) { |
1066 | dayStr = tmpStr.mid(index, 3); | 1068 | dayStr = tmpStr.mid(index, 3); |
1067 | int dayNum = numFromDay(dayStr); | 1069 | int dayNum = numFromDay(dayStr); |
1068 | qba.setBit(dayNum); | 1070 | qba.setBit(dayNum); |
1069 | index += 3; // advance to next day, or possibly "#" | 1071 | index += 3; // advance to next day, or possibly "#" |
1070 | } | 1072 | } |
1071 | } | 1073 | } |
1072 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1074 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1073 | if (tmpStr.find('T', index) != -1) { | 1075 | if (tmpStr.find('T', index) != -1) { |
1074 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1076 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1075 | anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate); | 1077 | anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate); |
1076 | } else { | 1078 | } else { |
1077 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1079 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1078 | if (rDuration == 0) | 1080 | if (rDuration == 0) |
1079 | anEvent->recurrence()->setWeekly(rFreq, qba, -1); | 1081 | anEvent->recurrence()->setWeekly(rFreq, qba, -1); |
1080 | else | 1082 | else |
1081 | anEvent->recurrence()->setWeekly(rFreq, qba, rDuration); | 1083 | anEvent->recurrence()->setWeekly(rFreq, qba, rDuration); |
1082 | } | 1084 | } |
1083 | } | 1085 | } |
1084 | /**************************** MONTHLY-BY-POS ***************************/ | 1086 | /**************************** MONTHLY-BY-POS ***************************/ |
1085 | else if (tmpStr.left(2) == "MP") { | 1087 | else if (tmpStr.left(2) == "MP") { |
1086 | int index = tmpStr.find(' '); | 1088 | int index = tmpStr.find(' '); |
1087 | int last = tmpStr.findRev(' ') + 1; | 1089 | int last = tmpStr.findRev(' ') + 1; |
1088 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); | 1090 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); |
1089 | index += 1; // advance to beginning of stuff after freq | 1091 | index += 1; // advance to beginning of stuff after freq |
1090 | QBitArray qba(7); | 1092 | QBitArray qba(7); |
1091 | short tmpPos; | 1093 | short tmpPos; |
1092 | if( index == last ) { | 1094 | if( index == last ) { |
1093 | // e.g. MP1 #0 | 1095 | // e.g. MP1 #0 |
1094 | tmpPos = anEvent->dtStart().date().day()/7 + 1; | 1096 | tmpPos = anEvent->dtStart().date().day()/7 + 1; |
1095 | if( tmpPos == 5 ) | 1097 | if( tmpPos == 5 ) |
1096 | tmpPos = -1; | 1098 | tmpPos = -1; |
1097 | qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); | 1099 | qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); |
1098 | anEvent->recurrence()->addMonthlyPos(tmpPos, qba); | 1100 | anEvent->recurrence()->addMonthlyPos(tmpPos, qba); |
1099 | } | 1101 | } |
1100 | else { | 1102 | else { |
1101 | // e.g. MP1 1+ SU #0 | 1103 | // e.g. MP1 1+ SU #0 |
1102 | while (index < last) { | 1104 | while (index < last) { |
1103 | tmpPos = tmpStr.mid(index,1).toShort(); | 1105 | tmpPos = tmpStr.mid(index,1).toShort(); |
1104 | index += 1; | 1106 | index += 1; |
1105 | if (tmpStr.mid(index,1) == "-") | 1107 | if (tmpStr.mid(index,1) == "-") |
1106 | // convert tmpPos to negative | 1108 | // convert tmpPos to negative |
1107 | tmpPos = 0 - tmpPos; | 1109 | tmpPos = 0 - tmpPos; |
1108 | index += 2; // advance to day(s) | 1110 | index += 2; // advance to day(s) |
1109 | while (numFromDay(tmpStr.mid(index,3)) >= 0) { | 1111 | while (numFromDay(tmpStr.mid(index,3)) >= 0) { |
1110 | int dayNum = numFromDay(tmpStr.mid(index,3)); | 1112 | int dayNum = numFromDay(tmpStr.mid(index,3)); |
1111 | qba.setBit(dayNum); | 1113 | qba.setBit(dayNum); |
1112 | index += 3; // advance to next day, or possibly pos or "#" | 1114 | index += 3; // advance to next day, or possibly pos or "#" |
1113 | } | 1115 | } |
1114 | anEvent->recurrence()->addMonthlyPos(tmpPos, qba); | 1116 | anEvent->recurrence()->addMonthlyPos(tmpPos, qba); |
1115 | qba.detach(); | 1117 | qba.detach(); |
1116 | qba.fill(FALSE); // clear out | 1118 | qba.fill(FALSE); // clear out |
1117 | } // while != "#" | 1119 | } // while != "#" |
1118 | } | 1120 | } |
1119 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1121 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1120 | if (tmpStr.find('T', index) != -1) { | 1122 | if (tmpStr.find('T', index) != -1) { |
1121 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - | 1123 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - |
1122 | index))).date(); | 1124 | index))).date(); |
1123 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate); | 1125 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate); |
1124 | } else { | 1126 | } else { |
1125 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1127 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1126 | if (rDuration == 0) | 1128 | if (rDuration == 0) |
1127 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1); | 1129 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1); |
1128 | else | 1130 | else |
1129 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration); | 1131 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration); |
1130 | } | 1132 | } |
1131 | } | 1133 | } |
1132 | 1134 | ||
1133 | /**************************** MONTHLY-BY-DAY ***************************/ | 1135 | /**************************** MONTHLY-BY-DAY ***************************/ |
1134 | else if (tmpStr.left(2) == "MD") { | 1136 | else if (tmpStr.left(2) == "MD") { |
1135 | int index = tmpStr.find(' '); | 1137 | int index = tmpStr.find(' '); |
1136 | int last = tmpStr.findRev(' ') + 1; | 1138 | int last = tmpStr.findRev(' ') + 1; |
1137 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); | 1139 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); |
1138 | index += 1; | 1140 | index += 1; |
1139 | short tmpDay; | 1141 | short tmpDay; |
1140 | if( index == last ) { | 1142 | if( index == last ) { |
1141 | // e.g. MD1 #0 | 1143 | // e.g. MD1 #0 |
1142 | tmpDay = anEvent->dtStart().date().day(); | 1144 | tmpDay = anEvent->dtStart().date().day(); |
1143 | anEvent->recurrence()->addMonthlyDay(tmpDay); | 1145 | anEvent->recurrence()->addMonthlyDay(tmpDay); |
1144 | } | 1146 | } |
1145 | else { | 1147 | else { |
1146 | // e.g. MD1 3 #0 | 1148 | // e.g. MD1 3 #0 |
1147 | while (index < last) { | 1149 | while (index < last) { |
1148 | int index2 = tmpStr.find(' ', index); | 1150 | int index2 = tmpStr.find(' ', index); |
1149 | tmpDay = tmpStr.mid(index, (index2-index)).toShort(); | 1151 | tmpDay = tmpStr.mid(index, (index2-index)).toShort(); |
1150 | index = index2-1; | 1152 | index = index2-1; |
1151 | if (tmpStr.mid(index, 1) == "-") | 1153 | if (tmpStr.mid(index, 1) == "-") |
1152 | tmpDay = 0 - tmpDay; | 1154 | tmpDay = 0 - tmpDay; |
1153 | index += 2; // advance the index; | 1155 | index += 2; // advance the index; |
1154 | anEvent->recurrence()->addMonthlyDay(tmpDay); | 1156 | anEvent->recurrence()->addMonthlyDay(tmpDay); |
1155 | } // while != # | 1157 | } // while != # |
1156 | } | 1158 | } |
1157 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1159 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1158 | if (tmpStr.find('T', index) != -1) { | 1160 | if (tmpStr.find('T', index) != -1) { |
1159 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1161 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1160 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate); | 1162 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate); |
1161 | } else { | 1163 | } else { |
1162 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1164 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1163 | if (rDuration == 0) | 1165 | if (rDuration == 0) |
1164 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1); | 1166 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1); |
1165 | else | 1167 | else |
1166 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration); | 1168 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration); |
1167 | } | 1169 | } |
1168 | } | 1170 | } |
1169 | 1171 | ||
1170 | /*********************** YEARLY-BY-MONTH *******************************/ | 1172 | /*********************** YEARLY-BY-MONTH *******************************/ |
1171 | else if (tmpStr.left(2) == "YM") { | 1173 | else if (tmpStr.left(2) == "YM") { |
1172 | // we have to set this such that recurrence accepts addYearlyNum(tmpDay); | 1174 | // we have to set this such that recurrence accepts addYearlyNum(tmpDay); |
1173 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, 1, -1); | 1175 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, 1, -1); |
1174 | int index = tmpStr.find(' '); | 1176 | int index = tmpStr.find(' '); |
1175 | int last = tmpStr.findRev(' ') + 1; | 1177 | int last = tmpStr.findRev(' ') + 1; |
1176 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); | 1178 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); |
1177 | index += 1; | 1179 | index += 1; |
1178 | short tmpMonth; | 1180 | short tmpMonth; |
1179 | if( index == last ) { | 1181 | if( index == last ) { |
1180 | // e.g. YM1 #0 | 1182 | // e.g. YM1 #0 |
1181 | tmpMonth = anEvent->dtStart().date().month(); | 1183 | tmpMonth = anEvent->dtStart().date().month(); |
1182 | anEvent->recurrence()->addYearlyNum(tmpMonth); | 1184 | anEvent->recurrence()->addYearlyNum(tmpMonth); |
1183 | } | 1185 | } |
1184 | else { | 1186 | else { |
1185 | // e.g. YM1 3 #0 | 1187 | // e.g. YM1 3 #0 |
1186 | while (index < last) { | 1188 | while (index < last) { |
1187 | int index2 = tmpStr.find(' ', index); | 1189 | int index2 = tmpStr.find(' ', index); |
1188 | tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); | 1190 | tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); |
1189 | index = index2+1; | 1191 | index = index2+1; |
1190 | anEvent->recurrence()->addYearlyNum(tmpMonth); | 1192 | anEvent->recurrence()->addYearlyNum(tmpMonth); |
1191 | } // while != # | 1193 | } // while != # |
1192 | } | 1194 | } |
1193 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1195 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1194 | if (tmpStr.find('T', index) != -1) { | 1196 | if (tmpStr.find('T', index) != -1) { |
1195 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1197 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1196 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); | 1198 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); |
1197 | } else { | 1199 | } else { |
1198 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1200 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1199 | if (rDuration == 0) | 1201 | if (rDuration == 0) |
1200 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); | 1202 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); |
1201 | else | 1203 | else |
1202 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); | 1204 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); |
1203 | } | 1205 | } |
1204 | } | 1206 | } |
1205 | 1207 | ||
1206 | /*********************** YEARLY-BY-DAY *********************************/ | 1208 | /*********************** YEARLY-BY-DAY *********************************/ |
1207 | else if (tmpStr.left(2) == "YD") { | 1209 | else if (tmpStr.left(2) == "YD") { |
1208 | // we have to set this such that recurrence accepts addYearlyNum(tmpDay); | 1210 | // we have to set this such that recurrence accepts addYearlyNum(tmpDay); |
1209 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, 1, -1); | 1211 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, 1, -1); |
1210 | int index = tmpStr.find(' '); | 1212 | int index = tmpStr.find(' '); |
1211 | int last = tmpStr.findRev(' ') + 1; | 1213 | int last = tmpStr.findRev(' ') + 1; |
1212 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); | 1214 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); |
1213 | index += 1; | 1215 | index += 1; |
1214 | short tmpDay; | 1216 | short tmpDay; |
1215 | if( index == last ) { | 1217 | if( index == last ) { |
1216 | // e.g. YD1 #0 | 1218 | // e.g. YD1 #0 |
1217 | tmpDay = anEvent->dtStart().date().dayOfYear(); | 1219 | tmpDay = anEvent->dtStart().date().dayOfYear(); |
1218 | anEvent->recurrence()->addYearlyNum(tmpDay); | 1220 | anEvent->recurrence()->addYearlyNum(tmpDay); |
1219 | } | 1221 | } |
1220 | else { | 1222 | else { |
1221 | // e.g. YD1 123 #0 | 1223 | // e.g. YD1 123 #0 |
1222 | while (index < last) { | 1224 | while (index < last) { |
1223 | int index2 = tmpStr.find(' ', index); | 1225 | int index2 = tmpStr.find(' ', index); |
1224 | tmpDay = tmpStr.mid(index, (index2-index)).toShort(); | 1226 | tmpDay = tmpStr.mid(index, (index2-index)).toShort(); |
1225 | index = index2+1; | 1227 | index = index2+1; |
1226 | anEvent->recurrence()->addYearlyNum(tmpDay); | 1228 | anEvent->recurrence()->addYearlyNum(tmpDay); |
1227 | } // while != # | 1229 | } // while != # |
1228 | } | 1230 | } |
1229 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1231 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1230 | if (tmpStr.find('T', index) != -1) { | 1232 | if (tmpStr.find('T', index) != -1) { |
1231 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1233 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1232 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); | 1234 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); |
1233 | } else { | 1235 | } else { |
1234 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1236 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1235 | if (rDuration == 0) | 1237 | if (rDuration == 0) |
1236 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); | 1238 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); |
1237 | else | 1239 | else |
1238 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); | 1240 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); |
1239 | } | 1241 | } |
1240 | } else { | 1242 | } else { |
1241 | kdDebug(5800) << "we don't understand this type of recurrence!" << endl; | 1243 | kdDebug(5800) << "we don't understand this type of recurrence!" << endl; |
1242 | } // if | 1244 | } // if |
1243 | } // repeats | 1245 | } // repeats |
1244 | 1246 | ||
1245 | 1247 | ||
1246 | // recurrence exceptions | 1248 | // recurrence exceptions |
1247 | if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) { | 1249 | if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) { |
1248 | s = fakeCString(vObjectUStringZValue(vo)); | 1250 | s = fakeCString(vObjectUStringZValue(vo)); |
1249 | QStringList exDates = QStringList::split(",",s); | 1251 | QStringList exDates = QStringList::split(",",s); |
1250 | QStringList::ConstIterator it; | 1252 | QStringList::ConstIterator it; |
1251 | for(it = exDates.begin(); it != exDates.end(); ++it ) { | 1253 | for(it = exDates.begin(); it != exDates.end(); ++it ) { |
1252 | anEvent->addExDate(ISOToQDate(*it)); | 1254 | anEvent->addExDate(ISOToQDate(*it)); |
1253 | } | 1255 | } |
1254 | deleteStr(s); | 1256 | deleteStr(s); |
1255 | } | 1257 | } |
1256 | 1258 | ||
1257 | // summary | 1259 | // summary |
1258 | if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { | 1260 | if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { |
1259 | s = fakeCString(vObjectUStringZValue(vo)); | 1261 | s = fakeCString(vObjectUStringZValue(vo)); |
1260 | anEvent->setSummary(QString::fromLocal8Bit(s)); | 1262 | anEvent->setSummary(QString::fromLocal8Bit(s)); |
1261 | deleteStr(s); | 1263 | deleteStr(s); |
1262 | } | 1264 | } |
1263 | if ((vo = isAPropertyOf(vevent, VCLocationProp))) { | 1265 | if ((vo = isAPropertyOf(vevent, VCLocationProp))) { |
1264 | s = fakeCString(vObjectUStringZValue(vo)); | 1266 | s = fakeCString(vObjectUStringZValue(vo)); |
1265 | anEvent->setLocation(QString::fromLocal8Bit(s)); | 1267 | anEvent->setLocation(QString::fromLocal8Bit(s)); |
1266 | deleteStr(s); | 1268 | deleteStr(s); |
1267 | } | 1269 | } |
1268 | 1270 | ||
1269 | // description | 1271 | // description |
1270 | if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) { | 1272 | if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) { |
1271 | s = fakeCString(vObjectUStringZValue(vo)); | 1273 | s = fakeCString(vObjectUStringZValue(vo)); |
1272 | if (!anEvent->description().isEmpty()) { | 1274 | if (!anEvent->description().isEmpty()) { |
1273 | anEvent->setDescription(anEvent->description() + "\n" + | 1275 | anEvent->setDescription(anEvent->description() + "\n" + |
1274 | QString::fromLocal8Bit(s)); | 1276 | QString::fromLocal8Bit(s)); |
1275 | } else { | 1277 | } else { |
1276 | anEvent->setDescription(QString::fromLocal8Bit(s)); | 1278 | anEvent->setDescription(QString::fromLocal8Bit(s)); |
1277 | } | 1279 | } |
1278 | deleteStr(s); | 1280 | deleteStr(s); |
1279 | } | 1281 | } |
1280 | 1282 | ||
1281 | // some stupid vCal exporters ignore the standard and use Description | 1283 | // some stupid vCal exporters ignore the standard and use Description |
1282 | // instead of Summary for the default field. Correct for this. | 1284 | // instead of Summary for the default field. Correct for this. |
1283 | if (anEvent->summary().isEmpty() && | 1285 | if (anEvent->summary().isEmpty() && |
1284 | !(anEvent->description().isEmpty())) { | 1286 | !(anEvent->description().isEmpty())) { |
1285 | QString tmpStr = anEvent->description().simplifyWhiteSpace(); | 1287 | QString tmpStr = anEvent->description().simplifyWhiteSpace(); |
1286 | anEvent->setDescription(""); | 1288 | anEvent->setDescription(""); |
1287 | anEvent->setSummary(tmpStr); | 1289 | anEvent->setSummary(tmpStr); |
1288 | } | 1290 | } |
1289 | 1291 | ||
1290 | #if 0 | 1292 | #if 0 |
1291 | // status | 1293 | // status |
1292 | if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { | 1294 | if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { |
1293 | QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); | 1295 | QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); |
1294 | deleteStr(s); | 1296 | deleteStr(s); |
1295 | // TODO: Define Event status | 1297 | // TODO: Define Event status |
1296 | // anEvent->setStatus(tmpStr); | 1298 | // anEvent->setStatus(tmpStr); |
1297 | } | 1299 | } |
1298 | else | 1300 | else |
1299 | // anEvent->setStatus("NEEDS ACTION"); | 1301 | // anEvent->setStatus("NEEDS ACTION"); |
1300 | #endif | 1302 | #endif |
1301 | 1303 | ||
1302 | // secrecy | 1304 | // secrecy |
1303 | int secrecy = Incidence::SecrecyPublic; | 1305 | int secrecy = Incidence::SecrecyPublic; |
1304 | if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { | 1306 | if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { |
1305 | s = fakeCString(vObjectUStringZValue(vo)); | 1307 | s = fakeCString(vObjectUStringZValue(vo)); |
1306 | if (strcmp(s,"PRIVATE") == 0) { | 1308 | if (strcmp(s,"PRIVATE") == 0) { |
1307 | secrecy = Incidence::SecrecyPrivate; | 1309 | secrecy = Incidence::SecrecyPrivate; |
1308 | } else if (strcmp(s,"CONFIDENTIAL") == 0) { | 1310 | } else if (strcmp(s,"CONFIDENTIAL") == 0) { |
1309 | secrecy = Incidence::SecrecyConfidential; | 1311 | secrecy = Incidence::SecrecyConfidential; |
1310 | } | 1312 | } |
1311 | deleteStr(s); | 1313 | deleteStr(s); |
1312 | } | 1314 | } |
1313 | anEvent->setSecrecy(secrecy); | 1315 | anEvent->setSecrecy(secrecy); |
1314 | 1316 | ||
1315 | // categories | 1317 | // categories |
1316 | QStringList tmpStrList; | 1318 | QStringList tmpStrList; |
1317 | if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { | 1319 | if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { |
1318 | s = fakeCString(vObjectUStringZValue(vo)); | 1320 | s = fakeCString(vObjectUStringZValue(vo)); |
1319 | QString categories = QString::fromLocal8Bit(s); | 1321 | QString categories = QString::fromLocal8Bit(s); |
1320 | deleteStr(s); | 1322 | deleteStr(s); |
1321 | tmpStrList = QStringList::split( ';', categories ); | 1323 | tmpStrList = QStringList::split( ';', categories ); |
1322 | anEvent->setCategories(tmpStrList); | 1324 | anEvent->setCategories(tmpStrList); |
1323 | } | 1325 | } |
1324 | 1326 | ||
1325 | // attachments | 1327 | // attachments |
1326 | initPropIterator(&voi, vevent); | 1328 | initPropIterator(&voi, vevent); |
1327 | while (moreIteration(&voi)) { | 1329 | while (moreIteration(&voi)) { |
1328 | vo = nextVObject(&voi); | 1330 | vo = nextVObject(&voi); |
1329 | if (strcmp(vObjectName(vo), VCAttachProp) == 0) { | 1331 | if (strcmp(vObjectName(vo), VCAttachProp) == 0) { |
1330 | s = fakeCString(vObjectUStringZValue(vo)); | 1332 | s = fakeCString(vObjectUStringZValue(vo)); |
1331 | anEvent->addAttachment(new Attachment(QString(s))); | 1333 | anEvent->addAttachment(new Attachment(QString(s))); |
1332 | deleteStr(s); | 1334 | deleteStr(s); |
1333 | } | 1335 | } |
1334 | } | 1336 | } |
1335 | 1337 | ||
1336 | // resources | 1338 | // resources |
1337 | if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { | 1339 | if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { |
1338 | QString resources = (s = fakeCString(vObjectUStringZValue(vo))); | 1340 | QString resources = (s = fakeCString(vObjectUStringZValue(vo))); |
1339 | deleteStr(s); | 1341 | deleteStr(s); |
1340 | tmpStrList = QStringList::split( ';', resources ); | 1342 | tmpStrList = QStringList::split( ';', resources ); |
1341 | anEvent->setResources(tmpStrList); | 1343 | anEvent->setResources(tmpStrList); |
1342 | } | 1344 | } |
1343 | /* alarm stuff */ | 1345 | /* alarm stuff */ |
1344 | if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { | 1346 | if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { |
1345 | Alarm* alarm = anEvent->newAlarm(); | 1347 | Alarm* alarm = anEvent->newAlarm(); |
1346 | VObject *a; | 1348 | VObject *a; |
1347 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { | 1349 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { |
1348 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); | 1350 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); |
1349 | deleteStr(s); | 1351 | deleteStr(s); |
1350 | } | 1352 | } |
1351 | alarm->setEnabled(true); | 1353 | alarm->setEnabled(true); |
1352 | if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { | 1354 | if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { |
1353 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { | 1355 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { |
1354 | s = fakeCString(vObjectUStringZValue(a)); | 1356 | s = fakeCString(vObjectUStringZValue(a)); |
1355 | alarm->setProcedureAlarm(QFile::decodeName(s)); | 1357 | alarm->setProcedureAlarm(QFile::decodeName(s)); |
1356 | deleteStr(s); | 1358 | deleteStr(s); |
1357 | } | 1359 | } |
1358 | } | 1360 | } |
1359 | if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { | 1361 | if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { |
1360 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { | 1362 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { |
1361 | s = fakeCString(vObjectUStringZValue(a)); | 1363 | s = fakeCString(vObjectUStringZValue(a)); |
1362 | alarm->setAudioAlarm(QFile::decodeName(s)); | 1364 | alarm->setAudioAlarm(QFile::decodeName(s)); |
1363 | deleteStr(s); | 1365 | deleteStr(s); |
1364 | } | 1366 | } |
1365 | } | 1367 | } |
1366 | } | 1368 | } |
1367 | 1369 | ||
1368 | // priority | 1370 | // priority |
1369 | if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { | 1371 | if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { |
1370 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 1372 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
1371 | deleteStr(s); | 1373 | deleteStr(s); |
1372 | } | 1374 | } |
1373 | 1375 | ||
1374 | // transparency | 1376 | // transparency |
1375 | if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { | 1377 | if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { |
1376 | int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); | 1378 | int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); |
1377 | anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); | 1379 | anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); |
1378 | deleteStr(s); | 1380 | deleteStr(s); |
1379 | } | 1381 | } |
1380 | 1382 | ||
1381 | // related event | 1383 | // related event |
1382 | if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { | 1384 | if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { |
1383 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); | 1385 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); |
1384 | deleteStr(s); | 1386 | deleteStr(s); |
1385 | mEventsRelate.append(anEvent); | 1387 | mEventsRelate.append(anEvent); |
1386 | } | 1388 | } |
1387 | 1389 | ||
1388 | /* PILOT SYNC STUFF */ | 1390 | /* PILOT SYNC STUFF */ |
1389 | if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { | 1391 | if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { |
1390 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 1392 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
1391 | deleteStr(s); | 1393 | deleteStr(s); |
1392 | } | 1394 | } |
1393 | else | 1395 | else |
1394 | anEvent->setPilotId(0); | 1396 | anEvent->setPilotId(0); |
1395 | 1397 | ||
1396 | if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { | 1398 | if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { |
1397 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 1399 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
1398 | deleteStr(s); | 1400 | deleteStr(s); |
1399 | } | 1401 | } |
1400 | else | 1402 | else |
1401 | anEvent->setSyncStatus(Event::SYNCMOD); | 1403 | anEvent->setSyncStatus(Event::SYNCMOD); |
1402 | 1404 | ||
1403 | return anEvent; | 1405 | return anEvent; |
1404 | } | 1406 | } |
1405 | 1407 | ||
1406 | 1408 | ||
1407 | QString VCalFormat::qDateToISO(const QDate &qd) | 1409 | QString VCalFormat::qDateToISO(const QDate &qd) |
1408 | { | 1410 | { |
1409 | QString tmpStr; | 1411 | QString tmpStr; |
1410 | 1412 | ||
1411 | ASSERT(qd.isValid()); | 1413 | Q_ASSERT(qd.isValid()); |
1412 | 1414 | ||
1413 | tmpStr.sprintf("%.2d%.2d%.2d", | 1415 | tmpStr.sprintf("%.2d%.2d%.2d", |
1414 | qd.year(), qd.month(), qd.day()); | 1416 | qd.year(), qd.month(), qd.day()); |
1415 | return tmpStr; | 1417 | return tmpStr; |
1416 | 1418 | ||
1417 | } | 1419 | } |
1418 | 1420 | ||
1419 | QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) | 1421 | QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) |
1420 | { | 1422 | { |
1421 | QString tmpStr; | 1423 | QString tmpStr; |
1422 | 1424 | ||
1423 | ASSERT(qdt.date().isValid()); | 1425 | Q_ASSERT(qdt.date().isValid()); |
1424 | ASSERT(qdt.time().isValid()); | 1426 | Q_ASSERT(qdt.time().isValid()); |
1425 | if (zulu && !useLocalTime ) { | 1427 | if (zulu && !useLocalTime ) { |
1426 | QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60); | 1428 | QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60); |
1427 | tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", | 1429 | tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", |
1428 | tmpDT.date().year(), tmpDT.date().month(), | 1430 | tmpDT.date().year(), tmpDT.date().month(), |
1429 | tmpDT.date().day(), tmpDT.time().hour(), | 1431 | tmpDT.date().day(), tmpDT.time().hour(), |
1430 | tmpDT.time().minute(), tmpDT.time().second()); | 1432 | tmpDT.time().minute(), tmpDT.time().second()); |
1431 | } else { | 1433 | } else { |
1432 | tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", | 1434 | tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", |
1433 | qdt.date().year(), qdt.date().month(), | 1435 | qdt.date().year(), qdt.date().month(), |
1434 | qdt.date().day(), qdt.time().hour(), | 1436 | qdt.date().day(), qdt.time().hour(), |
1435 | qdt.time().minute(), qdt.time().second()); | 1437 | qdt.time().minute(), qdt.time().second()); |
1436 | } | 1438 | } |
1437 | return tmpStr; | 1439 | return tmpStr; |
1438 | } | 1440 | } |
1439 | 1441 | ||
1440 | QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) | 1442 | QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) |
1441 | { | 1443 | { |
1442 | QDate tmpDate; | 1444 | QDate tmpDate; |
1443 | QTime tmpTime; | 1445 | QTime tmpTime; |
1444 | QString tmpStr; | 1446 | QString tmpStr; |
1445 | int year, month, day, hour, minute, second; | 1447 | int year, month, day, hour, minute, second; |
1446 | 1448 | ||
1447 | tmpStr = dtStr; | 1449 | tmpStr = dtStr; |
1448 | year = tmpStr.left(4).toInt(); | 1450 | year = tmpStr.left(4).toInt(); |
1449 | month = tmpStr.mid(4,2).toInt(); | 1451 | month = tmpStr.mid(4,2).toInt(); |
1450 | day = tmpStr.mid(6,2).toInt(); | 1452 | day = tmpStr.mid(6,2).toInt(); |
1451 | hour = tmpStr.mid(9,2).toInt(); | 1453 | hour = tmpStr.mid(9,2).toInt(); |
1452 | minute = tmpStr.mid(11,2).toInt(); | 1454 | minute = tmpStr.mid(11,2).toInt(); |
1453 | second = tmpStr.mid(13,2).toInt(); | 1455 | second = tmpStr.mid(13,2).toInt(); |
1454 | tmpDate.setYMD(year, month, day); | 1456 | tmpDate.setYMD(year, month, day); |
1455 | tmpTime.setHMS(hour, minute, second); | 1457 | tmpTime.setHMS(hour, minute, second); |
1456 | 1458 | ||
1457 | ASSERT(tmpDate.isValid()); | 1459 | Q_ASSERT(tmpDate.isValid()); |
1458 | ASSERT(tmpTime.isValid()); | 1460 | Q_ASSERT(tmpTime.isValid()); |
1459 | QDateTime tmpDT(tmpDate, tmpTime); | 1461 | QDateTime tmpDT(tmpDate, tmpTime); |
1460 | // correct for GMT if string is in Zulu format | 1462 | // correct for GMT if string is in Zulu format |
1461 | if (dtStr.at(dtStr.length()-1) == 'Z') | 1463 | if (dtStr.at(dtStr.length()-1) == 'Z') |
1462 | tmpDT = tmpDT.addSecs (KGlobal::locale()->localTimeOffset( tmpDT )*60); | 1464 | tmpDT = tmpDT.addSecs (KGlobal::locale()->localTimeOffset( tmpDT )*60); |
1463 | return tmpDT; | 1465 | return tmpDT; |
1464 | } | 1466 | } |
1465 | 1467 | ||
1466 | QDate VCalFormat::ISOToQDate(const QString &dateStr) | 1468 | QDate VCalFormat::ISOToQDate(const QString &dateStr) |
1467 | { | 1469 | { |
1468 | int year, month, day; | 1470 | int year, month, day; |
1469 | 1471 | ||
1470 | year = dateStr.left(4).toInt(); | 1472 | year = dateStr.left(4).toInt(); |
1471 | month = dateStr.mid(4,2).toInt(); | 1473 | month = dateStr.mid(4,2).toInt(); |
1472 | day = dateStr.mid(6,2).toInt(); | 1474 | day = dateStr.mid(6,2).toInt(); |
1473 | 1475 | ||
1474 | return(QDate(year, month, day)); | 1476 | return(QDate(year, month, day)); |
1475 | } | 1477 | } |
1476 | 1478 | ||
1477 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. | 1479 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. |
1478 | // and break it down from it's tree-like format into the dictionary format | 1480 | // and break it down from it's tree-like format into the dictionary format |
1479 | // that is used internally in the VCalFormat. | 1481 | // that is used internally in the VCalFormat. |
1480 | void VCalFormat::populate(VObject *vcal) | 1482 | void VCalFormat::populate(VObject *vcal) |
1481 | { | 1483 | { |
1482 | // this function will populate the caldict dictionary and other event | 1484 | // this function will populate the caldict dictionary and other event |
1483 | // lists. It turns vevents into Events and then inserts them. | 1485 | // lists. It turns vevents into Events and then inserts them. |
1484 | 1486 | ||
1485 | VObjectIterator i; | 1487 | VObjectIterator i; |
1486 | VObject *curVO, *curVOProp; | 1488 | VObject *curVO, *curVOProp; |
1487 | Event *anEvent; | 1489 | Event *anEvent; |
1488 | 1490 | ||
1489 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { | 1491 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { |
1490 | char *methodType = 0; | 1492 | char *methodType = 0; |
1491 | methodType = fakeCString(vObjectUStringZValue(curVO)); | 1493 | methodType = fakeCString(vObjectUStringZValue(curVO)); |
1492 | kdDebug() << "This calendar is an iTIP transaction of type '" | 1494 | kdDebug() << "This calendar is an iTIP transaction of type '" |
1493 | << methodType << "'" << endl; | 1495 | << methodType << "'" << endl; |
1494 | delete methodType; | 1496 | delete methodType; |
1495 | } | 1497 | } |
1496 | 1498 | ||
1497 | // warn the user that we might have trouble reading non-known calendar. | 1499 | // warn the user that we might have trouble reading non-known calendar. |
1498 | if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { | 1500 | if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { |
1499 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1501 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1500 | if (strcmp(productId().local8Bit(), s) != 0) | 1502 | if (strcmp(productId().local8Bit(), s) != 0) |
1501 | kdDebug() << "This vCalendar file was not created by KOrganizer " | 1503 | kdDebug() << "This vCalendar file was not created by KOrganizer " |
1502 | "or any other product we support. Loading anyway..." << endl; | 1504 | "or any other product we support. Loading anyway..." << endl; |
1503 | mLoadedProductId = s; | 1505 | mLoadedProductId = s; |
1504 | deleteStr(s); | 1506 | deleteStr(s); |
1505 | } | 1507 | } |
1506 | 1508 | ||
1507 | // warn the user we might have trouble reading this unknown version. | 1509 | // warn the user we might have trouble reading this unknown version. |
1508 | if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { | 1510 | if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { |
1509 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1511 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1510 | if (strcmp(_VCAL_VERSION, s) != 0) | 1512 | if (strcmp(_VCAL_VERSION, s) != 0) |
1511 | kdDebug() << "This vCalendar file has version " << s | 1513 | kdDebug() << "This vCalendar file has version " << s |
1512 | << "We only support " << _VCAL_VERSION << endl; | 1514 | << "We only support " << _VCAL_VERSION << endl; |
1513 | deleteStr(s); | 1515 | deleteStr(s); |
1514 | } | 1516 | } |
1515 | 1517 | ||
1516 | // set the time zone | 1518 | // set the time zone |
1517 | if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { | 1519 | if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { |
1518 | if ( vObjectUStringZValue(curVO) != 0 ) { | 1520 | if ( vObjectUStringZValue(curVO) != 0 ) { |
1519 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1521 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1520 | mCalendar->setTimeZone(s); | 1522 | mCalendar->setTimeZone(s); |
1521 | deleteStr(s); | 1523 | deleteStr(s); |
1522 | } | 1524 | } |
1523 | } | 1525 | } |
1524 | 1526 | ||
1525 | // Store all events with a relatedTo property in a list for post-processing | 1527 | // Store all events with a relatedTo property in a list for post-processing |
1526 | mEventsRelate.clear(); | 1528 | mEventsRelate.clear(); |
1527 | mTodosRelate.clear(); | 1529 | mTodosRelate.clear(); |
1528 | 1530 | ||
1529 | initPropIterator(&i, vcal); | 1531 | initPropIterator(&i, vcal); |
1530 | 1532 | ||
1531 | // go through all the vobjects in the vcal | 1533 | // go through all the vobjects in the vcal |
1532 | while (moreIteration(&i)) { | 1534 | while (moreIteration(&i)) { |
1533 | curVO = nextVObject(&i); | 1535 | curVO = nextVObject(&i); |
1534 | 1536 | ||
1535 | /************************************************************************/ | 1537 | /************************************************************************/ |
1536 | 1538 | ||
1537 | // now, check to see that the object is an event or todo. | 1539 | // now, check to see that the object is an event or todo. |
1538 | if (strcmp(vObjectName(curVO), VCEventProp) == 0) { | 1540 | if (strcmp(vObjectName(curVO), VCEventProp) == 0) { |
1539 | 1541 | ||
1540 | if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { | 1542 | if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { |
1541 | char *s; | 1543 | char *s; |
1542 | s = fakeCString(vObjectUStringZValue(curVOProp)); | 1544 | s = fakeCString(vObjectUStringZValue(curVOProp)); |
1543 | // check to see if event was deleted by the kpilot conduit | 1545 | // check to see if event was deleted by the kpilot conduit |
1544 | if (atoi(s) == Event::SYNCDEL) { | 1546 | if (atoi(s) == Event::SYNCDEL) { |
1545 | deleteStr(s); | 1547 | deleteStr(s); |
1546 | kdDebug(5800) << "skipping pilot-deleted event" << endl; | 1548 | kdDebug(5800) << "skipping pilot-deleted event" << endl; |
1547 | goto SKIP; | 1549 | goto SKIP; |
1548 | } | 1550 | } |
1549 | deleteStr(s); | 1551 | deleteStr(s); |
1550 | } | 1552 | } |
1551 | 1553 | ||
1552 | // this code checks to see if we are trying to read in an event | 1554 | // this code checks to see if we are trying to read in an event |
1553 | // that we already find to be in the calendar. If we find this | 1555 | // that we already find to be in the calendar. If we find this |
1554 | // to be the case, we skip the event. | 1556 | // to be the case, we skip the event. |
1555 | if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { | 1557 | if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { |
1556 | char *s = fakeCString(vObjectUStringZValue(curVOProp)); | 1558 | char *s = fakeCString(vObjectUStringZValue(curVOProp)); |
1557 | QString tmpStr(s); | 1559 | QString tmpStr(s); |
1558 | deleteStr(s); | 1560 | deleteStr(s); |
1559 | 1561 | ||
1560 | if (mCalendar->event(tmpStr)) { | 1562 | if (mCalendar->event(tmpStr)) { |
1561 | goto SKIP; | 1563 | goto SKIP; |
1562 | } | 1564 | } |
1563 | if (mCalendar->todo(tmpStr)) { | 1565 | if (mCalendar->todo(tmpStr)) { |
1564 | goto SKIP; | 1566 | goto SKIP; |
1565 | } | 1567 | } |
1566 | } | 1568 | } |
1567 | 1569 | ||
1568 | if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && | 1570 | if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && |
1569 | (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { | 1571 | (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { |
1570 | kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; | 1572 | kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; |
1571 | goto SKIP; | 1573 | goto SKIP; |
1572 | } | 1574 | } |
1573 | 1575 | ||
1574 | anEvent = VEventToEvent(curVO); | 1576 | anEvent = VEventToEvent(curVO); |
1575 | // we now use addEvent instead of insertEvent so that the | 1577 | // we now use addEvent instead of insertEvent so that the |
1576 | // signal/slot get connected. | 1578 | // signal/slot get connected. |
1577 | if (anEvent) { | 1579 | if (anEvent) { |
1578 | if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { | 1580 | if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { |
1579 | kdDebug() << "VCalFormat::populate(): Event has invalid dates." | 1581 | kdDebug() << "VCalFormat::populate(): Event has invalid dates." |
1580 | << endl; | 1582 | << endl; |
1581 | } else { | 1583 | } else { |
1582 | mCalendar->addEvent(anEvent); | 1584 | mCalendar->addEvent(anEvent); |
1583 | } | 1585 | } |
1584 | } else { | 1586 | } else { |
1585 | // some sort of error must have occurred while in translation. | 1587 | // some sort of error must have occurred while in translation. |
1586 | goto SKIP; | 1588 | goto SKIP; |
1587 | } | 1589 | } |
1588 | } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { | 1590 | } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { |
1589 | Todo *aTodo = VTodoToEvent(curVO); | 1591 | Todo *aTodo = VTodoToEvent(curVO); |
1590 | mCalendar->addTodo(aTodo); | 1592 | mCalendar->addTodo(aTodo); |
1591 | } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || | 1593 | } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || |
1592 | (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || | 1594 | (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || |
1593 | (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { | 1595 | (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { |
1594 | // do nothing, we know these properties and we want to skip them. | 1596 | // do nothing, we know these properties and we want to skip them. |
1595 | // we have either already processed them or are ignoring them. | 1597 | // we have either already processed them or are ignoring them. |
1596 | ; | 1598 | ; |
1597 | } else { | 1599 | } else { |
1598 | kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; | 1600 | kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; |
1599 | } | 1601 | } |
1600 | SKIP: | 1602 | SKIP: |
1601 | ; | 1603 | ; |
1602 | } // while | 1604 | } // while |
1603 | 1605 | ||
1604 | // Post-Process list of events with relations, put Event objects in relation | 1606 | // Post-Process list of events with relations, put Event objects in relation |
1605 | Event *ev; | 1607 | Event *ev; |
1606 | for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { | 1608 | for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { |
1607 | Incidence * inc = mCalendar->event(ev->relatedToUid()); | 1609 | Incidence * inc = mCalendar->event(ev->relatedToUid()); |
1608 | if ( inc ) | 1610 | if ( inc ) |
1609 | ev->setRelatedTo( inc ); | 1611 | ev->setRelatedTo( inc ); |
1610 | } | 1612 | } |
1611 | Todo *todo; | 1613 | Todo *todo; |
1612 | for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { | 1614 | for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { |
1613 | Incidence * inc = mCalendar->todo(todo->relatedToUid()); | 1615 | Incidence * inc = mCalendar->todo(todo->relatedToUid()); |
1614 | if ( inc ) | 1616 | if ( inc ) |
1615 | todo->setRelatedTo( inc ); | 1617 | todo->setRelatedTo( inc ); |
1616 | } | 1618 | } |
1617 | } | 1619 | } |
1618 | 1620 | ||
1619 | const char *VCalFormat::dayFromNum(int day) | 1621 | const char *VCalFormat::dayFromNum(int day) |
1620 | { | 1622 | { |
1621 | const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; | 1623 | const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; |
1622 | 1624 | ||
1623 | return days[day]; | 1625 | return days[day]; |
1624 | } | 1626 | } |
1625 | 1627 | ||
1626 | int VCalFormat::numFromDay(const QString &day) | 1628 | int VCalFormat::numFromDay(const QString &day) |
1627 | { | 1629 | { |
1628 | if (day == "MO ") return 0; | 1630 | if (day == "MO ") return 0; |
1629 | if (day == "TU ") return 1; | 1631 | if (day == "TU ") return 1; |
1630 | if (day == "WE ") return 2; | 1632 | if (day == "WE ") return 2; |
1631 | if (day == "TH ") return 3; | 1633 | if (day == "TH ") return 3; |
1632 | if (day == "FR ") return 4; | 1634 | if (day == "FR ") return 4; |
1633 | if (day == "SA ") return 5; | 1635 | if (day == "SA ") return 5; |
1634 | if (day == "SU ") return 6; | 1636 | if (day == "SU ") return 6; |
1635 | 1637 | ||
1636 | return -1; // something bad happened. :) | 1638 | return -1; // something bad happened. :) |
1637 | } | 1639 | } |
1638 | Attendee::Role VCalFormat::readRole(const char *s) const | 1640 | Attendee::Role VCalFormat::readRole(const char *s) const |
1639 | { | 1641 | { |
1640 | QString statStr = s; | 1642 | QString statStr = s; |
1641 | statStr = statStr.upper(); | 1643 | statStr = statStr.upper(); |
1642 | Attendee::Role role = Attendee::ReqParticipant; | 1644 | Attendee::Role role = Attendee::ReqParticipant; |
1643 | 1645 | ||
1644 | if ( statStr == "OWNER") | 1646 | if ( statStr == "OWNER") |
1645 | role = Attendee::Chair; | 1647 | role = Attendee::Chair; |
1646 | // enum Role { ReqParticipant, OptParticipant, NonParticipant, Chair }; | 1648 | // enum Role { ReqParticipant, OptParticipant, NonParticipant, Chair }; |
1647 | 1649 | ||
1648 | return role; | 1650 | return role; |
1649 | } | 1651 | } |
1650 | 1652 | ||
1651 | QCString VCalFormat::writeRole(Attendee::Role role) const | 1653 | Q3CString VCalFormat::writeRole(Attendee::Role role) const |
1652 | { | 1654 | { |
1653 | if ( role == Attendee::Chair ) | 1655 | if ( role == Attendee::Chair ) |
1654 | return "OWNER"; | 1656 | return "OWNER"; |
1655 | return "ATTENDEE"; | 1657 | return "ATTENDEE"; |
1656 | } | 1658 | } |
1657 | Attendee::PartStat VCalFormat::readStatus(const char *s) const | 1659 | Attendee::PartStat VCalFormat::readStatus(const char *s) const |
1658 | { | 1660 | { |
1659 | QString statStr = s; | 1661 | QString statStr = s; |
1660 | statStr = statStr.upper(); | 1662 | statStr = statStr.upper(); |
1661 | Attendee::PartStat status; | 1663 | Attendee::PartStat status; |
1662 | 1664 | ||
1663 | if (statStr == "X-ACTION") | 1665 | if (statStr == "X-ACTION") |
1664 | status = Attendee::NeedsAction; | 1666 | status = Attendee::NeedsAction; |
1665 | else if (statStr == "NEEDS ACTION") | 1667 | else if (statStr == "NEEDS ACTION") |
1666 | status = Attendee::NeedsAction; | 1668 | status = Attendee::NeedsAction; |
1667 | else if (statStr== "ACCEPTED") | 1669 | else if (statStr== "ACCEPTED") |
1668 | status = Attendee::Accepted; | 1670 | status = Attendee::Accepted; |
1669 | else if (statStr== "SENT") | 1671 | else if (statStr== "SENT") |
1670 | status = Attendee::NeedsAction; | 1672 | status = Attendee::NeedsAction; |
1671 | else if (statStr== "TENTATIVE") | 1673 | else if (statStr== "TENTATIVE") |
1672 | status = Attendee::Tentative; | 1674 | status = Attendee::Tentative; |
1673 | else if (statStr== "CONFIRMED") | 1675 | else if (statStr== "CONFIRMED") |
1674 | status = Attendee::Accepted; | 1676 | status = Attendee::Accepted; |
1675 | else if (statStr== "DECLINED") | 1677 | else if (statStr== "DECLINED") |
1676 | status = Attendee::Declined; | 1678 | status = Attendee::Declined; |
1677 | else if (statStr== "COMPLETED") | 1679 | else if (statStr== "COMPLETED") |
1678 | status = Attendee::Completed; | 1680 | status = Attendee::Completed; |
1679 | else if (statStr== "DELEGATED") | 1681 | else if (statStr== "DELEGATED") |
1680 | status = Attendee::Delegated; | 1682 | status = Attendee::Delegated; |
1681 | else { | 1683 | else { |
1682 | kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; | 1684 | kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; |
1683 | status = Attendee::NeedsAction; | 1685 | status = Attendee::NeedsAction; |
1684 | } | 1686 | } |
1685 | 1687 | ||
1686 | return status; | 1688 | return status; |
1687 | } | 1689 | } |
1688 | 1690 | ||
1689 | QCString VCalFormat::writeStatus(Attendee::PartStat status) const | 1691 | Q3CString VCalFormat::writeStatus(Attendee::PartStat status) const |
1690 | { | 1692 | { |
1691 | switch(status) { | 1693 | switch(status) { |
1692 | default: | 1694 | default: |
1693 | case Attendee::NeedsAction: | 1695 | case Attendee::NeedsAction: |
1694 | return "NEEDS ACTION"; | 1696 | return "NEEDS ACTION"; |
1695 | break; | 1697 | break; |
1696 | case Attendee::Accepted: | 1698 | case Attendee::Accepted: |
1697 | return "ACCEPTED"; | 1699 | return "ACCEPTED"; |
1698 | break; | 1700 | break; |
1699 | case Attendee::Declined: | 1701 | case Attendee::Declined: |
1700 | return "DECLINED"; | 1702 | return "DECLINED"; |
1701 | break; | 1703 | break; |
1702 | case Attendee::Tentative: | 1704 | case Attendee::Tentative: |
1703 | return "TENTATIVE"; | 1705 | return "TENTATIVE"; |
1704 | break; | 1706 | break; |
1705 | case Attendee::Delegated: | 1707 | case Attendee::Delegated: |
1706 | return "DELEGATED"; | 1708 | return "DELEGATED"; |
1707 | break; | 1709 | break; |
1708 | case Attendee::Completed: | 1710 | case Attendee::Completed: |
1709 | return "COMPLETED"; | 1711 | return "COMPLETED"; |
1710 | break; | 1712 | break; |
1711 | case Attendee::InProcess: | 1713 | case Attendee::InProcess: |
1712 | return "NEEDS ACTION"; | 1714 | return "NEEDS ACTION"; |
1713 | break; | 1715 | break; |
1714 | } | 1716 | } |
1715 | } | 1717 | } |
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h index 6dae3d2..cac9634 100644 --- a/libkcal/vcalformat.h +++ b/libkcal/vcalformat.h | |||
@@ -1,113 +1,116 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef _VCALFORMAT_H | 22 | #ifndef _VCALFORMAT_H |
23 | #define _VCALFORMAT_H | 23 | #define _VCALFORMAT_H |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | //Added by qt3to4: | ||
27 | #include <Q3CString> | ||
28 | #include <Q3PtrList> | ||
26 | 29 | ||
27 | #define _VCAL_VERSION "1.0" | 30 | #define _VCAL_VERSION "1.0" |
28 | 31 | ||
29 | class VObject; | 32 | class VObject; |
30 | 33 | ||
31 | namespace KCal { | 34 | namespace KCal { |
32 | 35 | ||
33 | /** | 36 | /** |
34 | This class implements the vCalendar format. It provides methods for | 37 | This class implements the vCalendar format. It provides methods for |
35 | loading/saving/converting vCalendar format data into the internal KOrganizer | 38 | loading/saving/converting vCalendar format data into the internal KOrganizer |
36 | representation as Calendar and Events. | 39 | representation as Calendar and Events. |
37 | 40 | ||
38 | @short vCalendar format implementation | 41 | @short vCalendar format implementation |
39 | */ | 42 | */ |
40 | class VCalFormat : public CalFormat { | 43 | class VCalFormat : public CalFormat { |
41 | public: | 44 | public: |
42 | VCalFormat(); | 45 | VCalFormat(); |
43 | virtual ~VCalFormat(); | 46 | virtual ~VCalFormat(); |
44 | 47 | ||
45 | /** loads a calendar on disk in vCalendar format into the current calendar. | 48 | /** loads a calendar on disk in vCalendar format into the current calendar. |
46 | * any information already present is lost. Returns TRUE if successful, | 49 | * any information already present is lost. Returns TRUE if successful, |
47 | * else returns FALSE. | 50 | * else returns FALSE. |
48 | * @param fileName the name of the calendar on disk. | 51 | * @param fileName the name of the calendar on disk. |
49 | */ | 52 | */ |
50 | bool load(Calendar *,const QString &fileName ); | 53 | bool load(Calendar *,const QString &fileName ); |
51 | /** writes out the calendar to disk in vCalendar format. Returns true if | 54 | /** writes out the calendar to disk in vCalendar format. Returns true if |
52 | * successful and false on error. | 55 | * successful and false on error. |
53 | * @param fileName the name of the file | 56 | * @param fileName the name of the file |
54 | */ | 57 | */ |
55 | bool save(Calendar *,const QString &fileName ); | 58 | bool save(Calendar *,const QString &fileName ); |
56 | 59 | ||
57 | /** | 60 | /** |
58 | Parse string and populate calendar with that information. | 61 | Parse string and populate calendar with that information. |
59 | */ | 62 | */ |
60 | bool fromString( Calendar *, const QString & ); | 63 | bool fromString( Calendar *, const QString & ); |
61 | /** | 64 | /** |
62 | Return calendar information as string. | 65 | Return calendar information as string. |
63 | */ | 66 | */ |
64 | void setLocalTime ( bool ); | 67 | void setLocalTime ( bool ); |
65 | QString toString( Calendar * ); | 68 | QString toString( Calendar * ); |
66 | QString eventToString( Event *, Calendar *calendar, bool useLocalTime = true ); | 69 | QString eventToString( Event *, Calendar *calendar, bool useLocalTime = true ); |
67 | QString todoToString( Todo * ,Calendar *calendar, bool useLocalTime = true ); | 70 | QString todoToString( Todo * ,Calendar *calendar, bool useLocalTime = true ); |
68 | 71 | ||
69 | protected: | 72 | protected: |
70 | /** translates a VObject of the TODO type into a Event */ | 73 | /** translates a VObject of the TODO type into a Event */ |
71 | Todo *VTodoToEvent(VObject *vtodo); | 74 | Todo *VTodoToEvent(VObject *vtodo); |
72 | /** translates a VObject into a Event and returns a pointer to it. */ | 75 | /** translates a VObject into a Event and returns a pointer to it. */ |
73 | Event *VEventToEvent(VObject *vevent); | 76 | Event *VEventToEvent(VObject *vevent); |
74 | /** translate a Event into a VTodo-type VObject and return pointer */ | 77 | /** translate a Event into a VTodo-type VObject and return pointer */ |
75 | VObject *eventToVTodo(const Todo *anEvent); | 78 | VObject *eventToVTodo(const Todo *anEvent); |
76 | /** translate a Event into a VObject and returns a pointer to it. */ | 79 | /** translate a Event into a VObject and returns a pointer to it. */ |
77 | VObject* eventToVEvent(Event *anEvent); | 80 | VObject* eventToVEvent(Event *anEvent); |
78 | 81 | ||
79 | /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ | 82 | /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ |
80 | QString qDateToISO(const QDate &); | 83 | QString qDateToISO(const QDate &); |
81 | /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ | 84 | /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ |
82 | QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); | 85 | QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); |
83 | /** takes a string in the format YYYYMMDDTHHMMSS and returns a | 86 | /** takes a string in the format YYYYMMDDTHHMMSS and returns a |
84 | * valid QDateTime. */ | 87 | * valid QDateTime. */ |
85 | QDateTime ISOToQDateTime(const QString & dtStr); | 88 | QDateTime ISOToQDateTime(const QString & dtStr); |
86 | /** takes a string in the format YYYYMMDD and returns a | 89 | /** takes a string in the format YYYYMMDD and returns a |
87 | * valid QDate. */ | 90 | * valid QDate. */ |
88 | QDate ISOToQDate(const QString & dtStr); | 91 | QDate ISOToQDate(const QString & dtStr); |
89 | /** takes a vCalendar tree of VObjects, and puts all of them that have | 92 | /** takes a vCalendar tree of VObjects, and puts all of them that have |
90 | * the "event" property into the dictionary, todos in the todo-list, etc. */ | 93 | * the "event" property into the dictionary, todos in the todo-list, etc. */ |
91 | void populate(VObject *vcal); | 94 | void populate(VObject *vcal); |
92 | 95 | ||
93 | /** takes a number 0 - 6 and returns the two letter string of that day, | 96 | /** takes a number 0 - 6 and returns the two letter string of that day, |
94 | * i.e. MO, TU, WE, etc. */ | 97 | * i.e. MO, TU, WE, etc. */ |
95 | const char *dayFromNum(int day); | 98 | const char *dayFromNum(int day); |
96 | /** the reverse of the above function. */ | 99 | /** the reverse of the above function. */ |
97 | int numFromDay(const QString &day); | 100 | int numFromDay(const QString &day); |
98 | Attendee::Role VCalFormat::readRole(const char *s) const; | 101 | Attendee::Role readRole(const char *s) const; |
99 | QCString writeRole(Attendee::Role role) const; | 102 | Q3CString writeRole(Attendee::Role role) const; |
100 | Attendee::PartStat readStatus(const char *s) const; | 103 | Attendee::PartStat readStatus(const char *s) const; |
101 | QCString writeStatus(Attendee::PartStat status) const; | 104 | Q3CString writeStatus(Attendee::PartStat status) const; |
102 | 105 | ||
103 | private: | 106 | private: |
104 | Calendar *mCalendar; | 107 | Calendar *mCalendar; |
105 | bool useLocalTime; | 108 | bool useLocalTime; |
106 | 109 | ||
107 | QPtrList<Event> mEventsRelate; // events with relations | 110 | Q3PtrList<Event> mEventsRelate; // events with relations |
108 | QPtrList<Todo> mTodosRelate; // todos with relations | 111 | Q3PtrList<Todo> mTodosRelate; // todos with relations |
109 | }; | 112 | }; |
110 | 113 | ||
111 | } | 114 | } |
112 | 115 | ||
113 | #endif | 116 | #endif |