Skip to content

Commit

Permalink
Merge branch 'jb46554' into 'master'
Browse files Browse the repository at this point in the history
Use ResponseType if available to show calendar attendance

See merge request mer-core/nemo-qml-plugin-calendar!47
  • Loading branch information
llewelld committed Jan 13, 2020
2 parents 69d36da + d44e8e9 commit 8b6b4c1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/calendarutils.cpp
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (c) 2015-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* Contact: Petri M. Gerdt <petri.gerdt@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
Expand Down Expand Up @@ -301,3 +303,22 @@ KCalCore::Attendee::PartStat CalendarUtils::convertResponse(CalendarEvent::Respo
return KCalCore::Attendee::NeedsAction;
}
}

CalendarEvent::Response CalendarUtils::convertResponseType(const QString &responseType)
{
// QString::toInt() conversion defaults to 0 on failure
switch (responseType.toInt()) {
case 1: // OrganizerResponseType (Organizer's acceptance is implicit)
case 3: // AcceptedResponseType
return CalendarEvent::ResponseAccept;
case 2: // TentativeResponseType
return CalendarEvent::ResponseTentative;
case 4: // DeclinedResponseType
return CalendarEvent::ResponseDecline;
case -1: // ResponseTypeUnset
case 0: // NoneResponseType
case 5: // NotRespondedResponseType
default:
return CalendarEvent::ResponseUnspecified;
}
}
5 changes: 4 additions & 1 deletion src/calendarutils.h
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (c) 2015-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* Contact: Petri M. Gerdt <petri.gerdt@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
Expand Down Expand Up @@ -53,6 +55,7 @@ bool importFromFile(const QString &fileName, KCalCore::Calendar::Ptr calendar);
bool importFromIcsRawData(const QByteArray &icsData, KCalCore::Calendar::Ptr calendar);
CalendarEvent::Response convertPartStat(KCalCore::Attendee::PartStat status);
KCalCore::Attendee::PartStat convertResponse(CalendarEvent::Response response);
CalendarEvent::Response convertResponseType(const QString &responseType);

} // namespace CalendarUtils

Expand Down
16 changes: 14 additions & 2 deletions src/calendarworker.cpp
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2014 Jolla Ltd.
* Copyright (c) 2014-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* Contact: Petri M. Gerdt <petri.gerdt@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
Expand Down Expand Up @@ -806,11 +808,21 @@ CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr
}
event.externalInvitation = externalInvitation;

// It would be good to set the attendance status directly in the event within the plugin,
// however in some cases the account email and owner attendee email won't necessarily match
// (e.g. in the case where server-side aliases are defined but unknown to the plugin).
// So we handle this here to avoid "missing" some status changes due to owner email mismatch.
// This defaults to QString() -> ResponseUnspecified in case the property is undefined
event.ownerStatus = CalendarUtils::convertResponseType(e->nonKDECustomProperty("X-EAS-RESPONSE-TYPE"));

KCalCore::Attendee::List attendees = e->attendees();

foreach (KCalCore::Attendee::Ptr calAttendee, attendees) {
if (calAttendee->email() == calendarOwnerEmail) {
event.ownerStatus = CalendarUtils::convertPartStat(calAttendee->status());
if (CalendarUtils::convertPartStat(calAttendee->status()) != CalendarEvent::ResponseUnspecified) {
// Override the ResponseType
event.ownerStatus = CalendarUtils::convertPartStat(calAttendee->status());
}
//TODO: KCalCore::Attendee::RSVP() returns false even if response was requested for some accounts like Google.
// We can use attendee role until the problem is not fixed (probably in Google plugin).
// To be updated later when google account support for responses is added.
Expand Down
1 change: 1 addition & 0 deletions src/src.pro
Expand Up @@ -6,6 +6,7 @@ CONFIG += qt plugin hide_symbols

QT += qml concurrent
QT -= gui
QMAKE_CXXFLAGS += -Werror

target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 libical accounts-qt5
Expand Down

0 comments on commit 8b6b4c1

Please sign in to comment.