Added basic stuff for localization/internationalization (i18n).
[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_QTGUI
32 #include <QApplication>
33 #include "client.h"
34 #include "qtgui.h"
35 #include "style.h"
36
37 #elif defined BUILD_MONO
38 #include <QApplication>
39 #include "client.h"
40 #include "core.h"
41 #include "coresession.h"
42 #include "qtgui.h"
43 #include "style.h"
44
45 #else
46 #error "Something is wrong - you need to #define a build mode!"
47 #endif
48
49 #include <signal.h>
50
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();
55 }
56
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);
61
62   qRegisterMetaType<QVariant>("QVariant");
63   qRegisterMetaType<Message>("Message");
64   qRegisterMetaType<BufferId>("BufferId");
65   qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
66   qRegisterMetaTypeStreamOperators<Message>("Message");
67   qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
68
69 #if defined BUILD_CORE
70   Global::runMode = Global::CoreOnly;
71   QCoreApplication app(argc, argv);
72 #elif defined BUILD_QTGUI
73   Global::runMode = Global::ClientOnly;
74   QApplication app(argc, argv);
75 #else
76   Global::runMode = Global::Monolithic;
77   QApplication app(argc, argv);
78 #endif
79
80 /* Just for testing
81   QTranslator translator;
82   translator.load(":i18n/quassel_de");
83   app.installTranslator(&translator);
84 */
85             
86   QCoreApplication::setOrganizationDomain("quassel-irc.org");
87   QCoreApplication::setApplicationName("Quassel IRC");
88   QCoreApplication::setOrganizationName("Quassel IRC Development Team");
89
90   Global::quasselDir = QDir::homePath() + "/.quassel";
91 #ifndef BUILD_QTGUI
92   Core::instance();  // create and init the core
93 #endif
94
95   //Settings::init();
96
97 #ifndef BUILD_CORE
98   Style::init();
99   QtGui *gui = new QtGui();
100   Client::init(gui);
101   gui->init();
102 #endif
103
104   int exitCode = app.exec();
105
106 #ifndef BUILD_CORE
107   // the mainWin has to be deleted before the Core
108   // if not Quassel will crash on exit under certain conditions since the gui
109   // still wants to access clientdata
110   delete gui;
111   Client::destroy();
112 #endif
113 #ifndef BUILD_QTGUI
114   Core::destroy();
115 #endif
116
117   return exitCode;
118 }
119
120 #ifdef BUILD_QTGUI
121 QVariant Client::connectToLocalCore(QString, QString) { return QVariant(); }
122 void Client::disconnectFromLocalCore() {}
123
124 #elif defined BUILD_MONO
125 QVariant Client::connectToLocalCore(QString user, QString passwd) {
126   // TODO catch exceptions
127   /*
128   QVariant reply = Core::connectLocalClient(user, passwd);
129   QObject::connect(Core::localSession(), SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)), ClientProxy::instance(), SLOT(recv(CoreSignal, QVariant, QVariant, QVariant)));
130   QObject::connect(ClientProxy::instance(), SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), Core::localSession(), SLOT(processSignal(ClientSignal, QVariant, QVariant, QVariant)));
131   return reply;
132   */
133   return QVariant();
134 }
135
136 void Client::disconnectFromLocalCore() {
137   /*
138   disconnect(Core::localSession(), 0, ClientProxy::instance(), 0);
139   disconnect(ClientProxy::instance(), 0, Core::localSession(), 0);
140   Core::disconnectLocalClient();
141   */
142 }
143
144 #endif