Index: kmess/chat/chatwindow.h
===================================================================
--- kmess/chat/chatwindow.h	(revisione 2202)
+++ kmess/chat/chatwindow.h	(copia locale)
@@ -176,6 +176,8 @@
     void               emoticonButtonPressed();
     // Forward the application command to the ChatMaster
     void               forwardAppCommand(QString cookie, QString contact, QString command);
+    // Return a list of the contacts in the chat to be used as window caption
+    QString            getCaption();
     // Invite a contact to the chat
     void               inviteContact(QString handle);
     // Notify the user of a received nudge
Index: kmess/chat/chatwindow.cpp
===================================================================
--- kmess/chat/chatwindow.cpp	(revisione 2202)
+++ kmess/chat/chatwindow.cpp	(copia locale)
@@ -231,12 +231,9 @@
 {
   ContactAction *contactAction;
 
-  if ( msnSwitchboardConnection_ != 0 )
-  {
-    // Avoid newlines which cause problems to the UI layout.
-    caption_ = msnSwitchboardConnection_->getCaption().replace( "\n", " " );
-    setCaption( caption_ );
-  }
+  // Avoid newlines which cause problems to the UI layout.
+  caption_ = getCaption().replace( "\n", " " );
+  setCaption( caption_ );
 
   if( ! participants_.contains( handle ) )
   {
@@ -287,11 +284,9 @@
     contactAction->setInChat( false );
   }
 
-  if( msnSwitchboardConnection_ != 0 )
-  {
-    caption_ = msnSwitchboardConnection_->getCaption().replace( "\n", "" );
-    setCaption( caption_ );
-  }
+  // Change the caption to remove the contact who has left
+  caption_ = getCaption().replace( "\n", "" );
+  setCaption( caption_ );
 
   participants_.remove( handle );
 
@@ -546,6 +541,51 @@
 
 
 
+// Return a list of the contacts in the chat to be used as window caption
+QString ChatWindow::getCaption()
+{
+    // The chat has no switchboard connection.. it is not even a chat!
+  if( msnSwitchboardConnection_ == 0 )
+  {
+    return i18n( "Chat" );
+  }
+
+  // Query the switchboard for the list of participants
+  QStringList activeContacts = msnSwitchboardConnection_->getContactsInChat();
+
+  switch( activeContacts.count() )
+  {
+    // The chat is empty
+    case 0:
+      return i18n("Chat");
+      break;
+
+    // One contact is connected; or the only contact of the session has left
+    case 1:
+      return i18n( "%1 - Chat" )
+                   .arg( currentAccount_->getContactFriendlyNameByHandle( activeContacts[0] ) );
+      break;
+
+    // Two contacts are connected
+    case 2:
+      return i18n( "%1 and %2 - Chat" )
+                   .arg( currentAccount_->getContactFriendlyNameByHandle( activeContacts[0] ) )
+                   .arg( currentAccount_->getContactFriendlyNameByHandle( activeContacts[1] ) );
+      break;
+
+    // Three or more contacts are connected
+    default:
+      return i18n( "%1 et al. - Chat" )
+                   .arg( currentAccount_->getContactFriendlyNameByHandle( activeContacts[0] ) );
+      break;
+  }
+
+  // We can't arrive here. Is there a clean way to avoid the useless compiler warning?
+  return QString::null;
+}
+
+
+
 // Return the contact action with the given handle
 ContactAction* ChatWindow::getContactActionByHandle(const QString& handle)
 {
@@ -1813,9 +1853,7 @@
 // An event requires the window to update its properties
 void ChatWindow::update()
 {
-  if( KMESS_NULL(msnSwitchboardConnection_) ) return;
-
-  caption_ = msnSwitchboardConnection_->getCaption().replace( "\n", " " );
+  caption_ = getCaption().replace( "\n", " " );
   setCaption( caption_ );
 }
 
Index: kmess/network/msnswitchboardconnection.cpp
===================================================================
--- kmess/network/msnswitchboardconnection.cpp	(revisione 2202)
+++ kmess/network/msnswitchboardconnection.cpp	(copia locale)
@@ -547,41 +547,6 @@
 
 
 
-// Get the switchboard to make a list of the contacts in the chat
-QString MsnSwitchboardConnection::getCaption()
-{
-  QString  caption;
-  QString  contactString;
-
-  // Make a list of the contacts in the chat
-  if( contactsInChat_.count() == 0 )
-  {
-    // Pretend the chat is still active, it will re-connect when the user or contact starts typing again.
-    return i18n("%1 - Chat")
-           .arg( currentAccount_->getContactFriendlyNameByHandle(lastContact_) );
-  }
-  else if( contactsInChat_.count() == 1 )
-  {
-    return i18n("%1 - Chat")
-            .arg( currentAccount_->getContactFriendlyNameByHandle(contactsInChat_[0]) );
-  }
-  else if ( contactsInChat_.count() == 2 )
-  {
-    return i18n("%1 and %2 - Chat")
-            .arg( currentAccount_->getContactFriendlyNameByHandle(contactsInChat_[0]) )
-            .arg( currentAccount_->getContactFriendlyNameByHandle(contactsInChat_[1]) );
-  }
-  else if ( contactsInChat_.count() > 2 )
-  {
-    return i18n("%1 et al. - Chat")
-            .arg( currentAccount_->getContactFriendlyNameByHandle(contactsInChat_[0]) );
-  }
-
-  return i18n("Chat");
-}
-
-
-
 // Make a list of the contacts in the chat
 QStringList MsnSwitchboardConnection::getContactsInChat() const
 {
Index: kmess/network/msnswitchboardconnection.h
===================================================================
--- kmess/network/msnswitchboardconnection.h	(revisione 2202)
+++ kmess/network/msnswitchboardconnection.h	(copia locale)
@@ -64,8 +64,6 @@
     virtual void         closeConnection();
     // Clean up, close the connection, destroy this object
     void                 closeConnectionLater(bool autoDelete = false);
-    // Get the switchboard to make a list of the contacts in the chat
-    QString              getCaption();
     // Make a list of the contacts in the chat
     QStringList          getContactsInChat() const;
     // Return the first contact the chat started with.

