From d705855ef04c0d1cf36e3468a988013150e30514 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Thu, 24 Jun 2021 23:50:46 +0200 Subject: [PATCH] MISC: Use Qt's log macros instead of redefining them --- src/Document/CRTPDocument.h | 2 +- src/Document/VivyDocument.cc | 24 ++++++++++++------------ src/Document/VivyDocumentStore.cc | 10 +++++----- src/Document/VivyDocumentView.cc | 2 +- src/MainWindow.cc | 12 ++++++------ src/Utils.cc | 2 -- src/Utils.h | 5 ----- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/Document/CRTPDocument.h b/src/Document/CRTPDocument.h index 1f6fd569..7c998a1e 100644 --- a/src/Document/CRTPDocument.h +++ b/src/Document/CRTPDocument.h @@ -47,7 +47,7 @@ protected: public: [[nodiscard("allocated")]] static Document *fromFile(const QString &path) noexcept { - LOG_DEBUG("Init document from file " << path); + qDebug() << "Init document from file " << path; Document *ret = new Document(); ret->filePath = path; ret->initFromPath(path); diff --git a/src/Document/VivyDocument.cc b/src/Document/VivyDocument.cc index 484186fc..ccb47a2a 100644 --- a/src/Document/VivyDocument.cc +++ b/src/Document/VivyDocument.cc @@ -8,7 +8,7 @@ VivyDocument::VivyDocument(const QString &name) : documentName(name) { - LOG_DEBUG("CONSTRUCTOR: VivyDocument(" << name << ")"); + qDebug() << "CONSTRUCTOR: VivyDocument(" << name << ")"; } auto @@ -20,17 +20,17 @@ VivyDocument::loadSubDocument(const QString &name) noexcept -> bool if (detectDocumentType(file, &type)) { switch (type) { case SubDocument::AudioAble: - LOG_DEBUG("Create an audio subDocument from " << name); + qDebug() << "Create an audio subDocument from " << name; audioDocument = std::unique_ptr<AudioDocument>(AudioDocument::fromFile(file.absoluteFilePath())); return true; case SubDocument::VideoAble: - LOG_DEBUG("Create a video subDocument from " << name); + qDebug() << "Create a video subDocument from " << name; videoDocument = std::unique_ptr<VideoDocument>(VideoDocument::fromFile(file.absoluteFilePath())); return true; case SubDocument::AssAble: - LOG_DEBUG("Create an ass subDocument from " << name); + qDebug() << "Create an ass subDocument from " << name; assDocument = std::unique_ptr<AssDocument>(AssDocument::fromFile(file.absoluteFilePath())); return true; } @@ -45,23 +45,23 @@ VivyDocument::loadSubDocument(const QString &name, VivyDocument::SubDocument asT QFileInfo file(name); SubDocument type; if (!detectDocumentType(file, &type)) { - LOG_DEBUG("Failed to detect type for file " << name); + qCritical() << "Failed to detect type for file " << name; return false; } if (type == SubDocument::AssAble && asType == SubDocument::AssAble) { - LOG_DEBUG("Create an ass subDocument from " << name); + qDebug() << "Create an ass subDocument from " << name; assDocument = std::unique_ptr<AssDocument>(AssDocument::fromFile(file.absoluteFilePath())); } else if (type == SubDocument::VideoAble && asType == SubDocument::VideoAble) { - LOG_DEBUG("Create a video subDocument from " << name); + qDebug() << "Create a video subDocument from " << name; videoDocument = std::unique_ptr<VideoDocument>(VideoDocument::fromFile(file.absoluteFilePath())); } else if (const bool requestAudio = (asType == SubDocument::AudioAble); (type == SubDocument::VideoAble && requestAudio) || (type == SubDocument::AudioAble && requestAudio)) { - LOG_DEBUG("Create an audio subDocument from " << name); + qDebug() << "Create an audio subDocument from " << name; audioDocument = std::unique_ptr<AudioDocument>(AudioDocument::fromFile(file.absoluteFilePath())); } @@ -103,18 +103,18 @@ VivyDocument::rename(const QString &name) noexcept -> bool QDir dirOp; const QString newAbsDirPath = newPath.dir().absolutePath(); if (!dirOp.exists(newAbsDirPath)) { - LOG_DEBUG("Create folder " << newAbsDirPath); + qInfo() << "Create folder " << newAbsDirPath; dirOp.mkpath(newAbsDirPath); } if (dirOp.rename(oldPath.absoluteFilePath(), newPath.absoluteFilePath())) { documentLocation = newPath.dir(); documentName = newPath.baseName(); - LOG_DEBUG("Rename " << oldPath << " to " << newPath); + qDebug() << "Rename " << oldPath << " to " << newPath; return true; } - LOG_DEBUG("Failed to rename " << oldPath << " to " << newPath); + qCritical() << "Failed to rename " << oldPath << " to " << newPath; return false; } @@ -142,7 +142,7 @@ VivyDocument::fromPath(const QString &path) noexcept -> VivyDocument * QFileInfo file(path); VivyDocument *ret = new VivyDocument(file.baseName()); if (!ret->loadSubDocument(path, SubDocument::AudioAble)) { - LOG_ERROR("Failed to create VIVY document from file " << path); + qCritical() << "Failed to create VIVY document from file " << path; delete ret; return nullptr; } diff --git a/src/Document/VivyDocumentStore.cc b/src/Document/VivyDocumentStore.cc index d30c3402..50095f78 100644 --- a/src/Document/VivyDocumentStore.cc +++ b/src/Document/VivyDocumentStore.cc @@ -17,17 +17,17 @@ VivyDocumentStore::loadDocument([[maybe_unused]] const QString &file) noexcept QFileInfo fileinfo(file); QString baseName = fileinfo.baseName(); if (VivyDocument *found = documents.value(baseName, nullptr); found != nullptr) { - LOG_ERROR("A document with the same name " << baseName << " was already loaded!"); + qCritical() << "A document with the same name " << baseName << " was already loaded!"; return found; } VivyDocument *ret = VivyDocument::fromPath(file); if (!ret) { - LOG_DEBUG("Failed to create document"); + qDebug() << "Failed to create document from " << file; return nullptr; } - LOG_DEBUG("Register document " << baseName); + qDebug() << "Register document " << baseName; documents[baseName] = ret; return ret; } @@ -42,7 +42,7 @@ VivyDocument * VivyDocumentStore::getDocument(const QString &name) const noexcept { if (!documents.contains(name)) { - LOG_ERROR("Couldn't find the document " << name); + qCritical() << "Couldn't find the document " << name; return nullptr; } return documents.value(name); @@ -52,7 +52,7 @@ VivyDocumentView * VivyDocumentStore::getDocumentView(const QString &name) const noexcept { if (!documents.contains(name)) { - LOG_ERROR("Can't get a view to a non-existant document " << name); + qCritical() << "Can't get a view to a non-existant document " << name; return nullptr; } VivyDocumentView *ret = new VivyDocumentView(documents.value(name)); diff --git a/src/Document/VivyDocumentView.cc b/src/Document/VivyDocumentView.cc index 2197b9aa..e40ce8d1 100644 --- a/src/Document/VivyDocumentView.cc +++ b/src/Document/VivyDocumentView.cc @@ -8,7 +8,7 @@ VivyDocumentView::VivyDocumentView(VivyDocument *doc) noexcept : document(*doc) { AudioDocument *const audioDocument = document.getAudioSubDocument(); - LOG_DEBUG("Create an audio vizualizer for the audio sub document " << audioDocument->getFilePath()); + qDebug() << "Create an audio vizualizer for the audio sub document " << audioDocument->getFilePath(); if (audioDocument != nullptr) { visualizer = AudioVisualizer::fromFile(audioDocument->getFilePath()); assert(visualizer != nullptr); diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 2c69d432..cf5539b5 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -44,25 +44,25 @@ MainWindow::openAudioFile() noexcept { QString filename = QFileDialog::getOpenFileName(this, "Select a file"); if (filename.isEmpty()) { - LOG_DEBUG("Found an empty filename"); + qWarning() << "Found an empty filename, don't open a file"; return; } QFileInfo fileInfo(filename); - LOG_DEBUG("Trying to open file " << filename); + qDebug() << "Trying to open file " << filename; VivyDocument *document = documentStore.loadDocument(filename); if (document == nullptr) { - LOG_DEBUG("Failed to load the document " << filename << "!"); + qCritical() << "Failed to load the document " << filename << "!"; return; } - LOG_DEBUG("Document " << filename << " was opened successfully, getting its view"); + qDebug() << "Document " << filename << " was opened successfully, getting its view"; VivyDocumentView *documentView = documentStore.getDocumentView(document->getName()); if (documentView != nullptr) { - LOG_DEBUG("View constructed successfully"); + qDebug() << "View constructed successfully"; setCentralWidget(documentView); } else { - LOG_DEBUG("Failed to create the document view for " << document->getName()); + qCritical() << "Failed to create the document view for " << document->getName(); } } diff --git a/src/Utils.cc b/src/Utils.cc index 6ffca3ea..eb974f1d 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -2,8 +2,6 @@ #include <QFileInfo> -QMessageLogger Vivy::Utils::logger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, "Vivy::Utils"); - bool Vivy::Utils::detectDocumentType(const QFileInfo &file, DocumentType *type) { diff --git a/src/Utils.h b/src/Utils.h index 39b5253f..e50543b3 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -14,11 +14,6 @@ static const QStringList videoFileSuffix = { "mkv", "mp4" }; static const QStringList assFileSuffix = { "ass" }; static const QStringList vivyFileSuffix = { "vivy" }; -extern QMessageLogger logger; -#define LOG_DEBUG(...) Vivy::Utils::logger.debug() << __VA_ARGS__ -#define LOG_ERROR(...) Vivy::Utils::logger.critical() << __VA_ARGS__ -#define LOG_WARNING(...) Vivy::Utils::logger.warning() << __VA_ARGS__ - enum DocumentType : unsigned long long { /* Basic types */ Vivy = (1 << 1), -- GitLab