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, "*****@*****.**" );

    // Try inserting it again, should do nothing
    dl.insertEntry( addr2, "*****@*****.**" );

    // And insert it with another email address
    dl.insertEntry( addr2, "*****@*****.**" );

    // 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, "*****@*****.**" );
    check( "third entry", entries[2].addressee.name(), "addr2" );
    check( "third entry", entries[2].email, "*****@*****.**" );

    // Test emails()
    QStringList emails = dl.emails( ab );
    kDebug() << emails;
    assert( emails.count() == 3 );
    check( "first email", emails[0], "addr1 <*****@*****.**>" );
    check( "second email", emails[1], "addr2 <*****@*****.**>" );
    check( "third email", emails[2], "addr2 <*****@*****.**>" );

    // Commit changes to the addressbook !!
    ab->insertAddressee( dl );
}
示例#2
0
void DistributionListEditor::changeEmail()
{
  DistributionList *list = mManager->list( mNameCombo->currentText() );
  if ( !list ) return;

  EditEntryItem *entryItem =
      dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
  if ( !entryItem ) return;

  QString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(),
                                               entryItem->email(), this );
  list->removeEntry( entryItem->addressee(), entryItem->email() );
  list->insertEntry( entryItem->addressee(), email );

  updateEntryView();
}
示例#3
0
bool DistributionListManager::load()
{
  KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );

  QMap<QString,QString> entryMap = cfg.entryMap( "DistributionLists" );
  cfg.setGroup( "DistributionLists" );

  // clear old lists
  mLists.clear();
  d->mMissingEntries.clear();

  QMap<QString,QString>::ConstIterator it;
  for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) {
    QString name = it.key();
    QStringList value = cfg.readListEntry( name );

    kdDebug(5700) << "DLM::load(): " << name << ": " << value.join(",") << endl;

    DistributionList *list = new DistributionList( this, name );

    MissingEntryList missingEntries;
    QStringList::ConstIterator entryIt = value.constBegin();
    while( entryIt != value.constEnd() ) {
      QString id = *entryIt++;
      QString email = *entryIt;

      kdDebug(5700) << "----- Entry " << id << endl; 
      
      Addressee a = d->mAddressBook->findByUid( id );
      if ( !a.isEmpty() ) {
        list->insertEntry( a, email );
      } else {
        missingEntries.append( qMakePair( id, email ) );
      }
      
      if ( entryIt == value.end() )
        break;
      ++entryIt;
    }

    d->mMissingEntries.insert( name, missingEntries );
  }
  
  return true;
}
示例#4
0
void DistributionListEditor::addEntry()
{
  AddresseeItem *addresseeItem =
      dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );

  if( !addresseeItem ) {
    kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
    return;
  }

  DistributionList *list = mManager->list( mNameCombo->currentText() );
  if ( !list ) {
    kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
    return;
  }

  list->insertEntry( addresseeItem->addressee() );
  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;
}