Commit 34bfe1b0 authored by Damien Caliste's avatar Damien Caliste

[nemo-qml-plugin-calendar] Add possibility to use a reminder at a given time and day.

parent 31bd515f
......@@ -69,6 +69,7 @@ struct Event {
QDate recurEndDate;
CalendarEvent::Days recurWeeklyDays;
int reminder; // seconds; 15 minutes before event = +900, at time of event = 0, no reminder = negative value.
QDateTime reminderDateTime; // Valid when reminder is at a given date and time.
QString uniqueId;
QDateTime recurrenceId;
QString location;
......
......@@ -137,6 +137,11 @@ int CalendarEvent::reminder() const
return mManager->getEvent(mUniqueId, mRecurrenceId).reminder;
}
QDateTime CalendarEvent::reminderDateTime() const
{
return mManager->getEvent(mUniqueId, mRecurrenceId).reminderDateTime;
}
QString CalendarEvent::uniqueId() const
{
return mUniqueId;
......
......@@ -59,6 +59,7 @@ class CalendarEvent : public QObject
Q_PROPERTY(bool hasRecurEndDate READ hasRecurEndDate NOTIFY hasRecurEndDateChanged)
Q_PROPERTY(CalendarEvent::Days recurWeeklyDays READ recurWeeklyDays NOTIFY recurWeeklyDaysChanged)
Q_PROPERTY(int reminder READ reminder NOTIFY reminderChanged)
Q_PROPERTY(QDateTime reminderDateTime READ reminderDateTime NOTIFY reminderDateTimeChanged)
Q_PROPERTY(QString uniqueId READ uniqueId NOTIFY uniqueIdChanged)
Q_PROPERTY(QString recurrenceId READ recurrenceIdString CONSTANT)
Q_PROPERTY(QString color READ color NOTIFY colorChanged)
......@@ -137,6 +138,7 @@ public:
bool hasRecurEndDate() const;
Days recurWeeklyDays() const;
int reminder() const;
QDateTime reminderDateTime() const;
QString uniqueId() const;
QString color() const;
bool readOnly() const;
......@@ -166,6 +168,7 @@ signals:
void allDayChanged();
void recurChanged();
void reminderChanged();
void reminderDateTimeChanged();
void uniqueIdChanged();
void colorChanged();
void calendarUidChanged();
......
......@@ -220,6 +220,19 @@ void CalendarEventModification::setReminder(int seconds)
}
}
QDateTime CalendarEventModification::reminderDateTime() const
{
return m_event.reminderDateTime;
}
void CalendarEventModification::setReminderDateTime(const QDateTime &dateTime)
{
if (dateTime != m_event.reminderDateTime) {
m_event.reminderDateTime = dateTime;
emit reminderDateTimeChanged();
}
}
QString CalendarEventModification::location() const
{
return m_event.location;
......
......@@ -55,6 +55,7 @@ class CalendarEventModification : public QObject
Q_PROPERTY(bool hasRecurEndDate READ hasRecurEndDate NOTIFY hasRecurEndDateChanged)
Q_PROPERTY(QString recurrenceId READ recurrenceIdString CONSTANT)
Q_PROPERTY(int reminder READ reminder WRITE setReminder NOTIFY reminderChanged)
Q_PROPERTY(QDateTime reminderDateTime READ reminderDateTime WRITE setReminderDateTime NOTIFY reminderDateTimeChanged)
Q_PROPERTY(QString location READ location WRITE setLocation NOTIFY locationChanged)
Q_PROPERTY(QString calendarUid READ calendarUid WRITE setCalendarUid NOTIFY calendarUidChanged)
......@@ -94,6 +95,9 @@ public:
int reminder() const;
void setReminder(int seconds);
QDateTime reminderDateTime() const;
void setReminderDateTime(const QDateTime &dateTime);
QString location() const;
void setLocation(const QString &newLocation);
......@@ -114,6 +118,7 @@ signals:
void recurChanged();
void recurWeeklyDaysChanged();
void reminderChanged();
void reminderDateTimeChanged();
void locationChanged();
void recurEndDateChanged();
void hasRecurEndDateChanged();
......
......@@ -109,6 +109,11 @@ int CalendarImportEvent::reminder() const
return CalendarUtils::getReminder(mEvent);
}
QDateTime CalendarImportEvent::reminderDateTime() const
{
return mEvent ? CalendarUtils::getReminderDateTime(mEvent) : QDateTime();
}
QString CalendarImportEvent::uniqueId() const
{
if (!mEvent)
......
......@@ -51,6 +51,7 @@ class CalendarImportEvent : public QObject
Q_PROPERTY(CalendarEvent::Recur recur READ recur CONSTANT)
Q_PROPERTY(CalendarEvent::Days recurWeeklyDays READ recurWeeklyDays CONSTANT)
Q_PROPERTY(int reminder READ reminder CONSTANT)
Q_PROPERTY(QDateTime reminderDateTime READ reminderDateTime CONSTANT)
Q_PROPERTY(QString uniqueId READ uniqueId CONSTANT)
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(QString location READ location CONSTANT)
......@@ -73,6 +74,7 @@ public:
CalendarEvent::Recur recur();
CalendarEvent::Days recurWeeklyDays();
int reminder() const;
QDateTime reminderDateTime() const;
QString uniqueId() const;
QString color() const;
bool readOnly() const;
......
......@@ -138,12 +138,12 @@ int CalendarUtils::getReminder(const KCalendarCore::Event::Ptr &event)
KCalendarCore::Alarm::Ptr alarm;
int seconds = -1;
int seconds = -1; // Any negative values means "no reminder"
for (int ii = 0; ii < alarms.count(); ++ii) {
if (alarms.at(ii)->type() == KCalendarCore::Alarm::Procedure)
continue;
alarm = alarms.at(ii);
if (alarm) {
if (alarm && !alarm->hasTime()) {
KCalendarCore::Duration d = alarm->startOffset();
seconds = d.asSeconds() * -1; // backend stores as "offset in seconds to dtStart", we return "seconds before"
if (seconds >= 0) {
......@@ -156,6 +156,17 @@ int CalendarUtils::getReminder(const KCalendarCore::Event::Ptr &event)
return seconds;
}
QDateTime CalendarUtils::getReminderDateTime(const KCalendarCore::Event::Ptr &event)
{
for (const KCalendarCore::Alarm::Ptr &alarm : event->alarms()) {
if (alarm && alarm->type() == KCalendarCore::Alarm::Display && alarm->hasTime()) {
return alarm->time();
}
}
return QDateTime();
}
QList<CalendarData::Attendee> CalendarUtils::getEventAttendees(const KCalendarCore::Event::Ptr &event)
{
QList<CalendarData::Attendee> result;
......
......@@ -48,6 +48,7 @@ CalendarEvent::Recur convertRecurrence(const KCalendarCore::Event::Ptr &event);
CalendarEvent::Days convertDayPositions(const KCalendarCore::Event::Ptr &event);
CalendarEvent::Secrecy convertSecrecy(const KCalendarCore::Event::Ptr &event);
int getReminder(const KCalendarCore::Event::Ptr &event);
QDateTime getReminderDateTime(const KCalendarCore::Event::Ptr &event);
QList<CalendarData::Attendee> getEventAttendees(const KCalendarCore::Event::Ptr &event);
QList<QObject*> convertAttendeeList(const QList<CalendarData::Attendee> &list);
CalendarData::EventOccurrence getNextOccurrence(const KCalendarCore::Event::Ptr &event,
......
......@@ -281,7 +281,7 @@ void CalendarWorker::setEventData(KCalendarCore::Event::Ptr &event, const Calend
event->setDtEnd(eventData.endTime);
event->setAllDay(eventData.allDay);
event->setLocation(eventData.location);
setReminder(event, eventData.reminder);
setReminder(event, eventData.reminder, eventData.reminderDateTime);
setRecurrence(event, eventData.recur, eventData.recurWeeklyDays);
if (eventData.recur != CalendarEvent::RecurOnce) {
......@@ -416,12 +416,13 @@ bool CalendarWorker::setRecurrence(KCalendarCore::Event::Ptr &event, CalendarEve
return false;
}
bool CalendarWorker::setReminder(KCalendarCore::Event::Ptr &event, int seconds)
bool CalendarWorker::setReminder(KCalendarCore::Event::Ptr &event, int seconds, const QDateTime &dateTime)
{
if (!event)
return false;
if (CalendarUtils::getReminder(event) == seconds)
if (CalendarUtils::getReminder(event) == seconds
&& CalendarUtils::getReminderDateTime(event) == dateTime)
return false;
KCalendarCore::Alarm::List alarms = event->alarms();
......@@ -439,6 +440,11 @@ bool CalendarWorker::setReminder(KCalendarCore::Event::Ptr &event, int seconds)
// backend stores as "offset to dtStart", i.e negative if reminder before event.
alarm->setStartOffset(-1 * seconds);
alarm->setType(KCalendarCore::Alarm::Display);
} else if (dateTime.isValid()) {
KCalendarCore::Alarm::Ptr alarm = event->newAlarm();
alarm->setEnabled(true);
alarm->setTime(dateTime);
alarm->setType(KCalendarCore::Alarm::Display);
}
return true;
......@@ -888,6 +894,7 @@ CalendarData::Event CalendarWorker::createEventStruct(const KCalendarCore::Event
event.recurEndDate = defaultRule->endDt().date();
}
event.reminder = CalendarUtils::getReminder(e);
event.reminderDateTime = CalendarUtils::getReminderDateTime(e);
event.startTime = e->dtStart();
return event;
}
......
......@@ -119,7 +119,7 @@ private:
bool saveExcludeNotebook(const QString &notebookUid, bool exclude);
bool setRecurrence(KCalendarCore::Event::Ptr &event, CalendarEvent::Recur recur, CalendarEvent::Days days);
bool setReminder(KCalendarCore::Event::Ptr &event, int reminderSeconds);
bool setReminder(KCalendarCore::Event::Ptr &event, int seconds, const QDateTime &dateTime);
bool needSendCancellation(KCalendarCore::Event::Ptr &event) const;
void updateEventAttendees(KCalendarCore::Event::Ptr event, bool newEvent,
const QList<CalendarData::EmailContact> &required,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment