[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [plasma-framework] src/declarativeimports/calendar: [calendar] Add plugin system for Calendar events
From:       Martin Klapetek <mklapetek () kde ! org>
Date:       2015-11-16 16:55:20
Message-ID: E1ZyN3o-0006OB-0G () scm ! kde ! org
[Download RAW message or body]

Git commit fe0384f0d4152e622b203385bd968657a3650d2c by Martin Klapetek.
Committed on 16/11/2015 at 16:46.
Pushed by mklapetek into branch 'master'.

[calendar] Add plugin system for Calendar events

This adds a simple plugin interface that can be subclassed
and provide events integration with Plasma Calendar applet.

It's asynchronous and I've kept it deliberately simple.
For now the Calendar tells the plugins which date range
is being displayed, the plugins load the data and then
emit the dataReady() signal containing the events.

The events are stored in a multihash for quick access
by the Calendar's agenda part but also for overall
easy-to-use (eg. in teh model data()).

The event data is stored in EventData class, which has
a pretty self-explanatory members, except perhaps the
"isMinor" property. The intention with this is to support
namedays, where in some countries the calendars have
different name every day. This is just a minor holiday
and as such should not mark the calendar grid, otherwise
the whole grid would be in a different color.

Putting the interface here might raise the question of
depending on plasma-framework, but plugins provided by
KDE can go to plasma-workspace and other 3rd party ones
would just have to live with it. I don't think it will
be a problem but if it turns out it is, we can rethink
the placement.

REVIEW: 125817
CCBUG: 349676
CHANGELOG: Allow plugins to supply event data to Calendar applet

M  +4    -3    src/declarativeimports/calendar/CMakeLists.txt
M  +3    -2    src/declarativeimports/calendar/calendarplugin.cpp
M  +164  -14   src/declarativeimports/calendar/daysmodel.cpp
M  +23   -1    src/declarativeimports/calendar/daysmodel.h
A  +76   -0    src/declarativeimports/calendar/eventdatadecorator.cpp     [License: \
GPL (v2+)] A  +60   -0    src/declarativeimports/calendar/eventdatadecorator.h     \
[License: GPL (v2+)] A  +58   -0    \
src/declarativeimports/calendar/plasmacalendarintegration/CMakeLists.txt A  +5    -0  \
src/declarativeimports/calendar/plasmacalendarintegration/PlasmaCalendarIntegrationConfig.cmake.in
 C  +13   -17   src/declarativeimports/calendar/plasmacalendarintegration/calendareventsplugin.cpp \
[from: src/declarativeimports/calendar/calendarplugin.cpp - 050% similarity] A  +233  \
-0    src/declarativeimports/calendar/plasmacalendarintegration/calendareventsplugin.h \
[License: GPL (v2+)] A  +170  -0    \
src/declarativeimports/calendar/plasmacalendarintegration/eventdata_p.cpp     \
[License: GPL (v2+)] A  +37   -0    \
src/declarativeimports/calendar/plasmacalendarintegration/plasmacalendarintegration_export.h \
[License: LGPL (v2+)]

http://commits.kde.org/plasma-framework/fe0384f0d4152e622b203385bd968657a3650d2c

diff --git a/src/declarativeimports/calendar/CMakeLists.txt \
b/src/declarativeimports/calendar/CMakeLists.txt index 40ead91..7497bda 100644
--- a/src/declarativeimports/calendar/CMakeLists.txt
+++ b/src/declarativeimports/calendar/CMakeLists.txt
@@ -7,6 +7,7 @@ set(calendar_SRCS
     #calendarroleproxymodel.cpp
     #datetimerangefiltermodel.cpp
     daysmodel.cpp
+    eventdatadecorator.cpp
 )
 
 add_library(calendarplugin SHARED ${calendar_SRCS})
@@ -16,11 +17,11 @@ target_link_libraries(calendarplugin
     Qt5::Quick
     Qt5::Qml
     Qt5::Gui
-    ${KDEPIMLIBS_AKONADI_LIBS}
-    ${KDEPIMLIBS_KCALCORE_LIBS}
-    ${KDEPIMLIBS_AKONADI_CALENDAR_LIBS}
+    KF5::I18n
+    plasmacalendarintegration
 )
 
 install(TARGETS calendarplugin DESTINATION \
${KDE_INSTALL_QMLDIR}/org/kde/plasma/calendar)  install(DIRECTORY qml/ DESTINATION \
${KDE_INSTALL_QMLDIR}/org/kde/plasma/calendar)  
+add_subdirectory(plasmacalendarintegration)
diff --git a/src/declarativeimports/calendar/calendarplugin.cpp \
b/src/declarativeimports/calendar/calendarplugin.cpp index bafe80c..a4014bd 100644
--- a/src/declarativeimports/calendar/calendarplugin.cpp
+++ b/src/declarativeimports/calendar/calendarplugin.cpp
@@ -20,6 +20,8 @@
 #include "calendarplugin.h"
 #include "calendardata.h"
 #include "calendar.h"
+#include "eventdatadecorator.h"
+
 #include <QtQml>
 #include <QAbstractItemModel>
 #include <QAbstractListModel>
@@ -29,10 +31,9 @@ void CalendarPlugin::registerTypes(const char *uri)
     Q_ASSERT(uri == QLatin1String("org.kde.plasma.calendar"));
     qmlRegisterType<CalendarData>(uri, 2, 0, "CalendarData");
     qmlRegisterType<Calendar>(uri, 2, 0, "Calendar");
-//   qmlRegisterType<CalendarData>(uri, 1, 0, "CalendarData");
-//    qmlRegisterType<CalendarData>(uri, 1, 0, "Calendar");
     qmlRegisterType<QAbstractItemModel>();
     qmlRegisterType<QAbstractListModel>();
+    qmlRegisterUncreatableType<EventDataDecorator>();
 }
 
 //Q_EXPORT_PLUGIN2(calendarplugin, CalendarPlugin)
