Added a commandline option to specify the datadir (the dir containing sqlite db and...
authorMarcus Eggenberger <egs@quassel-irc.org>
Fri, 1 Aug 2008 12:52:11 +0000 (14:52 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Fri, 1 Aug 2008 12:52:11 +0000 (14:52 +0200)
 - Mac OS X data dir is now ~/Library/Application Support/Quassel and no longer quassel
 - cli parser replaces now leading '~' with the homedir

src/common/cliparser.cpp
src/common/cliparser.h
src/common/main.cpp
src/common/util.cpp

index e3b8add..c4ca9b8 100644 (file)
@@ -19,6 +19,7 @@
  ***************************************************************************/
 #include "cliparser.h"
 
+#include <QDir>
 #include <QString>
 #include <QFileInfo>
 #include <QDebug>
@@ -38,7 +39,7 @@ void CliParser::addArgument(const QString &longName, const CliParserArg &arg) {
 bool CliParser::addLongArg(const CliParserArg::CliArgType type, const QString &name, const QString &value) {
   if(argsHash.contains(name)){
     if(type == CliParserArg::CliArgOption && argsHash.value(name).type == type) {
-      argsHash[name].value = value;
+      argsHash[name].value = escapedValue(value);
       return true;
     }
     else if (type == CliParserArg::CliArgSwitch && argsHash.value(name).type == type) {
@@ -54,7 +55,7 @@ bool CliParser::addShortArg(const CliParserArg::CliArgType type, const char shor
   QString longName = lnameOfShortArg(shortName);
   if(!longName.isNull()) {
     if(type == CliParserArg::CliArgOption && argsHash.value(longName).type == type) {
-      argsHash[longName].value = value;
+      argsHash[longName].value = escapedValue(value);
       return true;
     }
     else if (type == CliParserArg::CliArgSwitch) {
@@ -73,6 +74,14 @@ bool CliParser::addShortArg(const CliParserArg::CliArgType type, const char shor
   return false;
 }
 
+QString CliParser::escapedValue(const QString &value) {
+  QString escapedValue = value;
+  if(escapedValue.startsWith("~"))
+    escapedValue.replace(0, 1, QDir::homePath());
+
+  return escapedValue;
+}
+
 bool CliParser::parse() {
   QStringList::const_iterator currentArg;
   for (currentArg = argsRaw.constBegin(); currentArg != argsRaw.constEnd(); ++currentArg) {
index 1750843..5d83bcb 100644 (file)
@@ -67,6 +67,7 @@ private:
   void addArgument(const QString &longName, const CliParserArg &arg);
   bool addLongArg(const CliParserArg::CliArgType type, const QString &name, const QString &value = QString());
   bool addShortArg(const CliParserArg::CliArgType type, const char shortName, const QString &value = QString());
+  QString escapedValue(const QString &value);
   QString lnameOfShortArg(const char arg);
   QStringList argsRaw;
   QHash<QString, CliParserArg> argsHash;
index 555ec15..50221a2 100644 (file)
@@ -87,6 +87,7 @@ int main(int argc, char **argv) {
   Global::parser.addSwitch("norestore", 'n', "Don't restore last core's state");
   Global::parser.addOption("logfile",'l',"Path to logfile");
   Global::parser.addOption("loglevel",'L',"Loglevel Debug|Info|Warning|Error","Info");
+  Global::parser.addOption("datadir", 0, "Specify the directory holding datafiles like the Sqlite DB and the SSL Cert");
 #endif // BUILD_QTUI
 #ifndef BUILD_CORE
 // put client-only arguments here
@@ -114,7 +115,6 @@ int main(int argc, char **argv) {
         qWarning("Warning: Couldn't open logfile '%s' - will log to stdout instead",qPrintable(logFile.fileName()));
       else logFile.close();
     }
-    else qWarning("No logfile set - will log to stdout instead");
   }
 
   qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
index 9bd17d9..f0a7a74 100644 (file)
@@ -19,6 +19,7 @@
  ***************************************************************************/
 
 #include "util.h"
+#include "global.h"
 
 #include <QCoreApplication>
 #include <QDebug>
@@ -142,12 +143,18 @@ QByteArray methodName(const QMetaMethod &method) {
 }
 
 QDir quasselDir() {
-  // kinda ugly, but I currently see no other way to do that
+  QString quasselDir;
+  if(Global::parser.isSet("datadir")) {
+    quasselDir = Global::parser.value("datadir");
+  } else {
 #ifdef Q_OS_WIN32
-  QString quasselDir = qgetenv("APPDATA") + "/quassel/";
+    quasselDir = qgetenv("APPDATA") + "/quassel/";
+#elif defined Q_WS_MAC
+    quasselDir = QDir::homePath() + "/Library/Application Support/Quassel/";
 #else
-  QString quasselDir = QDir::homePath() + "/.quassel/";
+    quasselDir = QDir::homePath() + "/.quassel/";
 #endif
+  }
 
   QDir qDir(quasselDir);
   if(!qDir.exists(quasselDir)) {