diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c1fe997d..c7eb4128 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -278,7 +278,7 @@ jobs: run: | mkdir -p build/release cd build/release - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DDEBUG_OUTPUT=OFF -DGITTYUP_CI_TESTS=ON ${{ env.CMAKE_FLAGS }} ${{ matrix.env.cmake_flags }} ../.. + cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DGITTYUP_CI_TESTS=ON ${{ env.CMAKE_FLAGS }} ${{ matrix.env.cmake_flags }} ../.. - name: Build Information run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ab13ade..5b9765be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,23 +94,20 @@ if(UNIX) set(QT_MODULES ${QT_MODULES} DBus) endif() -if(CMAKE_BUILD_TYPE MATCHES Debug) - option(DEBUG_OUTPUT "Print debug output" ON) - option(DEBUG_OUTPUT_GENERAL "Enable general debug messages" ON) - option(DEBUG_OUTPUT_REFRESH "Enable debug messages to debug the refresh flow" - ON) - if(NOT DEBUG_OUTPUT) - add_compile_definitions(QT_NO_DEBUG_OUTPUT) - else() - if(DEBUG_OUTPUT_GENERAL) - add_compile_definitions(DEBUG_OUTPUT_GENERAL) - endif() - if(DEBUG_OUTPUT_REFRESH) - add_compile_definitions(DEBUG_OUTPUT_REFRESH) - endif() - endif() -else() +option(DEBUG_OUTPUT + "Print debug output (Only available if debug menu is enabled!)" ON) +option(DEBUG_OUTPUT_GENERAL "Enable general debug messages" ON) +option(DEBUG_OUTPUT_REFRESH "Enable debug messages to debug the refresh flow" + OFF) +if(NOT DEBUG_OUTPUT) add_compile_definitions(QT_NO_DEBUG_OUTPUT) +else() + if(DEBUG_OUTPUT_GENERAL) + add_compile_definitions(DEBUG_OUTPUT_GENERAL) + endif() + if(DEBUG_OUTPUT_REFRESH) + add_compile_definitions(DEBUG_OUTPUT_REFRESH) + endif() endif() find_package( diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 229787c6..fa117894 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -16,6 +16,7 @@ #include "ui/RepoView.h" #include "ui/TabWidget.h" #include "update/Updater.h" +#include "util/Debug.h" #include #include #include @@ -102,19 +103,6 @@ Application::Application(int &argc, char **argv, bool haltOnParseError) // Register types that are queued at runtime. qRegisterMetaType(); - qDebug() << QString("Root dir: %1").arg(Settings::rootDir().absolutePath()); - qDebug() << QString("App dir: %1").arg(Settings::appDir().absolutePath()); - qDebug() << QString("Doc dir: %1").arg(Settings::docDir().absolutePath()); - qDebug() << QString("Conf dir: %1").arg(Settings::confDir().absolutePath()); - qDebug() << QString("l10n dir: %1").arg(Settings::l10nDir().absolutePath()); - qDebug() << QString("dictionaries dir: %1") - .arg(Settings::dictionariesDir().absolutePath()); - qDebug() << QString("lexer dir: %1").arg(Settings::lexerDir().absolutePath()); - qDebug() - << QString("themes dir: %1").arg(Settings::themesDir().absolutePath()); - qDebug() << QString("pluginsDir dir: %1") - .arg(Settings::pluginsDir().absolutePath()); - // Connect updater signals. connect(Updater::instance(), &Updater::sslErrors, this, &Application::handleSslErrors); @@ -145,6 +133,18 @@ Application::Application(int &argc, char **argv, bool haltOnParseError) // Set debug menu option. MenuBar::setDebugMenuVisible(parser.isSet("debug-menu")); + Debug(QString("Root dir: %1").arg(Settings::rootDir().absolutePath())); + Debug(QString("App dir: %1").arg(Settings::appDir().absolutePath())); + Debug(QString("Doc dir: %1").arg(Settings::docDir().absolutePath())); + Debug(QString("Conf dir: %1").arg(Settings::confDir().absolutePath())); + Debug(QString("l10n dir: %1").arg(Settings::l10nDir().absolutePath())); + Debug(QString("dictionaries dir: %1") + .arg(Settings::dictionariesDir().absolutePath())); + Debug(QString("lexer dir: %1").arg(Settings::lexerDir().absolutePath())); + Debug(QString("themes dir: %1").arg(Settings::themesDir().absolutePath())); + Debug( + QString("pluginsDir dir: %1").arg(Settings::pluginsDir().absolutePath())); + // Set pathspec filter. mPathspec = parser.value("filter"); diff --git a/src/tools/MergeTool.cpp b/src/tools/MergeTool.cpp index 1afe840c..677f679b 100644 --- a/src/tools/MergeTool.cpp +++ b/src/tools/MergeTool.cpp @@ -83,9 +83,9 @@ bool MergeTool::start() { git::Repository repo = mLocalBlob.repo(); auto signal = QOverload::of(&QProcess::finished); QObject::connect(process, signal, [this, repo, backupPath, process] { - qDebug() << "Merge Process Exited!"; - qDebug() << "Stdout: " << process->readAllStandardOutput(); - qDebug() << "Stderr: " << process->readAllStandardError(); + Debug("Merge Process Exited!"); + Debug("Stdout: " << process->readAllStandardOutput()); + Debug("Stderr: " << process->readAllStandardError()); QFileInfo merged(mFile); QFileInfo backup(backupPath); diff --git a/src/ui/MenuBar.cpp b/src/ui/MenuBar.cpp index f29e3a2a..4f14cec1 100644 --- a/src/ui/MenuBar.cpp +++ b/src/ui/MenuBar.cpp @@ -39,6 +39,7 @@ #include "log/LogEntry.h" #include "log/LogView.h" #include "update/Updater.h" +#include "util/Debug.h" #include #include #include @@ -872,6 +873,12 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) { connect(remote, &QAction::triggered, [](bool checked) { git::Remote::setLoggingEnabled(checked); }); + QAction *debugMessages = debug->addAction(tr("Log Debug Messages")); + debugMessages->setCheckable(true); + debugMessages->setChecked(Debug::isLogging()); + connect(debugMessages, &QAction::triggered, + [](bool checked) { Debug::setLogging(checked); }); + debug->addSeparator(); QAction *diffs = debug->addAction(tr("Load All Diffs")); @@ -1138,6 +1145,7 @@ QList MenuBar::views() const { } void MenuBar::setDebugMenuVisible(bool visible) { sDebugMenuVisible = visible; } +bool MenuBar::isDebugMenuVisible() { return sDebugMenuVisible; } MenuBar *MenuBar::instance(QWidget *widget) { #ifdef Q_OS_MAC diff --git a/src/ui/MenuBar.h b/src/ui/MenuBar.h index a2bc2354..516eac26 100644 --- a/src/ui/MenuBar.h +++ b/src/ui/MenuBar.h @@ -40,6 +40,7 @@ public: void updateWindow(); static void setDebugMenuVisible(bool show); + static bool isDebugMenuVisible(); static MenuBar *instance(QWidget *widget); /*! * \brief isMaximized diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index a3e02b7d..4d039839 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(util Path.cpp Debug.h) +add_library(util Path.cpp Debug.h Debug.cpp) target_link_libraries(util Qt5::Core) target_include_directories(util INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/util/Debug.cpp b/src/util/Debug.cpp new file mode 100644 index 00000000..ee6f6384 --- /dev/null +++ b/src/util/Debug.cpp @@ -0,0 +1,24 @@ +#include +#include + +namespace { +const QString kLogKey = "debug/log"; +bool readSettings = false; +bool logging = false; +} // namespace + +namespace Debug { + +void setLogging(bool enable) { + logging = enable; + QSettings().setValue(kLogKey, enable); +} + +bool isLogging() { + if (!readSettings) { + readSettings = true; + logging = QSettings().value(kLogKey).toBool(); + } + return logging; +} +}; // namespace Debug \ No newline at end of file diff --git a/src/util/Debug.h b/src/util/Debug.h index 8d737d7c..eecc0b0f 100644 --- a/src/util/Debug.h +++ b/src/util/Debug.h @@ -3,10 +3,17 @@ #include +namespace Debug { + +void setLogging(bool enable); +bool isLogging(); +}; // namespace Debug + #ifdef DEBUG_OUTPUT_GENERAL #define Debug(x) \ do { \ - qDebug() << x; \ + if (Debug::isLogging()) \ + qDebug() << x; \ } while (false) #else #define Debug(x) @@ -15,7 +22,8 @@ #ifdef DEBUG_OUTPUT_REFRESH #define DebugRefresh(x) \ do { \ - qDebug() << Q_FUNC_INFO << QStringLiteral(": ") << x; \ + if (Debug::isLogging()) \ + qDebug() << Q_FUNC_INFO << QStringLiteral(": ") << x; \ } while (false) #else #define DebugRefresh(x)