X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fsessionthread.cpp;h=35caf13be27eef07c065e252a16b97219d5e8421;hp=d178c2bb81de4f36b3a7172dc694353170de4e8d;hb=a5ee21025ec613dc128ceb78a7e5fcd0f353275e;hpb=6f2f1723f5bb3d26908f6dd297890f6fba43793b diff --git a/src/core/sessionthread.cpp b/src/core/sessionthread.cpp index d178c2bb..35caf13b 100644 --- a/src/core/sessionthread.cpp +++ b/src/core/sessionthread.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,15 +21,18 @@ #include #include "sessionthread.h" - +#include "signalproxy.h" #include "coresession.h" +#include "core.h" -SessionThread::SessionThread(UserId uid, bool restoreState, QObject *parent) : QThread(parent) { - _user = uid; - _session = 0; - _sessionInitialized = false; - _restoreState = restoreState, - connect(this, SIGNAL(initialized()), this, SLOT(setSessionInitialized())); +SessionThread::SessionThread(UserId uid, bool restoreState, QObject *parent) + : QThread(parent), + _session(0), + _user(uid), + _sessionInitialized(false), + _restoreState(restoreState) +{ + connect(this, SIGNAL(initialized()), this, SLOT(setSessionInitialized())); } SessionThread::~SessionThread() { @@ -52,31 +55,51 @@ bool SessionThread::isSessionInitialized() { void SessionThread::setSessionInitialized() { _sessionInitialized = true; - foreach(QIODevice *socket, clientQueue) { - addClientToSession(socket); + foreach(QObject *peer, clientQueue) { + addClientToSession(peer); } clientQueue.clear(); } -void SessionThread::addClient(QIODevice *socket) { +void SessionThread::addClient(QObject *peer) { if(isSessionInitialized()) { - addClientToSession(socket); + addClientToSession(peer); } else { - clientQueue.append(socket); + clientQueue.append(peer); + } +} + +void SessionThread::addClientToSession(QObject *peer) { + QIODevice *socket = qobject_cast(peer); + if(socket) { + addRemoteClientToSession(socket); + return; + } + + SignalProxy *proxy = qobject_cast(peer); + if(proxy) { + addInternalClientToSession(proxy); + return; } + + qWarning() << "SessionThread::addClient() received neither QIODevice nor SignalProxy as peer!" << peer; } -void SessionThread::addClientToSession(QIODevice *socket) { +void SessionThread::addRemoteClientToSession(QIODevice *socket) { socket->setParent(0); socket->moveToThread(session()->thread()); - if(!QMetaObject::invokeMethod(session(), "addClient", Q_ARG(QObject *, socket))) { - qWarning() << qPrintable(tr("Could not initialize session!")); - socket->close(); - } + emit addRemoteClient(socket); +} + +void SessionThread::addInternalClientToSession(SignalProxy *proxy) { + emit addInternalClient(proxy); } void SessionThread::run() { _session = new CoreSession(user(), _restoreState); + connect(this, SIGNAL(addRemoteClient(QIODevice *)), _session, SLOT(addClient(QIODevice *))); + connect(this, SIGNAL(addInternalClient(SignalProxy *)), _session, SLOT(addClient(SignalProxy *))); + connect(_session, SIGNAL(sessionState(const QVariant &)), Core::instance(), SIGNAL(sessionState(const QVariant &))); emit initialized(); exec(); delete _session;