From 3c6a8ccdc1b948c927d1fc65187269e33f46c8ca Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Thu, 9 Sep 2021 16:06:38 +0200
Subject: [PATCH] LOG: Use the new LOG API in more place and remove old qDebug

---
 .../CRTPSubDocument/VideoSubDocument.cc       |  4 --
 src/UI/AboutWindow.cc                         |  2 +-
 src/UI/DocumentViews/AudioVisualizer.cc       |  1 -
 src/UI/DocumentViews/MpvContainer.cc          | 40 +++++++++----------
 src/UI/DocumentViews/MpvContainer.hh          |  3 ++
 src/UI/DocumentViews/MpvControls.cc           |  1 -
 src/UI/MainWindow.cc                          |  4 +-
 src/UI/Theme/Theme.cc                         |  8 ++--
 8 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/src/Lib/Document/CRTPSubDocument/VideoSubDocument.cc b/src/Lib/Document/CRTPSubDocument/VideoSubDocument.cc
index 6f837e9c..516bb8c1 100644
--- a/src/Lib/Document/CRTPSubDocument/VideoSubDocument.cc
+++ b/src/Lib/Document/CRTPSubDocument/VideoSubDocument.cc
@@ -7,11 +7,7 @@ using namespace Vivy;
 void
 VideoSubDocument::initFromPath(const QString &path)
 {
-    if (contextPtr)
-        qDebug() << "Replacing the video contetx by a new one for file" << path;
     contextPtr.reset(new VideoContext(path)); // May throw
-
-    qDebug() << "Video OK for" << path;
 }
 
 QString
diff --git a/src/UI/AboutWindow.cc b/src/UI/AboutWindow.cc
index 5995a016..2faabee9 100644
--- a/src/UI/AboutWindow.cc
+++ b/src/UI/AboutWindow.cc
@@ -75,7 +75,7 @@ AboutWindow::LicenceLabel::LicenceLabel(QWidget *parent, const QString &url,
     case Qt::PlainText:
     case Qt::RichText: setText(QString::fromUtf8(content.readAll())); break;
     case Qt::MarkdownText: setMarkdown(QString::fromUtf8(content.readAll())); break;
-    case Qt::AutoText: qCritical() << "Invalid text format for LicenceLabel" << format;
+    case Qt::AutoText: logError() << "Invalid text format for LicenceLabel" << format;
     }
 }
 
