void ConfirmSaveDialog::addIncidences( const Incidence::List &incidences, const QString &operation ) { Incidence::List::ConstIterator it; for( it = incidences.begin(); it != incidences.end(); ++it ) { Incidence *i = *it; KListViewItem *item = new KListViewItem( mListView ); item->setText( 0, operation ); item->setText( 1, i->type() ); item->setText( 2, i->summary() ); item->setText( 3, i->uid() ); } }
QMap<Todo *,KOTodoViewItem *>::ConstIterator KOTodoView::insertTodoItem(Todo *todo) { // kdDebug(5850) << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; Incidence *incidence = todo->relatedTo(); if (incidence && incidence->type() == "Todo") { // Use dynamic_cast, because in the future the related item might also be an event Todo *relatedTodo = dynamic_cast<Todo *>(incidence); // just make sure we know we have this item already to avoid endless recursion (Bug 101696) mTodoMap.insert(todo,0); // kdDebug(5850) << " has Related" << endl; QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; itemIterator = mTodoMap.find(relatedTodo); if (itemIterator == mTodoMap.end()) { // kdDebug(5850) << " related not yet in list" << endl; itemIterator = insertTodoItem (relatedTodo); } // isn't this pretty stupid? We give one Todo to the KOTodoViewItem // and one into the map. Sure finding is more easy but why? -zecke KOTodoViewItem *todoItem; // in case we found a related parent, which has no KOTodoViewItem yet, this must // be the case where 2 items refer to each other, therefore simply create item as root item if ( *itemIterator == 0 ) { todo->setRelatedTo(0); // break the recursion, else we will have troubles later todoItem = new KOTodoViewItem(mTodoListView,todo,this); } else todoItem = new KOTodoViewItem(*itemIterator,todo,this); return mTodoMap.insert(todo,todoItem); } else { // kdDebug(5850) << " no Related" << endl; // see above -zecke KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); return mTodoMap.insert(todo,todoItem); } }
void KCalResourceSlox::slotUploadResult( KJob *job ) { kDebug(); if ( job->error() ) { saveError( job->errorString() ); } else { kDebug() << "success"; if ( !mUploadJob ) { kDebug() << "mUploadJob was 0"; return; } QDomDocument doc = mUploadJob->response(); kDebug() << "UPLOAD RESULT:"; kDebug() << doc.toString( 2 ); QDomElement docElement = doc.documentElement(); QDomNode responseNode; for( responseNode = docElement.firstChild(); !responseNode.isNull(); responseNode = responseNode.nextSibling() ) { QDomElement responseElement = responseNode.toElement(); if ( responseElement.tagName() == "response" ) { QDomNode propstat = responseElement.namedItem( "propstat" ); if ( propstat.isNull() ) { kError() << "Unable to find propstat tag."; continue; } QDomNode status = propstat.namedItem( "status" ); if ( !status.isNull() ) { QDomElement statusElement = status.toElement(); QString response = statusElement.text(); if ( !response.contains( "200" ) ) { QString error = '\'' + mUploadedIncidence->summary() + "'\n"; error += response; QDomNode dn = propstat.namedItem( "responsedescription" ); QString d = dn.toElement().text(); if ( !d.isEmpty() ) error += '\n' + d; saveError( error ); continue; } } QDomNode prop = propstat.namedItem( "prop" ); if ( prop.isNull() ) { kError() << "Unable to find WebDAV property"; continue; } QDomNode sloxIdNode = prop.namedItem( fieldName( ObjectId ) ); if ( sloxIdNode.isNull() ) { kError() << "Unable to find SLOX id."; continue; } QDomElement sloxIdElement = sloxIdNode.toElement(); QString sloxId = sloxIdElement.text(); kDebug() << "SLOXID:" << sloxId; if ( mUploadIsDelete ) { kDebug() << "Incidence deleted"; } else { QDomNode clientIdNode = prop.namedItem( fieldName( ClientId ) ); if ( clientIdNode.isNull() ) { kError() << "Unable to find client id."; continue; } QDomElement clientidElement = clientIdNode.toElement(); QString clientId = clientidElement.text(); kDebug() << "CLIENTID:" << clientId; Incidence *i = mUploadedIncidence->clone(); QString uid; if ( i->type() == "Event" ) uid = sloxIdToEventUid( sloxId ); else if ( i->type() == "Todo" ) uid = sloxIdToTodoUid( sloxId ); else { kError() << "Unknown type:" << i->type(); } i->setUid( uid ); i->setCustomProperty( "SLOX", "ID", sloxId ); if ( type() == "ox" ) { // Update the last_modified property const QDomNode lastModifiedNode = prop.namedItem( fieldName( LastModified ) ); if ( !lastModifiedNode.isNull() ) { const QDomElement lastModifiedElement = lastModifiedNode.toElement(); const QString lastModified = lastModifiedElement.text(); i->setCustomProperty( "SLOX", "LastModified", lastModified ); } } disableChangeNotification(); calendar()->deleteIncidence( mUploadedIncidence ); calendar()->addIncidence( i ); saveToCache(); enableChangeNotification(); emit resourceChanged( this ); } } } } mUploadJob = 0; mUploadProgress->setComplete(); mUploadProgress = 0; clearChange( mUploadedIncidence ); uploadIncidences(); }
ScheduleMessage *ICalFormat::parseScheduleMessage(Calendar *cal, const QString &messageText) { setTimeZone(cal->timeZoneId(), !cal->isLocalTime()); clearException(); if(messageText.isEmpty()) { setException(new ErrorFormat(ErrorFormat::ParseErrorKcal, QString::fromLatin1("messageText was empty, unable to parse into a ScheduleMessage"))); return 0; } // TODO FIXME: Don't we have to ical-free message??? MEMLEAK icalcomponent *message; message = icalparser_parse_string(messageText.utf8()); if(!message) { setException(new ErrorFormat(ErrorFormat::ParseErrorKcal, QString::fromLatin1("icalparser was unable to parse messageText into a ScheduleMessage"))); return 0; } icalproperty *m = icalcomponent_get_first_property(message, ICAL_METHOD_PROPERTY); if(!m) { setException(new ErrorFormat(ErrorFormat::ParseErrorKcal, QString::fromLatin1("message didn't contain an ICAL_METHOD_PROPERTY"))); return 0; } icalcomponent *c; IncidenceBase *incidence = 0; c = icalcomponent_get_first_component(message, ICAL_VEVENT_COMPONENT); if(c) { icalcomponent *ctz = icalcomponent_get_first_component(message, ICAL_VTIMEZONE_COMPONENT); incidence = mImpl->readEvent(c, ctz); } if(!incidence) { c = icalcomponent_get_first_component(message, ICAL_VTODO_COMPONENT); if(c) { incidence = mImpl->readTodo(c); } } if(!incidence) { c = icalcomponent_get_first_component(message, ICAL_VJOURNAL_COMPONENT); if(c) { incidence = mImpl->readJournal(c); } } if(!incidence) { c = icalcomponent_get_first_component(message, ICAL_VFREEBUSY_COMPONENT); if(c) { incidence = mImpl->readFreeBusy(c); } } if(!incidence) { kdDebug(5800) << "ICalFormat:parseScheduleMessage: object is not a freebusy, event, todo or journal" << endl; setException(new ErrorFormat(ErrorFormat::ParseErrorKcal, QString::fromLatin1("object is not a freebusy, event, todo or journal"))); return 0; } kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; icalproperty_method icalmethod = icalproperty_get_method(m); Scheduler::Method method; switch(icalmethod) { case ICAL_METHOD_PUBLISH: method = Scheduler::Publish; break; case ICAL_METHOD_REQUEST: method = Scheduler::Request; break; case ICAL_METHOD_REFRESH: method = Scheduler::Refresh; break; case ICAL_METHOD_CANCEL: method = Scheduler::Cancel; break; case ICAL_METHOD_ADD: method = Scheduler::Add; break; case ICAL_METHOD_REPLY: method = Scheduler::Reply; break; case ICAL_METHOD_COUNTER: method = Scheduler::Counter; break; case ICAL_METHOD_DECLINECOUNTER: method = Scheduler::Declinecounter; break; default: method = Scheduler::NoMethod; kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; break; } kdDebug(5800) << "ICalFormat::parseScheduleMessage() restriction..." << endl; if(!icalrestriction_check(message)) { kdWarning(5800) << k_funcinfo << endl << "libkcal reported a problem while parsing:" << endl; kdWarning(5800) << Scheduler::translatedMethodName(method) + ": " + mImpl->extractErrorProperty(c) << endl; /* setException(new ErrorFormat(ErrorFormat::Restriction, Scheduler::translatedMethodName(method) + ": " + mImpl->extractErrorProperty(c))); delete incidence; return 0; */ } icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); Incidence *existingIncidence = cal->incidenceFromSchedulingID(incidence->uid()); if(existingIncidence) { // TODO: check, if cast is required, or if it can be done by virtual funcs. // TODO: Use a visitor for this! if(existingIncidence->type() == "Todo") { Todo *todo = static_cast<Todo *>(existingIncidence); icalcomponent_add_component(calendarComponent, mImpl->writeTodo(todo)); } if(existingIncidence->type() == "Event") { Event *event = static_cast<Event *>(existingIncidence); icalcomponent_add_component(calendarComponent, mImpl->writeEvent(event)); } } else { calendarComponent = 0; } kdDebug(5800) << "ICalFormat::parseScheduleMessage() classify..." << endl; icalproperty_xlicclass result = icalclassify(message, calendarComponent, (char *)""); kdDebug(5800) << "ICalFormat::parseScheduleMessage() returning..." << endl; kdDebug(5800) << "ICalFormat::parseScheduleMessage(), result = " << result << endl; ScheduleMessage::Status status; switch(result) { case ICAL_XLICCLASS_PUBLISHNEW: status = ScheduleMessage::PublishNew; break; case ICAL_XLICCLASS_PUBLISHUPDATE: status = ScheduleMessage::PublishUpdate; break; case ICAL_XLICCLASS_OBSOLETE: status = ScheduleMessage::Obsolete; break; case ICAL_XLICCLASS_REQUESTNEW: status = ScheduleMessage::RequestNew; break; case ICAL_XLICCLASS_REQUESTUPDATE: status = ScheduleMessage::RequestUpdate; break; case ICAL_XLICCLASS_UNKNOWN: default: status = ScheduleMessage::Unknown; break; } kdDebug(5800) << "ICalFormat::parseScheduleMessage(), status = " << status << endl; // TODO FIXME: Don't we have to free calendarComponent??? MEMLEAK return new ScheduleMessage(incidence, method, status); }