void KMail::FolderDialogACLTab::ListViewItem::save( ACLList& aclList,
                                                 KABC::AddressBook* addressBook,
                                                 IMAPUserIdFormat userIdFormat )
{
  // expand distribution lists
  KABC::DistributionList* list = addressBook->findDistributionListByName( userId(),  Qt::CaseInsensitive );
  if ( list ) {
    Q_ASSERT( mModified ); // it has to be new, it couldn't be stored as a distr list name....
    KABC::DistributionList::Entry::List entryList = list->entries();
    KABC::DistributionList::Entry::List::ConstIterator it; // nice number of "::"!
    for( it = entryList.constBegin(); it != entryList.constEnd(); ++it ) {
      QString email = (*it).email();
      if ( email.isEmpty() )
        email = addresseeToUserId( (*it).addressee(), userIdFormat );
      ACLListEntry entry( email, QString(), mPermissions );
      entry.changed = true;
      aclList.append( entry );
    }
  } else { // it wasn't a distribution list
    ACLListEntry entry( userId(), mInternalRightsList, mPermissions );
    if ( mModified ) {
      entry.internalRightsList.clear();
      entry.changed = true;
    }
    aclList.append( entry );
  }
}
Exemple #2
0
void KWMailMergeKABC::parseList( const QString& listName )
{
    if( listName.isEmpty() )
        return;

    kdDebug() << "KWMailMergeKABC::parseList: " << listName << endl;
    KABC::DistributionListManager dlm ( _addressBook );
    dlm.load();

    QStringList::Iterator listIt;

    KABC::DistributionList* list = dlm.list( listName );
    KABC::DistributionList::Entry::List entries = list->entries();

    KABC::DistributionList::Entry::List::Iterator itemIt;
    for ( itemIt = entries.begin(); itemIt != entries.end(); ++itemIt )
    {
        kdDebug() << "WMailMergeKABC::parseList: Listentry UID: " <<
        (*itemIt).addressee.uid() << endl;
        _listUIDs.append( (*itemIt).addressee.uid() );
    }
}
void DistributionListDialog::slotUser1()
{
  bool isEmpty = true;

  KABC::AddressBook *ab = KABC::StdAddressBook::self( true );

  for (int i = 0; i < mRecipientsList->topLevelItemCount(); ++i) {
    DistributionListItem *item = static_cast<DistributionListItem *>(
        mRecipientsList->topLevelItem( i ));
    if ( item && item->checkState( 0 ) == Qt::Checked ) {
      isEmpty = false;
      break;
    }
  }

  if ( isEmpty ) {
    KMessageBox::information( this,
                              i18nc("@info", "There are no recipients in your list. "
                                   "First select some recipients, "
                                   "then try again.") );
    return;
  }

  QString name = mTitleEdit->text();

  if ( name.isEmpty() ) {
    bool ok = false;
    name = KInputDialog::getText( i18nc("@title:window","New Distribution List"),
      i18nc("@label:textbox","Please enter name:"), QString(), &ok, this );
    if ( !ok || name.isEmpty() )
      return;
  }

  if ( ab->findDistributionListByName( name ) ) {
    KMessageBox::information( this,
      i18nc( "@info", "<para>Distribution list with the given name <resource>%1</resource> "
        "already exists. Please select a different name.</para>", name ) );
    return;
  }

  KABC::DistributionList *dlist = ab->createDistributionList( name );

  for (int i = 0; i < mRecipientsList->topLevelItemCount(); ++i) {
    DistributionListItem *item = static_cast<DistributionListItem *>(
        mRecipientsList->topLevelItem( i ));
    if ( item && item->checkState( 0 ) == Qt::Checked ) {
      kDebug() << item->addressee().fullEmail() << item->addressee().uid();
      if ( item->isTransient() ) {
        ab->insertAddressee( item->addressee() );
      }
      if ( item->email() == item->addressee().preferredEmail() ) {
        dlist->insertEntry( item->addressee() );
      } else {
        dlist->insertEntry( item->addressee(), item->email() );
      }
    }
  }

  // let the resource know that the data has changed
  KABC::Resource *resource = dlist->resource();
  resource->insertDistributionList( dlist );

  // save the resource
  bool saveError = true;
  KABC::Ticket *ticket = ab->requestSaveTicket( resource );
  if ( ticket ) {
    if ( ab->save( ticket ) ) {
      saveError = false;
    }
    else
      ab->releaseSaveTicket( ticket );
  }

  if ( saveError ) {
    kWarning() << "Couldn't save new addresses in the distribution list just created to the address book";
  }

  close();
}
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;
}