SignalProxy *p = signalProxy();
connect(p, SIGNAL(peerRemoved(QIODevice *)), this, SLOT(removeClient(QIODevice *)));
+ connect(p, SIGNAL(connected()), this, SLOT(clientsConnected()));
+ connect(p, SIGNAL(disconnected()), this, SLOT(clientsDisconnected()));
+
//p->attachSlot(SIGNAL(disconnectFromNetwork(NetworkId)), this, SLOT(disconnectFromNetwork(NetworkId))); // FIXME
p->attachSlot(SIGNAL(sendInput(BufferInfo, QString)), this, SLOT(msgFromClient(BufferInfo, QString)));
p->attachSignal(this, SIGNAL(displayMsg(Message)));
}
}
-UserId CoreSession::user() const {
- return _user;
-}
-
CoreNetwork *CoreSession::network(NetworkId id) const {
if(_networks.contains(id)) return _networks[id];
return 0;
void CoreSession::networkStateRequested() {
}
-void CoreSession::addClient(QObject *dev) { // this is QObject* so we can use it in signal connections
- QIODevice *device = qobject_cast<QIODevice *>(dev);
+void CoreSession::addClient(QIODevice *device) {
if(!device) {
quError() << "Invoking CoreSession::addClient with a QObject that is not a QIODevice!";
} else {
+ // if the socket is an orphan, the signalProxy adopts it.
+ // -> we don't need to care about it anymore
+ device->setParent(0);
signalProxy()->addPeer(device);
QVariantMap reply;
reply["MsgType"] = "SessionInit";
}
}
+void CoreSession::addClient(SignalProxy *proxy) {
+ signalProxy()->addPeer(proxy);
+ emit sessionState(sessionState());
+}
+
void CoreSession::removeClient(QIODevice *iodev) {
QTcpSocket *socket = qobject_cast<QTcpSocket *>(iodev);
if(socket)
quInfo() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt()));
- iodev->deleteLater();
}
SignalProxy *CoreSession::signalProxy() const {
emit bufferRenamed(bufferId, newName);
}
}
+
+void CoreSession::clientsConnected() {
+ QHash<NetworkId, NetworkConnection *>::iterator conIter = _connections.begin();
+ Identity *identity = 0;
+ NetworkConnection *con = 0;
+ Network *network = 0;
+ IrcUser *me = 0;
+ QString awayReason;
+ while(conIter != _connections.end()) {
+ con = *conIter;
+ conIter++;
+
+ if(!con->isConnected())
+ continue;
+ identity = con->identity();
+ if(!identity)
+ continue;
+ network = con->network();
+ if(!network)
+ continue;
+ me = network->me();
+ if(!me)
+ continue;
+
+ if(identity->detachAwayEnabled() && me->isAway()) {
+ con->userInputHandler()->handleAway(BufferInfo(), QString());
+ }
+ }
+}
+
+void CoreSession::clientsDisconnected() {
+ QHash<NetworkId, NetworkConnection *>::iterator conIter = _connections.begin();
+ Identity *identity = 0;
+ NetworkConnection *con = 0;
+ Network *network = 0;
+ IrcUser *me = 0;
+ QString awayReason;
+ while(conIter != _connections.end()) {
+ con = *conIter;
+ conIter++;
+
+ if(!con->isConnected())
+ continue;
+ identity = con->identity();
+ if(!identity)
+ continue;
+ network = con->network();
+ if(!network)
+ continue;
+ me = network->me();
+ if(!me)
+ continue;
+
+ if(identity->detachAwayEnabled() && !me->isAway()) {
+ if(identity->detachAwayReasonEnabled())
+ awayReason = identity->detachAwayReason();
+ else
+ awayReason = identity->awayReason();
+ con->userInputHandler()->handleAway(BufferInfo(), awayReason);
+ }
+ }
+}