author | zautrix <zautrix> | 2005-07-30 16:17:54 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-30 16:17:54 (UTC) |
commit | 6a32c95e5f0a36cd9a681a3f3302bec6e83acce5 (patch) (unidiff) | |
tree | 3f8da30f9fe779ae697c97e16eb4dd6f47c3ed00 /libkcal | |
parent | 9ca2cd947f22d33543e065f54c6487e86d80befa (diff) | |
download | kdepimpi-6a32c95e5f0a36cd9a681a3f3302bec6e83acce5.zip kdepimpi-6a32c95e5f0a36cd9a681a3f3302bec6e83acce5.tar.gz kdepimpi-6a32c95e5f0a36cd9a681a3f3302bec6e83acce5.tar.bz2 |
fixx
-rw-r--r-- | libkcal/attachment.cpp | 38 | ||||
-rw-r--r-- | libkcal/attachment.h | 71 | ||||
-rw-r--r-- | libkcal/icalformatimpl.cpp | 4 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 12 |
4 files changed, 96 insertions, 29 deletions
diff --git a/libkcal/attachment.cpp b/libkcal/attachment.cpp index 1ead923..520ac95 100644 --- a/libkcal/attachment.cpp +++ b/libkcal/attachment.cpp | |||
@@ -1,86 +1,120 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | |||
3 | Copyright (c) 2002 Michael Brade <brade@kde.org> | 4 | Copyright (c) 2002 Michael Brade <brade@kde.org> |
4 | 5 | ||
5 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
8 | 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. |
9 | 10 | ||
10 | 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, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 14 | Library General Public License for more details. |
14 | 15 | ||
15 | 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 |
16 | 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 |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
19 | */ | 20 | */ |
20 | 21 | ||
21 | #include "attachment.h" | 22 | #include "attachment.h" |
22 | 23 | ||
23 | using namespace KCal; | 24 | using namespace KCal; |
24 | 25 | ||
26 | Attachment::Attachment( const Attachment &attachment) | ||
27 | { | ||
28 | mMimeType = attachment.mMimeType; | ||
29 | mData = attachment.mData; | ||
30 | mBinary = attachment.mBinary; | ||
31 | mShowInline = attachment.mShowInline; | ||
32 | mLabel = attachment.mLabel; | ||
33 | } | ||
34 | |||
25 | Attachment::Attachment(const QString& uri, const QString& mime) | 35 | Attachment::Attachment(const QString& uri, const QString& mime) |
26 | { | 36 | { |
27 | mMimeType = mime; | 37 | mMimeType = mime; |
28 | mData = uri; | 38 | mData = uri; |
29 | mBinary = false; | 39 | mBinary = false; |
40 | mShowInline = false; | ||
41 | mLabel = QString::null; | ||
30 | } | 42 | } |
31 | 43 | ||
32 | Attachment::Attachment(const char *base64, const QString& mime) | 44 | Attachment::Attachment(const char *base64, const QString& mime) |
33 | { | 45 | { |
34 | mMimeType = mime; | 46 | mMimeType = mime; |
35 | mData = QString::fromUtf8(base64); | 47 | mData = QString::fromUtf8(base64); |
36 | mBinary = true; | 48 | mBinary = true; |
49 | mShowInline = false; | ||
50 | mLabel = QString::null; | ||
37 | } | 51 | } |
38 | 52 | ||
39 | bool Attachment::isURI() const | 53 | bool Attachment::isUri() const |
40 | { | 54 | { |
41 | return !mBinary; | 55 | return !mBinary; |
42 | } | 56 | } |
43 | 57 | ||
44 | QString Attachment::uri() const | 58 | QString Attachment::uri() const |
45 | { | 59 | { |
46 | if (!mBinary) | 60 | if (!mBinary) |
47 | return mData; | 61 | return mData; |
48 | else | 62 | else |
49 | return QString::null; | 63 | return QString::null; |
50 | } | 64 | } |
51 | 65 | ||
52 | void Attachment::setURI(const QString& uri) | 66 | void Attachment::setUri(const QString& uri) |
53 | { | 67 | { |
54 | mData = uri; | 68 | mData = uri; |
55 | mBinary = false; | 69 | mBinary = false; |
56 | } | 70 | } |
57 | 71 | ||
58 | bool Attachment::isBinary() const | 72 | bool Attachment::isBinary() const |
59 | { | 73 | { |
60 | return mBinary; | 74 | return mBinary; |
61 | } | 75 | } |
62 | 76 | ||
63 | char *Attachment::data() const | 77 | char *Attachment::data() const |
64 | { | 78 | { |
65 | if (mBinary) | 79 | if (mBinary) |
66 | return mData.utf8().data(); | 80 | return mData.utf8().data(); |
67 | else | 81 | else |
68 | return 0; | 82 | return 0; |
69 | } | 83 | } |
70 | 84 | ||
71 | void Attachment::setData(const char *base64) | 85 | void Attachment::setData(const char *base64) |
72 | { | 86 | { |
73 | mData = QString::fromUtf8(base64); | 87 | mData = QString::fromUtf8(base64); |
74 | mBinary = true; | 88 | mBinary = true; |
75 | } | 89 | } |
76 | 90 | ||
77 | QString Attachment::mimeType() const | 91 | QString Attachment::mimeType() const |
78 | { | 92 | { |
79 | return mMimeType; | 93 | return mMimeType; |
80 | } | 94 | } |
81 | 95 | ||
82 | void Attachment::setMimeType(const QString& mime) | 96 | void Attachment::setMimeType(const QString& mime) |
83 | { | 97 | { |
84 | mMimeType = mime; | 98 | mMimeType = mime; |
85 | } | 99 | } |
86 | 100 | ||
101 | bool Attachment::showInline() const | ||
102 | { | ||
103 | return mShowInline; | ||
104 | } | ||
105 | |||
106 | void Attachment::setShowInline( bool showinline ) | ||
107 | { | ||
108 | mShowInline = showinline; | ||
109 | } | ||
110 | |||
111 | QString Attachment::label() const | ||
112 | { | ||
113 | return mLabel; | ||
114 | } | ||
115 | |||
116 | void Attachment::setLabel( const QString& label ) | ||
117 | { | ||
118 | mLabel = label; | ||
119 | } | ||
120 | |||
diff --git a/libkcal/attachment.h b/libkcal/attachment.h index cdf2458..5301420 100644 --- a/libkcal/attachment.h +++ b/libkcal/attachment.h | |||
@@ -1,69 +1,94 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | |||
3 | Copyright (c) 2002 Michael Brade <brade@kde.org> | 4 | Copyright (c) 2002 Michael Brade <brade@kde.org> |
4 | 5 | ||
5 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
8 | 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. |
9 | 10 | ||
10 | 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, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 14 | Library General Public License for more details. |
14 | 15 | ||
15 | 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 |
16 | 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 |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
19 | */ | 20 | */ |
21 | #ifndef KCAL_ATTACHMENT_H | ||
22 | #define KCAL_ATTACHMENT_H | ||
20 | 23 | ||
21 | #ifndef _ATTACHMENT_H | ||
22 | #define _ATTACHMENT_H | ||
23 | 24 | ||
24 | #include <qstring.h> | ||
25 | 25 | ||
26 | #include <qstring.h> | ||
26 | 27 | ||
27 | namespace KCal { | 28 | namespace KCal { |
28 | 29 | ||
29 | /** | 30 | /** |
30 | * This class represents information related to an attachment. | 31 | This class represents information related to an attachment. |
31 | */ | 32 | */ |
32 | class Attachment | 33 | class Attachment |
33 | { | 34 | { |
34 | public: | 35 | public: |
36 | |||
35 | /** | 37 | /** |
36 | * Create a Reference to some URI. | 38 | Create a Reference to some URI by copying an existing Attachment. |
37 | * @param uri the uri this attachment refers to | 39 | |
38 | * @param mime the mime type of the resource being linked to | 40 | @param attachment the attachment to be duplicated |
39 | */ | 41 | */ |
40 | Attachment(const QString& uri, const QString& mime = QString::null); | 42 | Attachment( const Attachment &attachment ); |
41 | 43 | ||
42 | /** | 44 | /** |
43 | * Create a binary attachment. | 45 | Create a Reference to some URI. |
44 | * @param base64 the attachment in base64 format | 46 | |
45 | * @param mime the mime type of the attachment | 47 | @param uri the uri this attachment refers to |
46 | */ | 48 | @param mime the mime type of the resource being linked to |
47 | Attachment(const char *base64, const QString& mime = QString::null); | 49 | */ |
48 | 50 | Attachment( const QString &uri, const QString &mime = QString::null ); | |
49 | /* The VALUE parameter in Cal */ | 51 | |
50 | bool isURI() const; | 52 | /** |
53 | Create a binary attachment. | ||
54 | |||
55 | @param base64 the attachment in base64 format | ||
56 | @param mime the mime type of the attachment | ||
57 | */ | ||
58 | Attachment( const char *base64, const QString &mime = QString::null ); | ||
59 | |||
60 | /* The VALUE parameter in iCal */ | ||
61 | bool isUri() const; | ||
51 | QString uri() const; | 62 | QString uri() const; |
52 | void setURI(const QString& uri); | 63 | void setUri( const QString &uri ); |
53 | 64 | ||
54 | bool isBinary() const; | 65 | bool isBinary() const; |
55 | char *data() const; | 66 | char *data() const; |
56 | void setData(const char *base64); | 67 | void setData( const char *base64 ); |
57 | 68 | ||
58 | /* The optional FMTTYPE parameter in iCal */ | 69 | /* The optional FMTTYPE parameter in iCal */ |
59 | QString mimeType() const; | 70 | QString mimeType() const; |
60 | void setMimeType(const QString& mime); | 71 | void setMimeType( const QString &mime ); |
61 | private: | 72 | |
73 | /* The custom X-CONTENT-DISPOSITION parameter, used by OGo etc. */ | ||
74 | bool showInline() const; | ||
75 | void setShowInline( bool showinline ); | ||
76 | |||
77 | /* The custom X-LABEL parameter to show a human-readable title */ | ||
78 | QString label() const; | ||
79 | void setLabel( const QString &label ); | ||
80 | |||
81 | private: | ||
62 | QString mMimeType; | 82 | QString mMimeType; |
63 | QString mData; | 83 | QString mData; |
64 | bool mBinary; | 84 | bool mBinary; |
85 | bool mShowInline; | ||
86 | QString mLabel; | ||
87 | |||
88 | class Private; | ||
89 | Private *d; | ||
65 | }; | 90 | }; |
66 | 91 | ||
67 | } | 92 | } |
68 | 93 | ||
69 | #endif | 94 | #endif |
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp index 53aa039..65eabc8 100644 --- a/libkcal/icalformatimpl.cpp +++ b/libkcal/icalformatimpl.cpp | |||
@@ -261,519 +261,519 @@ void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) | |||
261 | // TODO: move this application-specific code to kpilot | 261 | // TODO: move this application-specific code to kpilot |
262 | if (incidence->pilotId()) { | 262 | if (incidence->pilotId()) { |
263 | incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); | 263 | incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); |
264 | incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); | 264 | incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); |
265 | } | 265 | } |
266 | if ( !incidence->IDStr().isEmpty()) { | 266 | if ( !incidence->IDStr().isEmpty()) { |
267 | incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); | 267 | incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); |
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
271 | writeIncidenceBase(parent,incidence); | 271 | writeIncidenceBase(parent,incidence); |
272 | if (incidence->cancelled()) { | 272 | if (incidence->cancelled()) { |
273 | icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); | 273 | icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); |
274 | } | 274 | } |
275 | 275 | ||
276 | // creation date | 276 | // creation date |
277 | icalcomponent_add_property(parent,icalproperty_new_created( | 277 | icalcomponent_add_property(parent,icalproperty_new_created( |
278 | writeICalDateTime(incidence->created()))); | 278 | writeICalDateTime(incidence->created()))); |
279 | 279 | ||
280 | // unique id | 280 | // unique id |
281 | icalcomponent_add_property(parent,icalproperty_new_uid( | 281 | icalcomponent_add_property(parent,icalproperty_new_uid( |
282 | incidence->uid().utf8())); | 282 | incidence->uid().utf8())); |
283 | 283 | ||
284 | // revision | 284 | // revision |
285 | icalcomponent_add_property(parent,icalproperty_new_sequence( | 285 | icalcomponent_add_property(parent,icalproperty_new_sequence( |
286 | incidence->revision())); | 286 | incidence->revision())); |
287 | 287 | ||
288 | // last modification date | 288 | // last modification date |
289 | icalcomponent_add_property(parent,icalproperty_new_lastmodified( | 289 | icalcomponent_add_property(parent,icalproperty_new_lastmodified( |
290 | writeICalDateTime(incidence->lastModified()))); | 290 | writeICalDateTime(incidence->lastModified()))); |
291 | 291 | ||
292 | // description | 292 | // description |
293 | if (!incidence->description().isEmpty()) { | 293 | if (!incidence->description().isEmpty()) { |
294 | icalcomponent_add_property(parent,icalproperty_new_description( | 294 | icalcomponent_add_property(parent,icalproperty_new_description( |
295 | incidence->description().utf8())); | 295 | incidence->description().utf8())); |
296 | } | 296 | } |
297 | 297 | ||
298 | // summary | 298 | // summary |
299 | if (!incidence->summary().isEmpty()) { | 299 | if (!incidence->summary().isEmpty()) { |
300 | icalcomponent_add_property(parent,icalproperty_new_summary( | 300 | icalcomponent_add_property(parent,icalproperty_new_summary( |
301 | incidence->summary().utf8())); | 301 | incidence->summary().utf8())); |
302 | } | 302 | } |
303 | 303 | ||
304 | // location | 304 | // location |
305 | if (!incidence->location().isEmpty()) { | 305 | if (!incidence->location().isEmpty()) { |
306 | icalcomponent_add_property(parent,icalproperty_new_location( | 306 | icalcomponent_add_property(parent,icalproperty_new_location( |
307 | incidence->location().utf8())); | 307 | incidence->location().utf8())); |
308 | } | 308 | } |
309 | 309 | ||
310 | // TODO: | 310 | // TODO: |
311 | // status | 311 | // status |
312 | // addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); | 312 | // addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); |
313 | 313 | ||
314 | // secrecy | 314 | // secrecy |
315 | enum icalproperty_class classInt; | 315 | enum icalproperty_class classInt; |
316 | switch (incidence->secrecy()) { | 316 | switch (incidence->secrecy()) { |
317 | case Incidence::SecrecyPublic: | 317 | case Incidence::SecrecyPublic: |
318 | classInt = ICAL_CLASS_PUBLIC; | 318 | classInt = ICAL_CLASS_PUBLIC; |
319 | break; | 319 | break; |
320 | case Incidence::SecrecyConfidential: | 320 | case Incidence::SecrecyConfidential: |
321 | classInt = ICAL_CLASS_CONFIDENTIAL; | 321 | classInt = ICAL_CLASS_CONFIDENTIAL; |
322 | break; | 322 | break; |
323 | case Incidence::SecrecyPrivate: | 323 | case Incidence::SecrecyPrivate: |
324 | classInt =ICAL_CLASS_PRIVATE ; | 324 | classInt =ICAL_CLASS_PRIVATE ; |
325 | default: | 325 | default: |
326 | classInt =ICAL_CLASS_PRIVATE ; | 326 | classInt =ICAL_CLASS_PRIVATE ; |
327 | break; | 327 | break; |
328 | } | 328 | } |
329 | icalcomponent_add_property(parent,icalproperty_new_class(classInt)); | 329 | icalcomponent_add_property(parent,icalproperty_new_class(classInt)); |
330 | 330 | ||
331 | // priority | 331 | // priority |
332 | icalcomponent_add_property(parent,icalproperty_new_priority( | 332 | icalcomponent_add_property(parent,icalproperty_new_priority( |
333 | incidence->priority())); | 333 | incidence->priority())); |
334 | 334 | ||
335 | // categories | 335 | // categories |
336 | QStringList categories = incidence->categories(); | 336 | QStringList categories = incidence->categories(); |
337 | QStringList::Iterator it; | 337 | QStringList::Iterator it; |
338 | for(it = categories.begin(); it != categories.end(); ++it ) { | 338 | for(it = categories.begin(); it != categories.end(); ++it ) { |
339 | icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); | 339 | icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); |
340 | } | 340 | } |
341 | // TODO: Ensure correct concatenation of categories properties. | 341 | // TODO: Ensure correct concatenation of categories properties. |
342 | 342 | ||
343 | /* | 343 | /* |
344 | // categories | 344 | // categories |
345 | tmpStrList = incidence->getCategories(); | 345 | tmpStrList = incidence->getCategories(); |
346 | tmpStr = ""; | 346 | tmpStr = ""; |
347 | QString catStr; | 347 | QString catStr; |
348 | for ( QStringList::Iterator it = tmpStrList.begin(); | 348 | for ( QStringList::Iterator it = tmpStrList.begin(); |
349 | it != tmpStrList.end(); | 349 | it != tmpStrList.end(); |
350 | ++it ) { | 350 | ++it ) { |
351 | catStr = *it; | 351 | catStr = *it; |
352 | if (catStr[0] == ' ') | 352 | if (catStr[0] == ' ') |
353 | tmpStr += catStr.mid(1); | 353 | tmpStr += catStr.mid(1); |
354 | else | 354 | else |
355 | tmpStr += catStr; | 355 | tmpStr += catStr; |
356 | // this must be a ';' character as the vCalendar specification requires! | 356 | // this must be a ';' character as the vCalendar specification requires! |
357 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 357 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
358 | // read in. | 358 | // read in. |
359 | tmpStr += ";"; | 359 | tmpStr += ";"; |
360 | } | 360 | } |
361 | if (!tmpStr.isEmpty()) { | 361 | if (!tmpStr.isEmpty()) { |
362 | tmpStr.truncate(tmpStr.length()-1); | 362 | tmpStr.truncate(tmpStr.length()-1); |
363 | icalcomponent_add_property(parent,icalproperty_new_categories( | 363 | icalcomponent_add_property(parent,icalproperty_new_categories( |
364 | writeText(incidence->getCategories().join(";")))); | 364 | writeText(incidence->getCategories().join(";")))); |
365 | } | 365 | } |
366 | */ | 366 | */ |
367 | 367 | ||
368 | // related event | 368 | // related event |
369 | if (!incidence->relatedToUid().isEmpty()) { | 369 | if (!incidence->relatedToUid().isEmpty()) { |
370 | icalcomponent_add_property(parent,icalproperty_new_relatedto( | 370 | icalcomponent_add_property(parent,icalproperty_new_relatedto( |
371 | incidence->relatedToUid().utf8())); | 371 | incidence->relatedToUid().utf8())); |
372 | } | 372 | } |
373 | 373 | ||
374 | // recurrence rule stuff | 374 | // recurrence rule stuff |
375 | if (incidence->doesRecur()) { | 375 | if (incidence->doesRecur()) { |
376 | icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence())); | 376 | icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence())); |
377 | // recurrence excpetion dates | 377 | // recurrence excpetion dates |
378 | DateList dateList = incidence->exDates(); | 378 | DateList dateList = incidence->exDates(); |
379 | DateList::ConstIterator exIt; | 379 | DateList::ConstIterator exIt; |
380 | for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { | 380 | for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { |
381 | icalcomponent_add_property(parent,icalproperty_new_exdate( | 381 | icalcomponent_add_property(parent,icalproperty_new_exdate( |
382 | writeICalDate(*exIt))); | 382 | writeICalDate(*exIt))); |
383 | } | 383 | } |
384 | } | 384 | } |
385 | 385 | ||
386 | // attachments | 386 | // attachments |
387 | QPtrList<Attachment> attachments = incidence->attachments(); | 387 | QPtrList<Attachment> attachments = incidence->attachments(); |
388 | for (Attachment *at = attachments.first(); at; at = attachments.next()) | 388 | for (Attachment *at = attachments.first(); at; at = attachments.next()) |
389 | icalcomponent_add_property(parent,writeAttachment(at)); | 389 | icalcomponent_add_property(parent,writeAttachment(at)); |
390 | 390 | ||
391 | // alarms | 391 | // alarms |
392 | QPtrList<Alarm> alarms = incidence->alarms(); | 392 | QPtrList<Alarm> alarms = incidence->alarms(); |
393 | Alarm* alarm; | 393 | Alarm* alarm; |
394 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 394 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
395 | if (alarm->enabled()) { | 395 | if (alarm->enabled()) { |
396 | kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; | 396 | kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; |
397 | icalcomponent_add_component(parent,writeAlarm(alarm)); | 397 | icalcomponent_add_component(parent,writeAlarm(alarm)); |
398 | } | 398 | } |
399 | } | 399 | } |
400 | if( incidence->hasRecurrenceID() ) { | 400 | if( incidence->hasRecurrenceID() ) { |
401 | icalcomponent_add_property(parent, | 401 | icalcomponent_add_property(parent, |
402 | icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); | 402 | icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); |
403 | } | 403 | } |
404 | // duration | 404 | // duration |
405 | 405 | ||
406 | // turned off as it always is set to PTS0 (and must not occur together with DTEND | 406 | // turned off as it always is set to PTS0 (and must not occur together with DTEND |
407 | 407 | ||
408 | if (incidence->hasDuration()) { | 408 | if (incidence->hasDuration()) { |
409 | icaldurationtype duration; | 409 | icaldurationtype duration; |
410 | duration = writeICalDuration(incidence->duration()); | 410 | duration = writeICalDuration(incidence->duration()); |
411 | icalcomponent_add_property(parent,icalproperty_new_duration(duration)); | 411 | icalcomponent_add_property(parent,icalproperty_new_duration(duration)); |
412 | } | 412 | } |
413 | } | 413 | } |
414 | 414 | ||
415 | void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) | 415 | void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) |
416 | { | 416 | { |
417 | icalcomponent_add_property(parent,icalproperty_new_dtstamp( | 417 | icalcomponent_add_property(parent,icalproperty_new_dtstamp( |
418 | writeICalDateTime(QDateTime::currentDateTime()))); | 418 | writeICalDateTime(QDateTime::currentDateTime()))); |
419 | 419 | ||
420 | // organizer stuff | 420 | // organizer stuff |
421 | icalcomponent_add_property(parent,icalproperty_new_organizer( | 421 | icalcomponent_add_property(parent,icalproperty_new_organizer( |
422 | ("MAILTO:" + incidenceBase->organizer()).utf8())); | 422 | ("MAILTO:" + incidenceBase->organizer()).utf8())); |
423 | 423 | ||
424 | // attendees | 424 | // attendees |
425 | if (incidenceBase->attendeeCount() != 0) { | 425 | if (incidenceBase->attendeeCount() != 0) { |
426 | QPtrList<Attendee> al = incidenceBase->attendees(); | 426 | QPtrList<Attendee> al = incidenceBase->attendees(); |
427 | QPtrListIterator<Attendee> ai(al); | 427 | QPtrListIterator<Attendee> ai(al); |
428 | for (; ai.current(); ++ai) { | 428 | for (; ai.current(); ++ai) { |
429 | icalcomponent_add_property(parent,writeAttendee(ai.current())); | 429 | icalcomponent_add_property(parent,writeAttendee(ai.current())); |
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
433 | // custom properties | 433 | // custom properties |
434 | writeCustomProperties(parent, incidenceBase); | 434 | writeCustomProperties(parent, incidenceBase); |
435 | } | 435 | } |
436 | 436 | ||
437 | void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) | 437 | void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) |
438 | { | 438 | { |
439 | QMap<QCString, QString> custom = properties->customProperties(); | 439 | QMap<QCString, QString> custom = properties->customProperties(); |
440 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { | 440 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { |
441 | icalproperty *p = icalproperty_new_x(c.data().utf8()); | 441 | icalproperty *p = icalproperty_new_x(c.data().utf8()); |
442 | icalproperty_set_x_name(p,c.key()); | 442 | icalproperty_set_x_name(p,c.key()); |
443 | icalcomponent_add_property(parent,p); | 443 | icalcomponent_add_property(parent,p); |
444 | } | 444 | } |
445 | } | 445 | } |
446 | 446 | ||
447 | icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) | 447 | icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) |
448 | { | 448 | { |
449 | icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); | 449 | icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); |
450 | 450 | ||
451 | if (!attendee->name().isEmpty()) { | 451 | if (!attendee->name().isEmpty()) { |
452 | icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); | 452 | icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); |
453 | } | 453 | } |
454 | 454 | ||
455 | 455 | ||
456 | icalproperty_add_parameter(p,icalparameter_new_rsvp( | 456 | icalproperty_add_parameter(p,icalparameter_new_rsvp( |
457 | attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); | 457 | attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); |
458 | 458 | ||
459 | icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; | 459 | icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; |
460 | switch (attendee->status()) { | 460 | switch (attendee->status()) { |
461 | default: | 461 | default: |
462 | case Attendee::NeedsAction: | 462 | case Attendee::NeedsAction: |
463 | status = ICAL_PARTSTAT_NEEDSACTION; | 463 | status = ICAL_PARTSTAT_NEEDSACTION; |
464 | break; | 464 | break; |
465 | case Attendee::Accepted: | 465 | case Attendee::Accepted: |
466 | status = ICAL_PARTSTAT_ACCEPTED; | 466 | status = ICAL_PARTSTAT_ACCEPTED; |
467 | break; | 467 | break; |
468 | case Attendee::Declined: | 468 | case Attendee::Declined: |
469 | status = ICAL_PARTSTAT_DECLINED; | 469 | status = ICAL_PARTSTAT_DECLINED; |
470 | break; | 470 | break; |
471 | case Attendee::Tentative: | 471 | case Attendee::Tentative: |
472 | status = ICAL_PARTSTAT_TENTATIVE; | 472 | status = ICAL_PARTSTAT_TENTATIVE; |
473 | break; | 473 | break; |
474 | case Attendee::Delegated: | 474 | case Attendee::Delegated: |
475 | status = ICAL_PARTSTAT_DELEGATED; | 475 | status = ICAL_PARTSTAT_DELEGATED; |
476 | break; | 476 | break; |
477 | case Attendee::Completed: | 477 | case Attendee::Completed: |
478 | status = ICAL_PARTSTAT_COMPLETED; | 478 | status = ICAL_PARTSTAT_COMPLETED; |
479 | break; | 479 | break; |
480 | case Attendee::InProcess: | 480 | case Attendee::InProcess: |
481 | status = ICAL_PARTSTAT_INPROCESS; | 481 | status = ICAL_PARTSTAT_INPROCESS; |
482 | break; | 482 | break; |
483 | } | 483 | } |
484 | icalproperty_add_parameter(p,icalparameter_new_partstat(status)); | 484 | icalproperty_add_parameter(p,icalparameter_new_partstat(status)); |
485 | 485 | ||
486 | icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; | 486 | icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; |
487 | switch (attendee->role()) { | 487 | switch (attendee->role()) { |
488 | case Attendee::Chair: | 488 | case Attendee::Chair: |
489 | role = ICAL_ROLE_CHAIR; | 489 | role = ICAL_ROLE_CHAIR; |
490 | break; | 490 | break; |
491 | default: | 491 | default: |
492 | case Attendee::ReqParticipant: | 492 | case Attendee::ReqParticipant: |
493 | role = ICAL_ROLE_REQPARTICIPANT; | 493 | role = ICAL_ROLE_REQPARTICIPANT; |
494 | break; | 494 | break; |
495 | case Attendee::OptParticipant: | 495 | case Attendee::OptParticipant: |
496 | role = ICAL_ROLE_OPTPARTICIPANT; | 496 | role = ICAL_ROLE_OPTPARTICIPANT; |
497 | break; | 497 | break; |
498 | case Attendee::NonParticipant: | 498 | case Attendee::NonParticipant: |
499 | role = ICAL_ROLE_NONPARTICIPANT; | 499 | role = ICAL_ROLE_NONPARTICIPANT; |
500 | break; | 500 | break; |
501 | } | 501 | } |
502 | icalproperty_add_parameter(p,icalparameter_new_role(role)); | 502 | icalproperty_add_parameter(p,icalparameter_new_role(role)); |
503 | 503 | ||
504 | if (!attendee->uid().isEmpty()) { | 504 | if (!attendee->uid().isEmpty()) { |
505 | icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); | 505 | icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); |
506 | icalparameter_set_xname(icalparameter_uid,"X-UID"); | 506 | icalparameter_set_xname(icalparameter_uid,"X-UID"); |
507 | icalproperty_add_parameter(p,icalparameter_uid); | 507 | icalproperty_add_parameter(p,icalparameter_uid); |
508 | } | 508 | } |
509 | 509 | ||
510 | return p; | 510 | return p; |
511 | } | 511 | } |
512 | 512 | ||
513 | icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) | 513 | icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) |
514 | { | 514 | { |
515 | #if 0 | 515 | #if 0 |
516 | icalattachtype* attach = icalattachtype_new(); | 516 | icalattachtype* attach = icalattachtype_new(); |
517 | if (att->isURI()) | 517 | if (att->isUri()) |
518 | icalattachtype_set_url(attach, att->uri().utf8().data()); | 518 | icalattachtype_set_url(attach, att->uri().utf8().data()); |
519 | else | 519 | else |
520 | icalattachtype_set_base64(attach, att->data(), 0); | 520 | icalattachtype_set_base64(attach, att->data(), 0); |
521 | #endif | 521 | #endif |
522 | icalattach *attach; | 522 | icalattach *attach; |
523 | if (att->isURI()) | 523 | if (att->isUri()) |
524 | attach = icalattach_new_from_url( att->uri().utf8().data()); | 524 | attach = icalattach_new_from_url( att->uri().utf8().data()); |
525 | else | 525 | else |
526 | attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); | 526 | attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); |
527 | icalproperty *p = icalproperty_new_attach(attach); | 527 | icalproperty *p = icalproperty_new_attach(attach); |
528 | if (!att->mimeType().isEmpty()) | 528 | if (!att->mimeType().isEmpty()) |
529 | icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); | 529 | icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); |
530 | 530 | ||
531 | if (att->isBinary()) { | 531 | if (att->isBinary()) { |
532 | icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); | 532 | icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); |
533 | icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); | 533 | icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); |
534 | } | 534 | } |
535 | return p; | 535 | return p; |
536 | } | 536 | } |
537 | 537 | ||
538 | icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) | 538 | icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) |
539 | { | 539 | { |
540 | // kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; | 540 | // kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; |
541 | 541 | ||
542 | icalrecurrencetype r; | 542 | icalrecurrencetype r; |
543 | 543 | ||
544 | icalrecurrencetype_clear(&r); | 544 | icalrecurrencetype_clear(&r); |
545 | 545 | ||
546 | int index = 0; | 546 | int index = 0; |
547 | int index2 = 0; | 547 | int index2 = 0; |
548 | 548 | ||
549 | QPtrList<Recurrence::rMonthPos> tmpPositions; | 549 | QPtrList<Recurrence::rMonthPos> tmpPositions; |
550 | QPtrList<int> tmpDays; | 550 | QPtrList<int> tmpDays; |
551 | int *tmpDay; | 551 | int *tmpDay; |
552 | Recurrence::rMonthPos *tmpPos; | 552 | Recurrence::rMonthPos *tmpPos; |
553 | bool datetime = false; | 553 | bool datetime = false; |
554 | int day; | 554 | int day; |
555 | int i; | 555 | int i; |
556 | 556 | ||
557 | switch(recur->doesRecur()) { | 557 | switch(recur->doesRecur()) { |
558 | case Recurrence::rMinutely: | 558 | case Recurrence::rMinutely: |
559 | r.freq = ICAL_MINUTELY_RECURRENCE; | 559 | r.freq = ICAL_MINUTELY_RECURRENCE; |
560 | datetime = true; | 560 | datetime = true; |
561 | break; | 561 | break; |
562 | case Recurrence::rHourly: | 562 | case Recurrence::rHourly: |
563 | r.freq = ICAL_HOURLY_RECURRENCE; | 563 | r.freq = ICAL_HOURLY_RECURRENCE; |
564 | datetime = true; | 564 | datetime = true; |
565 | break; | 565 | break; |
566 | case Recurrence::rDaily: | 566 | case Recurrence::rDaily: |
567 | r.freq = ICAL_DAILY_RECURRENCE; | 567 | r.freq = ICAL_DAILY_RECURRENCE; |
568 | break; | 568 | break; |
569 | case Recurrence::rWeekly: | 569 | case Recurrence::rWeekly: |
570 | r.freq = ICAL_WEEKLY_RECURRENCE; | 570 | r.freq = ICAL_WEEKLY_RECURRENCE; |
571 | r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); | 571 | r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); |
572 | for (i = 0; i < 7; i++) { | 572 | for (i = 0; i < 7; i++) { |
573 | if (recur->days().testBit(i)) { | 573 | if (recur->days().testBit(i)) { |
574 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 574 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
575 | r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); | 575 | r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); |
576 | } | 576 | } |
577 | } | 577 | } |
578 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 578 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
579 | break; | 579 | break; |
580 | case Recurrence::rMonthlyPos: | 580 | case Recurrence::rMonthlyPos: |
581 | r.freq = ICAL_MONTHLY_RECURRENCE; | 581 | r.freq = ICAL_MONTHLY_RECURRENCE; |
582 | 582 | ||
583 | tmpPositions = recur->monthPositions(); | 583 | tmpPositions = recur->monthPositions(); |
584 | for (tmpPos = tmpPositions.first(); | 584 | for (tmpPos = tmpPositions.first(); |
585 | tmpPos; | 585 | tmpPos; |
586 | tmpPos = tmpPositions.next()) { | 586 | tmpPos = tmpPositions.next()) { |
587 | for (i = 0; i < 7; i++) { | 587 | for (i = 0; i < 7; i++) { |
588 | if (tmpPos->rDays.testBit(i)) { | 588 | if (tmpPos->rDays.testBit(i)) { |
589 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 589 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
590 | day += tmpPos->rPos*8; | 590 | day += tmpPos->rPos*8; |
591 | if (tmpPos->negative) day = -day; | 591 | if (tmpPos->negative) day = -day; |
592 | r.by_day[index++] = day; | 592 | r.by_day[index++] = day; |
593 | } | 593 | } |
594 | } | 594 | } |
595 | } | 595 | } |
596 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 596 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
597 | break; | 597 | break; |
598 | case Recurrence::rMonthlyDay: | 598 | case Recurrence::rMonthlyDay: |
599 | r.freq = ICAL_MONTHLY_RECURRENCE; | 599 | r.freq = ICAL_MONTHLY_RECURRENCE; |
600 | 600 | ||
601 | tmpDays = recur->monthDays(); | 601 | tmpDays = recur->monthDays(); |
602 | for (tmpDay = tmpDays.first(); | 602 | for (tmpDay = tmpDays.first(); |
603 | tmpDay; | 603 | tmpDay; |
604 | tmpDay = tmpDays.next()) { | 604 | tmpDay = tmpDays.next()) { |
605 | r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); | 605 | r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); |
606 | } | 606 | } |
607 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 607 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
608 | break; | 608 | break; |
609 | case Recurrence::rYearlyMonth: | 609 | case Recurrence::rYearlyMonth: |
610 | case Recurrence::rYearlyPos: | 610 | case Recurrence::rYearlyPos: |
611 | r.freq = ICAL_YEARLY_RECURRENCE; | 611 | r.freq = ICAL_YEARLY_RECURRENCE; |
612 | 612 | ||
613 | tmpDays = recur->yearNums(); | 613 | tmpDays = recur->yearNums(); |
614 | for (tmpDay = tmpDays.first(); | 614 | for (tmpDay = tmpDays.first(); |
615 | tmpDay; | 615 | tmpDay; |
616 | tmpDay = tmpDays.next()) { | 616 | tmpDay = tmpDays.next()) { |
617 | r.by_month[index++] = *tmpDay; | 617 | r.by_month[index++] = *tmpDay; |
618 | } | 618 | } |
619 | // r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; | 619 | // r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; |
620 | if (recur->doesRecur() == Recurrence::rYearlyPos) { | 620 | if (recur->doesRecur() == Recurrence::rYearlyPos) { |
621 | tmpPositions = recur->monthPositions(); | 621 | tmpPositions = recur->monthPositions(); |
622 | for (tmpPos = tmpPositions.first(); | 622 | for (tmpPos = tmpPositions.first(); |
623 | tmpPos; | 623 | tmpPos; |
624 | tmpPos = tmpPositions.next()) { | 624 | tmpPos = tmpPositions.next()) { |
625 | for (i = 0; i < 7; i++) { | 625 | for (i = 0; i < 7; i++) { |
626 | if (tmpPos->rDays.testBit(i)) { | 626 | if (tmpPos->rDays.testBit(i)) { |
627 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 627 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
628 | day += tmpPos->rPos*8; | 628 | day += tmpPos->rPos*8; |
629 | if (tmpPos->negative) day = -day; | 629 | if (tmpPos->negative) day = -day; |
630 | r.by_day[index2++] = day; | 630 | r.by_day[index2++] = day; |
631 | } | 631 | } |
632 | } | 632 | } |
633 | } | 633 | } |
634 | // r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; | 634 | // r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; |
635 | } | 635 | } |
636 | break; | 636 | break; |
637 | case Recurrence::rYearlyDay: | 637 | case Recurrence::rYearlyDay: |
638 | r.freq = ICAL_YEARLY_RECURRENCE; | 638 | r.freq = ICAL_YEARLY_RECURRENCE; |
639 | 639 | ||
640 | tmpDays = recur->yearNums(); | 640 | tmpDays = recur->yearNums(); |
641 | for (tmpDay = tmpDays.first(); | 641 | for (tmpDay = tmpDays.first(); |
642 | tmpDay; | 642 | tmpDay; |
643 | tmpDay = tmpDays.next()) { | 643 | tmpDay = tmpDays.next()) { |
644 | r.by_year_day[index++] = *tmpDay; | 644 | r.by_year_day[index++] = *tmpDay; |
645 | } | 645 | } |
646 | // r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 646 | // r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
647 | break; | 647 | break; |
648 | default: | 648 | default: |
649 | r.freq = ICAL_NO_RECURRENCE; | 649 | r.freq = ICAL_NO_RECURRENCE; |
650 | kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; | 650 | kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; |
651 | break; | 651 | break; |
652 | } | 652 | } |
653 | 653 | ||
654 | r.interval = recur->frequency(); | 654 | r.interval = recur->frequency(); |
655 | 655 | ||
656 | if (recur->duration() > 0) { | 656 | if (recur->duration() > 0) { |
657 | r.count = recur->duration(); | 657 | r.count = recur->duration(); |
658 | } else if (recur->duration() == -1) { | 658 | } else if (recur->duration() == -1) { |
659 | r.count = 0; | 659 | r.count = 0; |
660 | } else { | 660 | } else { |
661 | if (datetime) | 661 | if (datetime) |
662 | r.until = writeICalDateTime(recur->endDateTime()); | 662 | r.until = writeICalDateTime(recur->endDateTime()); |
663 | else | 663 | else |
664 | r.until = writeICalDate(recur->endDate()); | 664 | r.until = writeICalDate(recur->endDate()); |
665 | } | 665 | } |
666 | 666 | ||
667 | // Debug output | 667 | // Debug output |
668 | #if 0 | 668 | #if 0 |
669 | const char *str = icalrecurrencetype_as_string(&r); | 669 | const char *str = icalrecurrencetype_as_string(&r); |
670 | if (str) { | 670 | if (str) { |
671 | kdDebug(5800) << " String: " << str << endl; | 671 | kdDebug(5800) << " String: " << str << endl; |
672 | } else { | 672 | } else { |
673 | kdDebug(5800) << " No String" << endl; | 673 | kdDebug(5800) << " No String" << endl; |
674 | } | 674 | } |
675 | #endif | 675 | #endif |
676 | 676 | ||
677 | return icalproperty_new_rrule(r); | 677 | return icalproperty_new_rrule(r); |
678 | } | 678 | } |
679 | 679 | ||
680 | icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) | 680 | icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) |
681 | { | 681 | { |
682 | icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); | 682 | icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); |
683 | 683 | ||
684 | icalproperty_action action; | 684 | icalproperty_action action; |
685 | icalattach *attach = 0; | 685 | icalattach *attach = 0; |
686 | 686 | ||
687 | switch (alarm->type()) { | 687 | switch (alarm->type()) { |
688 | case Alarm::Procedure: | 688 | case Alarm::Procedure: |
689 | action = ICAL_ACTION_PROCEDURE; | 689 | action = ICAL_ACTION_PROCEDURE; |
690 | attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); | 690 | attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); |
691 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 691 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
692 | if (!alarm->programArguments().isEmpty()) { | 692 | if (!alarm->programArguments().isEmpty()) { |
693 | icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); | 693 | icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); |
694 | } | 694 | } |
695 | icalattach_unref( attach ); | 695 | icalattach_unref( attach ); |
696 | break; | 696 | break; |
697 | case Alarm::Audio: | 697 | case Alarm::Audio: |
698 | action = ICAL_ACTION_AUDIO; | 698 | action = ICAL_ACTION_AUDIO; |
699 | if (!alarm->audioFile().isEmpty()) { | 699 | if (!alarm->audioFile().isEmpty()) { |
700 | attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); | 700 | attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); |
701 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 701 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
702 | icalattach_unref( attach ); | 702 | icalattach_unref( attach ); |
703 | } | 703 | } |
704 | break; | 704 | break; |
705 | case Alarm::Email: { | 705 | case Alarm::Email: { |
706 | action = ICAL_ACTION_EMAIL; | 706 | action = ICAL_ACTION_EMAIL; |
707 | QValueList<Person> addresses = alarm->mailAddresses(); | 707 | QValueList<Person> addresses = alarm->mailAddresses(); |
708 | for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { | 708 | for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { |
709 | icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); | 709 | icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); |
710 | if (!(*ad).name().isEmpty()) { | 710 | if (!(*ad).name().isEmpty()) { |
711 | icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); | 711 | icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); |
712 | } | 712 | } |
713 | icalcomponent_add_property(a,p); | 713 | icalcomponent_add_property(a,p); |
714 | } | 714 | } |
715 | icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); | 715 | icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); |
716 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); | 716 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); |
717 | QStringList attachments = alarm->mailAttachments(); | 717 | QStringList attachments = alarm->mailAttachments(); |
718 | if (attachments.count() > 0) { | 718 | if (attachments.count() > 0) { |
719 | for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { | 719 | for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { |
720 | attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); | 720 | attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); |
721 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 721 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
722 | icalattach_unref( attach ); | 722 | icalattach_unref( attach ); |
723 | } | 723 | } |
724 | } | 724 | } |
725 | break; | 725 | break; |
726 | } | 726 | } |
727 | case Alarm::Display: | 727 | case Alarm::Display: |
728 | action = ICAL_ACTION_DISPLAY; | 728 | action = ICAL_ACTION_DISPLAY; |
729 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); | 729 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); |
730 | break; | 730 | break; |
731 | case Alarm::Invalid: | 731 | case Alarm::Invalid: |
732 | default: | 732 | default: |
733 | kdDebug(5800) << "Unknown type of alarm" << endl; | 733 | kdDebug(5800) << "Unknown type of alarm" << endl; |
734 | action = ICAL_ACTION_NONE; | 734 | action = ICAL_ACTION_NONE; |
735 | break; | 735 | break; |
736 | } | 736 | } |
737 | icalcomponent_add_property(a,icalproperty_new_action(action)); | 737 | icalcomponent_add_property(a,icalproperty_new_action(action)); |
738 | 738 | ||
739 | // Trigger time | 739 | // Trigger time |
740 | icaltriggertype trigger; | 740 | icaltriggertype trigger; |
741 | if ( alarm->hasTime() ) { | 741 | if ( alarm->hasTime() ) { |
742 | trigger.time = writeICalDateTime(alarm->time()); | 742 | trigger.time = writeICalDateTime(alarm->time()); |
743 | trigger.duration = icaldurationtype_null_duration(); | 743 | trigger.duration = icaldurationtype_null_duration(); |
744 | } else { | 744 | } else { |
745 | trigger.time = icaltime_null_time(); | 745 | trigger.time = icaltime_null_time(); |
746 | Duration offset; | 746 | Duration offset; |
747 | if ( alarm->hasStartOffset() ) | 747 | if ( alarm->hasStartOffset() ) |
748 | offset = alarm->startOffset(); | 748 | offset = alarm->startOffset(); |
749 | else | 749 | else |
750 | offset = alarm->endOffset(); | 750 | offset = alarm->endOffset(); |
751 | trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); | 751 | trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); |
752 | } | 752 | } |
753 | icalproperty *p = icalproperty_new_trigger(trigger); | 753 | icalproperty *p = icalproperty_new_trigger(trigger); |
754 | if ( alarm->hasEndOffset() ) | 754 | if ( alarm->hasEndOffset() ) |
755 | icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); | 755 | icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); |
756 | icalcomponent_add_property(a,p); | 756 | icalcomponent_add_property(a,p); |
757 | 757 | ||
758 | // Repeat count and duration | 758 | // Repeat count and duration |
759 | if (alarm->repeatCount()) { | 759 | if (alarm->repeatCount()) { |
760 | icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); | 760 | icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); |
761 | icalcomponent_add_property(a,icalproperty_new_duration( | 761 | icalcomponent_add_property(a,icalproperty_new_duration( |
762 | icaldurationtype_from_int(alarm->snoozeTime()*60))); | 762 | icaldurationtype_from_int(alarm->snoozeTime()*60))); |
763 | } | 763 | } |
764 | 764 | ||
765 | // Custom properties | 765 | // Custom properties |
766 | QMap<QCString, QString> custom = alarm->customProperties(); | 766 | QMap<QCString, QString> custom = alarm->customProperties(); |
767 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { | 767 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { |
768 | icalproperty *p = icalproperty_new_x(c.data().utf8()); | 768 | icalproperty *p = icalproperty_new_x(c.data().utf8()); |
769 | icalproperty_set_x_name(p,c.key()); | 769 | icalproperty_set_x_name(p,c.key()); |
770 | icalcomponent_add_property(a,p); | 770 | icalcomponent_add_property(a,p); |
771 | } | 771 | } |
772 | 772 | ||
773 | return a; | 773 | return a; |
774 | } | 774 | } |
775 | 775 | ||
776 | Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) | 776 | Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) |
777 | { | 777 | { |
778 | Todo *todo = new Todo; | 778 | Todo *todo = new Todo; |
779 | 779 | ||
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 549014e..39c14f5 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,318 +1,325 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = 0;//new Recurrence(this); | 36 | mRecurrence = 0;//new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 42 | mHasRecurrenceID = false; |
43 | mHoliday = false; | 43 | mHoliday = false; |
44 | mBirthday = false; | 44 | mBirthday = false; |
45 | mAnniversary = false; | 45 | mAnniversary = false; |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
50 | { | 50 | { |
51 | // TODO: reenable attributes currently commented out. | 51 | // TODO: reenable attributes currently commented out. |
52 | mRevision = i.mRevision; | 52 | mRevision = i.mRevision; |
53 | mCreated = i.mCreated; | 53 | mCreated = i.mCreated; |
54 | mDescription = i.mDescription; | 54 | mDescription = i.mDescription; |
55 | mSummary = i.mSummary; | 55 | mSummary = i.mSummary; |
56 | mCategories = i.mCategories; | 56 | mCategories = i.mCategories; |
57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
58 | mRelatedTo = 0; | 58 | mRelatedTo = 0; |
59 | mRelatedToUid = i.mRelatedToUid; | 59 | mRelatedToUid = i.mRelatedToUid; |
60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
61 | mExDates = i.mExDates; | 61 | mExDates = i.mExDates; |
62 | mAttachments = i.mAttachments; | 62 | QPtrListIterator<Attachment> itat( i.mAttachments ); |
63 | Attachment *at; | ||
64 | while( (at = itat.current()) ) { | ||
65 | Attachment *a = new Attachment( *at ); | ||
66 | mAttachments.append( a ); | ||
67 | ++itat; | ||
68 | } | ||
69 | mAttachments.setAutoDelete( true ); | ||
63 | mResources = i.mResources; | 70 | mResources = i.mResources; |
64 | mSecrecy = i.mSecrecy; | 71 | mSecrecy = i.mSecrecy; |
65 | mPriority = i.mPriority; | 72 | mPriority = i.mPriority; |
66 | mLocation = i.mLocation; | 73 | mLocation = i.mLocation; |
67 | mCancelled = i.mCancelled; | 74 | mCancelled = i.mCancelled; |
68 | mHasStartDate = i.mHasStartDate; | 75 | mHasStartDate = i.mHasStartDate; |
69 | QPtrListIterator<Alarm> it( i.mAlarms ); | 76 | QPtrListIterator<Alarm> it( i.mAlarms ); |
70 | const Alarm *a; | 77 | const Alarm *a; |
71 | while( (a = it.current()) ) { | 78 | while( (a = it.current()) ) { |
72 | Alarm *b = new Alarm( *a ); | 79 | Alarm *b = new Alarm( *a ); |
73 | b->setParent( this ); | 80 | b->setParent( this ); |
74 | mAlarms.append( b ); | 81 | mAlarms.append( b ); |
75 | 82 | ||
76 | ++it; | 83 | ++it; |
77 | } | 84 | } |
78 | mAlarms.setAutoDelete(true); | 85 | mAlarms.setAutoDelete(true); |
79 | mHasRecurrenceID = i.mHasRecurrenceID; | 86 | mHasRecurrenceID = i.mHasRecurrenceID; |
80 | mRecurrenceID = i.mRecurrenceID; | 87 | mRecurrenceID = i.mRecurrenceID; |
81 | if ( i.mRecurrence ) | 88 | if ( i.mRecurrence ) |
82 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 89 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
83 | else | 90 | else |
84 | mRecurrence = 0; | 91 | mRecurrence = 0; |
85 | mHoliday = i.mHoliday ; | 92 | mHoliday = i.mHoliday ; |
86 | mBirthday = i.mBirthday; | 93 | mBirthday = i.mBirthday; |
87 | mAnniversary = i.mAnniversary; | 94 | mAnniversary = i.mAnniversary; |
88 | } | 95 | } |
89 | 96 | ||
90 | Incidence::~Incidence() | 97 | Incidence::~Incidence() |
91 | { | 98 | { |
92 | 99 | ||
93 | Incidence *ev; | 100 | Incidence *ev; |
94 | QPtrList<Incidence> Relations = relations(); | 101 | QPtrList<Incidence> Relations = relations(); |
95 | for (ev=Relations.first();ev;ev=Relations.next()) { | 102 | for (ev=Relations.first();ev;ev=Relations.next()) { |
96 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 103 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
97 | } | 104 | } |
98 | if (relatedTo()) relatedTo()->removeRelation(this); | 105 | if (relatedTo()) relatedTo()->removeRelation(this); |
99 | if ( mRecurrence ) | 106 | if ( mRecurrence ) |
100 | delete mRecurrence; | 107 | delete mRecurrence; |
101 | 108 | ||
102 | } | 109 | } |
103 | QString Incidence::durationText() | 110 | QString Incidence::durationText() |
104 | { | 111 | { |
105 | return "---"; | 112 | return "---"; |
106 | } | 113 | } |
107 | QString Incidence::durationText4Time( int offset ) | 114 | QString Incidence::durationText4Time( int offset ) |
108 | { | 115 | { |
109 | int min = offset/60; | 116 | int min = offset/60; |
110 | int hours = min /60; | 117 | int hours = min /60; |
111 | min = min % 60; | 118 | min = min % 60; |
112 | int days = hours /24; | 119 | int days = hours /24; |
113 | hours = hours % 24; | 120 | hours = hours % 24; |
114 | 121 | ||
115 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { | 122 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { |
116 | if ( days == 1 ) | 123 | if ( days == 1 ) |
117 | return "1" + i18n(" day"); | 124 | return "1" + i18n(" day"); |
118 | else | 125 | else |
119 | return QString::number( days )+ i18n(" days"); | 126 | return QString::number( days )+ i18n(" days"); |
120 | 127 | ||
121 | } | 128 | } |
122 | QString message = QString::number ( hours ) +":"; | 129 | QString message = QString::number ( hours ) +":"; |
123 | if ( min < 10 ) message += "0"; | 130 | if ( min < 10 ) message += "0"; |
124 | message += QString::number ( min ); | 131 | message += QString::number ( min ); |
125 | if ( days > 0 ) { | 132 | if ( days > 0 ) { |
126 | if ( days == 1 ) | 133 | if ( days == 1 ) |
127 | message = "1" + i18n(" day") + " "+message; | 134 | message = "1" + i18n(" day") + " "+message; |
128 | else | 135 | else |
129 | message = QString::number( days )+ i18n(" days") + " "+message; | 136 | message = QString::number( days )+ i18n(" days") + " "+message; |
130 | } | 137 | } |
131 | return message; | 138 | return message; |
132 | } | 139 | } |
133 | bool Incidence::isHoliday() const | 140 | bool Incidence::isHoliday() const |
134 | { | 141 | { |
135 | return mHoliday; | 142 | return mHoliday; |
136 | } | 143 | } |
137 | bool Incidence::isBirthday() const | 144 | bool Incidence::isBirthday() const |
138 | { | 145 | { |
139 | 146 | ||
140 | return mBirthday ; | 147 | return mBirthday ; |
141 | } | 148 | } |
142 | bool Incidence::isAnniversary() const | 149 | bool Incidence::isAnniversary() const |
143 | { | 150 | { |
144 | return mAnniversary ; | 151 | return mAnniversary ; |
145 | 152 | ||
146 | } | 153 | } |
147 | 154 | ||
148 | bool Incidence::hasRecurrenceID() const | 155 | bool Incidence::hasRecurrenceID() const |
149 | { | 156 | { |
150 | return mHasRecurrenceID; | 157 | return mHasRecurrenceID; |
151 | } | 158 | } |
152 | 159 | ||
153 | void Incidence::setHasRecurrenceID( bool b ) | 160 | void Incidence::setHasRecurrenceID( bool b ) |
154 | { | 161 | { |
155 | mHasRecurrenceID = b; | 162 | mHasRecurrenceID = b; |
156 | } | 163 | } |
157 | 164 | ||
158 | void Incidence::setRecurrenceID(QDateTime d) | 165 | void Incidence::setRecurrenceID(QDateTime d) |
159 | { | 166 | { |
160 | mRecurrenceID = d; | 167 | mRecurrenceID = d; |
161 | mHasRecurrenceID = true; | 168 | mHasRecurrenceID = true; |
162 | updated(); | 169 | updated(); |
163 | } | 170 | } |
164 | QDateTime Incidence::recurrenceID () const | 171 | QDateTime Incidence::recurrenceID () const |
165 | { | 172 | { |
166 | return mRecurrenceID; | 173 | return mRecurrenceID; |
167 | } | 174 | } |
168 | 175 | ||
169 | bool Incidence::cancelled() const | 176 | bool Incidence::cancelled() const |
170 | { | 177 | { |
171 | return mCancelled; | 178 | return mCancelled; |
172 | } | 179 | } |
173 | void Incidence::setCancelled( bool b ) | 180 | void Incidence::setCancelled( bool b ) |
174 | { | 181 | { |
175 | mCancelled = b; | 182 | mCancelled = b; |
176 | updated(); | 183 | updated(); |
177 | } | 184 | } |
178 | bool Incidence::hasStartDate() const | 185 | bool Incidence::hasStartDate() const |
179 | { | 186 | { |
180 | return mHasStartDate; | 187 | return mHasStartDate; |
181 | } | 188 | } |
182 | 189 | ||
183 | void Incidence::setHasStartDate(bool f) | 190 | void Incidence::setHasStartDate(bool f) |
184 | { | 191 | { |
185 | if (mReadOnly) return; | 192 | if (mReadOnly) return; |
186 | mHasStartDate = f; | 193 | mHasStartDate = f; |
187 | updated(); | 194 | updated(); |
188 | } | 195 | } |
189 | 196 | ||
190 | // A string comparison that considers that null and empty are the same | 197 | // A string comparison that considers that null and empty are the same |
191 | static bool stringCompare( const QString& s1, const QString& s2 ) | 198 | static bool stringCompare( const QString& s1, const QString& s2 ) |
192 | { | 199 | { |
193 | if ( s1.isEmpty() && s2.isEmpty() ) | 200 | if ( s1.isEmpty() && s2.isEmpty() ) |
194 | return true; | 201 | return true; |
195 | return s1 == s2; | 202 | return s1 == s2; |
196 | } | 203 | } |
197 | 204 | ||
198 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 205 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
199 | { | 206 | { |
200 | 207 | ||
201 | if( i1.alarms().count() != i2.alarms().count() ) { | 208 | if( i1.alarms().count() != i2.alarms().count() ) { |
202 | return false; // no need to check further | 209 | return false; // no need to check further |
203 | } | 210 | } |
204 | if ( i1.alarms().count() > 0 ) { | 211 | if ( i1.alarms().count() > 0 ) { |
205 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 212 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
206 | { | 213 | { |
207 | qDebug("alarm not equal "); | 214 | qDebug("alarm not equal "); |
208 | return false; | 215 | return false; |
209 | } | 216 | } |
210 | } | 217 | } |
211 | #if 0 | 218 | #if 0 |
212 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 219 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
213 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 220 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
214 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 221 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
215 | if( *a1.current() == *a2.current() ) { | 222 | if( *a1.current() == *a2.current() ) { |
216 | continue; | 223 | continue; |
217 | } | 224 | } |
218 | else { | 225 | else { |
219 | return false; | 226 | return false; |
220 | } | 227 | } |
221 | } | 228 | } |
222 | #endif | 229 | #endif |
223 | 230 | ||
224 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 231 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
225 | if ( i1.hasRecurrenceID() ) { | 232 | if ( i1.hasRecurrenceID() ) { |
226 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 233 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
227 | return false; | 234 | return false; |
228 | } | 235 | } |
229 | 236 | ||
230 | } else { | 237 | } else { |
231 | return false; | 238 | return false; |
232 | } | 239 | } |
233 | 240 | ||
234 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 241 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
235 | return false; | 242 | return false; |
236 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 243 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
237 | if ( i1.hasStartDate() ) { | 244 | if ( i1.hasStartDate() ) { |
238 | if ( i1.dtStart() != i2.dtStart() ) | 245 | if ( i1.dtStart() != i2.dtStart() ) |
239 | return false; | 246 | return false; |
240 | } | 247 | } |
241 | } else { | 248 | } else { |
242 | return false; | 249 | return false; |
243 | } | 250 | } |
244 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { | 251 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { |
245 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { | 252 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { |
246 | //qDebug("recurrence is NOT equal "); | 253 | //qDebug("recurrence is NOT equal "); |
247 | return false; | 254 | return false; |
248 | } | 255 | } |
249 | } else { | 256 | } else { |
250 | // one ( or both ) recurrence is 0 | 257 | // one ( or both ) recurrence is 0 |
251 | if ( i1.mRecurrence == 0 ) { | 258 | if ( i1.mRecurrence == 0 ) { |
252 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) | 259 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) |
253 | return false; | 260 | return false; |
254 | } else { | 261 | } else { |
255 | // i1.mRecurrence != 0 | 262 | // i1.mRecurrence != 0 |
256 | // i2.mRecurrence == 0 | 263 | // i2.mRecurrence == 0 |
257 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) | 264 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) |
258 | return false; | 265 | return false; |
259 | } | 266 | } |
260 | } | 267 | } |
261 | 268 | ||
262 | return | 269 | return |
263 | // i1.created() == i2.created() && | 270 | // i1.created() == i2.created() && |
264 | stringCompare( i1.description(), i2.description() ) && | 271 | stringCompare( i1.description(), i2.description() ) && |
265 | stringCompare( i1.summary(), i2.summary() ) && | 272 | stringCompare( i1.summary(), i2.summary() ) && |
266 | i1.categories() == i2.categories() && | 273 | i1.categories() == i2.categories() && |
267 | // no need to compare mRelatedTo | 274 | // no need to compare mRelatedTo |
268 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 275 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
269 | // i1.relations() == i2.relations() && | 276 | // i1.relations() == i2.relations() && |
270 | i1.exDates() == i2.exDates() && | 277 | i1.exDates() == i2.exDates() && |
271 | i1.attachments() == i2.attachments() && | 278 | i1.attachments() == i2.attachments() && |
272 | i1.resources() == i2.resources() && | 279 | i1.resources() == i2.resources() && |
273 | i1.secrecy() == i2.secrecy() && | 280 | i1.secrecy() == i2.secrecy() && |
274 | i1.priority() == i2.priority() && | 281 | i1.priority() == i2.priority() && |
275 | i1.cancelled() == i2.cancelled() && | 282 | i1.cancelled() == i2.cancelled() && |
276 | stringCompare( i1.location(), i2.location() ); | 283 | stringCompare( i1.location(), i2.location() ); |
277 | } | 284 | } |
278 | 285 | ||
279 | Incidence* Incidence::recreateCloneException( QDate d ) | 286 | Incidence* Incidence::recreateCloneException( QDate d ) |
280 | { | 287 | { |
281 | Incidence* newInc = clone(); | 288 | Incidence* newInc = clone(); |
282 | newInc->recreate(); | 289 | newInc->recreate(); |
283 | if ( doesRecur() ) { | 290 | if ( doesRecur() ) { |
284 | addExDate( d ); | 291 | addExDate( d ); |
285 | newInc->recurrence()->unsetRecurs(); | 292 | newInc->recurrence()->unsetRecurs(); |
286 | if ( typeID() == eventID ) { | 293 | if ( typeID() == eventID ) { |
287 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 294 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
288 | QTime tim = dtStart().time(); | 295 | QTime tim = dtStart().time(); |
289 | newInc->setDtStart( QDateTime(d, tim) ); | 296 | newInc->setDtStart( QDateTime(d, tim) ); |
290 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 297 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
291 | } else { | 298 | } else { |
292 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 299 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
293 | QTime tim = ((Todo*)this)->dtDue().time(); | 300 | QTime tim = ((Todo*)this)->dtDue().time(); |
294 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 301 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
295 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 302 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
296 | ((Todo*)this)->setRecurDates(); | 303 | ((Todo*)this)->setRecurDates(); |
297 | } | 304 | } |
298 | newInc->setExDates( DateList () ); | 305 | newInc->setExDates( DateList () ); |
299 | } | 306 | } |
300 | return newInc; | 307 | return newInc; |
301 | } | 308 | } |
302 | 309 | ||
303 | void Incidence::recreate() | 310 | void Incidence::recreate() |
304 | { | 311 | { |
305 | setCreated(QDateTime::currentDateTime()); | 312 | setCreated(QDateTime::currentDateTime()); |
306 | 313 | ||
307 | setUid(CalFormat::createUniqueId()); | 314 | setUid(CalFormat::createUniqueId()); |
308 | 315 | ||
309 | setRevision(0); | 316 | setRevision(0); |
310 | setIDStr( ":" ); | 317 | setIDStr( ":" ); |
311 | setLastModified(QDateTime::currentDateTime()); | 318 | setLastModified(QDateTime::currentDateTime()); |
312 | } | 319 | } |
313 | void Incidence::cloneRelations( Incidence * newInc ) | 320 | void Incidence::cloneRelations( Incidence * newInc ) |
314 | { | 321 | { |
315 | // newInc is already a clone of this incidence | 322 | // newInc is already a clone of this incidence |
316 | Incidence * inc; | 323 | Incidence * inc; |
317 | Incidence * cloneInc; | 324 | Incidence * cloneInc; |
318 | QPtrList<Incidence> Relations = relations(); | 325 | QPtrList<Incidence> Relations = relations(); |
@@ -504,342 +511,343 @@ QString Incidence::relatedToUid() const | |||
504 | void Incidence::setRelatedTo(Incidence *relatedTo) | 511 | void Incidence::setRelatedTo(Incidence *relatedTo) |
505 | { | 512 | { |
506 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 513 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
507 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 514 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
508 | if (mReadOnly || mRelatedTo == relatedTo) return; | 515 | if (mReadOnly || mRelatedTo == relatedTo) return; |
509 | if(mRelatedTo) { | 516 | if(mRelatedTo) { |
510 | // updated(); | 517 | // updated(); |
511 | mRelatedTo->removeRelation(this); | 518 | mRelatedTo->removeRelation(this); |
512 | } | 519 | } |
513 | mRelatedTo = relatedTo; | 520 | mRelatedTo = relatedTo; |
514 | if (mRelatedTo) { | 521 | if (mRelatedTo) { |
515 | mRelatedTo->addRelation(this); | 522 | mRelatedTo->addRelation(this); |
516 | mRelatedToUid = mRelatedTo->uid(); | 523 | mRelatedToUid = mRelatedTo->uid(); |
517 | } else { | 524 | } else { |
518 | mRelatedToUid = ""; | 525 | mRelatedToUid = ""; |
519 | } | 526 | } |
520 | } | 527 | } |
521 | 528 | ||
522 | Incidence *Incidence::relatedTo() const | 529 | Incidence *Incidence::relatedTo() const |
523 | { | 530 | { |
524 | return mRelatedTo; | 531 | return mRelatedTo; |
525 | } | 532 | } |
526 | 533 | ||
527 | QPtrList<Incidence> Incidence::relations() const | 534 | QPtrList<Incidence> Incidence::relations() const |
528 | { | 535 | { |
529 | return mRelations; | 536 | return mRelations; |
530 | } | 537 | } |
531 | 538 | ||
532 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) | 539 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) |
533 | { | 540 | { |
534 | Incidence* inc; | 541 | Incidence* inc; |
535 | QPtrList<Incidence> Relations = relations(); | 542 | QPtrList<Incidence> Relations = relations(); |
536 | for (inc=Relations.first();inc;inc=Relations.next()) { | 543 | for (inc=Relations.first();inc;inc=Relations.next()) { |
537 | inc->addRelationsToList( rel ); | 544 | inc->addRelationsToList( rel ); |
538 | } | 545 | } |
539 | if ( rel->findRef( this ) == -1 ) | 546 | if ( rel->findRef( this ) == -1 ) |
540 | rel->append( this ); | 547 | rel->append( this ); |
541 | } | 548 | } |
542 | 549 | ||
543 | void Incidence::addRelation(Incidence *event) | 550 | void Incidence::addRelation(Incidence *event) |
544 | { | 551 | { |
545 | setLastModifiedSubInvalid(); | 552 | setLastModifiedSubInvalid(); |
546 | if( mRelations.findRef( event ) == -1 ) { | 553 | if( mRelations.findRef( event ) == -1 ) { |
547 | mRelations.append(event); | 554 | mRelations.append(event); |
548 | //updated(); | 555 | //updated(); |
549 | } | 556 | } |
550 | } | 557 | } |
551 | 558 | ||
552 | void Incidence::removeRelation(Incidence *event) | 559 | void Incidence::removeRelation(Incidence *event) |
553 | { | 560 | { |
554 | setLastModifiedSubInvalid(); | 561 | setLastModifiedSubInvalid(); |
555 | mRelations.removeRef(event); | 562 | mRelations.removeRef(event); |
556 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 563 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
557 | } | 564 | } |
558 | 565 | ||
559 | bool Incidence::recursOn(const QDate &qd) const | 566 | bool Incidence::recursOn(const QDate &qd) const |
560 | { | 567 | { |
561 | if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; | 568 | if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; |
562 | else return false; | 569 | else return false; |
563 | } | 570 | } |
564 | 571 | ||
565 | void Incidence::setExDates(const DateList &exDates) | 572 | void Incidence::setExDates(const DateList &exDates) |
566 | { | 573 | { |
567 | if (mReadOnly) return; | 574 | if (mReadOnly) return; |
568 | mExDates = exDates; | 575 | mExDates = exDates; |
569 | recurrence()->setRecurExDatesCount(mExDates.count()); | 576 | recurrence()->setRecurExDatesCount(mExDates.count()); |
570 | 577 | ||
571 | updated(); | 578 | updated(); |
572 | } | 579 | } |
573 | 580 | ||
574 | void Incidence::addExDate(const QDate &date) | 581 | void Incidence::addExDate(const QDate &date) |
575 | { | 582 | { |
576 | if (mReadOnly) return; | 583 | if (mReadOnly) return; |
577 | mExDates.append(date); | 584 | mExDates.append(date); |
578 | 585 | ||
579 | recurrence()->setRecurExDatesCount(mExDates.count()); | 586 | recurrence()->setRecurExDatesCount(mExDates.count()); |
580 | 587 | ||
581 | updated(); | 588 | updated(); |
582 | } | 589 | } |
583 | 590 | ||
584 | DateList Incidence::exDates() const | 591 | DateList Incidence::exDates() const |
585 | { | 592 | { |
586 | return mExDates; | 593 | return mExDates; |
587 | } | 594 | } |
588 | 595 | ||
589 | bool Incidence::isException(const QDate &date) const | 596 | bool Incidence::isException(const QDate &date) const |
590 | { | 597 | { |
591 | DateList::ConstIterator it; | 598 | DateList::ConstIterator it; |
592 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 599 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
593 | if ( (*it) == date ) { | 600 | if ( (*it) == date ) { |
594 | return true; | 601 | return true; |
595 | } | 602 | } |
596 | } | 603 | } |
597 | 604 | ||
598 | return false; | 605 | return false; |
599 | } | 606 | } |
600 | 607 | ||
601 | void Incidence::addAttachment(Attachment *attachment) | 608 | void Incidence::addAttachment(Attachment *attachment) |
602 | { | 609 | { |
603 | if (mReadOnly || !attachment) return; | 610 | if (mReadOnly || !attachment) return; |
604 | mAttachments.append(attachment); | 611 | mAttachments.append(attachment); |
605 | updated(); | 612 | updated(); |
606 | } | 613 | } |
607 | 614 | ||
608 | void Incidence::deleteAttachment(Attachment *attachment) | 615 | void Incidence::deleteAttachment(Attachment *attachment) |
609 | { | 616 | { |
610 | mAttachments.removeRef(attachment); | 617 | mAttachments.removeRef(attachment); |
611 | } | 618 | } |
612 | 619 | ||
613 | void Incidence::deleteAttachments(const QString& mime) | 620 | void Incidence::deleteAttachments(const QString& mime) |
614 | { | 621 | { |
615 | Attachment *at = mAttachments.first(); | 622 | Attachment *at = mAttachments.first(); |
616 | while (at) { | 623 | while (at) { |
617 | if (at->mimeType() == mime) | 624 | if (at->mimeType() == mime) |
618 | mAttachments.remove(); | 625 | mAttachments.remove(); |
619 | else | 626 | else |
620 | at = mAttachments.next(); | 627 | at = mAttachments.next(); |
621 | } | 628 | } |
622 | } | 629 | } |
623 | 630 | ||
624 | QPtrList<Attachment> Incidence::attachments() const | 631 | QPtrList<Attachment> Incidence::attachments() const |
625 | { | 632 | { |
626 | return mAttachments; | 633 | return mAttachments; |
627 | } | 634 | } |
628 | 635 | ||
629 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 636 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
630 | { | 637 | { |
631 | QPtrList<Attachment> attachments; | 638 | QPtrList<Attachment> attachments; |
632 | QPtrListIterator<Attachment> it( mAttachments ); | 639 | QPtrListIterator<Attachment> it( mAttachments ); |
633 | Attachment *at; | 640 | Attachment *at; |
634 | while ( (at = it.current()) ) { | 641 | while ( (at = it.current()) ) { |
635 | if (at->mimeType() == mime) | 642 | if (at->mimeType() == mime) |
636 | attachments.append(at); | 643 | attachments.append(at); |
637 | ++it; | 644 | ++it; |
638 | } | 645 | } |
639 | 646 | ||
640 | return attachments; | 647 | return attachments; |
641 | } | 648 | } |
642 | 649 | ||
643 | void Incidence::setResources(const QStringList &resources) | 650 | void Incidence::setResources(const QStringList &resources) |
644 | { | 651 | { |
645 | if (mReadOnly) return; | 652 | if (mReadOnly) return; |
646 | mResources = resources; | 653 | mResources = resources; |
647 | updated(); | 654 | updated(); |
648 | } | 655 | } |
649 | 656 | ||
650 | QStringList Incidence::resources() const | 657 | QStringList Incidence::resources() const |
651 | { | 658 | { |
652 | return mResources; | 659 | return mResources; |
653 | } | 660 | } |
654 | 661 | ||
655 | 662 | ||
656 | void Incidence::setPriority(int priority) | 663 | void Incidence::setPriority(int priority) |
657 | { | 664 | { |
658 | if (mReadOnly) return; | 665 | if (mReadOnly) return; |
659 | mPriority = priority; | 666 | mPriority = priority; |
660 | updated(); | 667 | updated(); |
661 | } | 668 | } |
662 | 669 | ||
663 | int Incidence::priority() const | 670 | int Incidence::priority() const |
664 | { | 671 | { |
665 | return mPriority; | 672 | return mPriority; |
666 | } | 673 | } |
667 | 674 | ||
668 | void Incidence::setSecrecy(int sec) | 675 | void Incidence::setSecrecy(int sec) |
669 | { | 676 | { |
670 | if (mReadOnly) return; | 677 | if (mReadOnly) return; |
671 | mSecrecy = sec; | 678 | mSecrecy = sec; |
672 | updated(); | 679 | updated(); |
673 | } | 680 | } |
674 | 681 | ||
675 | int Incidence::secrecy() const | 682 | int Incidence::secrecy() const |
676 | { | 683 | { |
677 | return mSecrecy; | 684 | return mSecrecy; |
678 | } | 685 | } |
679 | 686 | ||
680 | QString Incidence::secrecyStr() const | 687 | QString Incidence::secrecyStr() const |
681 | { | 688 | { |
682 | return secrecyName(mSecrecy); | 689 | return secrecyName(mSecrecy); |
683 | } | 690 | } |
684 | 691 | ||
685 | QString Incidence::secrecyName(int secrecy) | 692 | QString Incidence::secrecyName(int secrecy) |
686 | { | 693 | { |
687 | switch (secrecy) { | 694 | switch (secrecy) { |
688 | case SecrecyPublic: | 695 | case SecrecyPublic: |
689 | return i18n("Public"); | 696 | return i18n("Public"); |
690 | break; | 697 | break; |
691 | case SecrecyPrivate: | 698 | case SecrecyPrivate: |
692 | return i18n("Private"); | 699 | return i18n("Private"); |
693 | break; | 700 | break; |
694 | case SecrecyConfidential: | 701 | case SecrecyConfidential: |
695 | return i18n("Confidential"); | 702 | return i18n("Confidential"); |
696 | break; | 703 | break; |
697 | default: | 704 | default: |
698 | return i18n("Undefined"); | 705 | return i18n("Undefined"); |
699 | break; | 706 | break; |
700 | } | 707 | } |
701 | } | 708 | } |
702 | 709 | ||
703 | QStringList Incidence::secrecyList() | 710 | QStringList Incidence::secrecyList() |
704 | { | 711 | { |
705 | QStringList list; | 712 | QStringList list; |
706 | list << secrecyName(SecrecyPublic); | 713 | list << secrecyName(SecrecyPublic); |
707 | list << secrecyName(SecrecyPrivate); | 714 | list << secrecyName(SecrecyPrivate); |
708 | list << secrecyName(SecrecyConfidential); | 715 | list << secrecyName(SecrecyConfidential); |
709 | 716 | ||
710 | return list; | 717 | return list; |
711 | } | 718 | } |
712 | 719 | ||
713 | 720 | ||
714 | QPtrList<Alarm> Incidence::alarms() const | 721 | QPtrList<Alarm> Incidence::alarms() const |
715 | { | 722 | { |
716 | return mAlarms; | 723 | return mAlarms; |
717 | } | 724 | } |
718 | 725 | ||
719 | Alarm* Incidence::newAlarm() | 726 | Alarm* Incidence::newAlarm() |
720 | { | 727 | { |
721 | Alarm* alarm = new Alarm(this); | 728 | Alarm* alarm = new Alarm(this); |
722 | mAlarms.append(alarm); | 729 | mAlarms.append(alarm); |
723 | // updated(); | 730 | // updated(); |
724 | return alarm; | 731 | return alarm; |
725 | } | 732 | } |
726 | 733 | ||
727 | void Incidence::addAlarm(Alarm *alarm) | 734 | void Incidence::addAlarm(Alarm *alarm) |
728 | { | 735 | { |
729 | mAlarms.append(alarm); | 736 | mAlarms.append(alarm); |
730 | updated(); | 737 | updated(); |
731 | } | 738 | } |
732 | 739 | ||
733 | void Incidence::removeAlarm(Alarm *alarm) | 740 | void Incidence::removeAlarm(Alarm *alarm) |
734 | { | 741 | { |
735 | mAlarms.removeRef(alarm); | 742 | mAlarms.removeRef(alarm); |
736 | updated(); | 743 | updated(); |
737 | } | 744 | } |
738 | 745 | ||
739 | void Incidence::clearAlarms() | 746 | void Incidence::clearAlarms() |
740 | { | 747 | { |
741 | mAlarms.clear(); | 748 | mAlarms.clear(); |
742 | updated(); | 749 | updated(); |
743 | } | 750 | } |
744 | 751 | ||
745 | bool Incidence::isAlarmEnabled() const | 752 | bool Incidence::isAlarmEnabled() const |
746 | { | 753 | { |
747 | Alarm* alarm; | 754 | Alarm* alarm; |
748 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 755 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
749 | if (alarm->enabled()) | 756 | if (alarm->enabled()) |
750 | return true; | 757 | return true; |
751 | } | 758 | } |
752 | return false; | 759 | return false; |
753 | } | 760 | } |
754 | #include <stdlib.h> | 761 | #include <stdlib.h> |
755 | Recurrence *Incidence::recurrence() | 762 | Recurrence *Incidence::recurrence() |
756 | { | 763 | { |
757 | if ( ! mRecurrence ) { | 764 | if ( ! mRecurrence ) { |
758 | mRecurrence = new Recurrence(this); | 765 | mRecurrence = new Recurrence(this); |
759 | mRecurrence->setRecurStart( dtStart() ); | 766 | mRecurrence->setRecurStart( dtStart() ); |
767 | mRecurrence->setRecurReadOnly( isReadOnly()); | ||
760 | //qDebug("creating new recurence "); | 768 | //qDebug("creating new recurence "); |
761 | //abort(); | 769 | //abort(); |
762 | } | 770 | } |
763 | return mRecurrence; | 771 | return mRecurrence; |
764 | } | 772 | } |
765 | void Incidence::setRecurrence( Recurrence * r) | 773 | void Incidence::setRecurrence( Recurrence * r) |
766 | { | 774 | { |
767 | if ( mRecurrence ) | 775 | if ( mRecurrence ) |
768 | delete mRecurrence; | 776 | delete mRecurrence; |
769 | mRecurrence = r; | 777 | mRecurrence = r; |
770 | } | 778 | } |
771 | 779 | ||
772 | void Incidence::setLocation(const QString &location) | 780 | void Incidence::setLocation(const QString &location) |
773 | { | 781 | { |
774 | if (mReadOnly) return; | 782 | if (mReadOnly) return; |
775 | mLocation = location; | 783 | mLocation = location; |
776 | updated(); | 784 | updated(); |
777 | } | 785 | } |
778 | 786 | ||
779 | QString Incidence::location() const | 787 | QString Incidence::location() const |
780 | { | 788 | { |
781 | return mLocation; | 789 | return mLocation; |
782 | } | 790 | } |
783 | QString Incidence::recurrenceText() const | 791 | QString Incidence::recurrenceText() const |
784 | { | 792 | { |
785 | if ( mRecurrence ) return mRecurrence->recurrenceText(); | 793 | if ( mRecurrence ) return mRecurrence->recurrenceText(); |
786 | return i18n("No"); | 794 | return i18n("No"); |
787 | } | 795 | } |
788 | 796 | ||
789 | ushort Incidence::doesRecur() const | 797 | ushort Incidence::doesRecur() const |
790 | { | 798 | { |
791 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 799 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
792 | else return Recurrence::rNone; | 800 | else return Recurrence::rNone; |
793 | } | 801 | } |
794 | 802 | ||
795 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 803 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
796 | { | 804 | { |
797 | QDateTime incidenceStart = dt; | 805 | QDateTime incidenceStart = dt; |
798 | *ok = false; | 806 | *ok = false; |
799 | if ( doesRecur() ) { | 807 | if ( doesRecur() ) { |
800 | bool last; | 808 | bool last; |
801 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); | 809 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); |
802 | int count = 0; | 810 | int count = 0; |
803 | if ( !last ) { | 811 | if ( !last ) { |
804 | while ( !last ) { | 812 | while ( !last ) { |
805 | ++count; | 813 | ++count; |
806 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); | 814 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); |
807 | if ( recursOn( incidenceStart.date() ) ) { | 815 | if ( recursOn( incidenceStart.date() ) ) { |
808 | last = true; // exit while llop | 816 | last = true; // exit while llop |
809 | } else { | 817 | } else { |
810 | if ( last ) { // no alarm on last recurrence | 818 | if ( last ) { // no alarm on last recurrence |
811 | return QDateTime (); | 819 | return QDateTime (); |
812 | } | 820 | } |
813 | int year = incidenceStart.date().year(); | 821 | int year = incidenceStart.date().year(); |
814 | // workaround for bug in recurrence | 822 | // workaround for bug in recurrence |
815 | if ( count == 100 || year < 1000 || year > 5000 ) { | 823 | if ( count == 100 || year < 1000 || year > 5000 ) { |
816 | return QDateTime (); | 824 | return QDateTime (); |
817 | } | 825 | } |
818 | incidenceStart = incidenceStart.addSecs( 1 ); | 826 | incidenceStart = incidenceStart.addSecs( 1 ); |
819 | } | 827 | } |
820 | } | 828 | } |
821 | } else { | 829 | } else { |
822 | return QDateTime (); | 830 | return QDateTime (); |
823 | } | 831 | } |
824 | } else { | 832 | } else { |
825 | if ( hasStartDate () ) { | 833 | if ( hasStartDate () ) { |
826 | incidenceStart = dtStart(); | 834 | incidenceStart = dtStart(); |
827 | } | 835 | } |
828 | if ( typeID() == todoID ) { | 836 | if ( typeID() == todoID ) { |
829 | if ( ((Todo*)this)->hasDueDate() ) | 837 | if ( ((Todo*)this)->hasDueDate() ) |
830 | incidenceStart = ((Todo*)this)->dtDue(); | 838 | incidenceStart = ((Todo*)this)->dtDue(); |
831 | } | 839 | } |
832 | } | 840 | } |
833 | if ( incidenceStart > dt ) | 841 | if ( incidenceStart > dt ) |
834 | *ok = true; | 842 | *ok = true; |
835 | return incidenceStart; | 843 | return incidenceStart; |
836 | } | 844 | } |
837 | QDateTime Incidence::dtStart() const | 845 | QDateTime Incidence::dtStart() const |
838 | { | 846 | { |
839 | if ( doesRecur() ) { | 847 | if ( doesRecur() ) { |
840 | if ( typeID() == todoID ) { | 848 | if ( typeID() == todoID ) { |
841 | ((Todo*)this)->checkSetCompletedFalse(); | 849 | ((Todo*)this)->checkSetCompletedFalse(); |
842 | } | 850 | } |
843 | } | 851 | } |
844 | return mDtStart; | 852 | return mDtStart; |
845 | } | 853 | } |