Building separate components does not work yet, but the monolithic build should be
able to go online again. Note that there are more significant changes in the framework
to expect.
# Define files
SET(quassel_mono_SRCS main/main_mono.cpp)
SET(quassel_core_SRCS main/main_core.cpp)
+#SET(quassel_gui_SRCS main/main_gui.cpp ${common_SRCS})
SET(quassel_RCCS images/icons.qrc)
-SET(quassel_DIRS gui core network)
+SET(quassel_DIRS main gui core network)
# Build correct absolute paths for subdirs to include
SET(SDIRS "")
SET(QT_DONT_USE_QTGUI true) # This is added later if GUI is requested
INCLUDE(${QT_USE_FILE})
-ADD_SUBDIRECTORY(network)
-ADD_SUBDIRECTORY(core)
+ADD_SUBDIRECTORY(main)
QT4_ADD_RESOURCES(_RCCS ${quassel_RCCS})
IF(BUILD_CORE)
+ ADD_DEFINITIONS(-DBUILD_CORE)
+ ADD_SUBDIRECTORY(network)
+ ADD_SUBDIRECTORY(core)
ADD_EXECUTABLE(quasselcore ${quassel_core_SRCS} ${_RCCS})
- TARGET_LINK_LIBRARIES(quasselcore core network ${QT_LIBRARIES})
+ TARGET_LINK_LIBRARIES(quasselcore core network main ${QT_LIBRARIES})
ENDIF(BUILD_CORE)
IF(BUILD_GUI OR BUILD_MONO) # OK, now we need QtGui!
INCLUDE(${QT_USE_FILE})
IF(BUILD_MONO)
+ ADD_DEFINITIONS(-DBUILD_MONO)
ADD_SUBDIRECTORY(gui)
+ ADD_SUBDIRECTORY(network)
+ ADD_SUBDIRECTORY(core)
ADD_EXECUTABLE(quassel ${quassel_mono_SRCS} ${_RCCS})
- TARGET_LINK_LIBRARIES(quassel gui core network ${QT_LIBRARIES})
+ TARGET_LINK_LIBRARIES(quassel gui core network main ${QT_LIBRARIES})
ENDIF(BUILD_MONO)
IF(BUILD_GUI)
+ ADD_DEFINITIONS(-DBUILD_GUI)
ADD_SUBDIRECTORY(gui)
- MESSAGE(FATAL_ERROR "Client mode not yet supported.")
+ ADD_EXECUTABLE(quasselgui ${quassel_gui_SRCS} ${_RCCS})
+ TARGET_LINK_LIBRARIES(quasselgui gui main ${QT_LIBRARIES})
ENDIF(BUILD_GUI)
ENDIF(BUILD_GUI OR BUILD_MONO)
-SET(core_SRCS logger.cpp quassel.cpp core.cpp)
+SET(core_SRCS core.cpp)
SET(core_HDRS )
-SET(core_MOCS logger.h core.h quassel.h)
+SET(core_MOCS core.h)
QT4_WRAP_CPP(_MOC ${core_MOCS})
ADD_LIBRARY(core ${_MOC} ${core_SRCS} ${core_HDRS})
#include "core.h"
#include "server.h"
+#include "quassel.h"
#include <QSettings>
-void Core::init() {
- Server::init();
-
+Core * Core::init() {
+ if(core) return core;
+ QSettings s;
+ VarMap identities = s.value("Network/Identities").toMap();
+ qDebug() << identities;
+ //VarMap networks = s.value("Network/
+ quassel->putData("Identities", identities);
+ return new Core();
}
void Core::run() {
QSettings s;
s.setValue("Network/Identities", identities);
}
+
+Core *core;
#include "server.h"
-typedef QMap<QString, QVariant> VarMap;
-
class Core : public QThread {
Q_OBJECT
public:
- static void init();
+ static Core * init();
static VarMap loadNetworks();
static void storeNetworks(VarMap);
static VarMap loadIdentities();
};
+extern Core *core;
+
#endif
-SET(gui_SRCS channelwidget.cpp mainwin.cpp serverlist.cpp)
+SET(gui_SRCS channelwidget.cpp mainwin.cpp serverlist.cpp guiproxy.cpp)
SET(gui_HDRS )
-SET(gui_MOCS channelwidget.h mainwin.h serverlist.h)
+SET(gui_MOCS channelwidget.h mainwin.h serverlist.h guiproxy.h)
SET(gui_UICS channelwidget.ui identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui nickeditdlg.ui serverlistdlg.ui)
QT4_WRAP_UI(_UIC ${gui_UICS})
QT4_WRAP_CPP(_MOC ${gui_MOCS})
-# We need to workaround a dependency bug with out-of-source builds...
+# We need to work around a dependency bug with out-of-source builds...
SET_SOURCE_FILES_PROPERTIES(${gui_SRCS} PROPERTIES OBJECT_DEPENDS "${_UIC}")
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
***************************************************************************/
#include "channelwidget.h"
+#include "guiproxy.h"
#include <QtGui>
#include <iostream>
*/
//connect(&core, SIGNAL(outputLine( const QString& )), ui.textBrowser, SLOT(insertPlainText(const QString &)));
//connect(ui.lineEdit, SIGNAL(
- connect(&core, SIGNAL(outputLine( const QString& )), ui.textBrowser, SLOT(insertPlainText(const QString &)));
+ connect(&core, SIGNAL(outputLine( const QString& )), this, SLOT(lineReceived(const QString &)));
connect(ui.lineEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed()));
connect(this, SIGNAL(inputLine( const QString& )), &core, SLOT(inputLine( const QString& )));
+
+ connect(this, SIGNAL(inputLine(QString)), guiProxy, SLOT(gsUserInput(QString)));
+
core.start();
- core.connectToIrc("irc.quakenet.org", 6668);
+ core.connectToIrc("irc.moep.net", 6668);
}
void ChannelWidget::enterPressed() {
emit inputLine(ui.lineEdit->text());
ui.lineEdit->clear();
}
+
+void ChannelWidget::lineReceived(QString s) {
+ ui.textBrowser->insertPlainText(s + "\n");
+ ui.textBrowser->ensureCursorVisible();
+}
private slots:
void enterPressed();
+ void lineReceived(QString);
private:
Ui::ChannelWidget ui;
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005/06 by The Quassel 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) any later version. *
+ * *
+ * 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 "guiproxy.h"
+
+GUIProxy * GUIProxy::init() {
+ if(guiProxy) return guiProxy;
+ return new GUIProxy;
+}
+
+void GUIProxy::gsUserInput(QString s) {
+ send(GS_USER_INPUT, s);
+}
+
+GUIProxy *guiProxy;
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005/06 by The Quassel 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) any later version. *
+ * *
+ * 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 _GUIPROXY_H_
+#define _GUIPROXY_H_
+
+#include "../main/proxy_common.h"
+
+#include <QObject>
+#include <QVariant>
+
+/** This class is the GUI side of the proxy. The GUI connects its signals and slots to it,
+ * and the calls are marshalled and sent to (or received and unmarshalled from) the CoreProxy.
+ * The connection function is defined in main/main_gui.cpp or main/main_mono.cpp.
+ */
+class GUIProxy : public QObject {
+ Q_OBJECT
+
+ private:
+ void send(GUISignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
+ void recv(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
+
+ public:
+ static GUIProxy * init();
+
+ public slots:
+ void gsUserInput(QString);
+
+
+ signals:
+ void psCoreMessage(QString);
+
+
+};
+
+extern GUIProxy *guiProxy;
+
+
+
+#endif
setWindowTitle("Quassel IRC");
setWindowIcon(QIcon(":/default/tux.png"));
setWindowIconText("Quassel IRC");
- workspace = new QWorkspace(this);
- setCentralWidget(workspace);
+ //workspace = new QWorkspace(this);
+ //setCentralWidget(workspace);
ChannelWidget *cw = new ChannelWidget(this);
- workspace->addWindow(cw);
- //setCentralWidget(cw);
+ //workspace->addWindow(cw);
+ setCentralWidget(cw);
serverListDlg = new ServerListDlg(this);
serverListDlg->setVisible(serverListDlg->showOnStartup());
//showServerList();
//QSettings s;
//s.beginGroup("Identities");
//identities = s.value("Network/Identities").toMap();
- identities = GuiProxy::loadIdentities();
+ //identities = GuiProxy::loadIdentities();
+ identities = quassel->getData("Identities").toMap();
while(!identities.contains("Default")) {
identities = VarMap();
editIdentities();
void ServerListDlg::storeIdentities() {
//QSettings s;
//s.setValue("Network/Identities", identities);
- GuiProxy::storeIdentities(identities);
+ //GuiProxy::storeIdentities(identities);
+ quassel->putData("Identities", identities);
}
void ServerListDlg::editIdentities() {
--- /dev/null
+SET(main_SRCS quassel.cpp logger.cpp)
+SET(main_HDRS )
+SET(main_MOCS quassel.h logger.h)
+
+QT4_WRAP_CPP(_MOC ${main_MOCS})
+ADD_LIBRARY(main ${_MOC} ${main_SRCS} ${main_HDRS})
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005 by The Quassel 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) any later version. *
+ * *
+ * 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 "quassel.h"
+#include "logger.h"
+
+#include <iostream>
+
+
+
+Logger::~Logger() {
+ //qInstallMsgHandler(0);
+}
+
+void messageHandler(QtMsgType type, const char *msg) {
+ switch (type) {
+ case QtDebugMsg:
+ std::cerr << "[DEBUG] " << msg << "\n";
+ break;
+ case QtWarningMsg:
+ std::cerr << "[WARNING] " << msg << "\n";
+ break;
+ case QtCriticalMsg:
+ std::cerr << "[CRITICAL] " << msg << "\n";
+ break;
+ case QtFatalMsg:
+ std::cerr << "[FATAL] " << msg << "\n";
+ abort(); // deliberately core dump
+ }
+}
+
+Logger::Logger() {
+ //qInstallMsgHandler(messageHandler);
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005 by The Quassel 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) any later version. *
+ * *
+ * 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 _LOGGER_H_
+#define _LOGGER_H_
+
+#include <QtCore>
+
+class Logger : public QObject {
+ Q_OBJECT
+
+ public:
+ Logger();
+ virtual ~Logger();
+
+
+
+ private:
+ //void messageHandler(QtMsgType type, const char *msg);
+};
+
+
+
+#endif
#include <QCoreApplication>
#include "quassel.h"
-#include "logger.h"
-#include "proxy.h"
+#include "core.h"
int main(int argc, char **argv) {
-
- Quassel::init();
- Logger *logger = new Logger();
- Quassel::setLogger(logger);
-
QCoreApplication app(argc, argv);
-
QCoreApplication::setOrganizationDomain("quassel-irc.org");
QCoreApplication::setApplicationName("Quassel IRC");
QCoreApplication::setOrganizationName("The Quassel Team");
- return app.exec();
+ Quassel::runMode = Quassel::CoreOnly;
+ quassel = Quassel::init();
+ core = Core::init();
+ //coreProxy = CoreProxy::init();
+
+ //Logger *logger = new Logger();
+ //Quassel::setLogger(logger);
+
+ int exitCode = app.exec();
+ delete quassel;
+ return exitCode;
}
-QVariant proxyConnect(uint func, QVariant arg) {
+Core *core = 0;
+
+//GUIProxy::send(uint func, QVariant arg) {
+ /*
switch(func) {
case LOAD_IDENTITIES: return (QVariant) CoreProxy::loadIdentities();
case STORE_IDENTITIES: CoreProxy::storeIdentities(arg.toMap()); return 0;
}
- return 0;
-}
+ */
+
+//}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005 by The Quassel 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) any later version. *
+ * *
+ * 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 <iostream>
+
+#include <QApplication>
+
+#include "quassel.h"
+#include "guiproxy.h"
+
+#include "mainwin.h"
+
+int main(int argc, char **argv) {
+ QApplication app(argc, argv);
+ QApplication::setOrganizationDomain("quassel-irc.org");
+ QApplication::setApplicationName("Quassel IRC");
+ QApplication::setOrganizationName("The Quassel Team");
+
+ Quassel::runMode = Quassel::GUIOnly;
+ quassel = Quassel::init();
+ guiProxy = GUIProxy::init();
+
+ MainWin mainWin;
+ mainWin.show();
+ int exitCode = app.exec();
+ delete guiProxy;
+ delete quassel;
+}
+
+void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+
+
+
+}
+
+void GUIProxy::recv(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+
+
+
+}
#include "core.h"
#include "quassel.h"
-#include "logger.h"
-#include "proxy.h"
+#include "guiproxy.h"
#include "mainwin.h"
int main(int argc, char **argv) {
-
- Quassel::init();
- Logger *logger = new Logger();
- Quassel::setLogger(logger);
-
QApplication app(argc, argv);
-
QApplication::setOrganizationDomain("quassel-irc.org");
QApplication::setApplicationName("Quassel IRC");
QApplication::setOrganizationName("The Quassel Team");
- Core::init();
+ Quassel::runMode = Quassel::Monolithic;
+ quassel = Quassel::init();
+ core = Core::init();
+ guiProxy = GUIProxy::init();
+ // coreProxy = CoreProxy::init();
MainWin mainWin;
mainWin.show();
- return app.exec();
+ int exitCode = app.exec();
+ delete guiProxy;
+ delete quassel;
}
-QVariant proxyConnect(uint func, QVariant arg) {
- using namespace Proxy;
+void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+
+
+
+}
+
+void GUIProxy::recv(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+
- switch(func) {
- case LOAD_IDENTITIES: return (QVariant) CoreProxy::loadIdentities();
- case STORE_IDENTITIES: CoreProxy::storeIdentities(arg.toMap()); return 0;
- }
- return 0;
}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005/06 by The Quassel 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) any later version. *
+ * *
+ * 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 _PROXY_COMMON_H_
+#define _PROXY_COMMON_H_
+
+enum GUISignal { GS_USER_INPUT
+
+};
+
+enum CoreSignal { GS_CORE_MESSAGE
+
+};
+
+
+#endif
#include "quassel.h"
#include "logger.h"
-#include "proxy.h"
+//#include "proxy.h"
+#include "core.h"
#include <QString>
#include <QDomDocument>
-void Quassel::init() {
- Core::init();
+extern void messageHandler(QtMsgType type, const char *msg);
+Quassel * Quassel::init() {
+ if(quassel) return quassel;
+ qInstallMsgHandler(messageHandler);
+ quassel = new Quassel();
//initIconMap();
+ return quassel;
}
+/*
void Quassel::setLogger(Logger *) {
};
+*/
+
+QVariant Quassel::getData(QString key) {
+ mutex.lock();
+ QVariant d = data[key];
+ mutex.unlock();
+ qDebug() << "getData("<<key<<"): " << d;
+ return d;
+}
+void Quassel::putData(QString key, const QVariant &d) {
+ mutex.lock();
+ data[key] = d;
+ mutex.unlock();
+ emit dataChanged(key, d);
+ qDebug() << "putData("<<key<<"): " << d;
+ qDebug() << "data: " << data;
+}
/* not done yet */
void Quassel::initIconMap() {
// return 0;
//}
+
+Quassel *quassel = 0;
+Quassel::RunMode Quassel::runMode;
+QMutex Quassel::mutex;
+QHash<QString, QVariant> Quassel::data;
#ifndef _QUASSEL_H_
#define _QUASSEL_H_
-class Logger;
+class Quassel;
-#include <QHash>
-#include <QString>
+#include <QtCore>
+//#include <QMutex>
+/* Some global stuff */
+typedef QMap<QString, QVariant> VarMap;
+extern Quassel *quassel;
/**
* A static class containing global data.
* This is used in both core and GUI modules. Where appropriate, accessors are thread-safe
* to account for that fact.
*/
-class Quassel {
+class Quassel : public QObject {
Q_OBJECT
public:
- static void init();
- static Logger *getLogger();
- static void setLogger(Logger *);
+ static Quassel * init();
+ //static Logger *getLogger();
+ //static void setLogger(Logger *);
// static QIcon *getIcon(QString symbol);
+ QVariant getData(QString key);
+
+ public slots:
+ void putData(QString key, const QVariant &data);
+
+ signals:
+ void dataChanged(QString key, const QVariant &data);
+
+ public:
+ enum RunMode { Monolithic, GUIOnly, CoreOnly };
+ static RunMode runMode;
+
private:
static void initIconMap();
- static Logger *logger;
+ //static Logger *logger;
// static QString iconPath;
static QHash<QString, QString> iconMap;
-
+ static QMutex mutex;
+ static QHash<QString, QVariant> data;
};
class Exception {
-SET(network_SRCS message.cpp builtin_cmds.cpp builtin_handlers.cpp server.cpp)
-SET(network_HDRS message.h cmdcodes.h)
+SET(network_SRCS server.cpp)
+SET(network_HDRS )
SET(network_MOCS server.h)
QT4_WRAP_CPP(_MOC ${network_MOCS})
***************************************************************************/
#include <QtGlobal>
-#include "message.h"
+//#include "message.h"
#include "cmdcodes.h"
/** This macro marks strings as translateable for Qt's linguist tools */
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+/* OBSOLETE CODE! */
+
#include "message.h"
#include <QtDebug>
#include "server.h"
#include "cmdcodes.h"
+#include <QMetaObject>
+
Server::Server() {
- socket = new QTcpSocket();
}
Server::~Server() {
- delete socket;
+
}
void Server::init() {
- Message::init(&dispatchServerMsg, &dispatchUserMsg);
+ //Message::init(&dispatchServerMsg, &dispatchUserMsg);
}
void Server::run() {
- connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
- connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
- connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
- connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
- connect(socket, SIGNAL(readyRead()), this, SLOT(socketHasData()));
-
- stream.setDevice(socket);
- //connectToIrc("irc.quakenet.org", 6667);
- exec();
-}
+ connect(&socket, SIGNAL(connected()), this, SLOT(socketConnected()));
+ connect(&socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
+ connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
+ connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
+ connect(&socket, SIGNAL(readyRead()), this, SLOT(socketHasData()));
-/*
-QAbstractSocket::SocketState TcpConnection::state( ) const {
- return socket.state();
+ exec();
}
-*/
void Server::connectToIrc( const QString & host, quint16 port ) {
qDebug() << "Connecting...";
- socket->connectToHost(host, port);
+ socket.connectToHost(host, port);
}
void Server::disconnectFromIrc( ) {
- socket->disconnectFromHost();
-}
-
-void Server::putRawLine( const QString &s ) {
- qDebug() << "Sent: " << s;
- stream << s << "\r\n" << flush;
- //Message::createFromServerString(this, s);
+ socket.disconnectFromHost();
}
-void Server::socketHasData( ) {
- while(socket->canReadLine()) {
- QString s = stream.readLine();
+void Server::socketHasData() {
+ while(socket.canReadLine()) {
+ QString s = socket.readLine().trimmed();
qDebug() << "Read: " << s;
emit recvRawServerMsg(s);
- Message *msg = Message::createFromServerString(this, s);
- if(msg) {
- try { handleServerMsg(msg); } catch(Exception e) {
- emit recvLine(e.msg() + "\n");
- }
- }
- delete msg;
+ //Message *msg = Message::createFromServerString(this, s);
+ handleServerMsg(s);
}
}
void Server::socketConnected( ) {
qDebug() << "Socket connected!";
- //emit connected();
+ putRawLine("NICK :Sput|QuasselDev");
+ putRawLine("USER Sputnick 8 * :Using Quassel IRC (WiP Version)");
}
void Server::socketDisconnected( ) {
qDebug() << "Socket state changed: " << state;
}
-/** Handle a message sent by the IRC server that does not have a custom handler. */
+void Server::putRawLine(QString s) {
+ qDebug() << "SentRaw: " << s;
+ s += "\r\n";
+ socket.write(s.toAscii());
+}
+
+void Server::putCmd(QString cmd, QStringList params, QString prefix) {
+ QString m;
+ if(!prefix.isEmpty()) m += ":" + prefix + " ";
+ m += cmd.toUpper();
+ for(int i = 0; i < params.size() - 1; i++) {
+ m += " " + params[i];
+ }
+ if(!params.isEmpty()) m += " :" + params.last();
+ qDebug() << "SentCmd: " << m;
+ m += "\r\n";
+ socket.write(m.toAscii());
+}
+
+/** Handle a raw message string sent by the server. We try to find a suitable handler, otherwise we call a default handler. */
+void Server::handleServerMsg(QString msg) {
+ try {
+ if(msg.isEmpty()) {
+ qWarning() << "Received empty string from server!";
+ return;
+ }
+ // OK, first we split the raw message into its various parts...
+ QString prefix;
+ QString cmd;
+ QStringList params;
+ if(msg[0] == ':') {
+ msg.remove(0,1);
+ prefix = msg.section(' ', 0, 0);
+ msg = msg.section(' ', 1);
+ }
+ cmd = msg.section(' ', 0, 0).toUpper();
+ msg = msg.section(' ', 1);
+ QString left = msg.section(':', 0, 0);
+ QString trailing = msg.section(':', 1);
+ if(!left.isEmpty()) {
+ params << left.split(' ', QString::SkipEmptyParts);
+ }
+ if(!trailing.isEmpty()) {
+ params << trailing;
+ }
+ // Now we try to find a handler for this message. BTW, I do love the Trolltech guys ;-)
+ QString hname = cmd.toLower();
+ hname[0] = hname[0].toUpper();
+ hname = "handle" + hname + "FromServer";
+ if(!QMetaObject::invokeMethod(this, hname.toAscii(), Q_ARG(QString, prefix), Q_ARG(QStringList, params))) {
+ // Ok. Default handler it is.
+ defaultHandlerForServer(cmd, prefix, params);
+ }
+ } catch(Exception e) {
+ emit recvLine(e.msg());
+ }
+}
+
+void Server::defaultHandlerForServer(QString cmd, QString prefix, QStringList params) {
+ uint num = cmd.toUInt();
+ if(num) {
+ recvLine(cmd + " " + params.join(" "));
+ } else {
+ recvLine(QString("Unknown: ") + cmd + " " + params.join(" "));
+ }
+}
+
+void Server::handleUserMsg(QString usrMsg) {
+
+}
+
+/*
void Server::handleServerMsg(Message *msg) {
int cmdCode = msg->getCmdCode();
QString prefix = msg->getPrefix();
switch(-cmdCode) {
case CMD_PING:
// PING <server1> [<server2>]
- if(params.size() == 1) {
- putRawLine(QString("PONG :") + params[0]);
- } else if(params.size() == 2) {
- putRawLine(QString("PONG ") + params[0] + " :" + params[1]);
- } else throw ParseError(msg);
+ if(params.size() < 1 || params.size() > 2) throw ParseError(msg);
+ putCmd("PONG", params);
break;
default:
throw UnknownCmdError(msg);
}
}
+*/
+
+void Server::handleNoticeFromServer(QString prefix, QStringList params) {
+ recvLine(params.join(" "));
-QString Server::handleUserMsg(Message *msg) {
- return "";
+}
+
+void Server::handlePingFromServer(QString prefix, QStringList params) {
+ putCmd("PONG", params);
}
/* Exception classes for message handling */
-Server::ParseError::ParseError(Message *msg) {
- _msg = QString("Command Parse Error: ") + msg->getCmd() + msg->getParams().join(" ");
+Server::ParseError::ParseError(QString cmd, QString prefix, QStringList params) {
+ _msg = QString("Command Parse Error: ") + cmd + params.join(" ");
}
-Server::UnknownCmdError::UnknownCmdError(Message *msg) {
- _msg = QString("Unknown Command: ") + msg->getCmd();
+Server::UnknownCmdError::UnknownCmdError(QString cmd, QString prefix, QStringList params) {
+ _msg = QString("Unknown Command: ") + cmd;
}
#define _SERVER_H_
#include <QtCore>
+#include <QTimer>
#include <QtNetwork>
#include "quassel.h"
-#include "message.h"
#define DEFAULT_PORT 6667
+
/**
* This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
* We have this run in its own thread mainly to not block other server objects or the core if something goes wrong,
void connectToIrc(const QString &host, quint16 port = DEFAULT_PORT);
void disconnectFromIrc();
- void putRawLine(const QString &input /*, Buffer *source = 0 */);
+ void putRawLine(QString input);
+ void putCmd(QString cmd, QStringList params, QString prefix = 0);
signals:
//void outputLine(const QString & /*, Buffer *target = 0 */);
void socketDisconnected();
void socketStateChanged(QAbstractSocket::SocketState);
+ /* Message Handlers */
+ /* handleXxxxFromServer(QString prefix, QStringList params); */
+ void handleNoticeFromServer(QString, QStringList);
+ void handlePingFromServer(QString, QStringList);
+
+ void defaultHandlerForServer(QString cmd, QString prefix, QStringList params);
+
private:
- QTcpSocket *socket;
+ QTcpSocket socket;
QTextStream stream;
- void handleServerMsg(Message *);
- QString handleUserMsg(Message *);
- static inline void dispatchServerMsg(Message *msg) { msg->getServer()->handleServerMsg(msg); }
- static inline void dispatchUserMsg(Message *msg) { msg->getServer()->handleUserMsg(msg); }
+ void handleServerMsg(QString rawMsg);
+ void handleUserMsg(QString usrMsg);
+ //static inline void dispatchServerMsg(Message *msg) { msg->getServer()->handleServerMsg(msg); }
+ //static inline void dispatchUserMsg(Message *msg) { msg->getServer()->handleUserMsg(msg); }
class ParseError : public Exception {
public:
- ParseError(Message *msg);
+ ParseError(QString cmd, QString prefix, QStringList params);
};
class UnknownCmdError : public Exception {
public:
- UnknownCmdError(Message *msg);
+ UnknownCmdError(QString cmd, QString prefix, QStringList params);
};
};
class Buffer {};
-/*
-class TcpConnection : public QThread {
- Q_OBJECT
-
-
- public:
- void run();
- QAbstractSocket::SocketState state() const;
-
- public slots:
- void connectToHost(const QString &host, quint16 port = DEFAULT_PORT);
- void disconnectFromHost();
- void sendLine(const QString &);
-
- signals:
- void recvLine(QString);
- void error(QAbstractSocket::SocketError);
- void connected();
- void disconnected();
- void stateChanged(QAbstractSocket::SocketState);
-
- private:
- QTcpSocket socket;
- QTextStream stream;
-};
-*/
#endif