From: Sebastian Goth Date: Wed, 16 Jul 2008 17:16:40 +0000 (+0200) Subject: Activate cliparser and adapt old global variables to it. X-Git-Tag: 0.3.0~259 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=6f534b8338f9e6cba5bfe7e8183d3a688075f428 Activate cliparser and adapt old global variables to it. qtopia sources haven't been touched but use the variables from global.h so they stay there for now. --- diff --git a/src/common/global.cpp b/src/common/global.cpp index bd5ee204..6a75e34f 100644 --- a/src/common/global.cpp +++ b/src/common/global.cpp @@ -137,3 +137,4 @@ Global::RunMode Global::runMode; uint Global::defaultPort; bool Global::DEBUG; +CliParser Global::parser; diff --git a/src/common/global.h b/src/common/global.h index ac136461..26f9f6b9 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -23,6 +23,8 @@ #ifndef _GLOBAL_H_ #define _GLOBAL_H_ +#include "cliparser.h" + #include // Enable some shortcuts and stuff @@ -55,7 +57,7 @@ namespace Global { extern unsigned int defaultPort; extern bool DEBUG; - + extern CliParser parser; void registerMetaTypes(); void setupVersion(); }; diff --git a/src/common/main.cpp b/src/common/main.cpp index 9dab54c5..f51f6b2c 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -27,6 +27,7 @@ #include "logger.h" #include "network.h" #include "settings.h" +#include "cliparser.h" #if defined BUILD_CORE #include @@ -79,6 +80,25 @@ int main(int argc, char **argv) { QApplication app(argc, argv); #endif + Global::parser = CliParser(QCoreApplication::arguments()); + +#ifndef BUILD_QTUI +// put core-only arguments here + Global::parser.addOption("port",'p',"The port quasselcore will listen at",QString("4242")); + Global::parser.addSwitch("norestore", 'n', "Don't restore last core's state"); +#endif // BUILD_QTUI +#ifndef BUILD_CORE +// put client-only arguments here +#endif // BUILD_QTCORE +// put shared client&core arguments here + Global::parser.addSwitch("debug",'d',"Enable debug output"); + Global::parser.addSwitch("help",'h', "Display this help and exit"); + + if(!Global::parser.parse() || Global::parser.isSet("help")) { + Global::parser.usage(); + return 1; + } + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); // Set up i18n support @@ -100,17 +120,6 @@ int main(int argc, char **argv) { QCoreApplication::setApplicationName("Quassel IRC"); QCoreApplication::setOrganizationName("Quassel Project"); - // Check if a non-standard core port is requested - QStringList args = QCoreApplication::arguments(); // TODO Build a CLI parser - Global::DEBUG = args.contains("--debug"); // This enables various debug features. - - Global::defaultPort = 4242; - int idx; - if((idx = args.indexOf("-p")) > 0 && idx < args.count() - 1) { - int port = args[idx+1].toInt(); - if(port >= 1024 && port < 65536) Global::defaultPort = port; - } - #ifndef BUILD_QTUI Core::instance(); // create and init the core #endif @@ -126,7 +135,7 @@ int main(int argc, char **argv) { #endif #ifndef BUILD_QTUI - if(!args.contains("--norestore")) { + if(!Global::parser.isSet("norestore")) { Core::restoreState(); } #endif diff --git a/src/core/core.h b/src/core/core.h index e6da7aba..11918957 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -295,7 +295,7 @@ class Core : public QObject { void bufferInfoUpdated(UserId user, const BufferInfo &info); private slots: - bool startListening(uint port = Global::defaultPort); + bool startListening(uint port = Global::parser.value("port").toUInt()); void stopListening(); void incomingConnection(); void clientHasData(); diff --git a/src/core/coresettings.h b/src/core/coresettings.h index 749c8ec1..775d88e9 100644 --- a/src/core/coresettings.h +++ b/src/core/coresettings.h @@ -36,7 +36,7 @@ class CoreSettings : public Settings { QVariant oldDbSettings(); // FIXME remove void setPort(const uint &port); - uint port(const uint &def = Global::defaultPort); + uint port(const uint &def = Global::parser.value("port").toUInt()); void setCoreState(const QVariant &data); QVariant coreState(const QVariant &def = QVariant());