Changeset View
Changeset View
Standalone View
Standalone View
plasmacalendarplugins/astronomical/astronomicaleventsplugin.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or modify | ||||
5 | it under the terms of the GNU General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or | ||||
7 | (at your option) any later version. | ||||
8 | | ||||
9 | This program is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | GNU General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License along | ||||
15 | with this program; if not, write to the Free Software Foundation, Inc., | ||||
16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
17 | | ||||
18 | */ | ||||
19 | | ||||
20 | #include "astronomicaleventsplugin.h" | ||||
21 | | ||||
22 | // KF | ||||
23 | #include <KSharedConfig> | ||||
24 | #include <KConfigGroup> | ||||
25 | #include <KHolidays/LunarPhase> | ||||
26 | #include <KHolidays/AstroSeasons> | ||||
27 | #include <KLocalizedString> | ||||
28 | // Qt | ||||
29 | #include <QDebug> | ||||
30 | | ||||
31 | AstronomicalEventsPlugin::AstronomicalEventsPlugin() | ||||
32 | : CalendarEvents::CalendarEventsPlugin() | ||||
33 | { | ||||
34 | auto config = KSharedConfig::openConfig(QStringLiteral("plasma_calendar_astronomicalevents")); | ||||
35 | const KConfigGroup generalConfig = config->group("General"); | ||||
36 | | ||||
37 | m_lunarPhaseShown = generalConfig.readEntry("showLunarPhase", true); | ||||
38 | m_seasonShown = generalConfig.readEntry("showSeason", true); | ||||
39 | } | ||||
40 | | ||||
41 | AstronomicalEventsPlugin::~AstronomicalEventsPlugin() | ||||
42 | { | ||||
43 | } | ||||
44 | | ||||
45 | void AstronomicalEventsPlugin::loadEventsForDateRange(const QDate &startDate, const QDate &endDate) | ||||
46 | { | ||||
47 | QMultiHash<QDate, CalendarEvents::EventData> data; | ||||
48 | | ||||
49 | for (QDate date = startDate; date <= endDate; date = date.addDays(1)) { | ||||
50 | if (m_lunarPhaseShown) { | ||||
51 | const auto phase = KHolidays::LunarPhase::phaseAtDate(date); | ||||
52 | if (phase != KHolidays::LunarPhase::None) { | ||||
53 | CalendarEvents::EventData lunarPhaseData; | ||||
54 | lunarPhaseData.setIsAllDay(true); | ||||
55 | lunarPhaseData.setTitle(KHolidays::LunarPhase::phaseName(phase)); | ||||
56 | lunarPhaseData.setEventType(CalendarEvents::EventData::Event); | ||||
57 | lunarPhaseData.setIsMinor(false); | ||||
58 | | ||||
59 | data.insert(date, lunarPhaseData); | ||||
60 | } | ||||
61 | } | ||||
62 | | ||||
63 | if (m_seasonShown) { | ||||
64 | const auto season = KHolidays::AstroSeasons::seasonAtDate(date); | ||||
65 | if (season != KHolidays::AstroSeasons::None) { | ||||
66 | CalendarEvents::EventData seasonData; | ||||
67 | seasonData.setIsAllDay(true); | ||||
68 | seasonData.setTitle(KHolidays::AstroSeasons::seasonName(season)); | ||||
69 | seasonData.setEventType(CalendarEvents::EventData::Event); | ||||
70 | seasonData.setIsMinor(false); | ||||
71 | | ||||
72 | data.insert(date, seasonData); | ||||
73 | } | ||||
74 | } | ||||
75 | } | ||||
76 | | ||||
77 | Q_EMIT dataReady(data); | ||||
78 | } |