Committing a lot of identity stuff which is still disabled.
[quassel.git] / src / common / main.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "global.h"
22 #include "identity.h"
23 #include "settings.h"
24 #include <QString>
25 #include <QTimer>
26 #include <QTranslator>
27
28 #if defined BUILD_CORE
29 #include <QCoreApplication>
30 #include <QDir>
31 #include "core.h"
32 #include "message.h"
33
34 #elif defined BUILD_QTUI
35 #include <QApplication>
36 #include "client.h"
37 #include "qtui.h"
38
39 #elif defined BUILD_MONO
40 #include <QApplication>
41 #include "client.h"
42 #include "core.h"
43 #include "coresession.h"
44 #include "qtui.h"
45
46 #else
47 #error "Something is wrong - you need to #define a build mode!"
48 #endif
49
50 #include <signal.h>
51
52 //! Signal handler for graceful shutdown.
53 void handle_signal(int sig) {
54   qWarning(QString("Caught signal %1 - exiting.").arg(sig).toAscii());
55   QCoreApplication::quit();
56 }
57
58 int main(int argc, char **argv) {
59   // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
60   signal(SIGTERM, handle_signal);
61   signal(SIGINT, handle_signal);
62
63   Global::registerMetaTypes();
64
65 #if defined BUILD_CORE
66   Global::runMode = Global::CoreOnly;
67   QCoreApplication app(argc, argv);
68 #elif defined BUILD_QTUI
69   Global::runMode = Global::ClientOnly;
70   QApplication app(argc, argv);
71 #else
72   Global::runMode = Global::Monolithic;
73   QApplication app(argc, argv);
74 #endif
75
76   // Set up i18n support
77   QLocale locale = QLocale::system();
78
79   QTranslator qtTranslator;
80   qtTranslator.load(QString(":i18n/qt_%1").arg(locale.name()));
81   app.installTranslator(&qtTranslator);
82
83   QTranslator quasselTranslator;
84   quasselTranslator.load(QString(":i18n/quassel_%1").arg(locale.name()));
85   app.installTranslator(&quasselTranslator);
86
87   QCoreApplication::setOrganizationDomain("quassel-irc.org");
88   QCoreApplication::setApplicationName("Quassel IRC");
89   QCoreApplication::setOrganizationName("Quassel Project");
90
91   // Check if a non-standard core port is requested
92   QStringList args = QCoreApplication::arguments();  // TODO Build a CLI parser
93
94   Global::defaultPort = 4242;
95   int idx;
96   if((idx = args.indexOf("-p")) > 0 && idx < args.count() - 1) {
97     int port = args[idx+1].toInt();
98     if(port >= 1024 && port < 65536) Global::defaultPort = port;
99   }
100
101 #ifndef BUILD_QTUI
102   Core::instance();  // create and init the core
103 #endif
104
105   //Settings::init();
106
107 #ifndef BUILD_CORE
108   QtUi *gui = new QtUi();
109   Client::init(gui);
110   // init gui only after the event loop has started
111   QTimer::singleShot(0, gui, SLOT(init()));
112   //gui->init();
113 #endif
114
115 #ifndef BUILD_QTUI
116   if(args.contains("--norestore")) {
117     Core::restoreState();
118   }
119 #endif
120
121   int exitCode = app.exec();
122
123 #ifndef BUILD_QTUI
124   Core::saveState();
125 #endif
126
127 #ifndef BUILD_CORE
128   // the mainWin has to be deleted before the Core
129   // if not Quassel will crash on exit under certain conditions since the gui
130   // still wants to access clientdata
131   delete gui;
132   Client::destroy();
133 #endif
134 #ifndef BUILD_QTUI
135   Core::destroy();
136 #endif
137
138   return exitCode;
139 }