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>
30 #if defined BUILD_CORE
31 #include <QCoreApplication>
36 #elif defined BUILD_QTUI
37 #include <QApplication>
41 #elif defined BUILD_MONO
42 #include <QApplication>
45 #include "coresession.h"
49 #error "Something is wrong - you need to #define a build mode!"
54 //! Signal handler for graceful shutdown.
55 void handle_signal(int sig) {
56 qWarning(QString("Caught signal %1 - exiting.").arg(sig).toAscii());
57 QCoreApplication::quit();
60 int main(int argc, char **argv) {
61 // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
62 signal(SIGTERM, handle_signal);
63 signal(SIGINT, handle_signal);
65 Global::registerMetaTypes();
67 #if defined BUILD_CORE
68 Global::runMode = Global::CoreOnly;
69 QCoreApplication app(argc, argv);
70 #elif defined BUILD_QTUI
71 Global::runMode = Global::ClientOnly;
72 QApplication app(argc, argv);
74 Global::runMode = Global::Monolithic;
75 QApplication app(argc, argv);
78 qsrand(QDateTime::currentDateTime().toTime_t());
80 // Set up i18n support
81 QLocale locale = QLocale::system();
83 QTranslator qtTranslator;
84 qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
85 app.installTranslator(&qtTranslator);
87 QTranslator quasselTranslator;
88 quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
89 app.installTranslator(&quasselTranslator);
91 QCoreApplication::setOrganizationDomain("quassel-irc.org");
92 QCoreApplication::setApplicationName("Quassel IRC");
93 QCoreApplication::setOrganizationName("Quassel Project");
95 // Check if a non-standard core port is requested
96 QStringList args = QCoreApplication::arguments(); // TODO Build a CLI parser
98 Global::defaultPort = 4242;
100 if((idx = args.indexOf("-p")) > 0 && idx < args.count() - 1) {
101 int port = args[idx+1].toInt();
102 if(port >= 1024 && port < 65536) Global::defaultPort = port;
106 Core::instance(); // create and init the core
112 QtUi *gui = new QtUi();
114 // init gui only after the event loop has started
115 QTimer::singleShot(0, gui, SLOT(init()));
120 if(!args.contains("--norestore")) {
121 Core::restoreState();
125 int exitCode = app.exec();
132 // the mainWin has to be deleted before the Core
133 // if not Quassel will crash on exit under certain conditions since the gui
134 // still wants to access clientdata