***************************************************************************/
#include "core.h"
+#include "server.h"
+#include "global.h"
+#include "coreproxy.h"
#include <QSettings>
-void Core::init() {
+Core::Core() {
+ if(core) qFatal("Trying to instantiate more than one Core object!");
+ connect(coreProxy, SIGNAL(gsRequestConnect(QString, quint16)), this, SLOT(connectToIrc(QString, quint16)));
+ connect(coreProxy, SIGNAL(gsUserInput(QString)), this, SLOT(inputLine(QString)));
-}
+ connect(&server, SIGNAL(recvLine(QString)), coreProxy, SLOT(csCoreMessage(QString)));
-VarMap Core::loadIdentities() {
+ // Read global settings from config file
QSettings s;
- return s.value("Network/Identities").toMap();
+ 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)));
+
+ server.start();
+}
+
+void Core::connectToIrc(const QString &h, quint16 port) {
+ if(server.isConnected()) return;
+ qDebug() << "Core: Connecting to " << h << ":" << port;
+ server.connectToIrc(h, port);
}
-void Core::storeIdentities(VarMap identities) {
+void Core::inputLine(QString s) {
+ server.putRawLine(s);
+
+}
+
+void Core::globalDataUpdated(QString key) {
+ QVariant data = global->getData(key);
QSettings s;
- s.setValue("Network/Identities", identities);
+ s.setValue(QString("Global/")+key, data);
}
+
+Core *core = 0;