fix: maybe to much time spent on this logger :/

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