summaryrefslogtreecommitdiff
path: root/src/loglist.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2022-05-17 11:47:01 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2023-07-09 17:20:40 +0200
commitd13f6bb870cdda71257f665367be8ef9fca86255 (patch)
tree52e214718478f1e52856572f5aa1a2ac58537f9f /src/loglist.cpp
parent86bb01ba9eac879d3685c439ac9da0028bc4bc80 (diff)
Apply clang-format.
Diffstat (limited to 'src/loglist.cpp')
-rw-r--r--src/loglist.cpp155
1 files changed, 82 insertions, 73 deletions
diff --git a/src/loglist.cpp b/src/loglist.cpp
index 587cf223..345e0c6b 100644
--- a/src/loglist.cpp
+++ b/src/loglist.cpp
@@ -18,23 +18,20 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "loglist.h"
-#include "organizercore.h"
#include "copyeventfilter.h"
#include "env.h"
+#include "organizercore.h"
using namespace MOBase;
static LogModel* g_instance = nullptr;
-const std::size_t MaxLines = 1000;
+const std::size_t MaxLines = 1000;
static std::unique_ptr<env::Console> m_console;
static bool m_stdout = false;
static std::mutex m_stdoutMutex;
-
-LogModel::LogModel()
-{
-}
+LogModel::LogModel() {}
void LogModel::create()
{
@@ -49,7 +46,11 @@ LogModel& LogModel::instance()
void LogModel::add(MOBase::log::Entry e)
{
QMetaObject::invokeMethod(
- this, [this, e]{ onEntryAdded(std::move(e)); }, Qt::QueuedConnection);
+ this,
+ [this, e] {
+ onEntryAdded(std::move(e));
+ },
+ Qt::QueuedConnection);
}
QString LogModel::formattedMessage(const QModelIndex& index) const
@@ -91,9 +92,7 @@ void LogModel::onEntryAdded(MOBase::log::Entry e)
if (!full) {
endInsertRows();
} else {
- emit dataChanged(
- createIndex(row, 0),
- createIndex(row + 1, columnCount({})));
+ emit dataChanged(createIndex(row, 0), createIndex(row + 1, columnCount({})));
}
}
@@ -134,10 +133,10 @@ QVariant LogModel::data(const QModelIndex& index, int role) const
if (role == Qt::DisplayRole) {
if (index.column() == 0) {
const auto ms = duration_cast<milliseconds>(e.time.time_since_epoch());
- const auto s = duration_cast<seconds>(ms);
+ const auto s = duration_cast<seconds>(ms);
const std::time_t tt = s.count();
- const int frac = static_cast<int>(ms.count() % 1000);
+ const int frac = static_cast<int>(ms.count() % 1000);
const auto time = QDateTime::fromSecsSinceEpoch(tt).time().addMSecs(frac);
return time.toString("hh:mm:ss.zzz");
@@ -149,18 +148,18 @@ QVariant LogModel::data(const QModelIndex& index, int role) const
if (role == Qt::DecorationRole) {
if (index.column() == 1) {
switch (e.level) {
- case log::Warning:
- return QIcon(":/MO/gui/warning");
+ case log::Warning:
+ return QIcon(":/MO/gui/warning");
- case log::Error:
- return QIcon(":/MO/gui/problem");
+ case log::Error:
+ return QIcon(":/MO/gui/problem");
- case log::Debug:
- return QIcon(":/MO/gui/debug");
- case log::Info:
- return QIcon(":/MO/gui/information");
- default:
- return {};
+ case log::Debug:
+ return QIcon(":/MO/gui/debug");
+ case log::Info:
+ return QIcon(":/MO/gui/information");
+ default:
+ return {};
}
}
}
@@ -173,11 +172,10 @@ QVariant LogModel::headerData(int, Qt::Orientation, int) const
return {};
}
-
LogList::LogList(QWidget* parent)
- : QTreeView(parent),
- m_core(nullptr),
- m_copyFilter(this, [=](auto&& index) { return LogModel::instance().formattedMessage(index); })
+ : QTreeView(parent), m_core(nullptr), m_copyFilter(this, [=](auto&& index) {
+ return LogModel::instance().formattedMessage(index);
+ })
{
setModel(&LogModel::instance());
@@ -188,15 +186,21 @@ LogList::LogList(QWidget* parent)
setAutoScroll(true);
scrollToBottom();
- connect(
- this, &QWidget::customContextMenuRequested,
- [&](auto&& pos){ onContextMenu(pos); });
+ connect(this, &QWidget::customContextMenuRequested, [&](auto&& pos) {
+ onContextMenu(pos);
+ });
- connect(model(), &LogModel::rowsInserted, this, [&]{ onNewEntry(); });
- connect(model(), &LogModel::dataChanged, this, [&]{ onNewEntry(); });
+ connect(model(), &LogModel::rowsInserted, this, [&] {
+ onNewEntry();
+ });
+ connect(model(), &LogModel::dataChanged, this, [&] {
+ onNewEntry();
+ });
m_timer.setSingleShot(true);
- connect(&m_timer, &QTimer::timeout, [&]{ scrollToBottom(); });
+ connect(&m_timer, &QTimer::timeout, [&] {
+ scrollToBottom();
+ });
installEventFilter(&m_copyFilter);
}
@@ -234,7 +238,8 @@ void LogList::clear()
void LogList::openLogsFolder()
{
- QString logsPath = qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::logPath());
+ QString logsPath = qApp->property("dataPath").toString() + "/" +
+ QString::fromStdWString(AppConfig::logPath());
shell::Explore(logsPath);
}
@@ -242,11 +247,19 @@ QMenu* LogList::createMenu(QWidget* parent)
{
auto* menu = new QMenu(parent);
- menu->addAction(tr("Copy"), [&]{ m_copyFilter.copySelection(); });
- menu->addAction(tr("&Copy all"), [&]{ copyToClipboard(); });
+ menu->addAction(tr("Copy"), [&] {
+ m_copyFilter.copySelection();
+ });
+ menu->addAction(tr("&Copy all"), [&] {
+ copyToClipboard();
+ });
menu->addSeparator();
- menu->addAction(tr("C&lear all"), [&]{ clear(); });
- menu->addAction(tr("&Open logs folder"), [&]{ openLogsFolder(); });
+ menu->addAction(tr("C&lear all"), [&] {
+ clear();
+ });
+ menu->addAction(tr("&Open logs folder"), [&] {
+ openLogsFolder();
+ });
auto* levels = new QMenu(tr("&Level"));
menu->addMenu(levels);
@@ -259,7 +272,7 @@ QMenu* LogList::createMenu(QWidget* parent)
a->setCheckable(true);
a->setChecked(log::getDefault().level() == level);
- connect(a, &QAction::triggered, [this, level]{
+ connect(a, &QAction::triggered, [this, level] {
if (m_core) {
m_core->setLogLevel(level);
}
@@ -282,29 +295,27 @@ void LogList::onContextMenu(const QPoint& pos)
menu->popup(viewport()->mapToGlobal(pos));
}
-
log::Levels convertQtLevel(QtMsgType t)
{
- switch (t)
- {
- case QtDebugMsg:
- return log::Debug;
+ switch (t) {
+ case QtDebugMsg:
+ return log::Debug;
- case QtWarningMsg:
- return log::Warning;
+ case QtWarningMsg:
+ return log::Warning;
- case QtCriticalMsg: // fall-through
- case QtFatalMsg:
- return log::Error;
+ case QtCriticalMsg: // fall-through
+ case QtFatalMsg:
+ return log::Error;
- case QtInfoMsg: // fall-through
- default:
- return log::Info;
+ case QtInfoMsg: // fall-through
+ default:
+ return log::Info;
}
}
-void qtLogCallback(
- QtMsgType type, const QMessageLogContext& context, const QString& message)
+void qtLogCallback(QtMsgType type, const QMessageLogContext& context,
+ const QString& message)
{
std::string_view file = "";
@@ -320,13 +331,10 @@ void qtLogCallback(
}
if (file.empty()) {
- log::log(
- convertQtLevel(type), "{}",
- message.toStdString());
+ log::log(convertQtLevel(type), "{}", message.toStdString());
} else {
- log::log(
- convertQtLevel(type), "[{}:{}] {}",
- file, context.line, message.toStdString());
+ log::log(convertQtLevel(type), "[{}:{}] {}", file, context.line,
+ message.toStdString());
}
}
@@ -351,29 +359,32 @@ void initLogging()
log::LoggerConfiguration conf;
conf.maxLevel = MOBase::log::Debug;
- conf.pattern = "%^[%Y-%m-%d %H:%M:%S.%e %L] %v%$";
- conf.utc = true;
+ conf.pattern = "%^[%Y-%m-%d %H:%M:%S.%e %L] %v%$";
+ conf.utc = true;
log::createDefault(conf);
- log::getDefault().setCallback(
- [](log::Entry e){ LogModel::instance().add(e); });
+ log::getDefault().setCallback([](log::Entry e) {
+ LogModel::instance().add(e);
+ });
- log::getDefault().addToBlacklist(std::string("\\") + getenv("USERNAME"), "\\USERNAME");
+ log::getDefault().addToBlacklist(std::string("\\") + getenv("USERNAME"),
+ "\\USERNAME");
log::getDefault().addToBlacklist(std::string("/") + getenv("USERNAME"), "/USERNAME");
qInstallMessageHandler(qtLogCallback);
}
-bool createAndMakeWritable(const std::wstring &subPath) {
+bool createAndMakeWritable(const std::wstring& subPath)
+{
QString const dataPath = qApp->property("dataPath").toString();
- QString fullPath = dataPath + "/" + QString::fromStdWString(subPath);
+ QString fullPath = dataPath + "/" + QString::fromStdWString(subPath);
if (!QDir(fullPath).exists() && !QDir().mkdir(fullPath)) {
QMessageBox::critical(nullptr, QObject::tr("Error"),
- QObject::tr("Failed to create \"%1\". Your user "
- "account probably lacks permission.")
- .arg(fullPath));
+ QObject::tr("Failed to create \"%1\". Your user "
+ "account probably lacks permission.")
+ .arg(fullPath));
return false;
} else {
return true;
@@ -382,10 +393,8 @@ bool createAndMakeWritable(const std::wstring &subPath) {
bool setLogDirectory(const QString& dir)
{
- const auto logFile =
- dir + "/" +
- QString::fromStdWString(AppConfig::logPath()) + "/" +
- QString::fromStdWString(AppConfig::logFileName());
+ const auto logFile = dir + "/" + QString::fromStdWString(AppConfig::logPath()) + "/" +
+ QString::fromStdWString(AppConfig::logFileName());
if (!createAndMakeWritable(AppConfig::logPath())) {
return false;