diff --git a/src/declarativeimports/calendar/daysmodel.cpp \
b/src/declarativeimports/calendar/daysmodel.cpp index 2d059a8..6572321 100644
--- a/src/declarativeimports/calendar/daysmodel.cpp
+++ b/src/declarativeimports/calendar/daysmodel.cpp
@@ -18,25 +18,74 @@
 */
 
 #include "daysmodel.h"
+
 #include <QDebug>
 #include <QByteArray>
+#include <QPluginLoader>
+#include <QDir>
+#include <QCoreApplication>
 
 DaysModel::DaysModel(QObject *parent) :
-    QAbstractListModel(parent)
+    QAbstractListModel(parent),
+    m_agendaNeedsUpdate(false)
 {
+    QString pluginPath;
+
+    const QStringList paths = QCoreApplication::libraryPaths();
+    Q_FOREACH (const QString &libraryPath, paths) {
+        const QString path(libraryPath + QStringLiteral("/plasmacalendarplugins"));
+        QDir dir(path);
+
+        if (!dir.exists()) {
+            continue;
+        }
+
+        QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
+        Q_FOREACH (const QString &fileName, entryList) {
+            QPluginLoader loader(dir.absoluteFilePath(fileName));
+
+            if (!loader.load()) {
+                qWarning() << "Could not create Plasma Calendar Plugin: " << \
pluginPath; +                qWarning() << loader.errorString();
+                continue;
+            }
+
+            QObject *obj = loader.instance();
+            if (obj) {
+                Plasma::CalendarEventsPlugin *eventsPlugin = \
qobject_cast<Plasma::CalendarEventsPlugin*>(obj); +                if (eventsPlugin) \
{ +                    qDebug() << "Adding Calendar plugin" << eventsPlugin;
+                    connect(eventsPlugin, &Plasma::CalendarEventsPlugin::dataReady,
+                            this, &DaysModel::onDataReady);
+                    connect(eventsPlugin, \
&Plasma::CalendarEventsPlugin::eventModified, +                            this, \
&DaysModel::onEventModified); +                    connect(eventsPlugin, \
&Plasma::CalendarEventsPlugin::eventRemoved, +                            this, \
&DaysModel::onEventRemoved); +                    m_eventPlugins << eventsPlugin;
+                } else {
+                    // not our/valid plugin, so unload it
+                    loader.unload();
+                }
+            } else {
+                loader.unload();
+            }
+        }
+    }
+
     QHash<int, QByteArray> roleNames;
 
-    roleNames.insert(isCurrent, "isCurrent");
-    //roleNames.insert(containsHolidayItems,   "containsHolidayItems");
-    //roleNames.insert(containsEventItems,     "containsEventItems");
-    // roleNames.insert(containsTodoItems,      "containsTodoItems");
-    // roleNames.insert(containsJournalItems,   "containsJournalItems");
+    roleNames.insert(isCurrent,              "isCurrent");
+    roleNames.insert(containsEventItems,     "containsEventItems");
     roleNames.insert(dayNumber,              "dayNumber");
     roleNames.insert(monthNumber,            "monthNumber");
     roleNames.insert(yearNumber,             "yearNumber");
 
     setRoleNames(roleNames);
+}
 
+DaysModel::~DaysModel()
+{
+    qDeleteAll(m_eventPlugins);
 }
 
 void DaysModel::setSourceData(QList<DayData> *data)
