Yay! After months, distributed client/core operation is working again!
[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
23 #if defined BUILD_CORE
24 #include <QCoreApplication>
25 #include <QDir>
26 #include "core.h"
27
28 #elif defined BUILD_QTGUI
29 #include <QApplication>
30 #include "client.h"
31 #include "clientproxy.h"
32 #include "qtgui.h"
33 #include "style.h"
34
35 #elif defined BUILD_MONO
36 #include <QApplication>
37 #include "client.h"
38 #include "clientproxy.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 int main(int argc, char **argv) {
49   qRegisterMetaType<Message>("Message");
50   qRegisterMetaType<BufferId>("BufferId");
51   qRegisterMetaTypeStreamOperators<Message>("Message");
52   qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
53
54 #if defined BUILD_CORE
55   Global::runMode = Global::CoreOnly;
56   QCoreApplication app(argc, argv);
57 #elif defined BUILD_QTGUI
58   Global::runMode = Global::ClientOnly;
59   QApplication app(argc, argv);
60 #else
61   Global::runMode = Global::Monolithic;
62   QApplication app(argc, argv);
63 #endif
64   QCoreApplication::setOrganizationDomain("quassel-irc.org");
65   QCoreApplication::setApplicationName("Quassel IRC");
66   QCoreApplication::setOrganizationName("Quassel IRC Development Team");
67
68   Global::quasselDir = QDir::homePath() + "/.quassel";
69 #ifndef BUILD_QTGUI
70   Core::instance();  // create and init the core
71 #endif
72
73   //Settings::init();
74
75 #ifndef BUILD_CORE
76   Style::init();
77   QtGui *gui = new QtGui();
78   Client::init(gui);
79   gui->init();
80 #endif
81
82   int exitCode = app.exec();
83
84 #ifndef BUILD_CORE
85   // the mainWin has to be deleted before the Core
86   // if not Quassel will crash on exit under certain conditions since the gui
87   // still wants to access clientdata
88   delete gui;
89   Client::destroy();
90 #endif
91 #ifndef BUILD_QTGUI
92   Core::destroy();
93 #endif
94
95   return exitCode;
96 }
97
98 #ifdef BUILD_QTGUI
99 QVariant Client::connectToLocalCore(QString, QString) { return QVariant(); }
100 void Client::disconnectFromLocalCore() {}
101
102 #elif defined BUILD_MONO
103 QVariant Client::connectToLocalCore(QString user, QString passwd) {
104   // TODO catch exceptions
105   QVariant reply = Core::connectLocalClient(user, passwd);
106   QObject::connect(Core::localSession(), SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)), ClientProxy::instance(), SLOT(recv(CoreSignal, QVariant, QVariant, QVariant)));
107   QObject::connect(ClientProxy::instance(), SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), Core::localSession(), SLOT(processSignal(ClientSignal, QVariant, QVariant, QVariant)));
108   return reply;
109 }
110
111 void Client::disconnectFromLocalCore() {
112   disconnect(Core::localSession(), 0, ClientProxy::instance(), 0);
113   disconnect(ClientProxy::instance(), 0, Core::localSession(), 0);
114   Core::disconnectLocalClient();
115 }
116
117 #endif