Ticket #76: getcaption.patch

File getcaption.patch, 5.7 KB (added by amroth, 4 years ago)

Move the getCaption() method from the switchboard to the chat window

  • kmess/chat/chatwindow.h

     
    176176    void               emoticonButtonPressed(); 
    177177    // Forward the application command to the ChatMaster 
    178178    void               forwardAppCommand(QString cookie, QString contact, QString command); 
     179    // Return a list of the contacts in the chat to be used as window caption 
     180    QString            getCaption(); 
    179181    // Invite a contact to the chat 
    180182    void               inviteContact(QString handle); 
    181183    // Notify the user of a received nudge 
  • kmess/chat/chatwindow.cpp

     
    231231{ 
    232232  ContactAction *contactAction; 
    233233 
    234   if ( msnSwitchboardConnection_ != 0 ) 
    235   { 
    236     // Avoid newlines which cause problems to the UI layout. 
    237     caption_ = msnSwitchboardConnection_->getCaption().replace( "\n", " " ); 
    238     setCaption( caption_ ); 
    239   } 
     234  // Avoid newlines which cause problems to the UI layout. 
     235  caption_ = getCaption().replace( "\n", " " ); 
     236  setCaption( caption_ ); 
    240237 
    241238  if( ! participants_.contains( handle ) ) 
    242239  { 
     
    287284    contactAction->setInChat( false ); 
    288285  } 
    289286 
    290   if( msnSwitchboardConnection_ != 0 ) 
    291   { 
    292     caption_ = msnSwitchboardConnection_->getCaption().replace( "\n", "" ); 
    293     setCaption( caption_ ); 
    294   } 
     287  // Change the caption to remove the contact who has left 
     288  caption_ = getCaption().replace( "\n", "" ); 
     289  setCaption( caption_ ); 
    295290 
    296291  participants_.remove( handle ); 
    297292 
     
    546541 
    547542 
    548543 
     544// Return a list of the contacts in the chat to be used as window caption 
     545QString ChatWindow::getCaption() 
     546{ 
     547    // The chat has no switchboard connection.. it is not even a chat! 
     548  if( msnSwitchboardConnection_ == 0 ) 
     549  { 
     550    return i18n( "Chat" ); 
     551  } 
     552 
     553  // Query the switchboard for the list of participants 
     554  QStringList activeContacts = msnSwitchboardConnection_->getContactsInChat(); 
     555 
     556  switch( activeContacts.count() ) 
     557  { 
     558    // The chat is empty 
     559    case 0: 
     560      return i18n("Chat"); 
     561      break; 
     562 
     563    // One contact is connected; or the only contact of the session has left 
     564    case 1: 
     565      return i18n( "%1 - Chat" ) 
     566                   .arg( currentAccount_->getContactFriendlyNameByHandle( activeContacts[0] ) ); 
     567      break; 
     568 
     569    // Two contacts are connected 
     570    case 2: 
     571      return i18n( "%1 and %2 - Chat" ) 
     572                   .arg( currentAccount_->getContactFriendlyNameByHandle( activeContacts[0] ) ) 
     573                   .arg( currentAccount_->getContactFriendlyNameByHandle( activeContacts[1] ) ); 
     574      break; 
     575 
     576    // Three or more contacts are connected 
     577    default: 
     578      return i18n( "%1 et al. - Chat" ) 
     579                   .arg( currentAccount_->getContactFriendlyNameByHandle( activeContacts[0] ) ); 
     580      break; 
     581  } 
     582 
     583  // We can't arrive here. Is there a clean way to avoid the useless compiler warning? 
     584  return QString::null; 
     585} 
     586 
     587 
     588 
    549589// Return the contact action with the given handle 
    550590ContactAction* ChatWindow::getContactActionByHandle(const QString& handle) 
    551591{ 
     
    18131853// An event requires the window to update its properties 
    18141854void ChatWindow::update() 
    18151855{ 
    1816   if( KMESS_NULL(msnSwitchboardConnection_) ) return; 
    1817  
    1818   caption_ = msnSwitchboardConnection_->getCaption().replace( "\n", " " ); 
     1856  caption_ = getCaption().replace( "\n", " " ); 
    18191857  setCaption( caption_ ); 
    18201858} 
    18211859 
  • kmess/network/msnswitchboardconnection.cpp

     
    547547 
    548548 
    549549 
    550 // Get the switchboard to make a list of the contacts in the chat 
    551 QString MsnSwitchboardConnection::getCaption() 
    552 { 
    553   QString  caption; 
    554   QString  contactString; 
    555  
    556   // Make a list of the contacts in the chat 
    557   if( contactsInChat_.count() == 0 ) 
    558   { 
    559     // Pretend the chat is still active, it will re-connect when the user or contact starts typing again. 
    560     return i18n("%1 - Chat") 
    561            .arg( currentAccount_->getContactFriendlyNameByHandle(lastContact_) ); 
    562   } 
    563   else if( contactsInChat_.count() == 1 ) 
    564   { 
    565     return i18n("%1 - Chat") 
    566             .arg( currentAccount_->getContactFriendlyNameByHandle(contactsInChat_[0]) ); 
    567   } 
    568   else if ( contactsInChat_.count() == 2 ) 
    569   { 
    570     return i18n("%1 and %2 - Chat") 
    571             .arg( currentAccount_->getContactFriendlyNameByHandle(contactsInChat_[0]) ) 
    572             .arg( currentAccount_->getContactFriendlyNameByHandle(contactsInChat_[1]) ); 
    573   } 
    574   else if ( contactsInChat_.count() > 2 ) 
    575   { 
    576     return i18n("%1 et al. - Chat") 
    577             .arg( currentAccount_->getContactFriendlyNameByHandle(contactsInChat_[0]) ); 
    578   } 
    579  
    580   return i18n("Chat"); 
    581 } 
    582  
    583  
    584  
    585550// Make a list of the contacts in the chat 
    586551QStringList MsnSwitchboardConnection::getContactsInChat() const 
    587552{ 
  • kmess/network/msnswitchboardconnection.h

     
    6464    virtual void         closeConnection(); 
    6565    // Clean up, close the connection, destroy this object 
    6666    void                 closeConnectionLater(bool autoDelete = false); 
    67     // Get the switchboard to make a list of the contacts in the chat 
    68     QString              getCaption(); 
    6967    // Make a list of the contacts in the chat 
    7068    QStringList          getContactsInChat() const; 
    7169    // Return the first contact the chat started with.