Fixed a problem where cmake apparently didn't get all deps right and screwed up by...
[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   QtGui *gui = new QtGui();
78   Client::init(gui);
79   gui->init();
80 //#else
81 //  Core::instance(); // create and init the core object
82 #endif
83
84   int exitCode = app.exec();
85
86 #ifndef BUILD_CORE
87   // the mainWin has to be deleted before the Core
88   // if not Quassel will crash on exit under certain conditions since the gui
89   // still wants to access clientdata
90   delete gui;
91   Client::destroy();
92 #endif
93 #ifndef BUILD_QTGUI
94   Core::destroy();
95 #endif
96
97   return exitCode;
98 }
99
100 #ifdef BUILD_QTGUI
101 QVariant Client::connectToLocalCore(QString, QString) { return QVariant(); }
102 void Client::disconnectFromLocalCore() {}
103 #elif defined BUILD_MONO
104
105 QVariant Client::connectToLocalCore(QString user, QString passwd) {
106   // TODO catch exceptions
107   QVariant reply = Core::connectLocalClient(user, passwd);
108   QObject::connect(Core::localSession(), SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)), ClientProxy::instance(), SLOT(recv(CoreSignal, QVariant, QVariant, QVariant)));
109   QObject::connect(ClientProxy::instance(), SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), Core::localSession(), SLOT(processSignal(ClientSignal, QVariant, QVariant, QVariant)));
110   return reply;
111 }
112
113 void Client::disconnectFromLocalCore() {
114   disconnect(Core::localSession(), 0, ClientProxy::instance(), 0);
115   disconnect(ClientProxy::instance(), 0, Core::localSession(), 0);
116   Core::disconnectLocalClient();
117 }
118
119 #endif