X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Fquassel.cpp;h=7ee7915e905a52608483faad752d02de1c0cb3b5;hb=f9e037ea6a0b946c84db62d324996d8f878c1efb;hp=dea2cd9b43280b0d3d6d0a71a0d709e123420858;hpb=9f91e0dd3c4eb5c2e2dedfc8d36a068d433d51b1;p=quassel.git diff --git a/src/common/quassel.cpp b/src/common/quassel.cpp index dea2cd9b..7ee7915e 100644 --- a/src/common/quassel.cpp +++ b/src/common/quassel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,7 +20,9 @@ #include "quassel.h" +#include #include + #include #if !defined Q_OS_WIN && !defined Q_OS_MAC # include @@ -116,37 +118,41 @@ bool Quassel::init() return false; } - // set up logging - if (Quassel::runMode() != Quassel::ClientOnly) { - if (isOptionSet("loglevel")) { - QString level = optionValue("loglevel"); - - if (level == "Debug") - setLogLevel(DebugLevel); - else if (level == "Info") - setLogLevel(InfoLevel); - else if (level == "Warning") - setLogLevel(WarningLevel); - else if (level == "Error") - setLogLevel(ErrorLevel); - else { - qWarning() << qPrintable(tr("Invalid log level %1; supported are Debug|Info|Warning|Error").arg(level)); - return false; - } + // Set up logging + if (isOptionSet("loglevel")) { + QString level = optionValue("loglevel").toLower(); + + if (level == "debug") + setLogLevel(DebugLevel); + else if (level == "info") + setLogLevel(InfoLevel); + else if (level == "warning") + setLogLevel(WarningLevel); + else if (level == "error") + setLogLevel(ErrorLevel); + else { + qWarning() << qPrintable(tr("Invalid log level %1; supported are Debug|Info|Warning|Error").arg(level)); + return false; } + } - QString logfilename = optionValue("logfile"); - if (!logfilename.isEmpty()) { - instance()->_logFile.reset(new QFile{logfilename}); - if (!logFile()->open(QIODevice::Append | QIODevice::Text)) { - qWarning() << "Could not open log file" << logfilename << ":" << logFile()->errorString(); - instance()->_logFile.reset(); - } + QString logfilename = optionValue("logfile"); + if (!logfilename.isEmpty()) { + instance()->_logFile.reset(new QFile{logfilename}); + if (!logFile()->open(QIODevice::Append | QIODevice::Text)) { + qWarning() << qPrintable(tr("Could not open log file \"%1\": %2").arg(logfilename, logFile()->errorString())); + instance()->_logFile.reset(); } + } #ifdef HAVE_SYSLOG - instance()->_logToSyslog = isOptionSet("syslog"); + instance()->_logToSyslog = isOptionSet("syslog"); +#endif + +#if QT_VERSION < 0x050000 + qInstallMsgHandler(Logger::logMessage); +#else + qInstallMessageHandler(Logger::logMessage); #endif - } return true; } @@ -294,7 +300,14 @@ void Quassel::setupBuildInfo() if (!QString(GIT_HEAD).isEmpty()) { buildInfo.commitHash = GIT_HEAD; QDateTime date; - date.setTime_t(GIT_COMMIT_DATE); +#if QT_VERSION >= 0x050800 + date.setSecsSinceEpoch(GIT_COMMIT_DATE); +#else + // toSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for now. + // See https://doc.qt.io/qt-5/qdatetime.html#toMSecsSinceEpoch + // Warning generated if not converting the 1000 to a qint64 first. + date.setMSecsSinceEpoch(GIT_COMMIT_DATE * (qint64)1000); +#endif buildInfo.commitDate = date.toString(); } else if (!QString(DIST_HASH).contains("Format")) { @@ -720,7 +733,13 @@ bool Quassel::Features::isEnabled(Feature feature) const QStringList Quassel::Features::toStringList(bool enabled) const { + // Check if any feature is enabled + if (!enabled && std::all_of(_features.cbegin(), _features.cend(), [](bool feature) { return !feature; })) { + return QStringList{} << "NoFeatures"; + } + QStringList result; + // TODO Qt5: Use QMetaEnum::fromType() auto featureEnum = Quassel::staticMetaObject.enumerator(Quassel::staticMetaObject.indexOfEnumerator("Feature")); for (quint32 i = 0; i < _features.size(); ++i) {