Implement core-side highlights
[quassel.git] / src / core / coreapplication.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 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 "coreapplication.h"
22
23 #include "core.h"
24 #include "logger.h"
25
26 CoreApplicationInternal::CoreApplicationInternal()
27     : _coreCreated(false)
28 {
29 }
30
31
32 CoreApplicationInternal::~CoreApplicationInternal()
33 {
34     if (_coreCreated) {
35         Core::saveState();
36         Core::destroy();
37     }
38 }
39
40
41 bool CoreApplicationInternal::init()
42 {
43     /* FIXME
44     This is an initial check if logfile is writable since the warning would spam stdout if done
45     in current Logger implementation. Can be dropped whenever the logfile is only opened once.
46     */
47     QFile logFile;
48     if (!Quassel::optionValue("logfile").isEmpty()) {
49         logFile.setFileName(Quassel::optionValue("logfile"));
50         if (!logFile.open(QIODevice::Append | QIODevice::Text))
51             qWarning("Warning: Couldn't open logfile '%s' - will log to stdout instead", qPrintable(logFile.fileName()));
52         else logFile.close();
53     }
54
55     Core::instance(); // create and init the core
56     _coreCreated = true;
57
58     if (!Quassel::isOptionSet("norestore"))
59         Core::restoreState();
60
61     return true;
62 }
63
64
65 bool CoreApplicationInternal::reloadConfig()
66 {
67     if (_coreCreated) {
68         // Currently, only reloading SSL certificates is supported
69         return Core::reloadCerts();
70     } else {
71         return false;
72     }
73 }
74
75
76 /*****************************************************************************/
77
78 CoreApplication::CoreApplication(int &argc, char **argv)
79     : QCoreApplication(argc, argv), Quassel()
80 {
81 #ifdef Q_OS_MAC
82     disableCrashhandler();
83 #endif /* Q_OS_MAC */
84
85     setRunMode(Quassel::CoreOnly);
86     _internal = new CoreApplicationInternal();
87 }
88
89
90 CoreApplication::~CoreApplication()
91 {
92     delete _internal;
93 }
94
95
96 bool CoreApplication::init()
97 {
98     if (Quassel::init() && _internal->init()) {
99 #if QT_VERSION < 0x050000
100         qInstallMsgHandler(Logger::logMessage);
101 #else
102         qInstallMessageHandler(Logger::logMessage);
103 #endif
104         return true;
105     }
106     return false;
107 }
108
109
110 bool CoreApplication::reloadConfig()
111 {
112     if (_internal) {
113         return _internal->reloadConfig();
114     } else {
115         return false;
116     }
117 }