Warning, file /plasma/kdeplasma-addons/plasmacalendarplugins/astronomical/astronomicaleventsplugin.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "astronomicaleventsplugin.h"
0008 
0009 // KF
0010 #include <KConfigGroup>
0011 #include <KHolidays/AstroSeasons>
0012 #include <KHolidays/LunarPhase>
0013 #include <KLocalizedString>
0014 #include <KSharedConfig>
0015 // Qt
0016 #include <QDebug>
0017 
0018 AstronomicalEventsPlugin::AstronomicalEventsPlugin()
0019     : CalendarEvents::CalendarEventsPlugin()
0020 {
0021     auto config = KSharedConfig::openConfig(QStringLiteral("plasma_calendar_astronomicalevents"));
0022     const KConfigGroup generalConfig = config->group("General");
0023 
0024     m_lunarPhaseShown = generalConfig.readEntry("showLunarPhase", true);
0025     m_seasonShown = generalConfig.readEntry("showSeason", true);
0026 }
0027 
0028 AstronomicalEventsPlugin::~AstronomicalEventsPlugin()
0029 {
0030 }
0031 
0032 void AstronomicalEventsPlugin::loadEventsForDateRange(const QDate &startDate, const QDate &endDate)
0033 {
0034     QMultiHash<QDate, CalendarEvents::EventData> data;
0035 
0036     if (!endDate.isValid()) {
0037         Q_EMIT dataReady(data);
0038         return;
0039     }
0040 
0041     for (QDate date = startDate; date <= endDate && date.isValid(); date = date.addDays(1)) {
0042         if (m_lunarPhaseShown) {
0043             const auto phase = KHolidays::LunarPhase::phaseAtDate(date);
0044             if (phase == KHolidays::LunarPhase::NewMoon || phase == KHolidays::LunarPhase::FirstQuarter || phase == KHolidays::LunarPhase::LastQuarter
0045                 || phase == KHolidays::LunarPhase::FullMoon) {
0046                 CalendarEvents::EventData lunarPhaseData;
0047                 lunarPhaseData.setIsAllDay(true);
0048                 lunarPhaseData.setTitle(KHolidays::LunarPhase::phaseName(phase));
0049                 lunarPhaseData.setEventType(CalendarEvents::EventData::Event);
0050                 lunarPhaseData.setIsMinor(false);
0051 
0052                 data.insert(date, lunarPhaseData);
0053             }
0054         }
0055 
0056         if (m_seasonShown) {
0057             const auto season = KHolidays::AstroSeasons::seasonAtDate(date);
0058             if (season != KHolidays::AstroSeasons::None) {
0059                 CalendarEvents::EventData seasonData;
0060                 seasonData.setIsAllDay(true);
0061                 seasonData.setTitle(KHolidays::AstroSeasons::seasonName(season));
0062                 seasonData.setEventType(CalendarEvents::EventData::Event);
0063                 seasonData.setIsMinor(false);
0064 
0065                 data.insert(date, seasonData);
0066             }
0067         }
0068     }
0069 
0070     Q_EMIT dataReady(data);
0071 }