From 9dd0108731c2435a36cfdb9edb9247c80f00c79f Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 11 Sep 2024 11:54:16 +0200 Subject: [PATCH] ParseJson(): Add parsing for prepaid-options. --- library/src/configuration.cpp | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index 9c07540..09b8b82 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -591,6 +591,49 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate); TariffPrepaidOption.static_end = t; } + } else + if (QString(inner_obj_name) == QString("prepaid_week")) { + if (k->value.IsArray()) { + auto days = k->value.GetArray(); + for (rapidjson::SizeType j=0; j < days.Size(); ++j) { + if (days[j].IsObject()) { + auto weekday = days[j].GetObject(); + for (auto w = weekday.MemberBegin(); w != weekday.MemberEnd(); ++w) { + int day = j+1; // 8 entries + + TariffPrepaidOption.prepaid[day].day = 0; + + QString member(QString::fromStdString(w->name.GetString())); + if (member == "prepaid_day") { + if (w->value.IsInt()) { + rapidjson::SizeType const d = w->value.GetInt(); + if (d != (j+1)) { + qCritical() << "ERROR: misconfigured jsonfile" << d << "!=" << (j+1); + } + TariffPrepaidOption.prepaid[day].day = day; + } + } else + if (member == "prepaid_duration") { + if (w->value.IsInt()) { + TariffPrepaidOption.prepaid[day].duration = w->value.GetInt(); + } + } else + if (member == "prepaid_static_start") { + if (w->value.IsString()) { + QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate); + TariffPrepaidOption.prepaid[day].static_start = t; + } + } else + if (member == "prepaid_static_end") { + if (w->value.IsString()) { + QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate); + TariffPrepaidOption.prepaid[day].static_end = t; + } + } + } + } + } + } } } break; case MemberType::InterpolationType: {