X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fmonoapplication.cpp;h=068ec711e1bd6c388c23140cac712c5f76ddf024;hb=4e43a17088e8ff76c220bd8b4ebf37d9dbb4863a;hp=1a8822d61498d4172334175d25ba33dbd97ef3d6;hpb=358e5d557d527675c7bc62e58a4c7ad3b408897c;p=quassel.git diff --git a/src/qtui/monoapplication.cpp b/src/qtui/monoapplication.cpp index 1a8822d6..068ec711 100644 --- a/src/qtui/monoapplication.cpp +++ b/src/qtui/monoapplication.cpp @@ -23,6 +23,7 @@ #include "client.h" #include "core.h" #include "internalpeer.h" +#include "logmessage.h" #include "qtui.h" class InternalPeer; @@ -30,18 +31,12 @@ class InternalPeer; MonolithicApplication::MonolithicApplication(int &argc, char **argv) : QtUiApplication(argc, argv) { -#if defined(HAVE_KDE4) || defined(Q_OS_MAC) - Quassel::disableCrashHandler(); -#endif /* HAVE_KDE4 || Q_OS_MAC */ - - Quassel::setRunMode(Quassel::Monolithic); } -bool MonolithicApplication::init() +void MonolithicApplication::init() { - if (!QtUiApplication::init()) - return false; + QtUiApplication::init(); connect(Client::coreConnection(), SIGNAL(connectToInternalCore(QPointer)), this, SLOT(onConnectionRequest(QPointer))); @@ -51,18 +46,41 @@ bool MonolithicApplication::init() if (Quassel::isOptionSet("port")) { startInternalCore(); } +} - return true; + +Quassel::QuitHandler MonolithicApplication::quitHandler() +{ + return [this]() { + quInfo() << "Client shutting down..."; + connect(_client.get(), SIGNAL(destroyed()), this, SLOT(onClientDestroyed())); + _client.release()->deleteLater(); + }; } -MonolithicApplication::~MonolithicApplication() +void MonolithicApplication::onClientDestroyed() { - // Client needs to be destroyed first - Client::destroy(); - _coreThread.quit(); - _coreThread.wait(); - Quassel::destroy(); + if (_core) { + connect(_core, SIGNAL(shutdownComplete()), this, SLOT(onCoreShutdown())); + _core->shutdown(); + } + else { + QCoreApplication::quit(); + } +} + + +void MonolithicApplication::onCoreShutdown() +{ + if (_core) { + connect(_core, SIGNAL(destroyed()), QCoreApplication::instance(), SLOT(quit())); + _coreThread.quit(); + _coreThread.wait(); + } + else { + QCoreApplication::quit(); + } } @@ -76,12 +94,15 @@ void MonolithicApplication::startInternalCore() // 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(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(); }