X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fqtuiapplication.cpp;h=fc04f59be7839161869265b7d0f5aa80673cacdd;hb=4e88f2c1bcce0c4ebb7e8901cc382513266dea56;hp=20c1662eb3cb61edc42ee3aa81cdd599c18701c0;hpb=f88bfa81380ceb2c4afce5b15f753570a1ef063d;p=quassel.git diff --git a/src/qtui/qtuiapplication.cpp b/src/qtui/qtuiapplication.cpp index 20c1662e..fc04f59b 100644 --- a/src/qtui/qtuiapplication.cpp +++ b/src/qtui/qtuiapplication.cpp @@ -29,8 +29,8 @@ #endif #include "chatviewsettings.h" -#include "client.h" #include "cliparser.h" +#include "logmessage.h" #include "mainwin.h" #include "qtui.h" #include "qtuisettings.h" @@ -82,10 +82,6 @@ QtUiApplication::QtUiApplication(int &argc, char **argv) #endif /* HAVE_KDE4 */ -#if defined(HAVE_KDE4) || defined(Q_OS_MAC) - Quassel::disableCrashHandler(); -#endif /* HAVE_KDE4 || Q_OS_MAC */ - Quassel::setRunMode(Quassel::ClientOnly); #if QT_VERSION >= 0x050000 @@ -110,29 +106,33 @@ void QtUiApplication::init() throw ExitException{EXIT_FAILURE, tr("Could not load or upgrade client settings!")}; } - Client::init(new QtUi()); + _client.reset(new Client(std::unique_ptr(new QtUi()))); // TODO C++14: std::make_unique // Init UI only after the event loop has started // TODO Qt5: Make this a lambda QTimer::singleShot(0, this, SLOT(initUi())); - - Quassel::registerQuitHandler([]() { - QtUi::mainWindow()->quit(); - }); } -QtUiApplication::~QtUiApplication() +void QtUiApplication::initUi() { - Client::destroy(); - Quassel::destroy(); + QtUi::instance()->init(); + + // Needs to happen after UI init, so the MainWin quit handler is registered first + Quassel::registerQuitHandler(quitHandler()); + + resumeSessionIfPossible(); } -void QtUiApplication::initUi() +Quassel::QuitHandler QtUiApplication::quitHandler() { - QtUi::instance()->init(); - resumeSessionIfPossible(); + // Wait until the Client instance is destroyed before quitting the event loop + return [this]() { + quInfo() << "Client shutting down..."; + connect(_client.get(), SIGNAL(destroyed()), QCoreApplication::instance(), SLOT(quit())); + _client.release()->deleteLater(); + }; }