void TestDistrList::testNewList()
{
    kDebug() ;
    DistributionList dl;
    dl.setName( "foo" );
    assert( !dl.isEmpty() );
    check( "name set", dl.formattedName(), "foo" );
    assert( DistributionList::isDistributionList( dl ) );

    KABC::AddressBook *ab = KABC::StdAddressBook::self();
    ab->insertAddressee( dl );
#if 0 // can't do that until we have KABC::AddressBook::findByFormattedName, or we use setName()
    KABC::Addressee::List addrList = ab->findByName( "foo" );
    assert( addrList.count() == 1 );
    KABC::Addressee addr = addrList.first();
    assert( !addr.isEmpty() );
    check( "correct name", addr.name(), "foo" );
    assert( DistributionList::isDistributionList( addr ) );
#else
    KABC::Addressee addr = dl;
#endif

    DistributionList dl2 = DistributionList::findByName( ab, "foo" );
    assert( !dl2.isEmpty() );
    check( "correct name", dl2.formattedName(), "foo" );
    assert( DistributionList::isDistributionList( dl2 ) );

    // Test the ctor that takes an addressee
    DistributionList dl3( addr );
    assert( !dl3.isEmpty() );
    assert( DistributionList::isDistributionList( dl3 ) );
    check( "correct name", dl3.formattedName(), "foo" );
}
Esempio n. 2
0
void DistributionListEditorWidget::editList()
{
  TQString oldName = mNameCombo->currentText();
  bool ok;
  TQString name = KInputDialog::getText( i18n( "Distribution List" ),
    i18n( "Please change &name:" ), oldName, &ok );
  if (!ok) return;

  DistributionList *list = mManager->list( oldName );
  list->setName( name );

  mNameCombo->clear();
  mNameCombo->insertStringList( mManager->listNames() );
  mNameCombo->setCurrentItem( mNameCombo->count() - 1 );

  updateEntryView();
  slotSelectionAddresseeViewChanged();
}
void TestDistrList::testConverter()
{
    kDebug() ;

    KABC::AddressBook *ab = KABC::StdAddressBook::self();
    QList<KABC::Resource*> resources = ab->resources();
    assert( resources.count() == 1 );

    DistributionListConverter converter( resources[ 0 ] );

    DistributionList pimList;
    KABC::DistributionList *kabcList = converter.convertToKABC( pimList );

    assert( kabcList != 0 );
    assert( kabcList->entries().isEmpty() && kabcList->emails().isEmpty() );
    assert( kabcList->identifier().isEmpty() && kabcList->name().isEmpty() );

    DistributionList pimList2 = converter.convertFromKABC( kabcList );
    assert( pimList2 == pimList );

    delete kabcList;

    pimList.setName( "pimlist-name" );
    pimList.setUid( "pimlist-id" );

    kabcList = converter.convertToKABC( pimList );
    assert( kabcList != 0 );
    assert( kabcList->entries().isEmpty() && kabcList->emails().isEmpty() );
    assert( kabcList->identifier() == "pimlist-id" &&
            kabcList->name() == "pimlist-name" );

    pimList2 = converter.convertFromKABC( kabcList );
    assert( pimList2 == pimList );

    delete kabcList;

    KABC::Addressee addr1 = ab->findByName( "addr1" ).first();
    assert( !addr1.isEmpty() );

    pimList.insertEntry( addr1 );

    kabcList = converter.convertToKABC( pimList );
    assert( kabcList != 0 );
    assert( kabcList->identifier() == "pimlist-id" &&
            kabcList->name() == "pimlist-name" );
    assert( kabcList->entries().count() == 1 && kabcList->emails().count() == 1 );
    assert( kabcList->entries()[ 0 ].addressee() == addr1 );

    pimList2 = converter.convertFromKABC( kabcList );
    assert( pimList2 == pimList );

    delete kabcList;

    KABC::Addressee addr2 = ab->findByName( "addr2" ).first();
    assert( !addr2.isEmpty() );

    pimList.insertEntry( addr2 );

    kabcList = converter.convertToKABC( pimList );
    assert( kabcList != 0 );
    assert( kabcList->identifier() == "pimlist-id" &&
            kabcList->name() == "pimlist-name" );
    assert( kabcList->entries().count() == 2 && kabcList->emails().count() == 2 );
    assert( kabcList->entries()[ 0 ].addressee() == addr1 );
    assert( kabcList->entries()[ 2 ].addressee() == addr2 );

    pimList2 = converter.convertFromKABC( kabcList );
    assert( pimList2 == pimList );

    delete kabcList;
}