author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /libkcal/icalformatimpl.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | libkcal/icalformatimpl.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp index 65eabc8..ea144ee 100644 --- a/libkcal/icalformatimpl.cpp +++ b/libkcal/icalformatimpl.cpp | |||
@@ -1,120 +1,123 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qdatetime.h> | 21 | #include <qdatetime.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qptrlist.h> | 23 | #include <q3ptrlist.h> |
24 | #include <qfile.h> | 24 | #include <qfile.h> |
25 | //Added by qt3to4: | ||
26 | #include <Q3ValueList> | ||
27 | #include <Q3CString> | ||
25 | 28 | ||
26 | #include <kdebug.h> | 29 | #include <kdebug.h> |
27 | #include <klocale.h> | 30 | #include <klocale.h> |
28 | #include <kglobal.h> | 31 | #include <kglobal.h> |
29 | 32 | ||
30 | extern "C" { | 33 | extern "C" { |
31 | #include <ical.h> | 34 | #include <ical.h> |
32 | #include <icalss.h> | 35 | #include <icalss.h> |
33 | #include <icalparser.h> | 36 | #include <icalparser.h> |
34 | #include <icalrestriction.h> | 37 | #include <icalrestriction.h> |
35 | } | 38 | } |
36 | 39 | ||
37 | #include "calendar.h" | 40 | #include "calendar.h" |
38 | #include "journal.h" | 41 | #include "journal.h" |
39 | #include "icalformat.h" | 42 | #include "icalformat.h" |
40 | #include "icalformatimpl.h" | 43 | #include "icalformatimpl.h" |
41 | #include "compat.h" | 44 | #include "compat.h" |
42 | 45 | ||
43 | #define _ICAL_VERSION "2.0" | 46 | #define _ICAL_VERSION "2.0" |
44 | 47 | ||
45 | using namespace KCal; | 48 | using namespace KCal; |
46 | 49 | ||
47 | const int gSecondsPerMinute = 60; | 50 | const int gSecondsPerMinute = 60; |
48 | const int gSecondsPerHour = gSecondsPerMinute * 60; | 51 | const int gSecondsPerHour = gSecondsPerMinute * 60; |
49 | const int gSecondsPerDay = gSecondsPerHour * 24; | 52 | const int gSecondsPerDay = gSecondsPerHour * 24; |
50 | const int gSecondsPerWeek = gSecondsPerDay * 7; | 53 | const int gSecondsPerWeek = gSecondsPerDay * 7; |
51 | 54 | ||
52 | ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : | 55 | ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : |
53 | mParent( parent ), mCalendarVersion( 0 ) | 56 | mParent( parent ), mCalendarVersion( 0 ) |
54 | { | 57 | { |
55 | mCompat = new Compat; | 58 | mCompat = new Compat; |
56 | } | 59 | } |
57 | 60 | ||
58 | ICalFormatImpl::~ICalFormatImpl() | 61 | ICalFormatImpl::~ICalFormatImpl() |
59 | { | 62 | { |
60 | delete mCompat; | 63 | delete mCompat; |
61 | } | 64 | } |
62 | 65 | ||
63 | class ToStringVisitor : public Incidence::Visitor | 66 | class ToStringVisitor : public Incidence::Visitor |
64 | { | 67 | { |
65 | public: | 68 | public: |
66 | ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} | 69 | ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} |
67 | 70 | ||
68 | bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } | 71 | bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } |
69 | bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } | 72 | bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } |
70 | bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } | 73 | bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } |
71 | 74 | ||
72 | icalcomponent *component() { return mComponent; } | 75 | icalcomponent *component() { return mComponent; } |
73 | 76 | ||
74 | private: | 77 | private: |
75 | ICalFormatImpl *mImpl; | 78 | ICalFormatImpl *mImpl; |
76 | icalcomponent *mComponent; | 79 | icalcomponent *mComponent; |
77 | }; | 80 | }; |
78 | 81 | ||
79 | icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) | 82 | icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) |
80 | { | 83 | { |
81 | ToStringVisitor v( this ); | 84 | ToStringVisitor v( this ); |
82 | incidence->accept(v); | 85 | incidence->accept(v); |
83 | return v.component(); | 86 | return v.component(); |
84 | } | 87 | } |
85 | 88 | ||
86 | icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) | 89 | icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) |
87 | { | 90 | { |
88 | QString tmpStr; | 91 | QString tmpStr; |
89 | QStringList tmpStrList; | 92 | QStringList tmpStrList; |
90 | 93 | ||
91 | icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); | 94 | icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); |
92 | 95 | ||
93 | writeIncidence(vtodo,todo); | 96 | writeIncidence(vtodo,todo); |
94 | 97 | ||
95 | // due date | 98 | // due date |
96 | if (todo->hasDueDate()) { | 99 | if (todo->hasDueDate()) { |
97 | icaltimetype due; | 100 | icaltimetype due; |
98 | if (todo->doesFloat()) { | 101 | if (todo->doesFloat()) { |
99 | due = writeICalDate(todo->dtDue().date()); | 102 | due = writeICalDate(todo->dtDue().date()); |
100 | } else { | 103 | } else { |
101 | due = writeICalDateTime(todo->dtDue()); | 104 | due = writeICalDateTime(todo->dtDue()); |
102 | } | 105 | } |
103 | icalcomponent_add_property(vtodo,icalproperty_new_due(due)); | 106 | icalcomponent_add_property(vtodo,icalproperty_new_due(due)); |
104 | } | 107 | } |
105 | 108 | ||
106 | // start time | 109 | // start time |
107 | if (todo->hasStartDate()) { | 110 | if (todo->hasStartDate()) { |
108 | icaltimetype start; | 111 | icaltimetype start; |
109 | if (todo->doesFloat()) { | 112 | if (todo->doesFloat()) { |
110 | // kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; | 113 | // kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; |
111 | start = writeICalDate(todo->dtStart().date()); | 114 | start = writeICalDate(todo->dtStart().date()); |
112 | } else { | 115 | } else { |
113 | // kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; | 116 | // kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; |
114 | start = writeICalDateTime(todo->dtStart()); | 117 | start = writeICalDateTime(todo->dtStart()); |
115 | } | 118 | } |
116 | icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); | 119 | icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); |
117 | } | 120 | } |
118 | 121 | ||
119 | // completion date | 122 | // completion date |
120 | if (todo->isCompleted()) { | 123 | if (todo->isCompleted()) { |
@@ -128,736 +131,736 @@ icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) | |||
128 | } | 131 | } |
129 | 132 | ||
130 | icalcomponent_add_property(vtodo, | 133 | icalcomponent_add_property(vtodo, |
131 | icalproperty_new_percentcomplete(todo->percentComplete())); | 134 | icalproperty_new_percentcomplete(todo->percentComplete())); |
132 | 135 | ||
133 | return vtodo; | 136 | return vtodo; |
134 | } | 137 | } |
135 | 138 | ||
136 | icalcomponent *ICalFormatImpl::writeEvent(Event *event) | 139 | icalcomponent *ICalFormatImpl::writeEvent(Event *event) |
137 | { | 140 | { |
138 | kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() | 141 | kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() |
139 | << ")" << endl; | 142 | << ")" << endl; |
140 | 143 | ||
141 | QString tmpStr; | 144 | QString tmpStr; |
142 | QStringList tmpStrList; | 145 | QStringList tmpStrList; |
143 | 146 | ||
144 | icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); | 147 | icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); |
145 | 148 | ||
146 | writeIncidence(vevent,event); | 149 | writeIncidence(vevent,event); |
147 | 150 | ||
148 | // start time | 151 | // start time |
149 | icaltimetype start; | 152 | icaltimetype start; |
150 | if (event->doesFloat()) { | 153 | if (event->doesFloat()) { |
151 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; | 154 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; |
152 | start = writeICalDate(event->dtStart().date()); | 155 | start = writeICalDate(event->dtStart().date()); |
153 | } else { | 156 | } else { |
154 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; | 157 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; |
155 | start = writeICalDateTime(event->dtStart()); | 158 | start = writeICalDateTime(event->dtStart()); |
156 | } | 159 | } |
157 | icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); | 160 | icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); |
158 | 161 | ||
159 | if (event->hasEndDate()) { | 162 | if (event->hasEndDate()) { |
160 | // end time | 163 | // end time |
161 | icaltimetype end; | 164 | icaltimetype end; |
162 | if (event->doesFloat()) { | 165 | if (event->doesFloat()) { |
163 | // kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; | 166 | // kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; |
164 | // +1 day because end date is non-inclusive. | 167 | // +1 day because end date is non-inclusive. |
165 | end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); | 168 | end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); |
166 | } else { | 169 | } else { |
167 | // kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; | 170 | // kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; |
168 | end = writeICalDateTime(event->dtEnd()); | 171 | end = writeICalDateTime(event->dtEnd()); |
169 | } | 172 | } |
170 | icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); | 173 | icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); |
171 | } | 174 | } |
172 | 175 | ||
173 | // TODO: attachments, resources | 176 | // TODO: attachments, resources |
174 | #if 0 | 177 | #if 0 |
175 | // attachments | 178 | // attachments |
176 | tmpStrList = anEvent->attachments(); | 179 | tmpStrList = anEvent->attachments(); |
177 | for ( QStringList::Iterator it = tmpStrList.begin(); | 180 | for ( QStringList::Iterator it = tmpStrList.begin(); |
178 | it != tmpStrList.end(); | 181 | it != tmpStrList.end(); |
179 | ++it ) | 182 | ++it ) |
180 | addPropValue(vevent, VCAttachProp, (*it).utf8()); | 183 | addPropValue(vevent, VCAttachProp, (*it).utf8()); |
181 | 184 | ||
182 | // resources | 185 | // resources |
183 | tmpStrList = anEvent->resources(); | 186 | tmpStrList = anEvent->resources(); |
184 | tmpStr = tmpStrList.join(";"); | 187 | tmpStr = tmpStrList.join(";"); |
185 | if (!tmpStr.isEmpty()) | 188 | if (!tmpStr.isEmpty()) |
186 | addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); | 189 | addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); |
187 | 190 | ||
188 | #endif | 191 | #endif |
189 | 192 | ||
190 | // Transparency | 193 | // Transparency |
191 | switch( event->transparency() ) { | 194 | switch( event->transparency() ) { |
192 | case Event::Transparent: | 195 | case Event::Transparent: |
193 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); | 196 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); |
194 | break; | 197 | break; |
195 | case Event::Opaque: | 198 | case Event::Opaque: |
196 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); | 199 | icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); |
197 | break; | 200 | break; |
198 | } | 201 | } |
199 | 202 | ||
200 | return vevent; | 203 | return vevent; |
201 | } | 204 | } |
202 | 205 | ||
203 | icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, | 206 | icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, |
204 | Scheduler::Method method) | 207 | Scheduler::Method method) |
205 | { | 208 | { |
206 | 209 | ||
207 | 210 | ||
208 | icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); | 211 | icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); |
209 | 212 | ||
210 | writeIncidenceBase(vfreebusy,freebusy); | 213 | writeIncidenceBase(vfreebusy,freebusy); |
211 | 214 | ||
212 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( | 215 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( |
213 | writeICalDateTime(freebusy->dtStart()))); | 216 | writeICalDateTime(freebusy->dtStart()))); |
214 | 217 | ||
215 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( | 218 | icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( |
216 | writeICalDateTime(freebusy->dtEnd()))); | 219 | writeICalDateTime(freebusy->dtEnd()))); |
217 | 220 | ||
218 | if (method == Scheduler::Request) { | 221 | if (method == Scheduler::Request) { |
219 | icalcomponent_add_property(vfreebusy,icalproperty_new_uid( | 222 | icalcomponent_add_property(vfreebusy,icalproperty_new_uid( |
220 | freebusy->uid().utf8())); | 223 | freebusy->uid().utf8())); |
221 | } | 224 | } |
222 | 225 | ||
223 | //Loops through all the periods in the freebusy object | 226 | //Loops through all the periods in the freebusy object |
224 | QValueList<Period> list = freebusy->busyPeriods(); | 227 | Q3ValueList<Period> list = freebusy->busyPeriods(); |
225 | QValueList<Period>::Iterator it; | 228 | Q3ValueList<Period>::Iterator it; |
226 | icalperiodtype period; | 229 | icalperiodtype period; |
227 | for (it = list.begin(); it!= list.end(); ++it) { | 230 | for (it = list.begin(); it!= list.end(); ++it) { |
228 | period.start = writeICalDateTime((*it).start()); | 231 | period.start = writeICalDateTime((*it).start()); |
229 | period.end = writeICalDateTime((*it).end()); | 232 | period.end = writeICalDateTime((*it).end()); |
230 | icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); | 233 | icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); |
231 | } | 234 | } |
232 | 235 | ||
233 | return vfreebusy; | 236 | return vfreebusy; |
234 | } | 237 | } |
235 | 238 | ||
236 | icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) | 239 | icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) |
237 | { | 240 | { |
238 | icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); | 241 | icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); |
239 | 242 | ||
240 | writeIncidence(vjournal,journal); | 243 | writeIncidence(vjournal,journal); |
241 | 244 | ||
242 | // start time | 245 | // start time |
243 | if (journal->dtStart().isValid()) { | 246 | if (journal->dtStart().isValid()) { |
244 | icaltimetype start; | 247 | icaltimetype start; |
245 | if (journal->doesFloat()) { | 248 | if (journal->doesFloat()) { |
246 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; | 249 | // kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; |
247 | start = writeICalDate(journal->dtStart().date()); | 250 | start = writeICalDate(journal->dtStart().date()); |
248 | } else { | 251 | } else { |
249 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; | 252 | // kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; |
250 | start = writeICalDateTime(journal->dtStart()); | 253 | start = writeICalDateTime(journal->dtStart()); |
251 | } | 254 | } |
252 | icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); | 255 | icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); |
253 | } | 256 | } |
254 | 257 | ||
255 | return vjournal; | 258 | return vjournal; |
256 | } | 259 | } |
257 | 260 | ||
258 | void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) | 261 | void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) |
259 | { | 262 | { |
260 | // pilot sync stuff | 263 | // pilot sync stuff |
261 | // TODO: move this application-specific code to kpilot | 264 | // TODO: move this application-specific code to kpilot |
262 | if (incidence->pilotId()) { | 265 | if (incidence->pilotId()) { |
263 | incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); | 266 | incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); |
264 | incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); | 267 | incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); |
265 | } | 268 | } |
266 | if ( !incidence->IDStr().isEmpty()) { | 269 | if ( !incidence->IDStr().isEmpty()) { |
267 | incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); | 270 | incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); |
268 | } | 271 | } |
269 | 272 | ||
270 | 273 | ||
271 | writeIncidenceBase(parent,incidence); | 274 | writeIncidenceBase(parent,incidence); |
272 | if (incidence->cancelled()) { | 275 | if (incidence->cancelled()) { |
273 | icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); | 276 | icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); |
274 | } | 277 | } |
275 | 278 | ||
276 | // creation date | 279 | // creation date |
277 | icalcomponent_add_property(parent,icalproperty_new_created( | 280 | icalcomponent_add_property(parent,icalproperty_new_created( |
278 | writeICalDateTime(incidence->created()))); | 281 | writeICalDateTime(incidence->created()))); |
279 | 282 | ||
280 | // unique id | 283 | // unique id |
281 | icalcomponent_add_property(parent,icalproperty_new_uid( | 284 | icalcomponent_add_property(parent,icalproperty_new_uid( |
282 | incidence->uid().utf8())); | 285 | incidence->uid().utf8())); |
283 | 286 | ||
284 | // revision | 287 | // revision |
285 | icalcomponent_add_property(parent,icalproperty_new_sequence( | 288 | icalcomponent_add_property(parent,icalproperty_new_sequence( |
286 | incidence->revision())); | 289 | incidence->revision())); |
287 | 290 | ||
288 | // last modification date | 291 | // last modification date |
289 | icalcomponent_add_property(parent,icalproperty_new_lastmodified( | 292 | icalcomponent_add_property(parent,icalproperty_new_lastmodified( |
290 | writeICalDateTime(incidence->lastModified()))); | 293 | writeICalDateTime(incidence->lastModified()))); |
291 | 294 | ||
292 | // description | 295 | // description |
293 | if (!incidence->description().isEmpty()) { | 296 | if (!incidence->description().isEmpty()) { |
294 | icalcomponent_add_property(parent,icalproperty_new_description( | 297 | icalcomponent_add_property(parent,icalproperty_new_description( |
295 | incidence->description().utf8())); | 298 | incidence->description().utf8())); |
296 | } | 299 | } |
297 | 300 | ||
298 | // summary | 301 | // summary |
299 | if (!incidence->summary().isEmpty()) { | 302 | if (!incidence->summary().isEmpty()) { |
300 | icalcomponent_add_property(parent,icalproperty_new_summary( | 303 | icalcomponent_add_property(parent,icalproperty_new_summary( |
301 | incidence->summary().utf8())); | 304 | incidence->summary().utf8())); |
302 | } | 305 | } |
303 | 306 | ||
304 | // location | 307 | // location |
305 | if (!incidence->location().isEmpty()) { | 308 | if (!incidence->location().isEmpty()) { |
306 | icalcomponent_add_property(parent,icalproperty_new_location( | 309 | icalcomponent_add_property(parent,icalproperty_new_location( |
307 | incidence->location().utf8())); | 310 | incidence->location().utf8())); |
308 | } | 311 | } |
309 | 312 | ||
310 | // TODO: | 313 | // TODO: |
311 | // status | 314 | // status |
312 | // addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); | 315 | // addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); |
313 | 316 | ||
314 | // secrecy | 317 | // secrecy |
315 | enum icalproperty_class classInt; | 318 | enum icalproperty_class classInt; |
316 | switch (incidence->secrecy()) { | 319 | switch (incidence->secrecy()) { |
317 | case Incidence::SecrecyPublic: | 320 | case Incidence::SecrecyPublic: |
318 | classInt = ICAL_CLASS_PUBLIC; | 321 | classInt = ICAL_CLASS_PUBLIC; |
319 | break; | 322 | break; |
320 | case Incidence::SecrecyConfidential: | 323 | case Incidence::SecrecyConfidential: |
321 | classInt = ICAL_CLASS_CONFIDENTIAL; | 324 | classInt = ICAL_CLASS_CONFIDENTIAL; |
322 | break; | 325 | break; |
323 | case Incidence::SecrecyPrivate: | 326 | case Incidence::SecrecyPrivate: |
324 | classInt =ICAL_CLASS_PRIVATE ; | 327 | classInt =ICAL_CLASS_PRIVATE ; |
325 | default: | 328 | default: |
326 | classInt =ICAL_CLASS_PRIVATE ; | 329 | classInt =ICAL_CLASS_PRIVATE ; |
327 | break; | 330 | break; |
328 | } | 331 | } |
329 | icalcomponent_add_property(parent,icalproperty_new_class(classInt)); | 332 | icalcomponent_add_property(parent,icalproperty_new_class(classInt)); |
330 | 333 | ||
331 | // priority | 334 | // priority |
332 | icalcomponent_add_property(parent,icalproperty_new_priority( | 335 | icalcomponent_add_property(parent,icalproperty_new_priority( |
333 | incidence->priority())); | 336 | incidence->priority())); |
334 | 337 | ||
335 | // categories | 338 | // categories |
336 | QStringList categories = incidence->categories(); | 339 | QStringList categories = incidence->categories(); |
337 | QStringList::Iterator it; | 340 | QStringList::Iterator it; |
338 | for(it = categories.begin(); it != categories.end(); ++it ) { | 341 | for(it = categories.begin(); it != categories.end(); ++it ) { |
339 | icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); | 342 | icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); |
340 | } | 343 | } |
341 | // TODO: Ensure correct concatenation of categories properties. | 344 | // TODO: Ensure correct concatenation of categories properties. |
342 | 345 | ||
343 | /* | 346 | /* |
344 | // categories | 347 | // categories |
345 | tmpStrList = incidence->getCategories(); | 348 | tmpStrList = incidence->getCategories(); |
346 | tmpStr = ""; | 349 | tmpStr = ""; |
347 | QString catStr; | 350 | QString catStr; |
348 | for ( QStringList::Iterator it = tmpStrList.begin(); | 351 | for ( QStringList::Iterator it = tmpStrList.begin(); |
349 | it != tmpStrList.end(); | 352 | it != tmpStrList.end(); |
350 | ++it ) { | 353 | ++it ) { |
351 | catStr = *it; | 354 | catStr = *it; |
352 | if (catStr[0] == ' ') | 355 | if (catStr[0] == ' ') |
353 | tmpStr += catStr.mid(1); | 356 | tmpStr += catStr.mid(1); |
354 | else | 357 | else |
355 | tmpStr += catStr; | 358 | tmpStr += catStr; |
356 | // this must be a ';' character as the vCalendar specification requires! | 359 | // this must be a ';' character as the vCalendar specification requires! |
357 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 360 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
358 | // read in. | 361 | // read in. |
359 | tmpStr += ";"; | 362 | tmpStr += ";"; |
360 | } | 363 | } |
361 | if (!tmpStr.isEmpty()) { | 364 | if (!tmpStr.isEmpty()) { |
362 | tmpStr.truncate(tmpStr.length()-1); | 365 | tmpStr.truncate(tmpStr.length()-1); |
363 | icalcomponent_add_property(parent,icalproperty_new_categories( | 366 | icalcomponent_add_property(parent,icalproperty_new_categories( |
364 | writeText(incidence->getCategories().join(";")))); | 367 | writeText(incidence->getCategories().join(";")))); |
365 | } | 368 | } |
366 | */ | 369 | */ |
367 | 370 | ||
368 | // related event | 371 | // related event |
369 | if (!incidence->relatedToUid().isEmpty()) { | 372 | if (!incidence->relatedToUid().isEmpty()) { |
370 | icalcomponent_add_property(parent,icalproperty_new_relatedto( | 373 | icalcomponent_add_property(parent,icalproperty_new_relatedto( |
371 | incidence->relatedToUid().utf8())); | 374 | incidence->relatedToUid().utf8())); |
372 | } | 375 | } |
373 | 376 | ||
374 | // recurrence rule stuff | 377 | // recurrence rule stuff |
375 | if (incidence->doesRecur()) { | 378 | if (incidence->doesRecur()) { |
376 | icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence())); | 379 | icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence())); |
377 | // recurrence excpetion dates | 380 | // recurrence excpetion dates |
378 | DateList dateList = incidence->exDates(); | 381 | DateList dateList = incidence->exDates(); |
379 | DateList::ConstIterator exIt; | 382 | DateList::ConstIterator exIt; |
380 | for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { | 383 | for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { |
381 | icalcomponent_add_property(parent,icalproperty_new_exdate( | 384 | icalcomponent_add_property(parent,icalproperty_new_exdate( |
382 | writeICalDate(*exIt))); | 385 | writeICalDate(*exIt))); |
383 | } | 386 | } |
384 | } | 387 | } |
385 | 388 | ||
386 | // attachments | 389 | // attachments |
387 | QPtrList<Attachment> attachments = incidence->attachments(); | 390 | Q3PtrList<Attachment> attachments = incidence->attachments(); |
388 | for (Attachment *at = attachments.first(); at; at = attachments.next()) | 391 | for (Attachment *at = attachments.first(); at; at = attachments.next()) |
389 | icalcomponent_add_property(parent,writeAttachment(at)); | 392 | icalcomponent_add_property(parent,writeAttachment(at)); |
390 | 393 | ||
391 | // alarms | 394 | // alarms |
392 | QPtrList<Alarm> alarms = incidence->alarms(); | 395 | Q3PtrList<Alarm> alarms = incidence->alarms(); |
393 | Alarm* alarm; | 396 | Alarm* alarm; |
394 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 397 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
395 | if (alarm->enabled()) { | 398 | if (alarm->enabled()) { |
396 | kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; | 399 | kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; |
397 | icalcomponent_add_component(parent,writeAlarm(alarm)); | 400 | icalcomponent_add_component(parent,writeAlarm(alarm)); |
398 | } | 401 | } |
399 | } | 402 | } |
400 | if( incidence->hasRecurrenceID() ) { | 403 | if( incidence->hasRecurrenceID() ) { |
401 | icalcomponent_add_property(parent, | 404 | icalcomponent_add_property(parent, |
402 | icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); | 405 | icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); |
403 | } | 406 | } |
404 | // duration | 407 | // duration |
405 | 408 | ||
406 | // turned off as it always is set to PTS0 (and must not occur together with DTEND | 409 | // turned off as it always is set to PTS0 (and must not occur together with DTEND |
407 | 410 | ||
408 | if (incidence->hasDuration()) { | 411 | if (incidence->hasDuration()) { |
409 | icaldurationtype duration; | 412 | icaldurationtype duration; |
410 | duration = writeICalDuration(incidence->duration()); | 413 | duration = writeICalDuration(incidence->duration()); |
411 | icalcomponent_add_property(parent,icalproperty_new_duration(duration)); | 414 | icalcomponent_add_property(parent,icalproperty_new_duration(duration)); |
412 | } | 415 | } |
413 | } | 416 | } |
414 | 417 | ||
415 | void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) | 418 | void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) |
416 | { | 419 | { |
417 | icalcomponent_add_property(parent,icalproperty_new_dtstamp( | 420 | icalcomponent_add_property(parent,icalproperty_new_dtstamp( |
418 | writeICalDateTime(QDateTime::currentDateTime()))); | 421 | writeICalDateTime(QDateTime::currentDateTime()))); |
419 | 422 | ||
420 | // organizer stuff | 423 | // organizer stuff |
421 | icalcomponent_add_property(parent,icalproperty_new_organizer( | 424 | icalcomponent_add_property(parent,icalproperty_new_organizer( |
422 | ("MAILTO:" + incidenceBase->organizer()).utf8())); | 425 | ("MAILTO:" + incidenceBase->organizer()).utf8())); |
423 | 426 | ||
424 | // attendees | 427 | // attendees |
425 | if (incidenceBase->attendeeCount() != 0) { | 428 | if (incidenceBase->attendeeCount() != 0) { |
426 | QPtrList<Attendee> al = incidenceBase->attendees(); | 429 | Q3PtrList<Attendee> al = incidenceBase->attendees(); |
427 | QPtrListIterator<Attendee> ai(al); | 430 | Q3PtrListIterator<Attendee> ai(al); |
428 | for (; ai.current(); ++ai) { | 431 | for (; ai.current(); ++ai) { |
429 | icalcomponent_add_property(parent,writeAttendee(ai.current())); | 432 | icalcomponent_add_property(parent,writeAttendee(ai.current())); |
430 | } | 433 | } |
431 | } | 434 | } |
432 | 435 | ||
433 | // custom properties | 436 | // custom properties |
434 | writeCustomProperties(parent, incidenceBase); | 437 | writeCustomProperties(parent, incidenceBase); |
435 | } | 438 | } |
436 | 439 | ||
437 | void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) | 440 | void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) |
438 | { | 441 | { |
439 | QMap<QCString, QString> custom = properties->customProperties(); | 442 | QMap<Q3CString, QString> custom = properties->customProperties(); |
440 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { | 443 | for (QMap<Q3CString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { |
441 | icalproperty *p = icalproperty_new_x(c.data().utf8()); | 444 | icalproperty *p = icalproperty_new_x(c.data().utf8()); |
442 | icalproperty_set_x_name(p,c.key()); | 445 | icalproperty_set_x_name(p,c.key()); |
443 | icalcomponent_add_property(parent,p); | 446 | icalcomponent_add_property(parent,p); |
444 | } | 447 | } |
445 | } | 448 | } |
446 | 449 | ||
447 | icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) | 450 | icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) |
448 | { | 451 | { |
449 | icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); | 452 | icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); |
450 | 453 | ||
451 | if (!attendee->name().isEmpty()) { | 454 | if (!attendee->name().isEmpty()) { |
452 | icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); | 455 | icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); |
453 | } | 456 | } |
454 | 457 | ||
455 | 458 | ||
456 | icalproperty_add_parameter(p,icalparameter_new_rsvp( | 459 | icalproperty_add_parameter(p,icalparameter_new_rsvp( |
457 | attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); | 460 | attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); |
458 | 461 | ||
459 | icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; | 462 | icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; |
460 | switch (attendee->status()) { | 463 | switch (attendee->status()) { |
461 | default: | 464 | default: |
462 | case Attendee::NeedsAction: | 465 | case Attendee::NeedsAction: |
463 | status = ICAL_PARTSTAT_NEEDSACTION; | 466 | status = ICAL_PARTSTAT_NEEDSACTION; |
464 | break; | 467 | break; |
465 | case Attendee::Accepted: | 468 | case Attendee::Accepted: |
466 | status = ICAL_PARTSTAT_ACCEPTED; | 469 | status = ICAL_PARTSTAT_ACCEPTED; |
467 | break; | 470 | break; |
468 | case Attendee::Declined: | 471 | case Attendee::Declined: |
469 | status = ICAL_PARTSTAT_DECLINED; | 472 | status = ICAL_PARTSTAT_DECLINED; |
470 | break; | 473 | break; |
471 | case Attendee::Tentative: | 474 | case Attendee::Tentative: |
472 | status = ICAL_PARTSTAT_TENTATIVE; | 475 | status = ICAL_PARTSTAT_TENTATIVE; |
473 | break; | 476 | break; |
474 | case Attendee::Delegated: | 477 | case Attendee::Delegated: |
475 | status = ICAL_PARTSTAT_DELEGATED; | 478 | status = ICAL_PARTSTAT_DELEGATED; |
476 | break; | 479 | break; |
477 | case Attendee::Completed: | 480 | case Attendee::Completed: |
478 | status = ICAL_PARTSTAT_COMPLETED; | 481 | status = ICAL_PARTSTAT_COMPLETED; |
479 | break; | 482 | break; |
480 | case Attendee::InProcess: | 483 | case Attendee::InProcess: |
481 | status = ICAL_PARTSTAT_INPROCESS; | 484 | status = ICAL_PARTSTAT_INPROCESS; |
482 | break; | 485 | break; |
483 | } | 486 | } |
484 | icalproperty_add_parameter(p,icalparameter_new_partstat(status)); | 487 | icalproperty_add_parameter(p,icalparameter_new_partstat(status)); |
485 | 488 | ||
486 | icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; | 489 | icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; |
487 | switch (attendee->role()) { | 490 | switch (attendee->role()) { |
488 | case Attendee::Chair: | 491 | case Attendee::Chair: |
489 | role = ICAL_ROLE_CHAIR; | 492 | role = ICAL_ROLE_CHAIR; |
490 | break; | 493 | break; |
491 | default: | 494 | default: |
492 | case Attendee::ReqParticipant: | 495 | case Attendee::ReqParticipant: |
493 | role = ICAL_ROLE_REQPARTICIPANT; | 496 | role = ICAL_ROLE_REQPARTICIPANT; |
494 | break; | 497 | break; |
495 | case Attendee::OptParticipant: | 498 | case Attendee::OptParticipant: |
496 | role = ICAL_ROLE_OPTPARTICIPANT; | 499 | role = ICAL_ROLE_OPTPARTICIPANT; |
497 | break; | 500 | break; |
498 | case Attendee::NonParticipant: | 501 | case Attendee::NonParticipant: |
499 | role = ICAL_ROLE_NONPARTICIPANT; | 502 | role = ICAL_ROLE_NONPARTICIPANT; |
500 | break; | 503 | break; |
501 | } | 504 | } |
502 | icalproperty_add_parameter(p,icalparameter_new_role(role)); | 505 | icalproperty_add_parameter(p,icalparameter_new_role(role)); |
503 | 506 | ||
504 | if (!attendee->uid().isEmpty()) { | 507 | if (!attendee->uid().isEmpty()) { |
505 | icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); | 508 | icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); |
506 | icalparameter_set_xname(icalparameter_uid,"X-UID"); | 509 | icalparameter_set_xname(icalparameter_uid,"X-UID"); |
507 | icalproperty_add_parameter(p,icalparameter_uid); | 510 | icalproperty_add_parameter(p,icalparameter_uid); |
508 | } | 511 | } |
509 | 512 | ||
510 | return p; | 513 | return p; |
511 | } | 514 | } |
512 | 515 | ||
513 | icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) | 516 | icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) |
514 | { | 517 | { |
515 | #if 0 | 518 | #if 0 |
516 | icalattachtype* attach = icalattachtype_new(); | 519 | icalattachtype* attach = icalattachtype_new(); |
517 | if (att->isUri()) | 520 | if (att->isUri()) |
518 | icalattachtype_set_url(attach, att->uri().utf8().data()); | 521 | icalattachtype_set_url(attach, att->uri().utf8().data()); |
519 | else | 522 | else |
520 | icalattachtype_set_base64(attach, att->data(), 0); | 523 | icalattachtype_set_base64(attach, att->data(), 0); |
521 | #endif | 524 | #endif |
522 | icalattach *attach; | 525 | icalattach *attach; |
523 | if (att->isUri()) | 526 | if (att->isUri()) |
524 | attach = icalattach_new_from_url( att->uri().utf8().data()); | 527 | attach = icalattach_new_from_url( att->uri().utf8().data()); |
525 | else | 528 | else |
526 | attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); | 529 | attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); |
527 | icalproperty *p = icalproperty_new_attach(attach); | 530 | icalproperty *p = icalproperty_new_attach(attach); |
528 | if (!att->mimeType().isEmpty()) | 531 | if (!att->mimeType().isEmpty()) |
529 | icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); | 532 | icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); |
530 | 533 | ||
531 | if (att->isBinary()) { | 534 | if (att->isBinary()) { |
532 | icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); | 535 | icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); |
533 | icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); | 536 | icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); |
534 | } | 537 | } |
535 | return p; | 538 | return p; |
536 | } | 539 | } |
537 | 540 | ||
538 | icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) | 541 | icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) |
539 | { | 542 | { |
540 | // kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; | 543 | // kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; |
541 | 544 | ||
542 | icalrecurrencetype r; | 545 | icalrecurrencetype r; |
543 | 546 | ||
544 | icalrecurrencetype_clear(&r); | 547 | icalrecurrencetype_clear(&r); |
545 | 548 | ||
546 | int index = 0; | 549 | int index = 0; |
547 | int index2 = 0; | 550 | int index2 = 0; |
548 | 551 | ||
549 | QPtrList<Recurrence::rMonthPos> tmpPositions; | 552 | Q3PtrList<Recurrence::rMonthPos> tmpPositions; |
550 | QPtrList<int> tmpDays; | 553 | Q3PtrList<int> tmpDays; |
551 | int *tmpDay; | 554 | int *tmpDay; |
552 | Recurrence::rMonthPos *tmpPos; | 555 | Recurrence::rMonthPos *tmpPos; |
553 | bool datetime = false; | 556 | bool datetime = false; |
554 | int day; | 557 | int day; |
555 | int i; | 558 | int i; |
556 | 559 | ||
557 | switch(recur->doesRecur()) { | 560 | switch(recur->doesRecur()) { |
558 | case Recurrence::rMinutely: | 561 | case Recurrence::rMinutely: |
559 | r.freq = ICAL_MINUTELY_RECURRENCE; | 562 | r.freq = ICAL_MINUTELY_RECURRENCE; |
560 | datetime = true; | 563 | datetime = true; |
561 | break; | 564 | break; |
562 | case Recurrence::rHourly: | 565 | case Recurrence::rHourly: |
563 | r.freq = ICAL_HOURLY_RECURRENCE; | 566 | r.freq = ICAL_HOURLY_RECURRENCE; |
564 | datetime = true; | 567 | datetime = true; |
565 | break; | 568 | break; |
566 | case Recurrence::rDaily: | 569 | case Recurrence::rDaily: |
567 | r.freq = ICAL_DAILY_RECURRENCE; | 570 | r.freq = ICAL_DAILY_RECURRENCE; |
568 | break; | 571 | break; |
569 | case Recurrence::rWeekly: | 572 | case Recurrence::rWeekly: |
570 | r.freq = ICAL_WEEKLY_RECURRENCE; | 573 | r.freq = ICAL_WEEKLY_RECURRENCE; |
571 | r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); | 574 | r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); |
572 | for (i = 0; i < 7; i++) { | 575 | for (i = 0; i < 7; i++) { |
573 | if (recur->days().testBit(i)) { | 576 | if (recur->days().testBit(i)) { |
574 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 577 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
575 | r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); | 578 | r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); |
576 | } | 579 | } |
577 | } | 580 | } |
578 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 581 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
579 | break; | 582 | break; |
580 | case Recurrence::rMonthlyPos: | 583 | case Recurrence::rMonthlyPos: |
581 | r.freq = ICAL_MONTHLY_RECURRENCE; | 584 | r.freq = ICAL_MONTHLY_RECURRENCE; |
582 | 585 | ||
583 | tmpPositions = recur->monthPositions(); | 586 | tmpPositions = recur->monthPositions(); |
584 | for (tmpPos = tmpPositions.first(); | 587 | for (tmpPos = tmpPositions.first(); |
585 | tmpPos; | 588 | tmpPos; |
586 | tmpPos = tmpPositions.next()) { | 589 | tmpPos = tmpPositions.next()) { |
587 | for (i = 0; i < 7; i++) { | 590 | for (i = 0; i < 7; i++) { |
588 | if (tmpPos->rDays.testBit(i)) { | 591 | if (tmpPos->rDays.testBit(i)) { |
589 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 592 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
590 | day += tmpPos->rPos*8; | 593 | day += tmpPos->rPos*8; |
591 | if (tmpPos->negative) day = -day; | 594 | if (tmpPos->negative) day = -day; |
592 | r.by_day[index++] = day; | 595 | r.by_day[index++] = day; |
593 | } | 596 | } |
594 | } | 597 | } |
595 | } | 598 | } |
596 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 599 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
597 | break; | 600 | break; |
598 | case Recurrence::rMonthlyDay: | 601 | case Recurrence::rMonthlyDay: |
599 | r.freq = ICAL_MONTHLY_RECURRENCE; | 602 | r.freq = ICAL_MONTHLY_RECURRENCE; |
600 | 603 | ||
601 | tmpDays = recur->monthDays(); | 604 | tmpDays = recur->monthDays(); |
602 | for (tmpDay = tmpDays.first(); | 605 | for (tmpDay = tmpDays.first(); |
603 | tmpDay; | 606 | tmpDay; |
604 | tmpDay = tmpDays.next()) { | 607 | tmpDay = tmpDays.next()) { |
605 | r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); | 608 | r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); |
606 | } | 609 | } |
607 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 610 | // r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
608 | break; | 611 | break; |
609 | case Recurrence::rYearlyMonth: | 612 | case Recurrence::rYearlyMonth: |
610 | case Recurrence::rYearlyPos: | 613 | case Recurrence::rYearlyPos: |
611 | r.freq = ICAL_YEARLY_RECURRENCE; | 614 | r.freq = ICAL_YEARLY_RECURRENCE; |
612 | 615 | ||
613 | tmpDays = recur->yearNums(); | 616 | tmpDays = recur->yearNums(); |
614 | for (tmpDay = tmpDays.first(); | 617 | for (tmpDay = tmpDays.first(); |
615 | tmpDay; | 618 | tmpDay; |
616 | tmpDay = tmpDays.next()) { | 619 | tmpDay = tmpDays.next()) { |
617 | r.by_month[index++] = *tmpDay; | 620 | r.by_month[index++] = *tmpDay; |
618 | } | 621 | } |
619 | // r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; | 622 | // r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; |
620 | if (recur->doesRecur() == Recurrence::rYearlyPos) { | 623 | if (recur->doesRecur() == Recurrence::rYearlyPos) { |
621 | tmpPositions = recur->monthPositions(); | 624 | tmpPositions = recur->monthPositions(); |
622 | for (tmpPos = tmpPositions.first(); | 625 | for (tmpPos = tmpPositions.first(); |
623 | tmpPos; | 626 | tmpPos; |
624 | tmpPos = tmpPositions.next()) { | 627 | tmpPos = tmpPositions.next()) { |
625 | for (i = 0; i < 7; i++) { | 628 | for (i = 0; i < 7; i++) { |
626 | if (tmpPos->rDays.testBit(i)) { | 629 | if (tmpPos->rDays.testBit(i)) { |
627 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 | 630 | day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 |
628 | day += tmpPos->rPos*8; | 631 | day += tmpPos->rPos*8; |
629 | if (tmpPos->negative) day = -day; | 632 | if (tmpPos->negative) day = -day; |
630 | r.by_day[index2++] = day; | 633 | r.by_day[index2++] = day; |
631 | } | 634 | } |
632 | } | 635 | } |
633 | } | 636 | } |
634 | // r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; | 637 | // r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; |
635 | } | 638 | } |
636 | break; | 639 | break; |
637 | case Recurrence::rYearlyDay: | 640 | case Recurrence::rYearlyDay: |
638 | r.freq = ICAL_YEARLY_RECURRENCE; | 641 | r.freq = ICAL_YEARLY_RECURRENCE; |
639 | 642 | ||
640 | tmpDays = recur->yearNums(); | 643 | tmpDays = recur->yearNums(); |
641 | for (tmpDay = tmpDays.first(); | 644 | for (tmpDay = tmpDays.first(); |
642 | tmpDay; | 645 | tmpDay; |
643 | tmpDay = tmpDays.next()) { | 646 | tmpDay = tmpDays.next()) { |
644 | r.by_year_day[index++] = *tmpDay; | 647 | r.by_year_day[index++] = *tmpDay; |
645 | } | 648 | } |
646 | // r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; | 649 | // r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; |
647 | break; | 650 | break; |
648 | default: | 651 | default: |
649 | r.freq = ICAL_NO_RECURRENCE; | 652 | r.freq = ICAL_NO_RECURRENCE; |
650 | kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; | 653 | kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; |
651 | break; | 654 | break; |
652 | } | 655 | } |
653 | 656 | ||
654 | r.interval = recur->frequency(); | 657 | r.interval = recur->frequency(); |
655 | 658 | ||
656 | if (recur->duration() > 0) { | 659 | if (recur->duration() > 0) { |
657 | r.count = recur->duration(); | 660 | r.count = recur->duration(); |
658 | } else if (recur->duration() == -1) { | 661 | } else if (recur->duration() == -1) { |
659 | r.count = 0; | 662 | r.count = 0; |
660 | } else { | 663 | } else { |
661 | if (datetime) | 664 | if (datetime) |
662 | r.until = writeICalDateTime(recur->endDateTime()); | 665 | r.until = writeICalDateTime(recur->endDateTime()); |
663 | else | 666 | else |
664 | r.until = writeICalDate(recur->endDate()); | 667 | r.until = writeICalDate(recur->endDate()); |
665 | } | 668 | } |
666 | 669 | ||
667 | // Debug output | 670 | // Debug output |
668 | #if 0 | 671 | #if 0 |
669 | const char *str = icalrecurrencetype_as_string(&r); | 672 | const char *str = icalrecurrencetype_as_string(&r); |
670 | if (str) { | 673 | if (str) { |
671 | kdDebug(5800) << " String: " << str << endl; | 674 | kdDebug(5800) << " String: " << str << endl; |
672 | } else { | 675 | } else { |
673 | kdDebug(5800) << " No String" << endl; | 676 | kdDebug(5800) << " No String" << endl; |
674 | } | 677 | } |
675 | #endif | 678 | #endif |
676 | 679 | ||
677 | return icalproperty_new_rrule(r); | 680 | return icalproperty_new_rrule(r); |
678 | } | 681 | } |
679 | 682 | ||
680 | icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) | 683 | icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) |
681 | { | 684 | { |
682 | icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); | 685 | icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); |
683 | 686 | ||
684 | icalproperty_action action; | 687 | icalproperty_action action; |
685 | icalattach *attach = 0; | 688 | icalattach *attach = 0; |
686 | 689 | ||
687 | switch (alarm->type()) { | 690 | switch (alarm->type()) { |
688 | case Alarm::Procedure: | 691 | case Alarm::Procedure: |
689 | action = ICAL_ACTION_PROCEDURE; | 692 | action = ICAL_ACTION_PROCEDURE; |
690 | attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); | 693 | attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); |
691 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 694 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
692 | if (!alarm->programArguments().isEmpty()) { | 695 | if (!alarm->programArguments().isEmpty()) { |
693 | icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); | 696 | icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); |
694 | } | 697 | } |
695 | icalattach_unref( attach ); | 698 | icalattach_unref( attach ); |
696 | break; | 699 | break; |
697 | case Alarm::Audio: | 700 | case Alarm::Audio: |
698 | action = ICAL_ACTION_AUDIO; | 701 | action = ICAL_ACTION_AUDIO; |
699 | if (!alarm->audioFile().isEmpty()) { | 702 | if (!alarm->audioFile().isEmpty()) { |
700 | attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); | 703 | attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); |
701 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 704 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
702 | icalattach_unref( attach ); | 705 | icalattach_unref( attach ); |
703 | } | 706 | } |
704 | break; | 707 | break; |
705 | case Alarm::Email: { | 708 | case Alarm::Email: { |
706 | action = ICAL_ACTION_EMAIL; | 709 | action = ICAL_ACTION_EMAIL; |
707 | QValueList<Person> addresses = alarm->mailAddresses(); | 710 | Q3ValueList<Person> addresses = alarm->mailAddresses(); |
708 | for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { | 711 | for (Q3ValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { |
709 | icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); | 712 | icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); |
710 | if (!(*ad).name().isEmpty()) { | 713 | if (!(*ad).name().isEmpty()) { |
711 | icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); | 714 | icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); |
712 | } | 715 | } |
713 | icalcomponent_add_property(a,p); | 716 | icalcomponent_add_property(a,p); |
714 | } | 717 | } |
715 | icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); | 718 | icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); |
716 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); | 719 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); |
717 | QStringList attachments = alarm->mailAttachments(); | 720 | QStringList attachments = alarm->mailAttachments(); |
718 | if (attachments.count() > 0) { | 721 | if (attachments.count() > 0) { |
719 | for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { | 722 | for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { |
720 | attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); | 723 | attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); |
721 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); | 724 | icalcomponent_add_property(a,icalproperty_new_attach(attach)); |
722 | icalattach_unref( attach ); | 725 | icalattach_unref( attach ); |
723 | } | 726 | } |
724 | } | 727 | } |
725 | break; | 728 | break; |
726 | } | 729 | } |
727 | case Alarm::Display: | 730 | case Alarm::Display: |
728 | action = ICAL_ACTION_DISPLAY; | 731 | action = ICAL_ACTION_DISPLAY; |
729 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); | 732 | icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); |
730 | break; | 733 | break; |
731 | case Alarm::Invalid: | 734 | case Alarm::Invalid: |
732 | default: | 735 | default: |
733 | kdDebug(5800) << "Unknown type of alarm" << endl; | 736 | kdDebug(5800) << "Unknown type of alarm" << endl; |
734 | action = ICAL_ACTION_NONE; | 737 | action = ICAL_ACTION_NONE; |
735 | break; | 738 | break; |
736 | } | 739 | } |
737 | icalcomponent_add_property(a,icalproperty_new_action(action)); | 740 | icalcomponent_add_property(a,icalproperty_new_action(action)); |
738 | 741 | ||
739 | // Trigger time | 742 | // Trigger time |
740 | icaltriggertype trigger; | 743 | icaltriggertype trigger; |
741 | if ( alarm->hasTime() ) { | 744 | if ( alarm->hasTime() ) { |
742 | trigger.time = writeICalDateTime(alarm->time()); | 745 | trigger.time = writeICalDateTime(alarm->time()); |
743 | trigger.duration = icaldurationtype_null_duration(); | 746 | trigger.duration = icaldurationtype_null_duration(); |
744 | } else { | 747 | } else { |
745 | trigger.time = icaltime_null_time(); | 748 | trigger.time = icaltime_null_time(); |
746 | Duration offset; | 749 | Duration offset; |
747 | if ( alarm->hasStartOffset() ) | 750 | if ( alarm->hasStartOffset() ) |
748 | offset = alarm->startOffset(); | 751 | offset = alarm->startOffset(); |
749 | else | 752 | else |
750 | offset = alarm->endOffset(); | 753 | offset = alarm->endOffset(); |
751 | trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); | 754 | trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); |
752 | } | 755 | } |
753 | icalproperty *p = icalproperty_new_trigger(trigger); | 756 | icalproperty *p = icalproperty_new_trigger(trigger); |
754 | if ( alarm->hasEndOffset() ) | 757 | if ( alarm->hasEndOffset() ) |
755 | icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); | 758 | icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); |
756 | icalcomponent_add_property(a,p); | 759 | icalcomponent_add_property(a,p); |
757 | 760 | ||
758 | // Repeat count and duration | 761 | // Repeat count and duration |
759 | if (alarm->repeatCount()) { | 762 | if (alarm->repeatCount()) { |
760 | icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); | 763 | icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); |
761 | icalcomponent_add_property(a,icalproperty_new_duration( | 764 | icalcomponent_add_property(a,icalproperty_new_duration( |
762 | icaldurationtype_from_int(alarm->snoozeTime()*60))); | 765 | icaldurationtype_from_int(alarm->snoozeTime()*60))); |
763 | } | 766 | } |
764 | 767 | ||
765 | // Custom properties | 768 | // Custom properties |
766 | QMap<QCString, QString> custom = alarm->customProperties(); | 769 | QMap<Q3CString, QString> custom = alarm->customProperties(); |
767 | for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { | 770 | for (QMap<Q3CString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { |
768 | icalproperty *p = icalproperty_new_x(c.data().utf8()); | 771 | icalproperty *p = icalproperty_new_x(c.data().utf8()); |
769 | icalproperty_set_x_name(p,c.key()); | 772 | icalproperty_set_x_name(p,c.key()); |
770 | icalcomponent_add_property(a,p); | 773 | icalcomponent_add_property(a,p); |
771 | } | 774 | } |
772 | 775 | ||
773 | return a; | 776 | return a; |
774 | } | 777 | } |
775 | 778 | ||
776 | Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) | 779 | Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) |
777 | { | 780 | { |
778 | Todo *todo = new Todo; | 781 | Todo *todo = new Todo; |
779 | 782 | ||
780 | readIncidence(vtodo,todo); | 783 | readIncidence(vtodo,todo); |
781 | 784 | ||
782 | icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); | 785 | icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); |
783 | 786 | ||
784 | // int intvalue; | 787 | // int intvalue; |
785 | icaltimetype icaltime; | 788 | icaltimetype icaltime; |
786 | 789 | ||
787 | QStringList categories; | 790 | QStringList categories; |
788 | 791 | ||
789 | while (p) { | 792 | while (p) { |
790 | icalproperty_kind kind = icalproperty_isa(p); | 793 | icalproperty_kind kind = icalproperty_isa(p); |
791 | switch (kind) { | 794 | switch (kind) { |
792 | 795 | ||
793 | case ICAL_DUE_PROPERTY: // due date | 796 | case ICAL_DUE_PROPERTY: // due date |
794 | icaltime = icalproperty_get_due(p); | 797 | icaltime = icalproperty_get_due(p); |
795 | if (icaltime.is_date) { | 798 | if (icaltime.is_date) { |
796 | todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); | 799 | todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); |
797 | todo->setFloats(true); | 800 | todo->setFloats(true); |
798 | 801 | ||
799 | } else { | 802 | } else { |
800 | todo->setDtDue(readICalDateTime(icaltime)); | 803 | todo->setDtDue(readICalDateTime(icaltime)); |
801 | todo->setFloats(false); | 804 | todo->setFloats(false); |
802 | } | 805 | } |
803 | todo->setHasDueDate(true); | 806 | todo->setHasDueDate(true); |
804 | break; | 807 | break; |
805 | 808 | ||
806 | case ICAL_COMPLETED_PROPERTY: // completion date | 809 | case ICAL_COMPLETED_PROPERTY: // completion date |
807 | icaltime = icalproperty_get_completed(p); | 810 | icaltime = icalproperty_get_completed(p); |
808 | todo->setCompleted(readICalDateTime(icaltime)); | 811 | todo->setCompleted(readICalDateTime(icaltime)); |
809 | break; | 812 | break; |
810 | 813 | ||
811 | case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed | 814 | case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed |
812 | todo->setPercentComplete(icalproperty_get_percentcomplete(p)); | 815 | todo->setPercentComplete(icalproperty_get_percentcomplete(p)); |
813 | break; | 816 | break; |
814 | 817 | ||
815 | case ICAL_RELATEDTO_PROPERTY: // related todo (parent) | 818 | case ICAL_RELATEDTO_PROPERTY: // related todo (parent) |
816 | todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); | 819 | todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); |
817 | mTodosRelate.append(todo); | 820 | mTodosRelate.append(todo); |
818 | break; | 821 | break; |
819 | 822 | ||
820 | case ICAL_DTSTART_PROPERTY: | 823 | case ICAL_DTSTART_PROPERTY: |
821 | // Flag that todo has start date. Value is read in by readIncidence(). | 824 | // Flag that todo has start date. Value is read in by readIncidence(). |
822 | todo->setHasStartDate(true); | 825 | todo->setHasStartDate(true); |
823 | break; | 826 | break; |
824 | 827 | ||
825 | default: | 828 | default: |
826 | // kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind | 829 | // kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind |
827 | // << endl; | 830 | // << endl; |
828 | break; | 831 | break; |
829 | } | 832 | } |
830 | 833 | ||
831 | p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); | 834 | p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); |
832 | } | 835 | } |
833 | 836 | ||
834 | return todo; | 837 | return todo; |
835 | } | 838 | } |
836 | 839 | ||
837 | Event *ICalFormatImpl::readEvent(icalcomponent *vevent) | 840 | Event *ICalFormatImpl::readEvent(icalcomponent *vevent) |
838 | { | 841 | { |
839 | Event *event = new Event; | 842 | Event *event = new Event; |
840 | event->setFloats(false); | 843 | event->setFloats(false); |
841 | 844 | ||
842 | readIncidence(vevent,event); | 845 | readIncidence(vevent,event); |
843 | 846 | ||
844 | icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); | 847 | icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); |
845 | 848 | ||
846 | // int intvalue; | 849 | // int intvalue; |
847 | icaltimetype icaltime; | 850 | icaltimetype icaltime; |
848 | 851 | ||
849 | QStringList categories; | 852 | QStringList categories; |
850 | QString transparency; | 853 | QString transparency; |
851 | 854 | ||
852 | while (p) { | 855 | while (p) { |
853 | icalproperty_kind kind = icalproperty_isa(p); | 856 | icalproperty_kind kind = icalproperty_isa(p); |
854 | switch (kind) { | 857 | switch (kind) { |
855 | 858 | ||
856 | case ICAL_DTEND_PROPERTY: // start date and time | 859 | case ICAL_DTEND_PROPERTY: // start date and time |
857 | icaltime = icalproperty_get_dtend(p); | 860 | icaltime = icalproperty_get_dtend(p); |
858 | if (icaltime.is_date) { | 861 | if (icaltime.is_date) { |
859 | event->setFloats( true ); | 862 | event->setFloats( true ); |
860 | // End date is non-inclusive | 863 | // End date is non-inclusive |
861 | QDate endDate = readICalDate( icaltime ).addDays( -1 ); | 864 | QDate endDate = readICalDate( icaltime ).addDays( -1 ); |
862 | mCompat->fixFloatingEnd( endDate ); | 865 | mCompat->fixFloatingEnd( endDate ); |
863 | if ( endDate < event->dtStart().date() ) { | 866 | if ( endDate < event->dtStart().date() ) { |
@@ -1246,193 +1249,193 @@ void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) | |||
1246 | icaltime = icalproperty_get_exdate(p); | 1249 | icaltime = icalproperty_get_exdate(p); |
1247 | incidence->addExDate(readICalDate(icaltime)); | 1250 | incidence->addExDate(readICalDate(icaltime)); |
1248 | break; | 1251 | break; |
1249 | 1252 | ||
1250 | case ICAL_CLASS_PROPERTY: { | 1253 | case ICAL_CLASS_PROPERTY: { |
1251 | int inttext = icalproperty_get_class(p); | 1254 | int inttext = icalproperty_get_class(p); |
1252 | if (inttext == ICAL_CLASS_PUBLIC ) { | 1255 | if (inttext == ICAL_CLASS_PUBLIC ) { |
1253 | incidence->setSecrecy(Incidence::SecrecyPublic); | 1256 | incidence->setSecrecy(Incidence::SecrecyPublic); |
1254 | } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { | 1257 | } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { |
1255 | incidence->setSecrecy(Incidence::SecrecyConfidential); | 1258 | incidence->setSecrecy(Incidence::SecrecyConfidential); |
1256 | } else { | 1259 | } else { |
1257 | incidence->setSecrecy(Incidence::SecrecyPrivate); | 1260 | incidence->setSecrecy(Incidence::SecrecyPrivate); |
1258 | } | 1261 | } |
1259 | } | 1262 | } |
1260 | break; | 1263 | break; |
1261 | 1264 | ||
1262 | case ICAL_ATTACH_PROPERTY: // attachments | 1265 | case ICAL_ATTACH_PROPERTY: // attachments |
1263 | incidence->addAttachment(readAttachment(p)); | 1266 | incidence->addAttachment(readAttachment(p)); |
1264 | break; | 1267 | break; |
1265 | 1268 | ||
1266 | default: | 1269 | default: |
1267 | // kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind | 1270 | // kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind |
1268 | // << endl; | 1271 | // << endl; |
1269 | break; | 1272 | break; |
1270 | } | 1273 | } |
1271 | 1274 | ||
1272 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); | 1275 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); |
1273 | } | 1276 | } |
1274 | if ( readrec ) { | 1277 | if ( readrec ) { |
1275 | readRecurrenceRule(rectype,incidence); | 1278 | readRecurrenceRule(rectype,incidence); |
1276 | } | 1279 | } |
1277 | // kpilot stuff | 1280 | // kpilot stuff |
1278 | // TODO: move this application-specific code to kpilot | 1281 | // TODO: move this application-specific code to kpilot |
1279 | QString kp = incidence->nonKDECustomProperty("X-PILOTID"); | 1282 | QString kp = incidence->nonKDECustomProperty("X-PILOTID"); |
1280 | if (!kp.isNull()) { | 1283 | if (!kp.isNull()) { |
1281 | incidence->setPilotId(kp.toInt()); | 1284 | incidence->setPilotId(kp.toInt()); |
1282 | } | 1285 | } |
1283 | kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); | 1286 | kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); |
1284 | if (!kp.isNull()) { | 1287 | if (!kp.isNull()) { |
1285 | incidence->setSyncStatus(kp.toInt()); | 1288 | incidence->setSyncStatus(kp.toInt()); |
1286 | } | 1289 | } |
1287 | 1290 | ||
1288 | 1291 | ||
1289 | kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); | 1292 | kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); |
1290 | if (!kp.isNull()) { | 1293 | if (!kp.isNull()) { |
1291 | incidence->setIDStr(kp); | 1294 | incidence->setIDStr(kp); |
1292 | } | 1295 | } |
1293 | 1296 | ||
1294 | // Cancel backwards compatibility mode for subsequent changes by the application | 1297 | // Cancel backwards compatibility mode for subsequent changes by the application |
1295 | if ( readrec ) | 1298 | if ( readrec ) |
1296 | incidence->recurrence()->setCompatVersion(); | 1299 | incidence->recurrence()->setCompatVersion(); |
1297 | 1300 | ||
1298 | // add categories | 1301 | // add categories |
1299 | incidence->setCategories(categories); | 1302 | incidence->setCategories(categories); |
1300 | 1303 | ||
1301 | // iterate through all alarms | 1304 | // iterate through all alarms |
1302 | for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); | 1305 | for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); |
1303 | alarm; | 1306 | alarm; |
1304 | alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { | 1307 | alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { |
1305 | readAlarm(alarm,incidence); | 1308 | readAlarm(alarm,incidence); |
1306 | } | 1309 | } |
1307 | } | 1310 | } |
1308 | 1311 | ||
1309 | void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) | 1312 | void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) |
1310 | { | 1313 | { |
1311 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); | 1314 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); |
1312 | 1315 | ||
1313 | while (p) { | 1316 | while (p) { |
1314 | icalproperty_kind kind = icalproperty_isa(p); | 1317 | icalproperty_kind kind = icalproperty_isa(p); |
1315 | switch (kind) { | 1318 | switch (kind) { |
1316 | 1319 | ||
1317 | case ICAL_UID_PROPERTY: // unique id | 1320 | case ICAL_UID_PROPERTY: // unique id |
1318 | incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); | 1321 | incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); |
1319 | break; | 1322 | break; |
1320 | 1323 | ||
1321 | case ICAL_ORGANIZER_PROPERTY: // organizer | 1324 | case ICAL_ORGANIZER_PROPERTY: // organizer |
1322 | incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); | 1325 | incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); |
1323 | break; | 1326 | break; |
1324 | 1327 | ||
1325 | case ICAL_ATTENDEE_PROPERTY: // attendee | 1328 | case ICAL_ATTENDEE_PROPERTY: // attendee |
1326 | incidenceBase->addAttendee(readAttendee(p)); | 1329 | incidenceBase->addAttendee(readAttendee(p)); |
1327 | break; | 1330 | break; |
1328 | 1331 | ||
1329 | default: | 1332 | default: |
1330 | break; | 1333 | break; |
1331 | } | 1334 | } |
1332 | 1335 | ||
1333 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); | 1336 | p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); |
1334 | } | 1337 | } |
1335 | 1338 | ||
1336 | // custom properties | 1339 | // custom properties |
1337 | readCustomProperties(parent, incidenceBase); | 1340 | readCustomProperties(parent, incidenceBase); |
1338 | } | 1341 | } |
1339 | 1342 | ||
1340 | void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) | 1343 | void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) |
1341 | { | 1344 | { |
1342 | QMap<QCString, QString> customProperties; | 1345 | QMap<Q3CString, QString> customProperties; |
1343 | 1346 | ||
1344 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); | 1347 | icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); |
1345 | 1348 | ||
1346 | while (p) { | 1349 | while (p) { |
1347 | QString value = QString::fromUtf8(icalproperty_get_x(p)); | 1350 | QString value = QString::fromUtf8(icalproperty_get_x(p)); |
1348 | customProperties[icalproperty_get_x_name(p)] = value; | 1351 | customProperties[icalproperty_get_x_name(p)] = value; |
1349 | //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); | 1352 | //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); |
1350 | 1353 | ||
1351 | p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); | 1354 | p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); |
1352 | } | 1355 | } |
1353 | 1356 | ||
1354 | properties->setCustomProperties(customProperties); | 1357 | properties->setCustomProperties(customProperties); |
1355 | } | 1358 | } |
1356 | 1359 | ||
1357 | void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) | 1360 | void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) |
1358 | { | 1361 | { |
1359 | // kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; | 1362 | // kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; |
1360 | 1363 | ||
1361 | Recurrence *recur = incidence->recurrence(); | 1364 | Recurrence *recur = incidence->recurrence(); |
1362 | recur->setCompatVersion(mCalendarVersion); | 1365 | recur->setCompatVersion(mCalendarVersion); |
1363 | recur->unsetRecurs(); | 1366 | recur->unsetRecurs(); |
1364 | 1367 | ||
1365 | struct icalrecurrencetype r = rrule; | 1368 | struct icalrecurrencetype r = rrule; |
1366 | 1369 | ||
1367 | dumpIcalRecurrence(r); | 1370 | dumpIcalRecurrence(r); |
1368 | readRecurrence( r, recur, incidence); | 1371 | readRecurrence( r, recur, incidence); |
1369 | } | 1372 | } |
1370 | 1373 | ||
1371 | void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) | 1374 | void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) |
1372 | { | 1375 | { |
1373 | int wkst; | 1376 | int wkst; |
1374 | int index = 0; | 1377 | int index = 0; |
1375 | short day = 0; | 1378 | short day = 0; |
1376 | QBitArray qba(7); | 1379 | QBitArray qba(7); |
1377 | int frequ = r.freq; | 1380 | int frequ = r.freq; |
1378 | int interv = r.interval; | 1381 | int interv = r.interval; |
1379 | // preprocessing for odd recurrence definitions | 1382 | // preprocessing for odd recurrence definitions |
1380 | 1383 | ||
1381 | if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { | 1384 | if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { |
1382 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 1385 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
1383 | interv = 12; | 1386 | interv = 12; |
1384 | } | 1387 | } |
1385 | } | 1388 | } |
1386 | if ( r.freq == ICAL_YEARLY_RECURRENCE ) { | 1389 | if ( r.freq == ICAL_YEARLY_RECURRENCE ) { |
1387 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { | 1390 | if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { |
1388 | frequ = ICAL_MONTHLY_RECURRENCE; | 1391 | frequ = ICAL_MONTHLY_RECURRENCE; |
1389 | interv = 12* r.interval; | 1392 | interv = 12* r.interval; |
1390 | } | 1393 | } |
1391 | } | 1394 | } |
1392 | 1395 | ||
1393 | switch (frequ) { | 1396 | switch (frequ) { |
1394 | case ICAL_MINUTELY_RECURRENCE: | 1397 | case ICAL_MINUTELY_RECURRENCE: |
1395 | if (!icaltime_is_null_time(r.until)) { | 1398 | if (!icaltime_is_null_time(r.until)) { |
1396 | recur->setMinutely(interv,readICalDateTime(r.until)); | 1399 | recur->setMinutely(interv,readICalDateTime(r.until)); |
1397 | } else { | 1400 | } else { |
1398 | if (r.count == 0) | 1401 | if (r.count == 0) |
1399 | recur->setMinutely(interv,-1); | 1402 | recur->setMinutely(interv,-1); |
1400 | else | 1403 | else |
1401 | recur->setMinutely(interv,r.count); | 1404 | recur->setMinutely(interv,r.count); |
1402 | } | 1405 | } |
1403 | break; | 1406 | break; |
1404 | case ICAL_HOURLY_RECURRENCE: | 1407 | case ICAL_HOURLY_RECURRENCE: |
1405 | if (!icaltime_is_null_time(r.until)) { | 1408 | if (!icaltime_is_null_time(r.until)) { |
1406 | recur->setHourly(interv,readICalDateTime(r.until)); | 1409 | recur->setHourly(interv,readICalDateTime(r.until)); |
1407 | } else { | 1410 | } else { |
1408 | if (r.count == 0) | 1411 | if (r.count == 0) |
1409 | recur->setHourly(interv,-1); | 1412 | recur->setHourly(interv,-1); |
1410 | else | 1413 | else |
1411 | recur->setHourly(interv,r.count); | 1414 | recur->setHourly(interv,r.count); |
1412 | } | 1415 | } |
1413 | break; | 1416 | break; |
1414 | case ICAL_DAILY_RECURRENCE: | 1417 | case ICAL_DAILY_RECURRENCE: |
1415 | if (!icaltime_is_null_time(r.until)) { | 1418 | if (!icaltime_is_null_time(r.until)) { |
1416 | recur->setDaily(interv,readICalDate(r.until)); | 1419 | recur->setDaily(interv,readICalDate(r.until)); |
1417 | } else { | 1420 | } else { |
1418 | if (r.count == 0) | 1421 | if (r.count == 0) |
1419 | recur->setDaily(interv,-1); | 1422 | recur->setDaily(interv,-1); |
1420 | else | 1423 | else |
1421 | recur->setDaily(interv,r.count); | 1424 | recur->setDaily(interv,r.count); |
1422 | } | 1425 | } |
1423 | break; | 1426 | break; |
1424 | case ICAL_WEEKLY_RECURRENCE: | 1427 | case ICAL_WEEKLY_RECURRENCE: |
1425 | // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; | 1428 | // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; |
1426 | wkst = (r.week_start + 5)%7 + 1; | 1429 | wkst = (r.week_start + 5)%7 + 1; |
1427 | if (!icaltime_is_null_time(r.until)) { | 1430 | if (!icaltime_is_null_time(r.until)) { |
1428 | recur->setWeekly(interv,qba,readICalDate(r.until),wkst); | 1431 | recur->setWeekly(interv,qba,readICalDate(r.until),wkst); |
1429 | } else { | 1432 | } else { |
1430 | if (r.count == 0) | 1433 | if (r.count == 0) |
1431 | recur->setWeekly(interv,qba,-1,wkst); | 1434 | recur->setWeekly(interv,qba,-1,wkst); |
1432 | else | 1435 | else |
1433 | recur->setWeekly(interv,qba,r.count,wkst); | 1436 | recur->setWeekly(interv,qba,r.count,wkst); |
1434 | } | 1437 | } |
1435 | if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { | 1438 | if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { |
1436 | int wday = incidence->dtStart().date().dayOfWeek ()-1; | 1439 | int wday = incidence->dtStart().date().dayOfWeek ()-1; |
1437 | //qDebug("weekly error found "); | 1440 | //qDebug("weekly error found "); |
1438 | qba.setBit(wday); | 1441 | qba.setBit(wday); |