Rather than hacking KDE support into CliParser using #ifdef (which forces all quassel binaries
to be built even with or without KDE support), I have now created an abstract base class and
specializations for the two cases. quasselcore now always builds without KDE deps.
COMPILE_FLAGS "-DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_CORE"
OUTPUT_NAME ../quasselcore)
target_link_libraries(quasselcore mod_core mod_common
- ${QUASSEL_QT_LIBRARIES} ${QUASSEL_KDE_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
+ ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
install(TARGETS quasselcore RUNTIME DESTINATION ${BIN_INSTALL_DIR})
endif(WANT_CORE)
set(SOURCES ${SOURCES} logbacktrace_unix.cpp)
endif(CMAKE_HOST_UNIX)
-
-
set(MOC_HDRS
aliasmanager.h
backlogmanager.h
syncableobject.h)
set(HEADERS ${MOC_HDRS}
+ abstractcliparser.h
bufferinfo.h
cliparser.h
logger.h
qt4_wrap_cpp(MOC ${MOC_HDRS})
-
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) # for version.inc and version.gen
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES version.gen)
add_library(mod_common STATIC ${SOURCES} ${MOC} ${CMAKE_BINARY_DIR}/i18n/qrc_i18n.cxx)
set_source_files_properties(${CMAKE_BINARY_DIR}/i18n/qrc_i18n.cxx PROPERTIES GENERATED true)
add_dependencies(mod_common i18n)
-
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef ABSTRACTCLIPARSER_H
+#define ABSTRACTCLIPARSER_H
+
+#include <QStringList>
+
+class AbstractCliParser {
+public:
+ virtual bool init(const QStringList &arguments = QStringList()) = 0;
+
+ virtual QString value(const QString &longName) = 0;
+ virtual bool isSet(const QString &longName) = 0;
+ inline void addSwitch(const QString &longName, const char shortName = 0, const QString &help = QString()) {
+ addArgument(longName, CliParserArg(CliParserArg::CliArgSwitch, shortName, help));
+ }
+ inline void addOption(const QString &longName, const char shortName = 0, const QString &help = QString(), const QString &def = QString()) {
+ addArgument(longName, CliParserArg(CliParserArg::CliArgOption, shortName, help, def));
+ }
+ virtual void usage() = 0;
+
+ virtual ~AbstractCliParser() {};
+
+protected:
+ struct CliParserArg {
+ enum CliArgType {
+ CliArgInvalid,
+ CliArgSwitch,
+ CliArgOption
+ };
+
+ CliParserArg(const CliArgType _type = CliArgInvalid, const char _shortName = 0, const QString _help = QString(), const QString _def = QString())
+ : type(_type),
+ shortName(_shortName),
+ help(_help),
+ def(_def),
+ value(QString()),
+ boolValue(false) {};
+
+ CliArgType type;
+ char shortName;
+ QString help;
+ QString def;
+ QString value;
+ bool boolValue;
+ };
+
+ virtual void addArgument(const QString &longName, const CliParserArg &arg) = 0;
+};
+
+#endif
#include <QString>
#include <QFileInfo>
-#ifdef HAVE_KDE
-# include <KCmdLineArgs>
-#endif
-
-CliParser::CliParser() {
+CliParser::CliParser() : AbstractCliParser() {
}
-#ifdef HAVE_KDE
-void CliParser::addArgument(const QString &longName, const CliParserArg &arg) {
- if(arg.shortName != 0) {
- _cmdLineOptions.add(QByteArray().append(arg.shortName));
- }
- _cmdLineOptions.add(longName.toUtf8(), ki18n(arg.help.toUtf8()), arg.def.toUtf8());
-}
-
-bool CliParser::init(const QStringList &) {
- KCmdLineArgs::addCmdLineOptions(_cmdLineOptions);
- return true;
-}
-
-QString CliParser::value(const QString &longName) {
- return KCmdLineArgs::parsedArgs()->getOption(longName.toUtf8());
-}
-
-bool CliParser::isSet(const QString &longName) {
- return KCmdLineArgs::parsedArgs()->isSet(longName.toUtf8());
-}
-
-void CliParser::usage() {
- KCmdLineArgs::usage();
-}
-
-#else
void CliParser::addArgument(const QString &longName_, const CliParserArg &arg) {
QString longName = longName_;
longName.remove(QRegExp("\\s*<.*>\\s*")); // KCmdLineArgs takes args of the form "arg <defval>"
}
return QString();
}
-
-#endif
#ifndef CLIPARSER_H
#define CLIPARSER_H
-#include <QString>
-#include <QStringList>
#include <QHash>
-#ifdef HAVE_KDE
-# include <KCmdLineOptions>
-#endif
+#include "abstractcliparser.h"
-class CliParser {
+//! Quassel's own parser for command line arguments
+class CliParser : public AbstractCliParser {
public:
CliParser();
QString value(const QString &longName);
bool isSet(const QString &longName);
- inline void addSwitch(const QString &longName, const char shortName = 0, const QString &help = QString()) {
- addArgument(longName, CliParserArg(CliParserArg::CliArgSwitch, shortName, help));
- }
- inline void addOption(const QString &longName, const char shortName = 0, const QString &help = QString(), const QString &def = QString()) {
- addArgument(longName, CliParserArg(CliParserArg::CliArgOption, shortName, help, def));
- }
void usage();
private:
- struct CliParserArg {
- enum CliArgType {
- CliArgInvalid,
- CliArgSwitch,
- CliArgOption
- };
- CliParserArg(const CliArgType _type = CliArgInvalid, const char _shortName = 0, const QString _help = QString(), const QString _def = QString())
- : type(_type),
- shortName(_shortName),
- help(_help),
- def(_def),
- value(QString()),
- boolValue(false) {};
-
- CliArgType type;
- char shortName;
- QString help;
- QString def;
- QString value;
- bool boolValue;
- };
-
void addArgument(const QString &longName, const CliParserArg &arg);
-
-#ifndef HAVE_KDE
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);
QStringList argsRaw;
QHash<QString, CliParserArg> argsHash;
-
-#else
- KCmdLineOptions _cmdLineOptions;
-#endif
};
#endif
#include <cstdlib>
-#ifdef HAVE_KDE
-# include <KCmdLineArgs>
-# include <KAboutData>
-#endif
-
#ifdef BUILD_CORE
# include "coreapplication.h"
#elif defined BUILD_QTUI
#error "Something is wrong - you need to #define a build mode!"
#endif
+// We don't want quasselcore to depend on KDE
+#if defined HAVE_KDE && defined BUILD_CORE
+# undef HAVE_KDE
+#endif
+
+#ifdef HAVE_KDE
+# include <KAboutData>
+# include "kcmdlinewrapper.h"
+#endif
+
+#include "cliparser.h"
#include "quassel.h"
int main(int argc, char **argv) {
QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
+ AbstractCliParser *cliParser;
+
#ifdef HAVE_KDE
// We need to init KCmdLineArgs first
// TODO: build an AboutData compat class to replace our aboutDlg strings
aboutData.addLicense(KAboutData::License_GPL_V3);
aboutData.setOrganizationDomain(Quassel::buildInfo().organizationDomain.toUtf8());
KCmdLineArgs::init(argc, argv, &aboutData);
+
+ cliParser = new KCmdLineWrapper();
+#else
+ cliParser = new CliParser();
#endif
+ Quassel::setCliParser(cliParser);
// Initialize CLI arguments
// NOTE: We can't use tr() at this point, since app is not yet created
- CliParser *cliParser = Quassel::cliParser();
// put shared client&core arguments here
cliParser->addSwitch("debug",'d', "Enable debug output");
#include "syncableobject.h"
Quassel::BuildInfo Quassel::_buildInfo;
-CliParser *Quassel::_cliParser = 0;
+AbstractCliParser *Quassel::_cliParser = 0;
Quassel::RunMode Quassel::_runMode;
bool Quassel::_initialized = false;
bool Quassel::DEBUG = false;
#include <QCoreApplication>
#include <QString>
-#include "cliparser.h"
+#include "abstractcliparser.h"
class Quassel {
Q_DECLARE_TR_FUNCTIONS(Quassel)
static inline const BuildInfo & buildInfo();
static inline RunMode runMode();
- static inline CliParser *cliParser();
+ static inline void setCliParser(AbstractCliParser *cliParser);
+ static inline AbstractCliParser *cliParser();
static inline QString optionValue(const QString &option);
static inline bool isOptionSet(const QString &option);
static void logBacktrace(const QString &filename);
static BuildInfo _buildInfo;
- static CliParser *_cliParser;
+ static AbstractCliParser *_cliParser;
static RunMode _runMode;
static bool _initialized;
Quassel::RunMode Quassel::runMode() { return _runMode; }
void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
-CliParser *Quassel::cliParser() { return _cliParser ? _cliParser : _cliParser = new CliParser(); }
+void Quassel::setCliParser(AbstractCliParser *parser) { _cliParser = parser; }
+AbstractCliParser *Quassel::cliParser() { return _cliParser; }
QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
Core::instance(); // create and init the core
_coreCreated = true;
-#ifdef HAVE_KDE
- // if using KDE, option is called "restore" instead of "norestore"
- if(Quassel::isOptionSet("restore"))
-#else
if(!Quassel::isOptionSet("norestore"))
-#endif
Core::restoreState();
return true;
/*****************************************************************************/
-CoreApplication::CoreApplication(int &argc, char **argv)
-#ifdef HAVE_KDE
-: KApplication(false), Quassel() {
- Q_UNUSED(argc); Q_UNUSED(argv);
-#else
-: QCoreApplication(argc, argv), Quassel() {
-#endif
-
+CoreApplication::CoreApplication(int &argc, char **argv) : QCoreApplication(argc, argv), Quassel() {
setRunMode(Quassel::CoreOnly);
_internal = new CoreApplicationInternal();
}
bool _coreCreated;
};
-#ifdef HAVE_KDE
-class CoreApplication : public KApplication, public Quassel {
-#else
class CoreApplication : public QCoreApplication, public Quassel {
-#endif
Q_OBJECT
public:
uisettings.h
uistyle.h)
+if(HAVE_KDE)
+ set(SOURCES ${SOURCES} kcmdlinewrapper.cpp)
+ set(HEADERS ${HEADERS} kcmdlinewrapper.h)
+endif(HAVE_KDE)
+
qt4_wrap_cpp(MOC ${MOC_HDRS})
include_directories(${CMAKE_SOURCE_DIR}/src/common
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "kcmdlinewrapper.h"
+
+#include <KCmdLineArgs>
+
+KCmdLineWrapper::KCmdLineWrapper() {
+
+}
+
+void KCmdLineWrapper::addArgument(const QString &longName, const CliParserArg &arg) {
+ if(arg.shortName != 0) {
+ _cmdLineOptions.add(QByteArray().append(arg.shortName));
+ }
+ _cmdLineOptions.add(longName.toUtf8(), ki18n(arg.help.toUtf8()), arg.def.toUtf8());
+}
+
+bool KCmdLineWrapper::init(const QStringList &) {
+ KCmdLineArgs::addCmdLineOptions(_cmdLineOptions);
+ return true;
+}
+
+QString KCmdLineWrapper::value(const QString &longName) {
+ return KCmdLineArgs::parsedArgs()->getOption(longName.toUtf8());
+}
+
+bool KCmdLineWrapper::isSet(const QString &longName) {
+ // KCmdLineArgs handles --nooption like NOT --option
+ if(longName.startsWith("no"))
+ return !KCmdLineArgs::parsedArgs()->isSet(longName.mid(2).toUtf8());
+ return KCmdLineArgs::parsedArgs()->isSet(longName.toUtf8());
+}
+
+void KCmdLineWrapper::usage() {
+ KCmdLineArgs::usage();
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef KCMDLINEWRAPPER_H
+#define KCMDLINEWRAPPER_H
+
+#include "abstractcliparser.h"
+
+#include <KCmdLineOptions>
+
+//! Wrapper for KCmdLineOptions
+class KCmdLineWrapper : public AbstractCliParser {
+public:
+ KCmdLineWrapper();
+
+ bool init(const QStringList &arguments = QStringList());
+
+ QString value(const QString &longName);
+ bool isSet(const QString &longName);
+ void usage();
+
+private:
+ void addArgument(const QString &longName, const CliParserArg &arg);
+
+ KCmdLineOptions _cmdLineOptions;
+};
+
+#endif