Commit 0b3312f0 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Add Plasma Calendar plugin Astronomical Events

Summary:
For now adds the option to show
* lunar phase events (full moon, new moon, quartermoon)
* astronomical season (solstices, equinoxes)

Future plan: also show sunset & sunrise for given location

Reviewers: #plasma, mart

Reviewed By: #plasma, mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D12433
parent 6e753e66
......@@ -39,6 +39,8 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Archive
Config
CoreAddons
Declarative
Holidays
I18n
IconThemes
KIO
......@@ -86,6 +88,8 @@ add_subdirectory(wallpapers)
add_subdirectory(windowswitchers)
add_subdirectory(desktopswitchers)
add_subdirectory(plasmacalendarplugins)
add_subdirectory(templates)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
add_subdirectory(astronomical)
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)
#! /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
/*
Copyright 2018 Friedrich W. H. Kossebau <kossebau@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 "astronomicaleventsplugin.h"
// KF
#include <KSharedConfig>
#include <KConfigGroup>
#include <KHolidays/LunarPhase>
#include <KHolidays/AstroSeasons>
#include <KLocalizedString>
// Qt
#include <QDebug>
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<QDate, CalendarEvents::EventData> 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);
}
/*
Copyright 2018 Friedrich W. H. Kossebau <kossebau@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, see <http://www.gnu.org/licenses/>
*/
#ifndef ASTRONOMICALEVENTSPLUGIN_H
#define ASTRONOMICALEVENTSPLUGIN_H
// KF
#include <CalendarEvents/CalendarEventsPlugin>
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
{
"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"
}
}
add_subdirectory(qml)
add_subdirectory(plugin)
\ No newline at end of file
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)
/*
Copyright 2018 Friedrich W. H. Kossebau <kossebau@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, see <http://www.gnu.org/licenses/>
*/
#include "configplugin.h"
#include "configstorage.h"
// Qt
#include <QQmlEngine>
void AstronomicalConfigPlugin::registerTypes(const char* uri)
{
qmlRegisterType<ConfigStorage>(uri, 1, 0, "ConfigStorage");
}
/*
Copyright 2018 Friedrich W. H. Kossebau <kossebau@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, see <http://www.gnu.org/licenses/>
*/
#ifndef CONFIGPLUGIN_H
#define CONFIGPLUGIN_H
#include <QQmlExtensionPlugin>
class AstronomicalConfigPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char* uri) override;
};
#endif
/*
Copyright 2018 Friedrich W. H. Kossebau <kossebau@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, see <http://www.gnu.org/licenses/>
*/
#include "configstorage.h"
// KF
#include <KSharedConfig>
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();
}
/*
Copyright 2018 Friedrich W. H. Kossebau <kossebau@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, see <http://www.gnu.org/licenses/>
*/
#ifndef CONFIGSTORAGE_H
#define CONFIGSTORAGE_H
// KF
#include <KConfigGroup>
#include <QDateTime>
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
module org.kde.plasmacalendar.astronomicaleventsconfig
plugin plasmacalendarastronomicaleventsconfig
/*
Copyright 2018 Friedrich W. H. Kossebau <kossebau@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, see <http://www.gnu.org/licenses/>
*/
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
}
}
install(FILES AstronomicalEventsConfig.qml DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasmacalendarplugins/astronomicalevents)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment