Skip to content

Commit

Permalink
[nemo-qml-plugin-calendar] Added possibility to send accept/reject re…
Browse files Browse the repository at this point in the history
…sponse from the calendar. Contributes to JB#42474

Right now it works only with accounts which are setting RSVP properly (Google account is not setting this value).
  • Loading branch information
sergkashin committed Nov 15, 2018
1 parent 1ac9cf0 commit fd6c474
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rpm/nemo-qml-plugin-calendar-qt5.spec
@@ -1,7 +1,7 @@
Name: nemo-qml-plugin-calendar-qt5

Summary: Calendar plugin for Nemo Mobile
Version: 0.2.22
Version: 0.3.6
Release: 1
Group: System/Libraries
License: BSD
Expand Down
5 changes: 5 additions & 0 deletions src/calendardata.h
Expand Up @@ -39,6 +39,8 @@ struct Event {
QString location;
NemoCalendarEvent::Secrecy secrecy;
QString calendarUid;
NemoCalendarEvent::Response ownerStatus = NemoCalendarEvent::ResponseUnspecified;
bool rsvp = false;

bool operator==(const Event& other) const
{
Expand All @@ -56,6 +58,7 @@ struct Notebook {
QString uid;
QString description;
QString color;
QString emailAddress;
int accountId;
QUrl accountIcon;
bool isDefault;
Expand All @@ -82,10 +85,12 @@ struct Notebook {
typedef QPair<QDate,QDate> Range;

struct Attendee {
bool isOwner;
bool isOrganizer;
QString name;
QString email;
KCalCore::Attendee::Role participationRole;
KCalCore::Attendee::PartStat status;
};

}
Expand Down
15 changes: 15 additions & 0 deletions src/calendarevent.cpp
Expand Up @@ -127,6 +127,21 @@ NemoCalendarEvent::Secrecy NemoCalendarEvent::secrecy() const
return mManager->getEvent(mUniqueId, mRecurrenceId).secrecy;
}

NemoCalendarEvent::Response NemoCalendarEvent::ownerStatus() const
{
return mManager->getEvent(mUniqueId, mRecurrenceId).ownerStatus;
}

bool NemoCalendarEvent::rsvp() const
{
return mManager->getEvent(mUniqueId, mRecurrenceId).rsvp;
}

bool NemoCalendarEvent::sendResponse(int response)
{
return mManager->sendResponse(mManager->getEvent(mUniqueId, mRecurrenceId), (Response)response);
}

KDateTime NemoCalendarEvent::recurrenceId() const
{
return mRecurrenceId;
Expand Down
30 changes: 27 additions & 3 deletions src/calendarevent.h
Expand Up @@ -48,23 +48,27 @@ class NemoCalendarEvent : public QObject
Q_ENUMS(TimeSpec)
Q_ENUMS(Secrecy)
Q_ENUMS(Response)
Q_ENUMS(ParticipantStatus)
Q_ENUMS(AttendeeRole)

Q_PROPERTY(QString displayLabel READ displayLabel NOTIFY displayLabelChanged)
Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
Q_PROPERTY(QDateTime startTime READ startTime NOTIFY startTimeChanged)
Q_PROPERTY(QDateTime endTime READ endTime NOTIFY endTimeChanged)
Q_PROPERTY(bool allDay READ allDay NOTIFY allDayChanged)
Q_PROPERTY(Recur recur READ recur NOTIFY recurChanged)
Q_PROPERTY(NemoCalendarEvent::Recur recur READ recur NOTIFY recurChanged)
Q_PROPERTY(QDateTime recurEndDate READ recurEndDate NOTIFY recurEndDateChanged)
Q_PROPERTY(bool hasRecurEndDate READ hasRecurEndDate NOTIFY hasRecurEndDateChanged)
Q_PROPERTY(Reminder reminder READ reminder NOTIFY reminderChanged)
Q_PROPERTY(NemoCalendarEvent::Reminder reminder READ reminder NOTIFY reminderChanged)
Q_PROPERTY(QString uniqueId READ uniqueId NOTIFY uniqueIdChanged)
Q_PROPERTY(QString recurrenceId READ recurrenceIdString CONSTANT)
Q_PROPERTY(QString color READ color NOTIFY colorChanged)
Q_PROPERTY(bool readonly READ readonly CONSTANT)
Q_PROPERTY(QString calendarUid READ calendarUid NOTIFY calendarUidChanged)
Q_PROPERTY(QString location READ location NOTIFY locationChanged)
Q_PROPERTY(Secrecy secrecy READ secrecy NOTIFY secrecyChanged)
Q_PROPERTY(NemoCalendarEvent::Secrecy secrecy READ secrecy NOTIFY secrecyChanged)
Q_PROPERTY(NemoCalendarEvent::Response ownerStatus READ ownerStatus NOTIFY ownerStatusChanged)
Q_PROPERTY(bool rsvp READ rsvp NOTIFY rsvpChanged)

public:
enum Recur {
Expand Down Expand Up @@ -107,6 +111,21 @@ class NemoCalendarEvent : public QObject
ResponseDecline
};

enum ParticipantStatus {
NeedsAction,
Accepted,
Declined,
Tentative,
Delegated
};

enum AttendeeRole {
ReqParticipant,
OptParticipant,
NonParticipant,
Chair
};

NemoCalendarEvent(NemoCalendarManager *manager, const QString &uid, const KDateTime &recurrenceId);
~NemoCalendarEvent();

Expand All @@ -127,7 +146,10 @@ class NemoCalendarEvent : public QObject
KDateTime recurrenceId() const;
QString recurrenceIdString() const;
Secrecy secrecy() const;
Response ownerStatus() const;
bool rsvp() const;

Q_INVOKABLE bool sendResponse(int response);
Q_INVOKABLE QString vCalendar(const QString &prodId = QString()) const;

private slots:
Expand All @@ -149,6 +171,8 @@ private slots:
void recurEndDateChanged();
void hasRecurEndDateChanged();
void secrecyChanged();
void ownerStatusChanged();
void rsvpChanged();

private:
NemoCalendarManager *mManager;
Expand Down
9 changes: 9 additions & 0 deletions src/calendareventmodification.cpp
Expand Up @@ -141,6 +141,15 @@ void NemoCalendarEventModification::unsetRecurEndDate()
setRecurEndDate(QDateTime());
}

QString NemoCalendarEventModification::recurrenceIdString() const
{
if (m_event.recurrenceId.isValid()) {
return m_event.recurrenceId.toString();
} else {
return QString();
}
}

NemoCalendarEvent::Reminder NemoCalendarEventModification::reminder() const
{
return m_event.reminder;
Expand Down
3 changes: 3 additions & 0 deletions src/calendareventmodification.h
Expand Up @@ -19,6 +19,7 @@ class NemoCalendarEventModification : public QObject
Q_PROPERTY(NemoCalendarEvent::Recur recur READ recur WRITE setRecur NOTIFY recurChanged)
Q_PROPERTY(QDateTime recurEndDate READ recurEndDate NOTIFY recurEndDateChanged)
Q_PROPERTY(bool hasRecurEndDate READ hasRecurEndDate NOTIFY hasRecurEndDateChanged)
Q_PROPERTY(QString recurrenceId READ recurrenceIdString CONSTANT)
Q_PROPERTY(NemoCalendarEvent::Reminder reminder READ reminder WRITE setReminder NOTIFY reminderChanged)
Q_PROPERTY(QString location READ location WRITE setLocation NOTIFY locationChanged)
Q_PROPERTY(QString calendarUid READ calendarUid WRITE setCalendarUid NOTIFY calendarUidChanged)
Expand Down Expand Up @@ -51,6 +52,8 @@ class NemoCalendarEventModification : public QObject
Q_INVOKABLE void setRecurEndDate(const QDateTime &dateTime);
Q_INVOKABLE void unsetRecurEndDate();

QString recurrenceIdString() const;

NemoCalendarEvent::Reminder reminder() const;
void setReminder(NemoCalendarEvent::Reminder);

Expand Down
22 changes: 21 additions & 1 deletion src/calendarimportevent.cpp
Expand Up @@ -34,6 +34,9 @@

#include "calendareventoccurrence.h"
#include "calendarutils.h"
#include "calendarmanager.h"

#include <QDebug>

CalendarImportEvent::CalendarImportEvent(KCalCore::Event::Ptr event)
: QObject(),
Expand Down Expand Up @@ -134,7 +137,8 @@ QList<QObject *> CalendarImportEvent::attendees() const
if (!mEvent)
return QList<QObject *>();

return NemoCalendarUtils::convertAttendeeList(NemoCalendarUtils::getEventAttendees(mEvent));
// TODO: ownerEmail to be fixed later when invitation creation is done in calendar
return NemoCalendarUtils::convertAttendeeList(NemoCalendarUtils::getEventAttendees(mEvent, QString()));
}

NemoCalendarEvent::Secrecy CalendarImportEvent::secrecy() const
Expand Down Expand Up @@ -170,6 +174,22 @@ void CalendarImportEvent::setColor(const QString &color)
emit colorChanged();
}

NemoCalendarEvent::Response CalendarImportEvent::ownerStatus() const
{
return NemoCalendarEvent::ResponseUnspecified;
}

bool CalendarImportEvent::rsvp() const
{
return false;
}

bool CalendarImportEvent::sendResponse(int response)
{
Q_UNUSED(response)
return false;
}

QObject *CalendarImportEvent::nextOccurrence()
{
if (!mEvent)
Expand Down
11 changes: 11 additions & 0 deletions src/calendarimportevent.h
Expand Up @@ -59,6 +59,9 @@ class CalendarImportEvent : public QObject
Q_PROPERTY(QString organizerEmail READ organizerEmail CONSTANT)
Q_PROPERTY(NemoCalendarEvent::Secrecy secrecy READ secrecy CONSTANT)

Q_PROPERTY(NemoCalendarEvent::Response ownerStatus READ ownerStatus NOTIFY ownerStatusChanged)
Q_PROPERTY(bool rsvp READ rsvp NOTIFY rsvpChanged)

public:
CalendarImportEvent(KCalCore::Event::Ptr event);

Expand All @@ -80,11 +83,19 @@ class CalendarImportEvent : public QObject

void setColor(const QString &color);

NemoCalendarEvent::Response ownerStatus() const;
bool rsvp() const;

Q_INVOKABLE bool sendResponse(int response);

public slots:
QObject *nextOccurrence();

signals:
void colorChanged();
void ownerStatusChanged();
void attendeeListChanged();
void rsvpChanged();

private:
KCalCore::Event::Ptr mEvent;
Expand Down
16 changes: 16 additions & 0 deletions src/calendarmanager.cpp
Expand Up @@ -549,6 +549,16 @@ NemoCalendarData::Event NemoCalendarManager::getEvent(const QString &uid, const
return NemoCalendarData::Event();
}

bool NemoCalendarManager::sendResponse(const NemoCalendarData::Event &eventData, NemoCalendarEvent::Response response)
{
bool result;
QMetaObject::invokeMethod(mCalendarWorker, "sendResponse", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(NemoCalendarData::Event, eventData),
Q_ARG(NemoCalendarEvent::Response, response));
return result;
}

void NemoCalendarManager::scheduleInvitationQuery(NemoCalendarInvitationQuery *query, const QString &invitationFile)
{
mInvitationQueryHash.insert(query, invitationFile);
Expand Down Expand Up @@ -770,4 +780,10 @@ void NemoCalendarManager::sendEventChangeSignals(const NemoCalendarData::Event &

if (newEvent.startTime != oldEvent.startTime)
emit eventObject->startTimeChanged();

if (newEvent.rsvp != oldEvent.rsvp)
emit eventObject->rsvpChanged();

if (newEvent.ownerStatus != oldEvent.ownerStatus)
emit eventObject->ownerStatusChanged();
}
1 change: 1 addition & 0 deletions src/calendarmanager.h
Expand Up @@ -76,6 +76,7 @@ class NemoCalendarManager : public QObject

// Event
NemoCalendarData::Event getEvent(const QString& uid, const KDateTime &recurrenceId);
bool sendResponse(const NemoCalendarData::Event &eventData, NemoCalendarEvent::Response response);

// Notebooks
QList<NemoCalendarData::Notebook> notebooks();
Expand Down
42 changes: 41 additions & 1 deletion src/calendarutils.cpp
Expand Up @@ -38,6 +38,10 @@
#include <icalformat.h>
#include <vcalformat.h>

//mkcal
#include <servicehandler.h>

// Qt
#include <QFile>
#include <QUrl>
#include <QString>
Expand Down Expand Up @@ -143,7 +147,7 @@ NemoCalendarEvent::Reminder NemoCalendarUtils::getReminder(const KCalCore::Event
}
}

QList<NemoCalendarData::Attendee> NemoCalendarUtils::getEventAttendees(const KCalCore::Event::Ptr &event)
QList<NemoCalendarData::Attendee> NemoCalendarUtils::getEventAttendees(const KCalCore::Event::Ptr &event, const QString &ownerEmail)
{
QList<NemoCalendarData::Attendee> result;
KCalCore::Person::Ptr calOrganizer = event->organizer();
Expand All @@ -154,13 +158,15 @@ QList<NemoCalendarData::Attendee> NemoCalendarUtils::getEventAttendees(const KCa
organizer.isOrganizer = true;
organizer.name = calOrganizer->name();
organizer.email = calOrganizer->email();
organizer.isOwner = organizer.email == ownerEmail;
organizer.participationRole = KCalCore::Attendee::ReqParticipant;
result.append(organizer);
}

KCalCore::Attendee::List attendees = event->attendees();
NemoCalendarData::Attendee attendee;
attendee.isOrganizer = false;
attendee.isOwner = false;

foreach (KCalCore::Attendee::Ptr calAttendee, attendees) {
attendee.name = calAttendee->name();
Expand All @@ -169,6 +175,10 @@ QList<NemoCalendarData::Attendee> NemoCalendarUtils::getEventAttendees(const KCa
// avoid duplicate info
continue;
}
attendee.isOwner = attendee.email == ownerEmail;
if (attendee.isOwner) {
attendee.status = calAttendee->status();
}
attendee.participationRole = calAttendee->role();
result.append(attendee);
}
Expand Down Expand Up @@ -270,3 +280,33 @@ bool NemoCalendarUtils::importFromIcsRawData(const QByteArray &icsData,

return ok;
}

NemoCalendarEvent::Response NemoCalendarUtils::convertPartStat(KCalCore::Attendee::PartStat status)
{
switch (status) {
case KCalCore::Attendee::Accepted:
return NemoCalendarEvent::ResponseAccept;
case KCalCore::Attendee::Declined:
return NemoCalendarEvent::ResponseDecline;
case KCalCore::Attendee::Tentative:
return NemoCalendarEvent::ResponseTentative;
case KCalCore::Attendee::NeedsAction:
case KCalCore::Attendee::None:
default:
return NemoCalendarEvent::ResponseUnspecified;
}
}

KCalCore::Attendee::PartStat NemoCalendarUtils::convertResponse(NemoCalendarEvent::Response response)
{
switch (response) {
case NemoCalendarEvent::ResponseAccept:
return KCalCore::Attendee::Accepted;
case NemoCalendarEvent::ResponseTentative:
return KCalCore::Attendee::Tentative;
case NemoCalendarEvent::ResponseDecline:
return KCalCore::Attendee::Declined;
default:
return KCalCore::Attendee::NeedsAction;
}
}
4 changes: 3 additions & 1 deletion src/calendarutils.h
Expand Up @@ -46,12 +46,14 @@ NemoCalendarEvent::Recur convertRecurrence(const KCalCore::Event::Ptr &event);
NemoCalendarEvent::Secrecy convertSecrecy(const KCalCore::Event::Ptr &event);
int getReminderSeconds(const KCalCore::Event::Ptr &event, bool *hasReminder);
NemoCalendarEvent::Reminder getReminder(const KCalCore::Event::Ptr &event);
QList<NemoCalendarData::Attendee> getEventAttendees(const KCalCore::Event::Ptr &event);
QList<NemoCalendarData::Attendee> getEventAttendees(const KCalCore::Event::Ptr &event, const QString &ownerEmail);
QList<QObject*> convertAttendeeList(const QList<NemoCalendarData::Attendee> &list);
NemoCalendarData::EventOccurrence getNextOccurrence(const KCalCore::Event::Ptr &event,
const QDateTime &start = QDateTime::currentDateTime());
bool importFromFile(const QString &fileName, KCalCore::Calendar::Ptr calendar);
bool importFromIcsRawData(const QByteArray &icsData, KCalCore::Calendar::Ptr calendar);
NemoCalendarEvent::Response convertPartStat(KCalCore::Attendee::PartStat status);
KCalCore::Attendee::PartStat convertResponse(NemoCalendarEvent::Response response);

} // namespace NemoCalendarUtils

Expand Down

0 comments on commit fd6c474

Please sign in to comment.