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"
31 #include "chatwidget.h"
35 int main(int argc, char **argv) {
36 QApplication app(argc, argv);
37 QApplication::setOrganizationDomain("quassel-irc.org");
38 QApplication::setApplicationName("Quassel IRC");
39 QApplication::setOrganizationName("The Quassel Team");
41 Global::runMode = Global::GUIOnly;
42 Global::quasselDir = QDir::homePath() + "/.quassel";
44 global = new Global();
45 guiProxy = new GuiProxy();
51 int exitCode = app.exec();
57 void MainWin::syncToCore() {
58 Q_ASSERT(!global->getData("CoreReady").toBool());
59 // ok, we are running as standalone GUI
60 coreConnectDlg = new CoreConnectDlg(this);
61 if(coreConnectDlg->exec() != QDialog::Accepted) {
65 VarMap state = coreConnectDlg->getCoreState().toMap();
66 delete coreConnectDlg;
67 VarMap data = state["CoreData"].toMap();
69 foreach(key, data.keys()) {
70 global->updateData(key, data[key]);
72 if(!global->getData("CoreReady").toBool()) {
73 QMessageBox::critical(this, tr("Fatal Error"), tr("<b>Could not synchronize with Quassel Core!</b><br>Quassel GUI will be aborted."), QMessageBox::Abort);
78 foreach(QString net, state["CoreBackLog"].toMap().keys()) {
79 QByteArray logbuf = state["CoreBackLog"].toMap()[net].toByteArray();
80 QDataStream in(&logbuf, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_4_2);
82 Message msg; in >> msg;
83 coreBackLog[net].append(msg);
85 qDebug() << net << coreBackLog[net].count();
89 foreach(QVariant v, state["CoreBuffers"].toList()) { coreBuffers.append(v.value<BufferId>()); }
94 GuiProxy::GuiProxy() {
95 if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!");
99 connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData()));
100 connect(&socket, SIGNAL(connected()), this, SIGNAL(coreConnected()));
101 connect(&socket, SIGNAL(disconnected()), this, SIGNAL(coreDisconnected()));
102 connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError)));
104 connect(global, SIGNAL(dataPutLocally(QString)), this, SLOT(updateCoreData(QString)));
105 connect(this, SIGNAL(csUpdateGlobalData(QString, QVariant)), global, SLOT(updateData(QString, QVariant)));
109 void GuiProxy::connectToCore(QString host, quint16 port) {
110 socket.connectToHost(host, port);
113 void GuiProxy::disconnectFromCore() {
117 void GuiProxy::serverError(QAbstractSocket::SocketError) {
118 emit coreConnectionError(socket.errorString());
119 //qFatal(QString("Connection error: %1").arg(socket.errorString()).toAscii());
122 void GuiProxy::serverHasData() {
124 while(readDataFromDevice(&socket, blockSize, item)) {
125 emit recvPartialItem(1,1);
126 QList<QVariant> sigdata = item.toList();
127 Q_ASSERT(sigdata.size() == 4);
128 recv((CoreSignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]);
132 emit recvPartialItem(socket.bytesAvailable(), blockSize);
137 void GuiProxy::send(GuiSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
138 QList<QVariant> sigdata;
139 sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3);
140 //qDebug() << "Sending signal: " << sigdata;
141 writeDataToDevice(&socket, QVariant(sigdata));
145 void GuiProxy::updateCoreData(QString key) {
146 QVariant data = global->getData(key);
147 send(GS_UPDATE_GLOBAL_DATA, key, data);