void CalDavClient::startQuickSync()
{
    FUNCTION_CALL_TRACE;

    mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::UTC()));
    mKCal::ExtendedStorage::Ptr storage = calendar->defaultStorage(calendar);

    storage->open();
    storage->load(QDateTime::currentDateTime().toUTC().addMonths(-6).date(),
                  QDateTime::currentDateTime().toUTC().addMonths(12).date());

    // we add 2 seconds to ensure that the timestamp doesn't
    // fall prior to when the calendar db commit fs sync finalises.
    KDateTime fromDate(lastSyncTime().addSecs(2));
    LOG_DEBUG("\n\nLAST SYNC TIME = " << fromDate.toString() << "\n\n");

    KCalCore::Incidence::List inserted;
    KCalCore::Incidence::List modified;
    KCalCore::Incidence::List deleted;
    QString errorString;
    if (!loadStorageChanges(storage, fromDate, &inserted, &modified, &deleted, &errorString)) {
        storage->close();
        calendar->close();
        syncFinished(Buteo::SyncResults::INTERNAL_ERROR, errorString);
        return;
    }
    LOG_DEBUG("Changes: inserted = " << inserted.count()
              << "modified = " << modified.count()
              << "deleted = " << deleted.count());
    if (inserted.isEmpty() && modified.isEmpty() && deleted.isEmpty()) {
        // no local changes to send, just do a REPORT to pull updates from server
        retrieveETags();
    } else {
        for (int i=0; i<inserted.count(); i++) {
            Put *put = new Put(mNAManager, &mSettings);
            mRequests.insert(put);
            connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            put->createEvent(inserted[i]);
        }
        for (int i=0; i<modified.count(); i++) {
            Put *put = new Put(mNAManager, &mSettings);
            mRequests.insert(put);
            connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            put->updateEvent(modified[i]);
        }
        for (int i=0; i<deleted.count(); i++) {
            Delete *del = new Delete(mNAManager, &mSettings);
            mRequests.insert(del);
            connect(del, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
            del->deleteEvent(deleted[i]);
        }
    }
    storage->close();
    calendar->close();
}
void NotebookSyncAgent::sendLocalChanges()
{
    NOTEBOOK_FUNCTION_CALL_TRACE;

    KCalCore::Incidence::List inserted;
    KCalCore::Incidence::List modified;
    KCalCore::Incidence::List deleted;
    if (!loadLocalChanges(mChangesSinceDate, &inserted, &modified, &deleted)) {
        emitFinished(Buteo::SyncResults::INTERNAL_ERROR, "Unable to load changes for calendar: " + mServerPath);
        return;
    }
    if (inserted.isEmpty() && modified.isEmpty() && deleted.isEmpty()) {
        LOG_DEBUG("No changes to send!");
        emitFinished(Buteo::SyncResults::NO_ERROR, "Done, no local changes for " + mServerPath);
        return;
    }
    LOG_DEBUG("Total changes for" << mServerPath << ":"
              << "inserted = " << inserted.count()
              << "modified = " << modified.count()
              << "deleted = " << deleted.count());

    for (int i=0; i<inserted.count(); i++) {
        Put *put = new Put(mNAManager, mSettings);
        mRequests.insert(put);
        connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
        put->createEvent(mServerPath, inserted[i]);
    }
    for (int i=0; i<modified.count(); i++) {
        Put *put = new Put(mNAManager, mSettings);
        mRequests.insert(put);
        connect(put, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
        put->updateEvent(mServerPath, modified[i], mLocalETags.value(modified[i]->uid()));
    }
    for (int i=0; i<deleted.count(); i++) {
        Delete *del = new Delete(mNAManager, mSettings);
        mRequests.insert(del);
        connect(del, SIGNAL(finished()), this, SLOT(nonReportRequestFinished()));
        del->deleteEvent(mServerPath, deleted[i]);
    }
}