From: Manuel Nickschas Date: Wed, 18 Oct 2006 17:13:20 +0000 (+0000) Subject: Finished logical separation of core and GUI. Monolithic build should work as expected. X-Git-Tag: 0.1.0~279 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=31d998779868a1b572972168b2e813893d70ab90;ds=sidebyside Finished logical separation of core and GUI. Monolithic build should work as expected. Separate builds non-functional yet. --- diff --git a/Quassel.kdevelop.filelist b/Quassel.kdevelop.filelist new file mode 100644 index 00000000..a8934b66 --- /dev/null +++ b/Quassel.kdevelop.filelist @@ -0,0 +1,37 @@ +# KDevelop Custom Project File List +network/server.h +network/server.cpp +core/core.cpp +core/CMakeLists.txt +core/core.h +gui/channelwidget.cpp +gui/channelwidget.h +gui/channelwidget.ui +gui/CMakeLists.txt +gui/identitiesdlg.ui +gui/identitieseditdlg.ui +gui/mainwin.cpp +gui/mainwin.h +gui/networkeditdlg.ui +gui/nickeditdlg.ui +gui/serverlist.cpp +gui/serverlist.h +gui/serverlistdlg.ui +images/iconmap.xml +images/icons.qrc +main/main_core.cpp +main/main_mono.cpp +network/CMakeLists.txt +CMakeLists.txt +COPYING +Doxyfile +Makefile +gui/guiproxy.h +gui/guiproxy.cpp +main/logger.cpp +main/logger.h +main/quassel.cpp +main/quassel.h +main/main_gui.cpp +core/coreproxy.cpp +core/coreproxy.h diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 2d5a7061..bde1fb02 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,6 +1,6 @@ -SET(core_SRCS core.cpp) +SET(core_SRCS core.cpp coreproxy.cpp) SET(core_HDRS ) -SET(core_MOCS core.h) +SET(core_MOCS core.h coreproxy.h) QT4_WRAP_CPP(_MOC ${core_MOCS}) ADD_LIBRARY(core ${_MOC} ${core_SRCS} ${core_HDRS}) diff --git a/core/core.cpp b/core/core.cpp index b7f0e39c..7c341d57 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -21,19 +21,32 @@ #include "core.h" #include "server.h" #include "quassel.h" +#include "coreproxy.h" #include -Core * Core::init() { - if(core) return core; +Core::Core() { + if(core) qFatal("Trying to instantiate more than one Core object!"); + + connect(coreProxy, SIGNAL(gsRequestConnect(QString, quint16)), this, SLOT(connectToIrc(QString, quint16))); + connect(coreProxy, SIGNAL(gsUserInput(QString)), this, SLOT(inputLine(QString))); + + connect(&server, SIGNAL(recvLine(QString)), coreProxy, SLOT(csCoreMessage(QString))); + QSettings s; VarMap identities = s.value("Network/Identities").toMap(); - qDebug() << identities; //VarMap networks = s.value("Network/ quassel->putData("Identities", identities); - return new Core(); + + server.start(); +} + +void Core::init() { + + } +/* void Core::run() { connect(&server, SIGNAL(recvLine(const QString &)), this, SIGNAL(outputLine(const QString &))); @@ -41,13 +54,15 @@ void Core::run() { server.start(); exec(); } +*/ -void Core::connectToIrc( const QString &h, quint16 port) { +void Core::connectToIrc(const QString &h, quint16 port) { + qDebug() << "Core: Connecting to " << h << ":" << port; server.connectToIrc(h, port); } -void Core::inputLine(const QString &s) { - server.putRawLine( s); +void Core::inputLine(QString s) { + server.putRawLine(s); } diff --git a/core/core.h b/core/core.h index f9cd9f16..96cba3a0 100644 --- a/core/core.h +++ b/core/core.h @@ -27,26 +27,27 @@ #include "server.h" -class Core : public QThread { +class Core : public QObject { Q_OBJECT public: - static Core * init(); - static VarMap loadNetworks(); - static void storeNetworks(VarMap); - static VarMap loadIdentities(); - static void storeIdentities(VarMap); + Core(); + void init(); + VarMap loadNetworks(); + void storeNetworks(VarMap); + VarMap loadIdentities(); + void storeIdentities(VarMap); public slots: - void inputLine(const QString &); // temp + void inputLine(QString); // temp void connectToIrc(const QString &, quint16 port = 6667); signals: void outputLine(const QString &); // temp - + private: - void run(); + //void run(); Server server; // temp diff --git a/core/proxy.h b/core/coreproxy.cpp similarity index 76% rename from core/proxy.h rename to core/coreproxy.cpp index ca0319bd..ab003842 100644 --- a/core/proxy.h +++ b/core/coreproxy.cpp @@ -18,34 +18,16 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _PROXY_H_ -#define _PROXY_H_ +#include "coreproxy.h" +#include -#include "core.h" +CoreProxy::CoreProxy() { + if(coreProxy) qFatal("Trying to instantiate more than one CoreProxy object!"); -namespace Proxy { - enum { LOAD_IDENTITIES, STORE_IDENTITIES }; -}; +} -class CoreProxy { - Q_OBJECT +void CoreProxy::csCoreMessage(QString s) { + send(CS_CORE_MESSAGE, s); +} - public: - static VarMap loadIdentities(); - static void storeIdentities(VarMap); - -}; - - -class GuiProxy { - Q_OBJECT - - public: - static VarMap loadIdentities(); - static void storeIdentities(VarMap); - -}; - -extern QVariant proxyConnect(uint func, QVariant arg = QVariant()); - -#endif +CoreProxy *coreProxy; diff --git a/core/proxy.cpp b/core/coreproxy.h similarity index 62% rename from core/proxy.cpp rename to core/coreproxy.h index 4e97362f..bd52bb07 100644 --- a/core/proxy.cpp +++ b/core/coreproxy.h @@ -18,37 +18,41 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "proxy.h" +#ifndef _COREPROXY_H_ +#define _COREPROXY_H_ -#include +#include "proxy_common.h" -using namespace Proxy; +#include +#include -VarMap CoreProxy::loadIdentities() { - return Core::loadIdentities(); -} +/** 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. + * The connection functions are defined in main/main_core.cpp or main/main_mono.cpp. + */ +class CoreProxy : public QObject { + Q_OBJECT -void CoreProxy::storeIdentities(VarMap id) { - Core::storeIdentities(id); -} + private: + void send(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant()); + void recv(GUISignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant()); + public: + CoreProxy(); + public slots: + void csCoreMessage(QString); -VarMap GuiProxy::loadIdentities() { - return proxyConnect(LOAD_IDENTITIES).toMap(); -} -void GuiProxy::storeIdentities(VarMap arg) { - proxyConnect(STORE_IDENTITIES, arg); -} + signals: + void gsUserInput(QString); + void gsRequestConnect(QString, quint16); -/* -QVariant proxyConnect(uint func, QVariant arg) { - switch(func) { - case LOAD_IDENTITIES: return (QVariant) CoreProxy::loadIdentities(); - case STORE_IDENTITIES: CoreProxy::storeIdentities(arg.toMap()); return 0; + friend class GUIProxy; +}; - } - return 0; -} -*/ +extern CoreProxy *coreProxy; + + + +#endif diff --git a/gui/channelwidget.cpp b/gui/channelwidget.cpp index 71a40755..7ff45372 100644 --- a/gui/channelwidget.cpp +++ b/gui/channelwidget.cpp @@ -41,14 +41,16 @@ ChannelWidget::ChannelWidget(QWidget *parent) : QWidget(parent) { */ //connect(&core, SIGNAL(outputLine( const QString& )), ui.textBrowser, SLOT(insertPlainText(const QString &))); //connect(ui.lineEdit, SIGNAL( - connect(&core, SIGNAL(outputLine( const QString& )), this, SLOT(lineReceived(const QString &))); + //connect(&core, SIGNAL(outputLine( const QString& )), this, SLOT(lineReceived(const QString &))); connect(ui.lineEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed())); - connect(this, SIGNAL(inputLine( const QString& )), &core, SLOT(inputLine( const QString& ))); + //connect(this, SIGNAL(inputLine( const QString& )), &core, SLOT(inputLine( const QString& ))); connect(this, SIGNAL(inputLine(QString)), guiProxy, SLOT(gsUserInput(QString))); + connect(this, SIGNAL(requestConnect(QString, quint16)), guiProxy, SLOT(gsRequestConnect(QString, quint16))); + connect(guiProxy, SIGNAL(csCoreMessage(QString)), this, SLOT(lineReceived(QString))); - core.start(); - core.connectToIrc("irc.moep.net", 6668); + //emit requestConnect("irc.scortum.moep.net", 6668); + emit requestConnect("irc.quakenet.org", 6668); } void ChannelWidget::enterPressed() { diff --git a/gui/channelwidget.h b/gui/channelwidget.h index b5cc2d49..932c5383 100644 --- a/gui/channelwidget.h +++ b/gui/channelwidget.h @@ -23,8 +23,6 @@ #include "ui_channelwidget.h" -#include "core.h" - class ChannelWidget : public QWidget { Q_OBJECT @@ -32,7 +30,8 @@ class ChannelWidget : public QWidget { ChannelWidget(QWidget *parent = 0); signals: - void inputLine(const QString &); + void requestConnect(QString, quint16); + void inputLine(QString); private slots: void enterPressed(); @@ -41,8 +40,6 @@ class ChannelWidget : public QWidget { private: Ui::ChannelWidget ui; - Core core; - Server server; }; diff --git a/gui/guiproxy.cpp b/gui/guiproxy.cpp index 4da47a48..4875d067 100644 --- a/gui/guiproxy.cpp +++ b/gui/guiproxy.cpp @@ -20,13 +20,17 @@ #include "guiproxy.h" -GUIProxy * GUIProxy::init() { - if(guiProxy) return guiProxy; - return new GUIProxy; +GUIProxy::GUIProxy() { + if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!"); + } void GUIProxy::gsUserInput(QString s) { send(GS_USER_INPUT, s); } +void GUIProxy::gsRequestConnect(QString h, quint16 p) { + send(GS_REQUEST_CONNECT, h, p); +} + GUIProxy *guiProxy; diff --git a/gui/guiproxy.h b/gui/guiproxy.h index 37bfd149..f3b48c0f 100644 --- a/gui/guiproxy.h +++ b/gui/guiproxy.h @@ -21,7 +21,7 @@ #ifndef _GUIPROXY_H_ #define _GUIPROXY_H_ -#include "../main/proxy_common.h" +#include "proxy_common.h" #include #include @@ -38,15 +38,17 @@ class GUIProxy : public QObject { void recv(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant()); public: - static GUIProxy * init(); + GUIProxy(); public slots: void gsUserInput(QString); + void gsRequestConnect(QString, quint16); signals: - void psCoreMessage(QString); + void csCoreMessage(QString); + friend class CoreProxy; }; diff --git a/gui/serverlist.cpp b/gui/serverlist.cpp index f6192501..677d3f41 100644 --- a/gui/serverlist.cpp +++ b/gui/serverlist.cpp @@ -19,7 +19,7 @@ ***************************************************************************/ #include "serverlist.h" -#include "proxy.h" +#include "quassel.h" /* NOTE: This dialog holds not only the server list, but also the identities. * This makes perfect sense given the fact that connections are initiated from diff --git a/main/main_core.cpp b/main/main_core.cpp index b7d33a43..90f46c18 100644 --- a/main/main_core.cpp +++ b/main/main_core.cpp @@ -23,6 +23,7 @@ #include "quassel.h" #include "core.h" +#include "coreproxy.h" int main(int argc, char **argv) { QCoreApplication app(argc, argv); @@ -31,14 +32,18 @@ int main(int argc, char **argv) { QCoreApplication::setOrganizationName("The Quassel Team"); Quassel::runMode = Quassel::CoreOnly; - quassel = Quassel::init(); - core = Core::init(); - //coreProxy = CoreProxy::init(); + quassel = new Quassel(); + coreProxy = new CoreProxy(); + core = new Core(); //Logger *logger = new Logger(); //Quassel::setLogger(logger); + core->init(); + int exitCode = app.exec(); + delete core; + delete coreProxy; delete quassel; return exitCode; } diff --git a/main/main_gui.cpp b/main/main_gui.cpp index 80e2f504..10bc53e1 100644 --- a/main/main_gui.cpp +++ b/main/main_gui.cpp @@ -34,8 +34,8 @@ int main(int argc, char **argv) { QApplication::setOrganizationName("The Quassel Team"); Quassel::runMode = Quassel::GUIOnly; - quassel = Quassel::init(); - guiProxy = GUIProxy::init(); + quassel = new Quassel(); + guiProxy = new GUIProxy(); MainWin mainWin; mainWin.show(); diff --git a/main/main_mono.cpp b/main/main_mono.cpp index 49078c1e..c7fb094c 100644 --- a/main/main_mono.cpp +++ b/main/main_mono.cpp @@ -25,6 +25,7 @@ #include "core.h" #include "quassel.h" #include "guiproxy.h" +#include "coreproxy.h" #include "mainwin.h" @@ -35,26 +36,42 @@ int main(int argc, char **argv) { QApplication::setOrganizationName("The Quassel Team"); Quassel::runMode = Quassel::Monolithic; - quassel = Quassel::init(); - core = Core::init(); - guiProxy = GUIProxy::init(); - // coreProxy = CoreProxy::init(); + quassel = new Quassel(); + guiProxy = new GUIProxy(); + coreProxy = new CoreProxy(); + core = new Core(); + + core->init(); MainWin mainWin; mainWin.show(); int exitCode = app.exec(); + delete core; delete guiProxy; + delete coreProxy; delete quassel; + return exitCode; } void GUIProxy::send(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { + coreProxy->recv(sig, arg1, arg2, arg3); +} +void CoreProxy::recv(GUISignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { + switch(sig) { + case GS_USER_INPUT: emit gsUserInput(arg1.toString()); break; + case GS_REQUEST_CONNECT: emit gsRequestConnect(arg1.toString(), arg2.toUInt()); break; + default: qWarning() << "Unknown signal in CoreProxy::recv: " << sig; + } +} - +void CoreProxy::send(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { + guiProxy->recv(sig, arg1, arg2, arg3); } void GUIProxy::recv(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { - - - + switch(sig) { + case CS_CORE_MESSAGE: emit csCoreMessage(arg1.toString()); break; + default: qWarning() << "Unknown signal in GUIProxy::recv: " << sig; + } } diff --git a/main/proxy_common.h b/main/proxy_common.h index 5f90c9e8..a25864c0 100644 --- a/main/proxy_common.h +++ b/main/proxy_common.h @@ -21,11 +21,11 @@ #ifndef _PROXY_COMMON_H_ #define _PROXY_COMMON_H_ -enum GUISignal { GS_USER_INPUT +enum GUISignal { GS_USER_INPUT, GS_REQUEST_CONNECT, }; -enum CoreSignal { GS_CORE_MESSAGE +enum CoreSignal { CS_CORE_MESSAGE }; diff --git a/main/quassel.cpp b/main/quassel.cpp index 6e90e13f..7ba190b1 100644 --- a/main/quassel.cpp +++ b/main/quassel.cpp @@ -28,12 +28,10 @@ extern void messageHandler(QtMsgType type, const char *msg); -Quassel * Quassel::init() { - if(quassel) return quassel; +Quassel::Quassel() { + if(quassel) qFatal("Trying to instantiate more than one Quassel object!"); qInstallMsgHandler(messageHandler); - quassel = new Quassel(); //initIconMap(); - return quassel; } /* @@ -95,5 +93,3 @@ void Quassel::initIconMap() { Quassel *quassel = 0; Quassel::RunMode Quassel::runMode; -QMutex Quassel::mutex; -QHash Quassel::data; diff --git a/main/quassel.h b/main/quassel.h index b3c942ba..3d2b5412 100644 --- a/main/quassel.h +++ b/main/quassel.h @@ -39,7 +39,7 @@ class Quassel : public QObject { Q_OBJECT public: - static Quassel * init(); + Quassel(); //static Logger *getLogger(); //static void setLogger(Logger *); @@ -63,9 +63,9 @@ class Quassel : public QObject { //static Logger *logger; // static QString iconPath; - static QHash iconMap; - static QMutex mutex; - static QHash data; + QHash iconMap; + QMutex mutex; + QHash data; }; class Exception {