1 /***************************************************************************
2 * Copyright (C) 2005/06 by The Quassel Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 #include "coreproxy.h"
31 if(core) qFatal("Trying to instantiate more than one Core object!");
33 connect(coreProxy, SIGNAL(requestServerStates()), this, SIGNAL(serverStateRequested()));
34 connect(coreProxy, SIGNAL(gsRequestConnect(QStringList)), this, SLOT(connectToIrc(QStringList)));
35 connect(coreProxy, SIGNAL(gsUserInput(BufferId, QString)), this, SLOT(msgFromGUI(BufferId, QString)));
36 connect(coreProxy, SIGNAL(gsImportBacklog()), &backlog, SLOT(importOldBacklog()));
37 connect(coreProxy, SIGNAL(gsRequestBacklog(BufferId, QVariant, QVariant)), this, SLOT(sendBacklog(BufferId, QVariant, QVariant)));
38 connect(this, SIGNAL(displayMsg(Message)), coreProxy, SLOT(csDisplayMsg(Message)));
39 connect(this, SIGNAL(displayStatusMsg(QString, QString)), coreProxy, SLOT(csDisplayStatusMsg(QString, QString)));
40 connect(this, SIGNAL(backlogData(BufferId, QList<QVariant>, bool)), coreProxy, SLOT(csBacklogData(BufferId, QList<QVariant>, bool)));
41 connect(&backlog, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId)));
42 connect(this, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId)));
43 // Read global settings from config file
45 s.beginGroup("Global");
47 foreach(key, s.childKeys()) {
48 global->updateData(key, s.value(key));
50 backlog.init("Default"); // FIXME
51 global->updateData("CoreReady", true);
52 // Now that we are in sync, we can connect signals to automatically store further updates.
53 // I don't think we care if global data changed locally or if it was updated by a client.
54 connect(global, SIGNAL(dataUpdatedRemotely(QString)), SLOT(globalDataUpdated(QString)));
55 connect(global, SIGNAL(dataPutLocally(QString)), SLOT(globalDataUpdated(QString)));
60 //foreach(Server *s, servers) {
65 void Core::globalDataUpdated(QString key) {
66 QVariant data = global->getData(key);
68 s.setValue(QString("Global/")+key, data);
71 void Core::connectToIrc(QStringList networks) {
72 foreach(QString net, networks) {
73 if(servers.contains(net)) {
76 Server *server = new Server(net);
77 connect(this, SIGNAL(serverStateRequested()), server, SLOT(sendState()));
78 connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString)));
79 connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString)));
80 connect(this, SIGNAL(msgFromGUI(QString, QString, QString)), server, SLOT(userInput(QString, QString, QString)));
81 connect(server, SIGNAL(serverState(QString, VarMap)), coreProxy, SLOT(csServerState(QString, VarMap)));
82 //connect(server, SIGNAL(displayMsg(Message)), this, SLOT(recvMessageFromServer(Message)));
83 connect(server, SIGNAL(displayMsg(Message::Type, QString, QString, QString, quint8)), this, SLOT(recvMessageFromServer(Message::Type, QString, QString, QString, quint8)));
84 connect(server, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString)));
85 connect(server, SIGNAL(modeSet(QString, QString, QString)), coreProxy, SLOT(csModeSet(QString, QString, QString)));
86 connect(server, SIGNAL(topicSet(QString, QString, QString)), coreProxy, SLOT(csTopicSet(QString, QString, QString)));
87 connect(server, SIGNAL(nickAdded(QString, QString, VarMap)), coreProxy, SLOT(csNickAdded(QString, QString, VarMap)));
88 connect(server, SIGNAL(nickRenamed(QString, QString, QString)), coreProxy, SLOT(csNickRenamed(QString, QString, QString)));
89 connect(server, SIGNAL(nickRemoved(QString, QString)), coreProxy, SLOT(csNickRemoved(QString, QString)));
90 connect(server, SIGNAL(nickUpdated(QString, QString, VarMap)), coreProxy, SLOT(csNickUpdated(QString, QString, VarMap)));
91 connect(server, SIGNAL(ownNickSet(QString, QString)), coreProxy, SLOT(csOwnNickSet(QString, QString)));
92 connect(server, SIGNAL(queryRequested(QString, QString)), coreProxy, SLOT(csQueryRequested(QString, QString)));
94 connect(server, SIGNAL(connected(QString)), coreProxy, SLOT(csServerConnected(QString)));
95 connect(server, SIGNAL(disconnected(QString)), this, SLOT(serverDisconnected(QString)));
98 servers[net] = server;
100 emit connectToIrc(net);
104 void Core::serverDisconnected(QString net) {
107 coreProxy->csServerDisconnected(net);
110 void Core::msgFromGUI(BufferId bufid, QString msg) {
111 emit msgFromGUI(bufid.network(), bufid.buffer(), msg);
114 // ALL messages coming pass through these functions before going to the GUI.
115 // So this is the perfect place for storing the backlog and log stuff.
117 void Core::recvMessageFromServer(Message::Type type, QString target, QString text, QString sender, quint8 flags) {
118 Server *s = qobject_cast<Server*>(this->sender());
121 if((flags & Message::PrivMsg) && !(flags & Message::Self)) {
122 buf = backlog.getBufferId(s->getNetwork(), nickFromMask(sender));
124 buf = backlog.getBufferId(s->getNetwork(), target);
126 Message msg(buf, type, text, sender, flags);
127 msg.msgId = backlog.logMessage(msg);
128 emit displayMsg(msg);
131 void Core::recvMessageFromServer(Message msg) {
132 Server *s = qobject_cast<Server*>(sender());
134 logMessage(s->getNetwork(), msg);
135 emit displayMsg(s->getNetwork(), msg);
139 void Core::recvStatusMsgFromServer(QString msg) {
140 Server *s = qobject_cast<Server*>(sender());
142 emit displayStatusMsg(s->getNetwork(), msg);
145 QList<BufferId> Core::getBuffers() {
146 return backlog.requestBuffers();
149 void Core::sendBacklog(BufferId id, QVariant v1, QVariant v2) {
151 QList<Message> msglist;
152 if(v1.type() == QVariant::DateTime) {
156 msglist = backlog.requestMsgs(id, v1.toInt(), v2.toInt());
159 // Send messages out in smaller packages - we don't want to make the signal data too large!
160 for(int i = 0; i < msglist.count(); i++) {
161 log.append(QVariant::fromValue(msglist[i]));
162 if(log.count() >= 5) {
163 emit backlogData(id, log, i >= msglist.count() - 1);
167 if(log.count() > 0) emit backlogData(id, log, true);