This makes the main classes use KDE if available. Since KApplication requires all
cli options to be defined before instantiation, we have to move CliParser init
into main(). CliParser fully abstracts KCmdLineArgs away, such that we won't need to
change anything for accessing options elsewhere.
#include "cliparser.h"
#include <QDir>
+#include <QDebug>
#include <QString>
#include <QFileInfo>
-#include <QDebug>
+#ifdef HAVE_KDE
+# include <KCmdLineArgs>
+#endif
+
+CliParser::CliParser() {
+
+}
+
+#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) {
if(argsHash.contains(longName)) qWarning() << "Warning: Multiple definition of argument" << longName;
if(arg.shortName != 0 && !lnameOfShortArg(arg.shortName).isNull())
return escapedValue;
}
-bool CliParser::parse(const QStringList &args) {
+bool CliParser::init(const QStringList &args) {
argsRaw = args;
QStringList::const_iterator currentArg;
for (currentArg = argsRaw.constBegin(); currentArg != argsRaw.constEnd(); ++currentArg) {
}
return QString();
}
+
+#endif
#include <QStringList>
#include <QHash>
-class CliParser{
+#ifdef HAVE_KDE
+# include <KCmdLineOptions>
+#endif
+
+class CliParser {
public:
- inline CliParser() {};
+ CliParser();
+
+ bool init(const QStringList &arguments = QStringList());
- bool parse(const QStringList &arguments);
QString value(const QString &longName);
bool isSet(const QString &longName);
inline void addSwitch(const QString &longName, const char shortName = 0, const QString &help = QString()) {
};
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
int main(int argc, char **argv) {
+ // Setup build information and version string
+ # include "version.gen"
+ buildinfo.append(QString(",%1,%2").arg(__DATE__, __TIME__));
+ Quassel::setupBuildInfo(buildinfo);
+ QCoreApplication::setApplicationName(Quassel::buildInfo().applicationName);
+ QCoreApplication::setOrganizationName(Quassel::buildInfo().organizationName);
+ QCoreApplication::setOrganizationDomain(Quassel::buildInfo().organizationDomain);
+
+#ifdef HAVE_KDE
+ // We need to init KCmdLineArgs first
+ // TODO: build an AboutData class to replace our aboutDlg strings
+ KAboutData aboutData(argv[0], 0, ki18n("Quassel IRC"), Quassel::buildInfo().plainVersionString.toUtf8());
+ aboutData.setOrganizationDomain(Quassel::buildInfo().organizationDomain.toUtf8());
+ KCmdLineArgs::init(argc, argv, &aboutData);
+#endif
+
+ // 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");
+ cliParser->addSwitch("help",'h', "Display this help and exit");
+
+#ifndef BUILD_CORE
+ // put client-only arguments here
+ cliParser->addSwitch("debugbufferswitches", 0, "Enables debugging for bufferswitches");
+ cliParser->addSwitch("debugmodel", 0, "Enables debugging for models");
+#endif
+#ifndef BUILD_QTCLIENT
+ // put core-only arguments here
+ cliParser->addOption("port <port>",'p', "The port quasselcore will listen at", QString("4242"));
+ cliParser->addSwitch("norestore", 'n', "Don't restore last core's state");
+ cliParser->addOption("logfile <path>", 'l', "Path to logfile");
+ cliParser->addOption("loglevel <level>", 'L', "Loglevel Debug|Info|Warning|Error", "Info");
+ cliParser->addOption("datadir <path>", 0, "Specify the directory holding datafiles like the Sqlite DB and the SSL Cert");
+#endif
+
+#ifdef HAVE_KDE
+ // the KDE version needs this extra call to parse argc/argv before app is instantiated
+ if(!cliParser->init()) {
+ cliParser->usage();
+ return EXIT_FAILURE;
+ }
+#endif
+
# if defined BUILD_CORE
CoreApplication app(argc, argv);
# elif defined BUILD_QTUI
MonolithicApplication app(argc, argv);
# endif
-# include "version.gen"
- buildinfo.append(QString(",%1,%2").arg(__DATE__, __TIME__));
- app.setupBuildInfo(buildinfo);
+#ifndef HAVE_KDE
+ // the non-KDE version parses after app has been instantiated
+ if(!cliParser->init(app.arguments())) {
+ cliParser->usage();
+ return false;
+ }
+#endif
if(!app.init()) return EXIT_FAILURE;
return app.exec();
# endif
#endif
- _cliParser = new CliParser();
-
- // put shared client&core arguments here
- cliParser()->addSwitch("debug",'d', tr("Enable debug output"));
- cliParser()->addSwitch("help",'h', tr("Display this help and exit"));
}
Quassel::~Quassel() {
Network::setDefaultCodecForEncoding("UTF-8");
Network::setDefaultCodecForDecoding("ISO-8859-15");
- if(!cliParser()->parse(QCoreApplication::arguments()) || isOptionSet("help")) {
+ if(isOptionSet("help")) {
cliParser()->usage();
return false;
}
+
DEBUG = isOptionSet("debug");
return true;
}
QString organizationDomain;
};
- void setupBuildInfo(const QString &generated);
-
virtual ~Quassel();
+ static void setupBuildInfo(const QString &generated);
static inline const BuildInfo & buildInfo();
static inline RunMode runMode();
Quassel::RunMode Quassel::runMode() { return _runMode; }
void Quassel::setRunMode(Quassel::RunMode mode) { _runMode = mode; }
-CliParser *Quassel::cliParser() { return _cliParser; }
+CliParser *Quassel::cliParser() { return _cliParser ? _cliParser : _cliParser = new CliParser(); }
QString Quassel::optionValue(const QString &key) { return cliParser()->value(key); }
bool Quassel::isOptionSet(const QString &key) { return cliParser()->isSet(key); }
: _coreCreated(false)
{
Q_INIT_RESOURCE(sql);
-
- // put core-only arguments here
- CliParser *parser = Quassel::cliParser();
- parser->addOption("port",'p', tr("The port quasselcore will listen at"), QString("4242"));
- parser->addSwitch("norestore", 'n', tr("Don't restore last core's state"));
- parser->addOption("logfile", 'l', tr("Path to logfile"));
- parser->addOption("loglevel", 'L', tr("Loglevel Debug|Info|Warning|Error"), "Info");
- parser->addOption("datadir", 0, tr("Specify the directory holding datafiles like the Sqlite DB and the SSL Cert"));
}
CoreApplicationInternal::~CoreApplicationInternal() {
Core::instance(); // create and init the core
_coreCreated = true;
- if(!Quassel::isOptionSet("norestore")) {
+ // if using KDE, option is called "restore" instead of "norestore"
+ if(Quassel::isOptionSet("restore") || !Quassel::isOptionSet("norestore"))
Core::restoreState();
- }
+
return true;
}
/*****************************************************************************/
CoreApplication::CoreApplication(int &argc, char **argv)
+#ifdef HAVE_KDE
+ : KApplication(false),
+#else
: QCoreApplication(argc, argv),
+#endif
Quassel()
{
setRunMode(Quassel::CoreOnly);
#ifndef COREAPPLICATION_H_
#define COREAPPLICATION_H_
-#include <QCoreApplication>
+#ifdef HAVE_KDE
+# include <KApplication>
+#else
+# include <QCoreApplication>
+#endif
#include "quassel.h"
~CoreApplicationInternal();
bool init();
-
+
private:
bool _coreCreated;
};
+#ifdef HAVE_KDE
+class CoreApplication : public KApplication, public Quassel {
+#else
class CoreApplication : public QCoreApplication, public Quassel {
+#endif
+
Q_OBJECT
public:
CoreApplication(int &argc, char **argv);
***************************************************************************/
#include "mainwin.h"
+#ifdef HAVE_KDE
+# include <KMenuBar>
+# include <KStatusBar>
+#endif
+
#include "aboutdlg.h"
#include "action.h"
#include "actioncollection.h"
#include "settingspages/notificationssettingspage.h"
MainWin::MainWin(QWidget *parent)
+#ifdef HAVE_KDE
+ : KMainWindow(parent),
+#else
: QMainWindow(parent),
+#endif
coreLagLabel(new QLabel()),
sslLabel(new QLabel()),
msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
QtUiSettings s;
s.setValue("MainWinSize", size());
s.setValue("MainWinPos", pos());
- s.setValue("MainWinState", saveState());
+ s.setValue("MainWinState", saveState()); qDebug() << "fini!";
}
void MainWin::updateIcon() {
#ifndef MAINWIN_H_
#define MAINWIN_H_
-#include <QMainWindow>
+#ifdef HAVE_KDE
+# include <KMainWindow>
+#else
+# include <QMainWindow>
+#endif
+
#include <QSystemTrayIcon>
#include "qtui.h"
class QLabel;
//!\brief The main window of Quassel's QtUi.
-class MainWin : public QMainWindow {
+class MainWin
+#ifdef HAVE_KDE
+: public KMainWindow {
+#else
+: public QMainWindow {
+#endif
Q_OBJECT
public:
// }
QtUiApplication::QtUiApplication(int &argc, char **argv)
+#ifdef HAVE_KDE
+ : KApplication(), Quassel()
+#else
: QApplication(argc, argv), Quassel()
+#endif
{
setRunMode(Quassel::ClientOnly);
- // put client-only arguments here
- CliParser *parser = Quassel::cliParser();
- parser->addSwitch("debugbufferswitches",0,"Enables debugging for bufferswitches");
- parser->addSwitch("debugmodel",0,"Enables debugging for models");
-
qInstallMsgHandler(Client::logMessage);
}
#ifndef QTUIAPPLICATION_H_
#define QTUIAPPLICATION_H_
-#include <QApplication>
+#ifdef HAVE_KDE
+# include <KApplication>
+#else
+# include <QApplication>
+#endif
+
#include <QSessionManager>
#include "quassel.h"
class QtUi;
+#ifdef HAVE_KDE
+class QtUiApplication : public KApplication, public Quassel {
+#else
class QtUiApplication : public QApplication, public Quassel {
+#endif
+
Q_OBJECT
public: