48760d2dcd40157149c8c8839ed13ae9429c0f2b
[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
26 #if defined BUILD_CORE
27 #include <QCoreApplication>
28 #include "core.h"
29
30 #elif defined BUILD_QTGUI
31 #include <QApplication>
32 #include "style.h"
33 #include "client.h"
34 #include "clientproxy.h"
35 #include "mainwin.h"
36
37 #elif defined BUILD_MONO
38 #include <QApplication>
39 #include "core.h"
40 #include "coreproxy.h"
41 #include "style.h"
42 #include "client.h"
43 #include "clientproxy.h"
44 #include "mainwin.h"
45
46 #else
47 #error "Something is wrong - you need to #define a build mode!"
48 #endif
49
50 int main(int argc, char **argv) {
51 #if defined BUILD_CORE
52   Global::runMode = Global::CoreOnly;
53   QCoreApplication app(argc, argv);
54 #elif defined BUILD_QTGUI
55   Global::runMode = Global::ClientOnly;
56   QApplication app(argc, argv);
57 #else
58   Global::runMode = Global::Monolithic;
59   QApplication app(argc, argv);
60 #endif
61
62   QCoreApplication::setOrganizationDomain("quassel-irc.org");
63   QCoreApplication::setApplicationName("Quassel IRC");
64   QCoreApplication::setOrganizationName("Quassel IRC Development Team");
65
66   Global::quasselDir = QDir::homePath() + "/.quassel";
67   Core::instance();
68 #ifdef BUILD_MONO
69   QObject::connect(Core::localSession(), SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)), ClientProxy::instance(), SLOT(recv(CoreSignal, QVariant, QVariant, QVariant)));
70   QObject::connect(ClientProxy::instance(), SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), Core::localSession(), SLOT(processSignal(ClientSignal, QVariant, QVariant, QVariant)));
71 #endif
72
73   Settings::init();
74
75 #ifndef BUILD_CORE
76   Style::init();
77   MainWin *mainWin = new MainWin();
78   Client::init(mainWin);
79   mainWin->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 mainWin;
91   Client::destroy();
92 #endif
93 #ifndef BUILD_QTGUI
94   Core::destroy();
95 #endif
96
97   return exitCode;
98 }
99
100 #ifndef BUILD_CORE
101 void Client::syncToCore() {
102   //Q_ASSERT(Global::data("CoreReady").toBool());
103   coreBuffers = Core::localSession()->buffers();
104   // NOTE: We don't need to request server states, because in the monolithic version there can't be
105   //       any servers connected at this stage...
106 }
107 #endif