Logo Search packages:      
Sourcecode: kmess version File versions  Download package

void ContactList::reset ( bool  restore = true  ) 

Empty the contact list

Deletes the contact list's contents and regenerates the special groups and the model. When exiting, the regeneration part can be skipped.

Definition at line 1762 of file contactlist.cpp.

References ContactListModelItem::child(), and ContactListModelItem::childCount().

Referenced by MsnNotificationConnection::closeConnection().

{
  // Empty the model structure and reset it
  if( rootNode_ )
  {
#ifdef KMESSDEBUG_CONTACTLISTMODEL
    kDebug() << "Resetting model tree...";
#endif

    // Delete everything from the model tree
    int childItemsCount = rootNode_->childCount();

    emit layoutAboutToBeChanged();
    for( int row = 0; row < childItemsCount; row++ )
    {
      ContactListModelItem *item = rootNode_->child( row );
      if( item != 0 )
      {
        continue;
      }
      int childItemsCount2 = item->childCount();
      for( int row2 = 0; row2 < childItemsCount2; row2++ )
      {
        delete item->child( row2 );
      }
    }
    emit layoutChanged();

    // Delete the root node
    delete rootNode_;
    rootNode_ = 0;
  }

  if( contacts_.count() || groups_.count() )
  {
#ifdef KMESSDEBUG_CONTACTLIST_DISCONNECTION
    kDebug() << "Resetting" << contacts_.count() << "contacts...";
#endif

    // Delete all contacts
    qDeleteAll( contacts_ );
    contacts_.clear();

#ifdef KMESSDEBUG_CONTACTLIST_DISCONNECTION
    kDebug() << "Resetting" << groups_.count() << "groups...";
#endif

    // Delete all groups
    qDeleteAll( groups_ );
    groups_.clear();
  }

  // Do not recreate the groups
  if( ! restore )
  {
    return;
  }

  // Regenerate the model's root node, the only one which contains groups and contacts
  rootNode_ = new ContactListModelItem();

  // Create the special groups
  addGroup( SpecialGroups::INDIVIDUALS, i18n("Individuals") );
  addGroup( SpecialGroups::ONLINE,      i18n("Online")      );
  addGroup( SpecialGroups::OFFLINE,     i18n("Offline")     );
  addGroup( SpecialGroups::ALLOWED,     i18n("Allowed")     );
  addGroup( SpecialGroups::REMOVED,     i18n("Removed")     );

#ifdef KMESSTEST
  KMESS_ASSERT( groups_.count() == 5 );
  KMESS_ASSERT( rootNode_->childCount() == 5 );
#endif
}


Generated by  Doxygen 1.6.0   Back to index