Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-calendar] Set error if event cannot be loaded. Contr…
…ibutes to JB#10055

If an event query attempts to load data for an event from storage,
but the event data cannot be loaded, then the event has been deleted.
In this case, set an error so that the UI can display an appropriate
description to the user.
  • Loading branch information
chriadam committed Nov 16, 2020
1 parent f317834 commit 8ba27b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/calendareventquery.cpp
Expand Up @@ -37,7 +37,7 @@
#include "calendarutils.h"

CalendarEventQuery::CalendarEventQuery()
: mIsComplete(true), mOccurrence(0), mAttendeesCached(false)
: mIsComplete(true), mOccurrence(0), mAttendeesCached(false), mEventError(false)
{
connect(CalendarManager::instance(), SIGNAL(dataUpdated()), this, SLOT(refresh()));
connect(CalendarManager::instance(), SIGNAL(storageModified()), this, SLOT(refresh()));
Expand Down Expand Up @@ -161,7 +161,7 @@ void CalendarEventQuery::componentComplete()
refresh();
}

void CalendarEventQuery::doRefresh(CalendarData::Event event)
void CalendarEventQuery::doRefresh(CalendarData::Event event, bool eventError)
{
// The value of mUid may have changed, verify that we got what we asked for
if (event.isValid() && (event.uniqueId != mUid || event.recurrenceId != mRecurrenceId))
Expand Down Expand Up @@ -212,6 +212,16 @@ void CalendarEventQuery::doRefresh(CalendarData::Event event)
mAttendeesCached = true;
emit attendeesChanged();
}

if (mEventError != eventError) {
mEventError = eventError;
emit eventErrorChanged();
}
}

bool CalendarEventQuery::eventError() const
{
return mEventError;
}

KDateTime CalendarEventQuery::recurrenceId()
Expand Down
7 changes: 6 additions & 1 deletion src/calendareventquery.h
Expand Up @@ -100,6 +100,7 @@ class CalendarEventQuery : public QObject, public QQmlParserStatus
Q_PROPERTY(QObject *event READ event NOTIFY eventChanged)
Q_PROPERTY(QObject *occurrence READ occurrence NOTIFY occurrenceChanged)
Q_PROPERTY(QList<QObject*> attendees READ attendees NOTIFY attendeesChanged)
Q_PROPERTY(bool eventError READ eventError NOTIFY eventErrorChanged)

public:
CalendarEventQuery();
Expand All @@ -121,10 +122,12 @@ class CalendarEventQuery : public QObject, public QQmlParserStatus

QList<QObject*> attendees();

bool eventError() const;

virtual void classBegin();
virtual void componentComplete();

void doRefresh(CalendarData::Event event);
void doRefresh(CalendarData::Event event, bool eventError);

signals:
void uniqueIdChanged();
Expand All @@ -133,6 +136,7 @@ class CalendarEventQuery : public QObject, public QQmlParserStatus
void occurrenceChanged();
void attendeesChanged();
void startTimeChanged();
void eventErrorChanged();

// Indicates that the event UID has changed in database, event has been moved between notebooks.
// The property uniqueId will not be changed, the data pointer properties event and occurrence
Expand All @@ -151,6 +155,7 @@ private slots:
CalendarData::Event mEvent;
CalendarEventOccurrence *mOccurrence;
bool mAttendeesCached;
bool mEventError;
QList<CalendarData::Attendee> mAttendees;
};

Expand Down
12 changes: 11 additions & 1 deletion src/calendarmanager.cpp
Expand Up @@ -465,9 +465,19 @@ void CalendarManager::doAgendaAndQueryRefresh()
if (event.uniqueId.isEmpty()
&& !mLoadedQueries.contains(eventUid)
&& !missingUidList.contains(eventUid)) {
// we haven't yet loaded this event from storage.
missingUidList << eventUid;
query->doRefresh(event, false);
} else if (event.uniqueId.isEmpty() && mLoadedQueries.contains(eventUid)) {
// the event was unable to be loaded from storage,
// even though we have attempted to load its data.
// most likely, the event has been deleted.
query->doRefresh(event, true);
} else {
// we have loaded this event from storage.
// refresh the query based on the loaded event data.
query->doRefresh(event, false);
}
query->doRefresh(event);

if (mResetPending && !missingUidList.contains(eventUid))
missingUidList << eventUid;
Expand Down

0 comments on commit 8ba27b0

Please sign in to comment.