From: Manuel Nickschas Date: Sun, 15 Oct 2006 22:27:15 +0000 (+0000) Subject: First sorta working network code added. We can connect to a server now and send/recv X-Git-Tag: 0.1.0~286 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=8b192b08f3df4ce0e7cc4a08564645c76efa688d;hp=ffd440f541000c365ce74bce4cef14e617283b51 First sorta working network code added. We can connect to a server now and send/recv raw messages! Most of the surrounding framework code is just badly hacked though to make fiddling with the server possible at least. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f04e5667..959790e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ FIND_PACKAGE(Qt4 REQUIRED) # Set needed libraries SET(QT_USE_QTXML true) +SET(QT_USE_QTNETWORK true) SET(QT_DONT_USE_QTGUI true) # This is added later if GUI is requested INCLUDE(${QT_USE_FILE}) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 4c00fa9f..fe1af92e 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,6 +1,6 @@ SET(core_SRCS logger.cpp quassel.cpp proxy.cpp core.cpp) -SET(core_HDRS quassel.h proxy.h core.h) -SET(core_MOCS logger.h) +SET(core_HDRS quassel.h proxy.h) +SET(core_MOCS logger.h core.h) QT4_WRAP_CPP(_MOC ${core_MOCS}) ADD_LIBRARY(core ${_MOC} ${core_SRCS} ${core_HDRS}) diff --git a/core/core.cpp b/core/core.cpp index 4d144023..10c9d3d6 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -19,12 +19,33 @@ ***************************************************************************/ #include "core.h" +#include "server.h" #include void Core::init() { +} + +void Core::run() { + + connect(this, SIGNAL(connectToIrc( const QString&, quint16 )), &server, SLOT(connectToIrc( const QString&, quint16 ))); + connect(&server, SIGNAL(recvLine(const QString &)), this, SIGNAL(outputLine(const QString &))); + //connect( + server.start(); + qDebug() << "Core running..."; + + exec(); +} + +void Core::connectToIrc( const QString &h, quint16 port) { + server.connectToIrc(h, port); +} + +void Core::inputLine(const QString &s) { + server.putRawLine( s); + } VarMap Core::loadIdentities() { diff --git a/core/core.h b/core/core.h index 4220056d..7cfecece 100644 --- a/core/core.h +++ b/core/core.h @@ -25,17 +25,33 @@ #include #include +#include "server.h" + typedef QMap VarMap; -class Core { +class Core : public QThread { + Q_OBJECT public: + static void init(); static VarMap loadNetworks(); static void storeNetworks(VarMap); static VarMap loadIdentities(); static void storeIdentities(VarMap); + public slots: + void inputLine(const QString &); // temp + void connectToIrc(const QString &, quint16 port = 6667); + + signals: + void outputLine(const QString &); // temp + + private: + void run(); + + Server server; // temp + }; #endif diff --git a/gui/channelwidget.cpp b/gui/channelwidget.cpp index d9851cd2..bde11c72 100644 --- a/gui/channelwidget.cpp +++ b/gui/channelwidget.cpp @@ -25,9 +25,9 @@ ChannelWidget::ChannelWidget(QWidget *parent) : QWidget(parent) { ui.setupUi(this); - ui.lineEdit->setText("foobar"); + //ui.lineEdit->setText("foobar"); - //ui.splitter-> +/* //ui.splitter-> ui.textBrowser->setHtml("[17:21] --> Dante has joined #quassel (~hurz@p1af2242.dip.t-dialin.net)
" "[17:21] --> Sput has joined #quassel (~Sput42@vincent.mindpool.net)
" "[17:23] <Dante> Das sieht ja soweit schonmal Klasse aus!
" @@ -37,4 +37,19 @@ ChannelWidget::ChannelWidget(QWidget *parent) : QWidget(parent) { ); ui.listWidget->addItem("@Dante"); ui.listWidget->addItem("@Sput"); + */ + //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(ui.lineEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed())); + connect(this, SIGNAL(inputLine( const QString& )), &core, SLOT(inputLine( const QString& ))); + core.start(); + core.connectToIrc("irc.quakenet.org"); } + +void ChannelWidget::enterPressed() { + emit inputLine(ui.lineEdit->text()); + ui.lineEdit->clear(); +} + + \ No newline at end of file diff --git a/gui/channelwidget.h b/gui/channelwidget.h index 3d36cf85..a9f768f6 100644 --- a/gui/channelwidget.h +++ b/gui/channelwidget.h @@ -23,14 +23,25 @@ #include "ui_channelwidget.h" +#include "core.h" + class ChannelWidget : public QWidget { Q_OBJECT public: ChannelWidget(QWidget *parent = 0); + signals: + void inputLine(const QString &); + + private slots: + void enterPressed(); + private: Ui::ChannelWidget ui; + + Core core; + Server server; }; diff --git a/gui/mainwin.cpp b/gui/mainwin.cpp index 4dd5d280..92316907 100644 --- a/gui/mainwin.cpp +++ b/gui/mainwin.cpp @@ -24,6 +24,9 @@ #include "channelwidget.h" #include "serverlist.h" +#include "core.h" +#include "server.h" + MainWin::MainWin() : QMainWindow() { setWindowTitle("Quassel IRC"); diff --git a/main/main_mono.cpp b/main/main_mono.cpp index 08398add..f3f4ab98 100644 --- a/main/main_mono.cpp +++ b/main/main_mono.cpp @@ -29,6 +29,7 @@ #include "mainwin.h" #include "messages.h" +#include "server.h" int main(int argc, char **argv) { @@ -39,8 +40,7 @@ int main(int argc, char **argv) { //Message *m = new Message("admin"); //m->*(m->getCmdHandler())(QStringList("")); //(m->*(m->getCmdHandler()))(QStringList()); - //exit(0); - + QApplication app(argc, argv); QApplication::setOrganizationDomain("quassel-irc.org"); diff --git a/network/CMakeLists.txt b/network/CMakeLists.txt index d8f9219f..e83a0ecc 100644 --- a/network/CMakeLists.txt +++ b/network/CMakeLists.txt @@ -1,6 +1,6 @@ SET(network_SRCS messages.cpp builtin_cmds.cpp builtin_handlers.cpp server.cpp) -SET(network_HDRS messages.h server.h) -SET(network_MOCS ) +SET(network_HDRS messages.h) +SET(network_MOCS server.h) QT4_WRAP_CPP(_MOC ${network_MOCS}) ADD_LIBRARY(network ${_MOC} ${network_SRCS} ${network_HDRS}) diff --git a/network/messages.h b/network/messages.h index 566e0d41..0ac7cfff 100644 --- a/network/messages.h +++ b/network/messages.h @@ -52,7 +52,7 @@ class Message { QString cmd; QStringList params; - Message(QString cmd, QStringList args = 0); + Message(QString cmd, QStringList args = QStringList()); virtual ~Message() {}; diff --git a/network/server.cpp b/network/server.cpp index e204ef82..d493e67c 100644 --- a/network/server.cpp +++ b/network/server.cpp @@ -17,3 +17,75 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ + +#include "server.h" + +Server::Server() { + socket = new QTcpSocket(); + +} + +Server::~Server() { + delete socket; +} + +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(); +} + +/* +QAbstractSocket::SocketState TcpConnection::state( ) const { + return socket.state(); +} +*/ + +void Server::connectToIrc( const QString & host, quint16 port ) { + qDebug() << "Connecting..."; + socket->connectToHost(host, port); +} + +void Server::disconnectFromIrc( ) { + socket->disconnectFromHost(); +} + +void Server::putRawLine( const QString &s ) { + qDebug() << "Raw line: " << s; + stream << s << "\r\n" << flush; +} + +void Server::socketHasData( ) { + while(socket->canReadLine()) { + QString s = stream.readLine(); + qDebug() << "Read: " << s; + emit recvLine(s + "\n"); + } +} + +void Server::socketError( QAbstractSocket::SocketError err ) { + qDebug() << "Socket Error!"; + //emit error(err); +} + +void Server::socketConnected( ) { + qDebug() << "Socket connected!"; + //emit connected(); +} + +void Server::socketDisconnected( ) { + qDebug() << "Socket disconnected!"; + //emit disconnected(); +} + +void Server::socketStateChanged(QAbstractSocket::SocketState state) { + qDebug() << "Socket state changed: " << state; +} + + diff --git a/network/server.h b/network/server.h index cc46899a..ce79fc88 100644 --- a/network/server.h +++ b/network/server.h @@ -24,20 +24,75 @@ #include #include -class Server { +#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, + * e.g. if some scripts starts running wild... + */ + +class Server : public QThread { Q_OBJECT + public: + Server(); + ~Server(); + + void run(); + + // serverState state(); + + public slots: + // void setServerOptions(); + void connectToIrc(const QString &host, quint16 port = DEFAULT_PORT); + void disconnectFromIrc(); + + void putRawLine(const QString &input /*, Buffer *source = 0 */); + + signals: + //void outputLine(const QString & /*, Buffer *target = 0 */); + void recvLine(const QString&); + + private slots: + void socketHasData(); + void socketError(QAbstractSocket::SocketError); + void socketConnected(); + void socketDisconnected(); + void socketStateChanged(QAbstractSocket::SocketState); private: + QTcpSocket *socket; + QTextStream stream; }; -class Connection : public QThread { +/* +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