summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-08-01 21:34:31 (UTC)
committer zautrix <zautrix>2004-08-01 21:34:31 (UTC)
commited3af1a632f953179ef3cad76ab5d99809f47d60 (patch) (unidiff)
treebe4fdfcf808d6876b4bee0698ddc17c8d20313d4
parent062113379f93ed645d2f246183c89eb8b6814834 (diff)
downloadkdepimpi-ed3af1a632f953179ef3cad76ab5d99809f47d60.zip
kdepimpi-ed3af1a632f953179ef3cad76ab5d99809f47d60.tar.gz
kdepimpi-ed3af1a632f953179ef3cad76ab5d99809f47d60.tar.bz2
More sync work
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp16
-rw-r--r--libkcal/incidencebase.cpp81
-rw-r--r--libkcal/incidencebase.h8
3 files changed, 92 insertions, 13 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index df05ab3..c23978d 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -14,519 +14,516 @@
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qdatetime.h> 21#include <qdatetime.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qptrlist.h> 23#include <qptrlist.h>
24#include <qfile.h> 24#include <qfile.h>
25 25
26#include <kdebug.h> 26#include <kdebug.h>
27#include <klocale.h> 27#include <klocale.h>
28#include <kglobal.h> 28#include <kglobal.h>
29 29
30extern "C" { 30extern "C" {
31 #include <ical.h> 31 #include <ical.h>
32 #include <icalss.h> 32 #include <icalss.h>
33 #include <icalparser.h> 33 #include <icalparser.h>
34 #include <icalrestriction.h> 34 #include <icalrestriction.h>
35} 35}
36 36
37#include "calendar.h" 37#include "calendar.h"
38#include "journal.h" 38#include "journal.h"
39#include "icalformat.h" 39#include "icalformat.h"
40#include "icalformatimpl.h" 40#include "icalformatimpl.h"
41#include "compat.h" 41#include "compat.h"
42 42
43#define _ICAL_VERSION "2.0" 43#define _ICAL_VERSION "2.0"
44 44
45using namespace KCal; 45using namespace KCal;
46 46
47const int gSecondsPerMinute = 60; 47const int gSecondsPerMinute = 60;
48const int gSecondsPerHour = gSecondsPerMinute * 60; 48const int gSecondsPerHour = gSecondsPerMinute * 60;
49const int gSecondsPerDay = gSecondsPerHour * 24; 49const int gSecondsPerDay = gSecondsPerHour * 24;
50const int gSecondsPerWeek = gSecondsPerDay * 7; 50const int gSecondsPerWeek = gSecondsPerDay * 7;
51 51
52ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : 52ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) :
53 mParent( parent ), mCalendarVersion( 0 ) 53 mParent( parent ), mCalendarVersion( 0 )
54{ 54{
55 mCompat = new Compat; 55 mCompat = new Compat;
56} 56}
57 57
58ICalFormatImpl::~ICalFormatImpl() 58ICalFormatImpl::~ICalFormatImpl()
59{ 59{
60 delete mCompat; 60 delete mCompat;
61} 61}
62 62
63class ToStringVisitor : public Incidence::Visitor 63class ToStringVisitor : public Incidence::Visitor
64{ 64{
65 public: 65 public:
66 ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} 66 ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {}
67 67
68 bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } 68 bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; }
69 bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } 69 bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; }
70 bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } 70 bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; }
71 71
72 icalcomponent *component() { return mComponent; } 72 icalcomponent *component() { return mComponent; }
73 73
74 private: 74 private:
75 ICalFormatImpl *mImpl; 75 ICalFormatImpl *mImpl;
76 icalcomponent *mComponent; 76 icalcomponent *mComponent;
77}; 77};
78 78
79icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) 79icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence)
80{ 80{
81 ToStringVisitor v( this ); 81 ToStringVisitor v( this );
82 incidence->accept(v); 82 incidence->accept(v);
83 return v.component(); 83 return v.component();
84} 84}
85 85
86icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) 86icalcomponent *ICalFormatImpl::writeTodo(Todo *todo)
87{ 87{
88 QString tmpStr; 88 QString tmpStr;
89 QStringList tmpStrList; 89 QStringList tmpStrList;
90 90
91 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); 91 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
92 92
93 writeIncidence(vtodo,todo); 93 writeIncidence(vtodo,todo);
94 94
95 // due date 95 // due date
96 if (todo->hasDueDate()) { 96 if (todo->hasDueDate()) {
97 icaltimetype due; 97 icaltimetype due;
98 if (todo->doesFloat()) { 98 if (todo->doesFloat()) {
99 due = writeICalDate(todo->dtDue().date()); 99 due = writeICalDate(todo->dtDue().date());
100 } else { 100 } else {
101 due = writeICalDateTime(todo->dtDue()); 101 due = writeICalDateTime(todo->dtDue());
102 } 102 }
103 icalcomponent_add_property(vtodo,icalproperty_new_due(due)); 103 icalcomponent_add_property(vtodo,icalproperty_new_due(due));
104 } 104 }
105 105
106 // start time 106 // start time
107 if (todo->hasStartDate()) { 107 if (todo->hasStartDate()) {
108 icaltimetype start; 108 icaltimetype start;
109 if (todo->doesFloat()) { 109 if (todo->doesFloat()) {
110// kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; 110// kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl;
111 start = writeICalDate(todo->dtStart().date()); 111 start = writeICalDate(todo->dtStart().date());
112 } else { 112 } else {
113// kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; 113// kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl;
114 start = writeICalDateTime(todo->dtStart()); 114 start = writeICalDateTime(todo->dtStart());
115 } 115 }
116 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); 116 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start));
117 } 117 }
118 118
119 // completion date 119 // completion date
120 if (todo->isCompleted()) { 120 if (todo->isCompleted()) {
121 if (!todo->hasCompletedDate()) { 121 if (!todo->hasCompletedDate()) {
122 // If todo was created by KOrganizer <2.2 it has no correct completion 122 // If todo was created by KOrganizer <2.2 it has no correct completion
123 // date. Set it to now. 123 // date. Set it to now.
124 todo->setCompleted(QDateTime::currentDateTime()); 124 todo->setCompleted(QDateTime::currentDateTime());
125 } 125 }
126 icaltimetype completed = writeICalDateTime(todo->completed()); 126 icaltimetype completed = writeICalDateTime(todo->completed());
127 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed)); 127 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed));
128 } 128 }
129 129
130 icalcomponent_add_property(vtodo, 130 icalcomponent_add_property(vtodo,
131 icalproperty_new_percentcomplete(todo->percentComplete())); 131 icalproperty_new_percentcomplete(todo->percentComplete()));
132 132
133 return vtodo; 133 return vtodo;
134} 134}
135 135
136icalcomponent *ICalFormatImpl::writeEvent(Event *event) 136icalcomponent *ICalFormatImpl::writeEvent(Event *event)
137{ 137{
138 kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() 138 kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid()
139 << ")" << endl; 139 << ")" << endl;
140 140
141 QString tmpStr; 141 QString tmpStr;
142 QStringList tmpStrList; 142 QStringList tmpStrList;
143 143
144 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); 144 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
145 145
146 writeIncidence(vevent,event); 146 writeIncidence(vevent,event);
147 147
148 // start time 148 // start time
149 icaltimetype start; 149 icaltimetype start;
150 if (event->doesFloat()) { 150 if (event->doesFloat()) {
151// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 151// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
152 start = writeICalDate(event->dtStart().date()); 152 start = writeICalDate(event->dtStart().date());
153 } else { 153 } else {
154// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 154// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
155 start = writeICalDateTime(event->dtStart()); 155 start = writeICalDateTime(event->dtStart());
156 } 156 }
157 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); 157 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start));
158 158
159 if (event->hasEndDate()) { 159 if (event->hasEndDate()) {
160 // end time 160 // end time
161 icaltimetype end; 161 icaltimetype end;
162 if (event->doesFloat()) { 162 if (event->doesFloat()) {
163// kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; 163// kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl;
164 // +1 day because end date is non-inclusive. 164 // +1 day because end date is non-inclusive.
165 end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); 165 end = writeICalDate( event->dtEnd().date().addDays( 1 ) );
166 } else { 166 } else {
167// kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; 167// kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl;
168 end = writeICalDateTime(event->dtEnd()); 168 end = writeICalDateTime(event->dtEnd());
169 } 169 }
170 icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); 170 icalcomponent_add_property(vevent,icalproperty_new_dtend(end));
171 } 171 }
172 172
173// TODO: attachments, resources 173// TODO: attachments, resources
174#if 0 174#if 0
175 // attachments 175 // attachments
176 tmpStrList = anEvent->attachments(); 176 tmpStrList = anEvent->attachments();
177 for ( QStringList::Iterator it = tmpStrList.begin(); 177 for ( QStringList::Iterator it = tmpStrList.begin();
178 it != tmpStrList.end(); 178 it != tmpStrList.end();
179 ++it ) 179 ++it )
180 addPropValue(vevent, VCAttachProp, (*it).utf8()); 180 addPropValue(vevent, VCAttachProp, (*it).utf8());
181 181
182 // resources 182 // resources
183 tmpStrList = anEvent->resources(); 183 tmpStrList = anEvent->resources();
184 tmpStr = tmpStrList.join(";"); 184 tmpStr = tmpStrList.join(";");
185 if (!tmpStr.isEmpty()) 185 if (!tmpStr.isEmpty())
186 addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); 186 addPropValue(vevent, VCResourcesProp, tmpStr.utf8());
187 187
188#endif 188#endif
189 189
190 // Transparency 190 // Transparency
191 switch( event->transparency() ) { 191 switch( event->transparency() ) {
192 case Event::Transparent: 192 case Event::Transparent:
193 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); 193 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT));
194 break; 194 break;
195 case Event::Opaque: 195 case Event::Opaque:
196 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); 196 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE));
197 break; 197 break;
198 } 198 }
199 199
200 return vevent; 200 return vevent;
201} 201}
202 202
203icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, 203icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy,
204 Scheduler::Method method) 204 Scheduler::Method method)
205{ 205{
206#if QT_VERSION >= 300 206#if QT_VERSION >= 300
207 kdDebug(5800) << "icalformatimpl: writeFreeBusy: startDate: " 207 kdDebug(5800) << "icalformatimpl: writeFreeBusy: startDate: "
208 << freebusy->dtStart().toString("ddd MMMM d yyyy: h:m:s ap") << " End Date: " 208 << freebusy->dtStart().toString("ddd MMMM d yyyy: h:m:s ap") << " End Date: "
209 << freebusy->dtEnd().toString("ddd MMMM d yyyy: h:m:s ap") << endl; 209 << freebusy->dtEnd().toString("ddd MMMM d yyyy: h:m:s ap") << endl;
210#endif 210#endif
211 211
212 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); 212 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
213 213
214 writeIncidenceBase(vfreebusy,freebusy); 214 writeIncidenceBase(vfreebusy,freebusy);
215 215
216 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( 216 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
217 writeICalDateTime(freebusy->dtStart()))); 217 writeICalDateTime(freebusy->dtStart())));
218 218
219 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( 219 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
220 writeICalDateTime(freebusy->dtEnd()))); 220 writeICalDateTime(freebusy->dtEnd())));
221 221
222 if (method == Scheduler::Request) { 222 if (method == Scheduler::Request) {
223 icalcomponent_add_property(vfreebusy,icalproperty_new_uid( 223 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
224 freebusy->uid().utf8())); 224 freebusy->uid().utf8()));
225 } 225 }
226 226
227 //Loops through all the periods in the freebusy object 227 //Loops through all the periods in the freebusy object
228 QValueList<Period> list = freebusy->busyPeriods(); 228 QValueList<Period> list = freebusy->busyPeriods();
229 QValueList<Period>::Iterator it; 229 QValueList<Period>::Iterator it;
230 icalperiodtype period; 230 icalperiodtype period;
231 for (it = list.begin(); it!= list.end(); ++it) { 231 for (it = list.begin(); it!= list.end(); ++it) {
232 period.start = writeICalDateTime((*it).start()); 232 period.start = writeICalDateTime((*it).start());
233 period.end = writeICalDateTime((*it).end()); 233 period.end = writeICalDateTime((*it).end());
234 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); 234 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
235 } 235 }
236 236
237 return vfreebusy; 237 return vfreebusy;
238} 238}
239 239
240icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) 240icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
241{ 241{
242 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); 242 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
243 243
244 writeIncidence(vjournal,journal); 244 writeIncidence(vjournal,journal);
245 245
246 // start time 246 // start time
247 if (journal->dtStart().isValid()) { 247 if (journal->dtStart().isValid()) {
248 icaltimetype start; 248 icaltimetype start;
249 if (journal->doesFloat()) { 249 if (journal->doesFloat()) {
250// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 250// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
251 start = writeICalDate(journal->dtStart().date()); 251 start = writeICalDate(journal->dtStart().date());
252 } else { 252 } else {
253// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 253// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
254 start = writeICalDateTime(journal->dtStart()); 254 start = writeICalDateTime(journal->dtStart());
255 } 255 }
256 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); 256 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
257 } 257 }
258 258
259 return vjournal; 259 return vjournal;
260} 260}
261 261
262void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) 262void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
263{ 263{
264 // pilot sync stuff 264 // pilot sync stuff
265// TODO: move this application-specific code to kpilot 265// TODO: move this application-specific code to kpilot
266 if (incidence->pilotId()) { 266 if (incidence->pilotId()) {
267 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); 267 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId()));
268 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); 268 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus()));
269 } 269 }
270 if (incidence->zaurusId() >= 0) { 270 if ( !incidence->IDStr().isEmpty()) {
271 incidence->setNonKDECustomProperty("X-ZAURUSID", QString::number(incidence->zaurusId())); 271 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() );
272 } 272 }
273 273
274 if (incidence->zaurusUid() > 0) {
275 incidence->setNonKDECustomProperty("X-ZAURUSUID", QString::number(incidence->zaurusUid()));
276 }
277 274
278 writeIncidenceBase(parent,incidence); 275 writeIncidenceBase(parent,incidence);
279 if (incidence->cancelled()) { 276 if (incidence->cancelled()) {
280 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); 277 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED));
281 } 278 }
282 279
283 // creation date 280 // creation date
284 icalcomponent_add_property(parent,icalproperty_new_created( 281 icalcomponent_add_property(parent,icalproperty_new_created(
285 writeICalDateTime(incidence->created()))); 282 writeICalDateTime(incidence->created())));
286 283
287 // unique id 284 // unique id
288 icalcomponent_add_property(parent,icalproperty_new_uid( 285 icalcomponent_add_property(parent,icalproperty_new_uid(
289 incidence->uid().utf8())); 286 incidence->uid().utf8()));
290 287
291 // revision 288 // revision
292 icalcomponent_add_property(parent,icalproperty_new_sequence( 289 icalcomponent_add_property(parent,icalproperty_new_sequence(
293 incidence->revision())); 290 incidence->revision()));
294 291
295 // last modification date 292 // last modification date
296 icalcomponent_add_property(parent,icalproperty_new_lastmodified( 293 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
297 writeICalDateTime(incidence->lastModified()))); 294 writeICalDateTime(incidence->lastModified())));
298 295
299 // description 296 // description
300 if (!incidence->description().isEmpty()) { 297 if (!incidence->description().isEmpty()) {
301 icalcomponent_add_property(parent,icalproperty_new_description( 298 icalcomponent_add_property(parent,icalproperty_new_description(
302 incidence->description().utf8())); 299 incidence->description().utf8()));
303 } 300 }
304 301
305 // summary 302 // summary
306 if (!incidence->summary().isEmpty()) { 303 if (!incidence->summary().isEmpty()) {
307 icalcomponent_add_property(parent,icalproperty_new_summary( 304 icalcomponent_add_property(parent,icalproperty_new_summary(
308 incidence->summary().utf8())); 305 incidence->summary().utf8()));
309 } 306 }
310 307
311 // location 308 // location
312 if (!incidence->location().isEmpty()) { 309 if (!incidence->location().isEmpty()) {
313 icalcomponent_add_property(parent,icalproperty_new_location( 310 icalcomponent_add_property(parent,icalproperty_new_location(
314 incidence->location().utf8())); 311 incidence->location().utf8()));
315 } 312 }
316 313
317// TODO: 314// TODO:
318 // status 315 // status
319// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); 316// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8());
320 317
321 // secrecy 318 // secrecy
322 enum icalproperty_class classInt; 319 enum icalproperty_class classInt;
323 switch (incidence->secrecy()) { 320 switch (incidence->secrecy()) {
324 case Incidence::SecrecyPublic: 321 case Incidence::SecrecyPublic:
325 classInt = ICAL_CLASS_PUBLIC; 322 classInt = ICAL_CLASS_PUBLIC;
326 break; 323 break;
327 case Incidence::SecrecyConfidential: 324 case Incidence::SecrecyConfidential:
328 classInt = ICAL_CLASS_CONFIDENTIAL; 325 classInt = ICAL_CLASS_CONFIDENTIAL;
329 break; 326 break;
330 case Incidence::SecrecyPrivate: 327 case Incidence::SecrecyPrivate:
331 classInt =ICAL_CLASS_PRIVATE ; 328 classInt =ICAL_CLASS_PRIVATE ;
332 default: 329 default:
333 classInt =ICAL_CLASS_PRIVATE ; 330 classInt =ICAL_CLASS_PRIVATE ;
334 break; 331 break;
335 } 332 }
336 icalcomponent_add_property(parent,icalproperty_new_class(classInt)); 333 icalcomponent_add_property(parent,icalproperty_new_class(classInt));
337 334
338 // priority 335 // priority
339 icalcomponent_add_property(parent,icalproperty_new_priority( 336 icalcomponent_add_property(parent,icalproperty_new_priority(
340 incidence->priority())); 337 incidence->priority()));
341 338
342 // categories 339 // categories
343 QStringList categories = incidence->categories(); 340 QStringList categories = incidence->categories();
344 QStringList::Iterator it; 341 QStringList::Iterator it;
345 for(it = categories.begin(); it != categories.end(); ++it ) { 342 for(it = categories.begin(); it != categories.end(); ++it ) {
346 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); 343 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
347 } 344 }
348// TODO: Ensure correct concatenation of categories properties. 345// TODO: Ensure correct concatenation of categories properties.
349 346
350/* 347/*
351 // categories 348 // categories
352 tmpStrList = incidence->getCategories(); 349 tmpStrList = incidence->getCategories();
353 tmpStr = ""; 350 tmpStr = "";
354 QString catStr; 351 QString catStr;
355 for ( QStringList::Iterator it = tmpStrList.begin(); 352 for ( QStringList::Iterator it = tmpStrList.begin();
356 it != tmpStrList.end(); 353 it != tmpStrList.end();
357 ++it ) { 354 ++it ) {
358 catStr = *it; 355 catStr = *it;
359 if (catStr[0] == ' ') 356 if (catStr[0] == ' ')
360 tmpStr += catStr.mid(1); 357 tmpStr += catStr.mid(1);
361 else 358 else
362 tmpStr += catStr; 359 tmpStr += catStr;
363 // this must be a ';' character as the vCalendar specification requires! 360 // this must be a ';' character as the vCalendar specification requires!
364 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 361 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
365 // read in. 362 // read in.
366 tmpStr += ";"; 363 tmpStr += ";";
367 } 364 }
368 if (!tmpStr.isEmpty()) { 365 if (!tmpStr.isEmpty()) {
369 tmpStr.truncate(tmpStr.length()-1); 366 tmpStr.truncate(tmpStr.length()-1);
370 icalcomponent_add_property(parent,icalproperty_new_categories( 367 icalcomponent_add_property(parent,icalproperty_new_categories(
371 writeText(incidence->getCategories().join(";")))); 368 writeText(incidence->getCategories().join(";"))));
372 } 369 }
373*/ 370*/
374 371
375 // related event 372 // related event
376 if (incidence->relatedTo()) { 373 if (incidence->relatedTo()) {
377 icalcomponent_add_property(parent,icalproperty_new_relatedto( 374 icalcomponent_add_property(parent,icalproperty_new_relatedto(
378 incidence->relatedTo()->uid().utf8())); 375 incidence->relatedTo()->uid().utf8()));
379 } 376 }
380 377
381 // recurrence rule stuff 378 // recurrence rule stuff
382 Recurrence *recur = incidence->recurrence(); 379 Recurrence *recur = incidence->recurrence();
383 if (recur->doesRecur()) { 380 if (recur->doesRecur()) {
384 381
385 icalcomponent_add_property(parent,writeRecurrenceRule(recur)); 382 icalcomponent_add_property(parent,writeRecurrenceRule(recur));
386 } 383 }
387 384
388 // recurrence excpetion dates 385 // recurrence excpetion dates
389 DateList dateList = incidence->exDates(); 386 DateList dateList = incidence->exDates();
390 DateList::ConstIterator exIt; 387 DateList::ConstIterator exIt;
391 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { 388 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
392 icalcomponent_add_property(parent,icalproperty_new_exdate( 389 icalcomponent_add_property(parent,icalproperty_new_exdate(
393 writeICalDate(*exIt))); 390 writeICalDate(*exIt)));
394 } 391 }
395 392
396 // attachments 393 // attachments
397 QPtrList<Attachment> attachments = incidence->attachments(); 394 QPtrList<Attachment> attachments = incidence->attachments();
398 for (Attachment *at = attachments.first(); at; at = attachments.next()) 395 for (Attachment *at = attachments.first(); at; at = attachments.next())
399 icalcomponent_add_property(parent,writeAttachment(at)); 396 icalcomponent_add_property(parent,writeAttachment(at));
400 397
401 // alarms 398 // alarms
402 QPtrList<Alarm> alarms = incidence->alarms(); 399 QPtrList<Alarm> alarms = incidence->alarms();
403 Alarm* alarm; 400 Alarm* alarm;
404 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 401 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
405 if (alarm->enabled()) { 402 if (alarm->enabled()) {
406 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; 403 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl;
407 icalcomponent_add_component(parent,writeAlarm(alarm)); 404 icalcomponent_add_component(parent,writeAlarm(alarm));
408 } 405 }
409 } 406 }
410 407
411 // duration 408 // duration
412 409
413// turned off as it always is set to PTS0 (and must not occur together with DTEND 410// turned off as it always is set to PTS0 (and must not occur together with DTEND
414 411
415// if (incidence->hasDuration()) { 412// if (incidence->hasDuration()) {
416// icaldurationtype duration; 413// icaldurationtype duration;
417// duration = writeICalDuration(incidence->duration()); 414// duration = writeICalDuration(incidence->duration());
418// icalcomponent_add_property(parent,icalproperty_new_duration(duration)); 415// icalcomponent_add_property(parent,icalproperty_new_duration(duration));
419// } 416// }
420} 417}
421 418
422void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 419void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
423{ 420{
424 icalcomponent_add_property(parent,icalproperty_new_dtstamp( 421 icalcomponent_add_property(parent,icalproperty_new_dtstamp(
425 writeICalDateTime(QDateTime::currentDateTime()))); 422 writeICalDateTime(QDateTime::currentDateTime())));
426 423
427 // organizer stuff 424 // organizer stuff
428 icalcomponent_add_property(parent,icalproperty_new_organizer( 425 icalcomponent_add_property(parent,icalproperty_new_organizer(
429 ("MAILTO:" + incidenceBase->organizer()).utf8())); 426 ("MAILTO:" + incidenceBase->organizer()).utf8()));
430 427
431 // attendees 428 // attendees
432 if (incidenceBase->attendeeCount() != 0) { 429 if (incidenceBase->attendeeCount() != 0) {
433 QPtrList<Attendee> al = incidenceBase->attendees(); 430 QPtrList<Attendee> al = incidenceBase->attendees();
434 QPtrListIterator<Attendee> ai(al); 431 QPtrListIterator<Attendee> ai(al);
435 for (; ai.current(); ++ai) { 432 for (; ai.current(); ++ai) {
436 icalcomponent_add_property(parent,writeAttendee(ai.current())); 433 icalcomponent_add_property(parent,writeAttendee(ai.current()));
437 } 434 }
438 } 435 }
439 436
440 // custom properties 437 // custom properties
441 writeCustomProperties(parent, incidenceBase); 438 writeCustomProperties(parent, incidenceBase);
442} 439}
443 440
444void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) 441void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties)
445{ 442{
446 QMap<QCString, QString> custom = properties->customProperties(); 443 QMap<QCString, QString> custom = properties->customProperties();
447 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 444 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
448 icalproperty *p = icalproperty_new_x(c.data().utf8()); 445 icalproperty *p = icalproperty_new_x(c.data().utf8());
449 icalproperty_set_x_name(p,c.key()); 446 icalproperty_set_x_name(p,c.key());
450 icalcomponent_add_property(parent,p); 447 icalcomponent_add_property(parent,p);
451 } 448 }
452} 449}
453 450
454icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) 451icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee)
455{ 452{
456 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); 453 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8());
457 454
458 if (!attendee->name().isEmpty()) { 455 if (!attendee->name().isEmpty()) {
459 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); 456 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
460 } 457 }
461 458
462 459
463 icalproperty_add_parameter(p,icalparameter_new_rsvp( 460 icalproperty_add_parameter(p,icalparameter_new_rsvp(
464 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); 461 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
465 462
466 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; 463 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
467 switch (attendee->status()) { 464 switch (attendee->status()) {
468 default: 465 default:
469 case Attendee::NeedsAction: 466 case Attendee::NeedsAction:
470 status = ICAL_PARTSTAT_NEEDSACTION; 467 status = ICAL_PARTSTAT_NEEDSACTION;
471 break; 468 break;
472 case Attendee::Accepted: 469 case Attendee::Accepted:
473 status = ICAL_PARTSTAT_ACCEPTED; 470 status = ICAL_PARTSTAT_ACCEPTED;
474 break; 471 break;
475 case Attendee::Declined: 472 case Attendee::Declined:
476 status = ICAL_PARTSTAT_DECLINED; 473 status = ICAL_PARTSTAT_DECLINED;
477 break; 474 break;
478 case Attendee::Tentative: 475 case Attendee::Tentative:
479 status = ICAL_PARTSTAT_TENTATIVE; 476 status = ICAL_PARTSTAT_TENTATIVE;
480 break; 477 break;
481 case Attendee::Delegated: 478 case Attendee::Delegated:
482 status = ICAL_PARTSTAT_DELEGATED; 479 status = ICAL_PARTSTAT_DELEGATED;
483 break; 480 break;
484 case Attendee::Completed: 481 case Attendee::Completed:
485 status = ICAL_PARTSTAT_COMPLETED; 482 status = ICAL_PARTSTAT_COMPLETED;
486 break; 483 break;
487 case Attendee::InProcess: 484 case Attendee::InProcess:
488 status = ICAL_PARTSTAT_INPROCESS; 485 status = ICAL_PARTSTAT_INPROCESS;
489 break; 486 break;
490 } 487 }
491 icalproperty_add_parameter(p,icalparameter_new_partstat(status)); 488 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
492 489
493 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; 490 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
494 switch (attendee->role()) { 491 switch (attendee->role()) {
495 case Attendee::Chair: 492 case Attendee::Chair:
496 role = ICAL_ROLE_CHAIR; 493 role = ICAL_ROLE_CHAIR;
497 break; 494 break;
498 default: 495 default:
499 case Attendee::ReqParticipant: 496 case Attendee::ReqParticipant:
500 role = ICAL_ROLE_REQPARTICIPANT; 497 role = ICAL_ROLE_REQPARTICIPANT;
501 break; 498 break;
502 case Attendee::OptParticipant: 499 case Attendee::OptParticipant:
503 role = ICAL_ROLE_OPTPARTICIPANT; 500 role = ICAL_ROLE_OPTPARTICIPANT;
504 break; 501 break;
505 case Attendee::NonParticipant: 502 case Attendee::NonParticipant:
506 role = ICAL_ROLE_NONPARTICIPANT; 503 role = ICAL_ROLE_NONPARTICIPANT;
507 break; 504 break;
508 } 505 }
509 icalproperty_add_parameter(p,icalparameter_new_role(role)); 506 icalproperty_add_parameter(p,icalparameter_new_role(role));
510 507
511 if (!attendee->uid().isEmpty()) { 508 if (!attendee->uid().isEmpty()) {
512 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); 509 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8());
513 icalparameter_set_xname(icalparameter_uid,"X-UID"); 510 icalparameter_set_xname(icalparameter_uid,"X-UID");
514 icalproperty_add_parameter(p,icalparameter_uid); 511 icalproperty_add_parameter(p,icalparameter_uid);
515 } 512 }
516 513
517 return p; 514 return p;
518} 515}
519 516
520icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) 517icalproperty *ICalFormatImpl::writeAttachment(Attachment *att)
521{ 518{
522#if 0 519#if 0
523 icalattachtype* attach = icalattachtype_new(); 520 icalattachtype* attach = icalattachtype_new();
524 if (att->isURI()) 521 if (att->isURI())
525 icalattachtype_set_url(attach, att->uri().utf8().data()); 522 icalattachtype_set_url(attach, att->uri().utf8().data());
526 else 523 else
527 icalattachtype_set_base64(attach, att->data(), 0); 524 icalattachtype_set_base64(attach, att->data(), 0);
528#endif 525#endif
529 icalattach *attach; 526 icalattach *attach;
530 if (att->isURI()) 527 if (att->isURI())
531 attach = icalattach_new_from_url( att->uri().utf8().data()); 528 attach = icalattach_new_from_url( att->uri().utf8().data());
532 else 529 else
@@ -1027,520 +1024,517 @@ Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1027 return journal; 1024 return journal;
1028} 1025}
1029 1026
1030Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) 1027Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1031{ 1028{
1032 icalparameter *p = 0; 1029 icalparameter *p = 0;
1033 1030
1034 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); 1031 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
1035 1032
1036 QString name; 1033 QString name;
1037 QString uid = QString::null; 1034 QString uid = QString::null;
1038 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); 1035 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1039 if (p) { 1036 if (p) {
1040 name = QString::fromUtf8(icalparameter_get_cn(p)); 1037 name = QString::fromUtf8(icalparameter_get_cn(p));
1041 } else { 1038 } else {
1042 } 1039 }
1043 1040
1044 bool rsvp=false; 1041 bool rsvp=false;
1045 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); 1042 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1046 if (p) { 1043 if (p) {
1047 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); 1044 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1048 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; 1045 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true;
1049 } 1046 }
1050 1047
1051 Attendee::PartStat status = Attendee::NeedsAction; 1048 Attendee::PartStat status = Attendee::NeedsAction;
1052 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); 1049 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1053 if (p) { 1050 if (p) {
1054 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); 1051 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1055 switch(partStatParameter) { 1052 switch(partStatParameter) {
1056 default: 1053 default:
1057 case ICAL_PARTSTAT_NEEDSACTION: 1054 case ICAL_PARTSTAT_NEEDSACTION:
1058 status = Attendee::NeedsAction; 1055 status = Attendee::NeedsAction;
1059 break; 1056 break;
1060 case ICAL_PARTSTAT_ACCEPTED: 1057 case ICAL_PARTSTAT_ACCEPTED:
1061 status = Attendee::Accepted; 1058 status = Attendee::Accepted;
1062 break; 1059 break;
1063 case ICAL_PARTSTAT_DECLINED: 1060 case ICAL_PARTSTAT_DECLINED:
1064 status = Attendee::Declined; 1061 status = Attendee::Declined;
1065 break; 1062 break;
1066 case ICAL_PARTSTAT_TENTATIVE: 1063 case ICAL_PARTSTAT_TENTATIVE:
1067 status = Attendee::Tentative; 1064 status = Attendee::Tentative;
1068 break; 1065 break;
1069 case ICAL_PARTSTAT_DELEGATED: 1066 case ICAL_PARTSTAT_DELEGATED:
1070 status = Attendee::Delegated; 1067 status = Attendee::Delegated;
1071 break; 1068 break;
1072 case ICAL_PARTSTAT_COMPLETED: 1069 case ICAL_PARTSTAT_COMPLETED:
1073 status = Attendee::Completed; 1070 status = Attendee::Completed;
1074 break; 1071 break;
1075 case ICAL_PARTSTAT_INPROCESS: 1072 case ICAL_PARTSTAT_INPROCESS:
1076 status = Attendee::InProcess; 1073 status = Attendee::InProcess;
1077 break; 1074 break;
1078 } 1075 }
1079 } 1076 }
1080 1077
1081 Attendee::Role role = Attendee::ReqParticipant; 1078 Attendee::Role role = Attendee::ReqParticipant;
1082 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); 1079 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1083 if (p) { 1080 if (p) {
1084 icalparameter_role roleParameter = icalparameter_get_role(p); 1081 icalparameter_role roleParameter = icalparameter_get_role(p);
1085 switch(roleParameter) { 1082 switch(roleParameter) {
1086 case ICAL_ROLE_CHAIR: 1083 case ICAL_ROLE_CHAIR:
1087 role = Attendee::Chair; 1084 role = Attendee::Chair;
1088 break; 1085 break;
1089 default: 1086 default:
1090 case ICAL_ROLE_REQPARTICIPANT: 1087 case ICAL_ROLE_REQPARTICIPANT:
1091 role = Attendee::ReqParticipant; 1088 role = Attendee::ReqParticipant;
1092 break; 1089 break;
1093 case ICAL_ROLE_OPTPARTICIPANT: 1090 case ICAL_ROLE_OPTPARTICIPANT:
1094 role = Attendee::OptParticipant; 1091 role = Attendee::OptParticipant;
1095 break; 1092 break;
1096 case ICAL_ROLE_NONPARTICIPANT: 1093 case ICAL_ROLE_NONPARTICIPANT:
1097 role = Attendee::NonParticipant; 1094 role = Attendee::NonParticipant;
1098 break; 1095 break;
1099 } 1096 }
1100 } 1097 }
1101 1098
1102 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); 1099 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1103 uid = icalparameter_get_xvalue(p); 1100 uid = icalparameter_get_xvalue(p);
1104 // This should be added, but there seems to be a libical bug here. 1101 // This should be added, but there seems to be a libical bug here.
1105 /*while (p) { 1102 /*while (p) {
1106 // if (icalparameter_get_xname(p) == "X-UID") { 1103 // if (icalparameter_get_xname(p) == "X-UID") {
1107 uid = icalparameter_get_xvalue(p); 1104 uid = icalparameter_get_xvalue(p);
1108 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); 1105 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER);
1109 } */ 1106 } */
1110 1107
1111 return new Attendee( name, email, rsvp, status, role, uid ); 1108 return new Attendee( name, email, rsvp, status, role, uid );
1112} 1109}
1113 1110
1114Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) 1111Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1115{ 1112{
1116 icalattach *a = icalproperty_get_attach(attach); 1113 icalattach *a = icalproperty_get_attach(attach);
1117 icalparameter_value v = ICAL_VALUE_NONE; 1114 icalparameter_value v = ICAL_VALUE_NONE;
1118 icalparameter_encoding e = ICAL_ENCODING_NONE; 1115 icalparameter_encoding e = ICAL_ENCODING_NONE;
1119 1116
1120 Attachment *attachment = 0; 1117 Attachment *attachment = 0;
1121 /* 1118 /*
1122 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); 1119 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER);
1123 if (vp) 1120 if (vp)
1124 v = icalparameter_get_value(vp); 1121 v = icalparameter_get_value(vp);
1125 1122
1126 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); 1123 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER);
1127 if (ep) 1124 if (ep)
1128 e = icalparameter_get_encoding(ep); 1125 e = icalparameter_get_encoding(ep);
1129 */ 1126 */
1130 int isurl = icalattach_get_is_url (a); 1127 int isurl = icalattach_get_is_url (a);
1131 if (isurl == 0) 1128 if (isurl == 0)
1132 attachment = new Attachment((const char*)icalattach_get_data(a)); 1129 attachment = new Attachment((const char*)icalattach_get_data(a));
1133 else { 1130 else {
1134 attachment = new Attachment(QString(icalattach_get_url(a))); 1131 attachment = new Attachment(QString(icalattach_get_url(a)));
1135 } 1132 }
1136 1133
1137 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); 1134 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
1138 if (p) 1135 if (p)
1139 attachment->setMimeType(QString(icalparameter_get_fmttype(p))); 1136 attachment->setMimeType(QString(icalparameter_get_fmttype(p)));
1140 1137
1141 return attachment; 1138 return attachment;
1142} 1139}
1143#include <qtextcodec.h> 1140#include <qtextcodec.h>
1144void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) 1141void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1145{ 1142{
1146 readIncidenceBase(parent,incidence); 1143 readIncidenceBase(parent,incidence);
1147 1144
1148 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1145 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1149 bool readrec = false; 1146 bool readrec = false;
1150 const char *text; 1147 const char *text;
1151 int intvalue; 1148 int intvalue;
1152 icaltimetype icaltime; 1149 icaltimetype icaltime;
1153 icaldurationtype icalduration; 1150 icaldurationtype icalduration;
1154 struct icalrecurrencetype rectype; 1151 struct icalrecurrencetype rectype;
1155 QStringList categories; 1152 QStringList categories;
1156 1153
1157 while (p) { 1154 while (p) {
1158 icalproperty_kind kind = icalproperty_isa(p); 1155 icalproperty_kind kind = icalproperty_isa(p);
1159 switch (kind) { 1156 switch (kind) {
1160 1157
1161 case ICAL_CREATED_PROPERTY: 1158 case ICAL_CREATED_PROPERTY:
1162 icaltime = icalproperty_get_created(p); 1159 icaltime = icalproperty_get_created(p);
1163 incidence->setCreated(readICalDateTime(icaltime)); 1160 incidence->setCreated(readICalDateTime(icaltime));
1164 break; 1161 break;
1165 1162
1166 case ICAL_SEQUENCE_PROPERTY: // sequence 1163 case ICAL_SEQUENCE_PROPERTY: // sequence
1167 intvalue = icalproperty_get_sequence(p); 1164 intvalue = icalproperty_get_sequence(p);
1168 incidence->setRevision(intvalue); 1165 incidence->setRevision(intvalue);
1169 break; 1166 break;
1170 1167
1171 case ICAL_LASTMODIFIED_PROPERTY: // last modification date 1168 case ICAL_LASTMODIFIED_PROPERTY: // last modification date
1172 icaltime = icalproperty_get_lastmodified(p); 1169 icaltime = icalproperty_get_lastmodified(p);
1173 incidence->setLastModified(readICalDateTime(icaltime)); 1170 incidence->setLastModified(readICalDateTime(icaltime));
1174 break; 1171 break;
1175 1172
1176 case ICAL_DTSTART_PROPERTY: // start date and time 1173 case ICAL_DTSTART_PROPERTY: // start date and time
1177 icaltime = icalproperty_get_dtstart(p); 1174 icaltime = icalproperty_get_dtstart(p);
1178 if (icaltime.is_date) { 1175 if (icaltime.is_date) {
1179 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 1176 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
1180 incidence->setFloats(true); 1177 incidence->setFloats(true);
1181 } else { 1178 } else {
1182 incidence->setDtStart(readICalDateTime(icaltime)); 1179 incidence->setDtStart(readICalDateTime(icaltime));
1183 } 1180 }
1184 break; 1181 break;
1185 1182
1186 case ICAL_DURATION_PROPERTY: // start date and time 1183 case ICAL_DURATION_PROPERTY: // start date and time
1187 icalduration = icalproperty_get_duration(p); 1184 icalduration = icalproperty_get_duration(p);
1188 incidence->setDuration(readICalDuration(icalduration)); 1185 incidence->setDuration(readICalDuration(icalduration));
1189 break; 1186 break;
1190 1187
1191 case ICAL_DESCRIPTION_PROPERTY: // description 1188 case ICAL_DESCRIPTION_PROPERTY: // description
1192 text = icalproperty_get_description(p); 1189 text = icalproperty_get_description(p);
1193 incidence->setDescription(QString::fromUtf8(text)); 1190 incidence->setDescription(QString::fromUtf8(text));
1194 break; 1191 break;
1195 1192
1196 case ICAL_SUMMARY_PROPERTY: // summary 1193 case ICAL_SUMMARY_PROPERTY: // summary
1197 { 1194 {
1198 text = icalproperty_get_summary(p); 1195 text = icalproperty_get_summary(p);
1199 incidence->setSummary(QString::fromUtf8(text)); 1196 incidence->setSummary(QString::fromUtf8(text));
1200 } 1197 }
1201 break; 1198 break;
1202 case ICAL_STATUS_PROPERTY: // summary 1199 case ICAL_STATUS_PROPERTY: // summary
1203 { 1200 {
1204 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) 1201 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
1205 incidence->setCancelled( true ); 1202 incidence->setCancelled( true );
1206 } 1203 }
1207 break; 1204 break;
1208 1205
1209 case ICAL_LOCATION_PROPERTY: // location 1206 case ICAL_LOCATION_PROPERTY: // location
1210 text = icalproperty_get_location(p); 1207 text = icalproperty_get_location(p);
1211 incidence->setLocation(QString::fromUtf8(text)); 1208 incidence->setLocation(QString::fromUtf8(text));
1212 break; 1209 break;
1213 1210
1214#if 0 1211#if 0
1215 // status 1212 // status
1216 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { 1213 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
1217 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); 1214 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
1218 deleteStr(s); 1215 deleteStr(s);
1219 } 1216 }
1220 else 1217 else
1221 incidence->setStatus("NEEDS ACTION"); 1218 incidence->setStatus("NEEDS ACTION");
1222#endif 1219#endif
1223 1220
1224 case ICAL_PRIORITY_PROPERTY: // priority 1221 case ICAL_PRIORITY_PROPERTY: // priority
1225 intvalue = icalproperty_get_priority(p); 1222 intvalue = icalproperty_get_priority(p);
1226 incidence->setPriority(intvalue); 1223 incidence->setPriority(intvalue);
1227 break; 1224 break;
1228 1225
1229 case ICAL_CATEGORIES_PROPERTY: // categories 1226 case ICAL_CATEGORIES_PROPERTY: // categories
1230 text = icalproperty_get_categories(p); 1227 text = icalproperty_get_categories(p);
1231 categories.append(QString::fromUtf8(text)); 1228 categories.append(QString::fromUtf8(text));
1232 break; 1229 break;
1233 //******************************************* 1230 //*******************************************
1234 case ICAL_RRULE_PROPERTY: 1231 case ICAL_RRULE_PROPERTY:
1235 // we do need (maybe )start datetime of incidence for recurrence 1232 // we do need (maybe )start datetime of incidence for recurrence
1236 // such that we can read recurrence only after we read incidence completely 1233 // such that we can read recurrence only after we read incidence completely
1237 readrec = true; 1234 readrec = true;
1238 rectype = icalproperty_get_rrule(p); 1235 rectype = icalproperty_get_rrule(p);
1239 break; 1236 break;
1240 1237
1241 case ICAL_EXDATE_PROPERTY: 1238 case ICAL_EXDATE_PROPERTY:
1242 icaltime = icalproperty_get_exdate(p); 1239 icaltime = icalproperty_get_exdate(p);
1243 incidence->addExDate(readICalDate(icaltime)); 1240 incidence->addExDate(readICalDate(icaltime));
1244 break; 1241 break;
1245 1242
1246 case ICAL_CLASS_PROPERTY: { 1243 case ICAL_CLASS_PROPERTY: {
1247 int inttext = icalproperty_get_class(p); 1244 int inttext = icalproperty_get_class(p);
1248 if (inttext == ICAL_CLASS_PUBLIC ) { 1245 if (inttext == ICAL_CLASS_PUBLIC ) {
1249 incidence->setSecrecy(Incidence::SecrecyPublic); 1246 incidence->setSecrecy(Incidence::SecrecyPublic);
1250 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { 1247 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1251 incidence->setSecrecy(Incidence::SecrecyConfidential); 1248 incidence->setSecrecy(Incidence::SecrecyConfidential);
1252 } else { 1249 } else {
1253 incidence->setSecrecy(Incidence::SecrecyPrivate); 1250 incidence->setSecrecy(Incidence::SecrecyPrivate);
1254 } 1251 }
1255 } 1252 }
1256 break; 1253 break;
1257 1254
1258 case ICAL_ATTACH_PROPERTY: // attachments 1255 case ICAL_ATTACH_PROPERTY: // attachments
1259 incidence->addAttachment(readAttachment(p)); 1256 incidence->addAttachment(readAttachment(p));
1260 break; 1257 break;
1261 1258
1262 default: 1259 default:
1263// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1260// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1264// << endl; 1261// << endl;
1265 break; 1262 break;
1266 } 1263 }
1267 1264
1268 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1265 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1269 } 1266 }
1270 if ( readrec ) { 1267 if ( readrec ) {
1271 readRecurrenceRule(rectype,incidence); 1268 readRecurrenceRule(rectype,incidence);
1272 } 1269 }
1273 // kpilot stuff 1270 // kpilot stuff
1274// TODO: move this application-specific code to kpilot 1271// TODO: move this application-specific code to kpilot
1275 QString kp = incidence->nonKDECustomProperty("X-PILOTID"); 1272 QString kp = incidence->nonKDECustomProperty("X-PILOTID");
1276 if (!kp.isNull()) { 1273 if (!kp.isNull()) {
1277 incidence->setPilotId(kp.toInt()); 1274 incidence->setPilotId(kp.toInt());
1278 } 1275 }
1279 kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); 1276 kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
1280 if (!kp.isNull()) { 1277 if (!kp.isNull()) {
1281 incidence->setSyncStatus(kp.toInt()); 1278 incidence->setSyncStatus(kp.toInt());
1282 } 1279 }
1283 kp = incidence->nonKDECustomProperty("X-ZAURUSID");
1284 if (!kp.isNull()) {
1285 incidence->setZaurusId(kp.toInt());
1286 }
1287 1280
1288 kp = incidence->nonKDECustomProperty("X-ZAURUSUID"); 1281
1282 kp = incidence->nonKDECustomProperty("X-KOPIEXTID");
1289 if (!kp.isNull()) { 1283 if (!kp.isNull()) {
1290 incidence->setZaurusUid(kp.toInt()); 1284 incidence->setIDStr(kp);
1291 } 1285 }
1292 1286
1293 // Cancel backwards compatibility mode for subsequent changes by the application 1287 // Cancel backwards compatibility mode for subsequent changes by the application
1294 incidence->recurrence()->setCompatVersion(); 1288 incidence->recurrence()->setCompatVersion();
1295 1289
1296 // add categories 1290 // add categories
1297 incidence->setCategories(categories); 1291 incidence->setCategories(categories);
1298 1292
1299 // iterate through all alarms 1293 // iterate through all alarms
1300 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); 1294 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1301 alarm; 1295 alarm;
1302 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { 1296 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1303 readAlarm(alarm,incidence); 1297 readAlarm(alarm,incidence);
1304 } 1298 }
1305} 1299}
1306 1300
1307void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 1301void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
1308{ 1302{
1309 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1303 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1310 1304
1311 while (p) { 1305 while (p) {
1312 icalproperty_kind kind = icalproperty_isa(p); 1306 icalproperty_kind kind = icalproperty_isa(p);
1313 switch (kind) { 1307 switch (kind) {
1314 1308
1315 case ICAL_UID_PROPERTY: // unique id 1309 case ICAL_UID_PROPERTY: // unique id
1316 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); 1310 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
1317 break; 1311 break;
1318 1312
1319 case ICAL_ORGANIZER_PROPERTY: // organizer 1313 case ICAL_ORGANIZER_PROPERTY: // organizer
1320 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); 1314 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
1321 break; 1315 break;
1322 1316
1323 case ICAL_ATTENDEE_PROPERTY: // attendee 1317 case ICAL_ATTENDEE_PROPERTY: // attendee
1324 incidenceBase->addAttendee(readAttendee(p)); 1318 incidenceBase->addAttendee(readAttendee(p));
1325 break; 1319 break;
1326 1320
1327 default: 1321 default:
1328 break; 1322 break;
1329 } 1323 }
1330 1324
1331 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1325 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1332 } 1326 }
1333 1327
1334 // custom properties 1328 // custom properties
1335 readCustomProperties(parent, incidenceBase); 1329 readCustomProperties(parent, incidenceBase);
1336} 1330}
1337 1331
1338void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1332void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1339{ 1333{
1340 QMap<QCString, QString> customProperties; 1334 QMap<QCString, QString> customProperties;
1341 1335
1342 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1336 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1343 1337
1344 while (p) { 1338 while (p) {
1345 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1339 QString value = QString::fromUtf8(icalproperty_get_x(p));
1346 customProperties[icalproperty_get_x_name(p)] = value; 1340 customProperties[icalproperty_get_x_name(p)] = value;
1347 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); 1341 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1348 1342
1349 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1343 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1350 } 1344 }
1351 1345
1352 properties->setCustomProperties(customProperties); 1346 properties->setCustomProperties(customProperties);
1353} 1347}
1354 1348
1355void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1349void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1356{ 1350{
1357// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; 1351// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
1358 1352
1359 Recurrence *recur = incidence->recurrence(); 1353 Recurrence *recur = incidence->recurrence();
1360 recur->setCompatVersion(mCalendarVersion); 1354 recur->setCompatVersion(mCalendarVersion);
1361 recur->unsetRecurs(); 1355 recur->unsetRecurs();
1362 1356
1363 struct icalrecurrencetype r = rrule; 1357 struct icalrecurrencetype r = rrule;
1364 1358
1365 dumpIcalRecurrence(r); 1359 dumpIcalRecurrence(r);
1366 readRecurrence( r, recur, incidence); 1360 readRecurrence( r, recur, incidence);
1367} 1361}
1368 1362
1369void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1363void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1370{ 1364{
1371 int wkst; 1365 int wkst;
1372 int index = 0; 1366 int index = 0;
1373 short day = 0; 1367 short day = 0;
1374 QBitArray qba(7); 1368 QBitArray qba(7);
1375 int frequ = r.freq; 1369 int frequ = r.freq;
1376 int interv = r.interval; 1370 int interv = r.interval;
1377 // preprocessing for odd recurrence definitions 1371 // preprocessing for odd recurrence definitions
1378 1372
1379 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1373 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1380 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1374 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1381 interv = 12; 1375 interv = 12;
1382 } 1376 }
1383 } 1377 }
1384 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1378 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1385 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1379 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1386 frequ = ICAL_MONTHLY_RECURRENCE; 1380 frequ = ICAL_MONTHLY_RECURRENCE;
1387 interv = 12* r.interval; 1381 interv = 12* r.interval;
1388 } 1382 }
1389 } 1383 }
1390 1384
1391 switch (frequ) { 1385 switch (frequ) {
1392 case ICAL_MINUTELY_RECURRENCE: 1386 case ICAL_MINUTELY_RECURRENCE:
1393 if (!icaltime_is_null_time(r.until)) { 1387 if (!icaltime_is_null_time(r.until)) {
1394 recur->setMinutely(interv,readICalDateTime(r.until)); 1388 recur->setMinutely(interv,readICalDateTime(r.until));
1395 } else { 1389 } else {
1396 if (r.count == 0) 1390 if (r.count == 0)
1397 recur->setMinutely(interv,-1); 1391 recur->setMinutely(interv,-1);
1398 else 1392 else
1399 recur->setMinutely(interv,r.count); 1393 recur->setMinutely(interv,r.count);
1400 } 1394 }
1401 break; 1395 break;
1402 case ICAL_HOURLY_RECURRENCE: 1396 case ICAL_HOURLY_RECURRENCE:
1403 if (!icaltime_is_null_time(r.until)) { 1397 if (!icaltime_is_null_time(r.until)) {
1404 recur->setHourly(interv,readICalDateTime(r.until)); 1398 recur->setHourly(interv,readICalDateTime(r.until));
1405 } else { 1399 } else {
1406 if (r.count == 0) 1400 if (r.count == 0)
1407 recur->setHourly(interv,-1); 1401 recur->setHourly(interv,-1);
1408 else 1402 else
1409 recur->setHourly(interv,r.count); 1403 recur->setHourly(interv,r.count);
1410 } 1404 }
1411 break; 1405 break;
1412 case ICAL_DAILY_RECURRENCE: 1406 case ICAL_DAILY_RECURRENCE:
1413 if (!icaltime_is_null_time(r.until)) { 1407 if (!icaltime_is_null_time(r.until)) {
1414 recur->setDaily(interv,readICalDate(r.until)); 1408 recur->setDaily(interv,readICalDate(r.until));
1415 } else { 1409 } else {
1416 if (r.count == 0) 1410 if (r.count == 0)
1417 recur->setDaily(interv,-1); 1411 recur->setDaily(interv,-1);
1418 else 1412 else
1419 recur->setDaily(interv,r.count); 1413 recur->setDaily(interv,r.count);
1420 } 1414 }
1421 break; 1415 break;
1422 case ICAL_WEEKLY_RECURRENCE: 1416 case ICAL_WEEKLY_RECURRENCE:
1423 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; 1417 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl;
1424 wkst = (r.week_start + 5)%7 + 1; 1418 wkst = (r.week_start + 5)%7 + 1;
1425 if (!icaltime_is_null_time(r.until)) { 1419 if (!icaltime_is_null_time(r.until)) {
1426 recur->setWeekly(interv,qba,readICalDate(r.until),wkst); 1420 recur->setWeekly(interv,qba,readICalDate(r.until),wkst);
1427 } else { 1421 } else {
1428 if (r.count == 0) 1422 if (r.count == 0)
1429 recur->setWeekly(interv,qba,-1,wkst); 1423 recur->setWeekly(interv,qba,-1,wkst);
1430 else 1424 else
1431 recur->setWeekly(interv,qba,r.count,wkst); 1425 recur->setWeekly(interv,qba,r.count,wkst);
1432 } 1426 }
1433 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { 1427 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) {
1434 int wday = incidence->dtStart().date().dayOfWeek ()-1; 1428 int wday = incidence->dtStart().date().dayOfWeek ()-1;
1435 //qDebug("weekly error found "); 1429 //qDebug("weekly error found ");
1436 qba.setBit(wday); 1430 qba.setBit(wday);
1437 } else { 1431 } else {
1438 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1432 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1439 // kdDebug(5800) << " " << day << endl; 1433 // kdDebug(5800) << " " << day << endl;
1440 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1434 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1441 } 1435 }
1442 } 1436 }
1443 break; 1437 break;
1444 case ICAL_MONTHLY_RECURRENCE: 1438 case ICAL_MONTHLY_RECURRENCE:
1445 1439
1446 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1440 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1447 if (!icaltime_is_null_time(r.until)) { 1441 if (!icaltime_is_null_time(r.until)) {
1448 recur->setMonthly(Recurrence::rMonthlyPos,interv, 1442 recur->setMonthly(Recurrence::rMonthlyPos,interv,
1449 readICalDate(r.until)); 1443 readICalDate(r.until));
1450 } else { 1444 } else {
1451 if (r.count == 0) 1445 if (r.count == 0)
1452 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); 1446 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1);
1453 else 1447 else
1454 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); 1448 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count);
1455 } 1449 }
1456 bool useSetPos = false; 1450 bool useSetPos = false;
1457 short pos = 0; 1451 short pos = 0;
1458 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1452 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1459 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1453 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1460 pos = icalrecurrencetype_day_position(day); 1454 pos = icalrecurrencetype_day_position(day);
1461 if (pos) { 1455 if (pos) {
1462 day = icalrecurrencetype_day_day_of_week(day); 1456 day = icalrecurrencetype_day_day_of_week(day);
1463 QBitArray ba(7); // don't wipe qba 1457 QBitArray ba(7); // don't wipe qba
1464 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1458 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1465 recur->addMonthlyPos(pos,ba); 1459 recur->addMonthlyPos(pos,ba);
1466 } else { 1460 } else {
1467 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1461 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1468 useSetPos = true; 1462 useSetPos = true;
1469 } 1463 }
1470 } 1464 }
1471 if (useSetPos) { 1465 if (useSetPos) {
1472 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1466 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1473 recur->addMonthlyPos(r.by_set_pos[0],qba); 1467 recur->addMonthlyPos(r.by_set_pos[0],qba);
1474 } 1468 }
1475 } 1469 }
1476 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1470 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1477 if (!icaltime_is_null_time(r.until)) { 1471 if (!icaltime_is_null_time(r.until)) {
1478 recur->setMonthly(Recurrence::rMonthlyDay,interv, 1472 recur->setMonthly(Recurrence::rMonthlyDay,interv,
1479 readICalDate(r.until)); 1473 readICalDate(r.until));
1480 } else { 1474 } else {
1481 if (r.count == 0) 1475 if (r.count == 0)
1482 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); 1476 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1);
1483 else 1477 else
1484 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); 1478 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count);
1485 } 1479 }
1486 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1480 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1487 // kdDebug(5800) << "----b " << day << endl; 1481 // kdDebug(5800) << "----b " << day << endl;
1488 recur->addMonthlyDay(day); 1482 recur->addMonthlyDay(day);
1489 } 1483 }
1490 } 1484 }
1491 break; 1485 break;
1492 case ICAL_YEARLY_RECURRENCE: 1486 case ICAL_YEARLY_RECURRENCE:
1493 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1487 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1494 //qDebug(" YEARLY DAY OF YEAR"); 1488 //qDebug(" YEARLY DAY OF YEAR");
1495 if (!icaltime_is_null_time(r.until)) { 1489 if (!icaltime_is_null_time(r.until)) {
1496 recur->setYearly(Recurrence::rYearlyDay,interv, 1490 recur->setYearly(Recurrence::rYearlyDay,interv,
1497 readICalDate(r.until)); 1491 readICalDate(r.until));
1498 } else { 1492 } else {
1499 if (r.count == 0) 1493 if (r.count == 0)
1500 recur->setYearly(Recurrence::rYearlyDay,interv,-1); 1494 recur->setYearly(Recurrence::rYearlyDay,interv,-1);
1501 else 1495 else
1502 recur->setYearly(Recurrence::rYearlyDay,interv,r.count); 1496 recur->setYearly(Recurrence::rYearlyDay,interv,r.count);
1503 } 1497 }
1504 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1498 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1505 recur->addYearlyNum(day); 1499 recur->addYearlyNum(day);
1506 } 1500 }
1507 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { 1501 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) {
1508 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1502 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1509 qDebug("YEARLY POS NOT SUPPORTED BY GUI"); 1503 qDebug("YEARLY POS NOT SUPPORTED BY GUI");
1510 if (!icaltime_is_null_time(r.until)) { 1504 if (!icaltime_is_null_time(r.until)) {
1511 recur->setYearly(Recurrence::rYearlyPos,interv, 1505 recur->setYearly(Recurrence::rYearlyPos,interv,
1512 readICalDate(r.until)); 1506 readICalDate(r.until));
1513 } else { 1507 } else {
1514 if (r.count == 0) 1508 if (r.count == 0)
1515 recur->setYearly(Recurrence::rYearlyPos,interv,-1); 1509 recur->setYearly(Recurrence::rYearlyPos,interv,-1);
1516 else 1510 else
1517 recur->setYearly(Recurrence::rYearlyPos,interv,r.count); 1511 recur->setYearly(Recurrence::rYearlyPos,interv,r.count);
1518 } 1512 }
1519 bool useSetPos = false; 1513 bool useSetPos = false;
1520 short pos = 0; 1514 short pos = 0;
1521 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1515 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1522 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1516 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1523 pos = icalrecurrencetype_day_position(day); 1517 pos = icalrecurrencetype_day_position(day);
1524 if (pos) { 1518 if (pos) {
1525 day = icalrecurrencetype_day_day_of_week(day); 1519 day = icalrecurrencetype_day_day_of_week(day);
1526 QBitArray ba(7); // don't wipe qba 1520 QBitArray ba(7); // don't wipe qba
1527 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1521 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1528 recur->addYearlyMonthPos(pos,ba); 1522 recur->addYearlyMonthPos(pos,ba);
1529 } else { 1523 } else {
1530 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1524 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1531 useSetPos = true; 1525 useSetPos = true;
1532 } 1526 }
1533 } 1527 }
1534 if (useSetPos) { 1528 if (useSetPos) {
1535 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1529 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1536 recur->addYearlyMonthPos(r.by_set_pos[0],qba); 1530 recur->addYearlyMonthPos(r.by_set_pos[0],qba);
1537 } 1531 }
1538 } 1532 }
1539 } else { 1533 } else {
1540 //qDebug("YEARLY MONTH "); 1534 //qDebug("YEARLY MONTH ");
1541 if (!icaltime_is_null_time(r.until)) { 1535 if (!icaltime_is_null_time(r.until)) {
1542 recur->setYearly(Recurrence::rYearlyMonth,interv, 1536 recur->setYearly(Recurrence::rYearlyMonth,interv,
1543 readICalDate(r.until)); 1537 readICalDate(r.until));
1544 } else { 1538 } else {
1545 if (r.count == 0) 1539 if (r.count == 0)
1546 recur->setYearly(Recurrence::rYearlyMonth,interv,-1); 1540 recur->setYearly(Recurrence::rYearlyMonth,interv,-1);
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 707d666..d7c4595 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,393 +1,470 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidencebase.h" 27#include "incidencebase.h"
28 28
29using namespace KCal; 29using namespace KCal;
30 30
31IncidenceBase::IncidenceBase() : 31IncidenceBase::IncidenceBase() :
32 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 32 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
33 mPilotId(0), mSyncStatus(SYNCMOD) 33 mPilotId(0), mSyncStatus(SYNCMOD)
34{ 34{
35 setUid(CalFormat::createUniqueId()); 35 setUid(CalFormat::createUniqueId());
36 mOrganizer = ""; 36 mOrganizer = "";
37 mFloats = false; 37 mFloats = false;
38 mDuration = 0; 38 mDuration = 0;
39 mHasDuration = false; 39 mHasDuration = false;
40 mPilotId = 0; 40 mPilotId = 0;
41 mZaurusId = -1; 41 mZaurusId = -1;
42 mZaurusUid = 0; 42 mZaurusUid = 0;
43 mExternalId = ":";
43 mTempSyncStat = 0; 44 mTempSyncStat = 0;
44 mSyncStatus = 0; 45 mSyncStatus = 0;
45 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
46} 47}
47 48
48IncidenceBase::IncidenceBase(const IncidenceBase &i) : 49IncidenceBase::IncidenceBase(const IncidenceBase &i) :
49 CustomProperties( i ) 50 CustomProperties( i )
50{ 51{
51 mReadOnly = i.mReadOnly; 52 mReadOnly = i.mReadOnly;
52 mDtStart = i.mDtStart; 53 mDtStart = i.mDtStart;
53 mDuration = i.mDuration; 54 mDuration = i.mDuration;
54 mHasDuration = i.mHasDuration; 55 mHasDuration = i.mHasDuration;
55 mOrganizer = i.mOrganizer; 56 mOrganizer = i.mOrganizer;
56 mUid = i.mUid; 57 mUid = i.mUid;
57 QPtrList<Attendee> attendees = i.attendees(); 58 QPtrList<Attendee> attendees = i.attendees();
58 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
59 mAttendees.append( new Attendee( *a ) ); 60 mAttendees.append( new Attendee( *a ) );
60 } 61 }
61 mFloats = i.mFloats; 62 mFloats = i.mFloats;
62 mLastModified = i.mLastModified; 63 mLastModified = i.mLastModified;
63 mPilotId = i.mPilotId; 64 mPilotId = i.mPilotId;
64 mZaurusId = i.mZaurusId; 65 mZaurusId = i.mZaurusId;
65 mZaurusUid = i.mZaurusUid; 66 mZaurusUid = i.mZaurusUid;
66 mTempSyncStat = i.mTempSyncStat; 67 mTempSyncStat = i.mTempSyncStat;
67 mSyncStatus = i.mSyncStatus; 68 mSyncStatus = i.mSyncStatus;
68 69 mExternalId = i.mExternalId;
69 // The copied object is a new one, so it isn't observed by the observer 70 // The copied object is a new one, so it isn't observed by the observer
70 // of the original object. 71 // of the original object.
71 mObservers.clear(); 72 mObservers.clear();
72 73
73 mAttendees.setAutoDelete( true ); 74 mAttendees.setAutoDelete( true );
74} 75}
75 76
76IncidenceBase::~IncidenceBase() 77IncidenceBase::~IncidenceBase()
77{ 78{
78} 79}
79 80
80 81
81bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 82bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
82{ 83{
83 84 // do not compare mSyncStatus and mExternalId
84 if( i1.attendees().count() != i2.attendees().count() ) { 85 if( i1.attendees().count() != i2.attendees().count() ) {
85 return false; // no need to check further 86 return false; // no need to check further
86 } 87 }
87 if ( i1.attendees().count() > 0 ) { 88 if ( i1.attendees().count() > 0 ) {
88 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 89 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
89 while ( a1 ) { 90 while ( a1 ) {
90 if ( !( (*a1) == (*a2)) ) 91 if ( !( (*a1) == (*a2)) )
91 { 92 {
92 //qDebug("Attendee not equal "); 93 //qDebug("Attendee not equal ");
93 return false; 94 return false;
94 } 95 }
95 a1 = i1.attendees().next(); 96 a1 = i1.attendees().next();
96 a2 = i2.attendees().next(); 97 a2 = i2.attendees().next();
97 } 98 }
98 } 99 }
99 //if ( i1.dtStart() != i2.dtStart() ) 100 //if ( i1.dtStart() != i2.dtStart() )
100 // return false; 101 // return false;
101#if 0 102#if 0
102 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 103 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
103 qDebug("1 %d ",i1.duration() == i2.duration() ); 104 qDebug("1 %d ",i1.duration() == i2.duration() );
104 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 105 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
105 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 106 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
106 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 107 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
107 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 108 qDebug("6 %d ",i1.organizer() == i2.organizer() );
108 109
109#endif 110#endif
110 return ( i1.organizer() == i2.organizer() && 111 return ( i1.organizer() == i2.organizer() &&
111 // i1.uid() == i2.uid() && 112 // i1.uid() == i2.uid() &&
112 // Don't compare lastModified, otherwise the operator is not 113 // Don't compare lastModified, otherwise the operator is not
113 // of much use. We are not comparing for identity, after all. 114 // of much use. We are not comparing for identity, after all.
114 i1.doesFloat() == i2.doesFloat() && 115 i1.doesFloat() == i2.doesFloat() &&
115 i1.duration() == i2.duration() && 116 i1.duration() == i2.duration() &&
116 i1.hasDuration() == i2.hasDuration() && 117 i1.hasDuration() == i2.hasDuration() &&
117 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 118 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
118 // no need to compare mObserver 119 // no need to compare mObserver
119} 120}
120 121
121 122
122QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 123QDateTime IncidenceBase::getEvenTime( QDateTime dt )
123{ 124{
124 QTime t = dt.time(); 125 QTime t = dt.time();
125 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 126 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
126 return dt; 127 return dt;
127} 128}
128 129
129 130
130void IncidenceBase::setUid(const QString &uid) 131void IncidenceBase::setUid(const QString &uid)
131{ 132{
132 mUid = uid; 133 mUid = uid;
133 updated(); 134 updated();
134} 135}
135 136
136QString IncidenceBase::uid() const 137QString IncidenceBase::uid() const
137{ 138{
138 return mUid; 139 return mUid;
139} 140}
140 141
141void IncidenceBase::setLastModified(const QDateTime &lm) 142void IncidenceBase::setLastModified(const QDateTime &lm)
142{ 143{
143 // DON'T! updated() because we call this from 144 // DON'T! updated() because we call this from
144 // Calendar::updateEvent(). 145 // Calendar::updateEvent().
145 mLastModified = getEvenTime(lm); 146 mLastModified = getEvenTime(lm);
146 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 147 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
147} 148}
148 149
149QDateTime IncidenceBase::lastModified() const 150QDateTime IncidenceBase::lastModified() const
150{ 151{
151 return mLastModified; 152 return mLastModified;
152} 153}
153 154
154void IncidenceBase::setOrganizer(const QString &o) 155void IncidenceBase::setOrganizer(const QString &o)
155{ 156{
156 // we don't check for readonly here, because it is 157 // we don't check for readonly here, because it is
157 // possible that by setting the organizer we are changing 158 // possible that by setting the organizer we are changing
158 // the event's readonly status... 159 // the event's readonly status...
159 mOrganizer = o; 160 mOrganizer = o;
160 if (mOrganizer.left(7).upper() == "MAILTO:") 161 if (mOrganizer.left(7).upper() == "MAILTO:")
161 mOrganizer = mOrganizer.remove(0,7); 162 mOrganizer = mOrganizer.remove(0,7);
162 163
163 updated(); 164 updated();
164} 165}
165 166
166QString IncidenceBase::organizer() const 167QString IncidenceBase::organizer() const
167{ 168{
168 return mOrganizer; 169 return mOrganizer;
169} 170}
170 171
171void IncidenceBase::setReadOnly( bool readOnly ) 172void IncidenceBase::setReadOnly( bool readOnly )
172{ 173{
173 mReadOnly = readOnly; 174 mReadOnly = readOnly;
174} 175}
175 176
176void IncidenceBase::setDtStart(const QDateTime &dtStart) 177void IncidenceBase::setDtStart(const QDateTime &dtStart)
177{ 178{
178// if (mReadOnly) return; 179// if (mReadOnly) return;
179 mDtStart = getEvenTime(dtStart); 180 mDtStart = getEvenTime(dtStart);
180 updated(); 181 updated();
181} 182}
182 183
183QDateTime IncidenceBase::dtStart() const 184QDateTime IncidenceBase::dtStart() const
184{ 185{
185 return mDtStart; 186 return mDtStart;
186} 187}
187 188
188QString IncidenceBase::dtStartTimeStr() const 189QString IncidenceBase::dtStartTimeStr() const
189{ 190{
190 return KGlobal::locale()->formatTime(dtStart().time()); 191 return KGlobal::locale()->formatTime(dtStart().time());
191} 192}
192 193
193QString IncidenceBase::dtStartDateStr(bool shortfmt) const 194QString IncidenceBase::dtStartDateStr(bool shortfmt) const
194{ 195{
195 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 196 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
196} 197}
197 198
198QString IncidenceBase::dtStartStr(bool shortfmt) const 199QString IncidenceBase::dtStartStr(bool shortfmt) const
199{ 200{
200 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 201 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
201} 202}
202 203
203 204
204bool IncidenceBase::doesFloat() const 205bool IncidenceBase::doesFloat() const
205{ 206{
206 return mFloats; 207 return mFloats;
207} 208}
208 209
209void IncidenceBase::setFloats(bool f) 210void IncidenceBase::setFloats(bool f)
210{ 211{
211 if (mReadOnly) return; 212 if (mReadOnly) return;
212 mFloats = f; 213 mFloats = f;
213 updated(); 214 updated();
214} 215}
215 216
216 217
217void IncidenceBase::addAttendee(Attendee *a, bool doupdate) 218void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
218{ 219{
219 if (mReadOnly) return; 220 if (mReadOnly) return;
220 if (a->name().left(7).upper() == "MAILTO:") 221 if (a->name().left(7).upper() == "MAILTO:")
221 a->setName(a->name().remove(0,7)); 222 a->setName(a->name().remove(0,7));
222 223
223 mAttendees.append(a); 224 mAttendees.append(a);
224 if (doupdate) updated(); 225 if (doupdate) updated();
225} 226}
226 227
227#if 0 228#if 0
228void IncidenceBase::removeAttendee(Attendee *a) 229void IncidenceBase::removeAttendee(Attendee *a)
229{ 230{
230 if (mReadOnly) return; 231 if (mReadOnly) return;
231 mAttendees.removeRef(a); 232 mAttendees.removeRef(a);
232 updated(); 233 updated();
233} 234}
234 235
235void IncidenceBase::removeAttendee(const char *n) 236void IncidenceBase::removeAttendee(const char *n)
236{ 237{
237 Attendee *a; 238 Attendee *a;
238 239
239 if (mReadOnly) return; 240 if (mReadOnly) return;
240 for (a = mAttendees.first(); a; a = mAttendees.next()) 241 for (a = mAttendees.first(); a; a = mAttendees.next())
241 if (a->getName() == n) { 242 if (a->getName() == n) {
242 mAttendees.remove(); 243 mAttendees.remove();
243 break; 244 break;
244 } 245 }
245} 246}
246#endif 247#endif
247 248
248void IncidenceBase::clearAttendees() 249void IncidenceBase::clearAttendees()
249{ 250{
250 if (mReadOnly) return; 251 if (mReadOnly) return;
251 mAttendees.clear(); 252 mAttendees.clear();
252} 253}
253 254
254#if 0 255#if 0
255Attendee *IncidenceBase::getAttendee(const char *n) const 256Attendee *IncidenceBase::getAttendee(const char *n) const
256{ 257{
257 QPtrListIterator<Attendee> qli(mAttendees); 258 QPtrListIterator<Attendee> qli(mAttendees);
258 259
259 qli.toFirst(); 260 qli.toFirst();
260 while (qli) { 261 while (qli) {
261 if (qli.current()->getName() == n) 262 if (qli.current()->getName() == n)
262 return qli.current(); 263 return qli.current();
263 ++qli; 264 ++qli;
264 } 265 }
265 return 0L; 266 return 0L;
266} 267}
267#endif 268#endif
268 269
269Attendee *IncidenceBase::attendeeByMail(const QString &email) 270Attendee *IncidenceBase::attendeeByMail(const QString &email)
270{ 271{
271 QPtrListIterator<Attendee> qli(mAttendees); 272 QPtrListIterator<Attendee> qli(mAttendees);
272 273
273 qli.toFirst(); 274 qli.toFirst();
274 while (qli) { 275 while (qli) {
275 if (qli.current()->email() == email) 276 if (qli.current()->email() == email)
276 return qli.current(); 277 return qli.current();
277 ++qli; 278 ++qli;
278 } 279 }
279 return 0L; 280 return 0L;
280} 281}
281 282
282Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 283Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
283{ 284{
284 QPtrListIterator<Attendee> qli(mAttendees); 285 QPtrListIterator<Attendee> qli(mAttendees);
285 286
286 QStringList mails = emails; 287 QStringList mails = emails;
287 if (!email.isEmpty()) { 288 if (!email.isEmpty()) {
288 mails.append(email); 289 mails.append(email);
289 } 290 }
290 qli.toFirst(); 291 qli.toFirst();
291 while (qli) { 292 while (qli) {
292 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 293 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
293 if (qli.current()->email() == *it) 294 if (qli.current()->email() == *it)
294 return qli.current(); 295 return qli.current();
295 } 296 }
296 297
297 ++qli; 298 ++qli;
298 } 299 }
299 return 0L; 300 return 0L;
300} 301}
301 302
302void IncidenceBase::setDuration(int seconds) 303void IncidenceBase::setDuration(int seconds)
303{ 304{
304 mDuration = seconds; 305 mDuration = seconds;
305 setHasDuration(true); 306 setHasDuration(true);
306} 307}
307 308
308int IncidenceBase::duration() const 309int IncidenceBase::duration() const
309{ 310{
310 return mDuration; 311 return mDuration;
311} 312}
312 313
313void IncidenceBase::setHasDuration(bool b) 314void IncidenceBase::setHasDuration(bool b)
314{ 315{
315 mHasDuration = b; 316 mHasDuration = b;
316} 317}
317 318
318bool IncidenceBase::hasDuration() const 319bool IncidenceBase::hasDuration() const
319{ 320{
320 return mHasDuration; 321 return mHasDuration;
321} 322}
322 323
323void IncidenceBase::setSyncStatus(int stat) 324void IncidenceBase::setSyncStatus(int stat)
324{ 325{
325 if (mReadOnly) return; 326 if (mReadOnly) return;
326 mSyncStatus = stat; 327 mSyncStatus = stat;
327} 328}
328 329
329int IncidenceBase::syncStatus() const 330int IncidenceBase::syncStatus() const
330{ 331{
331 return mSyncStatus; 332 return mSyncStatus;
332} 333}
333 334
334void IncidenceBase::setPilotId( int id ) 335void IncidenceBase::setPilotId( int id )
335{ 336{
336 if (mReadOnly) return; 337 if (mReadOnly) return;
337 mPilotId = id; 338 mPilotId = id;
338} 339}
339 340
340int IncidenceBase::pilotId() const 341int IncidenceBase::pilotId() const
341{ 342{
342 return mPilotId; 343 return mPilotId;
343} 344}
344void IncidenceBase::setZaurusId( int id ) 345void IncidenceBase::setZaurusId( int id )
345{ 346{
346 if (mReadOnly) return; 347 if (mReadOnly) return;
347 mZaurusId = id; 348 mZaurusId = id;
348} 349}
349 350
350int IncidenceBase::zaurusId() const 351int IncidenceBase::zaurusId() const
351{ 352{
352 return mZaurusId; 353 return mZaurusId;
353} 354}
354 355
355int IncidenceBase::zaurusUid() const 356int IncidenceBase::zaurusUid() const
356{ 357{
357 return mZaurusUid; 358 return mZaurusUid;
358} 359}
359void IncidenceBase::setZaurusUid( int id ) 360void IncidenceBase::setZaurusUid( int id )
360{ 361{
361 if (mReadOnly) return; 362 if (mReadOnly) return;
362 mZaurusUid = id; 363 mZaurusUid = id;
363} 364}
364 365
365int IncidenceBase::tempSyncStat() const 366int IncidenceBase::tempSyncStat() const
366{ 367{
367 return mTempSyncStat; 368 return mTempSyncStat;
368} 369}
369void IncidenceBase::setTempSyncStat( int id ) 370void IncidenceBase::setTempSyncStat( int id )
370{ 371{
371 if (mReadOnly) return; 372 if (mReadOnly) return;
372 mTempSyncStat = id; 373 mTempSyncStat = id;
373} 374}
374 375
376void IncidenceBase::setID( const QString & prof , int id )
377{
378 int num = mExternalId.find( ":"+prof+";" );
379 if ( num >= 0 ) {
380 int len = prof.length()+2;
381 int end = mExternalId.find( ";", num+len );
382 if ( end > 0 ) {
383 mExternalId = mExternalId.left( num+len ) +QString::number( id)+mExternalId.mid( end );
384 } else
385 qDebug("Error in IncidenceBase::setID ");
386 } else {
387 mExternalId += prof+";"+QString::number( id) +";0:";
388 }
389}
390int IncidenceBase::getID( const QString & prof)
391{
392 int ret = -1;
393 int num = mExternalId.find(":"+ prof+";" );
394 if ( num >= 0 ) {
395 int len = prof.length()+2;
396 int end = mExternalId.find( ";", num+len );
397 if ( end > 0 ) {
398 bool ok;
399 ret = mExternalId.mid ( num + len,end-len-num).toInt( &ok );
400 if (!ok)
401 return -1;
402 }
403 }
404 return ret;
405}
406
407// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
408// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
409void IncidenceBase::setCsum( const QString & prof , int id )
410{
411 int num = mExternalId.find( ":"+prof+";");
412 if ( num >= 0 ) {
413 int len = prof.length()+2;
414 num = mExternalId.find( ";", num+len );
415 int end = mExternalId.find( ":", num+1 );
416 if ( end > 0 ) {
417 mExternalId = mExternalId.left( num ) +QString::number(id)+mExternalId.mid( end );
418 } else
419 qDebug("Error in IncidenceBase::setCsum ");
420 } else {
421 mExternalId += prof+";-1;"+QString::number( id) +":";
422 }
423}
424int IncidenceBase::getCsum( const QString & prof)
425{
426 int ret = -1;
427 int num = mExternalId.find( ":"+prof+";" );
428 if ( num >= 0 ) {
429 int len = prof.length()+2;
430 num = mExternalId.find( ";", num+len );
431 int end = mExternalId.find( ":", num+1 );
432 if ( end > 0 ) {
433 bool ok;
434 ret = mExternalId.mid ( num ,end-num).toInt( &ok );
435 if (!ok)
436 return -1;
437 }
438 }
439 return ret;
440}
441
442void IncidenceBase::setIDStr( const QString & s )
443{
444 if (mReadOnly) return;
445 mExternalId = s;
446}
447
448QString IncidenceBase::IDStr() const
449{
450 return mExternalId ;
451}
375void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 452void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
376{ 453{
377 if( !mObservers.contains(observer) ) mObservers.append( observer ); 454 if( !mObservers.contains(observer) ) mObservers.append( observer );
378} 455}
379 456
380void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 457void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
381{ 458{
382 mObservers.remove( observer ); 459 mObservers.remove( observer );
383} 460}
384 461
385void IncidenceBase::updated() 462void IncidenceBase::updated()
386{ 463{
387 QPtrListIterator<Observer> it(mObservers); 464 QPtrListIterator<Observer> it(mObservers);
388 while( it.current() ) { 465 while( it.current() ) {
389 Observer *o = it.current(); 466 Observer *o = it.current();
390 ++it; 467 ++it;
391 o->incidenceUpdated( this ); 468 o->incidenceUpdated( this );
392 } 469 }
393} 470}
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index ce6e254..2f85df6 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -1,170 +1,178 @@
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#ifndef KCAL_INCIDENCEBASE_H 20#ifndef KCAL_INCIDENCEBASE_H
21#define KCAL_INCIDENCEBASE_H 21#define KCAL_INCIDENCEBASE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "attendee.h" 32#include "attendee.h"
33 33
34namespace KCal { 34namespace KCal {
35 35
36typedef QValueList<QDate> DateList; 36typedef QValueList<QDate> DateList;
37 37
38/** 38/**
39 This class provides the base class common to all calendar components. 39 This class provides the base class common to all calendar components.
40*/ 40*/
41class IncidenceBase : public CustomProperties 41class IncidenceBase : public CustomProperties
42{ 42{
43 public: 43 public:
44 class Observer { 44 class Observer {
45 public: 45 public:
46 virtual void incidenceUpdated( IncidenceBase * ) = 0; 46 virtual void incidenceUpdated( IncidenceBase * ) = 0;
47 }; 47 };
48 48
49 IncidenceBase(); 49 IncidenceBase();
50 IncidenceBase(const IncidenceBase &); 50 IncidenceBase(const IncidenceBase &);
51 virtual ~IncidenceBase(); 51 virtual ~IncidenceBase();
52 52
53 virtual QCString type() const = 0; 53 virtual QCString type() const = 0;
54 54
55 /** Set the unique id for the event */ 55 /** Set the unique id for the event */
56 void setUid(const QString &); 56 void setUid(const QString &);
57 /** Return the unique id for the event */ 57 /** Return the unique id for the event */
58 QString uid() const; 58 QString uid() const;
59 59
60 /** Sets the time the incidence was last modified. */ 60 /** Sets the time the incidence was last modified. */
61 void setLastModified(const QDateTime &lm); 61 void setLastModified(const QDateTime &lm);
62 /** Return the time the incidence was last modified. */ 62 /** Return the time the incidence was last modified. */
63 QDateTime lastModified() const; 63 QDateTime lastModified() const;
64 64
65 /** sets the organizer for the event */ 65 /** sets the organizer for the event */
66 void setOrganizer(const QString &o); 66 void setOrganizer(const QString &o);
67 QString organizer() const; 67 QString organizer() const;
68 68
69 /** Set readonly status. */ 69 /** Set readonly status. */
70 virtual void setReadOnly( bool ); 70 virtual void setReadOnly( bool );
71 /** Return if the object is read-only. */ 71 /** Return if the object is read-only. */
72 bool isReadOnly() const { return mReadOnly; } 72 bool isReadOnly() const { return mReadOnly; }
73 73
74 /** for setting the event's starting date/time with a QDateTime. */ 74 /** for setting the event's starting date/time with a QDateTime. */
75 virtual void setDtStart(const QDateTime &dtStart); 75 virtual void setDtStart(const QDateTime &dtStart);
76 /** returns an event's starting date/time as a QDateTime. */ 76 /** returns an event's starting date/time as a QDateTime. */
77 QDateTime dtStart() const; 77 QDateTime dtStart() const;
78 /** returns an event's starting time as a string formatted according to the 78 /** returns an event's starting time as a string formatted according to the
79 users locale settings */ 79 users locale settings */
80 QString dtStartTimeStr() const; 80 QString dtStartTimeStr() const;
81 /** returns an event's starting date as a string formatted according to the 81 /** returns an event's starting date as a string formatted according to the
82 users locale settings */ 82 users locale settings */
83 QString dtStartDateStr(bool shortfmt=true) const; 83 QString dtStartDateStr(bool shortfmt=true) const;
84 /** returns an event's starting date and time as a string formatted according 84 /** returns an event's starting date and time as a string formatted according
85 to the users locale settings */ 85 to the users locale settings */
86 QString dtStartStr(bool shortfmt=true) const; 86 QString dtStartStr(bool shortfmt=true) const;
87 87
88 virtual void setDuration(int seconds); 88 virtual void setDuration(int seconds);
89 int duration() const; 89 int duration() const;
90 void setHasDuration(bool); 90 void setHasDuration(bool);
91 bool hasDuration() const; 91 bool hasDuration() const;
92 92
93 /** Return true or false depending on whether the incidence "floats," 93 /** Return true or false depending on whether the incidence "floats,"
94 * i.e. has a date but no time attached to it. */ 94 * i.e. has a date but no time attached to it. */
95 bool doesFloat() const; 95 bool doesFloat() const;
96 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ 96 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
97 void setFloats(bool f); 97 void setFloats(bool f);
98 98
99 /** 99 /**
100 Add Attendee to this incidence. IncidenceBase takes ownership of the 100 Add Attendee to this incidence. IncidenceBase takes ownership of the
101 Attendee object. 101 Attendee object.
102 */ 102 */
103 void addAttendee(Attendee *a, bool doupdate=true ); 103 void addAttendee(Attendee *a, bool doupdate=true );
104// void removeAttendee(Attendee *a); 104// void removeAttendee(Attendee *a);
105// void removeAttendee(const char *n); 105// void removeAttendee(const char *n);
106 /** Remove all Attendees. */ 106 /** Remove all Attendees. */
107 void clearAttendees(); 107 void clearAttendees();
108 /** Return list of attendees. */ 108 /** Return list of attendees. */
109 QPtrList<Attendee> attendees() const { return mAttendees; }; 109 QPtrList<Attendee> attendees() const { return mAttendees; };
110 /** Return number of attendees. */ 110 /** Return number of attendees. */
111 int attendeeCount() const { return mAttendees.count(); }; 111 int attendeeCount() const { return mAttendees.count(); };
112 /** Return the Attendee with this email */ 112 /** Return the Attendee with this email */
113 Attendee* attendeeByMail(const QString &); 113 Attendee* attendeeByMail(const QString &);
114 /** Return first Attendee with one of this emails */ 114 /** Return first Attendee with one of this emails */
115 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); 115 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
116 116
117 /** pilot syncronization states */ 117 /** pilot syncronization states */
118 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; 118 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
119 /** Set synchronisation satus. */ 119 /** Set synchronisation satus. */
120 void setSyncStatus(int stat); 120 void setSyncStatus(int stat);
121 /** Return synchronisation status. */ 121 /** Return synchronisation status. */
122 int syncStatus() const; 122 int syncStatus() const;
123 123
124 /** Set Pilot Id. */ 124 /** Set Pilot Id. */
125 void setPilotId(int id); 125 void setPilotId(int id);
126 /** Return Pilot Id. */ 126 /** Return Pilot Id. */
127 int pilotId() const; 127 int pilotId() const;
128 128
129 void setZaurusId(int id); 129 void setZaurusId(int id);
130 int zaurusId() const; 130 int zaurusId() const;
131 void setZaurusUid(int id); 131 void setZaurusUid(int id);
132 int zaurusUid() const; 132 int zaurusUid() const;
133 void setTempSyncStat(int id); 133 void setTempSyncStat(int id);
134 int tempSyncStat() const; 134 int tempSyncStat() const;
135 void setIDStr( const QString & );
136 QString IDStr() const;
137 void setID( const QString &, int );
138 int getID( const QString & );
139 void setCsum( const QString &, int );
140 int getCsum( const QString & );
141
135 142
136 void registerObserver( Observer * ); 143 void registerObserver( Observer * );
137 void unRegisterObserver( Observer * ); 144 void unRegisterObserver( Observer * );
138 void updated(); 145 void updated();
139 146
140 protected: 147 protected:
141 bool mReadOnly; 148 bool mReadOnly;
142 QDateTime getEvenTime( QDateTime ); 149 QDateTime getEvenTime( QDateTime );
143 150
144 private: 151 private:
145 // base components 152 // base components
146 QDateTime mDtStart; 153 QDateTime mDtStart;
147 QString mOrganizer; 154 QString mOrganizer;
148 QString mUid; 155 QString mUid;
149 QDateTime mLastModified; 156 QDateTime mLastModified;
150 QPtrList<Attendee> mAttendees; 157 QPtrList<Attendee> mAttendees;
151 158
152 bool mFloats; 159 bool mFloats;
153 160
154 int mDuration; 161 int mDuration;
155 bool mHasDuration; 162 bool mHasDuration;
163 QString mExternalId;
156 int mZaurusId; 164 int mZaurusId;
157 int mZaurusUid; 165 int mZaurusUid;
158 int mTempSyncStat; 166 int mTempSyncStat;
159 167
160 // PILOT SYNCHRONIZATION STUFF 168 // PILOT SYNCHRONIZATION STUFF
161 int mPilotId; // unique id for pilot sync 169 int mPilotId; // unique id for pilot sync
162 int mSyncStatus; // status (for sync) 170 int mSyncStatus; // status (for sync)
163 171
164 QPtrList<Observer> mObservers; 172 QPtrList<Observer> mObservers;
165}; 173};
166 174
167bool operator==( const IncidenceBase&, const IncidenceBase& ); 175bool operator==( const IncidenceBase&, const IncidenceBase& );
168} 176}
169 177
170#endif 178#endif