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)));
42 // Read global settings from config file
44 s.beginGroup("Global");
46 foreach(key, s.childKeys()) {
47 global->updateData(key, s.value(key));
49 backlog.init("Default"); // FIXME
50 global->updateData("CoreReady", true);
51 // Now that we are in sync, we can connect signals to automatically store further updates.
52 // I don't think we care if global data changed locally or if it was updated by a client.
53 connect(global, SIGNAL(dataUpdatedRemotely(QString)), SLOT(globalDataUpdated(QString)));
54 connect(global, SIGNAL(dataPutLocally(QString)), SLOT(globalDataUpdated(QString)));
59 //foreach(Server *s, servers) {
64 void Core::globalDataUpdated(QString key) {
65 QVariant data = global->getData(key);
67 s.setValue(QString("Global/")+key, data);
70 void Core::connectToIrc(QStringList networks) {
71 foreach(QString net, networks) {
72 if(servers.contains(net)) {
75 Server *server = new Server(net);
76 connect(this, SIGNAL(serverStateRequested()), server, SLOT(sendState()));
77 connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString)));
78 connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString)));
79 connect(this, SIGNAL(msgFromGUI(QString, QString, QString)), server, SLOT(userInput(QString, QString, QString)));
80 connect(server, SIGNAL(serverState(QString, VarMap)), coreProxy, SLOT(csServerState(QString, VarMap)));
81 //connect(server, SIGNAL(displayMsg(Message)), this, SLOT(recvMessageFromServer(Message)));
82 connect(server, SIGNAL(displayMsg(Message::Type, QString, QString, QString, quint8)), this, SLOT(recvMessageFromServer(Message::Type, QString, QString, QString, quint8)));
83 connect(server, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString)));
84 connect(server, SIGNAL(modeSet(QString, QString, QString)), coreProxy, SLOT(csModeSet(QString, QString, QString)));
85 connect(server, SIGNAL(topicSet(QString, QString, QString)), coreProxy, SLOT(csTopicSet(QString, QString, QString)));
86 connect(server, SIGNAL(nickAdded(QString, QString, VarMap)), coreProxy, SLOT(csNickAdded(QString, QString, VarMap)));
87 connect(server, SIGNAL(nickRenamed(QString, QString, QString)), coreProxy, SLOT(csNickRenamed(QString, QString, QString)));
88 connect(server, SIGNAL(nickRemoved(QString, QString)), coreProxy, SLOT(csNickRemoved(QString, QString)));
89 connect(server, SIGNAL(nickUpdated(QString, QString, VarMap)), coreProxy, SLOT(csNickUpdated(QString, QString, VarMap)));
90 connect(server, SIGNAL(ownNickSet(QString, QString)), coreProxy, SLOT(csOwnNickSet(QString, QString)));
91 connect(server, SIGNAL(queryRequested(QString, QString)), coreProxy, SLOT(csQueryRequested(QString, QString)));
93 connect(server, SIGNAL(connected(QString)), coreProxy, SLOT(csServerConnected(QString)));
94 connect(server, SIGNAL(disconnected(QString)), this, SLOT(serverDisconnected(QString)));
97 servers[net] = server;
99 emit connectToIrc(net);
103 void Core::serverDisconnected(QString net) {
106 coreProxy->csServerDisconnected(net);
109 void Core::msgFromGUI(BufferId bufid, QString msg) {
110 emit msgFromGUI(bufid.network(), bufid.buffer(), msg);
113 // ALL messages coming pass through these functions before going to the GUI.
114 // So this is the perfect place for storing the backlog and log stuff.
116 void Core::recvMessageFromServer(Message::Type type, QString target, QString text, QString sender, quint8 flags) {
117 Server *s = qobject_cast<Server*>(this->sender());
120 if((flags & Message::PrivMsg) && !(flags & Message::Self)) {
121 buf = backlog.getBufferId(s->getNetwork(), nickFromMask(sender));
123 buf = backlog.getBufferId(s->getNetwork(), target);
125 Message msg(buf, type, text, sender, flags);
126 msg.msgId = backlog.logMessage(msg);
127 emit displayMsg(msg);
130 void Core::recvMessageFromServer(Message msg) {
131 Server *s = qobject_cast<Server*>(sender());
133 logMessage(s->getNetwork(), msg);
134 emit displayMsg(s->getNetwork(), msg);
138 void Core::recvStatusMsgFromServer(QString msg) {
139 Server *s = qobject_cast<Server*>(sender());
141 emit displayStatusMsg(s->getNetwork(), msg);
144 QList<BufferId> Core::getBuffers() {
145 return backlog.requestBuffers();
148 void Core::sendBacklog(BufferId id, QVariant v1, QVariant v2) {
150 QList<Message> msglist;
151 if(v1.type() == QVariant::DateTime) {
155 msglist = backlog.requestMsgs(id, v1.toInt(), v2.toInt());
158 // Send messages out in smaller packages - we don't want to make the signal data too large!
159 for(int i = 0; i < msglist.count(); i++) {
160 log.append(QVariant::fromValue(msglist[i]));
161 if(log.count() >= 5) {
162 emit backlogData(id, log, i >= msglist.count() - 1);
166 if(log.count() > 0) emit backlogData(id, log, true);