diff --git a/src/Lib/Ass/AssFactory.cc b/src/Lib/Ass/AssFactory.cc index 08ca4b7e08e93d57f0ca273adb463fb27b2032cf..93f8a92dddfeaee1929db77d0ca3b74dcf58dab2 100644 --- a/src/Lib/Ass/AssFactory.cc +++ b/src/Lib/Ass/AssFactory.cc @@ -23,9 +23,10 @@ AssFactory::initFromStorage() noexcept // Dectect sections else if (line.startsWith("[") && line.endsWith("]")) { currentSection = line.mid(1, line.size() - 2); - qDebug() << "Parsing section" << currentSection; + logDebug() << "Parsing section " << VIVY_LOG_QUOTED(currentSection); if (!validSections.contains(currentSection)) { - qWarning() << "The current section" << currentSection << "is invalid, ignoring it"; + logWarning() << "The current section " << VIVY_LOG_QUOTED(currentSection) + << " is invalid, ignoring it"; currentSection = ""; } } @@ -37,12 +38,12 @@ AssFactory::initFromStorage() noexcept // Easy way to see if the line was invalid if (separatorIndex < 0) - qWarning() << "Invalid line #" << lineIndex << ":" << line; + logWarning() << "Invalid line #" << lineIndex << ": " << line; // Script's info else if (currentSection == sectionScriptInfo) { assInfo.insert(line.mid(0, separatorIndex), line.mid(baseValueIndex)); - qDebug() << "Got line #" << lineIndex << ":" << line; + logDebug() << "Got line #" << lineIndex << ": " << line; } // Skip the headers and the comment lines @@ -65,10 +66,10 @@ AssFactory::initFromStorage() noexcept for (const auto &assLine : eventsContent) assLines.push_back(std::make_shared<Line>(this, assLine)); } catch (const std::runtime_error &e) { - qCritical() << "Failed to create ASS style or events with error:" << e.what(); + logError() << "Failed to create ASS style or events with error: " << e.what(); } - qDebug() << "Got" << assLines.size() << "ASS dialog lines"; + logDebug() << "Got " << assLines.size() << " ASS dialog lines"; return true; } @@ -77,7 +78,7 @@ bool AssFactory::checkValidity() const noexcept { if (assInfo.isEmpty()) { - qCritical() << "Empty info section"; + logError() << "Empty info section"; return false; } @@ -87,7 +88,7 @@ AssFactory::checkValidity() const noexcept while (it != end) { bool ok = false; if (intTypeFields.contains(it.key()) && (static_cast<void>(it.value().toInt(&ok)), !ok)) { - qCritical() << it.key() << "is not an integer:" << it.value(); + logError() << it.key() << " is not an integer: " << it.value(); return false; } ++it; @@ -97,8 +98,8 @@ AssFactory::checkValidity() const noexcept for (const auto &fixedValues : checkedValues) { if (const auto &first = fixedValues.first; assInfo.contains(first) && assInfo[first] != fixedValues.second) { - qCritical() << "Invalid" << first << "as it should be equal to" << fixedValues.second - << "but was" << assInfo[first]; + logError() << "Invalid " << first << " as it should be equal to " << fixedValues.second + << " but was " << assInfo[first]; return false; } } diff --git a/src/Lib/Ass/AssFactory.hh b/src/Lib/Ass/AssFactory.hh index b220c0f1995a4c633664cb42554505080b494452..98c8f3fea31fd3513f238b77c181f61f69b9e0e1 100644 --- a/src/Lib/Ass/AssFactory.hh +++ b/src/Lib/Ass/AssFactory.hh @@ -1,6 +1,7 @@ -#ifndef VIVY_ASS_FACTORY_H -#define VIVY_ASS_FACTORY_H +#pragma once +#include "../../VivyApplication.hh" +#include "../Log.hh" #include "../Utils.hh" #include "Style.hh" #include "Line.hh" @@ -13,6 +14,7 @@ namespace Vivy::Ass { class AssFactory final { VIVY_UNMOVABLE_OBJECT(AssFactory) + VIVY_APP_LOGGABLE_OBJECT(AssFactory, logger) public: enum class Section { ScriptInfo = 1, Styles = 2, Events = 3 }; @@ -55,7 +57,4 @@ public: void getStyles(QVector<StylePtr> &) const noexcept; void getLines(QVector<LinePtr> &) const noexcept; }; - } - -#endif // VIVY_ASS_FACTORY_H diff --git a/src/Lib/Ass/Line.cc b/src/Lib/Ass/Line.cc index fe0b257ab4585b7d0d962f2577177238cd328db9..046e313168aeaaf52a917bafc7e0a00d0f7ea718 100644 --- a/src/Lib/Ass/Line.cc +++ b/src/Lib/Ass/Line.cc @@ -65,7 +65,8 @@ Line::initSylFromString(const QString &line) noexcept // Matches syllabes like: `{\toto}{\alpha&HFF}content` QRegularExpression re("((?:{[^}]*})+[^{]*)"); if (!re.isValid()) - qFatal("The regex '%s' is not valid...", re.pattern().toStdString().c_str()); + logFatal() << "The regex " << VIVY_LOG_QUOTED(re.pattern().toStdString().c_str()) + << " is not valid..."; bool once = false; try { @@ -77,9 +78,8 @@ Line::initSylFromString(const QString &line) noexcept once |= true; } } catch (const std::runtime_error &e) { - qCritical() << "Failed to init syllabes with line:" << line; - qCritical() << "Error was:" << e.what(); - qCritical() << "Fallback to all line is one syllabe"; + qCritical() << "Failed to init syllabes with line: " << VIVY_LOG_QUOTED(line) + << ". Error was: " << e.what() << ". Fallback to all line is one syllabe"; once = false; } diff --git a/src/Lib/Ass/Line.hh b/src/Lib/Ass/Line.hh index 15984da129990d512c3cdc388b67143a4d808d08..11f91de64ed4c0c204b096080b16ec453f97eb63 100644 --- a/src/Lib/Ass/Line.hh +++ b/src/Lib/Ass/Line.hh @@ -1,5 +1,7 @@ #pragma once +#include "../../VivyApplication.hh" +#include "../Log.hh" #include "Syl.hh" #include "StyleProperties.hh" #include "Style.hh" @@ -9,7 +11,8 @@ namespace Vivy::Ass class AssFactory; class Line final { -private: + VIVY_APP_LOGGABLE_OBJECT(Line, logger) + quint64 start{ 0 }; quint64 end{ 0 }; int layer{ 0 }; diff --git a/src/Lib/Ass/Style.cc b/src/Lib/Ass/Style.cc index 1a6ce05cc1658ca8169c81a338917cb37f535ba8..2f80c9d1db58c37be84001ba4bd3ca5b3b1072ed 100644 --- a/src/Lib/Ass/Style.cc +++ b/src/Lib/Ass/Style.cc @@ -102,7 +102,7 @@ Style::Style(const QString &styleString) Utils::decodeLineToInteger(content[StyleIndex::Encoding], "Encoding is not an integer"); if (encoding != 1) - qWarning() << "Encoding is not '1' in the ASS Style"; + logWarning() << "Encoding is not '1' in the ASS Style"; } QString @@ -127,13 +127,8 @@ Color::fromString(const QString &colorString) noexcept startIndex++; // A valid string color is like 'AARRGGBB' for now (skipped 'aH') - if (colorString.size() - startIndex != 8) { - qCritical() - << "Invalid color string: size - index_start =" << (colorString.size() - startIndex) - << "| string =" << colorString.mid(startIndex); - qCritical() << "Found an invalid color string:" << colorString; + if (colorString.size() - startIndex != 8) return Color::defaultValue; - } bool ok_alpha = false; bool ok_red = false; @@ -144,10 +139,8 @@ Color::fromString(const QString &colorString) noexcept int green = colorString.mid(startIndex + 4, 2).toInt(&ok_green, 16); int blue = colorString.mid(startIndex + 6, 2).toInt(&ok_blue, 16); - if (!(ok_alpha && ok_red && ok_green && ok_blue)) { - qCritical() << "Found an invalid color string:" << colorString; + if (!(ok_alpha && ok_red && ok_green && ok_blue)) return Color::defaultValue; - } return QColor(red, green, blue, alpha); } diff --git a/src/Lib/Ass/Style.hh b/src/Lib/Ass/Style.hh index 696cfc79e4b082a14e8b3ad295e31455611f283c..c6c5f10b91924355bb23f33039a1a34b278a2e2d 100644 --- a/src/Lib/Ass/Style.hh +++ b/src/Lib/Ass/Style.hh @@ -1,5 +1,7 @@ #pragma once +#include "../../VivyApplication.hh" +#include "../Log.hh" #include "AssPrivate.hh" namespace Vivy::Ass @@ -15,7 +17,8 @@ private: }; class Style final { -private: + VIVY_APP_LOGGABLE_OBJECT(Style, logger) + QString styleName; QString fontName; int fontSize{}; diff --git a/src/Lib/Ass/Syl.cc b/src/Lib/Ass/Syl.cc index bac0a4d0363e269ec1d984466a767881c53108a6..65d29a85cd80ce92f5a259edfed905f59f6440f1 100644 --- a/src/Lib/Ass/Syl.cc +++ b/src/Lib/Ass/Syl.cc @@ -1,8 +1,6 @@ #include "Syl.hh" #include "Line.hh" -#include <QRegularExpression> - using namespace Vivy::Ass; Syl::Syl(Line *const line, const QString &lineString, ConstructMode mode) noexcept @@ -23,9 +21,6 @@ quint64 Syl::getDurationFromString(const QString &line) noexcept { QRegularExpression re("\\\\(?:k|K|ko|kf)(\\d+)"); - if (!re.isValid()) - qFatal("The regex '%s' is not valid...", re.pattern().toStdString().c_str()); - quint64 duration = 0; QRegularExpressionMatchIterator it = re.globalMatch(line); diff --git a/src/Lib/Ass/Syl.hh b/src/Lib/Ass/Syl.hh index 084e14e5f93ea11e001260bae8543aeef48c96d9..461746e90d6f8acf4027ddab62a3fcedf58bdb40 100644 --- a/src/Lib/Ass/Syl.hh +++ b/src/Lib/Ass/Syl.hh @@ -1,10 +1,6 @@ -#ifndef VIVY_SYL_H -#define VIVY_SYL_H +#pragma once #include "StyleProperties.hh" -#include <QString> -#include <QVector> -#include <QtGlobal> namespace Vivy::Ass { @@ -37,7 +33,4 @@ public: private: static quint64 getDurationFromString(const QString &) noexcept; }; - } - -#endif diff --git a/src/Lib/Log.cc b/src/Lib/Log.cc index b8d71f458293634242f1b18111e8a11c19ae7731..8cbebd7594a45800e6fc2b13f1b6f2a80a7506ea 100644 --- a/src/Lib/Log.cc +++ b/src/Lib/Log.cc @@ -144,6 +144,12 @@ LogMessage::operator<<(const std::string &msg) noexcept return (*this << msg.c_str()); } +LogMessage & +LogMessage::operator<<(const QVariant &variant) noexcept +{ + return (*this << variant.toString()); +} + LogMessage & LogMessage::operator<<(const QString &msg) noexcept { @@ -180,6 +186,18 @@ LogMessage::operator<<(const unsigned long i) noexcept return (*this << std::to_string(i)); } +LogMessage & +LogMessage::operator<<(const unsigned long long i) noexcept +{ + return (*this << std::to_string(i)); +} + +LogMessage & +LogMessage::operator<<(const long long i) noexcept +{ + return (*this << std::to_string(i)); +} + LogMessage & LogMessage::operator<<(const int i) noexcept { diff --git a/src/Lib/Log.hh b/src/Lib/Log.hh index b559571d699ec8d1b8620f3c02fb8f5a66f01156..a14b53920c4bc3a08561a799106ffef144cc8c96 100644 --- a/src/Lib/Log.hh +++ b/src/Lib/Log.hh @@ -194,15 +194,18 @@ public: LogMessage &operator<<(const std::string &) noexcept; LogMessage &operator<<(const std::string_view) noexcept; LogMessage &operator<<(const QString &) noexcept; + LogMessage &operator<<(const QVariant &) noexcept; LogMessage &operator<<(const QFileInfo &) noexcept; LogMessage &operator<<(const char *) noexcept; LogMessage &operator<<(const double *) noexcept; LogMessage &operator<<(const char) noexcept; LogMessage &operator<<(const int) noexcept; LogMessage &operator<<(const long) noexcept; + LogMessage &operator<<(const long long) noexcept; LogMessage &operator<<(const unsigned char) noexcept; LogMessage &operator<<(const unsigned int) noexcept; LogMessage &operator<<(const unsigned long) noexcept; + LogMessage &operator<<(const unsigned long long) noexcept; }; // A logger class, a client to LogSink. Will generate and send instances of