- implemented on request a chat monitor: a simple buffer which shows
[quassel.git] / src / client / client.cpp
index de43a0b..772601f 100644 (file)
@@ -65,6 +65,7 @@ Client::Client(QObject *parent)
     _connectedToCore(false),
     _syncedToCore(false)
 {
+  _monitorBuffer = new Buffer(BufferInfo(), this);
 }
 
 Client::~Client() {
@@ -105,7 +106,13 @@ void Client::init() {
   p->attachSignal(this, SIGNAL(requestRemoveIdentity(IdentityId)), SIGNAL(removeIdentity(IdentityId)));
   p->attachSlot(SIGNAL(identityCreated(const Identity &)), this, SLOT(coreIdentityCreated(const Identity &)));
   p->attachSlot(SIGNAL(identityRemoved(IdentityId)), this, SLOT(coreIdentityRemoved(IdentityId)));
-
+/*
+  p->attachSignal(this, SIGNAL(requestCreateNetwork(const NetworkInfo &)), SIGNAL(createNetwork(const NetworkInfo &)));
+  p->attachSignal(this, SIGNAL(requestUpdateNetwork(const NetworkInfo &)), SIGNAL(updateNetwork(const NetworkInfo &)));
+  p->attachSignal(this, SIGNAL(requestRemoveNetwork(NetworkId)), SIGNAL(removeNetwork(NetworkId)));
+  p->attachSlot(SIGNAL(networkCreated(const NetworkInfo &)), this, SLOT(coreNetworkCreated(const NetworkInfo &)));
+  p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
+*/
   connect(p, SIGNAL(disconnected()), this, SLOT(disconnectFromCore()));
 
   //connect(mainUi, SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &)));
@@ -159,6 +166,10 @@ Buffer *Client::buffer(BufferInfo id) {
   return buff;
 }
 
+Buffer *Client::monitorBuffer() {
+  return instance()->_monitorBuffer;
+}
+
 
 NetworkModel *Client::networkModel() {
   return instance()->_networkModel;
@@ -333,6 +344,13 @@ QStringList Client::sessionDataKeys() {
 
 /*** ***/
 
+// FIXME
+void Client::disconnectFromNetwork(NetworkId id) {
+  if(!instance()->_networks.contains(id)) return;
+  Network *net = instance()->_networks[id];
+  net->requestDisconnect();
+}
+
 /*
 void Client::networkConnected(uint netid) {
   // TODO: create statusBuffer / switch to networkids
@@ -362,19 +380,18 @@ void Client::networkDisconnected(NetworkId networkid) {
 }
 */
 
-void Client::addNetwork(NetworkId netid) {
-  Network *net = new Network(netid, instance());
-  addNetwork(net);
-}
-
 void Client::addNetwork(Network *net) {
   net->setProxy(signalProxy());
   signalProxy()->synchronize(net);
   networkModel()->attachNetwork(net);
   connect(net, SIGNAL(destroyed()), instance(), SLOT(networkDestroyed()));
   instance()->_networks[net->networkId()] = net;
-  emit instance()->networkAdded(net->networkId());
-  //if(net->networkId() == 1) net->requestConnect(); // FIXME
+  emit instance()->networkCreated(net->networkId());
+}
+
+void Client::createNetwork(const NetworkInfo &info) {
+
+
 }
 
 /*** ***/
@@ -396,8 +413,9 @@ void Client::bufferDestroyed() {
 }
 
 void Client::networkDestroyed() {
-  Network *netinfo = static_cast<Network *>(sender());
-  NetworkId networkId = netinfo->networkId();
+  // FIXME this is not gonna work, net is a QObject here already!
+  Network *net = static_cast<Network *>(sender());
+  NetworkId networkId = net->networkId();
   if(_networks.contains(networkId))
     _networks.remove(networkId);
 }
@@ -406,6 +424,13 @@ void Client::recvMessage(const Message &msg) {
   Buffer *b = buffer(msg.buffer());
   b->appendMsg(msg);
   networkModel()->updateBufferActivity(msg);
+
+  if(msg.type() == Message::Plain || msg.type() == Message::Notice || msg.type() == Message::Action) {
+    QString sender = msg.buffer().network() + ":" + msg.buffer().buffer() + ":" + msg.sender();
+    Message mmsg = Message(msg.timestamp(), msg.buffer(), msg.type(), msg.text(), sender, msg.flags());
+    monitorBuffer()->appendMsg(mmsg);
+  }
+
 }
 
 void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) {