diff --git a/src/UI/DocumentViews/AudioVisualizer.cc b/src/UI/DocumentViews/AudioVisualizer.cc
index a0215bda..bab53a25 100644
--- a/src/UI/DocumentViews/AudioVisualizer.cc
+++ b/src/UI/DocumentViews/AudioVisualizer.cc
@@ -9,7 +9,6 @@ AudioVisualizer::AudioVisualizer(AudioContext::StreamPtr stream, QWidget *parent
     : QWidget(parent)
 {
     if (!stream->isDecoded()) {
-        qDebug() << "Need to decode data for stream" << stream->getStreamIndex();
         stream->decodeData();
     }
 
diff --git a/src/UI/DocumentViews/MpvContainer.cc b/src/UI/DocumentViews/MpvContainer.cc
index 425346ed..b689349e 100644
--- a/src/UI/DocumentViews/MpvContainer.cc
+++ b/src/UI/DocumentViews/MpvContainer.cc
@@ -47,7 +47,7 @@ void
 MpvContainer::registerMpvTimeCallback(std::function<void(double)> callback) noexcept
 {
     if (mpvTimeCallback)
-        qWarning() << "Override a previous mpv callback!";
+        logWarning() << "Override a previous mpv callback!";
     mpvTimeCallback = callback;
 }
 
@@ -55,7 +55,7 @@ void
 MpvContainer::registerMpvDurationCallback(std::function<void(double)> callback) noexcept
 {
     if (mpvDurationCallback)
-        qWarning() << "Override a previous mpv callback!";
+        logWarning() << "Override a previous mpv callback!";
     mpvDurationCallback = callback;
 }
 
@@ -63,7 +63,7 @@ void
 MpvContainer::closeMpv() noexcept
 {
     if (mpv) {
-        qDebug() << "Closing the MPV context";
+        logDebug() << "Closing the MPV context";
         asyncCommand(AsyncCmdType::None, { "quit", nullptr });
         registerMpvTimeCallback(nullptr);
         registerMpvDurationCallback(nullptr);
@@ -98,8 +98,7 @@ MpvContainer::handleMpvEvent(const mpv_event *const event) noexcept
         msg     = reinterpret_cast<mpv_event_log_message *>(event->data);
         msgText = QString::fromUtf8(msg->text);
         msgText.replace('\n', "");
-        qDebug().nospace().noquote()
-            << "MPV - MSG [" << msg->prefix << "] " << msg->level << ": " << msgText;
+        logDebug() << "MPV - MSG [" << msg->prefix << "] " << msg->level << ": " << msgText;
         break;
 
     case MPV_EVENT_PROPERTY_CHANGE:
@@ -117,7 +116,7 @@ MpvContainer::handleMpvEvent(const mpv_event *const event) noexcept
         else if (checkProp(prop, "pause", MPV_FORMAT_FLAG)) {
             isPlaybackPaused = *reinterpret_cast<bool *>(prop->data);
             emit mpvPlaybackToggled(!isPlaybackPaused);
-            qDebug() << "MPV -> set to" << (isPlaybackPaused ? "pause" : "play");
+            logDebug() << "MPV -> set to" << (isPlaybackPaused ? "pause" : "play");
         }
 
         break;
@@ -125,20 +124,20 @@ MpvContainer::handleMpvEvent(const mpv_event *const event) noexcept
     case MPV_EVENT_PAUSE:
         isPlaybackPaused = true;
         emit mpvPlaybackToggled(!isPlaybackPaused);
-        qDebug() << "MPV -> set to pause";
+        logDebug() << "MPV -> set to pause";
         break;
 
     case MPV_EVENT_UNPAUSE:
         isPlaybackPaused = false;
         emit mpvPlaybackToggled(!isPlaybackPaused);
-        qDebug() << "MPV -> set to play";
+        logDebug() << "MPV -> set to play";
         break;
 
-    case MPV_EVENT_START_FILE: qDebug() << "MPV: Begin of file"; break;
-    case MPV_EVENT_END_FILE: qDebug() << "MPV: Reached end of file!"; break;
+    case MPV_EVENT_START_FILE: logDebug() << "MPV: Begin of file"; break;
+    case MPV_EVENT_END_FILE: logDebug() << "MPV: Reached end of file!"; break;
 
     case MPV_EVENT_COMMAND_REPLY:
-        qDebug() << "Got return of" << event->reply_userdata;
+        logDebug() << "Got return of" << event->reply_userdata;
         handleMpvEventCommandReply(static_cast<AsyncCmdType>(event->reply_userdata));
         break;
 
@@ -182,27 +181,26 @@ MpvContainer::handleMpvEventCommandReply(const AsyncCmdType type) noexcept
     case AsyncCmdType::LoadAssFile:
     case AsyncCmdType::ReloadAss:
         sid = getAssSid();
-        qDebug() << "Load ASS file with id:" << sid;
+        logDebug() << "Load ASS file with id:" << sid;
         break;
 
     case AsyncCmdType::UnloadAss:
         sid = getAssSid();
-        qDebug().nospace() << "Unload Ass, rc = " << sid;
+        logDebug() << "Unload Ass, rc = " << sid;
         if (sid != -1)
             unloadAssFile();
         break;
 
     case AsyncCmdType::LoadFile:
         sid = getAssSid();
-        qDebug() << "MPV - CMD: File loaded by mpv, sid =" << sid;
+        logDebug() << "MPV - CMD: File loaded by mpv, sid =" << sid;
         isPlaybackPaused = false;
         mpvPause();
         unloadAssFile();
         break;
 
-    case AsyncCmdType::SeekTime: qDebug() << "MPV - CMD: Seeked playback"; break;
-
-    case AsyncCmdType::TogglePlayback: qDebug() << "MPV - CMD: Playback was toggled"; break;
+    case AsyncCmdType::SeekTime: logDebug() << "MPV - CMD: Seeked playback"; break;
+    case AsyncCmdType::TogglePlayback: logDebug() << "MPV - CMD: Playback was toggled"; break;
     }
 }
 
@@ -217,14 +215,14 @@ MpvContainer::onMpvEvent() noexcept
     }
 
     if (mpv == nullptr) {
-        qDebug() << "MPV was closed while in the event loop!";
+        logDebug() << "MPV was closed while in the event loop!";
     }
 }
 
 void
 MpvContainer::loadFile(const QString &filename) noexcept
 {
-    qDebug() << "Loading file" << filename;
+    logDebug() << "Loading file" << filename;
     if (filename.size() == 0)
         return;
 
@@ -254,7 +252,7 @@ MpvContainer::printMpvError(int rc) const noexcept
     if (rc == MPV_ERROR_SUCCESS)
         return;
 
-    qCritical() << "MPV error:" << mpv_error_string(rc);
+    logError() << "MPV error:" << mpv_error_string(rc);
 }
 
 void
