Some more filename changes. Should be it for now.
[quassel.git] / main / main_gui.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005 by The Quassel 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 <QApplication>
24
25 #include "global.h"
26 #include "guiproxy.h"
27 #include "util.h"
28
29 #include "mainwin.h"
30
31 int main(int argc, char **argv) {
32   QApplication app(argc, argv);
33   QApplication::setOrganizationDomain("quassel-irc.org");
34   QApplication::setApplicationName("Quassel IRC");
35   QApplication::setOrganizationName("The Quassel Team");
36
37   Global::runMode = Global::GUIOnly;
38   global = new Global();
39   guiProxy = new GUIProxy();
40
41   MainWin mainWin;
42   int exitCode = app.exec();
43   delete guiProxy;
44   delete global;
45 }
46
47 GUIProxy::GUIProxy() {
48   if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!");
49
50   blockSize = 0;
51
52   connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData()));
53   connect(&socket, SIGNAL(connected()), this, SIGNAL(coreConnected()));
54   connect(&socket, SIGNAL(disconnected()), this, SIGNAL(coreDisconnected()));
55   connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError)));
56
57   connect(global, SIGNAL(dataPutLocally(QString)), this, SLOT(updateCoreData(QString)));
58   connect(this, SIGNAL(csUpdateGlobalData(QString, QVariant)), global, SLOT(updateData(QString, QVariant)));
59
60 }
61
62 void GUIProxy::connectToCore(QString host, quint16 port) {
63   socket.connectToHost(host, port);
64   //VarMap initmsg;
65   //initmsg["GUIProtocol"] = GUI_PROTOCOL;
66   //send(GS_CLIENT_INIT, QVariant(initmsg));
67 }
68
69 void GUIProxy::disconnectFromCore() {
70   socket.close();
71 }
72
73 void GUIProxy::serverError(QAbstractSocket::SocketError) {
74   emit coreConnectionError(socket.errorString());
75 }
76
77 void GUIProxy::serverHasData() {
78   QVariant item;
79   while(readDataFromDevice(&socket, blockSize, item)) {
80     emit recvPartialItem(1,1);
81     QList<QVariant> sigdata = item.toList();
82     Q_ASSERT(sigdata.size() == 4);
83     recv((CoreSignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]);
84     blockSize = 0;
85   }
86   if(blockSize > 0) {
87     emit recvPartialItem(socket.bytesAvailable(), blockSize);
88   }
89 }
90
91 void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
92   QList<QVariant> sigdata;
93   sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3);
94   //qDebug() << "Sending signal: " << sigdata;
95   writeDataToDevice(&socket, QVariant(sigdata));
96 }
97
98 void GUIProxy::updateCoreData(QString key) {
99   QVariant data = global->getData(key);
100   send(GS_UPDATE_GLOBAL_DATA, key, data);
101 }