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
34 #include <QCoreApplication>
39 #elif defined BUILD_QTUI
40 #include <QApplication>
44 #elif defined BUILD_MONO
45 #include <QApplication>
48 #include "coresession.h"
52 #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();
71 #if defined BUILD_CORE
72 Global::runMode = Global::CoreOnly;
73 QCoreApplication app(argc, argv);
74 #elif defined BUILD_QTUI
75 Global::runMode = Global::ClientOnly;
76 QApplication app(argc, argv);
78 Global::runMode = Global::Monolithic;
79 QApplication app(argc, argv);
82 Global::parser = CliParser(QCoreApplication::arguments());
85 // put core-only arguments here
86 Global::parser.addOption("port",'p',"The port quasselcore will listen at",QString("4242"));
87 Global::parser.addSwitch("norestore", 'n', "Don't restore last core's state");
88 Global::parser.addOption("logfile",'l',"Path to logfile");
89 Global::parser.addOption("loglevel",'L',"Loglevel Debug|Info|Warning|Error","Info");
92 // put client-only arguments here
93 Global::parser.addSwitch("debugbufferswitches",0,"Enables debugging for bufferswitches");
94 Global::parser.addSwitch("debugmodel",0,"Enables debugging for models");
95 #endif // BUILD_QTCORE
96 // put shared client&core arguments here
97 Global::parser.addSwitch("debug",'d',"Enable debug output");
98 Global::parser.addSwitch("help",'h', "Display this help and exit");
100 if(!Global::parser.parse() || Global::parser.isSet("help")) {
101 Global::parser.usage();
106 This is an initial check if logfile is writable since the warning would spam stdout if done
107 in current Logger implementation. Can be dropped whenever the logfile is only opened once.
109 if(Global::runMode != Global::ClientOnly) {
111 if(!Global::parser.value("logfile").isEmpty()) {
112 logFile.setFileName(Global::parser.value("logfile"));
113 if(!logFile.open(QIODevice::Append | QIODevice::Text))
114 qWarning("Warning: Couldn't open logfile '%s' - will log to stdout instead",qPrintable(logFile.fileName()));
115 else logFile.close();
117 else qWarning("No logfile set - will log to stdout instead");
120 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
122 // Set up i18n support
123 QLocale locale = QLocale::system();
125 QTranslator qtTranslator(&app);
126 qtTranslator.setObjectName("QtTr");
127 qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
128 app.installTranslator(&qtTranslator);
130 QTranslator quasselTranslator(&app);
131 quasselTranslator.setObjectName("QuasselTr");
132 quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
133 app.installTranslator(&quasselTranslator);
135 Network::setDefaultCodecForServer("ISO-8859-1");
136 Network::setDefaultCodecForEncoding("UTF-8");
137 Network::setDefaultCodecForDecoding("ISO-8859-15");
139 QCoreApplication::setOrganizationDomain("quassel-irc.org");
140 QCoreApplication::setApplicationName("Quassel IRC");
141 QCoreApplication::setOrganizationName("Quassel Project");
144 Core::instance(); // create and init the core
150 QtUi *gui = new QtUi();
152 // init gui only after the event loop has started
153 QTimer::singleShot(0, gui, SLOT(init()));
158 if(!Global::parser.isSet("norestore")) {
159 Core::restoreState();
163 int exitCode = app.exec();
170 // the mainWin has to be deleted before the Core
171 // if not Quassel will crash on exit under certain conditions since the gui
172 // still wants to access clientdata