int todaySeconds (const QDate &date, const KCalCore::Event::Ptr &event)
{
        if ( !event )
          return 0;

        kDebug(5970) << "found an event for task, event=" << event->uid();
        KDateTime startTime=event->dtStart();
        KDateTime endTime=event->dtEnd();
        KDateTime NextMidNight=startTime;
        NextMidNight.setTime(QTime ( 0,0 ));
        NextMidNight=NextMidNight.addDays(1);
        // LastMidNight := mdate.setTime(0:00) as it would read in a decent programming language
        KDateTime LastMidNight=KDateTime::currentLocalDateTime();
        LastMidNight.setDate(date);
        LastMidNight.setTime(QTime(0,0));
        int secsstartTillMidNight=startTime.secsTo(NextMidNight);
        int secondsToAdd=0; // seconds that need to be added to the actual cell
        if ( (startTime.date()==date) && (event->dtEnd().date()==date) ) // all the event occurred today
            secondsToAdd=startTime.secsTo(endTime);
        if ( (startTime.date()==date) && (endTime.date()>date) ) // the event started today, but ended later
            secondsToAdd=secsstartTillMidNight;
        if ( (startTime.date()<date) && (endTime.date()==date) ) // the event started before today and ended today
            secondsToAdd=LastMidNight.secsTo(event->dtEnd());
        if ( (startTime.date()<date) && (endTime.date()>date) ) // the event started before today and ended after
            secondsToAdd=86400;

        return secondsToAdd;
}
void timetrackerstorage::startTimer(const Task* task, const KDateTime &when)
{
    kDebug(5970) << "Entering function; when=" << when;
    KCalCore::Event::Ptr e;
    e = baseEvent(task);
    e->setDtStart(when);
    d->mCalendar->addEvent(e);
    task->taskView()->scheduleSave();
}
void NemoCalendarApi::remove(const QString &uid, const QDateTime &time)
{
    mKCal::ExtendedCalendar::Ptr calendar = NemoCalendarDb::calendar();
    KCalCore::Event::Ptr event = calendar->event(uid);
    if (!event)
        return;
    if (event->recurs())
        event->recurrence()->addExDateTime(KDateTime(time, KDateTime::Spec(KDateTime::LocalZone)));
    else
        calendar->deleteEvent(event);
    // TODO: this sucks
    NemoCalendarDb::storage()->save();
}
void KolabObjectTest::preserveUnicode()
{
    KCalCore::Event::Ptr event(new KCalCore::Event());
    QString summary(QString::fromUtf8("€Š�ـأبـ☺"));
    event->setSummary(summary);
    QCOMPARE(event->summary(), summary);
//     std::cout << event->summary().toStdString() << std::endl;
    KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event);
//     kDebug() << msg->encodedContent();
    KCalCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent();
    QVERIFY(readEvent);