@@ -62,18 +111,13 @@ QVariant DaysModel::data(const QModelIndex &index, int role) \
const  if (index.isValid()) {
 
         const DayData &currentData = m_data->at(index.row());
+        const QDate currentDate(currentData.yearNumber, currentData.monthNumber, \
currentData.dayNumber);  
         switch (role) {
         case isCurrent:
             return currentData.isCurrent;
-        //      case containsHolidayItems:
-        //          return currentData.containsHolidayItems;
-        /* case containsEventItems:
-             return currentData.containsEventItems;
-         case containsTodoItems:
-             return currentData.containsTodoItems;
-         case containsJournalItems:
-             return currentData.containsJournalItems;*/
+        case containsEventItems:
+            return m_eventsData.contains(currentDate);
         case dayNumber:
             return currentData.dayNumber;
         case monthNumber:
@@ -91,7 +135,113 @@ void DaysModel::update()
         return;
     }
 
+    m_eventsData.clear();
+
     // We always have 42 items (or weeks * num of days in week) so we only have to \
tell the view that the data changed.  layoutChanged();
+
+    const QDate modelFirstDay(m_data->at(0).yearNumber, m_data->at(0).monthNumber, \
m_data->at(0).dayNumber); +
+    Q_FOREACH (Plasma::CalendarEventsPlugin *eventsPlugin, m_eventPlugins) {
+        eventsPlugin->loadEventsForDateRange(modelFirstDay, \
modelFirstDay.addDays(42)); +    }
+}
+
+void DaysModel::onDataReady(const QMultiHash<QDate, Plasma::EventData> &data)
+{
+    m_eventsData.reserve(m_eventsData.size() + data.size());
+    m_eventsData += data;
+    layoutChanged();
 }
 
+void DaysModel::onEventModified(const Plasma::EventData &data)
+{
+    QList<QDate> updatesList;
+    auto i = m_eventsData.begin();
+    while (i != m_eventsData.end()) {
+        if (i->uid() == data.uid()) {
+            *i = data;
+            updatesList << i.key();
+        }
+
+        ++i;
+    }
+
+    if (!updatesList.isEmpty()) {
+        m_agendaNeedsUpdate = true;
+    }
+
+    Q_FOREACH (const QDate &date, updatesList) {
+        const QModelIndex changedIndex = indexForDate(date);
+        if (changedIndex.isValid()) {
+            Q_EMIT dataChanged(changedIndex, changedIndex);
+        }
+        Q_EMIT agendaUpdated(date);
+    }
+}
+
+void DaysModel::onEventRemoved(const QString &uid)
+{
+    QList<QDate> updatesList;
+    auto i = m_eventsData.begin();
+    while (i != m_eventsData.end()) {
+        if (i->uid() == uid) {
+            updatesList << i.key();
+            i = m_eventsData.erase(i);
+        } else {
+            ++i;
+        }
+    }
+
+    if (!updatesList.isEmpty()) {
+        m_agendaNeedsUpdate = true;
+    }
+
+    Q_FOREACH (const QDate &date, updatesList) {
+        const QModelIndex changedIndex = indexForDate(date);
+        if (changedIndex.isValid()) {
+            Q_EMIT dataChanged(changedIndex, changedIndex);
+        }
+        Q_EMIT agendaUpdated(date);
+    }
+}
+
+QList<QObject*> DaysModel::eventsForDate(const QDate &date)
+{
+    if (m_lastRequestedAgendaDate == date && !m_agendaNeedsUpdate) {
+        return m_qmlData;
+    }
+
+    m_lastRequestedAgendaDate = date;
+    qDeleteAll(m_qmlData);
+    m_qmlData.clear();
+
+    const QList<Plasma::EventData> events = m_eventsData.values(date);
+    m_qmlData.reserve(events.size());
+
+    Q_FOREACH (const Plasma::EventData &event, events) {
+        m_qmlData << new EventDataDecorator(event, this);
+    }
+
+    // sort events by their time
+    std::sort(m_qmlData.begin(), m_qmlData.end(), [](QObject *a, QObject *b) {
+        return qobject_cast<EventDataDecorator*>(b)->startDateTime() > \
qobject_cast<EventDataDecorator*>(a)->startDateTime(); +    });
+
+    m_agendaNeedsUpdate = false;
+    return m_qmlData;
+}
+
+QModelIndex DaysModel::indexForDate(const QDate &date)
+{
+    if (!m_data) {
+        return QModelIndex();
+    }
+
+    const DayData &firstDay = m_data->at(0);
+    const QDate firstDate(firstDay.yearNumber, firstDay.monthNumber, \
firstDay.dayNumber); +
+    qint64 daysTo = firstDate.daysTo(date);
+
+    return createIndex(daysTo, 0);
+}
diff --git a/src/declarativeimports/calendar/daysmodel.h \
b/src/declarativeimports/calendar/daysmodel.h index a5bdac9..8d97c79 100644
--- a/src/declarativeimports/calendar/daysmodel.h
+++ b/src/declarativeimports/calendar/daysmodel.h
@@ -21,7 +21,11 @@
 #define DAYSMODEL_H
 
 #include <QAbstractListModel>