@@ -274,7 +272,7 @@ MpvContainer::mpvPause() noexcept
 void
 MpvContainer::mpvTogglePlayback() noexcept
 {
-    qDebug() << "MPV: Toggling the playback";
+    logDebug() << "MPV: Toggling the playback";
     asyncCommand(AsyncCmdType::TogglePlayback, { "cycle", "pause", "up", nullptr });
 }
 
diff --git a/src/UI/DocumentViews/MpvContainer.hh b/src/UI/DocumentViews/MpvContainer.hh
index 760d5e4a..70804554 100644
--- a/src/UI/DocumentViews/MpvContainer.hh
+++ b/src/UI/DocumentViews/MpvContainer.hh
@@ -4,7 +4,9 @@
 #error "This is a C++ header"
 #endif
 
+#include "../../VivyApplication.hh"
 #include "../../Lib/Utils.hh"
+#include "../../Lib/Log.hh"
 
 extern "C" {
 struct mpv_handle;
@@ -16,6 +18,7 @@ namespace Vivy
 class MpvContainer final : public QWidget {
     Q_OBJECT
     VIVY_UNMOVABLE_OBJECT(MpvContainer)
+    VIVY_APP_LOGGABLE_OBJECT(MpvContainer, logger)
 
     enum AsyncCmdType : uint64_t {
         None,
diff --git a/src/UI/DocumentViews/MpvControls.cc b/src/UI/DocumentViews/MpvControls.cc
index 931239ac..453c87c5 100644
--- a/src/UI/DocumentViews/MpvControls.cc
+++ b/src/UI/DocumentViews/MpvControls.cc
@@ -49,7 +49,6 @@ MpvControls::MpvControls(MpvContainer *passedContainer, QWidget *parent) noexcep
             });
 
     connect(progressBar, &QAbstractSlider::sliderReleased, this, [this]() noexcept -> void {
-        qDebug() << "Slider set to" << askedSliderPosition << "max was" << timeDuration.count();
         timePosition = chrono::seconds(askedSliderPosition);
         mpv->seekInFile(timePosition);
     });
diff --git a/src/UI/MainWindow.cc b/src/UI/MainWindow.cc
index 83b281bd..47e764e1 100644
--- a/src/UI/MainWindow.cc
+++ b/src/UI/MainWindow.cc
@@ -413,9 +413,9 @@ MainWindow::addTab(AbstractDocumentView *const tab)
             [this, tab]() noexcept -> void {
                 int tabIndex = getIndexOfTab(tab);
                 if (tabIndex < 0) {
-                    qDebug() << "Tab was not found!";
+                    logDebug() << "Tab was not found!";
                 } else {
-                    qDebug() << "Tab was found at index" << tabIndex;
+                    logDebug() << "Tab was found at index" << tabIndex;
                     documents->setTabToolTip(tabIndex, tab->getDocumentTabToolTip());
                     documents->setTabText(tabIndex, tab->getDocumentTabName());
                 }
diff --git a/src/UI/Theme/Theme.cc b/src/UI/Theme/Theme.cc
index 6b2abeeb..7f60106d 100644
--- a/src/UI/Theme/Theme.cc
+++ b/src/UI/Theme/Theme.cc
@@ -164,7 +164,8 @@ Theme::readNamedColor(const QString &color) const
 
     const QColor col('#' + color);
     if (!col.isValid()) {
-        qWarning("Color \"%s\" is neither a named color nor a valid color", qPrintable(color));
+        logWarning() << "Color " << VIVY_LOG_QUOTED(qPrintable(color))
+                     << " is neither a named color nor a valid color";
         return qMakePair(Qt::black, QString());
     }
     return qMakePair(col, QString());
@@ -251,8 +252,9 @@ Theme::readSettings(QSettings *const settings) noexcept
             const QString key = QLatin1String(e.key(i));
             if (!settings->contains(key)) {
                 if (i < PaletteWindow || i > PalettePlaceholderTextDisabled)
-                    qWarning("Theme \"%s\" misses color setting for key \"%s\".",
-                             qPrintable(d->fileName), qPrintable(key));
+                    logWarning()
+                        << "Theme " << VIVY_LOG_QUOTED(qPrintable(d->fileName))
+                        << " misses color setting for key " << VIVY_LOG_QUOTED(qPrintable(key));
                 continue;
             }
             d->colors[i] = readNamedColor(settings->value(key).toString());
-- 
GitLab