Still working on the authentification stuff. Technically, now even in the monolithic...
[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 <iostream>
22
23 #include "global.h"
24 #include "settings.h"
25 #include "quasselui.h"
26
27 #if defined BUILD_CORE
28 #include <QCoreApplication>
29 #include "core.h"
30
31 #elif defined BUILD_QTGUI
32 #include <QApplication>
33 #include "style.h"
34 #include "client.h"
35 #include "clientproxy.h"
36 #include "mainwin.h"
37
38 #elif defined BUILD_MONO
39 #include <QApplication>
40 #include "core.h"
41 #include "coreproxy.h"
42 #include "style.h"
43 #include "client.h"
44 #include "clientproxy.h"
45 #include "mainwin.h"
46
47 #else
48 #error "Something is wrong - you need to #define a build mode!"
49 #endif
50
51 int main(int argc, char **argv) {
52 #if defined BUILD_CORE
53   Global::runMode = Global::CoreOnly;
54   QCoreApplication app(argc, argv);
55 #elif defined BUILD_QTGUI
56   Global::runMode = Global::ClientOnly;
57   QApplication app(argc, argv);
58 #else
59   Global::runMode = Global::Monolithic;
60   QApplication app(argc, argv);
61 #endif
62   //AbstractUi *foo = new AbstractUi();
63   //foo->init();
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   AbstractUi foo;  // This avoids an annoying linker error (bug?) where AbstractUi's vtable is not found.
78                    // Yes, it's fugly. Yes, I'd like an alternative.
79   QtGui *gui = new QtGui();
80   Client::init(gui);
81   gui->init();
82 //#else
83 //  Core::instance(); // create and init the core object
84 #endif
85
86   int exitCode = app.exec();
87
88 #ifndef BUILD_CORE
89   // the mainWin has to be deleted before the Core
90   // if not Quassel will crash on exit under certain conditions since the gui
91   // still wants to access clientdata
92   delete gui;
93   Client::destroy();
94 #endif
95 #ifndef BUILD_QTGUI
96   Core::destroy();
97 #endif
98
99   return exitCode;
100 }
101
102 #ifdef BUILD_QTGUI
103 QVariant Client::connectToLocalCore(QString, QString) { return QVariant(); }
104 void Client::disconnectFromLocalCore() {}
105 #elif defined BUILD_MONO
106
107 QVariant Client::connectToLocalCore(QString user, QString passwd) {
108   // TODO catch exceptions
109   QVariant reply = Core::connectLocalClient(user, passwd);
110   QObject::connect(Core::localSession(), SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)), ClientProxy::instance(), SLOT(recv(CoreSignal, QVariant, QVariant, QVariant)));
111   QObject::connect(ClientProxy::instance(), SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), Core::localSession(), SLOT(processSignal(ClientSignal, QVariant, QVariant, QVariant)));
112   return reply;
113 }
114
115 void Client::disconnectFromLocalCore() {
116   disconnect(Core::localSession(), 0, ClientProxy::instance(), 0);
117   disconnect(ClientProxy::instance(), 0, Core::localSession(), 0);
118   Core::disconnectLocalClient();
119 }
120
121 #endif