Commit e5cea2f7 authored by Volker Krause's avatar Volker Krause

Also show warnings about partial power plug incompatibilities

This now warns about the Swiss Type J socket for example, when coming from
a Europlug/Schuko country.
parent 53c96c4e
......@@ -157,14 +157,14 @@ private slots:
auto countryInfo = model.index(0, 0).data(TimelineModel::CountryInformationRole).value<CountryInformation>();
QCOMPARE(countryInfo.drivingSide(), KItinerary::KnowledgeDb::DrivingSide::Left);
QCOMPARE(countryInfo.drivingSideDiffers(), true);
QCOMPARE(countryInfo.powerPlugTypesDiffer(), true);
QCOMPARE(countryInfo.powerPlugCompatibility(), CountryInformation::Incompatible);
QCOMPARE(model.index(1, 0).data(TimelineModel::ElementTypeRole), TimelineModel::Flight);
QCOMPARE(model.index(2, 0).data(TimelineModel::ElementTypeRole), TimelineModel::CountryInfo);
countryInfo = model.index(2, 0).data(TimelineModel::CountryInformationRole).value<CountryInformation>();
QCOMPARE(countryInfo.drivingSide(), KItinerary::KnowledgeDb::DrivingSide::Right);
QCOMPARE(countryInfo.drivingSideDiffers(), false);
QCOMPARE(countryInfo.powerPlugTypesDiffer(), true);
QCOMPARE(countryInfo.powerPlugCompatibility(), CountryInformation::Incompatible);
QCOMPARE(model.index(3, 0).data(TimelineModel::ElementTypeRole), TimelineModel::Flight);
QCOMPARE(model.index(4, 0).data(TimelineModel::ElementTypeRole), TimelineModel::TodayMarker);
......
......@@ -61,9 +61,19 @@ Kirigami.AbstractCard {
}
QQC2.Label {
text: qsTr("Incompatible power plugs: %1").arg(countryInfo.powerPlugTypes)
text: qsTr("No compatible power sockets: %1").arg(countryInfo.powerSocketTypes)
color: Kirigami.Theme.negativeTextColor
visible: countryInfo.powerPlugTypesDiffer
visible: countryInfo.powerPlugCompatibility == CountryInformation.Incompatible
}
QQC2.Label {
text: qsTr("Some incompatible power sockets: %1").arg(countryInfo.powerSocketTypes)
color: Kirigami.Theme.negativeTextColor
visible: countryInfo.powerPlugCompatibility == CountryInformation.PartiallyCompatible && countryInfo.powerSocket != ""
}
QQC2.Label {
text: qsTr("Some incompatible power plugs: %1").arg(countryInfo.powerPlugTypes)
color: Kirigami.Theme.negativeTextColor
visible: countryInfo.powerPlugCompatibility == CountryInformation.PartiallyCompatible && countryInfo.powerPlugTypes != ""
}
}
}
......
......@@ -32,7 +32,8 @@ CountryInformation::~CountryInformation() = default;
bool CountryInformation::operator==(const CountryInformation& other) const
{
const auto dsEqual = m_drivingSide == other.m_drivingSide || m_drivingSide == KnowledgeDb::DrivingSide::Unknown || other.m_drivingSide == KnowledgeDb::DrivingSide::Unknown;
const auto ppEqual = (m_powerPlugs & other.m_powerPlugs) || m_powerPlugs == KnowledgeDb::Unknown || other.m_powerPlugs == KnowledgeDb::Unknown;
const auto ppEqual = (m_incompatPlugs == other.m_incompatPlugs && m_incompatSockets == other.m_incompatSockets)
|| m_powerPlugs == KnowledgeDb::Unknown || other.m_powerPlugs == KnowledgeDb::Unknown;
return dsEqual && ppEqual;
}
......@@ -76,6 +77,16 @@ void CountryInformation::setDrivingSide(KnowledgeDb::DrivingSide drivingSide)
m_drivingSide = drivingSide;
}
bool CountryInformation::drivingSideDiffers() const
{
return m_drivingSideDiffers;
}
CountryInformation::PowerPlugCompatibility CountryInformation::powerPlugCompatibility() const
{
return m_powerPlugCompat;
}
struct plugTypeName {
KnowledgeDb::PowerPlugType type;
const char *name;
......@@ -98,37 +109,42 @@ static const plug_name_table[] = {
{ KnowledgeDb::TypeN, I18N_NOOP("Type N") },
};
QString CountryInformation::powerPlugTypes() const
static QString plugTypesToString(KnowledgeDb::PowerPlugTypes type)
{
QStringList l;
for (const auto &elem : plug_name_table) {
if (m_powerPlugs & elem.type) {
if (type & elem.type) {
l.push_back(i18n(elem.name));
}
}
return l.join(QLatin1String(", "));
}
QString CountryInformation::powerPlugTypes() const
{
return plugTypesToString(m_incompatPlugs);
}
QString CountryInformation::powerSocketTypes() const
{
return plugTypesToString(m_incompatSockets);
}
void CountryInformation::setPowerPlugTypes(KItinerary::KnowledgeDb::PowerPlugTypes powerPlugs)
{
// TODO deal with partial incompatibilities and compatibilities between plug types
if (m_powerPlugs == powerPlugs || powerPlugs == KnowledgeDb::Unknown) {
return;
}
m_incompatPlugs = KnowledgeDb::incompatiblePowerPlugs(m_powerPlugs, powerPlugs);
m_incompatSockets = KnowledgeDb::incompatiblePowerSockets(m_powerPlugs, powerPlugs);
if ((m_powerPlugs & powerPlugs) == 0) {
m_powerPlugTypesDiffer = true;
m_powerPlugCompat = Incompatible;
} else if (m_incompatPlugs != KnowledgeDb::Unknown || m_incompatSockets != KnowledgeDb::Unknown) {
m_powerPlugCompat = PartiallyCompatible;
}
m_powerPlugs = powerPlugs;
}
bool CountryInformation::drivingSideDiffers() const
{
return m_drivingSideDiffers;
}
bool CountryInformation::powerPlugTypesDiffer() const
{
return m_powerPlugTypesDiffer;
}
......@@ -33,13 +33,23 @@ class CountryInformation
/** This indicates that the driving side information changed and needs to be displayed. */
Q_PROPERTY(bool drivingSideDiffers READ drivingSideDiffers)
Q_PROPERTY(PowerPlugCompatibility powerPlugCompatibility READ powerPlugCompatibility)
/** Plugs from the home country that will not fit. */
Q_PROPERTY(QString powerPlugTypes READ powerPlugTypes)
Q_PROPERTY(bool powerPlugTypesDiffer READ powerPlugTypesDiffer)
/** Sockets in the destination country that are incompatible with (some of) my plugs. */
Q_PROPERTY(QString powerSocketTypes READ powerSocketTypes)
public:
CountryInformation();
~CountryInformation();
enum PowerPlugCompatibility {
FullyCompatible,
PartiallyCompatible,
Incompatible
};
Q_ENUM(PowerPlugCompatibility)
bool operator==(const CountryInformation &other) const;
QString isoCode() const;
......@@ -48,8 +58,9 @@ public:
KItinerary::KnowledgeDb::DrivingSide drivingSide() const;
bool drivingSideDiffers() const;
PowerPlugCompatibility powerPlugCompatibility() const;
QString powerPlugTypes() const;
bool powerPlugTypesDiffer() const;
QString powerSocketTypes() const;
private:
void setDrivingSide(KItinerary::KnowledgeDb::DrivingSide drivingSide);
......@@ -57,9 +68,11 @@ private:
QString m_isoCode;
KItinerary::KnowledgeDb::PowerPlugTypes m_powerPlugs = KItinerary::KnowledgeDb::Unknown;
KItinerary::KnowledgeDb::PowerPlugTypes m_incompatPlugs = KItinerary::KnowledgeDb::Unknown;
KItinerary::KnowledgeDb::PowerPlugTypes m_incompatSockets = KItinerary::KnowledgeDb::Unknown;
KItinerary::KnowledgeDb::DrivingSide m_drivingSide = KItinerary::KnowledgeDb::DrivingSide::Unknown;
bool m_drivingSideDiffers = false;
bool m_powerPlugTypesDiffer = false;
PowerPlugCompatibility m_powerPlugCompat = FullyCompatible;
};
Q_DECLARE_METATYPE(CountryInformation)
......
......@@ -19,6 +19,7 @@
#include "logging.h"
#include "applicationcontroller.h"
#include "countryinformation.h"
#include "localizer.h"
#include "pkpassmanager.h"
#include "timelinemodel.h"
......@@ -115,6 +116,7 @@ int main(int argc, char **argv)
qmlRegisterUncreatableType<KItinerary::Ticket>("org.kde.kitinerary", 1, 0, "Ticket", {});
qmlRegisterUncreatableMetaObject(KItinerary::KnowledgeDb::staticMetaObject, "org.kde.kitinerary", 1, 0, "KnowledgeDb", {});
qmlRegisterUncreatableType<CountryInformation>("org.kde.itinerary", 1, 0, "CountryInformation", {});
qmlRegisterUncreatableType<TimelineModel>("org.kde.itinerary", 1, 0, "TimelineModel", {});
qmlRegisterSingletonType<Localizer>("org.kde.itinerary", 1, 0, "Localizer", [](QQmlEngine*, QJSEngine*) -> QObject*{
return new Localizer;
......
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