From 0ac9ce4d7cf768d13993d6aa1d6b791c4149a843 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 28 Jun 2007 00:57:31 +0000 Subject: [PATCH] Cleaning up the closet... or at least the code. Tried to reduce the number of #includes, removing inter-file dependencies as far as possible. There is probably some work left especially in qtgui, though. Also I removed some obsolete files and split up CoreSession and QtGui in their own files. --- Quassel.kdevelop.filelist | 22 +- src/CMakeLists.txt | 6 +- src/client/CMakeLists.txt | 2 +- src/client/buffer.cpp | 15 +- src/client/buffer.h | 12 +- src/client/buffertreemodel.cpp | 2 +- src/client/buffertreemodel.h | 3 +- src/client/client.cpp | 8 +- src/client/client.h | 11 +- src/client/clientproxy.cpp | 2 - src/client/clientproxy.h | 36 +- src/client/treemodel.h | 4 +- src/common/CMakeLists.txt | 6 +- src/common/global.cpp | 6 +- src/common/global.h | 8 +- src/common/logger.cpp | 1 - src/common/logger.h | 2 +- src/common/main.cpp | 22 +- src/common/main_gui.cpp | 148 -------- src/common/message.cpp | 54 --- src/common/message.h | 4 +- src/common/proxy_common.h | 1 - src/common/quasselui.h | 1 - src/common/settings.cpp | 4 +- src/common/settings.h | 3 +- src/common/util.cpp | 2 - src/core/CMakeLists.txt | 6 +- src/core/backlog.cpp | 337 ------------------ src/core/backlog.h | 85 ----- src/core/core.cpp | 183 +--------- src/core/core.h | 102 +----- src/core/coreproxy.cpp | 39 -- src/core/coreproxy.h | 17 +- src/core/coresession.cpp | 177 +++++++++ src/core/coresession.h | 83 +++++ src/core/server.cpp | 7 +- src/core/server.h | 8 +- src/core/sqlitestorage.cpp | 1 + src/core/sqlitestorage.h | 3 +- src/core/storage.h | 6 +- src/qtgui/CMakeLists.txt | 15 +- src/qtgui/bufferviewwidget.cpp | 45 --- src/qtgui/bufferwidget.h | 2 - src/qtgui/channelwidgetinput.cpp | 2 + src/qtgui/channelwidgetinput.h | 4 +- src/qtgui/mainwin.cpp | 54 +-- src/qtgui/mainwin.h | 27 +- src/{common/main_core.cpp => qtgui/qtgui.cpp} | 63 ++-- src/qtgui/{bufferviewwidget.h => qtgui.h} | 51 ++- src/qtgui/style.h | 3 +- 50 files changed, 414 insertions(+), 1291 deletions(-) delete mode 100644 src/common/main_gui.cpp delete mode 100644 src/core/backlog.cpp delete mode 100644 src/core/backlog.h create mode 100644 src/core/coresession.cpp create mode 100644 src/core/coresession.h delete mode 100644 src/qtgui/bufferviewwidget.cpp rename src/{common/main_core.cpp => qtgui/qtgui.cpp} (60%) rename src/qtgui/{bufferviewwidget.h => qtgui.h} (60%) diff --git a/Quassel.kdevelop.filelist b/Quassel.kdevelop.filelist index 2d5153c0..dc089253 100644 --- a/Quassel.kdevelop.filelist +++ b/Quassel.kdevelop.filelist @@ -1,8 +1,4 @@ # KDevelop Custom Project File List -dev-notes -dev-notes/builtin_cmds.obsolete.cpp -dev-notes/paulk-mainwindow.ui -Makefile src src/client src/client/buffer.cpp @@ -18,13 +14,15 @@ src/client/treemodel.cpp src/client/treemodel.h src/CMakeLists.txt src/common +src/common/build_core.cpp +src/common/build_mono.cpp +src/common/build_qtgui.cpp src/common/CMakeLists.txt src/common/global.cpp src/common/global.h src/common/logger.cpp src/common/logger.h -src/common/main_core.cpp -src/common/main_gui.cpp +src/common/main.cpp src/common/message.cpp src/common/message.h src/common/proxy_common.h @@ -34,13 +32,13 @@ src/common/settings.h src/common/util.cpp src/common/util.h src/core -src/core/backlog.cpp -src/core/backlog.h src/core/CMakeLists.txt src/core/core.cpp src/core/core.h src/core/coreproxy.cpp src/core/coreproxy.h +src/core/coresession.cpp +src/core/coresession.h src/core/server.cpp src/core/server.h src/core/sqlitestorage.cpp @@ -54,8 +52,6 @@ src/qtgui/bufferview.cpp src/qtgui/bufferviewfilter.cpp src/qtgui/bufferviewfilter.h src/qtgui/bufferview.h -src/qtgui/bufferviewwidget.cpp -src/qtgui/bufferviewwidget.h src/qtgui/bufferwidget.cpp src/qtgui/bufferwidget.h src/qtgui/channelwidgetinput.cpp @@ -71,6 +67,8 @@ src/qtgui/identities.cpp src/qtgui/identities.h src/qtgui/mainwin.cpp src/qtgui/mainwin.h +src/qtgui/qtgui.cpp +src/qtgui/qtgui.h src/qtgui/serverlist.cpp src/qtgui/serverlist.h src/qtgui/settingsdlg.cpp @@ -99,7 +97,3 @@ src/qtgui/ui/nickeditdlg.ui src/qtgui/ui/servereditdlg.ui src/qtgui/ui/serverlistdlg.ui src/qtgui/ui/settingsdlg.ui -src/common/build_mono.cpp -src/common/build_qtgui.cpp -src/common/build_core.cpp -src/common/main.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7e0244ff..65a664ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,9 +24,9 @@ IF(NOT BUILD_MONO AND NOT BUILD_CORE AND NOT BUILD_QTGUI) MESSAGE(FATAL_ERROR "\nYou have not selected which parts of Quassel I should build. Aborting.\nRun 'cmake -DBUILD=', where contains one or more of 'core', 'gui' or 'monolithic', or 'all' to build everything.\n") ENDIF(NOT BUILD_MONO AND NOT BUILD_CORE AND NOT BUILD_QTGUI) -#IF(BUILD_CORE OR BUILD_QTGUI) -# MESSAGE(FATAL_ERROR "\nBuilding of standalone core or GUI not supported at this time. Please check back later.\n") -#ENDIF(BUILD_CORE OR BUILD_QTGUI) +IF(BUILD_CORE OR BUILD_QTGUI) + MESSAGE(FATAL_ERROR "\nBuilding of standalone core or GUI not supported at this time. Please check back later.\n") +ENDIF(BUILD_CORE OR BUILD_QTGUI) SET(CMAKE_BUILD_TYPE Debug) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 40a7695f..920eb977 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -3,4 +3,4 @@ SET(client_HDRS ) SET(client_MOCS buffer.h buffertreemodel.h client.h clientproxy.h treemodel.h) QT4_WRAP_CPP(_MOC ${client_MOCS}) -ADD_LIBRARY(client ${_MOC} ${client_SRCS} ${client_HDRS}) +ADD_LIBRARY(client ${client_SRCS} ${_MOC}) diff --git a/src/client/buffer.cpp b/src/client/buffer.cpp index c8f375d0..7f4d885a 100644 --- a/src/client/buffer.cpp +++ b/src/client/buffer.cpp @@ -17,18 +17,11 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "buffer.h" #include "client.h" -#include "buffer.h" #include "util.h" -/* -Buffer::Buffer(QString netname, QString bufname) { - Buffer(BufferId(0, netname, bufname)); - - -} -*/ Buffer::Buffer(BufferId bufid) { id = bufid; @@ -172,9 +165,3 @@ void Buffer::setOwnNick(QString nick) { _ownNick = nick; emit ownNickSet(nick); } - -/****************************************************************************************/ - - -/****************************************************************************************/ - diff --git a/src/client/buffer.h b/src/client/buffer.h index 2c361d3d..8e9bf6c0 100644 --- a/src/client/buffer.h +++ b/src/client/buffer.h @@ -21,18 +21,14 @@ #ifndef _BUFFER_H_ #define _BUFFER_H_ -#include - #include "global.h" -#include "message.h" -#include "quasselui.h" +class AbstractUiMsg; +class Message; struct BufferState; //!\brief Encapsulates the contents of a single channel, query or server status context. -/** A Buffer maintains a list of existing nicks and their status. New messages can be appended using - * displayMsg(). A buffer displays its contents by way of a BufferWidget, which can be shown - * (and created on demand) by calling showWidget(). +/** A Buffer maintains a list of existing nicks and their status. */ class Buffer : public QObject { Q_OBJECT @@ -106,6 +102,6 @@ class Buffer : public QObject { QList layoutedMsgs; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel) +Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel) #endif diff --git a/src/client/buffertreemodel.cpp b/src/client/buffertreemodel.cpp index 741215f0..3f0a2adb 100644 --- a/src/client/buffertreemodel.cpp +++ b/src/client/buffertreemodel.cpp @@ -20,7 +20,7 @@ #include // FIXME Dependency on QtGui! -#include "global.h" +#include "clientproxy.h" #include "buffertreemodel.h" /***************************************** diff --git a/src/client/buffertreemodel.h b/src/client/buffertreemodel.h index 9916edd4..23471ad8 100644 --- a/src/client/buffertreemodel.h +++ b/src/client/buffertreemodel.h @@ -25,12 +25,11 @@ #include "treemodel.h" #include "buffer.h" -#include "clientproxy.h" /***************************************** * Fancy Buffer Items *****************************************/ -class BufferTreeItem : public TreeItem{ +class BufferTreeItem : public TreeItem { Q_OBJECT public: diff --git a/src/client/client.cpp b/src/client/client.cpp index 30eeb51d..6be7e077 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -19,9 +19,11 @@ ***************************************************************************/ #include "client.h" -#include "clientproxy.h" + #include "buffer.h" #include "buffertreemodel.h" +#include "clientproxy.h" +#include "quasselui.h" #include "util.h" Client * Client::instanceptr = 0; @@ -33,8 +35,6 @@ QHash Client::bufferIds; QHash > Client::nicks; QHash Client::netConnected; QHash Client::ownNick; -//QList Client::coreBuffers; - Client *Client::instance() { if(instanceptr) return instanceptr; @@ -180,7 +180,6 @@ void Client::syncToCore() { BufferId id = vid.value(); 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 } connectedToCore = true; emit connected(); @@ -404,4 +403,3 @@ void Client::setOwnNick(QString net, QString nick) { } } - diff --git a/src/client/client.h b/src/client/client.h index 9bc40345..452bed07 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -21,16 +21,20 @@ #ifndef _CLIENT_H_ #define _CLIENT_H_ -#include -#include +#include +#include +#include -#include "quasselui.h" #include "buffer.h" #include "message.h" #include "proxy_common.h" +class AbstractUi; class ClientProxy; class BufferTreeModel; +class QtGui; + +class QTimer; class Client : public QObject { Q_OBJECT @@ -127,7 +131,6 @@ class Client : public QObject { static QHash > nicks; static QHash netConnected; static QHash ownNick; - //static QList coreBuffers; QTimer *layoutTimer; QList layoutQueue; diff --git a/src/client/clientproxy.cpp b/src/client/clientproxy.cpp index c991dba3..3614aa29 100644 --- a/src/client/clientproxy.cpp +++ b/src/client/clientproxy.cpp @@ -18,8 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include - #include "clientproxy.h" #include "util.h" #include "message.h" diff --git a/src/client/clientproxy.h b/src/client/clientproxy.h index abe7ca46..e66aa65a 100644 --- a/src/client/clientproxy.h +++ b/src/client/clientproxy.h @@ -18,18 +18,15 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _GUIPROXY_H_ -#define _GUIPROXY_H_ +#ifndef _CLIENTPROXY_H_ +#define _CLIENTPROXY_H_ + +#include #include "proxy_common.h" #include "message.h" #include "global.h" -#include -#include -#include -#include - class ClientProxy : public QObject { Q_OBJECT @@ -46,9 +43,6 @@ class ClientProxy : public QObject { 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(); - signals: void csCoreState(QVariant); void csServerState(QString, QVariant); @@ -71,36 +65,14 @@ class ClientProxy : public QObject { void csGeneric(CoreSignal, QVariant, QVariant, QVariant); - //void coreConnected(); - //void coreDisconnected(); - //void coreConnectionError(QString errorMsg); - - //void recvPartialItem(quint32 avail, quint32 size); - 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: - //void updateCoreData(QString); - - //void serverError(QAbstractSocket::SocketError); - //void serverHasData(); - private: ClientProxy(); static ClientProxy *instanceptr; - - //QTcpSocket socket; - //quint32 blockSize; - - //friend class CoreProxy; - }; -//extern ClientProxy *guiProxy; - - - #endif diff --git a/src/client/treemodel.h b/src/client/treemodel.h index a4039843..1941602f 100644 --- a/src/client/treemodel.h +++ b/src/client/treemodel.h @@ -21,7 +21,9 @@ #ifndef _TREEMODEL_H_ #define _TREEMODEL_H_ -#include +#include +#include +#include /***************************************** * general item used in the Tree Model diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 55457d2f..e4e49e6e 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,6 +1,6 @@ -SET(common_SRCS global.cpp logger.cpp util.cpp message.cpp settings.cpp) -SET(common_HDRS util.h message.h settings.h) +SET(common_SRCS global.cpp logger.cpp message.cpp settings.cpp util.cpp) +SET(common_HDRS message.h settings.h util.h) SET(common_MOCS global.h logger.h quasselui.h) QT4_WRAP_CPP(_MOC ${common_MOCS}) -ADD_LIBRARY(common ${_MOC} ${common_SRCS} ${common_HDRS}) +ADD_LIBRARY(common ${common_SRCS} ${_MOC}) diff --git a/src/common/global.cpp b/src/common/global.cpp index b92f7959..eb4ee8f8 100644 --- a/src/common/global.cpp +++ b/src/common/global.cpp @@ -17,16 +17,14 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include +#include #include "global.h" #include "logger.h" -#include "core.h" #include "message.h" #include "util.h" -#include -#include - extern void messageHandler(QtMsgType type, const char *msg); Global *Global::instanceptr = 0; diff --git a/src/common/global.h b/src/common/global.h index 49f97505..2723b66b 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -22,15 +22,17 @@ #define _GLOBAL_H_ /** The protocol version we use fo the communication between core and GUI */ -#define GUI_PROTOCOL 2 +#define GUI_PROTOCOL 3 #define BACKLOG_FORMAT 2 #define BACKLOG_STRING "QuasselIRC Backlog File" class Global; -#include -//#include +#include +#include +#include +#include /* Some global stuff */ typedef QMap VarMap; diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 25bb06b0..76fa916e 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -18,7 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "global.h" #include "logger.h" #include diff --git a/src/common/logger.h b/src/common/logger.h index ba8eba42..24a8bb16 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -21,7 +21,7 @@ #ifndef _LOGGER_H_ #define _LOGGER_H_ -#include +#include class Logger : public QObject { Q_OBJECT diff --git a/src/common/main.cpp b/src/common/main.cpp index 51de3c46..c53daabc 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -18,11 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include - -#include "global.h" #include "settings.h" -#include "quasselui.h" #if defined BUILD_CORE #include @@ -30,19 +26,19 @@ #elif defined BUILD_QTGUI #include -#include "style.h" #include "client.h" #include "clientproxy.h" -#include "mainwin.h" +#include "qtgui.h" +#include "style.h" #elif defined BUILD_MONO #include -#include "core.h" -#include "coreproxy.h" -#include "style.h" #include "client.h" #include "clientproxy.h" -#include "mainwin.h" +#include "core.h" +#include "coresession.h" +#include "qtgui.h" +#include "style.h" #else #error "Something is wrong - you need to #define a build mode!" @@ -59,8 +55,6 @@ int main(int argc, char **argv) { Global::runMode = Global::Monolithic; QApplication app(argc, argv); #endif - //AbstractUi *foo = new AbstractUi(); - //foo->init(); QCoreApplication::setOrganizationDomain("quassel-irc.org"); QCoreApplication::setApplicationName("Quassel IRC"); QCoreApplication::setOrganizationName("Quassel IRC Development Team"); @@ -77,8 +71,6 @@ int main(int argc, char **argv) { QtGui *gui = new QtGui(); Client::init(gui); gui->init(); -//#else -// Core::instance(); // create and init the core object #endif int exitCode = app.exec(); @@ -100,8 +92,8 @@ int main(int argc, char **argv) { #ifdef BUILD_QTGUI QVariant Client::connectToLocalCore(QString, QString) { return QVariant(); } void Client::disconnectFromLocalCore() {} -#elif defined BUILD_MONO +#elif defined BUILD_MONO QVariant Client::connectToLocalCore(QString user, QString passwd) { // TODO catch exceptions QVariant reply = Core::connectLocalClient(user, passwd); diff --git a/src/common/main_gui.cpp b/src/common/main_gui.cpp deleted file mode 100644 index e9bd6c8e..00000000 --- a/src/common/main_gui.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 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 - -#include -#include - -#include "style.h" -#include "global.h" -#include "guiproxy.h" -#include "coreconnectdlg.h" -#include "util.h" -#include "chatwidget.h" - -#include "mainwin.h" - -int main(int argc, char **argv) { - QApplication app(argc, argv); - QApplication::setOrganizationDomain("quassel-irc.org"); - QApplication::setApplicationName("Quassel IRC"); - QApplication::setOrganizationName("The Quassel Team"); - - Global::runMode = Global::GUIOnly; - Global::quasselDir = QDir::homePath() + "/.quassel"; - - global = new Global(); - guiProxy = new GuiProxy(); - - Style::init(); - - MainWin mainWin; - mainWin.init(); - int exitCode = app.exec(); - delete guiProxy; - delete global; - return exitCode; -} - -void MainWin::syncToCore() { - Q_ASSERT(!global->getData("CoreReady").toBool()); - // ok, we are running as standalone GUI - coreConnectDlg = new CoreConnectDlg(this); - if(coreConnectDlg->exec() != QDialog::Accepted) { - //qApp->quit(); - exit(1); - } - VarMap state = coreConnectDlg->getCoreState().toMap(); - delete coreConnectDlg; - VarMap data = state["CoreData"].toMap(); - QString key; - foreach(key, data.keys()) { - global->updateData(key, data[key]); - } - if(!global->getData("CoreReady").toBool()) { - QMessageBox::critical(this, tr("Fatal Error"), tr("Could not synchronize with Quassel Core!
Quassel GUI will be aborted."), QMessageBox::Abort); - //qApp->quit(); - exit(1); - } - /* - foreach(QString net, state["CoreBackLog"].toMap().keys()) { - QByteArray logbuf = state["CoreBackLog"].toMap()[net].toByteArray(); - QDataStream in(&logbuf, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_4_2); - while(!in.atEnd()) { - Message msg; in >> msg; - coreBackLog[net].append(msg); - } - qDebug() << net << coreBackLog[net].count(); - } - */ - coreBuffers.clear(); - foreach(QVariant v, state["CoreBuffers"].toList()) { coreBuffers.append(v.value()); } -} - -/* - -GuiProxy::GuiProxy() { - if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!"); - - blockSize = 0; - - connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData())); - connect(&socket, SIGNAL(connected()), this, SIGNAL(coreConnected())); - connect(&socket, SIGNAL(disconnected()), this, SIGNAL(coreDisconnected())); - connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError))); - - connect(global, SIGNAL(dataPutLocally(QString)), this, SLOT(updateCoreData(QString))); - connect(this, SIGNAL(csUpdateGlobalData(QString, QVariant)), global, SLOT(updateData(QString, QVariant))); - -} - -void GuiProxy::connectToCore(QString host, quint16 port) { - socket.connectToHost(host, port); -} - -void GuiProxy::disconnectFromCore() { - socket.close(); -} - -void GuiProxy::serverError(QAbstractSocket::SocketError) { - emit coreConnectionError(socket.errorString()); - //qFatal(QString("Connection error: %1").arg(socket.errorString()).toAscii()); -} - -void GuiProxy::serverHasData() { - QVariant item; - while(readDataFromDevice(&socket, blockSize, item)) { - emit recvPartialItem(1,1); - QList sigdata = item.toList(); - Q_ASSERT(sigdata.size() == 4); - recv((CoreSignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]); - blockSize = 0; - } - if(blockSize > 0) { - emit recvPartialItem(socket.bytesAvailable(), blockSize); - } -} -*/ -/* -void GuiProxy::send(GuiSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { - QList 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) { - QVariant data = global->getData(key); - send(GS_UPDATE_GLOBAL_DATA, key, data); -} diff --git a/src/common/message.cpp b/src/common/message.cpp index e564b84f..8b9f1584 100644 --- a/src/common/message.cpp +++ b/src/common/message.cpp @@ -21,60 +21,6 @@ #include "message.h" #include -/* -Message Message::plain(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Plain, _text, _sender, _flags); -} - -Message Message::notice(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Notice, _text, _sender, _flags); -} - -Message Message::action(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Action, _text, _sender, _flags); -} - -Message Message::kick(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Kick, _text, _sender, _flags); -} - -Message Message::join(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Join, _text, _sender, _flags); -} - -Message Message::part(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Part, _text, _sender, _flags); -} - -Message Message::nick(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Nick, _text, _sender, _flags); -} - -Message Message::mode(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Mode, _text, _sender, _flags); -} - -Message Message::quit(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Quit, _text, _sender, _flags); -} - -Message Message::kill(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Kill, _text, _sender, _flags); -} - -Message Message::server(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Server, _text, _sender, _flags); -} - -Message Message::info(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Info, _text, _sender, _flags); -} - -Message Message::error(QString _target, QString _text, QString _sender, quint8 _flags) { - return Message(_target, Error, _text, _sender, _flags); -} -*/ - QDataStream &operator<<(QDataStream &out, const Message &msg) { /* out << (quint32)msg.timeStamp.toTime_t() << (quint8)msg.type << (quint8)msg.flags diff --git a/src/common/message.h b/src/common/message.h index 8cfa23ad..36950ec0 100644 --- a/src/common/message.h +++ b/src/common/message.h @@ -21,7 +21,9 @@ #ifndef _MESSAGE_H_ #define _MESSAGE_H_ -#include +#include +#include + #include "global.h" struct Message { diff --git a/src/common/proxy_common.h b/src/common/proxy_common.h index 2eacb0df..609b5933 100644 --- a/src/common/proxy_common.h +++ b/src/common/proxy_common.h @@ -33,5 +33,4 @@ enum CoreSignal { CS_CORE_STATE, CS_SERVER_CONNECTED, CS_SERVER_DISCONNECTED, CS }; - #endif diff --git a/src/common/quasselui.h b/src/common/quasselui.h index 2b31170f..5cfc5f05 100644 --- a/src/common/quasselui.h +++ b/src/common/quasselui.h @@ -41,7 +41,6 @@ class AbstractUi : public QObject { Q_OBJECT public: -// virtual ~AbstractUi() {}; virtual void init() {}; // called after the client is initialized virtual AbstractUiMsg *layoutMsg(const Message &) = 0; diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 6f2ba0f0..77144c7b 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -18,12 +18,12 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "settings.h" +#include +#include "settings.h" Settings *settings; - void Settings::init() { curProfile = QObject::tr("Default"); } diff --git a/src/common/settings.h b/src/common/settings.h index f2e0d384..4ef26640 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -21,7 +21,8 @@ #ifndef _SETTINGS_H_ #define _SETTINGS_H_ -#include +#include +#include class Settings { diff --git a/src/common/util.cpp b/src/common/util.cpp index b8652532..2238cbed 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -20,8 +20,6 @@ #include "util.h" -#include - QString nickFromMask(QString mask) { return mask.section('!', 0, 0); } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index fa1e53ea..db4cda71 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,6 +1,6 @@ -SET(core_SRCS core.cpp coreproxy.cpp server.cpp backlog.cpp storage.cpp sqlitestorage.cpp) +SET(core_SRCS core.cpp coreproxy.cpp coresession.cpp server.cpp sqlitestorage.cpp storage.cpp) SET(core_HDRS ) -SET(core_MOCS core.h coreproxy.h server.h backlog.h storage.h sqlitestorage.h) +SET(core_MOCS core.h coreproxy.h coresession.h server.h sqlitestorage.h storage.h) QT4_WRAP_CPP(_MOC ${core_MOCS}) -ADD_LIBRARY(core ${_MOC} ${core_SRCS} ${core_HDRS}) +ADD_LIBRARY(core ${core_SRCS} ${_MOC}) diff --git a/src/core/backlog.cpp b/src/core/backlog.cpp deleted file mode 100644 index 6a222afc..00000000 --- a/src/core/backlog.cpp +++ /dev/null @@ -1,337 +0,0 @@ -/*************************************************************************** - * 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 "backlog.h" -#include "util.h" - -#define DBVERSION 1 - -Backlog::Backlog() { - - -} - - -Backlog::~Backlog() { - logDb.close(); - - // FIXME Old stuff - foreach(QDataStream *s, logStreams) { - delete s; - } - foreach(QFile *f, logFiles) { - if(f->isOpen()) f->close(); - delete f; - } -} - - -void Backlog::init(QString _user) { - user = _user; - QDir backlogDir = QDir(Global::quasselDir); - if(!backlogDir.exists()) { - qWarning(QString("Creating backlog directory \"%1\"...").arg(backlogDir.absolutePath()).toAscii()); - if(!backlogDir.mkpath(backlogDir.absolutePath())) { - qWarning(QString("Could not create backlog directory! Disabling logging...").toAscii()); - backlogEnabled = false; - return; - } - } - QString backlogFile = Global::quasselDir + "/quassel-backlog.sqlite"; - logDb = QSqlDatabase::addDatabase("QSQLITE", user); - logDb.setDatabaseName(backlogFile); - bool ok = logDb.open(); - if(!ok) { - qWarning(tr("Could not open backlog database: %1").arg(logDb.lastError().text()).toAscii()); - qWarning(tr("Disabling logging...").toAscii()); - backlogEnabled = false; return; - } - - if(!logDb.transaction()) qWarning(tr("Database driver does not support transactions. This might lead to a corrupt database!").toAscii()); - QString tname = QString("'Backlog$%1$'").arg(user); - QSqlQuery query(logDb); - /* DEBUG */ - //query.exec(QString("DROP TABLE %1").arg(tname)); // DEBUG - //query.exec(QString("DROP TABLE 'Senders$%1$'").arg(user)); - //query.exec(QString("DROP TABLE 'Buffers$%1$'").arg(user)); - /* END DEBUG */ - query.exec(QString("CREATE TABLE IF NOT EXISTS %1 (" - "MsgId INTEGER PRIMARY KEY AUTOINCREMENT," - "Time INTEGER," - "BufferId INTEGER," - "Type INTEGER," - "Flags INTEGER," - "SenderId INTEGER," - "Text BLOB" - ")").arg(tname)); - query.exec(QString("INSERT OR REPLACE INTO %1 (MsgId, SenderId, Text) VALUES (0, '$VERSION$', %2)").arg(tname).arg(DBVERSION)); - query.exec(QString("CREATE TABLE IF NOT EXISTS 'Senders$%1$' (SenderId INTEGER PRIMARY KEY AUTOINCREMENT, Sender TEXT)").arg(user)); - query.exec(QString("CREATE TABLE IF NOT EXISTS 'Buffers$%1$' (BufferId INTEGER PRIMARY KEY AUTOINCREMENT, GroupId INTEGER, Network TEXT, Buffer TEXT)").arg(user)); - if(query.lastError().isValid()) { - qWarning(tr("Could not create backlog table: %1").arg(query.lastError().text()).toAscii()); - qWarning(tr("Disabling logging...").toAscii()); - logDb.rollback(); - backlogEnabled = false; return; - } - // Find the next free uid numbers - query.exec(QString("SELECT MsgId FROM %1 ORDER BY MsgId DESC LIMIT 1").arg(tname)); - query.first(); - if(query.value(0).isValid()) nextMsgId = query.value(0).toUInt() + 1; - else { - qWarning(tr("Something is wrong with the backlog database! %1").arg(query.lastError().text()).toAscii()); - nextMsgId = 1; - } - query.exec(QString("SELECT BufferId FROM 'Buffers$%1$' ORDER BY BufferId DESC LIMIT 1").arg(user)); - if(query.first()) { - if(query.value(0).isValid()) nextBufferId = query.value(0).toUInt() + 1; - else { - qWarning(tr("Something is wrong with the backlog database! %1").arg(query.lastError().text()).toAscii()); - nextBufferId = 0; - } - } else nextBufferId = 0; - query.exec(QString("SELECT SenderId FROM 'Senders$%1$' ORDER BY SenderId DESC LIMIT 1").arg(user)); - if(query.first()) { - if(query.value(0).isValid()) nextSenderId = query.value(0).toUInt() + 1; - else { - qWarning(tr("Something is wrong with the backlog database! %1").arg(query.lastError().text()).toAscii()); - nextSenderId = 0; - } - } else nextSenderId = 0; - logDb.commit(); - backlogEnabled = true; -} - -uint Backlog::logMessage(Message msg) { - if(!backlogEnabled) return 0; - bool ok; - logDb.transaction(); - QSqlQuery query(logDb); - QString s = msg.sender; s.replace('\'', "''"); - QString t = msg.text; t.replace('\'', "''"); - // Let's do some space-saving optimizations... - query.exec(QString("SELECT SenderId FROM 'Senders$%1$' WHERE Sender == '%2'").arg(user).arg(s)); - int suid; - if(!query.first()) { - query.exec(QString("INSERT INTO 'Senders$%1$' (SenderId, Sender) VALUES (%2, '%3')").arg(user).arg(nextSenderId).arg(s)); - suid = nextSenderId; - } else suid = query.value(0).toInt(); - query.exec(QString("INSERT INTO 'Backlog$%1$' (MsgId, Time, BufferId, Type, Flags, SenderId, Text) VALUES (%2, %3, %4, %5, %6, %7, X'%8')").arg(user) - .arg(nextMsgId).arg(msg.timeStamp.toTime_t()).arg(msg.buffer.uid()).arg(msg.type).arg(msg.flags).arg(suid).arg(t.toUtf8().toHex().constData())); - - if(query.lastError().isValid()) { - qWarning(tr("Database error while logging: %1").arg(query.lastError().text()).toAscii()); - logDb.rollback(); - return 0; - } - - nextMsgId++; - if(suid == nextSenderId) nextSenderId++; - logDb.commit(); - return nextMsgId - 1; -} - -// TODO: optimize by keeping free IDs in memory? What about deleted IDs? Nickchanges for queries? -BufferId Backlog::getBufferId(QString net, QString buf) { - if(!backlogEnabled) { - return BufferId(0, net, buf); - } - //QByteArray n = net.toUtf8().toHex(); - //QByteArray b = buf.toUtf8().toHex(); - bool flg = false; - logDb.transaction(); - QSqlQuery query(logDb); - int uid = -1; - query.exec(QString("SELECT BufferId FROM 'Buffers$%1$' WHERE Network == '%2' AND Buffer == '%3'").arg(user).arg(net).arg(buf)); - if(!query.first()) { - // TODO: joined buffers/queries - query.exec(QString("INSERT INTO 'Buffers$%1$' (BufferId, GroupId, Network, Buffer) VALUES (%2, %2, '%3', '%4')").arg(user).arg(nextBufferId).arg(net).arg(buf)); - uid = nextBufferId++; - flg = true; - } else uid = query.value(0).toInt(); - logDb.commit(); - BufferId id(uid, net, buf, uid); // FIXME (joined buffers) - if(flg) emit bufferIdUpdated(id); - return id; // FIXME (joined buffers) -} - -QList Backlog::requestBuffers(QDateTime since) { - QList result; - QSqlQuery query(logDb); - if(!since.isValid()) { - query.exec(QString("SELECT BufferId, GroupId, Network, Buffer FROM 'Buffers$%1$'").arg(user)); - } else { - query.exec(QString("SELECT DISTINCT 'Buffers$%1$'.BufferId, GroupId, Network, Buffer FROM 'Buffers$%1$' NATURAL JOIN 'Backlog$%1$' " - "WHERE Time >= %2").arg(user).arg(since.toTime_t())); - } - while(query.next()) { - result.append(BufferId(query.value(0).toUInt(), query.value(2).toString(), query.value(3).toString(), query.value(1).toUInt())); - } - return result; -} - -QList Backlog::requestMsgs(BufferId id, int lastlines, int offset) { - QList result; - QSqlQuery query(logDb); - QString limit; - if(lastlines > 0) limit = QString("LIMIT %1").arg(lastlines); - query.exec(QString("SELECT MsgId, Time, Type, Flags, Sender, Text FROM 'Senders$%1$' NATURAL JOIN 'Backlog$%1$' " - "WHERE BufferId IN (SELECT BufferId FROM 'Buffers$%1$' WHERE GroupId == %2) ORDER BY MsgId DESC %3").arg(user).arg(id.groupId()).arg(limit)); - while(query.next()) { - if(offset >= 0 && query.value(0).toInt() >= offset) continue; - Message msg(QDateTime::fromTime_t(query.value(1).toInt()), id, (Message::Type)query.value(2).toUInt(), QString::fromUtf8(query.value(5).toByteArray()), - query.value(4).toString(), query.value(3).toUInt()); - msg.msgId = query.value(0).toUInt(); - result.append(msg); - } - return result; -} - - -// OBSOLETE -// This is kept here for importing the old file-based backlog. - -void Backlog::importOldBacklog() { - qDebug() << "Deleting backlog database..."; - logDb.exec(QString("DELETE FROM 'Backlog$%1$' WHERE SenderId != '$VERSION$'").arg(user)); - logDb.exec(QString("DELETE FROM 'Senders$%1$'").arg(user)); - logDb.exec(QString("DELETE FROM 'Buffers$%1$'").arg(user)); - nextMsgId = 1; nextBufferId = 1; nextSenderId = 1; - qDebug() << "Importing old backlog files..."; - initBackLogOld(); - if(!backLogEnabledOld) return; - logDb.exec("VACUUM"); - qDebug() << "Backlog successfully imported, you have to restart Quassel now!"; - exit(0); - -} - -// file name scheme: quassel-backlog-2006-29-10.bin -void Backlog::initBackLogOld() { - backLogDir = QDir(Global::quasselDir + "/backlog"); - if(!backLogDir.exists()) { - qWarning(QString("Creating backlog directory \"%1\"...").arg(backLogDir.absolutePath()).toAscii()); - if(!backLogDir.mkpath(backLogDir.absolutePath())) { - qWarning(QString("Could not create backlog directory! Disabling logging...").toAscii()); - backLogEnabledOld = false; - return; - } - } - backLogDir.refresh(); - //if(!backLogDir.isReadable()) { - // qWarning(QString("Cannot read directory \"%1\". Disabling logging...").arg(backLogDir.absolutePath()).toAscii()); - // backLogEnabled = false; - // return; - //} - QStringList networks = backLogDir.entryList(QDir::Dirs|QDir::NoDotAndDotDot|QDir::Readable, QDir::Name); - foreach(QString net, networks) { - QDir dir(backLogDir.absolutePath() + "/" + net); - if(!dir.exists()) { - qWarning(QString("Could not change to directory \"%1\"!").arg(dir.absolutePath()).toAscii()); - continue; - } - QStringList logs = dir.entryList(QStringList("quassel-backlog-*.bin"), QDir::Files|QDir::Readable, QDir::Name); - foreach(QString name, logs) { - QFile f(dir.absolutePath() + "/" + name); - if(!f.open(QIODevice::ReadOnly)) { - qWarning(QString("Could not open \"%1\" for reading!").arg(f.fileName()).toAscii()); - continue; - } - QDataStream in(&f); - in.setVersion(QDataStream::Qt_4_2); - QByteArray verstring; quint8 vernum; in >> verstring >> vernum; - if(verstring != BACKLOG_STRING) { - qWarning(QString("\"%1\" is not a Quassel backlog file!").arg(f.fileName()).toAscii()); - f.close(); continue; - } - if(vernum != BACKLOG_FORMAT) { - qWarning(QString("\"%1\": Version mismatch!").arg(f.fileName()).toAscii()); - f.close(); continue; - } - qDebug() << "Reading backlog from" << f.fileName(); - logFileDates[net] = QDate::fromString(f.fileName(), - QString("'%1/quassel-backlog-'yyyy-MM-dd'.bin'").arg(dir.absolutePath())); - if(!logFileDates[net].isValid()) { - qWarning(QString("\"%1\" has an invalid file name!").arg(f.fileName()).toAscii()); - } - while(!in.atEnd()) { - quint8 t, f; - quint32 ts; - QByteArray s, m, targ; - in >> ts >> t >> f >> targ >> s >> m; - QString target = QString::fromUtf8(targ); - QString sender = QString::fromUtf8(s); - QString text = QString::fromUtf8(m); - BufferId id; - if((f & Message::PrivMsg) && !(f & Message::Self)) { - id = getBufferId(net, sender); - } else { - id = getBufferId(net, target); - } - Message msg(QDateTime::fromTime_t(ts), id, (Message::Type)t, text, sender, f); - //backLog[net].append(m); - logMessage(msg); - } - f.close(); - } - } - backLogEnabledOld = true; -} - - -/** Log a core message (emitted via a displayMsg() signal) to the backlog file. - * If a file for the current day does not exist, one will be created. Otherwise, messages will be appended. - * The file header is the string defined by BACKLOG_STRING, followed by a quint8 specifying the format - * version (BACKLOG_FORMAT). The rest is simply serialized Message objects. - */ -void Backlog::logMessageOld(QString net, Message msg) { - backLog[net].append(msg); - if(!logFileDirs.contains(net)) { - QDir dir(backLogDir.absolutePath() + "/" + net); - if(!dir.exists()) { - qWarning(QString("Creating backlog directory \"%1\"...").arg(dir.absolutePath()).toAscii()); - if(!dir.mkpath(dir.absolutePath())) { - qWarning(QString("Could not create backlog directory!").toAscii()); - return; - } - } - logFileDirs[net] = dir; - Q_ASSERT(!logFiles.contains(net) && !logStreams.contains(net)); - if(!logFiles.contains(net)) logFiles[net] = new QFile(); - if(!logStreams.contains(net)) logStreams[net] = new QDataStream(); - } - if(!logFileDates[net].isValid() || logFileDates[net] < QDate::currentDate()) { - if(logFiles[net]->isOpen()) logFiles[net]->close(); - logFileDates[net] = QDate::currentDate(); - } - if(!logFiles[net]->isOpen()) { - logFiles[net]->setFileName(QString("%1/%2").arg(logFileDirs[net].absolutePath()) - .arg(logFileDates[net].toString("'quassel-backlog-'yyyy-MM-dd'.bin'"))); - if(!logFiles[net]->open(QIODevice::WriteOnly|QIODevice::Append|QIODevice::Unbuffered)) { - qWarning(QString("Could not open \"%1\" for writing: %2") - .arg(logFiles[net]->fileName()).arg(logFiles[net]->errorString()).toAscii()); - return; - } - logStreams[net]->setDevice(logFiles[net]); logStreams[net]->setVersion(QDataStream::Qt_4_2); - if(!logFiles[net]->size()) *logStreams[net] << BACKLOG_STRING << (quint8)BACKLOG_FORMAT; - } - *logStreams[net] << msg; -} - - diff --git a/src/core/backlog.h b/src/core/backlog.h deleted file mode 100644 index 9dc0dcf1..00000000 --- a/src/core/backlog.h +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * 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. * - ***************************************************************************/ - -#ifndef _BACKLOG_H_ -#define _BACKLOG_H_ - -#include -#include - -#include "global.h" -#include "message.h" - -// TODO: is this threadsafe? should it be? -class Backlog : public QObject { - Q_OBJECT - - public: - Backlog(); - ~Backlog(); - - void init(QString user); - void setDefaultSettings(int lines = -1, QDateTime time = QDateTime()); - void setSettings(QString network, QString buffer, int lines = -1, QDateTime time = QDateTime()); - - BufferId getBufferId(QString network, QString buffer); - uint logMessage(Message msg); - - QList requestMsgs(BufferId, int lastlines = -1, int offset = -1); - QList requestMsgs(BufferId, QDateTime since, int offset = -1); - //QList requestMsgRange(BufferId, int first, int last); - - QList requestBuffers(QDateTime since = QDateTime()); - - public slots: - void importOldBacklog(); - - signals: - void bufferIdUpdated(BufferId); // sent also if a new bufferid is created - - private: - QString user; - bool backlogEnabled; - QSqlDatabase logDb; - - uint nextMsgId, nextBufferId, nextSenderId; - - QTimer cleanupTimer; - - void cleanup(); - - // Old stuff, just for importing old file-based data - void initBackLogOld(); - void logMessageOld(QString net, Message); - - bool backLogEnabledOld; - QDir backLogDir; - QHash > backLog; - //QHash netIdx; - QHash logFiles; - QHash logStreams; - QHash logFileDates; - QHash logFileDirs; - -}; - - - -#endif diff --git a/src/core/core.cpp b/src/core/core.cpp index f9bc84fa..e6b8c7f3 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -19,14 +19,9 @@ ***************************************************************************/ #include "core.h" -#include "server.h" -#include "global.h" -#include "util.h" -#include "coreproxy.h" +#include "coresession.h" #include "sqlitestorage.h" - -#include -#include +#include "util.h" Core *Core::instanceptr = 0; @@ -254,177 +249,3 @@ void Core::recvProxySignal(CoreSignal sig, QVariant arg1, QVariant arg2, QVarian if(validClients[socket] == uid) writeDataToDevice(socket, QVariant(sigdata)); } } - -/* - // Read global settings from config file - QSettings s; - s.beginGroup("Global"); - QString key; - foreach(key, s.childKeys()) { - global->updateData(key, s.value(key)); - } - - global->updateData("CoreReady", true); - // Now that we are in sync, we can connect signals to automatically store further updates. - // I don't think we care if global data changed locally or if it was updated by a client. - connect(global, SIGNAL(dataUpdatedRemotely(QString)), SLOT(globalDataUpdated(QString))); - connect(global, SIGNAL(dataPutLocally(QString)), SLOT(globalDataUpdated(QString))); - -} - */ - -CoreSession::CoreSession(UserId uid, Storage *_storage) : user(uid), storage(_storage) { - coreProxy = new CoreProxy(); - - connect(coreProxy, SIGNAL(send(CoreSignal, QVariant, QVariant, QVariant)), this, SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant))); - connect(coreProxy, SIGNAL(requestServerStates()), this, SIGNAL(serverStateRequested())); - connect(coreProxy, SIGNAL(gsRequestConnect(QStringList)), this, SLOT(connectToIrc(QStringList))); - connect(coreProxy, SIGNAL(gsUserInput(BufferId, QString)), this, SLOT(msgFromGui(BufferId, QString))); - connect(coreProxy, SIGNAL(gsImportBacklog()), storage, SLOT(importOldBacklog())); - connect(coreProxy, SIGNAL(gsRequestBacklog(BufferId, QVariant, QVariant)), this, SLOT(sendBacklog(BufferId, QVariant, QVariant))); - connect(coreProxy, SIGNAL(gsRequestNetworkStates()), this, SLOT(sendServerStates())); - connect(this, SIGNAL(displayMsg(Message)), coreProxy, SLOT(csDisplayMsg(Message))); - connect(this, SIGNAL(displayStatusMsg(QString, QString)), coreProxy, SLOT(csDisplayStatusMsg(QString, QString))); - connect(this, SIGNAL(backlogData(BufferId, QList, bool)), coreProxy, SLOT(csBacklogData(BufferId, QList, bool))); - connect(this, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId))); - connect(storage, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId))); - connect(Global::instance(), SIGNAL(dataUpdatedRemotely(UserId, QString)), this, SLOT(globalDataUpdated(UserId, QString))); - connect(Global::instance(), SIGNAL(dataPutLocally(UserId, QString)), this, SLOT(globalDataUpdated(UserId, QString))); -} - -CoreSession::~CoreSession() { - -} - -UserId CoreSession::userId() { - return user; -} - -void CoreSession::processSignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { - coreProxy->recv(sig, arg1, arg2, arg3); -} - -void CoreSession::globalDataUpdated(UserId uid, QString key) { - Q_ASSERT(uid == userId()); - QVariant data = Global::data(userId(), key); - QSettings s; - s.setValue(QString("Global/%1/").arg(userId())+key, data); -} - -void CoreSession::connectToIrc(QStringList networks) { - foreach(QString net, networks) { - if(servers.contains(net)) { - - } else { - Server *server = new Server(userId(), net); - connect(this, SIGNAL(serverStateRequested()), server, SLOT(sendState())); - connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString))); - connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString))); - connect(this, SIGNAL(msgFromGui(QString, QString, QString)), server, SLOT(userInput(QString, QString, QString))); - - connect(server, SIGNAL(connected(QString)), this, SLOT(serverConnected(QString))); - connect(server, SIGNAL(disconnected(QString)), this, SLOT(serverDisconnected(QString))); - - connect(server, SIGNAL(serverState(QString, VarMap)), coreProxy, SLOT(csServerState(QString, VarMap))); - //connect(server, SIGNAL(displayMsg(Message)), this, SLOT(recvMessageFromServer(Message))); - connect(server, SIGNAL(displayMsg(Message::Type, QString, QString, QString, quint8)), this, SLOT(recvMessageFromServer(Message::Type, QString, QString, QString, quint8))); - connect(server, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString))); - connect(server, SIGNAL(modeSet(QString, QString, QString)), coreProxy, SLOT(csModeSet(QString, QString, QString))); - connect(server, SIGNAL(topicSet(QString, QString, QString)), coreProxy, SLOT(csTopicSet(QString, QString, QString))); - connect(server, SIGNAL(nickAdded(QString, QString, VarMap)), coreProxy, SLOT(csNickAdded(QString, QString, VarMap))); - connect(server, SIGNAL(nickRenamed(QString, QString, QString)), coreProxy, SLOT(csNickRenamed(QString, QString, QString))); - connect(server, SIGNAL(nickRemoved(QString, QString)), coreProxy, SLOT(csNickRemoved(QString, QString))); - connect(server, SIGNAL(nickUpdated(QString, QString, VarMap)), coreProxy, SLOT(csNickUpdated(QString, QString, VarMap))); - connect(server, SIGNAL(ownNickSet(QString, QString)), coreProxy, SLOT(csOwnNickSet(QString, QString))); - connect(server, SIGNAL(queryRequested(QString, QString)), coreProxy, SLOT(csQueryRequested(QString, QString))); - // TODO add error handling - connect(server, SIGNAL(connected(QString)), coreProxy, SLOT(csServerConnected(QString))); - connect(server, SIGNAL(disconnected(QString)), coreProxy, SLOT(csServerDisconnected(QString))); - - server->start(); - servers[net] = server; - } - emit connectToIrc(net); - } -} - -void CoreSession::serverConnected(QString net) { - storage->getBufferId(userId(), net); // create status buffer -} - -void CoreSession::serverDisconnected(QString net) { - delete servers[net]; - servers.remove(net); - coreProxy->csServerDisconnected(net); -} - -void CoreSession::msgFromGui(BufferId bufid, QString msg) { - emit msgFromGui(bufid.network(), bufid.buffer(), msg); -} - -// ALL messages coming pass through these functions before going to the GUI. -// So this is the perfect place for storing the backlog and log stuff. - -void CoreSession::recvMessageFromServer(Message::Type type, QString target, QString text, QString sender, quint8 flags) { - Server *s = qobject_cast(this->sender()); - Q_ASSERT(s); - BufferId buf; - if((flags & Message::PrivMsg) && !(flags & Message::Self)) { - buf = storage->getBufferId(user, s->getNetwork(), nickFromMask(sender)); - } else { - buf = storage->getBufferId(user, s->getNetwork(), target); - } - Message msg(buf, type, text, sender, flags); - msg.msgId = storage->logMessage(msg); //qDebug() << msg.msgId; - Q_ASSERT(msg.msgId); - emit displayMsg(msg); -} - -void CoreSession::recvStatusMsgFromServer(QString msg) { - Server *s = qobject_cast(sender()); - Q_ASSERT(s); - emit displayStatusMsg(s->getNetwork(), msg); -} - - -QList CoreSession::buffers() const { - return storage->requestBuffers(user); -} - - -QVariant CoreSession::sessionState() { - VarMap v; - QList bufs; - foreach(BufferId id, storage->requestBuffers(user)) { bufs.append(QVariant::fromValue(id)); } - v["Buffers"] = bufs; - - return v; -} - -void CoreSession::sendServerStates() { - emit serverStateRequested(); -} - -void CoreSession::sendBacklog(BufferId id, QVariant v1, QVariant v2) { - QList log; - QList msglist; - if(v1.type() == QVariant::DateTime) { - - - } else { - msglist = storage->requestMsgs(id, v1.toInt(), v2.toInt()); - } - - // Send messages out in smaller packages - we don't want to make the signal data too large! - for(int i = 0; i < msglist.count(); i++) { - log.append(QVariant::fromValue(msglist[i])); - if(log.count() >= 5) { - emit backlogData(id, log, i >= msglist.count() - 1); - log.clear(); - } - } - if(log.count() > 0) emit backlogData(id, log, true); -} - - -//Core *core = 0; diff --git a/src/core/core.h b/src/core/core.h index aec04693..374d8210 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -23,14 +23,13 @@ #include #include -#include +#include +#include -#include "server.h" -#include "storage.h" -#include "global.h" #include "coreproxy.h" class CoreSession; +class Storage; class Core : public QObject { Q_OBJECT @@ -80,99 +79,4 @@ class Core : public QObject { QHash blockSizes; }; -class CoreSession : public QObject { - Q_OBJECT - - public: - CoreSession(UserId, Storage *); - ~CoreSession(); - - QList buffers() const; - inline UserId userId(); - QVariant sessionState(); - CoreProxy *proxy(); - - public slots: - void connectToIrc(QStringList); - void processSignal(ClientSignal, QVariant, QVariant, QVariant); - void sendBacklog(BufferId, QVariant, QVariant); - void msgFromGui(BufferId, QString message); - void sendServerStates(); - - signals: - void proxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant()); - - void msgFromGui(QString net, QString buf, QString message); - void displayMsg(Message message); - void displayStatusMsg(QString, QString); - - void connectToIrc(QString net); - void disconnectFromIrc(QString net); - void serverStateRequested(); - - void backlogData(BufferId, QList, bool done); - - void bufferIdUpdated(BufferId); - - private slots: - //void recvProxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant()); - void globalDataUpdated(UserId, QString); - void recvStatusMsgFromServer(QString msg); - void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None); - void serverConnected(QString net); - void serverDisconnected(QString net); - - private: - CoreProxy *coreProxy; - Storage *storage; - QHash servers; - UserId user; - -}; - -/* -class Core : public QObject { - Q_OBJECT - - public: - - Core(); - ~Core(); - QList getBuffers(); - - public slots: - void connectToIrc(QStringList); - void sendBacklog(BufferId, QVariant, QVariant); - void msgFromGUI(BufferId, QString message); - - signals: - void msgFromGUI(QString net, QString buf, QString message); - void displayMsg(Message message); - void displayStatusMsg(QString, QString); - - void connectToIrc(QString net); - void disconnectFromIrc(QString net); - void serverStateRequested(); - - void backlogData(BufferId, QList, bool done); - - void bufferIdUpdated(BufferId); - - private slots: - void globalDataUpdated(QString); - void recvStatusMsgFromServer(QString msg); - void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None); - void serverDisconnected(QString net); - - private: - Storage *storage; - QHash servers; - UserId user; - -}; - -*/ -//extern Core *core; - - #endif diff --git a/src/core/coreproxy.cpp b/src/core/coreproxy.cpp index 84c427c9..f10af419 100644 --- a/src/core/coreproxy.cpp +++ b/src/core/coreproxy.cpp @@ -18,47 +18,11 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include - #include "coreproxy.h" -#include "global.h" -#include "util.h" -#include "core.h" CoreProxy::CoreProxy() { -// connect(global, SIGNAL(dataPutLocally(QString)), this, SLOT(updateGlobalData(QString))); -// connect(&server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); -} - -/* -void CoreProxy::processClientUpdate(QTcpSocket *socket, QString key, QVariant data) { - global->updateData(key, data); - QList sigdata; - sigdata.append(CS_UPDATE_GLOBAL_DATA); sigdata.append(key); sigdata.append(data); sigdata.append(QVariant()); - QTcpSocket *s; - foreach(s, clients) { - if(s != socket) writeDataToDevice(s, QVariant(sigdata)); - } -} -void CoreProxy::updateGlobalData(QString key) { - QVariant data = global->getData(key); - emit csUpdateGlobalData(key, data); } -*/ - -/* -void CoreProxy::send(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { - - QList sigdata; - sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3); - //qDebug() << "Sending signal: " << sigdata; - QTcpSocket *socket; - foreach(socket, clients) { - writeDataToDevice(socket, QVariant(sigdata)); - } -} -*/ void CoreProxy::recv(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { //qDebug() << "[CORE] Received signal" << sig << ":" << arg1< -#include -#include +//#include +#include +//#include +//#include /** 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. @@ -74,20 +75,10 @@ class CoreProxy : public QObject { 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(ClientSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant()); - private: - void processClientUpdate(QTcpSocket *, QString key, QVariant data); - - private: - - friend class GuiProxy; }; -//extern CoreProxy *coreProxy; - - #endif diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp new file mode 100644 index 00000000..ae0bdb28 --- /dev/null +++ b/src/core/coresession.cpp @@ -0,0 +1,177 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +#include "coresession.h" +#include "server.h" +#include "storage.h" +#include "util.h" + +CoreSession::CoreSession(UserId uid, Storage *_storage) : user(uid), storage(_storage) { + coreProxy = new CoreProxy(); + + connect(coreProxy, SIGNAL(send(CoreSignal, QVariant, QVariant, QVariant)), this, SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant))); + connect(coreProxy, SIGNAL(requestServerStates()), this, SIGNAL(serverStateRequested())); + connect(coreProxy, SIGNAL(gsRequestConnect(QStringList)), this, SLOT(connectToIrc(QStringList))); + connect(coreProxy, SIGNAL(gsUserInput(BufferId, QString)), this, SLOT(msgFromGui(BufferId, QString))); + connect(coreProxy, SIGNAL(gsImportBacklog()), storage, SLOT(importOldBacklog())); + connect(coreProxy, SIGNAL(gsRequestBacklog(BufferId, QVariant, QVariant)), this, SLOT(sendBacklog(BufferId, QVariant, QVariant))); + connect(coreProxy, SIGNAL(gsRequestNetworkStates()), this, SLOT(sendServerStates())); + connect(this, SIGNAL(displayMsg(Message)), coreProxy, SLOT(csDisplayMsg(Message))); + connect(this, SIGNAL(displayStatusMsg(QString, QString)), coreProxy, SLOT(csDisplayStatusMsg(QString, QString))); + connect(this, SIGNAL(backlogData(BufferId, QList, bool)), coreProxy, SLOT(csBacklogData(BufferId, QList, bool))); + connect(this, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId))); + connect(storage, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId))); + connect(Global::instance(), SIGNAL(dataUpdatedRemotely(UserId, QString)), this, SLOT(globalDataUpdated(UserId, QString))); + connect(Global::instance(), SIGNAL(dataPutLocally(UserId, QString)), this, SLOT(globalDataUpdated(UserId, QString))); +} + +CoreSession::~CoreSession() { + +} + +UserId CoreSession::userId() const { + return user; +} + +void CoreSession::processSignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { + coreProxy->recv(sig, arg1, arg2, arg3); +} + +void CoreSession::globalDataUpdated(UserId uid, QString key) { + Q_ASSERT(uid == userId()); + QVariant data = Global::data(userId(), key); + QSettings s; + s.setValue(QString("Global/%1/").arg(userId())+key, data); +} + +void CoreSession::connectToIrc(QStringList networks) { + foreach(QString net, networks) { + if(servers.contains(net)) { + + } else { + Server *server = new Server(userId(), net); + connect(this, SIGNAL(serverStateRequested()), server, SLOT(sendState())); + connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString))); + connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString))); + connect(this, SIGNAL(msgFromGui(QString, QString, QString)), server, SLOT(userInput(QString, QString, QString))); + + connect(server, SIGNAL(connected(QString)), this, SLOT(serverConnected(QString))); + connect(server, SIGNAL(disconnected(QString)), this, SLOT(serverDisconnected(QString))); + + connect(server, SIGNAL(serverState(QString, VarMap)), coreProxy, SLOT(csServerState(QString, VarMap))); + //connect(server, SIGNAL(displayMsg(Message)), this, SLOT(recvMessageFromServer(Message))); + connect(server, SIGNAL(displayMsg(Message::Type, QString, QString, QString, quint8)), this, SLOT(recvMessageFromServer(Message::Type, QString, QString, QString, quint8))); + connect(server, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString))); + connect(server, SIGNAL(modeSet(QString, QString, QString)), coreProxy, SLOT(csModeSet(QString, QString, QString))); + connect(server, SIGNAL(topicSet(QString, QString, QString)), coreProxy, SLOT(csTopicSet(QString, QString, QString))); + connect(server, SIGNAL(nickAdded(QString, QString, VarMap)), coreProxy, SLOT(csNickAdded(QString, QString, VarMap))); + connect(server, SIGNAL(nickRenamed(QString, QString, QString)), coreProxy, SLOT(csNickRenamed(QString, QString, QString))); + connect(server, SIGNAL(nickRemoved(QString, QString)), coreProxy, SLOT(csNickRemoved(QString, QString))); + connect(server, SIGNAL(nickUpdated(QString, QString, VarMap)), coreProxy, SLOT(csNickUpdated(QString, QString, VarMap))); + connect(server, SIGNAL(ownNickSet(QString, QString)), coreProxy, SLOT(csOwnNickSet(QString, QString))); + connect(server, SIGNAL(queryRequested(QString, QString)), coreProxy, SLOT(csQueryRequested(QString, QString))); + // TODO add error handling + connect(server, SIGNAL(connected(QString)), coreProxy, SLOT(csServerConnected(QString))); + connect(server, SIGNAL(disconnected(QString)), coreProxy, SLOT(csServerDisconnected(QString))); + + server->start(); + servers[net] = server; + } + emit connectToIrc(net); + } +} + +void CoreSession::serverConnected(QString net) { + storage->getBufferId(userId(), net); // create status buffer +} + +void CoreSession::serverDisconnected(QString net) { + delete servers[net]; + servers.remove(net); + coreProxy->csServerDisconnected(net); +} + +void CoreSession::msgFromGui(BufferId bufid, QString msg) { + emit msgFromGui(bufid.network(), bufid.buffer(), msg); +} + +// ALL messages coming pass through these functions before going to the GUI. +// So this is the perfect place for storing the backlog and log stuff. + +void CoreSession::recvMessageFromServer(Message::Type type, QString target, QString text, QString sender, quint8 flags) { + Server *s = qobject_cast(this->sender()); + Q_ASSERT(s); + BufferId buf; + if((flags & Message::PrivMsg) && !(flags & Message::Self)) { + buf = storage->getBufferId(user, s->getNetwork(), nickFromMask(sender)); + } else { + buf = storage->getBufferId(user, s->getNetwork(), target); + } + Message msg(buf, type, text, sender, flags); + msg.msgId = storage->logMessage(msg); //qDebug() << msg.msgId; + Q_ASSERT(msg.msgId); + emit displayMsg(msg); +} + +void CoreSession::recvStatusMsgFromServer(QString msg) { + Server *s = qobject_cast(sender()); + Q_ASSERT(s); + emit displayStatusMsg(s->getNetwork(), msg); +} + + +QList CoreSession::buffers() const { + return storage->requestBuffers(user); +} + + +QVariant CoreSession::sessionState() { + VarMap v; + QList bufs; + foreach(BufferId id, storage->requestBuffers(user)) { bufs.append(QVariant::fromValue(id)); } + v["Buffers"] = bufs; + + return v; +} + +void CoreSession::sendServerStates() { + emit serverStateRequested(); +} + +void CoreSession::sendBacklog(BufferId id, QVariant v1, QVariant v2) { + QList log; + QList msglist; + if(v1.type() == QVariant::DateTime) { + + + } else { + msglist = storage->requestMsgs(id, v1.toInt(), v2.toInt()); + } + + // Send messages out in smaller packages - we don't want to make the signal data too large! + for(int i = 0; i < msglist.count(); i++) { + log.append(QVariant::fromValue(msglist[i])); + if(log.count() >= 5) { + emit backlogData(id, log, i >= msglist.count() - 1); + log.clear(); + } + } + if(log.count() > 0) emit backlogData(id, log, true); +} diff --git a/src/core/coresession.h b/src/core/coresession.h new file mode 100644 index 00000000..24d3d8d0 --- /dev/null +++ b/src/core/coresession.h @@ -0,0 +1,83 @@ +/*************************************************************************** + * 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 _CORESESSION_H_ +#define _CORESESSION_H_ + +#include +#include +#include + +#include "coreproxy.h" + +class Server; +class Storage; + +class CoreSession : public QObject { + Q_OBJECT + + public: + CoreSession(UserId, Storage *); + ~CoreSession(); + + QList buffers() const; + UserId userId() const; + QVariant sessionState(); + CoreProxy *proxy(); + + public slots: + void connectToIrc(QStringList); + void processSignal(ClientSignal, QVariant, QVariant, QVariant); + void sendBacklog(BufferId, QVariant, QVariant); + void msgFromGui(BufferId, QString message); + void sendServerStates(); + + signals: + void proxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant()); + + void msgFromGui(QString net, QString buf, QString message); + void displayMsg(Message message); + void displayStatusMsg(QString, QString); + + void connectToIrc(QString net); + void disconnectFromIrc(QString net); + void serverStateRequested(); + + void backlogData(BufferId, QList, bool done); + + void bufferIdUpdated(BufferId); + + private slots: + //void recvProxySignal(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant()); + void globalDataUpdated(UserId, QString); + void recvStatusMsgFromServer(QString msg); + void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None); + void serverConnected(QString net); + void serverDisconnected(QString net); + + private: + CoreProxy *coreProxy; + Storage *storage; + QHash servers; + UserId user; + +}; + +#endif diff --git a/src/core/server.cpp b/src/core/server.cpp index e5ed4eb3..39fcfb34 100644 --- a/src/core/server.cpp +++ b/src/core/server.cpp @@ -17,15 +17,14 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - -#include "util.h" -#include "global.h" #include "server.h" -#include "message.h" #include +#include #include +#include "util.h" + Server::Server(UserId uid, QString net) : user(uid), network(net) { QString MQUOTE = QString('\020'); ctcpMDequoteHash[MQUOTE + '0'] = QString('\000'); diff --git a/src/core/server.h b/src/core/server.h index c17b4d0f..34a45142 100644 --- a/src/core/server.h +++ b/src/core/server.h @@ -21,11 +21,13 @@ #ifndef _SERVER_H_ #define _SERVER_H_ -#include +#include +#include +#include +#include +#include #include -#include -#include "global.h" #include "message.h" #define DEFAULT_PORT 6667 diff --git a/src/core/sqlitestorage.cpp b/src/core/sqlitestorage.cpp index 00dc4c03..7ee2e565 100644 --- a/src/core/sqlitestorage.cpp +++ b/src/core/sqlitestorage.cpp @@ -20,6 +20,7 @@ #include "sqlitestorage.h" +#include SqliteStorage::SqliteStorage() { // TODO I don't think that this path is failsafe for windows users :) diff --git a/src/core/sqlitestorage.h b/src/core/sqlitestorage.h index 9b60aae9..393050b5 100644 --- a/src/core/sqlitestorage.h +++ b/src/core/sqlitestorage.h @@ -21,12 +21,13 @@ #ifndef _SQLITESTORAGE_H_ #define _SQLITESTORAGE_H_ -#include #include #include "global.h" #include "storage.h" +class QSqlQuery; + class SqliteStorage : public Storage { Q_OBJECT diff --git a/src/core/storage.h b/src/core/storage.h index e0d24a9c..d143443f 100644 --- a/src/core/storage.h +++ b/src/core/storage.h @@ -22,9 +22,9 @@ #define _STORAGE_H_ #include -#include +#include -#include "global.h" +//#include "global.h" #include "message.h" class Storage : public QObject { @@ -158,7 +158,7 @@ class Storage : public QObject { // Old stuff, just for importing old file-based data void initBackLogOld(UserId id); - QSqlDatabase logDb; + QSqlDatabase logDb; // FIXME this does not belong in the base class! bool backLogEnabledOld; QDir backLogDir; diff --git a/src/qtgui/CMakeLists.txt b/src/qtgui/CMakeLists.txt index 82ad6ff8..cef85a46 100644 --- a/src/qtgui/CMakeLists.txt +++ b/src/qtgui/CMakeLists.txt @@ -1,8 +1,8 @@ -SET(qtgui_SRCS chatwidget.cpp chatline.cpp channelwidgetinput.cpp tabcompleter.cpp mainwin.cpp serverlist.cpp bufferwidget.cpp - identities.cpp coreconnectdlg.cpp bufferview.cpp bufferviewwidget.cpp bufferviewfilter.cpp style.cpp settingsdlg.cpp settingspages.cpp) +SET(qtgui_SRCS bufferview.cpp bufferviewfilter.cpp bufferwidget.cpp channelwidgetinput.cpp chatline.cpp chatwidget.cpp coreconnectdlg.cpp + identities.cpp mainwin.cpp qtgui.cpp serverlist.cpp settingsdlg.cpp settingspages.cpp style.cpp tabcompleter.cpp) SET(qtgui_HDRS style.h) -SET(qtgui_MOCS chatwidget.h chatline.h channelwidgetinput.h tabcompleter.h mainwin.h serverlist.h identities.h coreconnectdlg.h - bufferview.h bufferwidget.h bufferviewwidget.h bufferviewfilter.h settingsdlg.h settingspages.h) +SET(qtgui_MOCS bufferview.h bufferviewfilter.h bufferwidget.h channelwidgetinput.h chatline.h chatwidget.h coreconnectdlg.h + identities.h mainwin.h qtgui.h serverlist.h settingsdlg.h settingspages.h tabcompleter.h) SET(qtgui_UICS identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui mainwin.ui nickeditdlg.ui serverlistdlg.ui servereditdlg.ui coreconnectdlg.ui ircwidget.ui bufferviewwidget.ui bufferwidget.ui settingsdlg.ui @@ -16,10 +16,7 @@ ENDFOREACH(ui) QT4_WRAP_UI(_UIC ${qtgui_UICS_UI}) QT4_WRAP_CPP(_MOC ${qtgui_MOCS}) -# We need to work around a dependency bug with out-of-source builds... -# Seems to be fixed! -#SET_SOURCE_FILES_PROPERTIES(${gui_SRCS} PROPERTIES OBJECT_DEPENDS "${_UIC}") -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) +#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) -ADD_LIBRARY(qtgui ${qtgui_HDRS} ${qtgui_SRCS} ${_MOC} ${_UIC}) +ADD_LIBRARY(qtgui ${qtgui_SRCS} ${_MOC} ${_UIC}) TARGET_LINK_LIBRARIES(qtgui common) \ No newline at end of file diff --git a/src/qtgui/bufferviewwidget.cpp b/src/qtgui/bufferviewwidget.cpp deleted file mode 100644 index 23d0df24..00000000 --- a/src/qtgui/bufferviewwidget.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * 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 "bufferviewwidget.h" - -/***************************************** - * This Widget Contains the BufferView - *****************************************/ -BufferViewWidget::BufferViewWidget(QWidget *parent) : QWidget(parent) { - ui.setupUi(this); -} - -QSize BufferViewWidget::sizeHint() const { - return QSize(150,100); -} - - -/***************************************** - * Dock and API for the BufferViews - *****************************************/ -BufferViewDock::BufferViewDock(QAbstractItemModel *model, const QString &viewname, const BufferViewFilter::Modes &mode, const QStringList &nets, QWidget *parent) : QDockWidget(parent) { - setObjectName(QString("View-" + viewname)); // should be unique for mainwindow state! - setWindowTitle(viewname); - - BufferViewWidget *viewWidget = new BufferViewWidget(this); - viewWidget->treeView()->setFilteredModel(model, mode, nets); - setWidget(viewWidget); -} diff --git a/src/qtgui/bufferwidget.h b/src/qtgui/bufferwidget.h index b6dd62b9..2024588b 100644 --- a/src/qtgui/bufferwidget.h +++ b/src/qtgui/bufferwidget.h @@ -24,8 +24,6 @@ #include "ui_bufferwidget.h" #include "global.h" -#include "message.h" -#include "chatwidget.h" class Buffer; struct BufferState; diff --git a/src/qtgui/channelwidgetinput.cpp b/src/qtgui/channelwidgetinput.cpp index c4d1a06f..5ee0daaf 100644 --- a/src/qtgui/channelwidgetinput.cpp +++ b/src/qtgui/channelwidgetinput.cpp @@ -20,6 +20,8 @@ #include "channelwidgetinput.h" +#include "tabcompleter.h" + ChannelWidgetInput::ChannelWidgetInput(QWidget *parent) : QLineEdit(parent) { idx = 0; connect(this, SIGNAL(returnPressed()), this, SLOT(enter())); diff --git a/src/qtgui/channelwidgetinput.h b/src/qtgui/channelwidgetinput.h index eb9a9de9..5efebd8a 100644 --- a/src/qtgui/channelwidgetinput.h +++ b/src/qtgui/channelwidgetinput.h @@ -21,9 +21,9 @@ #ifndef _CHANNELWIDGETINPUT_H_ #define _CHANNELWIDGETINPUT_H_ -#include #include -#include "tabcompleter.h" + +class TabCompleter; class ChannelWidgetInput : public QLineEdit { Q_OBJECT diff --git a/src/qtgui/mainwin.cpp b/src/qtgui/mainwin.cpp index bb193cf5..fedf028c 100644 --- a/src/qtgui/mainwin.cpp +++ b/src/qtgui/mainwin.cpp @@ -18,51 +18,17 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include -#include +#include "mainwin.h" +#include "bufferview.h" +#include "chatline.h" #include "client.h" -#include "util.h" -#include "global.h" -#include "message.h" #include "clientproxy.h" - -#include "mainwin.h" -#include "buffer.h" -#include "chatline.h" -#include "serverlist.h" #include "coreconnectdlg.h" +#include "serverlist.h" #include "settingsdlg.h" #include "settingspages.h" -QtGui::QtGui() : AbstractUi() { - mainWin = new MainWin(this); - connect(mainWin, SIGNAL(connectToCore(const VarMap &)), this, SIGNAL(connectToCore(const VarMap &))); - connect(mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore())); - -} - -QtGui::~QtGui() { - delete mainWin; -} - -void QtGui::init() { - mainWin->init(); -} - -AbstractUiMsg *QtGui::layoutMsg(const Message &msg) { - return mainWin->layoutMsg(msg); -} - -void QtGui::connectedToCore() { - mainWin->connectedToCore(); -} - -void QtGui::disconnectedFromCore() { - mainWin->disconnectedFromCore(); -} - MainWin::MainWin(QtGui *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui) { ui.setupUi(this); setWindowTitle("Quassel IRC"); @@ -109,18 +75,6 @@ void MainWin::init() { QString net = s.value("CurrentNetwork", "").toString(); QString buf = s.value("CurrentBuffer", "").toString(); s.endGroup(); - /* - if(!net.isEmpty()) { - if(buffers.contains(net)) { - if(buffers[net].contains(buf)) { - showBuffer(net, buf); - } else { - showBuffer(net, ""); - } - } - } - */ - } MainWin::~MainWin() { diff --git a/src/qtgui/mainwin.h b/src/qtgui/mainwin.h index eed60f78..24e6ccb8 100644 --- a/src/qtgui/mainwin.h +++ b/src/qtgui/mainwin.h @@ -21,38 +21,17 @@ #ifndef _MAINWIN_H_ #define _MAINWIN_H_ -#include #include "ui_mainwin.h" -//#include "global.h" -#include "message.h" -#include "chatwidget.h" +#include "qtgui.h" #include "bufferviewfilter.h" -#include "bufferview.h" class ServerListDlg; class CoreConnectDlg; class Buffer; class SettingsDlg; -class MainWin; - -class QtGui : public AbstractUi { - Q_OBJECT - - public: - QtGui(); - ~QtGui(); - void init(); - AbstractUiMsg *layoutMsg(const Message &); - - protected slots: - void connectedToCore(); - void disconnectedFromCore(); - - private: - MainWin *mainWin; -}; - +class QtGui; +class Message; //!\brief The main window of Quassel's QtGui. class MainWin : public QMainWindow { diff --git a/src/common/main_core.cpp b/src/qtgui/qtgui.cpp similarity index 60% rename from src/common/main_core.cpp rename to src/qtgui/qtgui.cpp index 607aada7..8b242175 100644 --- a/src/common/main_core.cpp +++ b/src/qtgui/qtgui.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005/06 by The Quassel Team * + * 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 * @@ -17,41 +17,34 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include - -#include -#include -#include -#include - -#include "global.h" -#include "core.h" -#include "coreproxy.h" -#include "util.h" - -int main(int argc, char **argv) { - QCoreApplication app(argc, argv); - QCoreApplication::setOrganizationDomain("quassel-irc.org"); - QCoreApplication::setApplicationName("Quassel IRC"); - QCoreApplication::setOrganizationName("The Quassel Team"); - - Global::runMode = Global::CoreOnly; - Global::quasselDir = QDir::homePath() + "/.quassel"; - - global = new Global(); - coreProxy = new CoreProxy(); - - //Logger *logger = new Logger(); - //Quassel::setLogger(logger); - - int exitCode = app.exec(); - delete core; - delete coreProxy; - delete global; - return exitCode; + +#include "qtgui.h" + +#include "mainwin.h" + +QtGui::QtGui() : AbstractUi() { + mainWin = new MainWin(this); + connect(mainWin, SIGNAL(connectToCore(const VarMap &)), this, SIGNAL(connectToCore(const VarMap &))); + connect(mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore())); + +} + +QtGui::~QtGui() { + delete mainWin; } -void CoreProxy::sendToGUI(CoreSignal, QVariant, QVariant, QVariant) { - // dummy function, no GUI available! +void QtGui::init() { + mainWin->init(); } +AbstractUiMsg *QtGui::layoutMsg(const Message &msg) { + return mainWin->layoutMsg(msg); +} + +void QtGui::connectedToCore() { + mainWin->connectedToCore(); +} + +void QtGui::disconnectedFromCore() { + mainWin->disconnectedFromCore(); +} diff --git a/src/qtgui/bufferviewwidget.h b/src/qtgui/qtgui.h similarity index 60% rename from src/qtgui/bufferviewwidget.h rename to src/qtgui/qtgui.h index 8de20358..429127ab 100644 --- a/src/qtgui/bufferviewwidget.h +++ b/src/qtgui/qtgui.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel Team * + * 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 * @@ -18,42 +18,31 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _BUFFERVIEWWIDGET_H_ -#define _BUFFERVIEWWIDGET_H_ +#ifndef _QTGUI_H_ +#define _QTGUI_H_ -#include -#include +#include "quasselui.h" +class MainWin; -#include "bufferviewfilter.h" -#include "bufferview.h" -#include "ui_bufferviewwidget.h" - - -/***************************************** - * This Widget Contains the BufferView - *****************************************/ -class BufferViewWidget : public QWidget { +//! This class encapsulates Quassel's Qt-based GUI. +/** This is basically a wrapper around MainWin, which is necessary because we cannot derive MainWin + * from both QMainWindow and AbstractUi (because of multiple inheritance of QObject). + */ +class QtGui : public AbstractUi { Q_OBJECT -public: - BufferViewWidget(QWidget *parent = 0); - virtual QSize sizeHint () const; - BufferView *treeView(){ return ui.treeView; } - -private: - Ui::BufferViewWidget ui; -}; + public: + QtGui(); + ~QtGui(); + void init(); + AbstractUiMsg *layoutMsg(const Message &); + protected slots: + void connectedToCore(); + void disconnectedFromCore(); -/***************************************** - * Dock and API for the BufferViews - *****************************************/ -class BufferViewDock : public QDockWidget { - Q_OBJECT - -public: - BufferViewDock(QAbstractItemModel *model, const QString &name, const BufferViewFilter::Modes &mode, const QStringList &nets = QStringList(), QWidget *parent = 0); + private: + MainWin *mainWin; }; - #endif diff --git a/src/qtgui/style.h b/src/qtgui/style.h index 861d5c59..a10a9698 100644 --- a/src/qtgui/style.h +++ b/src/qtgui/style.h @@ -22,7 +22,8 @@ #define _STYLE_H_ #include -#include +#include +#include class Style { -- 2.20.1