Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coreapplication.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 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 
33 {
34  if (_coreCreated) {
36  Core::destroy();
37  }
38 }
39 
40 
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"))
60 
61  return true;
62 }
63 
64 
65 /*****************************************************************************/
66 
67 CoreApplication::CoreApplication(int &argc, char **argv)
68  : QCoreApplication(argc, argv), Quassel()
69 {
70 #ifdef Q_OS_MAC
72 #endif /* Q_OS_MAC */
73 
74  setRunMode(Quassel::CoreOnly);
76 }
77 
78 
80 {
81  delete _internal;
82 }
83 
84 
86 {
87  if (Quassel::init() && _internal->init()) {
88 #if QT_VERSION < 0x050000
89  qInstallMsgHandler(Logger::logMessage);
90 #else
91  qInstallMessageHandler(Logger::logMessage);
92 #endif
93  return true;
94  }
95  return false;
96 }