1 /***************************************************************************
2 * Copyright (C) 2005 by The Quassel Team *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
24 #include <QApplication>
29 #include "coreconnectdlg.h"
34 int main(int argc, char **argv) {
35 QApplication app(argc, argv);
36 QApplication::setOrganizationDomain("quassel-irc.org");
37 QApplication::setApplicationName("Quassel IRC");
38 QApplication::setOrganizationName("The Quassel Team");
40 Global::runMode = Global::GUIOnly;
41 Global::quasselDir = QDir::homePath() + "/.quassel";
43 global = new Global();
44 guiProxy = new GUIProxy();
49 int exitCode = app.exec();
54 void MainWin::syncToCore() {
55 Q_ASSERT(!global->getData("CoreReady").toBool());
56 // ok, we are running as standalone GUI
57 coreConnectDlg = new CoreConnectDlg(this);
58 if(coreConnectDlg->exec() != QDialog::Accepted) {
62 VarMap state = coreConnectDlg->getCoreState().toMap();
63 delete coreConnectDlg;
64 VarMap data = state["CoreData"].toMap();
66 foreach(key, data.keys()) {
67 global->updateData(key, data[key]);
69 if(!global->getData("CoreReady").toBool()) {
70 QMessageBox::critical(this, tr("Fatal Error"), tr("<b>Could not synchronize with Quassel Core!</b><br>Quassel GUI will be aborted."), QMessageBox::Abort);
74 foreach(QString net, state["CoreBackLog"].toMap().keys()) {
75 QByteArray logbuf = state["CoreBackLog"].toMap()[net].toByteArray();
76 QDataStream in(&logbuf, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_4_2);
78 Message msg; in >> msg;
79 coreBackLog[net].append(msg);
81 qDebug() << net << coreBackLog[net].count();
85 GUIProxy::GUIProxy() {
86 if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!");
90 connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData()));
91 connect(&socket, SIGNAL(connected()), this, SIGNAL(coreConnected()));
92 connect(&socket, SIGNAL(disconnected()), this, SIGNAL(coreDisconnected()));
93 connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError)));
95 connect(global, SIGNAL(dataPutLocally(QString)), this, SLOT(updateCoreData(QString)));
96 connect(this, SIGNAL(csUpdateGlobalData(QString, QVariant)), global, SLOT(updateData(QString, QVariant)));
100 void GUIProxy::connectToCore(QString host, quint16 port) {
101 socket.connectToHost(host, port);
104 void GUIProxy::disconnectFromCore() {
108 void GUIProxy::serverError(QAbstractSocket::SocketError) {
109 emit coreConnectionError(socket.errorString());
110 //qFatal(QString("Connection error: %1").arg(socket.errorString()).toAscii());
113 void GUIProxy::serverHasData() {
115 while(readDataFromDevice(&socket, blockSize, item)) {
116 emit recvPartialItem(1,1);
117 QList<QVariant> sigdata = item.toList();
118 Q_ASSERT(sigdata.size() == 4);
119 recv((CoreSignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]);
123 emit recvPartialItem(socket.bytesAvailable(), blockSize);
127 void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
128 QList<QVariant> sigdata;
129 sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3);
130 //qDebug() << "Sending signal: " << sigdata;
131 writeDataToDevice(&socket, QVariant(sigdata));
134 void GUIProxy::updateCoreData(QString key) {
135 QVariant data = global->getData(key);
136 send(GS_UPDATE_GLOBAL_DATA, key, data);