Skip to content

Commit

Permalink
Merge branch 'external_invitation_info' into 'master'
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-calendar] Add externalInvitation property to events. Contributes to JB#45600

See merge request mer-core/nemo-qml-plugin-calendar!40
  • Loading branch information
pvuorela committed Jun 14, 2019
2 parents fde267c + b880a3f commit 9e1dacf
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 36 deletions.
16 changes: 9 additions & 7 deletions src/calendardata.h
Expand Up @@ -29,18 +29,19 @@ struct Event {
QString description;
KDateTime startTime;
KDateTime endTime;
bool allDay;
bool allDay = false;
bool readOnly = false;
bool rsvp = false;
bool externalInvitation = false;
CalendarEvent::Recur recur;
QDate recurEndDate;
int reminder; // seconds; 15 minutes before event = +900, at time of event = 0, no reminder = negative value.
QString uniqueId;
KDateTime recurrenceId;
bool readonly;
QString location;
CalendarEvent::Secrecy secrecy;
QString calendarUid;
CalendarEvent::Response ownerStatus = CalendarEvent::ResponseUnspecified;
bool rsvp = false;

bool operator==(const Event& other) const
{
Expand Down Expand Up @@ -70,10 +71,11 @@ struct Notebook {

bool operator==(const Notebook other) const
{
return uid == other.uid && name == other.name && description == other.description &&
color == other.color && accountId == other.accountId && accountIcon == other.accountIcon &&
isDefault == other.isDefault && readOnly == other.readOnly && localCalendar == other.localCalendar &&
excluded == other.excluded;
return uid == other.uid && name == other.name && description == other.description
&& color == other.color && emailAddress == other.emailAddress
&& accountId == other.accountId && accountIcon == other.accountIcon
&& isDefault == other.isDefault && readOnly == other.readOnly && localCalendar == other.localCalendar
&& excluded == other.excluded;
}

bool operator!=(const Notebook other) const
Expand Down
9 changes: 7 additions & 2 deletions src/calendarevent.cpp
Expand Up @@ -107,9 +107,9 @@ QString CalendarEvent::color() const
return mManager->getNotebookColor(mManager->getEvent(mUniqueId, mRecurrenceId).calendarUid);
}

bool CalendarEvent::readonly() const
bool CalendarEvent::readOnly() const
{
return mManager->getEvent(mUniqueId, mRecurrenceId).readonly;
return mManager->getEvent(mUniqueId, mRecurrenceId).readOnly;
}

QString CalendarEvent::calendarUid() const
Expand Down Expand Up @@ -137,6 +137,11 @@ bool CalendarEvent::rsvp() const
return mManager->getEvent(mUniqueId, mRecurrenceId).rsvp;
}

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

bool CalendarEvent::sendResponse(int response)
{
return mManager->sendResponse(mManager->getEvent(mUniqueId, mRecurrenceId), (Response)response);
Expand Down
7 changes: 5 additions & 2 deletions src/calendarevent.h
Expand Up @@ -61,12 +61,13 @@ class CalendarEvent : public QObject
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(bool readOnly READ readOnly CONSTANT)
Q_PROPERTY(QString calendarUid READ calendarUid NOTIFY calendarUidChanged)
Q_PROPERTY(QString location READ location NOTIFY locationChanged)
Q_PROPERTY(CalendarEvent::Secrecy secrecy READ secrecy NOTIFY secrecyChanged)
Q_PROPERTY(CalendarEvent::Response ownerStatus READ ownerStatus NOTIFY ownerStatusChanged)
Q_PROPERTY(bool rsvp READ rsvp NOTIFY rsvpChanged)
Q_PROPERTY(bool externalInvitation READ externalInvitation NOTIFY externalInvitationChanged)

public:
enum Recur {
Expand Down Expand Up @@ -111,14 +112,15 @@ class CalendarEvent : public QObject
int reminder() const;
QString uniqueId() const;
QString color() const;
bool readonly() const;
bool readOnly() const;
QString calendarUid() const;
QString location() const;
KDateTime recurrenceId() const;
QString recurrenceIdString() const;
Secrecy secrecy() const;
Response ownerStatus() const;
bool rsvp() const;
bool externalInvitation() const;

Q_INVOKABLE bool sendResponse(int response);
Q_INVOKABLE QString vCalendar(const QString &prodId = QString()) const;
Expand All @@ -144,6 +146,7 @@ private slots:
void secrecyChanged();
void ownerStatusChanged();
void rsvpChanged();
void externalInvitationChanged();

private:
CalendarManager *mManager;
Expand Down
6 changes: 3 additions & 3 deletions src/calendareventmodification.cpp
Expand Up @@ -8,13 +8,13 @@ CalendarEventModification::CalendarEventModification(CalendarData::Event data, Q
{
}

CalendarEventModification::CalendarEventModification(QObject *parent) :
QObject(parent), m_attendeesSet(false)
CalendarEventModification::CalendarEventModification(QObject *parent)
: QObject(parent), m_attendeesSet(false)
{
m_event.recur = CalendarEvent::RecurOnce;
m_event.reminder = -1; // ReminderNone
m_event.allDay = false;
m_event.readonly = false;
m_event.readOnly = false;
m_event.startTime = KDateTime(QDateTime(), KDateTime::LocalZone);
m_event.endTime = KDateTime(QDateTime(), KDateTime::LocalZone);
}
Expand Down
7 changes: 4 additions & 3 deletions src/calendarmanager.cpp
Expand Up @@ -583,9 +583,7 @@ void CalendarManager::unRegisterInvitationQuery(CalendarInvitationQuery *query)
mInvitationQueryHash.remove(query);
}

void CalendarManager::findMatchingEventFinished(
const QString &invitationFile,
const CalendarData::Event &event)
void CalendarManager::findMatchingEventFinished(const QString &invitationFile, const CalendarData::Event &event)
{
QHash<CalendarInvitationQuery*, QString>::iterator it = mInvitationQueryHash.begin();
while (it != mInvitationQueryHash.end()) {
Expand Down Expand Up @@ -797,6 +795,9 @@ void CalendarManager::sendEventChangeSignals(const CalendarData::Event &newEvent
if (newEvent.rsvp != oldEvent.rsvp)
emit eventObject->rsvpChanged();

if (newEvent.externalInvitation != oldEvent.externalInvitation)
emit eventObject->externalInvitationChanged();

if (newEvent.ownerStatus != oldEvent.ownerStatus)
emit eventObject->ownerStatusChanged();
}
52 changes: 34 additions & 18 deletions src/calendarworker.cpp
Expand Up @@ -734,7 +734,8 @@ void CalendarWorker::loadData(const QList<CalendarData::Range> &ranges,
foreach (const KCalCore::Event::Ptr e, list) {
// The database may have changed after loading the events, make sure that the notebook
// of the event still exists.
if (mStorage->notebook(mCalendar->notebook(e)).isNull()) {
mKCal::Notebook::Ptr notebook = mStorage->notebook(mCalendar->notebook(e));
if (notebook.isNull()) {
// This may be a symptom of a deeper bug: if a sync adapter (or mkcal)
// doesn't delete events which belong to a deleted notebook, then the
// events will be "orphan" and need to be deleted.
Expand All @@ -756,7 +757,7 @@ void CalendarWorker::loadData(const QList<CalendarData::Range> &ranges,
continue;
}

CalendarData::Event event = createEventStruct(e);
CalendarData::Event event = createEventStruct(e, notebook);

if (!mSentEvents.contains(event.uniqueId, event.recurrenceId)) {
mSentEvents.insert(event.uniqueId, event.recurrenceId);
Expand All @@ -776,7 +777,8 @@ void CalendarWorker::loadData(const QList<CalendarData::Range> &ranges,
emit dataLoaded(ranges, uidList, events, occurrences, dailyOccurrences, reset);
}

CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr &e) const
CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr &e,
mKCal::Notebook::Ptr notebook) const
{
CalendarData::Event event;
event.uniqueId = e->uid();
Expand All @@ -788,11 +790,23 @@ CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr
event.endTime = e->dtEnd();
event.location = e->location();
event.secrecy = CalendarUtils::convertSecrecy(e);
event.readonly = mStorage->notebook(event.calendarUid)->isReadOnly();
event.readOnly = mStorage->notebook(event.calendarUid)->isReadOnly();
event.recur = CalendarUtils::convertRecurrence(e);
bool externalInvitation = false;
const QString &calendarOwnerEmail = getNotebookAddress(e);

KCalCore::Person::Ptr organizer = e->organizer();
if (!organizer.isNull()) {
QString organizerEmail = organizer->email();

if (!organizerEmail.isEmpty() && organizerEmail != calendarOwnerEmail
&& (notebook.isNull() || !notebook->sharedWith().contains(organizer->email()))) {
externalInvitation = true;
}
}
event.externalInvitation = externalInvitation;

KCalCore::Attendee::List attendees = e->attendees();
const QString &calendarOwnerEmail = getNotebookAddress(e);

foreach (KCalCore::Attendee::Ptr calAttendee, attendees) {
if (calAttendee->email() == calendarOwnerEmail) {
Expand Down Expand Up @@ -825,26 +839,28 @@ void CalendarWorker::loadNotebooks()

bool changed = mNotebooks.isEmpty();
for (int ii = 0; ii < notebooks.count(); ++ii) {
CalendarData::Notebook notebook = mNotebooks.value(notebooks.at(ii)->uid(), CalendarData::Notebook());
notebook.name = notebooks.at(ii)->name();
notebook.uid = notebooks.at(ii)->uid();
notebook.description = notebooks.at(ii)->description();
notebook.emailAddress = mKCal::ServiceHandler::instance().emailAddress(notebooks.at(ii), mStorage);
notebook.isDefault = notebooks.at(ii)->isDefault();
notebook.readOnly = notebooks.at(ii)->isReadOnly();
notebook.localCalendar = notebooks.at(ii)->isMaster()
&& !notebooks.at(ii)->isShared()
&& notebooks.at(ii)->pluginName().isEmpty();
mKCal::Notebook::Ptr mkNotebook = notebooks.at(ii);
CalendarData::Notebook notebook = mNotebooks.value(mkNotebook->uid(), CalendarData::Notebook());

notebook.name = mkNotebook->name();
notebook.uid = mkNotebook->uid();
notebook.description = mkNotebook->description();
notebook.emailAddress = mKCal::ServiceHandler::instance().emailAddress(mkNotebook, mStorage);
notebook.isDefault = mkNotebook->isDefault();
notebook.readOnly = mkNotebook->isReadOnly();
notebook.localCalendar = mkNotebook->isMaster()
&& !mkNotebook->isShared()
&& mkNotebook->pluginName().isEmpty();

notebook.excluded = settings.value("exclude/" + notebook.uid, false).toBool();

notebook.color = settings.value("colors/" + notebook.uid, QString()).toString();
if (notebook.color.isEmpty())
notebook.color = notebooks.at(ii)->color();
notebook.color = mkNotebook->color();
if (notebook.color.isEmpty())
notebook.color = defaultNotebookColors.at((nextDefaultNotebookColor++) % defaultNotebookColors.count());

QString accountStr = notebooks.at(ii)->account();
QString accountStr = mkNotebook->account();
if (!accountStr.isEmpty()) {
if (!mAccountManager) {
mAccountManager = new Accounts::Manager(this);
Expand All @@ -868,7 +884,7 @@ void CalendarWorker::loadNotebooks()
if (mNotebooks.contains(notebook.uid) && mNotebooks.value(notebook.uid) != notebook)
changed = true;

if (notebooks.at(ii)->isVisible()) {
if (mkNotebook->isVisible()) {
newNotebooks.insert(notebook.uid, notebook);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/calendarworker.h
Expand Up @@ -127,7 +127,8 @@ public slots:
const QString &notebookUid);
QString getNotebookAddress(const KCalCore::Event::Ptr &event) const;

CalendarData::Event createEventStruct(const KCalCore::Event::Ptr &event) const;
CalendarData::Event createEventStruct(const KCalCore::Event::Ptr &event,
mKCal::Notebook::Ptr notebook = mKCal::Notebook::Ptr()) const;
QHash<QString, CalendarData::EventOccurrence> eventOccurrences(const QList<CalendarData::Range> &ranges) const;
QHash<QDate, QStringList> dailyEventOccurrences(const QList<CalendarData::Range> &ranges,
const QMultiHash<QString, KDateTime> &allDay,
Expand Down

0 comments on commit 9e1dacf

Please sign in to comment.