Undoing my recent bullshit... -.-
[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
24 #if defined BUILD_CORE
25 #include <QCoreApplication>
26 #include <QDir>
27 #include "core.h"
28 #include "message.h"
29
30 #elif defined BUILD_QTGUI
31 #include <QApplication>
32 #include "client.h"
33 #include "qtgui.h"
34 #include "style.h"
35
36 #elif defined BUILD_MONO
37 #include <QApplication>
38 #include "client.h"
39 #include "core.h"
40 #include "coresession.h"
41 #include "qtgui.h"
42 #include "style.h"
43
44 #else
45 #error "Something is wrong - you need to #define a build mode!"
46 #endif
47
48 #include <signal.h>
49
50 //! Signal handler for graceful shutdown.
51 void handle_signal(int sig) {
52   qWarning(QString("Caught signal %1 - exiting.").arg(sig).toAscii());
53   QCoreApplication::quit();
54 }
55
56 int main(int argc, char **argv) {
57   // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
58   signal(SIGTERM, handle_signal);
59   signal(SIGINT, handle_signal);
60
61   qRegisterMetaType<QVariant>("QVariant");
62   qRegisterMetaType<Message>("Message");
63   qRegisterMetaType<BufferId>("BufferId");
64   qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
65   qRegisterMetaTypeStreamOperators<Message>("Message");
66   qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
67
68 #if defined BUILD_CORE
69   Global::runMode = Global::CoreOnly;
70   QCoreApplication app(argc, argv);
71 #elif defined BUILD_QTGUI
72   Global::runMode = Global::ClientOnly;
73   QApplication app(argc, argv);
74 #else
75   Global::runMode = Global::Monolithic;
76   QApplication app(argc, argv);
77 #endif
78   QCoreApplication::setOrganizationDomain("quassel-irc.org");
79   QCoreApplication::setApplicationName("Quassel IRC");
80   QCoreApplication::setOrganizationName("Quassel IRC Development Team");
81
82   Global::quasselDir = QDir::homePath() + "/.quassel";
83 #ifndef BUILD_QTGUI
84   Core::instance();  // create and init the core
85 #endif
86
87   //Settings::init();
88
89 #ifndef BUILD_CORE
90   Style::init();
91   QtGui *gui = new QtGui();
92   Client::init(gui);
93   gui->init();
94 #endif
95
96   int exitCode = app.exec();
97
98 #ifndef BUILD_CORE
99   // the mainWin has to be deleted before the Core
100   // if not Quassel will crash on exit under certain conditions since the gui
101   // still wants to access clientdata
102   delete gui;
103   Client::destroy();
104 #endif
105 #ifndef BUILD_QTGUI
106   Core::destroy();
107 #endif
108
109   return exitCode;
110 }
111
112 #ifdef BUILD_QTGUI
113 QVariant Client::connectToLocalCore(QString, QString) { return QVariant(); }
114 void Client::disconnectFromLocalCore() {}
115
116 #elif defined BUILD_MONO
117 QVariant Client::connectToLocalCore(QString user, QString passwd) {
118   // TODO catch exceptions
119   /*
120   QVariant reply = Core::connectLocalClient(user, passwd);
121   QObject::connect(Core::localSession(), SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)), ClientProxy::instance(), SLOT(recv(CoreSignal, QVariant, QVariant, QVariant)));
122   QObject::connect(ClientProxy::instance(), SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), Core::localSession(), SLOT(processSignal(ClientSignal, QVariant, QVariant, QVariant)));
123   return reply;
124   */
125   return QVariant();
126 }
127
128 void Client::disconnectFromLocalCore() {
129   /*
130   disconnect(Core::localSession(), 0, ClientProxy::instance(), 0);
131   disconnect(ClientProxy::instance(), 0, Core::localSession(), 0);
132   Core::disconnectLocalClient();
133   */
134 }
135
136 #endif