author | zautrix <zautrix> | 2005-02-19 10:19:59 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-19 10:19:59 (UTC) |
commit | d2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3 (patch) (unidiff) | |
tree | d57e0a39b6c15b9108c260359fa19986e4823741 /libkcal | |
parent | 59a00e603e2ba14885e81c09daf3bb89859ff176 (diff) | |
download | kdepimpi-d2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3.zip kdepimpi-d2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3.tar.gz kdepimpi-d2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3.tar.bz2 |
duration fix
-rw-r--r-- | libkcal/icalformatimpl.cpp | 31 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 11 |
2 files changed, 25 insertions, 17 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp index 2e38ae3..eae41aa 100644 --- a/libkcal/icalformatimpl.cpp +++ b/libkcal/icalformatimpl.cpp | |||
@@ -1,2164 +1,2165 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qdatetime.h> | 21 | #include <qdatetime.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qptrlist.h> | 23 | #include <qptrlist.h> |
24 | #include <qfile.h> | 24 | #include <qfile.h> |
25 | 25 | ||
26 | #include <kdebug.h> | 26 | #include <kdebug.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | #include <kglobal.h> | 28 | #include <kglobal.h> |
29 | 29 | ||
30 | extern "C" { | 30 | extern "C" { |
31 | #include <ical.h> | 31 | #include <ical.h> |
32 | #include <icalss.h> | 32 | #include <icalss.h> |
33 | #include <icalparser.h> | 33 | #include <icalparser.h> |
34 | #include <icalrestriction.h> | 34 | #include <icalrestriction.h> |
35 | } | 35 | } |
36 | 36 | ||
37 | #include "calendar.h" | 37 | #include "calendar.h" |
38 | #include "journal.h" | 38 | #include "journal.h" |
39 | #include "icalformat.h" | 39 | #include "icalformat.h" |
40 | #include "icalformatimpl.h" | 40 | #include "icalformatimpl.h" |
41 | #include "compat.h" | 41 | #include "compat.h" |
42 | 42 | ||
43 | #define _ICAL_VERSION "2.0" | 43 | #define _ICAL_VERSION "2.0" |
44 | 44 | ||
45 | using namespace KCal; | 45 | using namespace KCal; |
46 | 46 | ||
47 | const int gSecondsPerMinute = 60; | 47 | const int gSecondsPerMinute = 60; |
48 | const int gSecondsPerHour = gSecondsPerMinute * 60; | 48 | const int gSecondsPerHour = gSecondsPerMinute * 60; |
49 | const int gSecondsPerDay = gSecondsPerHour * 24; | 49 | const int gSecondsPerDay = gSecondsPerHour * 24; |
50 | const int gSecondsPerWeek = gSecondsPerDay * 7; | 50 | const int gSecondsPerWeek = gSecondsPerDay * 7; |
51 | 51 | ||
52 | ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : | 52 | ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : |
53 | mParent( parent ), mCalendarVersion( 0 ) | 53 | mParent( parent ), mCalendarVersion( 0 ) |
54 | { | 54 | { |
55 | mCompat = new Compat; | 55 | mCompat = new Compat; |
56 | } | 56 | } |
57 | 57 | ||
58 | ICalFormatImpl::~ICalFormatImpl() | 58 | ICalFormatImpl::~ICalFormatImpl() |
59 | { | 59 | { |
60 | delete mCompat; | 60 | delete mCompat; |
61 | } | 61 | } |
62 | 62 | ||
63 | class ToStringVisitor : public Incidence::Visitor | 63 | class ToStringVisitor : public Incidence::Visitor |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} | 66 | ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} |
67 | 67 | ||
68 | bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } | 68 | bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } |
69 | bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } | 69 | bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } |
70 | bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } | 70 | bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } |
71 | 71 | ||
72 | icalcomponent *component() { return mComponent; } | 72 | icalcomponent *component() { return mComponent; } |
73 | 73 | ||
74 | private: | 74 | private: |
75 | ICalFormatImpl *mImpl; | 75 | ICalFormatImpl *mImpl; |
76 | icalcomponent *mComponent; | 76 | icalcomponent *mComponent; |
77 | }; | 77 | }; |
78 | 78 | ||
79 | icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) | 79 | icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) |
80 | { | 80 | { |
81 | ToStringVisitor v( this ); | 81 | ToStringVisitor v( this ); |
82 | incidence->accept(v); | 82 | incidence->accept(v); |
83 | return v.component(); | 83 | return v.component(); |
84 | } | 84 | } |
85 | 85 | ||
86 | icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) | 86 | icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) |
87 | { | 87 | { |
88 | QString tmpStr; | 88 | QString tmpStr; |
89 | QStringList tmpStrList; | 89 | QStringList tmpStrList; |
90 | 90 | ||
91 | icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); | 91 | icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); |
92 | 92 | ||
93 | writeIncidence(vtodo,todo); | 93 | writeIncidence(vtodo,todo); |
94 | 94 | ||
95 | // due date | 95 | // due date |
96 | if (todo->hasDueDate()) { | 96 | if (todo->hasDueDate()) { |
97 | icaltimetype due; | 97 | icaltimetype due; |
98 | if (todo->doesFloat()) { | 98 | if (todo->doesFloat()) { |
99 | due = writeICalDate(todo->dtDue().date()); | 99 | due = writeICalDate(todo->dtDue().date()); |
100 | } else { | 100 | } else { |
101 | due = writeICalDateTime(todo->dtDue()); | 101 | due = writeICalDateTime(todo->dtDue()); |
102 | } | 102 | } |
103 | icalcomponent_add_property(vtodo,icalproperty_new_due(due)); | 103 | icalcomponent_add_property(vtodo,icalproperty_new_due(due)); |
104 | } | 104 | } |
105 | 105 | ||
106 | // start time | 106 | // start time |
107 | if (todo->hasStartDate()) { | 107 | if (todo->hasStartDate()) { |
108 | icaltimetype start; | 108 | icaltimetype start; |
109 | if (todo->doesFloat()) { | 109 | if (todo->doesFloat()) { |
110 | // kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; | 110 | // kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; |
111 | start = writeICalDate(todo->dtStart().date()); | 111 | start = writeICalDate(todo->dtStart().date()); |
112 | } else { | 112 | } else { |
113 | // kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; | 113 | // kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; |
114 | start = writeICalDateTime(todo->dtStart()); | 114 | start = writeICalDateTime(todo->dtStart()); |
115 | } | 115 | } |
116 | icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); | 116 | icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); |
117 | } | 117 | } |
118 | 118 | ||
119 | // completion date | 119 | // completion date |
120 | if (todo->isCompleted()) { | 120 | if (todo->isCompleted()) { |
121 | if (!todo->hasCompletedDate()) { | 121 | if (!todo->hasCompletedDate()) { |
122 | // If todo was created by KOrganizer <2.2 it has no correct completion | 122 | // If todo was created by KOrganizer <2.2 it has no correct completion |
123 | // date. Set it to now. | 123 | // date. Set it to now. |
124 | todo->setCompleted(QDateTime::currentDateTime()); | 124 | todo->setCompleted(QDateTime::currentDateTime()); |
125 | } | 125 | } |
126 | icaltimetype completed = writeICalDateTime(todo->completed()); | 126 | icaltimetype completed = writeICalDateTime(todo->completed()); |
127 | icalcomponent_add_property(vtodo,icalproperty_new_completed(completed)); | 127 | icalcomponent_add_property(vtodo,icalproperty_new_completed(completed)); |
128 | } | 128 | } |
129 | 129 | ||
130 | icalcomponent_add_property(vtodo, | 130 | icalcomponent_add_property(vtodo, |
131 | icalproperty_new_percentcomplete(todo->percentComplete())); | 131 | icalproperty_new_percentcomplete(todo->percentComplete())); |
132 | 132 | ||
133 | return vtodo; | 133 | return vtodo; |
134 | } | 134 | } |
135 | 135 | ||
136 | icalcomponent *ICalFormatImpl::writeEvent(Event *event) | 136 | icalcomponent *ICalFormatImpl::writeEvent(Event *event) |
137 | { | 137 | { |
138 | kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() | 138 | kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() |
139 | << ")" << endl; | 139 | << ")" << endl; |
140 | 140 | ||
141 | QString tmpStr; | 141 | QString tmpStr; |
142 | QStringList tmpStrList; | 142 | QStringList tmpStrList; |
143 | 143 | ||
144 | icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); | 144 | icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); |
145 | 145 | ||
146 | writeIncidence(vevent,event); | 146 | writeIncidence(vevent,event); |
147 | 147 | ||
148 | // start time | 148 | // start time |
149 | icaltimetype start; | 149 | icaltimetype start; |
150 | if (event->doesFloat()) { | 150 | if (event->doesFloat()) { |
151 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; | 151 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; |
152 | start = writeICalDate(event->dtStart().date()); | 152 | start = writeICalDate(event->dtStart().date()); |
153 | } else { | 153 | } else { |
154 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; | 154 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; |
155 | start = writeICalDateTime(event->dtStart()); | 155 | start = writeICalDateTime(event->dtStart()); |
156 | } | 156 | } |
157 | icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); | 157 | icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); |
158 | 158 | ||
159 | if (event->hasEndDate()) { | 159 | if (event->hasEndDate()) { |
160 | // end time | 160 | // end time |
161 | icaltimetype end; | 161 | icaltimetype end; |
162 | if (event->doesFloat()) { | 162 | if (event->doesFloat()) { |
163 | // kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; | 163 | // kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; |
164 | // +1 day because end date is non-inclusive. | 164 | // +1 day because end date is non-inclusive. |
165 | end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); | 165 | end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); |
166 | } else { | 166 | } else { |
167 | // kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; | 167 | // kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; |
168 | end = writeICalDateTime(event->dtEnd()); | 168 | end = writeICalDateTime(event->dtEnd()); |
169 | } | 169 | } |
170 | icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); | 170 | icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); |
171 | } | 171 | } |
172 | 172 | ||
173 | // TODO: attachments, resources | 173 | // TODO: attachments, resources |
174 | #if 0 | 174 | #if 0 |
175 | // attachments | 175 | // attachments |
176 | tmpStrList = anEvent->attachments(); | 176 | tmpStrList = anEvent->attachments(); |
177 | for ( QStringList::Iterator it = tmpStrList.begin(); | 177 | for ( QStringList::Iterator it = tmpStrList.begin(); |
178 | it != tmpStrList.end(); | 178 | it != tmpStrList.end(); |
179 | ++it ) | 179 | ++it ) |
180 | addPropValue(vevent, VCAttachProp, (*it).utf8()); | 180 | addPropValue(vevent, VCAttachProp, (*it).utf8()); |
181 | 181 | ||
182 | // resources | 182 | // resources |
183 | tmpStrList = anEvent->resources(); | 183 | tmpStrList = anEvent->resources(); |
184 | tmpStr = tmpStrList.join(";"); | 184 | tmpStr = tmpStrList.join(";"); |
185 | if (!tmpStr.isEmpty()) | 185 | if (!tmpStr.isEmpty()) |
186 | addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); | 186 | addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); |
187 | 187 | ||
188 | #endif | 188 | #endif |
189 | 189 | ||
190 | // Transparency | 190 | // Transparency |
191 | switch( event->transparency() ) { | 191 | switch( event->transparency() ) { |
192 | case Event::Transparent: | 192 | case Event::Transparent: |
193 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); | 193 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); |
194 | break; | 194 | break; |
195 | case Event::Opaque: | 195 | case Event::Opaque: |
196 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); | 196 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); |
197 | break; | 197 | break; |
198 | } | 198 | } |
199 | 199 | ||
200 | return vevent; | 200 | return vevent; |
201 | } | 201 | } |
202 | 202 | ||
203 | icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, | 203 | icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, |
204 | Scheduler::Method method) | 204 | Scheduler::Method method) |
205 | { | 205 | { |
206 | 206 | ||
207 | 207 | ||
208 | icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); | 208 | icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); |
209 | 209 | ||
210 | writeIncidenceBase(vfreebusy,freebusy); | 210 | writeIncidenceBase(vfreebusy,freebusy); |
211 | 211 | ||
212 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( | 212 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( |
213 | writeICalDateTime(freebusy->dtStart()))); | 213 | writeICalDateTime(freebusy->dtStart()))); |
214 | 214 | ||
215 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( | 215 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( |
216 | writeICalDateTime(freebusy->dtEnd()))); | 216 | writeICalDateTime(freebusy->dtEnd()))); |
217 | 217 | ||
218 | if (method == Scheduler::Request) { | 218 | if (method == Scheduler::Request) { |
219 | icalcomponent_add_property(vfreebusy,icalproperty_new_uid( | 219 | icalcomponent_add_property(vfreebusy,icalproperty_new_uid( |
220 | freebusy->uid().utf8())); | 220 | freebusy->uid().utf8())); |
221 | } | 221 | } |
222 | 222 | ||
223 | //Loops through all the periods in the freebusy object | 223 | //Loops through all the periods in the freebusy object |
224 | QValueList<Period> list = freebusy->busyPeriods(); | 224 | QValueList<Period> list = freebusy->busyPeriods(); |
225 | QValueList<Period>::Iterator it; | 225 | QValueList<Period>::Iterator it; |
226 | icalperiodtype period; | 226 | icalperiodtype period; |
227 | for (it = list.begin(); it!= list.end(); ++it) { | 227 | for (it = list.begin(); it!= list.end(); ++it) { |
228 | period.start = writeICalDateTime((*it).start()); | 228 | period.start = writeICalDateTime((*it).start()); |
229 | period.end = writeICalDateTime((*it).end()); | 229 | period.end = writeICalDateTime((*it).end()); |
230 | icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); | 230 | icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); |
231 | } | 231 | } |
232 | 232 | ||
233 | return vfreebusy; | 233 | return vfreebusy; |
234 | } | 234 | } |
235 | 235 | ||
236 | icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) | 236 | icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) |
237 | { | 237 | { |
238 | icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); | 238 | icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); |
239 | 239 | ||
240 | writeIncidence(vjournal,journal); | 240 | writeIncidence(vjournal,journal); |
241 | 241 | ||
242 | // start time | 242 | // start time |
243 | if (journal->dtStart().isValid()) { | 243 | if (journal->dtStart().isValid()) { |
244 | icaltimetype start; | 244 | icaltimetype start; |
245 | if (journal->doesFloat()) { | 245 | if (journal->doesFloat()) { |
246 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; | 246 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; |
247 | start = writeICalDate(journal->dtStart().date()); | 247 | start = writeICalDate(journal->dtStart().date()); |
248 | } else { | 248 | } else { |
249 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; | 249 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; |
250 | start = writeICalDateTime(journal->dtStart()); | 250 | start = writeICalDateTime(journal->dtStart()); |
251 | } | 251 | } |
252 | icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); | 252 | icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); |
253 | } | 253 | } |
254 | 254 | ||
255 | return vjournal; | 255 | return vjournal; |
256 | } | 256 | } |
257 | 257 | ||
258 | void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) | 258 | void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) |
259 | { | 259 | { |
260 | // pilot sync stuff | 260 | // pilot sync stuff |
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->relatedTo()) { | 369 | if (incidence->relatedTo()) { |
370 | icalcomponent_add_property(parent,icalproperty_new_relatedto( | 370 | icalcomponent_add_property(parent,icalproperty_new_relatedto( |
371 | incidence->relatedTo()->uid().utf8())); | 371 | incidence->relatedTo()->uid().utf8())); |
372 | } | 372 | } |
373 | 373 | ||
374 | // recurrence rule stuff | 374 | // recurrence rule stuff |
375 | Recurrence *recur = incidence->recurrence(); | 375 | Recurrence *recur = incidence->recurrence(); |
376 | if (recur->doesRecur()) { | 376 | if (recur->doesRecur()) { |
377 | 377 | ||
378 | icalcomponent_add_property(parent,writeRecurrenceRule(recur)); | 378 | icalcomponent_add_property(parent,writeRecurrenceRule(recur)); |
379 | } | 379 | } |
380 | 380 | ||
381 | // recurrence excpetion dates | 381 | // recurrence excpetion dates |
382 | DateList dateList = incidence->exDates(); | 382 | DateList dateList = incidence->exDates(); |
383 | DateList::ConstIterator exIt; | 383 | DateList::ConstIterator exIt; |
384 | for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { | 384 | for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { |
385 | icalcomponent_add_property(parent,icalproperty_new_exdate( | 385 | icalcomponent_add_property(parent,icalproperty_new_exdate( |
386 | writeICalDate(*exIt))); | 386 | writeICalDate(*exIt))); |
387 | } | 387 | } |
388 | 388 | ||
389 | // attachments | 389 | // attachments |
390 | QPtrList<Attachment> attachments = incidence->attachments(); | 390 | QPtrList<Attachment> attachments = incidence->attachments(); |
391 | for (Attachment *at = attachments.first(); at; at = attachments.next()) | 391 | for (Attachment *at = attachments.first(); at; at = attachments.next()) |
392 | icalcomponent_add_property(parent,writeAttachment(at)); | 392 | icalcomponent_add_property(parent,writeAttachment(at)); |
393 | 393 | ||
394 | // alarms | 394 | // alarms |
395 | QPtrList<Alarm> alarms = incidence->alarms(); | 395 | QPtrList<Alarm> alarms = incidence->alarms(); |
396 | Alarm* alarm; | 396 | Alarm* alarm; |
397 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 397 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
398 | if (alarm->enabled()) { | 398 | if (alarm->enabled()) { |
399 | kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; | 399 | kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; |
400 | icalcomponent_add_component(parent,writeAlarm(alarm)); | 400 | icalcomponent_add_component(parent,writeAlarm(alarm)); |
401 | } | 401 | } |
402 | } | 402 | } |
403 | if( incidence->hasRecurrenceID() ) { | 403 | if( incidence->hasRecurrenceID() ) { |
404 | icalcomponent_add_property(parent, | 404 | icalcomponent_add_property(parent, |
405 | icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); | 405 | icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); |
406 | } | 406 | } |
407 | // duration | 407 | // duration |
408 | 408 | ||
409 | // turned off as it always is set to PTS0 (and must not occur together with DTEND | 409 | // turned off as it always is set to PTS0 (and must not occur together with DTEND |
410 | 410 | ||
411 | // if (incidence->hasDuration()) { | 411 | if (incidence->hasDuration()) { |
412 | // icaldurationtype duration; | 412 | icaldurationtype duration; |
413 | // duration = writeICalDuration(incidence->duration()); | 413 | duration = writeICalDuration(incidence->duration()); |
414 | // icalcomponent_add_property(parent,icalproperty_new_duration(duration)); | 414 | icalcomponent_add_property(parent,icalproperty_new_duration(duration)); |
415 | // } | 415 | } |
416 | } | 416 | } |
417 | 417 | ||
418 | void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) | 418 | void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) |
419 | { | 419 | { |
420 | icalcomponent_add_property(parent,icalproperty_new_dtstamp( | 420 | icalcomponent_add_property(parent,icalproperty_new_dtstamp( |
421 | writeICalDateTime(QDateTime::currentDateTime()))); | 421 | writeICalDateTime(QDateTime::currentDateTime()))); |
422 | 422 | ||
423 | // organizer stuff | 423 | // organizer stuff |
424 | icalcomponent_add_property(parent,icalproperty_new_organizer( | 424 | icalcomponent_add_property(parent,icalproperty_new_organizer( |
425 | ("MAILTO:" + incidenceBase->organizer()).utf8())); | 425 | ("MAILTO:" + incidenceBase->organizer()).utf8())); |
426 | 426 | ||
427 | // attendees | 427 | // attendees |
428 | if (incidenceBase->attendeeCount() != 0) { | 428 | if (incidenceBase->attendeeCount() != 0) { |
429 | QPtrList<Attendee> al = incidenceBase->attendees(); | 429 | QPtrList<Attendee> al = incidenceBase->attendees(); |
430 | QPtrListIterator<Attendee> ai(al); | 430 | QPtrListIterator<Attendee> ai(al); |
431 | for (; ai.current(); ++ai) { | 431 | for (; ai.current(); ++ai) { |
432 | icalcomponent_add_property(parent,writeAttendee(ai.current())); | 432 | icalcomponent_add_property(parent,writeAttendee(ai.current())); |
433 | } | 433 | } |
434 | } | 434 | } |
435 | 435 | ||
436 | // custom properties | 436 | // custom properties |
437 | writeCustomProperties(parent, incidenceBase); | 437 | writeCustomProperties(parent, incidenceBase); |
438 | } | 438 | } |
439 | 439 | ||
440 | void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) | 440 | void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) |
441 | { | 441 | { |
442 | QMap<QCString, QString> custom = properties->customProperties(); | 442 | QMap<QCString, QString> custom = properties->customProperties(); |
443 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { | 443 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { |
444 | icalproperty *p = icalproperty_new_x(c.data().utf8()); | 444 | icalproperty *p = icalproperty_new_x(c.data().utf8()); |
445 | icalproperty_set_x_name(p,c.key()); | 445 | icalproperty_set_x_name(p,c.key()); |
446 | icalcomponent_add_property(parent,p); | 446 | icalcomponent_add_property(parent,p); |
447 | } | 447 | } |
448 | } | 448 | } |
449 | 449 | ||
450 | icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) | 450 | icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) |
451 | { | 451 | { |
452 | icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); | 452 | icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); |
453 | 453 | ||
454 | if (!attendee->name().isEmpty()) { | 454 | if (!attendee->name().isEmpty()) { |
455 | icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); | 455 | icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); |
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||
459 | icalproperty_add_parameter(p,icalparameter_new_rsvp( | 459 | icalproperty_add_parameter(p,icalparameter_new_rsvp( |
460 | attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); | 460 | attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); |
461 | 461 | ||
462 | icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; | 462 | icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; |
463 | switch (attendee->status()) { | 463 | switch (attendee->status()) { |
464 | default: | 464 | default: |
465 | case Attendee::NeedsAction: | 465 | case Attendee::NeedsAction: |
466 | status = ICAL_PARTSTAT_NEEDSACTION; | 466 | status = ICAL_PARTSTAT_NEEDSACTION; |
467 | break; | 467 | break; |
468 | case Attendee::Accepted: | 468 | case Attendee::Accepted: |
469 | status = ICAL_PARTSTAT_ACCEPTED; | 469 | status = ICAL_PARTSTAT_ACCEPTED; |
470 | break; | 470 | break; |
471 | case Attendee::Declined: | 471 | case Attendee::Declined: |
472 | status = ICAL_PARTSTAT_DECLINED; | 472 | status = ICAL_PARTSTAT_DECLINED; |
473 | break; | 473 | break; |
474 | case Attendee::Tentative: | 474 | case Attendee::Tentative: |
475 | status = ICAL_PARTSTAT_TENTATIVE; | 475 | status = ICAL_PARTSTAT_TENTATIVE; |
476 | break; | 476 | break; |
477 | case Attendee::Delegated: | 477 | case Attendee::Delegated: |
478 | status = ICAL_PARTSTAT_DELEGATED; | 478 | status = ICAL_PARTSTAT_DELEGATED; |
479 | break; | 479 | break; |
480 | case Attendee::Completed: | 480 | case Attendee::Completed: |
481 | status = ICAL_PARTSTAT_COMPLETED; | 481 | status = ICAL_PARTSTAT_COMPLETED; |
482 | break; | 482 | break; |
483 | case Attendee::InProcess: | 483 | case Attendee::InProcess: |
484 | status = ICAL_PARTSTAT_INPROCESS; | 484 | status = ICAL_PARTSTAT_INPROCESS; |
485 | break; | 485 | break; |
486 | } | 486 | } |
487 | icalproperty_add_parameter(p,icalparameter_new_partstat(status)); | 487 | icalproperty_add_parameter(p,icalparameter_new_partstat(status)); |
488 | 488 | ||
489 | icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; | 489 | icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; |
490 | switch (attendee->role()) { | 490 | switch (attendee->role()) { |
491 | case Attendee::Chair: | 491 | case Attendee::Chair: |
492 | role = ICAL_ROLE_CHAIR; | 492 | role = ICAL_ROLE_CHAIR; |
493 | break; | 493 | break; |
494 | default: | 494 | default: |
495 | case Attendee::ReqParticipant: | 495 | case Attendee::ReqParticipant: |
496 | role = ICAL_ROLE_REQPARTICIPANT; | 496 | role = ICAL_ROLE_REQPARTICIPANT; |
497 | break; | 497 | break; |
498 | case Attendee::OptParticipant: | 498 | case Attendee::OptParticipant: |
499 | role = ICAL_ROLE_OPTPARTICIPANT; | 499 | role = ICAL_ROLE_OPTPARTICIPANT; |
500 | break; | 500 | break; |
501 | case Attendee::NonParticipant: | 501 | case Attendee::NonParticipant: |
502 | role = ICAL_ROLE_NONPARTICIPANT; | 502 | role = ICAL_ROLE_NONPARTICIPANT; |
503 | break; | 503 | break; |
504 | } | 504 | } |
505 | icalproperty_add_parameter(p,icalparameter_new_role(role)); | 505 | icalproperty_add_parameter(p,icalparameter_new_role(role)); |
506 | 506 | ||
507 | if (!attendee->uid().isEmpty()) { | 507 | if (!attendee->uid().isEmpty()) { |
508 | icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); | 508 | icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); |
509 | icalparameter_set_xname(icalparameter_uid,"X-UID"); | 509 | icalparameter_set_xname(icalparameter_uid,"X-UID"); |
510 | icalproperty_add_parameter(p,icalparameter_uid); | 510 | icalproperty_add_parameter(p,icalparameter_uid); |
511 | } | 511 | } |
512 | 512 | ||
513 | return p; | 513 | return p; |
514 | } | 514 | } |
515 | 515 | ||
516 | icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) | 516 | icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) |
517 | { | 517 | { |
518 | #if 0 | 518 | #if 0 |
519 | icalattachtype* attach = icalattachtype_new(); | 519 | icalattachtype* attach = icalattachtype_new(); |
520 | if (att->isURI()) | 520 | if (att->isURI()) |
521 | icalattachtype_set_url(attach, att->uri().utf8().data()); | 521 | icalattachtype_set_url(attach, att->uri().utf8().data()); |
522 | else | 522 | else |
523 | icalattachtype_set_base64(attach, att->data(), 0); | 523 | icalattachtype_set_base64(attach, att->data(), 0); |
524 | #endif | 524 | #endif |
525 | icalattach *attach; | 525 | icalattach *attach; |
526 | if (att->isURI()) | 526 | if (att->isURI()) |
527 | attach = icalattach_new_from_url( att->uri().utf8().data()); | 527 | attach = icalattach_new_from_url( att->uri().utf8().data()); |
528 | else | 528 | else |
529 | attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); | 529 | attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); |
530 | icalproperty *p = icalproperty_new_attach(attach); | 530 | icalproperty *p = icalproperty_new_attach(attach); |
531 | if (!att->mimeType().isEmpty()) | 531 | if (!att->mimeType().isEmpty()) |
532 | icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); | 532 | icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); |
533 | 533 | ||
534 | if (att->isBinary()) { | 534 | if (att->isBinary()) { |
535 | icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); | 535 | icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); |
536 | icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); | 536 | icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); |
537 | } | 537 | } |
538 | return p; | 538 | return p; |
539 | } | 539 | } |
540 | 540 | ||
541 | icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) | 541 | icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) |
542 | { | 542 | { |
543 | // kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; | 543 | // kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; |
544 | 544 | ||
545 | icalrecurrencetype r; | 545 | icalrecurrencetype r; |
546 | 546 | ||
547 | icalrecurrencetype_clear(&r); | 547 | icalrecurrencetype_clear(&r); |
548 | 548 | ||
549 | int index = 0; | 549 | int index = 0; |
550 | int index2 = 0; | 550 | int index2 = 0; |
551 | 551 | ||
552 | QPtrList<Recurrence::rMonthPos> tmpPositions; | 552 | QPtrList<Recurrence::rMonthPos> tmpPositions; |
553 | QPtrList<int> tmpDays; | 553 | QPtrList<int> tmpDays; |
554 | int *tmpDay; | 554 | int *tmpDay; |
555 | Recurrence::rMonthPos *tmpPos; | 555 | Recurrence::rMonthPos *tmpPos; |
556 | bool datetime = false; | 556 | bool datetime = false; |
557 | int day; | 557 | int day; |
558 | int i; | 558 | int i; |
559 | 559 | ||
560 | switch(recur->doesRecur()) { | 560 | switch(recur->doesRecur()) { |
561 | case Recurrence::rMinutely: | 561 | case Recurrence::rMinutely: |
562 | r.freq = ICAL_MINUTELY_RECURRENCE; | 562 | r.freq = ICAL_MINUTELY_RECURRENCE; |
563 | datetime = true; | 563 | datetime = true; |
564 | break; | 564 | break; |
565 | case Recurrence::rHourly: | 565 | case Recurrence::rHourly: |
566 | r.freq = ICAL_HOURLY_RECURRENCE; | 566 | r.freq = ICAL_HOURLY_RECURRENCE; |
567 | datetime = true; | 567 | datetime = true; |
568 | break; | 568 | break; |
569 | case Recurrence::rDaily: | 569 | case Recurrence::rDaily: |
570 | r.freq = ICAL_DAILY_RECURRENCE; | 570 | r.freq = ICAL_DAILY_RECURRENCE; |
571 | break; | 571 | break; |
572 | case Recurrence::rWeekly: | 572 | case Recurrence::rWeekly: |
573 | r.freq = ICAL_WEEKLY_RECURRENCE; | 573 | r.freq = ICAL_WEEKLY_RECURRENCE; |
574 | r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); | 574 | r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); |
575 | for (i = 0; i < 7; i++) { | 575 | for (i = 0; i < 7; i++) { |
576 | if (recur->days().testBit(i)) { | 576 | if (recur->days().testBit(i)) { |
577 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 577 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
578 | r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); | 578 | r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); |
579 | } | 579 | } |
580 | } | 580 | } |
581 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 581 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
582 | break; | 582 | break; |
583 | case Recurrence::rMonthlyPos: | 583 | case Recurrence::rMonthlyPos: |
584 | r.freq = ICAL_MONTHLY_RECURRENCE; | 584 | r.freq = ICAL_MONTHLY_RECURRENCE; |
585 | 585 | ||
586 | tmpPositions = recur->monthPositions(); | 586 | tmpPositions = recur->monthPositions(); |
587 | for (tmpPos = tmpPositions.first(); | 587 | for (tmpPos = tmpPositions.first(); |
588 | tmpPos; | 588 | tmpPos; |
589 | tmpPos = tmpPositions.next()) { | 589 | tmpPos = tmpPositions.next()) { |
590 | for (i = 0; i < 7; i++) { | 590 | for (i = 0; i < 7; i++) { |
591 | if (tmpPos->rDays.testBit(i)) { | 591 | if (tmpPos->rDays.testBit(i)) { |
592 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 592 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
593 | day += tmpPos->rPos*8; | 593 | day += tmpPos->rPos*8; |
594 | if (tmpPos->negative) day = -day; | 594 | if (tmpPos->negative) day = -day; |
595 | r.by_day[index++] = day; | 595 | r.by_day[index++] = day; |
596 | } | 596 | } |
597 | } | 597 | } |
598 | } | 598 | } |
599 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 599 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
600 | break; | 600 | break; |
601 | case Recurrence::rMonthlyDay: | 601 | case Recurrence::rMonthlyDay: |
602 | r.freq = ICAL_MONTHLY_RECURRENCE; | 602 | r.freq = ICAL_MONTHLY_RECURRENCE; |
603 | 603 | ||
604 | tmpDays = recur->monthDays(); | 604 | tmpDays = recur->monthDays(); |
605 | for (tmpDay = tmpDays.first(); | 605 | for (tmpDay = tmpDays.first(); |
606 | tmpDay; | 606 | tmpDay; |
607 | tmpDay = tmpDays.next()) { | 607 | tmpDay = tmpDays.next()) { |
608 | r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); | 608 | r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); |
609 | } | 609 | } |
610 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 610 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
611 | break; | 611 | break; |
612 | case Recurrence::rYearlyMonth: | 612 | case Recurrence::rYearlyMonth: |
613 | case Recurrence::rYearlyPos: | 613 | case Recurrence::rYearlyPos: |
614 | r.freq = ICAL_YEARLY_RECURRENCE; | 614 | r.freq = ICAL_YEARLY_RECURRENCE; |
615 | 615 | ||
616 | tmpDays = recur->yearNums(); | 616 | tmpDays = recur->yearNums(); |
617 | for (tmpDay = tmpDays.first(); | 617 | for (tmpDay = tmpDays.first(); |
618 | tmpDay; | 618 | tmpDay; |
619 | tmpDay = tmpDays.next()) { | 619 | tmpDay = tmpDays.next()) { |
620 | r.by_month[index++] = *tmpDay; | 620 | r.by_month[index++] = *tmpDay; |
621 | } | 621 | } |
622 | // r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; | 622 | // r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; |
623 | if (recur->doesRecur() == Recurrence::rYearlyPos) { | 623 | if (recur->doesRecur() == Recurrence::rYearlyPos) { |
624 | tmpPositions = recur->monthPositions(); | 624 | tmpPositions = recur->monthPositions(); |
625 | for (tmpPos = tmpPositions.first(); | 625 | for (tmpPos = tmpPositions.first(); |
626 | tmpPos; | 626 | tmpPos; |
627 | tmpPos = tmpPositions.next()) { | 627 | tmpPos = tmpPositions.next()) { |
628 | for (i = 0; i < 7; i++) { | 628 | for (i = 0; i < 7; i++) { |
629 | if (tmpPos->rDays.testBit(i)) { | 629 | if (tmpPos->rDays.testBit(i)) { |
630 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 630 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
631 | day += tmpPos->rPos*8; | 631 | day += tmpPos->rPos*8; |
632 | if (tmpPos->negative) day = -day; | 632 | if (tmpPos->negative) day = -day; |
633 | r.by_day[index2++] = day; | 633 | r.by_day[index2++] = day; |
634 | } | 634 | } |
635 | } | 635 | } |
636 | } | 636 | } |
637 | // r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; | 637 | // r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; |
638 | } | 638 | } |
639 | break; | 639 | break; |
640 | case Recurrence::rYearlyDay: | 640 | case Recurrence::rYearlyDay: |
641 | r.freq = ICAL_YEARLY_RECURRENCE; | 641 | r.freq = ICAL_YEARLY_RECURRENCE; |
642 | 642 | ||
643 | tmpDays = recur->yearNums(); | 643 | tmpDays = recur->yearNums(); |
644 | for (tmpDay = tmpDays.first(); | 644 | for (tmpDay = tmpDays.first(); |
645 | tmpDay; | 645 | tmpDay; |
646 | tmpDay = tmpDays.next()) { | 646 | tmpDay = tmpDays.next()) { |
647 | r.by_year_day[index++] = *tmpDay; | 647 | r.by_year_day[index++] = *tmpDay; |
648 | } | 648 | } |
649 | // r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 649 | // r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
650 | break; | 650 | break; |
651 | default: | 651 | default: |
652 | r.freq = ICAL_NO_RECURRENCE; | 652 | r.freq = ICAL_NO_RECURRENCE; |
653 | kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; | 653 | kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; |
654 | break; | 654 | break; |
655 | } | 655 | } |
656 | 656 | ||
657 | r.interval = recur->frequency(); | 657 | r.interval = recur->frequency(); |
658 | 658 | ||
659 | if (recur->duration() > 0) { | 659 | if (recur->duration() > 0) { |
660 | r.count = recur->duration(); | 660 | r.count = recur->duration(); |
661 | } else if (recur->duration() == -1) { | 661 | } else if (recur->duration() == -1) { |
662 | r.count = 0; | 662 | r.count = 0; |
663 | } else { | 663 | } else { |
664 | if (datetime) | 664 | if (datetime) |
665 | r.until = writeICalDateTime(recur->endDateTime()); | 665 | r.until = writeICalDateTime(recur->endDateTime()); |
666 | else | 666 | else |
667 | r.until = writeICalDate(recur->endDate()); | 667 | r.until = writeICalDate(recur->endDate()); |
668 | } | 668 | } |
669 | 669 | ||
670 | // Debug output | 670 | // Debug output |
671 | #if 0 | 671 | #if 0 |
672 | const char *str = icalrecurrencetype_as_string(&r); | 672 | const char *str = icalrecurrencetype_as_string(&r); |
673 | if (str) { | 673 | if (str) { |
674 | kdDebug(5800) << " String: " << str << endl; | 674 | kdDebug(5800) << " String: " << str << endl; |
675 | } else { | 675 | } else { |
676 | kdDebug(5800) << " No String" << endl; | 676 | kdDebug(5800) << " No String" << endl; |
677 | } | 677 | } |
678 | #endif | 678 | #endif |
679 | 679 | ||
680 | return icalproperty_new_rrule(r); | 680 | return icalproperty_new_rrule(r); |
681 | } | 681 | } |
682 | 682 | ||
683 | icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) | 683 | icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) |
684 | { | 684 | { |
685 | icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); | 685 | icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); |
686 | 686 | ||
687 | icalproperty_action action; | 687 | icalproperty_action action; |
688 | icalattach *attach = 0; | 688 | icalattach *attach = 0; |
689 | 689 | ||
690 | switch (alarm->type()) { | 690 | switch (alarm->type()) { |
691 | case Alarm::Procedure: | 691 | case Alarm::Procedure: |
692 | action = ICAL_ACTION_PROCEDURE; | 692 | action = ICAL_ACTION_PROCEDURE; |
693 | attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); | 693 | attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); |
694 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 694 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
695 | if (!alarm->programArguments().isEmpty()) { | 695 | if (!alarm->programArguments().isEmpty()) { |
696 | icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); | 696 | icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); |
697 | } | 697 | } |
698 | break; | 698 | break; |
699 | case Alarm::Audio: | 699 | case Alarm::Audio: |
700 | action = ICAL_ACTION_AUDIO; | 700 | action = ICAL_ACTION_AUDIO; |
701 | if (!alarm->audioFile().isEmpty()) { | 701 | if (!alarm->audioFile().isEmpty()) { |
702 | attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); | 702 | attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); |
703 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 703 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
704 | } | 704 | } |
705 | break; | 705 | break; |
706 | case Alarm::Email: { | 706 | case Alarm::Email: { |
707 | action = ICAL_ACTION_EMAIL; | 707 | action = ICAL_ACTION_EMAIL; |
708 | QValueList<Person> addresses = alarm->mailAddresses(); | 708 | QValueList<Person> addresses = alarm->mailAddresses(); |
709 | for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { | 709 | for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { |
710 | icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); | 710 | icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); |
711 | if (!(*ad).name().isEmpty()) { | 711 | if (!(*ad).name().isEmpty()) { |
712 | icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); | 712 | icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); |
713 | } | 713 | } |
714 | icalcomponent_add_property(a,p); | 714 | icalcomponent_add_property(a,p); |
715 | } | 715 | } |
716 | icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); | 716 | icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); |
717 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); | 717 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); |
718 | QStringList attachments = alarm->mailAttachments(); | 718 | QStringList attachments = alarm->mailAttachments(); |
719 | if (attachments.count() > 0) { | 719 | if (attachments.count() > 0) { |
720 | for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { | 720 | for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { |
721 | attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); | 721 | attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); |
722 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 722 | icalcomponent_add_property(a,icalproperty_new_attach(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 | ||
780 | readIncidence(vtodo,todo); | 780 | readIncidence(vtodo,todo); |
781 | 781 | ||
782 | icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); | 782 | icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); |
783 | 783 | ||
784 | // int intvalue; | 784 | // int intvalue; |
785 | icaltimetype icaltime; | 785 | icaltimetype icaltime; |
786 | 786 | ||
787 | QStringList categories; | 787 | QStringList categories; |
788 | 788 | ||
789 | while (p) { | 789 | while (p) { |
790 | icalproperty_kind kind = icalproperty_isa(p); | 790 | icalproperty_kind kind = icalproperty_isa(p); |
791 | switch (kind) { | 791 | switch (kind) { |
792 | 792 | ||
793 | case ICAL_DUE_PROPERTY: // due date | 793 | case ICAL_DUE_PROPERTY: // due date |
794 | icaltime = icalproperty_get_due(p); | 794 | icaltime = icalproperty_get_due(p); |
795 | if (icaltime.is_date) { | 795 | if (icaltime.is_date) { |
796 | todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); | 796 | todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); |
797 | todo->setFloats(true); | 797 | todo->setFloats(true); |
798 | 798 | ||
799 | } else { | 799 | } else { |
800 | todo->setDtDue(readICalDateTime(icaltime)); | 800 | todo->setDtDue(readICalDateTime(icaltime)); |
801 | todo->setFloats(false); | 801 | todo->setFloats(false); |
802 | } | 802 | } |
803 | todo->setHasDueDate(true); | 803 | todo->setHasDueDate(true); |
804 | break; | 804 | break; |
805 | 805 | ||
806 | case ICAL_COMPLETED_PROPERTY: // completion date | 806 | case ICAL_COMPLETED_PROPERTY: // completion date |
807 | icaltime = icalproperty_get_completed(p); | 807 | icaltime = icalproperty_get_completed(p); |
808 | todo->setCompleted(readICalDateTime(icaltime)); | 808 | todo->setCompleted(readICalDateTime(icaltime)); |
809 | break; | 809 | break; |
810 | 810 | ||
811 | case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed | 811 | case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed |
812 | todo->setPercentComplete(icalproperty_get_percentcomplete(p)); | 812 | todo->setPercentComplete(icalproperty_get_percentcomplete(p)); |
813 | break; | 813 | break; |
814 | 814 | ||
815 | case ICAL_RELATEDTO_PROPERTY: // related todo (parent) | 815 | case ICAL_RELATEDTO_PROPERTY: // related todo (parent) |
816 | todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); | 816 | todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); |
817 | mTodosRelate.append(todo); | 817 | mTodosRelate.append(todo); |
818 | break; | 818 | break; |
819 | 819 | ||
820 | case ICAL_DTSTART_PROPERTY: | 820 | case ICAL_DTSTART_PROPERTY: |
821 | // Flag that todo has start date. Value is read in by readIncidence(). | 821 | // Flag that todo has start date. Value is read in by readIncidence(). |
822 | todo->setHasStartDate(true); | 822 | todo->setHasStartDate(true); |
823 | break; | 823 | break; |
824 | 824 | ||
825 | default: | 825 | default: |
826 | // kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind | 826 | // kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind |
827 | // << endl; | 827 | // << endl; |
828 | break; | 828 | break; |
829 | } | 829 | } |
830 | 830 | ||
831 | p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); | 831 | p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); |
832 | } | 832 | } |
833 | 833 | ||
834 | return todo; | 834 | return todo; |
835 | } | 835 | } |
836 | 836 | ||
837 | Event *ICalFormatImpl::readEvent(icalcomponent *vevent) | 837 | Event *ICalFormatImpl::readEvent(icalcomponent *vevent) |
838 | { | 838 | { |
839 | Event *event = new Event; | 839 | Event *event = new Event; |
840 | event->setFloats(false); | 840 | event->setFloats(false); |
841 | 841 | ||
842 | readIncidence(vevent,event); | 842 | readIncidence(vevent,event); |
843 | 843 | ||
844 | icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); | 844 | icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); |
845 | 845 | ||
846 | // int intvalue; | 846 | // int intvalue; |
847 | icaltimetype icaltime; | 847 | icaltimetype icaltime; |
848 | 848 | ||
849 | QStringList categories; | 849 | QStringList categories; |
850 | QString transparency; | 850 | QString transparency; |
851 | 851 | ||
852 | while (p) { | 852 | while (p) { |
853 | icalproperty_kind kind = icalproperty_isa(p); | 853 | icalproperty_kind kind = icalproperty_isa(p); |
854 | switch (kind) { | 854 | switch (kind) { |
855 | 855 | ||
856 | case ICAL_DTEND_PROPERTY: // start date and time | 856 | case ICAL_DTEND_PROPERTY: // start date and time |
857 | icaltime = icalproperty_get_dtend(p); | 857 | icaltime = icalproperty_get_dtend(p); |
858 | if (icaltime.is_date) { | 858 | if (icaltime.is_date) { |
859 | event->setFloats( true ); | 859 | event->setFloats( true ); |
860 | // End date is non-inclusive | 860 | // End date is non-inclusive |
861 | QDate endDate = readICalDate( icaltime ).addDays( -1 ); | 861 | QDate endDate = readICalDate( icaltime ).addDays( -1 ); |
862 | mCompat->fixFloatingEnd( endDate ); | 862 | mCompat->fixFloatingEnd( endDate ); |
863 | if ( endDate < event->dtStart().date() ) { | 863 | if ( endDate < event->dtStart().date() ) { |
864 | endDate = event->dtStart().date(); | 864 | endDate = event->dtStart().date(); |
865 | } | 865 | } |
866 | event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); | 866 | event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); |
867 | } else { | 867 | } else { |
868 | event->setDtEnd(readICalDateTime(icaltime)); | 868 | event->setDtEnd(readICalDateTime(icaltime)); |
869 | } | 869 | } |
870 | break; | 870 | break; |
871 | 871 | ||
872 | // TODO: | 872 | // TODO: |
873 | // at this point, there should be at least a start or end time. | 873 | // at this point, there should be at least a start or end time. |
874 | // fix up for events that take up no time but have a time associated | 874 | // fix up for events that take up no time but have a time associated |
875 | #if 0 | 875 | #if 0 |
876 | if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) | 876 | if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) |
877 | anEvent->setDtStart(anEvent->dtEnd()); | 877 | anEvent->setDtStart(anEvent->dtEnd()); |
878 | if (!(vo = isAPropertyOf(vevent, VCDTendProp))) | 878 | if (!(vo = isAPropertyOf(vevent, VCDTendProp))) |
879 | anEvent->setDtEnd(anEvent->dtStart()); | 879 | anEvent->setDtEnd(anEvent->dtStart()); |
880 | #endif | 880 | #endif |
881 | 881 | ||
882 | // TODO: exdates | 882 | // TODO: exdates |
883 | #if 0 | 883 | #if 0 |
884 | // recurrence exceptions | 884 | // recurrence exceptions |
885 | if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { | 885 | if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { |
886 | anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); | 886 | anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); |
887 | deleteStr(s); | 887 | deleteStr(s); |
888 | } | 888 | } |
889 | #endif | 889 | #endif |
890 | 890 | ||
891 | #if 0 | 891 | #if 0 |
892 | // secrecy | 892 | // secrecy |
893 | if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { | 893 | if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { |
894 | anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); | 894 | anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); |
895 | deleteStr(s); | 895 | deleteStr(s); |
896 | } | 896 | } |
897 | else | 897 | else |
898 | anEvent->setSecrecy("PUBLIC"); | 898 | anEvent->setSecrecy("PUBLIC"); |
899 | 899 | ||
900 | // attachments | 900 | // attachments |
901 | tmpStrList.clear(); | 901 | tmpStrList.clear(); |
902 | initPropIterator(&voi, vevent); | 902 | initPropIterator(&voi, vevent); |
903 | while (moreIteration(&voi)) { | 903 | while (moreIteration(&voi)) { |
904 | vo = nextVObject(&voi); | 904 | vo = nextVObject(&voi); |
905 | if (strcmp(vObjectName(vo), VCAttachProp) == 0) { | 905 | if (strcmp(vObjectName(vo), VCAttachProp) == 0) { |
906 | tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); | 906 | tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); |
907 | deleteStr(s); | 907 | deleteStr(s); |
908 | } | 908 | } |
909 | } | 909 | } |
910 | anEvent->setAttachments(tmpStrList); | 910 | anEvent->setAttachments(tmpStrList); |
911 | 911 | ||
912 | // resources | 912 | // resources |
913 | if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { | 913 | if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { |
914 | QString resources = (s = fakeCString(vObjectUStringZValue(vo))); | 914 | QString resources = (s = fakeCString(vObjectUStringZValue(vo))); |
915 | deleteStr(s); | 915 | deleteStr(s); |
916 | tmpStrList.clear(); | 916 | tmpStrList.clear(); |
917 | index1 = 0; | 917 | index1 = 0; |
918 | index2 = 0; | 918 | index2 = 0; |
919 | QString resource; | 919 | QString resource; |
920 | while ((index2 = resources.find(';', index1)) != -1) { | 920 | while ((index2 = resources.find(';', index1)) != -1) { |
921 | resource = resources.mid(index1, (index2 - index1)); | 921 | resource = resources.mid(index1, (index2 - index1)); |
922 | tmpStrList.append(resource); | 922 | tmpStrList.append(resource); |
923 | index1 = index2; | 923 | index1 = index2; |
924 | } | 924 | } |
925 | anEvent->setResources(tmpStrList); | 925 | anEvent->setResources(tmpStrList); |
926 | } | 926 | } |
927 | #endif | 927 | #endif |
928 | 928 | ||
929 | case ICAL_RELATEDTO_PROPERTY: // releated event (parent) | 929 | case ICAL_RELATEDTO_PROPERTY: // releated event (parent) |
930 | event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); | 930 | event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); |
931 | mEventsRelate.append(event); | 931 | mEventsRelate.append(event); |
932 | break; | 932 | break; |
933 | 933 | ||
934 | case ICAL_TRANSP_PROPERTY: // Transparency | 934 | case ICAL_TRANSP_PROPERTY: // Transparency |
935 | if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT ) | 935 | if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT ) |
936 | event->setTransparency( Event::Transparent ); | 936 | event->setTransparency( Event::Transparent ); |
937 | else | 937 | else |
938 | event->setTransparency( Event::Opaque ); | 938 | event->setTransparency( Event::Opaque ); |
939 | break; | 939 | break; |
940 | 940 | ||
941 | default: | 941 | default: |
942 | // kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind | 942 | // kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind |
943 | // << endl; | 943 | // << endl; |
944 | break; | 944 | break; |
945 | } | 945 | } |
946 | 946 | ||
947 | p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); | 947 | p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); |
948 | } | 948 | } |
949 | 949 | ||
950 | QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); | 950 | QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); |
951 | if (!msade.isNull()) { | 951 | if (!msade.isNull()) { |
952 | bool floats = (msade == QString::fromLatin1("TRUE")); | 952 | bool floats = (msade == QString::fromLatin1("TRUE")); |
953 | kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; | 953 | kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; |
954 | event->setFloats(floats); | 954 | event->setFloats(floats); |
955 | if (floats) { | 955 | if (floats) { |
956 | QDateTime endDate = event->dtEnd(); | 956 | QDateTime endDate = event->dtEnd(); |
957 | event->setDtEnd(endDate.addDays(-1)); | 957 | event->setDtEnd(endDate.addDays(-1)); |
958 | } | 958 | } |
959 | } | 959 | } |
960 | 960 | ||
961 | // some stupid vCal exporters ignore the standard and use Description | 961 | // some stupid vCal exporters ignore the standard and use Description |
962 | // instead of Summary for the default field. Correct for this. | 962 | // instead of Summary for the default field. Correct for this. |
963 | if (event->summary().isEmpty() && | 963 | if (event->summary().isEmpty() && |
964 | !(event->description().isEmpty())) { | 964 | !(event->description().isEmpty())) { |
965 | QString tmpStr = event->description().simplifyWhiteSpace(); | 965 | QString tmpStr = event->description().simplifyWhiteSpace(); |
966 | event->setDescription(""); | 966 | event->setDescription(""); |
967 | event->setSummary(tmpStr); | 967 | event->setSummary(tmpStr); |
968 | } | 968 | } |
969 | 969 | ||
970 | return event; | 970 | return event; |
971 | } | 971 | } |
972 | 972 | ||
973 | FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) | 973 | FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) |
974 | { | 974 | { |
975 | FreeBusy *freebusy = new FreeBusy; | 975 | FreeBusy *freebusy = new FreeBusy; |
976 | 976 | ||
977 | readIncidenceBase(vfreebusy,freebusy); | 977 | readIncidenceBase(vfreebusy,freebusy); |
978 | 978 | ||
979 | icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); | 979 | icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); |
980 | 980 | ||
981 | icaltimetype icaltime; | 981 | icaltimetype icaltime; |
982 | icalperiodtype icalperiod; | 982 | icalperiodtype icalperiod; |
983 | QDateTime period_start, period_end; | 983 | QDateTime period_start, period_end; |
984 | 984 | ||
985 | while (p) { | 985 | while (p) { |
986 | icalproperty_kind kind = icalproperty_isa(p); | 986 | icalproperty_kind kind = icalproperty_isa(p); |
987 | switch (kind) { | 987 | switch (kind) { |
988 | 988 | ||
989 | case ICAL_DTSTART_PROPERTY: // start date and time | 989 | case ICAL_DTSTART_PROPERTY: // start date and time |
990 | icaltime = icalproperty_get_dtstart(p); | 990 | icaltime = icalproperty_get_dtstart(p); |
991 | freebusy->setDtStart(readICalDateTime(icaltime)); | 991 | freebusy->setDtStart(readICalDateTime(icaltime)); |
992 | break; | 992 | break; |
993 | 993 | ||
994 | case ICAL_DTEND_PROPERTY: // start End Date and Time | 994 | case ICAL_DTEND_PROPERTY: // start End Date and Time |
995 | icaltime = icalproperty_get_dtend(p); | 995 | icaltime = icalproperty_get_dtend(p); |
996 | freebusy->setDtEnd(readICalDateTime(icaltime)); | 996 | freebusy->setDtEnd(readICalDateTime(icaltime)); |
997 | break; | 997 | break; |
998 | 998 | ||
999 | case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times | 999 | case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times |
1000 | icalperiod = icalproperty_get_freebusy(p); | 1000 | icalperiod = icalproperty_get_freebusy(p); |
1001 | period_start = readICalDateTime(icalperiod.start); | 1001 | period_start = readICalDateTime(icalperiod.start); |
1002 | period_end = readICalDateTime(icalperiod.end); | 1002 | period_end = readICalDateTime(icalperiod.end); |
1003 | freebusy->addPeriod(period_start, period_end); | 1003 | freebusy->addPeriod(period_start, period_end); |
1004 | break; | 1004 | break; |
1005 | 1005 | ||
1006 | default: | 1006 | default: |
1007 | kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind | 1007 | kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind |
1008 | << endl; | 1008 | << endl; |
1009 | break; | 1009 | break; |
1010 | } | 1010 | } |
1011 | p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); | 1011 | p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); |
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | return freebusy; | 1014 | return freebusy; |
1015 | } | 1015 | } |
1016 | 1016 | ||
1017 | Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) | 1017 | Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) |
1018 | { | 1018 | { |
1019 | Journal *journal = new Journal; | 1019 | Journal *journal = new Journal; |
1020 | 1020 | ||
1021 | readIncidence(vjournal,journal); | 1021 | readIncidence(vjournal,journal); |
1022 | 1022 | ||
1023 | return journal; | 1023 | return journal; |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) | 1026 | Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) |
1027 | { | 1027 | { |
1028 | icalparameter *p = 0; | 1028 | icalparameter *p = 0; |
1029 | 1029 | ||
1030 | QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); | 1030 | QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); |
1031 | 1031 | ||
1032 | QString name; | 1032 | QString name; |
1033 | QString uid = QString::null; | 1033 | QString uid = QString::null; |
1034 | p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); | 1034 | p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); |
1035 | if (p) { | 1035 | if (p) { |
1036 | name = QString::fromUtf8(icalparameter_get_cn(p)); | 1036 | name = QString::fromUtf8(icalparameter_get_cn(p)); |
1037 | } else { | 1037 | } else { |
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | bool rsvp=false; | 1040 | bool rsvp=false; |
1041 | p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); | 1041 | p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); |
1042 | if (p) { | 1042 | if (p) { |
1043 | icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); | 1043 | icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); |
1044 | if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; | 1044 | if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; |
1045 | } | 1045 | } |
1046 | 1046 | ||
1047 | Attendee::PartStat status = Attendee::NeedsAction; | 1047 | Attendee::PartStat status = Attendee::NeedsAction; |
1048 | p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); | 1048 | p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); |
1049 | if (p) { | 1049 | if (p) { |
1050 | icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); | 1050 | icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); |
1051 | switch(partStatParameter) { | 1051 | switch(partStatParameter) { |
1052 | default: | 1052 | default: |
1053 | case ICAL_PARTSTAT_NEEDSACTION: | 1053 | case ICAL_PARTSTAT_NEEDSACTION: |
1054 | status = Attendee::NeedsAction; | 1054 | status = Attendee::NeedsAction; |
1055 | break; | 1055 | break; |
1056 | case ICAL_PARTSTAT_ACCEPTED: | 1056 | case ICAL_PARTSTAT_ACCEPTED: |
1057 | status = Attendee::Accepted; | 1057 | status = Attendee::Accepted; |
1058 | break; | 1058 | break; |
1059 | case ICAL_PARTSTAT_DECLINED: | 1059 | case ICAL_PARTSTAT_DECLINED: |
1060 | status = Attendee::Declined; | 1060 | status = Attendee::Declined; |
1061 | break; | 1061 | break; |
1062 | case ICAL_PARTSTAT_TENTATIVE: | 1062 | case ICAL_PARTSTAT_TENTATIVE: |
1063 | status = Attendee::Tentative; | 1063 | status = Attendee::Tentative; |
1064 | break; | 1064 | break; |
1065 | case ICAL_PARTSTAT_DELEGATED: | 1065 | case ICAL_PARTSTAT_DELEGATED: |
1066 | status = Attendee::Delegated; | 1066 | status = Attendee::Delegated; |
1067 | break; | 1067 | break; |
1068 | case ICAL_PARTSTAT_COMPLETED: | 1068 | case ICAL_PARTSTAT_COMPLETED: |
1069 | status = Attendee::Completed; | 1069 | status = Attendee::Completed; |
1070 | break; | 1070 | break; |
1071 | case ICAL_PARTSTAT_INPROCESS: | 1071 | case ICAL_PARTSTAT_INPROCESS: |
1072 | status = Attendee::InProcess; | 1072 | status = Attendee::InProcess; |
1073 | break; | 1073 | break; |
1074 | } | 1074 | } |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | Attendee::Role role = Attendee::ReqParticipant; | 1077 | Attendee::Role role = Attendee::ReqParticipant; |
1078 | p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); | 1078 | p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); |
1079 | if (p) { | 1079 | if (p) { |
1080 | icalparameter_role roleParameter = icalparameter_get_role(p); | 1080 | icalparameter_role roleParameter = icalparameter_get_role(p); |
1081 | switch(roleParameter) { | 1081 | switch(roleParameter) { |
1082 | case ICAL_ROLE_CHAIR: | 1082 | case ICAL_ROLE_CHAIR: |
1083 | role = Attendee::Chair; | 1083 | role = Attendee::Chair; |
1084 | break; | 1084 | break; |
1085 | default: | 1085 | default: |
1086 | case ICAL_ROLE_REQPARTICIPANT: | 1086 | case ICAL_ROLE_REQPARTICIPANT: |
1087 | role = Attendee::ReqParticipant; | 1087 | role = Attendee::ReqParticipant; |
1088 | break; | 1088 | break; |
1089 | case ICAL_ROLE_OPTPARTICIPANT: | 1089 | case ICAL_ROLE_OPTPARTICIPANT: |
1090 | role = Attendee::OptParticipant; | 1090 | role = Attendee::OptParticipant; |
1091 | break; | 1091 | break; |
1092 | case ICAL_ROLE_NONPARTICIPANT: | 1092 | case ICAL_ROLE_NONPARTICIPANT: |
1093 | role = Attendee::NonParticipant; | 1093 | role = Attendee::NonParticipant; |
1094 | break; | 1094 | break; |
1095 | } | 1095 | } |
1096 | } | 1096 | } |
1097 | 1097 | ||
1098 | p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); | 1098 | p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); |
1099 | uid = icalparameter_get_xvalue(p); | 1099 | uid = icalparameter_get_xvalue(p); |
1100 | // This should be added, but there seems to be a libical bug here. | 1100 | // This should be added, but there seems to be a libical bug here. |
1101 | /*while (p) { | 1101 | /*while (p) { |
1102 | // if (icalparameter_get_xname(p) == "X-UID") { | 1102 | // if (icalparameter_get_xname(p) == "X-UID") { |
1103 | uid = icalparameter_get_xvalue(p); | 1103 | uid = icalparameter_get_xvalue(p); |
1104 | p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); | 1104 | p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); |
1105 | } */ | 1105 | } */ |
1106 | 1106 | ||
1107 | return new Attendee( name, email, rsvp, status, role, uid ); | 1107 | return new Attendee( name, email, rsvp, status, role, uid ); |
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) | 1110 | Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) |
1111 | { | 1111 | { |
1112 | icalattach *a = icalproperty_get_attach(attach); | 1112 | icalattach *a = icalproperty_get_attach(attach); |
1113 | icalparameter_value v = ICAL_VALUE_NONE; | 1113 | icalparameter_value v = ICAL_VALUE_NONE; |
1114 | icalparameter_encoding e = ICAL_ENCODING_NONE; | 1114 | icalparameter_encoding e = ICAL_ENCODING_NONE; |
1115 | 1115 | ||
1116 | Attachment *attachment = 0; | 1116 | Attachment *attachment = 0; |
1117 | /* | 1117 | /* |
1118 | icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); | 1118 | icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); |
1119 | if (vp) | 1119 | if (vp) |
1120 | v = icalparameter_get_value(vp); | 1120 | v = icalparameter_get_value(vp); |
1121 | 1121 | ||
1122 | icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); | 1122 | icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); |
1123 | if (ep) | 1123 | if (ep) |
1124 | e = icalparameter_get_encoding(ep); | 1124 | e = icalparameter_get_encoding(ep); |
1125 | */ | 1125 | */ |
1126 | int isurl = icalattach_get_is_url (a); | 1126 | int isurl = icalattach_get_is_url (a); |
1127 | if (isurl == 0) | 1127 | if (isurl == 0) |
1128 | attachment = new Attachment((const char*)icalattach_get_data(a)); | 1128 | attachment = new Attachment((const char*)icalattach_get_data(a)); |
1129 | else { | 1129 | else { |
1130 | attachment = new Attachment(QString(icalattach_get_url(a))); | 1130 | attachment = new Attachment(QString(icalattach_get_url(a))); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); | 1133 | icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); |
1134 | if (p) | 1134 | if (p) |
1135 | attachment->setMimeType(QString(icalparameter_get_fmttype(p))); | 1135 | attachment->setMimeType(QString(icalparameter_get_fmttype(p))); |
1136 | 1136 | ||
1137 | return attachment; | 1137 | return attachment; |
1138 | } | 1138 | } |
1139 | #include <qtextcodec.h> | 1139 | #include <qtextcodec.h> |
1140 | void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) | 1140 | void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) |
1141 | { | 1141 | { |
1142 | readIncidenceBase(parent,incidence); | 1142 | readIncidenceBase(parent,incidence); |
1143 | 1143 | ||
1144 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); | 1144 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); |
1145 | bool readrec = false; | 1145 | bool readrec = false; |
1146 | const char *text; | 1146 | const char *text; |
1147 | int intvalue; | 1147 | int intvalue; |
1148 | icaltimetype icaltime; | 1148 | icaltimetype icaltime; |
1149 | icaldurationtype icalduration; | 1149 | icaldurationtype icalduration; |
1150 | struct icalrecurrencetype rectype; | 1150 | struct icalrecurrencetype rectype; |
1151 | QStringList categories; | 1151 | QStringList categories; |
1152 | 1152 | ||
1153 | while (p) { | 1153 | while (p) { |
1154 | icalproperty_kind kind = icalproperty_isa(p); | 1154 | icalproperty_kind kind = icalproperty_isa(p); |
1155 | switch (kind) { | 1155 | switch (kind) { |
1156 | 1156 | ||
1157 | case ICAL_CREATED_PROPERTY: | 1157 | case ICAL_CREATED_PROPERTY: |
1158 | icaltime = icalproperty_get_created(p); | 1158 | icaltime = icalproperty_get_created(p); |
1159 | incidence->setCreated(readICalDateTime(icaltime)); | 1159 | incidence->setCreated(readICalDateTime(icaltime)); |
1160 | break; | 1160 | break; |
1161 | 1161 | ||
1162 | case ICAL_SEQUENCE_PROPERTY: // sequence | 1162 | case ICAL_SEQUENCE_PROPERTY: // sequence |
1163 | intvalue = icalproperty_get_sequence(p); | 1163 | intvalue = icalproperty_get_sequence(p); |
1164 | incidence->setRevision(intvalue); | 1164 | incidence->setRevision(intvalue); |
1165 | break; | 1165 | break; |
1166 | 1166 | ||
1167 | case ICAL_LASTMODIFIED_PROPERTY: // last modification date | 1167 | case ICAL_LASTMODIFIED_PROPERTY: // last modification date |
1168 | icaltime = icalproperty_get_lastmodified(p); | 1168 | icaltime = icalproperty_get_lastmodified(p); |
1169 | incidence->setLastModified(readICalDateTime(icaltime)); | 1169 | incidence->setLastModified(readICalDateTime(icaltime)); |
1170 | break; | 1170 | break; |
1171 | 1171 | ||
1172 | case ICAL_DTSTART_PROPERTY: // start date and time | 1172 | case ICAL_DTSTART_PROPERTY: // start date and time |
1173 | icaltime = icalproperty_get_dtstart(p); | 1173 | icaltime = icalproperty_get_dtstart(p); |
1174 | if (icaltime.is_date) { | 1174 | if (icaltime.is_date) { |
1175 | incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); | 1175 | incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); |
1176 | incidence->setFloats(true); | 1176 | incidence->setFloats(true); |
1177 | } else { | 1177 | } else { |
1178 | incidence->setDtStart(readICalDateTime(icaltime)); | 1178 | incidence->setDtStart(readICalDateTime(icaltime)); |
1179 | } | 1179 | } |
1180 | break; | 1180 | break; |
1181 | 1181 | ||
1182 | case ICAL_DURATION_PROPERTY: // start date and time | 1182 | case ICAL_DURATION_PROPERTY: // start date and time |
1183 | icalduration = icalproperty_get_duration(p); | 1183 | icalduration = icalproperty_get_duration(p); |
1184 | incidence->setDuration(readICalDuration(icalduration)); | 1184 | incidence->setDuration(readICalDuration(icalduration)); |
1185 | break; | 1185 | break; |
1186 | 1186 | ||
1187 | case ICAL_DESCRIPTION_PROPERTY: // description | 1187 | case ICAL_DESCRIPTION_PROPERTY: // description |
1188 | text = icalproperty_get_description(p); | 1188 | text = icalproperty_get_description(p); |
1189 | incidence->setDescription(QString::fromUtf8(text)); | 1189 | incidence->setDescription(QString::fromUtf8(text)); |
1190 | break; | 1190 | break; |
1191 | 1191 | ||
1192 | case ICAL_SUMMARY_PROPERTY: // summary | 1192 | case ICAL_SUMMARY_PROPERTY: // summary |
1193 | { | 1193 | { |
1194 | text = icalproperty_get_summary(p); | 1194 | text = icalproperty_get_summary(p); |
1195 | incidence->setSummary(QString::fromUtf8(text)); | 1195 | incidence->setSummary(QString::fromUtf8(text)); |
1196 | } | 1196 | } |
1197 | break; | 1197 | break; |
1198 | case ICAL_STATUS_PROPERTY: // summary | 1198 | case ICAL_STATUS_PROPERTY: // summary |
1199 | { | 1199 | { |
1200 | if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) | 1200 | if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) |
1201 | incidence->setCancelled( true ); | 1201 | incidence->setCancelled( true ); |
1202 | } | 1202 | } |
1203 | break; | 1203 | break; |
1204 | 1204 | ||
1205 | case ICAL_LOCATION_PROPERTY: // location | 1205 | case ICAL_LOCATION_PROPERTY: // location |
1206 | text = icalproperty_get_location(p); | 1206 | text = icalproperty_get_location(p); |
1207 | incidence->setLocation(QString::fromUtf8(text)); | 1207 | incidence->setLocation(QString::fromUtf8(text)); |
1208 | break; | 1208 | break; |
1209 | 1209 | ||
1210 | case ICAL_RECURRENCEID_PROPERTY: | 1210 | case ICAL_RECURRENCEID_PROPERTY: |
1211 | icaltime = icalproperty_get_recurrenceid(p); | 1211 | icaltime = icalproperty_get_recurrenceid(p); |
1212 | incidence->setRecurrenceID( readICalDateTime(icaltime) ); | 1212 | incidence->setRecurrenceID( readICalDateTime(icaltime) ); |
1213 | //qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() ); | 1213 | //qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() ); |
1214 | break; | 1214 | break; |
1215 | #if 0 | 1215 | #if 0 |
1216 | // status | 1216 | // status |
1217 | if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { | 1217 | if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { |
1218 | incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); | 1218 | incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); |
1219 | deleteStr(s); | 1219 | deleteStr(s); |
1220 | } | 1220 | } |
1221 | else | 1221 | else |
1222 | incidence->setStatus("NEEDS ACTION"); | 1222 | incidence->setStatus("NEEDS ACTION"); |
1223 | #endif | 1223 | #endif |
1224 | 1224 | ||
1225 | case ICAL_PRIORITY_PROPERTY: // priority | 1225 | case ICAL_PRIORITY_PROPERTY: // priority |
1226 | intvalue = icalproperty_get_priority(p); | 1226 | intvalue = icalproperty_get_priority(p); |
1227 | incidence->setPriority(intvalue); | 1227 | incidence->setPriority(intvalue); |
1228 | break; | 1228 | break; |
1229 | 1229 | ||
1230 | case ICAL_CATEGORIES_PROPERTY: // categories | 1230 | case ICAL_CATEGORIES_PROPERTY: // categories |
1231 | text = icalproperty_get_categories(p); | 1231 | text = icalproperty_get_categories(p); |
1232 | categories.append(QString::fromUtf8(text)); | 1232 | categories.append(QString::fromUtf8(text)); |
1233 | break; | 1233 | break; |
1234 | //******************************************* | 1234 | //******************************************* |
1235 | case ICAL_RRULE_PROPERTY: | 1235 | case ICAL_RRULE_PROPERTY: |
1236 | // we do need (maybe )start datetime of incidence for recurrence | 1236 | // we do need (maybe )start datetime of incidence for recurrence |
1237 | // such that we can read recurrence only after we read incidence completely | 1237 | // such that we can read recurrence only after we read incidence completely |
1238 | readrec = true; | 1238 | readrec = true; |
1239 | rectype = icalproperty_get_rrule(p); | 1239 | rectype = icalproperty_get_rrule(p); |
1240 | break; | 1240 | break; |
1241 | 1241 | ||
1242 | case ICAL_EXDATE_PROPERTY: | 1242 | case ICAL_EXDATE_PROPERTY: |
1243 | icaltime = icalproperty_get_exdate(p); | 1243 | icaltime = icalproperty_get_exdate(p); |
1244 | incidence->addExDate(readICalDate(icaltime)); | 1244 | incidence->addExDate(readICalDate(icaltime)); |
1245 | break; | 1245 | break; |
1246 | 1246 | ||
1247 | case ICAL_CLASS_PROPERTY: { | 1247 | case ICAL_CLASS_PROPERTY: { |
1248 | int inttext = icalproperty_get_class(p); | 1248 | int inttext = icalproperty_get_class(p); |
1249 | if (inttext == ICAL_CLASS_PUBLIC ) { | 1249 | if (inttext == ICAL_CLASS_PUBLIC ) { |
1250 | incidence->setSecrecy(Incidence::SecrecyPublic); | 1250 | incidence->setSecrecy(Incidence::SecrecyPublic); |
1251 | } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { | 1251 | } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { |
1252 | incidence->setSecrecy(Incidence::SecrecyConfidential); | 1252 | incidence->setSecrecy(Incidence::SecrecyConfidential); |
1253 | } else { | 1253 | } else { |
1254 | incidence->setSecrecy(Incidence::SecrecyPrivate); | 1254 | incidence->setSecrecy(Incidence::SecrecyPrivate); |
1255 | } | 1255 | } |
1256 | } | 1256 | } |
1257 | break; | 1257 | break; |
1258 | 1258 | ||
1259 | case ICAL_ATTACH_PROPERTY: // attachments | 1259 | case ICAL_ATTACH_PROPERTY: // attachments |
1260 | incidence->addAttachment(readAttachment(p)); | 1260 | incidence->addAttachment(readAttachment(p)); |
1261 | break; | 1261 | break; |
1262 | 1262 | ||
1263 | default: | 1263 | default: |
1264 | // kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind | 1264 | // kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind |
1265 | // << endl; | 1265 | // << endl; |
1266 | break; | 1266 | break; |
1267 | } | 1267 | } |
1268 | 1268 | ||
1269 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); | 1269 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); |
1270 | } | 1270 | } |
1271 | if ( readrec ) { | 1271 | if ( readrec ) { |
1272 | readRecurrenceRule(rectype,incidence); | 1272 | readRecurrenceRule(rectype,incidence); |
1273 | } | 1273 | } |
1274 | // kpilot stuff | 1274 | // kpilot stuff |
1275 | // TODO: move this application-specific code to kpilot | 1275 | // TODO: move this application-specific code to kpilot |
1276 | QString kp = incidence->nonKDECustomProperty("X-PILOTID"); | 1276 | QString kp = incidence->nonKDECustomProperty("X-PILOTID"); |
1277 | if (!kp.isNull()) { | 1277 | if (!kp.isNull()) { |
1278 | incidence->setPilotId(kp.toInt()); | 1278 | incidence->setPilotId(kp.toInt()); |
1279 | } | 1279 | } |
1280 | kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); | 1280 | kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); |
1281 | if (!kp.isNull()) { | 1281 | if (!kp.isNull()) { |
1282 | incidence->setSyncStatus(kp.toInt()); | 1282 | incidence->setSyncStatus(kp.toInt()); |
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | 1285 | ||
1286 | kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); | 1286 | kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); |
1287 | if (!kp.isNull()) { | 1287 | if (!kp.isNull()) { |
1288 | incidence->setIDStr(kp); | 1288 | incidence->setIDStr(kp); |
1289 | } | 1289 | } |
1290 | 1290 | ||
1291 | // Cancel backwards compatibility mode for subsequent changes by the application | 1291 | // Cancel backwards compatibility mode for subsequent changes by the application |
1292 | incidence->recurrence()->setCompatVersion(); | 1292 | incidence->recurrence()->setCompatVersion(); |
1293 | 1293 | ||
1294 | // add categories | 1294 | // add categories |
1295 | incidence->setCategories(categories); | 1295 | incidence->setCategories(categories); |
1296 | 1296 | ||
1297 | // iterate through all alarms | 1297 | // iterate through all alarms |
1298 | for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); | 1298 | for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); |
1299 | alarm; | 1299 | alarm; |
1300 | alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { | 1300 | alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { |
1301 | readAlarm(alarm,incidence); | 1301 | readAlarm(alarm,incidence); |
1302 | } | 1302 | } |
1303 | } | 1303 | } |
1304 | 1304 | ||
1305 | void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) | 1305 | void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) |
1306 | { | 1306 | { |
1307 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); | 1307 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); |
1308 | 1308 | ||
1309 | while (p) { | 1309 | while (p) { |
1310 | icalproperty_kind kind = icalproperty_isa(p); | 1310 | icalproperty_kind kind = icalproperty_isa(p); |
1311 | switch (kind) { | 1311 | switch (kind) { |
1312 | 1312 | ||
1313 | case ICAL_UID_PROPERTY: // unique id | 1313 | case ICAL_UID_PROPERTY: // unique id |
1314 | incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); | 1314 | incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); |
1315 | break; | 1315 | break; |
1316 | 1316 | ||
1317 | case ICAL_ORGANIZER_PROPERTY: // organizer | 1317 | case ICAL_ORGANIZER_PROPERTY: // organizer |
1318 | incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); | 1318 | incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); |
1319 | break; | 1319 | break; |
1320 | 1320 | ||
1321 | case ICAL_ATTENDEE_PROPERTY: // attendee | 1321 | case ICAL_ATTENDEE_PROPERTY: // attendee |
1322 | incidenceBase->addAttendee(readAttendee(p)); | 1322 | incidenceBase->addAttendee(readAttendee(p)); |
1323 | break; | 1323 | break; |
1324 | 1324 | ||
1325 | default: | 1325 | default: |
1326 | break; | 1326 | break; |
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); | 1329 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); |
1330 | } | 1330 | } |
1331 | 1331 | ||
1332 | // custom properties | 1332 | // custom properties |
1333 | readCustomProperties(parent, incidenceBase); | 1333 | readCustomProperties(parent, incidenceBase); |
1334 | } | 1334 | } |
1335 | 1335 | ||
1336 | void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) | 1336 | void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) |
1337 | { | 1337 | { |
1338 | QMap<QCString, QString> customProperties; | 1338 | QMap<QCString, QString> customProperties; |
1339 | 1339 | ||
1340 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); | 1340 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); |
1341 | 1341 | ||
1342 | while (p) { | 1342 | while (p) { |
1343 | QString value = QString::fromUtf8(icalproperty_get_x(p)); | 1343 | QString value = QString::fromUtf8(icalproperty_get_x(p)); |
1344 | customProperties[icalproperty_get_x_name(p)] = value; | 1344 | customProperties[icalproperty_get_x_name(p)] = value; |
1345 | //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); | 1345 | //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); |
1346 | 1346 | ||
1347 | p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); | 1347 | p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | properties->setCustomProperties(customProperties); | 1350 | properties->setCustomProperties(customProperties); |
1351 | } | 1351 | } |
1352 | 1352 | ||
1353 | void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) | 1353 | void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) |
1354 | { | 1354 | { |
1355 | // kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; | 1355 | // kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; |
1356 | 1356 | ||
1357 | Recurrence *recur = incidence->recurrence(); | 1357 | Recurrence *recur = incidence->recurrence(); |
1358 | recur->setCompatVersion(mCalendarVersion); | 1358 | recur->setCompatVersion(mCalendarVersion); |
1359 | recur->unsetRecurs(); | 1359 | recur->unsetRecurs(); |
1360 | 1360 | ||
1361 | struct icalrecurrencetype r = rrule; | 1361 | struct icalrecurrencetype r = rrule; |
1362 | 1362 | ||
1363 | dumpIcalRecurrence(r); | 1363 | dumpIcalRecurrence(r); |
1364 | readRecurrence( r, recur, incidence); | 1364 | readRecurrence( r, recur, incidence); |
1365 | } | 1365 | } |
1366 | 1366 | ||
1367 | void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) | 1367 | void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) |
1368 | { | 1368 | { |
1369 | int wkst; | 1369 | int wkst; |
1370 | int index = 0; | 1370 | int index = 0; |
1371 | short day = 0; | 1371 | short day = 0; |
1372 | QBitArray qba(7); | 1372 | QBitArray qba(7); |
1373 | int frequ = r.freq; | 1373 | int frequ = r.freq; |
1374 | int interv = r.interval; | 1374 | int interv = r.interval; |
1375 | // preprocessing for odd recurrence definitions | 1375 | // preprocessing for odd recurrence definitions |
1376 | 1376 | ||
1377 | if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { | 1377 | if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { |
1378 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1378 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1379 | interv = 12; | 1379 | interv = 12; |
1380 | } | 1380 | } |
1381 | } | 1381 | } |
1382 | if ( r.freq == ICAL_YEARLY_RECURRENCE ) { | 1382 | if ( r.freq == ICAL_YEARLY_RECURRENCE ) { |
1383 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { | 1383 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { |
1384 | frequ = ICAL_MONTHLY_RECURRENCE; | 1384 | frequ = ICAL_MONTHLY_RECURRENCE; |
1385 | interv = 12* r.interval; | 1385 | interv = 12* r.interval; |
1386 | } | 1386 | } |
1387 | } | 1387 | } |
1388 | 1388 | ||
1389 | switch (frequ) { | 1389 | switch (frequ) { |
1390 | case ICAL_MINUTELY_RECURRENCE: | 1390 | case ICAL_MINUTELY_RECURRENCE: |
1391 | if (!icaltime_is_null_time(r.until)) { | 1391 | if (!icaltime_is_null_time(r.until)) { |
1392 | recur->setMinutely(interv,readICalDateTime(r.until)); | 1392 | recur->setMinutely(interv,readICalDateTime(r.until)); |
1393 | } else { | 1393 | } else { |
1394 | if (r.count == 0) | 1394 | if (r.count == 0) |
1395 | recur->setMinutely(interv,-1); | 1395 | recur->setMinutely(interv,-1); |
1396 | else | 1396 | else |
1397 | recur->setMinutely(interv,r.count); | 1397 | recur->setMinutely(interv,r.count); |
1398 | } | 1398 | } |
1399 | break; | 1399 | break; |
1400 | case ICAL_HOURLY_RECURRENCE: | 1400 | case ICAL_HOURLY_RECURRENCE: |
1401 | if (!icaltime_is_null_time(r.until)) { | 1401 | if (!icaltime_is_null_time(r.until)) { |
1402 | recur->setHourly(interv,readICalDateTime(r.until)); | 1402 | recur->setHourly(interv,readICalDateTime(r.until)); |
1403 | } else { | 1403 | } else { |
1404 | if (r.count == 0) | 1404 | if (r.count == 0) |
1405 | recur->setHourly(interv,-1); | 1405 | recur->setHourly(interv,-1); |
1406 | else | 1406 | else |
1407 | recur->setHourly(interv,r.count); | 1407 | recur->setHourly(interv,r.count); |
1408 | } | 1408 | } |
1409 | break; | 1409 | break; |
1410 | case ICAL_DAILY_RECURRENCE: | 1410 | case ICAL_DAILY_RECURRENCE: |
1411 | if (!icaltime_is_null_time(r.until)) { | 1411 | if (!icaltime_is_null_time(r.until)) { |
1412 | recur->setDaily(interv,readICalDate(r.until)); | 1412 | recur->setDaily(interv,readICalDate(r.until)); |
1413 | } else { | 1413 | } else { |
1414 | if (r.count == 0) | 1414 | if (r.count == 0) |
1415 | recur->setDaily(interv,-1); | 1415 | recur->setDaily(interv,-1); |
1416 | else | 1416 | else |
1417 | recur->setDaily(interv,r.count); | 1417 | recur->setDaily(interv,r.count); |
1418 | } | 1418 | } |
1419 | break; | 1419 | break; |
1420 | case ICAL_WEEKLY_RECURRENCE: | 1420 | case ICAL_WEEKLY_RECURRENCE: |
1421 | // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; | 1421 | // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; |
1422 | wkst = (r.week_start + 5)%7 + 1; | 1422 | wkst = (r.week_start + 5)%7 + 1; |
1423 | if (!icaltime_is_null_time(r.until)) { | 1423 | if (!icaltime_is_null_time(r.until)) { |
1424 | recur->setWeekly(interv,qba,readICalDate(r.until),wkst); | 1424 | recur->setWeekly(interv,qba,readICalDate(r.until),wkst); |
1425 | } else { | 1425 | } else { |
1426 | if (r.count == 0) | 1426 | if (r.count == 0) |
1427 | recur->setWeekly(interv,qba,-1,wkst); | 1427 | recur->setWeekly(interv,qba,-1,wkst); |
1428 | else | 1428 | else |
1429 | recur->setWeekly(interv,qba,r.count,wkst); | 1429 | recur->setWeekly(interv,qba,r.count,wkst); |
1430 | } | 1430 | } |
1431 | if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { | 1431 | if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { |
1432 | int wday = incidence->dtStart().date().dayOfWeek ()-1; | 1432 | int wday = incidence->dtStart().date().dayOfWeek ()-1; |
1433 | //qDebug("weekly error found "); | 1433 | //qDebug("weekly error found "); |
1434 | qba.setBit(wday); | 1434 | qba.setBit(wday); |
1435 | } else { | 1435 | } else { |
1436 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1436 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1437 | // kdDebug(5800) << " " << day << endl; | 1437 | // kdDebug(5800) << " " << day << endl; |
1438 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1438 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1439 | } | 1439 | } |
1440 | } | 1440 | } |
1441 | break; | 1441 | break; |
1442 | case ICAL_MONTHLY_RECURRENCE: | 1442 | case ICAL_MONTHLY_RECURRENCE: |
1443 | 1443 | ||
1444 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1444 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1445 | if (!icaltime_is_null_time(r.until)) { | 1445 | if (!icaltime_is_null_time(r.until)) { |
1446 | recur->setMonthly(Recurrence::rMonthlyPos,interv, | 1446 | recur->setMonthly(Recurrence::rMonthlyPos,interv, |
1447 | readICalDate(r.until)); | 1447 | readICalDate(r.until)); |
1448 | } else { | 1448 | } else { |
1449 | if (r.count == 0) | 1449 | if (r.count == 0) |
1450 | recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); | 1450 | recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); |
1451 | else | 1451 | else |
1452 | recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); | 1452 | recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); |
1453 | } | 1453 | } |
1454 | bool useSetPos = false; | 1454 | bool useSetPos = false; |
1455 | short pos = 0; | 1455 | short pos = 0; |
1456 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1456 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1457 | // kdDebug(5800) << "----a " << index << ": " << day << endl; | 1457 | // kdDebug(5800) << "----a " << index << ": " << day << endl; |
1458 | pos = icalrecurrencetype_day_position(day); | 1458 | pos = icalrecurrencetype_day_position(day); |
1459 | if (pos) { | 1459 | if (pos) { |
1460 | day = icalrecurrencetype_day_day_of_week(day); | 1460 | day = icalrecurrencetype_day_day_of_week(day); |
1461 | QBitArray ba(7); // don't wipe qba | 1461 | QBitArray ba(7); // don't wipe qba |
1462 | ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1462 | ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1463 | recur->addMonthlyPos(pos,ba); | 1463 | recur->addMonthlyPos(pos,ba); |
1464 | } else { | 1464 | } else { |
1465 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1465 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1466 | useSetPos = true; | 1466 | useSetPos = true; |
1467 | } | 1467 | } |
1468 | } | 1468 | } |
1469 | if (useSetPos) { | 1469 | if (useSetPos) { |
1470 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1470 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1471 | recur->addMonthlyPos(r.by_set_pos[0],qba); | 1471 | recur->addMonthlyPos(r.by_set_pos[0],qba); |
1472 | } | 1472 | } |
1473 | } | 1473 | } |
1474 | } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1474 | } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1475 | if (!icaltime_is_null_time(r.until)) { | 1475 | if (!icaltime_is_null_time(r.until)) { |
1476 | recur->setMonthly(Recurrence::rMonthlyDay,interv, | 1476 | recur->setMonthly(Recurrence::rMonthlyDay,interv, |
1477 | readICalDate(r.until)); | 1477 | readICalDate(r.until)); |
1478 | } else { | 1478 | } else { |
1479 | if (r.count == 0) | 1479 | if (r.count == 0) |
1480 | recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); | 1480 | recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); |
1481 | else | 1481 | else |
1482 | recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); | 1482 | recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); |
1483 | } | 1483 | } |
1484 | while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1484 | while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1485 | // kdDebug(5800) << "----b " << day << endl; | 1485 | // kdDebug(5800) << "----b " << day << endl; |
1486 | recur->addMonthlyDay(day); | 1486 | recur->addMonthlyDay(day); |
1487 | } | 1487 | } |
1488 | } | 1488 | } |
1489 | break; | 1489 | break; |
1490 | case ICAL_YEARLY_RECURRENCE: | 1490 | case ICAL_YEARLY_RECURRENCE: |
1491 | if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1491 | if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1492 | //qDebug(" YEARLY DAY OF YEAR"); | 1492 | //qDebug(" YEARLY DAY OF YEAR"); |
1493 | if (!icaltime_is_null_time(r.until)) { | 1493 | if (!icaltime_is_null_time(r.until)) { |
1494 | recur->setYearly(Recurrence::rYearlyDay,interv, | 1494 | recur->setYearly(Recurrence::rYearlyDay,interv, |
1495 | readICalDate(r.until)); | 1495 | readICalDate(r.until)); |
1496 | } else { | 1496 | } else { |
1497 | if (r.count == 0) | 1497 | if (r.count == 0) |
1498 | recur->setYearly(Recurrence::rYearlyDay,interv,-1); | 1498 | recur->setYearly(Recurrence::rYearlyDay,interv,-1); |
1499 | else | 1499 | else |
1500 | recur->setYearly(Recurrence::rYearlyDay,interv,r.count); | 1500 | recur->setYearly(Recurrence::rYearlyDay,interv,r.count); |
1501 | } | 1501 | } |
1502 | while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1502 | while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1503 | recur->addYearlyNum(day); | 1503 | recur->addYearlyNum(day); |
1504 | } | 1504 | } |
1505 | } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { | 1505 | } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { |
1506 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1506 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1507 | qDebug("YEARLY POS NOT SUPPORTED BY GUI"); | 1507 | qDebug("YEARLY POS NOT SUPPORTED BY GUI"); |
1508 | if (!icaltime_is_null_time(r.until)) { | 1508 | if (!icaltime_is_null_time(r.until)) { |
1509 | recur->setYearly(Recurrence::rYearlyPos,interv, | 1509 | recur->setYearly(Recurrence::rYearlyPos,interv, |
1510 | readICalDate(r.until)); | 1510 | readICalDate(r.until)); |
1511 | } else { | 1511 | } else { |
1512 | if (r.count == 0) | 1512 | if (r.count == 0) |
1513 | recur->setYearly(Recurrence::rYearlyPos,interv,-1); | 1513 | recur->setYearly(Recurrence::rYearlyPos,interv,-1); |
1514 | else | 1514 | else |
1515 | recur->setYearly(Recurrence::rYearlyPos,interv,r.count); | 1515 | recur->setYearly(Recurrence::rYearlyPos,interv,r.count); |
1516 | } | 1516 | } |
1517 | bool useSetPos = false; | 1517 | bool useSetPos = false; |
1518 | short pos = 0; | 1518 | short pos = 0; |
1519 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1519 | while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1520 | // kdDebug(5800) << "----a " << index << ": " << day << endl; | 1520 | // kdDebug(5800) << "----a " << index << ": " << day << endl; |
1521 | pos = icalrecurrencetype_day_position(day); | 1521 | pos = icalrecurrencetype_day_position(day); |
1522 | if (pos) { | 1522 | if (pos) { |
1523 | day = icalrecurrencetype_day_day_of_week(day); | 1523 | day = icalrecurrencetype_day_day_of_week(day); |
1524 | QBitArray ba(7); // don't wipe qba | 1524 | QBitArray ba(7); // don't wipe qba |
1525 | ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1525 | ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1526 | recur->addYearlyMonthPos(pos,ba); | 1526 | recur->addYearlyMonthPos(pos,ba); |
1527 | } else { | 1527 | } else { |
1528 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 | 1528 | qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 |
1529 | useSetPos = true; | 1529 | useSetPos = true; |
1530 | } | 1530 | } |
1531 | } | 1531 | } |
1532 | if (useSetPos) { | 1532 | if (useSetPos) { |
1533 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1533 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1534 | recur->addYearlyMonthPos(r.by_set_pos[0],qba); | 1534 | recur->addYearlyMonthPos(r.by_set_pos[0],qba); |
1535 | } | 1535 | } |
1536 | } | 1536 | } |
1537 | } else { | 1537 | } else { |
1538 | //qDebug("YEARLY MONTH "); | 1538 | //qDebug("YEARLY MONTH "); |
1539 | if (!icaltime_is_null_time(r.until)) { | 1539 | if (!icaltime_is_null_time(r.until)) { |
1540 | recur->setYearly(Recurrence::rYearlyMonth,interv, | 1540 | recur->setYearly(Recurrence::rYearlyMonth,interv, |
1541 | readICalDate(r.until)); | 1541 | readICalDate(r.until)); |
1542 | } else { | 1542 | } else { |
1543 | if (r.count == 0) | 1543 | if (r.count == 0) |
1544 | recur->setYearly(Recurrence::rYearlyMonth,interv,-1); | 1544 | recur->setYearly(Recurrence::rYearlyMonth,interv,-1); |
1545 | else | 1545 | else |
1546 | recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); | 1546 | recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); |
1547 | } | 1547 | } |
1548 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { | 1548 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { |
1549 | index = 0; | 1549 | index = 0; |
1550 | while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 1550 | while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
1551 | recur->addYearlyNum(day); | 1551 | recur->addYearlyNum(day); |
1552 | } | 1552 | } |
1553 | } else { | 1553 | } else { |
1554 | recur->addYearlyNum(incidence->dtStart().date().month()); | 1554 | recur->addYearlyNum(incidence->dtStart().date().month()); |
1555 | } | 1555 | } |
1556 | } | 1556 | } |
1557 | 1557 | ||
1558 | } | 1558 | } |
1559 | break; | 1559 | break; |
1560 | default: | 1560 | default: |
1561 | ; | 1561 | ; |
1562 | break; | 1562 | break; |
1563 | } | 1563 | } |
1564 | } | 1564 | } |
1565 | 1565 | ||
1566 | void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) | 1566 | void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) |
1567 | { | 1567 | { |
1568 | //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; | 1568 | //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; |
1569 | 1569 | ||
1570 | Alarm* ialarm = incidence->newAlarm(); | 1570 | Alarm* ialarm = incidence->newAlarm(); |
1571 | ialarm->setRepeatCount(0); | 1571 | ialarm->setRepeatCount(0); |
1572 | ialarm->setEnabled(true); | 1572 | ialarm->setEnabled(true); |
1573 | 1573 | ||
1574 | // Determine the alarm's action type | 1574 | // Determine the alarm's action type |
1575 | icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); | 1575 | icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); |
1576 | if ( !p ) { | 1576 | if ( !p ) { |
1577 | return; | 1577 | return; |
1578 | } | 1578 | } |
1579 | 1579 | ||
1580 | icalproperty_action action = icalproperty_get_action(p); | 1580 | icalproperty_action action = icalproperty_get_action(p); |
1581 | Alarm::Type type = Alarm::Display; | 1581 | Alarm::Type type = Alarm::Display; |
1582 | switch ( action ) { | 1582 | switch ( action ) { |
1583 | case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; | 1583 | case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; |
1584 | case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; | 1584 | case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; |
1585 | case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; | 1585 | case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; |
1586 | case ICAL_ACTION_EMAIL: type = Alarm::Email; break; | 1586 | case ICAL_ACTION_EMAIL: type = Alarm::Email; break; |
1587 | default: | 1587 | default: |
1588 | ; | 1588 | ; |
1589 | return; | 1589 | return; |
1590 | } | 1590 | } |
1591 | ialarm->setType(type); | 1591 | ialarm->setType(type); |
1592 | 1592 | ||
1593 | p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); | 1593 | p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); |
1594 | while (p) { | 1594 | while (p) { |
1595 | icalproperty_kind kind = icalproperty_isa(p); | 1595 | icalproperty_kind kind = icalproperty_isa(p); |
1596 | 1596 | ||
1597 | switch (kind) { | 1597 | switch (kind) { |
1598 | case ICAL_TRIGGER_PROPERTY: { | 1598 | case ICAL_TRIGGER_PROPERTY: { |
1599 | icaltriggertype trigger = icalproperty_get_trigger(p); | 1599 | icaltriggertype trigger = icalproperty_get_trigger(p); |
1600 | if (icaltime_is_null_time(trigger.time)) { | 1600 | if (icaltime_is_null_time(trigger.time)) { |
1601 | if (icaldurationtype_is_null_duration(trigger.duration)) { | 1601 | if (icaldurationtype_is_null_duration(trigger.duration)) { |
1602 | kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; | 1602 | kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; |
1603 | } else { | 1603 | } else { |
1604 | Duration duration = icaldurationtype_as_int( trigger.duration ); | 1604 | Duration duration = icaldurationtype_as_int( trigger.duration ); |
1605 | icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); | 1605 | icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); |
1606 | if (param && icalparameter_get_related(param) == ICAL_RELATED_END) | 1606 | if (param && icalparameter_get_related(param) == ICAL_RELATED_END) |
1607 | ialarm->setEndOffset(duration); | 1607 | ialarm->setEndOffset(duration); |
1608 | else | 1608 | else |
1609 | ialarm->setStartOffset(duration); | 1609 | ialarm->setStartOffset(duration); |
1610 | } | 1610 | } |
1611 | } else { | 1611 | } else { |
1612 | ialarm->setTime(readICalDateTime(trigger.time)); | 1612 | ialarm->setTime(readICalDateTime(trigger.time)); |
1613 | } | 1613 | } |
1614 | break; | 1614 | break; |
1615 | } | 1615 | } |
1616 | case ICAL_DURATION_PROPERTY: { | 1616 | case ICAL_DURATION_PROPERTY: { |
1617 | icaldurationtype duration = icalproperty_get_duration(p); | 1617 | icaldurationtype duration = icalproperty_get_duration(p); |
1618 | ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); | 1618 | ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); |
1619 | break; | 1619 | break; |
1620 | } | 1620 | } |
1621 | case ICAL_REPEAT_PROPERTY: | 1621 | case ICAL_REPEAT_PROPERTY: |
1622 | ialarm->setRepeatCount(icalproperty_get_repeat(p)); | 1622 | ialarm->setRepeatCount(icalproperty_get_repeat(p)); |
1623 | break; | 1623 | break; |
1624 | 1624 | ||
1625 | // Only in DISPLAY and EMAIL and PROCEDURE alarms | 1625 | // Only in DISPLAY and EMAIL and PROCEDURE alarms |
1626 | case ICAL_DESCRIPTION_PROPERTY: { | 1626 | case ICAL_DESCRIPTION_PROPERTY: { |
1627 | QString description = QString::fromUtf8(icalproperty_get_description(p)); | 1627 | QString description = QString::fromUtf8(icalproperty_get_description(p)); |
1628 | switch ( action ) { | 1628 | switch ( action ) { |
1629 | case ICAL_ACTION_DISPLAY: | 1629 | case ICAL_ACTION_DISPLAY: |
1630 | ialarm->setText( description ); | 1630 | ialarm->setText( description ); |
1631 | break; | 1631 | break; |
1632 | case ICAL_ACTION_PROCEDURE: | 1632 | case ICAL_ACTION_PROCEDURE: |
1633 | ialarm->setProgramArguments( description ); | 1633 | ialarm->setProgramArguments( description ); |
1634 | break; | 1634 | break; |
1635 | case ICAL_ACTION_EMAIL: | 1635 | case ICAL_ACTION_EMAIL: |
1636 | ialarm->setMailText( description ); | 1636 | ialarm->setMailText( description ); |
1637 | break; | 1637 | break; |
1638 | default: | 1638 | default: |
1639 | break; | 1639 | break; |
1640 | } | 1640 | } |
1641 | break; | 1641 | break; |
1642 | } | 1642 | } |
1643 | // Only in EMAIL alarm | 1643 | // Only in EMAIL alarm |
1644 | case ICAL_SUMMARY_PROPERTY: | 1644 | case ICAL_SUMMARY_PROPERTY: |
1645 | ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); | 1645 | ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); |
1646 | break; | 1646 | break; |
1647 | 1647 | ||
1648 | // Only in EMAIL alarm | 1648 | // Only in EMAIL alarm |
1649 | case ICAL_ATTENDEE_PROPERTY: { | 1649 | case ICAL_ATTENDEE_PROPERTY: { |
1650 | QString email = QString::fromUtf8(icalproperty_get_attendee(p)); | 1650 | QString email = QString::fromUtf8(icalproperty_get_attendee(p)); |
1651 | QString name; | 1651 | QString name; |
1652 | icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); | 1652 | icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); |
1653 | if (param) { | 1653 | if (param) { |
1654 | name = QString::fromUtf8(icalparameter_get_cn(param)); | 1654 | name = QString::fromUtf8(icalparameter_get_cn(param)); |
1655 | } | 1655 | } |
1656 | ialarm->addMailAddress(Person(name, email)); | 1656 | ialarm->addMailAddress(Person(name, email)); |
1657 | break; | 1657 | break; |
1658 | } | 1658 | } |
1659 | // Only in AUDIO and EMAIL and PROCEDURE alarms | 1659 | // Only in AUDIO and EMAIL and PROCEDURE alarms |
1660 | case ICAL_ATTACH_PROPERTY: { | 1660 | case ICAL_ATTACH_PROPERTY: { |
1661 | icalattach *attach = icalproperty_get_attach(p); | 1661 | icalattach *attach = icalproperty_get_attach(p); |
1662 | QString url = QFile::decodeName(icalattach_get_url(attach)); | 1662 | QString url = QFile::decodeName(icalattach_get_url(attach)); |
1663 | switch ( action ) { | 1663 | switch ( action ) { |
1664 | case ICAL_ACTION_AUDIO: | 1664 | case ICAL_ACTION_AUDIO: |
1665 | ialarm->setAudioFile( url ); | 1665 | ialarm->setAudioFile( url ); |
1666 | break; | 1666 | break; |
1667 | case ICAL_ACTION_PROCEDURE: | 1667 | case ICAL_ACTION_PROCEDURE: |
1668 | ialarm->setProgramFile( url ); | 1668 | ialarm->setProgramFile( url ); |
1669 | break; | 1669 | break; |
1670 | case ICAL_ACTION_EMAIL: | 1670 | case ICAL_ACTION_EMAIL: |
1671 | ialarm->addMailAttachment( url ); | 1671 | ialarm->addMailAttachment( url ); |
1672 | break; | 1672 | break; |
1673 | default: | 1673 | default: |
1674 | break; | 1674 | break; |
1675 | } | 1675 | } |
1676 | break; | 1676 | break; |
1677 | } | 1677 | } |
1678 | default: | 1678 | default: |
1679 | break; | 1679 | break; |
1680 | } | 1680 | } |
1681 | 1681 | ||
1682 | p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); | 1682 | p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); |
1683 | } | 1683 | } |
1684 | 1684 | ||
1685 | // custom properties | 1685 | // custom properties |
1686 | readCustomProperties(alarm, ialarm); | 1686 | readCustomProperties(alarm, ialarm); |
1687 | 1687 | ||
1688 | // TODO: check for consistency of alarm properties | 1688 | // TODO: check for consistency of alarm properties |
1689 | } | 1689 | } |
1690 | 1690 | ||
1691 | icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) | 1691 | icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) |
1692 | { | 1692 | { |
1693 | icaltimetype t; | 1693 | icaltimetype t; |
1694 | 1694 | ||
1695 | t.year = date.year(); | 1695 | t.year = date.year(); |
1696 | t.month = date.month(); | 1696 | t.month = date.month(); |
1697 | t.day = date.day(); | 1697 | t.day = date.day(); |
1698 | 1698 | ||
1699 | t.hour = 0; | 1699 | t.hour = 0; |
1700 | t.minute = 0; | 1700 | t.minute = 0; |
1701 | t.second = 0; | 1701 | t.second = 0; |
1702 | 1702 | ||
1703 | t.is_date = 1; | 1703 | t.is_date = 1; |
1704 | 1704 | ||
1705 | t.is_utc = 0; | 1705 | t.is_utc = 0; |
1706 | 1706 | ||
1707 | t.zone = 0; | 1707 | t.zone = 0; |
1708 | 1708 | ||
1709 | return t; | 1709 | return t; |
1710 | } | 1710 | } |
1711 | 1711 | ||
1712 | icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) | 1712 | icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) |
1713 | { | 1713 | { |
1714 | icaltimetype t; | 1714 | icaltimetype t; |
1715 | t.is_date = 0; | 1715 | t.is_date = 0; |
1716 | t.zone = 0; | 1716 | t.zone = 0; |
1717 | QDateTime datetime; | 1717 | QDateTime datetime; |
1718 | if ( mParent->utc() ) { | 1718 | if ( mParent->utc() ) { |
1719 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 1719 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
1720 | datetime = dt.addSecs ( -offset*60); | 1720 | datetime = dt.addSecs ( -offset*60); |
1721 | t.is_utc = 1; | 1721 | t.is_utc = 1; |
1722 | } | 1722 | } |
1723 | else { | 1723 | else { |
1724 | datetime = dt; | 1724 | datetime = dt; |
1725 | t.is_utc = 0; | 1725 | t.is_utc = 0; |
1726 | 1726 | ||
1727 | } | 1727 | } |
1728 | t.year = datetime.date().year(); | 1728 | t.year = datetime.date().year(); |
1729 | t.month = datetime.date().month(); | 1729 | t.month = datetime.date().month(); |
1730 | t.day = datetime.date().day(); | 1730 | t.day = datetime.date().day(); |
1731 | 1731 | ||
1732 | t.hour = datetime.time().hour(); | 1732 | t.hour = datetime.time().hour(); |
1733 | t.minute = datetime.time().minute(); | 1733 | t.minute = datetime.time().minute(); |
1734 | t.second = datetime.time().second(); | 1734 | t.second = datetime.time().second(); |
1735 | 1735 | ||
1736 | //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); | 1736 | //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); |
1737 | 1737 | ||
1738 | // if ( mParent->utc() ) { | 1738 | // if ( mParent->utc() ) { |
1739 | // datetime = KGlobal::locale()->localTime( dt ); | 1739 | // datetime = KGlobal::locale()->localTime( dt ); |
1740 | // qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); | 1740 | // qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); |
1741 | // if (mParent->timeZoneId().isEmpty()) | 1741 | // if (mParent->timeZoneId().isEmpty()) |
1742 | // t = icaltime_as_utc(t, 0); | 1742 | // t = icaltime_as_utc(t, 0); |
1743 | // else | 1743 | // else |
1744 | // t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); | 1744 | // t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); |
1745 | // } | 1745 | // } |
1746 | 1746 | ||
1747 | return t; | 1747 | return t; |
1748 | } | 1748 | } |
1749 | 1749 | ||
1750 | QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) | 1750 | QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) |
1751 | { | 1751 | { |
1752 | QDateTime dt (QDate(t.year,t.month,t.day), | 1752 | QDateTime dt (QDate(t.year,t.month,t.day), |
1753 | QTime(t.hour,t.minute,t.second) ); | 1753 | QTime(t.hour,t.minute,t.second) ); |
1754 | 1754 | ||
1755 | if (t.is_utc) { | 1755 | if (t.is_utc) { |
1756 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 1756 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
1757 | dt = dt.addSecs ( offset*60); | 1757 | dt = dt.addSecs ( offset*60); |
1758 | } | 1758 | } |
1759 | 1759 | ||
1760 | return dt; | 1760 | return dt; |
1761 | } | 1761 | } |
1762 | 1762 | ||
1763 | QDate ICalFormatImpl::readICalDate(icaltimetype t) | 1763 | QDate ICalFormatImpl::readICalDate(icaltimetype t) |
1764 | { | 1764 | { |
1765 | return QDate(t.year,t.month,t.day); | 1765 | return QDate(t.year,t.month,t.day); |
1766 | } | 1766 | } |
1767 | 1767 | ||
1768 | icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) | 1768 | icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) |
1769 | { | 1769 | { |
1770 | icaldurationtype d; | 1770 | icaldurationtype d; |
1771 | 1771 | ||
1772 | d.weeks = seconds % gSecondsPerWeek; | 1772 | d.is_neg = (seconds<0)?1:0; |
1773 | seconds -= d.weeks * gSecondsPerWeek; | 1773 | if (seconds<0) seconds = -seconds; |
1774 | d.days = seconds % gSecondsPerDay; | 1774 | |
1775 | seconds -= d.days * gSecondsPerDay; | 1775 | d.weeks = seconds / gSecondsPerWeek; |
1776 | d.hours = seconds % gSecondsPerHour; | 1776 | seconds %= gSecondsPerWeek; |
1777 | seconds -= d.hours * gSecondsPerHour; | 1777 | d.days = seconds / gSecondsPerDay; |
1778 | d.minutes = seconds % gSecondsPerMinute; | 1778 | seconds %= gSecondsPerDay; |
1779 | seconds -= d.minutes * gSecondsPerMinute; | 1779 | d.hours = seconds / gSecondsPerHour; |
1780 | seconds %= gSecondsPerHour; | ||
1781 | d.minutes = seconds / gSecondsPerMinute; | ||
1782 | seconds %= gSecondsPerMinute; | ||
1780 | d.seconds = seconds; | 1783 | d.seconds = seconds; |
1781 | d.is_neg = 0; | ||
1782 | |||
1783 | return d; | 1784 | return d; |
1784 | } | 1785 | } |
1785 | 1786 | ||
1786 | int ICalFormatImpl::readICalDuration(icaldurationtype d) | 1787 | int ICalFormatImpl::readICalDuration(icaldurationtype d) |
1787 | { | 1788 | { |
1788 | int result = 0; | 1789 | int result = 0; |
1789 | 1790 | ||
1790 | result += d.weeks * gSecondsPerWeek; | 1791 | result += d.weeks * gSecondsPerWeek; |
1791 | result += d.days * gSecondsPerDay; | 1792 | result += d.days * gSecondsPerDay; |
1792 | result += d.hours * gSecondsPerHour; | 1793 | result += d.hours * gSecondsPerHour; |
1793 | result += d.minutes * gSecondsPerMinute; | 1794 | result += d.minutes * gSecondsPerMinute; |
1794 | result += d.seconds; | 1795 | result += d.seconds; |
1795 | 1796 | ||
1796 | if (d.is_neg) result *= -1; | 1797 | if (d.is_neg) result *= -1; |
1797 | 1798 | ||
1798 | return result; | 1799 | return result; |
1799 | } | 1800 | } |
1800 | 1801 | ||
1801 | icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) | 1802 | icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) |
1802 | { | 1803 | { |
1803 | icalcomponent *calendar; | 1804 | icalcomponent *calendar; |
1804 | 1805 | ||
1805 | // Root component | 1806 | // Root component |
1806 | calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); | 1807 | calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); |
1807 | 1808 | ||
1808 | icalproperty *p; | 1809 | icalproperty *p; |
1809 | 1810 | ||
1810 | // Product Identifier | 1811 | // Product Identifier |
1811 | p = icalproperty_new_prodid(CalFormat::productId().utf8()); | 1812 | p = icalproperty_new_prodid(CalFormat::productId().utf8()); |
1812 | icalcomponent_add_property(calendar,p); | 1813 | icalcomponent_add_property(calendar,p); |
1813 | 1814 | ||
1814 | // TODO: Add time zone | 1815 | // TODO: Add time zone |
1815 | 1816 | ||
1816 | // iCalendar version (2.0) | 1817 | // iCalendar version (2.0) |
1817 | p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); | 1818 | p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); |
1818 | icalcomponent_add_property(calendar,p); | 1819 | icalcomponent_add_property(calendar,p); |
1819 | 1820 | ||
1820 | // Custom properties | 1821 | // Custom properties |
1821 | if( cal != 0 ) | 1822 | if( cal != 0 ) |
1822 | writeCustomProperties(calendar, cal); | 1823 | writeCustomProperties(calendar, cal); |
1823 | 1824 | ||
1824 | return calendar; | 1825 | return calendar; |
1825 | } | 1826 | } |
1826 | 1827 | ||
1827 | 1828 | ||
1828 | 1829 | ||
1829 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. | 1830 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. |
1830 | // and break it down from its tree-like format into the dictionary format | 1831 | // and break it down from its tree-like format into the dictionary format |
1831 | // that is used internally in the ICalFormatImpl. | 1832 | // that is used internally in the ICalFormatImpl. |
1832 | bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) | 1833 | bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) |
1833 | { | 1834 | { |
1834 | // this function will populate the caldict dictionary and other event | 1835 | // this function will populate the caldict dictionary and other event |
1835 | // lists. It turns vevents into Events and then inserts them. | 1836 | // lists. It turns vevents into Events and then inserts them. |
1836 | 1837 | ||
1837 | if (!calendar) return false; | 1838 | if (!calendar) return false; |
1838 | 1839 | ||
1839 | // TODO: check for METHOD | 1840 | // TODO: check for METHOD |
1840 | #if 0 | 1841 | #if 0 |
1841 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { | 1842 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { |
1842 | char *methodType = 0; | 1843 | char *methodType = 0; |
1843 | methodType = fakeCString(vObjectUStringZValue(curVO)); | 1844 | methodType = fakeCString(vObjectUStringZValue(curVO)); |
1844 | if (mEnableDialogs) | 1845 | if (mEnableDialogs) |
1845 | KMessageBox::information(mTopWidget, | 1846 | KMessageBox::information(mTopWidget, |
1846 | i18n("This calendar is an iTIP transaction of type \"%1\".") | 1847 | i18n("This calendar is an iTIP transaction of type \"%1\".") |
1847 | .arg(methodType), | 1848 | .arg(methodType), |
1848 | i18n("%1: iTIP Transaction").arg(CalFormat::application())); | 1849 | i18n("%1: iTIP Transaction").arg(CalFormat::application())); |
1849 | delete methodType; | 1850 | delete methodType; |
1850 | } | 1851 | } |
1851 | #endif | 1852 | #endif |
1852 | 1853 | ||
1853 | icalproperty *p; | 1854 | icalproperty *p; |
1854 | 1855 | ||
1855 | p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); | 1856 | p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); |
1856 | if (!p) { | 1857 | if (!p) { |
1857 | // TODO: does no PRODID really matter? | 1858 | // TODO: does no PRODID really matter? |
1858 | // mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 1859 | // mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
1859 | // return false; | 1860 | // return false; |
1860 | mLoadedProductId = ""; | 1861 | mLoadedProductId = ""; |
1861 | mCalendarVersion = 0; | 1862 | mCalendarVersion = 0; |
1862 | } else { | 1863 | } else { |
1863 | mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); | 1864 | mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); |
1864 | mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); | 1865 | mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); |
1865 | 1866 | ||
1866 | delete mCompat; | 1867 | delete mCompat; |
1867 | mCompat = CompatFactory::createCompat( mLoadedProductId ); | 1868 | mCompat = CompatFactory::createCompat( mLoadedProductId ); |
1868 | } | 1869 | } |
1869 | 1870 | ||
1870 | // TODO: check for unknown PRODID | 1871 | // TODO: check for unknown PRODID |
1871 | #if 0 | 1872 | #if 0 |
1872 | if (!mCalendarVersion | 1873 | if (!mCalendarVersion |
1873 | && CalFormat::productId() != mLoadedProductId) { | 1874 | && CalFormat::productId() != mLoadedProductId) { |
1874 | // warn the user that we might have trouble reading non-known calendar. | 1875 | // warn the user that we might have trouble reading non-known calendar. |
1875 | if (mEnableDialogs) | 1876 | if (mEnableDialogs) |
1876 | KMessageBox::information(mTopWidget, | 1877 | KMessageBox::information(mTopWidget, |
1877 | i18n("This vCalendar file was not created by KOrganizer " | 1878 | i18n("This vCalendar file was not created by KOrganizer " |
1878 | "or any other product we support. Loading anyway..."), | 1879 | "or any other product we support. Loading anyway..."), |
1879 | i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); | 1880 | i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); |
1880 | } | 1881 | } |
1881 | #endif | 1882 | #endif |
1882 | 1883 | ||
1883 | p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); | 1884 | p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); |
1884 | if (!p) { | 1885 | if (!p) { |
1885 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 1886 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
1886 | return false; | 1887 | return false; |
1887 | } else { | 1888 | } else { |
1888 | const char *version = icalproperty_get_version(p); | 1889 | const char *version = icalproperty_get_version(p); |
1889 | 1890 | ||
1890 | if (strcmp(version,"1.0") == 0) { | 1891 | if (strcmp(version,"1.0") == 0) { |
1891 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, | 1892 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, |
1892 | i18n("Expected iCalendar format"))); | 1893 | i18n("Expected iCalendar format"))); |
1893 | return false; | 1894 | return false; |
1894 | } else if (strcmp(version,"2.0") != 0) { | 1895 | } else if (strcmp(version,"2.0") != 0) { |
1895 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 1896 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
1896 | return false; | 1897 | return false; |
1897 | } | 1898 | } |
1898 | } | 1899 | } |
1899 | 1900 | ||
1900 | 1901 | ||
1901 | // TODO: check for calendar format version | 1902 | // TODO: check for calendar format version |
1902 | #if 0 | 1903 | #if 0 |
1903 | // warn the user we might have trouble reading this unknown version. | 1904 | // warn the user we might have trouble reading this unknown version. |
1904 | if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { | 1905 | if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { |
1905 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1906 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1906 | if (strcmp(_VCAL_VERSION, s) != 0) | 1907 | if (strcmp(_VCAL_VERSION, s) != 0) |
1907 | if (mEnableDialogs) | 1908 | if (mEnableDialogs) |
1908 | KMessageBox::sorry(mTopWidget, | 1909 | KMessageBox::sorry(mTopWidget, |
1909 | i18n("This vCalendar file has version %1.\n" | 1910 | i18n("This vCalendar file has version %1.\n" |
1910 | "We only support %2.") | 1911 | "We only support %2.") |
1911 | .arg(s).arg(_VCAL_VERSION), | 1912 | .arg(s).arg(_VCAL_VERSION), |
1912 | i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); | 1913 | i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); |
1913 | deleteStr(s); | 1914 | deleteStr(s); |
1914 | } | 1915 | } |
1915 | #endif | 1916 | #endif |
1916 | 1917 | ||
1917 | // custom properties | 1918 | // custom properties |
1918 | readCustomProperties(calendar, cal); | 1919 | readCustomProperties(calendar, cal); |
1919 | 1920 | ||
1920 | // TODO: set time zone | 1921 | // TODO: set time zone |
1921 | #if 0 | 1922 | #if 0 |
1922 | // set the time zone | 1923 | // set the time zone |
1923 | if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { | 1924 | if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { |
1924 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1925 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1925 | cal->setTimeZone(s); | 1926 | cal->setTimeZone(s); |
1926 | deleteStr(s); | 1927 | deleteStr(s); |
1927 | } | 1928 | } |
1928 | #endif | 1929 | #endif |
1929 | 1930 | ||
1930 | // Store all events with a relatedTo property in a list for post-processing | 1931 | // Store all events with a relatedTo property in a list for post-processing |
1931 | mEventsRelate.clear(); | 1932 | mEventsRelate.clear(); |
1932 | mTodosRelate.clear(); | 1933 | mTodosRelate.clear(); |
1933 | // TODO: make sure that only actually added ecvens go to this lists. | 1934 | // TODO: make sure that only actually added ecvens go to this lists. |
1934 | 1935 | ||
1935 | icalcomponent *c; | 1936 | icalcomponent *c; |
1936 | 1937 | ||
1937 | // Iterate through all todos | 1938 | // Iterate through all todos |
1938 | c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); | 1939 | c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); |
1939 | while (c) { | 1940 | while (c) { |
1940 | // kdDebug(5800) << "----Todo found" << endl; | 1941 | // kdDebug(5800) << "----Todo found" << endl; |
1941 | Todo *todo = readTodo(c); | 1942 | Todo *todo = readTodo(c); |
1942 | if (!cal->todo(todo->uid())) cal->addTodo(todo); | 1943 | if (!cal->todo(todo->uid())) cal->addTodo(todo); |
1943 | c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT); | 1944 | c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT); |
1944 | } | 1945 | } |
1945 | 1946 | ||
1946 | // Iterate through all events | 1947 | // Iterate through all events |
1947 | c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); | 1948 | c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); |
1948 | while (c) { | 1949 | while (c) { |
1949 | // kdDebug(5800) << "----Event found" << endl; | 1950 | // kdDebug(5800) << "----Event found" << endl; |
1950 | Event *event = readEvent(c); | 1951 | Event *event = readEvent(c); |
1951 | if (!cal->event(event->uid())) cal->addEvent(event); | 1952 | if (!cal->event(event->uid())) cal->addEvent(event); |
1952 | c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT); | 1953 | c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT); |
1953 | } | 1954 | } |
1954 | 1955 | ||
1955 | // Iterate through all journals | 1956 | // Iterate through all journals |
1956 | c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT); | 1957 | c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT); |
1957 | while (c) { | 1958 | while (c) { |
1958 | // kdDebug(5800) << "----Journal found" << endl; | 1959 | // kdDebug(5800) << "----Journal found" << endl; |
1959 | Journal *journal = readJournal(c); | 1960 | Journal *journal = readJournal(c); |
1960 | if (!cal->journal(journal->uid())) cal->addJournal(journal); | 1961 | if (!cal->journal(journal->uid())) cal->addJournal(journal); |
1961 | c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT); | 1962 | c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT); |
1962 | } | 1963 | } |
1963 | 1964 | ||
1964 | #if 0 | 1965 | #if 0 |
1965 | initPropIterator(&i, vcal); | 1966 | initPropIterator(&i, vcal); |
1966 | 1967 | ||
1967 | // go through all the vobjects in the vcal | 1968 | // go through all the vobjects in the vcal |
1968 | while (moreIteration(&i)) { | 1969 | while (moreIteration(&i)) { |
1969 | curVO = nextVObject(&i); | 1970 | curVO = nextVObject(&i); |
1970 | 1971 | ||
1971 | /************************************************************************/ | 1972 | /************************************************************************/ |
1972 | 1973 | ||
1973 | // now, check to see that the object is an event or todo. | 1974 | // now, check to see that the object is an event or todo. |
1974 | if (strcmp(vObjectName(curVO), VCEventProp) == 0) { | 1975 | if (strcmp(vObjectName(curVO), VCEventProp) == 0) { |
1975 | 1976 | ||
1976 | if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) { | 1977 | if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) { |
1977 | char *s; | 1978 | char *s; |
1978 | s = fakeCString(vObjectUStringZValue(curVOProp)); | 1979 | s = fakeCString(vObjectUStringZValue(curVOProp)); |
1979 | // check to see if event was deleted by the kpilot conduit | 1980 | // check to see if event was deleted by the kpilot conduit |
1980 | if (atoi(s) == Event::SYNCDEL) { | 1981 | if (atoi(s) == Event::SYNCDEL) { |
1981 | deleteStr(s); | 1982 | deleteStr(s); |
1982 | goto SKIP; | 1983 | goto SKIP; |
1983 | } | 1984 | } |
1984 | deleteStr(s); | 1985 | deleteStr(s); |
1985 | } | 1986 | } |
1986 | 1987 | ||
1987 | // this code checks to see if we are trying to read in an event | 1988 | // this code checks to see if we are trying to read in an event |
1988 | // that we already find to be in the calendar. If we find this | 1989 | // that we already find to be in the calendar. If we find this |
1989 | // to be the case, we skip the event. | 1990 | // to be the case, we skip the event. |
1990 | if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { | 1991 | if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { |
1991 | char *s = fakeCString(vObjectUStringZValue(curVOProp)); | 1992 | char *s = fakeCString(vObjectUStringZValue(curVOProp)); |
1992 | QString tmpStr(s); | 1993 | QString tmpStr(s); |
1993 | deleteStr(s); | 1994 | deleteStr(s); |
1994 | 1995 | ||
1995 | if (cal->event(tmpStr)) { | 1996 | if (cal->event(tmpStr)) { |
1996 | goto SKIP; | 1997 | goto SKIP; |
1997 | } | 1998 | } |
1998 | if (cal->todo(tmpStr)) { | 1999 | if (cal->todo(tmpStr)) { |
1999 | goto SKIP; | 2000 | goto SKIP; |
2000 | } | 2001 | } |
2001 | } | 2002 | } |
2002 | 2003 | ||
2003 | if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && | 2004 | if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && |
2004 | (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { | 2005 | (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { |
2005 | kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; | 2006 | kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; |
2006 | goto SKIP; | 2007 | goto SKIP; |
2007 | } | 2008 | } |
2008 | 2009 | ||
2009 | anEvent = VEventToEvent(curVO); | 2010 | anEvent = VEventToEvent(curVO); |
2010 | // we now use addEvent instead of insertEvent so that the | 2011 | // we now use addEvent instead of insertEvent so that the |
2011 | // signal/slot get connected. | 2012 | // signal/slot get connected. |
2012 | if (anEvent) | 2013 | if (anEvent) |
2013 | cal->addEvent(anEvent); | 2014 | cal->addEvent(anEvent); |
2014 | else { | 2015 | else { |
2015 | // some sort of error must have occurred while in translation. | 2016 | // some sort of error must have occurred while in translation. |
2016 | goto SKIP; | 2017 | goto SKIP; |
2017 | } | 2018 | } |
2018 | } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { | 2019 | } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { |
2019 | anEvent = VTodoToEvent(curVO); | 2020 | anEvent = VTodoToEvent(curVO); |
2020 | cal->addTodo(anEvent); | 2021 | cal->addTodo(anEvent); |
2021 | } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || | 2022 | } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || |
2022 | (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || | 2023 | (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || |
2023 | (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { | 2024 | (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { |
2024 | // do nothing, we know these properties and we want to skip them. | 2025 | // do nothing, we know these properties and we want to skip them. |
2025 | // we have either already processed them or are ignoring them. | 2026 | // we have either already processed them or are ignoring them. |
2026 | ; | 2027 | ; |
2027 | } else { | 2028 | } else { |
2028 | ; | 2029 | ; |
2029 | } | 2030 | } |
2030 | SKIP: | 2031 | SKIP: |
2031 | ; | 2032 | ; |
2032 | } // while | 2033 | } // while |
2033 | #endif | 2034 | #endif |
2034 | 2035 | ||
2035 | // Post-Process list of events with relations, put Event objects in relation | 2036 | // Post-Process list of events with relations, put Event objects in relation |
2036 | Event *ev; | 2037 | Event *ev; |
2037 | for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { | 2038 | for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { |
2038 | ev->setRelatedTo(cal->event(ev->relatedToUid())); | 2039 | ev->setRelatedTo(cal->event(ev->relatedToUid())); |
2039 | } | 2040 | } |
2040 | Todo *todo; | 2041 | Todo *todo; |
2041 | for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { | 2042 | for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { |
2042 | todo->setRelatedTo(cal->todo(todo->relatedToUid())); | 2043 | todo->setRelatedTo(cal->todo(todo->relatedToUid())); |
2043 | } | 2044 | } |
2044 | 2045 | ||
2045 | return true; | 2046 | return true; |
2046 | } | 2047 | } |
2047 | 2048 | ||
2048 | QString ICalFormatImpl::extractErrorProperty(icalcomponent *c) | 2049 | QString ICalFormatImpl::extractErrorProperty(icalcomponent *c) |
2049 | { | 2050 | { |
2050 | // kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " | 2051 | // kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " |
2051 | // << icalcomponent_as_ical_string(c) << endl; | 2052 | // << icalcomponent_as_ical_string(c) << endl; |
2052 | 2053 | ||
2053 | QString errorMessage; | 2054 | QString errorMessage; |
2054 | 2055 | ||
2055 | icalproperty *error; | 2056 | icalproperty *error; |
2056 | error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY); | 2057 | error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY); |
2057 | while(error) { | 2058 | while(error) { |
2058 | errorMessage += icalproperty_get_xlicerror(error); | 2059 | errorMessage += icalproperty_get_xlicerror(error); |
2059 | errorMessage += "\n"; | 2060 | errorMessage += "\n"; |
2060 | error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY); | 2061 | error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY); |
2061 | } | 2062 | } |
2062 | 2063 | ||
2063 | // kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl; | 2064 | // kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl; |
2064 | 2065 | ||
2065 | return errorMessage; | 2066 | return errorMessage; |
2066 | } | 2067 | } |
2067 | 2068 | ||
2068 | void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r) | 2069 | void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r) |
2069 | { | 2070 | { |
2070 | int i; | 2071 | int i; |
2071 | 2072 | ||
2072 | 2073 | ||
2073 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2074 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2074 | int index = 0; | 2075 | int index = 0; |
2075 | QString out = " By Day: "; | 2076 | QString out = " By Day: "; |
2076 | while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2077 | while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2077 | out.append(QString::number(i) + " "); | 2078 | out.append(QString::number(i) + " "); |
2078 | } | 2079 | } |
2079 | } | 2080 | } |
2080 | if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2081 | if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2081 | int index = 0; | 2082 | int index = 0; |
2082 | QString out = " By Month Day: "; | 2083 | QString out = " By Month Day: "; |
2083 | while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2084 | while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2084 | out.append(QString::number(i) + " "); | 2085 | out.append(QString::number(i) + " "); |
2085 | } | 2086 | } |
2086 | } | 2087 | } |
2087 | if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2088 | if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2088 | int index = 0; | 2089 | int index = 0; |
2089 | QString out = " By Year Day: "; | 2090 | QString out = " By Year Day: "; |
2090 | while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2091 | while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2091 | out.append(QString::number(i) + " "); | 2092 | out.append(QString::number(i) + " "); |
2092 | } | 2093 | } |
2093 | } | 2094 | } |
2094 | if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2095 | if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2095 | int index = 0; | 2096 | int index = 0; |
2096 | QString out = " By Month: "; | 2097 | QString out = " By Month: "; |
2097 | while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2098 | while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2098 | out.append(QString::number(i) + " "); | 2099 | out.append(QString::number(i) + " "); |
2099 | } | 2100 | } |
2100 | } | 2101 | } |
2101 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2102 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2102 | int index = 0; | 2103 | int index = 0; |
2103 | QString out = " By Set Pos: "; | 2104 | QString out = " By Set Pos: "; |
2104 | while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2105 | while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2105 | out.append(QString::number(i) + " "); | 2106 | out.append(QString::number(i) + " "); |
2106 | } | 2107 | } |
2107 | } | 2108 | } |
2108 | } | 2109 | } |
2109 | 2110 | ||
2110 | icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence, | 2111 | icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence, |
2111 | Scheduler::Method method) | 2112 | Scheduler::Method method) |
2112 | { | 2113 | { |
2113 | icalcomponent *message = createCalendarComponent(); | 2114 | icalcomponent *message = createCalendarComponent(); |
2114 | 2115 | ||
2115 | icalproperty_method icalmethod = ICAL_METHOD_NONE; | 2116 | icalproperty_method icalmethod = ICAL_METHOD_NONE; |
2116 | 2117 | ||
2117 | switch (method) { | 2118 | switch (method) { |
2118 | case Scheduler::Publish: | 2119 | case Scheduler::Publish: |
2119 | icalmethod = ICAL_METHOD_PUBLISH; | 2120 | icalmethod = ICAL_METHOD_PUBLISH; |
2120 | break; | 2121 | break; |
2121 | case Scheduler::Request: | 2122 | case Scheduler::Request: |
2122 | icalmethod = ICAL_METHOD_REQUEST; | 2123 | icalmethod = ICAL_METHOD_REQUEST; |
2123 | break; | 2124 | break; |
2124 | case Scheduler::Refresh: | 2125 | case Scheduler::Refresh: |
2125 | icalmethod = ICAL_METHOD_REFRESH; | 2126 | icalmethod = ICAL_METHOD_REFRESH; |
2126 | break; | 2127 | break; |
2127 | case Scheduler::Cancel: | 2128 | case Scheduler::Cancel: |
2128 | icalmethod = ICAL_METHOD_CANCEL; | 2129 | icalmethod = ICAL_METHOD_CANCEL; |
2129 | break; | 2130 | break; |
2130 | case Scheduler::Add: | 2131 | case Scheduler::Add: |
2131 | icalmethod = ICAL_METHOD_ADD; | 2132 | icalmethod = ICAL_METHOD_ADD; |
2132 | break; | 2133 | break; |
2133 | case Scheduler::Reply: | 2134 | case Scheduler::Reply: |
2134 | icalmethod = ICAL_METHOD_REPLY; | 2135 | icalmethod = ICAL_METHOD_REPLY; |
2135 | break; | 2136 | break; |
2136 | case Scheduler::Counter: | 2137 | case Scheduler::Counter: |
2137 | icalmethod = ICAL_METHOD_COUNTER; | 2138 | icalmethod = ICAL_METHOD_COUNTER; |
2138 | break; | 2139 | break; |
2139 | case Scheduler::Declinecounter: | 2140 | case Scheduler::Declinecounter: |
2140 | icalmethod = ICAL_METHOD_DECLINECOUNTER; | 2141 | icalmethod = ICAL_METHOD_DECLINECOUNTER; |
2141 | break; | 2142 | break; |
2142 | default: | 2143 | default: |
2143 | 2144 | ||
2144 | return message; | 2145 | return message; |
2145 | } | 2146 | } |
2146 | 2147 | ||
2147 | icalcomponent_add_property(message,icalproperty_new_method(icalmethod)); | 2148 | icalcomponent_add_property(message,icalproperty_new_method(icalmethod)); |
2148 | 2149 | ||
2149 | // TODO: check, if dynamic cast is required | 2150 | // TODO: check, if dynamic cast is required |
2150 | if(incidence->type() == "Todo") { | 2151 | if(incidence->type() == "Todo") { |
2151 | Todo *todo = static_cast<Todo *>(incidence); | 2152 | Todo *todo = static_cast<Todo *>(incidence); |
2152 | icalcomponent_add_component(message,writeTodo(todo)); | 2153 | icalcomponent_add_component(message,writeTodo(todo)); |
2153 | } | 2154 | } |
2154 | if(incidence->type() == "Event") { | 2155 | if(incidence->type() == "Event") { |
2155 | Event *event = static_cast<Event *>(incidence); | 2156 | Event *event = static_cast<Event *>(incidence); |
2156 | icalcomponent_add_component(message,writeEvent(event)); | 2157 | icalcomponent_add_component(message,writeEvent(event)); |
2157 | } | 2158 | } |
2158 | if(incidence->type() == "FreeBusy") { | 2159 | if(incidence->type() == "FreeBusy") { |
2159 | FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); | 2160 | FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); |
2160 | icalcomponent_add_component(message,writeFreeBusy(freebusy, method)); | 2161 | icalcomponent_add_component(message,writeFreeBusy(freebusy, method)); |
2161 | } | 2162 | } |
2162 | 2163 | ||
2163 | return message; | 2164 | return message; |
2164 | } | 2165 | } |
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index 51f2e9d..1e99082 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp | |||
@@ -1,420 +1,427 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | #include <kidmanager.h> | 24 | #include <kidmanager.h> |
25 | 25 | ||
26 | #include "calformat.h" | 26 | #include "calformat.h" |
27 | #include "syncdefines.h" | 27 | #include "syncdefines.h" |
28 | 28 | ||
29 | #include "incidencebase.h" | 29 | #include "incidencebase.h" |
30 | 30 | ||
31 | using namespace KCal; | 31 | using namespace KCal; |
32 | 32 | ||
33 | IncidenceBase::IncidenceBase() : | 33 | IncidenceBase::IncidenceBase() : |
34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), | 34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), |
35 | mPilotId(0), mSyncStatus(SYNCMOD) | 35 | mPilotId(0), mSyncStatus(SYNCMOD) |
36 | { | 36 | { |
37 | setUid(CalFormat::createUniqueId()); | 37 | setUid(CalFormat::createUniqueId()); |
38 | mOrganizer = ""; | 38 | mOrganizer = ""; |
39 | mFloats = false; | 39 | mFloats = false; |
40 | mDuration = 0; | 40 | mDuration = 0; |
41 | mHasDuration = false; | 41 | mHasDuration = false; |
42 | mPilotId = 0; | 42 | mPilotId = 0; |
43 | mExternalId = ":"; | 43 | mExternalId = ":"; |
44 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 44 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
45 | mSyncStatus = 0; | 45 | mSyncStatus = 0; |
46 | mAttendees.setAutoDelete( true ); | 46 | mAttendees.setAutoDelete( true ); |
47 | } | 47 | } |
48 | 48 | ||
49 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : | 49 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : |
50 | CustomProperties( i ) | 50 | CustomProperties( i ) |
51 | { | 51 | { |
52 | mReadOnly = i.mReadOnly; | 52 | mReadOnly = i.mReadOnly; |
53 | mDtStart = i.mDtStart; | 53 | mDtStart = i.mDtStart; |
54 | mDuration = i.mDuration; | 54 | mDuration = i.mDuration; |
55 | mHasDuration = i.mHasDuration; | 55 | mHasDuration = i.mHasDuration; |
56 | mOrganizer = i.mOrganizer; | 56 | mOrganizer = i.mOrganizer; |
57 | mUid = i.mUid; | 57 | mUid = i.mUid; |
58 | QPtrList<Attendee> attendees = i.attendees(); | 58 | QPtrList<Attendee> attendees = i.attendees(); |
59 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { | 59 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { |
60 | mAttendees.append( new Attendee( *a ) ); | 60 | mAttendees.append( new Attendee( *a ) ); |
61 | } | 61 | } |
62 | mFloats = i.mFloats; | 62 | mFloats = i.mFloats; |
63 | mLastModified = i.mLastModified; | 63 | mLastModified = i.mLastModified; |
64 | mPilotId = i.mPilotId; | 64 | mPilotId = i.mPilotId; |
65 | mTempSyncStat = i.mTempSyncStat; | 65 | mTempSyncStat = i.mTempSyncStat; |
66 | mSyncStatus = i.mSyncStatus; | 66 | mSyncStatus = i.mSyncStatus; |
67 | mExternalId = i.mExternalId; | 67 | mExternalId = i.mExternalId; |
68 | // The copied object is a new one, so it isn't observed by the observer | 68 | // The copied object is a new one, so it isn't observed by the observer |
69 | // of the original object. | 69 | // of the original object. |
70 | mObservers.clear(); | 70 | mObservers.clear(); |
71 | 71 | ||
72 | mAttendees.setAutoDelete( true ); | 72 | mAttendees.setAutoDelete( true ); |
73 | } | 73 | } |
74 | 74 | ||
75 | IncidenceBase::~IncidenceBase() | 75 | IncidenceBase::~IncidenceBase() |
76 | { | 76 | { |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) | 80 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) |
81 | { | 81 | { |
82 | // do not compare mSyncStatus and mExternalId | 82 | // do not compare mSyncStatus and mExternalId |
83 | if( i1.attendees().count() != i2.attendees().count() ) { | 83 | if( i1.attendees().count() != i2.attendees().count() ) { |
84 | return false; // no need to check further | 84 | return false; // no need to check further |
85 | } | 85 | } |
86 | if ( i1.attendees().count() > 0 ) { | 86 | if ( i1.attendees().count() > 0 ) { |
87 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; | 87 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; |
88 | while ( a1 ) { | 88 | while ( a1 ) { |
89 | if ( !( (*a1) == (*a2)) ) | 89 | if ( !( (*a1) == (*a2)) ) |
90 | { | 90 | { |
91 | //qDebug("Attendee not equal "); | 91 | //qDebug("Attendee not equal "); |
92 | return false; | 92 | return false; |
93 | } | 93 | } |
94 | a1 = i1.attendees().next(); | 94 | a1 = i1.attendees().next(); |
95 | a2 = i2.attendees().next(); | 95 | a2 = i2.attendees().next(); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | //if ( i1.dtStart() != i2.dtStart() ) | 98 | //if ( i1.dtStart() != i2.dtStart() ) |
99 | // return false; | 99 | // return false; |
100 | #if 0 | 100 | #if 0 |
101 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); | 101 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); |
102 | qDebug("1 %d ",i1.duration() == i2.duration() ); | 102 | qDebug("1 %d ",i1.duration() == i2.duration() ); |
103 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); | 103 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); |
104 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); | 104 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); |
105 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); | 105 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); |
106 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); | 106 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); |
107 | 107 | ||
108 | #endif | 108 | #endif |
109 | if ( i1.hasDuration() == i2.hasDuration() ) { | ||
110 | if ( i1.hasDuration() ) { | ||
111 | if ( i1.duration() != i2.duration() ) | ||
112 | return false; | ||
113 | } | ||
114 | } else { | ||
115 | return false; | ||
116 | } | ||
117 | |||
109 | return ( i1.organizer() == i2.organizer() && | 118 | return ( i1.organizer() == i2.organizer() && |
110 | // i1.uid() == i2.uid() && | 119 | // i1.uid() == i2.uid() && |
111 | // Don't compare lastModified, otherwise the operator is not | 120 | // Don't compare lastModified, otherwise the operator is not |
112 | // of much use. We are not comparing for identity, after all. | 121 | // of much use. We are not comparing for identity, after all. |
113 | i1.doesFloat() == i2.doesFloat() && | 122 | i1.doesFloat() == i2.doesFloat() && |
114 | i1.duration() == i2.duration() && | ||
115 | i1.hasDuration() == i2.hasDuration() && | ||
116 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); | 123 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); |
117 | // no need to compare mObserver | 124 | // no need to compare mObserver |
118 | } | 125 | } |
119 | 126 | ||
120 | 127 | ||
121 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) | 128 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) |
122 | { | 129 | { |
123 | QTime t = dt.time(); | 130 | QTime t = dt.time(); |
124 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 131 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
125 | return dt; | 132 | return dt; |
126 | } | 133 | } |
127 | 134 | ||
128 | 135 | ||
129 | void IncidenceBase::setUid(const QString &uid) | 136 | void IncidenceBase::setUid(const QString &uid) |
130 | { | 137 | { |
131 | mUid = uid; | 138 | mUid = uid; |
132 | updated(); | 139 | updated(); |
133 | } | 140 | } |
134 | 141 | ||
135 | QString IncidenceBase::uid() const | 142 | QString IncidenceBase::uid() const |
136 | { | 143 | { |
137 | return mUid; | 144 | return mUid; |
138 | } | 145 | } |
139 | 146 | ||
140 | void IncidenceBase::setLastModified(const QDateTime &lm) | 147 | void IncidenceBase::setLastModified(const QDateTime &lm) |
141 | { | 148 | { |
142 | // DON'T! updated() because we call this from | 149 | // DON'T! updated() because we call this from |
143 | // Calendar::updateEvent(). | 150 | // Calendar::updateEvent(). |
144 | mLastModified = getEvenTime(lm); | 151 | mLastModified = getEvenTime(lm); |
145 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); | 152 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); |
146 | } | 153 | } |
147 | 154 | ||
148 | QDateTime IncidenceBase::lastModified() const | 155 | QDateTime IncidenceBase::lastModified() const |
149 | { | 156 | { |
150 | return mLastModified; | 157 | return mLastModified; |
151 | } | 158 | } |
152 | 159 | ||
153 | void IncidenceBase::setOrganizer(const QString &o) | 160 | void IncidenceBase::setOrganizer(const QString &o) |
154 | { | 161 | { |
155 | // we don't check for readonly here, because it is | 162 | // we don't check for readonly here, because it is |
156 | // possible that by setting the organizer we are changing | 163 | // possible that by setting the organizer we are changing |
157 | // the event's readonly status... | 164 | // the event's readonly status... |
158 | mOrganizer = o; | 165 | mOrganizer = o; |
159 | if (mOrganizer.left(7).upper() == "MAILTO:") | 166 | if (mOrganizer.left(7).upper() == "MAILTO:") |
160 | mOrganizer = mOrganizer.remove(0,7); | 167 | mOrganizer = mOrganizer.remove(0,7); |
161 | 168 | ||
162 | updated(); | 169 | updated(); |
163 | } | 170 | } |
164 | 171 | ||
165 | QString IncidenceBase::organizer() const | 172 | QString IncidenceBase::organizer() const |
166 | { | 173 | { |
167 | return mOrganizer; | 174 | return mOrganizer; |
168 | } | 175 | } |
169 | 176 | ||
170 | void IncidenceBase::setReadOnly( bool readOnly ) | 177 | void IncidenceBase::setReadOnly( bool readOnly ) |
171 | { | 178 | { |
172 | mReadOnly = readOnly; | 179 | mReadOnly = readOnly; |
173 | } | 180 | } |
174 | 181 | ||
175 | void IncidenceBase::setDtStart(const QDateTime &dtStart) | 182 | void IncidenceBase::setDtStart(const QDateTime &dtStart) |
176 | { | 183 | { |
177 | // if (mReadOnly) return; | 184 | // if (mReadOnly) return; |
178 | mDtStart = getEvenTime(dtStart); | 185 | mDtStart = getEvenTime(dtStart); |
179 | updated(); | 186 | updated(); |
180 | } | 187 | } |
181 | 188 | ||
182 | 189 | ||
183 | QDateTime IncidenceBase::dtStart() const | 190 | QDateTime IncidenceBase::dtStart() const |
184 | { | 191 | { |
185 | return mDtStart; | 192 | return mDtStart; |
186 | } | 193 | } |
187 | 194 | ||
188 | QString IncidenceBase::dtStartTimeStr() const | 195 | QString IncidenceBase::dtStartTimeStr() const |
189 | { | 196 | { |
190 | return KGlobal::locale()->formatTime(dtStart().time()); | 197 | return KGlobal::locale()->formatTime(dtStart().time()); |
191 | } | 198 | } |
192 | 199 | ||
193 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const | 200 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const |
194 | { | 201 | { |
195 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 202 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
196 | } | 203 | } |
197 | 204 | ||
198 | QString IncidenceBase::dtStartStr(bool shortfmt) const | 205 | QString IncidenceBase::dtStartStr(bool shortfmt) const |
199 | { | 206 | { |
200 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); | 207 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); |
201 | } | 208 | } |
202 | 209 | ||
203 | 210 | ||
204 | bool IncidenceBase::doesFloat() const | 211 | bool IncidenceBase::doesFloat() const |
205 | { | 212 | { |
206 | return mFloats; | 213 | return mFloats; |
207 | } | 214 | } |
208 | 215 | ||
209 | void IncidenceBase::setFloats(bool f) | 216 | void IncidenceBase::setFloats(bool f) |
210 | { | 217 | { |
211 | if (mReadOnly) return; | 218 | if (mReadOnly) return; |
212 | mFloats = f; | 219 | mFloats = f; |
213 | updated(); | 220 | updated(); |
214 | } | 221 | } |
215 | 222 | ||
216 | 223 | ||
217 | bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) | 224 | bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) |
218 | { | 225 | { |
219 | if (mReadOnly) return false; | 226 | if (mReadOnly) return false; |
220 | if (a->name().left(7).upper() == "MAILTO:") | 227 | if (a->name().left(7).upper() == "MAILTO:") |
221 | a->setName(a->name().remove(0,7)); | 228 | a->setName(a->name().remove(0,7)); |
222 | 229 | ||
223 | QPtrListIterator<Attendee> qli(mAttendees); | 230 | QPtrListIterator<Attendee> qli(mAttendees); |
224 | 231 | ||
225 | qli.toFirst(); | 232 | qli.toFirst(); |
226 | while (qli) { | 233 | while (qli) { |
227 | if (*qli.current() == *a) | 234 | if (*qli.current() == *a) |
228 | return false; | 235 | return false; |
229 | ++qli; | 236 | ++qli; |
230 | } | 237 | } |
231 | mAttendees.append(a); | 238 | mAttendees.append(a); |
232 | if (doupdate) updated(); | 239 | if (doupdate) updated(); |
233 | return true; | 240 | return true; |
234 | } | 241 | } |
235 | 242 | ||
236 | #if 0 | 243 | #if 0 |
237 | void IncidenceBase::removeAttendee(Attendee *a) | 244 | void IncidenceBase::removeAttendee(Attendee *a) |
238 | { | 245 | { |
239 | if (mReadOnly) return; | 246 | if (mReadOnly) return; |
240 | mAttendees.removeRef(a); | 247 | mAttendees.removeRef(a); |
241 | updated(); | 248 | updated(); |
242 | } | 249 | } |
243 | 250 | ||
244 | void IncidenceBase::removeAttendee(const char *n) | 251 | void IncidenceBase::removeAttendee(const char *n) |
245 | { | 252 | { |
246 | Attendee *a; | 253 | Attendee *a; |
247 | 254 | ||
248 | if (mReadOnly) return; | 255 | if (mReadOnly) return; |
249 | for (a = mAttendees.first(); a; a = mAttendees.next()) | 256 | for (a = mAttendees.first(); a; a = mAttendees.next()) |
250 | if (a->getName() == n) { | 257 | if (a->getName() == n) { |
251 | mAttendees.remove(); | 258 | mAttendees.remove(); |
252 | break; | 259 | break; |
253 | } | 260 | } |
254 | } | 261 | } |
255 | #endif | 262 | #endif |
256 | 263 | ||
257 | void IncidenceBase::clearAttendees() | 264 | void IncidenceBase::clearAttendees() |
258 | { | 265 | { |
259 | if (mReadOnly) return; | 266 | if (mReadOnly) return; |
260 | mAttendees.clear(); | 267 | mAttendees.clear(); |
261 | } | 268 | } |
262 | 269 | ||
263 | #if 0 | 270 | #if 0 |
264 | Attendee *IncidenceBase::getAttendee(const char *n) const | 271 | Attendee *IncidenceBase::getAttendee(const char *n) const |
265 | { | 272 | { |
266 | QPtrListIterator<Attendee> qli(mAttendees); | 273 | QPtrListIterator<Attendee> qli(mAttendees); |
267 | 274 | ||
268 | qli.toFirst(); | 275 | qli.toFirst(); |
269 | while (qli) { | 276 | while (qli) { |
270 | if (qli.current()->getName() == n) | 277 | if (qli.current()->getName() == n) |
271 | return qli.current(); | 278 | return qli.current(); |
272 | ++qli; | 279 | ++qli; |
273 | } | 280 | } |
274 | return 0L; | 281 | return 0L; |
275 | } | 282 | } |
276 | #endif | 283 | #endif |
277 | 284 | ||
278 | Attendee *IncidenceBase::attendeeByMail(const QString &email) | 285 | Attendee *IncidenceBase::attendeeByMail(const QString &email) |
279 | { | 286 | { |
280 | QPtrListIterator<Attendee> qli(mAttendees); | 287 | QPtrListIterator<Attendee> qli(mAttendees); |
281 | 288 | ||
282 | qli.toFirst(); | 289 | qli.toFirst(); |
283 | while (qli) { | 290 | while (qli) { |
284 | if (qli.current()->email().lower() == email.lower()) | 291 | if (qli.current()->email().lower() == email.lower()) |
285 | return qli.current(); | 292 | return qli.current(); |
286 | ++qli; | 293 | ++qli; |
287 | } | 294 | } |
288 | return 0L; | 295 | return 0L; |
289 | } | 296 | } |
290 | 297 | ||
291 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) | 298 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) |
292 | { | 299 | { |
293 | QPtrListIterator<Attendee> qli(mAttendees); | 300 | QPtrListIterator<Attendee> qli(mAttendees); |
294 | 301 | ||
295 | QStringList mails = emails; | 302 | QStringList mails = emails; |
296 | if (!email.isEmpty()) { | 303 | if (!email.isEmpty()) { |
297 | mails.append(email); | 304 | mails.append(email); |
298 | } | 305 | } |
299 | qli.toFirst(); | 306 | qli.toFirst(); |
300 | while (qli) { | 307 | while (qli) { |
301 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { | 308 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { |
302 | if (qli.current()->email().lower() == (*it).lower()) | 309 | if (qli.current()->email().lower() == (*it).lower()) |
303 | return qli.current(); | 310 | return qli.current(); |
304 | } | 311 | } |
305 | 312 | ||
306 | ++qli; | 313 | ++qli; |
307 | } | 314 | } |
308 | return 0L; | 315 | return 0L; |
309 | } | 316 | } |
310 | 317 | ||
311 | void IncidenceBase::setDuration(int seconds) | 318 | void IncidenceBase::setDuration(int seconds) |
312 | { | 319 | { |
313 | mDuration = seconds; | 320 | mDuration = seconds; |
314 | setHasDuration(true); | 321 | setHasDuration(true); |
315 | } | 322 | } |
316 | 323 | ||
317 | int IncidenceBase::duration() const | 324 | int IncidenceBase::duration() const |
318 | { | 325 | { |
319 | return mDuration; | 326 | return mDuration; |
320 | } | 327 | } |
321 | 328 | ||
322 | void IncidenceBase::setHasDuration(bool b) | 329 | void IncidenceBase::setHasDuration(bool b) |
323 | { | 330 | { |
324 | mHasDuration = b; | 331 | mHasDuration = b; |
325 | } | 332 | } |
326 | 333 | ||
327 | bool IncidenceBase::hasDuration() const | 334 | bool IncidenceBase::hasDuration() const |
328 | { | 335 | { |
329 | return mHasDuration; | 336 | return mHasDuration; |
330 | } | 337 | } |
331 | 338 | ||
332 | void IncidenceBase::setSyncStatus(int stat) | 339 | void IncidenceBase::setSyncStatus(int stat) |
333 | { | 340 | { |
334 | if (mReadOnly) return; | 341 | if (mReadOnly) return; |
335 | mSyncStatus = stat; | 342 | mSyncStatus = stat; |
336 | } | 343 | } |
337 | 344 | ||
338 | int IncidenceBase::syncStatus() const | 345 | int IncidenceBase::syncStatus() const |
339 | { | 346 | { |
340 | return mSyncStatus; | 347 | return mSyncStatus; |
341 | } | 348 | } |
342 | 349 | ||
343 | void IncidenceBase::setPilotId( int id ) | 350 | void IncidenceBase::setPilotId( int id ) |
344 | { | 351 | { |
345 | if (mReadOnly) return; | 352 | if (mReadOnly) return; |
346 | mPilotId = id; | 353 | mPilotId = id; |
347 | } | 354 | } |
348 | 355 | ||
349 | int IncidenceBase::pilotId() const | 356 | int IncidenceBase::pilotId() const |
350 | { | 357 | { |
351 | return mPilotId; | 358 | return mPilotId; |
352 | } | 359 | } |
353 | 360 | ||
354 | int IncidenceBase::tempSyncStat() const | 361 | int IncidenceBase::tempSyncStat() const |
355 | { | 362 | { |
356 | return mTempSyncStat; | 363 | return mTempSyncStat; |
357 | } | 364 | } |
358 | void IncidenceBase::setTempSyncStat( int id ) | 365 | void IncidenceBase::setTempSyncStat( int id ) |
359 | { | 366 | { |
360 | if (mReadOnly) return; | 367 | if (mReadOnly) return; |
361 | mTempSyncStat = id; | 368 | mTempSyncStat = id; |
362 | } | 369 | } |
363 | 370 | ||
364 | void IncidenceBase::removeID(const QString &prof) | 371 | void IncidenceBase::removeID(const QString &prof) |
365 | { | 372 | { |
366 | if ( prof.isEmpty() ) | 373 | if ( prof.isEmpty() ) |
367 | mExternalId = ":"; | 374 | mExternalId = ":"; |
368 | else | 375 | else |
369 | mExternalId = KIdManager::removeId ( mExternalId, prof); | 376 | mExternalId = KIdManager::removeId ( mExternalId, prof); |
370 | 377 | ||
371 | } | 378 | } |
372 | void IncidenceBase::setID( const QString & prof , const QString & id ) | 379 | void IncidenceBase::setID( const QString & prof , const QString & id ) |
373 | { | 380 | { |
374 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); | 381 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); |
375 | } | 382 | } |
376 | QString IncidenceBase::getID( const QString & prof) | 383 | QString IncidenceBase::getID( const QString & prof) |
377 | { | 384 | { |
378 | return KIdManager::getId ( mExternalId, prof ); | 385 | return KIdManager::getId ( mExternalId, prof ); |
379 | } | 386 | } |
380 | 387 | ||
381 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: | 388 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: |
382 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 | 389 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 |
383 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) | 390 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) |
384 | { | 391 | { |
385 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); | 392 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); |
386 | } | 393 | } |
387 | QString IncidenceBase::getCsum( const QString & prof) | 394 | QString IncidenceBase::getCsum( const QString & prof) |
388 | { | 395 | { |
389 | return KIdManager::getCsum ( mExternalId, prof ); | 396 | return KIdManager::getCsum ( mExternalId, prof ); |
390 | } | 397 | } |
391 | 398 | ||
392 | void IncidenceBase::setIDStr( const QString & s ) | 399 | void IncidenceBase::setIDStr( const QString & s ) |
393 | { | 400 | { |
394 | if (mReadOnly) return; | 401 | if (mReadOnly) return; |
395 | mExternalId = s; | 402 | mExternalId = s; |
396 | } | 403 | } |
397 | 404 | ||
398 | QString IncidenceBase::IDStr() const | 405 | QString IncidenceBase::IDStr() const |
399 | { | 406 | { |
400 | return mExternalId ; | 407 | return mExternalId ; |
401 | } | 408 | } |
402 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) | 409 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) |
403 | { | 410 | { |
404 | if( !mObservers.contains(observer) ) mObservers.append( observer ); | 411 | if( !mObservers.contains(observer) ) mObservers.append( observer ); |
405 | } | 412 | } |
406 | 413 | ||
407 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) | 414 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) |
408 | { | 415 | { |
409 | mObservers.remove( observer ); | 416 | mObservers.remove( observer ); |
410 | } | 417 | } |
411 | 418 | ||
412 | void IncidenceBase::updated() | 419 | void IncidenceBase::updated() |
413 | { | 420 | { |
414 | QPtrListIterator<Observer> it(mObservers); | 421 | QPtrListIterator<Observer> it(mObservers); |
415 | while( it.current() ) { | 422 | while( it.current() ) { |
416 | Observer *o = it.current(); | 423 | Observer *o = it.current(); |
417 | ++it; | 424 | ++it; |
418 | o->incidenceUpdated( this ); | 425 | o->incidenceUpdated( this ); |
419 | } | 426 | } |
420 | } | 427 | } |