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

List:       kde-commits
Subject:    [plasma-workspace] /: Add simple calendar events plugin based on KHolidays
From:       Martin Klapetek <mklapetek () kde ! org>
Date:       2016-05-03 0:20:54
Message-ID: E1axO58-00068v-6g () scm ! kde ! org
[Download RAW message or body]

Git commit eb7544704751dc1a9c2997da56d386811b00454f by Martin Klapetek.
Committed on 03/05/2016 at 00:20.
Pushed by mklapetek into branch 'master'.

Add simple calendar events plugin based on KHolidays

This is very simple for now as there is no configuration
yet, so it just takes the default region (your locale)
and shows holidays from that.

Obviously this needs a config to set up which regions
you want to show in there, but this is a start.

REVIEW: 125862

M  +9    -0    CMakeLists.txt
A  +20   -0    plasmacalendarintegration/CMakeLists.txt
A  +110  -0    plasmacalendarintegration/HolidaysConfig.qml     [License: GPL (v2/3)]
A  +7    -0    plasmacalendarintegration/holidayeventsplugin.json
A  +82   -0    plasmacalendarintegration/holidaysevents.cpp     [License: GPL (v2+)]
A  +49   -0    plasmacalendarintegration/holidaysevents.h     [License: GPL (v2+)]
A  +10   -0    plasmacalendarintegration/qmlhelper/CMakeLists.txt
A  +81   -0    plasmacalendarintegration/qmlhelper/holidayeventshelperplugin.cpp     \
[License: LGPL (v2+)] A  +33   -0    \
plasmacalendarintegration/qmlhelper/holidayeventshelperplugin.h     [License: LGPL \
(v2+)] A  +3    -0    plasmacalendarintegration/qmlhelper/qmldir

http://commits.kde.org/plasma-workspace/eb7544704751dc1a9c2997da56d386811b00454f

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2636399..c689277 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,11 @@ find_package(KWinDBusInterface CONFIG REQUIRED)
 
 find_package(KScreenLocker REQUIRED)
 find_package(ScreenSaverDBusInterface CONFIG REQUIRED)
