diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ Archive Config CoreAddons + Declarative + Holidays I18n IconThemes KIO @@ -86,6 +88,8 @@ add_subdirectory(windowswitchers) add_subdirectory(desktopswitchers) +add_subdirectory(plasmacalendarplugins) + add_subdirectory(templates) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/plasmacalendarplugins/CMakeLists.txt b/plasmacalendarplugins/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(astronomical) diff --git a/plasmacalendarplugins/astronomical/CMakeLists.txt b/plasmacalendarplugins/astronomical/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/CMakeLists.txt @@ -0,0 +1,15 @@ +set(astronomicalevents_SRCS + astronomicaleventsplugin.cpp +) + +add_library(astronomicalevents MODULE ${astronomicalevents_SRCS}) +target_link_libraries(astronomicalevents + KF5::ConfigCore + KF5::Holidays + KF5::CalendarEvents + KF5::I18n +) + +install(TARGETS astronomicalevents DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasmacalendarplugins) + +add_subdirectory(config) diff --git a/plasmacalendarplugins/astronomical/Messages.sh b/plasmacalendarplugins/astronomical/Messages.sh new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/Messages.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash +$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp +$XGETTEXT `find . -name \*.js -o -name \*.qml -o -name \*.cpp` -o $podir/plasma_calendar_astronomicalevents.pot +rm -f rc.cpp diff --git a/plasmacalendarplugins/astronomical/astronomicaleventsplugin.h b/plasmacalendarplugins/astronomical/astronomicaleventsplugin.h new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/astronomicaleventsplugin.h @@ -0,0 +1,41 @@ +/* + Copyright 2018 Friedrich W. H. Kossebau + + 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, see +*/ + +#ifndef ASTRONOMICALEVENTSPLUGIN_H +#define ASTRONOMICALEVENTSPLUGIN_H + +// KF +#include + +class AstronomicalEventsPlugin : public CalendarEvents::CalendarEventsPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.kde.CalendarEventsPlugin" FILE "astronomicaleventsplugin.json") + Q_INTERFACES(CalendarEvents::CalendarEventsPlugin) + +public: + AstronomicalEventsPlugin(); + ~AstronomicalEventsPlugin() override; + + void loadEventsForDateRange(const QDate &startDate, const QDate &endDate) override; + +private: + bool m_lunarPhaseShown; + bool m_seasonShown; +}; + +#endif diff --git a/plasmacalendarplugins/astronomical/astronomicaleventsplugin.cpp b/plasmacalendarplugins/astronomical/astronomicaleventsplugin.cpp new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/astronomicaleventsplugin.cpp @@ -0,0 +1,78 @@ +/* + Copyright 2018 Friedrich W. H. Kossebau + + 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 "astronomicaleventsplugin.h" + +// KF +#include +#include +#include +#include +#include +// Qt +#include + +AstronomicalEventsPlugin::AstronomicalEventsPlugin() + : CalendarEvents::CalendarEventsPlugin() +{ + auto config = KSharedConfig::openConfig(QStringLiteral("plasma_calendar_astronomicalevents")); + const KConfigGroup generalConfig = config->group("General"); + + m_lunarPhaseShown = generalConfig.readEntry("showLunarPhase", true); + m_seasonShown = generalConfig.readEntry("showSeason", true); +} + +AstronomicalEventsPlugin::~AstronomicalEventsPlugin() +{ +} + +void AstronomicalEventsPlugin::loadEventsForDateRange(const QDate &startDate, const QDate &endDate) +{ + QMultiHash data; + + for (QDate date = startDate; date <= endDate; date = date.addDays(1)) { + if (m_lunarPhaseShown) { + const auto phase = KHolidays::LunarPhase::phaseAtDate(date); + if (phase != KHolidays::LunarPhase::None) { + CalendarEvents::EventData lunarPhaseData; + lunarPhaseData.setIsAllDay(true); + lunarPhaseData.setTitle(KHolidays::LunarPhase::phaseName(phase)); + lunarPhaseData.setEventType(CalendarEvents::EventData::Event); + lunarPhaseData.setIsMinor(false); + + data.insert(date, lunarPhaseData); + } + } + + if (m_seasonShown) { + const auto season = KHolidays::AstroSeasons::seasonAtDate(date); + if (season != KHolidays::AstroSeasons::None) { + CalendarEvents::EventData seasonData; + seasonData.setIsAllDay(true); + seasonData.setTitle(KHolidays::AstroSeasons::seasonName(season)); + seasonData.setEventType(CalendarEvents::EventData::Event); + seasonData.setIsMinor(false); + + data.insert(date, seasonData); + } + } + } + + Q_EMIT dataReady(data); +} diff --git a/plasmacalendarplugins/astronomical/astronomicaleventsplugin.json b/plasmacalendarplugins/astronomical/astronomicaleventsplugin.json new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/astronomicaleventsplugin.json @@ -0,0 +1,10 @@ +{ + "Name": "Astronomical Events", + "Description": "Calendar plugin for displaying astronomical events", + "Icon": "globe", + "ConfigUi": "astronomicalevents/AstronomicalEventsConfig.qml", + "Authors": { + "Name": "Friedrich W. H. Kossebau", + "Email": "kossebau@kde.org" + } +} diff --git a/plasmacalendarplugins/astronomical/config/CMakeLists.txt b/plasmacalendarplugins/astronomical/config/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(qml) +add_subdirectory(plugin) \ No newline at end of file diff --git a/plasmacalendarplugins/astronomical/config/plugin/CMakeLists.txt b/plasmacalendarplugins/astronomical/config/plugin/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/plugin/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(plasmacalendarastronomicaleventsconfig SHARED configplugin.cpp configstorage.cpp) + +target_link_libraries(plasmacalendarastronomicaleventsconfig + Qt5::Qml + Qt5::Core + KF5::ConfigCore +) + +install(TARGETS plasmacalendarastronomicaleventsconfig DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasmacalendar/astronomicaleventsconfig) +install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasmacalendar/astronomicaleventsconfig) diff --git a/plasmacalendarplugins/astronomical/config/plugin/configplugin.h b/plasmacalendarplugins/astronomical/config/plugin/configplugin.h new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/plugin/configplugin.h @@ -0,0 +1,32 @@ +/* + Copyright 2018 Friedrich W. H. Kossebau + + 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, see +*/ + +#ifndef CONFIGPLUGIN_H +#define CONFIGPLUGIN_H + +#include + +class AstronomicalConfigPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char* uri) override; +}; + +#endif diff --git a/plasmacalendarplugins/astronomical/config/plugin/configplugin.cpp b/plasmacalendarplugins/astronomical/config/plugin/configplugin.cpp new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/plugin/configplugin.cpp @@ -0,0 +1,29 @@ +/* + Copyright 2018 Friedrich W. H. Kossebau + + 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, see +*/ + +#include "configplugin.h" + +#include "configstorage.h" + +// Qt +#include + + +void AstronomicalConfigPlugin::registerTypes(const char* uri) +{ + qmlRegisterType(uri, 1, 0, "ConfigStorage"); +} diff --git a/plasmacalendarplugins/astronomical/config/plugin/configstorage.h b/plasmacalendarplugins/astronomical/config/plugin/configstorage.h new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/plugin/configstorage.h @@ -0,0 +1,47 @@ +/* + Copyright 2018 Friedrich W. H. Kossebau + + 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, see +*/ + +#ifndef CONFIGSTORAGE_H +#define CONFIGSTORAGE_H + +// KF +#include +#include + +class ConfigStorage : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool isLunarPhaseShown MEMBER m_lunarPhaseShown NOTIFY lunarPhaseShownChanged) + Q_PROPERTY(bool isSeasonShown MEMBER m_seasonShown NOTIFY seasonShownChanged) + +public: + explicit ConfigStorage(QObject *parent = nullptr); + + Q_INVOKABLE void save(); + +Q_SIGNALS: + void lunarPhaseShownChanged(); + void seasonShownChanged(); + +private: + KConfigGroup m_generalConfigGroup; + + bool m_lunarPhaseShown; + bool m_seasonShown; +}; + +#endif diff --git a/plasmacalendarplugins/astronomical/config/plugin/configstorage.cpp b/plasmacalendarplugins/astronomical/config/plugin/configstorage.cpp new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/plugin/configstorage.cpp @@ -0,0 +1,41 @@ +/* + Copyright 2018 Friedrich W. H. Kossebau + + 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, see +*/ + +#include "configstorage.h" + +// KF +#include + + +ConfigStorage::ConfigStorage(QObject *parent) + : QObject(parent) +{ + auto config = KSharedConfig::openConfig(QStringLiteral("plasma_calendar_astronomicalevents")); + m_generalConfigGroup = config->group("General"); + + m_lunarPhaseShown = m_generalConfigGroup.readEntry("showLunarPhase", true); + m_seasonShown = m_generalConfigGroup.readEntry("showSeason", true); +} + +void ConfigStorage::save() +{ + m_generalConfigGroup.writeEntry("showLunarPhase", m_lunarPhaseShown); + m_generalConfigGroup.writeEntry("showSeason", m_seasonShown); + + m_generalConfigGroup.sync(); +} + diff --git a/plasmacalendarplugins/astronomical/config/plugin/qmldir b/plasmacalendarplugins/astronomical/config/plugin/qmldir new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/plugin/qmldir @@ -0,0 +1,3 @@ +module org.kde.plasmacalendar.astronomicaleventsconfig + +plugin plasmacalendarastronomicaleventsconfig diff --git a/plasmacalendarplugins/astronomical/config/qml/AstronomicalEventsConfig.qml b/plasmacalendarplugins/astronomical/config/qml/AstronomicalEventsConfig.qml new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/qml/AstronomicalEventsConfig.qml @@ -0,0 +1,63 @@ +/* + Copyright 2018 Friedrich W. H. Kossebau + + 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, see +*/ + +import QtQuick 2.0 + +import QtQuick.Controls 1.2 as QtControls +import QtQuick.Layouts 1.0 + +import org.kde.plasmacalendar.astronomicaleventsconfig 1.0 + +ColumnLayout { + id: configPage + + // expected API + signal configurationChanged + + // expected API + function saveConfig() + { + configStorage.isLunarPhaseShown = showLunarPhasesCheckBox.checked; + configStorage.isSeasonShown = showSeasonsCheckBox.checked; + + configStorage.save(); + } + + ConfigStorage { + id: configStorage + } + + QtControls.CheckBox { + id: showLunarPhasesCheckBox + + checked: configStorage.isLunarPhaseShown + text: i18ndc("plasma_calendar_astronomicalevents", "@option:check", "Show lunar phases") + onCheckedChanged: configPage.configurationChanged(); + } + + QtControls.CheckBox { + id: showSeasonsCheckBox + + checked: configStorage.isSeasonShown + text: i18ndc("plasma_calendar_astronomicalevents", "@option:check", "Show astronomical seasons (solstices and equinoxes)") + onCheckedChanged: configPage.configurationChanged(); + } + + Item { // tighten layout + Layout.fillHeight: true + } +} diff --git a/plasmacalendarplugins/astronomical/config/qml/CMakeLists.txt b/plasmacalendarplugins/astronomical/config/qml/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plasmacalendarplugins/astronomical/config/qml/CMakeLists.txt @@ -0,0 +1 @@ +install(FILES AstronomicalEventsConfig.qml DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasmacalendarplugins/astronomicalevents)