+
 #include "daydata.h"
+#include "eventdatadecorator.h"
+
+#include "plasmacalendarintegration/calendareventsplugin.h"
 
 class DaysModel : public QAbstractListModel
 {
@@ -30,7 +34,7 @@ public:
     enum Roles {
         isCurrent = Qt::UserRole + 1,
         //containsHolidayItems,
-        //containsEventItems,
+        containsEventItems,
         //containsTodoItems,
         //containsJournalItems,
         dayNumber,
@@ -39,13 +43,31 @@ public:
     };
 
     explicit DaysModel(QObject *parent = 0);
+    virtual ~DaysModel();
     void setSourceData(QList<DayData> *data);
     int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
     QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
     void update();
 
+    Q_INVOKABLE QList<QObject*> eventsForDate(const QDate &date);
+
+Q_SIGNALS:
+    void agendaUpdated(const QDate &updatedDate);
+
+private Q_SLOTS:
+    void onDataReady(const QMultiHash<QDate, Plasma::EventData> &data);
+    void onEventModified(const Plasma::EventData &data);
+    void onEventRemoved(const QString &uid);
+
 private:
+    QModelIndex indexForDate(const QDate &date);
+
     QList<DayData> *m_data;
+    QList<QObject*> m_qmlData;
+    QDate m_lastRequestedAgendaDate;
+    QList<Plasma::CalendarEventsPlugin*> m_eventPlugins;
+    QMultiHash<QDate, Plasma::EventData> m_eventsData;
+    bool m_agendaNeedsUpdate;
 };
 
 #endif // DAYSMODEL_H
