Ejemplo n.º 1
0
void tst_storage::tst_rawEvents()
{
  // TODO: Should split tests if making more cases outside storage
  auto event = KCalCore::Event::Ptr(new KCalCore::Event);
  // NOTE: no other events should be made happening this day
  QDate startDate(2010, 12, 1);
  event->setDtStart(KDateTime(startDate, QTime(12, 0), KDateTime::ClockTime));
  event->setDtEnd(KDateTime(startDate, QTime(13, 0), KDateTime::ClockTime));

  KCalCore::Recurrence *recurrence = event->recurrence();
  recurrence->setDaily(1);
  recurrence->setStartDateTime(event->dtStart());

  m_calendar->addEvent(event, NotebookId);
  m_storage->save();
  QString uid = event->uid();
  reloadDb();

  auto fetchEvent = m_calendar->event(uid);
  QVERIFY(fetchEvent);
  KCalCore::Recurrence *fetchRecurrence = fetchEvent->recurrence();
  QVERIFY(fetchRecurrence);

  // should return occurrence for both days
  mKCal::ExtendedCalendar::ExpandedIncidenceList events
      = m_calendar->rawExpandedEvents(startDate, startDate.addDays(1), false, false, KDateTime::Spec(KDateTime::LocalZone));

  QCOMPARE(events.size(), 2);
}
Ejemplo n.º 2
0
void CalSettings::loadSpecial(const QUrl& url, const QColor& color)
{
    if (url.isEmpty())
    {
        qCDebug(KIPIPLUGINS_LOG) << "Loading calendar from file failed: No valid url provided!";
        return;
    }

    KCalCore::MemoryCalendar::Ptr memCal(new KCalCore::MemoryCalendar(QStringLiteral("UTC")));
    KCalCore::FileStorage::Ptr fileStorage(new KCalCore::FileStorage(memCal, url.path(), new KCalCore::ICalFormat));

    qCDebug(KIPIPLUGINS_LOG) << "Loading calendar from file " << url.path();

    if (!fileStorage->load())
    {
        qCDebug(KIPIPLUGINS_LOG) << "Failed!";
    }
    else
    {
        QDate qFirst, qLast;
        KLocale::global()->calendar()->setDate(qFirst, params.year, 1, 1);
        KLocale::global()->calendar()->setDate(qLast, params.year + 1, 1, 1);
        qLast = qLast.addDays(-1);
        KDateTime dtFirst(qFirst);
        KDateTime dtLast(qLast);
        KDateTime dtCurrent;

        int counter                = 0;
        KCalCore::Event::List list = memCal->rawEvents(qFirst, qLast);

        foreach(const KCalCore::Event::Ptr event, list)
        {
            qCDebug(KIPIPLUGINS_LOG) << event->summary() << endl << "--------";
            counter++;

            if (event->recurs())
            {
                KCalCore::Recurrence* recur = event->recurrence();

                for (dtCurrent = recur->getNextDateTime(dtFirst.addDays(-1));
                     (dtCurrent <= dtLast) && dtCurrent.isValid();
                     dtCurrent = recur->getNextDateTime(dtCurrent))
                {
                    addSpecial(dtCurrent.date(), Day(color, event->summary()));
                }
            }
            else
            {
                addSpecial(event->dtStart().date(), Day(color, event->summary()));
            }
        }

        qCDebug(KIPIPLUGINS_LOG) << "Loaded " << counter << " events";
        memCal->close();
        fileStorage->close();
    }
void NemoCalendarEventQuery::refresh()
{
    if (!mIsComplete)
        return;

    mKCal::ExtendedCalendar::Ptr calendar = NemoCalendarDb::calendar();
    KCalCore::Event::Ptr event = mUid.isEmpty()?KCalCore::Event::Ptr():calendar->event(mUid);
    if (event) {
        if (mOccurrence) {
            delete mOccurrence;
            mOccurrence = 0;
        }

        mKCal::ExtendedCalendar::ExpandedIncidenceValidity eiv = {
            event->dtStart().toLocalZone().dateTime(),
            event->dtEnd().toLocalZone().dateTime()
        };

        if (!mStartTime.isNull() && event->recurs()) {
            KDateTime startTime = KDateTime(mStartTime, KDateTime::Spec(KDateTime::LocalZone));
            KCalCore::Recurrence *recurrence = event->recurrence();
            if (recurrence->recursAt(startTime)) {
                eiv.dtStart = startTime.toLocalZone().dateTime();
                eiv.dtEnd = KCalCore::Duration(event->dtStart(), event->dtEnd()).end(startTime).toLocalZone().dateTime();
            } else {
                KDateTime match = recurrence->getNextDateTime(startTime);
                if (match.isNull())
                    match = recurrence->getPreviousDateTime(startTime);

                if (!match.isNull()) {
                    eiv.dtStart = match.toLocalZone().dateTime();
                    eiv.dtEnd = KCalCore::Duration(event->dtStart(), event->dtEnd()).end(match).toLocalZone().dateTime();
                }
            }
        }

        mOccurrence = new NemoCalendarEventOccurrence(qMakePair(eiv, event.dynamicCast<KCalCore::Incidence>()), 
                                                      this);
        emit occurrenceChanged();
        emit eventChanged();
    } else {
        if (mOccurrence) {
            delete mOccurrence;
            mOccurrence = 0;
            emit occurrenceChanged();
            emit eventChanged();
        }
    }
}
Ejemplo n.º 4
0
void tst_storage::tst_alldayRecurrence()
{
  auto event = KCalCore::Event::Ptr(new KCalCore::Event);

  QDate startDate(2013, 12, 1);
  event->setDtStart(KDateTime(startDate, QTime(), KDateTime::ClockTime));
  event->setAllDay(true);

  KCalCore::Recurrence *recurrence = event->recurrence();
  recurrence->setWeekly(1);
  recurrence->setStartDateTime(event->dtStart());

  m_calendar->addEvent(event, NotebookId);
  m_storage->save();
  QString uid = event->uid();
  reloadDb();

  auto fetchEvent = m_calendar->event(uid);
  QVERIFY(fetchEvent);
  KCalCore::Recurrence *fetchRecurrence = fetchEvent->recurrence();
  QVERIFY(fetchRecurrence);
  KDateTime match = recurrence->getNextDateTime(KDateTime(startDate));
  QCOMPARE(match, KDateTime(startDate.addDays(7), QTime(), KDateTime::ClockTime));
}