Merge pull request #7793 from spycrab/logging_async

Qt/LogWidget: Make logging asynchronous
This commit is contained in:
Mat M 2019-02-08 14:31:11 -05:00 committed by GitHub
commit e030a48741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 28 deletions

View File

@ -20,6 +20,7 @@
#include "Core/ConfigManager.h"
#include "DolphinQt/QtUtils/QueueOnObject.h"
#include "DolphinQt/Settings.h"
// Delay in ms between calls of UpdateLog()
@ -188,6 +189,10 @@ void LogWidget::SaveSettings()
void LogWidget::Log(LogTypes::LOG_LEVELS level, const char* text)
{
// The text has to be copied here as it will be deallocated after this method has returned
std::string str(text);
QueueOnObject(this, [this, level, str]() mutable {
std::lock_guard<std::mutex> lock(m_log_mutex);
const char* color = "white";
@ -211,12 +216,13 @@ void LogWidget::Log(LogTypes::LOG_LEVELS level, const char* text)
break;
}
std::string str(text);
StringPopBackIf(&str, '\n');
m_log_queue.push(QStringLiteral("%1 <span style=\"color: %2; white-space: pre\">%3</span>")
m_log_queue.push(
QStringLiteral("%1 <span style=\"color: %2; white-space: pre\">%3</span>")
.arg(QString::fromStdString(str.substr(0, TIMESTAMP_LENGTH)),
QString::fromStdString(color),
QString::fromStdString(str.substr(TIMESTAMP_LENGTH)).toHtmlEscaped()));
});
}
void LogWidget::closeEvent(QCloseEvent*)