+find_package(KF5Holidays)
+set_package_properties(KF5Holidays PROPERTIES DESCRIPTION "Holidays provider for \
Plasma calendar" +                       TYPE OPTIONAL
+                       PURPOSE "Needed to for holidays plugin for Plasma Calendar."
+                      )
 
 find_package(Phonon4Qt5 4.6.60 REQUIRED NO_MODULE)
 set_package_properties(Phonon4Qt5 PROPERTIES
@@ -166,6 +171,10 @@ ecm_optional_add_subdirectory(xembed-sni-proxy)
 
 add_subdirectory(soliduiserver)
 
+if(KF5Holidays_FOUND)
+    add_subdirectory(plasmacalendarintegration)
+endif()
+
 add_subdirectory(templates)
 
 feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/plasmacalendarintegration/CMakeLists.txt \
b/plasmacalendarintegration/CMakeLists.txt new file mode 100644
index 0000000..a182863
--- /dev/null
+++ b/plasmacalendarintegration/CMakeLists.txt
@@ -0,0 +1,20 @@
+set(holidays-plugin_SRCS
+    holidaysevents.cpp
+)
+
+add_library(holidaysevents MODULE ${holidays-plugin_SRCS})
+target_link_libraries(holidaysevents Qt5::Core
+                                     KF5::ConfigCore
+                                     KF5::Holidays
+                                     KF5::CalendarEvents
+)
+
+install (TARGETS holidaysevents
+         DESTINATION ${PLUGIN_INSTALL_DIR}/plasmacalendarplugins
+)
+
+install (FILES HolidaysConfig.qml
+         DESTINATION ${PLUGIN_INSTALL_DIR}/plasmacalendarplugins/holidays
+)
+
+add_subdirectory(qmlhelper)
diff --git a/plasmacalendarintegration/HolidaysConfig.qml \
b/plasmacalendarintegration/HolidaysConfig.qml new file mode 100644
index 0000000..108ce28
--- /dev/null
+++ b/plasmacalendarintegration/HolidaysConfig.qml
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
+ * Copyright 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) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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/>
+ */
+
+import QtQuick 2.0
+import QtQuick.Controls 1.2 as QtControls
+import QtQuick.Layouts 1.0
+import QtQuick.Dialogs 1.1
+
+import org.kde.plasma.private.digitalclock 1.0
+import org.kde.plasma.core 2.0 as PlasmaCore
+import org.kde.plasma.components 2.0 as PlasmaComponents
+import org.kde.kholidays 1.0 as KHolidays
+import org.kde.holidayeventshelperplugin 1.0
+
+Item {
+    id: holidaysConfig
+    width: parent.width
+    height: parent.height
+
+    function saveConfig()
+    {
+        KHolidays.HolidayRegionsModel.saveConfig();
+    }
+
+    // This is just for getting the column width
+    QtControls.CheckBox {
+        id: checkbox
+        visible: false
+    }
+
+    QmlConfigHelper {
+        id: configHelper
+    }
+
+    ColumnLayout {
+        anchors.fill: parent
+
+        QtControls.TextField {
+            id: filter
+            Layout.fillWidth: true
+            placeholderText: i18n("Search Holiday Regions")
+        }
+
+        QtControls.TableView {
+            id: holidaysView
+
+            signal toggleCurrent
+
+            Layout.fillWidth: true
+            Layout.fillHeight: true
+
+            Keys.onSpacePressed: toggleCurrent()
+
+            model: KHolidays.HolidayRegionsModel {
+                id: holidaysModel
+            }
+
+            QtControls.TableViewColumn {
+                width: checkbox.width
+                delegate: QtControls.CheckBox {
+                    id: checkBox
+                    anchors.centerIn: parent
+                    checked: styleData.value
+                    activeFocusOnTab: false // only let the TableView as a whole get \
focus +                    onClicked: {
+                        //needed for model's setData to be called
+                        if (checked) {
+                            configHelper.addRegion(model.region);
+                        } else {
+                            configHelper.removeRegion(model.region);
+                        }
+                    }
+                }
+
+                resizable: false
+                movable: false
+            }
+            QtControls.TableViewColumn {
+                role: "region"
+                title: i18n("Region")
+            }
+            QtControls.TableViewColumn {
+                role: "name"
+                title: i18n("Name")
+            }
+            QtControls.TableViewColumn {
+                role: "description"
+                title: i18n("Description")
+            }
+        }
+    }
+}
diff --git a/plasmacalendarintegration/holidayeventsplugin.json \
b/plasmacalendarintegration/holidayeventsplugin.json new file mode 100644
index 0000000..1557f44
--- /dev/null
+++ b/plasmacalendarintegration/holidayeventsplugin.json
@@ -0,0 +1,7 @@
+{
+    "Name": "Holidays plugin",
+    "Description": "Calendar plugin for displaying public holidays",
+    "Icon": "view-calendar",
+    "ConfigUi": "holidays/HolidaysConfig.qml",
+    "Authors": { "Name": "Martin Klapetek", "Email": "mklapetek@kde.org" }
+}
diff --git a/plasmacalendarintegration/holidaysevents.cpp \
b/plasmacalendarintegration/holidaysevents.cpp new file mode 100644
index 0000000..d71e4ee
--- /dev/null
+++ b/plasmacalendarintegration/holidaysevents.cpp
@@ -0,0 +1,82 @@
+/*
+    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 "holidaysevents.h"
+
+#include <KConfigGroup>
+#include <QDebug>
+
+HolidaysEventsPlugin::HolidaysEventsPlugin(QObject *parent)
+    : CalendarEvents::CalendarEventsPlugin(parent)
+{
+    KSharedConfig::Ptr m_config = \
KSharedConfig::openConfig("plasma_calendar_holiday_regions"); +    const KConfigGroup \
regionsConfig = m_config->group("General"); +    QStringList regionCodes = \
regionsConfig.readEntry("selectedRegions", QStringList()); +    \
regionCodes.removeDuplicates(); +
+    // If the config does not have any region stored
+    // add the default one
+    if (regionCodes.isEmpty()) {
+        regionCodes << KHolidays::HolidayRegion::defaultRegionCode();
+    }
+
+    Q_FOREACH (const QString &region, regionCodes) {
+        m_regions << new KHolidays::HolidayRegion(region);
+    }
+}
+
+HolidaysEventsPlugin::~HolidaysEventsPlugin()
+{
+    qDeleteAll(m_regions);
+}
+
+void HolidaysEventsPlugin::loadEventsForDateRange(const QDate &startDate, const \
QDate &endDate) +{
+    if (m_lastStartDate == startDate && m_lastEndDate == endDate) {
+        Q_EMIT dataReady(m_lastData);
+        return;
+    }
+
+    m_lastData.clear();
+    QMultiHash<QDate, CalendarEvents::EventData> data;
+
+    Q_FOREACH (KHolidays::HolidayRegion *region, m_regions) {
+        KHolidays::Holiday::List holidays = region->holidays(startDate, endDate);
+
+        Q_FOREACH (const KHolidays::Holiday &holiday, holidays) {
+            CalendarEvents::EventData eventData;
+            eventData.setStartDateTime(QDateTime(holiday.observedStartDate()));
+            eventData.setEndDateTime(QDateTime(holiday.observedEndDate()));
+            eventData.setIsAllDay(true);
+            eventData.setTitle(holiday.name());
+            eventData.setEventType(CalendarEvents::EventData::Holiday);
+            eventData.setIsMinor(false);
+
+            data.insert(holiday.observedStartDate(), eventData);
+        }
+    }
+
+    m_lastStartDate = startDate;
+    m_lastEndDate = endDate;
+    m_lastData = data;
+
+    qDebug() << data.size();
+
+    Q_EMIT dataReady(data);
+}
diff --git a/plasmacalendarintegration/holidaysevents.h \
b/plasmacalendarintegration/holidaysevents.h new file mode 100644
index 0000000..575a1f0
--- /dev/null
+++ b/plasmacalendarintegration/holidaysevents.h
@@ -0,0 +1,49 @@
+/*
+    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 HOLIDAYSEVENTSPLUGIN_H
+#define HOLIDAYSEVENTSPLUGIN_H
+
+#include <QObject>
+#include <CalendarEvents/CalendarEventsPlugin>
+
+#include <KHolidays/HolidayRegion>
+#include <KSharedConfig>
+
+class HolidaysEventsPlugin : public CalendarEvents::CalendarEventsPlugin
+{
+    Q_OBJECT
+    Q_PLUGIN_METADATA(IID "org.kde.CalendarEventsPlugin" FILE \
"holidayeventsplugin.json") +    Q_INTERFACES(CalendarEvents::CalendarEventsPlugin)
+
+public:
+    HolidaysEventsPlugin(QObject *parent = 0);
+    ~HolidaysEventsPlugin();
+
+    virtual void loadEventsForDateRange(const QDate &startDate, const QDate \
&endDate) Q_DECL_OVERRIDE; +
+private:
+    QDate m_lastStartDate;
+    QDate m_lastEndDate;
+    QList<KHolidays::HolidayRegion*> m_regions;
+    QMultiHash<QDate, CalendarEvents::EventData> m_lastData;
+    KSharedConfig::Ptr m_config;
+};
+
+#endif
diff --git a/plasmacalendarintegration/qmlhelper/CMakeLists.txt \
b/plasmacalendarintegration/qmlhelper/CMakeLists.txt new file mode 100644
index 0000000..cf222c8
--- /dev/null
+++ b/plasmacalendarintegration/qmlhelper/CMakeLists.txt
@@ -0,0 +1,10 @@
+
+add_library(holidayeventshelperplugin SHARED holidayeventshelperplugin.cpp)
+
+target_link_libraries(holidayeventshelperplugin Qt5::Qml
+                                                Qt5::Core
+                                                KF5::ConfigCore
+)
+
+install(TARGETS holidayeventshelperplugin DESTINATION \
${KDE_INSTALL_QMLDIR}/org/kde/holidayeventshelperplugin) +install(FILES qmldir \
                DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/holidayeventshelperplugin)
diff --git a/plasmacalendarintegration/qmlhelper/holidayeventshelperplugin.cpp \
b/plasmacalendarintegration/qmlhelper/holidayeventshelperplugin.cpp new file mode \
100644 index 0000000..adf0763
--- /dev/null
+++ b/plasmacalendarintegration/qmlhelper/holidayeventshelperplugin.cpp
@@ -0,0 +1,81 @@
+/*
+  Copyright (c) 2015 Martin Klapetek <mklapetek@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.
+*/
+
+#include "holidayeventshelperplugin.h"
+
+#include <qqml.h>
+#include <QDebug>
+
+#include <KSharedConfig>
+#include <KConfigGroup>
+
+class QmlConfigHelper : public QObject
+{
+    Q_OBJECT
+
+public:
+    QmlConfigHelper(QObject *parent = 0) : QObject(parent)
+    {
+        KSharedConfig::Ptr config = \
KSharedConfig::openConfig("plasma_calendar_holiday_regions"); +        m_configGroup \
= config->group("General"); +        connect(this, \
&QmlConfigHelper::selectedRegionsChanged, [=] { +            \
m_configGroup.writeEntry("selectedRegions", m_regions); +        });
+    }
+
+    ~QmlConfigHelper()
+    {
+        m_configGroup.sync();
+    }
+
+    Q_INVOKABLE void saveConfig()
+    {
+        m_configGroup.sync();
+    }
+
+    Q_INVOKABLE void addRegion(const QString &region)
+    {
+        if (!m_regions.contains(region)) {
+            m_regions.append(region);
+        }
+
+        Q_EMIT selectedRegionsChanged();
+    }
+
+    Q_INVOKABLE void removeRegion(const QString &region)
+    {
+        m_regions.removeOne(region);
+
+        Q_EMIT selectedRegionsChanged();
+    }
+
+Q_SIGNALS:
+    void selectedRegionsChanged();
+
+private:
+    QStringList m_regions;
+    KConfigGroup m_configGroup;
+};
+
+void HolidayEventsHelperPlugin::registerTypes(const char* uri)
+{
+    qmlRegisterType<QmlConfigHelper>(uri, 1, 0, "QmlConfigHelper");
+}
+
+#include "holidayeventshelperplugin.moc"
diff --git a/plasmacalendarintegration/qmlhelper/holidayeventshelperplugin.h \
b/plasmacalendarintegration/qmlhelper/holidayeventshelperplugin.h new file mode \
100644 index 0000000..32a0e68
--- /dev/null
+++ b/plasmacalendarintegration/qmlhelper/holidayeventshelperplugin.h
@@ -0,0 +1,33 @@
+/*
+  Copyright (c) 2015 Martin Klapetek <mklapetek@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 HOLIDAYEVENTSHELPERPLUGIN_H
+#define HOLIDAYEVENTSHELPERPLUGIN_H
+
+#include <QQmlExtensionPlugin>
+
+class HolidayEventsHelperPlugin : public QQmlExtensionPlugin
+{
+Q_OBJECT
+Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
+public:
+    virtual void registerTypes(const char* uri);
+};
+
+#endif // HOLIDAYEVENTSHELPERPLUGIN_H
diff --git a/plasmacalendarintegration/qmlhelper/qmldir \
b/plasmacalendarintegration/qmlhelper/qmldir new file mode 100644
index 0000000..5a875e5
--- /dev/null
+++ b/plasmacalendarintegration/qmlhelper/qmldir
@@ -0,0 +1,3 @@
+module org.kde.holidayeventshelperplugin
+
+plugin holidayeventshelperplugin


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

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