From 7a0c26e22498cabadd791be32614ba65f69125c3 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 17 May 2007 16:08:41 +0000 Subject: [PATCH] Added generic signals between Core and GUI. You can use these to avoid having to define custom signals for everything you need to send. This uses the usual mechanism, but instead of sending custom-named signals and perform a parameter conversion, we just emit the raw data and leave the processing to the user. Note that this might have a slight performance impact on the receiver's side if you connect the generic signal to several custom slots, because _all_ unhandled signals are sent to _all_ generic handlers (which then need to filter out whichever signal they need). Use as follows: - define signaltype in main/proxy_common.h - use slots CoreProxy::csGeneric(type, arg1, arg2, arg3) or GUIProcy::gsGeneric(type, arg1, arg2, arg3) - On the other side, the signal is emitted by the proxy, so you may connect your slot and then handle the sigtype as needed. --- core/coreproxy.cpp | 3 ++- core/coreproxy.h | 4 ++++ gui/buffer.cpp | 11 ----------- gui/guiproxy.cpp | 3 ++- gui/guiproxy.h | 4 +++- main/main_mono.cpp | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/core/coreproxy.cpp b/core/coreproxy.cpp index a09a4f52..5ae8d961 100644 --- a/core/coreproxy.cpp +++ b/core/coreproxy.cpp @@ -142,7 +142,8 @@ void CoreProxy::recv(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) case GS_REQUEST_CONNECT: emit gsRequestConnect(arg1.toStringList()); break; case GS_IMPORT_BACKLOG: emit gsImportBacklog(); break; case GS_REQUEST_BACKLOG: emit gsRequestBacklog(arg1.value(), arg2, arg3); break; - default: qWarning() << "Unknown signal in CoreProxy::recv: " << sig; + //default: qWarning() << "Unknown signal in CoreProxy::recv: " << sig; + default: emit gsGeneric(sig, arg1, arg2, arg3); } } diff --git a/core/coreproxy.h b/core/coreproxy.h index 6e724d59..9b4acc5a 100644 --- a/core/coreproxy.h +++ b/core/coreproxy.h @@ -57,6 +57,8 @@ class CoreProxy : public QObject { inline void csBacklogData(BufferId id, QList msg, bool done) { send(CS_BACKLOG_DATA, QVariant::fromValue(id), msg, done); } inline void csUpdateBufferId(BufferId id) { send(CS_UPDATE_BUFFERID, QVariant::fromValue(id)); } + inline void csGeneric(CoreSignal sig, QVariant v1 = QVariant(), QVariant v2 = QVariant(), QVariant v3 = QVariant()) { send(sig, v1, v2, v3); } + signals: void gsPutGlobalData(QString, QVariant); void gsUserInput(BufferId, QString); @@ -64,6 +66,8 @@ class CoreProxy : public QObject { void gsImportBacklog(); void gsRequestBacklog(BufferId, QVariant, QVariant); + void gsGeneric(GUISignal, QVariant, QVariant, QVariant); + void requestServerStates(); private: diff --git a/gui/buffer.cpp b/gui/buffer.cpp index ec45141b..9c9726e1 100644 --- a/gui/buffer.cpp +++ b/gui/buffer.cpp @@ -74,17 +74,6 @@ void Buffer::setActive(bool a) { } } -/* -void Buffer::displayMsg(Message msg) { - contents()->append(msg); - emit msgDisplayed(msg); -} - -void Buffer::prependMessages(QList msgs) { - _contents = msgs + _contents; -} -*/ - void Buffer::appendChatLine(ChatLine *line) { lines.append(line); emit chatLineAppended(line); diff --git a/gui/guiproxy.cpp b/gui/guiproxy.cpp index 373bf69f..7211649a 100644 --- a/gui/guiproxy.cpp +++ b/gui/guiproxy.cpp @@ -46,7 +46,8 @@ void GUIProxy::recv(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) case CS_BACKLOG_DATA: emit csBacklogData(arg1.value(), arg2.toList(), arg3.toBool()); break; case CS_UPDATE_BUFFERID: emit csUpdateBufferId(arg1.value()); break; - default: qWarning() << "Unknown signal in GUIProxy::recv: " << sig; + //default: qWarning() << "Unknown signal in GUIProxy::recv: " << sig; + default: emit csGeneric(sig, arg1, arg2, arg3); } } diff --git a/gui/guiproxy.h b/gui/guiproxy.h index b34bd33a..6e84b570 100644 --- a/gui/guiproxy.h +++ b/gui/guiproxy.h @@ -46,6 +46,8 @@ 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 gsGeneric(GUISignal sig, QVariant v1 = QVariant(), QVariant v2 = QVariant(), QVariant v3 = QVariant()) { send(sig, v1, v2, v3); } + void connectToCore(QString host, quint16 port); void disconnectFromCore(); @@ -69,7 +71,7 @@ class GUIProxy : public QObject { void csBacklogData(BufferId, QList, bool); void csUpdateBufferId(BufferId); - void csGeneric(int, QVariant, QVariant); + void csGeneric(CoreSignal, QVariant, QVariant, QVariant); void coreConnected(); void coreDisconnected(); diff --git a/main/main_mono.cpp b/main/main_mono.cpp index 87360c63..e12ad2e9 100644 --- a/main/main_mono.cpp +++ b/main/main_mono.cpp @@ -74,7 +74,7 @@ void CoreProxy::sendToGUI(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant } GUIProxy::GUIProxy() { - if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!"); + if(guiProxy) qFatal("Trying to instantiate more than one GUIProxy object!"); } void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { -- 2.20.1