X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fmonoapplication.cpp;h=d880f33f07e3d7e228bf000afaf711628f563549;hb=9f0918fca1d858523104435690e5094bfe6244b7;hp=c2ae9e5a0d4efbb78d40c4d0926beffa2135c030;hpb=fbb06e36ee772862c0d70ab43c9000225e9f8c42;p=quassel.git diff --git a/src/qtui/monoapplication.cpp b/src/qtui/monoapplication.cpp index c2ae9e5a..d880f33f 100644 --- a/src/qtui/monoapplication.cpp +++ b/src/qtui/monoapplication.cpp @@ -22,6 +22,7 @@ #include "coreapplication.h" #include "client.h" #include "core.h" +#include "internalpeer.h" #include "qtui.h" class InternalPeer; @@ -42,7 +43,14 @@ bool MonolithicApplication::init() if (!QtUiApplication::init()) return false; - connect(Client::coreConnection(), SIGNAL(startInternalCore()), SLOT(startInternalCore())); + connect(Client::coreConnection(), SIGNAL(connectToInternalCore(QPointer)), this, SLOT(onConnectionRequest(QPointer))); + + // If port is set, start internal core directly so external clients can connect + // This is useful in case the mono client re-gains remote connection capability, + // in which case the internal core would not have to be started by default. + if (Quassel::isOptionSet("port")) { + startInternalCore(); + } return true; } @@ -52,17 +60,42 @@ MonolithicApplication::~MonolithicApplication() { // Client needs to be destroyed first Client::destroy(); - _core.reset(); + _coreThread.quit(); + _coreThread.wait(); Quassel::destroy(); } void MonolithicApplication::startInternalCore() +{ + if (_core) { + // Already started + return; + } + + // Start internal core in a separate thread, so it doesn't block the UI + _core = new Core{}; + _core->moveToThread(&_coreThread); + connect(&_coreThread, SIGNAL(started()), _core, SLOT(init())); + connect(&_coreThread, SIGNAL(finished()), _core, SLOT(deleteLater())); + + connect(this, SIGNAL(connectInternalPeer(QPointer)), _core, SLOT(connectInternalPeer(QPointer))); + connect(_core, SIGNAL(sessionState(Protocol::SessionState)), Client::coreConnection(), SLOT(internalSessionStateReceived(Protocol::SessionState))); + + connect(_core, SIGNAL(dbUpgradeInProgress(bool)), Client::instance(), SLOT(onDbUpgradeInProgress(bool))); + + _coreThread.start(); +} + + +void MonolithicApplication::onConnectionRequest(QPointer peer) { if (!_core) { - _core.reset(new Core{}); // FIXME C++14: std::make_unique - Core::instance()->init(); + startInternalCore(); } - connect(Client::coreConnection(), SIGNAL(connectToInternalCore(InternalPeer*)), Core::instance(), SLOT(setupInternalClientSession(InternalPeer*))); - connect(Core::instance(), SIGNAL(sessionState(Protocol::SessionState)), Client::coreConnection(), SLOT(internalSessionStateReceived(Protocol::SessionState))); + + // While starting the core may take a while, the object itself is instantiated synchronously and the connections + // established, so it's safe to emit this immediately. The core will take care of queueing the request until + // initialization is complete. + emit connectInternalPeer(peer); }