Started to reorganize the Buffer{Model|View|Filter}. Mostly cleanup at the moment.
[quassel.git] / src / client / client.cpp
index 55bf9c5..4a6111e 100644 (file)
@@ -85,10 +85,10 @@ Buffer *Client::buffer(uint bufferUid) {
 
 Buffer *Client::buffer(BufferInfo id) {
   Buffer *buff = buffer(id.uid());
-  
+
   if(!buff) {
     Client *client = Client::instance();
-    Buffer *buff = new Buffer(id, client);
+    buff = new Buffer(id, client);
 
     connect(buff, SIGNAL(userInput(BufferInfo, QString)),
            client, SLOT(userInput(BufferInfo, QString)));
@@ -102,7 +102,7 @@ Buffer *Client::buffer(BufferInfo id) {
     client->_buffers[id.uid()] = buff;
     emit client->bufferUpdated(buff);
   }
-  
+  Q_ASSERT(buff);
   return buff;
 }
 
@@ -144,10 +144,6 @@ Client::Client(QObject *parent)
 }
 
 Client::~Client() {
-// since we're now the parent of buffers this should be no longer needed
-  
-//   foreach(Buffer *buf, buffers.values()) delete buf; // this is done by disconnectFromCore()! FIXME?
-//   Q_ASSERT(!buffers.count());
 }
 
 void Client::init() {
@@ -200,10 +196,21 @@ bool Client::isConnected() {
   return instance()->connectedToCore;
 }
 
+void Client::fakeInput(uint bufferUid, QString message) {
+  Buffer *buff = buffer(bufferUid);
+  if(!buff)
+    qWarning() << "No Buffer with uid" << bufferUid << "can't send Input" << message;
+  else
+    emit instance()->sendInput(buff->bufferInfo(), message);
+}
+
+void Client::fakeInput(BufferInfo bufferInfo, QString message) {
+  fakeInput(bufferInfo, message);
+}
+
 void Client::connectToCore(const QVariantMap &conn) {
   // TODO implement SSL
   coreConnectionInfo = conn;
-  
   if(isConnected()) {
     emit coreConnectionError(tr("Already connected to Core!"));
     return;
@@ -237,16 +244,9 @@ void Client::connectToCore(const QVariantMap &conn) {
 }
 
 void Client::disconnectFromCore() {
-  if(clientMode == RemoteCore) {
-    socket->close();
-    //QAbstractSocket *sock = qobject_cast<QAbstractSocket*>(socket);
-    //Q_ASSERT(sock);
-    //sock->disconnectFromHost();
-  } else {
-    socket->close();
-    //disconnectFromLocalCore();
+  socket->close();
+  if(clientMode == LocalCore)
     coreSocketDisconnected();
-  }
 }
 
 void Client::coreSocketConnected() {
@@ -267,17 +267,17 @@ void Client::coreSocketDisconnected() {
 
   /* Clear internal data. Hopefully nothing relies on it at this point. */
   _bufferModel->clear();
-  // Buffers, if deleted, send a signal that causes their removal from buffers and bufferInfos.
-  // So we cannot simply go through the array in a loop (or use qDeleteAll) for deletion...
-  while(!_buffers.empty()) {
-    delete _buffers.take(_buffers.keys()[0]);
+
+  foreach(Buffer *buffer, _buffers.values()) {
+    delete buffer;
   }
   Q_ASSERT(_buffers.empty());
 
-  while(!_networkInfo.empty()) {
-    delete _networkInfo.take(_networkInfo.keys()[0]);
+  foreach(NetworkInfo *networkinfo, _networkInfo.values()) {
+    delete networkinfo;
   }
-    
+  Q_ASSERT(_networkInfo.empty());
+
   coreConnectionInfo.clear();
   sessionData.clear();
   layoutQueue.clear();
@@ -343,18 +343,18 @@ void Client::updateCoreConnectionProgress() {
   int numChannelsWaiting = 0;
 
   foreach(NetworkInfo *net, networkInfos()) {
-    if(not net->initialized())
+    if(! net->initialized())
       numNetsWaiting++;
 
     numIrcUsers += net->ircUsers().count();
     foreach(IrcUser *user, net->ircUsers()) {
-      if(not user->initialized())
+      if(! user->initialized())
        numIrcUsersWaiting++;
     }
 
     numChannels += net->ircChannels().count();
     foreach(IrcChannel *channel, net->ircChannels()) {
-      if(not channel->initialized())
+      if(! channel->initialized())
        numChannelsWaiting++;
     }