Util Class
class ScreenPlay::UtilEasy to use global object to use when certain functionality is not available in QML. More...
Header: | #include <Util> |
Public Functions
Util(QNetworkAccessManager *networkAccessManager, QObject *parent = nullptr) | |
QString | debugMessages() const |
Public Slots
bool | copyPreviewThumbnail(QJsonObject &obj, const QString &name, const QString &destination) |
void | copyToClipboard(const QString &text) const |
QJsonArray | fillArray(const QVector<QString> &items) |
QString | generateRandomString(quint32 length = 32) |
std::optional<InstalledType::InstalledType> | getInstalledTypeFromString(const QString &type) |
SearchType::SearchType | getSearchTypeFromInstalledType(const InstalledType::InstalledType type) |
std::optional<QVersionNumber> | getVersionNumberFromString(const QString &str) |
void | logToGui(QtMsgType type, const QMessageLogContext &context, const QString &msg) |
void | openFolderInExplorer(const QString &url) const |
std::optional<QJsonObject> | openJsonFileToObject(const QString &path) |
std::optional<QString> | openJsonFileToString(const QString &path) |
std::optional<QJsonObject> | parseQByteArrayToQJsonObject(const QByteArray &byteArray) |
void | requestAllLicenses() |
void | requestDataProtection() |
QString | toLocal(const QString &url) |
QString | toString(const QStringList &list) |
bool | writeFile(const QString &text, const QString &absolutePath) |
bool | writeFileFromQrc(const QString &qrcPath, const QString &absolutePath) |
bool | writeJsonObjectToFile(const QString &absoluteFilePath, const QJsonObject &object, bool truncate = true) |
bool | writeSettings(const QJsonObject &obj, const QString &absolutePath) |
Signals
void | debugMessagesChanged(QString debugMessages) |
Detailed Description
Member Function Documentation
Util::Util(QNetworkAccessManager *networkAccessManager, QObject *parent = nullptr)
Constructor.
[static slot]
bool Util::copyPreviewThumbnail(QJsonObject &obj, const QString &name, const QString &destination)
Takes reference to obj. If the copy of the thumbnail is successful, it adds the corresponding settings entry to the json object reference.
[slot]
void Util::copyToClipboard(const QString &text) const
Copies the given string to the clipboard.
[static slot]
QJsonArray Util::fillArray(const QVector<QString> &items)
Util function that converts a QVector of Strings into a QJsonArray.
[static slot]
QString Util::generateRandomString(quint32 length = 32)
Generates a (non secure) random string with the default length of 32. Can contain:
- A-Z
- a-z
- 0-9
[static slot]
std::optional<InstalledType::InstalledType> Util::getInstalledTypeFromString(const QString &type)
Maps the installed type from a QString to an enum. Used for parsing the project.json.
[static slot]
SearchType::SearchType Util::getSearchTypeFromInstalledType(const InstalledType::InstalledType type)
Maps the Search type to an installed type. Used for filtering the installed content.
[static slot]
std::optional<QVersionNumber> Util::getVersionNumberFromString(const QString &str)
Parses a version from a given QString. The QString must be looke like this: 1.0.0 - Major.Minor.Patch. A fixed position is used for parsing (at 0,2,4). Return std::nullopt when not successful.
[static slot]
void Util::logToGui(QtMsgType type, const QMessageLogContext &context, const QString &msg)
Basic logging to the GUI. No logging is done to a log file for now. This string can be copied in the settings tab in the UI.
[slot]
void Util::openFolderInExplorer(const QString &url) const
Opens a native folder window on the given path. Windows and Mac only for now!
[static slot]
std::optional<QJsonObject> Util::openJsonFileToObject(const QString &path)
Opens a json file (absolute path) and tries to convert it to a QJsonObject. Returns std::nullopt when not successful.
[static slot]
std::optional<QString> Util::openJsonFileToString(const QString &path)
Opens a json file (absolute path) and tries to convert it to a QString. Returns std::nullopt when not successful.
[static slot]
std::optional<QJsonObject> Util::parseQByteArrayToQJsonObject(const QByteArray &byteArray)
Parses a QByteArray to a QJsonObject. If returns and std::nullopt on failure.
[slot]
void Util::requestAllLicenses()
Loads all content of the legal folder in the qrc into a property string of this class. allLicenseLoaded is emited when loading is finished.
[slot]
void Util::requestDataProtection()
Loads all dataprotection of the legal folder in the qrc into a property string of this class. allDataProtectionLoaded is emited when loading is finished.
[static slot]
QString Util::toLocal(const QString &url)
Converts the given url string to a local file path.
[static slot]
QString Util::toString(const QStringList &list)
Helper function to append a QStringList into a QString with a space between the items.
[static slot]
bool Util::writeFile(const QString &text, const QString &absolutePath)
Tries to save into a text file with absolute path.
[static slot]
bool Util::writeFileFromQrc(const QString &qrcPath, const QString &absolutePath)
Tries to save into a text file with absolute path.
[static slot]
bool Util::writeJsonObjectToFile(const QString &absoluteFilePath, const QJsonObject &object, bool truncate = true)
Writes a given QJsonObject to a file. The path must be absolute. When truncate is set to true the exsisting json file will be overriten.
[static slot]
bool Util::writeSettings(const QJsonObject &obj, const QString &absolutePath)
Takes ownership of obj and name. Tries to save into a text file with of name.