# # # patch "src/main.cpp" # from [70614a53d6fdc5f3bbc201ede2cc8bb3f0acfd2c] # to [e08f5e610c7b071bdc0e5eb2960c79cb61ef04b5] # # patch "src/util/DebugLog.cpp" # from [981d710b1ccf620eedbdc682d5f03872b0f8502f] # to [3c707a7820af0a0260c60a1f765e6a0e214418f7] # # patch "src/util/DebugLog.h" # from [468ea3e9a4dd5a5406caa98dd666a3d8d5a67320] # to [03c00cd416e6db6eea27b05f404f742af4c54b69] # # patch "src/view/dialogs/Preferences.cpp" # from [dcd25661e00b81d9b5347a225b257494763c65fd] # to [608c1282c24b69935efed352c24f8deb302ca8f4] # ============================================================ --- src/main.cpp 70614a53d6fdc5f3bbc201ede2cc8bb3f0acfd2c +++ src/main.cpp e08f5e610c7b071bdc0e5eb2960c79cb61ef04b5 @@ -26,29 +26,29 @@ #include "GuitoneStandalone.h" #include "GuitoneDriver.h" +#include #include #include #include #include -void guitoneMsgHandler(QtMsgType type, const char *msg) +void guitoneMsgHandler(QtMsgType type, const char * msg) { - switch (type) + static QMap typeMap; + if (typeMap.size() == 0) { - case QtDebugMsg: - DebugLog::debug(msg); - break; - case QtWarningMsg: - DebugLog::warn(msg); - break; - case QtCriticalMsg: - DebugLog::critical(msg); - break; - case QtFatalMsg: - DebugLog::fatal(msg); - abort(); - } + typeMap.insert(QtDebugMsg, DebugLog::Debug); + typeMap.insert(QtWarningMsg, DebugLog::Warn); + typeMap.insert(QtCriticalMsg, DebugLog::Critical); + typeMap.insert(QtFatalMsg, DebugLog::Fatal); + } + I(typeMap.contains(type)); + + DebugLog::log(typeMap.value(type), QString::fromUtf8(msg)); + + if (type == QtFatalMsg) + abort(); } int main(int argc, char** argv) @@ -94,6 +94,12 @@ int main(int argc, char** argv) guitone = new GuitoneStandalone(argc, argv); } +#ifdef Q_WS_MAC + guitone->addLibraryPath( + QDir::cleanPath(guitone->applicationDirPath() + "/../PlugIns") + ); +#endif + guitone->installTranslator(&appTranslator); guitone->installTranslator(&qtTranslator); ============================================================ --- src/util/DebugLog.cpp 981d710b1ccf620eedbdc682d5f03872b0f8502f +++ src/util/DebugLog.cpp 3c707a7820af0a0260c60a1f765e6a0e214418f7 @@ -37,165 +37,152 @@ DebugLog* DebugLog::singleton() return instance; } -DebugLog::DebugLog() +DebugLog::DebugLog() : loggedToConsole(false) {} + +QStringList DebugLog::intro() { - consoleLogging = Settings::getBool("ConsoleLogEnabled"); - int level = Settings::getLogLevel(); - if (level >= Fatal && level <= Debug) logLevel = static_cast(level); + QStringList lines; - if (Settings::getBool("FileLogEnabled")) - { - openLogfile(); - } + QString sep; + sep.fill('=', 64); - QString sep; + lines.append(sep); + QDate today = QDate::currentDate(); - sep.fill('=', 64); - log(Info, sep); - log(Info, - QString(" guitone session started (%1)") + lines.append( + QString(" guitone log started (%1)") .arg(today.toString("yyyy-MM-dd")) ); - log(Info, + lines.append( QString("version: %1, revision: %2") .arg(GUITONE_VERSION).arg(GUITONE_REVISION) ); - log(Info, sep); + lines.append(sep); + + return lines; } DebugLog::~DebugLog() { - if (logFile.isOpen()) closeLogfile(); + if (logFile.isOpen()) logFile.close(); } -void DebugLog::openLogfile() +QByteArray DebugLog::format(Type t, QString msg) { - logFile.setFileName(logFilePath()); - - QFlags flags = - QIODevice::WriteOnly | QIODevice::Append | - QIODevice::Text | QIODevice::Unbuffered; - - if (!logFile.open(flags)) + static QMap types; + if (types.size() == 0) { - fileLogging = false; - log(Critical, QString( - "cannot open logfile '%1' for writing, disable file logging " - "(error was: %2)" - ).arg(logFilePath()).arg(logFile.errorString())); - return; + types[Fatal] = "fatal"; + types[Critical] = "critical"; + types[Warn] = "warning"; + types[Info] = "info"; + types[Debug] = "debug"; } - fileLogging = true; -} + // do not use I here since this calls qFatal and results in + // an endless loop + assert(t <= types.size()); -void DebugLog::log(Type t, QString msg) -{ - if (!fileLogging && !consoleLogging) return; + QTime now = QTime::currentTime(); - if (logLevel == Fatal && t > Fatal) return; - if (logLevel == Critical && t > Critical) return; - if (logLevel == Warn && t > Warn) return; - if (logLevel == Info && t > Info) return; - if (logLevel == Debug && t > Debug) return; + QString logStr = QString("%1: %2: %3\n") + .arg(now.toString("hh:mm:ss.zzz")) + .arg(types[t]) + .arg(msg); - QMap errors; - errors[0] = "fatal"; - errors[1] = "critical"; - errors[2] = "warning"; - errors[3] = "info"; - errors[4] = "debug"; + return logStr.toUtf8(); +} - // do not use I here since this calls qFatal and results in - // an endless loop - assert(t <= errors.size()); +void DebugLog::doLog(Type t, QString msg) +{ + bool logToConsole = Settings::getBool("ConsoleLogEnabled"); + bool logToFile = Settings::getBool("FileLogEnabled"); - QTime now = QTime::currentTime(); + if (!logToFile && !logToConsole) + return; - QString logStr; - logStr.append( - QString("%1: %2: %3\n") - .arg(now.toString("hh:mm:ss.zzz")) - .arg(errors[t-1]) - .arg(msg) - ); + int logLevel = Settings::getLogLevel(); + if (logLevel == Fatal && t > Fatal) + return; + if (logLevel == Critical && t > Critical) + return; + if (logLevel == Warn && t > Warn) + return; + if (logLevel == Info && t > Info) + return; + if (logLevel == Debug && t > Debug) + return; - QByteArray utf8_msg = logStr.toUtf8(); - - // print the message on console - if (consoleLogging) + if (logToFile && !logFile.isOpen()) { - fprintf(stderr, utf8_msg.constData()); - } + logFile.setFileName(logFilePath()); - // print the message to the logfile - if (fileLogging && !logFile.write(utf8_msg)) - { - fileLogging = false; - log(Critical, QString( - "could not log to file, disable file log (error: %1)" - ).arg(logFile.errorString())); - } -} + QFlags flags = + QIODevice::WriteOnly | QIODevice::Append | + QIODevice::Text | QIODevice::Unbuffered; -void DebugLog::closeLogfile() -{ - if (logFile.isOpen()) logFile.close(); - fileLogging = false; -} + if (!logFile.open(flags)) + { + Settings::setBool("FileLogEnabled", false); -#ifndef QT_NO_DEBUG -void DebugLog::debug(QString msg) -{ - singleton()->log(Debug, msg); -} -#else -void DebugLog::debug(QString msg) { Q_UNUSED(msg); } -#endif + doLog(Critical, QString( + "cannot open logfile '%1' for writing, disable file logging " + "(error was: %2)" + ).arg(logFilePath()).arg(logFile.errorString())); -void DebugLog::info(QString msg) -{ - singleton()->log(Info, msg); -} + doLog(t, msg); + return; + } -void DebugLog::warn(QString msg) -{ - singleton()->log(Warn, msg); -} + foreach (const QString & line, intro()) + { + if (!logFile.write(format(Info, line))) + { + Settings::setBool("FileLogEnabled", false); -void DebugLog::critical(QString msg) -{ - singleton()->log(Critical, msg); -} + doLog(Critical, QString( + "could not log to file, disabling file log (error: %1)" + ).arg(logFile.errorString())); + return; + } + } + } + else if (!logToFile && logFile.isOpen()) + { + logFile.close(); + } -void DebugLog::fatal(QString msg) -{ - singleton()->log(Fatal, msg); -} + if (!loggedToConsole && logToConsole) + { + foreach (const QString & line, intro()) + { + fprintf(stderr, format(Info, line).constData()); + } + loggedToConsole = true; + } + else + if (loggedToConsole && !logToConsole) + { + loggedToConsole = false; + } -void DebugLog::setConsoleLogEnabled(bool enabled) -{ - DebugLog * log = singleton(); - log->consoleLogging = enabled; -} + QByteArray formattedMsg = format(t, msg); -void DebugLog::setFileLogEnabled(bool enabled) -{ - DebugLog * log = singleton(); - if (log->fileLogging && !enabled) + // print the message on console + if (logToConsole) { - log->closeLogfile(); + fprintf(stderr, formattedMsg.constData()); } - else if (!log->fileLogging && enabled) + + // print the message to the logfile + if (logToFile && !logFile.write(formattedMsg)) { - log->openLogfile(); - } -} + Settings::setBool("FileLogEnabled", false); -void DebugLog::setLogLevel(int level) -{ - if (level < Fatal || level > Debug) return; - singleton()->logLevel = static_cast(level); + doLog(Critical, QString( + "could not log to file, disabling file log (error: %1)" + ).arg(logFile.errorString())); + } } QString DebugLog::logFilePath() ============================================================ --- src/util/DebugLog.h 468ea3e9a4dd5a5406caa98dd666a3d8d5a67320 +++ src/util/DebugLog.h 03c00cd416e6db6eea27b05f404f742af4c54b69 @@ -33,38 +33,37 @@ public: // the name for a specific log type typedef Level Type; - static void setFileLogEnabled(bool); - static void setConsoleLogEnabled(bool); - static void setLogLevel(int); - static QString logFilePath(); - static void info(QString); - static void debug(QString); - inline static void debug(const char * msg) { return debug(QString::fromUtf8(msg)); } - static void warn(QString); - inline static void warn(const char * msg) { return warn(QString::fromUtf8(msg)); } - static void critical(QString); - inline static void critical(const char * msg) { return critical(QString::fromUtf8(msg)); } - static void fatal(QString); - inline static void fatal(const char * msg) { return fatal(QString::fromUtf8(msg)); } + inline static void debug(const QString & msg) + { +#ifndef QT_NO_DEBUG + singleton()->log(Debug, msg); +#else + Q_UNUSED(msg); +#endif; + } -private: + inline static void info(const QString & msg) { singleton()->doLog(Info, msg); } + inline static void warn(const QString & msg) { singleton()->doLog(Warn, msg); } + inline static void critical(const QString & msg) { singleton()->doLog(Critical, msg); } + inline static void fatal(const QString & msg) { singleton()->doLog(Fatal, msg); } + inline static void log(Type t, const QString & msg) { singleton()->doLog(t, msg); } +private: DebugLog(); ~DebugLog(); - void openLogfile(); - void closeLogfile(); - void log(Type, QString); - bool consoleLogging; - bool fileLogging; - Level logLevel; + static QStringList intro(); + + QByteArray format(Type, QString); + void doLog(Type, QString); + QFile logFile; + bool loggedToConsole; static DebugLog * singleton(); static DebugLog * instance; }; - #endif ============================================================ --- src/view/dialogs/Preferences.cpp dcd25661e00b81d9b5347a225b257494763c65fd +++ src/view/dialogs/Preferences.cpp 608c1282c24b69935efed352c24f8deb302ca8f4 @@ -165,6 +165,10 @@ void Preferences::accept() void Preferences::accept() { + Settings::setBool("ConsoleLogEnabled", enableConsoleLog->isChecked()); + Settings::setBool("FileLogEnabled", enableFileLog->isChecked()); + Settings::setLogLevel(logLevel->itemData(logLevel->currentIndex()).toInt()); + QString oldPath = Settings::getMtnBinaryPath(); QString newPath = mtnExecutablePath->text(); bool checkUpperBound = relaxedVersionCheck->isChecked(); @@ -201,18 +205,6 @@ void Preferences::accept() Settings::setMtnBinaryPath(newPath); } - bool consoleEnabled = enableConsoleLog->isChecked(); - bool fileEnabled = enableFileLog->isChecked(); - int level = logLevel->itemData(logLevel->currentIndex()).toInt(); - - DebugLog::setConsoleLogEnabled(consoleEnabled); - DebugLog::setFileLogEnabled(fileEnabled); - DebugLog::setLogLevel(level); - - Settings::setBool("ConsoleLogEnabled", consoleEnabled); - Settings::setBool("FileLogEnabled", fileEnabled); - Settings::setLogLevel(level); - Settings::setBool("CheckForUpdates", checkForUpdates->isChecked()); Settings::setBool("SaveEncodingAsFileAttribute", saveEncodingAsFileAttribute->isChecked()); Settings::setBool("FixUnwantedReverseDiffs", fixUnwantedReverseDiffs->isChecked());