X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=core%2Fcore.cpp;h=6270527f6930ab6ea6c8791ac133dd0ffbf448e9;hp=f5c06fd62eceab7e82a950b7a6bd52c15e2bacd0;hb=1c7d9f13b744cd517c0769f453fd8dc3106cd94c;hpb=84516825d33a1b448a894eaf2e804cabb032f5f1 diff --git a/core/core.cpp b/core/core.cpp index f5c06fd6..6270527f 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -20,37 +20,73 @@ #include "core.h" #include "server.h" +#include "global.h" +#include "coreproxy.h" #include -void Core::init() { - Server::init(); +Core::Core() { + if(core) qFatal("Trying to instantiate more than one Core object!"); -} + connect(coreProxy, SIGNAL(gsRequestConnect(QStringList)), this, SLOT(connectToIrc(QStringList))); + connect(coreProxy, SIGNAL(gsUserInput(QString, QString, QString)), this, SIGNAL(msgFromGUI(QString, QString, QString))); + connect(this, SIGNAL(sendMessage(QString, QString, Message)), coreProxy, SLOT(csSendMessage(QString, QString, Message))); + connect(this, SIGNAL(sendStatusMsg(QString, QString)), coreProxy, SLOT(csSendStatusMsg(QString, QString))); -void Core::run() { + // Read global settings from config file + QSettings s; + s.beginGroup("Global"); + QString key; + foreach(key, s.childKeys()) { + global->updateData(key, s.value(key)); + } + global->updateData("CoreReady", true); + // Now that we are in sync, we can connect signals to automatically store further updates. + // I don't think we care if global data changed locally or if it was updated by a client. + connect(global, SIGNAL(dataUpdatedRemotely(QString)), SLOT(globalDataUpdated(QString))); + connect(global, SIGNAL(dataPutLocally(QString)), SLOT(globalDataUpdated(QString))); - connect(&server, SIGNAL(recvLine(const QString &)), this, SIGNAL(outputLine(const QString &))); - //connect( - server.start(); - exec(); } -void Core::connectToIrc( const QString &h, quint16 port) { - server.connectToIrc(h, port); +void Core::globalDataUpdated(QString key) { + QVariant data = global->getData(key); + QSettings s; + s.setValue(QString("Global/")+key, data); } -void Core::inputLine(const QString &s) { - server.putRawLine( s); +void Core::connectToIrc(QStringList networks) { + foreach(QString net, networks) { + if(servers.contains(net)) { + + } else { + Server *server = new Server(net); + connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString))); + connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString))); + connect(this, SIGNAL(msgFromGUI(QString, QString, QString)), server, SLOT(userInput(QString, QString, QString))); + connect(server, SIGNAL(sendMessage(QString, Message)), this, SLOT(recvMessageFromServer(QString, Message))); + connect(server, SIGNAL(sendStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString))); + connect(server, SIGNAL(setTopic(QString, QString, QString)), coreProxy, SLOT(csSetTopic(QString, QString, QString))); + connect(server, SIGNAL(setNicks(QString, QString, QStringList)), coreProxy, SLOT(csSetNicks(QString, QString, QStringList))); + // add error handling + server->start(); + servers[net] = server; + } + emit connectToIrc(net); + } } -VarMap Core::loadIdentities() { - QSettings s; - return s.value("Network/Identities").toMap(); +void Core::recvMessageFromServer(QString buf, Message msg) { + Q_ASSERT(sender()); + QString net = qobject_cast(sender())->getNetwork(); + emit sendMessage(net, buf, msg); } -void Core::storeIdentities(VarMap identities) { - QSettings s; - s.setValue("Network/Identities", identities); +void Core::recvStatusMsgFromServer(QString msg) { + Q_ASSERT(sender()); + QString net = qobject_cast(sender())->getNetwork(); + emit sendStatusMsg(net, msg); } + + +Core *core = 0;