void KCalResourceSlox::createIncidenceAttributes( QDomDocument &doc,
                                                  QDomElement &parent,
                                                  Incidence *incidence )
{
  WebdavHandler::addSloxElement( this, doc, parent, fieldName( IncidenceTitle ),
                                 incidence->summary() );

  WebdavHandler::addSloxElement( this, doc, parent, fieldName( Description ),
                                 incidence->description() );

  if ( incidence->attendeeCount() > 0 ) {
    QDomElement members = WebdavHandler::addSloxElement( this, doc, parent,
        fieldName( Participants ) );
    Attendee::List attendees = incidence->attendees();
    Attendee::List::ConstIterator it;
    for( it = attendees.constBegin(); it != attendees.constEnd(); ++it ) {
      if ( mAccounts ) {
        QString userId = mAccounts->lookupId( (*it)->email() );
        QString status;
        switch ( (*it)->status() ) {
          case Attendee::Accepted: status = "accept"; break;
          case Attendee::Declined: status = "decline"; break;
          default: status = "none"; break;
        }
        QDomElement el = WebdavHandler::addSloxElement( this, doc, members, fieldName( Participant ), userId );
        el.setAttribute( "confirm", status );
      } else {
        kError() << "KCalResourceSlox: No accounts set.";
      }
    }
  }

  // set read attributes - if SecrecyPublic, set it to users
  // TODO OX support
  if ( incidence->secrecy() == Incidence::SecrecyPublic && type() != "ox" )
  {
    QDomElement rights = WebdavHandler::addSloxElement( this, doc, parent, "readrights" );
    WebdavHandler::addSloxElement( this, doc, rights, "group", "users" );
  }

  // set reminder as the number of minutes to the start of the event
  KCal::Alarm::List alarms = incidence->alarms();
  if ( !alarms.isEmpty() && alarms.first()->hasStartOffset() && alarms.first()->enabled() )
    WebdavHandler::addSloxElement( this, doc, parent, fieldName( Reminder ),
                                   QString::number( (-1) * alarms.first()->startOffset().asSeconds() / 60 ) );
  else
    WebdavHandler::addSloxElement( this, doc, parent, fieldName( Reminder ), "0" );

  // categories
  WebdavHandler::addSloxElement( this, doc, parent, fieldName( Categories ), incidence->categories().join( ", " ) );
}
Esempio n. 2
0
ngwt__Appointment *IncidenceConverter::convertToAppointment(KCal::Event *event)
{
    kdDebug() << "IncidenceConverter::convertToAppointment()" << endl;
    if(!event)
        return 0;

    ngwt__Appointment *appointment = soap_new_ngwt__Appointment(soap(), -1);
    appointment->startDate = 0;
    appointment->endDate = 0;
    appointment->startDay = 0;
    appointment->endDay = 0;
    appointment->acceptLevel = 0;
    appointment->alarm = 0;
    appointment->allDayEvent = 0;
    appointment->place = 0;
    appointment->timezone = 0;

    if(!convertToCalendarItem(event, appointment))
    {
        soap_dealloc(soap(), appointment);
        return 0;
    }

    if(event->doesFloat())
    {
        bool *allDayEvent = (bool *)soap_malloc(soap(), 1);
        (*allDayEvent) = true;
        appointment->allDayEvent = allDayEvent;

        if(event->dtStart().isValid())
        {
            /*      kdDebug() << " convertToAppointment() raw start date: " << event->dtStart().toString() << endl;*/
            QDateTime start = event->dtStart();
            start.setTime(QTime(0, 0, 0));
            appointment->startDate = qDateTimeToChar(start, mTimezone);
            //appointment->startDay = qDateToString( event->dtStart().date()/*.addDays( -1 )*/ );
            /*      kdDebug() << "   converted start date: " << appointment->startDate << endl;*/
        }
        else
            kdDebug() << "   event start date not valid " << endl;
        if(event->hasEndDate())
        {
            //       kdDebug() << " convertToAppointment() raw end date: " << event->dtEnd().toString() << endl;
            QDateTime end = event->dtEnd();
            end = end.addDays(1);
            end.setTime(QTime(0, 0, 0));
            appointment->endDate = qDateTimeToChar(end, mTimezone);
            //appointment->endDay = qDateToString( event->dtEnd().date() );
            //       kdDebug() << "   converted end date:" << appointment->endDate << endl;
        }
        else
            kdDebug() << "   event end date not valid " << endl;
    }
    else
    {
        appointment->allDayEvent = 0;

        if(event->dtStart().isValid())
            appointment->startDate = qDateTimeToChar(event->dtStart(), mTimezone);

        if(event->hasEndDate())
            appointment->endDate = qDateTimeToChar(event->dtEnd(), mTimezone);
    }

    enum ngwt__AcceptLevel *al = (enum ngwt__AcceptLevel *)soap_malloc(soap(), sizeof(enum ngwt__AcceptLevel));
    *al = Busy;
    appointment->acceptLevel = al;

    KCal::Alarm::List alarms = event->alarms();
    if(!alarms.isEmpty())
    {
        ngwt__Alarm *alarm = soap_new_ngwt__Alarm(soap(), -1);
        alarm->__item = alarms.first()->startOffset().asSeconds() * -1;
        bool *enabled = (bool *)soap_malloc(soap(), sizeof(bool));
        *enabled = alarms.first()->enabled();
        alarm->enabled = enabled;

        appointment->alarm = alarm;
    }
    else
        appointment->alarm = 0;

    if(!event->location().isEmpty())
    {
        std::string *location = qStringToString(event->location());

        appointment->place = location;
    }
    else
        appointment->place = 0;

    appointment->timezone = 0;

    return appointment;
}