diff --git a/src/Lib/AbstractDocument.hh b/src/Lib/AbstractDocument.hh index d7761f44e1d1d103600e9c77c245a315bd59f03b..c39fb5661a9cdcc3bd841950fe18c011f9214972 100644 --- a/src/Lib/AbstractDocument.hh +++ b/src/Lib/AbstractDocument.hh @@ -14,6 +14,8 @@ namespace Vivy class AbstractDocument : public QObject { Q_OBJECT VIVY_UNMOVABLE_OBJECT(AbstractDocument) + +protected: VIVY_APP_LOGGABLE_OBJECT(AbstractDocument, logger) void copyOrRenameWith(const QFileInfo &newFile, auto action, auto success) diff --git a/src/Lib/Document/CRTPSubDocument.hh b/src/Lib/Document/CRTPSubDocument.hh index c89f25c587539613cc5ad1f0c00305629f2eb984..7100a19ab30c7275d4cae86535dc0cd5c9f5c8c0 100644 --- a/src/Lib/Document/CRTPSubDocument.hh +++ b/src/Lib/Document/CRTPSubDocument.hh @@ -4,6 +4,8 @@ #error "This is a C++ header" #endif +#include "../../VivyApplication.hh" +#include "../Log.hh" #include "../Utils.hh" #include "../Audio.hh" #include "../Video.hh" @@ -15,10 +17,13 @@ namespace Vivy { // The Big CRTP class for all common things to all the subdocuments -template <class CRTPSubDocumentType, class Document, class Context> class CRTPSubDocument { +template <class CRTPSubDocumentType, class Document, class Context = void> class CRTPSubDocument { +protected: + VIVY_APP_LOGGABLE_OBJECT(CRTPSubDocument, logger) + friend std::unique_ptr<Document>; + public: using Type = CRTPSubDocumentType; - friend std::unique_ptr<Document>; protected: QString filePath; @@ -35,14 +40,15 @@ protected: public: static std::unique_ptr<Document> fromFile(const QString &path) noexcept { - qDebug() << "Init document from file " << path; - auto ret = std::unique_ptr<Document>(new Document()); + auto ret = std::unique_ptr<Document>(new Document()); + ret->logDebug() << "Init document from file " << VIVY_LOG_QUOTED(path); ret->filePath = path; try { ret->initFromPath(path); // May throw } catch (const std::runtime_error &e) { - qDebug().nospace() << "Failed to init document from file " << path << ": " << e.what(); + ret->logDebug() << "Failed to init document from file " << VIVY_LOG_QUOTED(path) << ": " + << e.what(); ret.reset(); } @@ -118,7 +124,7 @@ public: }; // ASS document -class AssSubDocument final : public CRTPSubDocument<AssDocumentType, AssSubDocument, void> { +class AssSubDocument final : public CRTPSubDocument<AssDocumentType, AssSubDocument> { static constexpr inline bool hasContext = false; const QStringList &suffixList = Vivy::Utils::assFileSuffix; diff --git a/src/Lib/Document/CRTPSubDocument/AudioSubDocument.cc b/src/Lib/Document/CRTPSubDocument/AudioSubDocument.cc index c91c3752109af9df968d21d46d32ca433557c1b9..d10fb949520f043cfd3d489f3127ddf23f4229fe 100644 --- a/src/Lib/Document/CRTPSubDocument/AudioSubDocument.cc +++ b/src/Lib/Document/CRTPSubDocument/AudioSubDocument.cc @@ -8,10 +8,10 @@ void AudioSubDocument::initFromPath(const QString &path) { if (contextPtr) - qDebug() << "Replacing the audio contetx by a new one for file" << path; + logDebug() << "Replacing the audio contetx by a new one for file " << VIVY_LOG_QUOTED(path); contextPtr.reset(new AudioContext(path)); // May throw - qDebug() << "Audio OK for" << path; + logDebug() << "Audio OK for " << VIVY_LOG_QUOTED(path); } QString diff --git a/src/Lib/Document/VivyDocument.cc b/src/Lib/Document/VivyDocument.cc index 6749fcc3cce6e5acb44bf584ccb9c345903835cc..6cff0405c0ea45aa91b05ce900c7660d150acbbc 100644 --- a/src/Lib/Document/VivyDocument.cc +++ b/src/Lib/Document/VivyDocument.cc @@ -154,18 +154,18 @@ VivyDocument::loadSubDocument(const QString &subName) noexcept if (detectDocumentType(file, &ableType)) { switch (ableType) { case Capabilities::AudioAble: - qDebug() << "Auto-detect audio document for" << subName; + logDebug() << "Auto-detect audio document for " << subName; setAudioSubDocument(file.absoluteFilePath()); return true; case Capabilities::VideoAble: - qDebug() << "Auto-detect video (and try audio) document for" << subName; + logDebug() << "Auto-detect video (and try audio) document for " << subName; setVideoSubDocument(file.absoluteFilePath()); setAudioSubDocument(file.absoluteFilePath()); return true; case Capabilities::AssAble: - qDebug() << "Auto-detect ASS document for" << subName; + logDebug() << "Auto-detect ASS document for " << subName; setAssSubDocument(file.absoluteFilePath()); return true; } @@ -180,24 +180,24 @@ VivyDocument::loadSubDocument(const QString &subName, VivyDocument::Capabilities QFileInfo file(subName); Capabilities ableType; if (!detectDocumentType(file, &ableType)) { - qCritical() << "Failed to detect type for file " << subName; + logError() << "Failed to detect type for file " << subName; return false; } if (ableType == Capabilities::AssAble && asType == Capabilities::AssAble) { - qDebug() << "Create an ass subDocument from " << subName; + logDebug() << "Create an ass subDocument from " << subName; setAssSubDocument(file.absoluteFilePath()); } else if (ableType == Capabilities::VideoAble && asType == Capabilities::VideoAble) { - qDebug() << "Create a video subDocument from " << subName; + logDebug() << "Create a video subDocument from " << subName; setVideoSubDocument(file.absoluteFilePath()); } else if (const bool requestAudio = (asType == Capabilities::AudioAble); (ableType == Capabilities::VideoAble && requestAudio) || (ableType == Capabilities::AudioAble && requestAudio)) { - qDebug() << "Create an audio subDocument from " << subName; + logDebug() << "Create an audio subDocument from " << subName; setAudioSubDocument(file.absoluteFilePath()); } @@ -237,7 +237,7 @@ VivyDocument::copy(const QString &newName) // Compute new paths, the document is really on disk initially else { - qDebug() << "Renaming a real file"; + logDebug() << "Renaming a real file to " << newName; copyWith(newPath, [=, this]() noexcept -> void { documentLocation = newPath.dir(); documentName = newPath.baseName(); @@ -259,7 +259,7 @@ VivyDocument::rename(const QString &newName) // Compute new paths, the document is really on disk initially else { - qDebug() << "Renaming a real file"; + logDebug() << "Renaming a real file to " << newName; renameWith(newPath, [=, this]() noexcept -> void { documentLocation = newPath.dir(); documentName = newPath.baseName(); @@ -285,8 +285,8 @@ VivyDocument::saveMemoryFile(const QFileInfo &newPath) documentLocation = newPath.absoluteDir(); name = newPath.absoluteFilePath(); documentOptions = static_cast<Options>(documentOptions & (~MemoryDocumentCreation)); - qDebug().nospace() << "Renaming a memory file => create it on disk with { " << documentLocation - << ", " << documentName << " }"; + logDebug() << "Renaming a memory file => create it on disk with { " + << documentLocation.absolutePath() << ", " << documentName << " }"; save(); } @@ -336,7 +336,7 @@ VivyDocument::getDocumentCapabilitiesString() const noexcept void VivyDocument::setAudioSubDocument(const QString filename) noexcept { - qDebug() << "[Audio sub-doc] Trying to open file" << filename; + logDebug() << "Audio sub-doc: Trying to open file " << filename; QFileInfo fileInfo(filename); const QString baseName = fileInfo.baseName(); @@ -353,7 +353,7 @@ VivyDocument::setAudioSubDocument(const QString filename) noexcept void VivyDocument::setVideoSubDocument(const QString filename) noexcept { - qDebug() << "[Video sub-doc] Trying to open file" << filename; + logDebug() << "Video sub-doc: Trying to open file " << filename; QFileInfo fileInfo(filename); const QString baseName = fileInfo.baseName(); @@ -370,7 +370,7 @@ VivyDocument::setVideoSubDocument(const QString filename) noexcept void VivyDocument::setAssSubDocument(const QString filename) noexcept { - qDebug() << "[ASS sub-doc] Trying to open file" << filename; + logDebug() << "ASS sub-doc: Trying to open file " << filename; QFileInfo fileInfo(filename); const QString baseName = fileInfo.baseName(); diff --git a/src/Lib/Document/VivyDocumentStore.cc b/src/Lib/Document/VivyDocumentStore.cc index 909d9e270367c90526b04c3c5c5f52d75d0fd93a..3d9618c86f192b0c79b8abce9a25f1fd34ddb042 100644 --- a/src/Lib/Document/VivyDocumentStore.cc +++ b/src/Lib/Document/VivyDocumentStore.cc @@ -15,10 +15,10 @@ VivyDocumentStore::newDocument(VivyDocument::Options opt) if (ret) { const Uuid uuid = ret->getUuid(); documents[uuid] = ret; - qDebug() << "Create new document " << newDocName << "with uuid" << uuid; + logDebug() << "Create new document " << newDocName << " with uuid" << uuid; return ret; } else { - qDebug() << "Failed to create new document " << newDocName; + logDebug() << "Failed to create new document " << newDocName; throw std::runtime_error("Failed to create the document"); } }