Example #1
0
KABC::Addressee VCard21Parser::readFromString(const QString &data)
{
    KABC::Addressee addressee;
    VCard21ParserImpl *vCard = VCard21ParserImpl::parseVCard(data);
    QString tmpStr;

    // Check if parsing failed
    if(vCard == 0)
    {
        kdDebug() << "Parsing failed" << endl;
        return addressee;
    }
    // set the addressees name and formated name
    QStringList tmpList = vCard->getValues(VCARD_N);
    QString formattedName = "";
    if(tmpList.count() > 0)
        addressee.setFamilyName(tmpList[0]);
    if(tmpList.count() > 1)
        addressee.setGivenName(tmpList[1]);
    if(tmpList.count() > 2)
        addressee.setAdditionalName(tmpList[2]);
    if(tmpList.count() > 3)
        addressee.setPrefix(tmpList[3]);
    if(tmpList.count() > 4)
        addressee.setSuffix(tmpList[4]);

    tmpStr = (vCard->getValue(VCARD_FN));
    if(!tmpStr.isEmpty())
        addressee.setFormattedName(tmpStr);

    // set the addressee's nick name
    tmpStr = vCard->getValue(VCARD_NICKNAME);
    addressee.setNickName(tmpStr);
    // set the addressee's organization
    tmpStr = vCard->getValue(VCARD_ORG);
    addressee.setOrganization(tmpStr);
    // set the addressee's title
    tmpStr = vCard->getValue(VCARD_TITLE);
    addressee.setTitle(tmpStr);
    // set the addressee's email - we can only deal with two.  The preferenced one and one other.
    tmpStr = vCard->getValue(VCARD_EMAIL, VCARD_EMAIL_INTERNET);
    addressee.insertEmail(tmpStr, false);
    tmpStr = vCard->getValue(VCARD_EMAIL, VCARD_EMAIL_PREF);
    addressee.insertEmail(tmpStr, true);
    // set the addressee's url
    tmpStr = vCard->getValue(VCARD_URL);
    if(tmpStr.isEmpty())
        tmpStr = vCard->getValue(VCARD_URL, VCARD_ADR_WORK);
    if(tmpStr.isEmpty())
        tmpStr = vCard->getValue(VCARD_URL, VCARD_ADR_HOME);
    if(!tmpStr.isEmpty())
    {
        addressee.setUrl(KURL(tmpStr));
    }

    // set the addressee's birthday
    tmpStr = vCard->getValue(VCARD_BDAY);
    addressee.setBirthday(VCardStringToDate(tmpStr));

    // set the addressee's phone numbers
    for(QValueListIterator< VCardLineX > i = vCard->_vcdata->begin(); i != vCard->_vcdata->end(); ++i)
    {
        if((*i).name == VCARD_TEL)
        {
            int type = 0;
            if((*i).qualified)
            {
                if((*i).qualifiers.contains(VCARD_TEL_HOME))
                    type |= PhoneNumber::Home;
                if((*i).qualifiers.contains(VCARD_TEL_WORK))
                    type |= PhoneNumber::Work;
                if((*i).qualifiers.contains(VCARD_TEL_PREF))
                    type |= PhoneNumber::Pref;
                // if ( (*i).qualifiers.contains( VCARD_TEL_VOICE ) )
                //  type |= PhoneNumber::Voice;
                if((*i).qualifiers.contains(VCARD_TEL_FAX))
                    type |= PhoneNumber::Fax;
                if((*i).qualifiers.contains(VCARD_TEL_MSG))
                    type |= PhoneNumber::Msg;
                if((*i).qualifiers.contains(VCARD_TEL_CELL))
                    type |= PhoneNumber::Cell;
                if((*i).qualifiers.contains(VCARD_TEL_PAGER))
                    type |= PhoneNumber::Pager;
                if((*i).qualifiers.contains(VCARD_TEL_BBS))
                    type |= PhoneNumber::Bbs;
                if((*i).qualifiers.contains(VCARD_TEL_MODEM))
                    type |= PhoneNumber::Modem;
                if((*i).qualifiers.contains(VCARD_TEL_CAR))
                    type |= PhoneNumber::Car;
                if((*i).qualifiers.contains(VCARD_TEL_ISDN))
                    type |= PhoneNumber::Isdn;
                if((*i).qualifiers.contains(VCARD_TEL_VIDEO))
                    type |= PhoneNumber::Video;
                if((*i).qualifiers.contains(VCARD_TEL_PCS))
                    type |= PhoneNumber::Pcs;
            }
            addressee.insertPhoneNumber(PhoneNumber((*i).parameters[0], type));
        }
    }

    // set the addressee's addresses
    for(QValueListIterator< VCardLineX > i = vCard->_vcdata->begin(); i != vCard->_vcdata->end(); ++i)
    {
        if((*i).name == VCARD_ADR)
        {
            int type = 0;
            if((*i).qualified)
            {
                if((*i).qualifiers.contains(VCARD_ADR_DOM))
                    type |= Address::Dom;
                if((*i).qualifiers.contains(VCARD_ADR_INTL))
                    type |= Address::Intl;
                if((*i).qualifiers.contains(VCARD_ADR_POSTAL))
                    type |= Address::Postal;
                if((*i).qualifiers.contains(VCARD_ADR_PARCEL))
                    type |= Address::Parcel;
                if((*i).qualifiers.contains(VCARD_ADR_HOME))
                    type |= Address::Home;
                if((*i).qualifiers.contains(VCARD_ADR_WORK))
                    type |= Address::Work;
                if((*i).qualifiers.contains(VCARD_ADR_PREF))
                    type |= Address::Pref;
            }
            addressee.insertAddress(readAddressFromQStringList((*i).parameters, type));
        }
    }

    // set the addressee's delivery label
    tmpStr = vCard->getValue(VCARD_LABEL);
    if(!tmpStr.isEmpty())
    {
        tmpStr.replace("\r\n", "\n");
        Address tmpAddress;
        tmpAddress.setLabel(tmpStr);
        addressee.insertAddress(tmpAddress);
    }

    // set the addressee's notes
    tmpStr = vCard->getValue(VCARD_NOTE);
    tmpStr.replace("\r\n", "\n");
    addressee.setNote(tmpStr);

    // set the addressee's timezone
    tmpStr = vCard->getValue(VCARD_TZ);
    TimeZone tmpZone(tmpStr.toInt());
    addressee.setTimeZone(tmpZone);

    // set the addressee's geographical position
    tmpList = vCard->getValues(VCARD_GEO);
    if(tmpList.count() == 2)
    {
        tmpStr = tmpList[0];
        float glat = tmpStr.toFloat();
        tmpStr = tmpList[1];
        float glong = tmpStr.toFloat();
        Geo tmpGeo(glat, glong);
        addressee.setGeo(tmpGeo);
    }

    // set the last revision date
    tmpStr = vCard->getValue(VCARD_REV);
    addressee.setRevision(VCardStringToDate(tmpStr));

    // set the role of the addressee
    tmpStr = vCard->getValue(VCARD_ROLE);
    addressee.setRole(tmpStr);

    delete vCard;

    return addressee;
}
Example #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;
}