Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit d8f8fa89 authored by Volker Krause's avatar Volker Krause

Show notifications on delays or platform changes

parent 649dee46
......@@ -24,6 +24,7 @@ find_package(Qt5 5.10 REQUIRED COMPONENTS Test Quick)
find_package(Qt5 CONFIG QUIET OPTIONAL_COMPONENTS QuickCompiler)
find_package(KF5 REQUIRED COMPONENTS I18n)
find_package(KF5Holidays 5.49.0 CONFIG QUIET)
find_package(KF5Notifications 5.49.0 CONFIG QUIET)
find_package(KF5Contacts CONFIG REQUIRED)
find_package(KPimPkPass CONFIG REQUIRED)
find_package(KPimItinerary 5.9.40 CONFIG REQUIRED)
......
if (TARGET KF5::Notifications)
SET(HAVE_NOTIFICATIONS TRUE)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-itinerary.h.in ${CMAKE_CURRENT_BINARY_DIR}/config-itinerary.h)
set(itinerary_srcs
applicationcontroller.cpp
contenttypeprober.cpp
......@@ -55,6 +60,9 @@ target_link_libraries(itinerary-app PRIVATE
KF5::Contacts
KPublicTransport
)
if (TARGET KF5::Notifications)
target_link_libraries(itinerary-app PRIVATE KF5::Notifications)
endif()
if (ANDROID)
# explicitly add runtime dependencies and transitive link dependencies,
# so androiddeployqt picks them up
......
/*
Copyright (c) 2018 Volker Krause <vkrause@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 CONFIG_ITINERARY_H
#define CONFIG_ITINERARY_H
#cmakedefine HAVE_NOTIFICATIONS
#endif
......@@ -15,6 +15,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config-itinerary.h"
#include "livedatamanager.h"
#include "logging.h"
#include "pkpassmanager.h"
......@@ -32,6 +34,12 @@
#include <KPublicTransport/Location>
#include <KPublicTransport/Manager>
#ifdef HAVE_NOTIFICATIONS
#include <KNotifications/KNotification>
#endif
#include <KLocalizedString>
#include <QDateTime>
#include <QDir>
#include <QDirIterator>
......@@ -171,9 +179,7 @@ void LiveDataManager::checkTrainTrip(const TrainTrip& trip, const QString& resId
continue;
}
qCDebug(Log) << "Found departure information:" << dep.route().line().name() << dep.expectedPlatform() << dep.expectedDepartureTime();
m_departures.insert(resId, dep);
storePublicTransportData(resId, dep, QStringLiteral("departure"));
emit departureUpdated(resId);
updateArrivalData(dep, resId);
break;
}
});
......@@ -195,13 +201,67 @@ void LiveDataManager::checkTrainTrip(const TrainTrip& trip, const QString& resId
continue;
}
qCDebug(Log) << "Found arrival information:" << arr.route().line().name() << arr.expectedPlatform() << arr.expectedDepartureTime();
m_arrivals.insert(resId, arr);
storePublicTransportData(resId, arr, QStringLiteral("arrival"));
emit arrivalUpdated(resId);
updateArrivalData(arr, resId);
break;
}
});
}
void LiveDataManager::updateArrivalData(const KPublicTransport::Departure &arr, const QString &resId)
{
const auto oldArr = m_departures.value(resId);
m_departures.insert(resId, arr);
storePublicTransportData(resId, arr, QStringLiteral("arrival"));
// check if something changed
if (oldArr.arrivalDelay() == arr.arrivalDelay() && oldArr.expectedPlatform() == arr.expectedPlatform()) {
return;
}
#ifdef HAVE_NOTIFICATIONS
// check if something worth notifying changed
// ### we could do that even more clever by skipping distant future changes
if (std::abs(oldArr.arrivalDelay() - arr.arrivalDelay()) > 2) {
KNotification::event(KNotification::Notification,
i18n("Delayed arrival on %1", arr.route().line().name()),
i18n("New arrival time is: %1", QLocale().toString(arr.expectedArrivalTime().time())),
QLatin1String("clock"));
}
#endif
emit departureUpdated(resId);
}
void LiveDataManager::updateDepartureData(const KPublicTransport::Departure &dep, const QString &resId)
{
const auto oldDep = m_departures.value(resId);
m_departures.insert(resId, dep);
storePublicTransportData(resId, dep, QStringLiteral("departure"));
// check if something changed
if (oldDep.departureDelay() == dep.departureDelay() && oldDep.expectedPlatform() == dep.expectedPlatform()) {
return;
}
#ifdef HAVE_NOTIFICATIONS
// check if something worth notifying changed
// ### we could do that even more clever by skipping distant future changes
if (std::abs(oldDep.departureDelay() - dep.departureDelay()) > 2) {
KNotification::event(KNotification::Notification,
i18n("Delayed departure on %1", dep.route().line().name()),
i18n("New departure time is: %1", QLocale().toString(dep.expectedDepartureTime().time())),
QLatin1String("clock"));
}
if (oldDep.expectedPlatform() != dep.expectedPlatform() && dep.scheduledPlatform() != dep.expectedPlatform()) {
KNotification::event(KNotification::Notification,
i18n("Platform change on %1", dep.route().line().name()),
i18n("New departure platform is: %1", dep.expectedPlatform()),
QLatin1String("clock"));
}
#endif
emit departureUpdated(resId);
}
void LiveDataManager::loadPublicTransportData(const QString &prefix, QHash<QString, KPublicTransport::Departure> &data) const
......
......@@ -61,6 +61,9 @@ signals:
private:
void checkTrainTrip(const KItinerary::TrainTrip &trip, const QString &resId);
void updateArrivalData(const KPublicTransport::Departure &arr, const QString &resId);
void updateDepartureData(const KPublicTransport::Departure &dep, const QString &resId);
void storePublicTransportData(const QString &resId, const KPublicTransport::Departure &dep, const QString &type) const;
void loadPublicTransportData();
void loadPublicTransportData(const QString &prefix, QHash<QString, KPublicTransport::Departure>& data) const;
......
Markdown is supported
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