本文整理汇总了C++中kabc::AddressBook::findByName方法的典型用法代码示例。如果您正苦于以下问题:C++ AddressBook::findByName方法的具体用法?C++ AddressBook::findByName怎么用?C++ AddressBook::findByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kabc::AddressBook
的用法示例。
在下文中一共展示了AddressBook::findByName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void TestDistrList::setup()
{
// We need a std addressbook
KABC::AddressBook *ab = KABC::StdAddressBook::self();
KABC::StdAddressBook::setAutomaticSave( false );
// and two contacts
KABC::Addressee addr1;
addr1.setName( "addr1" );
addr1.setFormattedName( "addr1" );
addr1.insertEmail( "[email protected]", true );
addr1.insertEmail( "[email protected]" );
ab->insertAddressee( addr1 );
assert( addr1.emails().count() == 2 );
KABC::Addressee addr2;
addr2.setName( "addr2" );
addr2.insertEmail( "[email protected]", true );
addr2.insertEmail( "[email protected]" );
ab->insertAddressee( addr2 );
assert( addr2.emails().count() == 2 );
assert( !ab->findByName( "addr1" ).isEmpty() );
assert( !ab->findByName( "addr2" ).isEmpty() );
}
示例2: testDuplicate
void TestDistrList::testDuplicate()
{
kDebug() ;
// This is a special test for the case where we have a contact and a distr list with the same name
KABC::AddressBook *ab = KABC::StdAddressBook::self();
KABC::Addressee addr;
addr.setName( "foo" );
addr.insertEmail( "[email protected]", true );
ab->insertAddressee( addr );
#if 0 // we need a findByFormattedName
KABC::Addressee::List addrList = ab->findByName( "foo" );
assert( addrList.count() == 2 );
bool a = DistributionList::isDistributionList( addrList.first() );
bool b = DistributionList::isDistributionList( addrList.last() );
// one is a distr list, but not both
assert( a || b );
//
assert( ! ( a && b ) );
#endif
DistributionList dl = DistributionList::findByName( ab, "foo" );
assert( !dl.isEmpty() );
assert( DistributionList::isDistributionList( dl ) );
assert( dl.formattedName() == "foo" );
}
示例3: testNewList
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" );
}
示例4: testInsertEntry
void TestDistrList::testInsertEntry()
{
kDebug() ;
KABC::AddressBook *ab = KABC::StdAddressBook::self();
DistributionList dl = DistributionList::findByName( ab, "foo" );
assert( !dl.isEmpty() );
#if 0 // the usual method
KABC::Addressee addr1 = ab->findByName( "addr1" ).first();
assert( !addr1.isEmpty() );
dl.insertEntry( addr1 );
#else // the kolab-resource method
dl.insertEntry( "addr1" );
#endif
KABC::Addressee addr2 = ab->findByName( "addr2" ).first();
assert( !addr2.isEmpty() );
dl.insertEntry( addr2, "[email protected]" );
// Try inserting it again, should do nothing
dl.insertEntry( addr2, "[email protected]" );
// And insert it with another email address
dl.insertEntry( addr2, "[email protected]" );
// Test entries()
DistributionList::Entry::List entries = dl.entries( ab );
check( "entries count", QString::number( entries.count() ), "3" );
check( "first entry", entries[0].addressee.name(), "addr1" );
check( "first entry", entries[0].email, QString() );
check( "second entry", entries[1].addressee.name(), "addr2" );
check( "second entry", entries[1].email, "[email protected]" );
check( "third entry", entries[2].addressee.name(), "addr2" );
check( "third entry", entries[2].email, "[email protected]" );
// Test emails()
QStringList emails = dl.emails( ab );
kDebug() << emails;
assert( emails.count() == 3 );
check( "first email", emails[0], "addr1 <[email protected]>" );
check( "second email", emails[1], "addr2 <[email protected]>" );
check( "third email", emails[2], "addr2 <[email protected]>" );
// Commit changes to the addressbook !!
ab->insertAddressee( dl );
}
示例5: testRemoveEntry
void TestDistrList::testRemoveEntry()
{
kDebug() ;
KABC::AddressBook *ab = KABC::StdAddressBook::self();
DistributionList dl = DistributionList::findByName( ab, "foo" );
assert( !dl.isEmpty() );
DistributionList::Entry::List entries = dl.entries( ab );
check( "entries count before removeEntry", QString::number( entries.count() ), "3" );
// Removing an empty entry shouldn't do anything
dl.removeEntry( KABC::Addressee() );
check( "entries count after removing empty entry", QString::number( dl.entries(ab).count() ), "3" );
KABC::Addressee addr1 = ab->findByName( "addr1" ).first();
assert( !addr1.isEmpty() );
// Removing an entry with the wrong email passed, shouldn't do anything
dl.removeEntry( addr1, "[email protected]" );
check( "entries count after removing entry with invalid email", QString::number( dl.entries(ab).count() ), "3" );
// Now remove entry correctly
dl.removeEntry( addr1 );
check( "removeEntry(addr1) worked", QString::number( dl.entries(ab).count() ), "2" );
QStringList emails = dl.emails( ab );
assert( emails.count() == 2 );
check( "first email", emails[0], "addr2 <[email protected]>" );
// Now move on to addr2. First remove with no or a wrong email (nothing should happen)
KABC::Addressee addr2 = ab->findByName( "addr2" ).first();
assert( !addr2.isEmpty() );
dl.removeEntry( addr2 );
check( "entries count after removing entry with no email", QString::number( dl.entries(ab).count() ), "2" );
// Now remove addr2 correctly
dl.removeEntry( addr2, "[email protected]" );
check( "entries count after removing addr2", QString::number( dl.entries(ab).count() ), "1" );
dl.removeEntry( addr2, "[email protected]" );
check( "entries count after removing alternate addr2", QString::number( dl.entries(ab).count() ), "0" );
assert( dl.entries(ab).isEmpty() );
assert( dl.emails(ab).isEmpty() );
assert( DistributionList::isDistributionList( dl ) );
ab->insertAddressee( dl );
}
示例6: testConverter
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;
}