client: Use sentence case for Core Info details
[quassel.git] / src / qtui / monoapplication.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "monoapplication.h"
22 #include "coreapplication.h"
23 #include "client.h"
24 #include "core.h"
25 #include "internalpeer.h"
26 #include "qtui.h"
27
28 class InternalPeer;
29
30 MonolithicApplication::MonolithicApplication(int &argc, char **argv)
31     : QtUiApplication(argc, argv)
32 {
33 #if defined(HAVE_KDE4) || defined(Q_OS_MAC)
34     Quassel::disableCrashHandler();
35 #endif /* HAVE_KDE4 || Q_OS_MAC */
36
37     Quassel::setRunMode(Quassel::Monolithic);
38 }
39
40
41 bool MonolithicApplication::init()
42 {
43     if (!QtUiApplication::init())
44         return false;
45
46     connect(Client::coreConnection(), SIGNAL(connectToInternalCore(QPointer<InternalPeer>)), this, SLOT(onConnectionRequest(QPointer<InternalPeer>)));
47
48     // If port is set, start internal core directly so external clients can connect
49     // This is useful in case the mono client re-gains remote connection capability,
50     // in which case the internal core would not have to be started by default.
51     if (Quassel::isOptionSet("port")) {
52         startInternalCore();
53     }
54
55     return true;
56 }
57
58
59 MonolithicApplication::~MonolithicApplication()
60 {
61     // Client needs to be destroyed first
62     Client::destroy();
63     _coreThread.quit();
64     _coreThread.wait();
65     Quassel::destroy();
66 }
67
68
69 void MonolithicApplication::startInternalCore()
70 {
71     if (_core) {
72         // Already started
73         return;
74     }
75
76     // Start internal core in a separate thread, so it doesn't block the UI
77     _core = new Core{};
78     _core->moveToThread(&_coreThread);
79     connect(&_coreThread, SIGNAL(started()), _core, SLOT(init()));
80     connect(&_coreThread, SIGNAL(finished()), _core, SLOT(deleteLater()));
81
82     connect(this, SIGNAL(connectInternalPeer(QPointer<InternalPeer>)), _core, SLOT(connectInternalPeer(QPointer<InternalPeer>)));
83     connect(_core, SIGNAL(sessionState(Protocol::SessionState)), Client::coreConnection(), SLOT(internalSessionStateReceived(Protocol::SessionState)));
84
85     connect(_core, SIGNAL(dbUpgradeInProgress(bool)), Client::instance(), SLOT(onDbUpgradeInProgress(bool)));
86
87     _coreThread.start();
88 }
89
90
91 void MonolithicApplication::onConnectionRequest(QPointer<InternalPeer> peer)
92 {
93     if (!_core) {
94         startInternalCore();
95     }
96
97     // While starting the core may take a while, the object itself is instantiated synchronously and the connections
98     // established, so it's safe to emit this immediately. The core will take care of queueing the request until
99     // initialization is complete.
100     emit connectInternalPeer(peer);
101 }