1 /***************************************************************************
2 * Copyright (C) 2005-08 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 #include <QTranslator>
31 #include "cliparser.h"
33 #if defined BUILD_CORE
38 #elif defined BUILD_QTUI
40 #include "qtuiapplication.h"
43 #elif defined BUILD_MONO
46 #include "coresession.h"
47 #include "qtuiapplication.h"
51 #error "Something is wrong - you need to #define a build mode!"
57 //! Signal handler for graceful shutdown.
58 void handle_signal(int sig) {
59 qWarning("%s", qPrintable(QString("Caught signal %1 - exiting.").arg(sig)));
60 QCoreApplication::quit();
63 int main(int argc, char **argv) {
64 // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
65 signal(SIGTERM, handle_signal);
66 signal(SIGINT, handle_signal);
68 Global::registerMetaTypes();
69 Global::setupVersion();
72 #if defined BUILD_CORE
73 Global::runMode = Global::CoreOnly;
74 QCoreApplication app(argc, argv);
75 #elif defined BUILD_QTUI
76 Global::runMode = Global::ClientOnly;
77 QApplication app(argc, argv);
79 Global::runMode = Global::Monolithic;
80 QApplication app(argc, argv);
83 #if defined BUILD_CORE
84 Global::runMode = Global::CoreOnly;
85 QCoreApplication app(argc, argv);
86 #elif defined BUILD_QTUI
87 Global::runMode = Global::ClientOnly;
88 QtUiApplication app(argc, argv);
90 Global::runMode = Global::Monolithic;
91 QtUiApplication app(argc, argv);
96 Global::parser = CliParser(QCoreApplication::arguments());
99 // put core-only arguments here
100 Global::parser.addOption("port",'p',"The port quasselcore will listen at",QString("4242"));
101 Global::parser.addSwitch("norestore", 'n', "Don't restore last core's state");
102 Global::parser.addOption("logfile",'l',"Path to logfile");
103 Global::parser.addOption("loglevel",'L',"Loglevel Debug|Info|Warning|Error","Info");
104 Global::parser.addOption("datadir", 0, "Specify the directory holding datafiles like the Sqlite DB and the SSL Cert");
107 // put client-only arguments here
108 Global::parser.addSwitch("debugbufferswitches",0,"Enables debugging for bufferswitches");
109 Global::parser.addSwitch("debugmodel",0,"Enables debugging for models");
110 #endif // BUILD_QTCORE
111 // put shared client&core arguments here
112 Global::parser.addSwitch("debug",'d',"Enable debug output");
113 Global::parser.addSwitch("help",'h', "Display this help and exit");
115 if(!Global::parser.parse() || Global::parser.isSet("help")) {
116 Global::parser.usage();
121 This is an initial check if logfile is writable since the warning would spam stdout if done
122 in current Logger implementation. Can be dropped whenever the logfile is only opened once.
124 if(Global::runMode != Global::ClientOnly) {
126 if(!Global::parser.value("logfile").isEmpty()) {
127 logFile.setFileName(Global::parser.value("logfile"));
128 if(!logFile.open(QIODevice::Append | QIODevice::Text))
129 qWarning("Warning: Couldn't open logfile '%s' - will log to stdout instead",qPrintable(logFile.fileName()));
130 else logFile.close();
134 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
136 // Set up i18n support
137 QLocale locale = QLocale::system();
139 QTranslator qtTranslator(&app);
140 qtTranslator.setObjectName("QtTr");
141 qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
142 app.installTranslator(&qtTranslator);
144 QTranslator quasselTranslator(&app);
145 quasselTranslator.setObjectName("QuasselTr");
146 quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
147 app.installTranslator(&quasselTranslator);
149 Network::setDefaultCodecForServer("ISO-8859-1");
150 Network::setDefaultCodecForEncoding("UTF-8");
151 Network::setDefaultCodecForDecoding("ISO-8859-15");
153 QCoreApplication::setOrganizationDomain("quassel-irc.org");
154 QCoreApplication::setApplicationName("Quassel IRC");
155 QCoreApplication::setOrganizationName("Quassel Project");
159 Core::instance(); // create and init the core
166 QtUi *gui = new QtUi();
168 // init gui only after the event loop has started
169 QTimer::singleShot(0, gui, SLOT(init()));
174 if(!Global::parser.isSet("norestore")) {
175 Core::restoreState();
180 app.resumeSessionIfPossible();
183 int exitCode = app.exec();
190 // the mainWin has to be deleted before the Core
191 // if not Quassel will crash on exit under certain conditions since the gui
192 // still wants to access clientdata