コード例 #1
0
bool CalDavClient::loadStorageChanges(mKCal::ExtendedStorage::Ptr storage,
                                      const KDateTime &fromDate,
                                      KCalCore::Incidence::List *inserted,
                                      KCalCore::Incidence::List *modified,
                                      KCalCore::Incidence::List *deleted,
                                      QString *error)
{
    FUNCTION_CALL_TRACE;

    QString accountId = QString::number(mSettings.accountId());
    QString notebookUid;
    mKCal::Notebook::List notebookList = storage->notebooks();
    Q_FOREACH (mKCal::Notebook::Ptr notebook, notebookList) {
        if (notebook->account() == accountId) {
            notebookUid = notebook->uid();
            break;
        }
    }

    if (notebookUid.isEmpty()) {
        *error = "Cannot find mkCal::Notebook for account: " + accountId;
        return false;
    }

    if (!storage->insertedIncidences(inserted, fromDate, notebookUid)) {
        *error = "mKCal::ExtendedStorage::insertedIncidences() failed";
        return false;
    }
    if (!storage->modifiedIncidences(modified, fromDate, notebookUid)) {
        *error = "mKCal::ExtendedStorage::modifiedIncidences() failed";
        return false;
    }
    if (!storage->deletedIncidences(deleted, fromDate, notebookUid)) {
        *error = "mKCal::ExtendedStorage::deletedIncidences() failed";
        return false;
    }

    // If an event has changed to/from the caldav notebook and back since the last sync,
    // it will be present in both the inserted and deleted lists. In this case, nothing
    // has actually changed, so remove it from both lists.
    int removed = removeCommonIncidences(inserted, deleted);
    if (removed > 0) {
        LOG_DEBUG("Removed" << removed << "UIDs found in both inserted and removed lists");
    }

    return true;
}
コード例 #2
0
bool NotebookSyncAgent::loadLocalChanges(const QDateTime &fromDate,
                                         KCalCore::Incidence::List *inserted,
                                         KCalCore::Incidence::List *modified,
                                         KCalCore::Incidence::List *deleted)
{
    FUNCTION_CALL_TRACE;

    if (!mStorage) {
        LOG_CRITICAL("mStorage not set");
        return false;
    }
    QString notebookUid = mNotebook->uid();
    KDateTime kFromDate(fromDate);
    if (!mStorage->insertedIncidences(inserted, kFromDate, notebookUid)) {
        LOG_CRITICAL("mKCal::ExtendedStorage::insertedIncidences() failed");
        return false;
    }
    if (!mStorage->modifiedIncidences(modified, kFromDate, notebookUid)) {
        LOG_CRITICAL("mKCal::ExtendedStorage::modifiedIncidences() failed");
        return false;
    }
    if (!mStorage->deletedIncidences(deleted, kFromDate, notebookUid)) {
        LOG_CRITICAL("mKCal::ExtendedStorage::deletedIncidences() failed");
        return false;
    }
    LOG_DEBUG("Initially found changes for" << mServerPath << "since" << fromDate << ":"
              << "inserted = " << inserted->count()
              << "modified = " << modified->count()
              << "deleted = " << deleted->count());

    // Any server changes synced to the local db during the last sync will be picked up as
    // "local changes", so we must discard these changes so that they are not sent back to
    // the server on this next sync.
    if (!discardRemoteChanges(inserted, modified, deleted)) {
        return false;
    }
    // If an event has changed to/from the caldav notebook and back since the last sync,
    // it will be present in both the inserted and deleted lists. In this case, nothing
    // has actually changed, so remove it from both lists.
    int removed = removeCommonIncidences(inserted, deleted);
    if (removed > 0) {
        LOG_DEBUG("Removed" << removed << "UIDs found in both inserted and removed lists");
    }
    return true;
}