From a0cb65ceeb68698518be89be2187a048dc0d6f82 Mon Sep 17 00:00:00 2001 From: namedkitten Date: Mon, 11 May 2020 11:46:40 +0100 Subject: [PATCH] Improve logging, fix #21 --- src/Backends/MPVCommon/MPVCommon.cpp | 12 ++++++++---- src/logger.cpp | 2 +- src/qml/Dialogs/PlaylistDialog.qml | 12 +++++++----- src/qml/MainMenu.qml | 14 +++++++++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Backends/MPVCommon/MPVCommon.cpp b/src/Backends/MPVCommon/MPVCommon.cpp index da9814e..f56c251 100644 --- a/src/Backends/MPVCommon/MPVCommon.cpp +++ b/src/Backends/MPVCommon/MPVCommon.cpp @@ -521,14 +521,18 @@ void handle_mpv_event(BackendInterface* b, mpv_event* event) case MPV_EVENT_LOG_MESSAGE: { struct mpv_event_log_message* msg = (struct mpv_event_log_message*)event->data; - QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text); + QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text).trimmed(); QString msgLevel = QString(msg->level); - if (msgLevel.startsWith("d") || msgLevel.startsWith("t")) { + if (msgLevel.startsWith("d")) { mpvLogger->info("{}", logMsg.toStdString()); - } else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) { + } else if (msgLevel.startsWith("t")) { + mpvLogger->warn("{}", logMsg.toStdString()); + } else if (msgLevel.startsWith("v")) { + mpvLogger->trace("{}", logMsg.toStdString()); + } else if (msgLevel.startsWith("i")) { mpvLogger->info("{}", logMsg.toStdString()); } else { - mpvLogger->debug("{}", logMsg.toStdString()); + mpvLogger->warn("What: {}", logMsg.toStdString()); } break; diff --git a/src/logger.cpp b/src/logger.cpp index 73a8483..daef6b1 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -36,7 +36,7 @@ initLogger(std::string name) auto console = std::make_shared(name, begin(sinks), end(sinks)); console->set_pattern("[%l][%n] %v%$"); spdlog::register_logger(console); - console->set_level(spdlog::level::debug); + console->set_level(spdlog::level::info); return spdlog::get(name); diff --git a/src/qml/Dialogs/PlaylistDialog.qml b/src/qml/Dialogs/PlaylistDialog.qml index 5922462..10ef923 100644 --- a/src/qml/Dialogs/PlaylistDialog.qml +++ b/src/qml/Dialogs/PlaylistDialog.qml @@ -33,7 +33,7 @@ Dialog { } Timer { - interval: 100 + interval: 500 repeat: true triggeredOnStart: true running: true @@ -49,7 +49,7 @@ Dialog { var thumbnailerProcess = component.createObject(playlistDialog, { "name": thumbnailJobs[0] }) - if (String(titleJobs[0]).indexOf("://") !== -1) { + if (String(thumbnailJobs[0]).indexOf("://") !== -1) { thumbnailerProcess.start("youtube-dl", ["--get-thumbnail", thumbnailJobs[0]]) @@ -74,8 +74,7 @@ Dialog { onTriggered: { if (titleJobsRunning < 5) { if (titleJobs.length > 0) { - if (titleJobs[0].startsWith( - "https://www.youtube.com/playlist?list=")) { + if (titleJobs[0].startsWith("https://www.youtube.com/playlist?list=")) { titleJobs.shift() return } @@ -132,6 +131,7 @@ Dialog { Connections { target: thumbnailCache onThumbnailReady: function (name, url, path) { + console.error(name,url,path,playlistItem.itemURL) if (name == playlistItem.itemURL) { thumbnail.source = path } @@ -183,7 +183,6 @@ Dialog { } Component.onCompleted: { - if (typeof playlistItemTitle !== "undefined") { playlistItem.itemTitle = playlistItemTitle } else { @@ -215,4 +214,7 @@ Dialog { } focus: true } + Component.onCompleted: { + playlistDialog.open() + } } diff --git a/src/qml/MainMenu.qml b/src/qml/MainMenu.qml index 973657e..73cc2f8 100644 --- a/src/qml/MainMenu.qml +++ b/src/qml/MainMenu.qml @@ -101,8 +101,16 @@ MenuBar { } } - PlaylistDialog { - id: playlistDialog + Loader { + id: playlistDialogLoader + active: false + source: "PlaylistDialog.qml" + } + Connections { + target: playlistDialogLoader.item + onDone: { + playlistDialogLoader.active = false + } } Loader { @@ -467,7 +475,7 @@ MenuBar { Action { text: translate.getTranslation("PLAYLIST_MENU", i18n.language) onTriggered: { - playlistDialog.open() + playlistDialogLoader.active = true } } Action {