fix: maybe to much time spent on this logger :/
This commit is contained in:
@@ -53,6 +53,12 @@ target_link_libraries(wallpaper_chooser PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
target_include_directories(wallpaper_chooser PRIVATE src)
|
||||
|
||||
if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
|
||||
target_compile_definitions(wallpaper_chooser PRIVATE
|
||||
GENERAL_LOGGER_DISABLED
|
||||
)
|
||||
endif()
|
||||
|
||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
# explicit, fixed bundle identifier manually though.
|
||||
|
||||
+3
-2
@@ -4,7 +4,8 @@
|
||||
"~/Pictures/116327446_p0.jpg"
|
||||
],
|
||||
"dirs": [
|
||||
"~/.config/backgrounds"
|
||||
"~/.config/backgrounds",
|
||||
"/run/media/kolkas/移硬1T/逆流茶会/"
|
||||
],
|
||||
"excludes": [
|
||||
"~/.config/backgrounds/nao-stars-crop-adjust-flop.jpg",
|
||||
@@ -26,4 +27,4 @@
|
||||
"type": "name",
|
||||
"reverse": false
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: Uyanide pywang0608@foxmail.com
|
||||
* @Date: 2025-08-05 01:34:52
|
||||
* @LastEditTime: 2025-08-07 00:09:51
|
||||
* @LastEditTime: 2025-08-07 21:27:26
|
||||
* @Description: Configuration manager.
|
||||
*/
|
||||
#include "config.h"
|
||||
@@ -66,37 +66,37 @@ void Config::_loadConfig(const QString &configPath) {
|
||||
{"actions.confirm", "confirm", [this](const QJsonValue &val) {
|
||||
if (val.isString()) {
|
||||
m_configItems.actionsConfirm = ::expandPath(val.toString());
|
||||
info(QString("Action confirm: %1").arg(m_configItems.actionsConfirm));
|
||||
info(QString("Action confirm: %1").arg(m_configItems.actionsConfirm), GeneralLogger::STEP);
|
||||
}
|
||||
}},
|
||||
{"style.aspect_ratio", "aspect_ratio", [this](const QJsonValue &val) {
|
||||
if (val.isDouble() && val.toDouble() > 0) {
|
||||
m_configItems.styleAspectRatio = val.toDouble();
|
||||
info(QString("Aspect ratio: %1").arg(m_configItems.styleAspectRatio));
|
||||
info(QString("Aspect ratio: %1").arg(m_configItems.styleAspectRatio), GeneralLogger::STEP);
|
||||
}
|
||||
}},
|
||||
{"style.image_width", "image_width", [this](const QJsonValue &val) {
|
||||
if (val.isDouble() && val.toDouble() > 0) {
|
||||
m_configItems.styleImageWidth = val.toInt();
|
||||
info(QString("Image width: %1").arg(m_configItems.styleImageWidth));
|
||||
info(QString("Image width: %1").arg(m_configItems.styleImageWidth), GeneralLogger::STEP);
|
||||
}
|
||||
}},
|
||||
{"style.image_focus_width", "image_focus_width", [this](const QJsonValue &val) {
|
||||
if (val.isDouble() && val.toDouble() > 0) {
|
||||
m_configItems.styleImageFocusWidth = val.toInt();
|
||||
info(QString("Image focus width: %1").arg(m_configItems.styleImageFocusWidth));
|
||||
info(QString("Image focus width: %1").arg(m_configItems.styleImageFocusWidth), GeneralLogger::STEP);
|
||||
}
|
||||
}},
|
||||
{"style.window_width", "window_width", [this](const QJsonValue &val) {
|
||||
if (val.isDouble() && val.toDouble() > 0) {
|
||||
m_configItems.styleWindowWidth = val.toInt();
|
||||
info(QString("Window width: %1").arg(m_configItems.styleWindowWidth));
|
||||
info(QString("Window width: %1").arg(m_configItems.styleWindowWidth), GeneralLogger::STEP);
|
||||
}
|
||||
}},
|
||||
{"style.window_height", "window_height", [this](const QJsonValue &val) {
|
||||
if (val.isDouble() && val.toDouble() > 0) {
|
||||
m_configItems.styleWindowHeight = val.toInt();
|
||||
info(QString("Window height: %1").arg(m_configItems.styleWindowHeight));
|
||||
info(QString("Window height: %1").arg(m_configItems.styleWindowHeight), GeneralLogger::STEP);
|
||||
}
|
||||
}},
|
||||
{"sort.type", "type", [this](const QJsonValue &val) {
|
||||
@@ -111,15 +111,15 @@ void Config::_loadConfig(const QString &configPath) {
|
||||
} else if (type == "size") {
|
||||
m_configItems.sortType = SortType::Size;
|
||||
} else {
|
||||
warn(QString("Unknown sort type: %1").arg(type));
|
||||
warn(QString("Unknown sort type: %1").arg(type), GeneralLogger::STEP);
|
||||
}
|
||||
}
|
||||
info(QString("Sort type: %1").arg(static_cast<int>(m_configItems.sortType)));
|
||||
info(QString("Sort type: %1").arg(static_cast<int>(m_configItems.sortType)), GeneralLogger::STEP);
|
||||
}},
|
||||
{"sort.reverse", "reverse", [this](const QJsonValue &val) {
|
||||
if (val.isBool()) {
|
||||
m_configItems.sortReverse = val.toBool();
|
||||
info(QString("Sort reverse: %1").arg(m_configItems.sortReverse));
|
||||
info(QString("Sort reverse: %1").arg(m_configItems.sortReverse), GeneralLogger::STEP);
|
||||
}
|
||||
}},
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: Uyanide pywang0608@foxmail.com
|
||||
* @Date: 2025-08-07 00:32:25
|
||||
* @LastEditTime: 2025-08-07 01:09:49
|
||||
* @Description: A loading indicator widget with a progress bar.
|
||||
* @LastEditTime: 2025-08-07 21:14:09
|
||||
* @Description: LoadingIndicator implementation.
|
||||
*/
|
||||
#include "loading_indicator.h"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: Uyanide pywang0608@foxmail.com
|
||||
* @Date: 2025-08-07 00:32:25
|
||||
* @LastEditTime: 2025-08-07 01:00:29
|
||||
* @Description: LoadingIndicator implementation.
|
||||
* @LastEditTime: 2025-08-07 21:13:59
|
||||
* @Description: A loading indicator widget with a progress bar.
|
||||
*/
|
||||
#ifndef LOADING_INDICATOR_H
|
||||
#define LOADING_INDICATOR_H
|
||||
|
||||
+20
-15
@@ -1,11 +1,13 @@
|
||||
/*
|
||||
* @Author: Uyanide pywang0608@foxmail.com
|
||||
* @Date: 2025-08-07 01:12:37
|
||||
* @LastEditTime: 2025-08-07 21:11:22
|
||||
* @LastEditTime: 2025-08-07 21:21:45
|
||||
* @Description: Implementation of logger.
|
||||
*/
|
||||
#include "logger.h"
|
||||
|
||||
#ifndef GENERAL_LOGGER_DISABLED
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -15,27 +17,25 @@
|
||||
#include <QTextStream>
|
||||
#include <QThreadPool>
|
||||
|
||||
#ifdef GENERAL_LOGGER_DISABLED
|
||||
#define ENSURE_ENABLED return;
|
||||
#else
|
||||
#define ENSURE_ENABLED
|
||||
#endif
|
||||
|
||||
Logger* Logger::instance(FILE* stream) {
|
||||
Logger* Logger::instance(FILE* stream,
|
||||
GeneralLogger::LogIndent indent,
|
||||
QObject* parent) {
|
||||
static Logger* logger{};
|
||||
if (!logger) {
|
||||
if (!stream) {
|
||||
stream = stderr; // Default to stderr if no stream provided
|
||||
}
|
||||
logger = new Logger(stream);
|
||||
logger = new Logger(stream, indent, parent);
|
||||
// Ensure logger runs in the main thread
|
||||
logger->moveToThread(QCoreApplication::instance()->thread());
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
Logger::Logger(FILE* stream, QObject* parent)
|
||||
: QObject(parent), m_stream(stream), m_logStream(stream) {
|
||||
Logger::Logger(FILE* stream,
|
||||
GeneralLogger::LogIndent indent,
|
||||
QObject* parent)
|
||||
: QObject(parent), m_stream(stream), m_logStream(stream), m_indent(indent) {
|
||||
connect(this,
|
||||
&Logger::logSig,
|
||||
this,
|
||||
@@ -49,8 +49,8 @@ void Logger::_log(
|
||||
const QString& levelColorString,
|
||||
const QString& textColorString,
|
||||
const GeneralLogger::LogIndent indent) {
|
||||
ENSURE_ENABLED
|
||||
|
||||
if (indent > m_indent) return;
|
||||
m_logStream << levelColorString << levelString << ' ';
|
||||
for (qint32 i = 0; i < indent; i++) m_logStream << " ";
|
||||
m_logStream << textColorString << msg << (textColorString.isEmpty() ? "\n" : "\033[0m\n");
|
||||
@@ -70,10 +70,12 @@ bool Logger::isColored() {
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // GENERAL_LOGGER_DISABLED
|
||||
|
||||
void GeneralLogger::info(
|
||||
const QString& msg,
|
||||
const GeneralLogger::LogIndent indent) {
|
||||
ENSURE_ENABLED
|
||||
#ifndef GENERAL_LOGGER_DISABLED
|
||||
constexpr const char* colorInfoMsg[]{"\033[32m", "\033[0m", "\033[0m"};
|
||||
const auto color = Logger::isColored();
|
||||
emit Logger::instance() -> logSig(msg,
|
||||
@@ -81,28 +83,31 @@ void GeneralLogger::info(
|
||||
color ? "\033[92m" : "",
|
||||
color ? colorInfoMsg[indent] : "",
|
||||
indent);
|
||||
#endif // GENERAL_LOGGER_DISABLED
|
||||
}
|
||||
|
||||
void GeneralLogger::warn(
|
||||
const QString& msg,
|
||||
const GeneralLogger::LogIndent indent) {
|
||||
ENSURE_ENABLED
|
||||
#ifndef GENERAL_LOGGER_DISABLED
|
||||
const auto color = Logger::isColored();
|
||||
emit Logger::instance() -> logSig(msg,
|
||||
"[WARN]",
|
||||
color ? "\033[93m" : "",
|
||||
color ? "\033[33m" : "",
|
||||
indent);
|
||||
#endif // GENERAL_LOGGER_DISABLED
|
||||
}
|
||||
|
||||
void GeneralLogger::error(
|
||||
const QString& msg,
|
||||
const GeneralLogger::LogIndent indent) {
|
||||
ENSURE_ENABLED
|
||||
#ifndef GENERAL_LOGGER_DISABLED
|
||||
const auto color = Logger::isColored();
|
||||
emit Logger::instance() -> logSig(msg,
|
||||
"[ERROR]",
|
||||
color ? "\033[91m" : "",
|
||||
color ? "\033[31m" : "",
|
||||
indent);
|
||||
#endif // GENERAL_LOGGER_DISABLED
|
||||
}
|
||||
+10
-3
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: Uyanide pywang0608@foxmail.com
|
||||
* @Date: 2025-08-05 10:43:31
|
||||
* @LastEditTime: 2025-08-07 01:55:42
|
||||
* @LastEditTime: 2025-08-07 21:26:09
|
||||
* @Description: A simple thread-safe logger for general use.
|
||||
*/
|
||||
#ifndef GENERAL_LOGGER_H
|
||||
@@ -29,16 +29,21 @@ void error(const QString& msg,
|
||||
const LogIndent indent = GENERAL);
|
||||
} // namespace GeneralLogger
|
||||
|
||||
#ifndef GENERAL_LOGGER_DISABLED
|
||||
class Logger : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static Logger* instance(FILE* stream = nullptr);
|
||||
static Logger* instance(FILE* stream = nullptr,
|
||||
GeneralLogger::LogIndent indent = GeneralLogger::DETAIL,
|
||||
QObject* parent = nullptr);
|
||||
|
||||
static bool isColored();
|
||||
|
||||
private:
|
||||
explicit Logger(FILE* stream, QObject* parent = nullptr);
|
||||
explicit Logger(FILE* stream,
|
||||
GeneralLogger::LogIndent indent,
|
||||
QObject* parent);
|
||||
|
||||
private slots:
|
||||
void _log(const QString& msg,
|
||||
@@ -50,6 +55,7 @@ class Logger : public QObject {
|
||||
private:
|
||||
FILE* m_stream;
|
||||
QTextStream m_logStream;
|
||||
GeneralLogger::LogIndent m_indent;
|
||||
|
||||
signals:
|
||||
void logSig(const QString& msg,
|
||||
@@ -59,4 +65,5 @@ class Logger : public QObject {
|
||||
const GeneralLogger::LogIndent indent);
|
||||
};
|
||||
|
||||
#endif // GENERAL_LOGGER_DISABLED
|
||||
#endif // GENERAL_LOGGER_H
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: Uyanide pywang0608@foxmail.com
|
||||
* @Date: 2025-08-05 00:37:58
|
||||
* @LastEditTime: 2025-08-07 01:49:07
|
||||
* @LastEditTime: 2025-08-07 21:25:43
|
||||
* @Description: Entry point.
|
||||
*/
|
||||
#include <qapplication.h>
|
||||
|
||||
Reference in New Issue
Block a user