From bc9ebb7d686fb3fa0388989c78269e837053186e Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 17 Jan 2024 15:18:03 +0100 Subject: [PATCH] Implemented helpers: QString getLocation(QString fileName); QString getTariffVersion(QString fileName); QString getTariffInfo(QString fileName); Read project location, tariff location and tariff-info from tariff[].json file. --- utils.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/utils.cpp b/utils.cpp index 870af4e..cab60d3 100644 --- a/utils.cpp +++ b/utils.cpp @@ -30,6 +30,82 @@ int Utils::read1stLineOfFile(QString fileName) { return -1; } +QString Utils::getLocation(QString fileName) { + QString location("N/A"); + QFile f(fileName); + if (f.exists()) { + if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&f); + in.setCodec("UTF-8"); + while(!in.atEnd()) { + QString const &line = in.readLine(); + if (line.indexOf("Project", Qt::CaseInsensitive) != -1) { + int const c = line.indexOf(":"); + if (c != -1) { + location = line.mid(c+1); + if (!location.isEmpty()) { + return location.replace(QChar('"'), QString("")).trimmed(); + } + } + } + } + } + } + + return location; +} + +QString Utils::getTariffVersion(QString fileName) { + QString version("N/A"); + QFile f(fileName); + if (f.exists()) { + if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&f); + in.setCodec("UTF-8"); + while(!in.atEnd()) { + QString const &line = in.readLine(); + if (line.indexOf("Version", Qt::CaseInsensitive) != -1) { + int const c = line.indexOf(":"); + if (c != -1) { + version = line.mid(c+1); + if (!version.isEmpty()) { + return version.replace(QChar('"'), QString("")).trimmed(); + } + } + } + } + } + } + + return version; +} + +QString Utils::getTariffInfo(QString fileName) { + QString info("N/A"); + QFile f(fileName); + if (f.exists()) { + if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&f); + in.setCodec("UTF-8"); + while(!in.atEnd()) { + QString const &line = in.readLine(); + if (line.indexOf("Info", Qt::CaseInsensitive) != -1) { + int const c = line.indexOf(":"); + if (c != -1) { + info = line.mid(c+1); + if (!info.isEmpty()) { + return info.replace(QChar('"'), QString("")).trimmed(); + } + } + } + } + } + } + + return info; + +} + QString Utils::zoneName(quint8 i) { static constexpr char const *zName[] = { "",