Commit 676fad6a authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Google Calendar: add mechanism to force full resync

In some cases (like the recent fix for ID/UID/recurrence) we need to
do full resync of all calendars. This introduces a simple mechanism
that allows us to easily force full resync instead of incremental sync.
parent 2cbb8037
......@@ -11,6 +11,7 @@ set(calendarresource_SRCS
../common/googleaccountmanager.cpp
../common/googlesettings.cpp
../common/googlesettingsdialog.cpp
../common/kgapiversionattribute.cpp
${accounts_SRCS}
)
ecm_qt_declare_logging_category(calendarresource_SRCS HEADER googlecalendarresource_debug.h IDENTIFIER GOOGLE_CALENDAR_LOG CATEGORY_NAME org.kde.pim.google.calendar)
......
......@@ -20,6 +20,7 @@
#include "settings.h"
#include "settingsdialog.h"
#include "googlecalendarresource_debug.h"
#include "common/kgapiversionattribute.h"
#include <AkonadiCore/Attribute>
#include <AkonadiCore/AttributeFactory>
......@@ -75,6 +76,13 @@
Q_DECLARE_METATYPE(KGAPI2::ObjectsList)
Q_DECLARE_METATYPE(KGAPI2::TaskPtr)
namespace {
static constexpr uint32_t KGAPIEventVersion = 1;
}
using namespace Akonadi;
using namespace KGAPI2;
......@@ -82,6 +90,7 @@ CalendarResource::CalendarResource(const QString &id)
: GoogleResource(id)
{
AttributeFactory::registerAttribute< DefaultReminderAttribute >();
AttributeFactory::registerAttribute<KGAPIVersionAttribute>();
updateResourceName();
}
......@@ -130,6 +139,10 @@ void CalendarResource::retrieveItems(const Akonadi::Collection &collection)
KGAPI2::Job *job = nullptr;
if (collection.contentMimeTypes().contains(KCalCore::Event::eventMimeType())) {
if (!collection.hasAttribute<KGAPIVersionAttribute>() || collection.attribute<KGAPIVersionAttribute>()->version() != KGAPIEventVersion) {
lastSyncDelta = -1;
}
EventFetchJob *fetchJob = new EventFetchJob(collection.remoteId(), account(), this);
if (lastSyncDelta > -1 && lastSyncDelta < 25 * 24 * 3600) {
fetchJob->setFetchOnlyUpdated(collection.remoteRevision().toULongLong());
......@@ -528,6 +541,8 @@ void CalendarResource::slotItemsRetrieved(KGAPI2::Job *job)
}
}
if (!isIncremental) {
collection.attribute<KGAPIVersionAttribute>(Collection::AddIfMissing)->setVersion(KGAPIEventVersion);
}
} else if (collection.contentMimeTypes().contains(KCalCore::Todo::todoMimeType())) {
isIncremental = (qobject_cast<TaskFetchJob *>(job)->fetchOnlyUpdated() > 0);
......
/*
Copyright (C) 2019 Daniel Vrátil <dvratil@kde.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "kgapiversionattribute.h"
KGAPIVersionAttribute::KGAPIVersionAttribute(uint32_t version)
: mVersion(version)
{}
QByteArray KGAPIVersionAttribute::type() const
{
return "KGAPIVersionAttribute";
}
Akonadi::Attribute *KGAPIVersionAttribute::clone() const
{
return new KGAPIVersionAttribute(mVersion);
}
void KGAPIVersionAttribute::deserialize(const QByteArray &data)
{
mVersion = data.toUInt();
}
QByteArray KGAPIVersionAttribute::serialized() const
{
return QByteArray::number(mVersion);
}
/*
Copyright (C) 2019 Daniel Vrátil <dvratil@kde.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef KGAPIVERSIONATTRIBUTE
#define KGAPIVERSIONATTRIBUTE
#include <AkonadiCore/Attribute>
class KGAPIVersionAttribute : public Akonadi::Attribute
{
public:
explicit KGAPIVersionAttribute() = default;
explicit KGAPIVersionAttribute(uint32_t version);
~KGAPIVersionAttribute() override = default;
uint32_t version() const { return mVersion; }
void setVersion(uint32_t version) { mVersion = version; }
QByteArray type() const override;
Akonadi::Attribute *clone() const override;
QByteArray serialized() const override;
void deserialize(const QByteArray &data) override;
private:
uint32_t mVersion = 0;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment