X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmonoapplication.cpp;h=e92afcc68bc36fc07417563141752b929585dfd2;hp=3d1a060d6ef7fa8ace88a28c02d6773b578d0caa;hb=54ebc1bf00f4f9a8376629925329f0e72be04662;hpb=68878dc8366f2f4a0afe132847aad9a51a80cdbf diff --git a/src/qtui/monoapplication.cpp b/src/qtui/monoapplication.cpp index 3d1a060d..e92afcc6 100644 --- a/src/qtui/monoapplication.cpp +++ b/src/qtui/monoapplication.cpp @@ -22,15 +22,14 @@ #include "coreapplication.h" #include "client.h" #include "core.h" +#include "internalpeer.h" #include "qtui.h" class InternalPeer; MonolithicApplication::MonolithicApplication(int &argc, char **argv) - : QtUiApplication(argc, argv), - _internalInitDone(false) + : QtUiApplication(argc, argv) { - _internal = new CoreApplicationInternal(); // needed for parser options #if defined(HAVE_KDE4) || defined(Q_OS_MAC) Quassel::disableCrashHandler(); #endif /* HAVE_KDE4 || Q_OS_MAC */ @@ -39,19 +38,18 @@ MonolithicApplication::MonolithicApplication(int &argc, char **argv) } -bool MonolithicApplication::init() +void MonolithicApplication::init() { - if (!QtUiApplication::init()) - return false; + QtUiApplication::init(); - connect(Client::coreConnection(), SIGNAL(startInternalCore()), SLOT(startInternalCore())); + connect(Client::coreConnection(), SIGNAL(connectToInternalCore(QPointer)), this, SLOT(onConnectionRequest(QPointer))); - // If port is given, start core so it can listen to incoming connections + // 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; } @@ -59,18 +57,43 @@ MonolithicApplication::~MonolithicApplication() { // Client needs to be destroyed first Client::destroy(); - delete _internal; + _coreThread.quit(); + _coreThread.wait(); + Quassel::destroy(); } void MonolithicApplication::startInternalCore() { - if (!_internalInitDone) { - _internal->init(); - _internalInitDone = true; + 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(initAsync())); + 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))); + connect(_core, SIGNAL(exitRequested(int,QString)), Client::instance(), SLOT(onExitRequested(int,QString))); + + _coreThread.start(); +} + + +void MonolithicApplication::onConnectionRequest(QPointer peer) +{ + if (!_core) { + startInternalCore(); } - Core *core = Core::instance(); - CoreConnection *connection = Client::coreConnection(); - connect(connection, SIGNAL(connectToInternalCore(InternalPeer*)), core, SLOT(setupInternalClientSession(InternalPeer*))); - connect(core, SIGNAL(sessionState(Protocol::SessionState)), connection, 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); }