1 /***************************************************************************
2 * Copyright (C) 2005-07 by the Quassel IRC Team *
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 ***************************************************************************/
25 #include <QTranslator>
27 #if defined BUILD_CORE
28 #include <QCoreApplication>
33 #elif defined BUILD_QTUI
34 #include <QApplication>
38 #elif defined BUILD_MONO
39 #include <QApplication>
42 #include "coresession.h"
46 #error "Something is wrong - you need to #define a build mode!"
51 //! Signal handler for graceful shutdown.
52 void handle_signal(int sig) {
53 qWarning(QString("Caught signal %1 - exiting.").arg(sig).toAscii());
54 QCoreApplication::quit();
57 int main(int argc, char **argv) {
58 // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
59 signal(SIGTERM, handle_signal);
60 signal(SIGINT, handle_signal);
62 Global::registerMetaTypes();
64 #if defined BUILD_CORE
65 Global::runMode = Global::CoreOnly;
66 QCoreApplication app(argc, argv);
67 #elif defined BUILD_QTUI
68 Global::runMode = Global::ClientOnly;
69 QApplication app(argc, argv);
71 Global::runMode = Global::Monolithic;
72 QApplication app(argc, argv);
75 // Set up i18n support
76 QLocale locale = QLocale::system();
78 QTranslator qtTranslator;
79 qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
80 app.installTranslator(&qtTranslator);
82 QTranslator quasselTranslator;
83 quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
84 app.installTranslator(&quasselTranslator);
86 QCoreApplication::setOrganizationDomain("quassel-irc.org");
87 QCoreApplication::setApplicationName("Quassel IRC");
88 QCoreApplication::setOrganizationName("Quassel Project");
90 // Check if a non-standard core port is requested
91 QStringList args = QCoreApplication::arguments(); // TODO Build a CLI parser
93 Global::defaultPort = 4242;
95 if((idx = args.indexOf("-p")) > 0 && idx < args.count() - 1) {
96 int port = args[idx+1].toInt();
97 if(port >= 1024 && port < 65536) Global::defaultPort = port;
101 Core::instance(); // create and init the core
107 QtUi *gui = new QtUi();
113 if(args.contains("--norestore")) {
114 Core::restoreState();
118 int exitCode = app.exec();
125 // the mainWin has to be deleted before the Core
126 // if not Quassel will crash on exit under certain conditions since the gui
127 // still wants to access clientdata