Skip to content

Commit

Permalink
[nemo-qml-plugin-calendar] Only support custom reminder times. Contri…
Browse files Browse the repository at this point in the history
…butes to JB#33108

Previously, we supported "quantized" reminders (predefined reminder
offsets) as well as custom reminder times.

This commit removes support for quantized reminder times, since all
such reminders can be perfectly represented with a "custom" reminder
time anyway.

It also changes the default granularity of custom reminders to
"seconds" since that is the most granular and what is supported
by the backend anyway.
  • Loading branch information
Chris Adams committed Jan 11, 2019
1 parent 4ebbb3a commit 3e3d190
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 207 deletions.
3 changes: 1 addition & 2 deletions src/calendardata.h
Expand Up @@ -32,8 +32,7 @@ struct Event {
bool allDay;
NemoCalendarEvent::Recur recur;
QDate recurEndDate;
NemoCalendarEvent::Reminder reminder;
int customReminder; // minutes
int reminder; // seconds; 15 minutes before event = +900, at time of event = 0, no reminder = negative value.
QString uniqueId;
KDateTime recurrenceId;
bool readonly;
Expand Down
7 changes: 1 addition & 6 deletions src/calendarevent.cpp
Expand Up @@ -92,16 +92,11 @@ bool NemoCalendarEvent::hasRecurEndDate() const
return mManager->getEvent(mUniqueId, mRecurrenceId).recurEndDate.isValid();
}

NemoCalendarEvent::Reminder NemoCalendarEvent::reminder() const
int NemoCalendarEvent::reminder() const
{
return mManager->getEvent(mUniqueId, mRecurrenceId).reminder;
}

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

QString NemoCalendarEvent::uniqueId() const
{
return mUniqueId;
Expand Down
20 changes: 2 additions & 18 deletions src/calendarevent.h
Expand Up @@ -59,8 +59,7 @@ class NemoCalendarEvent : public QObject
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(NemoCalendarEvent::Reminder reminder READ reminder NOTIFY reminderChanged)
Q_PROPERTY(int customReminder READ customReminder NOTIFY customReminderChanged)
Q_PROPERTY(int 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)
Expand All @@ -82,19 +81,6 @@ class NemoCalendarEvent : public QObject
RecurCustom
};

enum Reminder {
ReminderNone,
ReminderTime,
Reminder5Min,
Reminder15Min,
Reminder30Min,
Reminder1Hour,
Reminder2Hour,
Reminder1Day,
Reminder2Day,
ReminderCustom
};

enum TimeSpec {
SpecLocalZone,
SpecClockTime
Expand Down Expand Up @@ -139,8 +125,7 @@ class NemoCalendarEvent : public QObject
Recur recur() const;
QDateTime recurEndDate() const;
bool hasRecurEndDate() const;
Reminder reminder() const;
int customReminder() const;
int reminder() const;
QString uniqueId() const;
QString color() const;
bool readonly() const;
Expand All @@ -167,7 +152,6 @@ private slots:
void allDayChanged();
void recurChanged();
void reminderChanged();
void customReminderChanged();
void uniqueIdChanged();
void colorChanged();
void calendarUidChanged();
Expand Down
24 changes: 5 additions & 19 deletions src/calendareventmodification.cpp
Expand Up @@ -10,8 +10,7 @@ NemoCalendarEventModification::NemoCalendarEventModification(QObject *parent) :
QObject(parent)
{
m_event.recur = NemoCalendarEvent::RecurOnce;
m_event.reminder = NemoCalendarEvent::ReminderNone;
m_event.customReminder = 0;
m_event.reminder = -1; // ReminderNone
m_event.allDay = false;
m_event.readonly = false;
m_event.startTime = KDateTime(QDateTime(), KDateTime::LocalZone);
Expand Down Expand Up @@ -151,32 +150,19 @@ QString NemoCalendarEventModification::recurrenceIdString() const
}
}

NemoCalendarEvent::Reminder NemoCalendarEventModification::reminder() const
int NemoCalendarEventModification::reminder() const
{
return m_event.reminder;
}