diff --git a/src/declarativeimports/calendar/eventdatadecorator.cpp \
b/src/declarativeimports/calendar/eventdatadecorator.cpp new file mode 100644
index 0000000..ac450f2
--- /dev/null
+++ b/src/declarativeimports/calendar/eventdatadecorator.cpp
@@ -0,0 +1,76 @@
+/*
+    Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
+
+    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 2 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, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#include "eventdatadecorator.h"
+
+#include <KLocalizedString>
+
+EventDataDecorator::EventDataDecorator(const Plasma::EventData &data, QObject \
*parent) +    : QObject(parent),
+      m_data(data)
+{
+}
+
+QDateTime EventDataDecorator::startDateTime() const
+{
+    return m_data.startDateTime();
+}
+
+QDateTime EventDataDecorator::endDateTime() const
+{
+    return m_data.endDateTime();
+}
+
+bool EventDataDecorator::isAllDay() const
+{
+    return m_data.isAllDay();
+}
+
+bool EventDataDecorator::isMinor() const
+{
+    return m_data.isMinor();
+}
+
+QString EventDataDecorator::title() const
+{
+    return m_data.title();
+}
+
+QString EventDataDecorator::description() const
+{
+    return m_data.description();
+}
+
+QString EventDataDecorator::eventType() const
+{
+    switch (m_data.type()) {
+        case Plasma::EventData::Holiday:
+            return i18nc("Agenda listview section title", "Holidays");
+        case Plasma::EventData::Event:
+            return i18nc("Agenda listview section title", "Events");
+        case Plasma::EventData::Todo:
+            return i18nc("Agenda listview section title", "Todo");
+    }
+    return i18nc("Means 'Other calendar items'", "Other");
+}
+
+QString EventDataDecorator::eventColor() const
+{
+    return m_data.eventColor();
+}
diff --git a/src/declarativeimports/calendar/eventdatadecorator.h \
b/src/declarativeimports/calendar/eventdatadecorator.h new file mode 100644
index 0000000..622c697
--- /dev/null
+++ b/src/declarativeimports/calendar/eventdatadecorator.h
@@ -0,0 +1,60 @@
+/*
+    Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
+
+    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 2 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, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef EVENTDATADECORATOR_H
+#define EVENTDATADECORATOR_H
+
+#include <QObject>
+#include <QDateTime>
+#include <QString>
+
+#include "plasmacalendarintegration/calendareventsplugin.h"
+
+class EventDataDecorator : public QObject
+{
+    Q_OBJECT
+    Q_PROPERTY(QDateTime startDateTime READ startDateTime NOTIFY eventDataChanged)
+    Q_PROPERTY(QDateTime endDateTime READ endDateTime NOTIFY eventDataChanged)
+    Q_PROPERTY(bool isAllDay READ isAllDay NOTIFY eventDataChanged)
+    Q_PROPERTY(bool isMinor READ isMinor NOTIFY eventDataChanged)
+    Q_PROPERTY(QString title READ title NOTIFY eventDataChanged)
+    Q_PROPERTY(QString description READ description NOTIFY eventDataChanged)
+    Q_PROPERTY(QString eventColor READ eventColor NOTIFY eventDataChanged)
+    Q_PROPERTY(QString eventType READ eventType NOTIFY eventDataChanged)
+
+public:
+    EventDataDecorator(const Plasma::EventData &data, QObject *parent = Q_NULLPTR);
+
+    QDateTime startDateTime() const;
+    QDateTime endDateTime() const;
+    bool isAllDay() const;
+    bool isMinor() const;
+    QString title() const;
+    QString description() const;
+    QString eventType() const;
+    QString eventColor() const;
+
+Q_SIGNALS:
+    void eventDataChanged();
+
+private:
+    Plasma::EventData m_data;
+};
+
+#endif
diff --git a/src/declarativeimports/calendar/plasmacalendarintegration/CMakeLists.txt \
b/src/declarativeimports/calendar/plasmacalendarintegration/CMakeLists.txt new file \
mode 100644 index 0000000..aab860c
--- /dev/null
+++ b/src/declarativeimports/calendar/plasmacalendarintegration/CMakeLists.txt
@@ -0,0 +1,58 @@
+project(plasma-calendar-integration)
+
+set(CMAKECONFIG_INSTALL_DIR \
"${CMAKECONFIG_INSTALL_PREFIX}/PlasmaCalendarIntegration") +
+set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
+
+include(ECMPackageConfigHelpers)
+include(ECMSetupVersion)
+include(CMakePackageConfigHelpers)
+include(WriteBasicConfigVersionFile)
+include(KDECMakeSettings)
+
+ecm_setup_version(${PROJECT_VERSION}
+  VARIABLE_PREFIX PLASMACALENDARINTEGRATION
+  VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/plasmacalendarintegration_version.h"
+  PACKAGE_VERSION_FILE \
"${CMAKE_CURRENT_BINARY_DIR}/PlasmaCalendarIntegrationConfigVersion.cmake" +  \
SOVERSION 1) +
+set(calendar-integration_SRCS
+    calendareventsplugin.cpp
+    eventdata_p.cpp
+)
+
+add_library(plasmacalendarintegration SHARED ${calendar-integration_SRCS})
+
+target_link_libraries(plasmacalendarintegration
+    Qt5::Core
+)
+
+target_include_directories(plasmacalendarintegration INTERFACE \
"$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}/PlasmaCalendarIntegration>") \
+set_target_properties(plasmacalendarintegration PROPERTIES VERSION \
${PROJECT_VERSION} +                                                SOVERSION 1
+                                                EXPORT_NAME \
PlasmaCalendarIntegration +)
+
+ecm_configure_package_config_file(
+  "${CMAKE_CURRENT_SOURCE_DIR}/PlasmaCalendarIntegrationConfig.cmake.in"
+  "${CMAKE_CURRENT_BINARY_DIR}/PlasmaCalendarIntegrationConfig.cmake"
+  INSTALL_DESTINATION  ${CMAKECONFIG_INSTALL_DIR}
+)
+
+install(FILES
+  "${CMAKE_CURRENT_BINARY_DIR}/PlasmaCalendarIntegrationConfig.cmake"
+  "${CMAKE_CURRENT_BINARY_DIR}/PlasmaCalendarIntegrationConfigVersion.cmake"
+  DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
+  COMPONENT Devel
+)
+
+install(TARGETS plasmacalendarintegration EXPORT PlasmaCalendarIntegrationTargets \
${INSTALL_TARGETS_DEFAULT_ARGS}) +
+install(EXPORT PlasmaCalendarIntegrationTargets DESTINATION \
"${CMAKECONFIG_INSTALL_DIR}" FILE PlasmaCalendarIntegrationTargets.cmake) +
+install (FILES
+        calendareventsplugin.h
+        plasmacalendarintegration_export.h
+        ${CMAKE_CURRENT_BINARY_DIR}/plasmacalendarintegration_version.h
+        DESTINATION ${INCLUDE_INSTALL_DIR}/PlasmaCalendarIntegration COMPONENT Devel
+)
diff --git a/src/declarativeimports/calendar/plasmacalendarintegration/PlasmaCalendarIntegrationConfig.cmake.in \
b/src/declarativeimports/calendar/plasmacalendarintegration/PlasmaCalendarIntegrationConfig.cmake.in
 new file mode 100644
index 0000000..55813ad
--- /dev/null
+++ b/src/declarativeimports/calendar/plasmacalendarintegration/PlasmaCalendarIntegrationConfig.cmake.in
 @@ -0,0 +1,5 @@
+@PACKAGE_INIT@
+
+find_dependency(Qt5Core @REQUIRED_QT_VERSION@)
+
+include("${CMAKE_CURRENT_LIST_DIR}/PlasmaCalendarIntegrationTargets.cmake")
diff --git a/src/declarativeimports/calendar/calendarplugin.cpp \
b/src/declarativeimports/calendar/plasmacalendarintegration/calendareventsplugin.cpp \
similarity index 50% copy from src/declarativeimports/calendar/calendarplugin.cpp
copy to src/declarativeimports/calendar/plasmacalendarintegration/calendareventsplugin.cpp
 index bafe80c..39a026f 100644
--- a/src/declarativeimports/calendar/calendarplugin.cpp
+++ b/src/declarativeimports/calendar/plasmacalendarintegration/calendareventsplugin.cpp
 @@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Mark Gaiser <markg85@gmail.com>
+    Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
 
     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
@@ -17,23 +17,19 @@
 
 */
 
