Commit 8f5f1218 authored by Volker Krause's avatar Volker Krause
Browse files

Allow to show currency conversion rates

This is optional and off by default due to its need for online access.
parent da9aea35
Pipeline #102150 passed with stage
in 1 minute and 9 seconds
......@@ -47,7 +47,7 @@ set(QT_MIN_VERSION 5.15.2)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Test Quick Positioning Location QuickControls2)
find_package(Qt5 CONFIG QUIET OPTIONAL_COMPONENTS QuickCompiler)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS I18n CoreAddons Contacts Notifications)
find_package(KF5 ${KF5_MIN_VERSION} OPTIONAL_COMPONENTS Holidays NetworkManagerQt)
find_package(KF5 ${KF5_MIN_VERSION} OPTIONAL_COMPONENTS Holidays UnitConversion NetworkManagerQt)
find_package(KPimPkPass CONFIG REQUIRED)
find_package(KPimItinerary 5.18.0 CONFIG REQUIRED)
find_package(KPublicTransport CONFIG REQUIRED)
......@@ -89,6 +89,9 @@ endif()
if (TARGET KHealthCertificate)
set(HAVE_KHEALTHCERTIFICATE TRUE)
endif()
if (TARGET KF5::UnitConversion)
set(HAVE_KUNITCONVERSION TRUE)
endif()
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050f00)
add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055600)
......
......@@ -67,8 +67,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "GBP",
"currencyDiffers": true,
"currencyName": "GBP",
"drivingSide": "Left",
"drivingSideDiffers": true,
"isoCode": "GB",
......@@ -151,8 +151,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "USD",
"currencyDiffers": true,
"currencyName": "USD",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "US",
......
......@@ -67,8 +67,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "GBP",
"currencyDiffers": true,
"currencyName": "GBP",
"drivingSide": "Left",
"drivingSideDiffers": true,
"isoCode": "GB",
......@@ -151,8 +151,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "USD",
"currencyDiffers": true,
"currencyName": "USD",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "US",
......
......@@ -318,8 +318,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "EUR",
"currencyDiffers": false,
"currencyName": "EUR",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "IT",
......
......@@ -101,8 +101,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "CHF",
"currencyDiffers": true,
"currencyName": "CHF",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "CH",
......
......@@ -94,8 +94,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "CHF",
"currencyDiffers": true,
"currencyName": "CHF",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "CH",
......
......@@ -284,8 +284,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "EUR",
"currencyDiffers": false,
"currencyName": "EUR",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "IT",
......@@ -484,8 +484,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "USD",
"currencyDiffers": true,
"currencyName": "USD",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "US",
......@@ -643,8 +643,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "USD",
"currencyDiffers": true,
"currencyName": "USD",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "US",
......@@ -775,8 +775,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "CHF",
"currencyDiffers": true,
"currencyName": "CHF",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "CH",
......
......@@ -191,8 +191,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "USD",
"currencyDiffers": true,
"currencyName": "USD",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "US",
......@@ -350,8 +350,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "USD",
"currencyDiffers": true,
"currencyName": "USD",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "US",
......@@ -482,8 +482,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "CHF",
"currencyDiffers": true,
"currencyName": "CHF",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "CH",
......
......@@ -143,8 +143,8 @@
"locationInformation": {
"@context": "http://schema.org",
"@type": "LocationInformation",
"currencyCode": "CHF",
"currencyDiffers": true,
"currencyName": "CHF",
"drivingSide": "Right",
"drivingSideDiffers": false,
"isoCode": "CH",
......
......@@ -79,6 +79,7 @@ target_sources(itinerary-app PRIVATE
countrymodel.cpp
developmentmodecontroller.cpp
documentsmodel.cpp
locationinformationdelegatecontroller.cpp
mapdownloadmanager.cpp
notificationconfigcontroller.cpp
notifyrc.qrc
......@@ -196,6 +197,9 @@ endif()
if (TARGET KF5::Crash)
target_link_libraries(itinerary-app PRIVATE KF5::Crash)
endif()
if (TARGET KF5::UnitConversion)
target_link_libraries(itinerary-app PRIVATE KF5::UnitConversion)
endif()
install(TARGETS itinerary-app ${INSTALL_TARGETS_DEFAULT_ARGS})
ecm_install_icons(ICONS sc-apps-org.kde.itinerary.svg DESTINATION ${KDE_INSTALL_ICONDIR})
......
......@@ -15,7 +15,12 @@ import "." as App
Kirigami.AbstractCard {
id: root
property var locationInfo;
property alias locationInfo: _controller.locationInformation
property QtObject controller: LocationInformationDelegateController {
id: _controller
homeCurrencyCode: Country.fromAlpha2(Settings.homeCountryIsoCode).currencyCode
performCurrencyConversion: Settings.performCurrencyConversion
}
header: Rectangle {
id: headerBackground
......@@ -94,7 +99,7 @@ Kirigami.AbstractCard {
QQC2.Label {
width: topLayout.width
text: i18n("Currency: %1", locationInfo.currencyName)
text: i18n("Currency: %1", controller.hasCurrencyConversion ? controller.currencyConversionLabel : locationInfo.currencyCode)
color: Kirigami.Theme.neutralTextColor
visible: locationInfo.currencyDiffers
wrapMode: Text.WordWrap
......
......@@ -138,6 +138,23 @@ Kirigami.ScrollablePage {
font: Kirigami.Theme.smallFont
}
QQC2.CheckBox {
id: currencyConversion
text: i18n("Currency Conversion")
checked: Settings.performCurrencyConversion
onToggled: Settings.performCurrencyConversion = checked
Layout.fillWidth: true
visible: Settings.hasCurrencyConversion
}
QQC2.Label {
Kirigami.FormData.isSection: true
Layout.fillWidth: true
wrapMode: Text.WordWrap
text: i18n("Enabling this will perform online queries for exchange rates to currencies at travel destinations.")
font: Kirigami.Theme.smallFont
visible: Settings.hasCurrencyConversion
}
// Transfer assistant
Kirigami.Separator {
Kirigami.FormData.isSection: true
......
......@@ -6,3 +6,4 @@
#cmakedefine01 HAVE_KCRASH
#cmakedefine01 HAVE_KHEALTHCERTIFICATE
#cmakedefine01 HAVE_KUNITCONVERSION
......@@ -193,7 +193,7 @@ bool LocationInformation::currencyDiffers() const
return m_currencyDiffers;
}
QString LocationInformation::currencyName() const
QString LocationInformation::currencyCode() const
{
return m_currency;
}
......@@ -34,7 +34,7 @@ class LocationInformation
Q_PROPERTY(int timeZoneOffsetDelta READ timeZoneOffsetDelta)
Q_PROPERTY(bool currencyDiffers READ currencyDiffers)
Q_PROPERTY(QString currencyName READ currencyName)
Q_PROPERTY(QString currencyCode READ currencyCode)
public:
LocationInformation();
......@@ -68,7 +68,7 @@ public:
int timeZoneOffsetDelta() const;
bool currencyDiffers() const;
QString currencyName() const;
QString currencyCode() const;
private:
void setDrivingSide(KItinerary::KnowledgeDb::DrivingSide drivingSide);
......
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "config-itinerary.h"
#include "locationinformationdelegatecontroller.h"
#if HAVE_KUNITCONVERSION
#include <KUnitConversion/Value>
#endif
#include <KLocalizedString>
#include <QDebug>
LocationInformationDelegateController::LocationInformationDelegateController(QObject *parent)
: QObject(parent)
{
}
LocationInformationDelegateController::~LocationInformationDelegateController() = default;
LocationInformation LocationInformationDelegateController::locationInformation() const
{
return m_info;
}
void LocationInformationDelegateController::setLocationInformation(const LocationInformation &info)
{
m_info = info;
Q_EMIT infoChanged();
recheckCurrencyConversion();
}
QString LocationInformationDelegateController::homeCurrencyCode() const
{
return m_homeCurrency;
}
void LocationInformationDelegateController::setHomeCurrencyCode(const QString &currencyCode)
{
if (m_homeCurrency == currencyCode) {
return;
}
m_homeCurrency = currencyCode;
Q_EMIT homeCurrencyCodeChanged();
recheckCurrencyConversion();
}
bool LocationInformationDelegateController::performCurrencyConversion() const
{
return m_performCurrencyConverion;
}
void LocationInformationDelegateController::setPerformCurrencyConversion(bool enable)
{
if (m_performCurrencyConverion == enable) {
return;
}
m_performCurrencyConverion = enable;
Q_EMIT performCurrencyConversionChanged();
recheckCurrencyConversion();
}
bool LocationInformationDelegateController::hasCurrencyConversion() const
{
return m_performCurrencyConverion && m_conversionRate > 0.0f;
}
QString LocationInformationDelegateController::currencyConversionLabel() const
{
return i18nc("currency conversion rate", "1 %1 = %2 %3", m_homeCurrency, m_conversionRate, m_info.currencyCode());
}
void LocationInformationDelegateController::recheckCurrencyConversion()
{
float rate = 0.0f;
#if HAVE_KUNITCONVERSION
if (m_performCurrencyConverion && m_info.currencyDiffers() && !m_homeCurrency.isEmpty()) {
const auto value = KUnitConversion::Value(1.0, m_homeCurrency).convertTo(m_info.currencyCode());
if (value.isValid()) {
rate = value.number();
}
}
#endif
if (rate != m_conversionRate) {
m_conversionRate = rate;
Q_EMIT currencyConversionChanged();
}
}
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef LOCATIONINFORMATIONDELEGATECONTROLLER_H
#define LOCATIONINFORMATIONDELEGATECONTROLLER_H
#include "locationinformation.h"
#include <QObject>
/** Logic for location information delegates. */
class LocationInformationDelegateController : public QObject
{
Q_OBJECT
Q_PROPERTY(LocationInformation locationInformation READ locationInformation WRITE setLocationInformation NOTIFY infoChanged)
Q_PROPERTY(QString homeCurrencyCode READ homeCurrencyCode WRITE setHomeCurrencyCode NOTIFY homeCurrencyCodeChanged)
Q_PROPERTY(bool performCurrencyConversion READ performCurrencyConversion WRITE setPerformCurrencyConversion NOTIFY performCurrencyConversionChanged)
Q_PROPERTY(bool hasCurrencyConversion READ hasCurrencyConversion NOTIFY currencyConversionChanged)
Q_PROPERTY(QString currencyConversionLabel READ currencyConversionLabel NOTIFY currencyConversionChanged)
public:
explicit LocationInformationDelegateController(QObject *parent = nullptr);
~LocationInformationDelegateController();
LocationInformation locationInformation() const;
void setLocationInformation(const LocationInformation &info);
QString homeCurrencyCode() const;
void setHomeCurrencyCode(const QString &currencyCode);
bool performCurrencyConversion() const;
void setPerformCurrencyConversion(bool enable);
bool hasCurrencyConversion() const;
QString currencyConversionLabel() const;
Q_SIGNALS:
void infoChanged();
void homeCurrencyCodeChanged();
void currencyConversionChanged();
void performCurrencyConversionChanged();
private:
void recheckCurrencyConversion();
LocationInformation m_info;
QString m_homeCurrency;
float m_conversionRate = 0.0f;
bool m_performCurrencyConverion = false;
};
#endif // LOCATIONINFORMATIONDELEGATECONTROLLER_H
......@@ -18,6 +18,7 @@
#include "livedatamanager.h"
#include "localizer.h"
#include "locationinformation.h"
#include "locationinformationdelegatecontroller.h"
#include "mapdownloadmanager.h"
#include "navigationcontroller.h"
#include "notificationconfigcontroller.h"
......@@ -111,6 +112,7 @@ void registerApplicationTypes()
qmlRegisterType<CountryModel>("org.kde.itinerary", 1, 0, "CountryModel");
qmlRegisterType<DocumentsModel>("org.kde.itinerary", 1, 0, "DocumentsModel");
qmlRegisterType<LocationInformationDelegateController>("org.kde.itinerary", 1, 0, "LocationInformationDelegateController");
qmlRegisterType<QSortFilterProxyModel>("org.kde.itinerary", 1, 0, "SortFilterProxyModel"); // TODO use this from kitemmodels?
qmlRegisterType<StatisticsModel>("org.kde.itinerary", 1, 0, "StatisticsModel");
qmlRegisterType<StatisticsTimeRangeModel>("org.kde.itinerary", 1, 0, "StatisticsTimeRangeModel");
......
......@@ -4,6 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "config-itinerary.h"
#include "settings.h"
#include <KCountry>
......@@ -26,6 +27,8 @@ Settings::Settings(QObject *parent)
m_preloadMapData = s.value(QLatin1String("PreloadMapData"), false).toBool();
m_currencyConversion = s.value(QLatin1String("PerformCurrencyConversion"), false).toBool();
m_autoAddTransfers = s.value(QLatin1String("AutoAddTransfers"), true).toBool();
m_autoFillTransfers = s.value(QLatin1String("AutoFillTransfers"), false).toBool() && m_queryLiveData && m_autoAddTransfers;
......@@ -116,6 +119,34 @@ void Settings::setPreloadMapData(bool preload)
Q_EMIT preloadMapDataChanged(preload);
}
bool Settings::hasCurrencyConversion() const
{
#if HAVE_KUNITCONVERSION
return true;
#else
return false;
#endif
}
bool Settings::performCurrencyConversion() const
{
return m_currencyConversion;
}
void Settings::setPerformCurrencyConversion(bool enable)
{
if (m_currencyConversion == enable) {
return;
}
m_currencyConversion = enable;
QSettings s;
s.beginGroup(QLatin1String("Settings"));
s.setValue(QLatin1String("PerformCurrencyConversion"), enable);
Q_EMIT performCurrencyConversionChanged(enable);
}
bool Settings::autoAddTransfers() const
{
return m_autoAddTransfers;
......
......@@ -18,6 +18,9 @@ class Settings : public QObject
Q_PROPERTY(bool queryLiveData READ queryLiveData WRITE setQueryLiveData NOTIFY queryLiveDataChanged)
Q_PROPERTY(bool preloadMapData READ preloadMapData WRITE setPreloadMapData NOTIFY preloadMapDataChanged)
Q_PROPERTY(bool hasCurrencyConversion READ hasCurrencyConversion CONSTANT)
Q_PROPERTY(bool performCurrencyConversion READ performCurrencyConversion WRITE setPerformCurrencyConversion NOTIFY performCurrencyConversionChanged)
Q_PROPERTY(bool autoAddTransfers READ autoAddTransfers WRITE setAutoAddTransfers NOTIFY autoAddTransfersChanged)
Q_PROPERTY(bool autoFillTransfers READ autoFillTransfers WRITE setAutoFillTransfers NOTIFY autoFillTransfersChanged)
......@@ -41,6 +44,10 @@ public:
bool preloadMapData() const;
void setPreloadMapData(bool preload);
bool hasCurrencyConversion() const;
bool performCurrencyConversion() const;
void setPerformCurrencyConversion(bool enable);
bool autoAddTransfers() const;
void setAutoAddTransfers(bool autoAdd);
bool autoFillTransfers() const;
......@@ -57,6 +64,7 @@ Q_SIGNALS:
void homeCountryIsoCodeChanged(const QString &isoCode);
void queryLiveDataChanged(bool enabled);
void preloadMapDataChanged(bool preload);
void performCurrencyConversionChanged(bool enabled);
void autoAddTransfersChanged(bool autoAdd);
void autoFillTransfersChanged(bool autoFill);
void showNotificationOnLockScreenChanged(bool enabled);
......@@ -67,6 +75,7 @@ private:
bool m_weatherEnabled = false;
bool m_queryLiveData = false;
bool m_preloadMapData = false;
bool m_currencyConversion = false;
bool m_autoAddTransfers = true;
bool m_autoFillTransfers = false;
bool m_showNotificationOnLockScreen = false;
......
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