modernize: Use raw string literals instead of escaped strings
[quassel.git] / src / common / quassel.cpp
index b7a6fbf..03cf739 100644 (file)
@@ -44,6 +44,7 @@
 #include "protocol.h"
 #include "syncableobject.h"
 #include "types.h"
+#include "version.h"
 
 #ifndef Q_OS_WIN
 #    include "posixsignalwatcher.h"
 #    include "windowssignalwatcher.h"
 #endif
 
-#include "../../version.h"
-
 Quassel::Quassel()
     : Singleton<Quassel>{this}
     , _logger{new Logger{this}}
 {
+#ifdef EMBED_DATA
+    Q_INIT_RESOURCE(i18n);
+#endif
 }
 
 
@@ -70,22 +72,17 @@ void Quassel::init(RunMode runMode)
     setupEnvironment();
     registerMetaTypes();
 
-    Network::setDefaultCodecForServer("UTF-8");
-    Network::setDefaultCodecForEncoding("UTF-8");
-    Network::setDefaultCodecForDecoding("ISO-8859-15");
+    // Initial translation (may be overridden in UI settings)
+    loadTranslation(QLocale::system());
 
-    if (isOptionSet("help")) {
-        instance()->_cliParser->usage();
-        return;
-    }
-
-    if (isOptionSet("version")) {
-        std::cout << qPrintable("Quassel IRC: " + Quassel::buildInfo().plainVersionString) << std::endl;
-        return;
-    }
+    setupCliParser();
 
     // Don't keep a debug log on the core
     logger()->setup(runMode != RunMode::CoreOnly);
+
+    Network::setDefaultCodecForServer("UTF-8");
+    Network::setDefaultCodecForEncoding("UTF-8");
+    Network::setDefaultCodecForDecoding("ISO-8859-15");
 }
 
 
@@ -332,21 +329,95 @@ Quassel::RunMode Quassel::runMode() {
 }
 
 
-void Quassel::setCliParser(std::shared_ptr<AbstractCliParser> parser)
+void Quassel::setupCliParser()
 {
-    instance()->_cliParser = std::move(parser);
+    QList<QCommandLineOption> options;
+
+    // General options
+    /// @todo Bring back --datadir to specify the database location independent of config
+    if (runMode() == RunMode::ClientOnly) {
+        options += {{"c", "configdir"}, tr("Specify the directory holding the client configuration."), tr("path")};
+    }
+    else {
+        options += {{"c", "configdir"}, tr("Specify the directory holding configuration files, the SQlite database and the SSL certificate."), tr("path")};
+    }
+
+    // Client options
+    if (runMode() != RunMode::CoreOnly) {
+        options += {
+            {"icontheme", tr("Override the system icon theme ('breeze' is recommended)."), tr("theme")},
+            {"qss", tr("Load a custom application stylesheet."), tr("file.qss")},
+            {"hidewindow", tr("Start the client minimized to the system tray.")},
+        };
+    }
+
+    // Core options
+    if (runMode() != RunMode::ClientOnly) {
+        options += {
+            {"listen", tr("The address(es) quasselcore will listen on."), tr("<address>[,<address>[,...]]"), "::,0.0.0.0"},
+            {{"p", "port"}, tr("The port quasselcore will listen at."), tr("port"), "4242"},
+            {{"n", "norestore"}, tr("Don't restore last core's state.")},
+            {"config-from-environment", tr("Load configuration from environment variables.")},
+            {"select-backend", tr("Switch storage backend (migrating data if possible)."), tr("backendidentifier")},
+            {"select-authenticator", tr("Select authentication backend."), tr("authidentifier")},
+            {"add-user", tr("Starts an interactive session to add a new core user.")},
+            {"change-userpass", tr("Starts an interactive session to change the password of the user identified by <username>."), tr("username")},
+            {"strict-ident", tr("Use users' quasselcore username as ident reply. Ignores each user's configured ident setting.")},
+            {"ident-daemon", tr("Enable internal ident daemon.")},
+            {"ident-port", tr("The port quasselcore will listen at for ident requests. Only meaningful with --ident-daemon."), tr("port"), "10113"},
+            {"oidentd", tr("Enable oidentd integration. In most cases you should also enable --strict-ident.")},
+            {"oidentd-conffile", tr("Set path to oidentd configuration file."), tr("file")},
+#ifdef HAVE_SSL
+            {"require-ssl", tr("Require SSL for remote (non-loopback) client connections.")},
+            {"ssl-cert", tr("Specify the path to the SSL certificate."), tr("path"), "configdir/quasselCert.pem"},
+            {"ssl-key", tr("Specify the path to the SSL key."), tr("path"), "ssl-cert-path"},
+#endif
+        };
+    }
+
+    // Logging options
+    options += {
+        {{"L", "loglevel"}, tr("Supports one of Debug|Info|Warning|Error; default is Info."), tr("level"), "Info"},
+        {{"l", "logfile"}, tr("Log to a file."), "path"},
+#ifdef HAVE_SYSLOG
+        {"syslog", tr("Log to syslog.")},
+#endif
+    };
+
+    // Debug options
+    options += {{"d", "debug"}, tr("Enable debug output.")};
+    if (runMode() != RunMode::CoreOnly) {
+        options += {
+            {"debugbufferswitches", tr("Enables debugging for bufferswitches.")},
+            {"debugmodel", tr("Enables debugging for models.")},
+        };
+    }
+    if (runMode() != RunMode::ClientOnly) {
+        options += {
+            {"debug-irc", tr("Enable logging of all raw IRC messages to debug log, including passwords!  In most cases you should also set --loglevel Debug")},
+            {"debug-irc-id", tr("Limit raw IRC logging to this network ID.  Implies --debug-irc"), tr("database network ID"), "-1"},
+        };
+    }
+
+    _cliParser.addOptions(options);
+    _cliParser.addHelpOption();
+    _cliParser.addVersionOption();
+    _cliParser.setApplicationDescription(tr("Quassel IRC is a modern, distributed IRC client."));
+
+    // This will call ::exit() for --help, --version and in case of errors
+    _cliParser.process(*QCoreApplication::instance());
 }
 
 
 QString Quassel::optionValue(const QString &key)
 {
-    return instance()->_cliParser ? instance()->_cliParser->value(key) : QString{};
+    return instance()->_cliParser.value(key);
 }
 
 
 bool Quassel::isOptionSet(const QString &key)
 {
-    return instance()->_cliParser ? instance()->_cliParser->isSet(key) : false;
+    return instance()->_cliParser.isSet(key);
 }
 
 
