Skip to content

Commit

Permalink
calendar: add calendar plugin skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
rburchell committed Mar 20, 2013
0 parents commit 438b611
Show file tree
Hide file tree
Showing 12 changed files with 651 additions and 0 deletions.
4 changes: 4 additions & 0 deletions calendar.pro
@@ -0,0 +1,4 @@
TEMPLATE = subdirs
SUBDIRS = src

tests.depends = src
46 changes: 46 additions & 0 deletions src/calendarabstractmodel.cpp
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2013 Jolla Ltd.
* Contact: Robin Burchell <robin.burchell@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#include "calendarabstractmodel.h"
#include "calendarevent.h"

NemoCalendarAbstractModel::NemoCalendarAbstractModel(QObject *parent)
: QAbstractListModel(parent)
{

}

NemoCalendarEvent *NemoCalendarAbstractModel::createEvent()
{
return new NemoCalendarEvent;
}

49 changes: 49 additions & 0 deletions src/calendarabstractmodel.h
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2013 Jolla Ltd.
* Contact: Robin Burchell <robin.burchell@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#ifndef CALENDARABSTRACTMODEL_H
#define CALENDARABSTRACTMODEL_H

#include <QAbstractListModel>

class NemoCalendarEvent;

class NemoCalendarAbstractModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit NemoCalendarAbstractModel(QObject *parent = 0);

Q_INVOKABLE NemoCalendarEvent *createEvent();
};

#endif // CALENDARABSTRACTMODEL_H
116 changes: 116 additions & 0 deletions src/calendaragendamodel.cpp
@@ -0,0 +1,116 @@
/*
* Copyright (C) 2013 Jolla Ltd.
* Contact: Robin Burchell <robin.burchell@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

// Qt
#include <QDebug>

// mkcal
#include <event.h>

#include "calendaragendamodel.h"
#include "calendarevent.h"
#include "calendardb.h"

NemoCalendarAgendaModel::NemoCalendarAgendaModel(QObject *parent)
: NemoCalendarAbstractModel(parent)
{
QHash<int,QByteArray> roles;
roles[EventObjectRole] = "event";
roles[SectionBucketRole] = "sectionBucket";
roles[NotebookColorRole] = "notebookColor";
setRoleNames(roles);
}

NemoCalendarAgendaModel::~NemoCalendarAgendaModel()
{
qDeleteAll(mEvents);
}

QDate NemoCalendarAgendaModel::startDate() const
{
return mStartDate;
}

void NemoCalendarAgendaModel::setStartDate(const QDate &startDate)
{
if (mStartDate == startDate)
return;

mStartDate = startDate;
emit startDateChanged();

// load from database
// TODO: this init code should only run once, probably
NemoCalendarDb::storage()->loadNotebookIncidences(NemoCalendarDb::storage()->defaultNotebook()->uid());

// TODO: we really need a centralised event cache
KCalCore::Event::List eventList = NemoCalendarDb::calendar()->rawEventsForDate(startDate, KDateTime::Spec(KDateTime::LocalZone), KCalCore::EventSortStartDate, KCalCore::SortDirectionAscending);
qDebug() << Q_FUNC_INFO << "Loaded " << eventList.count() << " events for " << startDate;

beginResetModel();
qDeleteAll(mEvents);
mEvents.clear();
mEvents.reserve(eventList.size());

foreach (const KCalCore::Event::Ptr &evt, eventList) {
NemoCalendarEvent *event = new NemoCalendarEvent(evt);
mEvents.append(event);
}

endResetModel();
}

int NemoCalendarAgendaModel::rowCount(const QModelIndex &index) const
{
if (index != QModelIndex())
return 0;

return mEvents.size();
}

QVariant NemoCalendarAgendaModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= mEvents.count())
return QVariant();

switch (role) {
case EventObjectRole:
return QVariant::fromValue<QObject *>(mEvents.at(index.row()));
case SectionBucketRole:
return mEvents.at(index.row())->startTime().date();
case NotebookColorRole:
return "blue"; // TODO: hardcoded, as we only support local events for now
default:
return QVariant();
}
}

70 changes: 70 additions & 0 deletions src/calendaragendamodel.h
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2013 Jolla Ltd.
* Contact: Robin Burchell <robin.burchell@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#ifndef CALENDARAGENDAMODEL_H
#define CALENDARAGENDAMODEL_H

#include <QDate>

#include "calendarabstractmodel.h"
class NemoCalendarEvent;

class NemoCalendarAgendaModel : public NemoCalendarAbstractModel
{
Q_OBJECT

public:
enum {
EventObjectRole = Qt::UserRole,
SectionBucketRole,
NotebookColorRole
};

explicit NemoCalendarAgendaModel(QObject *parent = 0);
virtual ~NemoCalendarAgendaModel();

Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged)
QDate startDate() const;
void setStartDate(const QDate &startDate);

int rowCount(const QModelIndex &index) const;
QVariant data(const QModelIndex &index, int role) const;

signals:
void startDateChanged();

private:
QDate mStartDate;
QList<NemoCalendarEvent *> mEvents;
};

#endif // CALENDARAGENDAMODEL_H
54 changes: 54 additions & 0 deletions src/calendardb.cpp
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2013 Jolla Ltd.
* Contact: Robin Burchell <robin.burchell@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#include "calendardb.h"

mKCal::ExtendedCalendar::Ptr &NemoCalendarDb::calendar()
{
static mKCal::ExtendedCalendar::Ptr ptr;
if (ptr)
return ptr;

ptr = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
return ptr;
}

mKCal::ExtendedStorage::Ptr &NemoCalendarDb::storage()
{
static mKCal::ExtendedStorage::Ptr ptr;
if (ptr)
return ptr;

ptr = calendar()->defaultStorage(calendar());
ptr->open();
return ptr;
}
46 changes: 46 additions & 0 deletions src/calendardb.h
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2013 Jolla Ltd.
* Contact: Robin Burchell <robin.burchell@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#ifndef CALENDARDB_H
#define CALENDARDB_H

#include <extendedcalendar.h>
#include <extendedstorage.h>

class NemoCalendarDb
{
public:
static mKCal::ExtendedCalendar::Ptr &calendar();
static mKCal::ExtendedStorage::Ptr &storage();
};

#endif // CALENDARDB_H

0 comments on commit 438b611

Please sign in to comment.