void KCalResourceSlox::parseEventAttribute( const QDomElement &e,
                                            Event *event )
{
  QString tag = e.tagName();
  QString text = decodeText( e.text() );
  if ( text.isEmpty() ) return;

  if ( tag == fieldName( EventBegin ) ) {
    KDateTime dt;
    if ( event->allDay() ) {
      if ( type() == "ox" )
        dt = WebdavHandler::sloxToKDateTime( text, timeSpec() );
      else
        dt = WebdavHandler::sloxToKDateTime( text ); // ### is this really correct for SLOX?
      dt.setDateOnly( true );
    } else
      dt = WebdavHandler::sloxToKDateTime( text );
    event->setDtStart( dt );
  } else if ( tag == fieldName( EventEnd ) ) {
    KDateTime dt;
    if ( event->allDay() ) {
      dt = WebdavHandler::sloxToKDateTime( text );
      dt = dt.addSecs( -1 );
    }
    else dt = WebdavHandler::sloxToKDateTime( text );
    event->setDtEnd( dt );
  } else if ( tag == fieldName( Location ) ) {
    event->setLocation( text );
  }
}
예제 #2
0
void ComparisonVisitorTest::testEventComparison()
{
  const QString summary = QLatin1String( "Testing comparison" );
  const QString desc    = QLatin1String( "Testing ComparisonVisitor" );
  const KDateTime now   = KDateTime::currentUtcDateTime();
  const KDateTime later = now.addSecs( 3600 );

  Event reference;
  reference.setSummary( summary );
  reference.setDescription( desc );
  reference.setDtStart( now );
  reference.setDtEnd( later );

  // create a copy of the reference incidence
  Event event( reference );
  
  IncidenceBase *baseReference = &reference;
  IncidenceBase *baseIncidence = &event;

  QVERIFY( mComparator.compare( baseIncidence, baseReference ) );

  // change a property of Event (but not of IncidenceBase)
  event.setHasEndDate( !event.hasEndDate() );
  QVERIFY( !mComparator.compare( baseIncidence, baseReference ) );
}
/******************************************************************************
* If the minimum and maximum date/times fall on the same date, set the minimum
* and maximum times in the time edit box.
*/
void AlarmTimeWidget::setMaxMinTimeIf(const KDateTime& now)
{
	int   mint = 0;
	QTime maxt = time_23_59;
	mMinMaxTimeSet = false;
	if (mMaxDateTime.isValid())
	{
		bool set = true;
		KDateTime minDT;
		if (mMinDateTimeIsNow)
			minDT = now.addSecs(60);
		else if (mMinDateTime.isValid())
			minDT = mMinDateTime;
		else
			set = false;
		if (set  &&  mMaxDateTime.date() == minDT.date())
		{
			// The minimum and maximum times are on the same date, so
			// constrain the time value.
			mint = minDT.time().hour()*60 + minDT.time().minute();
			maxt = mMaxDateTime.time();
			mMinMaxTimeSet = true;
		}
	}
	mTimeEdit->setMinimum(mint);
	mTimeEdit->setMaximum(maxt);
	mTimeEdit->setWrapping(!mint  &&  maxt == time_23_59);
}
예제 #4
0
QDate Event::dateEnd() const
{
  KDateTime end = dtEnd().toTimeSpec( dtStart() );
  if ( allDay() ) {
    return end.date();
  } else {
    return end.addSecs(-1).date();
  }
}
예제 #5
0
void ComparisonVisitorTest::testFreeBusyComparison()
{
  const KDateTime now   = KDateTime::currentUtcDateTime();
  const KDateTime later = now.addSecs( 3600 );

  FreeBusy reference;
  reference.setDtStart( now );
  reference.setDtEnd( later );

  // create a copy of the reference incidence
  FreeBusy freebusy( reference );

  IncidenceBase *baseReference = &reference;
  IncidenceBase *baseIncidence = &freebusy;

  QVERIFY( mComparator.compare( baseIncidence, baseReference ) );

  // change a property of FreeBusy (but not of IncidenceBase)
  freebusy.setDtEnd( freebusy.dtEnd().addSecs( 3600 ) );
  QVERIFY( !mComparator.compare( baseIncidence, baseReference ) );
}
예제 #6
0
KCal::Alarm::List ResourceKolab::alarms( const KDateTime& from, const KDateTime& to )
{
    KCal::Alarm::List alarms;
    KCal::Journal::List notes = mCalendar.journals();
    KCal::Journal::List::ConstIterator note;
    for ( note = notes.constBegin(); note != notes.constEnd(); ++note )
    {
        KDateTime preTime = from.addSecs( -1 );
        KCal::Alarm::List::ConstIterator it;
        for( it = (*note)->alarms().constBegin(); it != (*note)->alarms().constEnd(); ++it )
        {
            if ( (*it)->enabled() )
            {
                KDateTime dt = (*it)->nextRepetition( preTime );
                if ( dt.isValid() && dt <= to )
                    alarms.append( *it );
            }
        }
    }

    return alarms;
}
예제 #7
0
    Incidence::Ptr pasteIncidence( const Incidence::Ptr &incidence,
                                   KDateTime newDateTime,
                                   const QFlags<PasteFlag> &pasteOptions )
    {
      Incidence::Ptr inc( incidence );

      if ( inc ) {
        inc = Incidence::Ptr( inc->clone() );
        inc->recreate();
      }

      if ( inc && newDateTime.isValid() ) {
        if ( inc->type() == Incidence::TypeEvent ) {
          Event::Ptr event = inc.staticCast<Event>();
          if ( pasteOptions & FlagPasteAtOriginalTime ) {
            // Set date and preserve time and timezone stuff
            const QDate date = newDateTime.date();
            newDateTime = event->dtStart();
            newDateTime.setDate( date );
          }

          // in seconds
          const int durationInSeconds = event->dtStart().secsTo( event->dtEnd() );
          const int durationInDays = event->dtStart().daysTo( event->dtEnd() );

          event->setDtStart( newDateTime );

          if ( newDateTime.isDateOnly() ) {
            event->setDtEnd( newDateTime.addDays( durationInDays ) );
          } else {
            event->setDtEnd( newDateTime.addSecs( durationInSeconds ) );
          }

        } else if ( inc->type() == Incidence::TypeTodo ) {
          Todo::Ptr aTodo = inc.staticCast<Todo>();
          const bool pasteAtDtStart = ( pasteOptions & FlagTodosPasteAtDtStart );
          if ( pasteOptions & FlagPasteAtOriginalTime ) {
            // Set date and preserve time and timezone stuff
            const QDate date = newDateTime.date();
            newDateTime = pasteAtDtStart ? aTodo->dtStart() : aTodo->dtDue();
            newDateTime.setDate( date );
          }
          if ( pasteAtDtStart ) {
            aTodo->setDtStart( newDateTime );
          } else {
            aTodo->setDtDue( newDateTime );
          }

        } else if ( inc->type() == Incidence::TypeJournal ) {
          if ( pasteOptions & FlagPasteAtOriginalTime ) {
            // Set date and preserve time and timezone stuff
            const QDate date = newDateTime.date();
            newDateTime = inc->dtStart();
            newDateTime.setDate( date );
          }
          inc->setDtStart( newDateTime );
        } else {
          kDebug() << "Trying to paste unknown incidence of type" << int( inc->type() );
        }
      }

      return inc;
    }
