Added utilities

void printCriticalErrorMsg(QString const &errorMsg);
    void printInfoMsg(QString const &infoMsg);
    void printLineEditInfo(QStringList const &lines);
    QString getTariffLoadTime(QString fileName);
This commit is contained in:
Gerhard Hoffmann 2023-08-11 11:03:21 +02:00
parent 8f26bfee0f
commit 202e83268b
2 changed files with 52 additions and 1 deletions

View File

@ -1,8 +1,9 @@
#include "utils.h"
#include "message_handler.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
int Utils::read1stLineOfFile(QString fileName) {
QFile f(fileName);
@ -33,3 +34,46 @@ QString Utils::zoneName(quint8 i) {
}
return "N/A";
}
void Utils::printCriticalErrorMsg(QString const &errorMsg) {
qCritical() << QString(80, '!');
qCritical() << errorMsg;
qCritical() << QString(80, '!');
}
void Utils::printInfoMsg(QString const &infoMsg) {
qCritical() << QString(80, '=');
qCritical() << infoMsg;
qCritical() << QString(80, '=');
}
void Utils::printLineEditInfo(QStringList const &lines) {
if (getDebugLevel() == LOG_DEBUG) {
for (int i=0; i<lines.size(); ++i) {
qInfo() << lines.at(i);
} qInfo() << ""; qInfo() << "";
}
}
QString Utils::getTariffLoadTime(QString fileName) {
QFileInfo fInfo(fileName);
if (fInfo.exists()) {
QDateTime lastModifiedTime = fInfo.lastModified();
if (lastModifiedTime.isValid()) {
return lastModifiedTime.toString(Qt::ISODateWithMs);
} else {
printCriticalErrorMsg(fileName + " HAS INVALID MODIFIED-TIME");
QDateTime birthTime = fInfo.birthTime();
if (birthTime.isValid()) {
return birthTime.toString(Qt::ISODateWithMs);
} else {
printCriticalErrorMsg(fileName + " HAS INVALID BIRTH-TIME");
}
}
} else {
printCriticalErrorMsg(fileName + " DOES NOT EXIST");
}
return "N/A";
}

View File

@ -3,11 +3,18 @@
#include <QObject>
#include <QString>
#include <QStringList>
#include <QFile>
#include <QFileInfo>
#include <QDateTime>
namespace Utils {
int read1stLineOfFile(QString fileName);
QString zoneName(quint8 i);
void printCriticalErrorMsg(QString const &errorMsg);
void printInfoMsg(QString const &infoMsg);
void printLineEditInfo(QStringList const &lines);
QString getTariffLoadTime(QString fileName);
}
#endif // UTILS_H_INCLUDED