コード例 #1
0
void CalendarBaseTest::createInitialIncidences()
{
    mExpectedSlotResult = true;

    for (int i=0; i<5; ++i) {
        Event::Ptr event = Event::Ptr(new Event());
        event->setUid(QStringLiteral("event") + QString::number(i));
        event->setSummary(QStringLiteral("summary") + QString::number(i));
        event->setDtStart(KDateTime::currentDateTime(KDateTime::UTC));
        mUids.append(event->uid());
        QVERIFY(mCalendar->addEvent(event));
        QTestEventLoop::instance().enterLoop(5);
        QVERIFY(!QTestEventLoop::instance().timeout());
    }
    mOneEventUid = mUids.last();

    for (int i=0; i<5; ++i) {
        Todo::Ptr todo = Todo::Ptr(new Todo());
        todo->setUid(QStringLiteral("todo") + QString::number(i));
        todo->setDtStart(KDateTime::currentDateTime(KDateTime::UTC));
        todo->setSummary(QStringLiteral("summary") + QString::number(i));
        mUids.append(todo->uid());
        QVERIFY(mCalendar->addTodo(todo));
        QTestEventLoop::instance().enterLoop(5);
        QVERIFY(!QTestEventLoop::instance().timeout());
    }
    mOneTodoUid = mUids.last();

    for (int i=0; i<5; ++i) {
        Journal::Ptr journal = Journal::Ptr(new Journal());
        journal->setUid(QStringLiteral("journal") + QString::number(i));
        journal->setSummary(QStringLiteral("summary") + QString::number(i));
        journal->setDtStart(KDateTime::currentDateTime(KDateTime::UTC));
        mUids.append(journal->uid());
        QVERIFY(mCalendar->addJournal(journal));
        QTestEventLoop::instance().enterLoop(5);
        QVERIFY(!QTestEventLoop::instance().timeout());
    }
    mOneJournalUid = mUids.last();

    for (int i=0; i<5; ++i) {
        Incidence::Ptr incidence = Incidence::Ptr(new Event());
        incidence->setUid(QStringLiteral("incidence") + QString::number(i));
        incidence->setSummary(QStringLiteral("summary") + QString::number(i));
        incidence->setDtStart(KDateTime::currentDateTime(KDateTime::UTC));
        mUids.append(incidence->uid());
        QVERIFY(mCalendar->addIncidence(incidence));
        QTestEventLoop::instance().enterLoop(5);
        QVERIFY(!QTestEventLoop::instance().timeout());
    }
    mOneIncidenceUid = mUids.last();
}
コード例 #2
0
ファイル: konsolekalendardelete.cpp プロジェクト: KDE/kdepim
bool KonsoleKalendarDelete::deleteEvent()
{
    bool status = false;

    qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendardelete.cpp::deleteEvent()";

    /*
     * Retrieve event on the basis of the unique string ID
     */
    Event::Ptr event = m_variables->getCalendar()->event(m_variables->getUID());
    if (event) {
        if (m_variables->isDryRun()) {
            cout << i18n("Delete Event <Dry Run>:").data()
                 << endl;
            printSpecs(event);
        } else {
            qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendardelete.cpp:deleteEvent() :"
                                         << m_variables->getUID().data();

            if (m_variables->isVerbose()) {
                cout << i18n("Delete Event <Verbose>:").data()
                     << endl;
                printSpecs(event);
            }

            QEventLoop loop;
            Akonadi::CalendarBase::Ptr calendar = m_variables->getCalendar();
            QObject::connect(calendar.data(), &Akonadi::CalendarBase::deleteFinished, &loop, &QEventLoop::quit);
            calendar->deleteEvent(event);
            loop.exec();
            qCDebug(KONSOLEKALENDAR_LOG) << "Finished deleting";
            status = calendar->incidence(event->uid()) == 0;

            if (status) {
                cout << i18n("Success: \"%1\" deleted", event->summary()).data() << endl;
            } else {
                cout << i18n("Error deleting: \"%1\"", event->summary()).data() << endl;
            }
        }
    }

    qCDebug(KONSOLEKALENDAR_LOG) << "konsolekalendardelete.cpp::deleteEvent() | Done";
    return status;
}