-rw-r--r-- | libkcal/alarm.cpp | 36 | ||||
-rw-r--r-- | libkcal/recurrence.cpp | 56 | ||||
-rw-r--r-- | libkcal/sharpformat.cpp | 7 |
3 files changed, 83 insertions, 16 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp index 29e6205..1fc7169 100644 --- a/libkcal/alarm.cpp +++ b/libkcal/alarm.cpp | |||
@@ -1,423 +1,457 @@ | |||
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 | 23 | ||
24 | #include "incidence.h" | 24 | #include "incidence.h" |
25 | #include "todo.h" | 25 | #include "todo.h" |
26 | 26 | ||
27 | #include "alarm.h" | 27 | #include "alarm.h" |
28 | 28 | ||
29 | using namespace KCal; | 29 | using namespace KCal; |
30 | #include <qwidget.h> | 30 | #include <qwidget.h> |
31 | Alarm::Alarm(Incidence *parent) | 31 | Alarm::Alarm(Incidence *parent) |
32 | : mParent(parent), | 32 | : mParent(parent), |
33 | mType(Audio), | 33 | mType(Audio), |
34 | mDescription(""), // to make operator==() not fail | 34 | mDescription(""), // to make operator==() not fail |
35 | mFile(""), // to make operator==() not fail | 35 | mFile(""), // to make operator==() not fail |
36 | mMailSubject(""), // to make operator==() not fail | 36 | mMailSubject(""), // to make operator==() not fail |
37 | mAlarmSnoozeTime(5), | 37 | mAlarmSnoozeTime(5), |
38 | mAlarmRepeatCount(0), | 38 | mAlarmRepeatCount(0), |
39 | mEndOffset(false), | 39 | mEndOffset(false), |
40 | mHasTime(false), | 40 | mHasTime(false), |
41 | mAlarmEnabled(false) | 41 | mAlarmEnabled(false) |
42 | { | 42 | { |
43 | 43 | ||
44 | } | 44 | } |
45 | 45 | ||
46 | Alarm::~Alarm() | 46 | Alarm::~Alarm() |
47 | { | 47 | { |
48 | } | 48 | } |
49 | 49 | ||
50 | bool Alarm::operator==( const Alarm& rhs ) const | 50 | bool Alarm::operator==( const Alarm& rhs ) const |
51 | { | 51 | { |
52 | |||
52 | if ( mType != rhs.mType || | 53 | if ( mType != rhs.mType || |
53 | mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || | 54 | mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || |
54 | mAlarmRepeatCount != rhs.mAlarmRepeatCount || | 55 | mAlarmRepeatCount != rhs.mAlarmRepeatCount || |
55 | mAlarmEnabled != rhs.mAlarmEnabled || | 56 | mAlarmEnabled != rhs.mAlarmEnabled || |
56 | mHasTime != rhs.mHasTime) | 57 | mHasTime != rhs.mHasTime) |
57 | return false; | 58 | return false; |
58 | 59 | ||
60 | #if 0 | ||
61 | if ( mType != rhs.mType ) { | ||
62 | |||
63 | qDebug("aaa1 "); | ||
64 | return false; | ||
65 | } | ||
66 | |||
67 | if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) { | ||
68 | |||
69 | qDebug("aaa2 "); | ||
70 | return false; | ||
71 | } | ||
72 | |||
73 | |||
74 | if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) { | ||
75 | |||
76 | qDebug("aaa3 "); | ||
77 | return false; | ||
78 | } | ||
79 | |||
80 | if ( mAlarmEnabled != rhs.mAlarmEnabled ) { | ||
81 | |||
82 | qDebug("aaa4 "); | ||
83 | return false; | ||
84 | } | ||
85 | |||
86 | if ( mHasTime != rhs.mHasTime ) { | ||
87 | |||
88 | qDebug("aaa5 "); | ||
89 | return false; | ||
90 | } | ||
91 | #endif | ||
92 | |||
93 | |||
59 | if (mHasTime) { | 94 | if (mHasTime) { |
60 | if (mAlarmTime != rhs.mAlarmTime) | 95 | if (mAlarmTime != rhs.mAlarmTime) |
61 | return false; | 96 | return false; |
62 | } else { | 97 | } else { |
63 | if (mOffset != rhs.mOffset || | 98 | if (mOffset != rhs.mOffset || |
64 | mEndOffset != rhs.mEndOffset) | 99 | mEndOffset != rhs.mEndOffset) |
65 | return false; | 100 | return false; |
66 | } | 101 | } |
67 | |||
68 | switch (mType) { | 102 | switch (mType) { |
69 | case Display: | 103 | case Display: |
70 | return mDescription == rhs.mDescription; | 104 | return mDescription == rhs.mDescription; |
71 | 105 | ||
72 | case Email: | 106 | case Email: |
73 | return mDescription == rhs.mDescription && | 107 | return mDescription == rhs.mDescription && |
74 | mMailAttachFiles == rhs.mMailAttachFiles && | 108 | mMailAttachFiles == rhs.mMailAttachFiles && |
75 | mMailAddresses == rhs.mMailAddresses && | 109 | mMailAddresses == rhs.mMailAddresses && |
76 | mMailSubject == rhs.mMailSubject; | 110 | mMailSubject == rhs.mMailSubject; |
77 | 111 | ||
78 | case Procedure: | 112 | case Procedure: |
79 | return mFile == rhs.mFile && | 113 | return mFile == rhs.mFile && |
80 | mDescription == rhs.mDescription; | 114 | mDescription == rhs.mDescription; |
81 | 115 | ||
82 | case Audio: | 116 | case Audio: |
83 | return mFile == rhs.mFile; | 117 | return mFile == rhs.mFile; |
84 | 118 | ||
85 | case Invalid: | 119 | case Invalid: |
86 | break; | 120 | break; |
87 | } | 121 | } |
88 | return false; | 122 | return false; |
89 | } | 123 | } |
90 | 124 | ||
91 | void Alarm::setType(Alarm::Type type) | 125 | void Alarm::setType(Alarm::Type type) |
92 | { | 126 | { |
93 | if (type == mType) | 127 | if (type == mType) |
94 | return; | 128 | return; |
95 | 129 | ||
96 | switch (type) { | 130 | switch (type) { |
97 | case Display: | 131 | case Display: |
98 | mDescription = ""; | 132 | mDescription = ""; |
99 | break; | 133 | break; |
100 | case Procedure: | 134 | case Procedure: |
101 | mFile = mDescription = ""; | 135 | mFile = mDescription = ""; |
102 | break; | 136 | break; |
103 | case Audio: | 137 | case Audio: |
104 | mFile = ""; | 138 | mFile = ""; |
105 | break; | 139 | break; |
106 | case Email: | 140 | case Email: |
107 | mMailSubject = mDescription = ""; | 141 | mMailSubject = mDescription = ""; |
108 | mMailAddresses.clear(); | 142 | mMailAddresses.clear(); |
109 | mMailAttachFiles.clear(); | 143 | mMailAttachFiles.clear(); |
110 | break; | 144 | break; |
111 | case Invalid: | 145 | case Invalid: |
112 | break; | 146 | break; |
113 | default: | 147 | default: |
114 | return; | 148 | return; |
115 | } | 149 | } |
116 | mType = type; | 150 | mType = type; |
117 | mParent->updated(); | 151 | mParent->updated(); |
118 | } | 152 | } |
119 | 153 | ||
120 | Alarm::Type Alarm::type() const | 154 | Alarm::Type Alarm::type() const |
121 | { | 155 | { |
122 | return mType; | 156 | return mType; |
123 | } | 157 | } |
124 | 158 | ||
125 | void Alarm::setAudioAlarm(const QString &audioFile) | 159 | void Alarm::setAudioAlarm(const QString &audioFile) |
126 | { | 160 | { |
127 | mType = Audio; | 161 | mType = Audio; |
128 | mFile = audioFile; | 162 | mFile = audioFile; |
129 | mParent->updated(); | 163 | mParent->updated(); |
130 | } | 164 | } |
131 | 165 | ||
132 | void Alarm::setAudioFile(const QString &audioFile) | 166 | void Alarm::setAudioFile(const QString &audioFile) |
133 | { | 167 | { |
134 | if (mType == Audio) { | 168 | if (mType == Audio) { |
135 | mFile = audioFile; | 169 | mFile = audioFile; |
136 | mParent->updated(); | 170 | mParent->updated(); |
137 | } | 171 | } |
138 | } | 172 | } |
139 | 173 | ||
140 | QString Alarm::audioFile() const | 174 | QString Alarm::audioFile() const |
141 | { | 175 | { |
142 | return (mType == Audio) ? mFile : QString::null; | 176 | return (mType == Audio) ? mFile : QString::null; |
143 | } | 177 | } |
144 | 178 | ||
145 | void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) | 179 | void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) |
146 | { | 180 | { |
147 | mType = Procedure; | 181 | mType = Procedure; |
148 | mFile = programFile; | 182 | mFile = programFile; |
149 | mDescription = arguments; | 183 | mDescription = arguments; |
150 | mParent->updated(); | 184 | mParent->updated(); |
151 | } | 185 | } |
152 | 186 | ||
153 | void Alarm::setProgramFile(const QString &programFile) | 187 | void Alarm::setProgramFile(const QString &programFile) |
154 | { | 188 | { |
155 | if (mType == Procedure) { | 189 | if (mType == Procedure) { |
156 | mFile = programFile; | 190 | mFile = programFile; |
157 | mParent->updated(); | 191 | mParent->updated(); |
158 | } | 192 | } |
159 | } | 193 | } |
160 | 194 | ||
161 | QString Alarm::programFile() const | 195 | QString Alarm::programFile() const |
162 | { | 196 | { |
163 | return (mType == Procedure) ? mFile : QString::null; | 197 | return (mType == Procedure) ? mFile : QString::null; |
164 | } | 198 | } |
165 | 199 | ||
166 | void Alarm::setProgramArguments(const QString &arguments) | 200 | void Alarm::setProgramArguments(const QString &arguments) |
167 | { | 201 | { |
168 | if (mType == Procedure) { | 202 | if (mType == Procedure) { |
169 | mDescription = arguments; | 203 | mDescription = arguments; |
170 | mParent->updated(); | 204 | mParent->updated(); |
171 | } | 205 | } |
172 | } | 206 | } |
173 | 207 | ||
174 | QString Alarm::programArguments() const | 208 | QString Alarm::programArguments() const |
175 | { | 209 | { |
176 | return (mType == Procedure) ? mDescription : QString::null; | 210 | return (mType == Procedure) ? mDescription : QString::null; |
177 | } | 211 | } |
178 | 212 | ||
179 | void Alarm::setEmailAlarm(const QString &subject, const QString &text, | 213 | void Alarm::setEmailAlarm(const QString &subject, const QString &text, |
180 | const QValueList<Person> &addressees, const QStringList &attachments) | 214 | const QValueList<Person> &addressees, const QStringList &attachments) |
181 | { | 215 | { |
182 | mType = Email; | 216 | mType = Email; |
183 | mMailSubject = subject; | 217 | mMailSubject = subject; |
184 | mDescription = text; | 218 | mDescription = text; |
185 | mMailAddresses = addressees; | 219 | mMailAddresses = addressees; |
186 | mMailAttachFiles = attachments; | 220 | mMailAttachFiles = attachments; |
187 | mParent->updated(); | 221 | mParent->updated(); |
188 | } | 222 | } |
189 | 223 | ||
190 | void Alarm::setMailAddress(const Person &mailAddress) | 224 | void Alarm::setMailAddress(const Person &mailAddress) |
191 | { | 225 | { |
192 | if (mType == Email) { | 226 | if (mType == Email) { |
193 | mMailAddresses.clear(); | 227 | mMailAddresses.clear(); |
194 | mMailAddresses += mailAddress; | 228 | mMailAddresses += mailAddress; |
195 | mParent->updated(); | 229 | mParent->updated(); |
196 | } | 230 | } |
197 | } | 231 | } |
198 | 232 | ||
199 | void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) | 233 | void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) |
200 | { | 234 | { |
201 | if (mType == Email) { | 235 | if (mType == Email) { |
202 | mMailAddresses = mailAddresses; | 236 | mMailAddresses = mailAddresses; |
203 | mParent->updated(); | 237 | mParent->updated(); |
204 | } | 238 | } |
205 | } | 239 | } |
206 | 240 | ||
207 | void Alarm::addMailAddress(const Person &mailAddress) | 241 | void Alarm::addMailAddress(const Person &mailAddress) |
208 | { | 242 | { |
209 | if (mType == Email) { | 243 | if (mType == Email) { |
210 | mMailAddresses += mailAddress; | 244 | mMailAddresses += mailAddress; |
211 | mParent->updated(); | 245 | mParent->updated(); |
212 | } | 246 | } |
213 | } | 247 | } |
214 | 248 | ||
215 | QValueList<Person> Alarm::mailAddresses() const | 249 | QValueList<Person> Alarm::mailAddresses() const |
216 | { | 250 | { |
217 | return (mType == Email) ? mMailAddresses : QValueList<Person>(); | 251 | return (mType == Email) ? mMailAddresses : QValueList<Person>(); |
218 | } | 252 | } |
219 | 253 | ||
220 | void Alarm::setMailSubject(const QString &mailAlarmSubject) | 254 | void Alarm::setMailSubject(const QString &mailAlarmSubject) |
221 | { | 255 | { |
222 | if (mType == Email) { | 256 | if (mType == Email) { |
223 | mMailSubject = mailAlarmSubject; | 257 | mMailSubject = mailAlarmSubject; |
224 | mParent->updated(); | 258 | mParent->updated(); |
225 | } | 259 | } |
226 | } | 260 | } |
227 | 261 | ||
228 | QString Alarm::mailSubject() const | 262 | QString Alarm::mailSubject() const |
229 | { | 263 | { |
230 | return (mType == Email) ? mMailSubject : QString::null; | 264 | return (mType == Email) ? mMailSubject : QString::null; |
231 | } | 265 | } |
232 | 266 | ||
233 | void Alarm::setMailAttachment(const QString &mailAttachFile) | 267 | void Alarm::setMailAttachment(const QString &mailAttachFile) |
234 | { | 268 | { |
235 | if (mType == Email) { | 269 | if (mType == Email) { |
236 | mMailAttachFiles.clear(); | 270 | mMailAttachFiles.clear(); |
237 | mMailAttachFiles += mailAttachFile; | 271 | mMailAttachFiles += mailAttachFile; |
238 | mParent->updated(); | 272 | mParent->updated(); |
239 | } | 273 | } |
240 | } | 274 | } |
241 | 275 | ||
242 | void Alarm::setMailAttachments(const QStringList &mailAttachFiles) | 276 | void Alarm::setMailAttachments(const QStringList &mailAttachFiles) |
243 | { | 277 | { |
244 | if (mType == Email) { | 278 | if (mType == Email) { |
245 | mMailAttachFiles = mailAttachFiles; | 279 | mMailAttachFiles = mailAttachFiles; |
246 | mParent->updated(); | 280 | mParent->updated(); |
247 | } | 281 | } |
248 | } | 282 | } |
249 | 283 | ||
250 | void Alarm::addMailAttachment(const QString &mailAttachFile) | 284 | void Alarm::addMailAttachment(const QString &mailAttachFile) |
251 | { | 285 | { |
252 | if (mType == Email) { | 286 | if (mType == Email) { |
253 | mMailAttachFiles += mailAttachFile; | 287 | mMailAttachFiles += mailAttachFile; |
254 | mParent->updated(); | 288 | mParent->updated(); |
255 | } | 289 | } |
256 | } | 290 | } |
257 | 291 | ||
258 | QStringList Alarm::mailAttachments() const | 292 | QStringList Alarm::mailAttachments() const |
259 | { | 293 | { |
260 | return (mType == Email) ? mMailAttachFiles : QStringList(); | 294 | return (mType == Email) ? mMailAttachFiles : QStringList(); |
261 | } | 295 | } |
262 | 296 | ||
263 | void Alarm::setMailText(const QString &text) | 297 | void Alarm::setMailText(const QString &text) |
264 | { | 298 | { |
265 | if (mType == Email) { | 299 | if (mType == Email) { |
266 | mDescription = text; | 300 | mDescription = text; |
267 | mParent->updated(); | 301 | mParent->updated(); |
268 | } | 302 | } |
269 | } | 303 | } |
270 | 304 | ||
271 | QString Alarm::mailText() const | 305 | QString Alarm::mailText() const |
272 | { | 306 | { |
273 | return (mType == Email) ? mDescription : QString::null; | 307 | return (mType == Email) ? mDescription : QString::null; |
274 | } | 308 | } |
275 | 309 | ||
276 | void Alarm::setDisplayAlarm(const QString &text) | 310 | void Alarm::setDisplayAlarm(const QString &text) |
277 | { | 311 | { |
278 | mType = Display; | 312 | mType = Display; |
279 | mDescription = text; | 313 | mDescription = text; |
280 | mParent->updated(); | 314 | mParent->updated(); |
281 | } | 315 | } |
282 | 316 | ||
283 | void Alarm::setText(const QString &text) | 317 | void Alarm::setText(const QString &text) |
284 | { | 318 | { |
285 | if (mType == Display) { | 319 | if (mType == Display) { |
286 | mDescription = text; | 320 | mDescription = text; |
287 | mParent->updated(); | 321 | mParent->updated(); |
288 | } | 322 | } |
289 | } | 323 | } |
290 | 324 | ||
291 | QString Alarm::text() const | 325 | QString Alarm::text() const |
292 | { | 326 | { |
293 | return (mType == Display) ? mDescription : QString::null; | 327 | return (mType == Display) ? mDescription : QString::null; |
294 | } | 328 | } |
295 | 329 | ||
296 | void Alarm::setTime(const QDateTime &alarmTime) | 330 | void Alarm::setTime(const QDateTime &alarmTime) |
297 | { | 331 | { |
298 | mAlarmTime = alarmTime; | 332 | mAlarmTime = alarmTime; |
299 | mHasTime = true; | 333 | mHasTime = true; |
300 | 334 | ||
301 | mParent->updated(); | 335 | mParent->updated(); |
302 | } | 336 | } |
303 | int Alarm::offset() | 337 | int Alarm::offset() |
304 | { | 338 | { |
305 | if ( hasTime() ) { | 339 | if ( hasTime() ) { |
306 | if (mParent->type()=="Todo") { | 340 | if (mParent->type()=="Todo") { |
307 | Todo *t = static_cast<Todo*>(mParent); | 341 | Todo *t = static_cast<Todo*>(mParent); |
308 | return t->dtDue().secsTo( mAlarmTime ) ; | 342 | return t->dtDue().secsTo( mAlarmTime ) ; |
309 | } else | 343 | } else |
310 | return mParent->dtStart().secsTo( mAlarmTime ) ; | 344 | return mParent->dtStart().secsTo( mAlarmTime ) ; |
311 | } | 345 | } |
312 | else | 346 | else |
313 | { | 347 | { |
314 | return mOffset.asSeconds(); | 348 | return mOffset.asSeconds(); |
315 | } | 349 | } |
316 | 350 | ||
317 | } | 351 | } |
318 | 352 | ||
319 | 353 | ||
320 | QDateTime Alarm::time() const | 354 | QDateTime Alarm::time() const |
321 | { | 355 | { |
322 | if ( hasTime() ) | 356 | if ( hasTime() ) |
323 | return mAlarmTime; | 357 | return mAlarmTime; |
324 | else | 358 | else |
325 | { | 359 | { |
326 | if (mParent->type()=="Todo") { | 360 | if (mParent->type()=="Todo") { |
327 | Todo *t = static_cast<Todo*>(mParent); | 361 | Todo *t = static_cast<Todo*>(mParent); |
328 | return mOffset.end( t->dtDue() ); | 362 | return mOffset.end( t->dtDue() ); |
329 | } else if (mEndOffset) { | 363 | } else if (mEndOffset) { |
330 | return mOffset.end( mParent->dtEnd() ); | 364 | return mOffset.end( mParent->dtEnd() ); |
331 | } else { | 365 | } else { |
332 | return mOffset.end( mParent->dtStart() ); | 366 | return mOffset.end( mParent->dtStart() ); |
333 | } | 367 | } |
334 | } | 368 | } |
335 | } | 369 | } |
336 | 370 | ||
337 | bool Alarm::hasTime() const | 371 | bool Alarm::hasTime() const |
338 | { | 372 | { |
339 | return mHasTime; | 373 | return mHasTime; |
340 | } | 374 | } |
341 | 375 | ||
342 | void Alarm::setSnoozeTime(int alarmSnoozeTime) | 376 | void Alarm::setSnoozeTime(int alarmSnoozeTime) |
343 | { | 377 | { |
344 | mAlarmSnoozeTime = alarmSnoozeTime; | 378 | mAlarmSnoozeTime = alarmSnoozeTime; |
345 | mParent->updated(); | 379 | mParent->updated(); |
346 | } | 380 | } |
347 | 381 | ||
348 | int Alarm::snoozeTime() const | 382 | int Alarm::snoozeTime() const |
349 | { | 383 | { |
350 | return mAlarmSnoozeTime; | 384 | return mAlarmSnoozeTime; |
351 | } | 385 | } |
352 | 386 | ||
353 | void Alarm::setRepeatCount(int alarmRepeatCount) | 387 | void Alarm::setRepeatCount(int alarmRepeatCount) |
354 | { | 388 | { |
355 | kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; | 389 | kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; |
356 | 390 | ||
357 | mAlarmRepeatCount = alarmRepeatCount; | 391 | mAlarmRepeatCount = alarmRepeatCount; |
358 | mParent->updated(); | 392 | mParent->updated(); |
359 | } | 393 | } |
360 | 394 | ||
361 | int Alarm::repeatCount() const | 395 | int Alarm::repeatCount() const |
362 | { | 396 | { |
363 | kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; | 397 | kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; |
364 | return mAlarmRepeatCount; | 398 | return mAlarmRepeatCount; |
365 | } | 399 | } |
366 | 400 | ||
367 | void Alarm::toggleAlarm() | 401 | void Alarm::toggleAlarm() |
368 | { | 402 | { |
369 | mAlarmEnabled = !mAlarmEnabled; | 403 | mAlarmEnabled = !mAlarmEnabled; |
370 | mParent->updated(); | 404 | mParent->updated(); |
371 | } | 405 | } |
372 | 406 | ||
373 | void Alarm::setEnabled(bool enable) | 407 | void Alarm::setEnabled(bool enable) |
374 | { | 408 | { |
375 | mAlarmEnabled = enable; | 409 | mAlarmEnabled = enable; |
376 | mParent->updated(); | 410 | mParent->updated(); |
377 | } | 411 | } |
378 | 412 | ||
379 | bool Alarm::enabled() const | 413 | bool Alarm::enabled() const |
380 | { | 414 | { |
381 | return mAlarmEnabled; | 415 | return mAlarmEnabled; |
382 | } | 416 | } |
383 | 417 | ||
384 | void Alarm::setStartOffset( const Duration &offset ) | 418 | void Alarm::setStartOffset( const Duration &offset ) |
385 | { | 419 | { |
386 | mOffset = offset; | 420 | mOffset = offset; |
387 | mEndOffset = false; | 421 | mEndOffset = false; |
388 | mHasTime = false; | 422 | mHasTime = false; |
389 | mParent->updated(); | 423 | mParent->updated(); |
390 | } | 424 | } |
391 | 425 | ||
392 | Duration Alarm::startOffset() const | 426 | Duration Alarm::startOffset() const |
393 | { | 427 | { |
394 | return (mHasTime || mEndOffset) ? 0 : mOffset; | 428 | return (mHasTime || mEndOffset) ? 0 : mOffset; |
395 | } | 429 | } |
396 | 430 | ||
397 | bool Alarm::hasStartOffset() const | 431 | bool Alarm::hasStartOffset() const |
398 | { | 432 | { |
399 | return !mHasTime && !mEndOffset; | 433 | return !mHasTime && !mEndOffset; |
400 | } | 434 | } |
401 | 435 | ||
402 | bool Alarm::hasEndOffset() const | 436 | bool Alarm::hasEndOffset() const |
403 | { | 437 | { |
404 | return !mHasTime && mEndOffset; | 438 | return !mHasTime && mEndOffset; |
405 | } | 439 | } |
406 | 440 | ||
407 | void Alarm::setEndOffset( const Duration &offset ) | 441 | void Alarm::setEndOffset( const Duration &offset ) |
408 | { | 442 | { |
409 | mOffset = offset; | 443 | mOffset = offset; |
410 | mEndOffset = true; | 444 | mEndOffset = true; |
411 | mHasTime = false; | 445 | mHasTime = false; |
412 | mParent->updated(); | 446 | mParent->updated(); |
413 | } | 447 | } |
414 | 448 | ||
415 | Duration Alarm::endOffset() const | 449 | Duration Alarm::endOffset() const |
416 | { | 450 | { |
417 | return (mHasTime || !mEndOffset) ? 0 : mOffset; | 451 | return (mHasTime || !mEndOffset) ? 0 : mOffset; |
418 | } | 452 | } |
419 | 453 | ||
420 | void Alarm::setParent( Incidence *parent ) | 454 | void Alarm::setParent( Incidence *parent ) |
421 | { | 455 | { |
422 | mParent = parent; | 456 | mParent = parent; |
423 | } | 457 | } |
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp index dd74e10..e84f672 100644 --- a/libkcal/recurrence.cpp +++ b/libkcal/recurrence.cpp | |||
@@ -1,1160 +1,1192 @@ | |||
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 | 32 | ||
33 | using namespace KCal; | 33 | using namespace KCal; |
34 | 34 | ||
35 | Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; | 35 | Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; |
36 | 36 | ||
37 | 37 | ||
38 | Recurrence::Recurrence(Incidence *parent, int compatVersion) | 38 | Recurrence::Recurrence(Incidence *parent, int compatVersion) |
39 | : recurs(rNone), // by default, it's not a recurring event | 39 | : recurs(rNone), // by default, it's not a recurring event |
40 | rWeekStart(1), // default is Monday | 40 | rWeekStart(1), // default is Monday |
41 | rDays(7), | 41 | rDays(7), |
42 | mFloats(parent ? parent->doesFloat() : false), | 42 | mFloats(parent ? parent->doesFloat() : false), |
43 | mRecurReadOnly(false), | 43 | mRecurReadOnly(false), |
44 | mRecurExDatesCount(0), | 44 | mRecurExDatesCount(0), |
45 | mFeb29YearlyType(mFeb29YearlyDefaultType), | 45 | mFeb29YearlyType(mFeb29YearlyDefaultType), |
46 | mCompatVersion(compatVersion ? compatVersion : INT_MAX), | 46 | mCompatVersion(compatVersion ? compatVersion : INT_MAX), |
47 | mCompatRecurs(rNone), | 47 | mCompatRecurs(rNone), |
48 | mCompatDuration(0), | 48 | mCompatDuration(0), |
49 | mParent(parent) | 49 | mParent(parent) |
50 | { | 50 | { |
51 | rMonthDays.setAutoDelete( true ); | 51 | rMonthDays.setAutoDelete( true ); |
52 | rMonthPositions.setAutoDelete( true ); | 52 | rMonthPositions.setAutoDelete( true ); |
53 | rYearNums.setAutoDelete( true ); | 53 | rYearNums.setAutoDelete( true ); |
54 | } | 54 | } |
55 | 55 | ||
56 | Recurrence::Recurrence(const Recurrence &r, Incidence *parent) | 56 | Recurrence::Recurrence(const Recurrence &r, Incidence *parent) |
57 | : recurs(r.recurs), | 57 | : recurs(r.recurs), |
58 | rWeekStart(r.rWeekStart), | 58 | rWeekStart(r.rWeekStart), |
59 | rDays(r.rDays.copy()), | 59 | rDays(r.rDays.copy()), |
60 | rFreq(r.rFreq), | 60 | rFreq(r.rFreq), |
61 | rDuration(r.rDuration), | 61 | rDuration(r.rDuration), |
62 | rEndDateTime(r.rEndDateTime), | 62 | rEndDateTime(r.rEndDateTime), |
63 | mRecurStart(r.mRecurStart), | 63 | mRecurStart(r.mRecurStart), |
64 | mFloats(r.mFloats), | 64 | mFloats(r.mFloats), |
65 | mRecurReadOnly(r.mRecurReadOnly), | 65 | mRecurReadOnly(r.mRecurReadOnly), |
66 | mRecurExDatesCount(r.mRecurExDatesCount), | 66 | mRecurExDatesCount(r.mRecurExDatesCount), |
67 | mFeb29YearlyType(r.mFeb29YearlyType), | 67 | mFeb29YearlyType(r.mFeb29YearlyType), |
68 | mCompatVersion(r.mCompatVersion), | 68 | mCompatVersion(r.mCompatVersion), |
69 | mCompatRecurs(r.mCompatRecurs), | 69 | mCompatRecurs(r.mCompatRecurs), |
70 | mCompatDuration(r.mCompatDuration), | 70 | mCompatDuration(r.mCompatDuration), |
71 | mParent(parent) | 71 | mParent(parent) |
72 | { | 72 | { |
73 | for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { | 73 | for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { |
74 | rMonthPos *tmp = new rMonthPos; | 74 | rMonthPos *tmp = new rMonthPos; |
75 | tmp->rPos = mp.current()->rPos; | 75 | tmp->rPos = mp.current()->rPos; |
76 | tmp->negative = mp.current()->negative; | 76 | tmp->negative = mp.current()->negative; |
77 | tmp->rDays = mp.current()->rDays.copy(); | 77 | tmp->rDays = mp.current()->rDays.copy(); |
78 | rMonthPositions.append(tmp); | 78 | rMonthPositions.append(tmp); |
79 | } | 79 | } |
80 | for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { | 80 | for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { |
81 | int *tmp = new int; | 81 | int *tmp = new int; |
82 | *tmp = *md.current(); | 82 | *tmp = *md.current(); |
83 | rMonthDays.append(tmp); | 83 | rMonthDays.append(tmp); |
84 | } | 84 | } |
85 | for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { | 85 | for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { |
86 | int *tmp = new int; | 86 | int *tmp = new int; |
87 | *tmp = *yn.current(); | 87 | *tmp = *yn.current(); |
88 | rYearNums.append(tmp); | 88 | rYearNums.append(tmp); |
89 | } | 89 | } |
90 | rMonthDays.setAutoDelete( true ); | 90 | rMonthDays.setAutoDelete( true ); |
91 | rMonthPositions.setAutoDelete( true ); | 91 | rMonthPositions.setAutoDelete( true ); |
92 | rYearNums.setAutoDelete( true ); | 92 | rYearNums.setAutoDelete( true ); |
93 | } | 93 | } |
94 | 94 | ||
95 | Recurrence::~Recurrence() | 95 | Recurrence::~Recurrence() |
96 | { | 96 | { |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | bool Recurrence::operator==( const Recurrence& r2 ) const | 100 | bool Recurrence::operator==( const Recurrence& r2 ) const |
101 | { | 101 | { |
102 | 102 | ||
103 | // the following line is obvious | 103 | // the following line is obvious |
104 | if ( recurs == rNone && r2.recurs == rNone ) | 104 | if ( recurs == rNone && r2.recurs == rNone ) |
105 | return true; | 105 | return true; |
106 | // we need the above line, because two non recurring events may | 106 | // we need the above line, because two non recurring events may |
107 | // differ in the other settings, because one (or both) | 107 | // differ in the other settings, because one (or both) |
108 | // may be not initialized properly | 108 | // may be not initialized properly |
109 | |||
109 | if ( recurs != r2.recurs | 110 | if ( recurs != r2.recurs |
110 | || rFreq != r2.rFreq | 111 | || rFreq != r2.rFreq |
111 | || rDuration != r2.rDuration | 112 | || rDuration != r2.rDuration |
112 | || !rDuration && rEndDateTime != r2.rEndDateTime | 113 | || !rDuration && rEndDateTime != r2.rEndDateTime |
113 | || mRecurStart != r2.mRecurStart | 114 | || mRecurStart != r2.mRecurStart |
114 | || mFloats != r2.mFloats | 115 | || mFloats != r2.mFloats |
115 | || mRecurReadOnly != r2.mRecurReadOnly | 116 | || mRecurReadOnly != r2.mRecurReadOnly |
116 | || mRecurExDatesCount != r2.mRecurExDatesCount ) | 117 | || mRecurExDatesCount != r2.mRecurExDatesCount ) |
117 | return false; | 118 | return false; |
118 | // no need to compare mCompat* and mParent | 119 | // no need to compare mCompat* and mParent |
119 | // OK to compare the pointers | 120 | // OK to compare the pointers |
120 | switch ( recurs ) | 121 | switch ( recurs ) |
121 | { | 122 | { |
122 | case rWeekly: | 123 | case rWeekly: |
123 | return rDays == r2.rDays | 124 | return rDays == r2.rDays |
124 | && rWeekStart == r2.rWeekStart; | 125 | && rWeekStart == r2.rWeekStart; |
125 | case rMonthlyPos: | 126 | case rMonthlyPos: { |
126 | return rMonthPositions.count() == r2.rMonthPositions.count(); | 127 | QPtrList<rMonthPos> MonthPositions = rMonthPositions; |
127 | case rMonthlyDay: | 128 | QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; |
128 | return rMonthDays.count() == r2.rMonthDays.count(); | 129 | if ( !MonthPositions.count() ) |
129 | case rYearlyPos: | 130 | return false; |
130 | return rYearNums.count() == r2.rYearNums.count() | 131 | if ( !MonthPositions2.count() ) |
131 | && rMonthPositions.count() == r2.rMonthPositions.count(); | 132 | return false; |
132 | case rYearlyMonth: | 133 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; |
133 | return rYearNums.count() == r2.rYearNums.count() | 134 | } |
134 | && mFeb29YearlyType == r2.mFeb29YearlyType; | 135 | case rMonthlyDay: { |
135 | case rYearlyDay: | 136 | QPtrList<int> MonthDays = rMonthDays ; |
136 | return rYearNums == r2.rYearNums; | 137 | QPtrList<int> MonthDays2 = r2.rMonthDays ; |
138 | if ( !MonthDays.count() ) | ||
139 | return false; | ||
140 | if ( !MonthDays2.count() ) | ||
141 | return false; | ||
142 | return *MonthDays.first() == *MonthDays2.first() ; | ||
143 | } | ||
144 | case rYearlyPos: { | ||
145 | |||
146 | QPtrList<int> YearNums = rYearNums; | ||
147 | QPtrList<int> YearNums2 = r2.rYearNums; | ||
148 | if ( *YearNums.first() != *YearNums2.first() ) | ||
149 | return false; | ||
150 | QPtrList<rMonthPos> MonthPositions = rMonthPositions; | ||
151 | QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; | ||
152 | if ( !MonthPositions.count() ) | ||
153 | return false; | ||
154 | if ( !MonthPositions2.count() ) | ||
155 | return false; | ||
156 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; | ||
157 | |||
158 | } | ||
159 | case rYearlyMonth: { | ||
160 | QPtrList<int> YearNums = rYearNums; | ||
161 | QPtrList<int> YearNums2 = r2.rYearNums; | ||
162 | return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType); | ||
163 | } | ||
164 | case rYearlyDay: { | ||
165 | QPtrList<int> YearNums = rYearNums; | ||
166 | QPtrList<int> YearNums2 = r2.rYearNums; | ||
167 | return ( *YearNums.first() == *YearNums2.first() ); | ||
168 | } | ||
137 | case rNone: | 169 | case rNone: |
138 | case rMinutely: | 170 | case rMinutely: |
139 | case rHourly: | 171 | case rHourly: |
140 | case rDaily: | 172 | case rDaily: |
141 | default: | 173 | default: |
142 | return true; | 174 | return true; |
143 | } | 175 | } |
144 | } | 176 | } |
145 | /* | 177 | /* |
146 | bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) | 178 | bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) |
147 | { | 179 | { |
148 | if ( l1.count() != l2.count() ) | 180 | if ( l1.count() != l2.count() ) |
149 | return false; | 181 | return false; |
150 | int count = l1.count(); | 182 | int count = l1.count(); |
151 | int i; | 183 | int i; |
152 | for ( i = 0; i < count ; ++i ) { | 184 | for ( i = 0; i < count ; ++i ) { |
153 | // if ( l1.at(i) != l2.at(i) ) | 185 | // if ( l1.at(i) != l2.at(i) ) |
154 | return false; | 186 | return false; |
155 | qDebug("compüare "); | 187 | qDebug("compüare "); |
156 | } | 188 | } |
157 | return true; | 189 | return true; |
158 | } | 190 | } |
159 | */ | 191 | */ |
160 | QString Recurrence::recurrenceText() const | 192 | QString Recurrence::recurrenceText() const |
161 | { | 193 | { |
162 | QString recurText = i18n("No"); | 194 | QString recurText = i18n("No"); |
163 | if ( recurs == Recurrence::rMinutely ) | 195 | if ( recurs == Recurrence::rMinutely ) |
164 | recurText = i18n("minutely"); | 196 | recurText = i18n("minutely"); |
165 | else if ( recurs == Recurrence::rHourly ) | 197 | else if ( recurs == Recurrence::rHourly ) |
166 | recurText = i18n("hourly"); | 198 | recurText = i18n("hourly"); |
167 | else if ( recurs == Recurrence::rDaily ) | 199 | else if ( recurs == Recurrence::rDaily ) |
168 | recurText = i18n("daily"); | 200 | recurText = i18n("daily"); |
169 | else if ( recurs == Recurrence::rWeekly ) | 201 | else if ( recurs == Recurrence::rWeekly ) |
170 | recurText = i18n("weekly"); | 202 | recurText = i18n("weekly"); |
171 | else if ( recurs == Recurrence::rMonthlyPos ) | 203 | else if ( recurs == Recurrence::rMonthlyPos ) |
172 | recurText = i18n("monthly"); | 204 | recurText = i18n("monthly"); |
173 | else if ( recurs == Recurrence::rMonthlyDay ) | 205 | else if ( recurs == Recurrence::rMonthlyDay ) |
174 | recurText = i18n("day-monthly"); | 206 | recurText = i18n("day-monthly"); |
175 | else if ( recurs == Recurrence::rYearlyMonth ) | 207 | else if ( recurs == Recurrence::rYearlyMonth ) |
176 | recurText = i18n("month-yearly"); | 208 | recurText = i18n("month-yearly"); |
177 | else if ( recurs == Recurrence::rYearlyDay ) | 209 | else if ( recurs == Recurrence::rYearlyDay ) |
178 | recurText = i18n("day-yearly"); | 210 | recurText = i18n("day-yearly"); |
179 | else if ( recurs == Recurrence::rYearlyPos ) | 211 | else if ( recurs == Recurrence::rYearlyPos ) |
180 | recurText = i18n("position-yearly"); | 212 | recurText = i18n("position-yearly"); |
181 | return recurText; | 213 | return recurText; |
182 | } | 214 | } |
183 | 215 | ||
184 | void Recurrence::setCompatVersion(int version) | 216 | void Recurrence::setCompatVersion(int version) |
185 | { | 217 | { |
186 | mCompatVersion = version ? version : INT_MAX; | 218 | mCompatVersion = version ? version : INT_MAX; |
187 | } | 219 | } |
188 | 220 | ||
189 | ushort Recurrence::doesRecur() const | 221 | ushort Recurrence::doesRecur() const |
190 | { | 222 | { |
191 | return recurs; | 223 | return recurs; |
192 | } | 224 | } |
193 | 225 | ||
194 | bool Recurrence::recursOnPure(const QDate &qd) const | 226 | bool Recurrence::recursOnPure(const QDate &qd) const |
195 | { | 227 | { |
196 | switch(recurs) { | 228 | switch(recurs) { |
197 | case rMinutely: | 229 | case rMinutely: |
198 | return recursSecondly(qd, rFreq*60); | 230 | return recursSecondly(qd, rFreq*60); |
199 | case rHourly: | 231 | case rHourly: |
200 | return recursSecondly(qd, rFreq*3600); | 232 | return recursSecondly(qd, rFreq*3600); |
201 | case rDaily: | 233 | case rDaily: |
202 | return recursDaily(qd); | 234 | return recursDaily(qd); |
203 | case rWeekly: | 235 | case rWeekly: |
204 | return recursWeekly(qd); | 236 | return recursWeekly(qd); |
205 | case rMonthlyPos: | 237 | case rMonthlyPos: |
206 | case rMonthlyDay: | 238 | case rMonthlyDay: |
207 | return recursMonthly(qd); | 239 | return recursMonthly(qd); |
208 | case rYearlyMonth: | 240 | case rYearlyMonth: |
209 | return recursYearlyByMonth(qd); | 241 | return recursYearlyByMonth(qd); |
210 | case rYearlyDay: | 242 | case rYearlyDay: |
211 | return recursYearlyByDay(qd); | 243 | return recursYearlyByDay(qd); |
212 | case rYearlyPos: | 244 | case rYearlyPos: |
213 | return recursYearlyByPos(qd); | 245 | return recursYearlyByPos(qd); |
214 | default: | 246 | default: |
215 | return false; | 247 | return false; |
216 | case rNone: | 248 | case rNone: |
217 | return false; | 249 | return false; |
218 | } // case | 250 | } // case |
219 | return false; | 251 | return false; |
220 | } | 252 | } |
221 | 253 | ||
222 | bool Recurrence::recursAtPure(const QDateTime &dt) const | 254 | bool Recurrence::recursAtPure(const QDateTime &dt) const |
223 | { | 255 | { |
224 | switch(recurs) { | 256 | switch(recurs) { |
225 | case rMinutely: | 257 | case rMinutely: |
226 | return recursMinutelyAt(dt, rFreq); | 258 | return recursMinutelyAt(dt, rFreq); |
227 | case rHourly: | 259 | case rHourly: |
228 | return recursMinutelyAt(dt, rFreq*60); | 260 | return recursMinutelyAt(dt, rFreq*60); |
229 | default: | 261 | default: |
230 | if (dt.time() != mRecurStart.time()) | 262 | if (dt.time() != mRecurStart.time()) |
231 | return false; | 263 | return false; |
232 | switch(recurs) { | 264 | switch(recurs) { |
233 | case rDaily: | 265 | case rDaily: |
234 | return recursDaily(dt.date()); | 266 | return recursDaily(dt.date()); |
235 | case rWeekly: | 267 | case rWeekly: |
236 | return recursWeekly(dt.date()); | 268 | return recursWeekly(dt.date()); |
237 | case rMonthlyPos: | 269 | case rMonthlyPos: |
238 | case rMonthlyDay: | 270 | case rMonthlyDay: |
239 | return recursMonthly(dt.date()); | 271 | return recursMonthly(dt.date()); |
240 | case rYearlyMonth: | 272 | case rYearlyMonth: |
241 | return recursYearlyByMonth(dt.date()); | 273 | return recursYearlyByMonth(dt.date()); |
242 | case rYearlyDay: | 274 | case rYearlyDay: |
243 | return recursYearlyByDay(dt.date()); | 275 | return recursYearlyByDay(dt.date()); |
244 | case rYearlyPos: | 276 | case rYearlyPos: |
245 | return recursYearlyByPos(dt.date()); | 277 | return recursYearlyByPos(dt.date()); |
246 | default: | 278 | default: |
247 | return false; | 279 | return false; |
248 | case rNone: | 280 | case rNone: |
249 | return false; | 281 | return false; |
250 | } | 282 | } |
251 | } // case | 283 | } // case |
252 | return false; | 284 | return false; |
253 | } | 285 | } |
254 | 286 | ||
255 | QDate Recurrence::endDate() const | 287 | QDate Recurrence::endDate() const |
256 | { | 288 | { |
257 | int count = 0; | 289 | int count = 0; |
258 | QDate end; | 290 | QDate end; |
259 | if (recurs != rNone) { | 291 | if (recurs != rNone) { |
260 | if (rDuration < 0) | 292 | if (rDuration < 0) |
261 | return QDate(); // infinite recurrence | 293 | return QDate(); // infinite recurrence |
262 | if (rDuration == 0) | 294 | if (rDuration == 0) |
263 | return rEndDateTime.date(); | 295 | return rEndDateTime.date(); |
264 | 296 | ||
265 | // The end date is determined by the recurrence count | 297 | // The end date is determined by the recurrence count |
266 | QDate dStart = mRecurStart.date(); | 298 | QDate dStart = mRecurStart.date(); |
267 | switch (recurs) | 299 | switch (recurs) |
268 | { | 300 | { |
269 | case rMinutely: | 301 | case rMinutely: |
270 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date(); | 302 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date(); |
271 | case rHourly: | 303 | case rHourly: |
272 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date(); | 304 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date(); |
273 | case rDaily: | 305 | case rDaily: |
274 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); | 306 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); |
275 | 307 | ||
276 | case rWeekly: | 308 | case rWeekly: |
277 | count = weeklyCalc(END_DATE_AND_COUNT, end); | 309 | count = weeklyCalc(END_DATE_AND_COUNT, end); |
278 | break; | 310 | break; |
279 | case rMonthlyPos: | 311 | case rMonthlyPos: |
280 | case rMonthlyDay: | 312 | case rMonthlyDay: |
281 | count = monthlyCalc(END_DATE_AND_COUNT, end); | 313 | count = monthlyCalc(END_DATE_AND_COUNT, end); |
282 | break; | 314 | break; |
283 | case rYearlyMonth: | 315 | case rYearlyMonth: |
284 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); | 316 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); |
285 | break; | 317 | break; |
286 | case rYearlyDay: | 318 | case rYearlyDay: |
287 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); | 319 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); |
288 | break; | 320 | break; |
289 | case rYearlyPos: | 321 | case rYearlyPos: |
290 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); | 322 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); |
291 | break; | 323 | break; |
292 | default: | 324 | default: |
293 | // catch-all. Should never get here. | 325 | // catch-all. Should never get here. |
294 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; | 326 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; |
295 | break; | 327 | break; |
296 | } | 328 | } |
297 | } | 329 | } |
298 | if (!count) | 330 | if (!count) |
299 | return QDate(); // error - there is no recurrence | 331 | return QDate(); // error - there is no recurrence |
300 | return end; | 332 | return end; |
301 | } | 333 | } |
302 | 334 | ||
303 | QDateTime Recurrence::endDateTime() const | 335 | QDateTime Recurrence::endDateTime() const |
304 | { | 336 | { |
305 | int count = 0; | 337 | int count = 0; |
306 | QDate end; | 338 | QDate end; |
307 | if (recurs != rNone) { | 339 | if (recurs != rNone) { |
308 | if (rDuration < 0) | 340 | if (rDuration < 0) |
309 | return QDateTime(); // infinite recurrence | 341 | return QDateTime(); // infinite recurrence |
310 | if (rDuration == 0) | 342 | if (rDuration == 0) |
311 | return rEndDateTime; | 343 | return rEndDateTime; |
312 | 344 | ||
313 | // The end date is determined by the recurrence count | 345 | // The end date is determined by the recurrence count |
314 | QDate dStart = mRecurStart.date(); | 346 | QDate dStart = mRecurStart.date(); |
315 | switch (recurs) | 347 | switch (recurs) |
316 | { | 348 | { |
317 | case rMinutely: | 349 | case rMinutely: |
318 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); | 350 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); |
319 | case rHourly: | 351 | case rHourly: |
320 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); | 352 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); |
321 | case rDaily: | 353 | case rDaily: |
322 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); | 354 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); |
323 | 355 | ||
324 | case rWeekly: | 356 | case rWeekly: |
325 | count = weeklyCalc(END_DATE_AND_COUNT, end); | 357 | count = weeklyCalc(END_DATE_AND_COUNT, end); |
326 | break; | 358 | break; |
327 | case rMonthlyPos: | 359 | case rMonthlyPos: |
328 | case rMonthlyDay: | 360 | case rMonthlyDay: |
329 | count = monthlyCalc(END_DATE_AND_COUNT, end); | 361 | count = monthlyCalc(END_DATE_AND_COUNT, end); |
330 | break; | 362 | break; |
331 | case rYearlyMonth: | 363 | case rYearlyMonth: |
332 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); | 364 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); |
333 | break; | 365 | break; |
334 | case rYearlyDay: | 366 | case rYearlyDay: |
335 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); | 367 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); |
336 | break; | 368 | break; |
337 | case rYearlyPos: | 369 | case rYearlyPos: |
338 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); | 370 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); |
339 | break; | 371 | break; |
340 | default: | 372 | default: |
341 | // catch-all. Should never get here. | 373 | // catch-all. Should never get here. |
342 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; | 374 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; |
343 | break; | 375 | break; |
344 | } | 376 | } |
345 | } | 377 | } |
346 | if (!count) | 378 | if (!count) |
347 | return QDateTime(); // error - there is no recurrence | 379 | return QDateTime(); // error - there is no recurrence |
348 | return QDateTime(end, mRecurStart.time()); | 380 | return QDateTime(end, mRecurStart.time()); |
349 | } | 381 | } |
350 | 382 | ||
351 | int Recurrence::durationTo(const QDate &date) const | 383 | int Recurrence::durationTo(const QDate &date) const |
352 | { | 384 | { |
353 | QDate d = date; | 385 | QDate d = date; |
354 | return recurCalc(COUNT_TO_DATE, d); | 386 | return recurCalc(COUNT_TO_DATE, d); |
355 | } | 387 | } |
356 | 388 | ||
357 | int Recurrence::durationTo(const QDateTime &datetime) const | 389 | int Recurrence::durationTo(const QDateTime &datetime) const |
358 | { | 390 | { |
359 | QDateTime dt = datetime; | 391 | QDateTime dt = datetime; |
360 | return recurCalc(COUNT_TO_DATE, dt); | 392 | return recurCalc(COUNT_TO_DATE, dt); |
361 | } | 393 | } |
362 | 394 | ||
363 | void Recurrence::unsetRecurs() | 395 | void Recurrence::unsetRecurs() |
364 | { | 396 | { |
365 | if (mRecurReadOnly) return; | 397 | if (mRecurReadOnly) return; |
366 | recurs = rNone; | 398 | recurs = rNone; |
367 | rMonthPositions.clear(); | 399 | rMonthPositions.clear(); |
368 | rMonthDays.clear(); | 400 | rMonthDays.clear(); |
369 | rYearNums.clear(); | 401 | rYearNums.clear(); |
370 | } | 402 | } |
371 | 403 | ||
372 | void Recurrence::setRecurStart(const QDateTime &start) | 404 | void Recurrence::setRecurStart(const QDateTime &start) |
373 | { | 405 | { |
374 | mRecurStart = start; | 406 | mRecurStart = start; |
375 | mFloats = false; | 407 | mFloats = false; |
376 | switch (recurs) | 408 | switch (recurs) |
377 | { | 409 | { |
378 | case rMinutely: | 410 | case rMinutely: |
379 | case rHourly: | 411 | case rHourly: |
380 | break; | 412 | break; |
381 | case rDaily: | 413 | case rDaily: |
382 | case rWeekly: | 414 | case rWeekly: |
383 | case rMonthlyPos: | 415 | case rMonthlyPos: |
384 | case rMonthlyDay: | 416 | case rMonthlyDay: |
385 | case rYearlyMonth: | 417 | case rYearlyMonth: |
386 | case rYearlyDay: | 418 | case rYearlyDay: |
387 | case rYearlyPos: | 419 | case rYearlyPos: |
388 | default: | 420 | default: |
389 | rEndDateTime.setTime(start.time()); | 421 | rEndDateTime.setTime(start.time()); |
390 | break; | 422 | break; |
391 | } | 423 | } |
392 | } | 424 | } |
393 | 425 | ||
394 | void Recurrence::setRecurStart(const QDate &start) | 426 | void Recurrence::setRecurStart(const QDate &start) |
395 | { | 427 | { |
396 | mRecurStart.setDate(start); | 428 | mRecurStart.setDate(start); |
397 | mRecurStart.setTime(QTime(0,0,0)); | 429 | mRecurStart.setTime(QTime(0,0,0)); |
398 | switch (recurs) | 430 | switch (recurs) |
399 | { | 431 | { |
400 | case rMinutely: | 432 | case rMinutely: |
401 | case rHourly: | 433 | case rHourly: |
402 | break; | 434 | break; |
403 | case rDaily: | 435 | case rDaily: |
404 | case rWeekly: | 436 | case rWeekly: |
405 | case rMonthlyPos: | 437 | case rMonthlyPos: |
406 | case rMonthlyDay: | 438 | case rMonthlyDay: |
407 | case rYearlyMonth: | 439 | case rYearlyMonth: |
408 | case rYearlyDay: | 440 | case rYearlyDay: |
409 | case rYearlyPos: | 441 | case rYearlyPos: |
410 | default: | 442 | default: |
411 | mFloats = true; | 443 | mFloats = true; |
412 | break; | 444 | break; |
413 | } | 445 | } |
414 | } | 446 | } |
415 | 447 | ||
416 | void Recurrence::setFloats(bool f) | 448 | void Recurrence::setFloats(bool f) |
417 | { | 449 | { |
418 | switch (recurs) | 450 | switch (recurs) |
419 | { | 451 | { |
420 | case rDaily: | 452 | case rDaily: |
421 | case rWeekly: | 453 | case rWeekly: |
422 | case rMonthlyPos: | 454 | case rMonthlyPos: |
423 | case rMonthlyDay: | 455 | case rMonthlyDay: |
424 | case rYearlyMonth: | 456 | case rYearlyMonth: |
425 | case rYearlyDay: | 457 | case rYearlyDay: |
426 | case rYearlyPos: | 458 | case rYearlyPos: |
427 | break; | 459 | break; |
428 | case rMinutely: | 460 | case rMinutely: |
429 | case rHourly: | 461 | case rHourly: |
430 | default: | 462 | default: |
431 | return; // can't set sub-daily to floating | 463 | return; // can't set sub-daily to floating |
432 | } | 464 | } |
433 | mFloats = f; | 465 | mFloats = f; |
434 | if (f) { | 466 | if (f) { |
435 | mRecurStart.setTime(QTime(0,0,0)); | 467 | mRecurStart.setTime(QTime(0,0,0)); |
436 | rEndDateTime.setTime(QTime(0,0,0)); | 468 | rEndDateTime.setTime(QTime(0,0,0)); |
437 | } | 469 | } |
438 | } | 470 | } |
439 | 471 | ||
440 | int Recurrence::frequency() const | 472 | int Recurrence::frequency() const |
441 | { | 473 | { |
442 | return rFreq; | 474 | return rFreq; |
443 | } | 475 | } |
444 | 476 | ||
445 | int Recurrence::duration() const | 477 | int Recurrence::duration() const |
446 | { | 478 | { |
447 | return rDuration; | 479 | return rDuration; |
448 | } | 480 | } |
449 | 481 | ||
450 | void Recurrence::setDuration(int _rDuration) | 482 | void Recurrence::setDuration(int _rDuration) |
451 | { | 483 | { |
452 | if (mRecurReadOnly) return; | 484 | if (mRecurReadOnly) return; |
453 | if (_rDuration > 0) { | 485 | if (_rDuration > 0) { |
454 | rDuration = _rDuration; | 486 | rDuration = _rDuration; |
455 | // Compatibility mode is only needed when reading the calendar in ICalFormatImpl, | 487 | // Compatibility mode is only needed when reading the calendar in ICalFormatImpl, |
456 | // so explicitly setting the duration means no backwards compatibility is needed. | 488 | // so explicitly setting the duration means no backwards compatibility is needed. |
457 | mCompatDuration = 0; | 489 | mCompatDuration = 0; |
458 | } | 490 | } |
459 | } | 491 | } |
460 | 492 | ||
461 | QString Recurrence::endDateStr(bool shortfmt) const | 493 | QString Recurrence::endDateStr(bool shortfmt) const |
462 | { | 494 | { |
463 | return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt); | 495 | return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt); |
464 | } | 496 | } |
465 | 497 | ||
466 | const QBitArray &Recurrence::days() const | 498 | const QBitArray &Recurrence::days() const |
467 | { | 499 | { |
468 | return rDays; | 500 | return rDays; |
469 | } | 501 | } |
470 | 502 | ||
471 | const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const | 503 | const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const |
472 | { | 504 | { |
473 | return rMonthPositions; | 505 | return rMonthPositions; |
474 | } | 506 | } |
475 | 507 | ||
476 | const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const | 508 | const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const |
477 | { | 509 | { |
478 | return rMonthPositions; | 510 | return rMonthPositions; |
479 | } | 511 | } |
480 | 512 | ||
481 | const QPtrList<int> &Recurrence::monthDays() const | 513 | const QPtrList<int> &Recurrence::monthDays() const |
482 | { | 514 | { |
483 | return rMonthDays; | 515 | return rMonthDays; |
484 | } | 516 | } |
485 | 517 | ||
486 | void Recurrence::setMinutely(int _rFreq, int _rDuration) | 518 | void Recurrence::setMinutely(int _rFreq, int _rDuration) |
487 | { | 519 | { |
488 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 520 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
489 | return; | 521 | return; |
490 | setDailySub(rMinutely, _rFreq, _rDuration); | 522 | setDailySub(rMinutely, _rFreq, _rDuration); |
491 | } | 523 | } |
492 | 524 | ||
493 | void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime) | 525 | void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime) |
494 | { | 526 | { |
495 | if (mRecurReadOnly) return; | 527 | if (mRecurReadOnly) return; |
496 | rEndDateTime = _rEndDateTime; | 528 | rEndDateTime = _rEndDateTime; |
497 | setDailySub(rMinutely, _rFreq, 0); | 529 | setDailySub(rMinutely, _rFreq, 0); |
498 | } | 530 | } |
499 | 531 | ||
500 | void Recurrence::setHourly(int _rFreq, int _rDuration) | 532 | void Recurrence::setHourly(int _rFreq, int _rDuration) |
501 | { | 533 | { |
502 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 534 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
503 | return; | 535 | return; |
504 | setDailySub(rHourly, _rFreq, _rDuration); | 536 | setDailySub(rHourly, _rFreq, _rDuration); |
505 | } | 537 | } |
506 | 538 | ||
507 | void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime) | 539 | void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime) |
508 | { | 540 | { |
509 | if (mRecurReadOnly) return; | 541 | if (mRecurReadOnly) return; |
510 | rEndDateTime = _rEndDateTime; | 542 | rEndDateTime = _rEndDateTime; |
511 | setDailySub(rHourly, _rFreq, 0); | 543 | setDailySub(rHourly, _rFreq, 0); |
512 | } | 544 | } |
513 | 545 | ||
514 | void Recurrence::setDaily(int _rFreq, int _rDuration) | 546 | void Recurrence::setDaily(int _rFreq, int _rDuration) |
515 | { | 547 | { |
516 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 548 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
517 | return; | 549 | return; |
518 | setDailySub(rDaily, _rFreq, _rDuration); | 550 | setDailySub(rDaily, _rFreq, _rDuration); |
519 | } | 551 | } |
520 | 552 | ||
521 | void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate) | 553 | void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate) |
522 | { | 554 | { |
523 | if (mRecurReadOnly) return; | 555 | if (mRecurReadOnly) return; |
524 | rEndDateTime.setDate(_rEndDate); | 556 | rEndDateTime.setDate(_rEndDate); |
525 | rEndDateTime.setTime(mRecurStart.time()); | 557 | rEndDateTime.setTime(mRecurStart.time()); |
526 | setDailySub(rDaily, _rFreq, 0); | 558 | setDailySub(rDaily, _rFreq, 0); |
527 | } | 559 | } |
528 | 560 | ||
529 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, | 561 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, |
530 | int _rDuration, int _rWeekStart) | 562 | int _rDuration, int _rWeekStart) |
531 | { | 563 | { |
532 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 564 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
533 | return; | 565 | return; |
534 | recurs = rWeekly; | 566 | recurs = rWeekly; |
535 | 567 | ||
536 | rFreq = _rFreq; | 568 | rFreq = _rFreq; |
537 | rDays = _rDays; | 569 | rDays = _rDays; |
538 | rWeekStart = _rWeekStart; | 570 | rWeekStart = _rWeekStart; |
539 | rDuration = _rDuration; | 571 | rDuration = _rDuration; |
540 | if (mCompatVersion < 310 && _rDuration > 0) { | 572 | if (mCompatVersion < 310 && _rDuration > 0) { |
541 | // Backwards compatibility for KDE < 3.1. | 573 | // Backwards compatibility for KDE < 3.1. |
542 | // rDuration was set to the number of time periods to recur, | 574 | // rDuration was set to the number of time periods to recur, |
543 | // with week start always on a Monday. | 575 | // with week start always on a Monday. |
544 | // Convert this to the number of occurrences. | 576 | // Convert this to the number of occurrences. |
545 | mCompatDuration = _rDuration; | 577 | mCompatDuration = _rDuration; |
546 | int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek()); | 578 | int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek()); |
547 | QDate end(mRecurStart.date().addDays(weeks * rFreq)); | 579 | QDate end(mRecurStart.date().addDays(weeks * rFreq)); |
548 | rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly | 580 | rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly |
549 | rDuration = weeklyCalc(COUNT_TO_DATE, end); | 581 | rDuration = weeklyCalc(COUNT_TO_DATE, end); |
550 | } else { | 582 | } else { |
551 | mCompatDuration = 0; | 583 | mCompatDuration = 0; |
552 | } | 584 | } |
553 | rMonthPositions.clear(); | 585 | rMonthPositions.clear(); |
554 | rMonthDays.clear(); | 586 | rMonthDays.clear(); |
555 | if (mParent) mParent->updated(); | 587 | if (mParent) mParent->updated(); |
556 | } | 588 | } |
557 | 589 | ||
558 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, | 590 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, |
559 | const QDate &_rEndDate, int _rWeekStart) | 591 | const QDate &_rEndDate, int _rWeekStart) |
560 | { | 592 | { |
561 | if (mRecurReadOnly) return; | 593 | if (mRecurReadOnly) return; |
562 | recurs = rWeekly; | 594 | recurs = rWeekly; |
563 | 595 | ||
564 | rFreq = _rFreq; | 596 | rFreq = _rFreq; |
565 | rDays = _rDays; | 597 | rDays = _rDays; |
566 | rWeekStart = _rWeekStart; | 598 | rWeekStart = _rWeekStart; |
567 | rEndDateTime.setDate(_rEndDate); | 599 | rEndDateTime.setDate(_rEndDate); |
568 | rEndDateTime.setTime(mRecurStart.time()); | 600 | rEndDateTime.setTime(mRecurStart.time()); |
569 | rDuration = 0; // set to 0 because there is an end date | 601 | rDuration = 0; // set to 0 because there is an end date |
570 | mCompatDuration = 0; | 602 | mCompatDuration = 0; |
571 | rMonthPositions.clear(); | 603 | rMonthPositions.clear(); |
572 | rMonthDays.clear(); | 604 | rMonthDays.clear(); |
573 | rYearNums.clear(); | 605 | rYearNums.clear(); |
574 | if (mParent) mParent->updated(); | 606 | if (mParent) mParent->updated(); |
575 | } | 607 | } |
576 | 608 | ||
577 | void Recurrence::setMonthly(short type, int _rFreq, int _rDuration) | 609 | void Recurrence::setMonthly(short type, int _rFreq, int _rDuration) |
578 | { | 610 | { |
579 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 611 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
580 | return; | 612 | return; |
581 | recurs = type; | 613 | recurs = type; |
582 | 614 | ||
583 | rFreq = _rFreq; | 615 | rFreq = _rFreq; |
584 | rDuration = _rDuration; | 616 | rDuration = _rDuration; |
585 | if (mCompatVersion < 310) | 617 | if (mCompatVersion < 310) |
586 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 618 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
587 | rYearNums.clear(); | 619 | rYearNums.clear(); |
588 | if (mParent) mParent->updated(); | 620 | if (mParent) mParent->updated(); |
589 | } | 621 | } |
590 | 622 | ||
591 | void Recurrence::setMonthly(short type, int _rFreq, | 623 | void Recurrence::setMonthly(short type, int _rFreq, |
592 | const QDate &_rEndDate) | 624 | const QDate &_rEndDate) |
593 | { | 625 | { |
594 | if (mRecurReadOnly) return; | 626 | if (mRecurReadOnly) return; |
595 | recurs = type; | 627 | recurs = type; |
596 | 628 | ||
597 | rFreq = _rFreq; | 629 | rFreq = _rFreq; |
598 | rEndDateTime.setDate(_rEndDate); | 630 | rEndDateTime.setDate(_rEndDate); |
599 | rEndDateTime.setTime(mRecurStart.time()); | 631 | rEndDateTime.setTime(mRecurStart.time()); |
600 | rDuration = 0; // set to 0 because there is an end date | 632 | rDuration = 0; // set to 0 because there is an end date |
601 | mCompatDuration = 0; | 633 | mCompatDuration = 0; |
602 | rYearNums.clear(); | 634 | rYearNums.clear(); |
603 | if (mParent) mParent->updated(); | 635 | if (mParent) mParent->updated(); |
604 | } | 636 | } |
605 | 637 | ||
606 | void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays) | 638 | void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays) |
607 | { | 639 | { |
608 | if (recurs == rMonthlyPos) | 640 | if (recurs == rMonthlyPos) |
609 | addMonthlyPos_(_rPos, _rDays); | 641 | addMonthlyPos_(_rPos, _rDays); |
610 | } | 642 | } |
611 | 643 | ||
612 | void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays) | 644 | void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays) |
613 | { | 645 | { |
614 | if (mRecurReadOnly | 646 | if (mRecurReadOnly |
615 | || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number | 647 | || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number |
616 | return; | 648 | return; |
617 | 649 | ||
618 | for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) { | 650 | for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) { |
619 | int itPos = it->negative ? -it->rPos : it->rPos; | 651 | int itPos = it->negative ? -it->rPos : it->rPos; |
620 | if (_rPos == itPos) { | 652 | if (_rPos == itPos) { |
621 | // This week is already in the list. | 653 | // This week is already in the list. |
622 | // Combine the specified days with those in the list. | 654 | // Combine the specified days with those in the list. |
623 | it->rDays |= _rDays; | 655 | it->rDays |= _rDays; |
624 | if (mParent) mParent->updated(); | 656 | if (mParent) mParent->updated(); |
625 | return; | 657 | return; |
626 | } | 658 | } |
627 | } | 659 | } |
628 | // Add the new position to the list | 660 | // Add the new position to the list |
629 | rMonthPos *tmpPos = new rMonthPos; | 661 | rMonthPos *tmpPos = new rMonthPos; |
630 | if (_rPos > 0) { | 662 | if (_rPos > 0) { |
631 | tmpPos->rPos = _rPos; | 663 | tmpPos->rPos = _rPos; |
632 | tmpPos->negative = false; | 664 | tmpPos->negative = false; |
633 | } else { | 665 | } else { |
634 | tmpPos->rPos = -_rPos; // take abs() | 666 | tmpPos->rPos = -_rPos; // take abs() |
635 | tmpPos->negative = true; | 667 | tmpPos->negative = true; |
636 | } | 668 | } |
637 | tmpPos->rDays = _rDays; | 669 | tmpPos->rDays = _rDays; |
638 | tmpPos->rDays.detach(); | 670 | tmpPos->rDays.detach(); |
639 | rMonthPositions.append(tmpPos); | 671 | rMonthPositions.append(tmpPos); |
640 | 672 | ||
641 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 673 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
642 | // Backwards compatibility for KDE < 3.1. | 674 | // Backwards compatibility for KDE < 3.1. |
643 | // rDuration was set to the number of time periods to recur. | 675 | // rDuration was set to the number of time periods to recur. |
644 | // Convert this to the number of occurrences. | 676 | // Convert this to the number of occurrences. |
645 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; | 677 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; |
646 | int month = mRecurStart.date().month() - 1 + monthsAhead; | 678 | int month = mRecurStart.date().month() - 1 + monthsAhead; |
647 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); | 679 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); |
648 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 680 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
649 | rDuration = recurCalc(COUNT_TO_DATE, end); | 681 | rDuration = recurCalc(COUNT_TO_DATE, end); |
650 | } | 682 | } |
651 | 683 | ||
652 | if (mParent) mParent->updated(); | 684 | if (mParent) mParent->updated(); |
653 | } | 685 | } |
654 | 686 | ||
655 | void Recurrence::addMonthlyDay(short _rDay) | 687 | void Recurrence::addMonthlyDay(short _rDay) |
656 | { | 688 | { |
657 | if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth) | 689 | if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth) |
658 | || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number | 690 | || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number |
659 | return; | 691 | return; |
660 | for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { | 692 | for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { |
661 | if (_rDay == *it) | 693 | if (_rDay == *it) |
662 | return; // this day is already in the list - avoid duplication | 694 | return; // this day is already in the list - avoid duplication |
663 | } | 695 | } |
664 | int *tmpDay = new int; | 696 | int *tmpDay = new int; |
665 | *tmpDay = _rDay; | 697 | *tmpDay = _rDay; |
666 | rMonthDays.append(tmpDay); | 698 | rMonthDays.append(tmpDay); |
667 | 699 | ||
668 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 700 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
669 | // Backwards compatibility for KDE < 3.1. | 701 | // Backwards compatibility for KDE < 3.1. |
670 | // rDuration was set to the number of time periods to recur. | 702 | // rDuration was set to the number of time periods to recur. |
671 | // Convert this to the number of occurrences. | 703 | // Convert this to the number of occurrences. |
672 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; | 704 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; |
673 | int month = mRecurStart.date().month() - 1 + monthsAhead; | 705 | int month = mRecurStart.date().month() - 1 + monthsAhead; |
674 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); | 706 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); |
675 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 707 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
676 | rDuration = recurCalc(COUNT_TO_DATE, end); | 708 | rDuration = recurCalc(COUNT_TO_DATE, end); |
677 | } | 709 | } |
678 | 710 | ||
679 | if (mParent) mParent->updated(); | 711 | if (mParent) mParent->updated(); |
680 | } | 712 | } |
681 | 713 | ||
682 | void Recurrence::setYearly(int type, int _rFreq, int _rDuration) | 714 | void Recurrence::setYearly(int type, int _rFreq, int _rDuration) |
683 | { | 715 | { |
684 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 716 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
685 | return; | 717 | return; |
686 | if (mCompatVersion < 310) | 718 | if (mCompatVersion < 310) |
687 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 719 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
688 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration); | 720 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration); |
689 | } | 721 | } |
690 | 722 | ||
691 | void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate) | 723 | void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate) |
692 | { | 724 | { |
693 | if (mRecurReadOnly) return; | 725 | if (mRecurReadOnly) return; |
694 | rEndDateTime.setDate(_rEndDate); | 726 | rEndDateTime.setDate(_rEndDate); |
695 | rEndDateTime.setTime(mRecurStart.time()); | 727 | rEndDateTime.setTime(mRecurStart.time()); |
696 | mCompatDuration = 0; | 728 | mCompatDuration = 0; |
697 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0); | 729 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0); |
698 | } | 730 | } |
699 | 731 | ||
700 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration) | 732 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration) |
701 | { | 733 | { |
702 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 734 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
703 | return; | 735 | return; |
704 | if (mCompatVersion < 310) | 736 | if (mCompatVersion < 310) |
705 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 737 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
706 | setYearly_(rYearlyMonth, type, _rFreq, _rDuration); | 738 | setYearly_(rYearlyMonth, type, _rFreq, _rDuration); |
707 | } | 739 | } |
708 | 740 | ||
709 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) | 741 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) |
710 | { | 742 | { |
711 | if (mRecurReadOnly) return; | 743 | if (mRecurReadOnly) return; |
712 | rEndDateTime.setDate(_rEndDate); | 744 | rEndDateTime.setDate(_rEndDate); |
713 | rEndDateTime.setTime(mRecurStart.time()); | 745 | rEndDateTime.setTime(mRecurStart.time()); |
714 | mCompatDuration = 0; | 746 | mCompatDuration = 0; |
715 | setYearly_(rYearlyMonth, type, _rFreq, 0); | 747 | setYearly_(rYearlyMonth, type, _rFreq, 0); |
716 | } | 748 | } |
717 | 749 | ||
718 | void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) | 750 | void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) |
719 | { | 751 | { |
720 | if (recurs == rYearlyPos) | 752 | if (recurs == rYearlyPos) |
721 | addMonthlyPos_(_rPos, _rDays); | 753 | addMonthlyPos_(_rPos, _rDays); |
722 | } | 754 | } |
723 | 755 | ||
724 | const QPtrList<int> &Recurrence::yearNums() const | 756 | const QPtrList<int> &Recurrence::yearNums() const |
725 | { | 757 | { |
726 | return rYearNums; | 758 | return rYearNums; |
727 | } | 759 | } |
728 | void Recurrence::addYearlyMonth(short _rPos ) | 760 | void Recurrence::addYearlyMonth(short _rPos ) |
729 | { | 761 | { |
730 | if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number | 762 | if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number |
731 | return; | 763 | return; |
732 | rMonthPos *tmpPos = new rMonthPos; | 764 | rMonthPos *tmpPos = new rMonthPos; |
733 | if ( _rPos > 0) { | 765 | if ( _rPos > 0) { |
734 | tmpPos->rPos = _rPos; | 766 | tmpPos->rPos = _rPos; |
735 | tmpPos->negative = false; | 767 | tmpPos->negative = false; |
736 | } else { | 768 | } else { |
737 | tmpPos->rPos = -_rPos; // take abs() | 769 | tmpPos->rPos = -_rPos; // take abs() |
738 | tmpPos->negative = true; | 770 | tmpPos->negative = true; |
739 | } | 771 | } |
740 | rMonthPositions.append(tmpPos); | 772 | rMonthPositions.append(tmpPos); |
741 | } | 773 | } |
742 | void Recurrence::addYearlyNum(short _rNum) | 774 | void Recurrence::addYearlyNum(short _rNum) |
743 | { | 775 | { |
744 | if (mRecurReadOnly | 776 | if (mRecurReadOnly |
745 | || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) | 777 | || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) |
746 | || _rNum <= 0) // invalid day/month number | 778 | || _rNum <= 0) // invalid day/month number |
747 | return; | 779 | return; |
748 | 780 | ||
749 | if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { | 781 | if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { |
750 | // Backwards compatibility for KDE < 3.1. | 782 | // Backwards compatibility for KDE < 3.1. |
751 | // Dates were stored as day numbers, with a fiddle to take account of leap years. | 783 | // Dates were stored as day numbers, with a fiddle to take account of leap years. |
752 | // Convert the day number to a month. | 784 | // Convert the day number to a month. |
753 | if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) | 785 | if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) |
754 | return; // invalid day number | 786 | return; // invalid day number |
755 | _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); | 787 | _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); |
756 | } else | 788 | } else |
757 | if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 | 789 | if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 |
758 | || recurs == rYearlyDay && _rNum > 366) | 790 | || recurs == rYearlyDay && _rNum > 366) |
759 | return; // invalid day number | 791 | return; // invalid day number |
760 | 792 | ||
761 | uint i = 0; | 793 | uint i = 0; |
762 | for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { | 794 | for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { |
763 | if (_rNum == *it) | 795 | if (_rNum == *it) |
764 | return; // this day/month is already in the list - avoid duplication | 796 | return; // this day/month is already in the list - avoid duplication |
765 | ++i; | 797 | ++i; |
766 | } | 798 | } |
767 | 799 | ||
768 | int *tmpNum = new int; | 800 | int *tmpNum = new int; |
769 | *tmpNum = _rNum; | 801 | *tmpNum = _rNum; |
770 | rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position | 802 | rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position |
771 | 803 | ||
772 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 804 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
773 | // Backwards compatibility for KDE < 3.1. | 805 | // Backwards compatibility for KDE < 3.1. |
774 | // rDuration was set to the number of time periods to recur. | 806 | // rDuration was set to the number of time periods to recur. |
775 | // Convert this to the number of occurrences. | 807 | // Convert this to the number of occurrences. |
776 | QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31); | 808 | QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31); |
777 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 809 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
778 | rDuration = recurCalc(COUNT_TO_DATE, end); | 810 | rDuration = recurCalc(COUNT_TO_DATE, end); |
779 | } | 811 | } |
780 | 812 | ||
781 | if (mParent) mParent->updated(); | 813 | if (mParent) mParent->updated(); |
782 | } | 814 | } |
783 | 815 | ||
784 | 816 | ||
785 | QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const | 817 | QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const |
786 | { | 818 | { |
787 | if (last) | 819 | if (last) |
788 | *last = false; | 820 | *last = false; |
789 | int freq; | 821 | int freq; |
790 | switch (recurs) | 822 | switch (recurs) |
791 | { | 823 | { |
792 | case rMinutely: | 824 | case rMinutely: |
793 | freq = rFreq * 60; | 825 | freq = rFreq * 60; |
794 | break; | 826 | break; |
795 | case rHourly: | 827 | case rHourly: |
796 | freq = rFreq * 3600; | 828 | freq = rFreq * 3600; |
797 | break; | 829 | break; |
798 | case rDaily: | 830 | case rDaily: |
799 | case rWeekly: | 831 | case rWeekly: |
800 | case rMonthlyPos: | 832 | case rMonthlyPos: |
801 | case rMonthlyDay: | 833 | case rMonthlyDay: |
802 | case rYearlyMonth: | 834 | case rYearlyMonth: |
803 | case rYearlyDay: | 835 | case rYearlyDay: |
804 | case rYearlyPos: { | 836 | case rYearlyPos: { |
805 | QDate preDate = preDateTime.date(); | 837 | QDate preDate = preDateTime.date(); |
806 | if (!mFloats && mRecurStart.time() > preDateTime.time()) | 838 | if (!mFloats && mRecurStart.time() > preDateTime.time()) |
807 | preDate = preDate.addDays(-1); | 839 | preDate = preDate.addDays(-1); |
808 | return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); | 840 | return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); |
809 | } | 841 | } |
810 | default: | 842 | default: |
811 | return QDateTime(); | 843 | return QDateTime(); |
812 | } | 844 | } |
813 | 845 | ||
814 | // It's a sub-daily recurrence | 846 | // It's a sub-daily recurrence |
815 | if (preDateTime < mRecurStart) | 847 | if (preDateTime < mRecurStart) |
816 | return mRecurStart; | 848 | return mRecurStart; |
817 | int count = mRecurStart.secsTo(preDateTime) / freq + 2; | 849 | int count = mRecurStart.secsTo(preDateTime) / freq + 2; |
818 | if (rDuration > 0) { | 850 | if (rDuration > 0) { |
819 | if (count > rDuration) | 851 | if (count > rDuration) |
820 | return QDateTime(); | 852 | return QDateTime(); |
821 | if (last && count == rDuration) | 853 | if (last && count == rDuration) |
822 | *last = true; | 854 | *last = true; |
823 | } | 855 | } |
824 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 856 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
825 | if (rDuration == 0) { | 857 | if (rDuration == 0) { |
826 | if (endtime > rEndDateTime) | 858 | if (endtime > rEndDateTime) |
827 | return QDateTime(); | 859 | return QDateTime(); |
828 | if (last && endtime == rEndDateTime) | 860 | if (last && endtime == rEndDateTime) |
829 | *last = true; | 861 | *last = true; |
830 | } | 862 | } |
831 | return endtime; | 863 | return endtime; |
832 | } | 864 | } |
833 | 865 | ||
834 | QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const | 866 | QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const |
835 | { | 867 | { |
836 | if (last) | 868 | if (last) |
837 | *last = false; | 869 | *last = false; |
838 | switch (recurs) | 870 | switch (recurs) |
839 | { | 871 | { |
840 | case rMinutely: | 872 | case rMinutely: |
841 | case rHourly: | 873 | case rHourly: |
842 | return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); | 874 | return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); |
843 | case rDaily: | 875 | case rDaily: |
844 | case rWeekly: | 876 | case rWeekly: |
845 | case rMonthlyPos: | 877 | case rMonthlyPos: |
846 | case rMonthlyDay: | 878 | case rMonthlyDay: |
847 | case rYearlyMonth: | 879 | case rYearlyMonth: |
848 | case rYearlyDay: | 880 | case rYearlyDay: |
849 | case rYearlyPos: | 881 | case rYearlyPos: |
850 | return getNextDateNoTime(preDate, last); | 882 | return getNextDateNoTime(preDate, last); |
851 | default: | 883 | default: |
852 | return QDate(); | 884 | return QDate(); |
853 | } | 885 | } |
854 | } | 886 | } |
855 | 887 | ||
856 | 888 | ||
857 | QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const | 889 | QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const |
858 | { | 890 | { |
859 | if (last) | 891 | if (last) |
860 | *last = false; | 892 | *last = false; |
861 | int freq; | 893 | int freq; |
862 | switch (recurs) | 894 | switch (recurs) |
863 | { | 895 | { |
864 | case rMinutely: | 896 | case rMinutely: |
865 | freq = rFreq * 60; | 897 | freq = rFreq * 60; |
866 | break; | 898 | break; |
867 | case rHourly: | 899 | case rHourly: |
868 | freq = rFreq * 3600; | 900 | freq = rFreq * 3600; |
869 | break; | 901 | break; |
870 | case rDaily: | 902 | case rDaily: |
871 | case rWeekly: | 903 | case rWeekly: |
872 | case rMonthlyPos: | 904 | case rMonthlyPos: |
873 | case rMonthlyDay: | 905 | case rMonthlyDay: |
874 | case rYearlyMonth: | 906 | case rYearlyMonth: |
875 | case rYearlyDay: | 907 | case rYearlyDay: |
876 | case rYearlyPos: { | 908 | case rYearlyPos: { |
877 | QDate afterDate = afterDateTime.date(); | 909 | QDate afterDate = afterDateTime.date(); |
878 | if (!mFloats && mRecurStart.time() < afterDateTime.time()) | 910 | if (!mFloats && mRecurStart.time() < afterDateTime.time()) |
879 | afterDate = afterDate.addDays(1); | 911 | afterDate = afterDate.addDays(1); |
880 | return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); | 912 | return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); |
881 | } | 913 | } |
882 | default: | 914 | default: |
883 | return QDateTime(); | 915 | return QDateTime(); |
884 | } | 916 | } |
885 | 917 | ||
886 | // It's a sub-daily recurrence | 918 | // It's a sub-daily recurrence |
887 | if (afterDateTime <= mRecurStart) | 919 | if (afterDateTime <= mRecurStart) |
888 | return QDateTime(); | 920 | return QDateTime(); |
889 | int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; | 921 | int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; |
890 | if (rDuration > 0) { | 922 | if (rDuration > 0) { |
891 | if (count > rDuration) | 923 | if (count > rDuration) |
892 | count = rDuration; | 924 | count = rDuration; |
893 | if (last && count == rDuration) | 925 | if (last && count == rDuration) |
894 | *last = true; | 926 | *last = true; |
895 | } | 927 | } |
896 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 928 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
897 | if (rDuration == 0) { | 929 | if (rDuration == 0) { |
898 | if (endtime > rEndDateTime) | 930 | if (endtime > rEndDateTime) |
899 | endtime = rEndDateTime; | 931 | endtime = rEndDateTime; |
900 | if (last && endtime == rEndDateTime) | 932 | if (last && endtime == rEndDateTime) |
901 | *last = true; | 933 | *last = true; |
902 | } | 934 | } |
903 | return endtime; | 935 | return endtime; |
904 | } | 936 | } |
905 | 937 | ||
906 | QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const | 938 | QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const |
907 | { | 939 | { |
908 | if (last) | 940 | if (last) |
909 | *last = false; | 941 | *last = false; |
910 | switch (recurs) | 942 | switch (recurs) |
911 | { | 943 | { |
912 | case rMinutely: | 944 | case rMinutely: |
913 | case rHourly: | 945 | case rHourly: |
914 | return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); | 946 | return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); |
915 | case rDaily: | 947 | case rDaily: |
916 | case rWeekly: | 948 | case rWeekly: |
917 | case rMonthlyPos: | 949 | case rMonthlyPos: |
918 | case rMonthlyDay: | 950 | case rMonthlyDay: |
919 | case rYearlyMonth: | 951 | case rYearlyMonth: |
920 | case rYearlyDay: | 952 | case rYearlyDay: |
921 | case rYearlyPos: | 953 | case rYearlyPos: |
922 | return getPreviousDateNoTime(afterDate, last); | 954 | return getPreviousDateNoTime(afterDate, last); |
923 | default: | 955 | default: |
924 | return QDate(); | 956 | return QDate(); |
925 | } | 957 | } |
926 | } | 958 | } |
927 | 959 | ||
928 | 960 | ||
929 | /***************************** PROTECTED FUNCTIONS ***************************/ | 961 | /***************************** PROTECTED FUNCTIONS ***************************/ |
930 | 962 | ||
931 | bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const | 963 | bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const |
932 | { | 964 | { |
933 | if ((qd >= mRecurStart.date()) && | 965 | if ((qd >= mRecurStart.date()) && |
934 | ((rDuration > 0) && (qd <= endDate()) || | 966 | ((rDuration > 0) && (qd <= endDate()) || |
935 | ((rDuration == 0) && (qd <= rEndDateTime.date())) || | 967 | ((rDuration == 0) && (qd <= rEndDateTime.date())) || |
936 | (rDuration == -1))) { | 968 | (rDuration == -1))) { |
937 | // The date queried falls within the range of the event. | 969 | // The date queried falls within the range of the event. |
938 | if (secondFreq < 24*3600) | 970 | if (secondFreq < 24*3600) |
939 | return true; // the event recurs at least once each day | 971 | return true; // the event recurs at least once each day |
940 | int after = mRecurStart.secsTo(QDateTime(qd)); | 972 | int after = mRecurStart.secsTo(QDateTime(qd)); |
941 | if (after / secondFreq != (after + 24*3600) / secondFreq) | 973 | if (after / secondFreq != (after + 24*3600) / secondFreq) |
942 | return true; | 974 | return true; |
943 | } | 975 | } |
944 | return false; | 976 | return false; |
945 | } | 977 | } |
946 | 978 | ||
947 | bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const | 979 | bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const |
948 | { | 980 | { |
949 | if ((dt >= mRecurStart) && | 981 | if ((dt >= mRecurStart) && |
950 | ((rDuration > 0) && (dt <= endDateTime()) || | 982 | ((rDuration > 0) && (dt <= endDateTime()) || |
951 | ((rDuration == 0) && (dt <= rEndDateTime)) || | 983 | ((rDuration == 0) && (dt <= rEndDateTime)) || |
952 | (rDuration == -1))) { | 984 | (rDuration == -1))) { |
953 | // The time queried falls within the range of the event. | 985 | // The time queried falls within the range of the event. |
954 | if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) | 986 | if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) |
955 | return true; | 987 | return true; |
956 | } | 988 | } |
957 | return false; | 989 | return false; |
958 | } | 990 | } |
959 | 991 | ||
960 | bool Recurrence::recursDaily(const QDate &qd) const | 992 | bool Recurrence::recursDaily(const QDate &qd) const |
961 | { | 993 | { |
962 | QDate dStart = mRecurStart.date(); | 994 | QDate dStart = mRecurStart.date(); |
963 | if ((dStart.daysTo(qd) % rFreq) == 0) { | 995 | if ((dStart.daysTo(qd) % rFreq) == 0) { |
964 | // The date is a day which recurs | 996 | // The date is a day which recurs |
965 | if (qd >= dStart | 997 | if (qd >= dStart |
966 | && ((rDuration > 0 && qd <= endDate()) || | 998 | && ((rDuration > 0 && qd <= endDate()) || |
967 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 999 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
968 | rDuration == -1)) { | 1000 | rDuration == -1)) { |
969 | // The date queried falls within the range of the event. | 1001 | // The date queried falls within the range of the event. |
970 | return true; | 1002 | return true; |
971 | } | 1003 | } |
972 | } | 1004 | } |
973 | return false; | 1005 | return false; |
974 | } | 1006 | } |
975 | 1007 | ||
976 | bool Recurrence::recursWeekly(const QDate &qd) const | 1008 | bool Recurrence::recursWeekly(const QDate &qd) const |
977 | { | 1009 | { |
978 | QDate dStart = mRecurStart.date(); | 1010 | QDate dStart = mRecurStart.date(); |
979 | if ((dStart.daysTo(qd)/7) % rFreq == 0) { | 1011 | if ((dStart.daysTo(qd)/7) % rFreq == 0) { |
980 | // The date is in a week which recurs | 1012 | // The date is in a week which recurs |
981 | if (qd >= dStart | 1013 | if (qd >= dStart |
982 | && ((rDuration > 0 && qd <= endDate()) || | 1014 | && ((rDuration > 0 && qd <= endDate()) || |
983 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1015 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
984 | rDuration == -1)) { | 1016 | rDuration == -1)) { |
985 | // The date queried falls within the range of the event. | 1017 | // The date queried falls within the range of the event. |
986 | // check if the bits set match today. | 1018 | // check if the bits set match today. |
987 | int i = qd.dayOfWeek()-1; | 1019 | int i = qd.dayOfWeek()-1; |
988 | if (rDays.testBit((uint) i)) | 1020 | if (rDays.testBit((uint) i)) |
989 | return true; | 1021 | return true; |
990 | } | 1022 | } |
991 | } | 1023 | } |
992 | return false; | 1024 | return false; |
993 | } | 1025 | } |
994 | 1026 | ||
995 | bool Recurrence::recursMonthly(const QDate &qd) const | 1027 | bool Recurrence::recursMonthly(const QDate &qd) const |
996 | { | 1028 | { |
997 | QDate dStart = mRecurStart.date(); | 1029 | QDate dStart = mRecurStart.date(); |
998 | int year = qd.year(); | 1030 | int year = qd.year(); |
999 | int month = qd.month(); | 1031 | int month = qd.month(); |
1000 | int day = qd.day(); | 1032 | int day = qd.day(); |
1001 | // calculate how many months ahead this date is from the original | 1033 | // calculate how many months ahead this date is from the original |
1002 | // event's date | 1034 | // event's date |
1003 | int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month()); | 1035 | int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month()); |
1004 | if ((monthsAhead % rFreq) == 0) { | 1036 | if ((monthsAhead % rFreq) == 0) { |
1005 | // The date is in a month which recurs | 1037 | // The date is in a month which recurs |
1006 | if (qd >= dStart | 1038 | if (qd >= dStart |
1007 | && ((rDuration > 0 && qd <= endDate()) || | 1039 | && ((rDuration > 0 && qd <= endDate()) || |
1008 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1040 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1009 | rDuration == -1)) { | 1041 | rDuration == -1)) { |
1010 | // The date queried falls within the range of the event. | 1042 | // The date queried falls within the range of the event. |
1011 | QValueList<int> days; | 1043 | QValueList<int> days; |
1012 | int daysInMonth = qd.daysInMonth(); | 1044 | int daysInMonth = qd.daysInMonth(); |
1013 | if (recurs == rMonthlyDay) | 1045 | if (recurs == rMonthlyDay) |
1014 | getMonthlyDayDays(days, daysInMonth); | 1046 | getMonthlyDayDays(days, daysInMonth); |
1015 | else if (recurs == rMonthlyPos) | 1047 | else if (recurs == rMonthlyPos) |
1016 | getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); | 1048 | getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); |
1017 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1049 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1018 | if (*it == day) | 1050 | if (*it == day) |
1019 | return true; | 1051 | return true; |
1020 | } | 1052 | } |
1021 | // no dates matched | 1053 | // no dates matched |
1022 | } | 1054 | } |
1023 | } | 1055 | } |
1024 | return false; | 1056 | return false; |
1025 | } | 1057 | } |
1026 | 1058 | ||
1027 | bool Recurrence::recursYearlyByMonth(const QDate &qd) const | 1059 | bool Recurrence::recursYearlyByMonth(const QDate &qd) const |
1028 | { | 1060 | { |
1029 | QDate dStart = mRecurStart.date(); | 1061 | QDate dStart = mRecurStart.date(); |
1030 | int startDay = dStart.day(); | 1062 | int startDay = dStart.day(); |
1031 | int qday = qd.day(); | 1063 | int qday = qd.day(); |
1032 | int qmonth = qd.month(); | 1064 | int qmonth = qd.month(); |
1033 | int qyear = qd.year(); | 1065 | int qyear = qd.year(); |
1034 | bool match = (qday == startDay); | 1066 | bool match = (qday == startDay); |
1035 | if (!match && startDay == 29 && dStart.month() == 2) { | 1067 | if (!match && startDay == 29 && dStart.month() == 2) { |
1036 | // It's a recurrence on February 29th | 1068 | // It's a recurrence on February 29th |
1037 | switch (mFeb29YearlyType) { | 1069 | switch (mFeb29YearlyType) { |
1038 | case rFeb28: | 1070 | case rFeb28: |
1039 | if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear)) | 1071 | if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear)) |
1040 | match = true; | 1072 | match = true; |
1041 | break; | 1073 | break; |
1042 | case rMar1: | 1074 | case rMar1: |
1043 | if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) { | 1075 | if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) { |
1044 | qmonth = 2; | 1076 | qmonth = 2; |
1045 | match = true; | 1077 | match = true; |
1046 | } | 1078 | } |
1047 | break; | 1079 | break; |
1048 | case rFeb29: | 1080 | case rFeb29: |
1049 | break; | 1081 | break; |
1050 | } | 1082 | } |
1051 | } | 1083 | } |
1052 | 1084 | ||
1053 | if (match) { | 1085 | if (match) { |
1054 | // The day of the month matches. Calculate how many years ahead | 1086 | // The day of the month matches. Calculate how many years ahead |
1055 | // this date is from the original event's date. | 1087 | // this date is from the original event's date. |
1056 | int yearsAhead = (qyear - dStart.year()); | 1088 | int yearsAhead = (qyear - dStart.year()); |
1057 | if (yearsAhead % rFreq == 0) { | 1089 | if (yearsAhead % rFreq == 0) { |
1058 | // The date is in a year which recurs | 1090 | // The date is in a year which recurs |
1059 | if (qd >= dStart | 1091 | if (qd >= dStart |
1060 | && ((rDuration > 0 && qd <= endDate()) || | 1092 | && ((rDuration > 0 && qd <= endDate()) || |
1061 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1093 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1062 | rDuration == -1)) { | 1094 | rDuration == -1)) { |
1063 | // The date queried falls within the range of the event. | 1095 | // The date queried falls within the range of the event. |
1064 | int i = qmonth; | 1096 | int i = qmonth; |
1065 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1097 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1066 | if (i == *qlin.current()) | 1098 | if (i == *qlin.current()) |
1067 | return true; | 1099 | return true; |
1068 | } | 1100 | } |
1069 | } | 1101 | } |
1070 | } | 1102 | } |
1071 | } | 1103 | } |
1072 | return false; | 1104 | return false; |
1073 | } | 1105 | } |
1074 | 1106 | ||
1075 | bool Recurrence::recursYearlyByPos(const QDate &qd) const | 1107 | bool Recurrence::recursYearlyByPos(const QDate &qd) const |
1076 | { | 1108 | { |
1077 | QDate dStart = mRecurStart.date(); | 1109 | QDate dStart = mRecurStart.date(); |
1078 | int year = qd.year(); | 1110 | int year = qd.year(); |
1079 | int month = qd.month(); | 1111 | int month = qd.month(); |
1080 | int day = qd.day(); | 1112 | int day = qd.day(); |
1081 | // calculate how many years ahead this date is from the original | 1113 | // calculate how many years ahead this date is from the original |
1082 | // event's date | 1114 | // event's date |
1083 | int yearsAhead = (year - dStart.year()); | 1115 | int yearsAhead = (year - dStart.year()); |
1084 | if (yearsAhead % rFreq == 0) { | 1116 | if (yearsAhead % rFreq == 0) { |
1085 | // The date is in a year which recurs | 1117 | // The date is in a year which recurs |
1086 | if (qd >= dStart | 1118 | if (qd >= dStart |
1087 | && ((rDuration > 0 && qd <= endDate()) || | 1119 | && ((rDuration > 0 && qd <= endDate()) || |
1088 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1120 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1089 | rDuration == -1)) { | 1121 | rDuration == -1)) { |
1090 | // The date queried falls within the range of the event. | 1122 | // The date queried falls within the range of the event. |
1091 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1123 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1092 | if (month == *qlin.current()) { | 1124 | if (month == *qlin.current()) { |
1093 | // The month recurs | 1125 | // The month recurs |
1094 | QValueList<int> days; | 1126 | QValueList<int> days; |
1095 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); | 1127 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); |
1096 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1128 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1097 | if (*it == day) | 1129 | if (*it == day) |
1098 | return true; | 1130 | return true; |
1099 | } | 1131 | } |
1100 | } | 1132 | } |
1101 | } | 1133 | } |
1102 | } | 1134 | } |
1103 | } | 1135 | } |
1104 | return false; | 1136 | return false; |
1105 | } | 1137 | } |
1106 | 1138 | ||
1107 | bool Recurrence::recursYearlyByDay(const QDate &qd) const | 1139 | bool Recurrence::recursYearlyByDay(const QDate &qd) const |
1108 | { | 1140 | { |
1109 | QDate dStart = mRecurStart.date(); | 1141 | QDate dStart = mRecurStart.date(); |
1110 | // calculate how many years ahead this date is from the original | 1142 | // calculate how many years ahead this date is from the original |
1111 | // event's date | 1143 | // event's date |
1112 | int yearsAhead = (qd.year() - dStart.year()); | 1144 | int yearsAhead = (qd.year() - dStart.year()); |
1113 | if (yearsAhead % rFreq == 0) { | 1145 | if (yearsAhead % rFreq == 0) { |
1114 | // The date is in a year which recurs | 1146 | // The date is in a year which recurs |
1115 | if (qd >= dStart | 1147 | if (qd >= dStart |
1116 | && ((rDuration > 0 && qd <= endDate()) || | 1148 | && ((rDuration > 0 && qd <= endDate()) || |
1117 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1149 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1118 | rDuration == -1)) { | 1150 | rDuration == -1)) { |
1119 | // The date queried falls within the range of the event. | 1151 | // The date queried falls within the range of the event. |
1120 | int i = qd.dayOfYear(); | 1152 | int i = qd.dayOfYear(); |
1121 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1153 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1122 | if (i == *qlin.current()) | 1154 | if (i == *qlin.current()) |
1123 | return true; | 1155 | return true; |
1124 | } | 1156 | } |
1125 | } | 1157 | } |
1126 | } | 1158 | } |
1127 | return false; | 1159 | return false; |
1128 | } | 1160 | } |
1129 | 1161 | ||
1130 | /* Get the date of the next recurrence, after the specified date. | 1162 | /* Get the date of the next recurrence, after the specified date. |
1131 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the | 1163 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the |
1132 | * last recurrence, else false. | 1164 | * last recurrence, else false. |
1133 | * Reply = date of next recurrence, or invalid date if none. | 1165 | * Reply = date of next recurrence, or invalid date if none. |
1134 | */ | 1166 | */ |
1135 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const | 1167 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const |
1136 | { | 1168 | { |
1137 | if (last) | 1169 | if (last) |
1138 | *last = false; | 1170 | *last = false; |
1139 | QDate dStart = mRecurStart.date(); | 1171 | QDate dStart = mRecurStart.date(); |
1140 | if (preDate < dStart) | 1172 | if (preDate < dStart) |
1141 | return dStart; | 1173 | return dStart; |
1142 | QDate earliestDate = preDate.addDays(1); | 1174 | QDate earliestDate = preDate.addDays(1); |
1143 | QDate nextDate; | 1175 | QDate nextDate; |
1144 | 1176 | ||
1145 | switch (recurs) { | 1177 | switch (recurs) { |
1146 | case rDaily: | 1178 | case rDaily: |
1147 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); | 1179 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); |
1148 | break; | 1180 | break; |
1149 | 1181 | ||
1150 | case rWeekly: { | 1182 | case rWeekly: { |
1151 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart | 1183 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart |
1152 | int earliestDayOfWeek = earliestDate.dayOfWeek(); | 1184 | int earliestDayOfWeek = earliestDate.dayOfWeek(); |
1153 | int weeksAhead = start.daysTo(earliestDate) / 7; | 1185 | int weeksAhead = start.daysTo(earliestDate) / 7; |
1154 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week | 1186 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week |
1155 | weeksAhead -= notThisWeek; // latest week which recurred | 1187 | weeksAhead -= notThisWeek; // latest week which recurred |
1156 | int weekday = 0; | 1188 | int weekday = 0; |
1157 | // First check for any remaining day this week, if this week is a recurring week | 1189 | // First check for any remaining day this week, if this week is a recurring week |
1158 | if (!notThisWeek) | 1190 | if (!notThisWeek) |
1159 | weekday = getFirstDayInWeek(earliestDayOfWeek); | 1191 | weekday = getFirstDayInWeek(earliestDayOfWeek); |
1160 | // Check for a day in the next scheduled week | 1192 | // Check for a day in the next scheduled week |
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index defdb09..89eb72f 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -1,1018 +1,1019 @@ | |||
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 <qptrlist.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 <qtextstream.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 | oldCategories = 0; | 67 | oldCategories = 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) | 70 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) |
71 | { | 71 | { |
72 | int i = 1; | 72 | int i = 1; |
73 | bool skip = true; | 73 | bool skip = true; |
74 | int max = attList.count() -2; | 74 | int max = attList.count() -2; |
75 | while ( i < max ) { | 75 | while ( i < max ) { |
76 | if ( !attList[i].isEmpty() ) { | 76 | if ( !attList[i].isEmpty() ) { |
77 | skip = false; | 77 | skip = false; |
78 | break; | 78 | break; |
79 | } | 79 | } |
80 | ++i ; | 80 | ++i ; |
81 | } | 81 | } |
82 | if ( skip ) | 82 | if ( skip ) |
83 | return false; | 83 | return false; |
84 | ulong cSum = SharpFormat::getCsum(attList ); | 84 | ulong cSum = SharpFormat::getCsum(attList ); |
85 | 85 | ||
86 | if ( qName == "Event" ) { | 86 | if ( qName == "Event" ) { |
87 | Event *event; | 87 | Event *event; |
88 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); | 88 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); |
89 | if ( event ) | 89 | if ( event ) |
90 | event = (Event*)event->clone(); | 90 | event = (Event*)event->clone(); |
91 | else | 91 | else |
92 | event = new Event; | 92 | event = new Event; |
93 | event->setID("Sharp_DTM", attList[0] ); | 93 | event->setID("Sharp_DTM", attList[0] ); |
94 | event->setCsum( "Sharp_DTM", QString::number( cSum )); | 94 | event->setCsum( "Sharp_DTM", QString::number( cSum )); |
95 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 95 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
96 | 96 | ||
97 | event->setSummary( attList[2] ); | 97 | event->setSummary( attList[2] ); |
98 | event->setLocation( attList[3] ); | 98 | event->setLocation( attList[3] ); |
99 | event->setDescription( attList[4] ); | 99 | event->setDescription( attList[4] ); |
100 | if ( attList[7] == "1" ) { | 100 | if ( attList[7] == "1" ) { |
101 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); | 101 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); |
102 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); | 102 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); |
103 | event->setFloats( true ); | 103 | event->setFloats( true ); |
104 | } else { | 104 | } else { |
105 | event->setFloats( false ); | 105 | event->setFloats( false ); |
106 | event->setDtStart( fromString( attList[5] ) ); | 106 | event->setDtStart( fromString( attList[5] ) ); |
107 | event->setDtEnd( fromString( attList[6] )); | 107 | event->setDtEnd( fromString( attList[6] )); |
108 | } | 108 | } |
109 | 109 | ||
110 | QString rtype = attList[11]; | 110 | QString rtype = attList[11]; |
111 | if ( rtype != "255" ) { | 111 | if ( rtype != "255" ) { |
112 | // qDebug("recurs "); | 112 | // qDebug("recurs "); |
113 | QDate startDate = event->dtStart().date(); | 113 | QDate startDate = event->dtStart().date(); |
114 | 114 | ||
115 | QString freqStr = attList[12]; | 115 | QString freqStr = attList[12]; |
116 | int freq = freqStr.toInt(); | 116 | int freq = freqStr.toInt(); |
117 | 117 | ||
118 | QString hasEndDateStr = attList[15] ; | 118 | QString hasEndDateStr = attList[15] ; |
119 | bool hasEndDate = hasEndDateStr == "1"; | 119 | bool hasEndDate = hasEndDateStr == "1"; |
120 | 120 | ||
121 | QString endDateStr = attList[16]; | 121 | QString endDateStr = attList[16]; |
122 | QDate endDate = fromString( endDateStr ).date(); | 122 | QDate endDate = fromString( endDateStr ).date(); |
123 | 123 | ||
124 | QString weekDaysStr = attList[14]; | 124 | QString weekDaysStr = attList[14]; |
125 | uint weekDaysNum = weekDaysStr.toInt(); | 125 | uint weekDaysNum = weekDaysStr.toInt(); |
126 | 126 | ||
127 | QBitArray weekDays( 7 ); | 127 | QBitArray weekDays( 7 ); |
128 | int i; | 128 | int i; |
129 | int bb = 1; | 129 | int bb = 1; |
130 | for( i = 1; i <= 7; ++i ) { | 130 | for( i = 1; i <= 7; ++i ) { |
131 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | 131 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); |
132 | bb = 2 << (i-1); | 132 | bb = 2 << (i-1); |
133 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | 133 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); |
134 | } | 134 | } |
135 | // qDebug("next "); | 135 | // qDebug("next "); |
136 | QString posStr = attList[13]; | 136 | QString posStr = attList[13]; |
137 | int pos = posStr.toInt(); | 137 | int pos = posStr.toInt(); |
138 | Recurrence *r = event->recurrence(); | 138 | Recurrence *r = event->recurrence(); |
139 | 139 | ||
140 | if ( rtype == "0" ) { | 140 | if ( rtype == "0" ) { |
141 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 141 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
142 | else r->setDaily( freq, -1 ); | 142 | else r->setDaily( freq, -1 ); |
143 | } else if ( rtype == "1" ) { | 143 | } else if ( rtype == "1" ) { |
144 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 144 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
145 | else r->setWeekly( freq, weekDays, -1 ); | 145 | else r->setWeekly( freq, weekDays, -1 ); |
146 | } else if ( rtype == "3" ) { | 146 | } else if ( rtype == "3" ) { |
147 | if ( hasEndDate ) | 147 | if ( hasEndDate ) |
148 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 148 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
149 | else | 149 | else |
150 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 150 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
151 | r->addMonthlyDay( startDate.day() ); | 151 | r->addMonthlyDay( startDate.day() ); |
152 | } else if ( rtype == "2" ) { | 152 | } else if ( rtype == "2" ) { |
153 | if ( hasEndDate ) | 153 | if ( hasEndDate ) |
154 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 154 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
155 | else | 155 | else |
156 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 156 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
157 | QBitArray days( 7 ); | 157 | QBitArray days( 7 ); |
158 | days.fill( false ); | 158 | days.fill( false ); |
159 | days.setBit( startDate.dayOfWeek() - 1 ); | 159 | days.setBit( startDate.dayOfWeek() - 1 ); |
160 | r->addMonthlyPos( pos, days ); | 160 | r->addMonthlyPos( pos, days ); |
161 | } else if ( rtype == "4" ) { | 161 | } else if ( rtype == "4" ) { |
162 | if ( hasEndDate ) | 162 | if ( hasEndDate ) |
163 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 163 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
164 | else | 164 | else |
165 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 165 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
166 | r->addYearlyNum( startDate.month() ); | 166 | r->addYearlyNum( startDate.month() ); |
167 | } | 167 | } |
168 | } else { | 168 | } else { |
169 | event->recurrence()->unsetRecurs(); | 169 | event->recurrence()->unsetRecurs(); |
170 | } | 170 | } |
171 | 171 | ||
172 | QString categoryList = attList[1] ; | 172 | QString categoryList = attList[1] ; |
173 | event->setCategories( lookupCategories( categoryList ) ); | 173 | event->setCategories( lookupCategories( categoryList ) ); |
174 | 174 | ||
175 | // strange 0 semms to mean: alarm enabled | 175 | // strange 0 semms to mean: alarm enabled |
176 | if ( attList[8] == "0" ) { | 176 | if ( attList[8] == "0" ) { |
177 | Alarm *alarm; | 177 | Alarm *alarm; |
178 | if ( event->alarms().count() > 0 ) | 178 | if ( event->alarms().count() > 0 ) |
179 | alarm = event->alarms().first(); | 179 | alarm = event->alarms().first(); |
180 | else { | 180 | else { |
181 | alarm = new Alarm( event ); | 181 | alarm = new Alarm( event ); |
182 | event->addAlarm( alarm ); | 182 | event->addAlarm( alarm ); |
183 | alarm->setType( Alarm::Audio ); | ||
183 | } | 184 | } |
184 | alarm->setType( Alarm::Audio ); | 185 | //alarm->setType( Alarm::Audio ); |
185 | alarm->setEnabled( true ); | 186 | alarm->setEnabled( true ); |
186 | int alarmOffset = attList[9].toInt(); | 187 | int alarmOffset = attList[9].toInt(); |
187 | alarm->setStartOffset( alarmOffset * -60 ); | 188 | alarm->setStartOffset( alarmOffset * -60 ); |
188 | } else { | 189 | } else { |
189 | Alarm *alarm; | 190 | Alarm *alarm; |
190 | if ( event->alarms().count() > 0 ) { | 191 | if ( event->alarms().count() > 0 ) { |
191 | alarm = event->alarms().first(); | 192 | alarm = event->alarms().first(); |
192 | alarm->setType( Alarm::Audio ); | 193 | alarm->setType( Alarm::Audio ); |
193 | alarm->setStartOffset( -60*15 ); | 194 | alarm->setStartOffset( -60*15 ); |
194 | alarm->setEnabled( false ); | 195 | alarm->setEnabled( false ); |
195 | } | 196 | } |
196 | } | 197 | } |
197 | 198 | ||
198 | mCalendar->addEvent( event); | 199 | mCalendar->addEvent( event); |
199 | } else if ( qName == "Todo" ) { | 200 | } else if ( qName == "Todo" ) { |
200 | Todo *todo; | 201 | Todo *todo; |
201 | 202 | ||
202 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); | 203 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); |
203 | if (todo ) | 204 | if (todo ) |
204 | todo = (Todo*)todo->clone(); | 205 | todo = (Todo*)todo->clone(); |
205 | else | 206 | else |
206 | todo = new Todo; | 207 | todo = new Todo; |
207 | 208 | ||
208 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 | 209 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 |
209 | // 0 1 2 3 4 5 6 7 8 | 210 | // 0 1 2 3 4 5 6 7 8 |
210 | //1,,,,,1,4,Loch zumachen,"" | 211 | //1,,,,,1,4,Loch zumachen,"" |
211 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " | 212 | //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 | 213 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes |
213 | 214 | ||
214 | todo->setID( "Sharp_DTM", attList[0]); | 215 | todo->setID( "Sharp_DTM", attList[0]); |
215 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); | 216 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); |
216 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 217 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
217 | 218 | ||
218 | todo->setSummary( attList[7] ); | 219 | todo->setSummary( attList[7] ); |
219 | todo->setDescription( attList[8]); | 220 | todo->setDescription( attList[8]); |
220 | 221 | ||
221 | int priority = attList[6].toInt(); | 222 | int priority = attList[6].toInt(); |
222 | if ( priority == 0 ) priority = 3; | 223 | if ( priority == 0 ) priority = 3; |
223 | todo->setPriority( priority ); | 224 | todo->setPriority( priority ); |
224 | 225 | ||
225 | QString categoryList = attList[1]; | 226 | QString categoryList = attList[1]; |
226 | todo->setCategories( lookupCategories( categoryList ) ); | 227 | todo->setCategories( lookupCategories( categoryList ) ); |
227 | 228 | ||
228 | 229 | ||
229 | 230 | ||
230 | QString hasDateStr = attList[3]; // due | 231 | QString hasDateStr = attList[3]; // due |
231 | if ( !hasDateStr.isEmpty() ) { | 232 | if ( !hasDateStr.isEmpty() ) { |
232 | if ( hasDateStr.right(6) == "000000" ) { | 233 | if ( hasDateStr.right(6) == "000000" ) { |
233 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); | 234 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); |
234 | todo->setFloats( true ); | 235 | todo->setFloats( true ); |
235 | } | 236 | } |
236 | else { | 237 | else { |
237 | todo->setDtDue( fromString( hasDateStr ) ); | 238 | todo->setDtDue( fromString( hasDateStr ) ); |
238 | todo->setFloats( false ); | 239 | todo->setFloats( false ); |
239 | } | 240 | } |
240 | 241 | ||
241 | todo->setHasDueDate( true ); | 242 | todo->setHasDueDate( true ); |
242 | } | 243 | } |
243 | hasDateStr = attList[2];//start | 244 | hasDateStr = attList[2];//start |
244 | if ( !hasDateStr.isEmpty() ) { | 245 | if ( !hasDateStr.isEmpty() ) { |
245 | 246 | ||
246 | todo->setDtStart( fromString( hasDateStr ) ); | 247 | todo->setDtStart( fromString( hasDateStr ) ); |
247 | todo->setHasStartDate( true); | 248 | todo->setHasStartDate( true); |
248 | } else | 249 | } else |
249 | todo->setHasStartDate( false ); | 250 | todo->setHasStartDate( false ); |
250 | hasDateStr = attList[4];//completed | 251 | hasDateStr = attList[4];//completed |
251 | if ( !hasDateStr.isEmpty() ) { | 252 | if ( !hasDateStr.isEmpty() ) { |
252 | todo->setCompleted(fromString( hasDateStr ) ); | 253 | todo->setCompleted(fromString( hasDateStr ) ); |
253 | } | 254 | } |
254 | QString completedStr = attList[5]; | 255 | QString completedStr = attList[5]; |
255 | if ( completedStr == "0" ) | 256 | if ( completedStr == "0" ) |
256 | todo->setCompleted( true ); | 257 | todo->setCompleted( true ); |
257 | else | 258 | else |
258 | todo->setCompleted( false ); | 259 | todo->setCompleted( false ); |
259 | mCalendar->addTodo( todo ); | 260 | mCalendar->addTodo( todo ); |
260 | 261 | ||
261 | } else if ( qName == "Category" ) { | 262 | } else if ( qName == "Category" ) { |
262 | /* | 263 | /* |
263 | QString id = attributes.value( "id" ); | 264 | QString id = attributes.value( "id" ); |
264 | QString name = attributes.value( "name" ); | 265 | QString name = attributes.value( "name" ); |
265 | setCategory( id, name ); | 266 | setCategory( id, name ); |
266 | */ | 267 | */ |
267 | } | 268 | } |
268 | //qDebug("end "); | 269 | //qDebug("end "); |
269 | return true; | 270 | return true; |
270 | } | 271 | } |
271 | 272 | ||
272 | 273 | ||
273 | void setCategoriesList ( QStringList * c ) | 274 | void setCategoriesList ( QStringList * c ) |
274 | { | 275 | { |
275 | oldCategories = c; | 276 | oldCategories = c; |
276 | } | 277 | } |
277 | 278 | ||
278 | QDateTime fromString ( QString s, bool useTz = true ) { | 279 | QDateTime fromString ( QString s, bool useTz = true ) { |
279 | QDateTime dt; | 280 | QDateTime dt; |
280 | int y,m,t,h,min,sec; | 281 | int y,m,t,h,min,sec; |
281 | y = s.mid(0,4).toInt(); | 282 | y = s.mid(0,4).toInt(); |
282 | m = s.mid(4,2).toInt(); | 283 | m = s.mid(4,2).toInt(); |
283 | t = s.mid(6,2).toInt(); | 284 | t = s.mid(6,2).toInt(); |
284 | h = s.mid(9,2).toInt(); | 285 | h = s.mid(9,2).toInt(); |
285 | min = s.mid(11,2).toInt(); | 286 | min = s.mid(11,2).toInt(); |
286 | sec = s.mid(13,2).toInt(); | 287 | sec = s.mid(13,2).toInt(); |
287 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | 288 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); |
288 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 289 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
289 | if ( useTz ) | 290 | if ( useTz ) |
290 | dt = dt.addSecs ( offset*60); | 291 | dt = dt.addSecs ( offset*60); |
291 | return dt; | 292 | return dt; |
292 | 293 | ||
293 | } | 294 | } |
294 | protected: | 295 | protected: |
295 | QDateTime toDateTime( const QString &value ) | 296 | QDateTime toDateTime( const QString &value ) |
296 | { | 297 | { |
297 | QDateTime dt; | 298 | QDateTime dt; |
298 | dt.setTime_t( value.toUInt() ); | 299 | dt.setTime_t( value.toUInt() ); |
299 | 300 | ||
300 | return dt; | 301 | return dt; |
301 | } | 302 | } |
302 | 303 | ||
303 | QStringList lookupCategories( const QString &categoryList ) | 304 | QStringList lookupCategories( const QString &categoryList ) |
304 | { | 305 | { |
305 | QStringList categoryIds = QStringList::split( ";", categoryList ); | 306 | QStringList categoryIds = QStringList::split( ";", categoryList ); |
306 | QStringList categories; | 307 | QStringList categories; |
307 | QStringList::ConstIterator it; | 308 | QStringList::ConstIterator it; |
308 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { | 309 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { |
309 | QString cate = category( *it ); | 310 | QString cate = category( *it ); |
310 | if ( oldCategories ) { | 311 | if ( oldCategories ) { |
311 | if ( ! oldCategories->contains( cate ) ) | 312 | if ( ! oldCategories->contains( cate ) ) |
312 | oldCategories->append( cate ); | 313 | oldCategories->append( cate ); |
313 | } | 314 | } |
314 | categories.append(cate ); | 315 | categories.append(cate ); |
315 | } | 316 | } |
316 | return categories; | 317 | return categories; |
317 | } | 318 | } |
318 | 319 | ||
319 | private: | 320 | private: |
320 | Calendar *mCalendar; | 321 | Calendar *mCalendar; |
321 | QStringList * oldCategories; | 322 | QStringList * oldCategories; |
322 | static QString category( const QString &id ) | 323 | static QString category( const QString &id ) |
323 | { | 324 | { |
324 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); | 325 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); |
325 | if ( it == mCategoriesMap.end() ) return id; | 326 | if ( it == mCategoriesMap.end() ) return id; |
326 | else return *it; | 327 | else return *it; |
327 | } | 328 | } |
328 | 329 | ||
329 | static void setCategory( const QString &id, const QString &name ) | 330 | static void setCategory( const QString &id, const QString &name ) |
330 | { | 331 | { |
331 | mCategoriesMap.insert( id, name ); | 332 | mCategoriesMap.insert( id, name ); |
332 | } | 333 | } |
333 | 334 | ||
334 | static QMap<QString,QString> mCategoriesMap; | 335 | static QMap<QString,QString> mCategoriesMap; |
335 | }; | 336 | }; |
336 | 337 | ||
337 | QMap<QString,QString> SharpParser::mCategoriesMap; | 338 | QMap<QString,QString> SharpParser::mCategoriesMap; |
338 | 339 | ||
339 | SharpFormat::SharpFormat() | 340 | SharpFormat::SharpFormat() |
340 | { | 341 | { |
341 | mCategories = 0; | 342 | mCategories = 0; |
342 | } | 343 | } |
343 | 344 | ||
344 | SharpFormat::~SharpFormat() | 345 | SharpFormat::~SharpFormat() |
345 | { | 346 | { |
346 | } | 347 | } |
347 | ulong SharpFormat::getCsum( const QStringList & attList) | 348 | ulong SharpFormat::getCsum( const QStringList & attList) |
348 | { | 349 | { |
349 | int max = attList.count() -1; | 350 | int max = attList.count() -1; |
350 | ulong cSum = 0; | 351 | ulong cSum = 0; |
351 | int j,k,i; | 352 | int j,k,i; |
352 | int add; | 353 | int add; |
353 | for ( i = 1; i < max ; ++i ) { | 354 | for ( i = 1; i < max ; ++i ) { |
354 | QString s = attList[i]; | 355 | QString s = attList[i]; |
355 | if ( ! s.isEmpty() ){ | 356 | if ( ! s.isEmpty() ){ |
356 | j = s.length(); | 357 | j = s.length(); |
357 | for ( k = 0; k < j; ++k ) { | 358 | for ( k = 0; k < j; ++k ) { |
358 | int mul = k +1; | 359 | int mul = k +1; |
359 | add = s[k].unicode (); | 360 | add = s[k].unicode (); |
360 | if ( k < 16 ) | 361 | if ( k < 16 ) |
361 | mul = mul * mul; | 362 | mul = mul * mul; |
362 | add = add * mul *i*i*i; | 363 | add = add * mul *i*i*i; |
363 | cSum += add; | 364 | cSum += add; |
364 | } | 365 | } |
365 | } | 366 | } |
366 | } | 367 | } |
367 | return cSum; | 368 | return cSum; |
368 | 369 | ||
369 | } | 370 | } |
370 | #include <stdlib.h> | 371 | #include <stdlib.h> |
371 | #define DEBUGMODE false | 372 | //#define DEBUGMODE false |
373 | #define DEBUGMODE true | ||
372 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) | 374 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) |
373 | { | 375 | { |
374 | 376 | ||
375 | 377 | ||
376 | bool debug = DEBUGMODE; | 378 | bool debug = DEBUGMODE; |
377 | //debug = true; | ||
378 | QString text; | 379 | QString text; |
379 | QString codec = "utf8"; | 380 | QString codec = "utf8"; |
380 | QLabel status ( i18n("Reading events ..."), 0 ); | 381 | QLabel status ( i18n("Reading events ..."), 0 ); |
381 | 382 | ||
382 | int w = status.sizeHint().width()+20 ; | 383 | int w = status.sizeHint().width()+20 ; |
383 | if ( w < 200 ) w = 200; | 384 | if ( w < 200 ) w = 200; |
384 | int h = status.sizeHint().height()+20 ; | 385 | int h = status.sizeHint().height()+20 ; |
385 | int dw = QApplication::desktop()->width(); | 386 | int dw = QApplication::desktop()->width(); |
386 | int dh = QApplication::desktop()->height(); | 387 | int dh = QApplication::desktop()->height(); |
387 | status.setCaption(i18n("Reading DTM Data") ); | 388 | status.setCaption(i18n("Reading DTM Data") ); |
388 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 389 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
389 | status.show(); | 390 | status.show(); |
390 | status.raise(); | 391 | status.raise(); |
391 | qApp->processEvents(); | 392 | qApp->processEvents(); |
392 | QString fileName; | 393 | QString fileName; |
393 | if ( ! debug ) { | 394 | if ( ! debug ) { |
394 | fileName = "/tmp/kopitempout"; | 395 | fileName = "/tmp/kopitempout"; |
395 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; | 396 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; |
396 | system ( command.latin1() ); | 397 | system ( command.latin1() ); |
397 | } else { | 398 | } else { |
398 | fileName = "/tmp/events.txt"; | 399 | fileName = "/tmp/events.txt"; |
399 | 400 | ||
400 | } | 401 | } |
401 | QFile file( fileName ); | 402 | QFile file( fileName ); |
402 | if (!file.open( IO_ReadOnly ) ) { | 403 | if (!file.open( IO_ReadOnly ) ) { |
403 | return false; | 404 | return false; |
404 | 405 | ||
405 | } | 406 | } |
406 | QTextStream ts( &file ); | 407 | QTextStream ts( &file ); |
407 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 408 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
408 | text = ts.read(); | 409 | text = ts.read(); |
409 | file.close(); | 410 | file.close(); |
410 | status.setText( i18n("Processing events ...") ); | 411 | status.setText( i18n("Processing events ...") ); |
411 | status.raise(); | 412 | status.raise(); |
412 | qApp->processEvents(); | 413 | qApp->processEvents(); |
413 | fromString2Cal( calendar, existngCal, text, "Event" ); | 414 | fromString2Cal( calendar, existngCal, text, "Event" ); |
414 | status.setText( i18n("Reading todos ...") ); | 415 | status.setText( i18n("Reading todos ...") ); |
415 | qApp->processEvents(); | 416 | qApp->processEvents(); |
416 | if ( ! debug ) { | 417 | if ( ! debug ) { |
417 | fileName = "/tmp/kopitempout"; | 418 | fileName = "/tmp/kopitempout"; |
418 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; | 419 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; |
419 | system ( command.latin1() ); | 420 | system ( command.latin1() ); |
420 | } else { | 421 | } else { |
421 | fileName = "/tmp/todo.txt"; | 422 | fileName = "/tmp/todo.txt"; |
422 | } | 423 | } |
423 | file.setName( fileName ); | 424 | file.setName( fileName ); |
424 | if (!file.open( IO_ReadOnly ) ) { | 425 | if (!file.open( IO_ReadOnly ) ) { |
425 | return false; | 426 | return false; |
426 | 427 | ||
427 | } | 428 | } |
428 | ts.setDevice( &file ); | 429 | ts.setDevice( &file ); |
429 | text = ts.read(); | 430 | text = ts.read(); |
430 | file.close(); | 431 | file.close(); |
431 | 432 | ||
432 | status.setText( i18n("Processing todos ...") ); | 433 | status.setText( i18n("Processing todos ...") ); |
433 | status.raise(); | 434 | status.raise(); |
434 | qApp->processEvents(); | 435 | qApp->processEvents(); |
435 | fromString2Cal( calendar, existngCal, text, "Todo" ); | 436 | fromString2Cal( calendar, existngCal, text, "Todo" ); |
436 | return true; | 437 | return true; |
437 | } | 438 | } |
438 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) | 439 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) |
439 | { | 440 | { |
440 | int retval = -1; | 441 | int retval = -1; |
441 | QStringList templist; | 442 | QStringList templist; |
442 | QString tempString; | 443 | QString tempString; |
443 | int start = 0; | 444 | int start = 0; |
444 | int len = answer.length(); | 445 | int len = answer.length(); |
445 | int end = answer.find ("\n",start)+1; | 446 | int end = answer.find ("\n",start)+1; |
446 | bool ok = true; | 447 | bool ok = true; |
447 | start = end; | 448 | start = end; |
448 | int ccc = 0; | 449 | int ccc = 0; |
449 | while ( start > 0 ) { | 450 | while ( start > 0 ) { |
450 | templist.clear(); | 451 | templist.clear(); |
451 | ok = true; | 452 | ok = true; |
452 | int loopCount = 0; | 453 | int loopCount = 0; |
453 | while ( ok ) { | 454 | while ( ok ) { |
454 | ++loopCount; | 455 | ++loopCount; |
455 | if ( loopCount > 25 ) { | 456 | if ( loopCount > 25 ) { |
456 | qDebug("KO: Error in while loop"); | 457 | qDebug("KO: Error in while loop"); |
457 | ok = false; | 458 | ok = false; |
458 | start = 0; | 459 | start = 0; |
459 | break; | 460 | break; |
460 | } | 461 | } |
461 | if ( ok ) | 462 | if ( ok ) |
462 | tempString = getPart( answer, ok, start ); | 463 | tempString = getPart( answer, ok, start ); |
463 | if ( start >= len || start == 0 ) { | 464 | if ( start >= len || start == 0 ) { |
464 | start = 0; | 465 | start = 0; |
465 | ok = false; | 466 | ok = false; |
466 | } | 467 | } |
467 | if ( tempString.right(1) =="\n" ) | 468 | if ( tempString.right(1) =="\n" ) |
468 | tempString = tempString.left( tempString.length()-1); | 469 | tempString = tempString.left( tempString.length()-1); |
469 | 470 | ||
470 | templist.append( tempString ); | 471 | templist.append( tempString ); |
471 | } | 472 | } |
472 | ++ccc; | 473 | ++ccc; |
473 | if ( ccc == 2 && loopCount < 25 ) { | 474 | if ( ccc == 2 && loopCount < 25 ) { |
474 | start = 0; | 475 | start = 0; |
475 | bool ok; | 476 | bool ok; |
476 | int newnum = templist[0].toInt( &ok ); | 477 | int newnum = templist[0].toInt( &ok ); |
477 | if ( ok && newnum > 0) { | 478 | if ( ok && newnum > 0) { |
478 | retval = newnum; | 479 | retval = newnum; |
479 | inc->setID( "Sharp_DTM",templist[0] ); | 480 | inc->setID( "Sharp_DTM",templist[0] ); |
480 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); | 481 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); |
481 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 482 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
482 | } | 483 | } |
483 | } | 484 | } |
484 | } | 485 | } |
485 | //qDebug("getNumFromRecord returning : %d ", retval); | 486 | //qDebug("getNumFromRecord returning : %d ", retval); |
486 | return retval; | 487 | return retval; |
487 | } | 488 | } |
488 | bool SharpFormat::save( Calendar *calendar) | 489 | bool SharpFormat::save( Calendar *calendar) |
489 | { | 490 | { |
490 | 491 | ||
491 | QLabel status ( i18n("Processing/adding events ..."), 0 ); | 492 | QLabel status ( i18n("Processing/adding events ..."), 0 ); |
492 | int w = status.sizeHint().width()+20 ; | 493 | int w = status.sizeHint().width()+20 ; |
493 | if ( w < 200 ) w = 200; | 494 | if ( w < 200 ) w = 200; |
494 | int h = status.sizeHint().height()+20 ; | 495 | int h = status.sizeHint().height()+20 ; |
495 | int dw = QApplication::desktop()->width(); | 496 | int dw = QApplication::desktop()->width(); |
496 | int dh = QApplication::desktop()->height(); | 497 | int dh = QApplication::desktop()->height(); |
497 | status.setCaption(i18n("Writing DTM Data") ); | 498 | status.setCaption(i18n("Writing DTM Data") ); |
498 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 499 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
499 | status.show(); | 500 | status.show(); |
500 | status.raise(); | 501 | status.raise(); |
501 | qApp->processEvents(); | 502 | qApp->processEvents(); |
502 | bool debug = DEBUGMODE; | 503 | bool debug = DEBUGMODE; |
503 | QString codec = "utf8"; | 504 | QString codec = "utf8"; |
504 | QString answer; | 505 | QString answer; |
505 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; | 506 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; |
506 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; | 507 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; |
507 | QString command; | 508 | QString command; |
508 | QPtrList<Event> er = calendar->rawEvents(); | 509 | QPtrList<Event> er = calendar->rawEvents(); |
509 | Event* ev = er.first(); | 510 | Event* ev = er.first(); |
510 | QString fileName = "/tmp/kopitempout"; | 511 | QString fileName = "/tmp/kopitempout"; |
511 | int i = 0; | 512 | int i = 0; |
512 | QString changeString = ePrefix; | 513 | QString changeString = ePrefix; |
513 | QString deleteString = ePrefix; | 514 | QString deleteString = ePrefix; |
514 | bool deleteEnt = false; | 515 | bool deleteEnt = false; |
515 | bool changeEnt = false; | 516 | bool changeEnt = false; |
516 | QString message = i18n("Processing event # "); | 517 | QString message = i18n("Processing event # "); |
517 | int procCount = 0; | 518 | int procCount = 0; |
518 | while ( ev ) { | 519 | while ( ev ) { |
519 | //qDebug("i %d ", ++i); | 520 | //qDebug("i %d ", ++i); |
520 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 521 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
521 | status.setText ( message + QString::number ( ++procCount ) ); | 522 | status.setText ( message + QString::number ( ++procCount ) ); |
522 | qApp->processEvents(); | 523 | qApp->processEvents(); |
523 | QString eString = getEventString( ev ); | 524 | QString eString = getEventString( ev ); |
524 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 525 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
525 | // deleting empty strings does not work. | 526 | // deleting empty strings does not work. |
526 | // we write first and x and then delete the record with the x | 527 | // we write first and x and then delete the record with the x |
527 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 528 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
528 | changeString += eString + "\n"; | 529 | changeString += eString + "\n"; |
529 | deleteString += eString + "\n"; | 530 | deleteString += eString + "\n"; |
530 | deleteEnt = true; | 531 | deleteEnt = true; |
531 | changeEnt = true; | 532 | changeEnt = true; |
532 | } | 533 | } |
533 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new | 534 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new |
534 | command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 535 | command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
535 | system ( command.utf8() ); | 536 | system ( command.utf8() ); |
536 | QFile file( fileName ); | 537 | QFile file( fileName ); |
537 | if (!file.open( IO_ReadOnly ) ) { | 538 | if (!file.open( IO_ReadOnly ) ) { |
538 | return false; | 539 | return false; |
539 | 540 | ||
540 | } | 541 | } |
541 | QTextStream ts( &file ); | 542 | QTextStream ts( &file ); |
542 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 543 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
543 | answer = ts.read(); | 544 | answer = ts.read(); |
544 | file.close(); | 545 | file.close(); |
545 | //qDebug("answer \n%s ", answer.latin1()); | 546 | //qDebug("answer \n%s ", answer.latin1()); |
546 | getNumFromRecord( answer, ev ) ; | 547 | getNumFromRecord( answer, ev ) ; |
547 | 548 | ||
548 | } | 549 | } |
549 | else { // change existing | 550 | else { // change existing |
550 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); | 551 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); |
551 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 552 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
552 | changeString += eString + "\n"; | 553 | changeString += eString + "\n"; |
553 | changeEnt = true; | 554 | changeEnt = true; |
554 | 555 | ||
555 | } | 556 | } |
556 | } | 557 | } |
557 | ev = er.next(); | 558 | ev = er.next(); |
558 | } | 559 | } |
559 | status.setText ( i18n("Changing events ...") ); | 560 | status.setText ( i18n("Changing events ...") ); |
560 | qApp->processEvents(); | 561 | qApp->processEvents(); |
561 | //qDebug("changing... "); | 562 | //qDebug("changing... "); |
562 | if ( changeEnt ) { | 563 | if ( changeEnt ) { |
563 | QFile file( fileName ); | 564 | QFile file( fileName ); |
564 | if (!file.open( IO_WriteOnly ) ) { | 565 | if (!file.open( IO_WriteOnly ) ) { |
565 | return false; | 566 | return false; |
566 | 567 | ||
567 | } | 568 | } |
568 | QTextStream ts( &file ); | 569 | QTextStream ts( &file ); |
569 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 570 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
570 | ts << changeString ; | 571 | ts << changeString ; |
571 | file.close(); | 572 | file.close(); |
572 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; | 573 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; |
573 | system ( command.latin1() ); | 574 | system ( command.latin1() ); |
574 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 575 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
575 | 576 | ||
576 | } | 577 | } |
577 | status.setText ( i18n("Deleting events ...") ); | 578 | status.setText ( i18n("Deleting events ...") ); |
578 | qApp->processEvents(); | 579 | qApp->processEvents(); |
579 | //qDebug("deleting... "); | 580 | //qDebug("deleting... "); |
580 | if ( deleteEnt ) { | 581 | if ( deleteEnt ) { |
581 | QFile file( fileName ); | 582 | QFile file( fileName ); |
582 | if (!file.open( IO_WriteOnly ) ) { | 583 | if (!file.open( IO_WriteOnly ) ) { |
583 | return false; | 584 | return false; |
584 | 585 | ||
585 | } | 586 | } |
586 | QTextStream ts( &file ); | 587 | QTextStream ts( &file ); |
587 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 588 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
588 | ts << deleteString; | 589 | ts << deleteString; |
589 | file.close(); | 590 | file.close(); |
590 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; | 591 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; |
591 | system ( command.latin1() ); | 592 | system ( command.latin1() ); |
592 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 593 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
593 | } | 594 | } |
594 | 595 | ||
595 | 596 | ||
596 | changeString = tPrefix; | 597 | changeString = tPrefix; |
597 | deleteString = tPrefix; | 598 | deleteString = tPrefix; |
598 | status.setText ( i18n("Processing todos ...") ); | 599 | status.setText ( i18n("Processing todos ...") ); |
599 | qApp->processEvents(); | 600 | qApp->processEvents(); |
600 | QPtrList<Todo> tl = calendar->rawTodos(); | 601 | QPtrList<Todo> tl = calendar->rawTodos(); |
601 | Todo* to = tl.first(); | 602 | Todo* to = tl.first(); |
602 | i = 0; | 603 | i = 0; |
603 | message = i18n("Processing todo # "); | 604 | message = i18n("Processing todo # "); |
604 | procCount = 0; | 605 | procCount = 0; |
605 | while ( to ) { | 606 | while ( to ) { |
606 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 607 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
607 | status.setText ( message + QString::number ( ++procCount ) ); | 608 | status.setText ( message + QString::number ( ++procCount ) ); |
608 | qApp->processEvents(); | 609 | qApp->processEvents(); |
609 | QString eString = getTodoString( to ); | 610 | QString eString = getTodoString( to ); |
610 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 611 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
611 | // deleting empty strings does not work. | 612 | // deleting empty strings does not work. |
612 | // we write first and x and then delete the record with the x | 613 | // we write first and x and then delete the record with the x |
613 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 614 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
614 | changeString += eString + "\n"; | 615 | changeString += eString + "\n"; |
615 | deleteString += eString + "\n"; | 616 | deleteString += eString + "\n"; |
616 | deleteEnt = true; | 617 | deleteEnt = true; |
617 | changeEnt = true; | 618 | changeEnt = true; |
618 | } | 619 | } |
619 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new | 620 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new |
620 | command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; | 621 | command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; |
621 | system ( command.utf8() ); | 622 | system ( command.utf8() ); |
622 | QFile file( fileName ); | 623 | QFile file( fileName ); |
623 | if (!file.open( IO_ReadOnly ) ) { | 624 | if (!file.open( IO_ReadOnly ) ) { |
624 | return false; | 625 | return false; |
625 | 626 | ||
626 | } | 627 | } |
627 | QTextStream ts( &file ); | 628 | QTextStream ts( &file ); |
628 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 629 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
629 | answer = ts.read(); | 630 | answer = ts.read(); |
630 | file.close(); | 631 | file.close(); |
631 | //qDebug("answer \n%s ", answer.latin1()); | 632 | //qDebug("answer \n%s ", answer.latin1()); |
632 | getNumFromRecord( answer, to ) ; | 633 | getNumFromRecord( answer, to ) ; |
633 | 634 | ||
634 | } | 635 | } |
635 | else { // change existing | 636 | else { // change existing |
636 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); | 637 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); |
637 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 638 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
638 | changeString += eString + "\n"; | 639 | changeString += eString + "\n"; |
639 | changeEnt = true; | 640 | changeEnt = true; |
640 | 641 | ||
641 | } | 642 | } |
642 | } | 643 | } |
643 | 644 | ||
644 | to = tl.next(); | 645 | to = tl.next(); |
645 | } | 646 | } |
646 | status.setText ( i18n("Changing todos ...") ); | 647 | status.setText ( i18n("Changing todos ...") ); |
647 | qApp->processEvents(); | 648 | qApp->processEvents(); |
648 | //qDebug("changing... "); | 649 | //qDebug("changing... "); |
649 | if ( changeEnt ) { | 650 | if ( changeEnt ) { |
650 | QFile file( fileName ); | 651 | QFile file( fileName ); |
651 | if (!file.open( IO_WriteOnly ) ) { | 652 | if (!file.open( IO_WriteOnly ) ) { |
652 | return false; | 653 | return false; |
653 | 654 | ||
654 | } | 655 | } |
655 | QTextStream ts( &file ); | 656 | QTextStream ts( &file ); |
656 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 657 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
657 | ts << changeString ; | 658 | ts << changeString ; |
658 | file.close(); | 659 | file.close(); |
659 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; | 660 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; |
660 | system ( command.latin1() ); | 661 | system ( command.latin1() ); |
661 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 662 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
662 | 663 | ||
663 | } | 664 | } |
664 | status.setText ( i18n("Deleting todos ...") ); | 665 | status.setText ( i18n("Deleting todos ...") ); |
665 | qApp->processEvents(); | 666 | qApp->processEvents(); |
666 | //qDebug("deleting... "); | 667 | //qDebug("deleting... "); |
667 | if ( deleteEnt ) { | 668 | if ( deleteEnt ) { |
668 | QFile file( fileName ); | 669 | QFile file( fileName ); |
669 | if (!file.open( IO_WriteOnly ) ) { | 670 | if (!file.open( IO_WriteOnly ) ) { |
670 | return false; | 671 | return false; |
671 | 672 | ||
672 | } | 673 | } |
673 | QTextStream ts( &file ); | 674 | QTextStream ts( &file ); |
674 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 675 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
675 | ts << deleteString; | 676 | ts << deleteString; |
676 | file.close(); | 677 | file.close(); |
677 | command = "db2file todo -d -c " + codec+ " < "+ fileName; | 678 | command = "db2file todo -d -c " + codec+ " < "+ fileName; |
678 | system ( command.latin1() ); | 679 | system ( command.latin1() ); |
679 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 680 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
680 | } | 681 | } |
681 | 682 | ||
682 | return true; | 683 | return true; |
683 | } | 684 | } |
684 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) | 685 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) |
685 | { | 686 | { |
686 | QString datestr; | 687 | QString datestr; |
687 | QString timestr; | 688 | QString timestr; |
688 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 689 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
689 | QDateTime dt; | 690 | QDateTime dt; |
690 | if (useTZ) | 691 | if (useTZ) |
691 | dt = dti.addSecs ( -(offset*60)); | 692 | dt = dti.addSecs ( -(offset*60)); |
692 | else | 693 | else |
693 | dt = dti; | 694 | dt = dti; |
694 | if(dt.date().isValid()){ | 695 | if(dt.date().isValid()){ |
695 | const QDate& date = dt.date(); | 696 | const QDate& date = dt.date(); |
696 | datestr.sprintf("%04d%02d%02d", | 697 | datestr.sprintf("%04d%02d%02d", |
697 | date.year(), date.month(), date.day()); | 698 | date.year(), date.month(), date.day()); |
698 | } | 699 | } |
699 | if(dt.time().isValid()){ | 700 | if(dt.time().isValid()){ |
700 | const QTime& time = dt.time(); | 701 | const QTime& time = dt.time(); |
701 | timestr.sprintf("T%02d%02d%02d", | 702 | timestr.sprintf("T%02d%02d%02d", |
702 | time.hour(), time.minute(), time.second()); | 703 | time.hour(), time.minute(), time.second()); |
703 | } | 704 | } |
704 | return datestr + timestr; | 705 | return datestr + timestr; |
705 | } | 706 | } |
706 | QString SharpFormat::getEventString( Event* event ) | 707 | QString SharpFormat::getEventString( Event* event ) |
707 | { | 708 | { |
708 | QStringList list; | 709 | QStringList list; |
709 | list.append( event->getID("Sharp_DTM") ); | 710 | list.append( event->getID("Sharp_DTM") ); |
710 | list.append( event->categories().join(",") ); | 711 | list.append( event->categories().join(",") ); |
711 | if ( !event->summary().isEmpty() ) | 712 | if ( !event->summary().isEmpty() ) |
712 | list.append( event->summary() ); | 713 | list.append( event->summary() ); |
713 | else | 714 | else |
714 | list.append("" ); | 715 | list.append("" ); |
715 | if ( !event->location().isEmpty() ) | 716 | if ( !event->location().isEmpty() ) |
716 | list.append( event->location() ); | 717 | list.append( event->location() ); |
717 | else | 718 | else |
718 | list.append("" ); | 719 | list.append("" ); |
719 | if ( !event->description().isEmpty() ) | 720 | if ( !event->description().isEmpty() ) |
720 | list.append( event->description() ); | 721 | list.append( event->description() ); |
721 | else | 722 | else |
722 | list.append( "" ); | 723 | list.append( "" ); |
723 | if ( event->doesFloat () ) { | 724 | if ( event->doesFloat () ) { |
724 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | 725 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); |
725 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | 726 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 |
726 | list.append( "1" ); | 727 | list.append( "1" ); |
727 | 728 | ||
728 | } | 729 | } |
729 | else { | 730 | else { |
730 | list.append( dtToString( event->dtStart()) ); | 731 | list.append( dtToString( event->dtStart()) ); |
731 | list.append( dtToString( event->dtEnd()) ); //6 | 732 | list.append( dtToString( event->dtEnd()) ); //6 |
732 | list.append( "0" ); | 733 | list.append( "0" ); |
733 | } | 734 | } |
734 | bool noAlarm = true; | 735 | bool noAlarm = true; |
735 | if ( event->alarms().count() > 0 ) { | 736 | if ( event->alarms().count() > 0 ) { |
736 | Alarm * al = event->alarms().first(); | 737 | Alarm * al = event->alarms().first(); |
737 | if ( al->enabled() ) { | 738 | if ( al->enabled() ) { |
738 | noAlarm = false; | 739 | noAlarm = false; |
739 | list.append( "0" ); // yes, 0 == alarm | 740 | list.append( "0" ); // yes, 0 == alarm |
740 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); | 741 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); |
741 | if ( al->type() == Alarm::Audio ) | 742 | if ( al->type() == Alarm::Audio ) |
742 | list.append( "1" ); // type audio | 743 | list.append( "1" ); // type audio |
743 | else | 744 | else |
744 | list.append( "0" ); // type silent | 745 | list.append( "0" ); // type silent |
745 | } | 746 | } |
746 | } | 747 | } |
747 | if ( noAlarm ) { | 748 | if ( noAlarm ) { |
748 | list.append( "1" ); // yes, 1 == no alarm | 749 | list.append( "1" ); // yes, 1 == no alarm |
749 | list.append( "0" ); // no alarm offset | 750 | list.append( "0" ); // no alarm offset |
750 | list.append( "1" ); // type | 751 | list.append( "1" ); // type |
751 | } | 752 | } |
752 | // next is: 11 | 753 | // next is: 11 |
753 | // next is: 11-16 are recurrence | 754 | // next is: 11-16 are recurrence |
754 | Recurrence* rec = event->recurrence(); | 755 | Recurrence* rec = event->recurrence(); |
755 | 756 | ||
756 | bool writeEndDate = false; | 757 | bool writeEndDate = false; |
757 | switch ( rec->doesRecur() ) | 758 | switch ( rec->doesRecur() ) |
758 | { | 759 | { |
759 | case Recurrence::rDaily: // 0 | 760 | case Recurrence::rDaily: // 0 |
760 | list.append( "0" ); | 761 | list.append( "0" ); |
761 | list.append( QString::number( rec->frequency() ));//12 | 762 | list.append( QString::number( rec->frequency() ));//12 |
762 | list.append( "0" ); | 763 | list.append( "0" ); |
763 | list.append( "0" ); | 764 | list.append( "0" ); |
764 | writeEndDate = true; | 765 | writeEndDate = true; |
765 | break; | 766 | break; |
766 | case Recurrence::rWeekly:// 1 | 767 | case Recurrence::rWeekly:// 1 |
767 | list.append( "1" ); | 768 | list.append( "1" ); |
768 | list.append( QString::number( rec->frequency()) );//12 | 769 | list.append( QString::number( rec->frequency()) );//12 |
769 | list.append( "0" ); | 770 | list.append( "0" ); |
770 | { | 771 | { |
771 | int days = 0; | 772 | int days = 0; |
772 | QBitArray weekDays = rec->days(); | 773 | QBitArray weekDays = rec->days(); |
773 | int i; | 774 | int i; |
774 | for( i = 1; i <= 7; ++i ) { | 775 | for( i = 1; i <= 7; ++i ) { |
775 | if ( weekDays[i-1] ) { | 776 | if ( weekDays[i-1] ) { |
776 | days += 1 << (i-1); | 777 | days += 1 << (i-1); |
777 | } | 778 | } |
778 | } | 779 | } |
779 | list.append( QString::number( days ) ); | 780 | list.append( QString::number( days ) ); |
780 | } | 781 | } |
781 | //pending weekdays | 782 | //pending weekdays |
782 | writeEndDate = true; | 783 | writeEndDate = true; |
783 | 784 | ||
784 | break; | 785 | break; |
785 | case Recurrence::rMonthlyPos:// 2 | 786 | case Recurrence::rMonthlyPos:// 2 |
786 | list.append( "2" ); | 787 | list.append( "2" ); |
787 | list.append( QString::number( rec->frequency()) );//12 | 788 | list.append( QString::number( rec->frequency()) );//12 |
788 | 789 | ||
789 | writeEndDate = true; | 790 | writeEndDate = true; |
790 | { | 791 | { |
791 | int count = 1; | 792 | int count = 1; |
792 | QPtrList<Recurrence::rMonthPos> rmp; | 793 | QPtrList<Recurrence::rMonthPos> rmp; |
793 | rmp = rec->monthPositions(); | 794 | rmp = rec->monthPositions(); |
794 | if ( rmp.first()->negative ) | 795 | if ( rmp.first()->negative ) |
795 | count = 5 - rmp.first()->rPos - 1; | 796 | count = 5 - rmp.first()->rPos - 1; |
796 | else | 797 | else |
797 | count = rmp.first()->rPos - 1; | 798 | count = rmp.first()->rPos - 1; |
798 | list.append( QString::number( count ) ); | 799 | list.append( QString::number( count ) ); |
799 | 800 | ||
800 | } | 801 | } |
801 | 802 | ||
802 | list.append( "0" ); | 803 | list.append( "0" ); |
803 | break; | 804 | break; |
804 | case Recurrence::rMonthlyDay:// 3 | 805 | case Recurrence::rMonthlyDay:// 3 |
805 | list.append( "3" ); | 806 | list.append( "3" ); |
806 | list.append( QString::number( rec->frequency()) );//12 | 807 | list.append( QString::number( rec->frequency()) );//12 |
807 | list.append( "0" ); | 808 | list.append( "0" ); |
808 | list.append( "0" ); | 809 | list.append( "0" ); |
809 | writeEndDate = true; | 810 | writeEndDate = true; |
810 | break; | 811 | break; |
811 | case Recurrence::rYearlyMonth://4 | 812 | case Recurrence::rYearlyMonth://4 |
812 | list.append( "4" ); | 813 | list.append( "4" ); |
813 | list.append( QString::number( rec->frequency()) );//12 | 814 | list.append( QString::number( rec->frequency()) );//12 |
814 | list.append( "0" ); | 815 | list.append( "0" ); |
815 | list.append( "0" ); | 816 | list.append( "0" ); |
816 | writeEndDate = true; | 817 | writeEndDate = true; |
817 | break; | 818 | break; |
818 | 819 | ||
819 | default: | 820 | default: |
820 | list.append( "255" ); | 821 | list.append( "255" ); |
821 | list.append( QString() ); | 822 | list.append( QString() ); |
822 | list.append( "0" ); | 823 | list.append( "0" ); |
823 | list.append( QString() ); | 824 | list.append( QString() ); |
824 | list.append( "0" ); | 825 | list.append( "0" ); |
825 | list.append( "20991231T000000" ); | 826 | list.append( "20991231T000000" ); |
826 | break; | 827 | break; |
827 | } | 828 | } |
828 | if ( writeEndDate ) { | 829 | if ( writeEndDate ) { |
829 | 830 | ||
830 | if ( rec->endDate().isValid() ) { // 15 + 16 | 831 | if ( rec->endDate().isValid() ) { // 15 + 16 |
831 | list.append( "1" ); | 832 | list.append( "1" ); |
832 | list.append( dtToString( rec->endDate()) ); | 833 | list.append( dtToString( rec->endDate()) ); |
833 | } else { | 834 | } else { |
834 | list.append( "0" ); | 835 | list.append( "0" ); |
835 | list.append( "20991231T000000" ); | 836 | list.append( "20991231T000000" ); |
836 | } | 837 | } |
837 | 838 | ||
838 | } | 839 | } |
839 | if ( event->doesFloat () ) { | 840 | if ( event->doesFloat () ) { |
840 | list.append( dtToString( event->dtStart(), false ).left( 8 )); | 841 | list.append( dtToString( event->dtStart(), false ).left( 8 )); |
841 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 | 842 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 |
842 | 843 | ||
843 | } | 844 | } |
844 | else { | 845 | else { |
845 | list.append( QString() ); | 846 | list.append( QString() ); |
846 | list.append( QString() ); | 847 | list.append( QString() ); |
847 | 848 | ||
848 | } | 849 | } |
849 | if (event->dtStart().date() == event->dtEnd().date() ) | 850 | if (event->dtStart().date() == event->dtEnd().date() ) |
850 | list.append( "0" ); | 851 | list.append( "0" ); |
851 | else | 852 | else |
852 | list.append( "1" ); | 853 | list.append( "1" ); |
853 | 854 | ||
854 | 855 | ||
855 | for(QStringList::Iterator it=list.begin(); | 856 | for(QStringList::Iterator it=list.begin(); |
856 | it!=list.end(); ++it){ | 857 | it!=list.end(); ++it){ |
857 | QString& s = (*it); | 858 | QString& s = (*it); |
858 | s.replace(QRegExp("\""), "\"\""); | 859 | s.replace(QRegExp("\""), "\"\""); |
859 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | 860 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ |
860 | s.prepend('\"'); | 861 | s.prepend('\"'); |
861 | s.append('\"'); | 862 | s.append('\"'); |
862 | } else if(s.isEmpty() && !s.isNull()){ | 863 | } else if(s.isEmpty() && !s.isNull()){ |
863 | s = "\"\""; | 864 | s = "\"\""; |
864 | } | 865 | } |
865 | } | 866 | } |
866 | return list.join(","); | 867 | return list.join(","); |
867 | 868 | ||
868 | 869 | ||
869 | } | 870 | } |
870 | QString SharpFormat::getTodoString( Todo* todo ) | 871 | QString SharpFormat::getTodoString( Todo* todo ) |
871 | { | 872 | { |
872 | QStringList list; | 873 | QStringList list; |
873 | list.append( todo->getID("Sharp_DTM") ); | 874 | list.append( todo->getID("Sharp_DTM") ); |
874 | list.append( todo->categories().join(",") ); | 875 | list.append( todo->categories().join(",") ); |
875 | 876 | ||
876 | if ( todo->hasStartDate() ) { | 877 | if ( todo->hasStartDate() ) { |
877 | list.append( dtToString( todo->dtStart()) ); | 878 | list.append( dtToString( todo->dtStart()) ); |
878 | } else | 879 | } else |
879 | list.append( QString() ); | 880 | list.append( QString() ); |
880 | 881 | ||
881 | if ( todo->hasDueDate() ) { | 882 | if ( todo->hasDueDate() ) { |
882 | QTime tim; | 883 | QTime tim; |
883 | if ( todo->doesFloat()) { | 884 | if ( todo->doesFloat()) { |
884 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; | 885 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; |
885 | } else { | 886 | } else { |
886 | list.append( dtToString(todo->dtDue() ) ); | 887 | list.append( dtToString(todo->dtDue() ) ); |
887 | } | 888 | } |
888 | } else | 889 | } else |
889 | list.append( QString() ); | 890 | list.append( QString() ); |
890 | 891 | ||
891 | if ( todo->isCompleted() ) { | 892 | if ( todo->isCompleted() ) { |
892 | list.append( dtToString( todo->completed()) ); | 893 | list.append( dtToString( todo->completed()) ); |
893 | list.append( "0" ); // yes 0 == completed | 894 | list.append( "0" ); // yes 0 == completed |
894 | } else { | 895 | } else { |
895 | list.append( dtToString( todo->completed()) ); | 896 | list.append( dtToString( todo->completed()) ); |
896 | list.append( "1" ); | 897 | list.append( "1" ); |
897 | } | 898 | } |
898 | list.append( QString::number( todo->priority() )); | 899 | list.append( QString::number( todo->priority() )); |
899 | if( ! todo->summary().isEmpty() ) | 900 | if( ! todo->summary().isEmpty() ) |
900 | list.append( todo->summary() ); | 901 | list.append( todo->summary() ); |
901 | else | 902 | else |
902 | list.append( "" ); | 903 | list.append( "" ); |
903 | if (! todo->description().isEmpty() ) | 904 | if (! todo->description().isEmpty() ) |
904 | list.append( todo->description() ); | 905 | list.append( todo->description() ); |
905 | else | 906 | else |
906 | list.append( "" ); | 907 | list.append( "" ); |
907 | for(QStringList::Iterator it=list.begin(); | 908 | for(QStringList::Iterator it=list.begin(); |
908 | it!=list.end(); ++it){ | 909 | it!=list.end(); ++it){ |
909 | QString& s = (*it); | 910 | QString& s = (*it); |
910 | s.replace(QRegExp("\""), "\"\""); | 911 | s.replace(QRegExp("\""), "\"\""); |
911 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | 912 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ |
912 | s.prepend('\"'); | 913 | s.prepend('\"'); |
913 | s.append('\"'); | 914 | s.append('\"'); |
914 | } else if(s.isEmpty() && !s.isNull()){ | 915 | } else if(s.isEmpty() && !s.isNull()){ |
915 | s = "\"\""; | 916 | s = "\"\""; |
916 | } | 917 | } |
917 | } | 918 | } |
918 | return list.join(","); | 919 | return list.join(","); |
919 | } | 920 | } |
920 | QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) | 921 | QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) |
921 | { | 922 | { |
922 | //qDebug("start %d ", start); | 923 | //qDebug("start %d ", start); |
923 | 924 | ||
924 | QString retval =""; | 925 | QString retval =""; |
925 | if ( text.at(start) == '"' ) { | 926 | if ( text.at(start) == '"' ) { |
926 | if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { | 927 | if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { |
927 | start = start +2; | 928 | start = start +2; |
928 | if ( text.mid( start,1) == "," ) { | 929 | if ( text.mid( start,1) == "," ) { |
929 | start += 1; | 930 | start += 1; |
930 | } | 931 | } |
931 | retval = ""; | 932 | retval = ""; |
932 | if ( text.mid( start,1) == "\n" ) { | 933 | if ( text.mid( start,1) == "\n" ) { |
933 | start += 1; | 934 | start += 1; |
934 | ok = false; | 935 | ok = false; |
935 | } | 936 | } |
936 | return retval; | 937 | return retval; |
937 | } | 938 | } |
938 | int hk = start+1; | 939 | int hk = start+1; |
939 | hk = text.find ('"',hk); | 940 | hk = text.find ('"',hk); |
940 | while ( text.at(hk+1) == '"' ) | 941 | while ( text.at(hk+1) == '"' ) |
941 | hk = text.find ('"',hk+2); | 942 | hk = text.find ('"',hk+2); |
942 | retval = text.mid( start+1, hk-start-1); | 943 | retval = text.mid( start+1, hk-start-1); |
943 | start = hk+1; | 944 | start = hk+1; |
944 | retval.replace( QRegExp("\"\""), "\""); | 945 | retval.replace( QRegExp("\"\""), "\""); |
945 | if ( text.mid( start,1) == "," ) { | 946 | if ( text.mid( start,1) == "," ) { |
946 | start += 1; | 947 | start += 1; |
947 | } | 948 | } |
948 | if ( text.mid( start,1) == "\n" ) { | 949 | if ( text.mid( start,1) == "\n" ) { |
949 | start += 1; | 950 | start += 1; |
950 | ok = false; | 951 | ok = false; |
951 | } | 952 | } |
952 | //qDebug("retval***%s*** ",retval.latin1() ); | 953 | //qDebug("retval***%s*** ",retval.latin1() ); |
953 | return retval; | 954 | return retval; |
954 | 955 | ||
955 | } else { | 956 | } else { |
956 | int nl = text.find ("\n",start); | 957 | int nl = text.find ("\n",start); |
957 | int kom = text.find (',',start); | 958 | int kom = text.find (',',start); |
958 | if ( kom < nl ) { | 959 | if ( kom < nl ) { |
959 | // qDebug("kom < nl %d ", kom); | 960 | // qDebug("kom < nl %d ", kom); |
960 | retval = text.mid(start, kom-start); | 961 | retval = text.mid(start, kom-start); |
961 | start = kom+1; | 962 | start = kom+1; |
962 | return retval; | 963 | return retval; |
963 | } else { | 964 | } else { |
964 | if ( nl == kom ) { | 965 | if ( nl == kom ) { |
965 | // qDebug(" nl == kom "); | 966 | // qDebug(" nl == kom "); |
966 | start = 0; | 967 | start = 0; |
967 | ok = false; | 968 | ok = false; |
968 | return "0"; | 969 | return "0"; |
969 | } | 970 | } |
970 | // qDebug(" nl < kom ", nl); | 971 | // qDebug(" nl < kom ", nl); |
971 | retval = text.mid( start, nl-start); | 972 | retval = text.mid( start, nl-start); |
972 | ok = false; | 973 | ok = false; |
973 | start = nl+1; | 974 | start = nl+1; |
974 | return retval; | 975 | return retval; |
975 | } | 976 | } |
976 | } | 977 | } |
977 | } | 978 | } |
978 | bool SharpFormat::fromString( Calendar *calendar, const QString & text) | 979 | bool SharpFormat::fromString( Calendar *calendar, const QString & text) |
979 | { | 980 | { |
980 | return false; | 981 | return false; |
981 | } | 982 | } |
982 | bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) | 983 | bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) |
983 | { | 984 | { |
984 | // qDebug("test %s ", text.latin1()); | 985 | // qDebug("test %s ", text.latin1()); |
985 | QStringList templist; | 986 | QStringList templist; |
986 | QString tempString; | 987 | QString tempString; |
987 | int start = 0; | 988 | int start = 0; |
988 | int len = text.length(); | 989 | int len = text.length(); |
989 | int end = text.find ("\n",start)+1; | 990 | int end = text.find ("\n",start)+1; |
990 | bool ok = true; | 991 | bool ok = true; |
991 | start = end; | 992 | start = end; |
992 | SharpParser handler( calendar ); | 993 | SharpParser handler( calendar ); |
993 | handler.setCategoriesList( mCategories ); | 994 | handler.setCategoriesList( mCategories ); |
994 | while ( start > 0 ) { | 995 | while ( start > 0 ) { |
995 | templist.clear(); | 996 | templist.clear(); |
996 | ok = true; | 997 | ok = true; |
997 | while ( ok ) { | 998 | while ( ok ) { |
998 | tempString = getPart( text, ok, start ); | 999 | tempString = getPart( text, ok, start ); |
999 | if ( start >= len || start == 0 ) { | 1000 | if ( start >= len || start == 0 ) { |
1000 | start = 0; | 1001 | start = 0; |
1001 | ok = false; | 1002 | ok = false; |
1002 | } | 1003 | } |
1003 | if ( tempString.right(1) =="\n" ) | 1004 | if ( tempString.right(1) =="\n" ) |
1004 | tempString = tempString.left( tempString.length()-1); | 1005 | tempString = tempString.left( tempString.length()-1); |
1005 | //if ( ok ) | 1006 | //if ( ok ) |
1006 | templist.append( tempString ); | 1007 | templist.append( tempString ); |
1007 | //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); | 1008 | //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); |
1008 | } | 1009 | } |
1009 | handler.startElement( existingCalendar, templist, type ); | 1010 | handler.startElement( existingCalendar, templist, type ); |
1010 | } | 1011 | } |
1011 | 1012 | ||
1012 | return false; | 1013 | return false; |
1013 | } | 1014 | } |
1014 | 1015 | ||
1015 | QString SharpFormat::toString( Calendar * ) | 1016 | QString SharpFormat::toString( Calendar * ) |
1016 | { | 1017 | { |
1017 | return QString::null; | 1018 | return QString::null; |
1018 | } | 1019 | } |