1 /***************************************************************************
2 * Copyright (C) 2005-2018 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"
22 #include "coreapplication.h"
25 #include "internalpeer.h"
30 MonolithicApplication::MonolithicApplication(int &argc, char **argv)
31 : QtUiApplication(argc, argv)
33 #if defined(HAVE_KDE4) || defined(Q_OS_MAC)
34 Quassel::disableCrashHandler();
35 #endif /* HAVE_KDE4 || Q_OS_MAC */
37 Quassel::setRunMode(Quassel::Monolithic);
41 void MonolithicApplication::init()
43 QtUiApplication::init();
45 connect(Client::coreConnection(), SIGNAL(connectToInternalCore(QPointer<InternalPeer>)), this, SLOT(onConnectionRequest(QPointer<InternalPeer>)));
47 // If port is set, start internal core directly so external clients can connect
48 // This is useful in case the mono client re-gains remote connection capability,
49 // in which case the internal core would not have to be started by default.
50 if (Quassel::isOptionSet("port")) {
56 Quassel::QuitHandler MonolithicApplication::quitHandler()
59 connect(_client.get(), SIGNAL(destroyed()), this, SLOT(onClientDestroyed()));
60 _client.release()->deleteLater();
65 void MonolithicApplication::onClientDestroyed()
68 connect(_core, SIGNAL(destroyed()), QCoreApplication::instance(), SLOT(quit()));
73 QCoreApplication::quit();
78 void MonolithicApplication::startInternalCore()
85 // Start internal core in a separate thread, so it doesn't block the UI
87 _core->moveToThread(&_coreThread);
88 connect(&_coreThread, SIGNAL(started()), _core, SLOT(initAsync()));
89 connect(&_coreThread, SIGNAL(finished()), _core, SLOT(deleteLater()));
91 connect(this, SIGNAL(connectInternalPeer(QPointer<InternalPeer>)), _core, SLOT(connectInternalPeer(QPointer<InternalPeer>)));
92 connect(_core, SIGNAL(sessionState(Protocol::SessionState)), Client::coreConnection(), SLOT(internalSessionStateReceived(Protocol::SessionState)));
94 connect(_core, SIGNAL(dbUpgradeInProgress(bool)), Client::instance(), SLOT(onDbUpgradeInProgress(bool)));
95 connect(_core, SIGNAL(exitRequested(int,QString)), Client::instance(), SLOT(onExitRequested(int,QString)));
101 void MonolithicApplication::onConnectionRequest(QPointer<InternalPeer> peer)
107 // While starting the core may take a while, the object itself is instantiated synchronously and the connections
108 // established, so it's safe to emit this immediately. The core will take care of queueing the request until
109 // initialization is complete.
110 emit connectInternalPeer(peer);