//     std::cout << readEvent->summary().toStdString() << std::endl;
    QCOMPARE(readEvent->summary(), summary);
}
QVariant NemoCalendarImportModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid() || index.row() >= mEventList.count())
        return QVariant();

    KCalCore::Event::Ptr event = mEventList.at(index.row());

    switch(role) {
    case DisplayLabelRole:
        return event->summary();
    case DescriptionRole:
        return event->description();
    case StartTimeRole:
        return event->dtStart().dateTime();
    case EndTimeRole:
        return event->dtEnd().dateTime();
    case AllDayRole:
        return event->allDay();
    case LocationRole:
        return event->location();
    case UidRole:
        return event->uid();
    default:
        return QVariant();
    }
}
void TestBirthdayPlugin::testLeapYears()
{
    const QString contactID = QUuid::createUuid().toString();
    QFETCH(QDate, contactBirthDate);

    // Add contact with birthday to tracker.
    QContactName contactName;
    contactName.setFirstName(contactID);
    QContactBirthday contactBirthday;
    contactBirthday.setDate(contactBirthDate);
    QContact contact;
    QVERIFY(contact.saveDetail(&contactName));
    QVERIFY(contact.saveDetail(&contactBirthday));
    QVERIFY(saveContact(contact));

    // Wait until calendar event gets to calendar.
    loopWait(calendarTimeout);

    // Open calendar database.
    mKCal::ExtendedCalendar::Ptr calendar =
        mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
    mKCal::ExtendedStorage::Ptr storage =
        mKCal::ExtendedCalendar::defaultStorage(calendar);

    QVERIFY(storage->open());
    QVERIFY(not storage->notebook(calNotebookId).isNull());

    // Check calendar database for contact.
    QVERIFY(storage->loadNotebookIncidences(calNotebookId));
    const KCalCore::Event::List eventList = findCalendarEvents(calendar->events(), contact);
    QCOMPARE(eventList.count(), 1);

    const KCalCore::Event::Ptr event = eventList.first();
    QCOMPARE(event->summary(), contactID);
    QCOMPARE(event->dtStart().date(), contactBirthDate);
    QCOMPARE(event->allDay(), true);

    // Check number of recurrences and their values.
    const KDateTime first(QDate(2000, 1, 1), QTime(), KDateTime::ClockTime);
    const KDateTime last(QDate(2020, 12, 31), QTime(), KDateTime::ClockTime);
    const KCalCore::DateTimeList instances = event->recurrence()->timesInInterval(first, last);

    QCOMPARE(instances.length(), 13);

    for(int i = 0; i < instances.length(); ++i) {
        QCOMPARE(instances.at(i).date(), contactBirthDate.addYears(i));
    }
}
Beispiel #7
0
void EventEditTest::shouldEventHasCorrectSubject()
{
    MessageViewer::EventEdit edit;
    KMime::Message::Ptr msg(new KMime::Message);
    QString subject = QStringLiteral("Test Note");
    msg->subject(true)->fromUnicodeString(subject, "us-ascii");
    edit.setMessage(msg);
    QLineEdit *noteedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
    QVERIFY(noteedit);
    QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection)));
    QTest::keyClick(noteedit, Qt::Key_Enter);
    QCOMPARE(spy.count(), 1);
    KCalCore::Event::Ptr eventPtr = spy.at(0).at(0).value<KCalCore::Event::Ptr>();
    QVERIFY(eventPtr);
    QCOMPARE(eventPtr->summary(), subject);
}
Beispiel #8
0
void EventEditTest::shouldHaveCorrectStartEndDateTime()
{
    MessageViewer::EventEdit edit;
    KMime::Message::Ptr msg(new KMime::Message);
    QString subject = QStringLiteral("Test Note");
    msg->subject(true)->fromUnicodeString(subject, "us-ascii");
    edit.setMessage(msg);

    QDateTime currentDateTime = QDateTime::currentDateTime();
    MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("startdatetimeedit"));
    startDateTime->setDateTime(currentDateTime);

    QDateTime endDt = currentDateTime.addDays(1);
    MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("enddatetimeedit"));
    endDateTime->setDateTime(endDt);

    QLineEdit *noteedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
    QVERIFY(noteedit);
    QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection)));
    QTest::keyClick(noteedit, Qt::Key_Enter);
    QCOMPARE(spy.count(), 1);
    KCalCore::Event::Ptr eventPtr = spy.at(0).at(0).value<KCalCore::Event::Ptr>();
    QVERIFY(eventPtr);
    QCOMPARE(eventPtr->dtStart().date(), currentDateTime.date());
    QCOMPARE(eventPtr->dtStart().time().hour(), currentDateTime.time().hour());
    QCOMPARE(eventPtr->dtStart().time().minute(), currentDateTime.time().minute());

    QCOMPARE(eventPtr->dtEnd().date(), endDt.date());
    QCOMPARE(eventPtr->dtEnd().time().hour(), endDt.time().hour());
    QCOMPARE(eventPtr->dtEnd().time().minute(), endDt.time().minute());
}
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();
        }
    }
}
void timetrackerstorage::changeTime(const Task* task, const long deltaSeconds)
{
    kDebug(5970) << "Entering function; deltaSeconds=" << deltaSeconds;
    KCalCore::Event::Ptr e;
    QDateTime end;
    e = baseEvent(task);

    // Don't use duration, as ICalFormatImpl::writeIncidence never writes a
    // duration, even though it looks like it's used in event.cpp.
    end = task->startTime();
    if ( deltaSeconds > 0 ) end = task->startTime().addSecs(deltaSeconds);
    e->setDtEnd(KDateTime(end, KDateTime::Spec::LocalZone()));

    // Use a custom property to keep a record of negative durations
    e->setCustomProperty( KGlobal::mainComponent().componentName().toUtf8(),
        QByteArray("duration"),
        QString::number(deltaSeconds));

    d->mCalendar->addEvent(e);
    task->taskView()->scheduleSave();
}
void timetrackerstorage::startTimer(QString taskID)
{
    kDebug(5970) << "Entering function";
    KCalCore::Todo::List todoList;
    KCalCore::Todo::List::ConstIterator todo;
    todoList = d->mCalendar->rawTodos();
    for( todo = todoList.constBegin(); todo != todoList.constEnd(); ++todo )
    {
        kDebug(5970) << (*todo)->uid();
        kDebug(5970) << taskID;
        if ( (*todo)->uid() == taskID )
        {
            kDebug(5970) << "adding event";
            KCalCore::Event::Ptr e;
            e = baseEvent((*todo));
            e->setDtStart(KDateTime::currentLocalDateTime());
            d->mCalendar->addEvent(e);
        }
    }
    saveCalendar();
}
void KoRdfCalendarEvent::saveToKCal()
{
#ifdef KDEPIMLIBS_FOUND
    KCalCore::Event::Ptr event = toKEvent();

    Akonadi::CollectionDialog collectionDialog;
    collectionDialog.setMimeTypeFilter(QStringList() << event->mimeType());
    collectionDialog.setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
    collectionDialog.setDescription(i18n("Select a calendar for saving:"));
    if (! collectionDialog.exec()) {
        return;
    }

    Akonadi::Collection collection = collectionDialog.selectedCollection();

    Akonadi::Item item;
    item.setPayload<KCalCore::Event::Ptr>(event);
    item.setMimeType(event->mimeType());

    Akonadi::ItemCreateJob *itemCreateJob = new Akonadi::ItemCreateJob(item, collection);
    connect(itemCreateJob, SIGNAL(result(KJob*) ), SLOT(onCreateJobFinished(KJob*)));
#endif
}
void KoRdfCalendarEvent::fromKEvent(KCalCore::Event::Ptr event)
{
    m_dtstart = event->dtStart();
    m_dtend   = event->dtEnd();
    m_summary = event->summary();
    m_location = event->location();
    m_uid = event->uid();
    Soprano::Node n = Soprano::LiteralValue(m_dtstart.dateTime());
    KDateTime::Spec tz = toKTimeZone(n);
    KDateTime roundTrip = VEventDateTimeToKDateTime(n.toString(), tz);

    kDebug(30015) << "summary:" << m_summary;
    kDebug(30015) << "location:" << m_location;
    kDebug(30015) << "uid:" << m_uid;
    kDebug(30015) << "dtstart:" << m_dtstart;
    kDebug(30015) << "dtstart.offset:" << m_dtstart.timeZone().currentOffset();
    kDebug(30015) << "dtstart.utc:" << m_dtstart.toUtc();
    kDebug(30015) << "  local.offset:" << KSystemTimeZones::local().currentOffset();
    kDebug(30015) << "dtstart.roundTrip:" << roundTrip;
    kDebug(30015) << "dtend:" << m_dtend;
    kDebug(30015) << "dtstart.rdfnode:" << n;
    kDebug(30015) << "dtstart.roundTrip.offset:" << tz.timeZone().currentOffset();
}
KCalCore::Event::Ptr KoRdfCalendarEvent::toKEvent() const
{
    KCalCore::Event::Ptr event = KCalCore::Event::Ptr(new KCalCore::Event());
    event->setDtStart(start());
    event->setDtEnd(end());
    event->setSummary(summary());
    event->setLocation(location());
    event->setUid(uid());
    return event;
}
Beispiel #15
0
void KCalConversionTest::testConversion()
{
    QFETCH(KCalCore::Event, kcal);
    QFETCH(Kolab::Event, kolab);
    
    KCalCore::Event::Ptr e = toKCalCore(kolab);
    const Kolab::Event &b = fromKCalCore(kcal);
    
    QCOMPARE(e->uid(), kcal.uid());
    QCOMPARE(e->created(), kcal.created());
    QCOMPARE(e->lastModified(), kcal.lastModified());
    QCOMPARE(e->revision(), kcal.revision());
    QCOMPARE(e->secrecy(), kcal.secrecy());
    QCOMPARE(e->categories(), kcal.categories());
    QCOMPARE(e->dtStart(), kcal.dtStart());
    QCOMPARE(e->dtEnd(), kcal.dtEnd());
    QCOMPARE(e->duration(), kcal.duration());
    QCOMPARE(e->transparency(), kcal.transparency());
    QCOMPARE(*e->recurrence(), *kcal.recurrence());
    QCOMPARE(e->recurrenceId(), kcal.recurrenceId());
    QCOMPARE(e->recurrenceType(), kcal.recurrenceType());
    QCOMPARE(e->summary(), kcal.summary());
    QCOMPARE(e->description(), kcal.description());
    QCOMPARE(e->priority(), kcal.priority());
    QCOMPARE(e->status(), kcal.status());
    QCOMPARE(e->location(), kcal.location());
    QCOMPARE(e->organizer()->name(), kcal.organizer()->name());
    QCOMPARE(e->organizer()->email(), kcal.organizer()->email());
    QCOMPARE(e->nonKDECustomProperty("X-KOLAB-URL"), kcal.nonKDECustomProperty("X-KOLAB-URL"));
    //otherwise we'd break the customProperties comparison
    e->removeNonKDECustomProperty("X-KOLAB-URL");
    kcal.removeNonKDECustomProperty("X-KOLAB-URL");
    compareAttendeesVectors(e->attendees(), kcal.attendees());
    comparePointerVectors(e->attachments(), kcal.attachments());
    
//     QCOMPARE(e->alarms(), kcal.alarms()); //TODO
    QCOMPARE(e->customProperties(), kcal.customProperties());

//     QBENCHMARK {
//         toKCalCore(kolab);
//     }
    
    QCOMPARE(b.uid(), kolab.uid());
    QCOMPARE(b.created(), kolab.created());
    QCOMPARE(b.lastModified(), kolab.lastModified());
    QCOMPARE(b.sequence(), kolab.sequence());
    QCOMPARE(b.classification(), kolab.classification());
    QCOMPARE(b.categories(), kolab.categories());
    QCOMPARE(b.start(), kolab.start());
    QCOMPARE(b.end(), kolab.end());
    QCOMPARE(b.duration(), kolab.duration());
    QCOMPARE(b.transparency(), kolab.transparency());
    
    QCOMPARE(b.recurrenceRule(), kolab.recurrenceRule());
    QCOMPARE(b.recurrenceID(), kolab.recurrenceID());
    QCOMPARE(b.recurrenceDates(), kolab.recurrenceDates());
    QCOMPARE(b.exceptionDates(), kolab.exceptionDates());
    
    QCOMPARE(b.summary(), kolab.summary());
    QCOMPARE(b.description(), kolab.description());
    QCOMPARE(b.status(), kolab.status());
    QCOMPARE(b.location(), kolab.location());
    QCOMPARE(b.organizer(), kolab.organizer());
    QCOMPARE(b.url(), kolab.url());
    QCOMPARE(b.attendees(), kolab.attendees());
    QCOMPARE(b.attachments(), kolab.attachments());
    QCOMPARE(b.customProperties(), kolab.customProperties());
}