void NemoCalendarEventModification::setReminder(NemoCalendarEvent::Reminder reminder)
void NemoCalendarEventModification::setReminder(int seconds)
{
if (reminder != m_event.reminder) {
m_event.reminder = reminder;
if (seconds != m_event.reminder) {
m_event.reminder = seconds;
emit reminderChanged();
}
}

int NemoCalendarEventModification::customReminder() const
{
return m_event.customReminder;
}

void NemoCalendarEventModification::setCustomReminder(int minutes)
{
if (minutes != m_event.customReminder) {
m_event.customReminder = minutes;
emit customReminderChanged();
}
}

QString NemoCalendarEventModification::location() const
{
return m_event.location;
Expand Down
11 changes: 3 additions & 8 deletions src/calendareventmodification.h
Expand Up @@ -20,8 +20,7 @@ class NemoCalendarEventModification : public QObject
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(int customReminder READ customReminder WRITE setCustomReminder NOTIFY customReminderChanged)
Q_PROPERTY(int 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 @@ -55,11 +54,8 @@ class NemoCalendarEventModification : public QObject

QString recurrenceIdString() const;

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

int customReminder() const;
void setCustomReminder(int minutes);
int reminder() const;
void setReminder(int seconds);

QString location() const;
void setLocation(const QString &newLocation);
Expand All @@ -78,7 +74,6 @@ class NemoCalendarEventModification : public QObject
void allDayChanged();
void recurChanged();
void reminderChanged();
void customReminderChanged();
void locationChanged();
void recurEndDateChanged();
void hasRecurEndDateChanged();
Expand Down
29 changes: 4 additions & 25 deletions src/calendarimportevent.cpp
Expand Up @@ -93,35 +93,14 @@ NemoCalendarEvent::Recur CalendarImportEvent::recur()
return NemoCalendarUtils::convertRecurrence(mEvent);
}

NemoCalendarEvent::Reminder CalendarImportEvent::reminder() const
int CalendarImportEvent::reminder() const
{
if (!mEvent)
return NemoCalendarEvent::ReminderNone;

// note: returns seconds before event, so 15 minutes before = 900.
// zero value means "reminder at time of the event".
// negative value means "no reminder".
return NemoCalendarUtils::getReminder(mEvent);
}

int CalendarImportEvent::customReminder() const
{
if (reminder() == NemoCalendarEvent::ReminderNone) {
return 0; // FIXME: this doesn't know how to say "no reminder"
}

// note: returns minutes before event, so 15 minutes before = 15
return NemoCalendarUtils::getCustomReminder(mEvent);
}

int CalendarImportEvent::reminderSeconds() const
{
if (reminder() == NemoCalendarEvent::ReminderNone) {
return 0; // FIXME: this doesn't know how to say "no reminder"
}

// note: returns seconds after event, so 15 minutes before = -900
bool hasReminder = false;
return NemoCalendarUtils::getReminderSeconds(mEvent, &hasReminder);
}

QString CalendarImportEvent::uniqueId() const
{
if (!mEvent)
Expand Down
8 changes: 2 additions & 6 deletions src/calendarimportevent.h
Expand Up @@ -49,9 +49,7 @@ class CalendarImportEvent : public QObject
Q_PROPERTY(QDateTime endTime READ endTime CONSTANT)
Q_PROPERTY(bool allDay READ allDay CONSTANT)
Q_PROPERTY(NemoCalendarEvent::Recur recur READ recur CONSTANT)
Q_PROPERTY(NemoCalendarEvent::Reminder reminder READ reminder CONSTANT)
Q_PROPERTY(int customReminder READ customReminder CONSTANT)
Q_PROPERTY(int reminderSeconds READ reminderSeconds CONSTANT)
Q_PROPERTY(int reminder READ reminder 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)
Expand All @@ -72,9 +70,7 @@ class CalendarImportEvent : public QObject
QDateTime endTime() const;
bool allDay() const;
NemoCalendarEvent::Recur recur();
NemoCalendarEvent::Reminder reminder() const;
int customReminder() const; // minutes
int reminderSeconds() const;
int reminder() const;
QString uniqueId() const;
QString color() const;
QString location() const;
Expand Down
4 changes: 0 additions & 4 deletions src/calendarmanager.cpp
Expand Up @@ -51,7 +51,6 @@ NemoCalendarManager::NemoCalendarManager() :
qRegisterMetaType<KDateTime>("KDateTime");
qRegisterMetaType<QList<KDateTime> >("QList<KDateTime>");
qRegisterMetaType<NemoCalendarEvent::Recur>("NemoCalendarEvent::Recur");
qRegisterMetaType<NemoCalendarEvent::Reminder>("NemoCalendarEvent::Reminder");
qRegisterMetaType<QHash<QString,NemoCalendarData::EventOccurrence> >("QHash<QString,NemoCalendarData::EventOccurrence>");
qRegisterMetaType<NemoCalendarData::Event>("NemoCalendarData::Event");
qRegisterMetaType<QMultiHash<QString,NemoCalendarData::Event> >("QMultiHash<QString,NemoCalendarData::Event>");
Expand Down Expand Up @@ -778,9 +777,6 @@ void NemoCalendarManager::sendEventChangeSignals(const NemoCalendarData::Event &
if (newEvent.reminder != oldEvent.reminder)
emit eventObject->reminderChanged();

if (newEvent.customReminder != oldEvent.customReminder)
emit eventObject->customReminderChanged();

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

Expand Down
54 changes: 10 additions & 44 deletions src/calendarutils.cpp
Expand Up @@ -88,62 +88,28 @@ NemoCalendarEvent::Secrecy NemoCalendarUtils::convertSecrecy(const KCalCore::Eve
}
}

int NemoCalendarUtils::getReminderSeconds(const KCalCore::Event::Ptr &event, bool *hasReminder)
int NemoCalendarUtils::getReminder(const KCalCore::Event::Ptr &event)
{
KCalCore::Alarm::List alarms = event->alarms();

KCalCore::Alarm::Ptr alarm;

int seconds = -1;
for (int ii = 0; ii < alarms.count(); ++ii) {
if (alarms.at(ii)->type() == KCalCore::Alarm::Procedure)
continue;
alarm = alarms.at(ii);
if (alarm) {
KCalCore::Duration d = alarm->startOffset();
seconds = d.asSeconds() * -1; // backend stores as "offset in seconds to dtStart", we return "seconds before"
if (seconds >= 0) {
break;
}
}
break;
}

if (!alarm) {
*hasReminder = false;
return 0;
}

KCalCore::Duration d = alarm->startOffset();
*hasReminder = true;
return d.asSeconds();
}

int NemoCalendarUtils::getCustomReminder(const KCalCore::Event::Ptr &event)
{
bool hasReminder = false;
int sec = getReminderSeconds(event, &hasReminder);

if (!hasReminder) {
return 0;
}

return -1 * sec / 60; // inverse of customReminderToDuration
}

NemoCalendarEvent::Reminder NemoCalendarUtils::getReminder(const KCalCore::Event::Ptr &event)
{
bool hasReminder = false;
int sec = getReminderSeconds(event, &hasReminder);

if (!hasReminder) {
return NemoCalendarEvent::ReminderNone;
}

switch (sec) {
case 0: return NemoCalendarEvent::ReminderTime;
case (-5 * 60): return NemoCalendarEvent::Reminder5Min;
case (-15 * 60): return NemoCalendarEvent::Reminder15Min;
case (-30 * 60): return NemoCalendarEvent::Reminder30Min;
case (-60 * 60): return NemoCalendarEvent::Reminder1Hour;
case (-2 * 60 * 60): return NemoCalendarEvent::Reminder2Hour;
case (-24 * 60 * 60): return NemoCalendarEvent::Reminder1Day;
case (-2 * 24 * 60 * 60): return NemoCalendarEvent::Reminder2Day;
default: return (sec > 0) ? NemoCalendarEvent::ReminderCustom
: NemoCalendarEvent::ReminderNone;
}
return seconds;
}

QList<NemoCalendarData::Attendee> NemoCalendarUtils::getEventAttendees(const KCalCore::Event::Ptr &event, const QString &ownerEmail)
Expand Down
4 changes: 1 addition & 3 deletions src/calendarutils.h
Expand Up @@ -44,9 +44,7 @@ namespace NemoCalendarUtils {

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);
int getCustomReminder(const KCalCore::Event::Ptr &event);
int getReminder(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,
Expand Down

0 comments on commit 3e3d190

Please sign in to comment.