/******************************************************************************
* Fetch the entered date/time.
* If 'checkExpired' is true and the entered value <= current time, an error occurs.
* If 'minsFromNow' is non-null, it is set to the number of minutes' delay selected,
* or to zero if a date/time was entered.
* In this case, if 'showErrorMessage' is true, output an error message.
* 'errorWidget' if non-null, is set to point to the widget containing the error.
* Reply = invalid date/time if error.
*/
KDateTime AlarmTimeWidget::getDateTime(int* minsFromNow, bool checkExpired, bool showErrorMessage, QWidget** errorWidget) const
{
	if (minsFromNow)
		*minsFromNow = 0;
	if (errorWidget)
		*errorWidget = 0;
	KDateTime now = KDateTime::currentUtcDateTime();
	now.setTime(QTime(now.time().hour(), now.time().minute(), 0));
	if (!mAtTimeRadio->isChecked())
	{
		if (!mDelayTimeEdit->isValid())
		{
			if (showErrorMessage)
				KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid time"));
			if (errorWidget)
				*errorWidget = mDelayTimeEdit;
			return KDateTime();
		}
		int delayMins = mDelayTimeEdit->value();
		if (minsFromNow)
			*minsFromNow = delayMins;
		return now.addSecs(delayMins * 60).toTimeSpec(mTimeSpec);
	}
	else
	{
		bool dateOnly = mAnyTimeAllowed && mAnyTimeCheckBox && mAnyTimeCheckBox->isChecked();
		if (!mDateEdit->isValid()  ||  !mTimeEdit->isValid())
		{
			// The date and/or time is invalid
			if (!mDateEdit->isValid())
			{
				if (showErrorMessage)
					KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid date"));
				if (errorWidget)
					*errorWidget = mDateEdit;
			}
			else
			{
				if (showErrorMessage)
					KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid time"));
				if (errorWidget)
					*errorWidget = mTimeEdit;
			}
			return KDateTime();
		}

		KDateTime result;
		if (dateOnly)
		{
			result = KDateTime(mDateEdit->date(), mTimeSpec);
			if (checkExpired  &&  result.date() < now.date())
			{
				if (showErrorMessage)
					KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Alarm date has already expired"));
				if (errorWidget)
					*errorWidget = mDateEdit;
				return KDateTime();
			}
		}
		else
		{
			result = KDateTime(mDateEdit->date(), mTimeEdit->time(), mTimeSpec);
			if (checkExpired  &&  result <= now.addSecs(1))
			{
				if (showErrorMessage)
					KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Alarm time has already expired"));
				if (errorWidget)
					*errorWidget = mTimeEdit;
				return KDateTime();
			}
		}
		return result;
	}
}