2023-08-18 10:53:03 +00:00
|
|
|
#include "StatusQ/stringutilsinternal.h"
|
|
|
|
|
2023-09-22 10:02:30 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileSelector>
|
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QQmlFileSelector>
|
|
|
|
|
2023-09-22 10:08:28 +00:00
|
|
|
StringUtilsInternal::StringUtilsInternal(QQmlEngine* engine, QObject* parent)
|
2023-09-22 10:02:30 +00:00
|
|
|
: m_engine(engine)
|
|
|
|
, QObject(parent)
|
2023-09-22 10:08:28 +00:00
|
|
|
{ }
|
2023-08-18 10:53:03 +00:00
|
|
|
|
2023-09-22 10:08:28 +00:00
|
|
|
QString StringUtilsInternal::escapeHtml(const QString& unsafe) const
|
2023-08-18 10:53:03 +00:00
|
|
|
{
|
|
|
|
return unsafe.toHtmlEscaped();
|
|
|
|
}
|
|
|
|
|
2023-09-22 10:02:30 +00:00
|
|
|
QString StringUtilsInternal::readTextFile(const QString& filePath) const
|
2023-08-18 10:53:03 +00:00
|
|
|
{
|
2023-09-22 10:02:30 +00:00
|
|
|
auto selector = QQmlFileSelector::get(m_engine);
|
|
|
|
if (!selector) {
|
|
|
|
qWarning() << Q_FUNC_INFO << "No QQmlFileSelector available to load text file:" << filePath;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto resolvedFilePath = selector->selector()->select(filePath);
|
|
|
|
|
|
|
|
QFile file(resolvedFilePath);
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
qWarning() << Q_FUNC_INFO << "Error opening" << resolvedFilePath << "for reading";
|
|
|
|
return {};
|
|
|
|
}
|
2023-08-18 10:53:03 +00:00
|
|
|
|
2023-09-22 10:02:30 +00:00
|
|
|
return file.readAll();
|
2023-08-18 10:53:03 +00:00
|
|
|
}
|