Commit d82e7001 authored by Volker Krause's avatar Volker Krause
Browse files

Use the new KCalendarCore::Calendar loading state API

The old Akonadi-specific isLoaded() method in CalendarBase can then be
dropped once all consumers have been adjusted.
parent 3aea1a4c
Pipeline #206233 passed with stage
in 2 minutes and 13 seconds
......@@ -90,7 +90,7 @@ void ETMCalendarTest::initTestCase()
fetchCollection();
mCalendar = new ETMCalendar();
QVERIFY(!mCalendar->isLoaded());
QVERIFY(mCalendar->isLoading());
connect(mCalendar, &ETMCalendar::collectionsAdded, this, &ETMCalendarTest::handleCollectionsAdded);
mCalendar->registerObserver(this);
......@@ -115,7 +115,7 @@ void ETMCalendarTest::initTestCase()
// Wait for incidences
QTestEventLoop::instance().enterLoop(10);
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(mCalendar->isLoaded());
QVERIFY(!mCalendar->isLoading());
}
void ETMCalendarTest::cleanupTestCase()
......@@ -247,7 +247,7 @@ void ETMCalendarTest::calendarIncidenceAdded(const Incidence::Ptr &incidence)
void ETMCalendarTest::handleCollectionsAdded(const Akonadi::Collection::List &)
{
QVERIFY(!mCalendar->isLoaded());
QVERIFY(mCalendar->isLoading());
QTestEventLoop::instance().exitLoop();
}
......
......@@ -12,8 +12,6 @@
#include <Akonadi/ItemFetchScope>
#include <Akonadi/Monitor>
#include <kcalendarcore_version.h>
SingleCollectionCalendar::SingleCollectionCalendar(const Akonadi::Collection &col, QObject *parent)
: Akonadi::CalendarBase(parent)
{
......@@ -22,10 +20,8 @@ SingleCollectionCalendar::SingleCollectionCalendar(const Akonadi::Collection &co
incidenceChanger()->setDefaultCollection(col);
incidenceChanger()->setGroupwareCommunication(false);
incidenceChanger()->setDestinationPolicy(Akonadi::IncidenceChanger::DestinationPolicyNeverAsk);
#if KCALENDARCORE_VERSION >= QT_VERSION_CHECK(5, 96, 0)
setIsLoading(true);
#endif
// here and below for monitoring: ensure items have a parent collection
// before calling internalInsert to prevent an extra collection fetch job
auto job = new Akonadi::ItemFetchJob(col, this);
......@@ -37,9 +33,7 @@ SingleCollectionCalendar::SingleCollectionCalendar(const Akonadi::Collection &co
item.setParentCollection(m_collection);
d->internalInsert(item);
}
#if KCALENDARCORE_VERSION >= QT_VERSION_CHECK(5, 96, 0)
setIsLoading(false);
#endif
});
auto monitor = new Akonadi::Monitor(this);
......
......@@ -652,7 +652,7 @@ void CalendarBase::endBatchAdding()
bool CalendarBase::isLoaded() const
{
return true;
return !isLoading();
}
#include "moc_calendarbase.cpp"
......
......@@ -195,7 +195,7 @@ public:
* Returns if the calendar already finished loading.
* Base class returns true.
*/
virtual bool isLoaded() const;
[[deprecated("use isLoading() instead")]] bool isLoaded() const;
Q_SIGNALS:
/**
......
......@@ -94,6 +94,7 @@ void ETMCalendarPrivate::init()
connect(mFilteredETM, &QAbstractItemModel::rowsAboutToBeRemoved, this, &ETMCalendarPrivate::onRowsAboutToBeRemovedInFilteredModel);
loadFromETM();
updateLoadingState();
}
void ETMCalendarPrivate::onCollectionChanged(const Akonadi::Collection &collection, const QSet<QByteArray> &attributeNames)
......@@ -298,6 +299,7 @@ void ETMCalendarPrivate::onCollectionPopulated(Akonadi::Collection::Id id)
{
mPopulatedCollectionIds.insert(id);
Q_EMIT q->calendarChanged();
updateLoadingState();
}
void ETMCalendarPrivate::onRowsRemoved(const QModelIndex &index, int start, int end)
......@@ -576,21 +578,19 @@ bool ETMCalendar::collectionFilteringEnabled() const
return d->mCollectionFilteringEnabled;
}
bool ETMCalendar::isLoaded() const
void ETMCalendarPrivate::updateLoadingState()
{
Q_D(const ETMCalendar);
if (!entityTreeModel()->isCollectionTreeFetched()) {
return false;
if (!q->entityTreeModel()->isCollectionTreeFetched()) {
return q->setIsLoading(true);
}
for (const Akonadi::Collection &collection : std::as_const(d->mCollectionMap)) {
if (!entityTreeModel()->isCollectionPopulated(collection.id())) {
return false;
for (const Akonadi::Collection &collection : std::as_const(mCollectionMap)) {
if (!q->entityTreeModel()->isCollectionPopulated(collection.id())) {
return q->setIsLoading(true);
}
}
return true;
q->setIsLoading(false);
}
#include "moc_etmcalendar.cpp"
......
......@@ -154,11 +154,6 @@ public:
*/
Q_REQUIRED_RESULT bool collectionFilteringEnabled() const;
/**
* Returns if the calendar already finished loading.
*/
Q_REQUIRED_RESULT bool isLoaded() const override;
Q_SIGNALS:
/**
* This signal is emitted if a collection has been changed (properties or attributes).
......
......@@ -104,6 +104,8 @@ public Q_SLOTS:
void onCollectionChanged(const Akonadi::Collection &collection, const QSet<QByteArray> &attributeNames);
void onCollectionPopulated(Akonadi::Collection::Id);
void updateLoadingState();
public:
Akonadi::CalendarModel::Ptr mETM;
Akonadi::EntityMimeTypeFilterModel *mFilteredETM = nullptr;
......
......@@ -18,6 +18,7 @@ FetchJobCalendarPrivate::FetchJobCalendarPrivate(FetchJobCalendar *qq)
: CalendarBasePrivate(qq)
, q(qq)
{
q->setIsLoading(true);
auto job = new IncidenceFetchJob();
connect(job, &KJob::result, this, &FetchJobCalendarPrivate::slotSearchJobFinished);
connect(this, &CalendarBasePrivate::fetchFinished, this, &FetchJobCalendarPrivate::slotFetchJobFinished);
......@@ -54,7 +55,7 @@ void FetchJobCalendarPrivate::slotSearchJobFinished(KJob *job)
void FetchJobCalendarPrivate::slotFetchJobFinished()
{
m_isLoaded = true;
q->setIsLoading(false);
// Q_EMIT loadFinished() in a delayed manner, due to freezes because of execs.
QMetaObject::invokeMethod(q, "loadFinished", Qt::QueuedConnection, Q_ARG(bool, m_success), Q_ARG(QString, m_errorMessage));
}
......@@ -66,11 +67,5 @@ FetchJobCalendar::FetchJobCalendar(QObject *parent)
FetchJobCalendar::~FetchJobCalendar() = default;
bool FetchJobCalendar::isLoaded() const
{
auto d = static_cast<FetchJobCalendarPrivate *>(d_ptr.get());
return d->m_isLoaded;
}
#include "moc_fetchjobcalendar.cpp"
#include "moc_fetchjobcalendar_p.cpp"
......@@ -44,12 +44,6 @@ public:
*/
~FetchJobCalendar() override;
/**
* Returns if the calendar already finished loading.
* This is an alternative to listening for the loadFinished() signal.
*/
Q_REQUIRED_RESULT bool isLoaded() const override;
Q_SIGNALS:
/**
* This signal is emitted when the IncidenceFetchJob finishes.
......
......@@ -24,9 +24,6 @@ public Q_SLOTS:
void slotSearchJobFinished(KJob *job);
void slotFetchJobFinished();
public:
bool m_isLoaded = false;
private:
FetchJobCalendar *const q;
QString m_errorMessage;
......
......@@ -210,7 +210,7 @@ bool ITIPHandlerPrivate::isLoaded()
{
FetchJobCalendar::Ptr fetchJobCalendar = calendar().dynamicCast<Akonadi::FetchJobCalendar>();
if (fetchJobCalendar) {
return fetchJobCalendar->isLoaded();
return !fetchJobCalendar->isLoading();
}
// If it's an ETMCalendar, set through setCalendar(), then it's already loaded, it's a requirement of setCalendar().
......
Supports Markdown
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