Added ModelPropertyMapper which allows to keep track of /current/ changes in the...
[quassel.git] / src / common / main.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel IRC Development Team             *
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) any later version.                                   *
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 "settings.h"
22 #include <QString>
23 #include <QTranslator>
24
25 #if defined BUILD_CORE
26 #include <QCoreApplication>
27 #include <QDir>
28 #include "core.h"
29 #include "message.h"
30
31 #elif defined BUILD_QTUI
32 #include <QApplication>
33 #include "client.h"
34 #include "qtui.h"
35
36 #elif defined BUILD_MONO
37 #include <QApplication>
38 #include "client.h"
39 #include "core.h"
40 #include "coresession.h"
41 #include "qtui.h"
42
43 #else
44 #error "Something is wrong - you need to #define a build mode!"
45 #endif
46
47 #include <signal.h>
48
49 //! Signal handler for graceful shutdown.
50 void handle_signal(int sig) {
51   qWarning(QString("Caught signal %1 - exiting.").arg(sig).toAscii());
52   QCoreApplication::quit();
53 }
54
55 int main(int argc, char **argv) {
56   // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
57   signal(SIGTERM, handle_signal);
58   signal(SIGINT, handle_signal);
59
60   qRegisterMetaType<QVariant>("QVariant");
61   qRegisterMetaType<Message>("Message");
62   qRegisterMetaType<BufferInfo>("BufferInfo");
63   qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
64   qRegisterMetaTypeStreamOperators<Message>("Message");
65   qRegisterMetaTypeStreamOperators<BufferInfo>("BufferInfo");
66
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);
73 #else
74   Global::runMode = Global::Monolithic;
75   QApplication app(argc, argv);
76 #endif
77
78   //Just for testing
79   //QTranslator translator;
80   //translator.load(":i18n/quassel_de");
81   //app.installTranslator(&translator);
82
83             
84   QCoreApplication::setOrganizationDomain("quassel-irc.org");
85   QCoreApplication::setApplicationName("Quassel IRC");
86   QCoreApplication::setOrganizationName("Quassel IRC Development Team");
87
88   Global::quasselDir = QDir::homePath() + "/.quassel";
89 #ifndef BUILD_QTUI
90   Core::instance();  // create and init the core
91 #endif
92
93   //Settings::init();
94
95 #ifndef BUILD_CORE
96   QtUi *gui = new QtUi();
97   Client::init(gui);
98   gui->init();
99 #endif
100
101   int exitCode = app.exec();
102
103 #ifndef BUILD_CORE
104   // the mainWin has to be deleted before the Core
105   // if not Quassel will crash on exit under certain conditions since the gui
106   // still wants to access clientdata
107   delete gui;
108   Client::destroy();
109 #endif
110 #ifndef BUILD_QTUI
111   Core::destroy();
112 #endif
113
114   return exitCode;
115 }