void CSVTemplate::setFieldText(int column, KABC::Addressee& addressee, const QString& text) const
{
    if (column < 0 || text.isEmpty()) return;
    if (m_columnToField.isEmpty()) return;

    QMap<int, int>::const_iterator it = m_columnToField.find(column);
    if (it == m_columnToField.end()) return;

    Address address;
    PhoneNumber phone;

    switch (it.value())
    {
        case  0: // "Formatted Name"
            addressee.setFormattedName(text);
            break;
        case  1: // "Family Name"
            addressee.setFamilyName(text);
            break;
        case  2: // "Given Name"
            addressee.setGivenName(text);
            break;
        case  3: // "Additional Names"
            addressee.setAdditionalName(text);
            break;
        case  4: // "Honorific Prefixes"
            addressee.setPrefix(text);
            break;
        case  5: // "Honorific Suffixes"
            addressee.setSuffix(text);
            break;
        case  6: // "Nick Name"
            addressee.setNickName(text);
            break;
        case  7: // "Birthday"
            addressee.setBirthday(parseDate(text));
            break;
        case  8: // "Home Address Street"
            address = addressee.address(Address::Home);
            address.setStreet(text);
            addressee.insertAddress(address);
            break;
        case  9: // "Home Address Locality"
            address = addressee.address(Address::Home);
            address.setLocality(text);
            addressee.insertAddress(address);
            break;
        case 10: // "Home Address Region"
            address = addressee.address(Address::Home);
            address.setRegion(text);
            addressee.insertAddress(address);
            break;
        case 11: // "Home Address Postal Code"
            address = addressee.address(Address::Home);
            address.setPostalCode(text);
            addressee.insertAddress(address);
            break;
        case 12: // "Home Address Country"
            address = addressee.address(Address::Home);
            address.setCountry(text);
            addressee.insertAddress(address);
            break;
        case 13: // "Home Address Label"
            address = addressee.address(Address::Home);
            address.setLabel(text);
            addressee.insertAddress(address);
            break;
        case 14: // "Business Address Street"
            address = addressee.address(Address::Work);
            address.setStreet(text);
            addressee.insertAddress(address);
            break;
        case 15: // "Business Address Locality"
            address = addressee.address(Address::Work);
            address.setLocality(text);
            addressee.insertAddress(address);
            break;
        case 16: // "Business Address Region"
            address = addressee.address(Address::Work);
            address.setRegion(text);
            addressee.insertAddress(address);
            break;
        case 17: // "Business Address Postal Code"
            address = addressee.address(Address::Work);
            address.setPostalCode(text);
            addressee.insertAddress(address);
            break;
        case 18: // "Business Address Country"
            address = addressee.address(Address::Work);
            address.setCountry(text);
            addressee.insertAddress(address);
            break;
        case 19: // "Business Address Label"
            address = addressee.address(Address::Work);
            address.setLabel(text);
            addressee.insertAddress(address);
            break;
        case 20: // "Home Phone"
            phone = PhoneNumber(text, PhoneNumber::Home);
            addressee.insertPhoneNumber(phone);
            break;
        case 21: // "Business Phone"
            phone = PhoneNumber(text, PhoneNumber::Work);
            addressee.insertPhoneNumber(phone);
            break;
        case 22: // "Mobile Phone"
            phone = PhoneNumber(text, PhoneNumber::Cell);
            addressee.insertPhoneNumber(phone);
            break;
        case 23: // "Home Fax"
            phone = PhoneNumber(text, PhoneNumber::Fax | PhoneNumber::Home);
            addressee.insertPhoneNumber(phone);
            break;
        case 24: // "Business Fax"
            phone = PhoneNumber(text, PhoneNumber::Fax | PhoneNumber::Work);
            addressee.insertPhoneNumber(phone);
            break;
        case 25: // "Car Phone"
            phone = PhoneNumber(text, PhoneNumber::Car);
            addressee.insertPhoneNumber(phone);
            break;
        case 26: // "Isdn"
            phone = PhoneNumber(text, PhoneNumber::Isdn);
            addressee.insertPhoneNumber(phone);
            break;
        case 27: // "Pager"
            phone = PhoneNumber(text, PhoneNumber::Pager);
            addressee.insertPhoneNumber(phone);
            break;
        case 28: // "Email Address"
            addressee.insertEmail(text);
            break;
        case 29: // "Mail Client"
            addressee.setMailer(text);
            break;
        case 30: // "Title"
            addressee.setTitle(text);
            break;
        case 31: // "Role"
            addressee.setRole(text);
            break;
        case 32: // "Organization"
            addressee.setOrganization(text);
            break;
        case 33: // "Note"
            addressee.setNote(text);
            break;
        case 34: // "URL"
            addressee.setUrl(text);
            break;
        case 35: // "Department"
            break;
        case 36: // "Profession"
            break;
        case 37: // "Assistant's Name"
            break;
        case 38: // "Manager's Name"
            break;
        case 39: // "Spouse's Name"
            break;
        case 40: // "Office"
            break;
        case 41: // "IM Address"
            break;
        case 42: // "Anniversary"
            break;

        default:
            break;
    }
}
Exemple #2
0
KABC::AddresseeList VCardXXPort::filterContacts( const KABC::AddresseeList &addrList )
{
  KABC::AddresseeList list;

  if ( addrList.isEmpty() )
    return addrList;

  VCardExportSelectionDialog dlg( parentWidget() );
  if ( !dlg.exec() )
    return list;

  KABC::AddresseeList::ConstIterator it;
  for ( it = addrList.begin(); it != addrList.end(); ++it ) {
    KABC::Addressee addr;

    addr.setUid( (*it).uid() );
    addr.setFormattedName( (*it).formattedName() );
    addr.setPrefix( (*it).prefix() );
    addr.setGivenName( (*it).givenName() );
    addr.setAdditionalName( (*it).additionalName() );
    addr.setFamilyName( (*it).familyName() );
    addr.setSuffix( (*it).suffix() );
    addr.setNickName( (*it).nickName() );
    addr.setMailer( (*it).mailer() );
    addr.setTimeZone( (*it).timeZone() );
    addr.setGeo( (*it).geo() );
    addr.setProductId( (*it).productId() );
    addr.setSortString( (*it).sortString() );
    addr.setUrl( (*it).url() );
    addr.setSecrecy( (*it).secrecy() );
    addr.setSound( (*it).sound() );
    addr.setEmails( (*it).emails() );
    addr.setCategories( (*it).categories() );

    if ( dlg.exportPrivateFields() ) {
      addr.setBirthday( (*it).birthday() );
      addr.setNote( (*it).note() );
      addr.setPhoto( (*it).photo() );
    }

    if ( dlg.exportBusinessFields() ) {
      addr.setTitle( (*it).title() );
      addr.setRole( (*it).role() );
      addr.setOrganization( (*it).organization() );

      addr.setLogo( (*it).logo() );

      KABC::PhoneNumber::List phones = (*it).phoneNumbers( KABC::PhoneNumber::Work );
      KABC::PhoneNumber::List::Iterator phoneIt;
      for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt )
        addr.insertPhoneNumber( *phoneIt );

      KABC::Address::List addresses = (*it).addresses( KABC::Address::Work );
      KABC::Address::List::Iterator addrIt;
      for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt )
        addr.insertAddress( *addrIt );
    }

    KABC::PhoneNumber::List phones = (*it).phoneNumbers();
    KABC::PhoneNumber::List::Iterator phoneIt;
    for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
      int type = (*phoneIt).type();

      if ( type & KABC::PhoneNumber::Home && dlg.exportPrivateFields() )
        addr.insertPhoneNumber( *phoneIt );
      else if ( type & KABC::PhoneNumber::Work && dlg.exportBusinessFields() )
        addr.insertPhoneNumber( *phoneIt );
      else if ( dlg.exportOtherFields() )
        addr.insertPhoneNumber( *phoneIt );
    }

    KABC::Address::List addresses = (*it).addresses();
    KABC::Address::List::Iterator addrIt;
    for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
      int type = (*addrIt).type();

      if ( type & KABC::Address::Home && dlg.exportPrivateFields() )
        addr.insertAddress( *addrIt );
      else if ( type & KABC::Address::Work && dlg.exportBusinessFields() )
        addr.insertAddress( *addrIt );
      else if ( dlg.exportOtherFields() )
        addr.insertAddress( *addrIt );
    }

    if ( dlg.exportOtherFields() )
      addr.setCustoms( (*it).customs() );

    if ( dlg.exportEncryptionKeys() ) {
      addKey( addr, KABC::Key::PGP );
      addKey( addr, KABC::Key::X509 );
    }

    list.append( addr );
  }

  return list;
}