-#include "calendarplugin.h"
-#include "calendardata.h"
-#include "calendar.h"
-#include <QtQml>
-#include <QAbstractItemModel>
-#include <QAbstractListModel>
+#include "calendareventsplugin.h"
 
-void CalendarPlugin::registerTypes(const char *uri)
+namespace Plasma {
+
+CalendarEventsPlugin::CalendarEventsPlugin(QObject *parent)
+    : QObject(parent)
 {
-    Q_ASSERT(uri == QLatin1String("org.kde.plasma.calendar"));
-    qmlRegisterType<CalendarData>(uri, 2, 0, "CalendarData");
-    qmlRegisterType<Calendar>(uri, 2, 0, "Calendar");
-//   qmlRegisterType<CalendarData>(uri, 1, 0, "CalendarData");
-//    qmlRegisterType<CalendarData>(uri, 1, 0, "Calendar");
-    qmlRegisterType<QAbstractItemModel>();
-    qmlRegisterType<QAbstractListModel>();
+
 }
 
-//Q_EXPORT_PLUGIN2(calendarplugin, CalendarPlugin)
-#include "moc_calendarplugin.cpp"
+CalendarEventsPlugin::~CalendarEventsPlugin()
+{
+
+}
+
+}
diff --git a/src/declarativeimports/calendar/plasmacalendarintegration/calendareventsplugin.h \
b/src/declarativeimports/calendar/plasmacalendarintegration/calendareventsplugin.h \
new file mode 100644 index 0000000..f73f3a9
--- /dev/null
+++ b/src/declarativeimports/calendar/plasmacalendarintegration/calendareventsplugin.h
 @@ -0,0 +1,233 @@
