X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fsessionthread.cpp;h=c29d1ff78b588e0c7154253f80b9382ca3090ec5;hp=d5070955485dbbf7247f363dda731571f9365c4f;hb=453ccab6ade4a21c7aa3c331af893c91468250a4;hpb=d1b6499b0b848d4287efae89107576548533502c diff --git a/src/core/sessionthread.cpp b/src/core/sessionthread.cpp index d5070955..c29d1ff7 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,21 +21,27 @@ #include #include "sessionthread.h" - +#include "signalproxy.h" #include "coresession.h" +#include "core.h" -SessionThread::SessionThread(UserId uid, QObject *parent) : QThread(parent) { - _user = uid; - _session = 0; - _sessionInitialized = false; - 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() { - // FIXME - quit(); - wait(); - if(session()) _session->deleteLater(); + if(_session) { + _session->setParent(0); + _session->moveToThread(thread()); + _session->deleteLater(); + _session = 0; + } } CoreSession *SessionThread::session() { @@ -52,32 +58,61 @@ 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()); + _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; + _session = 0; } +void SessionThread::stopSession() { + if(_session) { + connect(_session, SIGNAL(destroyed()), this, SLOT(quit())); + _session->deleteLater(); + _session = 0; + } +}