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/icalformat.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-p1.zip kdepimpi-p1.tar.gz kdepimpi-p1.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | libkcal/icalformat.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp index 6f3a799..3829bc1 100644 --- a/libkcal/icalformat.cpp +++ b/libkcal/icalformat.cpp | |||
@@ -1,402 +1,402 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qdatetime.h> | 21 | #include <qdatetime.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qptrlist.h> | 23 | #include <q3ptrlist.h> |
24 | #include <qregexp.h> | 24 | #include <qregexp.h> |
25 | #include <qclipboard.h> | 25 | #include <qclipboard.h> |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qtextstream.h> | 27 | #include <q3textstream.h> |
28 | #include <qtextcodec.h> | 28 | #include <qtextcodec.h> |
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <kglobal.h> | 32 | #include <kglobal.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | extern "C" { | 35 | extern "C" { |
36 | #include <ical.h> | 36 | #include <ical.h> |
37 | #include <icalss.h> | 37 | #include <icalss.h> |
38 | #include <icalparser.h> | 38 | #include <icalparser.h> |
39 | #include <icalrestriction.h> | 39 | #include <icalrestriction.h> |
40 | } | 40 | } |
41 | 41 | ||
42 | #include "calendar.h" | 42 | #include "calendar.h" |
43 | #include "calendarlocal.h" | 43 | #include "calendarlocal.h" |
44 | #include "journal.h" | 44 | #include "journal.h" |
45 | 45 | ||
46 | #include "icalformat.h" | 46 | #include "icalformat.h" |
47 | #include "icalformatimpl.h" | 47 | #include "icalformatimpl.h" |
48 | 48 | ||
49 | #define _ICAL_VERSION "2.0" | 49 | #define _ICAL_VERSION "2.0" |
50 | 50 | ||
51 | using namespace KCal; | 51 | using namespace KCal; |
52 | 52 | ||
53 | ICalFormat::ICalFormat( bool pe ) | 53 | ICalFormat::ICalFormat( bool pe ) |
54 | { | 54 | { |
55 | mProcessEvents = pe; | 55 | mProcessEvents = pe; |
56 | mImpl = new ICalFormatImpl( this ); | 56 | mImpl = new ICalFormatImpl( this ); |
57 | tzOffsetMin = 0; | 57 | tzOffsetMin = 0; |
58 | //qDebug("new ICalFormat() "); | 58 | //qDebug("new ICalFormat() "); |
59 | } | 59 | } |
60 | 60 | ||
61 | ICalFormat::~ICalFormat() | 61 | ICalFormat::~ICalFormat() |
62 | { | 62 | { |
63 | delete mImpl; | 63 | delete mImpl; |
64 | //qDebug("delete ICalFormat "); | 64 | //qDebug("delete ICalFormat "); |
65 | } | 65 | } |
66 | 66 | ||
67 | bool ICalFormat::load( Calendar *calendar, const QString &fileName) | 67 | bool ICalFormat::load( Calendar *calendar, const QString &fileName) |
68 | { | 68 | { |
69 | 69 | ||
70 | clearException(); | 70 | clearException(); |
71 | 71 | ||
72 | QFile file( fileName ); | 72 | QFile file( fileName ); |
73 | if (!file.open( IO_ReadOnly ) ) { | 73 | if (!file.open( QIODevice::ReadOnly ) ) { |
74 | setException(new ErrorFormat(ErrorFormat::LoadError)); | 74 | setException(new ErrorFormat(ErrorFormat::LoadError)); |
75 | return false; | 75 | return false; |
76 | } | 76 | } |
77 | QTextStream ts( &file ); | 77 | Q3TextStream ts( &file ); |
78 | QString text; | 78 | QString text; |
79 | 79 | ||
80 | ts.setEncoding( QTextStream::Latin1 ); | 80 | ts.setEncoding( Q3TextStream::Latin1 ); |
81 | text = ts.read(); | 81 | text = ts.read(); |
82 | file.close(); | 82 | file.close(); |
83 | 83 | ||
84 | return fromString( calendar, text ); | 84 | return fromString( calendar, text ); |
85 | } | 85 | } |
86 | 86 | ||
87 | //#include <qdatetime.h> | 87 | //#include <qdatetime.h> |
88 | bool ICalFormat::save( Calendar *calendar, const QString &fileName ) | 88 | bool ICalFormat::save( Calendar *calendar, const QString &fileName ) |
89 | { | 89 | { |
90 | //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; | 90 | //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; |
91 | //qDebug("ICalFormat::save "); | 91 | //qDebug("ICalFormat::save "); |
92 | clearException(); | 92 | clearException(); |
93 | QString text = toString( calendar ); | 93 | QString text = toString( calendar ); |
94 | //return false; | 94 | //return false; |
95 | // qDebug("to string takes ms: %d ",is.elapsed() ); | 95 | // qDebug("to string takes ms: %d ",is.elapsed() ); |
96 | if ( text.isNull() ) return false; | 96 | if ( text.isNull() ) return false; |
97 | 97 | ||
98 | // TODO: write backup file | 98 | // TODO: write backup file |
99 | //is.restart(); | 99 | //is.restart(); |
100 | QFile file( fileName ); | 100 | QFile file( fileName ); |
101 | if (!file.open( IO_WriteOnly ) ) { | 101 | if (!file.open( QIODevice::WriteOnly ) ) { |
102 | setException(new ErrorFormat(ErrorFormat::SaveError, | 102 | setException(new ErrorFormat(ErrorFormat::SaveError, |
103 | i18n("Could not open file '%1'").arg(fileName))); | 103 | i18n("Could not open file '%1'").arg(fileName))); |
104 | return false; | 104 | return false; |
105 | } | 105 | } |
106 | QTextStream ts( &file ); | 106 | Q3TextStream ts( &file ); |
107 | 107 | ||
108 | ts.setEncoding( QTextStream::Latin1 ); | 108 | ts.setEncoding( Q3TextStream::Latin1 ); |
109 | ts << text; | 109 | ts << text; |
110 | file.close(); | 110 | file.close(); |
111 | //qDebug("saving file takes ms: %d ", is.elapsed() ); | 111 | //qDebug("saving file takes ms: %d ", is.elapsed() ); |
112 | return true; | 112 | return true; |
113 | } | 113 | } |
114 | 114 | ||
115 | bool ICalFormat::fromString( Calendar *cal, const QString &text ) | 115 | bool ICalFormat::fromString( Calendar *cal, const QString &text ) |
116 | { | 116 | { |
117 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 117 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
118 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); | 118 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); |
119 | // Get first VCALENDAR component. | 119 | // Get first VCALENDAR component. |
120 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components | 120 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components |
121 | icalcomponent *calendar; | 121 | icalcomponent *calendar; |
122 | 122 | ||
123 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); | 123 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); |
124 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); | 124 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); |
125 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); | 125 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); |
126 | if (!calendar) { | 126 | if (!calendar) { |
127 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); | 127 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | 130 | ||
131 | bool success = true; | 131 | bool success = true; |
132 | 132 | ||
133 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { | 133 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { |
134 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); | 134 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); |
135 | success = false; | 135 | success = false; |
136 | } else { | 136 | } else { |
137 | // put all objects into their proper places | 137 | // put all objects into their proper places |
138 | if ( !mImpl->populate( cal, calendar ) ) { | 138 | if ( !mImpl->populate( cal, calendar ) ) { |
139 | if ( !exception() ) { | 139 | if ( !exception() ) { |
140 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); | 140 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); |
141 | } | 141 | } |
142 | success = false; | 142 | success = false; |
143 | } else | 143 | } else |
144 | mLoadedProductId = mImpl->loadedProductId(); | 144 | mLoadedProductId = mImpl->loadedProductId(); |
145 | } | 145 | } |
146 | 146 | ||
147 | icalcomponent_free( calendar ); | 147 | icalcomponent_free( calendar ); |
148 | icalmemory_free_ring(); | 148 | icalmemory_free_ring(); |
149 | 149 | ||
150 | return success; | 150 | return success; |
151 | } | 151 | } |
152 | 152 | ||
153 | Incidence *ICalFormat::fromString( const QString &text ) | 153 | Incidence *ICalFormat::fromString( const QString &text ) |
154 | { | 154 | { |
155 | CalendarLocal cal( mTimeZoneId ); | 155 | CalendarLocal cal( mTimeZoneId ); |
156 | fromString(&cal, text); | 156 | fromString(&cal, text); |
157 | 157 | ||
158 | Incidence *ical = 0; | 158 | Incidence *ical = 0; |
159 | QPtrList<Event> elist = cal.events(); | 159 | Q3PtrList<Event> elist = cal.events(); |
160 | if ( elist.count() > 0 ) { | 160 | if ( elist.count() > 0 ) { |
161 | ical = elist.first(); | 161 | ical = elist.first(); |
162 | } else { | 162 | } else { |
163 | QPtrList<Todo> tlist = cal.todos(); | 163 | Q3PtrList<Todo> tlist = cal.todos(); |
164 | if ( tlist.count() > 0 ) { | 164 | if ( tlist.count() > 0 ) { |
165 | ical = tlist.first(); | 165 | ical = tlist.first(); |
166 | } else { | 166 | } else { |
167 | QPtrList<Journal> jlist = cal.journals(); | 167 | Q3PtrList<Journal> jlist = cal.journals(); |
168 | if ( jlist.count() > 0 ) { | 168 | if ( jlist.count() > 0 ) { |
169 | ical = jlist.first(); | 169 | ical = jlist.first(); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | } | 172 | } |
173 | return ical; | 173 | return ical; |
174 | } | 174 | } |
175 | #include <qapp.h> | 175 | #include <qapplication.h> |
176 | 176 | ||
177 | QString ICalFormat::toString( Calendar *cal ) | 177 | QString ICalFormat::toString( Calendar *cal ) |
178 | { | 178 | { |
179 | 179 | ||
180 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 180 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
181 | 181 | ||
182 | icalcomponent *calendar = mImpl->createCalendarComponent(cal); | 182 | icalcomponent *calendar = mImpl->createCalendarComponent(cal); |
183 | 183 | ||
184 | icalcomponent *component; | 184 | icalcomponent *component; |
185 | 185 | ||
186 | // todos | 186 | // todos |
187 | QPtrList<Todo> todoList = cal->rawTodos(); | 187 | Q3PtrList<Todo> todoList = cal->rawTodos(); |
188 | QPtrListIterator<Todo> qlt(todoList); | 188 | Q3PtrListIterator<Todo> qlt(todoList); |
189 | for (; qlt.current(); ++qlt) { | 189 | for (; qlt.current(); ++qlt) { |
190 | component = mImpl->writeTodo(qlt.current()); | 190 | component = mImpl->writeTodo(qlt.current()); |
191 | icalcomponent_add_component(calendar,component); | 191 | icalcomponent_add_component(calendar,component); |
192 | //qDebug(" todos "); | 192 | //qDebug(" todos "); |
193 | if ( mProcessEvents ) { | 193 | if ( mProcessEvents ) { |
194 | //qDebug("mProcessEvents "); | 194 | //qDebug("mProcessEvents "); |
195 | qApp->processEvents(); | 195 | qApp->processEvents(); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | // events | 198 | // events |
199 | QPtrList<Event> events = cal->rawEvents(); | 199 | Q3PtrList<Event> events = cal->rawEvents(); |
200 | Event *ev; | 200 | Event *ev; |
201 | for(ev=events.first();ev;ev=events.next()) { | 201 | for(ev=events.first();ev;ev=events.next()) { |
202 | component = mImpl->writeEvent(ev); | 202 | component = mImpl->writeEvent(ev); |
203 | icalcomponent_add_component(calendar,component); | 203 | icalcomponent_add_component(calendar,component); |
204 | //qDebug("events "); | 204 | //qDebug("events "); |
205 | if ( mProcessEvents ) | 205 | if ( mProcessEvents ) |
206 | qApp->processEvents(); | 206 | qApp->processEvents(); |
207 | } | 207 | } |
208 | 208 | ||
209 | // journals | 209 | // journals |
210 | QPtrList<Journal> journals = cal->journals(); | 210 | Q3PtrList<Journal> journals = cal->journals(); |
211 | Journal *j; | 211 | Journal *j; |
212 | for(j=journals.first();j;j=journals.next()) { | 212 | for(j=journals.first();j;j=journals.next()) { |
213 | component = mImpl->writeJournal(j); | 213 | component = mImpl->writeJournal(j); |
214 | icalcomponent_add_component(calendar,component); | 214 | icalcomponent_add_component(calendar,component); |
215 | //qDebug("journals "); | 215 | //qDebug("journals "); |
216 | if ( mProcessEvents ) | 216 | if ( mProcessEvents ) |
217 | qApp->processEvents(); | 217 | qApp->processEvents(); |
218 | } | 218 | } |
219 | const char *text; | 219 | const char *text; |
220 | QString ret =""; | 220 | QString ret =""; |
221 | text = icalcomponent_as_ical_string( calendar ); | 221 | text = icalcomponent_as_ical_string( calendar ); |
222 | if ( mProcessEvents ) | 222 | if ( mProcessEvents ) |
223 | qApp->processEvents(); | 223 | qApp->processEvents(); |
224 | 224 | ||
225 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; | 225 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; |
226 | 226 | ||
227 | 227 | ||
228 | if ( text ) { | 228 | if ( text ) { |
229 | ret = QString ( text ); | 229 | ret = QString ( text ); |
230 | } | 230 | } |
231 | icalcomponent_free( calendar ); | 231 | icalcomponent_free( calendar ); |
232 | 232 | ||
233 | if (!text) { | 233 | if (!text) { |
234 | setException(new ErrorFormat(ErrorFormat::SaveError, | 234 | setException(new ErrorFormat(ErrorFormat::SaveError, |
235 | i18n("libical error"))); | 235 | i18n("libical error"))); |
236 | icalmemory_free_ring(); | 236 | icalmemory_free_ring(); |
237 | return QString::null; | 237 | return QString::null; |
238 | } | 238 | } |
239 | icalmemory_free_ring(); | 239 | icalmemory_free_ring(); |
240 | return ret; | 240 | return ret; |
241 | } | 241 | } |
242 | 242 | ||
243 | QString ICalFormat::toICalString( Incidence *incidence ) | 243 | QString ICalFormat::toICalString( Incidence *incidence ) |
244 | { | 244 | { |
245 | CalendarLocal cal( mTimeZoneId ); | 245 | CalendarLocal cal( mTimeZoneId ); |
246 | cal.addIncidence( incidence->clone() ); | 246 | cal.addIncidence( incidence->clone() ); |
247 | return toString( &cal ); | 247 | return toString( &cal ); |
248 | } | 248 | } |
249 | 249 | ||
250 | QString ICalFormat::toString( Incidence *incidence ) | 250 | QString ICalFormat::toString( Incidence *incidence ) |
251 | { | 251 | { |
252 | icalcomponent *component; | 252 | icalcomponent *component; |
253 | 253 | ||
254 | component = mImpl->writeIncidence( incidence ); | 254 | component = mImpl->writeIncidence( incidence ); |
255 | 255 | ||
256 | const char *text = icalcomponent_as_ical_string( component ); | 256 | const char *text = icalcomponent_as_ical_string( component ); |
257 | 257 | ||
258 | icalcomponent_free( component ); | 258 | icalcomponent_free( component ); |
259 | 259 | ||
260 | return QString::fromLocal8Bit( text ); | 260 | return QString::fromLocal8Bit( text ); |
261 | } | 261 | } |
262 | 262 | ||
263 | QString ICalFormat::toString( Recurrence *recurrence ) | 263 | QString ICalFormat::toString( Recurrence *recurrence ) |
264 | { | 264 | { |
265 | icalproperty *property; | 265 | icalproperty *property; |
266 | property = mImpl->writeRecurrenceRule( recurrence ); | 266 | property = mImpl->writeRecurrenceRule( recurrence ); |
267 | const char *text = icalproperty_as_ical_string( property ); | 267 | const char *text = icalproperty_as_ical_string( property ); |
268 | icalproperty_free( property ); | 268 | icalproperty_free( property ); |
269 | return QString::fromLocal8Bit( text ); | 269 | return QString::fromLocal8Bit( text ); |
270 | } | 270 | } |
271 | /* | 271 | /* |
272 | bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) | 272 | bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) |
273 | { | 273 | { |
274 | bool success = true; | 274 | bool success = true; |
275 | icalerror_clear_errno(); | 275 | icalerror_clear_errno(); |
276 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); | 276 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); |
277 | if ( icalerrno != ICAL_NO_ERROR ) { | 277 | if ( icalerrno != ICAL_NO_ERROR ) { |
278 | kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; | 278 | kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; |
279 | success = false; | 279 | success = false; |
280 | } | 280 | } |
281 | 281 | ||
282 | if ( success ) { | 282 | if ( success ) { |
283 | mImpl->readRecurrence( recur, recurrence ); | 283 | mImpl->readRecurrence( recur, recurrence ); |
284 | } | 284 | } |
285 | 285 | ||
286 | return success; | 286 | return success; |
287 | } | 287 | } |
288 | */ | 288 | */ |
289 | 289 | ||
290 | QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, | 290 | QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, |
291 | Scheduler::Method method) | 291 | Scheduler::Method method) |
292 | { | 292 | { |
293 | icalcomponent *message = mImpl->createScheduleComponent(incidence,method); | 293 | icalcomponent *message = mImpl->createScheduleComponent(incidence,method); |
294 | 294 | ||
295 | QString messageText = icalcomponent_as_ical_string(message); | 295 | QString messageText = icalcomponent_as_ical_string(message); |
296 | 296 | ||
297 | 297 | ||
298 | 298 | ||
299 | return messageText; | 299 | return messageText; |
300 | } | 300 | } |
301 | 301 | ||
302 | ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, | 302 | ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, |
303 | const QString &messageText ) | 303 | const QString &messageText ) |
304 | { | 304 | { |
305 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 305 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
306 | clearException(); | 306 | clearException(); |
307 | 307 | ||
308 | if (messageText.isEmpty()) return 0; | 308 | if (messageText.isEmpty()) return 0; |
309 | 309 | ||
310 | icalcomponent *message; | 310 | icalcomponent *message; |
311 | message = icalparser_parse_string(messageText.local8Bit()); | 311 | message = icalparser_parse_string(messageText.local8Bit()); |
312 | 312 | ||
313 | if (!message) return 0; | 313 | if (!message) return 0; |
314 | 314 | ||
315 | icalproperty *m = icalcomponent_get_first_property(message, | 315 | icalproperty *m = icalcomponent_get_first_property(message, |
316 | ICAL_METHOD_PROPERTY); | 316 | ICAL_METHOD_PROPERTY); |
317 | 317 | ||
318 | if (!m) return 0; | 318 | if (!m) return 0; |
319 | 319 | ||
320 | icalcomponent *c; | 320 | icalcomponent *c; |
321 | 321 | ||
322 | IncidenceBase *incidence = 0; | 322 | IncidenceBase *incidence = 0; |
323 | c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); | 323 | c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); |
324 | if (c) { | 324 | if (c) { |
325 | incidence = mImpl->readEvent(c); | 325 | incidence = mImpl->readEvent(c); |
326 | } | 326 | } |
327 | 327 | ||
328 | if (!incidence) { | 328 | if (!incidence) { |
329 | c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); | 329 | c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); |
330 | if (c) { | 330 | if (c) { |
331 | incidence = mImpl->readTodo(c); | 331 | incidence = mImpl->readTodo(c); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | if (!incidence) { | 335 | if (!incidence) { |
336 | c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); | 336 | c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); |
337 | if (c) { | 337 | if (c) { |
338 | incidence = mImpl->readFreeBusy(c); | 338 | incidence = mImpl->readFreeBusy(c); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | if (!incidence) { | 342 | if (!incidence) { |
343 | kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; | 343 | kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; |
344 | return 0; | 344 | return 0; |
345 | } | 345 | } |
346 | 346 | ||
347 | kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; | 347 | kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; |
348 | 348 | ||
349 | icalproperty_method icalmethod = icalproperty_get_method(m); | 349 | icalproperty_method icalmethod = icalproperty_get_method(m); |
350 | Scheduler::Method method; | 350 | Scheduler::Method method; |
351 | 351 | ||
352 | switch (icalmethod) { | 352 | switch (icalmethod) { |
353 | case ICAL_METHOD_PUBLISH: | 353 | case ICAL_METHOD_PUBLISH: |
354 | method = Scheduler::Publish; | 354 | method = Scheduler::Publish; |
355 | break; | 355 | break; |
356 | case ICAL_METHOD_REQUEST: | 356 | case ICAL_METHOD_REQUEST: |
357 | method = Scheduler::Request; | 357 | method = Scheduler::Request; |
358 | break; | 358 | break; |
359 | case ICAL_METHOD_REFRESH: | 359 | case ICAL_METHOD_REFRESH: |
360 | method = Scheduler::Refresh; | 360 | method = Scheduler::Refresh; |
361 | break; | 361 | break; |
362 | case ICAL_METHOD_CANCEL: | 362 | case ICAL_METHOD_CANCEL: |
363 | method = Scheduler::Cancel; | 363 | method = Scheduler::Cancel; |
364 | break; | 364 | break; |
365 | case ICAL_METHOD_ADD: | 365 | case ICAL_METHOD_ADD: |
366 | method = Scheduler::Add; | 366 | method = Scheduler::Add; |
367 | break; | 367 | break; |
368 | case ICAL_METHOD_REPLY: | 368 | case ICAL_METHOD_REPLY: |
369 | method = Scheduler::Reply; | 369 | method = Scheduler::Reply; |
370 | break; | 370 | break; |
371 | case ICAL_METHOD_COUNTER: | 371 | case ICAL_METHOD_COUNTER: |
372 | method = Scheduler::Counter; | 372 | method = Scheduler::Counter; |
373 | break; | 373 | break; |
374 | case ICAL_METHOD_DECLINECOUNTER: | 374 | case ICAL_METHOD_DECLINECOUNTER: |
375 | method = Scheduler::Declinecounter; | 375 | method = Scheduler::Declinecounter; |
376 | break; | 376 | break; |
377 | default: | 377 | default: |
378 | method = Scheduler::NoMethod; | 378 | method = Scheduler::NoMethod; |
379 | kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; | 379 | kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; |
380 | break; | 380 | break; |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | if (!icalrestriction_check(message)) { | 384 | if (!icalrestriction_check(message)) { |
385 | setException(new ErrorFormat(ErrorFormat::Restriction, | 385 | setException(new ErrorFormat(ErrorFormat::Restriction, |
386 | Scheduler::translatedMethodName(method) + ": " + | 386 | Scheduler::translatedMethodName(method) + ": " + |
387 | mImpl->extractErrorProperty(c))); | 387 | mImpl->extractErrorProperty(c))); |
388 | return 0; | 388 | return 0; |
389 | } | 389 | } |
390 | 390 | ||
391 | icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); | 391 | icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); |
392 | 392 | ||
393 | Incidence *existingIncidence = cal->event(incidence->uid()); | 393 | Incidence *existingIncidence = cal->event(incidence->uid()); |
394 | if (existingIncidence) { | 394 | if (existingIncidence) { |
395 | // TODO: check, if cast is required, or if it can be done by virtual funcs. | 395 | // TODO: check, if cast is required, or if it can be done by virtual funcs. |
396 | if (existingIncidence->typeID() == todoID ) { | 396 | if (existingIncidence->typeID() == todoID ) { |
397 | Todo *todo = static_cast<Todo *>(existingIncidence); | 397 | Todo *todo = static_cast<Todo *>(existingIncidence); |
398 | icalcomponent_add_component(calendarComponent, | 398 | icalcomponent_add_component(calendarComponent, |
399 | mImpl->writeTodo(todo)); | 399 | mImpl->writeTodo(todo)); |
400 | } | 400 | } |
401 | if (existingIncidence->typeID() == eventID ) { | 401 | if (existingIncidence->typeID() == eventID ) { |
402 | Event *event = static_cast<Event *>(existingIncidence); | 402 | Event *event = static_cast<Event *>(existingIncidence); |