+/*
+    Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
+
+    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 2 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, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef CALENDAREVENTSPLUGIN_H
+#define CALENDAREVENTSPLUGIN_H
+
+#include <QObject>
+#include <QDateTime>
+#include <QMultiHash>
+#include <QSharedDataPointer>
+
+#include "plasmacalendarintegration_export.h"
+
+namespace Plasma {
+
+class PLASMACALENDARINTEGRATION_EXPORT EventData
+{
+public:
+    enum EventType {
+        Holiday,    // Any holiday
+        Event,      // General event
+        Todo        // A Todo item
+    };
+
+    EventData();
+    EventData(const EventData &other);
+    ~EventData();
+
+    EventData &operator=(const EventData &other);
+
+    /**
+     * The start date and time of this event
+     */
+    QDateTime startDateTime() const;
+
+    /**
+     * Set the start date-time of this event
+     *
+     * @param startDateTime the date-time of when the event is starting
+     */
+    void setStartDateTime(const QDateTime &startDateTime);
+
+    /**
+     * The end date and time of this event
+     */
+    QDateTime endDateTime() const;
+
+    /**
+     * Set the end date-time of this event
+     *
+     * @param endDateTime the date-time of when the event is ending
+     */
+    void setEndDateTime(const QDateTime &endDateTime);
+
+    /**
+     * If true, this event goes on the whole day (eg. a holiday)
+     */
+    bool isAllDay() const;
+
+    /**
+     * If set to true, it will be displayed in the Calendar agenda
+     * without any time besides it, marked as "going on all day"
+     *
+     * This is useful for single-day events only, for multiple-day
+     * events, leave to false (default)
+     *
+     * @param isAllDay set to true if the event takes all day, false otherwise
+     *                 (defaults to false)
+     */
+    void setIsAllDay(bool isAllDay);
+
+    /**
+     * If true, this event won't mark the day in the calendar grid
+     * The main purpose for this flag is to support
+     * namedays, where in some countries the calendars have
+     * different name in them every day. This is just a minor holiday
+     * and as such should not mark the calendar grid, otherwise
+     * the whole grid would be in a different color.
+     */
+    bool isMinor() const;
+
+    /**
+     * If set to true, it won't be marked in the calendar grid
+     *
+     * @param isMinor true if it's a minor event (like a nameday holiday),
+     *                false otherwise (defaults to false)
+     */
+    void setIsMinor(bool isMinor);
+
+    /**
+     * Event title
+     */
+    QString title() const;
+
+    /**
+     * Sets the title of the event
+     *
+     * @param title The event title
+     */
+    void setTitle(const QString &title);
+
+    /**
+     * Event description, can provide more details about the event
+     */
+    QString description() const;
+
+    /**
+     * Sets the event description, which allows to add more details
+     * about this event
+     *
+     * @param description The description
+     */
+    void setDescription(const QString &description);
+
+    /**
+     * Type of the current event, eg. a holiday, an event or a todo item
+     */
+    EventType type() const;
+
+    /**
+     * Sets the event type, eg. a holiday, an event or a todo item
+     *
+     * @param type The event type,
+     */
+    void setEventType(EventType type);
+
+    /**
+     * The color that should be used to mark this event with
+     * It comes in the HTML hex format, eg. #AARRGGBB or #RRGGBB
+     */
+    QString eventColor() const;
+
+    /**
+     * This is to support various calendar colors the user might
+     * have configured elsewhere
+     *
+     * @param color The color for this event in the HTML hex format
+     *              eg. #AARRGGBB or #RRGGBB (this is passed directly
+     *              to QML)
+     */
+    void setEventColor(const QString &color);
+
+    /**
+     * Unique ID of the event
+     */
+    QString uid() const;
+
+    /**
+     * Sets the uid of the event
+     *
+     * This is a mandatory field only if you want to use
+     * the eventModified/eventRemoved signals, otherwise
+     * setting it is optional
+     *
+     * @param uid A unique id, recommended is to use the plugin name as prefix (to \
keep it unique) +     */
+    void setUid(const QString &uid);
+
+private:
+    class Private;
+    QSharedDataPointer<Private> d;
+};
+
+class PLASMACALENDARINTEGRATION_EXPORT CalendarEventsPlugin : public QObject
+{
+    Q_OBJECT
+
+public:
+    explicit CalendarEventsPlugin(QObject *parent = Q_NULLPTR);
+    virtual ~CalendarEventsPlugin();
+
+    /**
+     * When this is called, the plugin should load all events data
+     * between those two date ranges. Once the data are ready, it should
+     * just emit the dataReady() signal. The range is usually one month
+     *
+     * @param startDate the start of the range
+     * @param endDate the end of the range
+     */
+    virtual void loadEventsForDateRange(const QDate &startDate, const QDate \
&endDate) = 0; +
+Q_SIGNALS:
+    /**
+     * Emitted when the plugin has loaded the events data
+     *
+     * @param data A hash containing a QDate key for the event
+     *             in the value, Plasma::EventData, which holds all
+     *             the details for the given event
+     *             It's a multihash as there can be multiple events
+     *             in the same day
+     *             For multi-day events, insert just one with the key
+     *             being the startdate of the event
+     */
+    void dataReady(const QMultiHash<QDate, Plasma::EventData> &data);
+
+    /**
+     * Should be emitted when there is a modification of an event
+     * that was previously returned via the dataReady() signal
+     *
+     * @param event The modified event data
+     */
+    void eventModified(const Plasma::EventData &modifiedEvent);
+
+    /**
+     * Should be emitted when the plugin removes some event
+     * from its collection
+     *
+     * @param uid The uid of the event that was removed
+     */
+    void eventRemoved(const QString &uid);
+};
+
+}
+
+Q_DECLARE_INTERFACE(Plasma::CalendarEventsPlugin, \
"org.kde.plasma.CalendarEventsPlugin") +
+#endif
diff --git a/src/declarativeimports/calendar/plasmacalendarintegration/eventdata_p.cpp \
b/src/declarativeimports/calendar/plasmacalendarintegration/eventdata_p.cpp new file \
mode 100644 index 0000000..04e398a
--- /dev/null
+++ b/src/declarativeimports/calendar/plasmacalendarintegration/eventdata_p.cpp
@@ -0,0 +1,170 @@
+/*
+    Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
+
+    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 2 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, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#include "calendareventsplugin.h"
+
+#include <QSharedData>
+
+class Plasma::EventData::Private : public QSharedData {
+public:
+    Private() : isAllDay(false), isMinor(false) {};
+    Private(const Private &other)
+        : QSharedData(other)
+    {
+        startDateTime = other.startDateTime;
+        endDateTime = other.endDateTime;
+        title = other.title;
+        description = other.description;
+        uid = other.uid;
+        eventColor = other.eventColor;
+        type = other.type;
+        isAllDay = other.isAllDay;
+        isMinor = other.isMinor;
+    };
+    ~Private() {};
+    QDateTime startDateTime;    // Start of the event
+    QDateTime endDateTime;      // End of the event
+    QString title;              // Title of the event
+    QString description;        // Additional info of the event
+    QString uid;                // An internal event id, useful mostly just for the \
eventModified/Removed signals +    QString eventColor;         // Optional color of \
the event in the HTML hex format, eg. #AARRGGBB or #RRGGBB +    EventType type;       \
// Type of the event +    bool isAllDay;              // True if the event takes all \
day, then it won't be displayed with any time +    bool isMinor;               // A \
minor holiday that will not create a colored entry in the calendar +};
+
+//---------------------------------------------------
+
+namespace Plasma {
+
+EventData::EventData()
+    : d(new Private())
+{
+}
+
+EventData::EventData(const EventData &other)
+    : d(other.d)
+{
+}
+
+EventData::~EventData()
+{
+}
+
+EventData& EventData::operator=(const EventData &other)
+{
+    if (this == &other) {
+        return *this;
+    }
+
+    d = other.d;
+    return *this;
+}
+
+QDateTime EventData::startDateTime() const
+{
+    return d->startDateTime;
+}
+
+void EventData::setStartDateTime(const QDateTime &startDateTime)
+{
+    d->startDateTime = startDateTime;
+}
+
+QDateTime EventData::endDateTime() const
+{
+    return d->endDateTime;
+}
+
+void EventData::setEndDateTime(const QDateTime &endDateTime)
+{
+    d->endDateTime = endDateTime;
+}
+
+bool EventData::isAllDay() const
+{
+    return d->isAllDay;
+}
+
+void EventData::setIsAllDay(bool isAllDay)
+{
+    d->isAllDay = isAllDay;
+}
+
+bool EventData::isMinor() const
+{
+    return d->isMinor;
+}
+
+void EventData::setIsMinor(bool isMinor)
+{
+    d->isMinor = isMinor;
+}
+
+QString EventData::title() const
+{
+    return d->title;
+}
+
+void EventData::setTitle(const QString &title)
+{
+    d->title = title;
+}
+
+QString EventData::description() const
+{
+    return d->description;
+}
+
+void EventData::setDescription(const QString &description)
+{
+    d->description = description;
+}
+
+QString EventData::uid() const
+{
+    return d->uid;
+}
+
+void EventData::setUid(const QString &uid)
+{
+    d->uid = uid;
+}
+
+EventData::EventType EventData::type() const
+{
+    return d->type;
+}
+
+void EventData::setEventType(EventData::EventType type)
+{
+    d->type = type;
+}
+
+QString EventData::eventColor() const
+{
+    return d->eventColor;
+}
+
+void EventData::setEventColor(const QString &color)
+{
+    d->eventColor = color;
+}
+
+}
diff --git a/src/declarativeimports/calendar/plasmacalendarintegration/plasmacalendarintegration_export.h \
b/src/declarativeimports/calendar/plasmacalendarintegration/plasmacalendarintegration_export.h
 new file mode 100644
index 0000000..acb66d1
--- /dev/null
+++ b/src/declarativeimports/calendar/plasmacalendarintegration/plasmacalendarintegration_export.h
 @@ -0,0 +1,37 @@
+/*  This file is part of the KDE project
+ *    Copyright (C) 2007 David Faure <faure@kde.org>
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Library General Public
+ *    License as published by the Free Software Foundation; either
+ *    version 2 of the License, or (at your option) any later version.
+ *
+ *    This library 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
+ *    Library General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Library General Public License
+ *    along with this library; see the file COPYING.LIB.  If not, write to
+ *    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *    Boston, MA 02110-1301, USA.
+ */
+
+#ifndef PLASMACALENDARINTEGRATION_EXPORT_H
+#define PLASMACALENDARINTEGRATION_EXPORT_H
+
+#include <QtCore/QtGlobal>
+
+#ifndef PLASMACALENDARINTEGRATION_EXPORT
+/* We are building this library */
+#  define PLASMACALENDARINTEGRATION_EXPORT __attribute__((visibility("default")))
+# else
+/* We are using this library */
+#  define PLASMACALENDARINTEGRATION_EXPORT __attribute__((visibility("default")))
+#endif
+
+# ifndef PLASMACALENDARINTEGRATION_EXPORT_DEPRECATED
+#  define PLASMACALENDARINTEGRATION_EXPORT_DEPRECATED Q_DECL_DEPRECATED \
PLASMACALENDARINTEGRATION_EXPORT +# endif
+
+#endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic