summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--calendarevent.cpp119
-rw-r--r--calendarevent.h57
-rw-r--r--calendarsource.cpp113
-rw-r--r--calendarsource.h54
-rw-r--r--calendarsource_p.h52
-rw-r--r--libwatchfish.pri18
-rw-r--r--libwatchfish.pro2
-rw-r--r--musiccontroller_p.h20
8 files changed, 427 insertions, 8 deletions
diff --git a/calendarevent.cpp b/calendarevent.cpp
new file mode 100644
index 0000000..3e97243
--- /dev/null
+++ b/calendarevent.cpp
@@ -0,0 +1,119 @@
+#include "calendarevent.h"
+
+namespace watchfish
+{
+
+struct CalendarEventData : public QSharedData
+{
+ QString uid;
+ QDateTime start;
+ QDateTime end;
+ QString title;
+ QString location;
+ QString description;
+ bool allDay;
+};
+
+CalendarEvent::CalendarEvent() : data(new CalendarEventData)
+{
+}
+
+CalendarEvent::CalendarEvent(const CalendarEvent &rhs) : data(rhs.data)
+{
+}
+
+CalendarEvent &CalendarEvent::operator=(const CalendarEvent &rhs)
+{
+ if (this != &rhs)
+ data.operator=(rhs.data);
+ return *this;
+}
+
+CalendarEvent::~CalendarEvent()
+{
+}
+
+QString CalendarEvent::uid() const
+{
+ return data->uid;
+}
+
+void CalendarEvent::setUid(const QString &v)
+{
+ if (data->uid != v) {
+ data->uid = v;
+ }
+}
+
+
+QDateTime CalendarEvent::start() const
+{
+ return data->start;
+}
+
+void CalendarEvent::setStart(const QDateTime &v)
+{
+ if (data->start != v) {
+ data->start = v;
+ }
+}
+
+QDateTime CalendarEvent::end() const
+{
+ return data->end;
+}
+
+void CalendarEvent::setEnd(const QDateTime &v)
+{
+ if (data->end != v) {
+ data->end = v;
+ }
+}
+
+QString CalendarEvent::title() const
+{
+ return data->title;
+}
+
+void CalendarEvent::setTitle(const QString &v)
+{
+ if (data->title != v) {
+ data->title = v;
+ }
+}
+
+QString CalendarEvent::location() const
+{
+ return data->location;
+}
+
+void CalendarEvent::setLocation(const QString &v)
+{
+ if (data->location != v) {
+ data->location = v;
+ }
+}
+
+QString CalendarEvent::description() const
+{
+ return data->description;
+}
+
+void CalendarEvent::setDescription(const QString &v)
+{
+ if (data->description != v) {
+ data->description = v;
+ }
+}
+
+bool CalendarEvent::allDay() const {
+ return data->allDay;
+}
+
+void CalendarEvent::setAllDay(bool allDay) {
+ if (data->allDay != allDay) {
+ data->allDay = allDay;
+ }
+}
+
+}
diff --git a/calendarevent.h b/calendarevent.h
new file mode 100644
index 0000000..40aa2fc
--- /dev/null
+++ b/calendarevent.h
@@ -0,0 +1,57 @@
+#ifndef CALENDAREVENT_H
+#define CALENDAREVENT_H
+
+#include <QSharedDataPointer>
+#include <QDateTime>
+
+namespace watchfish
+{
+
+struct CalendarEventData;
+
+class CalendarEvent
+{
+ Q_GADGET
+
+ Q_PROPERTY(QString uid READ uid WRITE setUid)
+ Q_PROPERTY(QDateTime start READ start WRITE setStart)
+ Q_PROPERTY(QDateTime end READ end WRITE setEnd)
+ Q_PROPERTY(QString title READ title WRITE setTitle)
+ Q_PROPERTY(QString location READ location WRITE setLocation)
+ Q_PROPERTY(QString description READ description WRITE setDescription)
+ Q_PROPERTY(bool allDay READ allDay WRITE setAllDay)
+
+public:
+ CalendarEvent();
+ CalendarEvent(const CalendarEvent &);
+ CalendarEvent &operator=(const CalendarEvent &);
+ ~CalendarEvent();
+
+ QString uid() const;
+ void setUid(const QString &uid);
+
+ QDateTime start() const;
+ void setStart(const QDateTime &state);
+
+ QDateTime end() const;
+ void setEnd(const QDateTime &end);
+
+ QString title() const;
+ void setTitle(const QString &v);
+
+ QString location() const;
+ void setLocation(const QString &v);
+
+ QString description() const;
+ void setDescription(const QString &v);
+
+ bool allDay() const;
+ void setAllDay(bool allDay);
+
+private:
+ QSharedDataPointer<CalendarEventData> data;
+};
+
+}
+
+#endif // CALENDAREVENT_H
diff --git a/calendarsource.cpp b/calendarsource.cpp
new file mode 100644
index 0000000..8c3ad34
--- /dev/null
+++ b/calendarsource.cpp
@@ -0,0 +1,113 @@
+/*
+ * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs.
+ * Copyright (C) 2016 Javier S. Pedro <dev.git@javispedro.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "calendarsource.h"
+#include "calendarsource_p.h"
+
+namespace watchfish
+{
+
+Q_LOGGING_CATEGORY(calendarSourceCat, "watchfish-CalendarSource")
+
+CalendarSourcePrivate::CalendarSourcePrivate(CalendarSource *q)
+ : calendar(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone())),
+ calendarStorage(calendar->defaultStorage(calendar)),
+ q_ptr(q)
+{
+ calendarStorage->registerObserver(this);
+ if (!calendarStorage->open()) {
+ qCWarning(calendarSourceCat) << "Cannot open calendar database";
+ }
+}
+
+CalendarSourcePrivate::~CalendarSourcePrivate()
+{
+ calendarStorage->unregisterObserver(this);
+}
+
+void CalendarSourcePrivate::storageModified(mKCal::ExtendedStorage *storage, const QString &info)
+{
+ Q_Q(CalendarSource);
+ Q_UNUSED(storage);
+ qCDebug(calendarSourceCat) << "Storage modified:" << info;
+ emit q->changed();
+}
+
+void CalendarSourcePrivate::storageProgress(mKCal::ExtendedStorage *storage, const QString &info)
+{
+ Q_UNUSED(storage);
+ Q_UNUSED(info);
+ // Nothing to do
+}
+
+void CalendarSourcePrivate::storageFinished(mKCal::ExtendedStorage *storage, bool error, const QString &info)
+{
+ Q_UNUSED(storage);
+ Q_UNUSED(error);
+ Q_UNUSED(info);
+ // Nothing to do
+}
+
+CalendarEvent CalendarSourcePrivate::convertToEvent(const mKCal::ExtendedCalendar::ExpandedIncidence &expanded)
+{
+ const KCalCore::Incidence::Ptr &incidence = expanded.second;
+ CalendarEvent event;
+
+ event.setUid(incidence->uid());
+
+ event.setStart(expanded.first.dtStart);
+ event.setEnd(expanded.first.dtEnd);
+
+ event.setAllDay(incidence->allDay());
+ event.setTitle(incidence->summary());
+ event.setLocation(incidence->location());
+
+ return event;
+}
+
+CalendarSource::CalendarSource(QObject *parent)
+ : QObject(parent), d_ptr(new CalendarSourcePrivate(this))
+{
+}
+
+CalendarSource::~CalendarSource()
+{
+ delete d_ptr;
+}
+
+QList<CalendarEvent> CalendarSource::fetchEvents(const QDate &start, const QDate &end,
+ bool startInclusive, bool endInclusive)
+{
+ Q_D(CalendarSource);
+ int count = 0;
+ count += d->calendarStorage->loadRecurringIncidences();
+ qCDebug(calendarSourceCat) << "Loaded" << count << "recurring events";
+ count += d->calendarStorage->load(start, end);
+ qCDebug(calendarSourceCat) << "Loaded" << count << "events total";
+
+ QList<CalendarEvent> events;
+ QVector<mKCal::ExtendedCalendar::ExpandedIncidence> incidences = d->calendar->rawExpandedEvents(start, end, startInclusive, endInclusive);
+ Q_FOREACH(const mKCal::ExtendedCalendar::ExpandedIncidence &expanded, incidences) {
+ events.append(d->convertToEvent(expanded));
+ }
+
+ qCDebug(calendarSourceCat) << "Returning" << events.size() << "events";
+ return events;
+}
+
+}
diff --git a/calendarsource.h b/calendarsource.h
new file mode 100644
index 0000000..981c497
--- /dev/null
+++ b/calendarsource.h
@@ -0,0 +1,54 @@
+/*
+ * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs.
+ * Copyright (C) 2016 Javier S. Pedro <dev.git@javispedro.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WATCHFISH_CALENDARSOURCE_H
+#define WATCHFISH_CALENDARSOURCE_H
+
+#include <QtCore/QLoggingCategory>
+
+#include "calendarevent.h"
+
+namespace watchfish
+{
+
+Q_DECLARE_LOGGING_CATEGORY(calendarSourceCat)
+
+class CalendarSourcePrivate;
+
+class CalendarSource : public QObject
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(CalendarSource)
+
+public:
+ explicit CalendarSource(QObject *parent = 0);
+ ~CalendarSource();
+
+ Q_INVOKABLE QList<CalendarEvent> fetchEvents(const QDate &start, const QDate &end,
+ bool startInclusive = false, bool endInclusive = false);
+
+signals:
+ void changed();
+
+private:
+ CalendarSourcePrivate * const d_ptr;
+};
+
+}
+
+#endif // WATCHFISH_CALENDARSOURCE_H
diff --git a/calendarsource_p.h b/calendarsource_p.h
new file mode 100644
index 0000000..97b7ef2
--- /dev/null
+++ b/calendarsource_p.h
@@ -0,0 +1,52 @@
+/*
+ * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs.
+ * Copyright (C) 2016 Javier S. Pedro <dev.git@javispedro.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WATCHFISH_CALENDARSOURCE_P_H
+#define WATCHFISH_CALENDARSOURCE_P_H
+
+#include <extendedstorage.h>
+#include "calendarsource.h"
+
+namespace watchfish
+{
+
+class CalendarSourcePrivate : public QObject, public mKCal::ExtendedStorageObserver
+{
+ Q_OBJECT
+
+public:
+ explicit CalendarSourcePrivate(CalendarSource *q);
+ ~CalendarSourcePrivate();
+
+ mKCal::ExtendedCalendar::Ptr calendar;
+ mKCal::ExtendedStorage::Ptr calendarStorage;
+
+ void storageModified(mKCal::ExtendedStorage *storage, const QString &info) Q_DECL_OVERRIDE;
+ void storageProgress(mKCal::ExtendedStorage *storage, const QString &info) Q_DECL_OVERRIDE;
+ void storageFinished(mKCal::ExtendedStorage *storage, bool error, const QString &info) Q_DECL_OVERRIDE;
+
+ static CalendarEvent convertToEvent(const mKCal::ExtendedCalendar::ExpandedIncidence &expanded);
+
+private:
+ CalendarSource * const q_ptr;
+ Q_DECLARE_PUBLIC(CalendarSource)
+};
+
+}
+
+#endif // WATCHFISH_CALENDARSOURCE_P_H
diff --git a/libwatchfish.pri b/libwatchfish.pri
index eb1fb7d..6ff0728 100644
--- a/libwatchfish.pri
+++ b/libwatchfish.pri
@@ -2,18 +2,24 @@ CONFIG += link_pkgconfig
contains(WATCHFISH_FEATURES, notificationmonitor) {
PKGCONFIG += dbus-1
- HEADERS += $$PWD/notificationmonitor.h $$PWD/notificationmonitor_p.h $$PWD/notification.h
- SOURCES += $$PWD/notificationmonitor.cpp $$PWD/notification.cpp
+ HEADERS += $$PWD/notificationmonitor.h $$PWD/notificationmonitor_p.h $$PWD/notification.h
+ SOURCES += $$PWD/notificationmonitor.cpp $$PWD/notification.cpp
}
contains(WATCHFISH_FEATURES, walltime) {
PKGCONFIG += timed-qt5
- HEADERS += $$PWD/walltimemonitor.h $$PWD/walltimemonitor_p.h
- SOURCES += $$PWD/walltimemonitor.cpp
+ HEADERS += $$PWD/walltimemonitor.h $$PWD/walltimemonitor_p.h
+ SOURCES += $$PWD/walltimemonitor.cpp
}
contains(WATCHFISH_FEATURES, music) {
PKGCONFIG += mpris-qt5
- HEADERS += $$PWD/musiccontroller.h $$PWD/musiccontroller_p.h
- SOURCES += $$PWD/musiccontroller.cpp
+ HEADERS += $$PWD/musiccontroller.h $$PWD/musiccontroller_p.h
+ SOURCES += $$PWD/musiccontroller.cpp
+}
+
+contains(WATCHFISH_FEATURES, calendar) {
+ PKGCONFIG += libmkcal-qt5 libkcalcoren-qt5
+ HEADERS += $$PWD/calendarsource.h $$PWD/calendarsource_p.h $$PWD/calendarevent.h
+ SOURCES += $$PWD/calendarsource.cpp $$PWD/calendarevent.cpp
}
diff --git a/libwatchfish.pro b/libwatchfish.pro
index 8935a77..18313a4 100644
--- a/libwatchfish.pro
+++ b/libwatchfish.pro
@@ -4,5 +4,5 @@ TEMPLATE = lib
CONFIG += staticlib
QT += dbus
-WATCHFISH_FEATURES = notificationmonitor walltime music
+WATCHFISH_FEATURES = notificationmonitor walltime music calendar
include(libwatchfish.pri)
diff --git a/musiccontroller_p.h b/musiccontroller_p.h
index dd26ff0..9ade33a 100644
--- a/musiccontroller_p.h
+++ b/musiccontroller_p.h
@@ -1,3 +1,21 @@
+/*
+ * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs.
+ * Copyright (C) 2016 Javier S. Pedro <dev.git@javispedro.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef WATCHFISH_MUSICCONTROLLER_P_H
#define WATCHFISH_MUSICCONTROLLER_P_H
@@ -14,7 +32,7 @@ class MusicControllerPrivate : public QObject
Q_OBJECT
public:
- MusicControllerPrivate(MusicController *q);
+ explicit MusicControllerPrivate(MusicController *q);
~MusicControllerPrivate();
public: