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( ", " ) );
}
Example #2
0
KCal::Alarm::List ResourceLocal::alarms(const QDateTime &from, const QDateTime &to)
{
    KCal::Alarm::List alarms;
    KCal::Journal::List notes = mCalendar.journals();
    KCal::Journal::List::ConstIterator note;
    for(note = notes.begin(); note != notes.end(); ++note)
    {
        QDateTime preTime = from.addSecs(-1);
        KCal::Alarm::List::ConstIterator it;
        for(it = (*note)->alarms().begin(); it != (*note)->alarms().end(); ++it)
        {
            if((*it)->enabled())
            {
                QDateTime dt = (*it)->nextRepetition(preTime);
                if(dt.isValid() && dt <= to)
                    alarms.append(*it);
            }
        }
    }

    return alarms;
}
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;
}
Example #4
0
/******************************************************************************
* Check if any alarms are pending for a specified calendar, and display the
* pending alarms.
*/
void AlarmDaemon::checkAlarms(ADCalendar *cal)
{
    kdDebug(5901) << "AlarmDaemons::checkAlarms(" << cal->urlString() << ")" << endl;
    if(!cal->loaded()  ||  !cal->enabled())
        return;

    QDateTime now  = QDateTime::currentDateTime();
    kdDebug(5901) << "  To: " << now.toString() << endl;
    QValueList<KCal::Alarm *> alarms = cal->alarmsTo(now);
    if(!alarms.count())
        return;
    QValueList<KCal::Event *> eventsDone;
    for(QValueList<KCal::Alarm *>::ConstIterator it = alarms.begin();  it != alarms.end();  ++it)
    {
        KCal::Event *event = dynamic_cast<KCal::Event *>((*it)->parent());
        if(!event  ||  eventsDone.find(event) != eventsDone.end())
            continue;   // either not an event, or the event has already been processed
        eventsDone += event;
        const QString &eventID = event->uid();
        kdDebug(5901) << "AlarmDaemon::checkAlarms(): event " << eventID  << endl;

        // Check which of the alarms for this event are due.
        // The times in 'alarmtimes' corresponding to due alarms are set.
        // The times for non-due alarms are set invalid in 'alarmtimes'.
        bool recurs = event->doesRecur();
        const QStringList cats = event->categories();
        bool floats = (cats.find(QString::fromLatin1("DATE")) != cats.end());
        QDateTime nextDateTime = event->dtStart();
        if(recurs)
        {
            QString prop = event->customProperty("KALARM", "NEXTRECUR");
            if(prop.length() >= 8)
            {
                // The next due recurrence time is specified
                QDate d(prop.left(4).toInt(), prop.mid(4, 2).toInt(), prop.mid(6, 2).toInt());
                if(d.isValid())
                {
                    if(floats  &&  prop.length() == 8)
                        nextDateTime = d;
                    else if(!floats  &&  prop.length() == 15  &&  prop[8] == QChar('T'))
                    {
                        QTime t(prop.mid(9, 2).toInt(), prop.mid(11, 2).toInt(), prop.mid(13, 2).toInt());
                        if(t.isValid())
                            nextDateTime = QDateTime(d, t);
                    }
                }
            }
        }
        if(floats)
            nextDateTime.setTime(mStartOfDay);
        QValueList<QDateTime> alarmtimes;
        KCal::Alarm::List alarms = event->alarms();
        for(KCal::Alarm::List::ConstIterator al = alarms.begin();  al != alarms.end();  ++al)
        {
            KCal::Alarm *alarm = *al;
            QDateTime dt;
            if(alarm->enabled())
            {
                QDateTime dt1;
                if(!alarm->hasTime())
                {
                    // Find the latest recurrence for the alarm.
                    // Need to do this for alarms with offsets in order to detect
                    // reminders due for recurrences.
                    int offset = alarm->hasStartOffset() ? alarm->startOffset().asSeconds()
                                 : alarm->endOffset().asSeconds() + event->dtStart().secsTo(event->dtEnd());
                    if(offset)
                    {
                        dt1 = nextDateTime.addSecs(floats ? (offset / SECS_PER_DAY) * SECS_PER_DAY : offset);
                        if(dt1 > now)
                            dt1 = QDateTime();
                    }
                }
                // Get latest due repetition, or the recurrence time if none
                dt = nextDateTime;
                if(nextDateTime <= now  &&  alarm->repeatCount() > 0)
                {
                    int snoozeSecs = alarm->snoozeTime() * 60;
                    int offset = alarm->repeatCount() * snoozeSecs;
                    QDateTime lastRepetition = nextDateTime.addSecs(floats ? (offset / SECS_PER_DAY) * SECS_PER_DAY : offset);
                    if(lastRepetition <= now)
                        dt = lastRepetition;
                    else
                    {
                        int repetition = nextDateTime.secsTo(now) / snoozeSecs;
                        int offset = repetition * snoozeSecs;
                        dt = nextDateTime.addSecs(floats ? (offset / SECS_PER_DAY) * SECS_PER_DAY : offset);
                    }
                }
                if(!dt.isValid()  ||  dt > now
                        ||  dt1.isValid()  &&  dt1 > dt)  // already tested dt1 <= now
                    dt = dt1;
            }
            alarmtimes.append(dt);
        }
        if(!cal->eventHandled(event, alarmtimes))
        {
            if(notifyEvent(cal, eventID))
                cal->setEventPending(event, alarmtimes);
        }
    }
}