1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "monoapplication.h"
25 #include "coreapplication.h"
26 #include "internalpeer.h"
31 MonolithicApplication::MonolithicApplication(int& argc, char** argv)
32 : QtUiApplication(argc, argv)
35 void MonolithicApplication::init()
37 QtUiApplication::init();
39 connect(Client::coreConnection(), &CoreConnection::connectToInternalCore, this, &MonolithicApplication::onConnectionRequest);
41 // If port is set, start internal core directly so external clients can connect
42 // This is useful in case the mono client re-gains remote connection capability,
43 // in which case the internal core would not have to be started by default.
44 if (Quassel::isOptionSet("port")) {
49 Quassel::QuitHandler MonolithicApplication::quitHandler()
52 qInfo() << "Client shutting down...";
53 connect(_client.get(), &QObject::destroyed, this, &MonolithicApplication::onClientDestroyed);
54 _client.release()->deleteLater();
58 void MonolithicApplication::onClientDestroyed()
61 connect(_core, &Core::shutdownComplete, this, &MonolithicApplication::onCoreShutdown);
65 QCoreApplication::quit();
69 void MonolithicApplication::onCoreShutdown()
72 connect(_core, &QObject::destroyed, QCoreApplication::instance(), &QCoreApplication::quit);
77 QCoreApplication::quit();
81 void MonolithicApplication::startInternalCore()
88 // Start internal core in a separate thread, so it doesn't block the UI
90 _core->moveToThread(&_coreThread);
91 connect(&_coreThread, &QThread::started, _core.data(), &Core::initAsync);
92 connect(&_coreThread, &QThread::finished, _core.data(), &QObject::deleteLater);
94 connect(this, &MonolithicApplication::connectInternalPeer, _core, &Core::connectInternalPeer);
95 connect(_core, &Core::sessionStateReceived, Client::coreConnection(), &CoreConnection::internalSessionStateReceived);
97 connect(_core.data(), &Core::dbUpgradeInProgress, Client::instance(), &Client::onDbUpgradeInProgress);
98 connect(_core.data(), &Core::exitRequested, Client::instance(), &Client::onExitRequested);
103 void MonolithicApplication::onConnectionRequest(QPointer<InternalPeer> peer)
109 // While starting the core may take a while, the object itself is instantiated synchronously and the connections
110 // established, so it's safe to emit this immediately. The core will take care of queueing the request until
111 // initialization is complete.
112 emit connectInternalPeer(peer);