Activate cliparser and adapt old global variables to it.
authorSebastian Goth <seezer@roath.org>
Wed, 16 Jul 2008 17:16:40 +0000 (19:16 +0200)
committerSebastian Goth <seezer@roath.org>
Wed, 16 Jul 2008 22:57:30 +0000 (00:57 +0200)
qtopia sources haven't been touched but use the variables from global.h
so they stay there for now.

src/common/global.cpp
src/common/global.h
src/common/main.cpp
src/core/core.h
src/core/coresettings.h

index bd5ee20..6a75e34 100644 (file)
@@ -137,3 +137,4 @@ Global::RunMode Global::runMode;
 uint Global::defaultPort;
 
 bool Global::DEBUG;
+CliParser Global::parser;
index ac13646..26f9f6b 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef _GLOBAL_H_
 #define _GLOBAL_H_
 
+#include "cliparser.h"
+
 #include <QString>
 
 // 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();
 };
index 9dab54c..f51f6b2 100644 (file)
@@ -27,6 +27,7 @@
 #include "logger.h"
 #include "network.h"
 #include "settings.h"
+#include "cliparser.h"
 
 #if defined BUILD_CORE
 #include <QCoreApplication>
@@ -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
index e6da7ab..1191895 100644 (file)
@@ -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();
index 749c8ec..775d88e 100644 (file)
@@ -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());