Setting status buffer active on connection (by creating a BufferId for it in Core
[quassel.git] / core / core.cpp
index b1815d9..2a8d4cc 100644 (file)
@@ -56,8 +56,11 @@ void Core::init() {
   connect(&server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
   //startListening(); // FIXME
   if(Global::runMode == Global::Monolithic) {  // TODO Make GUI user configurable
-    guiUser = storage->validateUser("Default", "password");
-    if(!guiUser) guiUser = storage->addUser("Default", "password");
+    try {
+      guiUser = storage->validateUser("Default", "password");
+    } catch(Storage::AuthError) {
+      guiUser = storage->addUser("Default", "password");
+    }
     Q_ASSERT(guiUser);
     Global::setGuiUser(guiUser);
     createSession(guiUser);
@@ -253,8 +256,8 @@ void Core::recvProxySignal(CoreSignal sig, QVariant arg1, QVariant arg2, QVarian
 
 CoreSession::CoreSession(UserId uid, Storage *_storage) : user(uid), storage(_storage) {
   coreProxy = new CoreProxy();
-  connect(coreProxy, SIGNAL(send(CoreSignal, QVariant, QVariant, QVariant)), this, SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)));
 
+  connect(coreProxy, SIGNAL(send(CoreSignal, QVariant, QVariant, QVariant)), this, SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)));
   connect(coreProxy, SIGNAL(requestServerStates()), this, SIGNAL(serverStateRequested()));
   connect(coreProxy, SIGNAL(gsRequestConnect(QStringList)), this, SLOT(connectToIrc(QStringList)));
   connect(coreProxy, SIGNAL(gsUserInput(BufferId, QString)), this, SLOT(msgFromGui(BufferId, QString)));
@@ -267,7 +270,6 @@ CoreSession::CoreSession(UserId uid, Storage *_storage) : user(uid), storage(_st
   connect(storage, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId)));
   connect(Global::instance(), SIGNAL(dataUpdatedRemotely(UserId, QString)), this, SLOT(globalDataUpdated(UserId, QString)));
   connect(Global::instance(), SIGNAL(dataPutLocally(UserId, QString)), this, SLOT(globalDataUpdated(UserId, QString)));
-
 }
 
 CoreSession::~CoreSession() {
@@ -299,6 +301,10 @@ void CoreSession::connectToIrc(QStringList networks) {
       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(connected(QString)), this, SLOT(serverConnected(QString)));
+      connect(server, SIGNAL(disconnected(QString)), this, SLOT(serverDisconnected(QString)));
+
       connect(server, SIGNAL(serverState(QString, VarMap)), coreProxy, SLOT(csServerState(QString, VarMap)));
       //connect(server, SIGNAL(displayMsg(Message)), this, SLOT(recvMessageFromServer(Message)));
       connect(server, SIGNAL(displayMsg(Message::Type, QString, QString, QString, quint8)), this, SLOT(recvMessageFromServer(Message::Type, QString, QString, QString, quint8)));
@@ -313,7 +319,7 @@ void CoreSession::connectToIrc(QStringList networks) {
       connect(server, SIGNAL(queryRequested(QString, QString)), coreProxy, SLOT(csQueryRequested(QString, QString)));
       // TODO add error handling
       connect(server, SIGNAL(connected(QString)), coreProxy, SLOT(csServerConnected(QString)));
-      connect(server, SIGNAL(disconnected(QString)), this, SLOT(serverDisconnected(QString)));
+      connect(server, SIGNAL(disconnected(QString)), coreProxy, SLOT(csServerDisconnected(QString)));
 
       server->start();
       servers[net] = server;
@@ -322,6 +328,10 @@ void CoreSession::connectToIrc(QStringList networks) {
   }
 }
 
+void CoreSession::serverConnected(QString net) {
+  storage->getBufferId(userId(), net); // create status buffer
+}
+
 void CoreSession::serverDisconnected(QString net) {
   delete servers[net];
   servers.remove(net);