X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmonoapplication.cpp;h=c9695cc83f87d98659feda1a8bcf30cba94f99bb;hp=a0ddbc0c9b5079844499587ea050dedd30216e2b;hb=72473527f99cbe68dcfcb4ca17f828bd3775bba7;hpb=b65b9f7615165e8700a44d59b7275a55558dd45b diff --git a/src/qtui/monoapplication.cpp b/src/qtui/monoapplication.cpp index a0ddbc0c..c9695cc8 100644 --- a/src/qtui/monoapplication.cpp +++ b/src/qtui/monoapplication.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -22,54 +22,90 @@ #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) - disableCrashhandler(); + Quassel::disableCrashHandler(); #endif /* HAVE_KDE4 || Q_OS_MAC */ - setRunMode(Quassel::Monolithic); + + Quassel::setRunMode(Quassel::Monolithic); } -bool MonolithicApplication::init() +void MonolithicApplication::init() { - if (!Quassel::init()) // parse args - return false; + QtUiApplication::init(); - connect(Client::coreConnection(), SIGNAL(startInternalCore()), SLOT(startInternalCore())); + connect(Client::coreConnection(), SIGNAL(connectToInternalCore(QPointer)), this, SLOT(onConnectionRequest(QPointer))); - // FIXME what's this for? - if (isOptionSet("port")) { + // 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 QtUiApplication::init(); +Quassel::QuitHandler MonolithicApplication::quitHandler() +{ + return [this]() { + connect(_client.get(), SIGNAL(destroyed()), this, SLOT(onClientDestroyed())); + _client.release()->deleteLater(); + }; } -MonolithicApplication::~MonolithicApplication() +void MonolithicApplication::onClientDestroyed() { - // Client needs to be destroyed first - Client::destroy(); - delete _internal; + if (_core) { + connect(_core, SIGNAL(destroyed()), QCoreApplication::instance(), SLOT(quit())); + _coreThread.quit(); + _coreThread.wait(); + } + else { + QCoreApplication::quit(); + } } void MonolithicApplication::startInternalCore() { - if (!_internalInitDone) { - _internal->init(); - _internalInitDone = true; + if (_core) { + // Already started + return; } - 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))); + + // 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(); + } + + // 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); }