Refactoring the GUI. Work in progress.
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 19 Jun 2007 22:09:28 +0000 (22:09 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 19 Jun 2007 22:09:28 +0000 (22:09 +0000)
20 files changed:
core/core.cpp
core/core.h
core/coreproxy.cpp
core/coreproxy.h
core/server.cpp
gui/CMakeLists.txt
gui/bufferview.cpp
gui/bufferview.h
gui/bufferviewwidget.cpp
gui/coreconnectdlg.cpp
gui/gui.cpp [new file with mode: 0644]
gui/gui.h [new file with mode: 0644]
gui/guiproxy.cpp
gui/guiproxy.h
gui/mainwin.cpp
gui/mainwin.h
gui/serverlist.cpp
main/main_gui.cpp
main/main_mono.cpp
main/proxy_common.h

index 2a8d4cc..a3dcd26 100644 (file)
@@ -94,7 +94,7 @@ CoreSession *Core::session(UserId uid) {
   else return 0;
 }
 
   else return 0;
 }
 
-CoreSession *Core::guiSession() {
+CoreSession *Core::localSession() {
   Core *core = instance();
   if(core->guiUser && core->sessions.contains(core->guiUser)) return core->sessions[core->guiUser];
   else return 0;
   Core *core = instance();
   if(core->guiUser && core->sessions.contains(core->guiUser)) return core->sessions[core->guiUser];
   else return 0;
@@ -141,10 +141,10 @@ void Core::clientHasData() {
   while(readDataFromDevice(socket, bsize, item)) {
     if(validClients.contains(socket)) {
       QList<QVariant> sigdata = item.toList();
   while(readDataFromDevice(socket, bsize, item)) {
     if(validClients.contains(socket)) {
       QList<QVariant> sigdata = item.toList();
-      if((GUISignal)sigdata[0].toInt() == GS_UPDATE_GLOBAL_DATA) {
+      if((ClientSignal)sigdata[0].toInt() == GS_UPDATE_GLOBAL_DATA) {
         processClientUpdate(socket, sigdata[1].toString(), sigdata[2]);
       } else {
         processClientUpdate(socket, sigdata[1].toString(), sigdata[2]);
       } else {
-        sessions[validClients[socket]]->processSignal((GUISignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]);
+        sessions[validClients[socket]]->processSignal((ClientSignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]);
       }
     } else {
       // we need to auth the client
       }
     } else {
       // we need to auth the client
@@ -280,7 +280,7 @@ UserId CoreSession::userId() {
   return user;
 }
 
   return user;
 }
 
-void CoreSession::processSignal(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+void CoreSession::processSignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
   coreProxy->recv(sig, arg1, arg2, arg3);
 }
 
   coreProxy->recv(sig, arg1, arg2, arg3);
 }
 
index c4a6646..126e3a5 100644 (file)
@@ -40,7 +40,7 @@ class Core : public QObject {
     static void destroy();
 
     static CoreSession * session(UserId);
     static void destroy();
 
     static CoreSession * session(UserId);
-    static CoreSession * guiSession();
+    static CoreSession * localSession();
     static CoreSession * createSession(UserId);
 
   private slots:
     static CoreSession * createSession(UserId);
 
   private slots:
@@ -84,7 +84,7 @@ class CoreSession : public QObject {
 
   public slots:
     void connectToIrc(QStringList);
 
   public slots:
     void connectToIrc(QStringList);
-    void processSignal(GUISignal, QVariant, QVariant, QVariant);
+    void processSignal(ClientSignal, QVariant, QVariant, QVariant);
     void sendBacklog(BufferId, QVariant, QVariant);
     void msgFromGui(BufferId, QString message);
     void sendServerStates();
     void sendBacklog(BufferId, QVariant, QVariant);
     void msgFromGui(BufferId, QString message);
     void sendServerStates();
index c6325ee..ee9ea2d 100644 (file)
@@ -60,7 +60,7 @@ void CoreProxy::send(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3
 }
 */
 
 }
 */
 
-void CoreProxy::recv(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+void CoreProxy::recv(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
   //qDebug() << "[CORE] Received signal" << sig << ":" << arg1<<arg2<<arg3;
   switch(sig) {
     case GS_UPDATE_GLOBAL_DATA: emit gsPutGlobalData(arg1.toString(), arg2); break;
   //qDebug() << "[CORE] Received signal" << sig << ":" << arg1<<arg2<<arg3;
   switch(sig) {
     case GS_UPDATE_GLOBAL_DATA: emit gsPutGlobalData(arg1.toString(), arg2); break;
index e060c45..071f651 100644 (file)
@@ -30,7 +30,7 @@
 #include <QTcpServer>
 
 /** This class is the Core side of the proxy. The Core connects its signals and slots to it,
 #include <QTcpServer>
 
 /** This class is the Core side of the proxy. The Core connects its signals and slots to it,
- *  and the calls are marshalled and sent to (or received and unmarshalled from) the GUIProxy.
+ *  and the calls are marshalled and sent to (or received and unmarshalled from) the GuiProxy.
  *  The connection functions are defined in main/main_core.cpp or main/main_mono.cpp.
  */
 class CoreProxy : public QObject {
  *  The connection functions are defined in main/main_core.cpp or main/main_mono.cpp.
  */
 class CoreProxy : public QObject {
@@ -66,7 +66,7 @@ class CoreProxy : public QObject {
     void gsImportBacklog();
     void gsRequestBacklog(BufferId, QVariant, QVariant);
 
     void gsImportBacklog();
     void gsRequestBacklog(BufferId, QVariant, QVariant);
 
-    void gsGeneric(GUISignal, QVariant, QVariant, QVariant);
+    void gsGeneric(ClientSignal, QVariant, QVariant, QVariant);
 
     void requestServerStates();
 
 
     void requestServerStates();
 
@@ -74,7 +74,7 @@ class CoreProxy : public QObject {
 
   public:
     //void send(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
 
   public:
     //void send(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
-    void recv(GUISignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
+    void recv(ClientSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
 
   private:
     void processClientUpdate(QTcpSocket *, QString key, QVariant data);
 
   private:
     void processClientUpdate(QTcpSocket *, QString key, QVariant data);
@@ -82,7 +82,7 @@ class CoreProxy : public QObject {
 
   private:
 
 
   private:
 
-  friend class GUIProxy;
+  friend class GuiProxy;
 };
 
 //extern CoreProxy *coreProxy;
 };
 
 //extern CoreProxy *coreProxy;
index ca878d1..e5ed4eb 100644 (file)
@@ -879,7 +879,8 @@ void Server::handleCtcpPing(CtcpType ctcptype, QString prefix, QString target, Q
 void Server::handleCtcpVersion(CtcpType ctcptype, QString prefix, QString target, QString param) {
   if(ctcptype == CtcpQuery) {
     // FIXME use real Info about quassel :)
 void Server::handleCtcpVersion(CtcpType ctcptype, QString prefix, QString target, QString param) {
   if(ctcptype == CtcpQuery) {
     // FIXME use real Info about quassel :)
-    ctcpReply(nickFromMask(prefix), "VERSION", QString("Quassel:pre Release:*nix"));
+    //ctcpReply(nickFromMask(prefix), "VERSION", QString("Quassel:pre Release:*nix"));
+    ctcpReply(nickFromMask(prefix), "VERSION", QString("Quassel IRC (Pre-Release) - http://www.quassel-irc.org"));
     emit displayMsg(Message::Server, "", tr("Received CTCP VERSION request by %1").arg(prefix));
   } else {
     // TODO display Version answer
     emit displayMsg(Message::Server, "", tr("Received CTCP VERSION request by %1").arg(prefix));
   } else {
     // TODO display Version answer
index f118eae..d651be0 100644 (file)
@@ -1,7 +1,7 @@
-SET(gui_SRCS chatwidget.cpp channelwidgetinput.cpp tabcompleter.cpp mainwin.cpp serverlist.cpp buffer.cpp bufferwidget.cpp
+SET(gui_SRCS gui.cpp chatwidget.cpp channelwidgetinput.cpp tabcompleter.cpp mainwin.cpp serverlist.cpp buffer.cpp bufferwidget.cpp
              identities.cpp coreconnectdlg.cpp guiproxy.cpp bufferview.cpp bufferviewwidget.cpp style.cpp settingsdlg.cpp settingspages.cpp)
 SET(gui_HDRS style.h)
              identities.cpp coreconnectdlg.cpp guiproxy.cpp bufferview.cpp bufferviewwidget.cpp style.cpp settingsdlg.cpp settingspages.cpp)
 SET(gui_HDRS style.h)
-SET(gui_MOCS chatwidget.h channelwidgetinput.h tabcompleter.h mainwin.h serverlist.h identities.h coreconnectdlg.h
+SET(gui_MOCS gui.h chatwidget.h channelwidgetinput.h tabcompleter.h mainwin.h serverlist.h identities.h coreconnectdlg.h
              guiproxy.h bufferview.h buffer.h bufferwidget.h bufferviewwidget.h settingsdlg.h settingspages.h)
 SET(gui_UICS identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui mainwin.ui
              nickeditdlg.ui serverlistdlg.ui servereditdlg.ui coreconnectdlg.ui ircwidget.ui
              guiproxy.h bufferview.h buffer.h bufferwidget.h bufferviewwidget.h settingsdlg.h settingspages.h)
 SET(gui_UICS identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui mainwin.ui
              nickeditdlg.ui serverlistdlg.ui servereditdlg.ui coreconnectdlg.ui ircwidget.ui
index 68b7f31..017ce25 100644 (file)
@@ -110,6 +110,6 @@ void BufferView::dragEnterEvent(QDragEnterEvent *event) {
 }
 
 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
 }
 
 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
-  if(parent.parent() == QModelIndex()) setExpanded(parent, true);
+  if(parent.parent() == QModelIndex()) setExpanded(parent, true); qDebug() << "expanded";
   QTreeView::rowsInserted(parent, start, end);
 }
   QTreeView::rowsInserted(parent, start, end);
 }
index 6fcadf8..9daee9f 100644 (file)
@@ -78,7 +78,7 @@ class BufferView : public QTreeView {
   
     void dragEnterEvent(QDragEnterEvent *);
 
   
     void dragEnterEvent(QDragEnterEvent *);
 
-  protected:
+  protected slots:
     void rowsInserted (const QModelIndex & parent, int start, int end);
 };
 
     void rowsInserted (const QModelIndex & parent, int start, int end);
 };
 
index e21b98b..04331c3 100644 (file)
@@ -155,7 +155,7 @@ BufferTreeModel::BufferTreeModel(QObject *parent) : QAbstractItemModel(parent) {
   rootData << "Buffer" << "Network";
   rootItem = new TreeItem(rootData, 0);
   
   rootData << "Buffer" << "Network";
   rootItem = new TreeItem(rootData, 0);
   
-  connect(this, SIGNAL(fakeUserInput(BufferId, QString)), guiProxy, SLOT(gsUserInput(BufferId, QString)));
+  connect(this, SIGNAL(fakeUserInput(BufferId, QString)), ClientProxy::instance(), SLOT(gsUserInput(BufferId, QString)));
 }
 
 BufferTreeModel::~BufferTreeModel() {
 }
 
 BufferTreeModel::~BufferTreeModel() {
@@ -291,11 +291,11 @@ QModelIndex BufferTreeModel::getOrCreateBufferItemIndex(Buffer *buffer) {
     TreeItem *networkItem = static_cast<TreeItem*>(networkItemIndex.internalPointer());
 
     int nextRow = networkItem->childCount();
     TreeItem *networkItem = static_cast<TreeItem*>(networkItemIndex.internalPointer());
 
     int nextRow = networkItem->childCount();
-    
+
     beginInsertRows(networkItemIndex, nextRow, nextRow);
     networkItem->appendChild(new BufferTreeItem(buffer, networkItem));
     endInsertRows();
     beginInsertRows(networkItemIndex, nextRow, nextRow);
     networkItem->appendChild(new BufferTreeItem(buffer, networkItem));
     endInsertRows();
-                         
+
     bufferItem[buffer] = static_cast<BufferTreeItem *>(networkItem->child(nextRow));
     return index(nextRow, 0, networkItemIndex);
   }
     bufferItem[buffer] = static_cast<BufferTreeItem *>(networkItem->child(nextRow));
     return index(nextRow, 0, networkItemIndex);
   }
@@ -334,13 +334,14 @@ bool BufferTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
   if(sourceBuffer == targetBuffer) // we won't merge with ourself :)
     return false;
   
   if(sourceBuffer == targetBuffer) // we won't merge with ourself :)
     return false;
   
-  
+  /*
   if(QMessageBox::warning(static_cast<QWidget *>(QObject::parent()),
                           tr("Merge Buffers?"),
                           tr("Do you really want to merge the following Buffers?<br />%1.%2<br />%3.%4").arg(sourceBuffer->networkName()).arg(sourceBuffer->bufferName()).arg(targetBuffer->networkName()).arg(targetBuffer->bufferName()),
                           QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
     return false;
   if(QMessageBox::warning(static_cast<QWidget *>(QObject::parent()),
                           tr("Merge Buffers?"),
                           tr("Do you really want to merge the following Buffers?<br />%1.%2<br />%3.%4").arg(sourceBuffer->networkName()).arg(sourceBuffer->bufferName()).arg(targetBuffer->networkName()).arg(targetBuffer->bufferName()),
                           QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
     return false;
-    
+
+  */
   qDebug() << "merging" << sourceBuffer->bufferName() << "with" << targetBuffer->bufferName();
   bufferItem.remove(getBufferByIndex(parent));
   removeRow(parent.row(), BufferTreeModel::parent(parent));
   qDebug() << "merging" << sourceBuffer->bufferName() << "with" << targetBuffer->bufferName();
   bufferItem.remove(getBufferByIndex(parent));
   removeRow(parent.row(), BufferTreeModel::parent(parent));
index b465ae1..c0ca480 100644 (file)
@@ -22,6 +22,7 @@
 #include "coreconnectdlg.h"
 #include "guiproxy.h"
 #include "global.h"
 #include "coreconnectdlg.h"
 #include "guiproxy.h"
 #include "global.h"
+#include "gui.h"
 
 CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) {
   ui.setupUi(this);
 
 CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) {
   ui.setupUi(this);
@@ -56,9 +57,9 @@ void CoreConnectDlg::hostSelected() {
   ui.hostName->hide(); ui.hostPort->hide(); ui.hostLabel->hide(); ui.portLabel->hide();
   ui.statusText->setText(tr("Connecting to %1:%2" ).arg(ui.hostName->text()).arg(ui.hostPort->value()));
   ui.buttonBox->button(QDialogButtonBox::Ok)->hide();
   ui.hostName->hide(); ui.hostPort->hide(); ui.hostLabel->hide(); ui.portLabel->hide();
   ui.statusText->setText(tr("Connecting to %1:%2" ).arg(ui.hostName->text()).arg(ui.hostPort->value()));
   ui.buttonBox->button(QDialogButtonBox::Ok)->hide();
-  connect(guiProxy, SIGNAL(coreConnected()), this, SLOT(coreConnected()));
-  connect(guiProxy, SIGNAL(coreConnectionError(QString)), this, SLOT(coreConnectionError(QString)));
-  guiProxy->connectToCore(ui.hostName->text(), ui.hostPort->value());
+  connect(ClientProxy::instance(), SIGNAL(coreConnected()), this, SLOT(coreConnected()));
+  connect(ClientProxy::instance(), SIGNAL(coreConnectionError(QString)), this, SLOT(coreConnectionError(QString)));
+  Client::instance()->connectToCore(ui.hostName->text(), ui.hostPort->value());
 
 }
 
 
 }
 
@@ -69,8 +70,8 @@ void CoreConnectDlg::coreConnected() {
   s.setValue("GUI/CoreHost", ui.hostName->text());
   s.setValue("GUI/CorePort", ui.hostPort->value());
   s.setValue("GUI/CoreAutoConnect", ui.autoConnect->isChecked());
   s.setValue("GUI/CoreHost", ui.hostName->text());
   s.setValue("GUI/CorePort", ui.hostPort->value());
   s.setValue("GUI/CoreAutoConnect", ui.autoConnect->isChecked());
-  connect(guiProxy, SIGNAL(recvPartialItem(quint32, quint32)), this, SLOT(updateProgressBar(quint32, quint32)));
-  connect(guiProxy, SIGNAL(csCoreState(QVariant)), this, SLOT(recvCoreState(QVariant)));
+  connect(ClientProxy::instance(), SIGNAL(recvPartialItem(quint32, quint32)), this, SLOT(updateProgressBar(quint32, quint32)));
+  connect(ClientProxy::instance(), SIGNAL(csCoreState(QVariant)), this, SLOT(recvCoreState(QVariant)));
   ui.progressBar->show();
   VarMap initmsg;
   initmsg["GUIProtocol"] = GUI_PROTOCOL;
   ui.progressBar->show();
   VarMap initmsg;
   initmsg["GUIProtocol"] = GUI_PROTOCOL;
@@ -79,7 +80,7 @@ void CoreConnectDlg::coreConnected() {
 
 void CoreConnectDlg::coreConnectionError(QString err) {
   QMessageBox::warning(this, tr("Connection Error"), tr("<b>Could not connect to Quassel Core!</b><br>\n") + err, QMessageBox::Retry);
 
 void CoreConnectDlg::coreConnectionError(QString err) {
   QMessageBox::warning(this, tr("Connection Error"), tr("<b>Could not connect to Quassel Core!</b><br>\n") + err, QMessageBox::Retry);
-  disconnect(guiProxy, 0, this, 0);
+  disconnect(ClientProxy::instance(), 0, this, 0);
   ui.autoConnect->setChecked(false);
   setStartState();
 }
   ui.autoConnect->setChecked(false);
   setStartState();
 }
diff --git a/gui/gui.cpp b/gui/gui.cpp
new file mode 100644 (file)
index 0000000..9f38d19
--- /dev/null
@@ -0,0 +1,353 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "gui.h"
+#include "guiproxy.h"
+#include "mainwin.h"
+#include "buffer.h"
+#include "bufferview.h"
+#include "bufferviewwidget.h"
+#include "util.h"
+
+Client * Client::instanceptr = 0;
+
+Client::ClientMode Client::clientMode;
+QHash<BufferId, Buffer *> Client::buffers;
+QHash<uint, BufferId> Client::bufferIds;
+QHash<QString, QHash<QString, VarMap> > Client::nicks;
+QHash<QString, bool> Client::connected;
+QHash<QString, QString> Client::ownNick;
+QList<BufferId> Client::coreBuffers;
+
+
+Client *Client::instance() {
+  if(instanceptr) return instanceptr;
+  instanceptr = new Client();
+  instanceptr->init();
+}
+
+void Client::destroy() {
+  delete instanceptr;
+  instanceptr = 0;
+}
+
+Client::Client() {
+  clientProxy = ClientProxy::instance();
+
+  mainWin = new MainWin();
+  _bufferModel = new BufferTreeModel(mainWin);  // FIXME
+
+  connect(this, SIGNAL(bufferSelected(Buffer *)), _bufferModel, SLOT(selectBuffer(Buffer *)));
+  connect(this, SIGNAL(bufferUpdated(Buffer *)), _bufferModel, SLOT(bufferUpdated(Buffer *)));
+  connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), _bufferModel, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *)));
+
+    // TODO: make this configurable (allow monolithic client to connect to remote cores)
+  if(Global::runMode == Global::Monolithic) clientMode = LocalCore;
+  else clientMode = RemoteCore;
+}
+
+void Client::init() {
+  blockSize = 0;
+
+  connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData()));
+  connect(&socket, SIGNAL(connected()), this, SLOT(coreConnected()));
+  connect(&socket, SIGNAL(disconnected()), this, SLOT(coreDisconnected()));
+  connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError)));
+
+  connect(Global::instance(), SIGNAL(dataPutLocally(UserId, QString)), this, SLOT(updateCoreData(UserId, QString)));
+  connect(ClientProxy::instance(), SIGNAL(csUpdateGlobalData(QString, QVariant)), this, SLOT(updateLocalData(QString, QVariant)));
+
+  connect(ClientProxy::instance(), SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), this, SLOT(recvProxySignal(ClientSignal, QVariant, QVariant, QVariant)));
+
+  connect(clientProxy, SIGNAL(csServerState(QString, QVariant)), this, SLOT(recvNetworkState(QString, QVariant)));
+  connect(clientProxy, SIGNAL(csServerConnected(QString)), this, SLOT(networkConnected(QString)));
+  connect(clientProxy, SIGNAL(csServerDisconnected(QString)), this, SLOT(networkDisconnected(QString)));
+  connect(clientProxy, SIGNAL(csDisplayMsg(Message)), this, SLOT(recvMessage(Message)));
+  connect(clientProxy, SIGNAL(csDisplayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString)));
+  connect(clientProxy, SIGNAL(csTopicSet(QString, QString, QString)), this, SLOT(setTopic(QString, QString, QString)));
+  connect(clientProxy, SIGNAL(csNickAdded(QString, QString, VarMap)), this, SLOT(addNick(QString, QString, VarMap)));
+  connect(clientProxy, SIGNAL(csNickRemoved(QString, QString)), this, SLOT(removeNick(QString, QString)));
+  connect(clientProxy, SIGNAL(csNickRenamed(QString, QString, QString)), this, SLOT(renameNick(QString, QString, QString)));
+  connect(clientProxy, SIGNAL(csNickUpdated(QString, QString, VarMap)), this, SLOT(updateNick(QString, QString, VarMap)));
+  connect(clientProxy, SIGNAL(csOwnNickSet(QString, QString)), this, SLOT(setOwnNick(QString, QString)));
+  connect(clientProxy, SIGNAL(csBacklogData(BufferId, QList<QVariant>, bool)), this, SLOT(recvBacklogData(BufferId, QList<QVariant>, bool)));
+  connect(clientProxy, SIGNAL(csUpdateBufferId(BufferId)), this, SLOT(updateBufferId(BufferId)));
+  connect(this, SIGNAL(sendInput(BufferId, QString)), clientProxy, SLOT(gsUserInput(BufferId, QString)));
+  connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), clientProxy, SLOT(gsRequestBacklog(BufferId, QVariant, QVariant)));
+
+  syncToCore();
+
+  layoutTimer = new QTimer(this);
+  layoutTimer->setInterval(0);
+  layoutTimer->setSingleShot(false);
+  connect(layoutTimer, SIGNAL(timeout()), this, SLOT(layoutMsg()));
+
+  /* make lookups by id faster */
+  foreach(BufferId id, coreBuffers) {
+    bufferIds[id.uid()] = id;  // make lookups by id faster
+    buffer(id);                // create all buffers, so we see them in the network views
+    emit requestBacklog(id, -1, -1);  // TODO: use custom settings for backlog request
+  }
+
+  //mainWin = new MainWin();
+  mainWin->init();
+
+}
+
+Client::~Client() {
+  delete mainWin;
+  foreach(Buffer *buf, buffers.values()) delete buf;
+  delete _bufferModel;
+  ClientProxy::destroy();
+
+}
+
+BufferTreeModel *Client::bufferModel() {
+  return instance()->_bufferModel;
+}
+
+void Client::coreConnected() {
+
+}
+
+void Client::coreDisconnected() {
+
+}
+
+void Client::updateCoreData(UserId, QString key) {
+  if(clientMode == LocalCore) return;
+  QVariant data = Global::data(key);
+  recvProxySignal(GS_UPDATE_GLOBAL_DATA, key, data, QVariant());
+}
+
+void Client::updateLocalData(QString key, QVariant data) {
+  Global::updateData(key, data);
+}
+
+void Client::recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+  if(clientMode == LocalCore) return;
+  QList<QVariant> sigdata;
+  sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3);
+  //qDebug() << "Sending signal: " << sigdata;
+  writeDataToDevice(&socket, QVariant(sigdata));
+}
+
+void Client::connectToCore(QString host, quint16 port) {
+  // TODO implement SSL
+  socket.connectToHost(host, port);
+}
+
+void Client::disconnectFromCore() {
+  socket.close();
+}
+
+void Client::serverError(QAbstractSocket::SocketError) {
+  emit coreConnectionError(socket.errorString());
+}
+
+void Client::serverHasData() {
+  QVariant item;
+  while(readDataFromDevice(&socket, blockSize, item)) {
+    emit recvPartialItem(1,1);
+    QList<QVariant> sigdata = item.toList();
+    Q_ASSERT(sigdata.size() == 4);
+    ClientProxy::instance()->recv((CoreSignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]);
+    blockSize = 0;
+  }
+  if(blockSize > 0) {
+    emit recvPartialItem(socket.bytesAvailable(), blockSize);
+  }
+}
+
+/*******************************************************************************************************************/
+
+void Client::networkConnected(QString net) {
+  connected[net] = true;
+  BufferId id = statusBufferId(net);
+  Buffer *b = buffer(id);
+  b->setActive(true);
+  //b->displayMsg(Message(id, Message::Server, tr("Connected.")));
+  // TODO buffersUpdated();
+}
+
+void Client::networkDisconnected(QString net) {
+  foreach(BufferId id, buffers.keys()) {
+    if(id.network() != net) continue;
+    Buffer *b = buffer(id);
+    //b->displayMsg(Message(id, Message::Server, tr("Server disconnected."))); FIXME
+    b->setActive(false);
+  }
+  connected[net] = false;
+}
+
+void Client::updateBufferId(BufferId id) {
+  bufferIds[id.uid()] = id;  // make lookups by id faster
+  buffer(id);
+}
+
+BufferId Client::bufferId(QString net, QString buf) {
+  foreach(BufferId id, buffers.keys()) {
+    if(id.network() == net && id.buffer() == buf) return id;
+  }
+  Q_ASSERT(false);  // should never happen!
+  return BufferId();
+}
+
+BufferId Client::statusBufferId(QString net) {
+  return bufferId(net, "");
+}
+
+
+Buffer * Client::buffer(BufferId id) {
+  Client *client = Client::instance();
+  if(!buffers.contains(id)) {
+    Buffer *b = new Buffer(id);
+    b->setOwnNick(ownNick[id.network()]);
+    connect(b, SIGNAL(userInput(BufferId, QString)), client, SLOT(userInput(BufferId, QString)));
+    connect(b, SIGNAL(bufferUpdated(Buffer *)), client, SIGNAL(bufferUpdated(Buffer *)));
+    connect(b, SIGNAL(bufferDestroyed(Buffer *)), client, SIGNAL(bufferDestroyed(Buffer *)));
+    buffers[id] = b;
+    emit client->bufferUpdated(b);
+  }
+  return buffers[id];
+}
+
+void Client::recvNetworkState(QString net, QVariant state) {
+  connected[net] = true;
+  setOwnNick(net, state.toMap()["OwnNick"].toString());
+  buffer(statusBufferId(net))->setActive(true);
+  VarMap t = state.toMap()["Topics"].toMap();
+  VarMap n = state.toMap()["Nicks"].toMap();
+  foreach(QVariant v, t.keys()) {
+    QString buf = v.toString();
+    BufferId id = bufferId(net, buf);
+    buffer(id)->setActive(true);
+    setTopic(net, buf, t[buf].toString());
+  }
+  foreach(QString nick, n.keys()) {
+    addNick(net, nick, n[nick].toMap());
+  }
+}
+
+void Client::recvMessage(Message msg) {
+  Buffer *b = buffer(msg.buffer);
+
+  Buffer::ActivityLevel level = Buffer::OtherActivity;
+  if(msg.type == Message::Plain || msg.type == Message::Notice){
+    level |= Buffer::NewMessage;
+  }
+  if(msg.flags & Message::Highlight){
+    level |= Buffer::Highlight;
+  }
+  emit bufferActivity(level, b);
+
+  //b->displayMsg(msg);
+  b->appendChatLine(new ChatLine(msg));
+}
+
+void Client::recvStatusMsg(QString net, QString msg) {
+  //recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg)));
+
+}
+
+void Client::recvBacklogData(BufferId id, QList<QVariant> msgs, bool done) {
+  foreach(QVariant v, msgs) {
+    layoutQueue.append(v.value<Message>());
+  }
+  if(!layoutTimer->isActive()) layoutTimer->start();
+}
+
+
+void Client::layoutMsg() {
+  if(layoutQueue.count()) {
+    ChatLine *line = new ChatLine(layoutQueue.takeFirst());
+    buffer(line->bufferId())->prependChatLine(line);
+  }
+  if(!layoutQueue.count()) layoutTimer->stop();
+}
+
+void Client::userInput(BufferId id, QString msg) {
+  emit sendInput(id, msg);
+}
+
+void Client::setTopic(QString net, QString buf, QString topic) {
+  BufferId id = bufferId(net, buf);
+  if(!connected[id.network()]) return;
+  Buffer *b = buffer(id);
+  b->setTopic(topic);
+  //if(!b->isActive()) {
+  //  b->setActive(true);
+  //  buffersUpdated();
+  //}
+}
+
+void Client::addNick(QString net, QString nick, VarMap props) {
+  if(!connected[net]) return;
+  nicks[net][nick] = props;
+  VarMap chans = props["Channels"].toMap();
+  QStringList c = chans.keys();
+  foreach(QString bufname, c) {
+    buffer(bufferId(net, bufname))->addNick(nick, props);
+  }
+}
+
+void Client::renameNick(QString net, QString oldnick, QString newnick) {
+  if(!connected[net]) return;
+  QStringList chans = nicks[net][oldnick]["Channels"].toMap().keys();
+  foreach(QString c, chans) {
+    buffer(bufferId(net, c))->renameNick(oldnick, newnick);
+  }
+  nicks[net][newnick] = nicks[net].take(oldnick);
+}
+
+void Client::updateNick(QString net, QString nick, VarMap props) {
+  if(!connected[net]) return;
+  QStringList oldchans = nicks[net][nick]["Channels"].toMap().keys();
+  QStringList newchans = props["Channels"].toMap().keys();
+  foreach(QString c, newchans) {
+    if(oldchans.contains(c)) buffer(bufferId(net, c))->updateNick(nick, props);
+    else buffer(bufferId(net, c))->addNick(nick, props);
+  }
+  foreach(QString c, oldchans) {
+    if(!newchans.contains(c)) buffer(bufferId(net, c))->removeNick(nick);
+  }
+  nicks[net][nick] = props;
+}
+
+void Client::removeNick(QString net, QString nick) {
+  if(!connected[net]) return;
+  VarMap chans = nicks[net][nick]["Channels"].toMap();
+  foreach(QString bufname, chans.keys()) {
+    buffer(bufferId(net, bufname))->removeNick(nick);
+  }
+  nicks[net].remove(nick);
+}
+
+void Client::setOwnNick(QString net, QString nick) {
+  if(!connected[net]) return;
+  ownNick[net] = nick;
+  foreach(BufferId id, buffers.keys()) {
+    if(id.network() == net) {
+      buffers[id]->setOwnNick(nick);
+    }
+  }
+}
+
+
diff --git a/gui/gui.h b/gui/gui.h
new file mode 100644 (file)
index 0000000..6ec1dba
--- /dev/null
+++ b/gui/gui.h
@@ -0,0 +1,124 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel IRC Development Team             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef _GUI_H_
+#define _GUI_H_
+
+#include <QtCore>
+#include <QtGui>
+#include <QtNetwork>
+
+#include "global.h"
+#include "buffer.h"
+#include "message.h"
+#include "guiproxy.h"
+
+class MainWin;
+class ClientProxy;
+class BufferTreeModel;
+
+class Client : public QObject {
+  Q_OBJECT
+
+  public:
+    static Client *instance();
+    static void destroy();
+
+    static Buffer *buffer(BufferId);
+    static BufferId statusBufferId(QString net);
+    static BufferId bufferId(QString net, QString buf);
+
+    static BufferTreeModel *bufferModel();
+
+  signals:
+    void sendInput(BufferId, QString message);
+    void showBuffer(Buffer *);
+    void bufferSelected(Buffer *);
+    void bufferUpdated(Buffer *);
+    void bufferActivity(Buffer::ActivityLevel, Buffer *);
+    void bufferDestroyed(Buffer *);
+    void backlogReceived(Buffer *, QList<Message>);
+    void requestBacklog(BufferId, QVariant, QVariant);
+
+    void recvPartialItem(quint32 avail, quint32 size);
+    void coreConnectionError(QString errorMsg);
+
+  public slots:
+    //void selectBuffer(Buffer *);
+    void connectToCore(QString host, quint16 port);
+    void disconnectFromCore();
+
+  private slots:
+    void updateCoreData(UserId, QString);
+    void updateLocalData(QString, QVariant);
+    void recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3);
+
+    void serverError(QAbstractSocket::SocketError);
+    void serverHasData();
+    void coreConnected();
+    void coreDisconnected();
+
+    void userInput(BufferId, QString);
+    void networkConnected(QString);
+    void networkDisconnected(QString);
+    void recvNetworkState(QString, QVariant);
+    void recvMessage(Message message);
+    void recvStatusMsg(QString network, QString message);
+    void setTopic(QString net, QString buf, QString);
+    void addNick(QString net, QString nick, VarMap props);
+    void removeNick(QString net, QString nick);
+    void renameNick(QString net, QString oldnick, QString newnick);
+    void updateNick(QString net, QString nick, VarMap props);
+    void setOwnNick(QString net, QString nick);
+    void recvBacklogData(BufferId, QList<QVariant>, bool);
+    void updateBufferId(BufferId);
+
+    void layoutMsg();
+
+  private:
+    Client();
+    ~Client();
+    void init();
+    static Client *instanceptr;
+
+    void syncToCore();
+
+    enum ClientMode { LocalCore, RemoteCore };
+    static ClientMode clientMode;
+
+    MainWin *mainWin;
+    ClientProxy *clientProxy;
+    BufferTreeModel *_bufferModel;
+
+    QTcpSocket socket;
+    quint32 blockSize;
+
+    static QHash<BufferId, Buffer *> buffers;
+    static QHash<uint, BufferId> bufferIds;
+    static QHash<QString, QHash<QString, VarMap> > nicks;
+    static QHash<QString, bool> connected;
+    static QHash<QString, QString> ownNick;
+    static QList<BufferId> coreBuffers;
+
+    QTimer *layoutTimer;
+    QList<Message> layoutQueue;
+};
+
+#endif
index 7211649..5b6177f 100644 (file)
 #include "util.h"
 #include "message.h"
 
 #include "util.h"
 #include "message.h"
 
-void GUIProxy::recv(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+ClientProxy *ClientProxy::instanceptr = 0;
+
+ClientProxy *ClientProxy::instance() {
+  if(instanceptr) return instanceptr;
+  else return instanceptr = new ClientProxy();
+}
+
+void ClientProxy::destroy() {
+  delete instanceptr;
+  instanceptr = 0;
+}
+
+ClientProxy::ClientProxy() {
+
+
+}
+
+void ClientProxy::recv(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
   //qDebug() << "[GUI] Received signal:" << sig <<arg1<<arg2<<arg3;
   switch(sig) {
     case CS_CORE_STATE: emit csCoreState(arg1); break;
   //qDebug() << "[GUI] Received signal:" << sig <<arg1<<arg2<<arg3;
   switch(sig) {
     case CS_CORE_STATE: emit csCoreState(arg1); break;
@@ -46,9 +63,9 @@ void GUIProxy::recv(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3)
     case CS_BACKLOG_DATA: emit csBacklogData(arg1.value<BufferId>(), arg2.toList(), arg3.toBool()); break;
     case CS_UPDATE_BUFFERID: emit csUpdateBufferId(arg1.value<BufferId>()); break;
 
     case CS_BACKLOG_DATA: emit csBacklogData(arg1.value<BufferId>(), arg2.toList(), arg3.toBool()); break;
     case CS_UPDATE_BUFFERID: emit csUpdateBufferId(arg1.value<BufferId>()); break;
 
-    //default: qWarning() << "Unknown signal in GUIProxy::recv: " << sig;
+    //default: qWarning() << "Unknown signal in ClientProxy::recv: " << sig;
     default: emit csGeneric(sig, arg1, arg2, arg3);
   }
 }
 
     default: emit csGeneric(sig, arg1, arg2, arg3);
   }
 }
 
-GUIProxy *guiProxy;
+//ClientProxy *guiProxy;
index aeb12f3..28fbfff 100644 (file)
 #include <QTcpSocket>
 #include <QStringList>
 
 #include <QTcpSocket>
 #include <QStringList>
 
-/** This class is the GUI side of the proxy. The GUI connects its signals and slots to it,
- *  and the calls are marshalled and sent to (or received and unmarshalled from) the CoreProxy.
- *  The connection function is defined in main/main_gui.cpp or main/main_mono.cpp.
- */
-class GUIProxy : public QObject {
+class ClientProxy : public QObject {
   Q_OBJECT
 
   public:
   Q_OBJECT
 
   public:
-    GUIProxy();
+    static ClientProxy *instance();
+    static void destroy();
 
   public slots:
     inline void gsUserInput(BufferId id, QString msg)                 { send(GS_USER_INPUT, QVariant::fromValue(id), msg); }
 
   public slots:
     inline void gsUserInput(BufferId id, QString msg)                 { send(GS_USER_INPUT, QVariant::fromValue(id), msg); }
@@ -46,10 +43,10 @@ class GUIProxy : public QObject {
     inline void gsImportBacklog()                                     { send(GS_IMPORT_BACKLOG); }
     inline void gsRequestBacklog(BufferId id, QVariant v1, QVariant v2) { send(GS_REQUEST_BACKLOG, QVariant::fromValue(id), v1, v2); }
 
     inline void gsImportBacklog()                                     { send(GS_IMPORT_BACKLOG); }
     inline void gsRequestBacklog(BufferId id, QVariant v1, QVariant v2) { send(GS_REQUEST_BACKLOG, QVariant::fromValue(id), v1, v2); }
 
-    inline void gsGeneric(GUISignal sig, QVariant v1 = QVariant(), QVariant v2 = QVariant(), QVariant v3 = QVariant()) { send(sig, v1, v2, v3); }
+    inline void gsGeneric(ClientSignal sig, QVariant v1 = QVariant(), QVariant v2 = QVariant(), QVariant v3 = QVariant()) { send(sig, v1, v2, v3); }
 
 
-    void connectToCore(QString host, quint16 port);
-    void disconnectFromCore();
+    //void connectToCore(QString host, quint16 port);
+    //void disconnectFromCore();
 
   signals:
     void csCoreState(QVariant);
 
   signals:
     void csCoreState(QVariant);
@@ -73,32 +70,35 @@ class GUIProxy : public QObject {
 
     void csGeneric(CoreSignal, QVariant, QVariant, QVariant);
 
 
     void csGeneric(CoreSignal, QVariant, QVariant, QVariant);
 
-    void coreConnected();
-    void coreDisconnected();
-    void coreConnectionError(QString errorMsg);
+    //void coreConnected();
+    //void coreDisconnected();
+    //void coreConnectionError(QString errorMsg);
 
 
-    void recvPartialItem(quint32 avail, quint32 size);
+    //void recvPartialItem(quint32 avail, quint32 size);
 
 
-    void send(GUISignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
+    void send(ClientSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
 
   public slots:
     void recv(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
 
   private slots:
 
   public slots:
     void recv(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
 
   private slots:
-    void updateCoreData(QString);
+    //void updateCoreData(QString);
 
 
-    void serverError(QAbstractSocket::SocketError);
-    void serverHasData();
+    //void serverError(QAbstractSocket::SocketError);
+    //void serverHasData();
 
   private:
 
   private:
-    QTcpSocket socket;
-    quint32 blockSize;
+    ClientProxy();
+    static ClientProxy *instanceptr;
 
 
-  friend class CoreProxy;
+    //QTcpSocket socket;
+    //quint32 blockSize;
+
+  //friend class CoreProxy;
 
 };
 
 
 };
 
-extern GUIProxy *guiProxy;
+//extern ClientProxy *guiProxy;
 
 
 
 
 
 
index 2b63b17..3d2df39 100644 (file)
@@ -22,6 +22,7 @@
 #include <QtCore>
 #include <QSqlDatabase>
 
 #include <QtCore>
 #include <QSqlDatabase>
 
+#include "gui.h"
 #include "util.h"
 #include "global.h"
 #include "message.h"
 #include "util.h"
 #include "global.h"
 #include "message.h"
@@ -46,17 +47,13 @@ MainWin::MainWin() : QMainWindow() {
   setWindowIcon(QIcon(":/qirc-icon.png"));
   setWindowIconText("Quassel IRC");
 
   setWindowIcon(QIcon(":/qirc-icon.png"));
   setWindowIconText("Quassel IRC");
 
-  layoutTimer = new QTimer(this);
-  layoutTimer->setInterval(0);
-  layoutTimer->setSingleShot(false);
-  connect(layoutTimer, SIGNAL(timeout()), this, SLOT(layoutMsg()));
   //workspace = new QWorkspace(this);
   //setCentralWidget(workspace);
   statusBar()->showMessage(tr("Waiting for core..."));
 }
 
 void MainWin::init() {
   //workspace = new QWorkspace(this);
   //setCentralWidget(workspace);
   statusBar()->showMessage(tr("Waiting for core..."));
 }
 
 void MainWin::init() {
-
+/*
   connect(guiProxy, SIGNAL(csServerState(QString, QVariant)), this, SLOT(recvNetworkState(QString, QVariant)));
   connect(guiProxy, SIGNAL(csServerConnected(QString)), this, SLOT(networkConnected(QString)));
   connect(guiProxy, SIGNAL(csServerDisconnected(QString)), this, SLOT(networkDisconnected(QString)));
   connect(guiProxy, SIGNAL(csServerState(QString, QVariant)), this, SLOT(recvNetworkState(QString, QVariant)));
   connect(guiProxy, SIGNAL(csServerConnected(QString)), this, SLOT(networkConnected(QString)));
   connect(guiProxy, SIGNAL(csServerDisconnected(QString)), this, SLOT(networkDisconnected(QString)));
@@ -76,10 +73,11 @@ void MainWin::init() {
   //layoutThread = new LayoutThread();
   //layoutThread->start();
   //while(!layoutThread->isRunning()) {};
   //layoutThread = new LayoutThread();
   //layoutThread->start();
   //while(!layoutThread->isRunning()) {};
+*/
   ui.bufferWidget->init();
 
   show();
   ui.bufferWidget->init();
 
   show();
-  syncToCore();
+  //syncToCore();
   statusBar()->showMessage(tr("Ready."));
   systray = new QSystemTrayIcon(this);
   systray->setIcon(QIcon(":/qirc-icon.png"));
   statusBar()->showMessage(tr("Ready."));
   systray = new QSystemTrayIcon(this);
   systray->setIcon(QIcon(":/qirc-icon.png"));
@@ -100,13 +98,6 @@ void MainWin::init() {
   if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
   s.endGroup();
 
   if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
   s.endGroup();
 
-  /* make lookups by id faster */
-  foreach(BufferId id, coreBuffers) {
-    bufferIds[id.uid()] = id;  // make lookups by id faster
-    getBuffer(id);             // create all buffers, so we see them in the network views
-    emit requestBacklog(id, -1, -1);  // TODO: use custom settings for backlog request
-  }
-
   s.beginGroup("Buffers");
   QString net = s.value("CurrentNetwork", "").toString();
   QString buf = s.value("CurrentBuffer", "").toString();
   s.beginGroup("Buffers");
   QString net = s.value("CurrentNetwork", "").toString();
   QString buf = s.value("CurrentBuffer", "").toString();
@@ -131,7 +122,7 @@ MainWin::~MainWin() {
   //    delete b;
   //  }
   //}
   //    delete b;
   //  }
   //}
-  foreach(Buffer *buf, buffers.values()) delete buf;
+  //foreach(Buffer *buf, buffers.values()) delete buf;
 }
 
 /* This is implemented in settingspages.cpp */
 }
 
 /* This is implemented in settingspages.cpp */
@@ -149,15 +140,15 @@ void MainWin::setupMenus() {
   connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
   // for debugging
   connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
   connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
   // for debugging
   connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
-  connect(this, SIGNAL(importOldBacklog()), guiProxy, SLOT(gsImportBacklog()));
+  connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
 }
 
 void MainWin::setupViews() {
 }
 
 void MainWin::setupViews() {
-  BufferTreeModel *model = new BufferTreeModel(this); // FIXME Where is the delete for that? :p
+  BufferTreeModel *model = Client::bufferModel(); // FIXME Where is the delete for that? :p
   connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
   connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
-  connect(this, SIGNAL(bufferSelected(Buffer *)), model, SLOT(selectBuffer(Buffer *)));
-  connect(this, SIGNAL(bufferUpdated(Buffer *)), model, SLOT(bufferUpdated(Buffer *)));
-  connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), model, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *)));
+  //connect(this, SIGNAL(bufferSelected(Buffer *)), model, SLOT(selectBuffer(Buffer *)));
+  //connect(this, SIGNAL(bufferUpdated(Buffer *)), model, SLOT(bufferUpdated(Buffer *)));
+  //connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), model, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *)));
   
   BufferViewDock *all = new BufferViewDock(model, tr("All Buffers"), BufferViewFilter::AllNets);
   registerBufferViewDock(all);
   
   BufferViewDock *all = new BufferViewDock(model, tr("All Buffers"), BufferViewFilter::AllNets);
   registerBufferViewDock(all);
@@ -224,7 +215,7 @@ void MainWin::closeEvent(QCloseEvent *event)
 }
 
 void MainWin::showBuffer(BufferId id) {
 }
 
 void MainWin::showBuffer(BufferId id) {
-  showBuffer(getBuffer(id));
+  showBuffer(Client::buffer(id));
 }
 
 void MainWin::showBuffer(Buffer *b) {
 }
 
 void MainWin::showBuffer(Buffer *b) {
@@ -232,191 +223,7 @@ void MainWin::showBuffer(Buffer *b) {
   //emit bufferSelected(b);
   //qApp->processEvents();
   ui.bufferWidget->setBuffer(b);
   //emit bufferSelected(b);
   //qApp->processEvents();
   ui.bufferWidget->setBuffer(b);
-  emit bufferSelected(b);
-}
-
-void MainWin::networkConnected(QString net) {
-  connected[net] = true;
-  BufferId id = getStatusBufferId(net);
-  Buffer *b = getBuffer(id);
-  b->setActive(true);
-  //b->displayMsg(Message(id, Message::Server, tr("Connected.")));
-  // TODO buffersUpdated();
-}
-
-void MainWin::networkDisconnected(QString net) {
-  //getBuffer(net, "")->setActive(false);
-  foreach(BufferId id, buffers.keys()) {
-    if(id.network() != net) continue;
-    Buffer *b = getBuffer(id);
-    //b->displayMsg(Message(id, Message::Server, tr("Server disconnected."))); FIXME
-    b->setActive(false);
-  }
-  connected[net] = false;
-}
-
-void MainWin::updateBufferId(BufferId id) {
-  bufferIds[id.uid()] = id;  // make lookups by id faster
-  getBuffer(id);
-}
-
-BufferId MainWin::getBufferId(QString net, QString buf) {
-  foreach(BufferId id, buffers.keys()) {
-    if(id.network() == net && id.buffer() == buf) return id;
-  }
-  Q_ASSERT(false);
-  return BufferId();
-}
-
-BufferId MainWin::getStatusBufferId(QString net) {
-  return getBufferId(net, "");
-}
-
-
-Buffer * MainWin::getBuffer(BufferId id) {
-  if(!buffers.contains(id)) {
-    Buffer *b = new Buffer(id);
-    b->setOwnNick(ownNick[id.network()]);
-    connect(b, SIGNAL(userInput(BufferId, QString)), this, SLOT(userInput(BufferId, QString)));
-    connect(b, SIGNAL(bufferUpdated(Buffer *)), this, SIGNAL(bufferUpdated(Buffer *)));
-    connect(b, SIGNAL(bufferDestroyed(Buffer *)), this, SIGNAL(bufferDestroyed(Buffer *)));
-    buffers[id] = b;
-    emit bufferUpdated(b);
-  }
-  return buffers[id];
-}
-
-void MainWin::recvNetworkState(QString net, QVariant state) {
-  connected[net] = true;
-  setOwnNick(net, state.toMap()["OwnNick"].toString());
-  getBuffer(getStatusBufferId(net))->setActive(true);
-  VarMap t = state.toMap()["Topics"].toMap();
-  VarMap n = state.toMap()["Nicks"].toMap();
-  foreach(QVariant v, t.keys()) {
-    QString buf = v.toString();
-    BufferId id = getBufferId(net, buf);
-    getBuffer(id)->setActive(true);
-    setTopic(net, buf, t[buf].toString());
-  }
-  foreach(QString nick, n.keys()) {
-    addNick(net, nick, n[nick].toMap());
-  }
-}
-
-void MainWin::recvMessage(Message msg) {
-  /*
-  Buffer *b;
-  if(msg.flags & Message::PrivMsg) {
-  // query
-    if(msg.flags & Message::Self) b = getBuffer(net, msg.target);
-    else b = getBuffer(net, nickFromMask(msg.sender));
-  } else {
-    b = getBuffer(net, msg.target);
-  }
-  */
-  
-
-  Buffer *b = getBuffer(msg.buffer);
-  
-  Buffer::ActivityLevel level = Buffer::OtherActivity;
-  if(msg.type == Message::Plain or msg.type == Message::Notice){
-    level |= Buffer::NewMessage;
-  }
-  if(msg.flags & Message::Highlight){
-    level |= Buffer::Highlight;
-  }
-  emit bufferActivity(level, b);
-
-  //b->displayMsg(msg);
-  b->appendChatLine(new ChatLine(msg));
-}
-
-void MainWin::recvStatusMsg(QString net, QString msg) {
-  //recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg)));
-
-}
-
-void MainWin::recvBacklogData(BufferId id, QList<QVariant> msgs, bool done) {
-  foreach(QVariant v, msgs) {
-    layoutQueue.append(v.value<Message>());
-  }
-  if(!layoutTimer->isActive()) layoutTimer->start();
-}
-
-
-void MainWin::layoutMsg() {
-  if(layoutQueue.count()) {
-    ChatLine *line = new ChatLine(layoutQueue.takeFirst());
-    getBuffer(line->bufferId())->prependChatLine(line);
-  }
-  if(!layoutQueue.count()) layoutTimer->stop();
-}
-
-void MainWin::userInput(BufferId id, QString msg) {
-  emit sendInput(id, msg);
-}
-
-void MainWin::setTopic(QString net, QString buf, QString topic) {
-  BufferId id = getBufferId(net, buf);
-  if(!connected[id.network()]) return;
-  Buffer *b = getBuffer(id);
-  b->setTopic(topic);
-  //if(!b->isActive()) {
-  //  b->setActive(true);
-  //  buffersUpdated();
-  //}
-}
-
-void MainWin::addNick(QString net, QString nick, VarMap props) {
-  if(!connected[net]) return;
-  nicks[net][nick] = props;
-  VarMap chans = props["Channels"].toMap();
-  QStringList c = chans.keys();
-  foreach(QString bufname, c) {
-    getBuffer(getBufferId(net, bufname))->addNick(nick, props);
-  }
-}
-
-void MainWin::renameNick(QString net, QString oldnick, QString newnick) {
-  if(!connected[net]) return;
-  QStringList chans = nicks[net][oldnick]["Channels"].toMap().keys();
-  foreach(QString c, chans) {
-    getBuffer(getBufferId(net, c))->renameNick(oldnick, newnick);
-  }
-  nicks[net][newnick] = nicks[net].take(oldnick);
-}
-
-void MainWin::updateNick(QString net, QString nick, VarMap props) {
-  if(!connected[net]) return;
-  QStringList oldchans = nicks[net][nick]["Channels"].toMap().keys();
-  QStringList newchans = props["Channels"].toMap().keys();
-  foreach(QString c, newchans) {
-    if(oldchans.contains(c)) getBuffer(getBufferId(net, c))->updateNick(nick, props);
-    else getBuffer(getBufferId(net, c))->addNick(nick, props);
-  }
-  foreach(QString c, oldchans) {
-    if(!newchans.contains(c)) getBuffer(getBufferId(net, c))->removeNick(nick);
-  }
-  nicks[net][nick] = props;
-}
-
-void MainWin::removeNick(QString net, QString nick) {
-  if(!connected[net]) return;
-  VarMap chans = nicks[net][nick]["Channels"].toMap();
-  foreach(QString bufname, chans.keys()) {
-    getBuffer(getBufferId(net, bufname))->removeNick(nick);
-  }
-  nicks[net].remove(nick);
-}
-
-void MainWin::setOwnNick(QString net, QString nick) {
-  if(!connected[net]) return;
-  ownNick[net] = nick;
-  foreach(BufferId id, buffers.keys()) {
-    if(id.network() == net) {
-      buffers[id]->setOwnNick(nick);
-    }
-  }
+  //emit bufferSelected(b); // FIXME do we need this?
 }
 
 void MainWin::importBacklog() {
 }
 
 void MainWin::importBacklog() {
index 8092395..41d1a2f 100644 (file)
@@ -56,31 +56,32 @@ class MainWin : public QMainWindow {
     void closeEvent(QCloseEvent *event);
 
   signals:
     void closeEvent(QCloseEvent *event);
 
   signals:
-    void sendInput(BufferId, QString message);
-    void bufferSelected(Buffer *);
-    void bufferUpdated(Buffer *);
-    void bufferActivity(Buffer::ActivityLevel, Buffer *);
-    void bufferDestroyed(Buffer *);
-    void backlogReceived(Buffer *, QList<Message>);
-    void requestBacklog(BufferId, QVariant, QVariant);
+    //void sendInput(BufferId, QString message);
+    //void bufferSelected(Buffer *);
+    //void bufferUpdated(Buffer *);
+    //void bufferActivity(Buffer::ActivityLevel, Buffer *);
+    //void bufferDestroyed(Buffer *);
+    //void backlogReceived(Buffer *, QList<Message>);
+    //void requestBacklog(BufferId, QVariant, QVariant);
 
     void importOldBacklog();
 
   private slots:
 
     void importOldBacklog();
 
   private slots:
-    void userInput(BufferId, QString);
-    void networkConnected(QString);
-    void networkDisconnected(QString);
-    void recvNetworkState(QString, QVariant);
-    void recvMessage(Message message);
-    void recvStatusMsg(QString network, QString message);
-    void setTopic(QString net, QString buf, QString);
-    void addNick(QString net, QString nick, VarMap props);
-    void removeNick(QString net, QString nick);
-    void renameNick(QString net, QString oldnick, QString newnick);
-    void updateNick(QString net, QString nick, VarMap props);
-    void setOwnNick(QString net, QString nick);
-    void recvBacklogData(BufferId, QList<QVariant>, bool);
-    void updateBufferId(BufferId);
+    
+    //void userInput(BufferId, QString);
+    //void networkConnected(QString);
+    //void networkDisconnected(QString);
+    //void recvNetworkState(QString, QVariant);
+    //void recvMessage(Message message);
+    //void recvStatusMsg(QString network, QString message);
+    //void setTopic(QString net, QString buf, QString);
+    //void addNick(QString net, QString nick, VarMap props);
+    //void removeNick(QString net, QString nick);
+    //void renameNick(QString net, QString oldnick, QString newnick);
+    //void updateNick(QString net, QString nick, VarMap props);
+    //void setOwnNick(QString net, QString nick);
+    //void recvBacklogData(BufferId, QList<QVariant>, bool);
+    //void updateBufferId(BufferId);
 
     void showServerList();
     void showSettingsDlg();
 
     void showServerList();
     void showSettingsDlg();
@@ -89,7 +90,6 @@ class MainWin : public QMainWindow {
     void showBuffer(Buffer *);
 
     void importBacklog();
     void showBuffer(Buffer *);
 
     void importBacklog();
-    void layoutMsg();
 
   private:
     Ui::MainWin ui;
 
   private:
     Ui::MainWin ui;
@@ -97,7 +97,7 @@ class MainWin : public QMainWindow {
     void setupMenus();
     void setupViews();
     void setupSettingsDlg();
     void setupMenus();
     void setupViews();
     void setupSettingsDlg();
-    void syncToCore();  // implemented in main_mono.cpp or main_gui.cpp
+    //void syncToCore();  // implemented in main_mono.cpp or main_gui.cpp
     //Buffer * getBuffer(QString net, QString buf);
     Buffer *getBuffer(BufferId);
     BufferId getStatusBufferId(QString net);
     //Buffer * getBuffer(QString net, QString buf);
     Buffer *getBuffer(BufferId);
     BufferId getStatusBufferId(QString net);
@@ -116,13 +116,13 @@ class MainWin : public QMainWindow {
     //QString currentNetwork, currentBuffer;
     //QHash<QString, QHash<QString, Buffer*> > buffers;
     uint currentBuffer;
     //QString currentNetwork, currentBuffer;
     //QHash<QString, QHash<QString, Buffer*> > buffers;
     uint currentBuffer;
-    QHash<BufferId, Buffer *> buffers;
-    QHash<uint, BufferId> bufferIds;
-    QHash<QString, QHash<QString, VarMap> > nicks;
-    QHash<QString, bool> connected;
-    QHash<QString, QString> ownNick;
+    //QHash<BufferId, Buffer *> buffers;
+    //QHash<uint, BufferId> bufferIds;
+    //QHash<QString, QHash<QString, VarMap> > nicks;
+    //QHash<QString, bool> connected;
+    //QHash<QString, QString> ownNick;
     //QHash<QString, QList<Message> > coreBackLog;
     //QHash<QString, QList<Message> > coreBackLog;
-    QList<BufferId> coreBuffers;
+    //QList<BufferId> coreBuffers;
 
     QList<BufferViewDock *> netViews;
 
 
     QList<BufferViewDock *> netViews;
 
index 855056c..ab12919 100644 (file)
@@ -40,7 +40,7 @@ ServerListDlg::ServerListDlg(QWidget *parent) : QDialog(parent) {
   settings.endGroup();
   // check if we already have a valid identity
   if(!Global::data("Identities", VarMap()).toMap().contains("Default")) editIdentities(true);
   settings.endGroup();
   // check if we already have a valid identity
   if(!Global::data("Identities", VarMap()).toMap().contains("Default")) editIdentities(true);
-  connect(this, SIGNAL(requestConnect(QStringList)), guiProxy, SLOT(gsRequestConnect(QStringList)));
+  connect(this, SIGNAL(requestConnect(QStringList)), ClientProxy::instance(), SLOT(gsRequestConnect(QStringList)));
 
   // Autoconnect
   QStringList list;
 
   // Autoconnect
   QStringList list;
index f48f615..e9bd6c8 100644 (file)
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
   Global::quasselDir = QDir::homePath() + "/.quassel";
 
   global = new Global();
   Global::quasselDir = QDir::homePath() + "/.quassel";
 
   global = new Global();
-  guiProxy = new GUIProxy();
+  guiProxy = new GuiProxy();
 
   Style::init();
 
 
   Style::init();
 
@@ -89,7 +89,9 @@ void MainWin::syncToCore() {
   foreach(QVariant v, state["CoreBuffers"].toList()) { coreBuffers.append(v.value<BufferId>()); }
 }
 
   foreach(QVariant v, state["CoreBuffers"].toList()) { coreBuffers.append(v.value<BufferId>()); }
 }
 
-GUIProxy::GUIProxy() {
+/*
+
+GuiProxy::GuiProxy() {
   if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!");
 
   blockSize = 0;
   if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!");
 
   blockSize = 0;
@@ -104,20 +106,20 @@ GUIProxy::GUIProxy() {
 
 }
 
 
 }
 
-void GUIProxy::connectToCore(QString host, quint16 port) {
+void GuiProxy::connectToCore(QString host, quint16 port) {
   socket.connectToHost(host, port);
 }
 
   socket.connectToHost(host, port);
 }
 
-void GUIProxy::disconnectFromCore() {
+void GuiProxy::disconnectFromCore() {
   socket.close();
 }
 
   socket.close();
 }
 
-void GUIProxy::serverError(QAbstractSocket::SocketError) {
+void GuiProxy::serverError(QAbstractSocket::SocketError) {
   emit coreConnectionError(socket.errorString());
   //qFatal(QString("Connection error: %1").arg(socket.errorString()).toAscii());
 }
 
   emit coreConnectionError(socket.errorString());
   //qFatal(QString("Connection error: %1").arg(socket.errorString()).toAscii());
 }
 
-void GUIProxy::serverHasData() {
+void GuiProxy::serverHasData() {
   QVariant item;
   while(readDataFromDevice(&socket, blockSize, item)) {
     emit recvPartialItem(1,1);
   QVariant item;
   while(readDataFromDevice(&socket, blockSize, item)) {
     emit recvPartialItem(1,1);
@@ -130,15 +132,17 @@ void GUIProxy::serverHasData() {
     emit recvPartialItem(socket.bytesAvailable(), blockSize);
   }
 }
     emit recvPartialItem(socket.bytesAvailable(), blockSize);
   }
 }
-
-void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
+*/
+/*
+void GuiProxy::send(GuiSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
   QList<QVariant> sigdata;
   sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3);
   //qDebug() << "Sending signal: " << sigdata;
   writeDataToDevice(&socket, QVariant(sigdata));
 }
   QList<QVariant> sigdata;
   sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3);
   //qDebug() << "Sending signal: " << sigdata;
   writeDataToDevice(&socket, QVariant(sigdata));
 }
+*/
 
 
-void GUIProxy::updateCoreData(QString key) {
+void GuiProxy::updateCoreData(QString key) {
   QVariant data = global->getData(key);
   send(GS_UPDATE_GLOBAL_DATA, key, data);
 }
   QVariant data = global->getData(key);
   send(GS_UPDATE_GLOBAL_DATA, key, data);
 }
index d9c682f..419b150 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <QApplication>
 
 
 #include <QApplication>
 
+#include "gui.h"
 #include "core.h"
 #include "style.h"
 #include "global.h"
 #include "core.h"
 #include "style.h"
 #include "global.h"
@@ -43,31 +44,33 @@ int main(int argc, char **argv) {
 
   //settings = new Settings();
   //global = new Global();
 
   //settings = new Settings();
   //global = new Global();
-  guiProxy = new GUIProxy();
+  //guiProxy = new GUIProxy();
   //coreProxy = new CoreProxy();
   //coreProxy = new CoreProxy();
-  QObject::connect(Core::guiSession(), SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)), guiProxy, SLOT(recv(CoreSignal, QVariant, QVariant, QVariant)));
-  QObject::connect(guiProxy, SIGNAL(send(GUISignal, QVariant, QVariant, QVariant)), Core::guiSession(), SLOT(processSignal(GUISignal, QVariant, QVariant, QVariant)));
+  QObject::connect(Core::localSession(), SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant)), ClientProxy::instance(), SLOT(recv(CoreSignal, QVariant, QVariant, QVariant)));
+  QObject::connect(ClientProxy::instance(), SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), Core::localSession(), SLOT(processSignal(ClientSignal, QVariant, QVariant, QVariant)));
 
   Settings::init();
   Style::init();
 
 
   Settings::init();
   Style::init();
 
-  MainWin *mainWin = new MainWin();
-  mainWin->show();
-  mainWin->init();
+  //MainWin *mainWin = new MainWin();
+  //mainWin->show();
+  //mainWin->init();
+  Client::instance();
   int exitCode = app.exec();
   //delete core;
   int exitCode = app.exec();
   //delete core;
+  Client::destroy();
   Core::destroy();
   Core::destroy();
-  delete guiProxy;
+  //delete guiProxy;
   //delete coreProxy;
   //delete global;
   //delete coreProxy;
   //delete global;
-  delete mainWin;
+  //delete mainWin;
   //delete settings;
   return exitCode;
 }
 
   //delete settings;
   return exitCode;
 }
 
-void MainWin::syncToCore() {
+void Client::syncToCore() {
   //Q_ASSERT(Global::data("CoreReady").toBool());
   //Q_ASSERT(Global::data("CoreReady").toBool());
-  coreBuffers = Core::guiSession()->buffers();
+  coreBuffers = Core::localSession()->buffers();
   // NOTE: We don't need to request server states, because in the monolithic version there can't be
   //       any servers connected at this stage...
 }
   // NOTE: We don't need to request server states, because in the monolithic version there can't be
   //       any servers connected at this stage...
 }
@@ -78,10 +81,11 @@ void CoreProxy::sendToGUI(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant
 }
 */
 
 }
 */
 
+/*
 GUIProxy::GUIProxy() {
   if(guiProxy) qFatal("Trying to instantiate more than one GUIProxy object!");
 }
 GUIProxy::GUIProxy() {
   if(guiProxy) qFatal("Trying to instantiate more than one GUIProxy object!");
 }
-
+*/
 /*
 void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
   coreProxy->recv(sig, arg1, arg2, arg3);
 /*
 void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
   coreProxy->recv(sig, arg1, arg2, arg3);
@@ -90,9 +94,10 @@ void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3)
 
 // Dummy function definitions
 // These are not needed, since we don't have a network connection to the core.
 
 // Dummy function definitions
 // These are not needed, since we don't have a network connection to the core.
+/*
 void GUIProxy::serverHasData() {}
 void GUIProxy::connectToCore(QString, quint16) {}
 void GUIProxy::disconnectFromCore() {}
 void GUIProxy::updateCoreData(QString) {}
 void GUIProxy::serverError(QAbstractSocket::SocketError) {}
 void GUIProxy::serverHasData() {}
 void GUIProxy::connectToCore(QString, quint16) {}
 void GUIProxy::disconnectFromCore() {}
 void GUIProxy::updateCoreData(QString) {}
 void GUIProxy::serverError(QAbstractSocket::SocketError) {}
-
+*/
index 208bb88..30421e7 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef _PROXY_COMMON_H_
 #define _PROXY_COMMON_H_
 
 #ifndef _PROXY_COMMON_H_
 #define _PROXY_COMMON_H_
 
-enum GUISignal { GS_CLIENT_INIT, GS_USER_INPUT, GS_REQUEST_CONNECT, GS_UPDATE_GLOBAL_DATA, GS_IMPORT_BACKLOG,
+enum ClientSignal { GS_CLIENT_INIT, GS_USER_INPUT, GS_REQUEST_CONNECT, GS_UPDATE_GLOBAL_DATA, GS_IMPORT_BACKLOG,
   GS_REQUEST_BACKLOG
 
 };
   GS_REQUEST_BACKLOG
 
 };