Skip to content

Commit

Permalink
Merge branch 'jb32993' into 'master'
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-calendar] Prevent flicker of attendees. Contributes to JB#32993

See merge request mer-core/nemo-qml-plugin-calendar!54
  • Loading branch information
chriadam committed Mar 30, 2020
2 parents 9c36ae2 + 1ba0729 commit daefd33
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
14 changes: 11 additions & 3 deletions src/calendardata.h
Expand Up @@ -87,11 +87,19 @@ struct Notebook {
typedef QPair<QDate,QDate> Range;

struct Attendee {
bool isOrganizer;
bool isOrganizer = false;
QString name;
QString email;
KCalCore::Attendee::Role participationRole;
KCalCore::Attendee::PartStat status;
KCalCore::Attendee::Role participationRole = KCalCore::Attendee::OptParticipant;
KCalCore::Attendee::PartStat status = KCalCore::Attendee::None;

bool operator==(const Attendee &other) const {
return isOrganizer == other.isOrganizer
&& name == other.name
&& email == other.email
&& participationRole == other.participationRole
&& status == other.status;
}
};

struct EmailContact {
Expand Down
25 changes: 16 additions & 9 deletions src/calendareventquery.cpp
Expand Up @@ -140,8 +140,11 @@ QObject *CalendarEventQuery::occurrence() const
QList<QObject*> CalendarEventQuery::attendees()
{
if (!mAttendeesCached) {
mAttendees = CalendarManager::instance()->getEventAttendees(mUid, mRecurrenceId);
mAttendeesCached = true;
bool resultValid = false;
mAttendees = CalendarManager::instance()->getEventAttendees(mUid, mRecurrenceId, &resultValid);
if (resultValid) {
mAttendeesCached = true;
}
}

return CalendarUtils::convertAttendeeList(mAttendees);
Expand Down Expand Up @@ -187,9 +190,8 @@ void CalendarEventQuery::doRefresh(CalendarData::Event event)
mOccurrence = 0;

if (mEvent.isValid()) {
CalendarEventOccurrence *occurrence = CalendarManager::instance()->getNextOccurrence(mUid,
mRecurrenceId,
mStartTime);
CalendarEventOccurrence *occurrence = CalendarManager::instance()->getNextOccurrence(
mUid, mRecurrenceId, mStartTime);
if (occurrence) {
mOccurrence = occurrence;
mOccurrence->setParent(this);
Expand All @@ -201,10 +203,15 @@ void CalendarEventQuery::doRefresh(CalendarData::Event event)
if (signalEventChanged)
emit eventChanged();

// always emit also attendee change signal
mAttendees.clear();
mAttendeesCached = false;
emit attendeesChanged();
// check if attendees have changed.
bool resultValid = false;
QList<CalendarData::Attendee> attendees = CalendarManager::instance()->getEventAttendees(
mUid, mRecurrenceId, &resultValid);
if (resultValid && mAttendees != attendees) {
mAttendees = attendees;
mAttendeesCached = true;
emit attendeesChanged();
}
}

KDateTime CalendarEventQuery::recurrenceId()
Expand Down
25 changes: 20 additions & 5 deletions src/calendarmanager.cpp
Expand Up @@ -702,13 +702,28 @@ CalendarEventOccurrence* CalendarManager::getNextOccurrence(const QString &uid,
return new CalendarEventOccurrence(eo.eventUid, eo.recurrenceId, eo.startTime, eo.endTime);
}

QList<CalendarData::Attendee> CalendarManager::getEventAttendees(const QString &uid, const KDateTime &recurrenceId)
QList<CalendarData::Attendee> CalendarManager::getEventAttendees(const QString &uid, const KDateTime &recurrenceId, bool *resultValid)
{
QList<CalendarData::Attendee> attendees;
QMetaObject::invokeMethod(mCalendarWorker, "getEventAttendees", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QList<CalendarData::Attendee>, attendees),
Q_ARG(QString, uid),
Q_ARG(KDateTime, recurrenceId));

// Not foolproof, since thread interleaving means we might
// receive a storageModified() signal on the worker thread
// while we're dispatching this call here.
// But, this will at least ensure that if we _know_ that
// the storage is not in loaded state, that we don't
// attempt to read the invalid data.
// The other alternative would be to cache all attendee
// info in the event struct immediately within
// CalendarWorker::createEventStruct(), however it was
// decided that it would be better to avoid the memory usage.
*resultValid = !(mLoadPending || mResetPending);
if (*resultValid) {
QMetaObject::invokeMethod(mCalendarWorker, "getEventAttendees", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QList<CalendarData::Attendee>, attendees),
Q_ARG(QString, uid),
Q_ARG(KDateTime, recurrenceId));
}

return attendees;
}

Expand Down
2 changes: 1 addition & 1 deletion src/calendarmanager.h
Expand Up @@ -111,7 +111,7 @@ class CalendarManager : public QObject
CalendarEventOccurrence* getNextOccurrence(const QString &uid, const KDateTime &recurrenceId,
const QDateTime &start);
// return attendees for given event, synchronous call
QList<CalendarData::Attendee> getEventAttendees(const QString &uid, const KDateTime &recurrenceId);
QList<CalendarData::Attendee> getEventAttendees(const QString &uid, const KDateTime &recurrenceId, bool *resultValid);

private slots:
void storageModifiedSlot(const QString &info);
Expand Down

0 comments on commit daefd33

Please sign in to comment.