@@ -373,11 +444,7 @@ QString Quassel::configDirPath()
         return instance()->_configDirPath;
 
     QString path;
-    if (isOptionSet("datadir")) {
-        qWarning() << "Obsolete option --datadir used!";
-        path = Quassel::optionValue("datadir");
-    }
-    else if (isOptionSet("configdir")) {
+    if (isOptionSet("configdir")) {
         path = Quassel::optionValue("configdir");
     }
     else {
@@ -522,8 +589,8 @@ QString Quassel::translationDirPath()
 
 void Quassel::loadTranslation(const QLocale &locale)
 {
-    QTranslator *qtTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QtTr");
-    QTranslator *quasselTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QuasselTr");
+    auto *qtTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QtTr");
+    auto *quasselTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QuasselTr");
 
     if (qtTranslator)
         qApp->removeTranslator(qtTranslator);
@@ -536,11 +603,9 @@ void Quassel::loadTranslation(const QLocale &locale)
 
     qtTranslator = new QTranslator(qApp);
     qtTranslator->setObjectName("QtTr");
-    qApp->installTranslator(qtTranslator);
 
     quasselTranslator = new QTranslator(qApp);
     quasselTranslator->setObjectName("QuasselTr");
-    qApp->installTranslator(quasselTranslator);
 
 #ifndef Q_OS_MAC
     bool success = qtTranslator->load(locale, QString("qt_"), translationDirPath());
@@ -553,6 +618,9 @@ void Quassel::loadTranslation(const QLocale &locale)
         qtTranslator->load(QString("qt_%1").arg(locale.name()), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
     quasselTranslator->load(QString("%1").arg(locale.name()), translationDirPath());
 #endif
+
+    qApp->installTranslator(quasselTranslator);
+    qApp->installTranslator(qtTranslator);
 }
 
 
@@ -601,7 +669,7 @@ Quassel::Features::Features(const QStringList &features, LegacyFeatures legacyFe
 
 bool Quassel::Features::isEnabled(Feature feature) const
 {
-    size_t i = static_cast<size_t>(feature);
+    auto i = static_cast<size_t>(feature);
     return i < _features.size() ? _features[i] : false;
 }