summaryrefslogtreecommitdiff
path: root/rockworkd/libpebble/calendarevent.cpp
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2016-02-11 23:55:16 +0100
committerAndrew Branson <andrew.branson@cern.ch>2016-02-11 23:55:16 +0100
commit29aaea2d80a9eb1715b6cddfac2d2aacf76358bd (patch)
tree012795b6bec16c72f38d33cff46324c9a0225868 /rockworkd/libpebble/calendarevent.cpp
launchpad ~mzanetti/rockwork/trunk r87
Diffstat (limited to 'rockworkd/libpebble/calendarevent.cpp')
-rw-r--r--rockworkd/libpebble/calendarevent.cpp184
1 files changed, 184 insertions, 0 deletions
diff --git a/rockworkd/libpebble/calendarevent.cpp b/rockworkd/libpebble/calendarevent.cpp
new file mode 100644
index 0000000..ea99b56
--- /dev/null
+++ b/rockworkd/libpebble/calendarevent.cpp
@@ -0,0 +1,184 @@
+#include "calendarevent.h"
+
+#include <QSettings>
+#include <QFile>
+#include <QTimeZone>
+
+CalendarEvent::CalendarEvent():
+ m_uuid(QUuid::createUuid())
+{
+}
+
+bool CalendarEvent::isValid() const
+{
+ return !m_id.isNull();
+}
+
+QString CalendarEvent::id() const
+{
+ return m_id;
+}
+
+void CalendarEvent::setId(const QString &id)
+{
+ m_id = id;
+}
+
+QUuid CalendarEvent::uuid() const
+{
+ return m_uuid;
+}
+
+void CalendarEvent::generateNewUuid()
+{
+ m_uuid = QUuid::createUuid();
+}
+
+QString CalendarEvent::title() const
+{
+ return m_title;
+}
+
+void CalendarEvent::setTitle(const QString &title)
+{
+ m_title = title;
+}
+
+QString CalendarEvent::description() const
+{
+ return m_description;
+}
+
+void CalendarEvent::setDescription(const QString &description)
+{
+ m_description = description;
+}
+
+QDateTime CalendarEvent::startTime() const
+{
+ return m_startTime;
+}
+
+void CalendarEvent::setStartTime(const QDateTime &startTime)
+{
+ m_startTime = startTime;
+}
+
+QDateTime CalendarEvent::endTime() const
+{
+ return m_endTime;
+}
+
+void CalendarEvent::setEndTime(const QDateTime &endTime)
+{
+ m_endTime = endTime;
+}
+
+QString CalendarEvent::location() const
+{
+ return m_location;
+}
+
+void CalendarEvent::setLocation(const QString &location)
+{
+ m_location = location;
+}
+
+QString CalendarEvent::calendar() const
+{
+ return m_calendar;
+}
+
+void CalendarEvent::setCalendar(const QString &calendar)
+{
+ m_calendar = calendar;
+}
+
+QString CalendarEvent::comment() const
+{
+ return m_comment;
+}
+
+void CalendarEvent::setComment(const QString &comment)
+{
+ m_comment = comment;
+}
+
+QStringList CalendarEvent::guests() const
+{
+ return m_guests;
+}
+
+void CalendarEvent::setGuests(const QStringList &guests)
+{
+ m_guests = guests;
+}
+
+bool CalendarEvent::recurring() const
+{
+ return m_recurring;
+}
+
+void CalendarEvent::setRecurring(bool recurring)
+{
+ m_recurring = recurring;
+}
+
+bool CalendarEvent::operator==(const CalendarEvent &other) const
+{
+ // Storing a QDateTime to QSettings seems to lose time zone information. Lets ignore the time zone when
+ // comparing or we'll never find ourselves again.
+ QDateTime thisStartTime = m_startTime;
+ thisStartTime.setTimeZone(other.startTime().timeZone());
+ QDateTime thisEndTime = m_endTime;
+ thisEndTime.setTimeZone(other.endTime().timeZone());
+ return m_id == other.id()
+ && m_title == other.title()
+ && m_description == other.description()
+ && thisStartTime == other.startTime()
+ && thisEndTime == other.endTime()
+ && m_location == other.location()
+ && m_calendar == other.calendar()
+ && m_comment == other.comment()
+ && m_guests == other.guests()
+ && m_recurring == other.recurring();
+
+}
+
+void CalendarEvent::saveToCache(const QString &cachePath) const
+{
+ QSettings s(cachePath + "/calendarevent-" + m_uuid.toString(), QSettings::IniFormat);
+ s.setValue("id", m_id);
+ s.setValue("uuid", m_uuid);
+ s.setValue("title", m_title);
+ s.setValue("description", m_description);
+ s.setValue("startTime", m_startTime);
+ s.setValue("endTime", m_endTime);
+ s.setValue("location", m_location);
+ s.setValue("calendar", m_calendar);
+ s.setValue("comment", m_comment);
+ s.setValue("guests", m_guests);
+ s.setValue("recurring", m_recurring);
+}
+
+void CalendarEvent::loadFromCache(const QString &cachePath, const QString &uuid)
+{
+ m_uuid = uuid;
+ QSettings s(cachePath + "/calendarevent-" + m_uuid.toString(), QSettings::IniFormat);
+ m_id = s.value("id").toString();
+ m_title = s.value("title").toString();
+ m_description = s.value("description").toString();
+ m_startTime = s.value("startTime").toDateTime();
+ m_endTime = s.value("endTime").toDateTime();
+ m_location = s.value("location").toString();
+ m_calendar = s.value("calendar").toString();
+ m_comment = s.value("comment").toString();
+ m_guests = s.value("guests").toStringList();
+ m_recurring = s.value("recurring").toBool();
+}
+
+void CalendarEvent::removeFromCache(const QString &cachePath) const
+{
+ QFile::remove(cachePath + "/calendarevent-" + m_uuid.toString());
+}
+