Commit 1321e535 authored by pvuorela's avatar pvuorela

Merge branch 'reminderAt' into 'master'

Add bindings for timed alarms, contributes to TJC#37226

See merge request !65
parents 98257778 34bfe1b0
......@@ -6,7 +6,7 @@ QT += qml dbus
QT -= gui
CONFIG += link_pkgconfig
PKGCONFIG += KF5CalendarCore libmkcal-qt5 libical accounts-qt5
PKGCONFIG += KF5CalendarCore libmkcal-qt5 accounts-qt5
HEADERS += \
calendardataservice.h \
......
......@@ -3,9 +3,8 @@ Name: nemo-qml-plugin-calendar-qt5
Summary: Calendar plugin for Nemo Mobile
Version: 0.6.13
Release: 1
Group: System/Libraries
License: BSD
URL: https://git.merproject.org/mer-core/nemo-qml-plugin-calendar
URL: https://git.sailfishos.org/mer-core/nemo-qml-plugin-calendar
Source0: %{name}-%{version}.tar.bz2
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Gui)
......@@ -13,7 +12,6 @@ BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Concurrent)
BuildRequires: pkgconfig(libmkcal-qt5)
BuildRequires: pkgconfig(KF5CalendarCore)
BuildRequires: pkgconfig(libical)
BuildRequires: pkgconfig(accounts-qt5)
%description
......@@ -21,7 +19,6 @@ BuildRequires: pkgconfig(accounts-qt5)
%package tests
Summary: QML calendar plugin tests
Group: System/Libraries
BuildRequires: pkgconfig(Qt5Test)
Requires: %{name} = %{version}-%{release}
......@@ -30,7 +27,6 @@ Requires: %{name} = %{version}-%{release}
%package lightweight
Summary: Calendar lightweight QML plugin
Group: System/Libraries
BuildRequires: pkgconfig(Qt5DBus)
%description lightweight
......@@ -39,7 +35,6 @@ BuildRequires: pkgconfig(Qt5DBus)
%package tools
Summary: Calendar import/export tool
License: BSD
Group: Applications/System
BuildRequires: pkgconfig(libmkcal-qt5)
BuildRequires: pkgconfig(KF5CalendarCore)
......@@ -53,7 +48,7 @@ BuildRequires: pkgconfig(KF5CalendarCore)
%qmake5
make %{?jobs:-j%jobs}
make %{?_smp_mflags}
%install
rm -rf %{buildroot}
......
......@@ -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,
......
......@@ -50,9 +50,6 @@
#include <KCalendarCore/RecurrenceRule>
#include <KCalendarCore/MemoryCalendar>
#include <libical/vobject.h>
#include <libical/vcaltmp.h>
// libaccounts-qt
#include <Accounts/Manager>
#include <Accounts/Provider>
......@@ -284,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) {
......@@ -419,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();
......@@ -442,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;
......@@ -891,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,
......
......@@ -9,7 +9,7 @@ QT -= gui
QMAKE_CXXFLAGS += -Werror
target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
PKGCONFIG += KF5CalendarCore libmkcal-qt5 libical accounts-qt5
PKGCONFIG += KF5CalendarCore libmkcal-qt5 accounts-qt5
INSTALLS += target
......
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